From 53deb747001006c9083d2ed1930fa7b81b26bc83 Mon Sep 17 00:00:00 2001 From: Miika Alonen Date: Fri, 27 Oct 2023 15:00:39 +0300 Subject: [PATCH] Handle messages separately --- src/TransportNode.js | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/src/TransportNode.js b/src/TransportNode.js index db09830..83ee5ae 100644 --- a/src/TransportNode.js +++ b/src/TransportNode.js @@ -12,23 +12,24 @@ export class TransportNode extends AudioWorkletNode { /** @type {(this: MessagePort, ev: MessageEvent) => any} */ handleMessage = (message) => { - if (message.data && message.data.type === "elapsed") { - this.app.clock.elapsed = message.data.value - } - if (message.data && message.data.type === "bang") { - if (this.app.settings.send_clock) - this.app.api.MidiConnection.sendMidiClock(); - this.app.clock.tick++; - const futureTimeStamp = this.app.clock.convertTicksToTimeposition( - this.app.clock.tick - ); - this.app.clock.time_position = futureTimeStamp; - this.timeviewer.innerHTML = `${zeroPad(futureTimeStamp.bar, 2)}:${futureTimeStamp.beat + 1 - }:${zeroPad(futureTimeStamp.pulse, 2)} / ${this.app.clock.bpm}`; - if (this.app.exampleIsPlaying) { - tryEvaluate(this.app, this.app.example_buffer); - } else { - tryEvaluate(this.app, this.app.global_buffer); + if(message.data) { + if (message.data.type === "elapsed") { + this.app.clock.elapsed = message.data.value + } else if (message.data.type === "bang") { + if (this.app.settings.send_clock) + this.app.api.MidiConnection.sendMidiClock(); + this.app.clock.tick++; + const futureTimeStamp = this.app.clock.convertTicksToTimeposition( + this.app.clock.tick + ); + this.app.clock.time_position = futureTimeStamp; + this.timeviewer.innerHTML = `${zeroPad(futureTimeStamp.bar, 2)}:${futureTimeStamp.beat + 1 + }:${zeroPad(futureTimeStamp.pulse, 2)} / ${this.app.clock.bpm}`; + if (this.app.exampleIsPlaying) { + tryEvaluate(this.app, this.app.example_buffer); + } else { + tryEvaluate(this.app, this.app.global_buffer); + } } } };