Skip to content

Commit

Permalink
fix: clear schedule after stop
Browse files Browse the repository at this point in the history
  • Loading branch information
threedalpeng committed Feb 20, 2024
1 parent b974c2d commit 9b13b39
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 5 deletions.
10 changes: 8 additions & 2 deletions src/lib/device/metronome/metronome.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ class Metronome {
this.#isRunning = false;
this.timer.stop();
if (this.#stopScheduling) this.#stopScheduling();
this.clearSchedule();
this.#currentBeat = 0;
this.#currentBeatInAudioTick = 0;
this.#barPassed = 0;
Expand Down Expand Up @@ -168,10 +169,15 @@ class Metronome {
this.#onOptionChangeCallbacks.delete(cb);
}

destroy() {
this.stop();
clearSchedule() {
this.timer.clearSchedule();
this.#onBeatCallbacks.clear();
this.#onBarCallbacks.clear();
}

destroy() {
this.stop();
this.clearSchedule();
this.#onOptionChangeCallbacks.clear();
}
}
Expand Down
9 changes: 7 additions & 2 deletions src/lib/timer/tick.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ export class AudioClockTimer {
node.start(0);
}
if (!this.#isRunning) {
this.#startCallbacks.forEach((cb) => cb());
this.#isRunning = true;
// delay initial lookhead
this.#nextTick = this.audioCtx.currentTime + 0.1;
this.lookaheadTimer.postMessage('start');
this.#startCallbacks.forEach((cb) => cb());
this.#tickPassed = 0;
}
}
Expand Down Expand Up @@ -144,10 +144,15 @@ export class AudioClockTimer {
}
}

clearSchedule() {
this.#audioTickCallbacks.clear();
this.#tickCallbacks.clear();
}

destroy() {
this.stop();
this.#audioTickCallbacks.clear();
this.#tickCallbacks.clear();
this.stop();
}
}

Expand Down
104 changes: 103 additions & 1 deletion src/routes/tools/render-sample/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,112 @@ const practices: Record<string, Practice> = {
}
}
]
},
'rhythm-test': {
tempo: {
bpm: 120,
beatPerBar: 4,
signatureUnit: 4
},
guitar: {
tuning: TUNE.standard
},
scores: [
{
positions: [
{ line: 5, fret: 3 },
{ line: 6, fret: 3 },
{ line: 1, fret: 'open' },
{ line: 2, fret: 1 },
{ line: 3, fret: 'open' }
],
notes: [
{ position: 0, time: { start: 0, duration: 1 / 4 } },
{ position: 2, time: { start: 1 / 4, duration: 1 / 4 } },
{ position: 3, time: { start: 1 / 4, duration: 1 / 4 } },
{ position: 4, time: { start: 1 / 4, duration: 1 / 4 } },
{ position: 1, time: { start: 2 / 4, duration: 1 / 4 } },
{ position: 2, time: { start: 3 / 4, duration: 1 / 4 } },
{ position: 3, time: { start: 3 / 4, duration: 1 / 4 } },
{ position: 4, time: { start: 3 / 4, duration: 1 / 4 } },
{ position: 0, time: { start: 4 / 4, duration: 1 / 4 } },
{ position: 2, time: { start: 5 / 4, duration: 1 / 4 } },
{ position: 3, time: { start: 5 / 4, duration: 1 / 4 } },
{ position: 4, time: { start: 5 / 4, duration: 1 / 4 } },
{ position: 1, time: { start: 6 / 4, duration: 1 / 4 } },
{ position: 2, time: { start: 7 / 4, duration: 1 / 4 } },
{ position: 3, time: { start: 7 / 4, duration: 1 / 4 } },
{ position: 4, time: { start: 7 / 4, duration: 1 / 4 } },
{ position: 0, time: { start: 8 / 4, duration: 1 / 4 } },
{ position: 2, time: { start: 9 / 4, duration: 1 / 4 } },
{ position: 3, time: { start: 9 / 4, duration: 1 / 4 } },
{ position: 4, time: { start: 9 / 4, duration: 1 / 4 } },
{ position: 1, time: { start: 10 / 4, duration: 1 / 4 } },
{ position: 2, time: { start: 11 / 4, duration: 1 / 4 } },
{ position: 3, time: { start: 11 / 4, duration: 1 / 4 } },
{ position: 4, time: { start: 11 / 4, duration: 1 / 4 } },
{ position: 0, time: { start: 12 / 4, duration: 1 / 4 } },
{ position: 2, time: { start: 13 / 4, duration: 1 / 4 } },
{ position: 3, time: { start: 13 / 4, duration: 1 / 4 } },
{ position: 4, time: { start: 13 / 4, duration: 1 / 4 } },
{ position: 1, time: { start: 14 / 4, duration: 1 / 4 } },
{ position: 2, time: { start: 15 / 4, duration: 1 / 4 } },
{ position: 3, time: { start: 15 / 4, duration: 1 / 4 } },
{ position: 4, time: { start: 15 / 4, duration: 1 / 4 } }
],
boards: [
{
title: 'C line 1',
fingers: [0, 2, 3, 4],
time: { start: 0 }
},
{
title: 'C line 1',
fingers: [1, 2, 3, 4],
time: { start: 1 / 2 }
},
{
title: 'C line 1',
fingers: [0, 2, 3, 4],
time: { start: 2 / 2 }
},
{
title: 'C line 1',
fingers: [1, 2, 3, 4],
time: { start: 3 / 2 }
},
{
title: 'C line 1',
fingers: [0, 2, 3, 4],
time: { start: 4 / 2 }
},
{
title: 'C line 1',
fingers: [1, 2, 3, 4],
time: { start: 5 / 2 }
},
{
title: 'C line 1',
fingers: [0, 2, 3, 4],
time: { start: 6 / 2 }
},
{
title: 'C line 1',
fingers: [1, 2, 3, 4],
time: { start: 7 / 2 }
}
],
fretRange: {
start: 0,
end: 12,
visibility: 'all'
}
}
]
}
};

export const practice: Practice = practices['major-scale'];
export const practice: Practice = practices['rhythm-test'];

export const items = [
{
Expand Down

0 comments on commit 9b13b39

Please sign in to comment.