Move RouteGroup color into libardour.
[ardour.git] / libs / ardour / route_group.cc
index 291806c8cb4055cfbef3ee054f6e7f9cda29bd97..c41a890a02d68eef7528cb0174342213cb48d29b 100644 (file)
@@ -24,6 +24,7 @@
 #include "pbd/error.h"
 #include "pbd/enumwriter.h"
 #include "pbd/strsplit.h"
+#include "pbd/types_convert.h"
 #include "pbd/debug.h"
 
 #include "ardour/amp.h"
@@ -108,6 +109,7 @@ RouteGroup::RouteGroup (Session& s, const string &n)
        , _rec_enable_group (new ControlGroup (RecEnableAutomation))
        , _gain_group (new GainControlGroup ())
        , _monitoring_group (new ControlGroup (MonitoringAutomation))
+       , _rgba (0)
 {
        _xml_node_name = X_("RouteGroup");
 
@@ -233,15 +235,30 @@ RouteGroup::remove (boost::shared_ptr<Route> r)
        return -1;
 }
 
+void
+RouteGroup::set_rgba (uint32_t color) {
+       _rgba = color;
+
+       PBD::PropertyChange change;
+       change.add (Properties::color);
+       PropertyChanged (change);
+
+       if (!is_color ()) {
+               return;
+       }
+
+       for (RouteList::const_iterator i = routes->begin(); i != routes->end(); ++i) {
+               (*i)->presentation_info().PropertyChanged (Properties::color);
+       }
+}
 
 XMLNode&
 RouteGroup::get_state ()
 {
        XMLNode *node = new XMLNode ("RouteGroup");
 
-       char buf[64];
-       id().print (buf, sizeof (buf));
-       node->add_property ("id", buf);
+       node->set_property ("id", id());
+       node->set_property ("rgba", _rgba);
 
        add_properties (*node);
 
@@ -252,7 +269,7 @@ RouteGroup::get_state ()
                        str << (*i)->id () << ' ';
                }
 
-               node->add_property ("routes", str.str());
+               node->set_property ("routes", str.str());
        }
 
        return *node;
@@ -265,13 +282,13 @@ RouteGroup::set_state (const XMLNode& node, int version)
                return set_state_2X (node, version);
        }
 
-       XMLProperty const * prop;
-
        set_id (node);
        set_values (node);
+       node.get_property ("rgba", _rgba);
 
-       if ((prop = node.property ("routes")) != 0) {
-               stringstream str (prop->value());
+       std::string routes;
+       if (node.get_property ("routes", routes)) {
+               stringstream str (routes);
                vector<string> ids;
                split (str.str(), ids, ' ');
 
@@ -608,6 +625,7 @@ RouteGroup::push_to_groups ()
                _gain_group->set_active (false);
                _solo_group->set_active (false);
                _mute_group->set_active (false);
+
                _rec_enable_group->set_active (false);
                _monitoring_group->set_active (false);
        }
@@ -630,8 +648,19 @@ RouteGroup::assign_master (boost::shared_ptr<VCA> master)
                (*r)->assign (master, false);
        }
 
+       bool used_to_share_gain = false;
+
+       if (is_gain()) {
+               used_to_share_gain = true;
+       }
+
        group_master = master;
        _group_master_number = master->number();
+       _gain_group->set_active (false);
+
+       if (used_to_share_gain) {
+               send_change (PropertyChange (Properties::group_gain));
+       }
 }
 
 void
@@ -653,6 +682,18 @@ RouteGroup::unassign_master (boost::shared_ptr<VCA> master)
 
        group_master.reset ();
        _group_master_number = -1;
+
+       /* this is slightly tricky: is_gain() will return whether or not
+          the group is supposed to be sharing gain adjustment, and now that
+          we've reset _group_master_number to -1, it will reflect the user's
+          intentions correctly. Since there was a master before, and now there
+          is not, we are going to reactivate gain sharing ... and then tell
+          the world about it.
+       */
+       if (is_gain()) {
+               _gain_group->set_active (true);
+               send_change (PropertyChange (Properties::group_gain));
+       }
 }
 
 bool