From 77f5e81d0a1adc497040eaa89095635f3de3924e Mon Sep 17 00:00:00 2001 From: Brian Cully Date: Mon, 28 Jul 2025 08:52:51 -0400 Subject: attach octave values to frets sometimes just do the simple thing --- scale.mjs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'scale.mjs') diff --git a/scale.mjs b/scale.mjs index fbd3617..78c8433 100644 --- a/scale.mjs +++ b/scale.mjs @@ -1,4 +1,4 @@ -function notesBetween(a, b) { +export function naturalNotesBetween(a, b) { const [tonicA, tonicB] = [a[0], b[0]] const abs = tonicB.charCodeAt() - tonicA.charCodeAt(); if (abs < 0) { @@ -8,7 +8,20 @@ function notesBetween(a, b) { } } +export function chromaticNotesBetween(a, b) { + console.log('chromaticNotesBetween', a, b); + const [aNote, bNote] = [a, b].map(x => Note.fromString(x)); + console.log(' -- aNote', aNote); + console.log(' -- bNote', bNote); + const aIndex = Note.noteRange.findIndex(x => aNote.toString() == x.toString()); + const bIndex = Note.noteRange.findIndex(x => bNote.toString() == x.toString()); + console.log(' -- aNote', aIndex); + console.log(' -- bNote', bIndex); + return aIndex - bIndex; +} + export function toCents([aNote, aChord], [bNote, bChord]) { + console.debug('toCents', [aNote, aChord], [bNote, bChord]); console.debug('- a', [aNote, aChord]); console.debug('- b', [bNote, bChord]); const offset = (aNote.distanceTo(bNote)) * 100; @@ -150,7 +163,7 @@ function scaleFromIntervals(tonic, intervals) { const note = chromaticScale[scaleIndex + steps]; // don't display two base notes in a row by changing // accidentals. - const delta = notesBetween(lastBase, note); + const delta = naturalNotesBetween(lastBase, note); if (delta === 0) { const nextBase = chromaticScale[scaleIndex + steps + 1][0]; //console.log('0', 'prev', lastBase, 'next', nextBase, 'note', note) -- cgit v1.3