generalize VCA assign/unassign code.
authorPaul Davis <paul@linuxaudiosystems.com>
Mon, 25 Apr 2016 16:31:18 +0000 (12:31 -0400)
committerPaul Davis <paul@linuxaudiosystems.com>
Tue, 31 May 2016 19:30:41 +0000 (15:30 -0400)
Need to share this approach across Slavables

libs/ardour/vca.cc

index d1e93cc40350c5be84975721eb6a3c5936ef252d..2d1fbdec8fa929764ff0417d30821b1b9960a11d 100644 (file)
@@ -164,9 +164,26 @@ VCA::clear_all_solo_state ()
 int
 VCA::assign_controls (boost::shared_ptr<VCA> vca)
 {
-       _gain_control->add_master (vca->gain_control());
-       _solo_control->add_master (vca->solo_control());
-       _mute_control->add_master (vca->mute_control());
+       boost::shared_ptr<SlavableAutomationControl> slave;
+       boost::shared_ptr<AutomationControl> master;
+       AutomationType types[] = {
+               GainAutomation,
+               SoloAutomation,
+               MuteAutomation,
+               RecEnableAutomation,
+               MonitoringAutomation,
+               NullAutomation
+       };
+
+       for (uint32_t n = 0; types[n] != NullAutomation; ++n) {
+
+               slave = boost::dynamic_pointer_cast<SlavableAutomationControl> (automation_control (types[n]));
+               master = vca->automation_control (types[n]);
+
+               if (slave && master) {
+                       slave->add_master (master);
+               }
+       }
 
        return 0;
 }
@@ -174,15 +191,26 @@ VCA::assign_controls (boost::shared_ptr<VCA> vca)
 int
 VCA::unassign_controls (boost::shared_ptr<VCA> vca)
 {
-       if (!vca) {
-               /* unassign from all */
-               _gain_control->clear_masters ();
-               _solo_control->clear_masters ();
-               _mute_control->clear_masters ();
-       } else {
-               _gain_control->remove_master (vca->gain_control());
-               _solo_control->remove_master (vca->solo_control());
-               _mute_control->remove_master (vca->mute_control());
+       boost::shared_ptr<SlavableAutomationControl> slave;
+       boost::shared_ptr<AutomationControl> master;
+       AutomationType types[] = {
+               GainAutomation,
+               SoloAutomation,
+               MuteAutomation,
+               RecEnableAutomation,
+               MonitoringAutomation,
+               NullAutomation
+       };
+
+       for (uint32_t n = 0; types[n] != NullAutomation; ++n) {
+
+               slave = boost::dynamic_pointer_cast<SlavableAutomationControl> (automation_control (types[n]));
+               if (!vca) {
+                       /* unassign from all */
+                       slave->clear_masters ();
+               } else {
+                       slave->remove_master (master);
+               }
        }
 
        return 0;