Fix delay issue by moving things from TransportProcessor
This commit is contained in:
@ -9,8 +9,6 @@ class TransportProcessor extends AudioWorkletProcessor {
|
||||
this.bpm = 120;
|
||||
this.ppqn = 48;
|
||||
this.currentPulsePosition = 0;
|
||||
this.totalPausedTime = 0;
|
||||
this.lastPauseTime = null;
|
||||
}
|
||||
|
||||
handleMessage = (message) => {
|
||||
@ -18,18 +16,8 @@ class TransportProcessor extends AudioWorkletProcessor {
|
||||
this.port.postMessage(message.data);
|
||||
} else if (message.data.type === "start") {
|
||||
this.started = true;
|
||||
this.lastPlayPressTime = currentTime;
|
||||
this.totalPausedTime = 0;
|
||||
|
||||
} else if (message.data.type === "resume") {
|
||||
this.started = true;
|
||||
if (this.lastPauseTime !== null) {
|
||||
this.totalPausedTime += currentTime - this.lastPauseTime;
|
||||
this.lastPauseTime = null;
|
||||
}
|
||||
} else if (message.data.type === "pause") {
|
||||
this.started = false;
|
||||
this.lastPauseTime = currentTime;
|
||||
} else if (message.data.type === "stop") {
|
||||
this.started = false;
|
||||
} else if (message.data.type === 'bpm') {
|
||||
@ -40,7 +28,6 @@ class TransportProcessor extends AudioWorkletProcessor {
|
||||
} else if (message.data.type === 'nudge') {
|
||||
this.nudge = message.data.value;
|
||||
}
|
||||
console.log("Message delay: ", currentTime - message.data.sentAt);
|
||||
}
|
||||
|
||||
process(inputs, outputs, parameters) {
|
||||
@ -48,13 +35,9 @@ class TransportProcessor extends AudioWorkletProcessor {
|
||||
const adjustedCurrentTime = currentTime + (this.nudge / 100);
|
||||
const beatNumber = adjustedCurrentTime / (60 / this.bpm);
|
||||
const currentPulsePosition = Math.ceil(beatNumber * this.ppqn);
|
||||
const elapsedTime = (currentTime - this.lastPlayPressTime) - this.totalPausedTime;
|
||||
this.port.postMessage({ type: "elapsed", value: elapsedTime });
|
||||
if (currentPulsePosition > this.currentPulsePosition) {
|
||||
this.currentPulsePosition = currentPulsePosition;
|
||||
this.port.postMessage({ type: "bang", bpm: this.bpm });
|
||||
} else {
|
||||
console.log("No bang", currentPulsePosition, this.currentPulsePosition);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user