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:
@@ -22,7 +22,33 @@ export class SynthesisEngine {
|
|||||||
setupLayers(assignments: RoleAssignment[]): void {
|
setupLayers(assignments: RoleAssignment[]): void {
|
||||||
// Clean up existing layers
|
// Clean up existing layers
|
||||||
this.cleanupLayers();
|
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
|
// Store role assignments and create layers
|
||||||
for (const assignment of assignments) {
|
for (const assignment of assignments) {
|
||||||
const layer = this.createSynthLayer(assignment.role);
|
const layer = this.createSynthLayer(assignment.role);
|
||||||
@@ -30,7 +56,7 @@ export class SynthesisEngine {
|
|||||||
this.roleAssignments.set(assignment.role, assignment);
|
this.roleAssignments.set(assignment.role, assignment);
|
||||||
this.nextEventIndex.set(assignment.role, 0);
|
this.nextEventIndex.set(assignment.role, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('Setup layers for roles:', Array.from(this.roleAssignments.keys()));
|
console.log('Setup layers for roles:', Array.from(this.roleAssignments.keys()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user