- double current_value;
- double new_value;
- std::pair<Masters::iterator,bool> res;
-
- {
- Glib::Threads::RWLock::WriterLock lm (master_lock);
- current_value = get_value_locked ();
-
- /* ratio will be recomputed below */
-
- res = _masters.insert (make_pair<PBD::ID,MasterRecord> (m->id(), MasterRecord (m, 1.0)));
-
- if (res.second) {
-
- recompute_masters_ratios (current_value);
-
- /* note that we bind @param m as a weak_ptr<AutomationControl>, thus
- avoiding holding a reference to the control in the binding
- itself.
- */
-
- m->DropReferences.connect_same_thread (masters_connections, boost::bind (&AutomationControl::master_going_away, this, m));
-
- /* Store the connection inside the MasterRecord, so that when we destroy it, the connection is destroyed
- and we no longer hear about changes to the AutomationControl.
-
- Note that we fix the "from_self" argument that will
- be given to our own Changed signal to "false",
- because the change came from the master.
- */
-
-
- m->Changed.connect_same_thread (res.first->second.connection, boost::bind (&PBD::Signal2<void,bool,Controllable::GroupControlDisposition>::operator(), &Changed, false, _2));
- }
-
- new_value = get_value_locked ();
- }
-
- if (res.second) {
- MasterStatusChange (); /* EMIT SIGNAL */
- }
-
- if (new_value != current_value) {
- /* effective value changed by master */
- Changed (false, Controllable::NoGroup);
- }
-
-}
-
-void
-AutomationControl::master_going_away (boost::weak_ptr<AutomationControl> wm)
-{
- boost::shared_ptr<AutomationControl> m = wm.lock();
- if (m) {
- remove_master (m);
- }
-}
-
-void
-AutomationControl::remove_master (boost::shared_ptr<AutomationControl> m)
-{
- double current_value;
- double new_value;
- Masters::size_type erased = 0;
-
- {
- Glib::Threads::RWLock::WriterLock lm (master_lock);
- current_value = get_value_locked ();
- erased = _masters.erase (m->id());
- if (erased) {
- recompute_masters_ratios (current_value);
- }
- new_value = get_value_locked ();
- }
-
- if (erased) {
- MasterStatusChange (); /* EMIT SIGNAL */
- }
-
- if (new_value != current_value) {
- Changed (false, Controllable::NoGroup);
- }