Further preference-dialog re-layout work in progress..
[ardour.git] / gtk2_ardour / mixer_ui.cc
index af621daae37060f0cdee8c5c1b74605a258e4354..02daf63f1d80b4e51e976f42d1f544bb624dd55d 100644 (file)
@@ -25,6 +25,8 @@
 #include <map>
 #include <sigc++/bind.h>
 
+#include <boost/foreach.hpp>
+
 #include <gtkmm/accelmap.h>
 
 #include "pbd/convert.h"
@@ -69,7 +71,7 @@
 #include "ui_config.h"
 #include "vca_master_strip.h"
 
-#include "i18n.h"
+#include "pbd/i18n.h"
 
 using namespace ARDOUR;
 using namespace ARDOUR_UI_UTILS;
@@ -108,13 +110,14 @@ Mixer_UI::Mixer_UI ()
        , _following_editor_selection (false)
        , _maximised (false)
        , _show_mixer_list (true)
+       , myactions (X_("mixer"))
 {
-       PresentationInfo::Change.connect (*this, invalidator (*this), boost::bind (&Mixer_UI::sync_treeview_from_presentation_info, this), gui_context());
-
-       /* bindings was already set in MixerActor constructor */
-
+       register_actions ();
+       load_bindings ();
        _content.set_data ("ardour-bindings", bindings);
 
+       PresentationInfo::Change.connect (*this, invalidator (*this), boost::bind (&Mixer_UI::sync_treeview_from_presentation_info, this), gui_context());
+
        scroller.set_can_default (true);
        // set_default (scroller);
 
@@ -134,6 +137,8 @@ Mixer_UI::Mixer_UI ()
 
        _group_tabs = new MixerGroupTabs (this);
        VBox* b = manage (new VBox);
+       b->set_spacing (0);
+       b->set_border_width (0);
        b->pack_start (*_group_tabs, PACK_SHRINK);
        b->pack_start (strip_packer);
        b->show_all ();
@@ -249,15 +254,13 @@ Mixer_UI::Mixer_UI ()
        list_vpacker.pack_start (rhs_pane2, true, true);
 
        string vca_text = _("Control Masters");
-       Gtk::HBox* vca_top_padding = manage (new Gtk::HBox);
-       vca_top_padding->set_size_request (-1, 2);
-       vca_vpacker.pack_start (*vca_top_padding, false, false);
-
        vca_label.set_text (vca_text);
-       vca_label_bar.set_size_request (-1, 16); /* must match height in GroupTabs::set_size_request() */
+       vca_label_bar.set_size_request (-1, 16 + 1); /* must match height in GroupTabs::set_size_request()  + 1 border px*/
 
+#ifndef MIXBUS
        vca_label_bar.set_name (X_("VCALabelBar"));
        vca_label_bar.add (vca_label);
+#endif
 
        vca_vpacker.pack_start (vca_label_bar, false, false);
 
@@ -345,7 +348,6 @@ Mixer_UI::Mixer_UI ()
        rhs_pane2.show();
        strip_packer.show();
        inner_pane.show();
-       vca_top_padding->show ();
        vca_scroller.show();
        vca_vpacker.show();
        vca_hpacker.show();
@@ -618,7 +620,7 @@ Mixer_UI::add_stripables (StripableList& slist)
 
                        (*s)->presentation_info().PropertyChanged.connect (*this, invalidator(*this), boost::bind (&Mixer_UI::stripable_property_changed, this, _1, boost::weak_ptr<Stripable>(*s)), gui_context());
                        (*s)->PropertyChanged.connect (*this, invalidator(*this), boost::bind (&Mixer_UI::stripable_property_changed, this, _1, boost::weak_ptr<Stripable>(*s)), gui_context());
-                                               }
+               }
 
        } catch (const std::exception& e) {
                error << string_compose (_("Error adding GUI elements for new tracks/busses %1"), e.what()) << endmsg;
@@ -711,6 +713,11 @@ Mixer_UI::sync_presentation_info_from_treeview ()
        bool change = false;
        uint32_t order = 0;
 
+       // special case master if it's got PI order 0 lets keep it there
+       if (_session->master_out() && (_session->master_out()->presentation_info().order() == 0)) {
+               order++;
+       }
+
        for (ri = rows.begin(); ri != rows.end(); ++ri) {
                bool visible = (*ri)[stripable_columns.visible];
                boost::shared_ptr<Stripable> stripable = (*ri)[stripable_columns.stripable];
@@ -733,8 +740,13 @@ Mixer_UI::sync_presentation_info_from_treeview ()
 
                stripable->presentation_info().set_hidden (!visible);
 
+               // master may not get set here, but if it is zero keep it there
+               if (stripable->is_master() && (stripable->presentation_info().order() == 0)) {
+                       continue;
+               }
+
                if (order != stripable->presentation_info().order()) {
-                       stripable->set_presentation_order_explicit (order);
+                       stripable->set_presentation_order (order, false);
                        change = true;
                }
 
@@ -744,6 +756,7 @@ Mixer_UI::sync_presentation_info_from_treeview ()
        if (change) {
                DEBUG_TRACE (DEBUG::OrderKeys, "... notify PI change from mixer GUI\n");
                _session->notify_presentation_info_change ();
+               _session->set_dirty();
        }
 }
 
@@ -771,10 +784,11 @@ Mixer_UI::sync_treeview_from_presentation_info ()
        }
 
        OrderingKeys sorted;
+       const size_t cmp_max = rows.size ();
 
        for (TreeModel::Children::iterator ri = rows.begin(); ri != rows.end(); ++ri, ++old_order) {
                boost::shared_ptr<Stripable> stripable = (*ri)[stripable_columns.stripable];
-               sorted.push_back (OrderKeys (old_order, stripable->presentation_info().order()));
+               sorted.push_back (OrderKeys (old_order, stripable, cmp_max));
        }
 
        SortByNewDisplayOrder cmp;
@@ -934,6 +948,10 @@ Mixer_UI::set_session (Session* sess)
 
        _group_tabs->set_session (sess);
 
+       if (_monitor_section) {
+               _monitor_section->set_session (_session);
+       }
+
        if (!_session) {
                return;
        }
@@ -1054,7 +1072,8 @@ Mixer_UI::show_strip (MixerStrip* ms)
                MixerStrip* strip = dynamic_cast<MixerStrip*> (av);
                if (strip == ms) {
                        (*i)[stripable_columns.visible] = true;
-                       redisplay_track_list ();
+                       av->set_marked_for_display (true);
+                       update_track_visibility ();
                        break;
                }
        }
@@ -1072,7 +1091,8 @@ Mixer_UI::hide_strip (MixerStrip* ms)
                MixerStrip* strip = dynamic_cast<MixerStrip*> (av);
                if (strip == ms) {
                        (*i)[stripable_columns.visible] = false;
-                       redisplay_track_list ();
+                       av->set_marked_for_display (false);
+                       update_track_visibility ();
                        break;
                }
        }
@@ -1260,8 +1280,18 @@ void
 Mixer_UI::spill_redisplay (boost::shared_ptr<VCA> vca)
 {
        TreeModel::Children rows = track_model->children();
+       std::list<boost::shared_ptr<VCA> > vcas;
+       vcas.push_back (vca);
+
+       for (TreeModel::Children::const_iterator i = rows.begin(); i != rows.end(); ++i) {
+               AxisView* av = (*i)[stripable_columns.strip];
+               VCAMasterStrip* vms = dynamic_cast<VCAMasterStrip*> (av);
+               if (vms && vms->vca()->slaved_to (vca)) {
+                       vcas.push_back (vms->vca());
+               }
+       }
 
-       for (TreeModel::Children::iterator i = rows.begin(); i != rows.end(); ++i) {
+       for (TreeModel::Children::const_iterator i = rows.begin(); i != rows.end(); ++i) {
 
                AxisView* av = (*i)[stripable_columns.strip];
                MixerStrip* strip = dynamic_cast<MixerStrip*> (av);
@@ -1280,7 +1310,15 @@ Mixer_UI::spill_redisplay (boost::shared_ptr<VCA> vca)
                        continue;
                }
 
-               if (strip->route()->slaved_to (vca)) {
+               bool slaved = false;
+               for (std::list<boost::shared_ptr<VCA> >::const_iterator m = vcas.begin(); m != vcas.end(); ++m) {
+                       if (strip->route()->slaved_to (*m)) {
+                               slaved = true;
+                               break;
+                       }
+               }
+
+               if (slaved) {
 
                        if (strip->packed()) {
                                strip_packer.reorder_child (*strip, -1); /* put at end */
@@ -1475,10 +1513,54 @@ Mixer_UI::track_display_button_press (GdkEventButton* ev)
                show_track_list_menu ();
                return true;
        }
+       if ((ev->type == GDK_BUTTON_PRESS) && (ev->button == 1)) {
+               TreeModel::Path path;
+               TreeViewColumn* column;
+               int cellx, celly;
+               if (track_display.get_path_at_pos ((int)ev->x, (int)ev->y, path, column, cellx, celly)) {
+                       TreeIter iter = track_model->get_iter (path);
+                       if ((*iter)[stripable_columns.visible]) {
+                               boost::shared_ptr<ARDOUR::Stripable> s = (*iter)[stripable_columns.stripable];
+                               move_stripable_into_view (s);
+                       }
+               }
+       }
 
        return false;
 }
 
+void
+Mixer_UI::move_stripable_into_view (boost::shared_ptr<ARDOUR::Stripable> s)
+{
+       if (!scroller.get_hscrollbar()) {
+               return;
+       }
+       if (s->presentation_info().special () || s->presentation_info().flag_match (PresentationInfo::VCA)) {
+               return;
+       }
+#ifdef MIXBUS
+       if (s->mixbus ()) {
+               return;
+       }
+#endif
+       bool found = false;
+       int x0 = 0;
+       for (list<MixerStrip *>::const_iterator i = strips.begin(); i != strips.end(); ++i) {
+               if ((*i)->route() == s) {
+                       int y;
+                       found = true;
+                       (*i)->translate_coordinates (strip_packer, 0, 0, x0, y);
+                       break;
+               }
+       }
+       if (!found) {
+               return;
+       }
+
+       Adjustment* adj = scroller.get_hscrollbar()->get_adjustment();
+       scroller.get_hscrollbar()->set_value (max (adj->get_lower(), min (adj->get_upper(), x0 - 1.0)));
+}
+
 void
 Mixer_UI::build_track_menu ()
 {
@@ -2039,8 +2121,23 @@ Mixer_UI::scroll_left ()
 {
        if (!scroller.get_hscrollbar()) return;
        Adjustment* adj = scroller.get_hscrollbar()->get_adjustment();
-       /* stupid GTK: can't rely on clamping across versions */
-       scroller.get_hscrollbar()->set_value (max (adj->get_lower(), adj->get_value() - adj->get_step_increment()));
+       int sc_w = scroller.get_width();
+       int sp_w = strip_packer.get_width();
+       if (sp_w <= sc_w) {
+               return;
+       }
+       int lp = adj->get_value();
+       int lm = 0;
+       using namespace Gtk::Box_Helpers;
+       const BoxList& strips = strip_packer.children();
+       for (BoxList::const_iterator i = strips.begin(); i != strips.end(); ++i) {
+               lm += i->get_widget()->get_width ();
+               if (lm >= lp) {
+                       lm -= i->get_widget()->get_width ();
+                       break;
+               }
+       }
+       scroller.get_hscrollbar()->set_value (max (adj->get_lower(), min (adj->get_upper(), lm - 1.0)));
 }
 
 void
@@ -2048,8 +2145,22 @@ Mixer_UI::scroll_right ()
 {
        if (!scroller.get_hscrollbar()) return;
        Adjustment* adj = scroller.get_hscrollbar()->get_adjustment();
-       /* stupid GTK: can't rely on clamping across versions */
-       scroller.get_hscrollbar()->set_value (min (adj->get_upper(), adj->get_value() + adj->get_step_increment()));
+       int sc_w = scroller.get_width();
+       int sp_w = strip_packer.get_width();
+       if (sp_w <= sc_w) {
+               return;
+       }
+       int lp = adj->get_value();
+       int lm = 0;
+       using namespace Gtk::Box_Helpers;
+       const BoxList& strips = strip_packer.children();
+       for (BoxList::const_iterator i = strips.begin(); i != strips.end(); ++i) {
+               lm += i->get_widget()->get_width ();
+               if (lm > lp + 1) {
+                       break;
+               }
+       }
+       scroller.get_hscrollbar()->set_value (max (adj->get_lower(), min (adj->get_upper(), lm - 1.0)));
 }
 
 bool
@@ -2399,6 +2510,9 @@ Mixer_UI::refill_favorite_plugins ()
 #ifdef LXVST_SUPPORT
        refiller (plugs, mgr.lxvst_plugin_info ());
 #endif
+#ifdef MACVST_SUPPORT
+       refiller (plugs, mgr.mac_vst_plugin_info ());
+#endif
 #ifdef AUDIOUNIT_SUPPORT
        refiller (plugs, mgr.au_plugin_info ());
 #endif
@@ -2725,3 +2839,226 @@ Mixer_UI::showing_vca_slaves_for (boost::shared_ptr<VCA> vca) const
 {
        return vca == spilled_vca.lock();
 }
+
+void
+Mixer_UI::register_actions ()
+{
+       Glib::RefPtr<ActionGroup> group = myactions.create_action_group (X_("Mixer"));
+
+       myactions.register_action (group, "solo", _("Toggle Solo on Mixer-Selected Tracks/Busses"), sigc::mem_fun (*this, &Mixer_UI::solo_action));
+       myactions.register_action (group, "mute", _("Toggle Mute on Mixer-Selected Tracks/Busses"), sigc::mem_fun (*this, &Mixer_UI::mute_action));
+       myactions.register_action (group, "recenable", _("Toggle Rec-enable on Mixer-Selected Tracks/Busses"), sigc::mem_fun (*this, &Mixer_UI::rec_enable_action));
+       myactions.register_action (group, "increment-gain", _("Decrease Gain on Mixer-Selected Tracks/Busses"), sigc::mem_fun (*this, &Mixer_UI::step_gain_up_action));
+       myactions.register_action (group, "decrement-gain", _("Increase Gain on Mixer-Selected Tracks/Busses"), sigc::mem_fun (*this, &Mixer_UI::step_gain_down_action));
+       myactions.register_action (group, "unity-gain", _("Set Gain to 0dB on Mixer-Selected Tracks/Busses"), sigc::mem_fun (*this, &Mixer_UI::unity_gain_action));
+
+
+       myactions.register_action (group, "copy-processors", _("Copy Selected Processors"), sigc::mem_fun (*this, &Mixer_UI::copy_processors));
+       myactions.register_action (group, "cut-processors", _("Cut Selected Processors"), sigc::mem_fun (*this, &Mixer_UI::cut_processors));
+       myactions.register_action (group, "paste-processors", _("Paste Selected Processors"), sigc::mem_fun (*this, &Mixer_UI::paste_processors));
+       myactions.register_action (group, "delete-processors", _("Delete Selected Processors"), sigc::mem_fun (*this, &Mixer_UI::delete_processors));
+       myactions.register_action (group, "select-all-processors", _("Select All (visible) Processors"), sigc::mem_fun (*this, &Mixer_UI::select_all_processors));
+       myactions.register_action (group, "toggle-processors", _("Toggle Selected Processors"), sigc::mem_fun (*this, &Mixer_UI::toggle_processors));
+       myactions.register_action (group, "ab-plugins", _("Toggle Selected Plugins"), sigc::mem_fun (*this, &Mixer_UI::ab_plugins));
+       myactions.register_action (group, "select-none", _("Deselect all strips and processors"), sigc::mem_fun (*this, &Mixer_UI::select_none));
+
+       myactions.register_action (group, "scroll-left", _("Scroll Mixer Window to the left"), sigc::mem_fun (*this, &Mixer_UI::scroll_left));
+       myactions.register_action (group, "scroll-right", _("Scroll Mixer Window to the right"), sigc::mem_fun (*this, &Mixer_UI::scroll_right));
+
+       myactions.register_action (group, "toggle-midi-input-active", _("Toggle MIDI Input Active for Mixer-Selected Tracks/Busses"),
+                                  sigc::bind (sigc::mem_fun (*this, &Mixer_UI::toggle_midi_input_active), false));
+}
+
+void
+Mixer_UI::load_bindings ()
+{
+       bindings = Bindings::get_bindings (X_("Mixer"), myactions);
+}
+
+template<class T> void
+Mixer_UI::control_action (boost::shared_ptr<T> (Stripable::*get_control)() const)
+{
+       boost::shared_ptr<ControlList> cl (new ControlList);
+       boost::shared_ptr<AutomationControl> ac;
+       bool val = false;
+       bool have_val = false;
+
+       set_axis_targets_for_operation ();
+
+       BOOST_FOREACH(AxisView* r, _axis_targets) {
+               boost::shared_ptr<Stripable> s = r->stripable();
+               if (s) {
+                       ac = (s.get()->*get_control)();
+                       if (ac) {
+                               cl->push_back (ac);
+                               if (!have_val) {
+                                       val = !ac->get_value();
+                                       have_val = true;
+                               }
+                       }
+               }
+       }
+
+       _session->set_controls (cl,  val, Controllable::UseGroup);
+}
+
+void
+Mixer_UI::solo_action ()
+{
+       control_action (&Stripable::solo_control);
+}
+
+void
+Mixer_UI::mute_action ()
+{
+       control_action (&Stripable::mute_control);
+}
+
+void
+Mixer_UI::rec_enable_action ()
+{
+       control_action (&Stripable::rec_enable_control);
+}
+
+void
+Mixer_UI::step_gain_up_action ()
+{
+       set_axis_targets_for_operation ();
+
+       BOOST_FOREACH(AxisView* r, _axis_targets) {
+               MixerStrip* ms = dynamic_cast<MixerStrip*> (r);
+               if (ms) {
+                       ms->step_gain_up ();
+               }
+       }
+}
+
+void
+Mixer_UI::step_gain_down_action ()
+{
+       set_axis_targets_for_operation ();
+
+       BOOST_FOREACH(AxisView* r, _axis_targets) {
+               MixerStrip* ms = dynamic_cast<MixerStrip*> (r);
+               if (ms) {
+                       ms->step_gain_down ();
+               }
+       }
+}
+
+void
+Mixer_UI::unity_gain_action ()
+{
+       set_axis_targets_for_operation ();
+
+       BOOST_FOREACH(AxisView* r, _axis_targets) {
+               boost::shared_ptr<Stripable> s = r->stripable();
+               if (s) {
+                       boost::shared_ptr<AutomationControl> ac = s->gain_control();
+                       if (ac) {
+                               ac->set_value (1.0, Controllable::UseGroup);
+                       }
+               }
+       }
+}
+
+void
+Mixer_UI::copy_processors ()
+{
+       set_axis_targets_for_operation ();
+
+       BOOST_FOREACH(AxisView* r, _axis_targets) {
+               MixerStrip* ms = dynamic_cast<MixerStrip*> (r);
+               if (ms) {
+                       ms->copy_processors ();
+               }
+       }
+}
+void
+Mixer_UI::cut_processors ()
+{
+       set_axis_targets_for_operation ();
+
+       BOOST_FOREACH(AxisView* r, _axis_targets) {
+               MixerStrip* ms = dynamic_cast<MixerStrip*> (r);
+               if (ms) {
+                       ms->cut_processors ();
+               }
+       }
+}
+void
+Mixer_UI::paste_processors ()
+{
+       set_axis_targets_for_operation ();
+
+       BOOST_FOREACH(AxisView* r, _axis_targets) {
+               MixerStrip* ms = dynamic_cast<MixerStrip*> (r);
+               if (ms) {
+                       ms->paste_processors ();
+               }
+       }
+}
+void
+Mixer_UI::select_all_processors ()
+{
+       set_axis_targets_for_operation ();
+
+       BOOST_FOREACH(AxisView* r, _axis_targets) {
+               MixerStrip* ms = dynamic_cast<MixerStrip*> (r);
+               if (ms) {
+                       ms->select_all_processors ();
+               }
+       }
+}
+void
+Mixer_UI::toggle_processors ()
+{
+       set_axis_targets_for_operation ();
+
+       BOOST_FOREACH(AxisView* r, _axis_targets) {
+               MixerStrip* ms = dynamic_cast<MixerStrip*> (r);
+               if (ms) {
+                       ms->toggle_processors ();
+               }
+       }
+}
+void
+Mixer_UI::ab_plugins ()
+{
+       set_axis_targets_for_operation ();
+
+       BOOST_FOREACH(AxisView* r, _axis_targets) {
+               MixerStrip* ms = dynamic_cast<MixerStrip*> (r);
+               if (ms) {
+                       ms->ab_plugins ();
+               }
+       }
+}
+
+void
+Mixer_UI::vca_assign (boost::shared_ptr<VCA> vca)
+{
+       set_axis_targets_for_operation ();
+#if 0
+       BOOST_FOREACH(AxisView* r, _axis_targets) {
+               MixerStrip* ms = dynamic_cast<MixerStrip*> (r);
+               if (ms) {
+                       ms->vca_assign (vca);
+               }
+       }
+#endif
+}
+
+void
+Mixer_UI::vca_unassign (boost::shared_ptr<VCA> vca)
+{
+       set_axis_targets_for_operation ();
+#if 0
+       BOOST_FOREACH(AxisView* r, _axis_targets) {
+               MixerStrip* ms = dynamic_cast<MixerStrip*> (r);
+               if (ms) {
+                       ms->vca_unassign (vca);
+               }
+       }
+#endif
+}