remove Glib::ustring from gtk2_ardour
[ardour.git] / gtk2_ardour / route_ui.cc
index 5e89d6292a7d312481e512ca1193c9f445117011..ab83206a8c36f3bf18ffbdcea794f1941a574522 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2002-2006 Paul Davis 
+    Copyright (C) 2002-2006 Paul Davis
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -18,7 +18,6 @@
 */
 
 #include <gtkmm2ext/gtk_ui.h>
-#include <gtkmm2ext/stop_signal.h>
 #include <gtkmm2ext/choice.h>
 #include <gtkmm2ext/doi.h>
 #include <gtkmm2ext/bindable_button.h>
 #include <gtkmm2ext/gtk_ui.h>
 
 #include "ardour/route_group.h"
+#include "ardour/dB.h"
 #include "pbd/memento_command.h"
 #include "pbd/stacktrace.h"
-#include "pbd/shiva.h"
 #include "pbd/controllable.h"
+#include "pbd/enumwriter.h"
 
+#include "ardour_ui.h"
+#include "editor.h"
 #include "route_ui.h"
+#include "led.h"
 #include "keyboard.h"
 #include "utils.h"
 #include "prompter.h"
 #include "gui_thread.h"
 #include "ardour_dialog.h"
 #include "latency_gui.h"
+#include "mixer_strip.h"
 #include "automation_time_axis.h"
+#include "route_time_axis.h"
 
 #include "ardour/route.h"
+#include "ardour/event_type_map.h"
 #include "ardour/session.h"
 #include "ardour/audioengine.h"
 #include "ardour/audio_track.h"
-#include "ardour/audio_diskstream.h"
 #include "ardour/midi_track.h"
-#include "ardour/midi_diskstream.h"
 #include "ardour/template_utils.h"
 #include "ardour/filename_extensions.h"
 #include "ardour/directory_names.h"
 #include "ardour/profile.h"
 
 #include "i18n.h"
-using namespace sigc;
 using namespace Gtk;
 using namespace Gtkmm2ext;
 using namespace ARDOUR;
 using namespace PBD;
 
-RouteUI::RouteUI (ARDOUR::Session& sess, const char* mute_name, const char* solo_name, const char* rec_name)
+uint32_t RouteUI::_max_invert_buttons = 4;
+
+RouteUI::RouteUI (ARDOUR::Session* sess)
        : AxisView(sess)
 {
        init ();
-       set_button_names (mute_name, solo_name, rec_name);
 }
 
-RouteUI::RouteUI (boost::shared_ptr<ARDOUR::Route> rt, 
-                 ARDOUR::Session& sess, const char* mute_name, const char* solo_name, const char* rec_name)
+RouteUI::RouteUI (boost::shared_ptr<ARDOUR::Route> rt, ARDOUR::Session* sess)
        : AxisView(sess)
 {
        init ();
-       set_button_names (mute_name, solo_name, rec_name);
        set_route (rt);
 }
 
 RouteUI::~RouteUI()
 {
-       /* derived classes should emit GoingAway so that they receive the signal
-          when the object is still a legal derived instance.
-       */
-       
+       _route.reset (); /* drop reference to route, so that it can be cleaned up */
+       route_connections.drop_connections ();
+
        delete solo_menu;
        delete mute_menu;
-       delete remote_control_menu;
+       delete sends_menu;
+        delete record_menu;
+       delete _invert_menu;
 }
 
 void
@@ -93,61 +96,99 @@ RouteUI::init ()
        xml_node = 0;
        mute_menu = 0;
        solo_menu = 0;
-       remote_control_menu = 0;
-       ignore_toggle = false;
-       wait_for_release = false;
+       sends_menu = 0;
+        record_menu = 0;
+       _invert_menu = 0;
+       pre_fader_mute_check = 0;
+       post_fader_mute_check = 0;
+       listen_mute_check = 0;
+       main_mute_check = 0;
+        solo_safe_check = 0;
+        solo_isolated_check = 0;
+        solo_isolated_led = 0;
+        solo_safe_led = 0;
+       _solo_release = 0;
+       _mute_release = 0;
        route_active_menu_item = 0;
-       was_solo_safe = false;
-       polarity_menu_item = 0;
        denormal_menu_item = 0;
+        step_edit_item = 0;
        multiple_mute_change = false;
        multiple_solo_change = false;
+       _i_am_the_modifier = 0;
 
-       mute_button = manage (new BindableToggleButton (""));
-       mute_button->set_self_managed (true);
+       setup_invert_buttons ();
+
+       mute_button = manage (new BindableToggleButton ());
+       // mute_button->set_self_managed (true);
        mute_button->set_name ("MuteButton");
+       mute_button->add (mute_button_label);
+       mute_button_label.show ();
        UI::instance()->set_tip (mute_button, _("Mute this track"), "");
 
-       solo_button = manage (new BindableToggleButton (""));
-       solo_button->set_self_managed (true);
+       solo_button = manage (new BindableToggleButton ());
+       // solo_button->set_self_managed (true);
        solo_button->set_name ("SoloButton");
+       solo_button->add (solo_button_label);
+       solo_button_label.show ();
        UI::instance()->set_tip (solo_button, _("Mute other (non-soloed) tracks"), "");
+       solo_button->set_no_show_all (true);
 
-       rec_enable_button = manage (new BindableToggleButton (""));
+       rec_enable_button = manage (new BindableToggleButton ());
        rec_enable_button->set_name ("RecordEnableButton");
-       rec_enable_button->set_self_managed (true);
+       // rec_enable_button->set_self_managed (true);
+       rec_enable_button->add (rec_enable_button_label);
+       rec_enable_button_label.show ();
        UI::instance()->set_tip (rec_enable_button, _("Enable recording on this track"), "");
 
-       _session.SoloChanged.connect (mem_fun(*this, &RouteUI::solo_changed_so_update_mute));
+       show_sends_button = manage (new BindableToggleButton (""));
+       show_sends_button->set_name ("SendAlert");
+       // show_sends_button->set_self_managed (true);
+       UI::instance()->set_tip (show_sends_button, _("make mixer strips show sends to this bus"), "");
+
+       _session->SoloChanged.connect (_session_connections, invalidator (*this), boost::bind (&RouteUI::solo_changed_so_update_mute, this), gui_context());
+       _session->TransportStateChange.connect (_session_connections, invalidator (*this), boost::bind (&RouteUI::check_rec_enable_sensitivity, this), gui_context());
+       _session->RecordStateChanged.connect (_session_connections, invalidator (*this), boost::bind (&RouteUI::session_rec_enable_changed, this), gui_context());
+
+       Config->ParameterChanged.connect (*this, invalidator (*this), ui_bind (&RouteUI::parameter_changed, this, _1), gui_context());
+
+       rec_enable_button->signal_button_press_event().connect (sigc::mem_fun(*this, &RouteUI::rec_enable_press), false);
+       rec_enable_button->signal_button_release_event().connect (sigc::mem_fun(*this, &RouteUI::rec_enable_release), false);
+
+       show_sends_button->signal_button_press_event().connect (sigc::mem_fun(*this, &RouteUI::show_sends_press), false);
+       show_sends_button->signal_button_release_event().connect (sigc::mem_fun(*this, &RouteUI::show_sends_release));
+
+       solo_button->signal_button_press_event().connect (sigc::mem_fun(*this, &RouteUI::solo_press), false);
+       solo_button->signal_button_release_event().connect (sigc::mem_fun(*this, &RouteUI::solo_release), false);
+       mute_button->signal_button_press_event().connect (sigc::mem_fun(*this, &RouteUI::mute_press), false);
+       mute_button->signal_button_release_event().connect (sigc::mem_fun(*this, &RouteUI::mute_release), false);
 }
 
 void
 RouteUI::reset ()
 {
-       connections.clear ();
+       route_connections.drop_connections ();
 
        delete solo_menu;
        solo_menu = 0;
 
        delete mute_menu;
        mute_menu = 0;
-       
+
        if (xml_node) {
                /* do not delete the node - its owned by the route */
                xml_node = 0;
        }
 
        route_active_menu_item = 0;
-       polarity_menu_item = 0;
        denormal_menu_item = 0;
 }
 
 void
-RouteUI::set_button_names (const char* mute, const char* solo, const char* rec)
+RouteUI::self_delete ()
 {
-       m_name = mute;
-       s_name = solo;
-       r_name = rec;
+       /* This may be called from a non-GUI thread. Keep it safe */
+
+       delete_when_idle (this);
 }
 
 void
@@ -161,63 +202,80 @@ RouteUI::set_route (boost::shared_ptr<Route> rp)
                set_color (unique_random_color());
        }
 
-       /* no, there is no memory leak here. This object cleans itself (and other stuff)
-          up when the route is destroyed.
-       */
-
        if (self_destruct) {
-               new PairedShiva<Route,RouteUI> (*_route, *this);
+               rp->DropReferences.connect (route_connections, invalidator (*this), boost::bind (&RouteUI::self_delete, this), gui_context());
        }
-
-       mute_button->set_controllable (_route->mute_control());
-       mute_button->set_label (m_name);
        
+       mute_button->set_controllable (_route->mute_control());
        solo_button->set_controllable (_route->solo_control());
-       solo_button->set_label (s_name);
-  
-       connections.push_back (_route->active_changed.connect (mem_fun (*this, &RouteUI::route_active_changed)));
-       connections.push_back (_route->mute_changed.connect (mem_fun(*this, &RouteUI::mute_changed)));
-       connections.push_back (_route->solo_changed.connect (mem_fun(*this, &RouteUI::solo_changed)));
-       connections.push_back (_route->solo_safe_changed.connect (mem_fun(*this, &RouteUI::solo_changed)));
-  
-       /* when solo changes, update mute state too, in case the user wants us to display it */
-
-       _session.SoloChanged.connect (mem_fun(*this, &RouteUI::solo_changed_so_update_mute));
-       
-       if (is_track()) {
+
+       _route->active_changed.connect (route_connections, invalidator (*this), boost::bind (&RouteUI::route_active_changed, this), gui_context());
+       _route->mute_changed.connect (route_connections, invalidator (*this), ui_bind (&RouteUI::mute_changed, this, _1), gui_context());
+
+       _route->solo_changed.connect (route_connections, invalidator (*this), boost::bind (&RouteUI::update_solo_display, this), gui_context());
+       _route->solo_safe_changed.connect (route_connections, invalidator (*this), boost::bind (&RouteUI::update_solo_display, this), gui_context());
+       _route->listen_changed.connect (route_connections, invalidator (*this), boost::bind (&RouteUI::update_solo_display, this), gui_context());
+       _route->solo_isolated_changed.connect (route_connections, invalidator (*this), boost::bind (&RouteUI::update_solo_display, this), gui_context());
+
+        _route->phase_invert_changed.connect (route_connections, invalidator (*this), boost::bind (&RouteUI::polarity_changed, this), gui_context());
+       _route->PropertyChanged.connect (route_connections, invalidator (*this), ui_bind (&RouteUI::property_changed, this, _1), gui_context());
+
+       _route->io_changed.connect (route_connections, invalidator (*this), ui_bind (&RouteUI::setup_invert_buttons, this), gui_context ());
+
+       if (_session->writable() && is_track()) {
                boost::shared_ptr<Track> t = boost::dynamic_pointer_cast<Track>(_route);
 
-               connections.push_back (t->diskstream()->RecordEnableChanged.connect (mem_fun (*this, &RouteUI::route_rec_enable_changed)));
-               connections.push_back (_session.RecordStateChanged.connect (mem_fun (*this, &RouteUI::session_rec_enable_changed)));
+               t->RecordEnableChanged.connect (route_connections, invalidator (*this), boost::bind (&RouteUI::route_rec_enable_changed, this), gui_context());
 
                rec_enable_button->show();
                rec_enable_button->set_controllable (t->rec_enable_control());
-               rec_enable_button->set_label (r_name);
 
                update_rec_display ();
-       } 
+
+                if (is_midi_track()) {
+                        midi_track()->StepEditStatusChange.connect (route_connections, invalidator (*this),
+                                                                    ui_bind (&RouteUI::step_edit_changed, this, _1), gui_context());
+                }
+
+       }
 
        mute_button->unset_flags (Gtk::CAN_FOCUS);
        solo_button->unset_flags (Gtk::CAN_FOCUS);
-       
-       mute_button->show();
-       solo_button->show();
 
-       connections.push_back (_route->RemoteControlIDChanged.connect (mem_fun(*this, &RouteUI::refresh_remote_control_menu)));
+       mute_button->show();
 
-       /* map the current state */
+       if (_route->is_monitor()) {
+               solo_button->hide ();
+       } else {
+               solo_button->show();
+       }
 
        map_frozen ();
+
+       setup_invert_buttons ();
+       set_invert_button_state ();
+}
+
+void
+RouteUI::polarity_changed ()
+{
+        if (!_route) {
+                return;
+        }
+
+       set_invert_button_state ();
 }
 
 bool
-RouteUI::mute_press(GdkEventButton* ev)
+RouteUI::mute_press (GdkEventButton* ev)
 {
        if (ev->type == GDK_2BUTTON_PRESS || ev->type == GDK_3BUTTON_PRESS ) {
                return true;
        }
+
        multiple_mute_change = false;
-       if (!ignore_toggle) {
+
+       if (!_i_am_the_modifier) {
 
                if (Keyboard::is_context_menu_event (ev)) {
 
@@ -232,46 +290,52 @@ RouteUI::mute_press(GdkEventButton* ev)
                        if (Keyboard::is_button2_event (ev)) {
                                // Primary-button2 click is the midi binding click
                                // button2-click is "momentary"
-                               
-                               if (!Keyboard::modifier_state_equals (ev->state, Keyboard::ModifierMask (Keyboard::PrimaryModifier))) {
-                                       wait_for_release = true;
-                               } else {
-                                       return false;
-                               }
+
+
+                               if (mute_button->on_button_press_event (ev)) {
+                                        return true;
+                                }
+
+                               _mute_release = new SoloMuteRelease (_route->muted ());
                        }
 
                        if (ev->button == 1 || Keyboard::is_button2_event (ev)) {
 
                                if (Keyboard::modifier_state_equals (ev->state, Keyboard::ModifierMask (Keyboard::PrimaryModifier|Keyboard::TertiaryModifier))) {
 
-                                       /* Primary-Tertiary-click applies change to all routes */
+                                       if (_mute_release) {
+                                               _mute_release->routes = _session->get_routes ();
+                                       }
 
-                                       _session.begin_reversible_command (_("mute change"));
-                                        Session::GlobalMuteStateCommand *cmd = new Session::GlobalMuteStateCommand(_session, this);
-                                       _session.set_all_mute (!_route->muted());
-                                        cmd->mark();
-                                       _session.add_command(cmd);
-                                       _session.commit_reversible_command ();
-                                       multiple_mute_change = true;
+                                       _session->set_mute (_session->get_routes(), !_route->muted());
 
                                } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
 
-                                       /* Primary-button1 applies change to the mix group.
+                                       /* Primary-button1 applies change to the mix group even if it is not active
                                           NOTE: Primary-button2 is MIDI learn.
                                        */
 
-                                       if (ev->button == 1) {
-                                               set_mix_group_mute (_route, !_route->muted());
+                                       if (ev->button == 1 && _route->route_group()) {
+                                               if (_mute_release) {
+                                                       _mute_release->routes = _session->get_routes ();
+                                               }
+                                                               
+                                               _session->set_mute (_session->get_routes(), !_route->muted(), Session::rt_cleanup, true);
                                        }
-                                       
+
                                } else {
 
                                        /* plain click applies change to this route */
-                                       if (wait_for_release) {
-                                               _route->set_mute (!_route->muted(), this);
-                                       } else {
-                                               reversibly_apply_route_boolean ("mute change", &Route::set_mute, !_route->muted(), this);
+                                       
+                                       boost::shared_ptr<RouteList> rl (new RouteList);
+                                       rl->push_back (_route);
+
+                                       if (_mute_release) {
+                                               _mute_release->routes = rl;
                                        }
+
+                                       _session->set_mute (rl, !_route->muted());
+
                                }
                        }
                }
@@ -282,21 +346,16 @@ RouteUI::mute_press(GdkEventButton* ev)
 }
 
 bool
-RouteUI::mute_release(GdkEventButton* ev)
-{
-       if (!ignore_toggle) {
-               if (wait_for_release){
-                       wait_for_release = false;
-                       if (multiple_mute_change) {
-                               multiple_mute_change = false;
-                               // undo the last op
-                               // because the press was the last undoable thing we did
-                               _session.undo (1U);
-                       } else {
-                               _route->set_mute (!_route->muted(), this);
-                       }
+RouteUI::mute_release (GdkEventButton*)
+{
+       if (!_i_am_the_modifier) {
+               if (_mute_release){
+                       _session->set_mute (_mute_release->routes, _mute_release->active, Session::rt_cleanup, true);
+                       delete _mute_release;
+                       _mute_release = 0;
                }
        }
+
        return true;
 }
 
@@ -308,102 +367,118 @@ RouteUI::solo_press(GdkEventButton* ev)
        if (ev->type == GDK_2BUTTON_PRESS || ev->type == GDK_3BUTTON_PRESS ) {
                return true;
        }
+       
        multiple_solo_change = false;
-       if (!ignore_toggle) {
 
+       if (!_i_am_the_modifier) {
+               
                if (Keyboard::is_context_menu_event (ev)) {
-
-                       if (solo_menu == 0) {
-                               build_solo_menu ();
-                       }
-
-                       solo_menu->popup (1, ev->time);
-
+                       
+                        if (!solo_isolated_led) {
+
+                                if (solo_menu == 0) {
+                                        build_solo_menu ();
+                                }
+                                
+                                solo_menu->popup (1, ev->time);
+                        }
+                       
                } else {
-
+                       
                        if (Keyboard::is_button2_event (ev)) {
-
+                               
                                // Primary-button2 click is the midi binding click
                                // button2-click is "momentary"
                                
-                               if (!Keyboard::modifier_state_equals (ev->state, Keyboard::ModifierMask (Keyboard::PrimaryModifier))) {
-                                       wait_for_release = true;
-                               } else {
-                                       return false;
-                               }
-                       }
+                                if (solo_button->on_button_press_event (ev)) {
+                                        return true;
+                                }
 
+                               _solo_release = new SoloMuteRelease (_route->self_soloed());
+                       }
+                       
                        if (ev->button == 1 || Keyboard::is_button2_event (ev)) {
-
+                               
                                if (Keyboard::modifier_state_equals (ev->state, Keyboard::ModifierMask (Keyboard::PrimaryModifier|Keyboard::TertiaryModifier))) {
-
+                                       
                                        /* Primary-Tertiary-click applies change to all routes */
-                                       bool was_not_latched = false;
-                                       if (!Config->get_solo_latched ()) {
-                                               was_not_latched = true;
-                                               /*
-                                                 XXX it makes no sense to solo all tracks if we're 
-                                                 not in latched mode, but doing nothing feels like a bug, 
-                                                 so do it anyway 
-                                               */
-                                               Config->set_solo_latched (true);
+
+                                       if (_solo_release) {
+                                               _solo_release->routes = _session->get_routes ();
                                        }
-                                       _session.begin_reversible_command (_("solo change"));
-                                        Session::GlobalSoloStateCommand *cmd = new Session::GlobalSoloStateCommand(_session, this);
-                                       _session.set_all_solo (!_route->soloed());
-                                        cmd->mark();
-                                       _session.add_command (cmd);
-                                       _session.commit_reversible_command ();
-                                       multiple_solo_change = true;
-                                       if (was_not_latched) {
-                                               Config->set_solo_latched (false);
+                                       
+                                       if (Config->get_solo_control_is_listen_control()) {
+                                               _session->set_listen (_session->get_routes(), !_route->listening(),  Session::rt_cleanup, true);
+                                       } else {
+                                               _session->set_solo (_session->get_routes(), !_route->self_soloed(),  Session::rt_cleanup, true);
                                        }
                                        
                                } else if (Keyboard::modifier_state_contains (ev->state, Keyboard::ModifierMask (Keyboard::PrimaryModifier|Keyboard::SecondaryModifier))) {
+                                       
+                                       // Primary-Secondary-click: exclusively solo this track
 
-                                       // Primary-Secondary-click: exclusively solo this track, not a toggle */
-
-                                       _session.begin_reversible_command (_("solo change"));
-                                        Session::GlobalSoloStateCommand *cmd = new Session::GlobalSoloStateCommand (_session, this);
-                                       _session.set_all_solo (false);
-                                       _route->set_solo (true, this);
-                                        cmd->mark();
-                                       _session.add_command(cmd);
-                                       _session.commit_reversible_command ();
+                                       if (_solo_release) {
+                                               _solo_release->exclusive = true;
 
-                               } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::TertiaryModifier)) {
+                                               boost::shared_ptr<RouteList> routes = _session->get_routes();
 
-                                       // shift-click: set this route to solo safe
-
-                                       if (Profile->get_sae() && ev->button == 1) {
-                                               // button 1 and shift-click: disables solo_latched for this click
-                                               if (!Config->get_solo_latched ()) {
-                                                       Config->set_solo_latched (true);
-                                                       reversibly_apply_route_boolean ("solo change", &Route::set_solo, !_route->soloed(), this);
-                                                       Config->set_solo_latched (false);
+                                               for (RouteList::iterator i = routes->begin(); i != routes->end(); ++i) {
+                                                       if ((*i)->soloed ()) {
+                                                               _solo_release->routes_on->push_back (*i);
+                                                       } else {
+                                                               _solo_release->routes_off->push_back (*i);
+                                                       }
                                                }
+                                       }
+                                       
+                                       if (Config->get_solo_control_is_listen_control()) {
+                                               /* ??? we need a just_one_listen() method */
                                        } else {
-                                               _route->set_solo_safe (!_route->solo_safe(), this);
-                                               wait_for_release = false;
+                                               _session->set_just_one_solo (_route, true);
                                        }
 
+                               } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::TertiaryModifier)) {
+                                       
+                                       // shift-click: toggle solo isolated status
+                                       
+                                       _route->set_solo_isolated (!_route->solo_isolated(), this);
+                                       delete _solo_release;
+                                       _solo_release = 0;
+                                       
                                } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
-
+                                       
                                        /* Primary-button1: solo mix group.
                                           NOTE: Primary-button2 is MIDI learn.
                                        */
+                                       
+                                       if (ev->button == 1 && _route->route_group()) {
 
-                                       if (ev->button == 1) {
-                                               set_mix_group_solo (_route, !_route->soloed());
+                                               if (_solo_release) {
+                                                       _solo_release->routes = _route->route_group()->route_list();
+                                               }
+                                       
+                                               if (Config->get_solo_control_is_listen_control()) {
+                                                       _session->set_listen (_route->route_group()->route_list(), !_route->listening(),  Session::rt_cleanup, true);
+                                               } else {
+                                                       _session->set_solo (_route->route_group()->route_list(), !_route->self_soloed(),  Session::rt_cleanup, true);
+                                               }
                                        }
-
+                                       
                                } else {
-
+                                       
                                        /* click: solo this route */
-                                       if (wait_for_release) {
-                                               _route->set_solo (!_route->soloed(), this);
+                                       
+                                       boost::shared_ptr<RouteList> rl (new RouteList);
+                                       rl->push_back (route());
+
+                                       if (_solo_release) {
+                                               _solo_release->routes = rl;
+                                       }
+
+                                       if (Config->get_solo_control_is_listen_control()) {
+                                               _session->set_listen (rl, !_route->listening());
                                        } else {
-                                               reversibly_apply_route_boolean ("solo change", &Route::set_solo, !_route->soloed(), this);
+                                               _session->set_solo (rl, !_route->self_soloed());
                                        }
                                }
                        }
@@ -414,21 +489,24 @@ RouteUI::solo_press(GdkEventButton* ev)
 }
 
 bool
-RouteUI::solo_release(GdkEventButton* ev)
-{
-       if (!ignore_toggle) {
-               if (wait_for_release) {
-                       wait_for_release = false;
-                       if (multiple_solo_change) {
-                               multiple_solo_change = false;
-                               // undo the last op
-                               // because the press was the last undoable thing we did
-                               _session.undo (1U);
+RouteUI::solo_release (GdkEventButton*)
+{
+       if (!_i_am_the_modifier) {
+               
+               if (_solo_release) {
+
+                       if (_solo_release->exclusive) {
+
                        } else {
-                               // we don't use "undo the last op"
-                               // here because its expensive for the GUI
-                               _route->set_solo (!_route->soloed(), this);
+                                if (Config->get_solo_control_is_listen_control()) {
+                                        _session->set_listen (_solo_release->routes, _solo_release->active, Session::rt_cleanup, true);
+                                } else {
+                                        _session->set_solo (_solo_release->routes, _solo_release->active, Session::rt_cleanup, true);
+                                }
                        }
+
+                       delete _solo_release;
+                       _solo_release = 0;
                }
        }
 
@@ -442,415 +520,722 @@ RouteUI::rec_enable_press(GdkEventButton* ev)
                return true;
        }
 
-       if (!_session.engine().connected()) {
+       if (!_session->engine().connected()) {
                MessageDialog msg (_("Not connected to JACK - cannot engage record"));
                msg.run ();
                return true;
        }
 
-       if (!ignore_toggle && is_track() && rec_enable_button) {
+        if (is_midi_track()) {
 
-               if (Keyboard::is_button2_event (ev) && Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
+                /* cannot rec-enable while step-editing */
 
-                       // do nothing on midi bind event
-                       return false;
+                if (midi_track()->step_editing()) {
+                        return true;
+                } 
+        }
 
-               } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::ModifierMask (Keyboard::PrimaryModifier|Keyboard::TertiaryModifier))) {
+       if (!_i_am_the_modifier && is_track() && rec_enable_button) {
 
-                       _session.begin_reversible_command (_("rec-enable change"));
-                        Session::GlobalRecordEnableStateCommand *cmd = new Session::GlobalRecordEnableStateCommand(_session, this);
+               if (Keyboard::is_button2_event (ev)) {
 
-                       if (rec_enable_button->get_active()) {
-                               _session.record_disenable_all ();
-                       } else {
-                               _session.record_enable_all ();
-                       }
+                       // do nothing on midi sigc::bind event
+                       return rec_enable_button->on_button_press_event (ev);
+
+               } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::ModifierMask (Keyboard::PrimaryModifier|Keyboard::TertiaryModifier))) {
 
-                        cmd->mark();
-                       _session.add_command(cmd);
-                       _session.commit_reversible_command ();
+                       _session->set_record_enabled (_session->get_routes(), !rec_enable_button->get_active());
 
                } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
 
-                       /* Primary-button1 applies change to the mix group.
+                       /* Primary-button1 applies change to the route group (even if it is not active)
                           NOTE: Primary-button2 is MIDI learn.
                        */
+                       if (ev->button == 1 && _route->route_group()) {
+                               _session->set_record_enabled (_route->route_group()->route_list(), !rec_enable_button->get_active(), Session::rt_cleanup, true);
+                       }
+
+               } else if (Keyboard::is_context_menu_event (ev)) {
 
-                       set_mix_group_rec_enable (_route, !_route->record_enabled());
+                       /* do this on release */
 
                } else {
 
-                       reversibly_apply_track_boolean ("rec-enable change", &Track::set_record_enable, !track()->record_enabled(), this);
+                       boost::shared_ptr<RouteList> rl (new RouteList);
+                       rl->push_back (route());
+                       _session->set_record_enabled (rl, !rec_enable_button->get_active());
                }
        }
 
        return true;
 }
 
+void
+RouteUI::build_record_menu ()
+{
+        if (record_menu) {
+                return;
+        }
+
+        /* no rec-button context menu for non-MIDI tracks 
+         */
+
+        if (is_midi_track()) {
+                record_menu = new Menu;
+                record_menu->set_name ("ArdourContextMenu");
+                
+                using namespace Menu_Helpers;
+                MenuList& items = record_menu->items();
+                
+                items.push_back (CheckMenuElem (_("Step Edit"), sigc::mem_fun (*this, &RouteUI::toggle_step_edit)));
+                step_edit_item = dynamic_cast<CheckMenuItem*> (&items.back());
+
+                if (_route->record_enabled()) {
+                        step_edit_item->set_sensitive (false);
+                }
+
+                step_edit_item->set_active (midi_track()->step_editing());
+        }
+}
+
+void
+RouteUI::toggle_step_edit ()
+{
+        if (!is_midi_track() || _route->record_enabled()) {
+                return;
+        }
+
+        midi_track()->set_step_editing (step_edit_item->get_active());
+}
+
+void
+RouteUI::step_edit_changed (bool yn)
+{
+        if (yn) {
+                if (rec_enable_button) {
+                        rec_enable_button->set_visual_state (3);
+                } 
+
+                start_step_editing ();
+
+                if (step_edit_item) {
+                        step_edit_item->set_active (true);
+                }
+
+        } else {
+
+                if (rec_enable_button) {
+                        rec_enable_button->set_visual_state (0);
+                } 
+
+                stop_step_editing ();
+
+                if (step_edit_item) {
+                        step_edit_item->set_active (false);
+                }
+        }
+}
+
 bool
 RouteUI::rec_enable_release (GdkEventButton* ev)
 {
+        if (Keyboard::is_context_menu_event (ev)) {
+                build_record_menu ();
+                if (record_menu) {
+                        record_menu->popup (1, ev->time);
+                }
+                return true;
+        }
+
        return true;
 }
 
 void
-RouteUI::solo_changed(void* src)
+RouteUI::build_sends_menu ()
 {
+       using namespace Menu_Helpers;
+
+       sends_menu = new Menu;
+       sends_menu->set_name ("ArdourContextMenu");
+       MenuList& items = sends_menu->items();
+
+       items.push_back (MenuElem(_("Assign all tracks (prefader)"), sigc::bind (sigc::mem_fun (*this, &RouteUI::create_sends), PreFader)));
+       items.push_back (MenuElem(_("Assign all tracks (postfader)"), sigc::bind (sigc::mem_fun (*this, &RouteUI::create_sends), PostFader)));
+       items.push_back (MenuElem(_("Assign selected tracks (prefader)"), sigc::bind (sigc::mem_fun (*this, &RouteUI::create_selected_sends), PreFader)));
+       items.push_back (MenuElem(_("Assign selected tracks (postfader)"), sigc::bind (sigc::mem_fun (*this, &RouteUI::create_selected_sends), PostFader)));
+       items.push_back (MenuElem(_("Copy track gains to sends"), sigc::mem_fun (*this, &RouteUI::set_sends_gain_from_track)));
+       items.push_back (MenuElem(_("Set sends gain to -inf"), sigc::mem_fun (*this, &RouteUI::set_sends_gain_to_zero)));
+       items.push_back (MenuElem(_("Set sends gain to 0dB"), sigc::mem_fun (*this, &RouteUI::set_sends_gain_to_unity)));
 
-       Gtkmm2ext::UI::instance()->call_slot (mem_fun (*this, &RouteUI::update_solo_display));
 }
 
 void
-RouteUI::update_solo_display ()
+RouteUI::create_sends (Placement p)
 {
-       bool x;
-       vector<Gdk::Color> fg_colors;
-       Gdk::Color c;
-       
-       if (solo_button->get_active() != (x = _route->soloed())){
-               ignore_toggle = true;
-               solo_button->set_active(x);
-               ignore_toggle = false;
-       } 
-       
-       if (_route->solo_safe()) {
-               solo_button->set_visual_state (2);
-       } else if (_route->soloed()) {
-               solo_button->set_visual_state (1);
-       } else {
-               solo_button->set_visual_state (0);
+       _session->globally_add_internal_sends (_route, p);
+}
+
+void
+RouteUI::create_selected_sends (Placement p)
+{
+       boost::shared_ptr<RouteList> rlist (new RouteList);
+       TrackSelection& selected_tracks (ARDOUR_UI::instance()->the_editor().get_selection().tracks);
+
+       for (TrackSelection::iterator i = selected_tracks.begin(); i != selected_tracks.end(); ++i) {
+               RouteTimeAxisView* rtv;
+               RouteUI* rui;
+               if ((rtv = dynamic_cast<RouteTimeAxisView*>(*i)) != 0) {
+                       if ((rui = dynamic_cast<RouteUI*>(rtv)) != 0) {
+                               if (boost::dynamic_pointer_cast<AudioTrack>(rui->route())) {
+                                       rlist->push_back (rui->route());
+                               }
+                       }
+               }
        }
+       
+       _session->add_internal_sends (_route, p, rlist);
 }
 
 void
-RouteUI::solo_changed_so_update_mute ()
+RouteUI::set_sends_gain_from_track ()
 {
-       Gtkmm2ext::UI::instance()->call_slot (mem_fun (*this, &RouteUI::update_mute_display));
+       _session->globally_set_send_gains_from_track (_route);
 }
 
 void
-RouteUI::mute_changed(void* src)
+RouteUI::set_sends_gain_to_zero ()
 {
-       Gtkmm2ext::UI::instance()->call_slot (mem_fun (*this, &RouteUI::update_mute_display));
+       _session->globally_set_send_gains_to_zero (_route);
 }
 
 void
-RouteUI::update_mute_display ()
+RouteUI::set_sends_gain_to_unity ()
 {
-       bool model = _route->muted();
-       bool view = mute_button->get_active();
-
-       /* first make sure the button's "depressed" visual
-          is correct.
-       */
+       _session->globally_set_send_gains_to_unity (_route);
+}
 
-       if (model != view) {
-               ignore_toggle = true;
-               mute_button->set_active (model);
-               ignore_toggle = false;
+bool
+RouteUI::show_sends_press(GdkEventButton* ev)
+{
+       if (ev->type == GDK_2BUTTON_PRESS || ev->type == GDK_3BUTTON_PRESS ) {
+               return true;
        }
 
-       /* now attend to visual state */
-       
-       if (Config->get_show_solo_mutes()) {
-               if (_route->muted()) {
-                       mute_button->set_visual_state (2);
-               } else if (!_route->soloed() && _route->solo_muted()) {
-                       
-                       mute_button->set_visual_state (1);
-               } else {
-                       mute_button->set_visual_state (0);
-               }
-       } else {
-               if (_route->muted()) {
-                       mute_button->set_visual_state (2);
+       if (!_i_am_the_modifier && !is_track() && show_sends_button) {
+
+               if (Keyboard::is_button2_event (ev) && Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
+
+                       // do nothing on midi sigc::bind event
+                       return false;
+
+               } else if (Keyboard::is_context_menu_event (ev)) {
+
+                       if (sends_menu == 0) {
+                               build_sends_menu ();
+                       }
+
+                       sends_menu->popup (0, ev->time);
+
                } else {
-                       mute_button->set_visual_state (0);
+
+                       /* change button state */
+
+                       show_sends_button->set_active (!show_sends_button->get_active());
+
+                       /* start blinking */
+
+                       if (show_sends_button->get_active()) {
+                               /* show sends to this bus */
+                               MixerStrip::SwitchIO (_route);
+                               send_blink_connection = ARDOUR_UI::instance()->Blink.connect (sigc::mem_fun(*this, &RouteUI::send_blink));
+                       } else {
+                               /* everybody back to normal */
+                               send_blink_connection.disconnect ();
+                               MixerStrip::SwitchIO (boost::shared_ptr<Route>());
+                       }
+
                }
        }
 
+       return true;
 }
 
-void
-RouteUI::route_rec_enable_changed ()
+bool
+RouteUI::show_sends_release (GdkEventButton*)
 {
-       Gtkmm2ext::UI::instance()->call_slot (mem_fun (*this, &RouteUI::update_rec_display));
+       return true;
 }
 
 void
-RouteUI::session_rec_enable_changed ()
+RouteUI::send_blink (bool onoff)
 {
-       Gtkmm2ext::UI::instance()->call_slot (mem_fun (*this, &RouteUI::update_rec_display));
+       if (!show_sends_button) {
+               return;
+       }
+
+       if (onoff) {
+               show_sends_button->set_state (STATE_ACTIVE);
+       } else {
+               show_sends_button->set_state (STATE_NORMAL);
+       }
 }
 
-void
-RouteUI::update_rec_display ()
+int
+RouteUI::solo_visual_state (boost::shared_ptr<Route> r)
 {
-       bool model = _route->record_enabled();
-       bool view = rec_enable_button->get_active();
+       if (r->is_master() || r->is_monitor()) {
+               return 0;
+       }
+       
+       if (Config->get_solo_control_is_listen_control()) {
 
-       /* first make sure the button's "depressed" visual
-          is correct.
-       */
+               if (r->listening()) {
+                       return 1;
+               } else {
+                       return 0;
+               }
 
-       if (model != view) {
-               ignore_toggle = true;
-               rec_enable_button->set_active (model);
-               ignore_toggle = false;
+       } 
+       
+       if (r->soloed()) {
+                if (!r->self_soloed()) {
+                        return 3;
+                } else {
+                        return 1;
+                }
+       } else {
+               return 0;
+       }
+}
+
+int
+RouteUI::solo_visual_state_with_isolate (boost::shared_ptr<Route> r)
+{
+       if (r->is_master() || r->is_monitor()) {
+               return 0;
        }
        
-       /* now make sure its color state is correct */
+       if (Config->get_solo_control_is_listen_control()) {
 
-       if (model) {
+               if (r->listening()) {
+                       return 1;
+               } else {
+                        return 0;
+               }
 
-               switch (_session.record_status ()) {
-               case Session::Recording:
-                       rec_enable_button->set_visual_state (1);
-                       break;
+       } 
+       
+       if (r->solo_isolated()) {
+               return 2;
+       } else if (r->soloed()) {
+                if (!r->self_soloed()) {
+                        return 3;
+                } else {
+                        return 1;
+                }
+       } else {
+               return 0;
+       }
+}
 
-               case Session::Disabled:
-               case Session::Enabled:
-                       rec_enable_button->set_visual_state (2);
-                       break;
+int
+RouteUI::solo_isolate_visual_state (boost::shared_ptr<Route> r)
+{
+       if (r->is_master() || r->is_monitor()) {
+               return 0;
+       }
+       
+       if (r->solo_isolated()) {
+               return 1;
+       } else {
+               return 0;
+       }
+}
 
+int
+RouteUI::solo_safe_visual_state (boost::shared_ptr<Route> r)
+{
+       if (r->is_master() || r->is_monitor()) {
+               return 0;
+       }
+       
+       if (r->solo_safe()) {
+               return 1;
+       } else {
+               return 0;
+       }
+}
+
+void
+RouteUI::update_solo_display ()
+{
+       bool x;
+
+       if (Config->get_solo_control_is_listen_control()) {
+
+               if (solo_button->get_active() != (x = _route->listening())) {
+                       ++_i_am_the_modifier;
+                       solo_button->set_active(x);
+                       --_i_am_the_modifier;
                }
 
        } else {
-               rec_enable_button->set_visual_state (0);
+
+               if (solo_button->get_active() != (x = _route->soloed())) {
+                       ++_i_am_the_modifier;
+                       solo_button->set_active (x);
+                       --_i_am_the_modifier;
+               }
+
+       }
+
+       bool yn = _route->solo_safe ();
+
+       if (solo_safe_check && solo_safe_check->get_active() != yn) {
+               solo_safe_check->set_active (yn);
        }
+
+       yn = _route->solo_isolated ();
+
+       if (solo_isolated_check && solo_isolated_check->get_active() != yn) {
+               solo_isolated_check->set_active (yn);
+       }
+
+        set_button_names ();
+
+        if (solo_isolated_led) {
+                solo_isolated_led->set_visual_state (_route->solo_isolated() ? 1 : 0);
+        }
+
+        if (solo_safe_led) {
+                solo_safe_led->set_visual_state (_route->solo_safe() ? 1 : 0);
+        }
+
+       solo_button->set_visual_state (solo_visual_state (_route));
+        
+        /* some changes to solo status can affect mute display, so catch up 
+         */
+
+        update_mute_display ();
 }
 
 void
-RouteUI::build_remote_control_menu ()
+RouteUI::solo_changed_so_update_mute ()
 {
-       remote_control_menu = new Menu;
-       refresh_remote_control_menu ();
+       update_mute_display ();
 }
 
 void
-RouteUI::refresh_remote_control_menu ()
+RouteUI::mute_changed(void* /*src*/)
 {
-       ENSURE_GUI_THREAD (mem_fun (*this, &RouteUI::refresh_remote_control_menu));
+       update_mute_display ();
+}
 
-       // only refresh the menu if it has been instantiated
+int
+RouteUI::mute_visual_state (Session* s, boost::shared_ptr<Route> r)
+{
+       if (r->is_master() || r->is_monitor()) {
+               return 0;
+       }
 
-       if (remote_control_menu == 0) {
-               return;
+       if (Config->get_show_solo_mutes()) {
+
+               if (r->muted ()) {
+                       /* full mute */
+                       return 2;
+               } else if (s->soloing() && !r->soloed() && !r->solo_isolated()) {
+                       return 1;
+               } else {
+                       /* no mute at all */
+                       return 0;
+               }
+
+       } else {
+
+               if (r->muted()) {
+                       /* full mute */
+                       return 2;
+               } else {
+                       /* no mute at all */
+                       return 0;
+               }
        }
 
-       using namespace Menu_Helpers;
+       return 0;
+}
 
-       RadioMenuItem::Group rc_group;
-       CheckMenuItem* rc_active;
-       uint32_t limit = _session.ntracks() + _session.nbusses();
-       char buf[32];
+void
+RouteUI::update_mute_display ()
+{
+        if (!_route) {
+                return;
+        }
 
-       MenuList& rc_items = remote_control_menu->items();
-       rc_items.clear ();
+       bool model = _route->muted();
+       bool view = mute_button->get_active();
 
-       /* note that this menu list starts at zero, not 1, because zero
-          is a valid, if useless, ID.
+       /* first make sure the button's "depressed" visual
+          is correct.
        */
 
-       limit += 4; /* leave some breathing room */
-       
-       rc_items.push_back (RadioMenuElem (rc_group, _("None")));
-       if (_route->remote_control_id() == 0) {
-               rc_active = dynamic_cast<CheckMenuItem*> (&rc_items.back());
-               rc_active->set_active ();
-       }
-               
-       for (uint32_t i = 1; i < limit; ++i) {
-               snprintf (buf, sizeof (buf), "%u", i);
-               rc_items.push_back (RadioMenuElem (rc_group, buf));
-               rc_active = dynamic_cast<RadioMenuItem*>(&rc_items.back());
-               if (_route->remote_control_id() == i) {
-                       rc_active = dynamic_cast<CheckMenuItem*> (&rc_items.back());
-                       rc_active->set_active ();
-               }
-               rc_active->signal_activate().connect (bind (mem_fun (*this, &RouteUI::set_remote_control_id), i, rc_active));
+       if (model != view) {
+               ++_i_am_the_modifier;
+               mute_button->set_active (model);
+               --_i_am_the_modifier;
        }
+
+       mute_button->set_visual_state (mute_visual_state (_session, _route));
+}
+
+void
+RouteUI::route_rec_enable_changed ()
+{
+        update_rec_display ();
+}
+
+void
+RouteUI::session_rec_enable_changed ()
+{
+        update_rec_display ();
 }
 
 void
-RouteUI::set_remote_control_id (uint32_t id, CheckMenuItem* item)
+RouteUI::update_rec_display ()
 {
-       /* this is called when the radio menu item is toggled, and so 
-          is actually invoked twice per menu selection. we only
-          care about the invocation for the item that was being
-          marked active.
+       if (!rec_enable_button || !_route) {
+               return;
+       }
+                       
+       bool model = _route->record_enabled();
+       bool view = rec_enable_button->get_active();
+
+       /* first make sure the button's "depressed" visual
+          is correct.
        */
 
-       if (item->get_active()) {
-               _route->set_remote_control_id (id);
+       if (model != view) {
+               ++_i_am_the_modifier;
+               rec_enable_button->set_active (model);
+               --_i_am_the_modifier;
+       }
+
+       /* now make sure its color state is correct */
+
+       if (model) {
+                switch (_session->record_status ()) {
+                case Session::Recording:
+                        rec_enable_button->set_visual_state (1);
+                        break;
+                        
+                case Session::Disabled:
+                case Session::Enabled:
+                        rec_enable_button->set_visual_state (2);
+                        break;
+                        
+                }
+
+                if (step_edit_item) {
+                        step_edit_item->set_sensitive (false);
+                }
+
+       } else {
+               rec_enable_button->set_visual_state (0);
+
+                if (step_edit_item) {
+                        step_edit_item->set_sensitive (true);
+                }
        }
+        
+
+       check_rec_enable_sensitivity ();
 }
 
 void
 RouteUI::build_solo_menu (void)
 {
        using namespace Menu_Helpers;
-       
+
        solo_menu = new Menu;
        solo_menu->set_name ("ArdourContextMenu");
        MenuList& items = solo_menu->items();
        CheckMenuItem* check;
 
-       check = new CheckMenuItem(_("Solo-safe"));
+       check = new CheckMenuItem(_("Solo Isolate"));
+       check->set_active (_route->solo_isolated());
+       check->signal_toggled().connect (sigc::bind (sigc::mem_fun (*this, &RouteUI::toggle_solo_isolated), check));
+       items.push_back (CheckMenuElem(*check));
+        solo_isolated_check = dynamic_cast<CheckMenuItem*>(&items.back());
+       check->show_all();
+
+       check = new CheckMenuItem(_("Solo Safe"));
        check->set_active (_route->solo_safe());
-       check->signal_toggled().connect (bind (mem_fun (*this, &RouteUI::toggle_solo_safe), check));
-       _route->solo_safe_changed.connect(bind (mem_fun (*this, &RouteUI::solo_safe_toggle), check));
+       check->signal_toggled().connect (sigc::bind (sigc::mem_fun (*this, &RouteUI::toggle_solo_safe), check));
        items.push_back (CheckMenuElem(*check));
+        solo_safe_check = dynamic_cast<CheckMenuItem*>(&items.back());
        check->show_all();
 
        //items.push_back (SeparatorElem());
-       // items.push_back (MenuElem (_("MIDI Bind"), mem_fun (*mute_button, &BindableToggleButton::midi_learn)));
-       
+       // items.push_back (MenuElem (_("MIDI Bind"), sigc::mem_fun (*mute_button, &BindableToggleButton::midi_learn)));
+
 }
 
 void
 RouteUI::build_mute_menu(void)
 {
        using namespace Menu_Helpers;
-       
+
        mute_menu = new Menu;
        mute_menu->set_name ("ArdourContextMenu");
-       MenuList& items = mute_menu->items();
-       CheckMenuItem* check;
-       
-       check = new CheckMenuItem(_("Pre Fader"));
-       init_mute_menu(PRE_FADER, check);
-       check->signal_toggled().connect(bind (mem_fun (*this, &RouteUI::toggle_mute_menu), PRE_FADER, check));
-       _route->pre_fader_changed.connect(bind (mem_fun (*this, &RouteUI::pre_fader_toggle), check));
-       items.push_back (CheckMenuElem(*check));
-       check->show_all();
 
-       check = new CheckMenuItem(_("Post Fader"));
-       init_mute_menu(POST_FADER, check);
-       check->signal_toggled().connect(bind (mem_fun (*this, &RouteUI::toggle_mute_menu), POST_FADER, check));
-       _route->post_fader_changed.connect(bind (mem_fun (*this, &RouteUI::post_fader_toggle), check));
-       items.push_back (CheckMenuElem(*check));
-       check->show_all();
-       
-       check = new CheckMenuItem(_("Control Outs"));
-       init_mute_menu(CONTROL_OUTS, check);
-       check->signal_toggled().connect(bind (mem_fun (*this, &RouteUI::toggle_mute_menu), CONTROL_OUTS, check));
-       _route->control_outs_changed.connect(bind (mem_fun (*this, &RouteUI::control_outs_toggle), check));
-       items.push_back (CheckMenuElem(*check));
-       check->show_all();
+       MenuList& items = mute_menu->items();
 
-       check = new CheckMenuItem(_("Main Outs"));
-       init_mute_menu(MAIN_OUTS, check);
-       check->signal_toggled().connect(bind (mem_fun (*this, &RouteUI::toggle_mute_menu), MAIN_OUTS, check));
-       _route->main_outs_changed.connect(bind (mem_fun (*this, &RouteUI::main_outs_toggle), check));
-       items.push_back (CheckMenuElem(*check));
-       check->show_all();
+       pre_fader_mute_check = manage (new CheckMenuItem(_("Pre Fader")));
+       init_mute_menu(MuteMaster::PreFader, pre_fader_mute_check);
+       pre_fader_mute_check->signal_toggled().connect(sigc::bind (sigc::mem_fun (*this, &RouteUI::toggle_mute_menu), MuteMaster::PreFader, pre_fader_mute_check));
+       items.push_back (CheckMenuElem(*pre_fader_mute_check));
+       pre_fader_mute_check->show_all();
+
+       post_fader_mute_check = manage (new CheckMenuItem(_("Post Fader")));
+       init_mute_menu(MuteMaster::PostFader, post_fader_mute_check);
+       post_fader_mute_check->signal_toggled().connect(sigc::bind (sigc::mem_fun (*this, &RouteUI::toggle_mute_menu), MuteMaster::PostFader, post_fader_mute_check));
+       items.push_back (CheckMenuElem(*post_fader_mute_check));
+       post_fader_mute_check->show_all();
+
+       listen_mute_check = manage (new CheckMenuItem(_("Control Outs")));
+       init_mute_menu(MuteMaster::Listen, listen_mute_check);
+       listen_mute_check->signal_toggled().connect(sigc::bind (sigc::mem_fun (*this, &RouteUI::toggle_mute_menu), MuteMaster::Listen, listen_mute_check));
+       items.push_back (CheckMenuElem(*listen_mute_check));
+       listen_mute_check->show_all();
+
+       main_mute_check = manage (new CheckMenuItem(_("Main Outs")));
+       init_mute_menu(MuteMaster::Main, main_mute_check);
+       main_mute_check->signal_toggled().connect(sigc::bind (sigc::mem_fun (*this, &RouteUI::toggle_mute_menu), MuteMaster::Main, main_mute_check));
+       items.push_back (CheckMenuElem(*main_mute_check));
+       main_mute_check->show_all();
 
        //items.push_back (SeparatorElem());
-       // items.push_back (MenuElem (_("MIDI Bind"), mem_fun (*mute_button, &BindableToggleButton::midi_learn)));
-}
+       // items.push_back (MenuElem (_("MIDI Bind"), sigc::mem_fun (*mute_button, &BindableToggleButton::midi_learn)));
 
-void
-RouteUI::init_mute_menu(mute_type type, CheckMenuItem* check)
-{
-       if (_route->get_mute_config (type)) {
-               check->set_active (true);
-       }
+       _route->mute_points_changed.connect (route_connections, invalidator (*this), boost::bind (&RouteUI::muting_change, this), gui_context());
 }
 
 void
-RouteUI::toggle_mute_menu(mute_type type, Gtk::CheckMenuItem* check)
+RouteUI::init_mute_menu(MuteMaster::MutePoint mp, CheckMenuItem* check)
 {
-       _route->set_mute_config(type, check->get_active(), this);
+       check->set_active (_route->mute_points() & mp);
 }
 
 void
-RouteUI::toggle_solo_safe (Gtk::CheckMenuItem* check)
+RouteUI::toggle_mute_menu(MuteMaster::MutePoint mp, Gtk::CheckMenuItem* check)
 {
-       _route->set_solo_safe (check->get_active(), this);
+       if (check->get_active()) {
+               _route->set_mute_points (MuteMaster::MutePoint (_route->mute_points() | mp));
+       } else {
+               _route->set_mute_points (MuteMaster::MutePoint (_route->mute_points() & ~mp));
+       }
 }
 
 void
-RouteUI::set_mix_group_solo(boost::shared_ptr<Route> route, bool yn)
+RouteUI::muting_change ()
 {
-       RouteGroup* mix_group;
+       ENSURE_GUI_THREAD (*this, &RouteUI::muting_change)
 
-       if((mix_group = route->mix_group()) != 0){
-               _session.begin_reversible_command (_("mix group solo  change"));
-                Session::GlobalSoloStateCommand *cmd = new Session::GlobalSoloStateCommand(_session, this);
-               mix_group->apply(&Route::set_solo, yn, this);
-                cmd->mark();
-               _session.add_command (cmd);
-               _session.commit_reversible_command ();
-       } else {
-               reversibly_apply_route_boolean ("solo change", &Route::set_solo, !route->soloed(), this);
+       bool yn;
+       MuteMaster::MutePoint current = _route->mute_points ();
+
+       yn = (current & MuteMaster::PreFader);
+
+       if (pre_fader_mute_check->get_active() != yn) {
+               pre_fader_mute_check->set_active (yn);
+       }
+
+       yn = (current & MuteMaster::PostFader);
+
+       if (post_fader_mute_check->get_active() != yn) {
+               post_fader_mute_check->set_active (yn);
+       }
+
+       yn = (current & MuteMaster::Listen);
+
+       if (listen_mute_check->get_active() != yn) {
+               listen_mute_check->set_active (yn);
+       }
+
+       yn = (current & MuteMaster::Main);
+
+       if (main_mute_check->get_active() != yn) {
+               main_mute_check->set_active (yn);
        }
 }
 
-void
-RouteUI::reversibly_apply_route_boolean (string name, void (Route::*func)(bool, void *), bool yn, void *arg)
+bool
+RouteUI::solo_isolate_button_release (GdkEventButton* ev)
 {
-       _session.begin_reversible_command (name);
-       XMLNode &before = _route->get_state();
-       bind(mem_fun(*_route, func), yn, arg)();
-       XMLNode &after = _route->get_state();
-       _session.add_command (new MementoCommand<Route>(*_route, &before, &after));
-       _session.commit_reversible_command ();
+        if (ev->type == GDK_2BUTTON_PRESS || ev->type == GDK_3BUTTON_PRESS) {
+                return true;
+        }
+
+        bool view = (solo_isolated_led->visual_state() != 0);
+        bool model = _route->solo_isolated();
+
+        /* called BEFORE the view has changed */
+
+        if (ev->button == 1) {
+                if (Keyboard::modifier_state_equals (ev->state, Keyboard::ModifierMask (Keyboard::PrimaryModifier|Keyboard::TertiaryModifier))) {
+
+                        if (model) {
+                                /* disable isolate for all routes */
+                                _session->set_solo_isolated (_session->get_routes(), false, Session::rt_cleanup, true);
+                        }
+
+                } else {
+                        if (model == view) {
+
+                                /* flip just this route */
+
+                                boost::shared_ptr<RouteList> rl (new RouteList);
+                                rl->push_back (_route);
+                                _session->set_solo_isolated (rl, !view, Session::rt_cleanup, true);
+                        }
+                }
+        }
+
+        return true;
 }
 
-void
-RouteUI::reversibly_apply_track_boolean (string name, void (Track::*func)(bool, void *), bool yn, void *arg)
+bool
+RouteUI::solo_safe_button_release (GdkEventButton*)
 {
-       _session.begin_reversible_command (name);
-       XMLNode &before = track()->get_state();
-       bind (mem_fun (*track(), func), yn, arg)();
-       XMLNode &after = track()->get_state();
-       _session.add_command (new MementoCommand<Track>(*track(), &before, &after));
-       _session.commit_reversible_command ();
+        _route->set_solo_safe (!(solo_safe_led->visual_state() > 0), this);
+        return true;
 }
 
 void
-RouteUI::set_mix_group_mute(boost::shared_ptr<Route> route, bool yn)
+RouteUI::toggle_solo_isolated (Gtk::CheckMenuItem* check)
 {
-       RouteGroup* mix_group;
+        bool view = check->get_active();
+        bool model = _route->solo_isolated();
 
-       if((mix_group = route->mix_group()) != 0){
-               _session.begin_reversible_command (_("mix group mute change"));
-                Session::GlobalMuteStateCommand *cmd = new Session::GlobalMuteStateCommand (_session, this);
-               mix_group->apply(&Route::set_mute, yn, this);
-                cmd->mark();
-               _session.add_command(cmd);
-               _session.commit_reversible_command ();
-       } else {
-               reversibly_apply_route_boolean ("mute change", &Route::set_mute, !route->muted(), this);
-       }
+        /* called AFTER the view has changed */
+
+        if (model != view) {
+                _route->set_solo_isolated (view, this);
+        }
 }
 
 void
-RouteUI::set_mix_group_rec_enable(boost::shared_ptr<Route> route, bool yn)
+RouteUI::toggle_solo_safe (Gtk::CheckMenuItem* check)
 {
-       RouteGroup* mix_group;
-
-       if((mix_group = route->mix_group()) != 0){
-               _session.begin_reversible_command (_("mix group rec-enable change"));
-                Session::GlobalRecordEnableStateCommand *cmd = new Session::GlobalRecordEnableStateCommand(_session, this);
-               mix_group->apply (&Route::set_record_enable, yn, this);
-                cmd->mark();
-               _session.add_command(cmd);
-               _session.commit_reversible_command ();
-       } else {
-               reversibly_apply_route_boolean ("rec-enable change", &Route::set_record_enable, !_route->record_enabled(), this);
-       }
+       _route->set_solo_safe (check->get_active(), this);
 }
 
-
 bool
 RouteUI::choose_color()
 {
        bool picked;
        Gdk::Color color;
 
-       color = Gtkmm2ext::UI::instance()->get_color (_("ardour: color selection"), picked, &_color);
+       color = Gtkmm2ext::UI::instance()->get_color (_("Color Selection"), picked, &_color);
 
        if (picked) {
                set_color (color);
@@ -863,9 +1248,9 @@ void
 RouteUI::set_color (const Gdk::Color & c)
 {
        char buf[64];
-       
+
        _color = c;
-       
+
        ensure_xml_node ();
        snprintf (buf, sizeof (buf), "%d:%d:%d", c.get_red(), c.get_green(), c.get_blue());
        xml_node->add_property ("color", buf);
@@ -886,20 +1271,27 @@ RouteUI::ensure_xml_node ()
 }
 
 XMLNode*
-RouteUI::get_automation_child_xml_node (Evoral::Parameter param)
+RouteUI::get_automation_child_xml_node (Evoral::Parameter param, int version)
 {
        ensure_xml_node ();
-       
+
        XMLNodeList kids = xml_node->children();
        XMLNodeConstIterator iter;
 
        const string sym = ARDOUR::EventTypeMap::instance().to_symbol(param);
 
        for (iter = kids.begin(); iter != kids.end(); ++iter) {
-               if ((*iter)->name() == AutomationTimeAxisView::state_node_name) {
-                       XMLProperty* type = (*iter)->property("automation-id");
-                       if (type && type->value() == sym)
+
+               if (version < 3000) {
+                       if ((*iter)->name() == sym) {
                                return *iter;
+                       }
+               } else {
+                       if ((*iter)->name() == AutomationTimeAxisView::state_node_name) {
+                               XMLProperty* type = (*iter)->property("automation-id");
+                               if (type && type->value() == sym)
+                                       return *iter;
+                       }
                }
        }
 
@@ -915,7 +1307,7 @@ int
 RouteUI::set_color_from_route ()
 {
        XMLProperty *prop;
-       
+
        RouteUI::ensure_xml_node ();
 
        if ((prop = xml_node->property ("color")) != 0) {
@@ -925,36 +1317,62 @@ RouteUI::set_color_from_route ()
                _color.set_green(g);
                _color.set_blue(b);
                return 0;
-       } 
+       }
        return 1;
 }
 
 void
 RouteUI::remove_this_route ()
 {
+        if ((route()->is_master() || route()->is_monitor()) &&
+            !Config->get_allow_special_bus_removal()) {
+                MessageDialog msg (_("That would be bad news ...."),
+                                   false,
+                                   Gtk::MESSAGE_INFO,
+                                   Gtk::BUTTONS_OK);
+                msg.set_secondary_text (string_compose (_(
+"Removing the master or monitor bus is such a bad idea\n\
+that %1 is not going to allow it.\n\
+\n\
+If you really want to do this sort of thing\n\
+edit your ardour.rc file to set the\n\
+\"allow-special-bus-removal\" option to be \"yes\""), PROGRAM_NAME));
+
+                msg.present ();
+                msg.run ();
+                return;
+        }
+
        vector<string> choices;
        string prompt;
 
        if (is_track()) {
-               prompt  = string_compose (_("Do you really want to remove track \"%1\" ?\n\nYou may also lose the playlist used by this track.\n(cannot be undone)"), _route->name());
+               prompt  = string_compose (_("Do you really want to remove track \"%1\" ?\n\nYou may also lose the playlist used by this track.\n\n(This action cannot be undone, and the session file will be overwritten)"), _route->name());
        } else {
-               prompt  = string_compose (_("Do you really want to remove bus \"%1\" ?\n(cannot be undone)"), _route->name());
+               prompt  = string_compose (_("Do you really want to remove bus \"%1\" ?\n\nYou may also lose the playlist used by this track.\n\n(This action cannot be undone, and the session file will be overwritten)"), _route->name());
        }
 
        choices.push_back (_("No, do nothing."));
        choices.push_back (_("Yes, remove it."));
 
-       Choice prompter (prompt, choices);
+       string title;
+       if (is_track()) {
+               title = _("Remove track");
+       } else {
+               title = _("Remove bus");
+       }
+
+       Choice prompter (title, prompt, choices);
 
        if (prompter.run () == 1) {
-               Glib::signal_idle().connect (bind (sigc::ptr_fun (&RouteUI::idle_remove_this_route), this));
+               Glib::signal_idle().connect (sigc::bind (sigc::ptr_fun (&RouteUI::idle_remove_this_route), this));
        }
 }
 
 gint
 RouteUI::idle_remove_this_route (RouteUI *rui)
 {
-       rui->_session.remove_route (rui->_route);
+       rui->_session->remove_route (rui->route());
        return false;
 }
 
@@ -963,32 +1381,36 @@ RouteUI::route_rename ()
 {
        ArdourPrompter name_prompter (true);
        string result;
-       name_prompter.set_prompt (_("New Name: "));
+       if (is_track()) {
+               name_prompter.set_title (_("Rename Track"));
+       } else {
+               name_prompter.set_title (_("Rename Bus"));
+       }
+       name_prompter.set_prompt (_("New name:"));
        name_prompter.set_initial_text (_route->name());
        name_prompter.add_button (_("Rename"), Gtk::RESPONSE_ACCEPT);
        name_prompter.set_response_sensitive (Gtk::RESPONSE_ACCEPT, false);
        name_prompter.show_all ();
 
        switch (name_prompter.run ()) {
-
        case Gtk::RESPONSE_ACCEPT:
-        name_prompter.get_result (result);
-        if (result.length()) {
+                name_prompter.get_result (result);
+                if (result.length()) {
                        _route->set_name (result);
-               }       
+               }
                break;
        }
 
        return;
-  
+
 }
 
 void
-RouteUI::name_changed ()
+RouteUI::property_changed (const PropertyChange& what_changed)
 {
-       ENSURE_GUI_THREAD(sigc::mem_fun(*this, &RouteUI::name_changed));
-
-       name_label.set_text (_route->name());
+       if (what_changed.contains (ARDOUR::Properties::name)) {
+               name_label.set_text (_route->name());
+       }
 }
 
 void
@@ -1007,35 +1429,10 @@ void
 RouteUI::route_active_changed ()
 {
        if (route_active_menu_item) {
-               Gtkmm2ext::UI::instance()->call_slot (bind (mem_fun (*route_active_menu_item, &CheckMenuItem::set_active), _route->active()));
-       }
-}
-
-void
-RouteUI::toggle_polarity ()
-{
-       if (polarity_menu_item) {
-
-               bool x;
-
-               ENSURE_GUI_THREAD(mem_fun (*this, &RouteUI::toggle_polarity));
-               
-               if ((x = polarity_menu_item->get_active()) != _route->phase_invert()) {
-                       _route->set_phase_invert (x, this);
-                       if (x) {
-                               name_label.set_text (X_("Ø ") + name_label.get_text());
-                       } else {
-                               name_label.set_text (_route->name());
-                       }
-               }
+               Gtkmm2ext::UI::instance()->call_slot (invalidator (*this), boost::bind (&CheckMenuItem::set_active, route_active_menu_item, _route->active()));
        }
 }
 
-void
-RouteUI::polarity_changed ()
-{
-       /* no signal for this yet */
-}
 
 void
 RouteUI::toggle_denormal_protection ()
@@ -1044,10 +1441,10 @@ RouteUI::toggle_denormal_protection ()
 
                bool x;
 
-               ENSURE_GUI_THREAD(mem_fun (*this, &RouteUI::toggle_denormal_protection));
-               
+               ENSURE_GUI_THREAD (*this, &RouteUI::toggle_denormal_protection)
+
                if ((x = denormal_menu_item->get_active()) != _route->denormal_protection()) {
-                       _route->set_denormal_protection (x, this);
+                       _route->set_denormal_protection (x);
                }
        }
 }
@@ -1055,73 +1452,21 @@ RouteUI::toggle_denormal_protection ()
 void
 RouteUI::denormal_protection_changed ()
 {
-       /* no signal for this yet */
-}
-
-
-void
-RouteUI::solo_safe_toggle(void* src, Gtk::CheckMenuItem* check)
-{
-       bool yn = _route->solo_safe ();
-
-       if (check->get_active() != yn) {
-               check->set_active (yn);
-       }
-}
-void
-RouteUI::pre_fader_toggle(void* src, Gtk::CheckMenuItem* check)
-{
-       ENSURE_GUI_THREAD(bind (mem_fun (*this, &RouteUI::pre_fader_toggle), src, check));
-       
-       bool yn = _route->get_mute_config(PRE_FADER);
-       if (check->get_active() != yn) {
-               check->set_active (yn);
-       }
-}
-
-void
-RouteUI::post_fader_toggle(void* src, Gtk::CheckMenuItem* check)
-{
-       ENSURE_GUI_THREAD(bind (mem_fun (*this, &RouteUI::post_fader_toggle), src, check));
-       
-       bool yn = _route->get_mute_config(POST_FADER);
-       if (check->get_active() != yn) {
-               check->set_active (yn);
-       }
-}
-
-void
-RouteUI::control_outs_toggle(void* src, Gtk::CheckMenuItem* check)
-{
-       ENSURE_GUI_THREAD(bind (mem_fun (*this, &RouteUI::control_outs_toggle), src, check));
-       
-       bool yn = _route->get_mute_config(CONTROL_OUTS);
-       if (check->get_active() != yn) {
-               check->set_active (yn);
-       }
-}
-
-void
-RouteUI::main_outs_toggle(void* src, Gtk::CheckMenuItem* check)
-{
-       ENSURE_GUI_THREAD(bind (mem_fun (*this, &RouteUI::main_outs_toggle), src, check));
-       
-       bool yn = _route->get_mute_config(MAIN_OUTS);
-       if (check->get_active() != yn) {
-               check->set_active (yn);
+       if (denormal_menu_item) {
+               denormal_menu_item->set_active (_route->denormal_protection());
        }
 }
 
 void
 RouteUI::disconnect_input ()
 {
-       _route->disconnect_inputs (this);
+       _route->input()->disconnect (this);
 }
 
 void
 RouteUI::disconnect_output ()
 {
-       _route->disconnect_outputs (this);
+       _route->output()->disconnect (this);
 }
 
 bool
@@ -1160,16 +1505,10 @@ RouteUI::midi_track() const
        return boost::dynamic_pointer_cast<MidiTrack>(_route);
 }
 
-boost::shared_ptr<Diskstream>
-RouteUI::get_diskstream () const
+bool
+RouteUI::has_audio_outputs () const
 {
-       boost::shared_ptr<Track> t;
-
-       if ((t = boost::dynamic_pointer_cast<Track>(_route)) != 0) {
-               return t->diskstream();
-       } else {
-               return boost::shared_ptr<Diskstream> ((Diskstream*) 0);
-       }
+       return (_route->n_outputs().n_audio() > 0);
 }
 
 string
@@ -1181,7 +1520,7 @@ RouteUI::name() const
 void
 RouteUI::map_frozen ()
 {
-       ENSURE_GUI_THREAD (mem_fun (*this, &RouteUI::map_frozen));
+       ENSURE_GUI_THREAD (*this, &RouteUI::map_frozen)
 
        AudioTrack* at = dynamic_cast<AudioTrack*>(_route.get());
 
@@ -1200,25 +1539,26 @@ RouteUI::map_frozen ()
 void
 RouteUI::adjust_latency ()
 {
-       LatencyDialog dialog (_route->name() + _("latency"), *(_route.get()), _session.frame_rate(), _session.engine().frames_per_cycle());
+       LatencyDialog dialog (_route->name() + _(" latency"), *(_route->output()), _session->frame_rate(), _session->engine().frames_per_cycle());
 }
 
 void
 RouteUI::save_as_template ()
 {
        sys::path path;
-       Glib::ustring safe_name;
+       std::string safe_name;
        string name;
-       
+
        path = ARDOUR::user_route_template_directory ();
-       
+
        if (g_mkdir_with_parents (path.to_string().c_str(), 0755)) {
                error << string_compose (_("Cannot create route template directory %1"), path.to_string()) << endmsg;
                return;
        }
-       
+
        Prompter p (true); // modal
-       
+
+       p.set_title (_("Save As Template"));
        p.set_prompt (_("Template name:"));
        switch (p.run()) {
        case RESPONSE_ACCEPT:
@@ -1226,14 +1566,209 @@ RouteUI::save_as_template ()
        default:
                return;
        }
-       
+
        p.hide ();
        p.get_result (name, true);
-       
+
        safe_name = legalize_for_path (name);
        safe_name += template_suffix;
-       
+
        path /= safe_name;
-       
+
        _route->save_as_template (path.to_string(), name);
 }
+
+void
+RouteUI::check_rec_enable_sensitivity ()
+{
+       if (_session->transport_rolling() && rec_enable_button->get_active() && Config->get_disable_disarm_during_roll()) {
+               rec_enable_button->set_sensitive (false);
+       } else {
+               rec_enable_button->set_sensitive (true);
+       }
+}
+
+void
+RouteUI::parameter_changed (string const & p)
+{
+       if (p == "disable-disarm-during-roll") {
+               check_rec_enable_sensitivity ();
+       } else if (p == "solo-control-is-listen-control") {
+               set_button_names ();
+       } else if (p == "listen-position") {
+               set_button_names ();
+       }
+}
+
+void
+RouteUI::step_gain_up ()
+{
+       _route->set_gain (dB_to_coefficient (accurate_coefficient_to_dB (_route->gain_control()->get_value()) + 0.1), this);
+}
+
+void
+RouteUI::page_gain_up ()
+{
+       _route->set_gain (dB_to_coefficient (accurate_coefficient_to_dB (_route->gain_control()->get_value()) + 0.5), this);
+}
+
+void
+RouteUI::step_gain_down ()
+{
+       _route->set_gain (dB_to_coefficient (accurate_coefficient_to_dB (_route->gain_control()->get_value()) - 0.1), this);
+}
+
+void
+RouteUI::page_gain_down ()
+{
+       _route->set_gain (dB_to_coefficient (accurate_coefficient_to_dB (_route->gain_control()->get_value()) - 0.5), this);
+}
+
+void
+RouteUI::open_remote_control_id_dialog ()
+{
+       ArdourDialog dialog (_("Remote Control ID"));
+
+       uint32_t const limit = _session->ntracks() + _session->nbusses () + 4;
+
+       HBox* hbox = manage (new HBox);
+       hbox->set_spacing (6);
+       hbox->pack_start (*manage (new Label (_("Remote control ID:"))));
+       SpinButton* spin = manage (new SpinButton);
+       spin->set_digits (0);
+       spin->set_increments (1, 10);
+       spin->set_range (0, limit);
+       spin->set_value (_route->remote_control_id());
+       hbox->pack_start (*spin);
+       dialog.get_vbox()->pack_start (*hbox);
+
+       dialog.add_button (Stock::CANCEL, RESPONSE_CANCEL);
+       dialog.add_button (Stock::APPLY, RESPONSE_ACCEPT);
+
+       dialog.show_all ();
+       int const r = dialog.run ();
+
+       if (r == RESPONSE_ACCEPT) {
+               _route->set_remote_control_id (spin->get_value_as_int ());
+       }
+}
+
+void
+RouteUI::setup_invert_buttons ()
+{
+       /* remove old invert buttons */
+       for (list<BindableToggleButton*>::iterator i = _invert_buttons.begin(); i != _invert_buttons.end(); ++i) {
+               _invert_button_box.remove (**i);
+       }
+
+       _invert_buttons.clear ();
+
+       if (!_route || !_route->input()) {
+               return;
+       }
+
+       uint32_t const N = _route->input()->n_ports().n_audio ();
+
+       uint32_t const to_add = (N <= _max_invert_buttons) ? N : 1;
+
+       for (uint32_t i = 0; i < to_add; ++i) {
+               BindableToggleButton* b = manage (new BindableToggleButton);
+               b->signal_toggled().connect (sigc::bind (sigc::mem_fun (*this, &RouteUI::invert_toggled), i, b));
+               b->signal_button_press_event().connect (sigc::mem_fun (*this, &RouteUI::invert_press));
+               
+               b->set_name (X_("MixerInvertButton"));
+               if (to_add == 1) {
+                       b->add (*manage (new Label (X_("Ø"))));
+               } else {
+                       b->add (*manage (new Label (string_compose (X_("Ø%1"), i + 1))));
+               }
+
+               if (N <= 4) {
+                       UI::instance()->set_tip (*b, string_compose (_("Left-click to invert (phase reverse) channel %1 of this track.  Right-click to show menu."), i + 1));
+               } else {
+                       UI::instance()->set_tip (*b, string_compose (_("Left-click to invert (phase reverse) all channels of this track.  Right-click to show menu."), i + 1));
+               }
+               
+               _invert_buttons.push_back (b);
+               _invert_button_box.pack_start (*b);
+       }
+       
+       _invert_button_box.show_all ();
+}
+
+void
+RouteUI::set_invert_button_state ()
+{
+       ++_i_am_the_modifier;
+       
+       uint32_t const N = _route->input()->n_ports().n_audio();
+       if (N > _max_invert_buttons) {
+               _invert_buttons.front()->set_active (_route->phase_invert().any());
+               --_i_am_the_modifier;
+               return;
+       }
+
+       int j = 0;
+       for (list<BindableToggleButton*>::iterator i = _invert_buttons.begin(); i != _invert_buttons.end(); ++i, ++j) {
+               (*i)->set_active (_route->phase_invert (j));
+       }
+
+       --_i_am_the_modifier;
+}
+
+void
+RouteUI::invert_toggled (uint32_t i, BindableToggleButton* b)
+{
+       if (_i_am_the_modifier) {
+               return;
+       }
+       
+       uint32_t const N = _route->input()->n_ports().n_audio();
+       if (N <= _max_invert_buttons) {
+               _route->set_phase_invert (i, b->get_active ());
+       } else {
+               boost::dynamic_bitset<> p (N);
+               if (b->get_active ()) {
+                       p.set ();
+               }
+               _route->set_phase_invert (p);
+       }
+}
+
+bool
+RouteUI::invert_press (GdkEventButton* ev)
+{
+       using namespace Menu_Helpers;
+
+       if (ev->button != 3) {
+               return true;
+       }
+
+       delete _invert_menu;
+       _invert_menu = new Menu;
+       _invert_menu->set_name ("ArdourContextMenu");
+       MenuList& items = _invert_menu->items ();
+
+       uint32_t const N = _route->input()->n_ports().n_audio();
+       for (uint32_t i = 0; i < N; ++i) {
+               items.push_back (CheckMenuElem (string_compose (X_("Ø%1"), i + 1), sigc::bind (sigc::mem_fun (*this, &RouteUI::invert_menu_toggled), i)));
+               CheckMenuItem* e = dynamic_cast<CheckMenuItem*> (&items.back ());
+               ++_i_am_the_modifier;
+               e->set_active (_route->phase_invert (i));
+               --_i_am_the_modifier;
+       }
+
+       _invert_menu->popup (0, ev->time);
+
+       return false;
+}
+
+void
+RouteUI::invert_menu_toggled (uint32_t c)
+{
+       if (_i_am_the_modifier) {
+               return;
+       }
+       
+       _route->set_phase_invert (c, !_route->phase_invert (c));
+}