From 349d25a2d22a4dc8e6985f9ebf6d7705682a30e5 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Fri, 27 Jan 2023 23:04:15 +0100 Subject: [PATCH] Update latency compensation when sends are added or removed Previously only adding an aux-send triggered a graph-reorder but copying or deleting sends did nothing. Adding/removing an aux-send may not even change the graph, but both upstream/downstream latency can change and delaylines need to be configured (which is done by calling update_latency_compensation with force_whole_graph = true). This fixes an issue with incorrect initial latency compensation after copying a send (any later change to connections will correctly recalculate it). --- libs/ardour/ardour/types.h | 3 ++- libs/ardour/route.cc | 24 +++++++++++++++++++++--- libs/ardour/session.cc | 2 -- libs/ardour/session_transport.cc | 7 ++++++- 4 files changed, 29 insertions(+), 7 deletions(-) diff --git a/libs/ardour/ardour/types.h b/libs/ardour/ardour/types.h index fa2ecf8696..a3b395b941 100644 --- a/libs/ardour/ardour/types.h +++ b/libs/ardour/ardour/types.h @@ -703,7 +703,8 @@ struct RouteProcessorChange { enum Type { MeterPointChange = 0x1, RealTimeChange = 0x2, - GeneralChange = 0x4 + GeneralChange = 0x4, + SendReturnChange = 0x8 }; RouteProcessorChange () : type (GeneralChange), meter_visibly_changed (true) diff --git a/libs/ardour/route.cc b/libs/ardour/route.cc index ae4b096a92..09d20e4612 100644 --- a/libs/ardour/route.cc +++ b/libs/ardour/route.cc @@ -1104,6 +1104,8 @@ Route::add_processors (const ProcessorList& others, boost::shared_ptr } } + bool routing_processor_added = false; + { Glib::Threads::Mutex::Lock lx (AudioEngine::instance()->process_lock ()); Glib::Threads::RWLock::WriterLock lm (_processor_lock); @@ -1177,6 +1179,10 @@ Route::add_processors (const ProcessorList& others, boost::shared_ptr send->output()->changed.connect_same_thread (**i, boost::bind (&Route::output_change_handler, this, _1, _2)); } } + + if (boost::dynamic_pointer_cast(*i)) { + routing_processor_added = true; + } } for (ProcessorList::const_iterator i = _processors.begin(); i != _processors.end(); ++i) { @@ -1192,7 +1198,7 @@ Route::add_processors (const ProcessorList& others, boost::shared_ptr } reset_instrument_info (); - processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */ + processors_changed (RouteProcessorChange (routing_processor_added ? RouteProcessorChange::SendReturnChange : RouteProcessorChange::GeneralChange, false)); /* EMIT SIGNAL */ set_processor_positions (); if (fanout && fanout->configured () @@ -1465,6 +1471,8 @@ Route::remove_processor (boost::shared_ptr processor, ProcessorStream return 1; } + bool routing_processor_removed = false; + processor_max_streams.reset(); { @@ -1508,6 +1516,10 @@ Route::remove_processor (boost::shared_ptr processor, ProcessorStream lm.acquire (); } + if (boost::dynamic_pointer_cast(*i)) { + routing_processor_removed = true; + } + _processors.erase (i); if (configure_processors_unlocked (err, &lm)) { @@ -1536,7 +1548,7 @@ Route::remove_processor (boost::shared_ptr processor, ProcessorStream reset_instrument_info (); processor->drop_references (); - processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */ + processors_changed (RouteProcessorChange (routing_processor_removed ? RouteProcessorChange::SendReturnChange : RouteProcessorChange::GeneralChange, false)); /* EMIT SIGNAL */ set_processor_positions (); return 0; @@ -1648,6 +1660,8 @@ Route::remove_processors (const ProcessorList& to_be_deleted, ProcessorStreams* return 1; } + bool routing_processor_removed = false; + processor_max_streams.reset(); { @@ -1692,6 +1706,10 @@ Route::remove_processors (const ProcessorList& to_be_deleted, ProcessorStreams* iop->disconnect (); } + if (boost::dynamic_pointer_cast(processor)) { + routing_processor_removed = true; + } + deleted.push_back (processor); i = _processors.erase (i); } @@ -1730,7 +1748,7 @@ Route::remove_processors (const ProcessorList& to_be_deleted, ProcessorStreams* } reset_instrument_info (); - processors_changed (RouteProcessorChange ()); /* EMIT SIGNAL */ + processors_changed (RouteProcessorChange (routing_processor_removed ? RouteProcessorChange::SendReturnChange : RouteProcessorChange::GeneralChange, false)); /* EMIT SIGNAL */ set_processor_positions (); return 0; diff --git a/libs/ardour/session.cc b/libs/ardour/session.cc index 5116ef5112..7d62c9bd79 100644 --- a/libs/ardour/session.cc +++ b/libs/ardour/session.cc @@ -3468,8 +3468,6 @@ Session::add_internal_send (boost::shared_ptr dest, boost::shared_ptradd_aux_send (dest, before); - - graph_reordered (false); } void diff --git a/libs/ardour/session_transport.cc b/libs/ardour/session_transport.cc index 345869b851..2e9713f226 100644 --- a/libs/ardour/session_transport.cc +++ b/libs/ardour/session_transport.cc @@ -1896,7 +1896,12 @@ Session::route_processors_changed (RouteProcessorChange c) } resort_routes (); - update_latency_compensation (false, false); + + if (c.type == RouteProcessorChange::SendReturnChange) { + update_latency_compensation (true, false); + } else { + update_latency_compensation (false, false); + } set_dirty (); }