@errozero/beatstepper
Advanced tools
+21
| //Web Worker as a string, removes the need to provide a url to a worker file, this dynamically creates one | ||
| const workerCode = ` | ||
| let speed = 100; | ||
| let timerID = null; | ||
| onmessage = e => { | ||
| if(e.data.speed) speed = e.data.speed; | ||
| if(e.data.message === 'start'){ | ||
| timerID = setInterval(() => {postMessage('pulse')}, speed); | ||
| } | ||
| else if(e.data.message === 'stop'){ | ||
| clearInterval(timerID); | ||
| timerID=null; | ||
| } | ||
| } | ||
| `; | ||
| const workerBlob = new Blob([workerCode], {type: 'application/javascript'}); | ||
| export default new Worker(URL.createObjectURL(workerBlob)); |
+5
-26
| //Based on article: https://html5rocks.com/en/tutorials/audio/scheduling/ | ||
| //Web Worker as a string, removes the need to provide a url to a worker file, this dynamically creates one | ||
| //https://stackoverflow.com/a/61621269/2347456 | ||
| import tempoWorker from './worker'; | ||
| const workerCode = ` | ||
| let speed = 100; | ||
| let timerID = null; | ||
| onmessage = (e) => { | ||
| //console.log('MESSAGE', e.data); | ||
| if(e.data.speed) speed = e.data.speed; | ||
| if(e.data.message === 'start'){ | ||
| timerID = setInterval(() => {postMessage('pulse')}, speed); | ||
| } | ||
| else if(e.data.message === 'stop'){ | ||
| clearInterval(timerID); | ||
| timerID=null; | ||
| } | ||
| } | ||
| `; | ||
| const workerBlob = new Blob([workerCode], {type: 'application/javascript'}) | ||
| interface IBeatstepperCallbackData { | ||
@@ -40,5 +19,5 @@ step: number, | ||
| private tempoWorker: Worker; | ||
| private scheduleAheadTime = 0.18; //How far ahead to schedule events (in seconds) | ||
| private lookAhead = 20.0; //How frequently to call scheduling (in ms) | ||
| private nextStepTime = 0; | ||
| private scheduleAheadTime = 0.18; //How far ahead to schedule events (in seconds) | ||
| private lookAhead = 20.0; //How frequently to call scheduling (in ms) | ||
| private nextStepTime = 0; | ||
| private currentStep = 0; | ||
@@ -59,3 +38,3 @@ private currentBeat = 0; | ||
| this.tempoWorker = new Worker(URL.createObjectURL(workerBlob)); | ||
| this.tempoWorker = tempoWorker; | ||
| this.tempoWorker.postMessage({speed: this.lookAhead}); | ||
@@ -62,0 +41,0 @@ this.tempoWorker.onmessage = () => {this.scheduler()}; |
+4
-4
@@ -7,3 +7,3 @@ { | ||
| }, | ||
| "version": "1.0.3", | ||
| "version": "1.0.4", | ||
| "description": "", | ||
@@ -19,6 +19,6 @@ "main": "dist/Beatstepper.js", | ||
| "keywords": [ | ||
| "webaudio", | ||
| "scheduler", | ||
| "web audio" | ||
| "webaudio", | ||
| "scheduler", | ||
| "web audio" | ||
| ] | ||
| } |
7
16.67%23852
-0.1%358
-0.28%