Cope with drags of selections that include regions on hidden tracks (#3493).
[ardour.git] / gtk2_ardour / mixer_strip.cc
index 2b260bcb5af15df74252e23166d7be6edd27c266..5ce4caa3af1b74866a95e2073aa5fab38ccc17e8 100644 (file)
@@ -87,6 +87,7 @@ MixerStrip::MixerStrip (Mixer_UI& mx, Session* sess, bool in_mixer)
        , panners (sess)
        , button_table (3, 1)
        , solo_led_table (2, 2)
+       , top_button_table (1, 2)
        , middle_button_table (1, 2)
        , bottom_button_table (1, 2)
        , meter_point_label (_("pre"))
@@ -127,7 +128,6 @@ MixerStrip::init ()
        input_selector = 0;
        output_selector = 0;
        group_menu = 0;
-       _marked_for_display = false;
        route_ops_menu = 0;
        ignore_comment_edit = false;
        ignore_toggle = false;
@@ -185,6 +185,9 @@ MixerStrip::init ()
        mute_button->set_name ("MixerMuteButton");
        solo_button->set_name ("MixerSoloButton");
 
+       monitor_input_button->set_name ("MixerMonitorInputButton");
+       monitor_disk_button->set_name ("MixerMonitorInputButton");
+
         solo_isolated_led = manage (new LED);
         solo_isolated_led->show ();
         solo_isolated_led->set_diameter (6);
@@ -218,8 +221,14 @@ MixerStrip::init ()
         solo_led_table.attach (*solo_isolated_led, 1, 2, 0, 1, Gtk::FILL, Gtk::FILL);
        solo_led_table.attach (*_safe_label, 0, 1, 1, 2, Gtk::FILL, Gtk::FILL);
         solo_led_table.attach (*solo_safe_led, 1, 2, 1, 2, Gtk::FILL, Gtk::FILL);
-
         solo_led_table.show ();
+
+       top_button_table.set_homogeneous (true);
+       top_button_table.set_spacings (0);
+       top_button_table.attach (*monitor_input_button, 0, 1, 0, 1);
+        top_button_table.attach (*monitor_disk_button, 1, 2, 0, 1);
+       top_button_table.show ();
+
        below_panner_box.set_border_width (2);
        below_panner_box.set_spacing (2);
         below_panner_box.pack_end (solo_led_table, false, false);
@@ -272,6 +281,7 @@ MixerStrip::init ()
        global_vpacker.pack_start (button_table, Gtk::PACK_SHRINK);
        global_vpacker.pack_start (processor_box, true, true);
        global_vpacker.pack_start (panners, Gtk::PACK_SHRINK);
+       global_vpacker.pack_start (top_button_table, Gtk::PACK_SHRINK);
        global_vpacker.pack_start (below_panner_box, Gtk::PACK_SHRINK);
        global_vpacker.pack_start (middle_button_table, Gtk::PACK_SHRINK);
        global_vpacker.pack_start (gpm, Gtk::PACK_SHRINK);
@@ -335,7 +345,7 @@ MixerStrip::init ()
        SwitchIO.connect (sigc::mem_fun (*this, &MixerStrip::switch_io));
 
        AudioEngine::instance()->PortConnectedOrDisconnected.connect (
-               *this, invalidator (*this), boost::bind (&MixerStrip::port_connected_or_disconnected, this, _1, _2), gui_context ()
+               *this, invalidator (*this), boost::bind (&MixerStrip::port_connected_or_disconnected, this, _1, _3), gui_context ()
                );
 }
 
@@ -376,10 +386,6 @@ MixerStrip::set_route (boost::shared_ptr<Route> rt)
 
        revert_to_default_display ();
 
-       if (set_color_from_route()) {
-               set_color (unique_random_color());
-       }
-
        if (route()->is_master()) {
                solo_button->hide ();
                below_panner_box.hide ();
@@ -401,13 +407,22 @@ MixerStrip::set_route (boost::shared_ptr<Route> rt)
                global_vpacker.pack_start (*spacer, false, false);
        }
 
+       if (is_track()) {
+               monitor_input_button->show ();
+               monitor_disk_button->show ();
+       } else {
+               monitor_input_button->hide();
+               monitor_disk_button->hide ();
+       }
+
        if (is_midi_track()) {
                if (midi_input_enable_button == 0) {
                        Image* img = manage (new Image (get_icon (X_("midi_socket_small"))));
                        midi_input_enable_button = manage (new StatefulToggleButton);
                        midi_input_enable_button->set_name ("MixerMidiInputEnableButton");
                        midi_input_enable_button->set_image (*img);
-                       midi_input_enable_button->signal_toggled().connect (sigc::mem_fun (*this, &MixerStrip::midi_input_toggled));
+                       midi_input_enable_button->signal_button_press_event().connect (sigc::mem_fun (*this, &MixerStrip::input_active_button_press), false);
+                       midi_input_enable_button->signal_button_release_event().connect (sigc::mem_fun (*this, &MixerStrip::input_active_button_release), false);
                        ARDOUR_UI::instance()->set_tip (midi_input_enable_button, _("Enable/Disable MIDI input"));
                } else {
                        input_button_box.remove (*midi_input_enable_button);
@@ -460,7 +475,7 @@ MixerStrip::set_route (boost::shared_ptr<Route> rt)
        _route->meter_change.connect (route_connections, invalidator (*this), bind (&MixerStrip::meter_changed, this), gui_context());
        _route->route_group_changed.connect (route_connections, invalidator (*this), boost::bind (&MixerStrip::route_group_changed, this), gui_context());
 
-       if (_route->panner()) {
+       if (_route->panner_shell()) {
                _route->panner_shell()->Changed.connect (route_connections, invalidator (*this), boost::bind (&MixerStrip::connect_to_pan, this), gui_context());
        }
 
@@ -469,7 +484,6 @@ MixerStrip::set_route (boost::shared_ptr<Route> rt)
        }
 
        _route->comment_changed.connect (route_connections, invalidator (*this), ui_bind (&MixerStrip::comment_changed, this, _1), gui_context());
-       _route->gui_changed.connect (route_connections, invalidator (*this), ui_bind (&MixerStrip::route_gui_changed, this, _1, _2), gui_context());
 
        set_stuff_from_route ();
 
@@ -526,25 +540,11 @@ MixerStrip::set_route (boost::shared_ptr<Route> rt)
 void
 MixerStrip::set_stuff_from_route ()
 {
-       XMLProperty *prop;
-
-       ensure_xml_node ();
-
        /* if width is not set, it will be set by the MixerUI or editor */
 
-       if ((prop = xml_node->property ("strip-width")) != 0) {
-               set_width_enum (Width (string_2_enum (prop->value(), _width)), this);
-       }
-
-       if ((prop = xml_node->property ("shown-mixer")) != 0) {
-               if (prop->value() == "no") {
-                       _marked_for_display = false;
-               } else {
-                       _marked_for_display = true;
-               }
-       } else {
-               /* backwards compatibility */
-               _marked_for_display = true;
+       string str = gui_property ("strip-width");
+       if (!str.empty()) {
+               set_width_enum (Width (string_2_enum (str, _width)), this);
        }
 }
 
@@ -560,12 +560,10 @@ MixerStrip::set_width_enum (Width w, void* owner)
 
        _width_owner = owner;
 
-       ensure_xml_node ();
-
        _width = w;
 
        if (_width_owner == this) {
-               xml_node->add_property ("strip-width", enum_2_string (_width));
+               set_gui_property ("strip-width", enum_2_string (_width));
        }
 
        set_button_names ();
@@ -634,12 +632,10 @@ MixerStrip::set_packed (bool yn)
 {
        _packed = yn;
 
-       ensure_xml_node ();
-
        if (_packed) {
-               xml_node->add_property ("shown-mixer", "yes");
+               set_gui_property ("visible", true);
        } else {
-               xml_node->add_property ("shown-mixer", "no");
+               set_gui_property ("visible", false);
        }
 }
 
@@ -936,7 +932,7 @@ MixerStrip::update_diskstream_display ()
                        input_selector->hide_all ();
                }
 
-               show_route_color ();
+               route_color_changed ();
 
        } else {
 
@@ -1335,21 +1331,8 @@ MixerStrip::route_group_changed ()
        }
 }
 
-
 void
-MixerStrip::route_gui_changed (string what_changed, void*)
-{
-       ENSURE_GUI_THREAD (*this, &MixerStrip::route_gui_changed, what_changed, ignored)
-
-       if (what_changed == "color") {
-               if (set_color_from_route () == 0) {
-                       show_route_color ();
-               }
-       }
-}
-
-void
-MixerStrip::show_route_color ()
+MixerStrip::route_color_changed ()
 {
        name_button.modify_bg (STATE_NORMAL, color());
        top_event_box.modify_bg (STATE_NORMAL, color());
@@ -1679,6 +1662,8 @@ MixerStrip::drop_send ()
        rec_enable_button->set_sensitive (true);
        solo_isolated_led->set_sensitive (true);
        solo_safe_led->set_sensitive (true);
+       monitor_input_button->set_sensitive (true);
+       monitor_disk_button->set_sensitive (true);
 }
 
 void
@@ -1715,6 +1700,8 @@ MixerStrip::show_send (boost::shared_ptr<Send> send)
        rec_enable_button->set_sensitive (false);
        solo_isolated_led->set_sensitive (false);
        solo_safe_led->set_sensitive (false);
+       monitor_input_button->set_sensitive (false);
+       monitor_disk_button->set_sensitive (false);
 
        if (boost::dynamic_pointer_cast<InternalSend>(send)) {
                output_button.set_sensitive (false);
@@ -1750,6 +1737,8 @@ MixerStrip::set_button_names ()
        case Wide:
                rec_enable_button_label.set_text (_("Rec"));
                mute_button_label.set_text (_("Mute"));
+               monitor_input_button_label.set_text (_("In"));
+               monitor_disk_button_label.set_text (_("Disk"));
                if (_route && _route->solo_safe()) {
                        solo_button_label.set_text (X_("!"));
                } else {
@@ -1771,6 +1760,8 @@ MixerStrip::set_button_names ()
        default:
                rec_enable_button_label.set_text (_("R"));
                mute_button_label.set_text (_("M"));
+               monitor_input_button_label.set_text (_("I"));
+               monitor_disk_button_label.set_text (_("D"));
                if (_route && _route->solo_safe()) {
                        solo_button_label.set_text (X_("!"));
                        if (!Config->get_solo_control_is_listen_control()) {
@@ -1915,16 +1906,40 @@ MixerStrip::hide_things ()
        processor_box.hide_things ();
 }
 
-void
-MixerStrip::midi_input_toggled ()
+bool
+MixerStrip::input_active_button_press (GdkEventButton*)
+{
+       /* nothing happens on press */
+       return true;
+}
+
+bool
+MixerStrip::input_active_button_release (GdkEventButton* ev)
 {
        boost::shared_ptr<MidiTrack> mt = midi_track ();
 
        if (!mt) {
-               return;
+               return true;
+       }
+
+       if (mt->input_active()) {
+               if (Keyboard::modifier_state_contains (ev->state, Keyboard::ModifierMask (Keyboard::PrimaryModifier|Keyboard::SecondaryModifier))) {
+                       /* turn all other tracks using this input off */
+                       _session->set_exclusive_input_active (mt, false);
+               } else {
+                       mt->set_input_active (false);
+               }
+
+       } else {
+               if (Keyboard::modifier_state_contains (ev->state, Keyboard::ModifierMask (Keyboard::PrimaryModifier|Keyboard::SecondaryModifier))) {
+                       /* turn all other tracks using this input on */
+                       _session->set_exclusive_input_active (mt, true);
+               } else {
+                       mt->set_input_active (true);
+               }
        }
 
-       mt->set_input_active (midi_input_enable_button->get_active());
+       return true;
 }
 
 void
@@ -1936,3 +1951,9 @@ MixerStrip::midi_input_status_changed ()
                midi_input_enable_button->set_active (mt->input_active ());
        }
 }
+
+string
+MixerStrip::state_id () const
+{
+       return string_compose ("strip %1", _route->id().to_s());
+}