summaryrefslogtreecommitdiffstats
path: root/scale.mjs
diff options
context:
space:
mode:
Diffstat (limited to 'scale.mjs')
-rw-r--r--scale.mjs17
1 files changed, 15 insertions, 2 deletions
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)