Fix 10-second silence at start of Motif playback

Normalize all event times to start at 0 by finding the earliest
event across all roles and subtracting that offset. Prevents
silence when MIDI files have delayed first notes.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
b1rdmania
2025-12-18 21:20:28 +00:00
parent 7209fad127
commit 34092f2301
+26
View File
@@ -23,6 +23,32 @@ export class SynthesisEngine {
// Clean up existing layers
this.cleanupLayers();
// Find the earliest event time across all assignments
let earliestTime = Infinity;
for (const assignment of assignments) {
if (assignment.events.length > 0) {
earliestTime = Math.min(earliestTime, assignment.events[0].time);
}
if (assignment.chords.length > 0) {
earliestTime = Math.min(earliestTime, assignment.chords[0].time);
}
}
// If we found events, normalize times to start at 0
if (earliestTime !== Infinity && earliestTime > 0) {
console.log('Normalizing event times, earliest was:', earliestTime);
for (const assignment of assignments) {
// Normalize note events
for (const event of assignment.events) {
event.time -= earliestTime;
}
// Normalize chord events
for (const chord of assignment.chords) {
chord.time -= earliestTime;
}
}
}
// Store role assignments and create layers
for (const assignment of assignments) {
const layer = this.createSynthLayer(assignment.role);