Skip to content

Commit

Permalink
fix(DmPerformance): properly move forward messages when looping a seg…
Browse files Browse the repository at this point in the history
…ment to avoid silences
  • Loading branch information
lmichaelis committed Apr 29, 2024
1 parent df02187 commit e644513
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Performance.c
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,11 @@ static void DmPerformance_handleMessage(DmPerformance* slf, DmMessage* msg) {
"DmPerformance: MESSAGE time=%d msg=segment-change segment=\"%s\"",
slf->time,
msg->segment.segment->info.unam);
Dm_report(DmLogLevel_DEBUG,
"DmPerformance: Playing segment \"%s\" (repeat %d/%d)",
msg->segment.segment->info.unam,
msg->segment.loop + 1,
msg->segment.segment->repeats);

// TODO(lmichaelis): The segment in this message might no longer be valid, since we
// have called `pop` on the queue but not kept a strong reference to the message!
Expand All @@ -680,6 +685,7 @@ static void DmPerformance_handleMessage(DmPerformance* slf, DmMessage* msg) {
DmSynth_sendNoteOffEverything(&slf->synth);

// Reset the time to combat drift
uint32_t loop_offset = msg->segment.loop > 0 ? sgt->loop_start : 0;
slf->time = 0;

for (size_t i = 0; i < sgt->messages.length; ++i) {
Expand All @@ -693,7 +699,7 @@ static void DmPerformance_handleMessage(DmPerformance* slf, DmMessage* msg) {
continue;
}

DmMessageQueue_add(&slf->control_queue, m, slf->time + m->time, DmQueueConflict_REPLACE);
DmMessageQueue_add(&slf->control_queue, m, slf->time + m->time - loop_offset, DmQueueConflict_REPLACE);
}

DmSegment_release(slf->segment);
Expand Down

0 comments on commit e644513

Please sign in to comment.