do not sort MIDI regions by layer since they are all transparent
[ardour.git] / gtk2_ardour / route_ui.cc
index ba805f7d4bc23b05db266624eb8c1555ba9a8293..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
@@ -26,6 +26,7 @@
 #include <gtkmm2ext/gtk_ui.h>
 
 #include "ardour/route_group.h"
+#include "ardour/dB.h"
 #include "pbd/memento_command.h"
 #include "pbd/stacktrace.h"
 #include "pbd/shiva.h"
@@ -44,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"
@@ -80,10 +82,9 @@ 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 remote_control_menu;
        delete sends_menu;
 }
 
@@ -94,7 +95,6 @@ RouteUI::init ()
        xml_node = 0;
        mute_menu = 0;
        solo_menu = 0;
-       remote_control_menu = 0;
        sends_menu = 0;
        ignore_toggle = false;
        wait_for_release = false;
@@ -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,39 +184,36 @@ 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)));
-               connections.push_back (t->diskstream()->RecordEnableChanged.connect (mem_fun (PublicEditor::instance(), &PublicEditor::update_rec_display)));
                connections.push_back (_session.RecordStateChanged.connect (mem_fun (*this, &RouteUI::session_rec_enable_changed)));
 
                rec_enable_button->show();
                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_master()) {
+       if (_route->is_control()) {
                solo_button->hide ();
        } else {
                solo_button->show();
        }
 
-       connections.push_back (_route->RemoteControlIDChanged.connect (mem_fun(*this, &RouteUI::refresh_remote_control_menu)));
-
        /* map the current state */
 
        mute_changed (0);
@@ -247,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 {
@@ -278,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 */
@@ -297,7 +294,7 @@ RouteUI::mute_press(GdkEventButton* ev)
 }
 
 bool
-RouteUI::mute_release(GdkEventButton* ev)
+RouteUI::mute_release(GdkEventButton*)
 {
        if (!ignore_toggle) {
                if (wait_for_release){
@@ -332,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);
                                                }
@@ -380,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"));
@@ -437,7 +434,7 @@ RouteUI::solo_press(GdkEventButton* ev)
 }
 
 bool
-RouteUI::solo_release(GdkEventButton* ev)
+RouteUI::solo_release(GdkEventButton*)
 {
        if (!ignore_toggle) {
                if (wait_for_release) {
@@ -502,6 +499,10 @@ 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 {
                        reversibly_apply_track_boolean ("rec-enable change", &Track::set_record_enable, !track()->record_enabled(), this);
                        check_rec_enable_sensitivity ();
@@ -512,7 +513,7 @@ RouteUI::rec_enable_press(GdkEventButton* ev)
 }
 
 bool
-RouteUI::rec_enable_release (GdkEventButton* ev)
+RouteUI::rec_enable_release (GdkEventButton*)
 {
        return true;
 }
@@ -521,12 +522,13 @@ 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"), mem_fun (*this, &RouteUI::create_sends)));
+
+       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)));
        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)));
@@ -534,24 +536,27 @@ RouteUI::build_sends_menu ()
 }
 
 void
-RouteUI::create_sends ()
+RouteUI::create_sends (Placement p)
 {
-       _session.globally_add_internal_sends (_route);
+       _session.globally_add_internal_sends (_route, p);
 }
 
 void
 RouteUI::set_sends_gain_from_track ()
 {
+       _session.globally_set_send_gains_from_track (_route);
 }
 
 void
 RouteUI::set_sends_gain_to_zero ()
 {
+       _session.globally_set_send_gains_to_zero (_route);
 }
 
 void
 RouteUI::set_sends_gain_to_unity ()
 {
+       _session.globally_set_send_gains_to_unity (_route);
 }
 
 bool
@@ -601,7 +606,7 @@ RouteUI::show_sends_press(GdkEventButton* ev)
 }
 
 bool
-RouteUI::show_sends_release (GdkEventButton* ev)
+RouteUI::show_sends_release (GdkEventButton*)
 {
        return true;
 }
@@ -612,7 +617,7 @@ RouteUI::send_blink (bool onoff)
        if (!show_sends_button) {
                return;
        }
-               
+
        if (onoff) {
                show_sends_button->set_state (STATE_ACTIVE);
        } else {
@@ -621,14 +626,14 @@ RouteUI::send_blink (bool onoff)
 }
 
 void
-RouteUI::solo_changed(void* src)
+RouteUI::solo_changed(void* /*src*/)
 {
        Gtkmm2ext::UI::instance()->call_slot (mem_fun (*this, &RouteUI::update_solo_display));
 }
 
 
 void
-RouteUI::listen_changed(void* src)
+RouteUI::listen_changed(void* /*src*/)
 {
        Gtkmm2ext::UI::instance()->call_slot (mem_fun (*this, &RouteUI::update_solo_display));
 }
@@ -646,17 +651,24 @@ RouteUI::update_solo_display ()
                        ignore_toggle = false;
                }
 
+               if (x) {
+                       solo_button->set_visual_state (1);
+               } else {
+                       solo_button->set_visual_state (0);
+               }
+
+
        } else {
 
                if (solo_button->get_active() != (x = _route->soloed())){
                        ignore_toggle = true;
-                       solo_button->set_active(x);
+                       solo_button->set_active (x);
                        ignore_toggle = false;
-               } 
-               
+               }
+
                if (_route->solo_isolated()) {
                        solo_button->set_visual_state (2);
-               } else if (_route->soloed()) {
+               } else if (x) {
                        solo_button->set_visual_state (1);
                } else {
                        solo_button->set_visual_state (0);
@@ -671,7 +683,7 @@ RouteUI::solo_changed_so_update_mute ()
 }
 
 void
-RouteUI::mute_changed(void* src)
+RouteUI::mute_changed(void* /*src*/)
 {
        Gtkmm2ext::UI::instance()->call_slot (mem_fun (*this, &RouteUI::update_mute_display));
 }
@@ -693,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);
@@ -742,7 +754,7 @@ RouteUI::update_rec_display ()
        else {
                return;
        }
-       
+
        /* now make sure its color state is correct */
 
        if (model) {
@@ -764,77 +776,11 @@ RouteUI::update_rec_display ()
        }
 }
 
-void
-RouteUI::build_remote_control_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;
-       CheckMenuItem* rc_active;
-       uint32_t limit = _session.ntracks() + _session.nbusses();
-       char buf[32];
-
-       MenuList& rc_items = remote_control_menu->items();
-       rc_items.clear ();
-
-       /* note that this menu list starts at zero, not 1, because zero
-          is a valid, if useless, ID.
-       */
-
-       limit += 4; /* leave some breathing room */
-       
-       rc_items.push_back (RadioMenuElem (rc_group, _("None")));
-       if (_route->remote_control_id() == 0) {
-               rc_active = dynamic_cast<CheckMenuItem*> (&rc_items.back());
-               rc_active->set_active ();
-       }
-               
-       for (uint32_t i = 1; i < limit; ++i) {
-               snprintf (buf, sizeof (buf), "%u", i);
-               rc_items.push_back (RadioMenuElem (rc_group, buf));
-               rc_active = dynamic_cast<RadioMenuItem*>(&rc_items.back());
-               if (_route->remote_control_id() == i) {
-                       rc_active = dynamic_cast<CheckMenuItem*> (&rc_items.back());
-                       rc_active->set_active ();
-               }
-               rc_active->signal_activate().connect (bind (mem_fun (*this, &RouteUI::set_remote_control_id), i, rc_active));
-       }
-}
-
-void
-RouteUI::set_remote_control_id (uint32_t id, CheckMenuItem* item)
-{
-       /* this is called when the radio menu item is toggled, and so 
-          is actually invoked twice per menu selection. we only
-          care about the invocation for the item that was being
-          marked active.
-       */
-
-       if (item->get_active()) {
-               _route->set_remote_control_id (id);
-       }
-}
-
 void
 RouteUI::build_solo_menu (void)
 {
        using namespace Menu_Helpers;
-       
+
        solo_menu = new Menu;
        solo_menu->set_name ("ArdourContextMenu");
        MenuList& items = solo_menu->items();
@@ -849,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;
 
@@ -877,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));
@@ -903,7 +849,7 @@ RouteUI::init_mute_menu(MuteMaster::MutePoint mp, CheckMenuItem* check)
 }
 
 void
-RouteUI::toggle_mute_menu(MuteMaster::MutePoint mp, Gtk::CheckMenuItem* check)
+RouteUI::toggle_mute_menu(MuteMaster::MutePoint /*mp*/, Gtk::CheckMenuItem* /*check*/)
 {
        // _route->set_mute_config(type, check->get_active(), this);
 }
@@ -1007,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);
@@ -1033,7 +979,7 @@ XMLNode*
 RouteUI::get_automation_child_xml_node (Evoral::Parameter param)
 {
        ensure_xml_node ();
-       
+
        XMLNodeList kids = xml_node->children();
        XMLNodeConstIterator iter;
 
@@ -1059,7 +1005,7 @@ int
 RouteUI::set_color_from_route ()
 {
        XMLProperty *prop;
-       
+
        RouteUI::ensure_xml_node ();
 
        if ((prop = xml_node->property ("color")) != 0) {
@@ -1069,7 +1015,7 @@ RouteUI::set_color_from_route ()
                _color.set_green(g);
                _color.set_blue(b);
                return 0;
-       } 
+       }
        return 1;
 }
 
@@ -1119,12 +1065,12 @@ RouteUI::route_rename ()
         name_prompter.get_result (result);
         if (result.length()) {
                        _route->set_name (result);
-               }       
+               }
                break;
        }
 
        return;
-  
+
 }
 
 void
@@ -1163,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) {
@@ -1193,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);
                }
@@ -1209,7 +1155,7 @@ RouteUI::denormal_protection_changed ()
 }
 
 void
-RouteUI::solo_isolated_toggle(void* src, Gtk::CheckMenuItem* check)
+RouteUI::solo_isolated_toggle(void* /*src*/, Gtk::CheckMenuItem* check)
 {
        bool yn = _route->solo_isolated ();
 
@@ -1223,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);
@@ -1234,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);
@@ -1245,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);
@@ -1256,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);
@@ -1361,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:
@@ -1378,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);
 }
 
@@ -1404,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") {
@@ -1414,3 +1360,55 @@ RouteUI::parameter_changed (string const & p)
        }
 }
 
+void
+RouteUI::step_gain_up ()
+{
+       _route->set_gain (dB_to_coefficient (accurate_coefficient_to_dB (_route->gain_control()->get_value()) + 0.1), this);
+}
+
+void
+RouteUI::page_gain_up ()
+{
+       _route->set_gain (dB_to_coefficient (accurate_coefficient_to_dB (_route->gain_control()->get_value()) + 0.5), this);
+}
+
+void
+RouteUI::step_gain_down ()
+{
+       _route->set_gain (dB_to_coefficient (accurate_coefficient_to_dB (_route->gain_control()->get_value()) - 0.1), this);
+}
+
+void
+RouteUI::page_gain_down ()
+{
+       _route->set_gain (dB_to_coefficient (accurate_coefficient_to_dB (_route->gain_control()->get_value()) - 0.5), this);
+}
+
+void
+RouteUI::open_remote_control_id_dialog ()
+{
+       ArdourDialog dialog (_("Remote Control ID"));
+
+       uint32_t const limit = _session.ntracks() + _session.nbusses () + 4;
+
+       HBox* hbox = manage (new HBox);
+       hbox->set_spacing (6);
+       hbox->pack_start (*manage (new Label (_("Remote control ID:"))));
+       SpinButton* spin = manage (new SpinButton);
+       spin->set_digits (0);
+       spin->set_increments (1, 10);
+       spin->set_range (0, limit);
+       spin->set_value (_route->remote_control_id());
+       hbox->pack_start (*spin);
+       dialog.get_vbox()->pack_start (*hbox);
+
+       dialog.add_button (Stock::CANCEL, RESPONSE_CANCEL);
+       dialog.add_button (Stock::APPLY, RESPONSE_ACCEPT);
+
+       dialog.show_all ();
+       int const r = dialog.run ();
+
+       if (r == RESPONSE_ACCEPT) {
+               _route->set_remote_control_id (spin->get_value_as_int ());
+       }
+}