gain controls are supposed to be "gain-like"
[ardour.git] / libs / ardour / slavable_automation_control.cc
index 71769ad15578f7e7ce30a941cb692808f51f61f1..a80598439d3710100c9711a9ebac7df1bc2f83d6 100644 (file)
@@ -32,8 +32,9 @@ SlavableAutomationControl::SlavableAutomationControl(ARDOUR::Session& s,
                                                      const Evoral::Parameter&                  parameter,
                                                      const ParameterDescriptor&                desc,
                                                      boost::shared_ptr<ARDOUR::AutomationList> l,
-                                                     const std::string&                        name)
-       : AutomationControl (s, parameter, desc, l, name)
+                                                     const std::string&                        name,
+                                                     Controllable::Flag                        flags)
+       : AutomationControl (s, parameter, desc, l, name, flags)
 {
 }
 
@@ -141,8 +142,16 @@ SlavableAutomationControl::add_master (boost::shared_ptr<AutomationControl> 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",
@@ -242,18 +251,22 @@ SlavableAutomationControl::remove_master (boost::shared_ptr<AutomationControl> m
 
        pre_remove_master (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 */
        }