From 34092f2301c814d83b2a4519ba86865a5afffa9d Mon Sep 17 00:00:00 2001 From: b1rdmania <102524336+b1rdmania@users.noreply.github.com> Date: Thu, 18 Dec 2025 21:20:28 +0000 Subject: [PATCH] Fix 10-second silence at start of Motif playback MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/synthesis/SynthesisEngine.ts | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/src/synthesis/SynthesisEngine.ts b/src/synthesis/SynthesisEngine.ts index 91d7a4e..d4eeb5f 100644 --- a/src/synthesis/SynthesisEngine.ts +++ b/src/synthesis/SynthesisEngine.ts @@ -22,7 +22,33 @@ export class SynthesisEngine { setupLayers(assignments: RoleAssignment[]): void { // 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); @@ -30,7 +56,7 @@ export class SynthesisEngine { this.roleAssignments.set(assignment.role, assignment); this.nextEventIndex.set(assignment.role, 0); } - + console.log('Setup layers for roles:', Array.from(this.roleAssignments.keys())); }