From e75a8ab77ce1e4bf41a59a427b497a7a92ea57f8 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Tue, 15 Feb 2022 15:27:55 -0700 Subject: [PATCH] triggerbox: clarify handling of end-of-clip conditions This doesn't enter Playout state, when the final event matches the predicted final beat, but also returns the correct number of frames covered --- libs/ardour/triggerbox.cc | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/libs/ardour/triggerbox.cc b/libs/ardour/triggerbox.cc index 200c92de84..78099cbc0a 100644 --- a/libs/ardour/triggerbox.cc +++ b/libs/ardour/triggerbox.cc @@ -2510,7 +2510,7 @@ MIDITrigger::midi_run (BufferSet& bufs, samplepos_t start_sample, samplepos_t en if (last_event_timeline_beats <= final_beat) { - DEBUG_TRACE (DEBUG::Triggers, string_compose ("%1 entering playout because ... leb %2 >= fb %3\n", index(), last_event_timeline_beats, final_beat)); + DEBUG_TRACE (DEBUG::Triggers, string_compose ("%1 entering playout because ... leb %2 <= fb %3\n", index(), last_event_timeline_beats, final_beat)); if (_state != Playout) { _state = Playout; @@ -2534,18 +2534,13 @@ MIDITrigger::midi_run (BufferSet& bufs, samplepos_t start_sample, samplepos_t en } else { + samplepos_t final_processed_sample = tmap->sample_at (timepos_t (final_beat)); + nframes = orig_nframes - (final_processed_sample - start_sample); _loop_cnt++; _state = Stopped; - - /* the time we processed spans from start to the last event */ - - if (last_event_samples != max_samplepos) { - nframes = (last_event_samples - start_sample); - } else { - /* all frames covered */ - nframes = 0; - } + DEBUG_TRACE (DEBUG::Triggers, string_compose ("%1 reached final event, now stopped, nf = %2 fb %3 fs %4 %5\n", index(), nframes, final_beat, final_processed_sample, start_sample)); } + } else { /* we didn't reach the end of the MIDI data, ergo we covered the entire timespan passed into us.