fix uppercase notes
This commit is contained in:
parent
420a955314
commit
ee2d32339f
1 changed files with 1 additions and 1 deletions
2
util.mjs
2
util.mjs
|
|
@ -2,7 +2,7 @@ export const isNote = (name) => /^[a-gA-G][#b]?[0-9]$/.test(name);
|
||||||
export const tokenizeNote = (note) => note.match(/^([a-gA-G])([#b])?([0-9])?$/).slice(1);
|
export const tokenizeNote = (note) => note.match(/^([a-gA-G])([#b])?([0-9])?$/).slice(1);
|
||||||
export const toMidi = (note) => {
|
export const toMidi = (note) => {
|
||||||
const [pc, acc, oct] = tokenizeNote(note);
|
const [pc, acc, oct] = tokenizeNote(note);
|
||||||
const chroma = { c: 0, d: 2, e: 4, f: 5, g: 7, a: 9, b: 11 }[pc];
|
const chroma = { c: 0, d: 2, e: 4, f: 5, g: 7, a: 9, b: 11 }[pc.toLowerCase()];
|
||||||
const offset = acc?.split('').reduce((o, char) => o + { '#': 1, b: -1 }[char], 0) || 0;
|
const offset = acc?.split('').reduce((o, char) => o + { '#': 1, b: -1 }[char], 0) || 0;
|
||||||
return (Number(oct) + 1) * 12 + chroma + offset;
|
return (Number(oct) + 1) * 12 + chroma + offset;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue