From 413f2e9d1b454b6f507ea41d2ced17e41c01b7fb Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Thu, 20 Jan 2022 11:01:00 -0700 Subject: [PATCH] triggerbox: implement (?) JumpTrigger follow action --- libs/ardour/ardour/types.h | 10 +++++++++- libs/ardour/enums.cc | 1 + libs/ardour/triggerbox.cc | 14 ++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/libs/ardour/ardour/types.h b/libs/ardour/ardour/types.h index 6159fdd43d..1a7c913c1c 100644 --- a/libs/ardour/ardour/types.h +++ b/libs/ardour/ardour/types.h @@ -836,12 +836,13 @@ struct FollowAction { LastTrigger, AnyTrigger, OtherTrigger, + JumpTrigger, }; /* We could theoretically limit this to default_triggers_per_box but * doing it this way makes it likely that this will not change. Could * be worth a constexpr-style compile time assert to check - * default_triggers_per_box < 64. + * default_triggers_per_box < 64 */ typedef std::bitset<64> Targets; @@ -854,6 +855,13 @@ struct FollowAction { FollowAction (Type t, std::string const & bitstring) : type (t), targets (bitstring) {} FollowAction (std::string const &); + static Targets target_any () { Targets t; t.set(); return t; } + static Targets target_other (uint8_t skip) { Targets t; t.set (); t.reset (skip); return t; } + static Targets target_next_wrap (uint8_t from) { Targets t; if (from < t.size() - 1) { t.set (from + 1); } else { t.set (0); } return t; } + static Targets target_prev_wrap (uint8_t from) { Targets t; if (from) { t.set (from - 1); } else { t.set (t.size() - 1); } return t; } + static Targets target_next_nowrap (uint8_t from) { Targets t; if (from < t.size() - 1) { t.set (from + 1); } return t; } + static Targets target_prev_nowrap (uint8_t from) { Targets t; if (from) { t.set (from - 1); } return t; } + bool operator!= (FollowAction const & other) const { return other.type != type || other.targets != targets; } diff --git a/libs/ardour/enums.cc b/libs/ardour/enums.cc index a64154872d..315b6e77f9 100644 --- a/libs/ardour/enums.cc +++ b/libs/ardour/enums.cc @@ -871,6 +871,7 @@ setup_enum_writer () REGISTER_CLASS_ENUM (FollowAction, LastTrigger); REGISTER_CLASS_ENUM (FollowAction, AnyTrigger); REGISTER_CLASS_ENUM (FollowAction, OtherTrigger); + REGISTER_CLASS_ENUM (FollowAction, JumpTrigger); REGISTER (_FollowAction); REGISTER_CLASS_ENUM (Trigger, OneShot); diff --git a/libs/ardour/triggerbox.cc b/libs/ardour/triggerbox.cc index 69d5be13fa..fa0f4e27bc 100644 --- a/libs/ardour/triggerbox.cc +++ b/libs/ardour/triggerbox.cc @@ -2995,6 +2995,9 @@ TriggerBox::determine_next_trigger (uint32_t current) { uint32_t n; uint32_t runnable = 0; + std::vector possible_targets; + + possible_targets.reserve (default_triggers_per_box); /* count number of triggers that can actually be run (i.e. they have a region) */ @@ -3157,6 +3160,17 @@ TriggerBox::determine_next_trigger (uint32_t current) } return n; + case FollowAction::JumpTrigger: + for (std::size_t n = 0; n < default_triggers_per_box; ++n) { + if (fa.targets.test (n) && all_triggers[n]->region()) { + possible_targets.push_back (n); + } + } + if (possible_targets.empty()) { + return 1; + } + return possible_targets[_pcg.rand (possible_targets.size())]; + /* NOTREACHED */ case FollowAction::Stop: