diff --git a/packages/tonal/test/tonal.test.mjs b/packages/tonal/test/tonal.test.mjs index 8dd0e1861..968534c80 100644 --- a/packages/tonal/test/tonal.test.mjs +++ b/packages/tonal/test/tonal.test.mjs @@ -30,6 +30,14 @@ describe('tonal', () => { .firstCycleValues.map((h) => h.note), ).toEqual(['C3', 'D3', 'E3']); }); + it('scale with n and note values', () => { + expect( + n(0, 1, 2) + .note(3, 4, 5) + .scale('C major') + .firstCycleValues.map((h) => h.note), + ).toEqual(['F3', 'G3', 'A3']); + }); it('scale with colon', () => { expect( n(0, 1, 2) @@ -37,6 +45,13 @@ describe('tonal', () => { .firstCycleValues.map((h) => h.note), ).toEqual(['C3', 'D3', 'E3']); }); + it('scale without tonic', () => { + expect( + n(0, 1, 2) + .scale('major') + .firstCycleValues.map((h) => h.note), + ).toEqual(['C3', 'D3', 'E3']); + }); it('scale with mininotation colon', () => { expect( n(0, 1, 2) diff --git a/packages/tonal/tonal.mjs b/packages/tonal/tonal.mjs index 4c25d23ea..012a0fc20 100644 --- a/packages/tonal/tonal.mjs +++ b/packages/tonal/tonal.mjs @@ -14,7 +14,7 @@ function scaleStep(step, scale) { scale = scale.replaceAll(':', ' '); step = Math.ceil(step); let { intervals, tonic, empty } = Scale.get(scale); - if ((empty && isNote(scale)) || (!empty && !tonic)) { + if ((empty && isNote(scale)) || (empty && !tonic)) { throw new Error(`incomplete scale. Make sure to use ":" instead of spaces, example: .scale("C:major")`); } else if (empty) { throw new Error(`invalid scale "${scale}"`); @@ -199,10 +199,7 @@ export const scale = register( pat .fmap((value) => { const isObject = typeof value === 'object'; - let step = isObject ? value.n : value; - if (isObject) { - delete value.n; // remove n so it won't cause trouble - } + let step = isObject ? (value.note ?? value.n) : value; if (isNote(step)) { // legacy.. return pure(step);