fix two oddities in strings
[ardour.git] / gtk2_ardour / group_tabs.cc
index 9fa9c8bf732732759a5a7c6d51d1f4eb92764e67..99a21668c14933256a4cf213f2f2905a1e32cd5e 100644 (file)
 
 #include "gui_thread.h"
 #include "route_group_dialog.h"
+#include "global_signals.h"
 #include "group_tabs.h"
 #include "keyboard.h"
 #include "i18n.h"
 #include "ardour_ui.h"
+#include "rgb_macros.h"
 #include "utils.h"
 
 using namespace std;
 using namespace Gtk;
 using namespace ARDOUR;
+using namespace ARDOUR_UI_UTILS;
 using Gtkmm2ext::Keyboard;
 
 list<Gdk::Color> GroupTabs::_used_colors;
@@ -42,7 +45,8 @@ GroupTabs::GroupTabs ()
        , _dragging (0)
        , _dragging_new_tab (0)
 {
-
+       add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::POINTER_MOTION_MASK);
+       ColorsChanged.connect (sigc::mem_fun (*this, &GroupTabs::queue_draw));  
 }
 
 GroupTabs::~GroupTabs ()
@@ -175,12 +179,14 @@ GroupTabs::on_motion_notify_event (GdkEventMotion* ev)
        set_dirty ();
        queue_draw ();
 
+       gdk_event_request_motions(ev);
+
        return true;
 }
 
 
 bool
-GroupTabs::on_button_release_event (GdkEventButton* ev)
+GroupTabs::on_button_release_event (GdkEventButton*)
 {
        if (_dragging == 0) {
                return false;
@@ -235,7 +241,7 @@ GroupTabs::on_button_release_event (GdkEventButton* ev)
 }
 
 void
-GroupTabs::render (cairo_t* cr)
+GroupTabs::render (cairo_t* cr, cairo_rectangle_t*)
 {
        if (_dragging == 0) {
                _tabs = compute_tabs ();
@@ -319,7 +325,11 @@ GroupTabs::get_menu (RouteGroup* g)
                items.push_back (MenuElem (_("Collect Group"), sigc::bind (sigc::mem_fun (*this, &GroupTabs::collect), g)));
                items.push_back (MenuElem (_("Remove Group"), sigc::bind (sigc::mem_fun (*this, &GroupTabs::remove_group), g)));
                items.push_back (SeparatorElem());
-               items.push_back (MenuElem (_("Add New Subgroup Bus"), sigc::bind (sigc::mem_fun (*this, &GroupTabs::subgroup), g, false, PreFader)));
+               if (g->has_subgroup()) {
+                       items.push_back (MenuElem (_("Remove Subgroup Bus"), sigc::bind (sigc::mem_fun (*this, &GroupTabs::un_subgroup), g)));
+               } else {
+                       items.push_back (MenuElem (_("Add New Subgroup Bus"), sigc::bind (sigc::mem_fun (*this, &GroupTabs::subgroup), g, false, PreFader)));
+               }
                items.push_back (MenuElem (_("Add New Aux Bus (pre-fader)"), sigc::bind (sigc::mem_fun (*this, &GroupTabs::subgroup), g, true, PreFader)));
                items.push_back (MenuElem (_("Add New Aux Bus (post-fader)"), sigc::bind (sigc::mem_fun (*this, &GroupTabs::subgroup), g, true, PostFader)));
        }
@@ -385,6 +395,26 @@ GroupTabs::new_from_soloed ()
        run_new_group_dialog (soloed);
 }
 
+PBD::PropertyList
+GroupTabs::default_properties () const
+{
+       PBD::PropertyList plist;
+
+       plist.add (Properties::route_active, true);
+       plist.add (Properties::active, true);
+       plist.add (Properties::gain, true);
+       plist.add (Properties::relative, true);
+       plist.add (Properties::color, true);
+       plist.add (Properties::monitoring, true);
+       plist.add (Properties::select, true);
+       plist.add (Properties::mute, true);
+       plist.add (Properties::solo, true);
+       plist.add (Properties::gain, true);
+       plist.add (Properties::recenable, true);
+
+       return plist;
+}
+
 void
 GroupTabs::run_new_group_dialog (RouteList const & rl)
 {
@@ -434,25 +464,22 @@ GroupTabs::subgroup (RouteGroup* g, bool aux, Placement placement)
        g->make_subgroup (aux, placement);
 }
 
-struct CollectSorter {
-       CollectSorter (string const & key) : _key (key) {}
+void
+GroupTabs::un_subgroup (RouteGroup* g)
+{
+       g->destroy_subgroup ();
+}
 
+struct CollectSorter {
        bool operator () (boost::shared_ptr<Route> a, boost::shared_ptr<Route> b) {
-               return a->order_key (_key) < b->order_key (_key);
+               return a->order_key () < b->order_key ();
        }
-
-       string _key;
 };
 
 struct OrderSorter {
-       OrderSorter (string const & key) : _key (key) {}
-       
        bool operator() (boost::shared_ptr<Route> a, boost::shared_ptr<Route> b) {
-               /* use of ">" forces the correct sort order */
-               return a->order_key (_key) < b->order_key (_key);
+               return a->order_key () < b->order_key ();
        }
-
-       string _key;
 };
 
 /** Collect all members of a RouteGroup so that they are together in the Editor or Mixer.
@@ -462,19 +489,19 @@ void
 GroupTabs::collect (RouteGroup* g)
 {
        boost::shared_ptr<RouteList> group_routes = g->route_list ();
-       group_routes->sort (CollectSorter (order_key ()));
+       group_routes->sort (CollectSorter ());
        int const N = group_routes->size ();
 
        RouteList::iterator i = group_routes->begin ();
        boost::shared_ptr<RouteList> routes = _session->get_routes ();
-       routes->sort (OrderSorter (order_key ()));
+       routes->sort (OrderSorter ());
        RouteList::const_iterator j = routes->begin ();
 
        int diff = 0;
        int coll = -1;
        while (i != group_routes->end() && j != routes->end()) {
 
-               int const k = (*j)->order_key (order_key ());
+               int const k = (*j)->order_key ();
 
                if (*i == *j) {
 
@@ -485,14 +512,14 @@ GroupTabs::collect (RouteGroup* g)
                                --diff;
                        }
 
-                       (*j)->set_order_key (order_key (), coll);
+                       (*j)->set_order_key (coll);
 
                        ++coll;
                        ++i;
 
                } else {
 
-                       (*j)->set_order_key (order_key (), k + diff);
+                       (*j)->set_order_key (k + diff);
 
                }
 
@@ -532,20 +559,31 @@ GroupTabs::remove_group (RouteGroup* g)
 
 /** Set the color of the tab of a route group */
 void
-GroupTabs::set_group_color (RouteGroup* group, Gdk::Color color)
+GroupTabs::set_group_color (RouteGroup* group, uint32_t color)
 {
        assert (group);
+       uint32_t r, g, b, a;
+
+       UINT_TO_RGBA (color, &r, &g, &b, &a);
 
        /* 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);
+
+       if (r == 0 && g == 0 && b == 0) {
+               r = 25;
+               g = 25;
+               b = 25;
        }
        
        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 (group_gui_id (group), "color", buf);
+       
+       /* for historical reasons the colors must be stored as 16 bit color
+        * values. Ugh.
+        */
+
+       snprintf (buf, sizeof (buf), "%d:%d:%d", (r<<8), (g<<8), (b<<8));
+       gui_state.set_property (group_gui_id (group), "color", buf);
        
        /* the group color change notification */
        
@@ -574,35 +612,35 @@ GroupTabs::group_gui_id (RouteGroup* group)
 }
 
 /** @return the color to use for a route group tab */
-Gdk::Color
+uint32_t
 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;
+               uint32_t c = gdk_color_to_rgba (unique_random_color (_used_colors));
+               set_group_color (group, c);
+               return c;
        }
 
-       Gdk::Color c;
-
        int r, g, b;
 
+       /* for historical reasons, colors are stored as 16 bit values.
+        */
+
        sscanf (color.c_str(), "%d:%d:%d", &r, &g, &b);
 
-       c.set_red (r);
-       c.set_green (g);
-       c.set_blue (b);
-       
-       return c;
+       r /= 256;
+       g /= 256;
+       b /= 256;
+
+       return RGBA_TO_UINT (r, g, b, 255);
 }
 
 void