color management and handling for VCAs
authorPaul Davis <paul@linuxaudiosystems.com>
Thu, 9 Jun 2016 19:35:56 +0000 (15:35 -0400)
committerPaul Davis <paul@linuxaudiosystems.com>
Thu, 9 Jun 2016 20:03:14 +0000 (16:03 -0400)
gtk2_ardour/control_slave_ui.cc
gtk2_ardour/control_slave_ui.h
gtk2_ardour/route_ui.cc
gtk2_ardour/utils.cc
gtk2_ardour/vca_master_strip.cc
gtk2_ardour/vca_master_strip.h

index 12a3495293006535fdd8b9ae8bcbf377b7e49677..3fd752c72f0d8be19c364b905c8845b5a7c7566d 100644 (file)
@@ -84,10 +84,15 @@ ControlSlaveUI::set_stripable (boost::shared_ptr<Stripable> s)
 void
 ControlSlaveUI::update_vca_display ()
 {
+       if (!_session || _session->deletion_in_progress()) {
+               return;
+       }
+
        VCAList vcas (_session->vca_manager().vcas());
        bool any = false;
 
        Gtkmm2ext::container_clear (*this);
+       master_connections.drop_connections ();
 
        for (VCAList::iterator v = vcas.begin(); v != vcas.end(); ++v) {
                if (stripable->gain_control()->slaved_to ((*v)->gain_control())) {
@@ -221,7 +226,16 @@ ControlSlaveUI::add_vca_button (boost::shared_ptr<VCA> vca)
        vca_button->add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK);
        vca_button->signal_button_release_event().connect (sigc::bind (sigc::mem_fun (*this, &ControlSlaveUI::specific_vca_button_release), vca->number()), false);
        vca_button->set_text (PBD::to_string (vca->number(), std::dec));
+       vca_button->set_fixed_colors (vca->presentation_info().color(), vca->presentation_info().color ());
+
+       vca->presentation_info().PropertyChanged.connect (master_connections, invalidator (*this), boost::bind (&ControlSlaveUI::master_property_changed, this, _1), gui_context());
 
        pack_start (*vca_button);
        vca_button->show ();
 }
+
+void
+ControlSlaveUI::master_property_changed (PBD::PropertyChange const& /* what_changed */)
+{
+       update_vca_display ();
+}
index 1ce35720ec49c5895de4bb47131493b30f594b96..3443e1a79a8d57aee7af30e7ae66b84a814dab70 100644 (file)
@@ -27,6 +27,7 @@
 #include <gtkmm/checkmenuitem.h>
 
 #include "pbd/signals.h"
+#include "pbd/properties.h"
 
 #include "ardour/session_handle.h"
 
@@ -47,8 +48,10 @@ class ControlSlaveUI : public Gtk::HBox, public ARDOUR::SessionHandlePtr
    private:
        boost::shared_ptr<ARDOUR::Stripable> stripable;
        PBD::ScopedConnectionList connections;
+       PBD::ScopedConnectionList master_connections;
        ArdourButton  initial_button;
 
+       void master_property_changed (PBD::PropertyChange const &);
        void update_vca_display ();
        void vca_menu_toggle (Gtk::CheckMenuItem*, uint32_t n);
        bool specific_vca_button_release (GdkEventButton* ev, uint32_t n);
index 7f43a9e2513bcabfd95abd456ff65c8bcb1fa008..b7b4b22fb6fa20ef3819e3dfa279b017bef7d01a 100644 (file)
@@ -63,6 +63,7 @@
 #include "mixer_strip.h"
 #include "plugin_pin_dialog.h"
 #include "prompter.h"
+#include "rgb_macros.h"
 #include "route_time_axis.h"
 #include "route_ui.h"
 #include "timers.h"
@@ -2211,9 +2212,8 @@ RouteUI::route_color () const
 
                        /* old v4.x or earlier session. Use this information */
 
-                       int component;
+                       int red, green, blue;
                        char colon;
-                       PresentationInfo::color_t color = 0;
 
                        stringstream ss (p);
 
@@ -2224,16 +2224,17 @@ RouteUI::route_color () const
                           decode to rgb ..
                        */
 
-                       ss >> component;
+                       ss >> red;
                        ss >> colon;
-                       color |= ((component >> 2) << 16);
-                       ss >> component;
+                       ss >> green;
                        ss >> colon;
-                       color |= ((component >> 2) << 8);
-                       ss >> component;
-                       color |= (component >> 2);
+                       ss >> blue;
 
-                       _route->presentation_info().set_color (color);
+                       red >>= 2;
+                       green >>= 2;
+                       blue >>= 2;
+
+                       _route->presentation_info().set_color (RGBA_TO_UINT (red, green, blue, 255));
                }
 
                set_color_from_rgba (c, _route->presentation_info().color());
index 6ad6d9bb3cf44fe6ea45f5f276dff16081b439d7..6fb5caa7e5993a7f357800c2c7315a9d608201e8 100644 (file)
@@ -313,7 +313,6 @@ ARDOUR_UI_UTILS::gdk_color_to_rgba (Gdk::Color const& c)
        return RGBA_TO_UINT (r,g,b,a);
 }
 
-
 bool
 ARDOUR_UI_UTILS::relay_key_press (GdkEventKey* ev, Gtk::Window* win)
 {
index 4c56832b23508ba64612c262d98a087bf3af2a20..4ef1e4adaf5eaf5f5ccbea6e5fef92577de3f56f 100644 (file)
@@ -17,6 +17,7 @@
 */
 
 #include <gtkmm/stock.h>
+#include <gtkmm/colorselection.h>
 
 #include "pbd/convert.h"
 
@@ -34,6 +35,7 @@
 #include "mixer_ui.h"
 #include "tooltips.h"
 #include "ui_config.h"
+#include "utils.h"
 #include "vca_master_strip.h"
 
 #include "i18n.h"
@@ -55,6 +57,15 @@ VCAMasterStrip::VCAMasterStrip (Session* s, boost::shared_ptr<VCA> v)
        , delete_dialog (0)
        , control_slave_ui (s)
 {
+
+       PresentationInfo::color_t c = _vca->presentation_info().color ();
+
+       /* XXX need a (better) test of "has a color" */
+
+       if (c == 0) {
+               _vca->presentation_info().set_color (gdk_color_to_rgba (unique_random_color()));
+       }
+
        control_slave_ui.set_stripable (boost::dynamic_pointer_cast<Stripable> (v));
 
        gain_meter.set_controls (boost::shared_ptr<Route>(),
@@ -96,6 +107,7 @@ VCAMasterStrip::VCAMasterStrip (Session* s, boost::shared_ptr<VCA> v)
        vertical_button.set_layout_font (UIConfiguration::instance().get_NormalBoldFont());
        vertical_button.signal_button_release_event().connect (sigc::mem_fun (*this, &VCAMasterStrip::vertical_button_press));
        vertical_button.set_fallthrough_to_parent (true);
+       vertical_button.set_active_color (_vca->presentation_info().color ());
        set_tooltip (vertical_button, _("Click to show slaves only")); /* tooltip updated dynamically */
 
        drop_button.set_text(_("drop"));
@@ -145,6 +157,7 @@ VCAMasterStrip::VCAMasterStrip (Session* s, boost::shared_ptr<VCA> v)
        Mixer_UI::instance()->show_vca_change.connect (sigc::mem_fun (*this, &VCAMasterStrip::spill_change));
 
        _vca->PropertyChanged.connect (vca_connections, invalidator (*this), boost::bind (&VCAMasterStrip::vca_property_changed, this, _1), gui_context());
+       _vca->presentation_info().PropertyChanged.connect (vca_connections, invalidator (*this), boost::bind (&VCAMasterStrip::vca_property_changed, this, _1), gui_context());
        _vca->DropReferences.connect (vca_connections, invalidator (*this), boost::bind (&VCAMasterStrip::self_delete, this), gui_context());
 
        _vca->solo_control()->Changed.connect (vca_connections, invalidator (*this), boost::bind (&VCAMasterStrip::solo_changed, this), gui_context());
@@ -372,6 +385,10 @@ VCAMasterStrip::vca_property_changed (PropertyChange const & what_changed)
        if (what_changed.contains (ARDOUR::Properties::name)) {
                update_vca_name ();
        }
+
+       if (what_changed.contains (ARDOUR::Properties::color)) {
+               vertical_button.set_active_color (_vca->presentation_info().color ());
+       }
 }
 
 void
@@ -388,6 +405,7 @@ VCAMasterStrip::build_context_menu ()
        context_menu = new Menu;
        MenuList& items = context_menu->items();
        items.push_back (MenuElem (_("Rename"), sigc::mem_fun (*this, &VCAMasterStrip::start_name_edit)));
+       items.push_back (MenuElem (_("Color..."), sigc::mem_fun (*this, &VCAMasterStrip::start_color_edit)));
        items.push_back (SeparatorElem());
        items.push_back (MenuElem (_("Drop All Slaves"), sigc::mem_fun (*this, &VCAMasterStrip::drop_all_slaves)));
        items.push_back (SeparatorElem());
@@ -445,7 +463,7 @@ VCAMasterStrip::drop_button_press ()
 Gdk::Color
 VCAMasterStrip::color () const
 {
-       return gdk_color_from_rgb (_vca->presentation_info().color ());
+       return gdk_color_from_rgba (_vca->presentation_info().color ());
 }
 
 string
@@ -453,3 +471,32 @@ VCAMasterStrip::state_id () const
 {
        return string_compose (X_("vms-%1"), _vca->number());
 }
+
+void
+VCAMasterStrip::start_color_edit ()
+{
+       Gtk::ColorSelectionDialog* color_dialog = new Gtk::ColorSelectionDialog;
+
+       color_dialog->get_colorsel()->set_has_opacity_control (false);
+       color_dialog->get_colorsel()->set_has_palette (true);
+
+       Gdk::Color c = gdk_color_from_rgba (_vca->presentation_info().color ());
+
+       color_dialog->get_colorsel()->set_previous_color (c);
+       color_dialog->get_colorsel()->set_current_color (c);
+
+       color_dialog->signal_response().connect (sigc::bind (sigc::mem_fun (*this, &VCAMasterStrip::finish_color_edit), color_dialog));
+       color_dialog->present ();
+}
+
+void
+VCAMasterStrip::finish_color_edit (int response, Gtk::ColorSelectionDialog* dialog)
+{
+       switch (response) {
+       case RESPONSE_OK:
+               _vca->presentation_info().set_color (gdk_color_to_rgba (dialog->get_colorsel()->get_current_color()));
+               break;
+       }
+
+       delete_when_idle (dialog);
+}
index 63b5e7a896b3e188ca455ea88bff6fe999aa890b..7d1edf1acd44b2e988a56d74a87f077a5f9eb163 100644 (file)
@@ -98,6 +98,9 @@ class VCAMasterStrip : public AxisView, public Gtk::EventBox
 
        void parameter_changed (std::string const& p);
        void set_button_names ();
+
+       void start_color_edit ();
+       void finish_color_edit (int, Gtk::ColorSelectionDialog*);
 };