fixed issue with keyToStr function
This commit is contained in:
@@ -86,7 +86,7 @@ const PianoKeyComp = ({
|
|||||||
alignItems="center"
|
alignItems="center"
|
||||||
>
|
>
|
||||||
{isNoteVisible(showNoteNames, isPressed, isHovered) && (
|
{isNoteVisible(showNoteNames, isPressed, isHovered) && (
|
||||||
<Text {...textProps}>{keyToStr(pianoKey)}</Text>
|
<Text {...textProps}>{keyToStr(pianoKey, false)}</Text>
|
||||||
)}
|
)}
|
||||||
</Box>
|
</Box>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { Row, Box } from "native-base";
|
import { Row, Box } from "native-base";
|
||||||
import React, { useState, useEffect } from "react";
|
import React, { useState, useEffect } from "react";
|
||||||
import Octave from "./Octave";
|
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<typeof Row>[0] & {
|
type VirtualPianoProps = Parameters<typeof Row>[0] & {
|
||||||
onNoteDown: (note: PianoKey) => void;
|
onNoteDown: (note: PianoKey) => void;
|
||||||
@@ -75,10 +75,10 @@ const VirtualPiano = ({
|
|||||||
|
|
||||||
VirtualPiano.defaultProps = {
|
VirtualPiano.defaultProps = {
|
||||||
onNoteDown: (n) => {
|
onNoteDown: (n) => {
|
||||||
console.log("Note down: " + n);
|
console.log("Note down: " + keyToStr(n));
|
||||||
},
|
},
|
||||||
onNoteUp: (n) => {
|
onNoteUp: (n) => {
|
||||||
console.log("Note up: " + n);
|
console.log("Note up: " + keyToStr(n));
|
||||||
},
|
},
|
||||||
startOctave: 2,
|
startOctave: 2,
|
||||||
startNote: Note.C,
|
startNote: Note.C,
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ export const strToKey = (str: string): PianoKey => {
|
|||||||
return new PianoKey(note, accidental, octave);
|
return new PianoKey(note, accidental, octave);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const keyToStr = (key: PianoKey): string => {
|
export const keyToStr = (key: PianoKey, showOctave: boolean = true): string => {
|
||||||
let s = "";
|
let s = "";
|
||||||
switch (key.note) {
|
switch (key.note) {
|
||||||
case Note.C: s += "C"; break;
|
case Note.C: s += "C"; break;
|
||||||
@@ -89,15 +89,12 @@ export const keyToStr = (key: PianoKey): string => {
|
|||||||
case Note.A: s += "A"; break;
|
case Note.A: s += "A"; break;
|
||||||
case Note.B: s += "B"; break;
|
case Note.B: s += "B"; break;
|
||||||
}
|
}
|
||||||
if (key.accidental) {
|
if (key.accidental !== undefined) {
|
||||||
switch (key.accidental) {
|
switch (key.accidental) {
|
||||||
case Accidental["#"]: s += "#"; break;
|
default: s += "#"; break;
|
||||||
case Accidental["b"]: s += "b"; break;
|
|
||||||
case Accidental["##"]: s += "x"; break;
|
|
||||||
case Accidental["bb"]: s += "n"; break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (key.octave) {
|
if (showOctave && key.octave) {
|
||||||
s += key.octave;
|
s += key.octave;
|
||||||
}
|
}
|
||||||
return s;
|
return s;
|
||||||
|
|||||||
Reference in New Issue
Block a user