From c620d3d41137c766d16c21d084ed7e39fb2d6bfd Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Wed, 11 Aug 2021 23:03:53 -0600 Subject: [PATCH] triggerbox: follow action "probability" --- libs/ardour/ardour/triggerbox.h | 4 ++++ libs/ardour/triggerbox.cc | 20 ++++++++++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/libs/ardour/ardour/triggerbox.h b/libs/ardour/ardour/triggerbox.h index 9fae2b22bb..796839691e 100644 --- a/libs/ardour/ardour/triggerbox.h +++ b/libs/ardour/ardour/triggerbox.h @@ -145,6 +145,9 @@ class LIBARDOUR_API Trigger : public PBD::Stateful { void set_next_trigger (int n); int next_trigger() const { return _next_trigger; } + void set_follow_action_probability (int zero_to_a_hundred); + int follow_action_probability() const { return _follow_action_probability; } + protected: TriggerBox& _box; State _state; @@ -155,6 +158,7 @@ class LIBARDOUR_API Trigger : public PBD::Stateful { int _next_trigger; LaunchStyle _launch_style; FollowAction _follow_action[2]; + int _follow_action_probability; boost::shared_ptr _region; Temporal::BBT_Offset _quantization; diff --git a/libs/ardour/triggerbox.cc b/libs/ardour/triggerbox.cc index 952227e172..885ff4455e 100644 --- a/libs/ardour/triggerbox.cc +++ b/libs/ardour/triggerbox.cc @@ -559,7 +559,7 @@ AudioTrigger::run (BufferSet& bufs, pframes_t nframes, pframes_t dest_offset, bo /* We reached the end */ - if (_follow_action[0] == Again) { + if (_next_trigger > 0 && (size_t) _next_trigger == _index) { /* self repeat */ nframes -= this_read; dest_offset += this_read; DEBUG_TRACE (DEBUG::Triggers, string_compose ("%1 was reached end, but set to loop, so retrigger\n", index())); @@ -917,7 +917,7 @@ TriggerBox::run (BufferSet& bufs, samplepos_t start_sample, samplepos_t end_samp if (trigger.state() == Trigger::Stopped) { - if (trigger.follow_action(0) != Trigger::Stop) { + if (trigger.next_trigger() != -1) { int nxt = trigger.next_trigger(); @@ -950,9 +950,21 @@ TriggerBox::set_next_trigger (size_t current) } } - switch (all_triggers[current]->follow_action(0)) { + int which_follow_action; + int r = random() % 100; + + if (r <= all_triggers[current]->follow_action_probability()) { + which_follow_action = 0; + } else { + which_follow_action = 1; + } + + switch (all_triggers[current]->follow_action (which_follow_action)) { + case Trigger::Stop: + all_triggers[current]->set_next_trigger (-1); return; + case Trigger::QueuedTrigger: /* XXX implement me */ return; @@ -963,7 +975,7 @@ TriggerBox::set_next_trigger (size_t current) } } - switch (all_triggers[current]->follow_action(0)) { + switch (all_triggers[current]->follow_action (which_follow_action)) { case Trigger::Again: all_triggers[current]->set_next_trigger (current);