NO-OP: whitespace and some guaranteed assertion removal
[ardour.git] / gtk2_ardour / control_slave_ui.cc
index 7be2d5daba0e09faee6acb36cd647cefe8ff140d..0c8ad87d28da3b26eed082cc0d25bb40a5c86be3 100644 (file)
@@ -20,7 +20,7 @@
 
 #include <gtkmm/menu.h>
 
-#include "pbd/convert.h"
+#include "pbd/string_convert.h"
 
 #include "ardour/session.h"
 #include "ardour/stripable.h"
 #include "gtkmm2ext/gtk_ui.h"
 #include "gtkmm2ext/utils.h"
 
-#include "ardour_button.h"
 #include "control_slave_ui.h"
 #include "gui_thread.h"
 
-#include "i18n.h"
+#include "pbd/i18n.h"
 
 using namespace ARDOUR;
+using namespace ArdourWidgets;
 using namespace Gtk;
 using std::string;
 
 ControlSlaveUI::ControlSlaveUI (Session* s)
        : SessionHandlePtr (s)
        , initial_button (ArdourButton::default_elements)
+       , context_menu (0)
 {
        set_no_show_all (true);
 
-       Gtkmm2ext::UI::instance()->set_tip (*this, _("Control Masters"));
+       Gtkmm2ext::UI::instance()->set_tip (*this, _("VCA Assign"));
 
        initial_button.set_no_show_all (true);
        initial_button.set_name (X_("vca assign"));
-       initial_button.set_text (_("-vca-"));
+       initial_button.set_text (_("-VCAs-"));
        initial_button.show ();
        initial_button.add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK);
        initial_button.signal_button_release_event().connect (sigc::bind (sigc::mem_fun (*this, &ControlSlaveUI::vca_button_release), 0), false);
@@ -59,6 +60,11 @@ ControlSlaveUI::ControlSlaveUI (Session* s)
        pack_start (initial_button, true, true);
 }
 
+ControlSlaveUI::~ControlSlaveUI ()
+{
+       delete context_menu;
+}
+
 void
 ControlSlaveUI::set_stripable (boost::shared_ptr<Stripable> s)
 {
@@ -84,20 +90,28 @@ 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())) {
-                       add_vca_button (*v);
-                       any = true;
+       if (stripable) {
+               for (VCAList::iterator v = vcas.begin(); v != vcas.end(); ++v) {
+                       if (stripable->gain_control()->slaved_to ((*v)->gain_control())) {
+                               add_vca_button (*v);
+                               any = true;
+                       }
                }
        }
 
        if (!any) {
                pack_start (initial_button, true, true);
+               initial_button.show ();
        }
 
        show ();
@@ -170,21 +184,39 @@ ControlSlaveUI::vca_button_release (GdkEventButton* ev, uint32_t n)
                return true;
        }
 
-       Menu* menu = new Menu;
-       MenuList& items = menu->items();
+       delete context_menu;
+       context_menu = new Menu;
+       MenuList& items = context_menu->items();
+       bool slaved = false;
 
        for (VCAList::iterator v = vcas.begin(); v != vcas.end(); ++v) {
+
+               if (stripable->assigned_to (_session->vca_manager_ptr (), *v)) {
+                       /* master(stripable) is directly or indirectly controlled by slave (v) */
+                       continue;
+               }
+
                items.push_back (CheckMenuElem ((*v)->name()));
                Gtk::CheckMenuItem* item = dynamic_cast<Gtk::CheckMenuItem*> (&items.back());
-               if (stripable->gain_control()->slaved_to ((*v)->gain_control())) {
+
+               boost::shared_ptr<GainControl> gcs = stripable->gain_control();
+               boost::shared_ptr<GainControl> gcm = (*v)->gain_control();
+
+               if (gcs->slaved_to (gcm)) {
                        item->set_active (true);
+                       slaved = true;
                }
+
                item->signal_activate().connect (sigc::bind (sigc::mem_fun (*this, &ControlSlaveUI::vca_menu_toggle), item, (*v)->number()));
        }
 
-       items.push_back (MenuElem (_("Unassign All"), sigc::mem_fun (*this, &ControlSlaveUI::unassign_all)));
+       if (slaved) {
+               items.push_back (MenuElem (_("Unassign All"), sigc::mem_fun (*this, &ControlSlaveUI::unassign_all)));
+       }
 
-       menu->popup (1, ev->time);
+       if (!items.empty()) {
+               context_menu->popup (1, ev->time);
+       }
 
        return true;
 }
@@ -198,8 +230,17 @@ ControlSlaveUI::add_vca_button (boost::shared_ptr<VCA> vca)
        vca_button->set_name (X_("vca assign"));
        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_text (PBD::to_string (vca->number()));
+       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 ();
+}