Fix gain inc/dec with multiple-selection spanning groups
[ardour.git] / gtk2_ardour / mixer_ui.cc
index 55d1d115428a2a00229674c8cebaa9d84644a282..c775b9b2b9b4dc8b16d4bee92d6a9d276370ab92 100644 (file)
@@ -48,6 +48,7 @@
 #include "ardour/midi_track.h"
 #include "ardour/plugin_manager.h"
 #include "ardour/route_group.h"
+#include "ardour/selection.h"
 #include "ardour/session.h"
 #include "ardour/vca.h"
 #include "ardour/vca_manager.h"
@@ -71,7 +72,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;
@@ -105,18 +106,18 @@ Mixer_UI::Mixer_UI ()
        , _plugin_selector (0)
        , _strip_width (UIConfiguration::instance().get_default_narrow_ms() ? Narrow : Wide)
        , ignore_reorder (false)
-        , _in_group_rebuild_or_clear (false)
-        , _route_deletion_in_progress (false)
-       , _following_editor_selection (false)
+       , _in_group_rebuild_or_clear (false)
+       , _route_deletion_in_progress (false)
        , _maximised (false)
        , _show_mixer_list (true)
        , myactions (X_("mixer"))
+       , _selection (*this, *this)
 {
        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());
+       PresentationInfo::Change.connect (*this, invalidator (*this), boost::bind (&Mixer_UI::presentation_info_changed, this, _1), gui_context());
 
        scroller.set_can_default (true);
        // set_default (scroller);
@@ -137,9 +138,12 @@ 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 ();
+       b->signal_scroll_event().connect (sigc::mem_fun (*this, &Mixer_UI::on_scroll_event), false);
 
        scroller.add (*b);
        scroller.set_policy (Gtk::POLICY_ALWAYS, Gtk::POLICY_AUTOMATIC);
@@ -251,17 +255,7 @@ 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_name (X_("VCALabelBar"));
-       vca_label_bar.add (vca_label);
-
+       vca_label_bar.set_size_request (-1, 16 + 1); /* must match height in GroupTabs::set_size_request()  + 1 border px*/
        vca_vpacker.pack_start (vca_label_bar, false, false);
 
        vca_scroller_base.add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK);
@@ -284,36 +278,30 @@ Mixer_UI::Mixer_UI ()
        list_hpane.set_check_divider_position (true);
        list_hpane.add (list_vpacker);
        list_hpane.add (global_hpacker);
-
+       list_hpane.set_child_minsize (list_vpacker, 1);
 
        XMLNode const * settings = ARDOUR_UI::instance()->mixer_settings();
-       XMLProperty const * prop;
        float fract;
 
-       {
-               LocaleGuard lg;
+       if (!settings || !settings->get_property ("mixer-rhs-pane1-pos", fract) || fract > 1.0) {
+               fract = 0.6f;
+       }
+       rhs_pane1.set_divider (0, fract);
 
-               if (!settings || ((prop = settings->property ("mixer-rhs-pane1-pos")) == 0) || ((fract = atof (prop->value())) > 1.0)) {
-                       rhs_pane1.set_divider (0, 0.6f);
-               } else {
-                       rhs_pane1.set_divider (0, fract);
-               }
-               if (!settings || ((prop = settings->property ("mixer-rhs-pane2-pos")) == 0) || ((fract = atof (prop->value())) > 1.0)) {
-                       rhs_pane2.set_divider (0, 0.7f);
-               } else {
-                       rhs_pane2.set_divider (0, fract);
-               }
-               if (!settings || ((prop = settings->property ("mixer-list-hpane-pos")) == 0) || ((fract = atof (prop->value())) > 1.0)) {
-                       list_hpane.set_divider (0, 0.2f);
-               } else {
-                       list_hpane.set_divider (0, fract);
-               }
-               if (!settings || ((prop = settings->property ("mixer-inner-pane-pos")) == 0)  || ((fract = atof (prop->value())) > 1.0)) {
-                       inner_pane.set_divider (0, 0.8f);
-               } else {
-                       inner_pane.set_divider (0, atof (prop->value()));
-               }
+       if (!settings || !settings->get_property ("mixer-rhs-pane2-pos", fract) || fract > 1.0) {
+               fract = 0.7f;
        }
+       rhs_pane2.set_divider (0, fract);
+
+       if (!settings || !settings->get_property ("mixer-list-hpane-pos", fract) || fract > 1.0) {
+               fract = 0.2f;
+       }
+       list_hpane.set_divider (0, fract);
+
+       if (!settings || !settings->get_property ("mixer-inner-pane-pos", fract) || fract > 1.0) {
+               fract = 0.8f;
+       }
+       inner_pane.set_divider (0, fract);
 
        rhs_pane1.set_drag_cursor (*PublicEditor::instance().cursors()->expand_up_down);
        rhs_pane2.set_drag_cursor (*PublicEditor::instance().cursors()->expand_up_down);
@@ -348,7 +336,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();
@@ -383,6 +370,7 @@ Mixer_UI::~Mixer_UI ()
                delete _monitor_section;
        }
        delete _plugin_selector;
+       delete track_menu;
 }
 
 void
@@ -391,12 +379,6 @@ Mixer_UI::escape ()
        select_none ();
 }
 
-void
-Mixer_UI::track_editor_selection ()
-{
-       PublicEditor::instance().get_selection().TracksChanged.connect (sigc::mem_fun (*this, &Mixer_UI::follow_editor_selection));
-}
-
 Gtk::Window*
 Mixer_UI::use_own_window (bool and_fill_it)
 {
@@ -404,14 +386,16 @@ Mixer_UI::use_own_window (bool and_fill_it)
 
        Gtk::Window* win = Tabbable::use_own_window (and_fill_it);
 
-
        if (win && new_window) {
                win->set_name ("MixerWindow");
                ARDOUR_UI::instance()->setup_toplevel_window (*win, _("Mixer"), this);
-               win->signal_scroll_event().connect (sigc::mem_fun (*this, &Mixer_UI::on_scroll_event), false);
                win->signal_event().connect (sigc::bind (sigc::ptr_fun (&Keyboard::catch_user_event_for_pre_dialog_focus), win));
                win->set_data ("ardour-bindings", bindings);
                update_title ();
+               if (!win->get_focus()) {
+                       /* set focus widget to something, anything */
+                       win->set_focus (scroller);
+               }
        }
 
        return win;
@@ -458,7 +442,7 @@ Mixer_UI::remove_master (VCAMasterStrip* vms)
 
        for (ri = rows.begin(); ri != rows.end(); ++ri) {
                if ((*ri)[stripable_columns.strip] == vms) {
-                        PBD::Unwinder<bool> uw (_route_deletion_in_progress, true);
+                       PBD::Unwinder<bool> uw (_route_deletion_in_progress, true);
                        track_model->erase (ri);
                        break;
                }
@@ -509,7 +493,7 @@ Mixer_UI::add_stripables (StripableList& slist)
        bool from_scratch = (track_model->children().size() == 0);
        uint32_t nroutes = 0;
 
-       slist.sort (StripablePresentationInfoSorter());
+       slist.sort (Stripable::Sorter());
 
        for (Gtk::TreeModel::Children::iterator it = track_model->children().begin(); it != track_model->children().end(); ++it) {
                boost::shared_ptr<Stripable> s = (*it)[stripable_columns.stripable];
@@ -520,6 +504,7 @@ Mixer_UI::add_stripables (StripableList& slist)
 
                nroutes++;
 
+               // XXX what does this special case do?
                if (s->presentation_info().order() == (slist.front()->presentation_info().order() + slist.size())) {
                        insert_iter = it;
                        break;
@@ -528,7 +513,6 @@ Mixer_UI::add_stripables (StripableList& slist)
 
        MixerStrip* strip;
 
-
        try {
                PBD::Unwinder<bool> uw (no_track_list_redisplay, true);
 
@@ -576,7 +560,11 @@ Mixer_UI::add_stripables (StripableList& slist)
                                        _monitor_section->tearoff().Detach.connect (sigc::mem_fun(*this, &Mixer_UI::monitor_section_detached));
                                        _monitor_section->tearoff().Attach.connect (sigc::mem_fun(*this, &Mixer_UI::monitor_section_attached));
 
-                                       monitor_section_attached ();
+                                       if (_monitor_section->tearoff().torn_off()) {
+                                               monitor_section_detached ();
+                                       } else {
+                                               monitor_section_attached ();
+                                       }
 
                                        route->DropReferences.connect (*this, invalidator(*this), boost::bind (&Mixer_UI::monitor_section_going_away, this), gui_context());
 
@@ -605,10 +593,6 @@ Mixer_UI::add_stripables (StripableList& slist)
                                        row[stripable_columns.stripable] = route;
                                        row[stripable_columns.strip] = strip;
 
-                                       if (nroutes != 0) {
-                                               _selection.add (strip);
-                                       }
-
                                } else {
 
                                        out_packer.pack_start (*strip, false, false);
@@ -621,7 +605,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;
@@ -629,6 +613,9 @@ Mixer_UI::add_stripables (StripableList& slist)
 
        track_display.set_model (track_model);
 
+       /* catch up on selection state, which we left to the editor to set */
+       sync_treeview_from_presentation_info (PropertyChange (Properties::selected));
+
        if (!from_scratch) {
                sync_presentation_info_from_treeview ();
        }
@@ -644,16 +631,6 @@ Mixer_UI::deselect_all_strip_processors ()
        }
 }
 
-void
-Mixer_UI::select_strip (MixerStrip& ms, bool add)
-{
-       if (add) {
-               _selection.add (&ms);
-       } else {
-               _selection.set (&ms);
-       }
-}
-
 void
 Mixer_UI::select_none ()
 {
@@ -686,15 +663,34 @@ Mixer_UI::remove_strip (MixerStrip* strip)
                strips.erase (i);
        }
 
+       PBD::Unwinder<bool> uwi (ignore_reorder, true);
+
        for (ri = rows.begin(); ri != rows.end(); ++ri) {
                if ((*ri)[stripable_columns.strip] == strip) {
-                        PBD::Unwinder<bool> uw (_route_deletion_in_progress, true);
+                       PBD::Unwinder<bool> uw (_route_deletion_in_progress, true);
                        track_model->erase (ri);
                        break;
                }
        }
 }
 
+void
+Mixer_UI::presentation_info_changed (PropertyChange const & what_changed)
+{
+       if (what_changed.contains (Properties::selected)) {
+               _selection.presentation_info_changed (what_changed);
+       }
+
+       PropertyChange soh;
+       soh.add (Properties::selected);
+       soh.add (Properties::order);
+       soh.add (Properties::hidden);
+
+       if (what_changed.contains (soh)) {
+               sync_treeview_from_presentation_info (what_changed);
+       }
+}
+
 void
 Mixer_UI::sync_presentation_info_from_treeview ()
 {
@@ -712,46 +708,55 @@ Mixer_UI::sync_presentation_info_from_treeview ()
 
        TreeModel::Children::iterator ri;
        bool change = false;
-       uint32_t order = 0;
+
+       PresentationInfo::order_t master_key = _session->master_order_key ();
+       PresentationInfo::order_t order = 0;
+
+       PresentationInfo::ChangeSuspender cs;
 
        for (ri = rows.begin(); ri != rows.end(); ++ri) {
                bool visible = (*ri)[stripable_columns.visible];
                boost::shared_ptr<Stripable> stripable = (*ri)[stripable_columns.stripable];
 
+#ifndef NDEBUG // these should not exist in the mixer's treeview
                if (!stripable) {
+                       assert (0);
                        continue;
                }
-
-               /* Monitor and Auditioner do not get their presentation
-                * info reset here.
-                */
-
                if (stripable->is_monitor() || stripable->is_auditioner()) {
+                       assert (0);
                        continue;
                }
-
-               /* Master also doesn't get set here but since the editor allows
-                * it to be reordered, we need to preserve its ordering.
-                */
+               if (stripable->is_master()) {
+                       assert (0);
+                       continue;
+               }
+#endif
 
                stripable->presentation_info().set_hidden (!visible);
 
+               // leave master where it is.
+               if (order == master_key) {
+                       ++order;
+               }
+
                if (order != stripable->presentation_info().order()) {
-                       stripable->set_presentation_order_explicit (order);
+                       stripable->set_presentation_order (order);
                        change = true;
                }
-
                ++order;
        }
 
+       change |= _session->ensure_stripable_sort_order ();
+
        if (change) {
                DEBUG_TRACE (DEBUG::OrderKeys, "... notify PI change from mixer GUI\n");
-               _session->notify_presentation_info_change ();
+               _session->set_dirty();
        }
 }
 
 void
-Mixer_UI::sync_treeview_from_presentation_info ()
+Mixer_UI::sync_treeview_from_presentation_info (PropertyChange const & what_changed)
 {
        if (!_session || _session->deletion_in_progress()) {
                return;
@@ -773,21 +778,20 @@ Mixer_UI::sync_treeview_from_presentation_info ()
                return;
        }
 
-       OrderingKeys sorted;
-
+       TreeOrderKeys sorted;
        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 (TreeOrderKey (old_order, stripable));
        }
 
-       SortByNewDisplayOrder cmp;
+       TreeOrderKeySorter cmp;
 
        sort (sorted.begin(), sorted.end(), cmp);
        neworder.assign (sorted.size(), 0);
 
        uint32_t n = 0;
 
-       for (OrderingKeys::iterator sr = sorted.begin(); sr != sorted.end(); ++sr, ++n) {
+       for (TreeOrderKeys::iterator sr = sorted.begin(); sr != sorted.end(); ++sr, ++n) {
 
                neworder[n] = sr->old_display_order;
 
@@ -801,35 +805,25 @@ Mixer_UI::sync_treeview_from_presentation_info ()
                track_model->reorder (neworder);
        }
 
-       redisplay_track_list ();
-}
-
-void
-Mixer_UI::follow_editor_selection ()
-{
-       if (_following_editor_selection) {
-               return;
-       }
-
-       _following_editor_selection = true;
-       _selection.block_routes_changed (true);
+       if (what_changed.contains (Properties::selected)) {
 
-       TrackSelection& s (PublicEditor::instance().get_selection().tracks);
+               PresentationInfo::ChangeSuspender cs;
 
-       _selection.clear_routes ();
-
-       for (TrackViewList::iterator i = s.begin(); i != s.end(); ++i) {
-               TimeAxisView* tav = dynamic_cast<TimeAxisView*> (*i);
-               if (tav) {
-                       AxisView* axis = axis_by_stripable (tav->stripable());
-                       if (axis) {
-                               _selection.add (axis);
+               for (list<MixerStrip *>::const_iterator i = strips.begin(); i != strips.end(); ++i) {
+                       boost::shared_ptr<Stripable> stripable = (*i)->stripable();
+                       if (stripable && stripable->is_selected()) {
+                               _selection.add (*i);
+                       } else {
+                               _selection.remove (*i);
                        }
                }
+
+               if (!_selection.axes.empty() && !PublicEditor::instance().track_selection_change_without_scroll ()) {
+                       move_stripable_into_view ((*_selection.axes.begin())->stripable());
+               }
        }
 
-       _following_editor_selection = false;
-       _selection.block_routes_changed (false);
+       redisplay_track_list ();
 }
 
 
@@ -845,8 +839,20 @@ Mixer_UI::strip_by_route (boost::shared_ptr<Route> r) const
        return 0;
 }
 
+MixerStrip*
+Mixer_UI::strip_by_stripable (boost::shared_ptr<Stripable> s) const
+{
+       for (list<MixerStrip *>::const_iterator i = strips.begin(); i != strips.end(); ++i) {
+               if ((*i)->stripable() == s) {
+                       return (*i);
+               }
+       }
+
+       return 0;
+}
+
 AxisView*
-Mixer_UI::axis_by_stripable (boost::shared_ptr<Stripable> s) const
+Mixer_UI::axis_view_by_stripable (boost::shared_ptr<Stripable> s) const
 {
        for (list<MixerStrip *>::const_iterator i = strips.begin(); i != strips.end(); ++i) {
                if ((*i)->stripable() == s) {
@@ -857,6 +863,27 @@ Mixer_UI::axis_by_stripable (boost::shared_ptr<Stripable> s) const
        return 0;
 }
 
+AxisView*
+Mixer_UI::axis_view_by_control (boost::shared_ptr<AutomationControl> c) const
+{
+       for (list<MixerStrip *>::const_iterator i = strips.begin(); i != strips.end(); ++i) {
+               if ((*i)->control() == c) {
+                       return (*i);
+               }
+       }
+
+       return 0;
+}
+
+struct MixerStripSorter {
+       bool operator() (const MixerStrip* ms_a, const MixerStrip* ms_b)
+       {
+               boost::shared_ptr<ARDOUR::Stripable> const& a = ms_a->stripable ();
+               boost::shared_ptr<ARDOUR::Stripable> const& b = ms_b->stripable ();
+               return ARDOUR::Stripable::Sorter(true)(a, b);
+       }
+};
+
 bool
 Mixer_UI::strip_button_release_event (GdkEventButton *ev, MixerStrip *strip)
 {
@@ -880,10 +907,13 @@ Mixer_UI::strip_button_release_event (GdkEventButton *ev, MixerStrip *strip)
                                bool accumulate = false;
                                bool found_another = false;
 
-                               tmp.push_back (strip);
+                               strips.sort (MixerStripSorter());
 
                                for (list<MixerStrip*>::iterator i = strips.begin(); i != strips.end(); ++i) {
-                                       if ((*i) == strip) {
+                                       MixerStrip* ms = *i;
+                                       assert (ms);
+
+                                       if (ms == strip) {
                                                /* hit clicked strip, start accumulating till we hit the first
                                                   selected strip
                                                */
@@ -893,7 +923,7 @@ Mixer_UI::strip_button_release_event (GdkEventButton *ev, MixerStrip *strip)
                                                } else {
                                                        accumulate = true;
                                                }
-                                       } else if (_selection.selected (*i)) {
+                                       } else if (_selection.selected (ms)) {
                                                /* hit selected strip. if currently accumulating others,
                                                   we're done. if not accumulating others, start doing so.
                                                */
@@ -906,17 +936,21 @@ Mixer_UI::strip_button_release_event (GdkEventButton *ev, MixerStrip *strip)
                                                }
                                        } else {
                                                if (accumulate) {
-                                                       tmp.push_back (*i);
+                                                       tmp.push_back (ms);
                                                }
                                        }
                                }
 
+                               tmp.push_back (strip);
+
                                if (found_another) {
+                                       PresentationInfo::ChangeSuspender cs;
                                        for (vector<MixerStrip*>::iterator i = tmp.begin(); i != tmp.end(); ++i) {
                                                _selection.add (*i);
                                        }
-                               } else
+                               } else {
                                        _selection.set (strip);  //user wants to start a range selection, but there aren't any others selected yet
+                               }
                        } else {
                                _selection.set (strip);
                        }
@@ -937,7 +971,12 @@ Mixer_UI::set_session (Session* sess)
 
        _group_tabs->set_session (sess);
 
+       if (_monitor_section) {
+               _monitor_section->set_session (_session);
+       }
+
        if (!_session) {
+               _selection.clear ();
                return;
        }
 
@@ -967,6 +1006,13 @@ Mixer_UI::set_session (Session* sess)
        if (_visible) {
                show_window();
        }
+
+       /* catch up on selection state, etc. */
+
+       PropertyChange sc;
+       sc.add (Properties::selected);
+       _selection.presentation_info_changed (sc);
+
        start_updating ();
 }
 
@@ -1057,7 +1103,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;
                }
        }
@@ -1075,7 +1122,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;
                }
        }
@@ -1084,15 +1132,15 @@ Mixer_UI::hide_strip (MixerStrip* ms)
 gint
 Mixer_UI::start_updating ()
 {
-    fast_screen_update_connection = Timers::super_rapid_connect (sigc::mem_fun(*this, &Mixer_UI::fast_update_strips));
-    return 0;
+       fast_screen_update_connection = Timers::super_rapid_connect (sigc::mem_fun(*this, &Mixer_UI::fast_update_strips));
+       return 0;
 }
 
 gint
 Mixer_UI::stop_updating ()
 {
-    fast_screen_update_connection.disconnect();
-    return 0;
+       fast_screen_update_connection.disconnect();
+       return 0;
 }
 
 void
@@ -1254,20 +1302,31 @@ Mixer_UI::track_list_delete (const Gtk::TreeModel::Path&)
        DEBUG_TRACE (DEBUG::OrderKeys, "mixer UI treeview row deleted\n");
        sync_presentation_info_from_treeview ();
 
-        if (_route_deletion_in_progress) {
-                redisplay_track_list ();
-        }
+       if (_route_deletion_in_progress) {
+               redisplay_track_list ();
+       }
 }
 
 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::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];
+               VCAMasterStrip* vms = dynamic_cast<VCAMasterStrip*> (av);
+               if (vms && vms->vca()->slaved_to (vca)) {
+                       vcas.push_back (vms->vca());
+               }
+       }
+
+       for (TreeModel::Children::const_iterator i = rows.begin(); i != rows.end(); ++i) {
 
                AxisView* av = (*i)[stripable_columns.strip];
                MixerStrip* strip = dynamic_cast<MixerStrip*> (av);
+               bool const visible = (*i)[stripable_columns.visible];
 
                if (!strip) {
                        /* we're in the middle of changing a row, don't worry */
@@ -1283,7 +1342,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 && visible) {
 
                        if (strip->packed()) {
                                strip_packer.reorder_child (*strip, -1); /* put at end */
@@ -1309,11 +1376,13 @@ Mixer_UI::redisplay_track_list ()
                return;
        }
 
-       boost::shared_ptr<VCA> sv = spilled_vca.lock ();
-
-       if (sv) {
-               spill_redisplay (sv);
-               return;
+       boost::shared_ptr<Stripable> ss = spilled_strip.lock ();
+       if (ss) {
+               boost::shared_ptr<VCA> sv = boost::dynamic_pointer_cast<VCA> (ss);
+               if (sv) {
+                       spill_redisplay (sv);
+                       return;
+               }
        }
 
        TreeModel::Children rows = track_model->children();
@@ -1458,30 +1527,75 @@ Mixer_UI::initial_track_display ()
                add_stripables (sl);
        }
 
-       redisplay_track_list ();
-}
-
-void
-Mixer_UI::show_track_list_menu ()
-{
-       if (track_menu == 0) {
-               build_track_menu ();
-       }
-
-       track_menu->popup (1, gtk_get_current_event_time());
+       sync_treeview_from_presentation_info (Properties::order);
 }
 
 bool
 Mixer_UI::track_display_button_press (GdkEventButton* ev)
 {
        if (Keyboard::is_context_menu_event (ev)) {
-               show_track_list_menu ();
+               if (track_menu == 0) {
+                       build_track_menu ();
+               }
+               track_menu->popup (ev->button, ev->time);
                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;
+       Gtk::Allocation alloc;
+       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);
+                       alloc = (*i)->get_allocation ();
+                       break;
+               }
+       }
+       if (!found) {
+               return;
+       }
+
+       Adjustment* adj = scroller.get_hscrollbar()->get_adjustment();
+
+       if (x0 < adj->get_value()) {
+               adj->set_value (max (adj->get_lower(), min (adj->get_upper(), (double) x0)));
+       } else if (x0 + alloc.get_width() >= adj->get_value() + adj->get_page_size()) {
+               int x1 = x0 + alloc.get_width() - adj->get_page_size();
+               adj->set_value (max (adj->get_lower(), min (adj->get_upper(), (double) x1)));
+       }
+}
+
 void
 Mixer_UI::build_track_menu ()
 {
@@ -1537,6 +1651,10 @@ Mixer_UI::stripable_property_changed (const PropertyChange& what_changed, boost:
                }
        }
 
+       if (s->is_master ()) {
+               return;
+       }
+
        error << _("track display list item for renamed strip not found!") << endmsg;
 }
 
@@ -1549,13 +1667,17 @@ Mixer_UI::group_display_button_press (GdkEventButton* ev)
        int celly;
 
        if (!group_display.get_path_at_pos ((int)ev->x, (int)ev->y, path, column, cellx, celly)) {
-               _group_tabs->get_menu(0)->popup (1, ev->time);
+               if (ev->button == 3) {
+                       _group_tabs->get_menu(0)->popup (ev->button, ev->time);
+               }
                return true;
        }
 
        TreeIter iter = group_model->get_iter (path);
        if (!iter) {
-               _group_tabs->get_menu(0)->popup (1, ev->time);
+               if (ev->button == 3) {
+                       _group_tabs->get_menu(0)->popup (ev->button, ev->time);
+               }
                return true;
        }
 
@@ -1933,27 +2055,21 @@ private:
 int
 Mixer_UI::set_state (const XMLNode& node, int version)
 {
-       XMLProperty const * prop;
-       LocaleGuard lg;
+       bool yn;
 
        Tabbable::set_state (node, version);
 
-       if ((prop = node.property ("narrow-strips"))) {
-               if (string_is_affirmative (prop->value())) {
+       if (node.get_property ("narrow-strips", yn)) {
+               if (yn) {
                        set_strip_width (Narrow);
                } else {
                        set_strip_width (Wide);
                }
        }
 
-       if ((prop = node.property ("show-mixer"))) {
-               if (string_is_affirmative (prop->value())) {
-                      _visible = true;
-               }
-       }
+       node.get_property ("show-mixer", _visible);
 
-       if ((prop = node.property ("maximised"))) {
-               bool yn = string_is_affirmative (prop->value());
+       if (node.get_property ("maximised", yn)) {
                Glib::RefPtr<Action> act = ActionManager::get_action (X_("Common"), X_("ToggleMaximalMixer"));
                assert (act);
                Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
@@ -1963,8 +2079,7 @@ Mixer_UI::set_state (const XMLNode& node, int version)
                }
        }
 
-       if ((prop = node.property ("show-mixer-list"))) {
-               bool yn = string_is_affirmative (prop->value());
+       if (node.get_property ("show-mixer-list", yn)) {
                Glib::RefPtr<Action> act = ActionManager::get_action (X_("Common"), X_("ToggleMixerList"));
                assert (act);
                Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
@@ -1974,6 +2089,14 @@ Mixer_UI::set_state (const XMLNode& node, int version)
                tact->set_active (yn);
        }
 
+       if (node.get_property ("monitor-section-visible", yn)) {
+               Glib::RefPtr<Action> act = ActionManager::get_action ("Common", "ToggleMonitorSection");
+               Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
+               /* do it twice to force the change */
+               tact->set_active (yn);
+               show_monitor_section (yn);
+       }
+
 
        XMLNode* plugin_order;
        if ((plugin_order = find_named_node (node, "PluginOrder")) != 0) {
@@ -1982,11 +2105,11 @@ Mixer_UI::set_state (const XMLNode& node, int version)
                const XMLNodeList& kids = plugin_order->children("PluginInfo");
                XMLNodeConstIterator i;
                for (i = kids.begin(); i != kids.end(); ++i) {
-                       if ((prop = (*i)->property ("unique-id"))) {
-                               std::string unique_id = prop->value();
+                       std::string unique_id;
+                       if ((*i)->get_property ("unique-id", unique_id)) {
                                order.push_back (unique_id);
-                               if ((prop = (*i)->property ("expanded"))) {
-                                       favorite_ui_state[unique_id] = string_is_affirmative (prop->value());
+                               if ((*i)->get_property ("expanded", yn)) {
+                                       favorite_ui_state[unique_id] = yn;
                                }
                        }
                }
@@ -2001,34 +2124,33 @@ XMLNode&
 Mixer_UI::get_state ()
 {
        XMLNode* node = new XMLNode (X_("Mixer"));
-       char buf[128];
-       LocaleGuard lg;
 
        node->add_child_nocopy (Tabbable::get_state());
 
-       snprintf(buf,sizeof(buf), "%f", rhs_pane1.get_divider());
-       node->add_property(X_("mixer-rhs-pane1-pos"), string(buf));
-       snprintf(buf,sizeof(buf), "%f", rhs_pane2.get_divider());
-       node->add_property(X_("mixer-rhs_pane2-pos"), string(buf));
-       snprintf(buf,sizeof(buf), "%f", list_hpane.get_divider());
-       node->add_property(X_("mixer-list-hpane-pos"), string(buf));
-       snprintf(buf,sizeof(buf), "%f", inner_pane.get_divider());
-       node->add_property(X_("mixer-inner-pane-pos"), string(buf));
+       node->set_property (X_("mixer-rhs-pane1-pos"), rhs_pane1.get_divider());
+       node->set_property (X_("mixer-rhs_pane2-pos"), rhs_pane2.get_divider());
+       node->set_property (X_("mixer-list-hpane-pos"), list_hpane.get_divider());
+       node->set_property (X_("mixer-inner-pane-pos"),  inner_pane.get_divider());
+
+       node->set_property ("narrow-strips", (_strip_width == Narrow));
+       node->set_property ("show-mixer", _visible);
+       node->set_property ("show-mixer-list", _show_mixer_list);
+       node->set_property ("maximised", _maximised);
 
-       node->add_property ("narrow-strips", _strip_width == Narrow ? "yes" : "no");
-       node->add_property ("show-mixer", _visible ? "yes" : "no");
-       node->add_property ("show-mixer-list", _show_mixer_list ? "yes" : "no");
-       node->add_property ("maximised", _maximised ? "yes" : "no");
+       Glib::RefPtr<Action> act = ActionManager::get_action ("Common", "ToggleMonitorSection");
+       Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
+       assert (tact);
+       node->set_property ("monitor-section-visible", tact->get_active ());
 
        store_current_favorite_order ();
        XMLNode* plugin_order = new XMLNode ("PluginOrder");
-       int cnt = 0;
+       uint32_t cnt = 0;
        for (PluginInfoList::const_iterator i = favorite_order.begin(); i != favorite_order.end(); ++i, ++cnt) {
                XMLNode* p = new XMLNode ("PluginInfo");
-               p->add_property ("sort", cnt);
-               p->add_property ("unique-id", (*i)->unique_id);
+               p->set_property ("sort", cnt);
+               p->set_property ("unique-id", (*i)->unique_id);
                if (favorite_ui_state.find ((*i)->unique_id) != favorite_ui_state.end ()) {
-                       p->add_property ("expanded", favorite_ui_state[(*i)->unique_id]);
+                       p->set_property ("expanded", favorite_ui_state[(*i)->unique_id]);
                }
                plugin_order->add_child_nocopy (*p);
        }
@@ -2042,8 +2164,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
@@ -2051,8 +2188,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
@@ -2100,10 +2251,6 @@ Mixer_UI::parameter_changed (string const & p)
                for (list<MixerStrip*>::iterator i = strips.begin(); i != strips.end(); ++i) {
                        (*i)->set_width_enum (s ? Narrow : Wide, this);
                }
-       } else if (p == "use-monitor-bus") {
-               if (_session && !_session->monitor_out()) {
-                       monitor_section_detached ();
-               }
        }
 }
 
@@ -2252,6 +2399,22 @@ void
 Mixer_UI::monitor_section_going_away ()
 {
        if (_monitor_section) {
+               XMLNode* ui_node = Config->extra_xml(X_("UI"));
+               /* immediate state save.
+                *
+                * Tearoff settings are otherwise only stored during
+                * save_ardour_state(). The mon-section may or may not
+                * exist at that point.
+                * */
+               if (ui_node) {
+                       XMLNode* tearoff_node = ui_node->child (X_("Tearoffs"));
+                       if (tearoff_node) {
+                               tearoff_node->remove_nodes_and_delete (X_("monitor-section"));
+                               XMLNode* t = new XMLNode (X_("monitor-section"));
+                               _monitor_section->tearoff().add_state (*t);
+                               tearoff_node->add_child_nocopy (*t);
+                       }
+               }
                monitor_section_detached ();
                out_packer.remove (_monitor_section->tearoff());
                _monitor_section->set_session (0);
@@ -2316,7 +2479,7 @@ Mixer_UI::monitor_section_attached ()
        Glib::RefPtr<Action> act = ActionManager::get_action ("Common", "ToggleMonitorSection");
        Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
        act->set_sensitive (true);
-       tact->set_active ();
+       show_monitor_section (tact->get_active ());
 }
 
 void
@@ -2402,6 +2565,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
@@ -2708,13 +2874,13 @@ Mixer_UI::do_vca_unassign (boost::shared_ptr<VCA> vca)
 }
 
 void
-Mixer_UI::show_vca_slaves (boost::shared_ptr<VCA> vca)
+Mixer_UI::show_spill (boost::shared_ptr<Stripable> s)
 {
-       boost::shared_ptr<VCA> v = spilled_vca.lock();
-       if (v != vca) {
-               spilled_vca = vca;
-               show_vca_change (vca); /* EMIT SIGNAL */
-               if (vca) {
+       boost::shared_ptr<Stripable> ss = spilled_strip.lock();
+       if (ss != s) {
+               spilled_strip = s;
+               show_spill_change (s); /* EMIT SIGNAL */
+               if (s) {
                        _group_tabs->hide ();
                } else {
                        _group_tabs->show ();
@@ -2724,9 +2890,15 @@ Mixer_UI::show_vca_slaves (boost::shared_ptr<VCA> vca)
 }
 
 bool
-Mixer_UI::showing_vca_slaves_for (boost::shared_ptr<VCA> vca) const
+Mixer_UI::showing_spill_for (boost::shared_ptr<Stripable> s) const
 {
-       return vca == spilled_vca.lock();
+       return s == spilled_strip.lock();
+}
+
+void
+Mixer_UI::show_editor_window () const
+{
+       PublicEditor::instance().make_visible ();
 }
 
 void
@@ -2734,6 +2906,8 @@ Mixer_UI::register_actions ()
 {
        Glib::RefPtr<ActionGroup> group = myactions.create_action_group (X_("Mixer"));
 
+       myactions.register_action (group, "show-editor", _("Show Editor"), sigc::mem_fun (*this, &Mixer_UI::show_editor_window));
+
        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));
@@ -2752,7 +2926,7 @@ Mixer_UI::register_actions ()
        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 left"), sigc::mem_fun (*this, &Mixer_UI::scroll_right));
+       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));
@@ -2809,29 +2983,44 @@ Mixer_UI::rec_enable_action ()
        control_action (&Stripable::rec_enable_control);
 }
 
-void
-Mixer_UI::step_gain_up_action ()
+AutomationControlSet
+Mixer_UI::selected_gaincontrols ()
 {
        set_axis_targets_for_operation ();
-
+       AutomationControlSet rv;
        BOOST_FOREACH(AxisView* r, _axis_targets) {
                MixerStrip* ms = dynamic_cast<MixerStrip*> (r);
                if (ms) {
-                       ms->step_gain_up ();
+                       boost::shared_ptr<GainControl> ac (ms->route()->gain_control());
+                       ControlList cl (ac->grouped_controls());
+                       for (ControlList::const_iterator c = cl.begin(); c != cl.end (); ++c) {
+                               rv.insert (*c);
+                       }
+                       rv.insert (ac);
                }
        }
+       return rv;
 }
 
 void
-Mixer_UI::step_gain_down_action ()
+Mixer_UI::step_gain_up_action ()
 {
-       set_axis_targets_for_operation ();
+       AutomationControlSet acs = selected_gaincontrols ();
+       for (AutomationControlSet::const_iterator i = acs.begin(); i != acs.end (); ++i) {
+               boost::shared_ptr<GainControl> ac = boost::dynamic_pointer_cast<GainControl> (*i);
+               assert (ac);
+               ac->set_value (dB_to_coefficient (accurate_coefficient_to_dB (ac->get_value()) + 0.1), Controllable::NoGroup);
+       }
+}
 
-       BOOST_FOREACH(AxisView* r, _axis_targets) {
-               MixerStrip* ms = dynamic_cast<MixerStrip*> (r);
-               if (ms) {
-                       ms->step_gain_down ();
-               }
+void
+Mixer_UI::step_gain_down_action ()
+{
+       AutomationControlSet acs = selected_gaincontrols ();
+       for (AutomationControlSet::const_iterator i = acs.begin(); i != acs.end (); ++i) {
+               boost::shared_ptr<GainControl> ac = boost::dynamic_pointer_cast<GainControl> (*i);
+               assert (ac);
+               ac->set_value (dB_to_coefficient (accurate_coefficient_to_dB (ac->get_value()) - 0.1), Controllable::NoGroup);
        }
 }
 
@@ -2928,26 +3117,22 @@ 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
 }