do not sort MIDI regions by layer since they are all transparent
[ardour.git] / gtk2_ardour / route_ui.cc
index 6c42de58480f2108cf3a5f7104d0bbc99ddfc126..68c84bb1e7537eb2d2c7e5b22f26cf366cf41ad9 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2002-2006 Paul Davis 
+    Copyright (C) 2002-2006 Paul Davis
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -45,6 +45,7 @@
 #include "automation_time_axis.h"
 
 #include "ardour/route.h"
+#include "ardour/event_type_map.h"
 #include "ardour/session.h"
 #include "ardour/audioengine.h"
 #include "ardour/audio_track.h"
@@ -81,7 +82,7 @@ RouteUI::~RouteUI()
        /* derived classes should emit GoingAway so that they receive the signal
           when the object is still a legal derived instance.
        */
-       
+
        delete solo_menu;
        delete mute_menu;
        delete sends_menu;
@@ -95,7 +96,6 @@ RouteUI::init ()
        mute_menu = 0;
        solo_menu = 0;
        sends_menu = 0;
-       rec_context_menu = 0;
        ignore_toggle = false;
        wait_for_release = false;
        route_active_menu_item = 0;
@@ -152,7 +152,7 @@ RouteUI::reset ()
 
        delete mute_menu;
        mute_menu = 0;
-       
+
        if (xml_node) {
                /* do not delete the node - its owned by the route */
                xml_node = 0;
@@ -184,14 +184,14 @@ RouteUI::set_route (boost::shared_ptr<Route> rp)
 
        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)));
-  
-       if (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)));
@@ -201,11 +201,11 @@ RouteUI::set_route (boost::shared_ptr<Route> rp)
                rec_enable_button->set_controllable (t->rec_enable_control());
 
                update_rec_display ();
-       } 
+       }
 
        mute_button->unset_flags (Gtk::CAN_FOCUS);
        solo_button->unset_flags (Gtk::CAN_FOCUS);
-       
+
        mute_button->show();
 
        if (_route->is_control()) {
@@ -244,7 +244,7 @@ RouteUI::mute_press(GdkEventButton* ev)
                        if (Keyboard::is_button2_event (ev)) {
                                // Primary-button2 click is the midi binding click
                                // button2-click is "momentary"
-                               
+
                                if (!Keyboard::modifier_state_equals (ev->state, Keyboard::ModifierMask (Keyboard::PrimaryModifier))) {
                                        wait_for_release = true;
                                } else {
@@ -275,7 +275,7 @@ RouteUI::mute_press(GdkEventButton* ev)
                                        if (ev->button == 1) {
                                                set_route_group_mute (_route, !_route->muted());
                                        }
-                                       
+
                                } else {
 
                                        /* plain click applies change to this route */
@@ -329,41 +329,41 @@ RouteUI::solo_press(GdkEventButton* ev)
 
                multiple_solo_change = false;
                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))) {
                                                wait_for_release = true;
                                        } else {
                                                return false;
                                        }
                                }
-                               
+
                                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 
+                                                         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);
                                                }
@@ -377,9 +377,9 @@ RouteUI::solo_press(GdkEventButton* ev)
                                                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, not a toggle */
 
                                                _session.begin_reversible_command (_("solo change"));
@@ -500,7 +500,7 @@ RouteUI::rec_enable_press(GdkEventButton* ev)
                        set_route_group_rec_enable (_route, !_route->record_enabled());
 
                } else if (Keyboard::is_context_menu_event (ev)) {
-                       
+
                        /* do this on release */
 
                } else {
@@ -512,31 +512,9 @@ RouteUI::rec_enable_press(GdkEventButton* ev)
        return true;
 }
 
-
-void
-RouteUI::show_rec_context_menu ()
-{
-       if (!rec_context_menu) {
-               cerr << "build menu\n";
-               build_rec_context_menu ();
-       }
-
-       if (rec_context_menu) {
-               /* only do this if build_rec_context_menu() actually did something */
-               cerr << "show menu\n";
-               rec_context_menu->popup (1, gtk_get_current_event_time());
-       }
-}
-
 bool
-RouteUI::rec_enable_release (GdkEventButton* ev)
+RouteUI::rec_enable_release (GdkEventButton*)
 {
-       cerr << "release\n";
-       if (Keyboard::is_context_menu_event(ev)) {
-               cerr << "context\n";
-               show_rec_context_menu ();
-       }
-
        return true;
 }
 
@@ -544,11 +522,11 @@ void
 RouteUI::build_sends_menu ()
 {
        using namespace Menu_Helpers;
-       
+
        sends_menu = new Menu;
        sends_menu->set_name ("ArdourContextMenu");
        MenuList& items = sends_menu->items();
-       
+
        items.push_back (MenuElem(_("Assign all tracks (prefader)"), 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(_("Copy track gains to sends"), mem_fun (*this, &RouteUI::set_sends_gain_from_track)));
@@ -639,7 +617,7 @@ RouteUI::send_blink (bool onoff)
        if (!show_sends_button) {
                return;
        }
-               
+
        if (onoff) {
                show_sends_button->set_state (STATE_ACTIVE);
        } else {
@@ -686,8 +664,8 @@ RouteUI::update_solo_display ()
                        ignore_toggle = true;
                        solo_button->set_active (x);
                        ignore_toggle = false;
-               } 
-               
+               }
+
                if (_route->solo_isolated()) {
                        solo_button->set_visual_state (2);
                } else if (x) {
@@ -727,7 +705,7 @@ RouteUI::update_mute_display ()
        }
 
        /* now attend to visual state */
-       
+
        if (Config->get_show_solo_mutes()) {
                if (_route->muted()) {
                        mute_button->set_visual_state (2);
@@ -776,7 +754,7 @@ RouteUI::update_rec_display ()
        else {
                return;
        }
-       
+
        /* now make sure its color state is correct */
 
        if (model) {
@@ -802,7 +780,7 @@ void
 RouteUI::build_solo_menu (void)
 {
        using namespace Menu_Helpers;
-       
+
        solo_menu = new Menu;
        solo_menu->set_name ("ArdourContextMenu");
        MenuList& items = solo_menu->items();
@@ -817,18 +795,18 @@ RouteUI::build_solo_menu (void)
 
        //items.push_back (SeparatorElem());
        // items.push_back (MenuElem (_("MIDI Bind"), mem_fun (*mute_button, &BindableToggleButton::midi_learn)));
-       
+
 }
 
 void
 RouteUI::build_mute_menu(void)
 {
        using namespace Menu_Helpers;
-       
+
        mute_menu = new Menu;
        mute_menu->set_name ("ArdourContextMenu");
 
-#if FIX_ME_IN_3_0      
+#if FIX_ME_IN_3_0
        MenuList& items = mute_menu->items();
        CheckMenuItem* check;
 
@@ -845,7 +823,7 @@ RouteUI::build_mute_menu(void)
        _route->post_fader_changed.connect(bind (mem_fun (*this, &RouteUI::post_fader_toggle), check));
        items.push_back (CheckMenuElem(*check));
        check->show_all();
-       
+
        check = new CheckMenuItem(_("Control Outs"));
        init_mute_menu(CONTROL_OUTS, check);
        check->signal_toggled().connect(bind (mem_fun (*this, &RouteUI::toggle_mute_menu), CONTROL_OUTS, check));
@@ -975,9 +953,9 @@ void
 RouteUI::set_color (const Gdk::Color & c)
 {
        char buf[64];
-       
+
        _color = c;
-       
+
        ensure_xml_node ();
        snprintf (buf, sizeof (buf), "%d:%d:%d", c.get_red(), c.get_green(), c.get_blue());
        xml_node->add_property ("color", buf);
@@ -1001,7 +979,7 @@ XMLNode*
 RouteUI::get_automation_child_xml_node (Evoral::Parameter param)
 {
        ensure_xml_node ();
-       
+
        XMLNodeList kids = xml_node->children();
        XMLNodeConstIterator iter;
 
@@ -1027,7 +1005,7 @@ int
 RouteUI::set_color_from_route ()
 {
        XMLProperty *prop;
-       
+
        RouteUI::ensure_xml_node ();
 
        if ((prop = xml_node->property ("color")) != 0) {
@@ -1037,7 +1015,7 @@ RouteUI::set_color_from_route ()
                _color.set_green(g);
                _color.set_blue(b);
                return 0;
-       } 
+       }
        return 1;
 }
 
@@ -1087,12 +1065,12 @@ RouteUI::route_rename ()
         name_prompter.get_result (result);
         if (result.length()) {
                        _route->set_name (result);
-               }       
+               }
                break;
        }
 
        return;
-  
+
 }
 
 void
@@ -1131,7 +1109,7 @@ RouteUI::toggle_polarity ()
                bool x;
 
                ENSURE_GUI_THREAD(mem_fun (*this, &RouteUI::toggle_polarity));
-               
+
                if ((x = polarity_menu_item->get_active()) != _route->phase_invert()) {
                        _route->set_phase_invert (x);
                        if (x) {
@@ -1161,7 +1139,7 @@ RouteUI::toggle_denormal_protection ()
                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);
                }
@@ -1191,7 +1169,7 @@ void
 RouteUI::pre_fader_toggle(void* src, Gtk::CheckMenuItem* check)
 {
        ENSURE_GUI_THREAD(bind (mem_fun (*this, &RouteUI::pre_fader_toggle), src, check));
-       
+
        bool yn = _route->get_mute_config(PRE_FADER);
        if (check->get_active() != yn) {
                check->set_active (yn);
@@ -1202,7 +1180,7 @@ void
 RouteUI::post_fader_toggle(void* src, Gtk::CheckMenuItem* check)
 {
        ENSURE_GUI_THREAD(bind (mem_fun (*this, &RouteUI::post_fader_toggle), src, check));
-       
+
        bool yn = _route->get_mute_config(POST_FADER);
        if (check->get_active() != yn) {
                check->set_active (yn);
@@ -1213,7 +1191,7 @@ void
 RouteUI::control_outs_toggle(void* src, Gtk::CheckMenuItem* check)
 {
        ENSURE_GUI_THREAD(bind (mem_fun (*this, &RouteUI::control_outs_toggle), src, check));
-       
+
        bool yn = _route->get_mute_config(CONTROL_OUTS);
        if (check->get_active() != yn) {
                check->set_active (yn);
@@ -1224,7 +1202,7 @@ void
 RouteUI::main_outs_toggle(void* src, Gtk::CheckMenuItem* check)
 {
        ENSURE_GUI_THREAD(bind (mem_fun (*this, &RouteUI::main_outs_toggle), src, check));
-       
+
        bool yn = _route->get_mute_config(MAIN_OUTS);
        if (check->get_active() != yn) {
                check->set_active (yn);
@@ -1329,16 +1307,16 @@ RouteUI::save_as_template ()
        sys::path path;
        Glib::ustring safe_name;
        string name;
-       
+
        path = ARDOUR::user_route_template_directory ();
-       
+
        if (g_mkdir_with_parents (path.to_string().c_str(), 0755)) {
                error << string_compose (_("Cannot create route template directory %1"), path.to_string()) << endmsg;
                return;
        }
-       
+
        Prompter p (true); // modal
-       
+
        p.set_prompt (_("Template name:"));
        switch (p.run()) {
        case RESPONSE_ACCEPT:
@@ -1346,15 +1324,15 @@ RouteUI::save_as_template ()
        default:
                return;
        }
-       
+
        p.hide ();
        p.get_result (name, true);
-       
+
        safe_name = legalize_for_path (name);
        safe_name += template_suffix;
-       
+
        path /= safe_name;
-       
+
        _route->save_as_template (path.to_string(), name);
 }
 
@@ -1372,7 +1350,7 @@ 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") {