Handle messages separately

This commit is contained in:
2023-10-27 15:00:39 +03:00
parent 34b4c1c114
commit 53deb74700

View File

@ -12,23 +12,24 @@ export class TransportNode extends AudioWorkletNode {
/** @type {(this: MessagePort, ev: MessageEvent<any>) => any} */ /** @type {(this: MessagePort, ev: MessageEvent<any>) => any} */
handleMessage = (message) => { handleMessage = (message) => {
if (message.data && message.data.type === "elapsed") { if(message.data) {
this.app.clock.elapsed = message.data.value if (message.data.type === "elapsed") {
} this.app.clock.elapsed = message.data.value
if (message.data && message.data.type === "bang") { } else if (message.data.type === "bang") {
if (this.app.settings.send_clock) if (this.app.settings.send_clock)
this.app.api.MidiConnection.sendMidiClock(); this.app.api.MidiConnection.sendMidiClock();
this.app.clock.tick++; this.app.clock.tick++;
const futureTimeStamp = this.app.clock.convertTicksToTimeposition( const futureTimeStamp = this.app.clock.convertTicksToTimeposition(
this.app.clock.tick this.app.clock.tick
); );
this.app.clock.time_position = futureTimeStamp; this.app.clock.time_position = futureTimeStamp;
this.timeviewer.innerHTML = `${zeroPad(futureTimeStamp.bar, 2)}:${futureTimeStamp.beat + 1 this.timeviewer.innerHTML = `${zeroPad(futureTimeStamp.bar, 2)}:${futureTimeStamp.beat + 1
}:${zeroPad(futureTimeStamp.pulse, 2)} / ${this.app.clock.bpm}`; }:${zeroPad(futureTimeStamp.pulse, 2)} / ${this.app.clock.bpm}`;
if (this.app.exampleIsPlaying) { if (this.app.exampleIsPlaying) {
tryEvaluate(this.app, this.app.example_buffer); tryEvaluate(this.app, this.app.example_buffer);
} else { } else {
tryEvaluate(this.app, this.app.global_buffer); tryEvaluate(this.app, this.app.global_buffer);
}
} }
} }
}; };