triggerbox: change FollowActions into an object with a target list

Should be no functional changes in this commit, but older sessions will likely not
load.
This commit is contained in:
Paul Davis 2022-01-19 15:50:32 -07:00
parent b51621a1ae
commit 95edfbac4a
5 changed files with 163 additions and 64 deletions

View File

@ -44,6 +44,8 @@
#include "ardour/midi_state_tracker.h" #include "ardour/midi_state_tracker.h"
#include "ardour/processor.h" #include "ardour/processor.h"
#include "ardour/segment_descriptor.h" #include "ardour/segment_descriptor.h"
#include "ardour/types.h"
#include "ardour/types_convert.h"
#include "ardour/libardour_visibility.h" #include "ardour/libardour_visibility.h"
@ -171,21 +173,6 @@ class LIBARDOUR_API Trigger : public PBD::Stateful {
LaunchStyle launch_style() const; LaunchStyle launch_style() const;
void set_launch_style (LaunchStyle); void set_launch_style (LaunchStyle);
enum FollowAction {
None,
Stop,
Again,
QueuedTrigger, /* DP-style */
NextTrigger, /* Live-style, and below */
PrevTrigger,
ForwardTrigger, /* any "next" skipping empties */
ReverseTrigger, /* any "prev" skipping empties */
FirstTrigger,
LastTrigger,
AnyTrigger,
OtherTrigger,
};
FollowAction follow_action (uint32_t n) const { assert (n < 2); return n ? _follow_action1 : _follow_action0; } FollowAction follow_action (uint32_t n) const { assert (n < 2); return n ? _follow_action1 : _follow_action0; }
void set_follow_action (FollowAction, uint32_t n); void set_follow_action (FollowAction, uint32_t n);
@ -571,7 +558,7 @@ class LIBARDOUR_API TriggerBox : public Processor
TriggerPtr currently_playing() const { return _currently_playing; } TriggerPtr currently_playing() const { return _currently_playing; }
void clear_all_triggers (); void clear_all_triggers ();
void set_all_follow_action (ARDOUR::Trigger::FollowAction, uint32_t n=0); void set_all_follow_action (ARDOUR::FollowAction const &, uint32_t n=0);
void set_all_launch_style (ARDOUR::Trigger::LaunchStyle); void set_all_launch_style (ARDOUR::Trigger::LaunchStyle);
void set_all_quantization (Temporal::BBT_Offset const&); void set_all_quantization (Temporal::BBT_Offset const&);
void set_all_probability (int zero_to_a_hundred); void set_all_probability (int zero_to_a_hundred);
@ -617,8 +604,6 @@ class LIBARDOUR_API TriggerBox : public Processor
static void init (); static void init ();
static const int32_t default_triggers_per_box;
static TriggerBoxThread* worker; static TriggerBoxThread* worker;
static void start_transport_stop (Session&); static void start_transport_stop (Session&);
@ -733,8 +718,8 @@ namespace Properties {
LIBARDOUR_API extern PBD::PropertyDescriptor<Temporal::BBT_Offset> quantization; LIBARDOUR_API extern PBD::PropertyDescriptor<Temporal::BBT_Offset> quantization;
LIBARDOUR_API extern PBD::PropertyDescriptor<Temporal::BBT_Offset> follow_length; LIBARDOUR_API extern PBD::PropertyDescriptor<Temporal::BBT_Offset> follow_length;
LIBARDOUR_API extern PBD::PropertyDescriptor<Trigger::LaunchStyle> launch_style; LIBARDOUR_API extern PBD::PropertyDescriptor<Trigger::LaunchStyle> launch_style;
LIBARDOUR_API extern PBD::PropertyDescriptor<Trigger::FollowAction> follow_action0; LIBARDOUR_API extern PBD::PropertyDescriptor<FollowAction> follow_action0;
LIBARDOUR_API extern PBD::PropertyDescriptor<Trigger::FollowAction> follow_action1; LIBARDOUR_API extern PBD::PropertyDescriptor<FollowAction> follow_action1;
LIBARDOUR_API extern PBD::PropertyDescriptor<Trigger::StretchMode> stretch_mode; LIBARDOUR_API extern PBD::PropertyDescriptor<Trigger::StretchMode> stretch_mode;
LIBARDOUR_API extern PBD::PropertyDescriptor<uint32_t> follow_count; LIBARDOUR_API extern PBD::PropertyDescriptor<uint32_t> follow_count;
LIBARDOUR_API extern PBD::PropertyDescriptor<int> follow_action_probability; LIBARDOUR_API extern PBD::PropertyDescriptor<int> follow_action_probability;
@ -751,7 +736,7 @@ namespace Properties {
} // namespace ARDOUR } // namespace ARDOUR
namespace PBD { namespace PBD {
DEFINE_ENUM_CONVERT(ARDOUR::Trigger::FollowAction); DEFINE_ENUM_CONVERT(ARDOUR::FollowAction::Type);
DEFINE_ENUM_CONVERT(ARDOUR::Trigger::LaunchStyle); DEFINE_ENUM_CONVERT(ARDOUR::Trigger::LaunchStyle);
DEFINE_ENUM_CONVERT(ARDOUR::Trigger::StretchMode); DEFINE_ENUM_CONVERT(ARDOUR::Trigger::StretchMode);
} /* namespace PBD */ } /* namespace PBD */

View File

@ -31,6 +31,7 @@
#ifndef __ardour_types_h__ #ifndef __ardour_types_h__
#define __ardour_types_h__ #define __ardour_types_h__
#include <bitset>
#include <istream> #include <istream>
#include <vector> #include <vector>
#include <map> #include <map>
@ -818,6 +819,53 @@ enum CueBehavior {
typedef std::vector<CaptureInfo*> CaptureInfos; typedef std::vector<CaptureInfo*> CaptureInfos;
const int32_t default_triggers_per_box = 8;
struct FollowAction {
enum Type {
None,
Stop,
Again,
QueuedTrigger, /* DP-style */
NextTrigger, /* Live-style, and below */
PrevTrigger,
ForwardTrigger, /* any "next" skipping empties */
ReverseTrigger, /* any "prev" skipping empties */
FirstTrigger,
LastTrigger,
AnyTrigger,
OtherTrigger,
};
/* 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.
*/
typedef std::bitset<64> Targets;
Type type;
Targets targets;
FollowAction () : type (None) {}
FollowAction (Type t, Targets const & tgts = Targets()) : type (t), targets (tgts) {}
FollowAction (Type t, std::string const & bitstring) : type (t), targets (bitstring) {}
FollowAction (std::string const &);
bool operator!= (FollowAction const & other) const {
return other.type != type || other.targets != targets;
}
bool operator== (FollowAction const & other) const {
return other.type == type && other.targets == targets;
}
std::string to_string() const;
};
} // namespace ARDOUR } // namespace ARDOUR
/* for now, break the rules and use "using" to make this "global" */ /* for now, break the rules and use "using" to make this "global" */

View File

@ -30,6 +30,14 @@
#include "ardour/data_type.h" #include "ardour/data_type.h"
#include "ardour/mode.h" #include "ardour/mode.h"
/* NOTE: when adding types to this file, you must add four functions:
std::string to_string (T);
T string_to (std::string const &);
bool to_string (T, std::string &);
bool string_to (std::string const &, T&);
*/
namespace PBD { namespace PBD {
DEFINE_ENUM_CONVERT(Timecode::TimecodeFormat) DEFINE_ENUM_CONVERT(Timecode::TimecodeFormat)
@ -162,6 +170,33 @@ inline bool string_to (const std::string& str, ARDOUR::DataType& dt)
return true; return true;
} }
template <>
inline bool to_string (ARDOUR::FollowAction fa, std::string& str)
{
str = fa.to_string();
return true;
}
template <>
inline bool string_to (const std::string& str, ARDOUR::FollowAction& fa)
{
fa = ARDOUR::FollowAction (str);
return true;
}
template<>
inline std::string to_string (ARDOUR::FollowAction fa)
{
return fa.to_string ();
}
template<>
inline ARDOUR::FollowAction string_to (std::string const & str)
{
return ARDOUR::FollowAction (str);
}
} // namespace PBD } // namespace PBD
#endif // ARDOUR_TYPES_CONVERT_H #endif // ARDOUR_TYPES_CONVERT_H

View File

@ -157,7 +157,7 @@ setup_enum_writer ()
LocateTransportDisposition _LocateTransportDisposition; LocateTransportDisposition _LocateTransportDisposition;
Trigger::State _TriggerState; Trigger::State _TriggerState;
Trigger::LaunchStyle _TriggerLaunchStyle; Trigger::LaunchStyle _TriggerLaunchStyle;
Trigger::FollowAction _TriggerFollowAction; FollowAction::Type _FollowAction;
Trigger::StretchMode _TriggerStretchMode; Trigger::StretchMode _TriggerStretchMode;
CueBehavior _CueBehavior; CueBehavior _CueBehavior;
@ -859,19 +859,19 @@ setup_enum_writer ()
REGISTER_CLASS_ENUM (Trigger, Stopping); REGISTER_CLASS_ENUM (Trigger, Stopping);
REGISTER (_TriggerState); REGISTER (_TriggerState);
REGISTER_CLASS_ENUM (Trigger, None); REGISTER_CLASS_ENUM (FollowAction, None);
REGISTER_CLASS_ENUM (Trigger, Stop); REGISTER_CLASS_ENUM (FollowAction, Stop);
REGISTER_CLASS_ENUM (Trigger, Again); REGISTER_CLASS_ENUM (FollowAction, Again);
REGISTER_CLASS_ENUM (Trigger, QueuedTrigger); REGISTER_CLASS_ENUM (FollowAction, QueuedTrigger);
REGISTER_CLASS_ENUM (Trigger, NextTrigger); REGISTER_CLASS_ENUM (FollowAction, NextTrigger);
REGISTER_CLASS_ENUM (Trigger, PrevTrigger); REGISTER_CLASS_ENUM (FollowAction, PrevTrigger);
REGISTER_CLASS_ENUM (Trigger, ForwardTrigger); REGISTER_CLASS_ENUM (FollowAction, ForwardTrigger);
REGISTER_CLASS_ENUM (Trigger, ReverseTrigger); REGISTER_CLASS_ENUM (FollowAction, ReverseTrigger);
REGISTER_CLASS_ENUM (Trigger, FirstTrigger); REGISTER_CLASS_ENUM (FollowAction, FirstTrigger);
REGISTER_CLASS_ENUM (Trigger, LastTrigger); REGISTER_CLASS_ENUM (FollowAction, LastTrigger);
REGISTER_CLASS_ENUM (Trigger, AnyTrigger); REGISTER_CLASS_ENUM (FollowAction, AnyTrigger);
REGISTER_CLASS_ENUM (Trigger, OtherTrigger); REGISTER_CLASS_ENUM (FollowAction, OtherTrigger);
REGISTER (_TriggerFollowAction); REGISTER (_FollowAction);
REGISTER_CLASS_ENUM (Trigger, OneShot); REGISTER_CLASS_ENUM (Trigger, OneShot);
REGISTER_CLASS_ENUM (Trigger, ReTrigger); REGISTER_CLASS_ENUM (Trigger, ReTrigger);

View File

@ -54,8 +54,8 @@ namespace ARDOUR {
PBD::PropertyDescriptor<Temporal::BBT_Offset> quantization; PBD::PropertyDescriptor<Temporal::BBT_Offset> quantization;
PBD::PropertyDescriptor<Temporal::BBT_Offset> follow_length; PBD::PropertyDescriptor<Temporal::BBT_Offset> follow_length;
PBD::PropertyDescriptor<Trigger::LaunchStyle> launch_style; PBD::PropertyDescriptor<Trigger::LaunchStyle> launch_style;
PBD::PropertyDescriptor<Trigger::FollowAction> follow_action0; PBD::PropertyDescriptor<ARDOUR::FollowAction> follow_action0;
PBD::PropertyDescriptor<Trigger::FollowAction> follow_action1; PBD::PropertyDescriptor<ARDOUR::FollowAction> follow_action1;
PBD::PropertyDescriptor<uint32_t> currently_playing; PBD::PropertyDescriptor<uint32_t> currently_playing;
PBD::PropertyDescriptor<uint32_t> follow_count; PBD::PropertyDescriptor<uint32_t> follow_count;
PBD::PropertyDescriptor<int> follow_action_probability; PBD::PropertyDescriptor<int> follow_action_probability;
@ -68,6 +68,38 @@ namespace ARDOUR {
} }
} }
FollowAction::FollowAction (std::string const & str)
{
std::string::size_type colon = str.find_first_of (':');
if (colon == std::string::npos) {
throw failed_constructor ();
}
type = FollowAction::Type (string_2_enum (str.substr (0, colon), type));
/* We use the ulong representation of the bitset because the string
version is absurd.
*/
unsigned long ul;
std::stringstream ss (str.substr (colon+1));
ss >> ul;
if (!ss) {
throw failed_constructor();
}
targets = Targets (ul);
}
std::string
FollowAction::to_string () const
{
/* We use the ulong representation of the bitset because the string
version is absurd.
*/
return string_compose ("%1:%2", enum_2_string (type), targets.to_ulong());
}
Trigger * const Trigger::MagicClearPointerValue = (Trigger*) 0xfeedface; Trigger * const Trigger::MagicClearPointerValue = (Trigger*) 0xfeedface;
Trigger::Trigger (uint32_t n, TriggerBox& b) Trigger::Trigger (uint32_t n, TriggerBox& b)
@ -82,8 +114,8 @@ Trigger::Trigger (uint32_t n, TriggerBox& b)
, _pending_velocity_gain (1.0) , _pending_velocity_gain (1.0)
, _velocity_gain (1.0) , _velocity_gain (1.0)
, _launch_style (Properties::launch_style, OneShot) , _launch_style (Properties::launch_style, OneShot)
, _follow_action0 (Properties::follow_action0, Again) , _follow_action0 (Properties::follow_action0, FollowAction (FollowAction::Again))
, _follow_action1 (Properties::follow_action1, Stop) , _follow_action1 (Properties::follow_action1, FollowAction (FollowAction::Stop))
, _follow_action_probability (Properties::follow_action_probability, 0) , _follow_action_probability (Properties::follow_action_probability, 0)
, _follow_count (Properties::follow_count, 1) , _follow_count (Properties::follow_count, 1)
, _quantization (Properties::quantization, Temporal::BBT_Offset (1, 0, 0)) , _quantization (Properties::quantization, Temporal::BBT_Offset (1, 0, 0))
@ -148,8 +180,8 @@ Trigger::swap_pending (Trigger* t)
bool bool
Trigger::will_not_follow () const Trigger::will_not_follow () const
{ {
return (_follow_action0 == None && _follow_action_probability == 0) || return (_follow_action0.val().type == FollowAction::None && _follow_action_probability == 0) ||
(_follow_action0 == None && _follow_action1 == None); (_follow_action0.val().type == FollowAction::None && _follow_action1.val().type == FollowAction::None);
} }
void void
@ -1132,18 +1164,18 @@ AudioTrigger::set_region_in_worker_thread (boost::shared_ptr<Region> r)
if (_segment_tempo == 0.) { if (_segment_tempo == 0.) {
_stretchable = false; _stretchable = false;
_quantization = Temporal::BBT_Offset (-1, 0, 0); _quantization = Temporal::BBT_Offset (-1, 0, 0);
_follow_action0 = None; _follow_action0 = FollowAction (FollowAction::None);
} else { } else {
if (probably_oneshot()) { if (probably_oneshot()) {
/* short trigger, treat as a one shot */ /* short trigger, treat as a one shot */
_stretchable = false; _stretchable = false;
_follow_action0 = None; _follow_action0 = FollowAction (FollowAction::None);
_quantization = Temporal::BBT_Offset (-1, 0, 0); _quantization = Temporal::BBT_Offset (-1, 0, 0);
} else { } else {
_stretchable = true; _stretchable = true;
_quantization = Temporal::BBT_Offset (1, 0, 0); _quantization = Temporal::BBT_Offset (1, 0, 0);
_follow_action0 = Again; _follow_action0 = FollowAction (FollowAction::Again);
} }
} }
@ -2138,7 +2170,6 @@ Trigger::make_property_quarks ()
DEBUG_TRACE (DEBUG::Properties, string_compose ("quark for stretch_mode = %1\n", Properties::stretch_mode.property_id)); DEBUG_TRACE (DEBUG::Properties, string_compose ("quark for stretch_mode = %1\n", Properties::stretch_mode.property_id));
} }
const int32_t TriggerBox::default_triggers_per_box = 8;
Temporal::BBT_Offset TriggerBox::_assumed_trigger_duration (4, 0, 0); Temporal::BBT_Offset TriggerBox::_assumed_trigger_duration (4, 0, 0);
//TriggerBox::TriggerMidiMapMode TriggerBox::_midi_map_mode (TriggerBox::AbletonPush); //TriggerBox::TriggerMidiMapMode TriggerBox::_midi_map_mode (TriggerBox::AbletonPush);
TriggerBox::TriggerMidiMapMode TriggerBox::_midi_map_mode (TriggerBox::SequentialNote); TriggerBox::TriggerMidiMapMode TriggerBox::_midi_map_mode (TriggerBox::SequentialNote);
@ -2378,7 +2409,7 @@ TriggerBox::set_all_launch_style (ARDOUR::Trigger::LaunchStyle ls)
} }
void void
TriggerBox::set_all_follow_action (ARDOUR::Trigger::FollowAction fa, uint32_t fa_n) TriggerBox::set_all_follow_action (ARDOUR::FollowAction const & fa, uint32_t fa_n)
{ {
for (uint64_t n = 0; n < all_triggers.size(); ++n) { for (uint64_t n = 0; n < all_triggers.size(); ++n) {
all_triggers[n]->set_follow_action (fa, fa_n); all_triggers[n]->set_follow_action (fa, fa_n);
@ -2982,7 +3013,7 @@ TriggerBox::determine_next_trigger (uint32_t current)
*/ */
int r = _pcg.rand (100); // 0 .. 99 int r = _pcg.rand (100); // 0 .. 99
Trigger::FollowAction fa; FollowAction fa;
if (r >= all_triggers[current]->follow_action_probability()) { if (r >= all_triggers[current]->follow_action_probability()) {
fa = all_triggers[current]->follow_action (0); fa = all_triggers[current]->follow_action (0);
@ -2994,14 +3025,14 @@ TriggerBox::determine_next_trigger (uint32_t current)
* nothing or just repeat the current trigger * nothing or just repeat the current trigger
*/ */
DEBUG_TRACE (DEBUG::Triggers, string_compose ("choose next trigger using follow action %1 given prob %2 and rnd %3\n", enum_2_string (fa), all_triggers[current]->follow_action_probability(), r)); DEBUG_TRACE (DEBUG::Triggers, string_compose ("choose next trigger using follow action %1 given prob %2 and rnd %3\n", fa.to_string(), all_triggers[current]->follow_action_probability(), r));
switch (fa) { switch (fa.type) {
case Trigger::Stop: case FollowAction::Stop:
return -1; return -1;
case Trigger::QueuedTrigger: case FollowAction::QueuedTrigger:
/* XXX implement me */ /* XXX implement me */
return -1; return -1;
default: default:
@ -3015,15 +3046,15 @@ TriggerBox::determine_next_trigger (uint32_t current)
/* second switch: handle the "real" follow actions */ /* second switch: handle the "real" follow actions */
switch (fa) { switch (fa.type) {
case Trigger::None: case FollowAction::None:
return -1; return -1;
case Trigger::Again: case FollowAction::Again:
return current; return current;
case Trigger::NextTrigger: case FollowAction::NextTrigger:
n = current + 1; n = current + 1;
if (n < all_triggers.size()) { if (n < all_triggers.size()) {
if (all_triggers[n]->region()) { if (all_triggers[n]->region()) {
@ -3032,7 +3063,7 @@ TriggerBox::determine_next_trigger (uint32_t current)
} }
break; break;
case Trigger::PrevTrigger: case FollowAction::PrevTrigger:
if (current > 0) { if (current > 0) {
n = current - 1; n = current - 1;
if (all_triggers[n]->region()) { if (all_triggers[n]->region()) {
@ -3041,7 +3072,7 @@ TriggerBox::determine_next_trigger (uint32_t current)
} }
break; break;
case Trigger::ForwardTrigger: case FollowAction::ForwardTrigger:
n = current; n = current;
while (true) { while (true) {
++n; ++n;
@ -3062,7 +3093,7 @@ TriggerBox::determine_next_trigger (uint32_t current)
} }
break; break;
case Trigger::ReverseTrigger: case FollowAction::ReverseTrigger:
n = current; n = current;
while (true) { while (true) {
if (n == 0) { if (n == 0) {
@ -3081,14 +3112,14 @@ TriggerBox::determine_next_trigger (uint32_t current)
} }
break; break;
case Trigger::FirstTrigger: case FollowAction::FirstTrigger:
for (n = 0; n < all_triggers.size(); ++n) { for (n = 0; n < all_triggers.size(); ++n) {
if (all_triggers[n]->region() && !all_triggers[n]->active ()) { if (all_triggers[n]->region() && !all_triggers[n]->active ()) {
return n; return n;
} }
} }
break; break;
case Trigger::LastTrigger: case FollowAction::LastTrigger:
for (int i = all_triggers.size() - 1; i >= 0; --i) { for (int i = all_triggers.size() - 1; i >= 0; --i) {
if (all_triggers[i]->region() && !all_triggers[i]->active ()) { if (all_triggers[i]->region() && !all_triggers[i]->active ()) {
return i; return i;
@ -3096,7 +3127,7 @@ TriggerBox::determine_next_trigger (uint32_t current)
} }
break; break;
case Trigger::AnyTrigger: case FollowAction::AnyTrigger:
while (true) { while (true) {
n = _pcg.rand (all_triggers.size()); n = _pcg.rand (all_triggers.size());
if (!all_triggers[n]->region()) { if (!all_triggers[n]->region()) {
@ -3110,7 +3141,7 @@ TriggerBox::determine_next_trigger (uint32_t current)
return n; return n;
case Trigger::OtherTrigger: case FollowAction::OtherTrigger:
while (true) { while (true) {
n = _pcg.rand (all_triggers.size()); n = _pcg.rand (all_triggers.size());
if ((uint32_t) n == current) { if ((uint32_t) n == current) {
@ -3128,8 +3159,8 @@ TriggerBox::determine_next_trigger (uint32_t current)
/* NOTREACHED */ /* NOTREACHED */
case Trigger::Stop: case FollowAction::Stop:
case Trigger::QueuedTrigger: case FollowAction::QueuedTrigger:
break; break;
} }