+
+/** Set the color of the tab of a route group */
+void
+GroupTabs::set_group_color (RouteGroup* group, Gdk::Color color)
+{
+ assert (group);
+
+ /* Hack to disallow black route groups; force a dark grey instead */
+ if (color.get_red() == 0 && color.get_green() == 0 && color.get_blue() == 0) {
+ color.set_grey_p (0.1);
+ }
+
+ GUIObjectState& gui_state = *ARDOUR_UI::instance()->gui_object_state;
+
+ char buf[64];
+ snprintf (buf, sizeof (buf), "%d:%d:%d", color.get_red(), color.get_green(), color.get_blue());
+ gui_state.set_property (group_gui_id (group), "color", buf);
+
+ /* the group color change notification */
+
+ PBD::PropertyChange change;
+ change.add (Properties::color);
+ group->PropertyChanged (change);
+
+ /* This is a bit of a hack, but this might change
+ our route's effective color, so emit gui_changed
+ for our routes.
+ */
+
+ emit_gui_changed_for_members (group);
+}
+
+/** @return the ID string to use for the GUI state of a route group */
+string
+GroupTabs::group_gui_id (RouteGroup* group)
+{
+ assert (group);
+
+ char buf[64];
+ snprintf (buf, sizeof (buf), "route_group %s", group->id().to_s().c_str ());
+
+ return buf;
+}
+
+/** @return the color to use for a route group tab */
+Gdk::Color
+GroupTabs::group_color (RouteGroup* group)
+{
+ assert (group);
+
+ GUIObjectState& gui_state = *ARDOUR_UI::instance()->gui_object_state;
+
+ string const gui_id = group_gui_id (group);
+
+ bool empty;
+ string const color = gui_state.get_string (gui_id, "color", &empty);
+ if (empty) {
+ /* no color has yet been set, so use a random one */
+ Gdk::Color const color = unique_random_color (_used_colors);
+ set_group_color (group, color);
+ return color;
+ }
+
+ Gdk::Color c;
+
+ int r, g, b;
+
+ sscanf (color.c_str(), "%d:%d:%d", &r, &g, &b);
+
+ c.set_red (r);
+ c.set_green (g);
+ c.set_blue (b);
+
+ return c;
+}
+
+void
+GroupTabs::route_group_property_changed (RouteGroup* rg)
+{
+ /* This is a bit of a hack, but this might change
+ our route's effective color, so emit gui_changed
+ for our routes.
+ */
+
+ emit_gui_changed_for_members (rg);
+
+ set_dirty ();
+}
+
+void
+GroupTabs::route_added_to_route_group (RouteGroup*, boost::weak_ptr<Route> w)
+{
+ /* Similarly-spirited hack as in route_group_property_changed */
+
+ boost::shared_ptr<Route> r = w.lock ();
+ if (!r) {
+ return;
+ }
+
+ r->gui_changed (X_("color"), 0);
+
+ set_dirty ();
+}
+
+void
+GroupTabs::route_removed_from_route_group (RouteGroup*, boost::weak_ptr<Route> w)
+{
+ /* Similarly-spirited hack as in route_group_property_changed */
+
+ boost::shared_ptr<Route> r = w.lock ();
+ if (!r) {
+ return;
+ }
+
+ r->gui_changed (X_("color"), 0);
+
+ set_dirty ();
+}
+
+void
+GroupTabs::emit_gui_changed_for_members (RouteGroup* rg)
+{
+ for (RouteList::iterator i = rg->route_list()->begin(); i != rg->route_list()->end(); ++i) {
+ (*i)->gui_changed (X_("color"), 0);
+ }
+}