From d8c90decf3e174b4ee179598f950d0c950f91052 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Thu, 13 Jan 2022 12:09:23 -0700 Subject: [PATCH] triggerbox: use follow length when quantizing re-start of Again-selected trigger This also changes the virtual method from ::startup() to ::_startup() so that we can safely have a default argument in ::startup(). --- libs/ardour/ardour/triggerbox.h | 10 ++++---- libs/ardour/triggerbox.cc | 42 +++++++++++++++++++++++-------- libs/temporal/temporal/bbt_time.h | 3 +++ 3 files changed, 39 insertions(+), 16 deletions(-) diff --git a/libs/ardour/ardour/triggerbox.h b/libs/ardour/ardour/triggerbox.h index dbe77f69ca..0f4925a76e 100644 --- a/libs/ardour/ardour/triggerbox.h +++ b/libs/ardour/ardour/triggerbox.h @@ -226,7 +226,7 @@ class LIBARDOUR_API Trigger : public PBD::Stateful { void set_legato (bool yn); bool legato () const { return _legato; } - virtual void startup (); + void startup (Temporal::BBT_Offset const & start_quantization = Temporal::BBT_Offset ()); virtual void shutdown (BufferSet& bufs, pframes_t dest_offset); virtual void jump_start (); virtual void jump_stop (BufferSet& bufs, pframes_t dest_offset); @@ -319,12 +319,13 @@ class LIBARDOUR_API Trigger : public PBD::Stateful { double _barcnt; /* our estimate of the number of bars in the region */ double _apparent_tempo; samplepos_t expected_end_sample; - + Temporal::BBT_Offset _start_quantization; std::atomic _pending; void when_stopped_during_run (BufferSet& bufs, pframes_t dest_offset); void set_region_internal (boost::shared_ptr); virtual void retrigger() = 0; + virtual void _startup (Temporal::BBT_Offset const &); }; typedef boost::shared_ptr TriggerPtr; @@ -351,7 +352,6 @@ class LIBARDOUR_API AudioTrigger : public Trigger { double position_as_fraction() const; int set_region_in_worker_thread (boost::shared_ptr); - void startup (); void jump_start (); void jump_stop (BufferSet& bufs, pframes_t dest_offset); @@ -398,6 +398,7 @@ class LIBARDOUR_API AudioTrigger : public Trigger { int load_data (boost::shared_ptr); void determine_tempo (); void setup_stretcher (); + void _startup (Temporal::BBT_Offset const &); }; @@ -423,7 +424,6 @@ class LIBARDOUR_API MIDITrigger : public Trigger { double position_as_fraction() const; int set_region_in_worker_thread (boost::shared_ptr); - void startup (); void jump_start (); void shutdown (BufferSet& bufs, pframes_t dest_offset); void jump_stop (BufferSet& bufs, pframes_t dest_offset); @@ -455,9 +455,9 @@ class LIBARDOUR_API MIDITrigger : public Trigger { int load_data (boost::shared_ptr); void compute_and_set_length (); + void _startup (Temporal::BBT_Offset const &); }; - class LIBARDOUR_API TriggerBoxThread { public: diff --git a/libs/ardour/triggerbox.cc b/libs/ardour/triggerbox.cc index e30bfd0808..3ee26a587b 100644 --- a/libs/ardour/triggerbox.cc +++ b/libs/ardour/triggerbox.cc @@ -431,12 +431,28 @@ Trigger::request_stop () } void -Trigger::startup() +Trigger::startup (Temporal::BBT_Offset const & start_quantization) +{ + /* This is just a non-virtual wrapper with a default parameter that calls _startup() */ + _startup (start_quantization); +} + +void +Trigger::_startup (Temporal::BBT_Offset const & start_quantization) { _state = WaitingToStart; _loop_cnt = 0; _velocity_gain = _pending_velocity_gain; _explicitly_stopped = false; + + if (start_quantization != Temporal::BBT_Offset()) { + _start_quantization = start_quantization; + } else { + _start_quantization = _quantization; + } + + retrigger (); + DEBUG_TRACE (DEBUG::Triggers, string_compose ("%1 starts up\n", name())); PropertyChanged (ARDOUR::Properties::running); } @@ -605,7 +621,7 @@ Trigger::maybe_compute_next_transition (samplepos_t start_sample, Temporal::Beat TempoMap::SharedPtr tmap (TempoMap::use()); Temporal::BBT_Time transition_bbt; pframes_t extra_offset = 0; - BBT_Offset q (_quantization); + BBT_Offset q (_start_quantization); /* Clips don't stop on their own quantize; in Live they stop on the Global Quantize setting; we will choose 1 bar (Live's default) for now */ #warning when Global Quantize is implemented, use that instead of '1 bar' here @@ -811,10 +827,9 @@ AudioTrigger::get_segment_descriptor () const } void -AudioTrigger::startup () +AudioTrigger::_startup (Temporal::BBT_Offset const & start_quantization) { - Trigger::startup (); - retrigger (); + Trigger::_startup (start_quantization); } void @@ -1555,9 +1570,9 @@ AudioTrigger::reload (BufferSet&, void*) MIDITrigger::MIDITrigger (uint32_t n, TriggerBox& b) : Trigger (n, b) - , _start_offset (0, 0, 0) , data_length (Temporal::Beats()) , last_event_beats (Temporal::Beats()) + , _start_offset (0, 0, 0) , _legato_offset (0, 0, 0) { } @@ -1624,10 +1639,9 @@ MIDITrigger::get_segment_descriptor () const } void -MIDITrigger::startup () +MIDITrigger::_startup (Temporal::BBT_Offset const & start_quantization) { - Trigger::startup (); - retrigger (); + Trigger::_startup (start_quantization); } void @@ -2734,6 +2748,7 @@ TriggerBox::run (BufferSet& bufs, samplepos_t start_sample, samplepos_t end_samp if (_currently_playing->use_follow()) { int n = determine_next_trigger (_currently_playing->index()); + Temporal::BBT_Offset start_quantization; std::cerr << "dnt = " << n << endl; if (n < 0) { DEBUG_TRACE (DEBUG::Triggers, string_compose ("%1 finished, no next trigger\n", _currently_playing->name())); @@ -2741,9 +2756,14 @@ TriggerBox::run (BufferSet& bufs, samplepos_t start_sample, samplepos_t end_samp PropertyChanged (Properties::currently_playing); break; /* no triggers to come next, break out of nframes loop */ } - DEBUG_TRACE (DEBUG::Triggers, string_compose ("switching to next trigger %1\n", _currently_playing->name())); + if (_currently_playing->index() == n) { + start_quantization = _currently_playing->follow_length(); + DEBUG_TRACE (DEBUG::Triggers, string_compose ("switching to next trigger %1\n, will use start Q %2", all_triggers[n]->name(), _currently_playing->follow_length())); + } else { + DEBUG_TRACE (DEBUG::Triggers, string_compose ("switching to next trigger %1\n", all_triggers[n]->name())); + } _currently_playing = all_triggers[n]; - _currently_playing->startup (); + _currently_playing->startup (start_quantization); can_clear = true; PropertyChanged (Properties::currently_playing); } else { diff --git a/libs/temporal/temporal/bbt_time.h b/libs/temporal/temporal/bbt_time.h index fe88802c71..20d8443865 100644 --- a/libs/temporal/temporal/bbt_time.h +++ b/libs/temporal/temporal/bbt_time.h @@ -240,6 +240,9 @@ struct LIBTEMPORAL_API BBT_Offset return bars != other.bars || beats != other.beats || ticks != other.ticks; } + operator bool() const { + return bars == 0 && beats == 0 && ticks == 0; + } }; inline BBT_Offset LIBTEMPORAL_API bbt_delta (Temporal::BBT_Time const & a, Temporal::BBT_Time const & b) {