From 643d2cebe51068f1fe837651bc1538f99ce557c5 Mon Sep 17 00:00:00 2001 From: Dominique Loiseau <5888729+domi7777@users.noreply.github.com> Date: Fri, 4 Oct 2024 16:18:48 +0200 Subject: [PATCH] fix(loop): add stop time at end of loop to avoid playing next loop too early --- src/scenes/KitScene.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/scenes/KitScene.ts b/src/scenes/KitScene.ts index 4d22efb..a6eae10 100644 --- a/src/scenes/KitScene.ts +++ b/src/scenes/KitScene.ts @@ -11,7 +11,7 @@ let isRecording = false; let startRecordingTime = 0; type LoopEntry = { - instrument: Instrument, + instrument: Instrument | null, time: number, } let loop: LoopEntry[] = []; @@ -27,6 +27,10 @@ function startRecording() { function stopRecording() { isRecording = false; + loop.push({ + instrument: null, + time: Date.now() - startRecordingTime + }); console.log('Recording stopped'); } @@ -39,7 +43,7 @@ function startPlaying() { const previousTime = currentLoopIndex === 0 ? 0 : loop[currentLoopIndex - 1].time; loopTimeout = setTimeout(() => { console.log(`Playing ${instrument} after ${time}ms`); - playInstrument(instrument); + instrument && playInstrument(instrument); currentLoopIndex++; playLoop(); }, time - previousTime);