Correctly handle silences for non-notes

This commit is contained in:
Aria
2025-09-14 17:04:39 -05:00
parent b8c46d6b26
commit 92b2013cf6
2 changed files with 4 additions and 5 deletions
+1 -1
View File
@@ -66,7 +66,7 @@ describe('tonal', () => {
n(seq('0b#', '1#b', '2#b#'))
.scale('C major')
.firstCycleValues.map((h) => h.note),
).toEqual(['', '', '']);
).toEqual([]);
});
it('snaps notes (upwards) to scale', () => {
const inputNotes = ['Cb', 'Eb', 'G', 'A#', 'Bb'];
+3 -4
View File
@@ -189,8 +189,7 @@ function _convertStepToNumberAndOffset(step) {
const match = /^(-?\d+)(#+|b+)?$/.exec(step);
if (!match) {
logger(`[tonal] invalid scale step "${step}", expected number or integer with optional # b suffixes`, 'error');
return [silence, 0];
throw new Error(`invalid scale step "${step}", expected number or integer with optional # b suffixes`);
}
asNumber = Number(match[1]);
// These decorations will determine the semitone offset based on the number of
@@ -275,8 +274,8 @@ export const scale = register(
// legacy..
return pure(step);
}
const [number, offset] = _convertStepToNumberAndOffset(step);
try {
const [number, offset] = _convertStepToNumberAndOffset(step);
let note;
if (isObject && value.anchor) {
note = stepInNamedScale(number, scale, value.anchor);
@@ -287,7 +286,7 @@ export const scale = register(
value = pure(isObject ? { ...value, note } : note);
} catch (err) {
logger(`[tonal] ${err.message}`, 'error');
value = silence;
return silence;
}
return value;
}