a reverb is a reverb is a reverb
[ardour.git] / gtk2_ardour / control_slave_ui.cc
index 7be2d5daba0e09faee6acb36cd647cefe8ff140d..55705cf590cc6f47aa98091506b575525dae65b6 100644 (file)
@@ -35,7 +35,7 @@
 #include "control_slave_ui.h"
 #include "gui_thread.h"
 
-#include "i18n.h"
+#include "pbd/i18n.h"
 
 using namespace ARDOUR;
 using namespace Gtk;
@@ -84,15 +84,22 @@ 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;
+                       }
                }
        }
 
@@ -172,19 +179,41 @@ ControlSlaveUI::vca_button_release (GdkEventButton* ev, uint32_t n)
 
        Menu* menu = new Menu;
        MenuList& items = menu->items();
+       bool slaved = false;
 
        for (VCAList::iterator v = vcas.begin(); v != vcas.end(); ++v) {
+
+               boost::shared_ptr<GainControl> gcs = stripable->gain_control();
+               boost::shared_ptr<GainControl> gcm = (*v)->gain_control();
+
+               if (gcs == gcm) {
+                       /* asked to slave to self. not ok */
+                       continue;
+               }
+
+               if (gcm->slaved_to (gcs)) {
+                       /* master is already slaved to slave */
+                       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())) {
+
+               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()) {
+               menu->popup (1, ev->time);
+       }
 
        return true;
 }
@@ -199,7 +228,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 ();
+}