fixed strToKey issue when discarding the accidental part of the string
This commit is contained in:
@@ -99,6 +99,7 @@ const Octave = (props: OctaveProps) => {
|
|||||||
const isHighlighted = highlightedKey !== undefined;
|
const isHighlighted = highlightedKey !== undefined;
|
||||||
const highlightColor =
|
const highlightColor =
|
||||||
highlightedKey?.bgColor ?? defaultHighlightColor;
|
highlightedKey?.bgColor ?? defaultHighlightColor;
|
||||||
|
console.log(key, highlightedNotes, highlightedKey, isHighlighted, highlightColor);
|
||||||
return (
|
return (
|
||||||
<PianoKeyComp
|
<PianoKeyComp
|
||||||
key={i}
|
key={i}
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ import {
|
|||||||
NoteNameBehavior,
|
NoteNameBehavior,
|
||||||
KeyPressStyle,
|
KeyPressStyle,
|
||||||
keyToStr,
|
keyToStr,
|
||||||
|
strToKey,
|
||||||
|
HighlightedKey,
|
||||||
} from "../../models/Piano";
|
} from "../../models/Piano";
|
||||||
|
|
||||||
type VirtualPianoProps = Parameters<typeof Row>[0] & {
|
type VirtualPianoProps = Parameters<typeof Row>[0] & {
|
||||||
@@ -17,10 +19,8 @@ type VirtualPianoProps = Parameters<typeof Row>[0] & {
|
|||||||
endOctave: number;
|
endOctave: number;
|
||||||
endNote: Note;
|
endNote: Note;
|
||||||
showNoteNames: NoteNameBehavior; // default "onpress"
|
showNoteNames: NoteNameBehavior; // default "onpress"
|
||||||
highlightedNotes: Array<PianoKey | string>;
|
highlightedNotes: Array<HighlightedKey>;
|
||||||
highlightColor: string;
|
highlightColor: string;
|
||||||
specialHighlightedNotes: Array<PianoKey | string>;
|
|
||||||
specialHighlightColor: string;
|
|
||||||
showOctaveNumbers: boolean;
|
showOctaveNumbers: boolean;
|
||||||
keyPressStyle: KeyPressStyle;
|
keyPressStyle: KeyPressStyle;
|
||||||
vividKeyPressColor: string;
|
vividKeyPressColor: string;
|
||||||
@@ -36,8 +36,6 @@ const VirtualPiano = ({
|
|||||||
showNoteNames,
|
showNoteNames,
|
||||||
highlightedNotes,
|
highlightedNotes,
|
||||||
highlightColor,
|
highlightColor,
|
||||||
specialHighlightedNotes,
|
|
||||||
specialHighlightColor,
|
|
||||||
showOctaveNumbers,
|
showOctaveNumbers,
|
||||||
keyPressStyle,
|
keyPressStyle,
|
||||||
vividKeyPressColor,
|
vividKeyPressColor,
|
||||||
@@ -94,10 +92,8 @@ VirtualPiano.defaultProps = {
|
|||||||
endOctave: 2,
|
endOctave: 2,
|
||||||
endNote: Note.B,
|
endNote: Note.B,
|
||||||
showNoteNames: NoteNameBehavior.onpress,
|
showNoteNames: NoteNameBehavior.onpress,
|
||||||
highlightedNotes: [{ key: Note.D }, { key: Note.G, bgColor: "blue" }],
|
highlightedNotes: [{ key: strToKey("D") }, { key: strToKey("A#"), bgColor: "#00FF00" }],
|
||||||
highlightColor: "red",
|
highlightColor: "red",
|
||||||
specialHighlightedNotes: [Note.D, Note.G],
|
|
||||||
specialHighlightColor: "blue",
|
|
||||||
showOctaveNumbers: true,
|
showOctaveNumbers: true,
|
||||||
keyPressStyle: "subtle",
|
keyPressStyle: "subtle",
|
||||||
vividKeyPressColor: "red",
|
vividKeyPressColor: "red",
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ export class PianoKey {
|
|||||||
|
|
||||||
export const strToKey = (str: string): PianoKey => {
|
export const strToKey = (str: string): PianoKey => {
|
||||||
let note: Note;
|
let note: Note;
|
||||||
switch (str[0]) {
|
switch (str.substring(0, 2)) {
|
||||||
case "C":
|
case "C":
|
||||||
note = Note.C;
|
note = Note.C;
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user