summaryrefslogtreecommitdiffstats
path: root/fretboard.mjs
diff options
context:
space:
mode:
Diffstat (limited to 'fretboard.mjs')
-rw-r--r--fretboard.mjs13
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 {