Skip to content

Commit

Permalink
fix: midi piano missing csound instance
Browse files Browse the repository at this point in the history
  • Loading branch information
hlolli committed Mar 2, 2024
1 parent 006ce37 commit 771bc03
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/elements/midi-piano.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import React from "react";
import { Piano, KeyboardShortcuts, MidiNumbers } from "react-piano";
import { ICsoundStatus } from "@comp/csound/types";
import { CsoundObj } from "@csound/browser";
import { useSelector } from "react-redux";
import { path, pathOr } from "ramda";
import { pathOr } from "ramda";
import { csoundInstance } from "@comp/csound/actions";
import "react-piano/dist/styles.css";

const MidiPiano = (): React.ReactElement => {
const firstNote = MidiNumbers.fromNote("c3");
const lastNote = MidiNumbers.fromNote("f5");
const csound: CsoundObj | undefined = useSelector(
path(["csound", "csound"])
);
const csound = csoundInstance;

const csoundStatus: ICsoundStatus = useSelector(
pathOr("stopped", ["csound", "status"])
) as ICsoundStatus;

console.log("csoundStatus", csoundStatus);

const keyboardShortcuts = KeyboardShortcuts.create({
firstNote: firstNote,
lastNote: lastNote,
Expand All @@ -26,13 +26,13 @@ const MidiPiano = (): React.ReactElement => {
return (
<Piano
noteRange={{ first: firstNote, last: lastNote }}
playNote={(midiNumber) => {
playNote={(midiNumber: number) => {
// TODO make velocity configureable
if (csound && csoundStatus === "playing") {
csound.midiMessage(144, midiNumber, 64);
}
}}
stopNote={(midiNumber) => {
stopNote={(midiNumber: number) => {
if (csound && csoundStatus === "playing") {
csound.midiMessage(128, midiNumber, 64);
}
Expand Down

0 comments on commit 771bc03

Please sign in to comment.