Skip to content

Commit

Permalink
Convert midi name to midi note
Browse files Browse the repository at this point in the history
  • Loading branch information
kmturley committed Feb 20, 2024
1 parent d92c608 commit 9c090c5
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"webpack-merge": "^5.8.0"
},
"dependencies": {
"@sfz-tools/core": "^0.0.27",
"@sfz-tools/core": "^0.0.28",
"browser-fs-access": "^0.33.0",
"node-fetch": "^2.6.12",
"xml-js": "^1.6.11"
Expand Down
21 changes: 20 additions & 1 deletion src/components/Audio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Event from './event';
import { FileLocal, FileRemote } from '../types/files';
import FileLoader from '../utils/fileLoader';
import Sample from './Sample';
import { pathGetDirectory } from '@sfz-tools/core/dist/utils';
import { midiNameToNum, pathGetDirectory } from '@sfz-tools/core/dist/utils';
import { parseHeaders, parseSfz } from '@sfz-tools/core/dist/parse';
import { ParseHeader, ParseOpcodeObj } from '@sfz-tools/core/dist/types/parse';

Expand Down Expand Up @@ -80,6 +80,7 @@ class Audio extends Event {
}

this.regions = parseHeaders(headers, prefix);
this.regions = this.midiNamesToNum(this.regions);
console.log('regions', this.regions);

console.log('preload', this.preload);
Expand All @@ -99,6 +100,24 @@ class Audio extends Event {
return keyboardMap;
}

midiNameToNumConvert(val: string | number) {
if (typeof val === 'number') return val;
const isLetters: RegExp = /[a-zA-Z]/g;
if (isLetters.test(val)) return midiNameToNum(val);
return parseInt(val, 10);
}

midiNamesToNum(regions: ParseOpcodeObj[]) {
for (const key in regions) {
const region: ParseOpcodeObj = regions[key];
if (region.lokey) region.lokey = this.midiNameToNumConvert(region.lokey);
if (region.hikey) region.hikey = this.midiNameToNumConvert(region.hikey);
if (region.key) region.key = this.midiNameToNumConvert(region.key);
if (region.pitch_keycenter) region.pitch_keycenter = this.midiNameToNumConvert(region.pitch_keycenter);
}
return regions;
}

updateKeyboardMap(region: ParseOpcodeObj, keyboardMap: AudioKeyboardMap) {
if (!region.lokey && region.key) region.lokey = region.key;
if (!region.hikey && region.key) region.hikey = region.key;
Expand Down

0 comments on commit 9c090c5

Please sign in to comment.