File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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' ,
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 ;
You can’t perform that action at this time.
0 commit comments