From d094c81418a11c7634bb7b557d178dbd04b2c123 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Le=20Bihan?= Date: Mon, 20 Mar 2023 00:55:51 +0100 Subject: [PATCH] fixed strToKey issue when discarding the accidental part of the string --- front/components/VirtualPiano/Octave.tsx | 1 + front/components/VirtualPiano/VirtualPiano.tsx | 12 ++++-------- front/models/Piano.ts | 2 +- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/front/components/VirtualPiano/Octave.tsx b/front/components/VirtualPiano/Octave.tsx index 2c18796..308a6be 100644 --- a/front/components/VirtualPiano/Octave.tsx +++ b/front/components/VirtualPiano/Octave.tsx @@ -99,6 +99,7 @@ const Octave = (props: OctaveProps) => { const isHighlighted = highlightedKey !== undefined; const highlightColor = highlightedKey?.bgColor ?? defaultHighlightColor; + console.log(key, highlightedNotes, highlightedKey, isHighlighted, highlightColor); return ( [0] & { @@ -17,10 +19,8 @@ type VirtualPianoProps = Parameters[0] & { endOctave: number; endNote: Note; showNoteNames: NoteNameBehavior; // default "onpress" - highlightedNotes: Array; + highlightedNotes: Array; highlightColor: string; - specialHighlightedNotes: Array; - specialHighlightColor: string; showOctaveNumbers: boolean; keyPressStyle: KeyPressStyle; vividKeyPressColor: string; @@ -36,8 +36,6 @@ const VirtualPiano = ({ showNoteNames, highlightedNotes, highlightColor, - specialHighlightedNotes, - specialHighlightColor, showOctaveNumbers, keyPressStyle, vividKeyPressColor, @@ -94,10 +92,8 @@ VirtualPiano.defaultProps = { endOctave: 2, endNote: Note.B, showNoteNames: NoteNameBehavior.onpress, - highlightedNotes: [{ key: Note.D }, { key: Note.G, bgColor: "blue" }], + highlightedNotes: [{ key: strToKey("D") }, { key: strToKey("A#"), bgColor: "#00FF00" }], highlightColor: "red", - specialHighlightedNotes: [Note.D, Note.G], - specialHighlightColor: "blue", showOctaveNumbers: true, keyPressStyle: "subtle", vividKeyPressColor: "red", diff --git a/front/models/Piano.ts b/front/models/Piano.ts index f15d0f2..00dfec0 100644 --- a/front/models/Piano.ts +++ b/front/models/Piano.ts @@ -46,7 +46,7 @@ export class PianoKey { export const strToKey = (str: string): PianoKey => { let note: Note; - switch (str[0]) { + switch (str.substring(0, 2)) { case "C": note = Note.C; break;