Add GPL boilerplate.
[ardour.git] / gtk2_ardour / processor_box.cc
index 3c72eb5d01b768378550a79c448c68602f6c2300..cc322df13d060a00583ed68ee4f7c0df7cf1f13f 100644 (file)
 #include <gtkmm2ext/utils.h>
 #include <gtkmm2ext/choice.h>
 #include <gtkmm2ext/utils.h>
-#include <gtkmm2ext/stop_signal.h>
 #include <gtkmm2ext/doi.h>
 
 #include "ardour/amp.h"
 #include "ardour/ardour.h"
-#include "ardour/audio_diskstream.h"
 #include "ardour/audio_track.h"
 #include "ardour/audioengine.h"
 #include "ardour/internal_send.h"
@@ -80,7 +78,6 @@ class AUPluginUI;
 #endif
 
 using namespace std;
-using namespace sigc;
 using namespace ARDOUR;
 using namespace PBD;
 using namespace Gtk;
@@ -89,10 +86,13 @@ using namespace Gtkmm2ext;
 
 ProcessorBox* ProcessorBox::_current_processor_box = 0;
 RefPtr<Action> ProcessorBox::paste_action;
+RefPtr<Action> ProcessorBox::cut_action;
+RefPtr<Action> ProcessorBox::rename_action;
 Glib::RefPtr<Gdk::Pixbuf> SendProcessorEntry::_slider;
 
 ProcessorEntry::ProcessorEntry (boost::shared_ptr<Processor> p, Width w)
-       : _processor (p), _width (w)
+       : _processor (p)
+       , _width (w)
 {
        _hbox.pack_start (_active, false, false);
        _event_box.add (_name);
@@ -104,10 +104,10 @@ ProcessorEntry::ProcessorEntry (boost::shared_ptr<Processor> p, Width w)
        _name.set_padding (2, 2);
        
        _active.set_active (_processor->active ());
-       _active.signal_toggled().connect (mem_fun (*this, &ProcessorEntry::active_toggled));
+       _active.signal_toggled().connect (sigc::mem_fun (*this, &ProcessorEntry::active_toggled));
        
-       _processor->ActiveChanged.connect (mem_fun (*this, &ProcessorEntry::processor_active_changed));
-       _processor->NameChanged.connect (mem_fun (*this, &ProcessorEntry::processor_name_changed));
+       _processor->ActiveChanged.connect (active_connection, invalidator (*this), boost::bind (&ProcessorEntry::processor_active_changed, this), gui_context());
+       _processor->PropertyChanged.connect (name_connection, invalidator (*this), ui_bind (&ProcessorEntry::processor_property_changed, this, _1), gui_context());
 }
 
 EventBox&
@@ -135,7 +135,7 @@ ProcessorEntry::processor () const
 }
 
 void
-ProcessorEntry::set_width (Width w)
+ProcessorEntry::set_enum_width (Width w)
 {
        _width = w;
 }
@@ -163,9 +163,11 @@ ProcessorEntry::processor_active_changed ()
 }
 
 void
-ProcessorEntry::processor_name_changed ()
+ProcessorEntry::processor_property_changed (const PropertyChange& what_changed)
 {
-       _name.set_text (name ());
+       if (what_changed.contains (ARDOUR::Properties::name)) {
+               _name.set_text (name ());
+       }
 }
 
 string
@@ -174,10 +176,6 @@ ProcessorEntry::name () const
        boost::shared_ptr<Send> send;
        string name_display;
        
-       if (!_processor->active()) {
-               name_display = " (";
-       }
-       
        if ((send = boost::dynamic_pointer_cast<Send> (_processor)) != 0 &&
            !boost::dynamic_pointer_cast<InternalSend>(_processor)) {
                
@@ -211,10 +209,6 @@ ProcessorEntry::name () const
                
        }
        
-       if (!_processor->active()) {
-               name_display += ')';
-       }
-       
        return name_display;
 }
 
@@ -222,14 +216,14 @@ SendProcessorEntry::SendProcessorEntry (boost::shared_ptr<Send> s, Width w)
        : ProcessorEntry (s, w),
          _send (s),
          _adjustment (0, 0, 1, 0.01, 0.1),
-         _fader (_slider, &_adjustment, false),
+         _fader (_slider, &_adjustment, 0, false),
          _ignore_gain_change (false)
 {
        _fader.set_controllable (_send->amp()->gain_control ());
        _vbox.pack_start (_fader);
 
-       _adjustment.signal_value_changed().connect (mem_fun (*this, &SendProcessorEntry::gain_adjusted));
-       _send->amp()->gain_control()->Changed.connect (mem_fun (*this, &SendProcessorEntry::show_gain));
+       _adjustment.signal_value_changed().connect (sigc::mem_fun (*this, &SendProcessorEntry::gain_adjusted));
+       _send->amp()->gain_control()->Changed.connect (send_gain_connection, invalidator (*this), boost::bind (&SendProcessorEntry::show_gain, this), gui_context());
        show_gain ();
 }
 
@@ -243,7 +237,7 @@ SendProcessorEntry::setup_slider_pix ()
 void
 SendProcessorEntry::show_gain ()
 {
-       ENSURE_GUI_THREAD (mem_fun (*this, &SendProcessorEntry::show_gain));
+       ENSURE_GUI_THREAD (*this, &SendProcessorEntry::show_gain)
        
        float const value = gain_to_slider_position (_send->amp()->gain ());
 
@@ -264,17 +258,23 @@ SendProcessorEntry::gain_adjusted ()
        _send->amp()->set_gain (slider_position_to_gain (_adjustment.get_value()), this);
 }
 
+void
+SendProcessorEntry::set_pixel_width (int p)
+{
+       _fader.set_fader_length (p);
+}
 
-
-ProcessorBox::ProcessorBox (ARDOUR::Session& sess, sigc::slot<PluginSelector*> get_plugin_selector,
-                       RouteRedirectSelection& rsel, MixerStrip* parent, bool owner_is_mixer)
-       : _session(sess)
-       , _parent_strip (parent)
+ProcessorBox::ProcessorBox (ARDOUR::Session* sess, boost::function<PluginSelector*()> get_plugin_selector,
+                           RouteRedirectSelection& rsel, MixerStrip* parent, bool owner_is_mixer)
+       : _parent_strip (parent)
        , _owner_is_mixer (owner_is_mixer)
+       , ab_direction (true)
        , _get_plugin_selector (get_plugin_selector)
        , _placement(PreFader)
        , _rr_selection(rsel)
 {
+       set_session (sess);
+
        _width = Wide;
        processor_menu = 0;
        send_action_menu = 0;
@@ -289,18 +289,18 @@ ProcessorBox::ProcessorBox (ARDOUR::Session& sess, sigc::slot<PluginSelector*> g
        processor_display.set_size_request (48, -1);
        processor_display.set_data ("processorbox", this);
 
-       processor_display.signal_enter_notify_event().connect (mem_fun(*this, &ProcessorBox::enter_notify), false);
-       processor_display.signal_leave_notify_event().connect (mem_fun(*this, &ProcessorBox::leave_notify), false);
+       processor_display.signal_enter_notify_event().connect (sigc::mem_fun(*this, &ProcessorBox::enter_notify), false);
+       processor_display.signal_leave_notify_event().connect (sigc::mem_fun(*this, &ProcessorBox::leave_notify), false);
 
-       processor_display.signal_key_press_event().connect (mem_fun(*this, &ProcessorBox::processor_key_press_event));
-       processor_display.signal_key_release_event().connect (mem_fun(*this, &ProcessorBox::processor_key_release_event));
+       processor_display.signal_key_press_event().connect (sigc::mem_fun(*this, &ProcessorBox::processor_key_press_event));
+       processor_display.signal_key_release_event().connect (sigc::mem_fun(*this, &ProcessorBox::processor_key_release_event));
 
-       processor_display.ButtonPress.connect (mem_fun (*this, &ProcessorBox::processor_button_press_event));
-       processor_display.ButtonRelease.connect (mem_fun (*this, &ProcessorBox::processor_button_release_event));
+       processor_display.ButtonPress.connect (sigc::mem_fun (*this, &ProcessorBox::processor_button_press_event));
+       processor_display.ButtonRelease.connect (sigc::mem_fun (*this, &ProcessorBox::processor_button_release_event));
 
-       processor_display.Reordered.connect (mem_fun (*this, &ProcessorBox::reordered));
-       processor_display.DropFromAnotherBox.connect (mem_fun (*this, &ProcessorBox::object_drop));
-       processor_display.SelectionChanged.connect (mem_fun (*this, &ProcessorBox::selection_changed));
+       processor_display.Reordered.connect (sigc::mem_fun (*this, &ProcessorBox::reordered));
+       processor_display.DropFromAnotherBox.connect (sigc::mem_fun (*this, &ProcessorBox::object_drop));
+       processor_display.SelectionChanged.connect (sigc::mem_fun (*this, &ProcessorBox::selection_changed));
 }
 
 ProcessorBox::~ProcessorBox ()
@@ -310,18 +310,19 @@ ProcessorBox::~ProcessorBox ()
 void
 ProcessorBox::set_route (boost::shared_ptr<Route> r)
 {
-       connections.clear ();
+       if (_route == r) {
+               return;
+       }
+       
+       connections.drop_connections();
 
        /* new route: any existing block on processor redisplay must be meaningless */
        no_processor_redisplay = false;
        _route = r;
 
-       connections.push_back (_route->processors_changed.connect (
-                       mem_fun(*this, &ProcessorBox::redisplay_processors)));
-       connections.push_back (_route->GoingAway.connect (
-                       mem_fun (*this, &ProcessorBox::route_going_away)));
-       connections.push_back (_route->NameChanged.connect (
-                       mem_fun(*this, &ProcessorBox::route_name_changed)));
+       _route->processors_changed.connect (connections, invalidator (*this), ui_bind (&ProcessorBox::route_processors_changed, this, _1), gui_context());
+       _route->DropReferences.connect (connections, invalidator (*this), boost::bind (&ProcessorBox::route_going_away, this), gui_context());
+       _route->PropertyChanged.connect (connections, invalidator (*this), ui_bind (&ProcessorBox::route_property_changed, this, _1), gui_context());
 
        redisplay_processors ();
 }
@@ -385,7 +386,7 @@ ProcessorBox::set_width (Width w)
 
        list<ProcessorEntry*> children = processor_display.children ();
        for (list<ProcessorEntry*>::iterator i = children.begin(); i != children.end(); ++i) {
-               (*i)->set_width (w);
+               (*i)->set_enum_width (w);
        }
 
        redisplay_processors ();
@@ -422,14 +423,14 @@ ProcessorBox::build_send_action_menu ()
        send_action_menu->set_name ("ArdourContextMenu");
        MenuList& items = send_action_menu->items();
 
-       items.push_back (MenuElem (_("New send"), mem_fun(*this, &ProcessorBox::new_send)));
-       items.push_back (MenuElem (_("Show send controls"), mem_fun(*this, &ProcessorBox::show_send_controls)));
+       items.push_back (MenuElem (_("New send"), sigc::mem_fun(*this, &ProcessorBox::new_send)));
+       items.push_back (MenuElem (_("Show send controls"), sigc::mem_fun(*this, &ProcessorBox::show_send_controls)));
 }
 
 Gtk::Menu*
 ProcessorBox::build_possible_aux_menu ()
 {
-       boost::shared_ptr<RouteList> rl = _session.get_routes_with_internal_returns();
+       boost::shared_ptr<RouteList> rl = _session->get_routes_with_internal_returns();
 
        if (rl->empty()) {
                return 0;
@@ -441,7 +442,7 @@ ProcessorBox::build_possible_aux_menu ()
 
        for (RouteList::iterator r = rl->begin(); r != rl->end(); ++r) {
                if (!_route->internal_send_for (*r) && *r != _route) {
-                       items.push_back (MenuElem ((*r)->name(), bind (sigc::ptr_fun (ProcessorBox::rb_choose_aux), boost::weak_ptr<Route>(*r))));
+                       items.push_back (MenuElem ((*r)->name(), sigc::bind (sigc::ptr_fun (ProcessorBox::rb_choose_aux), boost::weak_ptr<Route>(*r))));
                }
        }
 
@@ -485,6 +486,7 @@ ProcessorBox::show_processor_menu (gint arg)
                }
        }
 
+        cut_action->set_sensitive (can_cut());
        paste_action->set_sensitive (!_rr_selection.processors.empty());
 
        processor_menu->popup (1, arg);
@@ -542,15 +544,24 @@ ProcessorBox::processor_key_release_event (GdkEventKey *ev)
 
 
        switch (ev->keyval) {
+       case GDK_a:
+               if (Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
+                       processor_display.select_all ();
+                       ret = true;
+               } 
+               break;
+
        case GDK_c:
                if (Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
                        copy_processors (targets);
+                       ret = true;
                }
                break;
 
        case GDK_x:
                if (Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
                        cut_processors (targets);
+                       ret = true;
                }
                break;
 
@@ -561,16 +572,23 @@ ProcessorBox::processor_key_release_event (GdkEventKey *ev)
                        } else {
                                paste_processors (targets.front());
                        }
+                       ret = true;
                }
                break;
 
+       case GDK_Up:
+               break;
+
+       case GDK_Down:
+               break;
+
        case GDK_Delete:
        case GDK_BackSpace:
                delete_processors (targets);
                ret = true;
                break;
 
-       case GDK_slash:
+       case GDK_Return:
                for (ProcSelection::iterator i = targets.begin(); i != targets.end(); ++i) {
                        if ((*i)->active()) {
                                (*i)->deactivate ();
@@ -581,6 +599,11 @@ ProcessorBox::processor_key_release_event (GdkEventKey *ev)
                ret = true;
                break;
 
+       case GDK_slash:
+               ab_plugins ();
+               ret = true;
+               break;
+
        default:
                break;
        }
@@ -601,7 +624,7 @@ ProcessorBox::processor_button_press_event (GdkEventButton *ev, ProcessorEntry*
 
        if (processor && (Keyboard::is_edit_event (ev) || (ev->button == 1 && ev->type == GDK_2BUTTON_PRESS))) {
 
-               if (_session.engine().connected()) {
+               if (_session->engine().connected()) {
                        /* XXX giving an error message here is hard, because we may be in the midst of a button press */
                        edit_processor (processor);
                }
@@ -633,8 +656,8 @@ ProcessorBox::processor_button_release_event (GdkEventButton *ev, ProcessorEntry
 
        if (processor && Keyboard::is_delete_event (ev)) {
 
-               Glib::signal_idle().connect (bind (
-                               mem_fun(*this, &ProcessorBox::idle_delete_processor),
+               Glib::signal_idle().connect (sigc::bind (
+                               sigc::mem_fun(*this, &ProcessorBox::idle_delete_processor),
                                boost::weak_ptr<Processor>(processor)));
                ret = true;
 
@@ -693,6 +716,11 @@ ProcessorBox::selection_changed ()
 {
        bool sensitive = (processor_display.selection().empty()) ? false : true;
        ActionManager::set_sensitive (ActionManager::plugin_selection_sensitive_actions, sensitive);
+
+       /* disallow rename for multiple selections and for plugin inserts */
+       rename_action->set_sensitive (
+               processor_display.selection().size() == 1 && boost::dynamic_pointer_cast<PluginInsert> (processor_display.selection().front()->processor()) == 0
+               );
 }
 
 void
@@ -713,12 +741,13 @@ ProcessorBox::choose_plugin ()
        _get_plugin_selector()->set_interested_object (*this);
 }
 
-void
+/** @return true if an error occurred, otherwise false */
+bool
 ProcessorBox::use_plugins (const SelectedPlugins& plugins)
 {
        for (SelectedPlugins::const_iterator p = plugins.begin(); p != plugins.end(); ++p) {
 
-               boost::shared_ptr<Processor> processor (new PluginInsert (_session, *p));
+               boost::shared_ptr<Processor> processor (new PluginInsert (*_session, *p));
 
                Route::ProcessorStreams err_streams;
 
@@ -728,6 +757,7 @@ ProcessorBox::use_plugins (const SelectedPlugins& plugins)
 
                if (_route->add_processor (processor, _placement, &err_streams)) {
                        weird_plugin_dialog (**p, err_streams);
+                       return true;
                        // XXX SHAREDPTR delete plugin here .. do we even need to care?
                } else {
 
@@ -736,12 +766,14 @@ ProcessorBox::use_plugins (const SelectedPlugins& plugins)
                        }
                }
        }
+
+       return false;
 }
 
 void
 ProcessorBox::weird_plugin_dialog (Plugin& p, Route::ProcessorStreams streams)
 {
-       ArdourDialog dialog (_("ardour: weird plugin dialog"));
+       ArdourDialog dialog (_("Plugin Incompatibility"));
        Label label;
 
        string text = string_compose(_("You attempted to add the plugin \"%1\" at index %2.\n"),
@@ -766,7 +798,7 @@ ProcessorBox::weird_plugin_dialog (Plugin& p, Route::ProcessorStreams streams)
                text += string_compose("\t%1 ", streams.count.n_audio()) + _("audio channel(s)\n");
        }
 
-       text += _("\nArdour is unable to insert this plugin here.\n");
+       text += string_compose (_("\n%1 is unable to insert this plugin here.\n"), PROGRAM_NAME);
        label.set_text(text);
 
        dialog.get_vbox()->pack_start (label);
@@ -783,18 +815,18 @@ ProcessorBox::weird_plugin_dialog (Plugin& p, Route::ProcessorStreams streams)
 void
 ProcessorBox::choose_insert ()
 {
-       boost::shared_ptr<Processor> processor (new PortInsert (_session, _route->mute_master()));
+       boost::shared_ptr<Processor> processor (new PortInsert (*_session, _route->mute_master()));
        _route->add_processor (processor, _placement);
 }
 
 void
 ProcessorBox::choose_send ()
 {
-       boost::shared_ptr<Send> send (new Send (_session, _route->mute_master()));
+       boost::shared_ptr<Send> send (new Send (*_session, _route->mute_master()));
 
        /* make an educated guess at the initial number of outputs for the send */
-       ChanCount outs = (_session.master_out())
-                       ? _session.master_out()->n_outputs()
+       ChanCount outs = (_session->master_out())
+                       ? _session->master_out()->n_outputs()
                        : _route->n_outputs();
 
        /* XXX need processor lock on route */
@@ -820,8 +852,8 @@ ProcessorBox::choose_send ()
        */
        _processor_being_created = send;
 
-       ios->selector().Finished.connect (bind (
-                       mem_fun(*this, &ProcessorBox::send_io_finished),
+       ios->selector().Finished.connect (sigc::bind (
+                       sigc::mem_fun(*this, &ProcessorBox::send_io_finished),
                        boost::weak_ptr<Processor>(send), ios));
 
 }
@@ -854,35 +886,6 @@ ProcessorBox::send_io_finished (IOSelector::Result r, boost::weak_ptr<Processor>
        delete_when_idle (ios);
 }
 
-void
-ProcessorBox::choose_return ()
-{
-       boost::shared_ptr<Return> retrn (new Return (_session));
-
-       /* assume user just wants a single audio input (sidechain) by default */
-       ChanCount ins(DataType::AUDIO, 1);
-
-       /* XXX need processor lock on route */
-       try {
-               retrn->input()->ensure_io (ins, false, this);
-       } catch (AudioEngine::PortRegistrationFailure& err) {
-               error << string_compose (_("Cannot set up new return: %1"), err.what()) << endmsg;
-               return;
-       }
-
-       /* let the user adjust the IO setup before creation */
-       IOSelectorWindow *ios = new IOSelectorWindow (_session, retrn->input(), true);
-       ios->show_all ();
-
-       /* keep a reference to the return so it doesn't get deleted while
-          the IOSelectorWindow is doing its stuff */
-       _processor_being_created = retrn;
-
-       ios->selector().Finished.connect (bind (
-                       mem_fun(*this, &ProcessorBox::return_io_finished),
-                       boost::weak_ptr<Processor>(retrn), ios));
-}
-
 void
 ProcessorBox::return_io_finished (IOSelector::Result r, boost::weak_ptr<Processor> weak_processor, IOSelectorWindow* ios)
 {
@@ -927,13 +930,24 @@ ProcessorBox::choose_aux (boost::weak_ptr<Route> wr)
        boost::shared_ptr<RouteList> rlist (new RouteList);
        rlist->push_back (_route);
 
-       _session.add_internal_sends (target, PreFader, rlist);
+       _session->add_internal_sends (target, PreFader, rlist);
+}
+
+void
+ProcessorBox::route_processors_changed (RouteProcessorChange c)
+{
+       if (c.type == RouteProcessorChange::MeterPointChange && c.meter_visibly_changed == false) {
+               /* the meter has moved, but it was and still is invisible to the user, so nothing to do */
+               return;
+       }
+
+       redisplay_processors ();
 }
 
 void
 ProcessorBox::redisplay_processors ()
 {
-       ENSURE_GUI_THREAD (mem_fun(*this, &ProcessorBox::redisplay_processors));
+       ENSURE_GUI_THREAD (*this, &ProcessorBox::redisplay_processors)
 
        if (no_processor_redisplay) {
                return;
@@ -941,7 +955,7 @@ ProcessorBox::redisplay_processors ()
 
        processor_display.clear ();
 
-       _route->foreach_processor (mem_fun (*this, &ProcessorBox::add_processor_to_display));
+       _route->foreach_processor (sigc::mem_fun (*this, &ProcessorBox::add_processor_to_display));
 
        build_processor_tooltip (processor_eventbox, _("Inserts, sends & plugins:"));
 }
@@ -956,11 +970,14 @@ ProcessorBox::add_processor_to_display (boost::weak_ptr<Processor> p)
        }
 
        boost::shared_ptr<Send> send = boost::dynamic_pointer_cast<Send> (processor);
+       ProcessorEntry* e = 0;
        if (send) {
-               processor_display.add_child (new SendProcessorEntry (send, _width));
+               e = new SendProcessorEntry (send, _width);
        } else {
-               processor_display.add_child (new ProcessorEntry (processor, _width));
+               e = new ProcessorEntry (processor, _width);
        }
+       e->set_pixel_width (get_allocation().get_width());
+       processor_display.add_child (e);
 }
 
 
@@ -975,7 +992,7 @@ ProcessorBox::build_processor_tooltip (EventBox& box, string start)
                tip += (*i)->processor()->name();
        }
        
-       ARDOUR_UI::instance()->tooltips().set_tip (box, tip);
+       ARDOUR_UI::instance()->set_tip (box, tip);
 }
 
 void
@@ -1002,14 +1019,15 @@ ProcessorBox::compute_processor_sort_keys ()
 
                /* now tell them about the problem */
 
-               ArdourDialog dialog (_("ardour: weird plugin dialog"));
+               ArdourDialog dialog (_("Plugin Incompatibility"));
                Label label;
 
                label.set_text (_("\
-You cannot reorder this set of processors\n\
+You cannot reorder these plugins/sends/inserts\n\
 in that way because the inputs and\n\
-outputs do not work correctly."));
+outputs will not work correctly."));
 
+               dialog.get_vbox()->set_border_width (12);
                dialog.get_vbox()->pack_start (label);
                dialog.add_button (Stock::OK, RESPONSE_ACCEPT);
 
@@ -1038,6 +1056,27 @@ ProcessorBox::rename_processors ()
        }
 }
 
+bool
+ProcessorBox::can_cut () const
+{
+        vector<boost::shared_ptr<Processor> > sel;
+
+        get_selected_processors (sel);
+        
+        /* cut_processors () does not cut inserts */
+
+        for (vector<boost::shared_ptr<Processor> >::const_iterator i = sel.begin (); i != sel.end (); ++i) {
+                
+               if (boost::dynamic_pointer_cast<PluginInsert>((*i)) != 0 ||
+                   (boost::dynamic_pointer_cast<Send>((*i)) != 0) ||
+                   (boost::dynamic_pointer_cast<Return>((*i)) != 0)) {
+                        return true;
+                }
+        }
+        
+        return false;
+}
+
 void
 ProcessorBox::cut_processors ()
 {
@@ -1205,11 +1244,27 @@ ProcessorBox::rename_processor (boost::shared_ptr<Processor> processor)
        case Gtk::RESPONSE_ACCEPT:
                name_prompter.get_result (result);
                if (result.length()) {
-                       if (_session.route_by_name (result)) {
-                               ARDOUR_UI::instance()->popup_error (_("A track already exists with that name."));
-                               return;
-                       }
-                       processor->set_name (result);
+
+                       int tries = 0;
+                       string test = result;
+
+                       while (tries < 100) {
+                               if (_session->io_name_is_legal (test)) {
+                                       result = test;
+                                       break;
+                               }
+                               tries++;
+
+                               test = string_compose ("%1-%2", result, tries);
+                       }
+
+                       if (tries < 100) {
+                               processor->set_name (result);
+                       } else {
+                               /* unlikely! */
+                               ARDOUR_UI::instance()->popup_error
+                                       (string_compose (_("At least 100 IO objects exist with a name like %1 - name not changed"), result));
+                       }
                }
                break;
        }
@@ -1265,20 +1320,36 @@ ProcessorBox::paste_processor_state (const XMLNodeList& nlist, boost::shared_ptr
                        } else if (type->value() == "send") {
 
                                XMLNode n (**niter);
-                               Send::make_unique (n, _session);
-                               p.reset (new Send (_session, _route->mute_master(), n));
+                               Send::make_unique (n, *_session);
+                                Send* s = new Send (*_session, _route->mute_master());
+                                if (s->set_state (n, Stateful::loading_state_version)) {
+                                        delete s;
+                                        return;
+                                }
+
+                               p.reset (s);
+                                        
 
                        } else if (type->value() == "return") {
 
                                XMLNode n (**niter);
-                               Return::make_unique (n, _session);
-                               p.reset (new Return (_session, **niter));
+                               Return::make_unique (n, *_session);
+                                Return* r = new Return (*_session);
+
+                                if (r->set_state (n, Stateful::loading_state_version)) {
+                                        delete r;
+                                        return;
+                                }
+
+                               p.reset (r);
 
                        } else {
                                /* XXX its a bit limiting to assume that everything else
                                   is a plugin.
                                */
-                               p.reset (new PluginInsert (_session, **niter));
+
+                               p.reset (new PluginInsert (*_session));
+                                p->set_state (**niter, Stateful::current_state_version);
                        }
 
                        copies.push_back (p);
@@ -1317,10 +1388,10 @@ ProcessorBox::deactivate_processor (boost::shared_ptr<Processor> r)
 }
 
 void
-ProcessorBox::get_selected_processors (ProcSelection& processors)
+ProcessorBox::get_selected_processors (ProcSelection& processors) const
 {
-       list<ProcessorEntry*> selection = processor_display.selection ();
-       for (list<ProcessorEntry*>::iterator i = selection.begin(); i != selection.end(); ++i) {
+       const list<ProcessorEntry*> selection = processor_display.selection ();
+       for (list<ProcessorEntry*>::const_iterator i = selection.begin(); i != selection.end(); ++i) {
                processors.push_back ((*i)->processor ());
        }
 }
@@ -1360,7 +1431,7 @@ ProcessorBox::clear_processors ()
        choices.push_back (_("Cancel"));
        choices.push_back (_("Yes, remove them all"));
 
-       Gtkmm2ext::Choice prompter (prompt, choices);
+       Gtkmm2ext::Choice prompter (_("Remove processors"), prompt, choices);
 
        if (prompter.run () == 1) {
                _route->clear_processors (PreFader);
@@ -1385,7 +1456,7 @@ ProcessorBox::clear_processors (Placement p)
        choices.push_back (_("Cancel"));
        choices.push_back (_("Yes, remove them all"));
 
-       Gtkmm2ext::Choice prompter (prompt, choices);
+       Gtkmm2ext::Choice prompter (_("Remove processors"), prompt, choices);
 
        if (prompter.run () == 1) {
                _route->clear_processors (p);
@@ -1410,7 +1481,7 @@ ProcessorBox::edit_processor (boost::shared_ptr<Processor> processor)
 
        if ((send = boost::dynamic_pointer_cast<Send> (processor)) != 0) {
 
-               if (!_session.engine().connected()) {
+               if (!_session->engine().connected()) {
                        return;
                }
 
@@ -1435,7 +1506,7 @@ ProcessorBox::edit_processor (boost::shared_ptr<Processor> processor)
 
        } else if ((retrn = boost::dynamic_pointer_cast<Return> (processor)) != 0) {
 
-               if (!_session.engine().connected()) {
+               if (!_session->engine().connected()) {
                        return;
                }
 
@@ -1479,7 +1550,7 @@ ProcessorBox::edit_processor (boost::shared_ptr<Processor> processor)
 
        } else if ((port_insert = boost::dynamic_pointer_cast<PortInsert> (processor)) != 0) {
 
-               if (!_session.engine().connected()) {
+               if (!_session->engine().connected()) {
                        MessageDialog msg ( _("Not connected to JACK - no I/O changes are possible"));
                        msg.run ();
                        return;
@@ -1526,8 +1597,6 @@ ProcessorBox::register_actions ()
        ActionManager::jack_sensitive_actions.push_back (act);
 
        ActionManager::register_action (popup_act_grp, X_("newaux"), _("New Aux Send ..."));
-       ActionManager::register_action (popup_act_grp, X_("newreturn"), _("New Return ..."),
-                                       sigc::ptr_fun (ProcessorBox::rb_choose_return));
 
        ActionManager::register_action (popup_act_grp, X_("clear"), _("Clear (all)"),
                        sigc::ptr_fun (ProcessorBox::rb_clear));
@@ -1537,9 +1606,9 @@ ProcessorBox::register_actions ()
                        sigc::ptr_fun (ProcessorBox::rb_clear_post));
 
        /* standard editing stuff */
-       act = ActionManager::register_action (popup_act_grp, X_("cut"), _("Cut"),
-                       sigc::ptr_fun (ProcessorBox::rb_cut));
-       ActionManager::plugin_selection_sensitive_actions.push_back(act);
+       cut_action = ActionManager::register_action (popup_act_grp, X_("cut"), _("Cut"),
+                                                     sigc::ptr_fun (ProcessorBox::rb_cut));
+       ActionManager::plugin_selection_sensitive_actions.push_back(cut_action);
        act = ActionManager::register_action (popup_act_grp, X_("copy"), _("Copy"),
                        sigc::ptr_fun (ProcessorBox::rb_copy));
        ActionManager::plugin_selection_sensitive_actions.push_back(act);
@@ -1550,64 +1619,65 @@ ProcessorBox::register_actions ()
 
        paste_action = ActionManager::register_action (popup_act_grp, X_("paste"), _("Paste"),
                        sigc::ptr_fun (ProcessorBox::rb_paste));
-       act = ActionManager::register_action (popup_act_grp, X_("rename"), _("Rename"),
+       rename_action = ActionManager::register_action (popup_act_grp, X_("rename"), _("Rename"),
                        sigc::ptr_fun (ProcessorBox::rb_rename));
-       ActionManager::plugin_selection_sensitive_actions.push_back(act);
        ActionManager::register_action (popup_act_grp, X_("selectall"), _("Select All"),
                        sigc::ptr_fun (ProcessorBox::rb_select_all));
        ActionManager::register_action (popup_act_grp, X_("deselectall"), _("Deselect All"),
                        sigc::ptr_fun (ProcessorBox::rb_deselect_all));
 
-       /* activation */
+       /* activation etc. */
 
-       ActionManager::plugin_selection_sensitive_actions.push_back(act);
        ActionManager::register_action (popup_act_grp, X_("activate_all"), _("Activate all"),
-                       sigc::ptr_fun (ProcessorBox::rb_activate_all));
+                                       sigc::ptr_fun (ProcessorBox::rb_activate_all));
        ActionManager::register_action (popup_act_grp, X_("deactivate_all"), _("Deactivate all"),
-                       sigc::ptr_fun (ProcessorBox::rb_deactivate_all));
+                                       sigc::ptr_fun (ProcessorBox::rb_deactivate_all));
+       ActionManager::register_action (popup_act_grp, X_("ab_plugins"), _("A/B Plugins"),
+                                       sigc::ptr_fun (ProcessorBox::rb_ab_plugins));
 
        /* show editors */
        act = ActionManager::register_action (popup_act_grp, X_("edit"), _("Edit"),
-                       sigc::ptr_fun (ProcessorBox::rb_edit));
+                                             sigc::ptr_fun (ProcessorBox::rb_edit));
        ActionManager::plugin_selection_sensitive_actions.push_back(act);
 
        ActionManager::add_action_group (popup_act_grp);
 }
 
 void
-ProcessorBox::rb_choose_plugin ()
+ProcessorBox::rb_ab_plugins ()
 {
        if (_current_processor_box == 0) {
                return;
        }
-       _current_processor_box->choose_plugin ();
+
+       _current_processor_box->ab_plugins ();
 }
 
 void
-ProcessorBox::rb_choose_insert ()
+ProcessorBox::rb_choose_plugin ()
 {
        if (_current_processor_box == 0) {
                return;
        }
-       _current_processor_box->choose_insert ();
+       _current_processor_box->choose_plugin ();
 }
 
 void
-ProcessorBox::rb_choose_send ()
+ProcessorBox::rb_choose_insert ()
 {
        if (_current_processor_box == 0) {
                return;
        }
-       _current_processor_box->choose_send ();
+       _current_processor_box->choose_insert ();
 }
 
 void
-ProcessorBox::rb_choose_return ()
+ProcessorBox::rb_choose_send ()
 {
        if (_current_processor_box == 0) {
                return;
        }
-       _current_processor_box->choose_return ();
+       _current_processor_box->choose_send ();
 }
 
 void
@@ -1750,9 +1820,13 @@ ProcessorBox::rb_edit ()
 }
 
 void
-ProcessorBox::route_name_changed ()
+ProcessorBox::route_property_changed (const PropertyChange& what_changed)
 {
-       ENSURE_GUI_THREAD (mem_fun (*this, &ProcessorBox::route_name_changed));
+       if (!what_changed.contains (ARDOUR::Properties::name)) {
+               return;
+       }
+
+       ENSURE_GUI_THREAD (*this, &ProcessorBox::route_property_changed, what_changed);
 
        boost::shared_ptr<Processor> processor;
        boost::shared_ptr<PluginInsert> plugin_insert;
@@ -1798,3 +1872,13 @@ ProcessorBox::generate_processor_title (boost::shared_ptr<PluginInsert> pi)
        return string_compose(_("%1: %2 (by %3)"), _route->name(), pi->name(), maker);
 }
 
+void
+ProcessorBox::on_size_allocate (Allocation& a)
+{
+       HBox::on_size_allocate (a);
+
+       list<ProcessorEntry*> children = processor_display.children ();
+       for (list<ProcessorEntry*>::const_iterator i = children.begin(); i != children.end(); ++i) {
+               (*i)->set_pixel_width (a.get_width ());
+       }
+}