From e4270f343a54129ab505edddf92724d310224c9c Mon Sep 17 00:00:00 2001 From: Brian Cully Date: Mon, 10 Mar 2025 16:08:28 -0400 Subject: fretboard: use Note for normalization --- fretboard.mjs | 26 ++++---------------------- 1 file 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; } -- cgit v1.3