mackie: fix behaviour of clear solo button
[ardour.git] / libs / surfaces / mackie / mcp_buttons.cc
index 60de07480e3cd130a133e782d892339d11a44f9e..2e2c936f9110a2274ccada68b5f38daa64f1885d 100644 (file)
@@ -102,15 +102,15 @@ MackieControlProtocol::left_press (Button &)
                return none;
        }
 
-       Sorted sorted = get_sorted_routes();
+       Sorted sorted = get_sorted_stripables();
        uint32_t strip_cnt = n_strips ();
 
        DEBUG_TRACE (DEBUG::MackieControl, string_compose ("bank left with current initial = %1 nstrips = %2 tracks/busses = %3\n",
                                                           _current_initial_bank, strip_cnt, sorted.size()));
        if (_current_initial_bank > 0) {
-               switch_banks ((_current_initial_bank - 1) / strip_cnt * strip_cnt);
+               (void) switch_banks ((_current_initial_bank - 1) / strip_cnt * strip_cnt);
        } else {
-               switch_banks (0);
+               (void) switch_banks (0);
        }
 
 
@@ -120,7 +120,7 @@ MackieControlProtocol::left_press (Button &)
 LedState
 MackieControlProtocol::left_release (Button &)
 {
-       return off;
+       return none;
 }
 
 LedState
@@ -130,7 +130,7 @@ MackieControlProtocol::right_press (Button &)
                return none;
        }
 
-       Sorted sorted = get_sorted_routes();
+       Sorted sorted = get_sorted_stripables();
        uint32_t strip_cnt = n_strips();
        uint32_t route_cnt = sorted.size();
        uint32_t max_bank = route_cnt / strip_cnt * strip_cnt;
@@ -141,23 +141,16 @@ MackieControlProtocol::right_press (Button &)
 
        if (_current_initial_bank < max_bank) {
                uint32_t new_initial = (_current_initial_bank / strip_cnt * strip_cnt) + strip_cnt;
-
-               switch_banks (new_initial);
-       } else {
-               switch_banks (max_bank);
+               (void) switch_banks (new_initial);
        }
 
-       return on;
+       return none;
 }
 
 LedState
 MackieControlProtocol::right_release (Button &)
 {
-       if (zoom_mode()) {
-
-       }
-
-       return off;
+       return none;
 }
 
 LedState
@@ -239,7 +232,7 @@ MackieControlProtocol::cursor_up_press (Button&)
                        VerticalZoomInAll (); /* EMIT SIGNAL */
                }
        } else {
-               StepTracksUp (); /* EMIT SIGNAL */
+               access_action ("Editor/select-prev-route");
        }
        return off;
 }
@@ -260,7 +253,7 @@ MackieControlProtocol::cursor_down_press (Button&)
                        VerticalZoomOutAll (); /* EMIT SIGNAL */
                }
        } else {
-               StepTracksDown (); /* EMIT SIGNAL */
+               access_action ("Editor/select-next-route");
        }
        return off;
 }
@@ -277,7 +270,7 @@ MackieControlProtocol::channel_left_press (Button &)
        if (_subview_mode != None) {
                return none;
        }
-       Sorted sorted = get_sorted_routes();
+       Sorted sorted = get_sorted_stripables();
        if (sorted.size() > n_strips()) {
                prev_track();
                return on;
@@ -298,7 +291,7 @@ MackieControlProtocol::channel_right_press (Button &)
        if (_subview_mode != None) {
                return none;
        }
-       Sorted sorted = get_sorted_routes();
+       Sorted sorted = get_sorted_stripables();
        if (sorted.size() > n_strips()) {
                next_track();
                return on;
@@ -350,44 +343,54 @@ MackieControlProtocol::scrub_release (Mackie::Button &)
 LedState
 MackieControlProtocol::undo_press (Button&)
 {
-       if (main_modifier_state() & MODIFIER_SHIFT) {
-               Redo(); /* EMIT SIGNAL */
+       if (main_modifier_state() == MODIFIER_SHIFT) {
+               redo();
        } else {
-               Undo(); /* EMIT SIGNAL */
+               undo ();
        }
-       return off;
+       return none;
 }
 
 LedState
 MackieControlProtocol::undo_release (Button&)
 {
-       return off;
+       return none;
 }
 
 LedState
 MackieControlProtocol::drop_press (Button &)
 {
-       session->remove_last_capture();
-       return on;
+       if (main_modifier_state() == MODIFIER_SHIFT) {
+               toggle_punch_in();
+               return none;
+       } else {
+               access_action ("Editor/start-range-from-playhead");
+       }
+       return none;
 }
 
 LedState
 MackieControlProtocol::drop_release (Button &)
 {
-       return off;
+       return none;
 }
 
 LedState
 MackieControlProtocol::save_press (Button &)
 {
-       session->save_state ("");
-       return on;
+       if (main_modifier_state() == MODIFIER_SHIFT) {
+               quick_snapshot_switch();
+       } else {
+               save_state ();
+       }
+
+       return none;
 }
 
 LedState
 MackieControlProtocol::save_release (Button &)
 {
-       return off;
+       return none;
 }
 
 LedState
@@ -421,13 +424,37 @@ MackieControlProtocol::timecode_beats_release (Button &)
 LedState
 MackieControlProtocol::marker_press (Button &)
 {
+       if (main_modifier_state() & MODIFIER_SHIFT) {
+               access_action ("Editor/remove-location-from-playhead");
+               return off;
+       } else {
+               _modifier_state |= MODIFIER_MARKER;
+               marker_modifier_consumed_by_button = false;
+               return on;
+       }
+}
+
+LedState
+MackieControlProtocol::marker_release (Button &)
+{
+       _modifier_state &= ~MODIFIER_MARKER;
+
+       if (main_modifier_state() & MODIFIER_SHIFT)
+               return off;   //if shift was held, we already did the action
+
+       if (marker_modifier_consumed_by_button) {
+               /* marker was used a modifier for some other button(s), so do
+                  nothing
+               */
+               return off;
+       }
+
        string markername;
 
        /* Don't add another mark if one exists within 1/100th of a second of
         * the current position and we're not rolling.
         */
 
-
        framepos_t where = session->audible_frame();
 
        if (session->transport_stopped() && session->locations()->mark_at (where, session->frame_rate() / 100.0)) {
@@ -437,12 +464,6 @@ MackieControlProtocol::marker_press (Button &)
        session->locations()->next_available_name (markername,"marker");
        add_marker (markername);
 
-       return on;
-}
-
-LedState
-MackieControlProtocol::marker_release (Button &)
-{
        return off;
 }
 
@@ -454,6 +475,11 @@ LedState
 MackieControlProtocol::stop_press (Button &)
 {
        transport_stop ();
+
+       if (main_modifier_state() == MODIFIER_SHIFT) {
+               session->midi_panic();
+       }
+
        return on;
 }
 
@@ -496,7 +522,11 @@ MackieControlProtocol::record_release (Button &)
 LedState
 MackieControlProtocol::rewind_press (Button &)
 {
-       if (main_modifier_state() == MODIFIER_CONTROL) {
+       if (modifier_state() & MODIFIER_MARKER) {
+               prev_marker ();
+       } else if (modifier_state() & MODIFIER_NUDGE) {
+               access_action ("Editor/nudge-playhead-backward");
+       } else if (main_modifier_state() & MODIFIER_SHIFT) {
                goto_start ();
        } else {
                rewind ();
@@ -513,7 +543,11 @@ MackieControlProtocol::rewind_release (Button &)
 LedState
 MackieControlProtocol::ffwd_press (Button &)
 {
-       if (main_modifier_state() == MODIFIER_CONTROL) {
+       if (modifier_state() & MODIFIER_MARKER) {
+               next_marker ();
+       } else if (modifier_state() & MODIFIER_NUDGE) {
+               access_action ("Editor/nudge-playhead-forward");
+       } else if (main_modifier_state() & MODIFIER_SHIFT) {
                goto_end();
        } else {
                ffwd ();
@@ -530,9 +564,14 @@ MackieControlProtocol::ffwd_release (Button &)
 LedState
 MackieControlProtocol::loop_press (Button &)
 {
-       bool was_on = session->get_play_loop();
-       session->request_play_loop (!was_on);
-       return was_on ? off : on;
+       if (main_modifier_state() & MODIFIER_SHIFT) {
+               access_action ("Editor/set-loop-from-edit-range");
+               return off;
+       } else {
+               bool was_on = session->get_play_loop();
+               session->request_play_loop (!was_on);
+               return was_on ? off : on;
+       }
 }
 
 LedState
@@ -541,31 +580,21 @@ MackieControlProtocol::loop_release (Button &)
        return none;
 }
 
-LedState
-MackieControlProtocol::clicking_press (Button &)
-{
-       bool state = !Config->get_clicking();
-       Config->set_clicking (state);
-       return state;
-}
-
-LedState
-MackieControlProtocol::clicking_release (Button &)
-{
-       return Config->get_clicking();
-}
-
 LedState
 MackieControlProtocol::enter_press (Button &)
 {
-       Enter(); /* EMIT SIGNAL */
-       return off;
+       if (main_modifier_state() & MODIFIER_SHIFT) {
+               access_action ("Transport/ToggleFollowEdits");
+       } else {
+               access_action ("Editor/select-all-tracks");
+       }
+       return none;
 }
 
 LedState
 MackieControlProtocol::enter_release (Button &)
 {
-       return off;
+       return none;
 }
 
 LedState
@@ -581,7 +610,7 @@ MackieControlProtocol::bank_release (Button& b, uint32_t basic_bank_num)
                bank_num = 8 + basic_bank_num;
        }
 
-       switch_banks (n_strips() * bank_num);
+       (void) switch_banks (n_strips() * bank_num);
 
        return on;
 }
@@ -673,7 +702,8 @@ MackieControlProtocol::F8_release (Button &)
 LedState
 MackieControlProtocol::pan_press (Button &)
 {
-       set_pot_mode (Pan);
+       /* XXX eventually pan may have its own subview mode */
+       set_subview_mode (MackieControlProtocol::None, boost::shared_ptr<Stripable>());
        return none;
 }
 LedState
@@ -696,8 +726,7 @@ MackieControlProtocol::plugin_release (Button &)
 LedState
 MackieControlProtocol::eq_press (Button &)
 {
-       boost::shared_ptr<Route> r = first_selected_route ();
-       set_subview_mode (EQ, r);
+       set_subview_mode (EQ, first_selected_stripable ());
        return none; /* led state handled by set_subview_mode() */
 
 }
@@ -709,8 +738,7 @@ MackieControlProtocol::eq_release (Button &)
 LedState
 MackieControlProtocol::dyn_press (Button &)
 {
-       boost::shared_ptr<Route> r = first_selected_route ();
-       set_subview_mode (Dynamics, r);
+       set_subview_mode (Dynamics, first_selected_stripable ());
        return none; /* led state handled by set_subview_mode() */
 }
 
@@ -722,13 +750,18 @@ MackieControlProtocol::dyn_release (Button &)
 LedState
 MackieControlProtocol::flip_press (Button &)
 {
-       if (_flip_mode != Normal) {
-               set_flip_mode (Normal);
-       } else {
-               set_flip_mode (Mirror);
+       if (subview_mode() == MackieControlProtocol::Sends) {
+               if (_flip_mode != Normal) {
+                       set_flip_mode (Normal);
+               } else {
+                       set_flip_mode (Mirror);
+               }
+               return ((_flip_mode != Normal) ? on : off);
        }
-       return ((_flip_mode != Normal) ? on : off);
+
+       return none;
 }
+
 LedState
 MackieControlProtocol::flip_release (Button &)
 {
@@ -747,22 +780,28 @@ MackieControlProtocol::name_value_release (Button &)
 LedState
 MackieControlProtocol::touch_press (Button &)
 {
-       return off;
+       return none;
 }
 LedState
 MackieControlProtocol::touch_release (Button &)
 {
-       return off;
+       set_automation_state (ARDOUR::Touch);
+       return none;
 }
 LedState
 MackieControlProtocol::cancel_press (Button &)
 {
-       return off;
+       if (main_modifier_state() & MODIFIER_SHIFT) {
+               access_action ("Transport/ToggleExternalSync");
+       } else {
+               access_action ("Main/Escape");
+       }
+       return none;
 }
 LedState
 MackieControlProtocol::cancel_release (Button &)
 {
-       return off;
+       return none;
 }
 LedState
 MackieControlProtocol::user_a_press (Button &)
@@ -817,14 +856,14 @@ MackieControlProtocol::master_fader_touch_release (Mackie::Button &)
 Mackie::LedState
 MackieControlProtocol::read_press (Mackie::Button&)
 {
-       _metering_active = !_metering_active;
-       notify_metering_state_changed ();
-       return _metering_active;
+       return none;
 }
+
 Mackie::LedState
 MackieControlProtocol::read_release (Mackie::Button&)
 {
-       return _metering_active;
+       set_automation_state (ARDOUR::Play);
+       return none;
 }
 Mackie::LedState
 MackieControlProtocol::write_press (Mackie::Button&)
@@ -834,6 +873,7 @@ MackieControlProtocol::write_press (Mackie::Button&)
 Mackie::LedState
 MackieControlProtocol::write_release (Mackie::Button&)
 {
+       set_automation_state (ARDOUR::Write);
        return none;
 }
 
@@ -841,8 +881,16 @@ Mackie::LedState
 MackieControlProtocol::clearsolo_press (Mackie::Button&)
 {
        // clears all solos and listens (pfl/afl)
-       session->set_solo (session->get_routes(), false);
-       session->set_listen (session->get_routes(), false);
+
+       if (main_modifier_state() & MODIFIER_SHIFT) {
+               access_action ("Editor/set-session-from-edit-range");
+               return none;
+       }
+
+       if (session) {
+               session->set_controls (route_list_to_control_list (session->get_routes(), &Stripable::solo_control), 0.0, Controllable::NoGroup);
+               session->clear_all_solo_state (session->get_routes()); 
+       }
        return none;
 }
 
@@ -856,7 +904,7 @@ MackieControlProtocol::clearsolo_release (Mackie::Button&)
 Mackie::LedState
 MackieControlProtocol::track_press (Mackie::Button&)
 {
-       set_pot_mode (Trim);
+       set_subview_mode (TrackView, first_selected_stripable());
        return none;
 }
 Mackie::LedState
@@ -867,8 +915,7 @@ MackieControlProtocol::track_release (Mackie::Button&)
 Mackie::LedState
 MackieControlProtocol::send_press (Mackie::Button&)
 {
-       boost::shared_ptr<Route> r = first_selected_route ();
-       set_subview_mode (Sends, r);
+       set_subview_mode (Sends, first_selected_stripable());
        return none; /* led state handled by set_subview_mode() */
 }
 Mackie::LedState
@@ -911,13 +958,13 @@ MackieControlProtocol::audiotracks_release (Mackie::Button&)
 Mackie::LedState
 MackieControlProtocol::audioinstruments_press (Mackie::Button& b)
 {
-       return dyn_press (b);
+       return none;
 }
 
 Mackie::LedState
 MackieControlProtocol::audioinstruments_release (Mackie::Button& b)
 {
-       return dyn_release (b);
+       return none;
 
 }
 Mackie::LedState
@@ -992,21 +1039,45 @@ MackieControlProtocol::grp_press (Mackie::Button&)
 Mackie::LedState
 MackieControlProtocol::grp_release (Mackie::Button&)
 {
+       /* There is no "Off" button for automation,
+          so we use Group for this purpose.
+       */
+       set_automation_state (Off);
        return none;
 }
 Mackie::LedState
 MackieControlProtocol::nudge_press (Mackie::Button&)
 {
-       return none;
+       _modifier_state |= MODIFIER_NUDGE;
+       nudge_modifier_consumed_by_button = false;
+       return on;
 }
 Mackie::LedState
 MackieControlProtocol::nudge_release (Mackie::Button&)
 {
-       return none;
+       _modifier_state &= ~MODIFIER_NUDGE;
+
+       /* XXX these action names are stupid, because the action can affect
+        * regions, markers or the playhead depending on selection state.
+        */
+
+       if (main_modifier_state() & MODIFIER_SHIFT) {
+               access_action ("Region/nudge-backward");
+       } else {
+               access_action ("Region/nudge-forward");
+       }
+
+       return off;
 }
 Mackie::LedState
 MackieControlProtocol::replace_press (Mackie::Button&)
 {
+       if (main_modifier_state() == MODIFIER_SHIFT) {
+               toggle_punch_out();
+               return none;
+       } else {
+               access_action ("Editor/finish-range-from-playhead");
+       }
        return none;
 }
 Mackie::LedState
@@ -1017,7 +1088,14 @@ MackieControlProtocol::replace_release (Mackie::Button&)
 Mackie::LedState
 MackieControlProtocol::click_press (Mackie::Button&)
 {
-       return none;
+       if (main_modifier_state() & MODIFIER_SHIFT) {
+               access_action ("Editor/set-punch-from-edit-range");
+               return off;
+       } else {
+               bool state = !Config->get_clicking();
+               Config->set_clicking (state);
+               return state;
+       }
 }
 Mackie::LedState
 MackieControlProtocol::click_release (Mackie::Button&)