diff options
| author | Brian Cully <bjc@spork.org> | 2025-03-10 15:43:48 -0400 |
|---|---|---|
| committer | Brian Cully <bjc@spork.org> | 2025-03-10 15:43:48 -0400 |
| commit | e0142eb8ea95f98bd636e54e6905e3c47ace5b68 (patch) | |
| tree | 50454dd604781cb0aa66af99d5e5a9aa36846909 | |
| parent | 21df494a6d39f78831fefdbbe78e306fdd3ebb64 (diff) | |
| download | chords-e0142eb8ea95f98bd636e54e6905e3c47ace5b68.tar.gz chords-e0142eb8ea95f98bd636e54e6905e3c47ace5b68.zip | |
fretboard: calculate selected note from x-data-note
| -rw-r--r-- | fretboard.mjs | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/fretboard.mjs b/fretboard.mjs index 4f5344e..d1d0766 100644 --- a/fretboard.mjs +++ b/fretboard.mjs @@ -29,26 +29,25 @@ function alternateAccidental(note) { } // convert ‘fret2’ to Number(2) -function fretToNote(stringName, fretName) { +function fretToNote(form, stringName, fretName) { const string = strings[stringName]; if (!string) { return null; } if (!fretName?.startsWith('fret')) { - return string; + return form.querySelector(`.${stringName} .open`).getAttribute("x-data-note"); } - const root = chromaticScale.indexOf(string) - const fret = Number(fretName.substring(4)); - return chromaticScale[root+fret]; + return form.querySelector(`.${stringName} [value="${fretName}"]`).parentNode.getAttribute("x-data-note"); } function formChanged(form) { const formData = new FormData(form); form.querySelectorAll('tbody .selected').forEach(elt => { - const val = formData.get(elt.parentNode.className) - const note = fretToNote(elt.parentNode.className, val) || ''; + const string = elt.parentNode.className; + const val = formData.get(string); + const note = fretToNote(form, string, val) || ''; if (isAccidental(note)) { elt.innerText = `${note} / ${alternateAccidental(note)}`; } else { |
