diff --git a/src/TransportNode.js b/src/TransportNode.js index 4366e0f..c70ce37 100644 --- a/src/TransportNode.js +++ b/src/TransportNode.js @@ -10,7 +10,6 @@ export class TransportNode extends AudioWorkletNode { this.port.start(); /** @type {HTMLSpanElement} */ this.$clock = document.getElementById("clockviewer"); - this.offset_time = 0; } /** @type {(this: MessagePort, ev: MessageEvent) => any} */ handleMessage = (message) => { @@ -31,20 +30,14 @@ export class TransportNode extends AudioWorkletNode { } convertTimeToBarsBeats(currentTime) { - // Calculate the duration of one beat in seconds const beatDuration = 60 / this.app.clock.bpm; + const beatNumber = (currentTime) / beatDuration; - // Calculate the beat number - const beatNumber = (currentTime - this.offset_time) / beatDuration; - - // Calculate the bar and beat numbers const beatsPerBar = this.app.clock.time_signature[0]; const barNumber = Math.floor(beatNumber / beatsPerBar) + 1; // Adding 1 to make it 1-indexed const beatWithinBar = Math.floor(beatNumber % beatsPerBar) + 1; // Adding 1 to make it 1-indexed - // Calculate the PPQN position const ppqnPosition = Math.floor((beatNumber % 1) * this.app.clock.ppqn); return { bar: barNumber, beat: beatWithinBar, ppqn: ppqnPosition }; -} - + } } \ No newline at end of file