only the last step-edited note remains selected after each note addition; waf install...
[ardour.git] / gtk2_ardour / route_ui.cc
index 284925d06a224bb1a395f8d128f3c7b555710c63..c56bde907d08e09afcd1d187f19278dab891235b 100644 (file)
@@ -18,7 +18,6 @@
 */
 
 #include <gtkmm2ext/gtk_ui.h>
-#include <gtkmm2ext/stop_signal.h>
 #include <gtkmm2ext/choice.h>
 #include <gtkmm2ext/doi.h>
 #include <gtkmm2ext/bindable_button.h>
@@ -35,6 +34,7 @@
 #include "ardour_ui.h"
 #include "editor.h"
 #include "route_ui.h"
+#include "led.h"
 #include "keyboard.h"
 #include "utils.h"
 #include "prompter.h"
@@ -50,9 +50,7 @@
 #include "ardour/session.h"
 #include "ardour/audioengine.h"
 #include "ardour/audio_track.h"
-#include "ardour/audio_diskstream.h"
 #include "ardour/midi_track.h"
-#include "ardour/midi_diskstream.h"
 #include "ardour/template_utils.h"
 #include "ardour/filename_extensions.h"
 #include "ardour/directory_names.h"
@@ -85,6 +83,7 @@ RouteUI::~RouteUI()
        delete solo_menu;
        delete mute_menu;
        delete sends_menu;
+        delete record_menu;
 }
 
 void
@@ -95,15 +94,21 @@ RouteUI::init ()
        mute_menu = 0;
        solo_menu = 0;
        sends_menu = 0;
+        record_menu = 0;
        pre_fader_mute_check = 0;
        post_fader_mute_check = 0;
        listen_mute_check = 0;
        main_mute_check = 0;
+        solo_safe_check = 0;
+        solo_isolated_check = 0;
+        solo_isolated_led = 0;
+        solo_safe_led = 0;
        ignore_toggle = false;
        _solo_release = 0;
        _mute_release = 0;
        route_active_menu_item = 0;
        denormal_menu_item = 0;
+        step_edit_item = 0;
        multiple_mute_change = false;
        multiple_solo_change = false;
 
@@ -209,21 +214,30 @@ RouteUI::set_route (boost::shared_ptr<Route> rp)
 
        _route->active_changed.connect (route_connections, invalidator (*this), boost::bind (&RouteUI::route_active_changed, this), gui_context());
        _route->mute_changed.connect (route_connections, invalidator (*this), ui_bind (&RouteUI::mute_changed, this, _1), gui_context());
-       _route->solo_changed.connect (route_connections, invalidator (*this), ui_bind (&RouteUI::solo_changed, this, _1), gui_context());
-       _route->listen_changed.connect (route_connections, invalidator (*this), ui_bind (&RouteUI::listen_changed, this, _1), gui_context());
-       _route->solo_isolated_changed.connect (route_connections, invalidator (*this), ui_bind (&RouteUI::solo_changed, this, _1), gui_context());
+
+       _route->solo_changed.connect (route_connections, invalidator (*this), boost::bind (&RouteUI::update_solo_display, this), gui_context());
+       _route->solo_safe_changed.connect (route_connections, invalidator (*this), boost::bind (&RouteUI::update_solo_display, this), gui_context());
+       _route->listen_changed.connect (route_connections, invalidator (*this), boost::bind (&RouteUI::update_solo_display, this), gui_context());
+       _route->solo_isolated_changed.connect (route_connections, invalidator (*this), boost::bind (&RouteUI::update_solo_display, this), gui_context());
+
         _route->phase_invert_changed.connect (route_connections, invalidator (*this), boost::bind (&RouteUI::polarity_changed, this), gui_context());
        _route->PropertyChanged.connect (route_connections, invalidator (*this), ui_bind (&RouteUI::property_changed, this, _1), gui_context());
 
        if (_session->writable() && is_track()) {
                boost::shared_ptr<Track> t = boost::dynamic_pointer_cast<Track>(_route);
 
-               t->diskstream()->RecordEnableChanged.connect (route_connections, invalidator (*this), boost::bind (&RouteUI::route_rec_enable_changed, this), gui_context());
+               t->RecordEnableChanged.connect (route_connections, invalidator (*this), boost::bind (&RouteUI::route_rec_enable_changed, this), gui_context());
 
                rec_enable_button->show();
                rec_enable_button->set_controllable (t->rec_enable_control());
 
                update_rec_display ();
+
+                if (is_midi_track()) {
+                        midi_track()->StepEditStatusChange.connect (route_connections, invalidator (*this),
+                                                                    ui_bind (&RouteUI::step_edit_changed, this, _1), gui_context());
+                }
+
        }
 
        mute_button->unset_flags (Gtk::CAN_FOCUS);
@@ -238,18 +252,12 @@ RouteUI::set_route (boost::shared_ptr<Route> rp)
                solo_button->show();
        }
 
-       /* map the current state */
-
-       mute_changed (0);
-       solo_changed (0);
-
        map_frozen ();
 }
 
 void
 RouteUI::invert_toggled ()
 {
-        cerr << this << " button state = " << invert_button->get_active() << " PI = " << _route->phase_invert() << endl;
         _route->set_phase_invert (invert_button->get_active());
 }
 
@@ -375,11 +383,14 @@ RouteUI::solo_press(GdkEventButton* ev)
                
                if (Keyboard::is_context_menu_event (ev)) {
                        
-                       if (solo_menu == 0) {
-                               build_solo_menu ();
-                       }
-                       
-                       solo_menu->popup (1, ev->time);
+                        if (!solo_isolated_led) {
+
+                                if (solo_menu == 0) {
+                                        build_solo_menu ();
+                                }
+                                
+                                solo_menu->popup (1, ev->time);
+                        }
                        
                } else {
                        
@@ -392,7 +403,7 @@ RouteUI::solo_press(GdkEventButton* ev)
                                         return true;
                                 }
 
-                               _solo_release = new SoloMuteRelease (_route->soloed());
+                               _solo_release = new SoloMuteRelease (_route->self_soloed());
                        }
                        
                        if (ev->button == 1 || Keyboard::is_button2_event (ev)) {
@@ -408,7 +419,7 @@ RouteUI::solo_press(GdkEventButton* ev)
                                        if (Config->get_solo_control_is_listen_control()) {
                                                _session->set_listen (_session->get_routes(), !_route->listening(),  Session::rt_cleanup, true);
                                        } else {
-                                               _session->set_solo (_session->get_routes(), !_route->soloed(),  Session::rt_cleanup, true);
+                                               _session->set_solo (_session->get_routes(), !_route->self_soloed(),  Session::rt_cleanup, true);
                                        }
                                        
                                } else if (Keyboard::modifier_state_contains (ev->state, Keyboard::ModifierMask (Keyboard::PrimaryModifier|Keyboard::SecondaryModifier))) {
@@ -458,7 +469,7 @@ RouteUI::solo_press(GdkEventButton* ev)
                                                if (Config->get_solo_control_is_listen_control()) {
                                                        _session->set_listen (_route->route_group()->route_list(), !_route->listening(),  Session::rt_cleanup, true);
                                                } else {
-                                                       _session->set_solo (_route->route_group()->route_list(), !_route->soloed(),  Session::rt_cleanup, true);
+                                                       _session->set_solo (_route->route_group()->route_list(), !_route->self_soloed(),  Session::rt_cleanup, true);
                                                }
                                        }
                                        
@@ -476,7 +487,7 @@ RouteUI::solo_press(GdkEventButton* ev)
                                        if (Config->get_solo_control_is_listen_control()) {
                                                _session->set_listen (rl, !_route->listening());
                                        } else {
-                                               _session->set_solo (rl, !_route->soloed());
+                                               _session->set_solo (rl, !_route->self_soloed());
                                        }
                                }
                        }
@@ -524,6 +535,15 @@ RouteUI::rec_enable_press(GdkEventButton* ev)
                return true;
        }
 
+        if (is_midi_track()) {
+
+                /* cannot rec-enable while step-editing */
+
+                if (midi_track()->step_editing()) {
+                        return true;
+                } 
+        }
+
        if (!ignore_toggle && is_track() && rec_enable_button) {
 
                if (Keyboard::is_button2_event (ev)) {
@@ -533,7 +553,7 @@ RouteUI::rec_enable_press(GdkEventButton* ev)
 
                } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::ModifierMask (Keyboard::PrimaryModifier|Keyboard::TertiaryModifier))) {
 
-                       _session->set_record_enable (_session->get_routes(), !rec_enable_button->get_active());
+                       _session->set_record_enabled (_session->get_routes(), !rec_enable_button->get_active());
 
                } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
 
@@ -541,7 +561,7 @@ RouteUI::rec_enable_press(GdkEventButton* ev)
                           NOTE: Primary-button2 is MIDI learn.
                        */
                        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);
+                               _session->set_record_enabled (_route->route_group()->route_list(), !rec_enable_button->get_active(), Session::rt_cleanup, true);
                        }
 
                } else if (Keyboard::is_context_menu_event (ev)) {
@@ -552,16 +572,90 @@ RouteUI::rec_enable_press(GdkEventButton* ev)
 
                        boost::shared_ptr<RouteList> rl (new RouteList);
                        rl->push_back (route());
-                       _session->set_record_enable (rl, !rec_enable_button->get_active());
+                       _session->set_record_enabled (rl, !rec_enable_button->get_active());
                }
        }
 
        return true;
 }
 
-bool
-RouteUI::rec_enable_release (GdkEventButton*)
+void
+RouteUI::build_record_menu ()
 {
+        if (record_menu) {
+                return;
+        }
+
+        /* no rec-button context menu for non-MIDI tracks 
+         */
+
+        if (is_midi_track()) {
+                record_menu = new Menu;
+                record_menu->set_name ("ArdourContextMenu");
+                
+                using namespace Menu_Helpers;
+                MenuList& items = record_menu->items();
+                
+                items.push_back (CheckMenuElem (_("Step Edit"), sigc::mem_fun (*this, &RouteUI::toggle_step_edit)));
+                step_edit_item = dynamic_cast<CheckMenuItem*> (&items.back());
+
+                if (_route->record_enabled()) {
+                        step_edit_item->set_sensitive (false);
+                }
+
+                step_edit_item->set_active (midi_track()->step_editing());
+        }
+}
+
+void
+RouteUI::toggle_step_edit ()
+{
+        if (!is_midi_track() || _route->record_enabled()) {
+                return;
+        }
+
+        midi_track()->set_step_editing (step_edit_item->get_active());
+}
+
+void
+RouteUI::step_edit_changed (bool yn)
+{
+        if (yn) {
+                if (rec_enable_button) {
+                        rec_enable_button->set_visual_state (3);
+                } 
+
+                start_step_editing ();
+
+                if (step_edit_item) {
+                        step_edit_item->set_active (true);
+                }
+
+        } else {
+
+                if (rec_enable_button) {
+                        rec_enable_button->set_visual_state (0);
+                } 
+
+                stop_step_editing ();
+
+                if (step_edit_item) {
+                        step_edit_item->set_active (false);
+                }
+        }
+}
+
+bool
+RouteUI::rec_enable_release (GdkEventButton* ev)
+{
+        if (Keyboard::is_context_menu_event (ev)) {
+                build_record_menu ();
+                if (record_menu) {
+                        record_menu->popup (1, ev->time);
+                }
+                return true;
+        }
+
        return true;
 }
 
@@ -695,19 +789,6 @@ RouteUI::send_blink (bool onoff)
        }
 }
 
-void
-RouteUI::solo_changed(void* /*src*/)
-{
-       Gtkmm2ext::UI::instance()->call_slot (invalidator (*this), boost::bind (&RouteUI::update_solo_display, this));
-}
-
-
-void
-RouteUI::listen_changed(void* /*src*/)
-{
-       Gtkmm2ext::UI::instance()->call_slot (invalidator (*this), boost::bind (&RouteUI::update_solo_display, this));
-}
-
 int
 RouteUI::solo_visual_state (boost::shared_ptr<Route> r)
 {
@@ -726,7 +807,11 @@ RouteUI::solo_visual_state (boost::shared_ptr<Route> r)
        } 
        
        if (r->soloed()) {
-               return 1;
+                if (!r->self_soloed()) {
+                        return 3;
+                } else {
+                        return 1;
+                }
        } else {
                return 0;
        }
@@ -744,7 +829,7 @@ RouteUI::solo_visual_state_with_isolate (boost::shared_ptr<Route> r)
                if (r->listening()) {
                        return 1;
                } else {
-                       return 0;
+                        return 0;
                }
 
        } 
@@ -752,7 +837,11 @@ RouteUI::solo_visual_state_with_isolate (boost::shared_ptr<Route> r)
        if (r->solo_isolated()) {
                return 2;
        } else if (r->soloed()) {
-               return 1;
+                if (!r->self_soloed()) {
+                        return 3;
+                } else {
+                        return 1;
+                }
        } else {
                return 0;
        }
@@ -809,7 +898,34 @@ RouteUI::update_solo_display ()
 
        }
 
-       solo_button->set_visual_state (solo_visual_state_with_isolate (_route));
+       bool yn = _route->solo_safe ();
+
+       if (solo_safe_check && solo_safe_check->get_active() != yn) {
+               solo_safe_check->set_active (yn);
+       }
+
+       yn = _route->solo_isolated ();
+
+       if (solo_isolated_check && solo_isolated_check->get_active() != yn) {
+               solo_isolated_check->set_active (yn);
+       }
+
+        set_button_names ();
+
+        if (solo_isolated_led) {
+                solo_isolated_led->set_visual_state (_route->solo_isolated() ? 1 : 0);
+        }
+
+        if (solo_safe_led) {
+                solo_safe_led->set_visual_state (_route->solo_safe() ? 1 : 0);
+        }
+
+       solo_button->set_visual_state (solo_visual_state (_route));
+        
+        /* some changes to solo status can affect mute display, so catch up 
+         */
+
+        update_mute_display ();
 }
 
 void
@@ -830,14 +946,13 @@ RouteUI::mute_visual_state (Session* s, boost::shared_ptr<Route> r)
        if (r->is_master() || r->is_monitor()) {
                return 0;
        }
-       
+
        if (Config->get_show_solo_mutes()) {
-               
+
                if (r->muted ()) {
                        /* full mute */
                        return 2;
                } else if (s->soloing() && !r->soloed() && !r->solo_isolated()) {
-                       /* mute-because-not-soloed */
                        return 1;
                } else {
                        /* no mute at all */
@@ -884,7 +999,7 @@ RouteUI::update_mute_display ()
 void
 RouteUI::route_rec_enable_changed ()
 {
-       Gtkmm2ext::UI::instance()->call_slot (invalidator (*this), boost::bind (&RouteUI::update_rec_display, this));
+        update_rec_display ();
 }
 
 void
@@ -916,22 +1031,30 @@ RouteUI::update_rec_display ()
        /* now make sure its color state is correct */
 
        if (model) {
-
-               switch (_session->record_status ()) {
-               case Session::Recording:
-                       rec_enable_button->set_visual_state (1);
-                       break;
-
-               case Session::Disabled:
-               case Session::Enabled:
-                       rec_enable_button->set_visual_state (2);
-                       break;
-
-               }
+                switch (_session->record_status ()) {
+                case Session::Recording:
+                        rec_enable_button->set_visual_state (1);
+                        break;
+                        
+                case Session::Disabled:
+                case Session::Enabled:
+                        rec_enable_button->set_visual_state (2);
+                        break;
+                        
+                }
+
+                if (step_edit_item) {
+                        step_edit_item->set_sensitive (false);
+                }
 
        } else {
                rec_enable_button->set_visual_state (0);
+
+                if (step_edit_item) {
+                        step_edit_item->set_sensitive (true);
+                }
        }
+        
 
        check_rec_enable_sensitivity ();
 }
@@ -949,15 +1072,15 @@ RouteUI::build_solo_menu (void)
        check = new CheckMenuItem(_("Solo Isolate"));
        check->set_active (_route->solo_isolated());
        check->signal_toggled().connect (sigc::bind (sigc::mem_fun (*this, &RouteUI::toggle_solo_isolated), check));
-       _route->solo_isolated_changed.connect (route_connections, invalidator (*this), ui_bind (&RouteUI::solo_isolated_toggle, this, _1, check), gui_context());
        items.push_back (CheckMenuElem(*check));
+        solo_isolated_check = dynamic_cast<CheckMenuItem*>(&items.back());
        check->show_all();
 
        check = new CheckMenuItem(_("Solo Safe"));
        check->set_active (_route->solo_safe());
        check->signal_toggled().connect (sigc::bind (sigc::mem_fun (*this, &RouteUI::toggle_solo_safe), check));
-       _route->solo_safe_changed.connect (route_connections, invalidator (*this), ui_bind (&RouteUI::solo_safe_toggle, this, _1, check), gui_context());
        items.push_back (CheckMenuElem(*check));
+        solo_safe_check = dynamic_cast<CheckMenuItem*>(&items.back());
        check->show_all();
 
        //items.push_back (SeparatorElem());
@@ -1054,10 +1177,59 @@ RouteUI::muting_change ()
        }
 }
 
+bool
+RouteUI::solo_isolate_button_release (GdkEventButton* ev)
+{
+        if (ev->type == GDK_2BUTTON_PRESS || ev->type == GDK_3BUTTON_PRESS) {
+                return true;
+        }
+
+        bool view = (solo_isolated_led->visual_state() != 0);
+        bool model = _route->solo_isolated();
+
+        /* called BEFORE the view has changed */
+
+        if (ev->button == 1) {
+                if (Keyboard::modifier_state_equals (ev->state, Keyboard::ModifierMask (Keyboard::PrimaryModifier|Keyboard::TertiaryModifier))) {
+
+                        if (model) {
+                                /* disable isolate for all routes */
+                                _session->set_solo_isolated (_session->get_routes(), false, Session::rt_cleanup, true);
+                        }
+
+                } else {
+                        if (model == view) {
+
+                                /* flip just this route */
+
+                                boost::shared_ptr<RouteList> rl (new RouteList);
+                                rl->push_back (_route);
+                                _session->set_solo_isolated (rl, !view, Session::rt_cleanup, true);
+                        }
+                }
+        }
+
+        return true;
+}
+
+bool
+RouteUI::solo_safe_button_release (GdkEventButton* ev)
+{
+        _route->set_solo_safe (!(solo_safe_led->visual_state() > 0), this);
+        return true;
+}
+
 void
 RouteUI::toggle_solo_isolated (Gtk::CheckMenuItem* check)
 {
-       _route->set_solo_isolated (check->get_active(), this);
+        bool view = check->get_active();
+        bool model = _route->solo_isolated();
+
+        /* called AFTER the view has changed */
+
+        if (model != view) {
+                _route->set_solo_isolated (view, this);
+        }
 }
 
 void
@@ -1072,7 +1244,7 @@ RouteUI::choose_color()
        bool picked;
        Gdk::Color color;
 
-       color = Gtkmm2ext::UI::instance()->get_color (_("ardour: color selection"), picked, &_color);
+       color = Gtkmm2ext::UI::instance()->get_color (_("Color Selection"), picked, &_color);
 
        if (picked) {
                set_color (color);
@@ -1154,6 +1326,25 @@ RouteUI::set_color_from_route ()
 void
 RouteUI::remove_this_route ()
 {
+        if ((route()->is_master() || route()->is_monitor()) &&
+            !Config->get_allow_special_bus_removal()) {
+                MessageDialog msg (_("That would be bad news ...."),
+                                   false,
+                                   Gtk::MESSAGE_INFO,
+                                   Gtk::BUTTONS_OK);
+                msg.set_secondary_text (string_compose (_(
+"Removing the master or monitor bus is such a bad idea\n\
+that %1 is not going to allow it.\n\
+\n\
+If you really want to do this sort of thing\n\
+edit your ardour.rc file to set the\n\
+\"allow-special-bus-removal\" option to be \"yes\""), PROGRAM_NAME));
+
+                msg.present ();
+                msg.run ();
+                return;
+        }
+
        vector<string> choices;
        string prompt;
 
@@ -1183,7 +1374,7 @@ RouteUI::remove_this_route ()
 gint
 RouteUI::idle_remove_this_route (RouteUI *rui)
 {
-       rui->_session->remove_route (rui->_route);
+       rui->_session->remove_route (rui->route());
        return false;
 }
 
@@ -1192,7 +1383,12 @@ RouteUI::route_rename ()
 {
        ArdourPrompter name_prompter (true);
        string result;
-       name_prompter.set_prompt (_("New Name: "));
+       if (is_track()) {
+               name_prompter.set_title (_("Rename Track"));
+       } else {
+               name_prompter.set_title (_("Rename Bus"));
+       }
+       name_prompter.set_prompt (_("New name:"));
        name_prompter.set_initial_text (_route->name());
        name_prompter.add_button (_("Rename"), Gtk::RESPONSE_ACCEPT);
        name_prompter.set_response_sensitive (Gtk::RESPONSE_ACCEPT, false);
@@ -1264,27 +1460,6 @@ RouteUI::denormal_protection_changed ()
        }
 }
 
-void
-RouteUI::solo_isolated_toggle(void* /*src*/, Gtk::CheckMenuItem* check)
-{
-       bool yn = _route->solo_isolated ();
-
-       if (check->get_active() != yn) {
-               check->set_active (yn);
-       }
-}
-
-
-void
-RouteUI::solo_safe_toggle(void* /*src*/, Gtk::CheckMenuItem* check)
-{
-       bool yn = _route->solo_safe ();
-
-       if (check->get_active() != yn) {
-               check->set_active (yn);
-       }
-}
-
 void
 RouteUI::disconnect_input ()
 {
@@ -1333,16 +1508,10 @@ RouteUI::midi_track() const
        return boost::dynamic_pointer_cast<MidiTrack>(_route);
 }
 
-boost::shared_ptr<Diskstream>
-RouteUI::get_diskstream () const
+bool
+RouteUI::has_audio_outputs () const
 {
-       boost::shared_ptr<Track> t;
-
-       if ((t = boost::dynamic_pointer_cast<Track>(_route)) != 0) {
-               return t->diskstream();
-       } else {
-               return boost::shared_ptr<Diskstream> ((Diskstream*) 0);
-       }
+       return (_route->n_outputs().n_audio() > 0);
 }
 
 string
@@ -1392,6 +1561,7 @@ RouteUI::save_as_template ()
 
        Prompter p (true); // modal
 
+       p.set_title (_("Save As Template"));
        p.set_prompt (_("Template name:"));
        switch (p.run()) {
        case RESPONSE_ACCEPT: