use awp as time reference at max precision

This commit is contained in:
Fr0stbyteR
2023-07-29 00:00:57 +08:00
parent 2e1c0947b5
commit cf3428b3c3
2 changed files with 14 additions and 12 deletions

View File

@ -13,8 +13,8 @@ export class TransportNode extends AudioWorkletNode {
}
/** @type {(this: MessagePort, ev: MessageEvent<any>) => any} */
handleMessage = (message) => {
if (message.data === "bang") {
let info = this.convertTimeToBarsBeats(this.context.currentTime);
if (message.data && message.data.type === "bang") {
let info = this.convertTimeToBarsBeats(message.data.currentTime);
this.app.clock.time_position = { bar: info.bar, beat: info.beat, pulse: info.ppqn }
this.$clock.innerHTML = `[${info.bar} | ${info.beat} | ${zeroPad(info.ppqn, '2')}]`
tryEvaluate( this.app, this.app.global_buffer );

View File

@ -4,29 +4,31 @@ class TransportProcessor extends AudioWorkletProcessor {
super(options);
this.port.addEventListener("message", this.handleMessage);
this.port.start();
this.stated = false;
/*
this.interval = 0.0001;
this.origin = currentTime;
this.next = this.origin + this.interval;
*/
}
handleMessage = (message) => {
if (message.data === "start") {
this.origin = currentTime;
this.next = this.origin + this.interval;
this.started = true;
// this.origin = currentTime;
// this.next = this.origin + this.interval;
} else if (message.data === "pause") {
this.next = Infinity;
// this.next = Infinity;
this.started = false;
} else if (message.data === "stop") {
this.origin = currentTime;
this.next = Infinity;
// this.origin = currentTime;
// this.next = Infinity;
this.started = false;
}
};
process(inputs, outputs, parameters) {
if (currentTime >= this.next) {
while (this.next < currentTime)
this.next += this.interval;
this.port.postMessage("bang");
}
if (this.started) this.port.postMessage({ type: "bang", currentTime });
return true;
}
}