From aa72f34a6c8fe64eeae83f13362ac2f3eaeb33b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Le=20Bihan?= Date: Mon, 20 Mar 2023 00:19:36 +0100 Subject: [PATCH] fixed issue with keyToStr function --- front/components/VirtualPiano/PianoKeyComp.tsx | 2 +- front/components/VirtualPiano/VirtualPiano.tsx | 6 +++--- front/models/Piano.ts | 11 ++++------- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/front/components/VirtualPiano/PianoKeyComp.tsx b/front/components/VirtualPiano/PianoKeyComp.tsx index fe6f87f..e55e40e 100644 --- a/front/components/VirtualPiano/PianoKeyComp.tsx +++ b/front/components/VirtualPiano/PianoKeyComp.tsx @@ -86,7 +86,7 @@ const PianoKeyComp = ({ alignItems="center" > {isNoteVisible(showNoteNames, isPressed, isHovered) && ( - {keyToStr(pianoKey)} + {keyToStr(pianoKey, false)} )} )} diff --git a/front/components/VirtualPiano/VirtualPiano.tsx b/front/components/VirtualPiano/VirtualPiano.tsx index 29bef1f..9c84ab7 100644 --- a/front/components/VirtualPiano/VirtualPiano.tsx +++ b/front/components/VirtualPiano/VirtualPiano.tsx @@ -1,7 +1,7 @@ import { Row, Box } from "native-base"; import React, { useState, useEffect } from "react"; import Octave from "./Octave"; -import { Note, PianoKey, NoteNameBehavior, KeyPressStyle, octaveKeys } from "../../models/Piano"; +import { Note, PianoKey, NoteNameBehavior, KeyPressStyle, keyToStr } from "../../models/Piano"; type VirtualPianoProps = Parameters[0] & { onNoteDown: (note: PianoKey) => void; @@ -75,10 +75,10 @@ const VirtualPiano = ({ VirtualPiano.defaultProps = { onNoteDown: (n) => { - console.log("Note down: " + n); + console.log("Note down: " + keyToStr(n)); }, onNoteUp: (n) => { - console.log("Note up: " + n); + console.log("Note up: " + keyToStr(n)); }, startOctave: 2, startNote: Note.C, diff --git a/front/models/Piano.ts b/front/models/Piano.ts index ec8a199..71e4182 100644 --- a/front/models/Piano.ts +++ b/front/models/Piano.ts @@ -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;