RAII collect processor-change signals

This commit is contained in:
Robin Gareus 2020-04-18 23:54:24 +02:00
parent b7c7c02680
commit 9875a95829
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04
4 changed files with 30 additions and 19 deletions

View File

@ -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;

View File

@ -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)

View File

@ -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<RouteList> 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<RouteList> 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<RouteList> r = routes.reader ();
for (RouteList::const_iterator ci = r->begin(); ci != r->end(); ++ci) {
(*ci)->emit_pending_signals ();

View File

@ -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;
}