diff --git a/libs/surfaces/osc/osc_cue_observer.cc b/libs/surfaces/osc/osc_cue_observer.cc index 8300b2ff48..8ca17d27a3 100644 --- a/libs/surfaces/osc/osc_cue_observer.cc +++ b/libs/surfaces/osc/osc_cue_observer.cc @@ -1,5 +1,6 @@ /* * Copyright (C) 2017-2018 Len Ovens + * Copyright (C) 2024 Robin Gareus * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -90,12 +91,12 @@ OSCCueObserver::refresh_strip (std::shared_ptr new_strip, Sor _strip->PropertyChanged.connect (strip_connections, MISSING_INVALIDATOR, std::bind (&OSCCueObserver::name_changed, this,_1, 0), OSC::instance()); name_changed (ARDOUR::Properties::name, 0); - _strip->mute_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, std::bind (&OSCCueObserver::send_change_message, this, X_("/cue/mute"), 0, _strip->mute_control()), OSC::instance()); + _strip->mute_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, std::bind (&OSCCueObserver::send_change_message, this, X_("/cue/mute"), 0, std::weak_ptr(_strip->mute_control())), OSC::instance()); send_change_message (X_("/cue/mute"), 0, _strip->mute_control()); gain_timeout.push_back (0); _last_gain[0] = -1; // unused - _strip->gain_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, std::bind (&OSCCueObserver::send_gain_message, this, 0, _strip->gain_control(), false), OSC::instance()); + _strip->gain_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, std::bind (&OSCCueObserver::send_gain_message, this, 0, std::weak_ptr(_strip->gain_control()), false), OSC::instance()); send_gain_message (0, _strip->gain_control(), true); send_init (); @@ -163,13 +164,14 @@ OSCCueObserver::send_init() if (send->gain_control()) { gain_timeout.push_back (0); _last_gain[i + 1] = -1.0; - send->gain_control()->Changed.connect (send_connections, MISSING_INVALIDATOR, std::bind (&OSCCueObserver::send_gain_message, this, i + 1, send->gain_control(), false), OSC::instance()); + send->gain_control()->Changed.connect (send_connections, MISSING_INVALIDATOR, std::bind (&OSCCueObserver::send_gain_message, this, i + 1, std::weak_ptr(send->gain_control()), false), OSC::instance()); send_gain_message (i + 1, send->gain_control(), true); } std::shared_ptr proc = std::dynamic_pointer_cast (send); - proc->ActiveChanged.connect (send_connections, MISSING_INVALIDATOR, std::bind (&OSCCueObserver::send_enabled_message, this, X_("/cue/send/enable"), i + 1, proc), OSC::instance()); - send_enabled_message (X_("/cue/send/enable"), i + 1, proc); + std::weak_ptr wproc (proc); + proc->ActiveChanged.connect (send_connections, MISSING_INVALIDATOR, std::bind (&OSCCueObserver::send_enabled_message, this, X_("/cue/send/enable"), i + 1, wproc), OSC::instance()); + send_enabled_message (X_("/cue/send/enable"), i + 1, wproc); } } @@ -218,8 +220,12 @@ OSCCueObserver::name_changed (const PBD::PropertyChange& what_changed, uint32_t } void -OSCCueObserver::send_change_message (string path, uint32_t id, std::shared_ptr controllable) +OSCCueObserver::send_change_message (string path, uint32_t id, std::weak_ptr weak_controllable) { + std::shared_ptr controllable = weak_controllable.lock (); + if (!controllable) { + return; + } if (id) { path = string_compose("%1/%2", path, id); } @@ -228,8 +234,12 @@ OSCCueObserver::send_change_message (string path, uint32_t id, std::shared_ptr controllable, bool force) +OSCCueObserver::send_gain_message (uint32_t id, std::weak_ptr weak_controllable, bool force) { + std::shared_ptr controllable = weak_controllable.lock (); + if (!controllable) { + return; + } if (_last_gain[id] != controllable->get_value()) { _last_gain[id] = controllable->get_value(); } else { @@ -247,8 +257,12 @@ OSCCueObserver::send_gain_message (uint32_t id, std::shared_ptr c } void -OSCCueObserver::send_enabled_message (std::string path, uint32_t id, std::shared_ptr proc) +OSCCueObserver::send_enabled_message (std::string path, uint32_t id, std::weak_ptr weak_proc) { + std::shared_ptr proc = weak_proc.lock (); + if (!proc) { + return; + } if (id) { _osc.float_message_with_id (path, id, (float) proc->enabled(), true, addr); } else { diff --git a/libs/surfaces/osc/osc_cue_observer.h b/libs/surfaces/osc/osc_cue_observer.h index 97baa31da4..b31bf56596 100644 --- a/libs/surfaces/osc/osc_cue_observer.h +++ b/libs/surfaces/osc/osc_cue_observer.h @@ -1,5 +1,6 @@ /* * Copyright (C) 2017-2018 Len Ovens + * Copyright (C) 2024 Robin Gareus * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -64,9 +65,9 @@ class OSCCueObserver std::map _last_gain; void name_changed (const PBD::PropertyChange& what_changed, uint32_t id); - void send_change_message (std::string path, uint32_t id, std::shared_ptr controllable); - void send_gain_message (uint32_t id, std::shared_ptr controllable, bool force); - void send_enabled_message (std::string path, uint32_t id, std::shared_ptr proc); + void send_change_message (std::string path, uint32_t id, std::weak_ptr controllable); + void send_gain_message (uint32_t id, std::weak_ptr controllable, bool force); + void send_enabled_message (std::string path, uint32_t id, std::weak_ptr proc); void send_init (void); void send_end (uint32_t new_sends_size); void send_restart (void);