Skip to content

Commit

Permalink
Merge pull request #650 from bwagner/tonleiter
Browse files Browse the repository at this point in the history
FIXES: TODO in rotateChroma
  • Loading branch information
felixroos authored Jul 17, 2023
2 parents bbb29eb + 4298e58 commit 584d469
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
7 changes: 3 additions & 4 deletions packages/tonal/test/tonleiter.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions packages/tonal/tonleiter.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion test/__snapshots__/tunes.test.mjs.snap
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Vitest Snapshot v1
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`renders tunes > tune: amensister 1`] = `
[
Expand Down

0 comments on commit 584d469

Please sign in to comment.