Skip to content

Commit

Permalink
fix(loop): add stop time at end of loop to avoid playing next loop to…
Browse files Browse the repository at this point in the history
…o early
  • Loading branch information
domi7777 committed Oct 4, 2024
1 parent c7dd878 commit 643d2ce
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/scenes/KitScene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ let isRecording = false;
let startRecordingTime = 0;

type LoopEntry = {
instrument: Instrument,
instrument: Instrument | null,
time: number,
}
let loop: LoopEntry[] = [];
Expand All @@ -27,6 +27,10 @@ function startRecording() {

function stopRecording() {
isRecording = false;
loop.push({
instrument: null,
time: Date.now() - startRecordingTime
});
console.log('Recording stopped');
}

Expand All @@ -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);
Expand Down

0 comments on commit 643d2ce

Please sign in to comment.