From c2bf45a03367feba1e8b6e9e44e12968e5600c45 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Sat, 3 Aug 2024 20:21:53 +0200 Subject: [PATCH] Fix triggerbox cues when looping This correctly handles the case when a cue marker is at the same position as loop-end. Previously the cue was triggered even though transport looped --- libs/ardour/ardour/triggerbox.h | 1 + libs/ardour/triggerbox.cc | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/libs/ardour/ardour/triggerbox.h b/libs/ardour/ardour/triggerbox.h index 45905db455..6695393a51 100644 --- a/libs/ardour/ardour/triggerbox.h +++ b/libs/ardour/ardour/triggerbox.h @@ -732,6 +732,7 @@ class LIBARDOUR_API TriggerBox : public Processor static PBD::Signal0 CueRecordingChanged; void run (BufferSet& bufs, samplepos_t start_sample, samplepos_t end_sample, double speed, pframes_t nframes, bool result_required); + void run_cycle (BufferSet& bufs, samplepos_t start_sample, samplepos_t end_sample, double speed, pframes_t nframes); bool can_support_io_configuration (const ChanCount& in, ChanCount& out); bool configure_io (ChanCount in, ChanCount out); diff --git a/libs/ardour/triggerbox.cc b/libs/ardour/triggerbox.cc index 9817730601..870b15780c 100644 --- a/libs/ardour/triggerbox.cc +++ b/libs/ardour/triggerbox.cc @@ -4129,6 +4129,38 @@ TriggerBox::run (BufferSet& bufs, samplepos_t start_sample, samplepos_t end_samp return; } + const Location* const loop_loc = _loop_location; + + if (!loop_loc) { + run_cycle (bufs, start_sample, end_sample, speed, nframes); + } else { + const samplepos_t loop_start = loop_loc->start_sample (); + const samplepos_t loop_end = loop_loc->end_sample (); + const samplecnt_t looplen = loop_end - loop_start; + + samplecnt_t remain = nframes; + samplepos_t start_pos = start_sample; + + while (remain > 0) { + if (start_pos >= loop_end) { + sampleoffset_t start_off = (start_pos - loop_start) % looplen; + start_pos = loop_start + start_off; + } + + samplecnt_t move = std::min ((samplecnt_t)nframes, loop_end - start_pos); + + run_cycle (bufs, start_pos, start_pos + move, speed, move); + + remain -= move; + start_pos += move; + } + } +} + +void +TriggerBox::run_cycle (BufferSet& bufs, samplepos_t start_sample, samplepos_t end_sample, double speed, pframes_t nframes) +{ + #ifndef NDEBUG { Temporal::TempoMap::SharedPtr __tmap (Temporal::TempoMap::use());