From 4be38042a2e2ef51e635e1ebc30969573ab81dca Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Fri, 31 Dec 2021 17:52:07 -0700 Subject: [PATCH] triggerbox: consolidate some code that is used in both MIDITrigger and AudioTrigger::run() This comments out the reset of transition_beats that had been necessary to get MIDI triggers to work correctly. Testing doesn't show a problem with it (so far). --- libs/ardour/ardour/triggerbox.h | 1 + libs/ardour/triggerbox.cc | 135 +++++++++++++------------------- 2 files changed, 54 insertions(+), 82 deletions(-) diff --git a/libs/ardour/ardour/triggerbox.h b/libs/ardour/ardour/triggerbox.h index ed344bd726..a6a6d0db25 100644 --- a/libs/ardour/ardour/triggerbox.h +++ b/libs/ardour/ardour/triggerbox.h @@ -297,6 +297,7 @@ class LIBARDOUR_API Trigger : public PBD::Stateful { std::atomic _pending; + void when_stopped_during_run (); void set_region_internal (boost::shared_ptr); virtual void retrigger() = 0; virtual void set_usable_length () = 0; diff --git a/libs/ardour/triggerbox.cc b/libs/ardour/triggerbox.cc index 037f6408f5..2486132285 100644 --- a/libs/ardour/triggerbox.cc +++ b/libs/ardour/triggerbox.cc @@ -687,6 +687,57 @@ Trigger::maybe_compute_next_transition (samplepos_t start_sample, Temporal::Beat return extra_offset; } +void +Trigger::when_stopped_during_run () +{ + if (_state == Stopped || _state == Stopping) { + + if ((_state == Stopped) && !_explicitly_stopped && (launch_style() == Trigger::Gate || launch_style() == Trigger::Repeat)) { + + jump_start (); + DEBUG_TRACE (DEBUG::Triggers, string_compose ("%1 was stopped, repeat/gate ret\n", index())); + + } else { + + if ((launch_style() != Repeat) && (launch_style() != Gate) && (_loop_cnt == _follow_count)) { + + /* have played the specified number of times, we're done */ + + DEBUG_TRACE (DEBUG::Triggers, string_compose ("%1 loop cnt %2 satisfied, now stopped\n", index(), _follow_count)); + shutdown (); + + + } else if (_state == Stopping) { + + /* did not reach the end of the data. Presumably + * another trigger was explicitly queued, and we + * stopped + */ + + DEBUG_TRACE (DEBUG::Triggers, string_compose ("%1 not at end, but ow stopped\n", index())); + shutdown (); + + } else { + + /* reached the end, but we haven't done that enough + * times yet for a follow action/stop to take + * effect. Time to get played again. + */ + + DEBUG_TRACE (DEBUG::Triggers, string_compose ("%1 was stopping, now waiting to retrigger, loop cnt %2 fc %3\n", index(), _loop_cnt, _follow_count)); + /* we will "restart" at the beginning of the + next iteration of the trigger. + */ + // transition_beats = transition_beats + data_length; + _state = WaitingToStart; + retrigger (); + PropertyChanged (ARDOUR::Properties::running); + } + } + } +} + + /*--------------------*/ AudioTrigger::AudioTrigger (uint32_t n, TriggerBox& b) @@ -1362,45 +1413,7 @@ AudioTrigger::run (BufferSet& bufs, samplepos_t start_sample, samplepos_t end_sa } if (_state == Stopped || _state == Stopping) { - - if ((_state == Stopped) && !_explicitly_stopped && (launch_style() == Trigger::Gate || launch_style() == Trigger::Repeat)) { - - jump_start (); - DEBUG_TRACE (DEBUG::Triggers, string_compose ("%1 was stopped, repeat/gate ret\n", index())); - - } else { - - if ((launch_style() != Repeat) && (launch_style() != Gate) && (_loop_cnt == _follow_count)) { - - /* have played the specified number of times, we're done */ - - DEBUG_TRACE (DEBUG::Triggers, string_compose ("%1 loop cnt %2 satisfied, now stopped\n", index(), _follow_count)); - shutdown (); - - - } else if (_state == Stopping) { - - /* did not reach the end of the data. Presumably - * another trigger was explicitly queued, and we - * stopped - */ - - DEBUG_TRACE (DEBUG::Triggers, string_compose ("%1 not at end, but ow stopped\n", index())); - shutdown (); - - } else { - - /* reached the end, but we haven't done that enough - * times yet for a follow action/stop to take - * effect. Time to get played again. - */ - - DEBUG_TRACE (DEBUG::Triggers, string_compose ("%1 was stopping, now waiting to retrigger, loop cnt %2 fc %3\n", index(), _loop_cnt, _follow_count)); - _state = WaitingToStart; - retrigger (); - PropertyChanged (ARDOUR::Properties::running); - } - } + when_stopped_during_run (); } return orig_nframes - nframes; @@ -1760,49 +1773,7 @@ MIDITrigger::run (BufferSet& bufs, samplepos_t start_sample, samplepos_t end_sam } if (_state == Stopped || _state == Stopping) { - - if ((_state == Stopped) && !_explicitly_stopped && (launch_style() == Trigger::Gate || launch_style() == Trigger::Repeat)) { - - jump_start (); - DEBUG_TRACE (DEBUG::Triggers, string_compose ("%1 was stopped, repeat/gate ret\n", index())); - - } else { - - if ((launch_style() != Repeat) && (launch_style() != Gate) && (_loop_cnt == _follow_count)) { - - /* have played the specified number of times, we're done */ - - DEBUG_TRACE (DEBUG::Triggers, string_compose ("%1 loop cnt %2 satisfied, now stopped\n", index(), _follow_count)); - shutdown (); - - - } else if (_state == Stopping) { - - /* did not reach the end of the data. Presumably - * another trigger was explicitly queued, and we - * stopped - */ - - DEBUG_TRACE (DEBUG::Triggers, string_compose ("%1 not at end, but ow stopped\n", index())); - shutdown (); - - } else { - - /* reached the end, but we haven't done that enough - * times yet for a follow action/stop to take - * effect. Time to get played again. - */ - - DEBUG_TRACE (DEBUG::Triggers, string_compose ("%1 was stopping, now waiting to retrigger, loop cnt %2 fc %3 , reset TS to %4 + %5\n", index(), _loop_cnt, _follow_count, transition_beats, data_length)); - /* we will "restart" at the beginning of the - next iteration of the trigger. - */ - transition_beats = transition_beats + data_length; - _state = WaitingToStart; - retrigger (); - PropertyChanged (ARDOUR::Properties::running); - } - } + when_stopped_during_run (); } return orig_nframes - nframes;