fixed issue with keyToStr function

This commit is contained in:
Clément Le Bihan
2023-03-20 00:19:36 +01:00
parent efede253dc
commit aa72f34a6c
3 changed files with 8 additions and 11 deletions
+4 -7
View File
@@ -78,7 +78,7 @@ export const strToKey = (str: string): PianoKey => {
return new PianoKey(note, accidental, octave);
};
export const keyToStr = (key: PianoKey): string => {
export const keyToStr = (key: PianoKey, showOctave: boolean = true): string => {
let s = "";
switch (key.note) {
case Note.C: s += "C"; break;
@@ -89,15 +89,12 @@ export const keyToStr = (key: PianoKey): string => {
case Note.A: s += "A"; break;
case Note.B: s += "B"; break;
}
if (key.accidental) {
if (key.accidental !== undefined) {
switch (key.accidental) {
case Accidental["#"]: s += "#"; break;
case Accidental["b"]: s += "b"; break;
case Accidental["##"]: s += "x"; break;
case Accidental["bb"]: s += "n"; break;
default: s += "#"; break;
}
}
if (key.octave) {
if (showOctave && key.octave) {
s += key.octave;
}
return s;