diff --git a/packages/tonal/test/tonleiter.test.mjs b/packages/tonal/test/tonleiter.test.mjs index da029b7b..ecced7e7 100644 --- a/packages/tonal/test/tonleiter.test.mjs +++ b/packages/tonal/test/tonleiter.test.mjs @@ -61,8 +61,7 @@ describe('tonleiter', () => { }); test('rotateChroma', () => { expect(rotateChroma(0, 1)).toBe(1); - expect(rotateChroma(0, -1)).toBe(-1); // this is wrong... - //expect(rotateChroma(0, -1)).toBe(11); // <-- TODO + expect(rotateChroma(0, -1)).toBe(11); expect(rotateChroma(11, 1)).toBe(0); expect(rotateChroma(11, 13)).toBe(0); }); @@ -81,9 +80,9 @@ describe('tonleiter', () => { }); test('note2pc', () => { expect(note2pc('C5')).toBe('C'); - // expect(note2pc('C52')).toBe('C'); // <- 2 digits fail + expect(note2pc('C52')).toBe('C'); expect(note2pc('Bb3')).toBe('Bb'); - //expect(note2pc('F')).toBe('F'); // <- fails + expect(note2pc('F')).toBe('F'); }); test('note2oct', () => { expect(note2oct('C5')).toBe(5); diff --git a/packages/tonal/tonleiter.mjs b/packages/tonal/tonleiter.mjs index f0e5a224..d491a2d9 100644 --- a/packages/tonal/tonleiter.mjs +++ b/packages/tonal/tonleiter.mjs @@ -13,7 +13,7 @@ export const pc2chroma = (pc) => { return pcs.indexOf(letter.toLowerCase()) + rest.reduce((sum, sign) => sum + accs[sign], 0); }; -export const rotateChroma = (chroma, steps) => (chroma + steps) % 12; +export const rotateChroma = (chroma, steps) => (chroma + (steps % 12) + 12) % 12; export const chroma2pc = (chroma, sharp = false) => { return (sharp ? sharps : flats)[chroma]; @@ -27,7 +27,7 @@ export function tokenizeChord(chord) { } return match.slice(1); } -export const note2pc = (note) => note.slice(0, -1); +export const note2pc = (note) => note.match(/^[A-G][#b]?/i)[0]; export const note2oct = (note) => Number(note.slice(-1)); export const note2chroma = (note) => { diff --git a/test/__snapshots__/tunes.test.mjs.snap b/test/__snapshots__/tunes.test.mjs.snap index 3bf945e6..3c072ca2 100644 --- a/test/__snapshots__/tunes.test.mjs.snap +++ b/test/__snapshots__/tunes.test.mjs.snap @@ -1,4 +1,4 @@ -// Vitest Snapshot v1 +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html exports[`renders tunes > tune: amensister 1`] = ` [