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