From 3e3dd368c148053d8d18f7338c5da844fa5e8168 Mon Sep 17 00:00:00 2001 From: Fr0stbyteR Date: Wed, 2 Aug 2023 20:31:32 +0800 Subject: [PATCH] fix some bugs --- src/TransportNode.js | 5 +++-- src/main.ts | 16 ++++++++-------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/TransportNode.js b/src/TransportNode.js index 19a0816..bc2ee0d 100644 --- a/src/TransportNode.js +++ b/src/TransportNode.js @@ -44,7 +44,7 @@ export class TransportNode extends AudioWorkletNode { this.app.api.midi_clock(); const then = performance.now(); this.lastLatencies[this.indexOfLastLatencies] = then - now; - this.indexOfLastLatencies = (indexOfLastLatencies + 1) % this.lastLatencies.length; + this.indexOfLastLatencies = (this.indexOfLastLatencies + 1) % this.lastLatencies.length; const averageLatency = this.lastLatencies.reduce((a, b) => a + b) / this.lastLatencies.length; this.executionLatency = averageLatency / 1000; }, (timeToNextPulse + this.executionLatency) * 1000); @@ -76,6 +76,7 @@ export class TransportNode extends AudioWorkletNode { convertTimeToNextBarsBeats(currentTime) { const beatDuration = 60 / this.app.clock.bpm; const beatNumber = (currentTime) / beatDuration; + const beatsPerBar = this.app.clock.time_signature[0]; this.currentPulsePosition = beatNumber * this.app.clock.ppqn; const nextPulsePosition = Math.ceil(this.currentPulsePosition); @@ -86,7 +87,7 @@ export class TransportNode extends AudioWorkletNode { const futureTimeStamp = { bar: Math.floor(futureBarNumber) + 1, beat: Math.floor(futureBarNumber) % beatsPerBar + 1, - pulse: this.nextPulsePosition + pulse: Math.floor(this.nextPulsePosition) % this.app.clock.ppqn }; this.app.clock.tick++ return { diff --git a/src/main.ts b/src/main.ts index 114ce0f..7af22dc 100644 --- a/src/main.ts +++ b/src/main.ts @@ -679,11 +679,11 @@ document.addEventListener("keydown", startOnEnter); document.getElementById("start-button")!.addEventListener("click", startClock); // When the user leaves the page, all the universes should be saved in the localStorage -window.addEventListener("beforeunload", () => { - event.preventDefault(); - event.returnValue = ""; - // Iterate over all local files and set the candidate to the committed - app.currentFile.candidate = app.view.state.doc.toString(); - app.currentFile.committed = app.view.state.doc.toString(); - app.settings.saveApplicationToLocalStorage(app.universes, app.settings); -}); +// window.addEventListener("beforeunload", () => { +// event.preventDefault(); +// event.returnValue = ""; +// // Iterate over all local files and set the candidate to the committed +// app.currentFile.candidate = app.view.state.doc.toString(); +// app.currentFile.committed = app.view.state.doc.toString(); +// app.settings.saveApplicationToLocalStorage(app.universes, app.settings); +// });