Introduce a macro for imprecise configurations
[ardour.git] / libs / ardour / control_group.cc
index 6752940d27c421b502f3c155fe4cc56866ebc0fe..51a1515c6a39ab3d8f9bd81e5e1ae19d672b12a6 100644 (file)
@@ -44,7 +44,12 @@ void
 ControlGroup::set_active (bool yn)
 {
        _active = yn;
-       std::cerr << " CG for " << enum_2_string ((AutomationType) _parameter.type()) << " now active ? " << _active << std::endl;
+}
+
+void
+ControlGroup::set_mode (Mode m)
+{
+       _mode = m;
 }
 
 void
@@ -104,9 +109,19 @@ ControlGroup::control_going_away (boost::weak_ptr<AutomationControl> wac)
 int
 ControlGroup::remove_control (boost::shared_ptr<AutomationControl> ac)
 {
-       Glib::Threads::RWLock::WriterLock lm (controls_lock);
+       int erased;
+
+       {
+               Glib::Threads::RWLock::WriterLock lm (controls_lock);
+               erased = _controls.erase (ac->id());
+       }
+
+       if (erased) {
+               ac->set_group (boost::shared_ptr<ControlGroup>());
+       }
+
        /* return zero if erased, non-zero otherwise */
-       return !(_controls.erase (ac->id()) > 0);
+       return !erased;
 }
 
 int
@@ -146,6 +161,10 @@ ControlGroup::set_group_value (boost::shared_ptr<AutomationControl> control, dou
 
        control->set_value (val, Controllable::ForGroup);
 
+       if (!_active) {
+               return;
+       }
+
        /* now propagate across the group */
 
        Glib::Threads::RWLock::ReaderLock lm (controls_lock);
@@ -172,6 +191,11 @@ ControlGroup::set_group_value (boost::shared_ptr<AutomationControl> control, dou
 
 /*---- GAIN CONTROL GROUP -----------*/
 
+GainControlGroup::GainControlGroup ()
+       : ControlGroup (GainAutomation)
+{
+}
+
 gain_t
 GainControlGroup::get_min_factor (gain_t factor)
 {
@@ -222,11 +246,11 @@ GainControlGroup::get_max_factor (gain_t factor)
 void
 GainControlGroup::set_group_value (boost::shared_ptr<AutomationControl> control, double val)
 {
-       /* set the primary control */
-
-       control->set_value (val, Controllable::ForGroup);
-
-       /* now propagate across the group */
+       if (!_active) {
+               /* set the primary control */
+               control->set_value (val, Controllable::ForGroup);
+               return;
+       }
 
        Glib::Threads::RWLock::ReaderLock lm (controls_lock);
 
@@ -245,8 +269,9 @@ GainControlGroup::set_group_value (boost::shared_ptr<AutomationControl> control,
 
                delta -= usable_gain;
 
-               if (delta == 0.0f)
+               if (delta == 0.0f) {
                        return;
+               }
 
                gain_t factor = delta / usable_gain;
 
@@ -264,6 +289,12 @@ GainControlGroup::set_group_value (boost::shared_ptr<AutomationControl> control,
                        }
                }
 
+               /* set the primary control */
+
+               control->set_value (val, Controllable::ForGroup);
+
+               /* now propagate across the group */
+
                for (ControlMap::iterator c = _controls.begin(); c != _controls.end(); ++c) {
                        if (c->second == control) {
                                continue;
@@ -278,10 +309,10 @@ GainControlGroup::set_group_value (boost::shared_ptr<AutomationControl> control,
 
        } else {
 
+               /* just set entire group */
+
                for (ControlMap::iterator c = _controls.begin(); c != _controls.end(); ++c) {
-                       if (c->second != control) {
-                               c->second->set_value (val, Controllable::ForGroup);
-                       }
+                       c->second->set_value (val, Controllable::ForGroup);
                }
        }
 }