Skip to content

Commit 36fe8a0

Browse files
authored
seek block 🎉
1 parent a4d40f3 commit 36fe8a0

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

static/extensions/Gen1x/beat_sync.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,17 @@
204204
blockType: Scratch.BlockType.COMMAND,
205205
text: 'reset beat to 0'
206206
},
207+
{
208+
opcode: 'seekToBeat',
209+
blockType: Scratch.BlockType.COMMAND,
210+
text: 'seek to beat [BEAT]',
211+
arguments: {
212+
BEAT: {
213+
type: Scratch.ArgumentType.NUMBER,
214+
defaultValue: 0
215+
}
216+
}
217+
},
207218
'---',
208219
{
209220
opcode: 'waitUntilNextBeat',
@@ -392,6 +403,18 @@
392403
}
393404
}
394405

406+
seekToBeat(args) {
407+
const beat = Number(args.BEAT);
408+
const secondsPerBeat = 60 / this.bpm;
409+
this.pausedElapsed = beat * secondsPerBeat;
410+
this.totalBeats = beat;
411+
this.beatPosition = beat % 1;
412+
if (this.isRunning) {
413+
const ctx = this.getAudioCtx();
414+
this.startAudioTime = ctx.currentTime;
415+
}
416+
}
417+
395418
resetBeat() {
396419
this.pausedElapsed = 0;
397420
this.totalBeats = 0;

0 commit comments

Comments
 (0)