diff options
| author | Brian Cully <bjc@spork.org> | 2025-07-28 08:52:51 -0400 |
|---|---|---|
| committer | Brian Cully <bjc@spork.org> | 2025-07-28 08:52:51 -0400 |
| commit | 77f5e81d0a1adc497040eaa89095635f3de3924e (patch) | |
| tree | 4ad6a00edf5cfe3c5c2bf0090ba80f8d13c143cc /scale.mjs | |
| parent | 2d12e407ccac850dd2e1ce133a2f335677a2ef29 (diff) | |
| download | chords-77f5e81d0a1adc497040eaa89095635f3de3924e.tar.gz chords-77f5e81d0a1adc497040eaa89095635f3de3924e.zip | |
attach octave values to frets
sometimes just do the simple thing
Diffstat (limited to 'scale.mjs')
| -rw-r--r-- | scale.mjs | 17 |
1 files changed, 15 insertions, 2 deletions
@@ -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) |
