From 0fa5832b639dcaa19705f9b6be323e26c20f9246 Mon Sep 17 00:00:00 2001 From: Bernhard Wagner Date: Fri, 14 Jul 2023 13:45:27 +0200 Subject: [PATCH 1/4] FIXES: TODO in rotateChroma --- packages/tonal/test/tonleiter.test.mjs | 3 +-- packages/tonal/tonleiter.mjs | 3 ++- test/__snapshots__/tunes.test.mjs.snap | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/tonal/test/tonleiter.test.mjs b/packages/tonal/test/tonleiter.test.mjs index da029b7b..960d3770 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); }); diff --git a/packages/tonal/tonleiter.mjs b/packages/tonal/tonleiter.mjs index f0e5a224..67a7b272 100644 --- a/packages/tonal/tonleiter.mjs +++ b/packages/tonal/tonleiter.mjs @@ -13,7 +13,8 @@ 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]; diff --git a/test/__snapshots__/tunes.test.mjs.snap b/test/__snapshots__/tunes.test.mjs.snap index 3bf945e6..cb8ac606 100644 --- a/test/__snapshots__/tunes.test.mjs.snap +++ b/test/__snapshots__/tunes.test.mjs.snap @@ -7831,8 +7831,8 @@ exports[`renders tunes > tune: hyperpop 1`] = ` "[ 3/2 ⇜ (11/6 → 15/8) | note:C#5 s:sawtooth gain:0.3422847385870941 attack:0.001 decay:0.2 sustain:0 hcutoff:5845.47833980621 cutoff:4000 ]", "[ 15/8 → 2/1 | note:D3 s:sawtooth gain:0.3 attack:0.01 decay:0.1 sustain:0.5 cutoff:2151.2782118349805 ]", "[ 15/8 → 2/1 | note:D3 s:square gain:0.3 attack:0.01 decay:0.1 sustain:0.5 cutoff:2151.2782118349805 ]", - "[ (15/8 → 2/1) ⇝ 9/4 | note:A5 s:sawtooth gain:0.35343108171056004 attack:0.001 decay:0.2 sustain:0 hcutoff:5796.978025372246 cutoff:4000 ]", - "[ (15/8 → 2/1) ⇝ 9/4 | note:C#5 s:sawtooth gain:0.35343108171056004 attack:0.001 decay:0.2 sustain:0 hcutoff:5796.978025372246 cutoff:4000 ]", + "[ (15/8 → 2/1) ⇝ 9/4 | note:A5 s:sawtooth gain:0.35343108171056015 attack:0.001 decay:0.2 sustain:0 hcutoff:5796.978025372246 cutoff:4000 ]", + "[ (15/8 → 2/1) ⇝ 9/4 | note:C#5 s:sawtooth gain:0.35343108171056015 attack:0.001 decay:0.2 sustain:0 hcutoff:5796.978025372246 cutoff:4000 ]", "[ (15/8 → 2/1) ⇝ 19/8 | note:F#3 s:square gain:0.7 attack:0.01 decay:0.1 sustain:0 cutoff:2151.2782118349805 ]", "[ (15/8 → 2/1) ⇝ 19/8 | note:A3 s:square gain:0.7 attack:0.01 decay:0.1 sustain:0 cutoff:2151.2782118349805 ]", "[ 13/8 ⇜ (23/12 → 2/1) | note:F#5 s:sawtooth gain:0.3479759264430665 attack:0.001 decay:0.2 sustain:0 hcutoff:5822.02388217981 cutoff:4000 ]", From b8929a0d18e10c725a19fc85c867d6eec42b7978 Mon Sep 17 00:00:00 2001 From: Bernhard Wagner Date: Fri, 14 Jul 2023 13:56:36 +0200 Subject: [PATCH 2/4] FIXES: prettier formatting --- packages/tonal/tonleiter.mjs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/tonal/tonleiter.mjs b/packages/tonal/tonleiter.mjs index 67a7b272..e23edf13 100644 --- a/packages/tonal/tonleiter.mjs +++ b/packages/tonal/tonleiter.mjs @@ -13,8 +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) + 12) % 12; - +export const rotateChroma = (chroma, steps) => (chroma + (steps % 12) + 12) % 12; export const chroma2pc = (chroma, sharp = false) => { return (sharp ? sharps : flats)[chroma]; From a3fdfbbc162f4ac2472fc8f8a7a7e69c463fcafa Mon Sep 17 00:00:00 2001 From: Bernhard Wagner Date: Fri, 14 Jul 2023 14:04:35 +0200 Subject: [PATCH 3/4] FIXES: weird gain difference --- test/__snapshots__/tunes.test.mjs.snap | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/__snapshots__/tunes.test.mjs.snap b/test/__snapshots__/tunes.test.mjs.snap index cb8ac606..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`] = ` [ @@ -7831,8 +7831,8 @@ exports[`renders tunes > tune: hyperpop 1`] = ` "[ 3/2 ⇜ (11/6 → 15/8) | note:C#5 s:sawtooth gain:0.3422847385870941 attack:0.001 decay:0.2 sustain:0 hcutoff:5845.47833980621 cutoff:4000 ]", "[ 15/8 → 2/1 | note:D3 s:sawtooth gain:0.3 attack:0.01 decay:0.1 sustain:0.5 cutoff:2151.2782118349805 ]", "[ 15/8 → 2/1 | note:D3 s:square gain:0.3 attack:0.01 decay:0.1 sustain:0.5 cutoff:2151.2782118349805 ]", - "[ (15/8 → 2/1) ⇝ 9/4 | note:A5 s:sawtooth gain:0.35343108171056015 attack:0.001 decay:0.2 sustain:0 hcutoff:5796.978025372246 cutoff:4000 ]", - "[ (15/8 → 2/1) ⇝ 9/4 | note:C#5 s:sawtooth gain:0.35343108171056015 attack:0.001 decay:0.2 sustain:0 hcutoff:5796.978025372246 cutoff:4000 ]", + "[ (15/8 → 2/1) ⇝ 9/4 | note:A5 s:sawtooth gain:0.35343108171056004 attack:0.001 decay:0.2 sustain:0 hcutoff:5796.978025372246 cutoff:4000 ]", + "[ (15/8 → 2/1) ⇝ 9/4 | note:C#5 s:sawtooth gain:0.35343108171056004 attack:0.001 decay:0.2 sustain:0 hcutoff:5796.978025372246 cutoff:4000 ]", "[ (15/8 → 2/1) ⇝ 19/8 | note:F#3 s:square gain:0.7 attack:0.01 decay:0.1 sustain:0 cutoff:2151.2782118349805 ]", "[ (15/8 → 2/1) ⇝ 19/8 | note:A3 s:square gain:0.7 attack:0.01 decay:0.1 sustain:0 cutoff:2151.2782118349805 ]", "[ 13/8 ⇜ (23/12 → 2/1) | note:F#5 s:sawtooth gain:0.3479759264430665 attack:0.001 decay:0.2 sustain:0 hcutoff:5822.02388217981 cutoff:4000 ]", From 4298e582fb67324410f8e912f83c1ae0c01070bc Mon Sep 17 00:00:00 2001 From: Bernhard Wagner Date: Fri, 14 Jul 2023 14:38:26 +0200 Subject: [PATCH 4/4] FIXES: note2pc TODOs --- packages/tonal/test/tonleiter.test.mjs | 4 ++-- packages/tonal/tonleiter.mjs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/tonal/test/tonleiter.test.mjs b/packages/tonal/test/tonleiter.test.mjs index 960d3770..ecced7e7 100644 --- a/packages/tonal/test/tonleiter.test.mjs +++ b/packages/tonal/test/tonleiter.test.mjs @@ -80,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 e23edf13..d491a2d9 100644 --- a/packages/tonal/tonleiter.mjs +++ b/packages/tonal/tonleiter.mjs @@ -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) => {