From bbb29ebd7c1ee4af8d8cd2ba36d30cb2fd88b466 Mon Sep 17 00:00:00 2001 From: Felix Roos Date: Thu, 13 Jul 2023 12:52:57 +0200 Subject: [PATCH] fix: duck mode with n + detect chord obj in rootNotes --- packages/tonal/tonleiter.mjs | 7 ++++--- packages/tonal/voicings.mjs | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/tonal/tonleiter.mjs b/packages/tonal/tonleiter.mjs index d4937b4a..f0e5a224 100644 --- a/packages/tonal/tonleiter.mjs +++ b/packages/tonal/tonleiter.mjs @@ -119,12 +119,13 @@ export function renderVoicing({ chord, dictionary, offset = 0, n, mode = 'below' const voicingMidi = voicing.map((v) => anchorMidi - targetStep + v); let notes = voicingMidi.map((n) => midi2note(n)); + + if (mode === 'duck') { + notes = notes.filter((_, i) => voicingMidi[i] !== noteToMidi(anchor)); + } if (n !== undefined) { return [scaleStep(notes, n)]; } - if (mode === 'duck') { - notes = notes.filter((n) => x2midi(n) !== noteToMidi(anchor)); - } return notes; } diff --git a/packages/tonal/voicings.mjs b/packages/tonal/voicings.mjs index 996bbb28..bd11a961 100644 --- a/packages/tonal/voicings.mjs +++ b/packages/tonal/voicings.mjs @@ -159,9 +159,10 @@ export const voicings = register('voicings', function (dictionary, pat) { */ export const rootNotes = register('rootNotes', function (octave, pat) { return pat.fmap((value) => { - value = value.chord || value; - const root = value.match(/^([a-gA-G][b#]?).*$/)[1]; - return root + octave; + const chord = value.chord || value; + const root = chord.match(/^([a-gA-G][b#]?).*$/)[1]; + const note = root + octave; + return value.chord ? { note } : note; }); });