Merge pull request #650 from bwagner/tonleiter

FIXES: TODO in rotateChroma
This commit is contained in:
Felix Roos 2023-07-17 17:57:16 +02:00 committed by GitHub
commit 584d469a73
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 7 deletions

View File

@ -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);

View File

@ -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) => {

View File

@ -1,4 +1,4 @@
// Vitest Snapshot v1
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`renders tunes > tune: amensister 1`] = `
[