From edeab7dd3dfc3a903d5ef1f86becd613321cdcf2 Mon Sep 17 00:00:00 2001 From: Gabe Serna Date: Tue, 22 Oct 2024 17:03:42 -0400 Subject: [PATCH] temporarily link midi display and audio --- app/audio/preview/page.tsx | 19 ++++++++++++++----- components/PianoRoll.tsx | 9 +++++++-- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/app/audio/preview/page.tsx b/app/audio/preview/page.tsx index a5c142a..7aa96f6 100644 --- a/app/audio/preview/page.tsx +++ b/app/audio/preview/page.tsx @@ -7,9 +7,10 @@ import MinimapPlugin from "wavesurfer.js/dist/plugins/minimap"; export default function Preview() { const containerRef = useRef(null); + const [isPlaying, setIsPlaying] = useState(false); const [midiFile, setMidiFile] = useState(null); - const { wavesurfer, isReady, isPlaying, currentTime } = useWavesurfer({ + const { wavesurfer, isReady, currentTime } = useWavesurfer({ container: containerRef, url: "/audio/tsubasa_bass.mp3", waveColor: "#eab308", @@ -47,15 +48,17 @@ export default function Preview() { } }, [isReady, wavesurfer]); - const onPlayPause = () => { + useEffect(() => { wavesurfer && wavesurfer.playPause(); - }; + }, [isPlaying]); return (
- +
- {midiFile && }{" "} + {midiFile && ( + + )}
); diff --git a/components/PianoRoll.tsx b/components/PianoRoll.tsx index c2c349b..6975e80 100644 --- a/components/PianoRoll.tsx +++ b/components/PianoRoll.tsx @@ -6,6 +6,8 @@ import { Midi } from "@tonejs/midi"; interface PianoRollProps { midiFile: Blob; // Accepting the MIDI file as a Blob prop + isPlaying: boolean; + setIsPlaying: (isPlaying: boolean) => void; } interface MidiNote { @@ -14,10 +16,13 @@ interface MidiNote { duration: number; } -const PianoRoll: React.FC = ({ midiFile }) => { +const PianoRoll: React.FC = ({ + midiFile, + isPlaying, + setIsPlaying, +}) => { const canvasRef = useRef(null); const [midiData, setMidiData] = useState([]); - const [isPlaying, setIsPlaying] = useState(false); const [progress, setProgress] = useState(0); // Track progress of MIDI playback useEffect(() => {