@errozero/beatstepper
Advanced tools
Comparing version 1.0.3 to 1.0.4
//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()}; |
@@ -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
23852
358