diff --git a/libs/ardour/ardour/session.h b/libs/ardour/ardour/session.h index b2afd9decc..1bfbc7d203 100644 --- a/libs/ardour/ardour/session.h +++ b/libs/ardour/ardour/session.h @@ -1386,7 +1386,7 @@ public: int num_triggerboxes () const; std::shared_ptr triggerbox_at (int32_t route_index) const; TriggerPtr trigger_at (int32_t route_index, int32_t row_index) const; - bool bang_trigger_at(int32_t route_index, int32_t row_index); + bool bang_trigger_at(int32_t route_index, int32_t row_index, float velocity = 1.0); bool unbang_trigger_at(int32_t route_index, int32_t row_index); void clear_cue (int row_index); diff --git a/libs/ardour/ardour/triggerbox.h b/libs/ardour/ardour/triggerbox.h index c31ae2626b..45905db455 100644 --- a/libs/ardour/ardour/triggerbox.h +++ b/libs/ardour/ardour/triggerbox.h @@ -261,7 +261,7 @@ class LIBARDOUR_API Trigger : public PBD::Stateful { /* Calling ::bang() will cause this Trigger to be placed in its owning TriggerBox's queue. */ - void bang (); + void bang (float velocity = 1.0f); /* Calling ::unbang() is equivalent to a mouse-up or note-off ... it MIGHT cause a clip to stop, but more likely has no effect, depending on the slot's launch-style. @@ -745,7 +745,7 @@ class LIBARDOUR_API TriggerBox : public Processor TriggerPtr trigger (Triggers::size_type); - void bang_trigger_at (Triggers::size_type row); + void bang_trigger_at (Triggers::size_type row, float velocity = 1.0f); void unbang_trigger_at (Triggers::size_type row); void add_trigger (TriggerPtr); diff --git a/libs/ardour/session_process.cc b/libs/ardour/session_process.cc index 99c9434ccf..c5db5d0f0f 100644 --- a/libs/ardour/session_process.cc +++ b/libs/ardour/session_process.cc @@ -1729,7 +1729,7 @@ Session::trigger_cue_row (int32_t cue) bool -Session::bang_trigger_at (int32_t route_index, int32_t row_index) +Session::bang_trigger_at (int32_t route_index, int32_t row_index, float velocity) { /* this is a convenience function for simple control surfaces to bang a trigger without any regards to banking */ @@ -1747,7 +1747,7 @@ Session::bang_trigger_at (int32_t route_index, int32_t row_index) continue; } if (index == route_index) { - r->triggerbox()->bang_trigger_at(row_index); + r->triggerbox()->bang_trigger_at(row_index, velocity); return true; } index++; diff --git a/libs/ardour/triggerbox.cc b/libs/ardour/triggerbox.cc index 80c8b1d8c5..714d9710f8 100644 --- a/libs/ardour/triggerbox.cc +++ b/libs/ardour/triggerbox.cc @@ -560,11 +560,12 @@ Trigger::set_ui (void* p) } void -Trigger::bang () +Trigger::bang (float velocity) { if (!_region) { return; } + _pending_velocity_gain = velocity; _bang.fetch_add (1); DEBUG_TRACE (DEBUG::Triggers, string_compose ("bang on %1\n", _index)); } @@ -2072,7 +2073,13 @@ AudioTrigger::audio_run (BufferSet& bufs, samplepos_t start_sample, samplepos_t AudioBuffer& buf (bufs.get_audio (chn)); Sample* src = do_stretch ? bufp[channel] : (data[channel] + read_index); - gain_t gain = _velocity_gain * _gain; //incorporate the gain from velocity_effect + gain_t gain; + + if (_velocity_effect) { + gain = (_velocity_effect * _velocity_gain) * _gain; + } else { + gain = _gain; + } if (gain != 1.0f) { buf.accumulate_with_gain_from (src, from_stretcher, gain, dest_offset); @@ -3762,11 +3769,11 @@ TriggerBox::stop_all_quantized () } void -TriggerBox::bang_trigger_at (Triggers::size_type row) +TriggerBox::bang_trigger_at (Triggers::size_type row, float velocity) { TriggerPtr t = trigger(row); if (t && t->region()) { - t->bang(); + t->bang (velocity); } else { /* by convention, an empty slot is effectively a STOP button */ stop_all_quantized();