From e8822e76d605cd49e758225081bcef339de58224 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Fri, 20 Sep 2019 20:25:04 +0200 Subject: Add abstract API for latency compensated sends This is in preparation for MixbusSends that are not derived from Delivery : IOProcessor. --- libs/ardour/ardour/send.h | 35 ++++++++++++++++++++++++++++------- libs/ardour/route.cc | 3 ++- libs/ardour/send.cc | 12 ++++++++---- libs/ardour/session.cc | 2 +- 4 files changed, 39 insertions(+), 13 deletions(-) diff --git a/libs/ardour/ardour/send.h b/libs/ardour/ardour/send.h index 94e0070bbd..e711e68685 100644 --- a/libs/ardour/ardour/send.h +++ b/libs/ardour/ardour/send.h @@ -37,7 +37,32 @@ class Amp; class GainControl; class DelayLine; -class LIBARDOUR_API Send : public Delivery +/** Internal Abstraction for Sends (and MixbusSends) */ +class LIBARDOUR_API LatentSend +{ +public: + LatentSend (); + virtual ~LatentSend() {} + + samplecnt_t get_delay_in () const { return _delay_in; } + samplecnt_t get_delay_out () const { return _delay_out; } + + /* should only be called by Route::update_signal_latency */ + virtual void set_delay_in (samplecnt_t) = 0; + + /* should only be called by InternalReturn::set_playback_offset + * (via Route::update_signal_latency) + */ + virtual void set_delay_out (samplecnt_t, size_t bus = 0) = 0; + + static PBD::Signal0 ChangedLatency; + +protected: + samplecnt_t _delay_in; + samplecnt_t _delay_out; +}; + +class LIBARDOUR_API Send : public Delivery, public LatentSend { public: Send (Session&, boost::shared_ptr pannable, boost::shared_ptr, Delivery::Role r = Delivery::Send, bool ignore_bitslot = false); @@ -69,14 +94,12 @@ public: bool configure_io (ChanCount in, ChanCount out); /* latency compensation */ - void set_delay_in (samplecnt_t); // should only be called by Route::update_signal_latency - void set_delay_out (samplecnt_t); // should only be called by InternalReturn::set_playback_offset (via Route::update_signal_latency) + void set_delay_in (samplecnt_t); + void set_delay_out (samplecnt_t, size_t bus = 0); samplecnt_t get_delay_in () const { return _delay_in; } samplecnt_t get_delay_out () const { return _delay_out; } samplecnt_t signal_latency () const; - static PBD::Signal0 ChangedLatency; - void activate (); void deactivate (); @@ -106,8 +129,6 @@ private: int set_state_2X (XMLNode const &, int); uint32_t _bitslot; - samplecnt_t _delay_in; - samplecnt_t _delay_out; bool _remove_on_disconnect; }; diff --git a/libs/ardour/route.cc b/libs/ardour/route.cc index 962f23bda1..49d8172829 100644 --- a/libs/ardour/route.cc +++ b/libs/ardour/route.cc @@ -4115,7 +4115,7 @@ Route::update_signal_latency (bool apply_to_delayline) samplecnt_t l_in = 0; samplecnt_t l_out = _output->effective_latency (); for (ProcessorList::reverse_iterator i = _processors.rbegin(); i != _processors.rend(); ++i) { - if (boost::shared_ptr snd = boost::dynamic_pointer_cast (*i)) { + if (boost::shared_ptr snd = boost::dynamic_pointer_cast (*i)) { snd->set_delay_in (l_out + _output->latency()); } @@ -4155,6 +4155,7 @@ Route::update_signal_latency (bool apply_to_delayline) snd->output ()->set_private_port_latencies (capt_lat_in + l_in, false); /* take send-target's playback latency into account */ snd->set_delay_out (snd->output ()->connected_latency (true)); + /* InternalReturn::set_playback_offset() below, also calls set_delay_out() */ } } diff --git a/libs/ardour/send.cc b/libs/ardour/send.cc index 8e530efeba..950ee0b74d 100644 --- a/libs/ardour/send.cc +++ b/libs/ardour/send.cc @@ -49,7 +49,13 @@ using namespace ARDOUR; using namespace PBD; using namespace std; -PBD::Signal0 Send::ChangedLatency; +PBD::Signal0 LatentSend::ChangedLatency; + +LatentSend::LatentSend () + : _delay_in (0) + , _delay_out (0) +{ +} string Send::name_and_id_new_send (Session& s, Role r, uint32_t& bitslot, bool ignore_bitslot) @@ -83,8 +89,6 @@ Send::name_and_id_new_send (Session& s, Role r, uint32_t& bitslot, bool ignore_b Send::Send (Session& s, boost::shared_ptr p, boost::shared_ptr mm, Role r, bool ignore_bitslot) : Delivery (s, p, mm, name_and_id_new_send (s, r, _bitslot, ignore_bitslot), r) , _metering (false) - , _delay_in (0) - , _delay_out (0) , _remove_on_disconnect (false) { if (_role == Listen) { @@ -198,7 +202,7 @@ Send::set_delay_in (samplecnt_t delay) } void -Send::set_delay_out (samplecnt_t delay) +Send::set_delay_out (samplecnt_t delay, size_t /*bus*/) { if (_delay_out == delay) { return; diff --git a/libs/ardour/session.cc b/libs/ardour/session.cc index a042dbf4f3..7cdcc894a3 100644 --- a/libs/ardour/session.cc +++ b/libs/ardour/session.cc @@ -460,7 +460,7 @@ Session::Session (AudioEngine &eng, StartTimeChanged.connect_same_thread (*this, boost::bind (&Session::start_time_changed, this, _1)); EndTimeChanged.connect_same_thread (*this, boost::bind (&Session::end_time_changed, this, _1)); - Send::ChangedLatency.connect_same_thread (*this, boost::bind (&Session::send_latency_compensation_change, this)); + LatentSend::ChangedLatency.connect_same_thread (*this, boost::bind (&Session::send_latency_compensation_change, this)); emit_thread_start (); auto_connect_thread_start (); -- cgit v1.2.3