OSC: Make pan controls work properly with MB too.
[ardour.git] / libs / ardour / slavable_automation_control.cc
index 78a1cc192d87ca11b619cf8485fa930f2dca6ae4..d4002343e881e48909eb37e7c54b0da16e00d4a4 100644 (file)
@@ -127,7 +127,8 @@ SlavableAutomationControl::add_master (boost::shared_ptr<AutomationControl> m)
 
                /* ratio will be recomputed below */
 
-               res = _masters.insert (make_pair<PBD::ID,MasterRecord> (m->id(), MasterRecord (m, 1.0)));
+               pair<PBD::ID,MasterRecord> newpair (m->id(), MasterRecord (m, 1.0));
+               res = _masters.insert (newpair);
 
                if (res.second) {
 
@@ -138,10 +139,18 @@ SlavableAutomationControl::add_master (boost::shared_ptr<AutomationControl> m)
                           itself.
                        */
 
-                       m->DropReferences.connect_same_thread (masters_connections, boost::bind (&SlavableAutomationControl::master_going_away, this, m));
+                       m->DropReferences.connect_same_thread (masters_connections, boost::bind (&SlavableAutomationControl::master_going_away, this, boost::weak_ptr<AutomationControl>(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.
+                       /* 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 this also makes it safe to store a
+                          boost::shared_ptr<AutomationControl> in the functor,
+                          since we know we will destroy the functor when the 
+                          connection is destroyed, which happens when we
+                          disconnect from the master (for any reason).
 
                           Note that we fix the "from_self" argument that will
                           be given to our own Changed signal to "false",
@@ -199,7 +208,7 @@ SlavableAutomationControl::update_boolean_masters_records (boost::shared_ptr<Aut
                           really) which have more than a simple scalar
                           value. For example, the master may be a mute control
                           which can be muted_by_self() and/or
-                          muted_by_others(). When either of those two
+                          muted_by_masters(). When either of those two
                           conditions changes, Changed() will be emitted, even
                           though ::get_value() will return the same value each
                           time (1.0 if either are true, 0.0 if neither is).
@@ -245,13 +254,18 @@ SlavableAutomationControl::remove_master (boost::shared_ptr<AutomationControl> m
                Glib::Threads::RWLock::WriterLock lm (master_lock);
                current_value = get_value_locked ();
                erased = _masters.erase (m->id());
-               if (erased) {
+               if (erased && !_session.deletion_in_progress()) {
                        recompute_masters_ratios (current_value);
                }
                masters_left = _masters.size ();
                new_value = get_value_locked ();
        }
 
+       if (_session.deletion_in_progress()) {
+               /* no reason to care about new values or sending signals */
+               return;
+       }
+
        if (erased) {
                MasterStatusChange (); /* EMIT SIGNAL */
        }