make that status-bar error change actually compile
[ardour.git] / gtk2_ardour / route_ui.cc
index c122f666ebb79d58a75bba8dce235f97f051cf85..73a9d59540ce70f0589476b6cc6468ce1adfb5c4 100644 (file)
@@ -15,7 +15,6 @@
     along with this program; if not, write to the Free Software
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
-    $Id$
 */
 
 #include <gtkmm2ext/gtk_ui.h>
@@ -23,6 +22,8 @@
 #include <gtkmm2ext/choice.h>
 #include <gtkmm2ext/doi.h>
 #include <gtkmm2ext/bindable_button.h>
+#include <gtkmm2ext/gtk_ui.h>
+#include <gtkmm2ext/prompter.h>
 
 #include <ardour/route_group.h>
 #include <pbd/memento_command.h>
@@ -40,6 +41,8 @@
 #include <ardour/audioengine.h>
 #include <ardour/audio_track.h>
 #include <ardour/audio_diskstream.h>
+#include <ardour/profile.h>
+#include <ardour/utils.h>
 
 #include "i18n.h"
 using namespace sigc;
@@ -48,14 +51,26 @@ using namespace Gtkmm2ext;
 using namespace ARDOUR;
 using namespace PBD;
 
-RouteUI::RouteUI (boost::shared_ptr<ARDOUR::Route> rt, ARDOUR::Session& sess, const char* m_name,
-                 const char* s_name, const char* r_name)
-       : AxisView(sess),
-         _route(rt),
-         mute_button(0),
-         solo_button(0),
-         rec_enable_button(0)
+RouteUI::RouteUI (ARDOUR::Session& sess, const char* mute_name, const char* solo_name, const char* rec_name)
+       : 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)
+       : AxisView(sess)
+{
+       init ();
+       set_button_names (mute_name, solo_name, rec_name);
+       set_route (rt);
+}
+
+void
+RouteUI::init ()
 {
+       self_destruct = true;
        xml_node = 0;
        mute_menu = 0;
        solo_menu = 0;
@@ -64,79 +79,112 @@ RouteUI::RouteUI (boost::shared_ptr<ARDOUR::Route> rt, ARDOUR::Session& sess, co
        wait_for_release = false;
        route_active_menu_item = 0;
        was_solo_safe = false;
+       polarity_menu_item = 0;
+       denormal_menu_item = 0;
+       multiple_mute_change = false;
+       multiple_solo_change = false;
 
-       if (set_color_from_route()) {
-               set_color (unique_random_color());
+       mute_button = manage (new BindableToggleButton (0, ""));
+       mute_button->set_self_managed (true);
+       mute_button->set_name ("MuteButton");
+       UI::instance()->set_tip (mute_button, _("Mute this track"), "");
+
+       solo_button = manage (new BindableToggleButton (0, ""));
+       solo_button->set_self_managed (true);
+       solo_button->set_name ("SoloButton");
+       UI::instance()->set_tip (solo_button, _("Mute other (non-soloed) tracks"), "");
+
+       rec_enable_button = manage (new BindableToggleButton (0, ""));
+       rec_enable_button->set_name ("RecordEnableButton");
+       rec_enable_button->set_self_managed (true);
+       UI::instance()->set_tip (rec_enable_button, _("Enable recording on this track"), "");
+
+       _session.SoloChanged.connect (mem_fun(*this, &RouteUI::solo_changed_so_update_mute));
+}
+
+void
+RouteUI::reset ()
+{
+       connections.clear ();
+
+       if (solo_menu) {
+               delete solo_menu;
+               solo_menu = 0;
        }
 
-       new PairedShiva<Route,RouteUI> (*_route, *this);
+       if (mute_menu) {
+               delete mute_menu;
+               mute_menu = 0;
+       }
+       
+       if (xml_node) {
+               /* do not delete the node - its owned by the route */
+               xml_node = 0;
+       }
 
-       _route->active_changed.connect (mem_fun (*this, &RouteUI::route_active_changed));
+       route_active_menu_item = 0;
+       polarity_menu_item = 0;
+       denormal_menu_item = 0;
+}
 
-        mute_button = manage (new BindableToggleButton (_route->mute_control(), m_name ));
-       mute_button->set_self_managed (true);
+void
+RouteUI::set_button_names (const char* mute, const char* solo, const char* rec)
+{
+       m_name = mute;
+       s_name = solo;
+       r_name = rec;
+}
 
-        solo_button = manage (new BindableToggleButton (_route->solo_control(), s_name ));
+void
+RouteUI::set_route (boost::shared_ptr<Route> rp)
+{
+       reset ();
 
-       mute_button->set_name ("MuteButton");
-       solo_button->set_name ("SoloButton");
+       _route = rp;
 
-       vector<Gdk::Color> colors;
-       Gdk::Color c;
+       if (set_color_from_route()) {
+               set_color (unique_random_color());
+       }
 
-       ::set_color(c, rgba_from_style (X_("MuteButton"), 0x7f, 0xff, 0x7f, 0, "bg", Gtk::STATE_SELECTED, false ));
-       colors.push_back (c);
-       ::set_color(c, rgba_from_style (X_("MuteButton"), 0x7f, 0xff, 0x7f, 0, "bg", Gtk::STATE_ACTIVE, false ));
-       colors.push_back (c);
-       mute_button->set_colors (colors);
+       /* 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);
+       }
 
-       colors.clear ();
+       mute_button->set_controllable (&_route->mute_control());
+       mute_button->set_label (m_name);
        
-       /* mute+solo buttons get 2 color states, so add one here to supplement the existing one */
-       ::set_color(c, rgba_from_style (X_("SoloButton"), 0x7f, 0xff, 0x7f, 0, "bg", Gtk::STATE_ACTIVE, false ));
-       colors.push_back (c);
-       solo_button->set_colors (colors);
+       solo_button->set_controllable (&_route->solo_control());
+       solo_button->set_label (s_name);
 
-       _route->mute_changed.connect (mem_fun(*this, &RouteUI::mute_changed));
-       _route->solo_changed.connect (mem_fun(*this, &RouteUI::solo_changed));
-       _route->solo_safe_changed.connect (mem_fun(*this, &RouteUI::solo_changed));
+       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));
-       
        update_solo_display ();
        update_mute_display ();
 
-       if (is_track()) {
+       if (_session.writable() && is_track()) {
                boost::shared_ptr<Track> t = boost::dynamic_pointer_cast<Track>(_route);
 
-               t->diskstream()->RecordEnableChanged.connect (mem_fun (*this, &RouteUI::route_rec_enable_changed));
-
-               _session.RecordStateChanged.connect (mem_fun (*this, &RouteUI::session_rec_enable_changed));
+               connections.push_back (t->diskstream()->RecordEnableChanged.connect (mem_fun (*this, &RouteUI::route_rec_enable_changed)));
 
-               rec_enable_button = manage (new BindableToggleButton (t->rec_enable_control(), r_name ));
+               connections.push_back (_session.RecordStateChanged.connect (mem_fun (*this, &RouteUI::session_rec_enable_changed)));
 
-               /* we manage colors for the rec button, since it has 3 (disabled,enabled,recording), 
-                  not just 2 (active&inactive)
-               */
+               rec_enable_button->set_controllable (&t->rec_enable_control());
+               rec_enable_button->set_label (r_name);
 
-               rec_enable_button->set_self_managed (true);
-
-               colors.clear ();
-
-               /* record button has 3 color states, so we set 2 extra here */
-               ::set_color(c, rgba_from_style (X_("RecordEnableButton"), 0xff, 0, 0, 0, "bg", Gtk::STATE_SELECTED, false ));
-               colors.push_back (c);
-               
-               ::set_color(c, rgba_from_style (X_("RecordEnableButton"), 0xff, 0, 0, 0, "bg", Gtk::STATE_ACTIVE, false ));
-               colors.push_back (c);
-               
-               rec_enable_button->set_colors (colors);
-               
                update_rec_display ();
        } 
        
+       connections.push_back (_route->RemoteControlIDChanged.connect (mem_fun(*this, &RouteUI::refresh_remote_control_menu)));
+
        /* map the current state */
 
        map_frozen ();
@@ -144,13 +192,33 @@ RouteUI::RouteUI (boost::shared_ptr<ARDOUR::Route> rt, ARDOUR::Session& sess, co
 
 RouteUI::~RouteUI()
 {
-       GoingAway (); /* EMIT SIGNAL */
-       delete mute_menu;
+       /* derived classes should emit GoingAway so that they receive the signal
+          when the object is still a legal derived instance.
+        */
+
+       if (solo_menu) {
+               delete solo_menu;
+       }
+
+       if (mute_menu) {
+               delete mute_menu;
+       }
+       
+       /* Note: the remote control menu is constructed
+          by derived classes (e.g. MixerStrip or RouteTimeAxis) and
+          is always attached to a context menu. It then becomes
+          owned by that menu, and will deleted along with it. We
+          do not need to take care of it here.
+       */
 }
 
 bool
 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)) {
@@ -163,22 +231,21 @@ RouteUI::mute_press(GdkEventButton* ev)
 
                } else {
 
-                       if (ev->button == 2) {
-                               // ctrl-button2 click is the midi binding click
-                               // button2-click is "momentary"
+                       if (Keyboard::is_button2_event (ev)) {
                                
-                               if (!Keyboard::modifier_state_equals (ev->state, Keyboard::ModifierMask (Keyboard::Control))) {
-                                       wait_for_release = true;
+                               if (mute_button->on_button_press_event (ev)) {
+                                       return true;
                                } else {
-                                       return false;
-                               }
+                                       // button2-click is "momentary"
+                                       wait_for_release = true;
+                               } 
                        }
 
-                       if (ev->button == 1 || ev->button == 2) {
+                       if (ev->button == 1 || Keyboard::is_button2_event (ev)) {
 
-                               if (Keyboard::modifier_state_equals (ev->state, Keyboard::ModifierMask (Keyboard::Control|Keyboard::Shift))) {
+                               if (Keyboard::modifier_state_equals (ev->state, Keyboard::ModifierMask (Keyboard::PrimaryModifier|Keyboard::TertiaryModifier))) {
 
-                                       /* ctrl-shift-click applies change to all routes */
+                                       /* Primary-Tertiary-click applies change to all routes */
 
                                        _session.begin_reversible_command (_("mute change"));
                                         Session::GlobalMuteStateCommand *cmd = new Session::GlobalMuteStateCommand(_session, this);
@@ -186,11 +253,12 @@ RouteUI::mute_press(GdkEventButton* ev)
                                         cmd->mark();
                                        _session.add_command(cmd);
                                        _session.commit_reversible_command ();
+                                       multiple_mute_change = true;
 
-                               } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::Control)) {
+                               } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
 
-                                       /* ctrl-click applies change to the mix group.
-                                          ctrl-button2 is MIDI learn.
+                                       /* Primary-button1 applies change to the mix group.
+                                          NOTE: Primary-button2 is MIDI learn.
                                        */
 
                                        if (ev->button == 1) {
@@ -200,8 +268,11 @@ RouteUI::mute_press(GdkEventButton* ev)
                                } else {
 
                                        /* plain click applies change to this route */
-
-                                       reversibly_apply_route_boolean ("mute change", &Route::set_mute, !_route->muted(), this);
+                                       if (wait_for_release) {
+                                               _route->set_mute (!_route->muted(), this);
+                                       } else {
+                                               reversibly_apply_route_boolean ("mute change", &Route::set_mute, !_route->muted(), this);
+                                       }
                                }
                        }
                }
@@ -217,9 +288,14 @@ RouteUI::mute_release(GdkEventButton* ev)
        if (!ignore_toggle) {
                if (wait_for_release){
                        wait_for_release = false;
-                       // undo the last op
-                       // because the press was the last undoable thing we did
-                       _session.undo (1U);
+                       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);
+                       }
                }
        }
        return true;
@@ -228,10 +304,16 @@ RouteUI::mute_release(GdkEventButton* ev)
 bool
 RouteUI::solo_press(GdkEventButton* ev)
 {
+       /* ignore double/triple clicks */
+
+       if (ev->type == GDK_2BUTTON_PRESS || ev->type == GDK_3BUTTON_PRESS ) {
+               return true;
+       }
+       multiple_solo_change = false;
        if (!ignore_toggle) {
 
                if (Keyboard::is_context_menu_event (ev)) {
-                       
+
                        if (solo_menu == 0) {
                                build_solo_menu ();
                        }
@@ -240,34 +322,45 @@ RouteUI::solo_press(GdkEventButton* ev)
 
                } else {
 
-                       if (ev->button == 2) {
+                       if (Keyboard::is_button2_event (ev)) {
 
-                               // ctrl-button2 click is the midi binding click
-                               // button2-click is "momentary"
-                               
-                               if (!Keyboard::modifier_state_equals (ev->state, Keyboard::ModifierMask (Keyboard::Control))) {
-                                       wait_for_release = true;
+                               if (solo_button->on_button_press_event (ev)) {
+                                       return true;
                                } else {
-                                       return false;
-                               }
+                                       // button2-click is "momentary"
+                                       wait_for_release = true;
+                               } 
                        }
 
-                       if (ev->button == 1 || ev->button == 2) {
+                       if (ev->button == 1 || Keyboard::is_button2_event (ev)) {
 
-                               if (Keyboard::modifier_state_equals (ev->state, Keyboard::ModifierMask (Keyboard::Control|Keyboard::Shift))) {
-
-                                       /* ctrl-shift-click applies change to all routes */
+                               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::Control|Keyboard::Alt))) {
+                               } else if (Keyboard::modifier_state_contains (ev->state, Keyboard::ModifierMask (Keyboard::PrimaryModifier|Keyboard::SecondaryModifier))) {
 
-                                       // ctrl-alt-click: exclusively solo this track, not a toggle */
+                                       // Primary-Secondary-click: exclusively solo this track, not a toggle */
 
                                        _session.begin_reversible_command (_("solo change"));
                                         Session::GlobalSoloStateCommand *cmd = new Session::GlobalSoloStateCommand (_session, this);
@@ -277,17 +370,26 @@ RouteUI::solo_press(GdkEventButton* ev)
                                        _session.add_command(cmd);
                                        _session.commit_reversible_command ();
 
-                               } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::Shift)) {
+                               } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::TertiaryModifier)) {
 
                                        // shift-click: set this route to solo safe
 
-                                       _route->set_solo_safe (!_route->solo_safe(), this);
-                                       wait_for_release = false;
+                                       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);
+                                               }
+                                       } else {
+                                               _route->set_solo_safe (!_route->solo_safe(), this);
+                                               wait_for_release = false;
+                                       }
 
-                               } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::Control)) {
+                               } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
 
-                                       /* ctrl-click: solo mix group.
-                                          ctrl-button2 is MIDI learn.
+                                       /* Primary-button1: solo mix group.
+                                          NOTE: Primary-button2 is MIDI learn.
                                        */
 
                                        if (ev->button == 1) {
@@ -297,8 +399,11 @@ RouteUI::solo_press(GdkEventButton* ev)
                                } else {
 
                                        /* click: solo this route */
-
-                                       reversibly_apply_route_boolean ("solo change", &Route::set_solo, !_route->soloed(), this);
+                                       if (wait_for_release) {
+                                               _route->set_solo (!_route->soloed(), this);
+                                       } else {
+                                               reversibly_apply_route_boolean ("solo change", &Route::set_solo, !_route->soloed(), this);
+                                       }
                                }
                        }
                }
@@ -313,10 +418,16 @@ RouteUI::solo_release(GdkEventButton* ev)
        if (!ignore_toggle) {
                if (wait_for_release) {
                        wait_for_release = false;
-                       // undo the last op
-                       // because the press was the last undoable thing we did
-
-                       _session.undo (1U);
+                       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);
+                       } else {
+                               // we don't use "undo the last op"
+                               // here because its expensive for the GUI
+                               _route->set_solo (!_route->soloed(), this);
+                       }
                }
        }
 
@@ -326,6 +437,10 @@ RouteUI::solo_release(GdkEventButton* ev)
 bool
 RouteUI::rec_enable_press(GdkEventButton* ev)
 {
+       if (ev->type == GDK_2BUTTON_PRESS || ev->type == GDK_3BUTTON_PRESS ) {
+               return true;
+       }
+
        if (!_session.engine().connected()) {
                MessageDialog msg (_("Not connected to JACK - cannot engage record"));
                msg.run ();
@@ -334,11 +449,11 @@ RouteUI::rec_enable_press(GdkEventButton* ev)
 
        if (!ignore_toggle && is_track() && rec_enable_button) {
 
-               if (ev->button == 2 && Keyboard::modifier_state_equals (ev->state, Keyboard::Control)) {
+               if (Keyboard::is_button2_event (ev)) {
 
-                       // do nothing on midi bind event
+                       return rec_enable_button->on_button_press_event (ev);
 
-               } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::ModifierMask (Keyboard::Control|Keyboard::Shift))) {
+               } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::ModifierMask (Keyboard::PrimaryModifier|Keyboard::TertiaryModifier))) {
 
                        _session.begin_reversible_command (_("rec-enable change"));
                         Session::GlobalRecordEnableStateCommand *cmd = new Session::GlobalRecordEnableStateCommand(_session, this);
@@ -353,7 +468,11 @@ RouteUI::rec_enable_press(GdkEventButton* ev)
                        _session.add_command(cmd);
                        _session.commit_reversible_command ();
 
-               } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::Control)) {
+               } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
+
+                       /* Primary-button1 applies change to the mix group.
+                          NOTE: Primary-button2 is MIDI learn.
+                       */
 
                        set_mix_group_rec_enable (_route, !_route->record_enabled());
 
@@ -375,6 +494,7 @@ RouteUI::rec_enable_release (GdkEventButton* ev)
 void
 RouteUI::solo_changed(void* src)
 {
+
        Gtkmm2ext::UI::instance()->call_slot (mem_fun (*this, &RouteUI::update_solo_display));
 }
 
@@ -382,32 +502,22 @@ void
 RouteUI::update_solo_display ()
 {
        bool x;
-       vector<Gdk::Color> colors;
+       vector<Gdk::Color> fg_colors;
        Gdk::Color c;
-
-       if (_route->solo_safe() != was_solo_safe){
-
-               if (_route->solo_safe()) {
-                       /* show solo safe */
-                       ::set_color(c, rgba_from_style (safe_solo_button_name(), 0x7f, 0xff, 0x7f, 0, "bg", Gtk::STATE_ACTIVE, false ));
-                       solo_button->set_name(safe_solo_button_name());
-               } else {
-                       ::set_color(c, rgba_from_style (solo_button_name(), 0x7f, 0xff, 0x7f, 0, "bg", Gtk::STATE_ACTIVE, false ));
-                       solo_button->set_name(solo_button_name());
-               }
-
-               colors.push_back (c);
-               solo_button->set_colors (colors);
-
-               was_solo_safe = !was_solo_safe;
-       }
-
+       
        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);
+       }
 }
 
 void
@@ -425,7 +535,7 @@ RouteUI::mute_changed(void* src)
 void
 RouteUI::update_mute_display ()
 {
-       bool model = _route->record_enabled();
+       bool model = _route->muted();
        bool view = mute_button->get_active();
 
        /* first make sure the button's "depressed" visual
@@ -492,14 +602,15 @@ RouteUI::update_rec_display ()
        if (model) {
 
                switch (_session.record_status ()) {
-               case Session::Disabled:
-               case Session::Enabled:
+               case Session::Recording:
                        rec_enable_button->set_visual_state (1);
                        break;
 
-               case Session::Recording:
+               case Session::Disabled:
+               case Session::Enabled:
                        rec_enable_button->set_visual_state (2);
                        break;
+
                }
 
        } else {
@@ -510,13 +621,21 @@ RouteUI::update_rec_display ()
 void
 RouteUI::build_remote_control_menu ()
 {
-       remote_control_menu = manage (new Menu);
+       remote_control_menu = new Menu;
        refresh_remote_control_menu ();
 }
 
 void
 RouteUI::refresh_remote_control_menu ()
 {
+       ENSURE_GUI_THREAD (mem_fun (*this, &RouteUI::refresh_remote_control_menu));
+
+       // only refresh the menu if it has been instantiated
+
+       if (remote_control_menu == 0) {
+               return;
+       }
+
        using namespace Menu_Helpers;
 
        RadioMenuItem::Group rc_group;
@@ -575,7 +694,7 @@ RouteUI::build_solo_menu (void)
        MenuList& items = solo_menu->items();
        CheckMenuItem* check;
 
-       check = new CheckMenuItem(_("Solo-safe"));
+       check = new CheckMenuItem(_("Solo Lock"));
        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));
@@ -824,7 +943,7 @@ gint
 RouteUI::idle_remove_this_route (RouteUI *rui)
 {
        rui->_session.remove_route (rui->_route);
-       return FALSE;
+       return false;
 }
 
 void
@@ -906,6 +1025,28 @@ RouteUI::polarity_changed ()
        /* no signal for this yet */
 }
 
+void
+RouteUI::toggle_denormal_protection ()
+{
+       if (denormal_menu_item) {
+
+               bool x;
+
+               ENSURE_GUI_THREAD(mem_fun (*this, &RouteUI::toggle_denormal_protection));
+               
+               if ((x = denormal_menu_item->get_active()) != _route->denormal_protection()) {
+                       _route->set_denormal_protection (x, this);
+               }
+       }
+}
+
+void
+RouteUI::denormal_protection_changed ()
+{
+       /* no signal for this yet */
+}
+
+
 void
 RouteUI::solo_safe_toggle(void* src, Gtk::CheckMenuItem* check)
 {
@@ -974,25 +1115,25 @@ RouteUI::disconnect_output ()
 bool
 RouteUI::is_track () const
 {
-       return dynamic_cast<Track*>(_route.get()) != 0;
+       return boost::dynamic_pointer_cast<Track>(_route) != 0;
 }
 
-Track*
+boost::shared_ptr<Track>
 RouteUI::track() const
 {
-       return dynamic_cast<Track*>(_route.get());
+       return boost::dynamic_pointer_cast<Track>(_route);
 }
 
 bool
 RouteUI::is_audio_track () const
 {
-       return dynamic_cast<AudioTrack*>(_route.get()) != 0;
+       return boost::dynamic_pointer_cast<AudioTrack>(_route) != 0;
 }
 
-AudioTrack*
+boost::shared_ptr<AudioTrack>
 RouteUI::audio_track() const
 {
-       return dynamic_cast<AudioTrack*>(_route.get());
+       return boost::dynamic_pointer_cast<AudioTrack>(_route);
 }
 
 boost::shared_ptr<Diskstream>
@@ -1032,3 +1173,38 @@ RouteUI::map_frozen ()
        }
 }
 
+void
+RouteUI::save_as_template ()
+{
+       Glib::ustring path;
+       Glib::ustring safe_name;
+       std::string name;
+       
+       path = Session::route_template_dir();
+       
+       if (g_mkdir_with_parents (path.c_str(), 0755)) {
+               error << string_compose (_("Cannot create route template directory %1"), path) << endmsg;
+               return;
+       }
+       
+       Prompter p (true); // modal
+       
+       p.set_prompt (_("Template name:"));
+       switch (p.run()) {
+       case RESPONSE_ACCEPT:
+               break;
+       default:
+               return;
+       }
+       
+       p.hide ();
+       p.get_result (name, true);
+       
+       safe_name = legalize_for_path (name);
+       safe_name += Session::template_suffix ();
+       
+       path = Glib::build_filename (path, safe_name);
+       
+       _route->save_as_template (path, name);
+}
+