Add logical time to transportprocessor
This commit is contained in:
@ -4,7 +4,11 @@ class TransportProcessor extends AudioWorkletProcessor {
|
||||
super(options);
|
||||
this.port.addEventListener("message", this.handleMessage);
|
||||
this.port.start();
|
||||
this.stated = false;
|
||||
this.started = false;
|
||||
this.totalPausedTime = 0;
|
||||
this.lastPausedTime = 0;
|
||||
this.startedAgainTime = 0;
|
||||
this.wasStopped = false;
|
||||
}
|
||||
|
||||
handleMessage = (message) => {
|
||||
@ -14,14 +18,33 @@ class TransportProcessor extends AudioWorkletProcessor {
|
||||
this.started = true;
|
||||
} else if (message.data === "pause") {
|
||||
this.started = false;
|
||||
if(this.lastPausedTime === 0) {
|
||||
this.lastPausedTime = currentTime;
|
||||
}
|
||||
} else if (message.data === "stop") {
|
||||
this.started = false;
|
||||
this.currentTime = 0;
|
||||
this.totalPausedTime = 0;
|
||||
this.lastPausedTime = 0;
|
||||
this.startedAgainTime = 0;
|
||||
this.wasStopped = true;
|
||||
}
|
||||
};
|
||||
|
||||
process(inputs, outputs, parameters) {
|
||||
if (this.started) this.port.postMessage({ type: "bang", currentTime });
|
||||
if (this.started) {
|
||||
if(this.lastPausedTime>0) {
|
||||
const pausedTime = currentTime-this.lastPausedTime;
|
||||
this.totalPausedTime += pausedTime;
|
||||
this.lastPausedTime = 0;
|
||||
}
|
||||
if(this.wasStopped) {
|
||||
this.startedAgainTime = currentTime;
|
||||
this.wasStopped = false;
|
||||
}
|
||||
const logicalTime = currentTime-this.totalPausedTime-this.startedAgainTime;
|
||||
//console.log("Logical/Current:", logicalTime, currentTime);
|
||||
this.port.postMessage({ type: "bang", logicalTime });
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user