monitor section: make sip/afl/pfl buttons work, add rude solo, mono function, rearrange
[ardour.git] / gtk2_ardour / route_ui.cc
index 9a849257a29503150e4078e8156514175dd6daed..befed977436c402e53f2ed9c0b0e1016cc3d7643 100644 (file)
@@ -29,7 +29,6 @@
 #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/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)
+RouteUI::RouteUI (ARDOUR::Session* sess)
        : AxisView(sess)
 {
        init ();
 }
 
-RouteUI::RouteUI (boost::shared_ptr<ARDOUR::Route> rt, ARDOUR::Session& sess)
+RouteUI::RouteUI (boost::shared_ptr<ARDOUR::Route> rt, ARDOUR::Session* sess)
        : AxisView(sess)
 {
        init ();
@@ -81,9 +79,8 @@ RouteUI::RouteUI (boost::shared_ptr<ARDOUR::Route> rt, ARDOUR::Session& sess)
 
 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;
@@ -103,7 +100,8 @@ RouteUI::init ()
        listen_mute_check = 0;
        main_mute_check = 0;
        ignore_toggle = false;
-       wait_for_release = false;
+       _solo_release = 0;
+       _mute_release = 0;
        route_active_menu_item = 0;
        polarity_menu_item = 0;
        denormal_menu_item = 0;
@@ -137,21 +135,28 @@ RouteUI::init ()
        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 (mem_fun(*this, &RouteUI::solo_changed_so_update_mute));
-       _session.TransportStateChange.connect (mem_fun (*this, &RouteUI::check_rec_enable_sensitivity));
+       _session->SoloChanged.connect (_session_connections, boost::bind (&RouteUI::solo_changed_so_update_mute, this), gui_context());
+       _session->TransportStateChange.connect (_session_connections, boost::bind (&RouteUI::check_rec_enable_sensitivity, this), gui_context());
+       _session->RecordStateChanged.connect (_session_connections, boost::bind (&RouteUI::session_rec_enable_changed, this), gui_context());
 
-       Config->ParameterChanged.connect (mem_fun (*this, &RouteUI::parameter_changed));
+       Config->ParameterChanged.connect (*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 ()
 {
-       //Remove route connections associated with us.
-       for (vector<sigc::connection>::iterator it = connections.begin(); it!=connections.end(); ++it) {
-           (*it).disconnect();
-       }
-
-       connections.clear ();
+       route_connections.drop_connections ();
 
        delete solo_menu;
        solo_menu = 0;
@@ -169,6 +174,14 @@ RouteUI::reset ()
        denormal_menu_item = 0;
 }
 
+void
+RouteUI::self_delete ()
+{
+       /* This may be called from a non-GUI thread. Keep it safe */
+
+       delete_when_idle (this);
+}
+
 void
 RouteUI::set_route (boost::shared_ptr<Route> rp)
 {
@@ -180,28 +193,24 @@ 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, boost::bind (&RouteUI::self_delete, this), gui_context());
        }
-
+       
        mute_button->set_controllable (_route->mute_control());
        solo_button->set_controllable (_route->solo_control());
 
-       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->listen_changed.connect (mem_fun(*this, &RouteUI::listen_changed)));
-       connections.push_back (_route->solo_isolated_changed.connect (mem_fun(*this, &RouteUI::solo_changed)));
+       _route->active_changed.connect (route_connections, boost::bind (&RouteUI::route_active_changed, this), gui_context());
+       _route->mute_changed.connect (route_connections, ui_bind (&RouteUI::mute_changed, this, _1), gui_context());
+       _route->solo_changed.connect (route_connections, ui_bind (&RouteUI::solo_changed, this, _1), gui_context());
+       _route->listen_changed.connect (route_connections, ui_bind (&RouteUI::listen_changed, this, _1), gui_context());
+       _route->solo_isolated_changed.connect (route_connections, ui_bind (&RouteUI::solo_changed, this, _1), gui_context());
+       _route->PropertyChanged.connect (route_connections, ui_bind (&RouteUI::property_changed, this, _1), gui_context());
 
-       if (_session.writable() && is_track()) {
+       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->diskstream()->RecordEnableChanged.connect (route_connections, boost::bind (&RouteUI::route_rec_enable_changed, this), gui_context());
 
                rec_enable_button->show();
                rec_enable_button->set_controllable (t->rec_enable_control());
@@ -229,12 +238,14 @@ RouteUI::set_route (boost::shared_ptr<Route> rp)
 }
 
 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 (Keyboard::is_context_menu_event (ev)) {
@@ -251,45 +262,50 @@ RouteUI::mute_press(GdkEventButton* 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 {
+                               if (Keyboard::modifier_state_equals (ev->state, Keyboard::ModifierMask (Keyboard::PrimaryModifier))) {
                                        return false;
                                }
+
+                               _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_route_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());
+
                                }
                        }
                }
@@ -300,21 +316,16 @@ RouteUI::mute_press(GdkEventButton* ev)
 }
 
 bool
-RouteUI::mute_release(GdkEventButton*)
+RouteUI::mute_release (GdkEventButton*)
 {
        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);
-                       }
+               if (_mute_release){
+                       _session->set_mute (_mute_release->routes, _mute_release->active, Session::rt_cleanup, true);
+                       delete _mute_release;
+                       _mute_release = 0;
                }
        }
+
        return true;
 }
 
@@ -326,102 +337,116 @@ RouteUI::solo_press(GdkEventButton* ev)
        if (ev->type == GDK_2BUTTON_PRESS || ev->type == GDK_3BUTTON_PRESS ) {
                return true;
        }
+       
+       multiple_solo_change = false;
 
-       if (Config->get_solo_control_is_listen_control()) {
-
-               _route->set_listen (!_route->listening(), this);
-
-       } else {
-
-               multiple_solo_change = false;
-               if (!ignore_toggle) {
-
-                       if (Keyboard::is_context_menu_event (ev)) {
-
-                               if (solo_menu == 0) {
-                                       build_solo_menu ();
+       if (!ignore_toggle) {
+               
+               if (Keyboard::is_context_menu_event (ev)) {
+                       
+                       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))) {
+                                       return false;
                                }
 
-                               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"
+                               _solo_release = new SoloMuteRelease (_route->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 */
 
-                                       if (!Keyboard::modifier_state_equals (ev->state, Keyboard::ModifierMask (Keyboard::PrimaryModifier))) {
-                                               wait_for_release = true;
+                                       if (_solo_release) {
+                                               _solo_release->routes = _session->get_routes ();
+                                       }
+                                       
+                                       if (Config->get_solo_control_is_listen_control()) {
+                                               _session->set_listen (_session->get_routes(), !_route->listening(),  Session::rt_cleanup, true);
                                        } else {
-                                               return false;
+                                               _session->set_solo (_session->get_routes(), !_route->soloed(),  Session::rt_cleanup, true);
                                        }
-                               }
-
-                               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);
-                                               }
-                                               _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);
+                                       
+                               } else if (Keyboard::modifier_state_contains (ev->state, Keyboard::ModifierMask (Keyboard::PrimaryModifier|Keyboard::SecondaryModifier))) {
+                                       
+                                       // Primary-Secondary-click: exclusively solo this track
+
+                                       if (_solo_release) {
+                                               _solo_release->exclusive = true;
+
+                                               boost::shared_ptr<RouteList> routes = _session->get_routes();
+
+                                               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 {
+                                               _session->set_just_one_solo (_route, true);
+                                       }
 
-                                       } else if (Keyboard::modifier_state_contains (ev->state, Keyboard::ModifierMask (Keyboard::PrimaryModifier|Keyboard::SecondaryModifier))) {
-
-                                               // 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 ();
-
-                                       } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::TertiaryModifier)) {
-
-                                               // shift-click: toggle solo isolated status
-
-                                               _route->set_solo_isolated (!_route->solo_isolated(), this);
-                                               wait_for_release = false;
-
-                                       } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
-
-                                               /* Primary-button1: solo mix group.
-                                                  NOTE: Primary-button2 is MIDI learn.
-                                               */
+                               } 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_route_group_solo (_route, !_route->soloed());
+                                               if (_solo_release) {
+                                                       _solo_release->routes = _route->route_group()->route_list();
                                                }
-
-                                       } else {
-
-                                               /* click: solo this route */
-                                               if (wait_for_release) {
-                                                       _route->set_solo (!_route->soloed(), this);
+                                       
+                                               if (Config->get_solo_control_is_listen_control()) {
+                                                       _session->set_listen (_route->route_group()->route_list(), !_route->listening(),  Session::rt_cleanup, true);
                                                } else {
-                                                       reversibly_apply_route_boolean ("solo change", &Route::set_solo, !_route->soloed(), this);
+                                                       _session->set_solo (_route->route_group()->route_list(), !_route->soloed(),  Session::rt_cleanup, true);
                                                }
                                        }
+                                       
+                               } else {
+                                       
+                                       /* click: solo this route */
+                                       
+                                       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 {
+                                               _session->set_solo (rl, !_route->soloed());
+                                       }
                                }
                        }
                }
@@ -431,73 +456,26 @@ RouteUI::solo_press(GdkEventButton* ev)
 }
 
 bool
-RouteUI::solo_release(GdkEventButton*)
+RouteUI::solo_release (GdkEventButton*)
 {
        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);
+               
+               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);
+                               _session->set_solo (_solo_release->routes, _solo_release->active, Session::rt_cleanup, true);
                        }
+
+                       delete _solo_release;
+                       _solo_release = 0;
                }
        }
 
        return true;
 }
 
-void
-RouteUI::post_rtop_cleanup (SessionEvent* ev)
-{
-       ENSURE_GUI_THREAD (bind (mem_fun (*this, &RouteUI::post_rtop_cleanup), ev));
-       delete ev;
-}
-
-void
-RouteUI::post_group_rtop_cleanup (SessionEvent* ev, RouteGroup* rg, RouteGroup::Property prop)
-{
-       ENSURE_GUI_THREAD (bind (mem_fun (*this, &RouteUI::post_group_rtop_cleanup), ev, rg, prop));
-       delete ev;
-       rg->set_property (prop, false);
-}
-
-void
-RouteUI::queue_route_group_op (RouteGroup::Property prop, void (Session::*session_method)(boost::shared_ptr<RouteList>, bool), bool yn)
-{
-       RouteGroup* rg = _route->route_group();
-       bool prop_was_active;
-
-       if (rg) {
-               prop_was_active = rg->active_property (prop);
-               rg->set_property (prop, true);
-       } else {
-               prop_was_active = false;
-       }
-
-       /* we will queue the op for just this route, but because its route group now has the relevant property marked active,
-          the operation will apply to the whole group (if there is a group)
-       */
-       
-       boost::shared_ptr<RouteList> rl (new RouteList);
-       rl->push_back (route());
-       
-       SessionEvent* ev = new SessionEvent (SessionEvent::RealTimeOperation, SessionEvent::Add, SessionEvent::Immediate, 0, 0.0);
-       ev->rt_slot =   bind (sigc::mem_fun (_session, session_method), rl, yn);
-       if (rg && !prop_was_active) {
-               ev->rt_return = bind (sigc::mem_fun (*this, &RouteUI::post_group_rtop_cleanup), rg, prop);
-       } else {
-               ev->rt_return = sigc::mem_fun (*this, &RouteUI::post_rtop_cleanup);
-       }
-       
-       _session.queue_event (ev);
-}
-
 bool
 RouteUI::rec_enable_press(GdkEventButton* ev)
 {
@@ -505,7 +483,7 @@ 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;
@@ -515,25 +493,20 @@ RouteUI::rec_enable_press(GdkEventButton* ev)
 
                if (Keyboard::is_button2_event (ev) && Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
 
-                       // do nothing on midi bind event
+                       // do nothing on midi sigc::bind event
                        return false;
 
                } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::ModifierMask (Keyboard::PrimaryModifier|Keyboard::TertiaryModifier))) {
 
-                       SessionEvent* ev = new SessionEvent (SessionEvent::RealTimeOperation, SessionEvent::Add, SessionEvent::Immediate, 0, 0.0);
-                       ev->rt_slot =   bind (sigc::mem_fun (_session, &Session::set_all_record_enable), _session.get_routes(), !rec_enable_button->get_active());
-                       ev->rt_return = sigc::mem_fun (*this, &RouteUI::post_rtop_cleanup);
-                       
-                       _session.queue_event (ev);
+                       _session->set_record_enable (_session->get_routes(), !rec_enable_button->get_active());
 
                } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
 
                        /* Primary-button1 applies change to the route group (even if it is not active)
                           NOTE: Primary-button2 is MIDI learn.
                        */
-                       
-                       if (ev->button == 1) {
-                               queue_route_group_op (RouteGroup::RecEnable, &Session::set_all_record_enable, !rec_enable_button->get_active());
+                       if (ev->button == 1 && _route->route_group()) {
+                               _session->set_record_enable (_route->route_group()->route_list(), !rec_enable_button->get_active(), Session::rt_cleanup, true);
                        }
 
                } else if (Keyboard::is_context_menu_event (ev)) {
@@ -541,14 +514,10 @@ RouteUI::rec_enable_press(GdkEventButton* ev)
                        /* do this on release */
 
                } else {
+
                        boost::shared_ptr<RouteList> rl (new RouteList);
                        rl->push_back (route());
-
-                       SessionEvent* ev = new SessionEvent (SessionEvent::RealTimeOperation, SessionEvent::Add, SessionEvent::Immediate, 0, 0.0);
-                       ev->rt_slot =   bind (sigc::mem_fun (_session, &Session::set_all_record_enable), rl, !rec_enable_button->get_active());
-                       ev->rt_return = sigc::mem_fun (*this, &RouteUI::post_rtop_cleanup);
-
-                       _session.queue_event (ev);
+                       _session->set_record_enable (rl, !rec_enable_button->get_active());
                }
        }
 
@@ -570,20 +539,20 @@ RouteUI::build_sends_menu ()
        sends_menu->set_name ("ArdourContextMenu");
        MenuList& items = sends_menu->items();
 
-       items.push_back (MenuElem(_("Assign all tracks (prefader)"), bind (mem_fun (*this, &RouteUI::create_sends), PreFader)));
-       items.push_back (MenuElem(_("Assign all tracks (postfader)"), bind (mem_fun (*this, &RouteUI::create_sends), PostFader)));
-       items.push_back (MenuElem(_("Assign selected tracks (prefader)"), bind (mem_fun (*this, &RouteUI::create_selected_sends), PreFader)));
-       items.push_back (MenuElem(_("Assign selected tracks (postfader)"), bind (mem_fun (*this, &RouteUI::create_selected_sends), PostFader)));
-       items.push_back (MenuElem(_("Copy track gains to sends"), mem_fun (*this, &RouteUI::set_sends_gain_from_track)));
-       items.push_back (MenuElem(_("Set sends gain to -inf"), mem_fun (*this, &RouteUI::set_sends_gain_to_zero)));
-       items.push_back (MenuElem(_("Set sends gain to 0dB"), mem_fun (*this, &RouteUI::set_sends_gain_to_unity)));
+       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)));
 
 }
 
 void
 RouteUI::create_sends (Placement p)
 {
-       _session.globally_add_internal_sends (_route, p);
+       _session->globally_add_internal_sends (_route, p);
 }
 
 void
@@ -604,25 +573,25 @@ RouteUI::create_selected_sends (Placement p)
                }
        }
        
-       _session.add_internal_sends (_route, p, rlist);
+       _session->add_internal_sends (_route, p, rlist);
 }
 
 void
 RouteUI::set_sends_gain_from_track ()
 {
-       _session.globally_set_send_gains_from_track (_route);
+       _session->globally_set_send_gains_from_track (_route);
 }
 
 void
 RouteUI::set_sends_gain_to_zero ()
 {
-       _session.globally_set_send_gains_to_zero (_route);
+       _session->globally_set_send_gains_to_zero (_route);
 }
 
 void
 RouteUI::set_sends_gain_to_unity ()
 {
-       _session.globally_set_send_gains_to_unity (_route);
+       _session->globally_set_send_gains_to_unity (_route);
 }
 
 bool
@@ -636,7 +605,7 @@ RouteUI::show_sends_press(GdkEventButton* ev)
 
                if (Keyboard::is_button2_event (ev) && Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
 
-                       // do nothing on midi bind event
+                       // do nothing on midi sigc::bind event
                        return false;
 
                } else if (Keyboard::is_context_menu_event (ev)) {
@@ -658,7 +627,7 @@ RouteUI::show_sends_press(GdkEventButton* ev)
                        if (show_sends_button->get_active()) {
                                /* show sends to this bus */
                                MixerStrip::SwitchIO (_route);
-                               send_blink_connection = ARDOUR_UI::instance()->Blink.connect (mem_fun(*this, &RouteUI::send_blink));
+                               send_blink_connection = ARDOUR_UI::instance()->Blink.connect (sigc::mem_fun(*this, &RouteUI::send_blink));
                        } else {
                                /* everybody back to normal */
                                send_blink_connection.disconnect ();
@@ -694,19 +663,23 @@ RouteUI::send_blink (bool onoff)
 void
 RouteUI::solo_changed(void* /*src*/)
 {
-       Gtkmm2ext::UI::instance()->call_slot (mem_fun (*this, &RouteUI::update_solo_display));
+       Gtkmm2ext::UI::instance()->call_slot (boost::bind (&RouteUI::update_solo_display, this));
 }
 
 
 void
 RouteUI::listen_changed(void* /*src*/)
 {
-       Gtkmm2ext::UI::instance()->call_slot (mem_fun (*this, &RouteUI::update_solo_display));
+       Gtkmm2ext::UI::instance()->call_slot (boost::bind (&RouteUI::update_solo_display, this));
 }
 
 int
 RouteUI::solo_visual_state (boost::shared_ptr<Route> r)
 {
+       if (r->is_master() || r->is_control()) {
+               return 0;
+       }
+       
        if (Config->get_solo_control_is_listen_control()) {
 
                if (r->listening()) {
@@ -715,25 +688,60 @@ RouteUI::solo_visual_state (boost::shared_ptr<Route> r)
                        return 0;
                }
 
+       } 
+       
+       if (r->soloed()) {
+               return 1;
        } else {
+               return 0;
+       }
+}
 
-               if (r->solo_isolated()) {
-                       return 2;
-               } else if (r->soloed()) {
+int
+RouteUI::solo_visual_state_with_isolate (boost::shared_ptr<Route> r)
+{
+       if (r->is_master() || r->is_control()) {
+               return 0;
+       }
+       
+       if (Config->get_solo_control_is_listen_control()) {
+
+               if (r->listening()) {
                        return 1;
                } else {
                        return 0;
                }
+
+       } 
+       
+       if (r->solo_isolated()) {
+               return 2;
+       } else if (r->soloed()) {
+               return 1;
+       } else {
+               return 0;
        }
+}
 
-       return 0;
+int
+RouteUI::solo_isolate_visual_state (boost::shared_ptr<Route> r)
+{
+       if (r->is_master() || r->is_control()) {
+               return 0;
+       }
+       
+       if (r->solo_isolated()) {
+                       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())) {
@@ -752,30 +760,34 @@ RouteUI::update_solo_display ()
 
        }
 
-       solo_button->set_visual_state (solo_visual_state (_route));
+       solo_button->set_visual_state (solo_visual_state_with_isolate (_route));
 }
 
 void
 RouteUI::solo_changed_so_update_mute ()
 {
-       Gtkmm2ext::UI::instance()->call_slot (mem_fun (*this, &RouteUI::update_mute_display));
+       update_mute_display ();
 }
 
 void
 RouteUI::mute_changed(void* /*src*/)
 {
-       Gtkmm2ext::UI::instance()->call_slot (mem_fun (*this, &RouteUI::update_mute_display));
+       update_mute_display ();
 }
 
 int
-RouteUI::mute_visual_state (Session& s, boost::shared_ptr<Route> r)
+RouteUI::mute_visual_state (Session* s, boost::shared_ptr<Route> r)
 {
+       if (r->is_master() || r->is_control()) {
+               return 0;
+       }
+       
        if (Config->get_show_solo_mutes()) {
                
                if (r->muted ()) {
                        /* full mute */
                        return 2;
-               } else if (s.soloing() && !r->soloed() && !r->solo_isolated()) {
+               } else if (s->soloing() && !r->soloed() && !r->solo_isolated()) {
                        /* mute-because-not-soloed */
                        return 1;
                } else {
@@ -800,6 +812,10 @@ RouteUI::mute_visual_state (Session& s, boost::shared_ptr<Route> r)
 void
 RouteUI::update_mute_display ()
 {
+        if (!_route) {
+                return;
+        }
+
        bool model = _route->muted();
        bool view = mute_button->get_active();
 
@@ -819,18 +835,22 @@ RouteUI::update_mute_display ()
 void
 RouteUI::route_rec_enable_changed ()
 {
-       Gtkmm2ext::UI::instance()->call_slot (mem_fun (*this, &RouteUI::update_rec_display));
+       Gtkmm2ext::UI::instance()->call_slot (boost::bind (&RouteUI::update_rec_display, this));
 }
 
 void
 RouteUI::session_rec_enable_changed ()
 {
-       Gtkmm2ext::UI::instance()->call_slot (mem_fun (*this, &RouteUI::update_rec_display));
+        update_rec_display ();
 }
 
 void
 RouteUI::update_rec_display ()
 {
+       if (!rec_enable_button || !_route) {
+               return;
+       }
+                       
        bool model = _route->record_enabled();
        bool view = rec_enable_button->get_active();
 
@@ -848,7 +868,7 @@ RouteUI::update_rec_display ()
 
        if (model) {
 
-               switch (_session.record_status ()) {
+               switch (_session->record_status ()) {
                case Session::Recording:
                        rec_enable_button->set_visual_state (1);
                        break;
@@ -879,20 +899,20 @@ RouteUI::build_solo_menu (void)
 
        check = new CheckMenuItem(_("Solo Isolate"));
        check->set_active (_route->solo_isolated());
-       check->signal_toggled().connect (bind (mem_fun (*this, &RouteUI::toggle_solo_isolated), check));
-       _route->solo_isolated_changed.connect(bind (mem_fun (*this, &RouteUI::solo_isolated_toggle), check));
+       check->signal_toggled().connect (sigc::bind (sigc::mem_fun (*this, &RouteUI::toggle_solo_isolated), check));
+       _route->solo_isolated_changed.connect (route_connections, ui_bind (&RouteUI::solo_isolated_toggle, this, _1, check), gui_context());
        items.push_back (CheckMenuElem(*check));
        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));
+       _route->solo_safe_changed.connect (route_connections, ui_bind (&RouteUI::solo_safe_toggle, this, _1, check), gui_context());
        items.push_back (CheckMenuElem(*check));
        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)));
 
 }
 
@@ -908,32 +928,32 @@ RouteUI::build_mute_menu(void)
 
        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(bind (mem_fun (*this, &RouteUI::toggle_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(bind (mem_fun (*this, &RouteUI::toggle_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(bind (mem_fun (*this, &RouteUI::toggle_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(bind (mem_fun (*this, &RouteUI::toggle_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)));
 
-       _route->mute_points_changed.connect (mem_fun (*this, &RouteUI::muting_change));
+       _route->mute_points_changed.connect (route_connections, boost::bind (&RouteUI::muting_change, this), gui_context());
 }
 
 void
@@ -955,7 +975,7 @@ RouteUI::toggle_mute_menu(MuteMaster::MutePoint mp, Gtk::CheckMenuItem* check)
 void
 RouteUI::muting_change ()
 {
-       ENSURE_GUI_THREAD(mem_fun (*this, &RouteUI::muting_change));
+       ENSURE_GUI_THREAD (*this, &RouteUI::muting_change)
 
        bool yn;
        MuteMaster::MutePoint current = _route->mute_points ();
@@ -997,80 +1017,6 @@ RouteUI::toggle_solo_safe (Gtk::CheckMenuItem* check)
        _route->set_solo_safe (check->get_active(), this);
 }
 
-void
-RouteUI::set_route_group_solo(boost::shared_ptr<Route> route, bool yn)
-{
-       RouteGroup* route_group;
-
-       if((route_group = route->route_group()) != 0){
-               _session.begin_reversible_command (_("mix group solo  change"));
-                Session::GlobalSoloStateCommand *cmd = new Session::GlobalSoloStateCommand(_session, this);
-               route_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);
-       }
-}
-
-void
-RouteUI::reversibly_apply_route_boolean (string name, void (Route::*func)(bool, void *), bool yn, void *arg)
-{
-       _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 ();
-}
-
-void
-RouteUI::reversibly_apply_track_boolean (string name, void (Track::*func)(bool, void *), bool yn, void *arg)
-{
-       _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 ();
-}
-
-void
-RouteUI::set_route_group_mute(boost::shared_ptr<Route> route, bool yn)
-{
-       RouteGroup* route_group;
-
-       if((route_group = route->route_group()) != 0){
-               _session.begin_reversible_command (_("mix group mute change"));
-                Session::GlobalMuteStateCommand *cmd = new Session::GlobalMuteStateCommand (_session, this);
-               route_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);
-       }
-}
-
-void
-RouteUI::set_route_group_rec_enable(boost::shared_ptr<Route> route, bool yn)
-{
-       RouteGroup* route_group;
-
-       if((route_group = route->route_group()) != 0){
-               _session.begin_reversible_command (_("mix group rec-enable change"));
-                Session::GlobalRecordEnableStateCommand *cmd = new Session::GlobalRecordEnableStateCommand(_session, this);
-               route_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);
-       }
-}
-
-
 bool
 RouteUI::choose_color()
 {
@@ -1163,25 +1109,32 @@ RouteUI::remove_this_route ()
        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(this cannot be undone)"), _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(this cannot be undone)"), _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;
 }
 
@@ -1211,11 +1164,11 @@ RouteUI::route_rename ()
 }
 
 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
@@ -1234,7 +1187,7 @@ 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()));
+               Gtkmm2ext::UI::instance()->call_slot (boost::bind (&CheckMenuItem::set_active, route_active_menu_item, _route->active()));
        }
 }
 
@@ -1245,7 +1198,7 @@ RouteUI::toggle_polarity ()
 
                bool x;
 
-               ENSURE_GUI_THREAD(mem_fun (*this, &RouteUI::toggle_polarity));
+               ENSURE_GUI_THREAD (*this, &RouteUI::toggle_polarity)
 
                if ((x = polarity_menu_item->get_active()) != _route->phase_invert()) {
                        _route->set_phase_invert (x);
@@ -1275,7 +1228,7 @@ 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);
@@ -1381,7 +1334,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());
 
@@ -1400,7 +1353,7 @@ RouteUI::map_frozen ()
 void
 RouteUI::adjust_latency ()
 {
-       LatencyDialog dialog (_route->name() + _(" latency"), *(_route->output()), _session.frame_rate(), _session.engine().frames_per_cycle());
+       LatencyDialog dialog (_route->name() + _(" latency"), *(_route->output()), _session->frame_rate(), _session->engine().frames_per_cycle());
 }
 
 void
@@ -1441,7 +1394,7 @@ RouteUI::save_as_template ()
 void
 RouteUI::check_rec_enable_sensitivity ()
 {
-       if (_session.transport_rolling() && rec_enable_button->get_active() && Config->get_disable_disarm_during_roll()) {
+       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);
@@ -1451,8 +1404,6 @@ RouteUI::check_rec_enable_sensitivity ()
 void
 RouteUI::parameter_changed (string const & p)
 {
-       ENSURE_GUI_THREAD (bind (mem_fun (*this, &RouteUI::parameter_changed), p));
-
        if (p == "disable-disarm-during-roll") {
                check_rec_enable_sensitivity ();
        } else if (p == "solo-control-is-listen-control") {
@@ -1491,7 +1442,7 @@ RouteUI::open_remote_control_id_dialog ()
 {
        ArdourDialog dialog (_("Remote Control ID"));
 
-       uint32_t const limit = _session.ntracks() + _session.nbusses () + 4;
+       uint32_t const limit = _session->ntracks() + _session->nbusses () + 4;
 
        HBox* hbox = manage (new HBox);
        hbox->set_spacing (6);