only show plugin context-menu if there is a selection
[ardour.git] / gtk2_ardour / mixer_ui.cc
index 8126a81e85837c1abbd96b510ec14f74fd8b0c22..45299ba020b96b97cf041a29e22a89d60cc77741 100644 (file)
 #include <gtkmm2ext/tearoff.h>
 #include <gtkmm2ext/window_title.h>
 
+#include "ardour/amp.h"
 #include "ardour/debug.h"
 #include "ardour/midi_track.h"
 #include "ardour/plugin_manager.h"
 #include "ardour/route_group.h"
+#include "ardour/route_sorters.h"
 #include "ardour/session.h"
 
 #include "keyboard.h"
 #include "actions.h"
 #include "gui_thread.h"
 #include "mixer_group_tabs.h"
+#include "timers.h"
+#include "ui_config.h"
 
 #include "i18n.h"
 
 using namespace ARDOUR;
+using namespace ARDOUR_UI_UTILS;
 using namespace PBD;
 using namespace Gtk;
 using namespace Glib;
@@ -72,11 +77,11 @@ using PBD::Unwinder;
 Mixer_UI* Mixer_UI::_instance = 0;
 
 Mixer_UI*
-Mixer_UI::instance () 
+Mixer_UI::instance ()
 {
        if (!_instance) {
                _instance  = new Mixer_UI;
-       } 
+       }
 
        return _instance;
 }
@@ -89,9 +94,14 @@ Mixer_UI::Mixer_UI ()
        , in_group_row_change (false)
        , track_menu (0)
        , _monitor_section (0)
-       , _strip_width (Config->get_default_narrow_ms() ? Narrow : Wide)
+       , _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)
+       , _maximised (false)
+       , _show_mixer_list (true)
 {
        /* allow this window to become the key focus window */
        set_flags (CAN_FOCUS);
@@ -115,7 +125,7 @@ Mixer_UI::Mixer_UI ()
        b->show_all ();
 
        scroller.add (*b);
-       scroller.set_policy (Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
+       scroller.set_policy (Gtk::POLICY_ALWAYS, Gtk::POLICY_AUTOMATIC);
 
        setup_track_display ();
 
@@ -132,6 +142,7 @@ Mixer_UI::Mixer_UI ()
        group_display.set_reorderable (true);
        group_display.set_headers_visible (true);
        group_display.set_rules_hint (true);
+       group_display.set_can_focus(false);
 
        /* name is directly editable */
 
@@ -183,23 +194,45 @@ Mixer_UI::Mixer_UI ()
        group_display_frame.set_shadow_type (Gtk::SHADOW_IN);
        group_display_frame.add (group_display_vbox);
 
-       rhs_pane1.pack1 (track_display_frame);
-       rhs_pane1.pack2 (group_display_frame);
-
-       list_vpacker.pack_start (rhs_pane1, true, true);
+       favorite_plugins_model = PluginTreeStore::create (favorite_plugins_columns);
+       favorite_plugins_display.set_model (favorite_plugins_model);
+       favorite_plugins_display.append_column (_("Favorite Plugins"), favorite_plugins_columns.name);
+       favorite_plugins_display.set_name ("EditGroupList");
+       favorite_plugins_display.get_selection()->set_mode (Gtk::SELECTION_SINGLE);
+       favorite_plugins_display.set_reorderable (false);
+       favorite_plugins_display.set_headers_visible (true);
+       favorite_plugins_display.set_rules_hint (true);
+       favorite_plugins_display.set_can_focus (false);
+       favorite_plugins_display.add_object_drag (favorite_plugins_columns.plugin.index(), "PluginPresetPtr");
+       favorite_plugins_display.set_drag_column (favorite_plugins_columns.name.index());
+       favorite_plugins_display.signal_row_activated().connect (sigc::mem_fun (*this, &Mixer_UI::plugin_row_activated));
+       favorite_plugins_display.signal_button_press_event().connect (sigc::mem_fun (*this, &Mixer_UI::plugin_row_button_press), false);
+       favorite_plugins_display.signal_drop.connect (sigc::mem_fun (*this, &Mixer_UI::plugin_drop));
+
+       favorite_plugins_scroller.add (favorite_plugins_display);
+       favorite_plugins_scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
+
+       favorite_plugins_frame.set_name ("BaseFrame");
+       favorite_plugins_frame.set_shadow_type (Gtk::SHADOW_IN);
+       favorite_plugins_frame.add (favorite_plugins_scroller);
+
+       rhs_pane1.pack1 (favorite_plugins_frame, false, true);
+       rhs_pane1.pack2 (track_display_frame);
+       rhs_pane2.pack1 (rhs_pane1);
+       rhs_pane2.pack2 (group_display_frame);
+
+       list_vpacker.pack_start (rhs_pane2, true, true);
 
        global_hpacker.pack_start (scroller, true, true);
-#ifdef GTKOSX
-       /* current gtk-quartz has dirty updates on borders like this one */
        global_hpacker.pack_start (out_packer, false, false, 0);
-#else
-       global_hpacker.pack_start (out_packer, false, false, 12);
-#endif
-       list_hpane.pack1(list_vpacker, true, true);
+
+       list_hpane.pack1(list_vpacker, false, true);
        list_hpane.pack2(global_hpacker, true, false);
 
        rhs_pane1.signal_size_allocate().connect (sigc::bind (sigc::mem_fun(*this, &Mixer_UI::pane_allocation_handler),
                                                        static_cast<Gtk::Paned*> (&rhs_pane1)));
+       rhs_pane2.signal_size_allocate().connect (sigc::bind (sigc::mem_fun(*this, &Mixer_UI::pane_allocation_handler),
+                                                       static_cast<Gtk::Paned*> (&rhs_pane2)));
        list_hpane.signal_size_allocate().connect (sigc::bind (sigc::mem_fun(*this, &Mixer_UI::pane_allocation_handler),
                                                         static_cast<Gtk::Paned*> (&list_hpane)));
 
@@ -231,30 +264,37 @@ Mixer_UI::Mixer_UI ()
        group_display_button_label.show();
        group_display_button.show();
        group_display_scroller.show();
+       favorite_plugins_scroller.show();
        group_display_vbox.show();
        group_display_frame.show();
+       favorite_plugins_frame.show();
        rhs_pane1.show();
+       rhs_pane2.show();
        strip_packer.show();
        out_packer.show();
        list_hpane.show();
        group_display.show();
-
-       _in_group_rebuild_or_clear = false;
+       favorite_plugins_display.show();
 
        MixerStrip::CatchDeletion.connect (*this, invalidator (*this), boost::bind (&Mixer_UI::remove_strip, this, _1), gui_context());
 
-        MonitorSection::setup_knob_images ();
-
 #ifndef DEFER_PLUGIN_SELECTOR_LOAD
        _plugin_selector = new PluginSelector (PluginManager::instance ());
+#else
+#error implement deferred Plugin-Favorite list
 #endif
+       PluginManager::instance ().PluginListChanged.connect (*this, invalidator (*this), boost::bind (&Mixer_UI::refill_favorite_plugins, this), gui_context());
+       PluginManager::instance ().PluginStatusesChanged.connect (*this, invalidator (*this), boost::bind (&Mixer_UI::refill_favorite_plugins, this), gui_context());
+       ARDOUR::Plugin::PresetsChanged.connect (*this, invalidator (*this), boost::bind (&Mixer_UI::refill_favorite_plugins, this), gui_context());
 }
 
 Mixer_UI::~Mixer_UI ()
 {
        if (_monitor_section) {
+               monitor_section_detached ();
                delete _monitor_section;
        }
+       delete _plugin_selector;
 }
 
 void
@@ -290,10 +330,10 @@ Mixer_UI::show_window ()
                        ms = (*ri)[track_columns.strip];
                        ms->set_width_enum (ms->get_width_enum (), ms->width_owner());
                        /* Fix visibility of mixer strip stuff */
-                       ms->parameter_changed (X_("mixer-strip-visibility"));
+                       ms->parameter_changed (X_("mixer-element-visibility"));
                }
        }
-       
+
        /* force focus into main area */
        scroller_base.grab_focus ();
 
@@ -313,6 +353,22 @@ Mixer_UI::hide_window (GdkEventAny *ev)
 void
 Mixer_UI::add_strips (RouteList& routes)
 {
+       bool from_scratch = track_model->children().size() == 0;
+       Gtk::TreeModel::Children::iterator insert_iter = track_model->children().end();
+
+       for (Gtk::TreeModel::Children::iterator it = track_model->children().begin(); it != track_model->children().end(); ++it) {
+               boost::shared_ptr<Route> r = (*it)[track_columns.route];
+
+               if (r->order_key() == (routes.front()->order_key() + routes.size())) {
+                       insert_iter = it;
+                       break;
+               }
+       }
+
+       if(!from_scratch) {
+               _selection.clear_routes ();
+       }
+
        MixerStrip* strip;
 
        try {
@@ -321,52 +377,61 @@ Mixer_UI::add_strips (RouteList& routes)
 
                for (RouteList::iterator x = routes.begin(); x != routes.end(); ++x) {
                        boost::shared_ptr<Route> route = (*x);
-                       
+
                        if (route->is_auditioner()) {
                                continue;
                        }
-                       
+
                        if (route->is_monitor()) {
-                               
+
                                if (!_monitor_section) {
                                        _monitor_section = new MonitorSection (_session);
-                                       
+
                                        XMLNode* mnode = ARDOUR_UI::instance()->tearoff_settings (X_("monitor-section"));
                                        if (mnode) {
                                                _monitor_section->tearoff().set_state (*mnode);
                                        }
-                               } 
-                               
+                               }
+
                                out_packer.pack_end (_monitor_section->tearoff(), false, false);
                                _monitor_section->set_session (_session);
                                _monitor_section->tearoff().show_all ();
-                               
+
+                               _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 ();
+
                                route->DropReferences.connect (*this, invalidator(*this), boost::bind (&Mixer_UI::monitor_section_going_away, this), gui_context());
-                               
+
                                /* no regular strip shown for control out */
-                               
+
                                continue;
                        }
-                       
+
                        strip = new MixerStrip (*this, _session, route);
                        strips.push_back (strip);
 
-                       Config->get_default_narrow_ms() ? _strip_width = Narrow : _strip_width = Wide;
-                       
+                       UIConfiguration::instance().get_default_narrow_ms() ? _strip_width = Narrow : _strip_width = Wide;
+
                        if (strip->width_owner() != strip) {
                                strip->set_width_enum (_strip_width, this);
                        }
-                       
+
                        show_strip (strip);
-                       
-                       TreeModel::Row row = *(track_model->append());
+
+                       TreeModel::Row row = *(track_model->insert(insert_iter));
                        row[track_columns.text] = route->name();
                        row[track_columns.visible] = strip->route()->is_master() ? true : strip->marked_for_display();
                        row[track_columns.route] = route;
                        row[track_columns.strip] = strip;
-                       
+
+                       if (!from_scratch) {
+                               _selection.add (strip);
+                       }
+
                        route->PropertyChanged.connect (*this, invalidator (*this), boost::bind (&Mixer_UI::strip_property_changed, this, _1, strip), gui_context());
-                       
+
                        strip->WidthChanged.connect (sigc::mem_fun(*this, &Mixer_UI::strip_width_changed));
                        strip->signal_button_release_event().connect (sigc::bind (sigc::mem_fun(*this, &Mixer_UI::strip_button_release_event), strip));
                }
@@ -376,11 +441,35 @@ Mixer_UI::add_strips (RouteList& routes)
 
        no_track_list_redisplay = false;
        track_display.set_model (track_model);
-       
+
        sync_order_keys_from_treeview ();
        redisplay_track_list ();
 }
 
+void
+Mixer_UI::deselect_all_strip_processors ()
+{
+       for (list<MixerStrip *>::iterator i = strips.begin(); i != strips.end(); ++i) {
+               (*i)->deselect_all_processors();
+       }
+}
+
+void
+Mixer_UI::select_none ()
+{
+       _selection.clear_routes();
+       deselect_all_strip_processors();
+}
+
+void
+Mixer_UI::delete_processors ()
+{
+       for (list<MixerStrip *>::iterator i = strips.begin(); i != strips.end(); ++i) {
+               (*i)->delete_processors();
+       }
+}
+
+
 void
 Mixer_UI::remove_strip (MixerStrip* strip)
 {
@@ -392,13 +481,14 @@ Mixer_UI::remove_strip (MixerStrip* strip)
        TreeModel::Children rows = track_model->children();
        TreeModel::Children::iterator ri;
        list<MixerStrip *>::iterator i;
-       
+
        if ((i = find (strips.begin(), strips.end(), strip)) != strips.end()) {
                strips.erase (i);
        }
-       
+
        for (ri = rows.begin(); ri != rows.end(); ++ri) {
                if ((*ri)[track_columns.strip] == strip) {
+                        PBD::Unwinder<bool> uw (_route_deletion_in_progress, true);
                        track_model->erase (ri);
                        break;
                }
@@ -413,7 +503,7 @@ Mixer_UI::reset_remote_control_ids ()
        }
 
        TreeModel::Children rows = track_model->children();
-       
+
        if (rows.empty()) {
                return;
        }
@@ -426,18 +516,29 @@ Mixer_UI::reset_remote_control_ids ()
        uint32_t invisible_key = UINT32_MAX;
 
        for (ri = rows.begin(); ri != rows.end(); ++ri) {
+
+               /* skip two special values */
+
+               if (rid == Route::MasterBusRemoteControlID) {
+                       rid++;
+               }
+
+               if (rid == Route::MonitorBusRemoteControlID) {
+                       rid++;
+               }
+
                boost::shared_ptr<Route> route = (*ri)[track_columns.route];
                bool visible = (*ri)[track_columns.visible];
 
                if (!route->is_master() && !route->is_monitor()) {
-                       
+
                        uint32_t new_rid = (visible ? rid : invisible_key--);
-                       
+
                        if (new_rid != route->remote_control_id()) {
-                               route->set_remote_control_id_explicit (new_rid);        
+                               route->set_remote_control_id_explicit (new_rid);
                                rid_change = true;
                        }
-                       
+
                        if (visible) {
                                rid++;
                        }
@@ -458,7 +559,7 @@ Mixer_UI::sync_order_keys_from_treeview ()
        }
 
        TreeModel::Children rows = track_model->children();
-       
+
        if (rows.empty()) {
                return;
        }
@@ -488,10 +589,10 @@ Mixer_UI::sync_order_keys_from_treeview ()
                        uint32_t new_rid = (visible ? rid : invisible_key--);
 
                        if (new_rid != route->remote_control_id()) {
-                               route->set_remote_control_id_explicit (new_rid);        
+                               route->set_remote_control_id_explicit (new_rid);
                                rid_change = true;
                        }
-                       
+
                        if (visible) {
                                rid++;
                        }
@@ -548,7 +649,7 @@ Mixer_UI::sync_treeview_from_order_keys ()
        neworder.assign (sorted_routes.size(), 0);
 
        uint32_t n = 0;
-       
+
        for (OrderKeySortedRoutes::iterator sr = sorted_routes.begin(); sr != sorted_routes.end(); ++sr, ++n) {
 
                neworder[n] = sr->old_display_order;
@@ -572,13 +673,13 @@ Mixer_UI::sync_treeview_from_order_keys ()
 void
 Mixer_UI::follow_editor_selection ()
 {
-       if (!Config->get_link_editor_and_mixer_selection() || _following_editor_selection) {
+       if (_following_editor_selection) {
                return;
        }
 
        _following_editor_selection = true;
        _selection.block_routes_changed (true);
-       
+
        TrackSelection& s (PublicEditor::instance().get_selection().tracks);
 
        _selection.clear_routes ();
@@ -618,24 +719,28 @@ Mixer_UI::strip_button_release_event (GdkEventButton *ev, MixerStrip *strip)
                        /* primary-click: toggle selection state of strip */
                        if (Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
                                _selection.remove (strip);
-                       } 
+                       } else if (_selection.routes.size() > 1) {
+                               /* de-select others */
+                               _selection.set (strip);
+                       }
                } else {
                        if (Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
                                _selection.add (strip);
                        } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::RangeSelectModifier)) {
 
                                if (!_selection.selected(strip)) {
-                               
+
                                        /* extend selection */
-                                       
+
                                        vector<MixerStrip*> tmp;
                                        bool accumulate = false;
-                                       
+                                       bool found_another = false;
+
                                        tmp.push_back (strip);
 
                                        for (list<MixerStrip*>::iterator i = strips.begin(); i != strips.end(); ++i) {
                                                if ((*i) == strip) {
-                                                       /* hit clicked strip, start accumulating till we hit the first 
+                                                       /* hit clicked strip, start accumulating till we hit the first
                                                           selected strip
                                                        */
                                                        if (accumulate) {
@@ -648,6 +753,7 @@ Mixer_UI::strip_button_release_event (GdkEventButton *ev, MixerStrip *strip)
                                                        /* hit selected strip. if currently accumulating others,
                                                           we're done. if not accumulating others, start doing so.
                                                        */
+                                                       found_another = true;
                                                        if (accumulate) {
                                                                /* done */
                                                                break;
@@ -661,9 +767,12 @@ Mixer_UI::strip_button_release_event (GdkEventButton *ev, MixerStrip *strip)
                                                }
                                        }
 
-                                       for (vector<MixerStrip*>::iterator i = tmp.begin(); i != tmp.end(); ++i) {
-                                               _selection.add (*i);
-                                       }
+                                       if (found_another) {
+                                               for (vector<MixerStrip*>::iterator i = tmp.begin(); i != tmp.end(); ++i) {
+                                                       _selection.add (*i);
+                                               }
+                                       } else
+                                               _selection.set (strip);  //user wants to start a range selection, but there aren't any others selected yet
                                }
 
                        } else {
@@ -711,14 +820,9 @@ Mixer_UI::set_session (Session* sess)
 
        if (_visible) {
                show_window();
-
-               /* Bit of a hack; if we're here, we're opening the mixer because of our
-                  instant XML state having a show-mixer property.  Fix up the corresponding
-                  action state.
-               */
-               ActionManager::check_toggleaction ("<Actions>/Common/toggle-mixer");
        }
 
+       refill_favorite_plugins();
        start_updating ();
 }
 
@@ -738,9 +842,11 @@ Mixer_UI::session_going_away ()
                delete (*i);
        }
 
-        if (_monitor_section) {
-                _monitor_section->tearoff().hide_visible ();
-        }
+       if (_monitor_section) {
+               _monitor_section->tearoff().hide_visible ();
+       }
+
+       monitor_section_detached ();
 
        strips.clear ();
 
@@ -781,15 +887,15 @@ Mixer_UI::update_track_visibility ()
 
        {
                Unwinder<bool> uw (no_track_list_redisplay, true);
-               
+
                for (i = rows.begin(); i != rows.end(); ++i) {
                        MixerStrip *strip = (*i)[track_columns.strip];
                        (*i)[track_columns.visible] = strip->marked_for_display ();
                }
-               
+
                /* force route order keys catch up with visibility changes
                 */
-               
+
                sync_order_keys_from_treeview ();
        }
 
@@ -833,7 +939,7 @@ Mixer_UI::hide_strip (MixerStrip* ms)
 gint
 Mixer_UI::start_updating ()
 {
-    fast_screen_update_connection = ARDOUR_UI::instance()->SuperRapidScreenUpdate.connect (sigc::mem_fun(*this, &Mixer_UI::fast_update_strips));
+    fast_screen_update_connection = Timers::super_rapid_connect (sigc::mem_fun(*this, &Mixer_UI::fast_update_strips));
     return 0;
 }
 
@@ -862,20 +968,20 @@ Mixer_UI::set_all_strips_visibility (bool yn)
 
        {
                Unwinder<bool> uw (no_track_list_redisplay, true);
-               
+
                for (i = rows.begin(); i != rows.end(); ++i) {
-                       
+
                        TreeModel::Row row = (*i);
                        MixerStrip* strip = row[track_columns.strip];
-                       
+
                        if (strip == 0) {
                                continue;
                        }
-                       
+
                        if (strip->route()->is_master() || strip->route()->is_monitor()) {
                                continue;
                        }
-                       
+
                        (*i)[track_columns.visible] = yn;
                }
        }
@@ -885,41 +991,48 @@ Mixer_UI::set_all_strips_visibility (bool yn)
 
 
 void
-Mixer_UI::set_all_audio_visibility (int tracks, bool yn)
+Mixer_UI::set_all_audio_midi_visibility (int tracks, bool yn)
 {
        TreeModel::Children rows = track_model->children();
        TreeModel::Children::iterator i;
 
        {
                Unwinder<bool> uw (no_track_list_redisplay, true);
-               
+
                for (i = rows.begin(); i != rows.end(); ++i) {
                        TreeModel::Row row = (*i);
                        MixerStrip* strip = row[track_columns.strip];
-                       
+
                        if (strip == 0) {
                                continue;
                        }
-                       
+
                        if (strip->route()->is_master() || strip->route()->is_monitor()) {
                                continue;
                        }
-                       
+
                        boost::shared_ptr<AudioTrack> at = strip->audio_track();
-                       
+                       boost::shared_ptr<MidiTrack> mt = strip->midi_track();
+
                        switch (tracks) {
                        case 0:
                                (*i)[track_columns.visible] = yn;
                                break;
-                               
+
                        case 1:
                                if (at) { /* track */
                                        (*i)[track_columns.visible] = yn;
                                }
                                break;
-                               
+
                        case 2:
-                               if (!at) { /* bus */
+                               if (!at && !mt) { /* bus */
+                                       (*i)[track_columns.visible] = yn;
+                               }
+                               break;
+
+                       case 3:
+                               if (mt) { /* midi-track */
                                        (*i)[track_columns.visible] = yn;
                                }
                                break;
@@ -945,25 +1058,37 @@ Mixer_UI::show_all_routes ()
 void
 Mixer_UI::show_all_audiobus ()
 {
-       set_all_audio_visibility (2, true);
+       set_all_audio_midi_visibility (2, true);
 }
 void
 Mixer_UI::hide_all_audiobus ()
 {
-       set_all_audio_visibility (2, false);
+       set_all_audio_midi_visibility (2, false);
 }
 
 void
 Mixer_UI::show_all_audiotracks()
 {
-       set_all_audio_visibility (1, true);
+       set_all_audio_midi_visibility (1, true);
 }
 void
 Mixer_UI::hide_all_audiotracks ()
 {
-       set_all_audio_visibility (1, false);
+       set_all_audio_midi_visibility (1, false);
 }
 
+void
+Mixer_UI::show_all_miditracks()
+{
+       set_all_audio_midi_visibility (3, true);
+}
+void
+Mixer_UI::hide_all_miditracks ()
+{
+       set_all_audio_midi_visibility (3, false);
+}
+
+
 void
 Mixer_UI::track_list_reorder (const TreeModel::Path&, const TreeModel::iterator&, int* /*new_order*/)
 {
@@ -976,9 +1101,17 @@ Mixer_UI::track_list_delete (const Gtk::TreeModel::Path&)
 {
        /* this happens as the second step of a DnD within the treeview as well
           as when a row/route is actually deleted.
+
+           if it was a deletion then we have to force a redisplay because
+           order keys may not have changed.
        */
+
        DEBUG_TRACE (DEBUG::OrderKeys, "mixer UI treeview row deleted\n");
        sync_order_keys_from_treeview ();
+
+        if (_route_deletion_in_progress) {
+                redisplay_track_list ();
+        }
 }
 
 void
@@ -986,7 +1119,7 @@ Mixer_UI::redisplay_track_list ()
 {
        TreeModel::Children rows = track_model->children();
        TreeModel::Children::iterator i;
-       
+
        if (no_track_list_redisplay) {
                return;
        }
@@ -1069,28 +1202,12 @@ Mixer_UI::strip_width_changed ()
 
 }
 
-struct SignalOrderRouteSorter {
-    bool operator() (boost::shared_ptr<Route> a, boost::shared_ptr<Route> b) {
-           if (a->is_master() || a->is_monitor()) {
-                   /* "a" is a special route (master, monitor, etc), and comes
-                    * last in the mixer ordering
-                    */
-                   return false;
-           } else if (b->is_master() || b->is_monitor()) {
-                   /* everything comes before b */
-                   return true;
-           }
-           return a->order_key () < b->order_key ();
-
-    }
-};
-
 void
 Mixer_UI::initial_track_display ()
 {
        boost::shared_ptr<RouteList> routes = _session->get_routes();
        RouteList copy (*routes);
-       SignalOrderRouteSorter sorter;
+       ARDOUR::SignalOrderRouteSorter sorter;
 
        copy.sort (sorter);
 
@@ -1101,7 +1218,7 @@ Mixer_UI::initial_track_display ()
                track_model->clear ();
                add_strips (copy);
        }
-       
+
        _session->sync_order_keys ();
 
        redisplay_track_list ();
@@ -1144,6 +1261,8 @@ Mixer_UI::build_track_menu ()
        items.push_back (MenuElem (_("Hide All Audio Tracks"), sigc::mem_fun(*this, &Mixer_UI::hide_all_audiotracks)));
        items.push_back (MenuElem (_("Show All Audio Busses"), sigc::mem_fun(*this, &Mixer_UI::show_all_audiobus)));
        items.push_back (MenuElem (_("Hide All Audio Busses"), sigc::mem_fun(*this, &Mixer_UI::hide_all_audiobus)));
+       items.push_back (MenuElem (_("Show All Midi Tracks"), sigc::mem_fun (*this, &Mixer_UI::show_all_miditracks)));
+       items.push_back (MenuElem (_("Hide All Midi Tracks"), sigc::mem_fun (*this, &Mixer_UI::hide_all_miditracks)));
 
 }
 
@@ -1178,12 +1297,14 @@ 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)) {
-               return false;
+               _group_tabs->get_menu(0)->popup (1, ev->time);
+               return true;
        }
 
        TreeIter iter = group_model->get_iter (path);
        if (!iter) {
-               return false;
+               _group_tabs->get_menu(0)->popup (1, ev->time);
+               return true;
        }
 
        RouteGroup* group = (*iter)[group_columns.group];
@@ -1246,6 +1367,14 @@ Mixer_UI::route_groups_changed ()
 
        group_model->clear ();
 
+#if 0
+       /* this is currently not used,
+        * Mixer_UI::group_display_button_press() has a case for it,
+        * and a commented edit_route_group() but that's n/a since 2011.
+        *
+        * This code is left as reminder that
+        * row[group_columns.group] = 0 has special meaning.
+        */
        {
                TreeModel::Row row;
                row = *(group_model->append());
@@ -1253,6 +1382,7 @@ Mixer_UI::route_groups_changed ()
                row[group_columns.text] = (_("-all-"));
                row[group_columns.group] = 0;
        }
+#endif
 
        _session->foreach_route_group (sigc::mem_fun (*this, &Mixer_UI::add_route_group));
 
@@ -1341,6 +1471,40 @@ Mixer_UI::route_group_property_changed (RouteGroup* group, const PropertyChange&
        }
 }
 
+void
+Mixer_UI::show_mixer_list (bool yn)
+{
+       if (yn) {
+               list_vpacker.show ();
+               
+               //if user wants to show the pane, we should make sure that it is wide enough to be visible 
+               int width = list_hpane.get_position();
+               if (width < 40)
+                       list_hpane.set_position(40);
+       } else {
+               list_vpacker.hide ();
+       }
+       
+       _show_mixer_list = yn;
+}
+
+void
+Mixer_UI::show_monitor_section (bool yn)
+{
+       if (!monitor_section()) {
+               return;
+       }
+       if (monitor_section()->tearoff().torn_off()) {
+               return;
+       }
+
+       if (yn) {
+               monitor_section()->tearoff().show();
+       } else {
+               monitor_section()->tearoff().hide();
+       }
+}
+
 void
 Mixer_UI::route_group_name_edit (const std::string& path, const std::string& new_text)
 {
@@ -1473,13 +1637,35 @@ Mixer_UI::set_window_pos_and_size ()
        move (m_root_x, m_root_y);
 }
 
-       void
+void
 Mixer_UI::get_window_pos_and_size ()
 {
        get_position(m_root_x, m_root_y);
        get_size(m_width, m_height);
 }
 
+struct PluginStateSorter {
+public:
+       bool operator() (PluginInfoPtr a, PluginInfoPtr b) const {
+               std::list<std::string>::const_iterator aiter = std::find(_user.begin(), _user.end(), (*a).unique_id);
+               std::list<std::string>::const_iterator biter = std::find(_user.begin(), _user.end(), (*b).unique_id);
+               if (aiter != _user.end() && biter != _user.end()) {
+                       return std::distance (_user.begin(), aiter)  < std::distance (_user.begin(), biter);
+               }
+               if (aiter != _user.end()) {
+                       return true;
+               }
+               if (biter != _user.end()) {
+                       return false;
+               }
+               return ARDOUR::cmp_nocase((*a).name, (*b).name) == -1;
+       }
+
+       PluginStateSorter(std::list<std::string> user) : _user (user)  {}
+private:
+       std::list<std::string> _user;
+};
+
 int
 Mixer_UI::set_state (const XMLNode& node)
 {
@@ -1539,6 +1725,50 @@ Mixer_UI::set_state (const XMLNode& node)
                }
        }
 
+       if ((prop = node.property ("maximised"))) {
+               bool yn = string_is_affirmative (prop->value());
+               Glib::RefPtr<Action> act = ActionManager::get_action (X_("Common"), X_("ToggleMaximalMixer"));
+               assert (act);
+               Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
+               bool fs = tact && tact->get_active();
+               if (yn ^ fs) {
+                       ActionManager::do_action ("Common",
+                                       "ToggleMaximalMixer");
+               }
+       }
+
+       if ((prop = node.property ("show-mixer-list"))) {
+               bool yn = string_is_affirmative (prop->value());
+               Glib::RefPtr<Action> act = ActionManager::get_action (X_("Common"), X_("ToggleMixerList"));
+               assert (act);
+               Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
+
+               /* do it twice to force the change */
+               tact->set_active (!yn);
+               tact->set_active (yn);
+       }
+
+
+       XMLNode* plugin_order;
+       if ((plugin_order = find_named_node (node, "PluginOrder")) != 0) {
+               store_current_favorite_order ();
+               std::list<string> order;
+               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();
+                               order.push_back (unique_id);
+                               if ((prop = (*i)->property ("expanded"))) {
+                                       favorite_ui_state[unique_id] = string_is_affirmative (prop->value());
+                               }
+                       }
+               }
+               PluginStateSorter cmp (order);
+               favorite_order.sort (cmp);
+               sync_treeview_from_favorite_order ();
+       }
+
        return 0;
 }
 
@@ -1571,6 +1801,8 @@ Mixer_UI::get_state (void)
 
                snprintf(buf,sizeof(buf), "%d",gtk_paned_get_position (static_cast<Paned*>(&rhs_pane1)->gobj()));
                geometry->add_property(X_("mixer_rhs_pane1_pos"), string(buf));
+               snprintf(buf,sizeof(buf), "%d",gtk_paned_get_position (static_cast<Paned*>(&rhs_pane2)->gobj()));
+               geometry->add_property(X_("mixer_rhs_pane2_pos"), string(buf));
                snprintf(buf,sizeof(buf), "%d",gtk_paned_get_position (static_cast<Paned*>(&list_hpane)->gobj()));
                geometry->add_property(X_("mixer_list_hpane_pos"), string(buf));
 
@@ -1581,6 +1813,24 @@ Mixer_UI::get_state (void)
 
        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");
+
+       store_current_favorite_order ();
+       XMLNode* plugin_order = new XMLNode ("PluginOrder");
+       int 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);
+                       if (favorite_ui_state.find ((*i)->unique_id) != favorite_ui_state.end ()) {
+                               p->add_property ("expanded", favorite_ui_state[(*i)->unique_id]);
+                       }
+                       plugin_order->add_child_nocopy (*p);
+               ;
+       }
+       node->add_child_nocopy (*plugin_order);
        return *node;
 }
 
@@ -1590,7 +1840,6 @@ Mixer_UI::pane_allocation_handler (Allocation&, Gtk::Paned* which)
 {
        int pos;
        XMLProperty* prop = 0;
-       char buf[32];
        XMLNode* node = ARDOUR_UI::instance()->mixer_settings();
        XMLNode* geometry;
        int height;
@@ -1616,7 +1865,6 @@ Mixer_UI::pane_allocation_handler (Allocation&, Gtk::Paned* which)
 
                if (!geometry || (prop = geometry->property("mixer-rhs-pane1-pos")) == 0) {
                        pos = height / 3;
-                       snprintf (buf, sizeof(buf), "%d", pos);
                } else {
                        pos = atoi (prop->value());
                }
@@ -1625,6 +1873,20 @@ Mixer_UI::pane_allocation_handler (Allocation&, Gtk::Paned* which)
                        rhs_pane1.set_position (pos);
                }
 
+       } else if (which == static_cast<Gtk::Paned*> (&rhs_pane2)) {
+               if (done[1]) {
+                       return;
+               }
+
+               if (!geometry || (prop = geometry->property("mixer-rhs-pane2-pos")) == 0) {
+                       pos = 2 * height / 3;
+               } else {
+                       pos = atoi (prop->value());
+               }
+
+               if ((done[1] = GTK_WIDGET(rhs_pane2.gobj())->allocation.height > pos)) {
+                       rhs_pane2.set_position (pos);
+               }
        } else if (which == static_cast<Gtk::Paned*> (&list_hpane)) {
 
                if (done[2]) {
@@ -1632,10 +1894,9 @@ Mixer_UI::pane_allocation_handler (Allocation&, Gtk::Paned* which)
                }
 
                if (!geometry || (prop = geometry->property("mixer-list-hpane-pos")) == 0) {
-                       pos = 75;
-                       snprintf (buf, sizeof(buf), "%d", pos);
+                       pos = std::max ((float)100, rintf ((float) 125 * UIConfiguration::instance().get_ui_scale()));
                } else {
-                       pos = atoi (prop->value());
+                       pos = max (36, atoi (prop->value ()));
                }
 
                if ((done[2] = GTK_WIDGET(list_hpane.gobj())->allocation.width > pos)) {
@@ -1689,7 +1950,7 @@ Mixer_UI::on_key_release_event (GdkEventKey* ev)
        }
 
        KeyboardKey k (ev->state, ev->keyval);
-       
+
        if (bindings.activate (k, Bindings::Release)) {
                return true;
        }
@@ -1740,12 +2001,16 @@ Mixer_UI::parameter_changed (string const & p)
                        _group_tabs->hide ();
                }
        } else if (p == "default-narrow_ms") {
-               bool const s = Config->get_default_narrow_ms ();
+               bool const s = UIConfiguration::instance().get_default_narrow_ms ();
                for (list<MixerStrip*>::iterator i = strips.begin(); i != strips.end(); ++i) {
                        (*i)->set_width_enum (s ? Narrow : Wide, this);
                }
        } else if (p == "remote-model") {
                reset_remote_control_ids ();
+       } else if (p == "use-monitor-bus") {
+               if (!_session->monitor_out()) {
+                       monitor_section_detached ();
+               }
        }
 }
 
@@ -1777,10 +2042,12 @@ Mixer_UI::setup_track_display ()
        track_display.get_column (1)->set_data (X_("colnum"), GUINT_TO_POINTER(1));
        track_display.get_column (0)->set_expand(true);
        track_display.get_column (1)->set_expand(false);
+       track_display.get_column (0)->set_sizing (Gtk::TREE_VIEW_COLUMN_FIXED);
        track_display.set_name (X_("EditGroupList"));
        track_display.get_selection()->set_mode (Gtk::SELECTION_NONE);
        track_display.set_reorderable (true);
        track_display.set_headers_visible (true);
+       track_display.set_can_focus(false);
 
        track_model->signal_row_deleted().connect (sigc::mem_fun (*this, &Mixer_UI::track_list_delete));
        track_model->signal_rows_reordered().connect (sigc::mem_fun (*this, &Mixer_UI::track_list_reorder));
@@ -1830,7 +2097,7 @@ Mixer_UI::update_title ()
 {
        if (_session) {
                string n;
-               
+
                if (_session->snap_name() != _session->name()) {
                        n = _session->snap_name ();
                } else {
@@ -1840,14 +2107,14 @@ Mixer_UI::update_title ()
                if (_session->dirty ()) {
                        n = "*" + n;
                }
-               
+
                WindowTitle title (n);
                title += S_("Window|Mixer");
                title += Glib::get_application_name ();
                set_title (title.get_string());
 
        } else {
-               
+
                WindowTitle title (S_("Window|Mixer"));
                title += Glib::get_application_name ();
                set_title (title.get_string());
@@ -1881,24 +2148,19 @@ Mixer_UI::set_route_targets_for_operation ()
                return;
        }
 
-       /* nothing selected ... try to get mixer strip at mouse */
+//  removed "implicit" selections of strips, after discussion on IRC
 
-       int x, y;
-       get_pointer (x, y);
-       
-       MixerStrip* ms = strip_by_x (x);
-       
-       if (ms) {
-               _route_targets.insert (ms);
-       }
 }
 
 void
 Mixer_UI::monitor_section_going_away ()
 {
        if (_monitor_section) {
+               monitor_section_detached ();
                out_packer.remove (_monitor_section->tearoff());
                _monitor_section->set_session (0);
+               delete _monitor_section;
+               _monitor_section = 0;
        }
 }
 
@@ -1918,7 +2180,356 @@ Mixer_UI::toggle_midi_input_active (bool flip_others)
                        onoff = !mt->input_active();
                }
        }
-       
+
        _session->set_exclusive_input_active (rl, onoff, flip_others);
 }
 
+void
+Mixer_UI::maximise_mixer_space ()
+{
+       if (_maximised) {
+               return;
+       }
+
+       fullscreen ();
+
+       _maximised = true;
+}
+
+void
+Mixer_UI::restore_mixer_space ()
+{
+       if (!_maximised) {
+               return;
+       }
+
+       unfullscreen();
+
+       _maximised = false;
+}
+
+void
+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 ();
+}
+
+void
+Mixer_UI::monitor_section_detached ()
+{
+       Glib::RefPtr<Action> act = ActionManager::get_action ("Common", "ToggleMonitorSection");
+       act->set_sensitive (false);
+}
+
+void
+Mixer_UI::store_current_favorite_order ()
+{
+       typedef Gtk::TreeModel::Children type_children;
+       type_children children = favorite_plugins_model->children();
+       favorite_order.clear();
+       for(type_children::iterator iter = children.begin(); iter != children.end(); ++iter)
+       {
+               Gtk::TreeModel::Row row = *iter;
+               ARDOUR::PluginPresetPtr ppp = row[favorite_plugins_columns.plugin];
+               favorite_order.push_back (ppp->_pip);
+               std::string name = row[favorite_plugins_columns.name];
+               favorite_ui_state[(*ppp->_pip).unique_id] = favorite_plugins_display.row_expanded (favorite_plugins_model->get_path(iter));
+       }
+}
+
+void
+Mixer_UI::refiller (PluginInfoList& result, const PluginInfoList& plugs)
+{
+       PluginManager& manager (PluginManager::instance());
+       for (PluginInfoList::const_iterator i = plugs.begin(); i != plugs.end(); ++i) {
+               if (manager.get_status (*i) != PluginManager::Favorite) {
+                       continue;
+               }
+               result.push_back (*i);
+       }
+}
+
+struct PluginCustomSorter {
+public:
+       bool operator() (PluginInfoPtr a, PluginInfoPtr b) const {
+               PluginInfoList::const_iterator aiter = std::find(_user.begin(), _user.end(), a);
+               PluginInfoList::const_iterator biter = std::find(_user.begin(), _user.end(), b);
+
+               if (aiter != _user.end() && biter != _user.end()) {
+                       return std::distance (_user.begin(), aiter)  < std::distance (_user.begin(), biter);
+               }
+               if (aiter != _user.end()) {
+                       return true;
+               }
+               if (biter != _user.end()) {
+                       return false;
+               }
+               return ARDOUR::cmp_nocase((*a).name, (*b).name) == -1;
+       }
+       PluginCustomSorter(PluginInfoList user) : _user (user)  {}
+private:
+       PluginInfoList _user;
+};
+
+void
+Mixer_UI::refill_favorite_plugins ()
+{
+       PluginInfoList plugs;
+       PluginManager& mgr (PluginManager::instance());
+
+#ifdef LV2_SUPPORT
+       refiller (plugs, mgr.lv2_plugin_info ());
+#endif
+#ifdef WINDOWS_VST_SUPPORT
+       refiller (plugs, mgr.windows_vst_plugin_info ());
+#endif
+#ifdef LXVST_SUPPORT
+       refiller (plugs, mgr.lxvst_plugin_info ());
+#endif
+#ifdef AUDIOUNIT_SUPPORT
+       refiller (plugs, mgr.au_plugin_info ());
+#endif
+       refiller (plugs, mgr.ladspa_plugin_info ());
+
+       store_current_favorite_order ();
+
+       PluginCustomSorter cmp (favorite_order);
+       plugs.sort (cmp);
+
+       favorite_order = plugs;
+
+       sync_treeview_from_favorite_order ();
+}
+
+void
+Mixer_UI::sync_treeview_from_favorite_order ()
+{
+       favorite_plugins_model->clear ();
+       for (PluginInfoList::const_iterator i = favorite_order.begin(); i != favorite_order.end(); ++i) {
+               PluginInfoPtr pip = (*i);
+
+               TreeModel::Row newrow = *(favorite_plugins_model->append());
+               newrow[favorite_plugins_columns.name] = (*i)->name;
+               newrow[favorite_plugins_columns.plugin] = PluginPresetPtr (new PluginPreset(pip));
+               if (!_session) {
+                       continue;
+               }
+
+               PluginPtr plugin = (*i)->load (*_session);
+
+               vector<ARDOUR::Plugin::PresetRecord> presets = plugin->get_presets();
+               for (vector<ARDOUR::Plugin::PresetRecord>::const_iterator j = presets.begin(); j != presets.end(); ++j) {
+                       Gtk::TreeModel::Row child_row = *(favorite_plugins_model->append (newrow.children()));
+                       child_row[favorite_plugins_columns.name] = (*j).label;
+                       child_row[favorite_plugins_columns.plugin] = PluginPresetPtr (new PluginPreset(pip, &(*j)));
+               }
+               if (favorite_ui_state.find (pip->unique_id) != favorite_ui_state.end ()) {
+                       if (favorite_ui_state[pip->unique_id]) {
+                               favorite_plugins_display.expand_row (favorite_plugins_model->get_path(newrow), true);
+                       }
+               }
+       }
+}
+
+void
+Mixer_UI::popup_note_context_menu (GdkEventButton *ev)
+{
+       using namespace Gtk::Menu_Helpers;
+
+       Gtk::Menu* m = manage (new Menu);
+       MenuList& items = m->items ();
+
+       if (_selection.routes.empty()) {
+               items.push_back (MenuElem (_("No Track/Bus is selected.")));
+       } else {
+               items.push_back (MenuElem (_("Add at the top"),
+                                       sigc::bind (sigc::mem_fun (*this, &Mixer_UI::add_selected_processor), AddTop)));
+               items.push_back (MenuElem (_("Add Pre-Fader"),
+                                       sigc::bind (sigc::mem_fun (*this, &Mixer_UI::add_selected_processor), AddPreFader)));
+               items.push_back (MenuElem (_("Add Post-Fader"),
+                                       sigc::bind (sigc::mem_fun (*this, &Mixer_UI::add_selected_processor), AddPostFader)));
+               items.push_back (MenuElem (_("Add at the end"),
+                                       sigc::bind (sigc::mem_fun (*this, &Mixer_UI::add_selected_processor), AddBottom)));
+       }
+
+       items.push_back (SeparatorElem());
+
+       items.push_back (MenuElem (_("Remove from favorites"), sigc::mem_fun (*this, &Mixer_UI::remove_selected_from_favorites)));
+
+       ARDOUR::PluginPresetPtr ppp = selected_plugin();
+       if (ppp && ppp->_preset.valid) {
+               items.push_back (MenuElem (_("Delete Preset"), sigc::mem_fun (*this, &Mixer_UI::delete_selected_preset)));
+       }
+
+       m->popup (ev->button, ev->time);
+}
+
+bool
+Mixer_UI::plugin_row_button_press (GdkEventButton *ev)
+{
+       if ((ev->type == GDK_BUTTON_PRESS) && (ev->button == 3) ) {
+               TreeModel::Path path;
+               TreeViewColumn* column;
+               int cellx, celly;
+               if (favorite_plugins_display.get_path_at_pos ((int)ev->x, (int)ev->y, path, column, cellx, celly)) {
+                       Glib::RefPtr<Gtk::TreeView::Selection> selection = favorite_plugins_display.get_selection();
+                       if (selection) {
+                               selection->unselect_all();
+                               selection->select(path);
+                       }
+               }
+               ARDOUR::PluginPresetPtr ppp = selected_plugin();
+               if (ppp) {
+                       popup_note_context_menu (ev);
+               }
+       }
+       return false;
+}
+
+
+PluginPresetPtr
+Mixer_UI::selected_plugin ()
+{
+       Glib::RefPtr<Gtk::TreeView::Selection> selection = favorite_plugins_display.get_selection();
+       if (!selection) {
+               return PluginPresetPtr();
+       }
+       Gtk::TreeModel::iterator iter = selection->get_selected();
+       if (!iter) {
+               return PluginPresetPtr();
+       }
+       return (*iter)[favorite_plugins_columns.plugin];
+}
+
+void
+Mixer_UI::add_selected_processor (ProcessorPosition pos)
+{
+       ARDOUR::PluginPresetPtr ppp = selected_plugin();
+       if (ppp) {
+               add_favorite_processor (ppp, pos);
+       }
+}
+
+void
+Mixer_UI::delete_selected_preset ()
+{
+       if (!_session) {
+               return;
+       }
+       ARDOUR::PluginPresetPtr ppp = selected_plugin();
+       if (!ppp || !ppp->_preset.valid) {
+               return;
+       }
+       PluginPtr plugin = ppp->_pip->load (*_session);
+       plugin->get_presets();
+       plugin->remove_preset (ppp->_preset.label);
+}
+
+void
+Mixer_UI::remove_selected_from_favorites ()
+{
+       ARDOUR::PluginPresetPtr ppp = selected_plugin();
+       if (!ppp) {
+               return;
+       }
+       PluginManager::PluginStatusType status = PluginManager::Normal;
+       PluginManager& manager (PluginManager::instance());
+
+       manager.set_status (ppp->_pip->type, ppp->_pip->unique_id, status);
+       manager.save_statuses ();
+}
+
+void
+Mixer_UI::plugin_row_activated (const TreeModel::Path& path, TreeViewColumn* column)
+{
+       TreeIter iter;
+       if (!(iter = favorite_plugins_model->get_iter (path))) {
+               return;
+       }
+       ARDOUR::PluginPresetPtr ppp = (*iter)[favorite_plugins_columns.plugin];
+       add_favorite_processor (ppp, AddPreFader); // TODO: preference?!
+}
+
+void
+Mixer_UI::add_favorite_processor (ARDOUR::PluginPresetPtr ppp, ProcessorPosition pos)
+{
+       if (!_session || _selection.routes.empty()) {
+               return;
+       }
+
+       PluginInfoPtr pip = ppp->_pip;
+       for (RouteUISelection::iterator i = _selection.routes.begin(); i != _selection.routes.end(); ++i) {
+               boost::shared_ptr<ARDOUR::Route> rt = (*i)->route();
+               if (!rt) { continue; }
+
+               PluginPtr p = pip->load (*_session);
+               if (!p) { continue; }
+
+               if (ppp->_preset.valid) {
+                       p->load_preset (ppp->_preset);
+               }
+
+               Route::ProcessorStreams err;
+               boost::shared_ptr<Processor> processor (new PluginInsert (*_session, p));
+
+               switch (pos) {
+                       case AddTop:
+                               rt->add_processor_by_index (processor, 0, &err, Config->get_new_plugins_active ());
+                               break;
+                       case AddPreFader:
+                               rt->add_processor (processor, PreFader, &err, Config->get_new_plugins_active ());
+                               break;
+                       case AddPostFader:
+                               {
+                                       int idx = 0;
+                                       for (;;++idx) {
+                                               boost::shared_ptr<Processor> np = rt->nth_processor (idx);
+                                               if (!np || boost::dynamic_pointer_cast<Amp> (np)) {
+                                                       break;
+                                               }
+                                       }
+                                       rt->add_processor_by_index (processor, ++idx, &err, Config->get_new_plugins_active ());
+                               }
+                               break;
+                       case AddBottom:
+                               rt->add_processor_by_index (processor, -1, &err, Config->get_new_plugins_active ());
+                               break;
+               }
+       }
+}
+
+bool
+PluginTreeStore::row_drop_possible_vfunc(const Gtk::TreeModel::Path& dest, const Gtk::SelectionData& data) const
+{
+       if (data.get_target() != "GTK_TREE_MODEL_ROW") {
+               return false;
+       }
+       Gtk::TreeModel::Path _dest = dest; // un const
+       const bool is_child = _dest.up (); // explicit bool for clang
+       if (!is_child || _dest.empty ()) {
+               return true;
+       }
+       return false;
+}
+
+void
+Mixer_UI::plugin_drop (const Glib::RefPtr<Gdk::DragContext>&, const Gtk::SelectionData& data)
+{
+       if (data.get_target() != "PluginPresetPtr") {
+               return;
+       }
+       if (data.get_length() != sizeof (PluginPresetPtr)) {
+               return;
+       }
+       const void *d = data.get_data();
+       const PluginPresetPtr ppp = *(static_cast<const PluginPresetPtr*> (d));
+
+       PluginManager::PluginStatusType status = PluginManager::Favorite;
+       PluginManager& manager (PluginManager::instance());
+
+       manager.set_status (ppp->_pip->type, ppp->_pip->unique_id, status);
+       manager.save_statuses ();
+}