diff options
| author | Brian Cully <bjc@spork.org> | 2025-03-10 16:08:28 -0400 |
|---|---|---|
| committer | Brian Cully <bjc@spork.org> | 2025-03-10 16:08:28 -0400 |
| commit | e4270f343a54129ab505edddf92724d310224c9c (patch) | |
| tree | 380b1ad6710ba187036828f1cbea5df029c8464a /fretboard.mjs | |
| parent | e0142eb8ea95f98bd636e54e6905e3c47ace5b68 (diff) | |
| download | chords-e4270f343a54129ab505edddf92724d310224c9c.tar.gz chords-e4270f343a54129ab505edddf92724d310224c9c.zip | |
fretboard: use Note for normalization
Diffstat (limited to 'fretboard.mjs')
| -rw-r--r-- | fretboard.mjs | 26 |
1 files changed, 4 insertions, 22 deletions
diff --git a/fretboard.mjs b/fretboard.mjs index d1d0766..6d92813 100644 --- a/fretboard.mjs +++ b/fretboard.mjs @@ -1,4 +1,4 @@ -import { chromaticScale } from "./scale.mjs"; +import { Note } from "./scale.mjs"; // open string notes, starting from the deepest string. const strings = { @@ -10,24 +10,6 @@ const strings = { string6: 'E' }; -// true if not a natural note -function isAccidental(note) { - return note[1] === '♯' || note[1] === '♭'; -} - -// convert ‘E♭’ to ‘D♯’ and vice versa. -function alternateAccidental(note) { - const root = chromaticScale.indexOf(note[0]); - switch (note[1]) { - case '♯': - return `${chromaticScale[root+2]}♭`; - case '♭': - return `${chromaticScale[root-1]}♯`; - default: - return note; - } -} - // convert ‘fret2’ to Number(2) function fretToNote(form, stringName, fretName) { const string = strings[stringName]; @@ -47,9 +29,9 @@ function formChanged(form) { form.querySelectorAll('tbody .selected').forEach(elt => { const string = elt.parentNode.className; const val = formData.get(string); - const note = fretToNote(form, string, val) || ''; - if (isAccidental(note)) { - elt.innerText = `${note} / ${alternateAccidental(note)}`; + const note = Note.fromString(fretToNote(form, string, val)); + if (note.isSharp) { + elt.innerText = `${note} / ${note.toAlternateString()}`; } else { elt.innerText = note; } |
