Allow individual plugin controls to be shown / hidden.
authorCarl Hetherington <carl@carlh.net>
Sat, 21 Jan 2012 20:32:13 +0000 (20:32 +0000)
committerCarl Hetherington <carl@carlh.net>
Sat, 21 Jan 2012 20:32:13 +0000 (20:32 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@11294 d708f5d6-7413-0410-9779-e7cbd77b26cf

gtk2_ardour/processor_box.cc
gtk2_ardour/processor_box.h

index db5ee835c5d3882c82940a018808e91785883f68..d3ad32bbf59e2f61d80e8fb1bbadaf6744d7ac12 100644 (file)
@@ -95,9 +95,10 @@ RefPtr<Action> ProcessorBox::edit_action;
 RefPtr<Action> ProcessorBox::controls_action;
 Glib::RefPtr<Gdk::Pixbuf> ProcessorEntry::_slider_pixbuf;
 
-ProcessorEntry::ProcessorEntry (boost::shared_ptr<Processor> p, Width w)
+ProcessorEntry::ProcessorEntry (ProcessorBox* parent, boost::shared_ptr<Processor> p, Width w)
        : _button (ArdourButton::led_default_elements)
        , _position (PreFader)
+       , _parent (parent)
        , _processor (p)
        , _width (w)
        , _visual_state (Gtk::STATE_NORMAL)
@@ -125,20 +126,19 @@ ProcessorEntry::ProcessorEntry (boost::shared_ptr<Processor> p, Width w)
 
                set<Evoral::Parameter> p = _processor->what_can_be_automated ();
                for (set<Evoral::Parameter>::iterator i = p.begin(); i != p.end(); ++i) {
-                       if (boost::dynamic_pointer_cast<Amp> (_processor)) {
-                               /* Don't give Fader processors separate controls here */
-                               continue;
+                       
+                       Control* c = new Control (_slider_pixbuf, _processor->automation_control (*i), _processor->describe_parameter (*i));
+                       _controls.push_back (c);
+
+                       if (boost::dynamic_pointer_cast<Amp> (_processor) == 0) {
+                               /* Add non-Amp controls to the processor box */
+                               _vbox.pack_start (c->box);
                        }
 
-                       string d = _processor->describe_parameter (*i);
                        if (boost::dynamic_pointer_cast<Send> (_processor)) {
-                               /* Little hack; don't label send level faders */
-                               d = "";
+                               /* Don't label send faders */
+                               c->hide_label ();
                        }
-
-                       Control* c = new Control (_slider_pixbuf, _processor->automation_control (*i), d);
-                       _controls.push_back (c);
-                       _vbox.pack_start (c->box);
                }
 
                setup_tooltip ();
@@ -325,16 +325,20 @@ void
 ProcessorEntry::show_all_controls ()
 {
        for (list<Control*>::iterator i = _controls.begin(); i != _controls.end(); ++i) {
-               (*i)->show ();
+               (*i)->set_visible (true);
        }
+
+       _parent->update_gui_object_state (this);
 }
 
 void
 ProcessorEntry::hide_all_controls ()
 {
        for (list<Control*>::iterator i = _controls.begin(); i != _controls.end(); ++i) {
-               (*i)->hide ();
+               (*i)->set_visible (false);
        }
+
+       _parent->update_gui_object_state (this);
 }
 
 void
@@ -367,23 +371,59 @@ ProcessorEntry::hide_things ()
        }
 }
 
-ProcessorEntry::Control::Control (Glib::RefPtr<Gdk::Pixbuf> s, boost::shared_ptr<AutomationControl> c, string const & l)
+
+Menu *
+ProcessorEntry::build_controls_menu ()
+{
+       using namespace Menu_Helpers;
+       Menu* menu = manage (new Menu);
+       MenuList& items = menu->items ();
+
+       items.push_back (
+               MenuElem (_("Show All Controls"), sigc::mem_fun (*this, &ProcessorEntry::show_all_controls))
+               );
+               
+       items.push_back (
+               MenuElem (_("Hide All Controls"), sigc::mem_fun (*this, &ProcessorEntry::hide_all_controls))
+               );
+
+       if (!_controls.empty ()) {
+               items.push_back (SeparatorElem ());
+       }
+       
+       for (list<Control*>::iterator i = _controls.begin(); i != _controls.end(); ++i) {
+               items.push_back (CheckMenuElem ((*i)->name ()));
+               CheckMenuItem* c = dynamic_cast<CheckMenuItem*> (&items.back ());
+               c->set_active ((*i)->visible ());
+               c->signal_toggled().connect (sigc::bind (sigc::mem_fun (*this, &ProcessorEntry::toggle_control_visibility), *i));
+       }
+
+       return menu;
+}
+
+void
+ProcessorEntry::toggle_control_visibility (Control* c)
+{
+       c->set_visible (!c->visible ());
+       _parent->update_gui_object_state (this);
+}
+
+ProcessorEntry::Control::Control (Glib::RefPtr<Gdk::Pixbuf> s, boost::shared_ptr<AutomationControl> c, string const & n)
        : _control (c)
        , _adjustment (gain_to_slider_position_with_max (1.0, Config->get_max_gain()), 0, 1, 0.01, 0.1)
        , _slider (s, &_adjustment, 0, false)
        , _ignore_slider_adjustment (false)
        , _visible (false)
+       , _name (n)
 {
        _slider.set_controllable (c);
 
-       if (!l.empty ()) {
-               box.pack_start (_label);
-               _label.show ();
-               _label.set_text (l);
-       }
+       box.pack_start (_label);
+       _label.show ();
+       _label.set_text (_name);
 
-       _slider.show ();
        box.pack_start (_slider);
+       _slider.show ();
 
        double const lo = c->internal_to_interface (c->lower ());
        double const up = c->internal_to_interface (c->upper ());
@@ -459,28 +499,22 @@ ProcessorEntry::Control::set_state (XMLNode const * node)
        XMLNode* n = GUIObjectState::get_node (node, state_id ());
        if (n) {
                XMLProperty* p = n->property (X_("visible"));
-               if (p && string_is_affirmative (p->value ())) {
-                       show ();
-               } else {
-                       hide ();
-               }
+               set_visible (p && string_is_affirmative (p->value ()));
        } else {
-               hide ();
+               set_visible (false);
        }
 }
 
 void
-ProcessorEntry::Control::show ()
+ProcessorEntry::Control::set_visible (bool v)
 {
-       box.show ();
-       _visible = true;
-}
-
-void
-ProcessorEntry::Control::hide ()
-{
-       box.hide ();
-       _visible = false;
+       if (v) {
+               box.show ();
+       } else {
+               box.hide ();
+       }
+       
+       _visible = v;
 }
 
 /** Called when the Editor might have re-shown things that
@@ -494,6 +528,12 @@ ProcessorEntry::Control::hide_things ()
        }
 }
 
+void
+ProcessorEntry::Control::hide_label ()
+{
+       _label.hide ();
+}
+
 string
 ProcessorEntry::Control::state_id () const
 {
@@ -503,13 +543,13 @@ ProcessorEntry::Control::state_id () const
        return string_compose (X_("control %1"), c->id().to_s ());
 }
 
-BlankProcessorEntry::BlankProcessorEntry (Width w)
-       : ProcessorEntry (boost::shared_ptr<Processor>(), w)
+BlankProcessorEntry::BlankProcessorEntry (ProcessorBox* b, Width w)
+       : ProcessorEntry (b, boost::shared_ptr<Processor>(), w)
 {
 }
 
-PluginInsertProcessorEntry::PluginInsertProcessorEntry (boost::shared_ptr<ARDOUR::PluginInsert> p, Width w)
-       : ProcessorEntry (p, w)
+PluginInsertProcessorEntry::PluginInsertProcessorEntry (ProcessorBox* b, boost::shared_ptr<ARDOUR::PluginInsert> p, Width w)
+       : ProcessorEntry (b, p, w)
        , _plugin_insert (p)
 {
        p->SplittingChanged.connect (
@@ -800,9 +840,9 @@ ProcessorBox::show_processor_menu (int arg)
                }
        }
 
-       boost::shared_ptr<Processor> single_selection;
+       ProcessorEntry* single_selection = 0;
        if (processor_display.selection().size() == 1) {
-               single_selection = processor_display.selection().front()->processor ();
+               single_selection = processor_display.selection().front();
        }
 
        /* And the controls submenu */
@@ -811,7 +851,7 @@ ProcessorBox::show_processor_menu (int arg)
 
        if (controls_menu_item) {
                if (single_selection) {
-                       Menu* m = build_controls_menu (single_selection);
+                       Menu* m = single_selection->build_controls_menu ();
                        if (m && !m->items().empty()) {
                                controls_menu_item->set_submenu (*m);
                                controls_menu_item->set_sensitive (true);
@@ -833,11 +873,11 @@ ProcessorBox::show_processor_menu (int arg)
 
        boost::shared_ptr<PluginInsert> pi;
        if (single_selection) {
-               pi = boost::dynamic_pointer_cast<PluginInsert> (single_selection);
+               pi = boost::dynamic_pointer_cast<PluginInsert> (single_selection->processor ());
        }
 
        /* disallow rename for multiple selections, for plugin inserts and for the fader */
-       rename_action->set_sensitive (single_selection && !pi && !boost::dynamic_pointer_cast<Amp> (single_selection));
+       rename_action->set_sensitive (single_selection && !pi && !boost::dynamic_pointer_cast<Amp> (single_selection->processor ()));
 
        processor_menu->popup (1, arg);
 
@@ -1250,7 +1290,7 @@ ProcessorBox::redisplay_processors ()
                                               &_visible_prefader_processors, &fader_seen));
 
        if (_visible_prefader_processors == 0) { // fader only
-               BlankProcessorEntry* bpe = new BlankProcessorEntry (_width);
+               BlankProcessorEntry* bpe = new BlankProcessorEntry (this, _width);
                bpe->set_pixel_width (get_allocation().get_width());
                processor_display.add_child (bpe);
        }
@@ -1371,9 +1411,9 @@ ProcessorBox::add_processor_to_display (boost::weak_ptr<Processor> p)
        boost::shared_ptr<PluginInsert> plugin_insert = boost::dynamic_pointer_cast<PluginInsert> (processor);
        ProcessorEntry* e = 0;
        if (plugin_insert) {
-               e = new PluginInsertProcessorEntry (plugin_insert, _width);
+               e = new PluginInsertProcessorEntry (this, plugin_insert, _width);
        } else {
-               e = new ProcessorEntry (processor, _width);
+               e = new ProcessorEntry (this, processor, _width);
        }
 
        e->set_pixel_width (get_allocation().get_width());
@@ -2443,51 +2483,6 @@ ProcessorBox::processor_menu_unmapped ()
        processor_display.remove_placeholder ();
 }
 
-Menu *
-ProcessorBox::build_controls_menu (boost::shared_ptr<Processor> p)
-{
-       using namespace Menu_Helpers;
-       Menu* menu = manage (new Menu);
-       MenuList& items = menu->items ();
-
-       items.push_back (
-               MenuElem (_("Show All Controls"), sigc::bind (sigc::mem_fun (*this, &ProcessorBox::show_or_hide_all_controls), boost::weak_ptr<Processor> (p), true)
-                       ));
-       
-       items.push_back (
-               MenuElem (_("Hide All Controls"), sigc::bind (sigc::mem_fun (*this, &ProcessorBox::show_or_hide_all_controls), boost::weak_ptr<Processor> (p), false)
-                       ));
-
-       return menu;
-}
-
-void
-ProcessorBox::show_or_hide_all_controls (boost::weak_ptr<Processor> w, bool show)
-{
-       boost::shared_ptr<Processor> p (w.lock ());
-       if (!p) {
-               return;
-       }
-
-       list<ProcessorEntry*> processors = processor_display.children ();
-       list<ProcessorEntry*>::iterator i = processors.begin();
-       while (i != processors.end () && (*i)->processor() != p) {
-               ++i;
-       }
-
-       if (i == processors.end ()) {
-               return;
-       }
-
-       if (show) {
-               (*i)->show_all_controls ();
-       } else {
-               (*i)->hide_all_controls ();
-       }
-
-       update_gui_object_state (*i);
-}
-
 XMLNode *
 ProcessorBox::entry_gui_object_state (ProcessorEntry* entry)
 {
index 364ab7b1165919675953f1d715beb85eb275dd78..c4047cdc83950065bf3c3d21fc886ef4cb81ac42 100644 (file)
@@ -101,7 +101,7 @@ private:
 class ProcessorEntry : public Gtkmm2ext::DnDVBoxChild, public sigc::trackable
 {
 public:
-       ProcessorEntry (boost::shared_ptr<ARDOUR::Processor>, Width);
+       ProcessorEntry (ProcessorBox *, boost::shared_ptr<ARDOUR::Processor>, Width);
        ~ProcessorEntry ();
 
        Gtk::EventBox& action_widget ();
@@ -128,6 +128,7 @@ public:
        void add_control_state (XMLNode *) const;
        void set_control_state (XMLNode const *);
        std::string state_id () const;
+       Gtk::Menu* build_controls_menu ();
 
        static void setup_slider_pix ();
 
@@ -147,6 +148,7 @@ private:
        std::string name (Width) const;
        void setup_tooltip ();
 
+       ProcessorBox* _parent;
        boost::shared_ptr<ARDOUR::Processor> _processor;
        Width _width;
        Gtk::StateType _visual_state;
@@ -158,11 +160,19 @@ private:
                Control (Glib::RefPtr<Gdk::Pixbuf>, boost::shared_ptr<ARDOUR::AutomationControl>, std::string const &);
 
                void set_pixel_width (int);
-               void show ();
-               void hide ();
+               void set_visible (bool);
                void add_state (XMLNode *) const;
                void set_state (XMLNode const *);
                void hide_things ();
+               void hide_label ();
+
+               bool visible () const {
+                       return _visible;
+               }
+
+               std::string name () const {
+                       return _name;
+               }
                
                Gtk::VBox box;
 
@@ -178,21 +188,24 @@ private:
                bool _ignore_slider_adjustment;
                PBD::ScopedConnection _connection;
                bool _visible;
+               std::string _name;
        };
 
        std::list<Control*> _controls;
+
+       void toggle_control_visibility (Control *);
 };
 
 class BlankProcessorEntry : public ProcessorEntry
 {
   public:
-       BlankProcessorEntry (Width w);
+       BlankProcessorEntry (ProcessorBox *, Width w);
 };
 
 class PluginInsertProcessorEntry : public ProcessorEntry
 {
 public:
-       PluginInsertProcessorEntry (boost::shared_ptr<ARDOUR::PluginInsert>, Width);
+       PluginInsertProcessorEntry (ProcessorBox *, boost::shared_ptr<ARDOUR::PluginInsert>, Width);
 
        void hide_things ();
 
@@ -246,6 +259,8 @@ class ProcessorBox : public Gtk::HBox, public PluginInterestedObject, public ARD
        Gtk::Window* get_processor_ui (boost::shared_ptr<ARDOUR::Processor>) const;
        void toggle_edit_processor (boost::shared_ptr<ARDOUR::Processor>);
 
+       void update_gui_object_state (ProcessorEntry *);
+       
        sigc::signal<void,boost::shared_ptr<ARDOUR::Processor> > ProcessorSelected;
        sigc::signal<void,boost::shared_ptr<ARDOUR::Processor> > ProcessorUnselected;
 
@@ -289,9 +304,6 @@ class ProcessorBox : public Gtk::HBox, public PluginInterestedObject, public ARD
        Gtk::Menu * build_processor_menu ();
        void show_processor_menu (int);
        Gtk::Menu* build_possible_aux_menu();
-       Gtk::Menu* build_controls_menu (boost::shared_ptr<ARDOUR::Processor>);
-
-       void show_or_hide_all_controls (boost::weak_ptr<ARDOUR::Processor>, bool);
 
        void choose_aux (boost::weak_ptr<ARDOUR::Route>);
        void choose_send ();
@@ -393,7 +405,6 @@ class ProcessorBox : public Gtk::HBox, public PluginInterestedObject, public ARD
 
        void mixer_strip_delivery_changed (boost::weak_ptr<ARDOUR::Delivery>);
 
-       void update_gui_object_state (ProcessorEntry *);
        XMLNode* entry_gui_object_state (ProcessorEntry *);
 };