RAII collect processor-change signals

Multimedia / Ardour - Robin Gareus [gareus.org] - 18 April 2020 21:54 EDT



###

diff --git a/libs/ardour/ardour/session.h b/libs/ardour/ardour/session.h
index 4c93ecb95f..4c259232f5 100644
--- a/libs/ardour/ardour/session.h
+++ b/libs/ardour/ardour/session.h
@@ -646,23 +646,27 @@ public:
};

class ProcessorChangeBlocker {
- public:
- ProcessorChangeBlocker (Session* s, bool rc = true)
- : _session (s)
- , _reconfigure_on_delete (rc)
- {
- g_atomic_int_inc (&s->_ignore_route_processor_changes);
- }
- ~ProcessorChangeBlocker () {
- if (g_atomic_int_dec_and_test (&_session->_ignore_route_processor_changes)) {
+ public:
+ ProcessorChangeBlocker (Session* s, bool rc = true)
+ : _session (s)
+ , _reconfigure_on_delete (rc)
+ {
+ g_atomic_int_inc (&s->_ignore_route_processor_changes);
+ }
+
+ ~ProcessorChangeBlocker ()
+ {
+ if (g_atomic_int_dec_and_test (&_session->_ignore_route_processor_changes)) {
+ if (g_atomic_int_compare_and_exchange (&_session->_ignored_a_processor_change, 1, 0)) {
if (_reconfigure_on_delete) {
_session->route_processors_changed (RouteProcessorChange ());
}
}
}
- private:
- Session* _session;
- bool _reconfigure_on_delete;
+ }
+ private:
+ Session* _session;
+ bool _reconfigure_on_delete;
};

RouteGroup* new_route_group (const std::string&);
@@ -2128,6 +2132,7 @@ private:

friend class ProcessorChangeBlocker;
gint _ignore_route_processor_changes; /* atomic */
+ gint _ignored_a_processor_change;

MidiClockTicker* midi_clock;

diff --git a/libs/ardour/session.cc b/libs/ardour/session.cc
index 0c73acdaa5..253a80a4b3 100644
--- a/libs/ardour/session.cc
+++ b/libs/ardour/session.cc
@@ -314,6 +314,7 @@ Session::Session (AudioEngine &eng,
, _suspend_timecode_transmission (0)
, _speakers (new Speakers)
, _ignore_route_processor_changes (0)
+ , _ignored_a_processor_change (0)
, midi_clock (0)
, _scene_changer (0)
, _midi_ports (0)
diff --git a/libs/ardour/session_process.cc b/libs/ardour/session_process.cc
index f5613d3af4..828299d8e0 100644
--- a/libs/ardour/session_process.cc
+++ b/libs/ardour/session_process.cc
@@ -102,14 +102,17 @@ Session::process (pframes_t nframes)
* Route::process_output_buffers() but various functions
* callig it hold a _processor_lock reader-lock
*/
- boost::shared_ptr r = routes.reader ();
bool one_or_more_routes_declicking = false;
- for (RouteList::const_iterator i = r->begin(); i != r->end(); ++i) {
- if ((*i)->apply_processor_changes_rt()) {
- _rt_emit_pending = true;
- }
- if ((*i)->declick_in_progress()) {
- one_or_more_routes_declicking = true;
+ {
+ ProcessorChangeBlocker pcb (this);
+ boost::shared_ptr r = routes.reader ();
+ for (RouteList::const_iterator i = r->begin(); i != r->end(); ++i) {
+ if ((*i)->apply_processor_changes_rt()) {
+ _rt_emit_pending = true;
+ }
+ if ((*i)->declick_in_progress()) {
+ one_or_more_routes_declicking = true;
+ }
}
}

@@ -1051,6 +1054,7 @@ Session::emit_route_signals ()
{
// TODO use RAII to allow using these signals in other places
BatchUpdateStart(); /* EMIT SIGNAL */
+ ProcessorChangeBlocker pcb (this);
boost::shared_ptr r = routes.reader ();
for (RouteList::const_iterator ci = r->begin(); ci != r->end(); ++ci) {
(*ci)->emit_pending_signals ();
diff --git a/libs/ardour/session_transport.cc b/libs/ardour/session_transport.cc
index f136eebc5d..2924629d88 100644
--- a/libs/ardour/session_transport.cc
+++ b/libs/ardour/session_transport.cc
@@ -1851,6 +1851,7 @@ void
Session::route_processors_changed (RouteProcessorChange c)
{
if (g_atomic_int_get (&_ignore_route_processor_changes) > 0) {
+ g_atomic_int_set (&_ignored_a_processor_change, 1);
return;
}

9875a95829 RAII collect processor-change signals
libs/ardour/ardour/session.h | 29 +++++++++++++++++------------
libs/ardour/session.cc | 1 +
libs/ardour/session_process.cc | 18 +++++++++++-------
libs/ardour/session_transport.cc | 1 +
4 files changed, 30 insertions(+), 19 deletions(-)

  • Share