Skip to content

Commit 2e15bad

Browse files
committed
Fixed bug where overlapping notes of the same pitch were being incorrectly overwritten during MIDI upload
1 parent b8881cc commit 2e15bad

1 file changed

Lines changed: 6 additions & 7 deletions

File tree

build/midi-upload.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,14 @@ document.getElementById("midiFile").addEventListener("change", async (e) => {
9999
const active = {};
100100
track.events.forEach(ev => {
101101
if (ev.type === "on") {
102-
if (active[ev.pitch] == null) {
103-
active[ev.pitch] = ev.time;
104-
}
105-
} else if (ev.type === "off" && active[ev.pitch] != null) {
106-
const dur = ev.time - active[ev.pitch];
102+
if (!active[ev.pitch]) active[ev.pitch] = [];
103+
active[ev.pitch].push(ev.time); // Stack multiple starts
104+
} else if (ev.type === "off" && active[ev.pitch] && active[ev.pitch].length > 0) {
105+
const startTime = active[ev.pitch].shift(); // Take earliest start
106+
const dur = ev.time - startTime;
107107
if (dur > 0) {
108-
allNotes.push({ start: active[ev.pitch], dur, pitch: ev.pitch, hand });
108+
allNotes.push({ start: startTime, dur, pitch: ev.pitch, hand });
109109
}
110-
delete active[ev.pitch];
111110
}
112111
});
113112
});

0 commit comments

Comments
 (0)