fix ordering of track view list & route list resync in editor, to avoid clearing...
[ardour.git] / gtk2_ardour / route_ui.cc
index 842e06953ece8780731c02d64419cbadb484e1af..6cbb5290d47ca98e02e479c17579aa69644b00e3 100644 (file)
@@ -22,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>
@@ -39,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;
@@ -66,6 +70,7 @@ RouteUI::RouteUI (boost::shared_ptr<ARDOUR::Route> rt,
 void
 RouteUI::init ()
 {
+       self_destruct = true;
        xml_node = 0;
        mute_menu = 0;
        solo_menu = 0;
@@ -76,18 +81,23 @@ RouteUI::init ()
        was_solo_safe = false;
        polarity_menu_item = 0;
        denormal_menu_item = 0;
+       multiple_mute_change = false;
+       multiple_solo_change = false;
 
        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));
 }
@@ -107,11 +117,6 @@ RouteUI::reset ()
                mute_menu = 0;
        }
        
-       if (remote_control_menu) {
-               delete remote_control_menu;
-               remote_control_menu = 0;
-       }
-
        if (xml_node) {
                /* do not delete the node - its owned by the route */
                xml_node = 0;
@@ -145,7 +150,9 @@ RouteUI::set_route (boost::shared_ptr<Route> rp)
           up when the route is destroyed.
        */
 
-       new PairedShiva<Route,RouteUI> (*_route, *this);
+       if (self_destruct) {
+               new PairedShiva<Route,RouteUI> (*_route, *this);
+       }
 
        mute_button->set_controllable (&_route->mute_control());
        mute_button->set_label (m_name);
@@ -185,7 +192,10 @@ RouteUI::set_route (boost::shared_ptr<Route> rp)
 
 RouteUI::~RouteUI()
 {
-       GoingAway (); /* EMIT SIGNAL */
+       /* 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;
        }
@@ -193,19 +203,22 @@ RouteUI::~RouteUI()
        if (mute_menu) {
                delete mute_menu;
        }
-
-       if (remote_control_menu) {
-               delete remote_control_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) {
+       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)) {
@@ -218,7 +231,7 @@ RouteUI::mute_press(GdkEventButton* ev)
 
                } else {
 
-                       if (ev->button == 2) {
+                       if (Keyboard::is_button2_event (ev)) {
                                // Primary-button2 click is the midi binding click
                                // button2-click is "momentary"
                                
@@ -229,7 +242,7 @@ RouteUI::mute_press(GdkEventButton* ev)
                                }
                        }
 
-                       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::PrimaryModifier|Keyboard::TertiaryModifier))) {
 
@@ -241,6 +254,7 @@ 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::PrimaryModifier)) {
 
@@ -255,8 +269,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);
+                                       }
                                }
                        }
                }
@@ -272,9 +289,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;
@@ -283,16 +305,16 @@ RouteUI::mute_release(GdkEventButton* ev)
 bool
 RouteUI::solo_press(GdkEventButton* ev)
 {
-       /* ignore double clicks */
+       /* ignore double/triple clicks */
 
-       if (ev->type == GDK_2BUTTON_PRESS) {
+       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 ();
                        }
@@ -301,7 +323,7 @@ RouteUI::solo_press(GdkEventButton* ev)
 
                } else {
 
-                       if (ev->button == 2) {
+                       if (Keyboard::is_button2_event (ev)) {
 
                                // Primary-button2 click is the midi binding click
                                // button2-click is "momentary"
@@ -313,18 +335,31 @@ RouteUI::solo_press(GdkEventButton* ev)
                                }
                        }
 
-                       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::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))) {
 
@@ -342,8 +377,17 @@ RouteUI::solo_press(GdkEventButton* ev)
 
                                        // 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::PrimaryModifier)) {
 
@@ -358,7 +402,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);
+                                       }
                                }
                        }
                }
@@ -373,10 +421,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);
+                       }
                }
        }
 
@@ -386,7 +440,7 @@ RouteUI::solo_release(GdkEventButton* ev)
 bool
 RouteUI::rec_enable_press(GdkEventButton* ev)
 {
-       if (ev->type == GDK_2BUTTON_PRESS) {
+       if (ev->type == GDK_2BUTTON_PRESS || ev->type == GDK_3BUTTON_PRESS ) {
                return true;
        }
 
@@ -398,7 +452,7 @@ 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::PrimaryModifier)) {
+               if (Keyboard::is_button2_event (ev) && Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
 
                        // do nothing on midi bind event
                        return false;
@@ -444,6 +498,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));
 }
 
@@ -892,7 +947,7 @@ gint
 RouteUI::idle_remove_this_route (RouteUI *rui)
 {
        rui->_session.remove_route (rui->_route);
-       return FALSE;
+       return false;
 }
 
 void
@@ -1122,3 +1177,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);
+}
+