Skip to content

Commit dac8b0e

Browse files
committed
Fix desync on bpm change
1 parent 69113d7 commit dac8b0e

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

index.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,10 @@ <h3>Examples</h3>
285285

286286
<div class="container">
287287
<h2>Version history</h2>
288+
<p>
289+
v1.9c<br>
290+
Fixed an issue where tempo changes could desync
291+
</p>
288292
<p>
289293
v1.9b<br>
290294
Fixed an issue where tempo changes were applied at the wrong time

src/midiToNotes.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ const MidiToNotes = (function () {
8888
const bType = getEventType(b);
8989

9090
// Tempo change events
91-
if (aType === "meta" && a.metaType == 81) aPriority = 2;
92-
if (bType === "meta" && b.metaType == 81) bPriority = 2;
91+
if (aType === "meta" && a.metaType === 81) aPriority = 2;
92+
if (bType === "meta" && b.metaType === 81) bPriority = 2;
9393

9494
if (
9595
(aType === "noteOn" || aType === "noteOff") &&
@@ -112,6 +112,10 @@ const MidiToNotes = (function () {
112112
return bPriority - aPriority;
113113
});
114114

115+
for (let i = 1; i < allMidiEvents.length; i++) {
116+
allMidiEvents[i].deltaTime = allMidiEvents[i].time - allMidiEvents[i-1].time;
117+
}
118+
115119
return allMidiEvents;
116120
}
117121

0 commit comments

Comments
 (0)