summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fretboard.mjs26
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;
}