summaryrefslogtreecommitdiffstats
path: root/scale.mjs
diff options
context:
space:
mode:
authorBrian Cully <bjc@spork.org>2025-07-26 14:55:53 -0400
committerBrian Cully <bjc@spork.org>2025-07-26 14:55:53 -0400
commit2a9b6ef0be04b5b5cacc47922e19c05d190d6ade (patch)
treee07e9648891b065cb8c12cea563386a9b92264c7 /scale.mjs
parent18b63657328a619a638688e5a85c9c1da2b196c1 (diff)
downloadchords-2a9b6ef0be04b5b5cacc47922e19c05d190d6ade.tar.gz
chords-2a9b6ef0be04b5b5cacc47922e19c05d190d6ade.zip
first stab at fretboard player.
need to handle actual chord positions so everything isn't in 4, but otherwise works?
Diffstat (limited to 'scale.mjs')
-rw-r--r--scale.mjs30
1 files changed, 29 insertions, 1 deletions
diff --git a/scale.mjs b/scale.mjs
index 5b04831..fbd3617 100644
--- a/scale.mjs
+++ b/scale.mjs
@@ -8,12 +8,22 @@ function notesBetween(a, b) {
}
}
+export function toCents([aNote, aChord], [bNote, bChord]) {
+ console.debug('- a', [aNote, aChord]);
+ console.debug('- b', [bNote, bChord]);
+ const offset = (aNote.distanceTo(bNote)) * 100;
+ console.debug('- offset', offset);
+ const scale = (bChord - aChord) * 1200;
+ console.debug('- scale', scale);
+ return scale + offset;
+}
+
export class Note {
static natural = '♮';
static sharp = '♯';
static flat = '♭';
- static range = ['A', 'B', 'C', 'D', 'E', 'F', 'G'];
+ static range = ['C', 'D', 'E', 'F', 'G', 'A', 'B'];
static get first() {
return this.range.at(0);
}
@@ -26,6 +36,16 @@ export class Note {
return this.noSharps.map(n => String.fromCharCode(n.charCodeAt()+1))
}
+ static get noteRange() {
+ return this.range.flatMap(n => {
+ if (this.noSharps.includes(n)) {
+ return new Note(n);
+ } else {
+ return [new Note(n, false), new Note(n, true)];
+ }
+ })
+ }
+
static fromString(string) {
const [root, accidental] = [string[0], string[1]];
switch (accidental) {
@@ -62,6 +82,14 @@ export class Note {
this.isSharp = isSharp;
}
+ distanceTo(dest) {
+ const srcFromC = Note.noteRange.findIndex(t =>
+ t.toString() === this.toString());
+ const destFromC = Note.noteRange.findIndex(t =>
+ t.toString() === dest.toString());
+ return destFromC - srcFromC;
+ }
+
toString() {
return this.root + (this.isSharp ? Note.sharp : '');
}