From dd3f4e4751bf06d9a1f0ae8a3c0adf7d55bd3d8f Mon Sep 17 00:00:00 2001 From: Felix Roos Date: Mon, 27 Jun 2022 00:03:06 +0200 Subject: [PATCH] support "s" as "#" alternative inside note names --- packages/core/util.mjs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/core/util.mjs b/packages/core/util.mjs index 35a0d8f4..0a4866d0 100644 --- a/packages/core/util.mjs +++ b/packages/core/util.mjs @@ -10,7 +10,7 @@ export const tokenizeNote = (note) => { if (typeof note !== 'string') { return []; } - const [pc, acc = '', oct] = note.match(/^([a-gA-G])([#b]*)([0-9])?$/)?.slice(1) || []; + const [pc, acc = '', oct] = note.match(/^([a-gA-G])([#bs]*)([0-9])?$/)?.slice(1) || []; if (!pc) { return []; } @@ -24,7 +24,7 @@ export const toMidi = (note) => { throw new Error('not a note: "' + note + '"'); } 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, s: 1 }[char], 0) || 0; return (Number(oct) + 1) * 12 + chroma + offset; }; export const fromMidi = (n) => {