2 * Copyright (C) 2006-2007 John Anderson
3 * Copyright (C) 2012-2018 Paul Davis <paul@linuxaudiosystems.com>
4 * Copyright (C) 2015-2016 Len Ovens <len@ovenwerks.net>
5 * Copyright (C) 2015-2017 Robin Gareus <robin@gareus.org>
6 * Copyright (C) 2016-2019 Ben Loftis <ben@harrisonconsoles.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 #include "pbd/memento_command.h"
27 #include "ardour/debug.h"
28 #include "ardour/profile.h"
29 #include "ardour/session.h"
30 #include "ardour/route.h"
31 #include "ardour/location.h"
32 #include "ardour/rc_configuration.h"
34 #include "mackie_control_protocol.h"
40 /* handlers for all buttons, broken into a separate file to avoid clutter in
41 * mackie_control_protocol.cc
45 using namespace ARDOUR;
47 using namespace ArdourSurface;
48 using namespace Mackie;
51 MackieControlProtocol::shift_press (Button &)
53 _modifier_state |= MODIFIER_SHIFT;
57 MackieControlProtocol::shift_release (Button &)
59 _modifier_state &= ~MODIFIER_SHIFT;
63 MackieControlProtocol::option_press (Button &)
65 _modifier_state |= MODIFIER_OPTION;
69 MackieControlProtocol::option_release (Button &)
71 _modifier_state &= ~MODIFIER_OPTION;
75 MackieControlProtocol::control_press (Button &)
77 _modifier_state |= MODIFIER_CONTROL;
78 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("CONTROL Press: modifier state now set to %1\n", _modifier_state));
82 MackieControlProtocol::control_release (Button &)
84 _modifier_state &= ~MODIFIER_CONTROL;
85 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("CONTROL Release: modifier state now set to %1\n", _modifier_state));
89 MackieControlProtocol::cmd_alt_press (Button &)
91 _modifier_state |= MODIFIER_CMDALT;
95 MackieControlProtocol::cmd_alt_release (Button &)
97 _modifier_state &= ~MODIFIER_CMDALT;
102 MackieControlProtocol::left_press (Button &)
104 if (_subview_mode != None) {
108 Sorted sorted = get_sorted_stripables();
109 uint32_t strip_cnt = n_strips ();
111 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("bank left with current initial = %1 nstrips = %2 tracks/busses = %3\n",
112 _current_initial_bank, strip_cnt, sorted.size()));
113 if (_current_initial_bank > 0) {
114 (void) switch_banks ((_current_initial_bank - 1) / strip_cnt * strip_cnt);
116 (void) switch_banks (0);
124 MackieControlProtocol::left_release (Button &)
130 MackieControlProtocol::right_press (Button &)
132 if (_subview_mode != None) {
136 Sorted sorted = get_sorted_stripables();
137 uint32_t strip_cnt = n_strips();
138 uint32_t route_cnt = sorted.size();
139 uint32_t max_bank = route_cnt / strip_cnt * strip_cnt;
142 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("bank right with current initial = %1 nstrips = %2 tracks/busses = %3\n",
143 _current_initial_bank, strip_cnt, route_cnt));
145 if (_current_initial_bank < max_bank) {
146 uint32_t new_initial = (_current_initial_bank / strip_cnt * strip_cnt) + strip_cnt;
147 (void) switch_banks (new_initial);
154 MackieControlProtocol::right_release (Button &)
160 MackieControlProtocol::cursor_left_press (Button& )
164 if (main_modifier_state() & MODIFIER_OPTION) {
165 /* reset selected tracks to default vertical zoom */
167 ZoomOut (); /* EMIT SIGNAL */
171 if (main_modifier_state() == MODIFIER_CONTROL) {
173 } else if (main_modifier_state() == MODIFIER_OPTION) {
175 } else if (main_modifier_state() == MODIFIER_SHIFT) {
178 page_fraction = 0.25;
181 ScrollTimeline (-page_fraction);
188 MackieControlProtocol::cursor_left_release (Button&)
194 MackieControlProtocol::cursor_right_press (Button& )
198 if (main_modifier_state() & MODIFIER_OPTION) {
199 /* reset selected tracks to default vertical zoom */
201 ZoomIn (); /* EMIT SIGNAL */
205 if (main_modifier_state() == MODIFIER_CONTROL) {
207 } else if (main_modifier_state() == MODIFIER_OPTION) {
209 } else if (main_modifier_state() == MODIFIER_SHIFT) {
212 page_fraction = 0.25;
215 ScrollTimeline (page_fraction);
222 MackieControlProtocol::cursor_right_release (Button&)
228 MackieControlProtocol::cursor_up_press (Button&)
232 if (main_modifier_state() & MODIFIER_CONTROL) {
233 VerticalZoomInSelected (); /* EMIT SIGNAL */
235 VerticalZoomInAll (); /* EMIT SIGNAL */
238 access_action ("Editor/select-prev-route");
244 MackieControlProtocol::cursor_up_release (Button&)
250 MackieControlProtocol::cursor_down_press (Button&)
253 if (main_modifier_state() & MODIFIER_OPTION) {
254 VerticalZoomOutSelected (); /* EMIT SIGNAL */
256 VerticalZoomOutAll (); /* EMIT SIGNAL */
259 access_action ("Editor/select-next-route");
265 MackieControlProtocol::cursor_down_release (Button&)
271 MackieControlProtocol::channel_left_press (Button &)
273 if (_device_info.single_fader_follows_selection()) {
274 access_action ("Editor/select-prev-route");
278 if (_subview_mode != None) {
281 Sorted sorted = get_sorted_stripables();
282 if (sorted.size() > n_strips()) {
291 MackieControlProtocol::channel_left_release (Button &)
297 MackieControlProtocol::channel_right_press (Button &)
299 if (_device_info.single_fader_follows_selection()) {
300 access_action ("Editor/select-next-route");
304 if (_subview_mode != None) {
307 Sorted sorted = get_sorted_stripables();
308 if (sorted.size() > n_strips()) {
317 MackieControlProtocol::channel_right_release (Button &)
323 MackieControlProtocol::zoom_press (Mackie::Button &)
329 MackieControlProtocol::zoom_release (Mackie::Button &)
331 if (_modifier_state & MODIFIER_ZOOM) {
332 _modifier_state &= ~MODIFIER_ZOOM;
334 _modifier_state |= MODIFIER_ZOOM;
337 return (zoom_mode() ? on : off);
341 MackieControlProtocol::scrub_press (Mackie::Button &)
343 if (!surfaces.empty()) {
344 // surfaces.front()->next_jog_mode ();
345 _master_surface->next_jog_mode ();
351 MackieControlProtocol::scrub_release (Mackie::Button &)
357 MackieControlProtocol::undo_press (Button&)
359 if (main_modifier_state() == MODIFIER_SHIFT) {
368 MackieControlProtocol::undo_release (Button&)
374 MackieControlProtocol::drop_press (Button &)
376 if (main_modifier_state() == MODIFIER_SHIFT) {
380 access_action ("Common/start-range-from-playhead");
386 MackieControlProtocol::drop_release (Button &)
392 MackieControlProtocol::save_press (Button &)
394 if (main_modifier_state() == MODIFIER_SHIFT) {
395 quick_snapshot_switch();
404 MackieControlProtocol::save_release (Button &)
410 MackieControlProtocol::timecode_beats_press (Button &)
412 switch (_timecode_type) {
413 case ARDOUR::AnyTime::BBT:
414 _timecode_type = ARDOUR::AnyTime::Timecode;
416 case ARDOUR::AnyTime::Timecode:
417 _timecode_type = ARDOUR::AnyTime::BBT;
423 update_timecode_beats_led();
429 MackieControlProtocol::timecode_beats_release (Button &)
434 /////////////////////////////////////
436 /////////////////////////////////////
438 MackieControlProtocol::marker_press (Button &)
440 if (main_modifier_state() & MODIFIER_SHIFT) {
441 access_action ("Common/remove-location-from-playhead");
444 _modifier_state |= MODIFIER_MARKER;
445 marker_modifier_consumed_by_button = false;
451 MackieControlProtocol::marker_release (Button &)
453 _modifier_state &= ~MODIFIER_MARKER;
455 if (main_modifier_state() & MODIFIER_SHIFT) {
456 return off; //if shift was held, we already did the action
459 if (marker_modifier_consumed_by_button) {
460 DEBUG_TRACE (DEBUG::MackieControl, "marked modifier consumed by button, ignored\n");
461 /* marker was used a modifier for some other button(s), so do
469 /* Don't add another mark if one exists within 1/100th of a second of
470 * the current position and we're not rolling.
473 samplepos_t where = session->audible_sample();
475 if (session->transport_stopped() && session->locations()->mark_at (where, session->sample_rate() / 100.0)) {
479 session->locations()->next_available_name (markername,"mark");
480 add_marker (markername);
485 /////////////////////////////////////
487 /////////////////////////////////////
490 MackieControlProtocol::stop_press (Button &)
494 if (main_modifier_state() == MODIFIER_SHIFT) {
495 session->midi_panic();
502 MackieControlProtocol::stop_release (Button &)
504 return session->transport_stopped();
508 MackieControlProtocol::play_press (Button &)
510 /* if we're already rolling at normal speed, and we're pressed
511 again, jump back to where we started last time
514 transport_play (session->transport_speed() == 1.0);
519 MackieControlProtocol::play_release (Button &)
525 MackieControlProtocol::record_press (Button &)
527 rec_enable_toggle ();
532 MackieControlProtocol::record_release (Button &)
538 MackieControlProtocol::rewind_press (Button &)
540 if (modifier_state() & MODIFIER_MARKER) {
542 } else if (modifier_state() & MODIFIER_NUDGE) {
543 access_action ("Common/nudge-playhead-backward");
544 } else if (main_modifier_state() & MODIFIER_SHIFT) {
553 MackieControlProtocol::rewind_release (Button &)
559 MackieControlProtocol::ffwd_press (Button &)
561 if (modifier_state() & MODIFIER_MARKER) {
563 } else if (modifier_state() & MODIFIER_NUDGE) {
564 access_action ("Common/nudge-playhead-forward");
565 } else if (main_modifier_state() & MODIFIER_SHIFT) {
574 MackieControlProtocol::ffwd_release (Button &)
580 MackieControlProtocol::loop_press (Button &)
582 if (main_modifier_state() & MODIFIER_SHIFT) {
583 access_action ("Editor/set-loop-from-edit-range");
586 bool was_on = session->get_play_loop();
588 return was_on ? off : on;
593 MackieControlProtocol::loop_release (Button &)
599 MackieControlProtocol::enter_press (Button &)
601 if (main_modifier_state() & MODIFIER_SHIFT) {
602 access_action ("Transport/ToggleFollowEdits");
604 access_action ("Common/select-all-tracks");
610 MackieControlProtocol::enter_release (Button &)
616 MackieControlProtocol::bank_release (Button& b, uint32_t basic_bank_num)
618 if (_subview_mode != None) {
622 uint32_t bank_num = basic_bank_num;
624 if (b.long_press_count() > 0) {
625 bank_num = 8 + basic_bank_num;
628 (void) switch_banks (n_strips() * bank_num);
633 /* F-KEYS are only used for actions that are bound from the control panel; no need to address them here
635 MackieControlProtocol::F1_press (Button &b)
640 MackieControlProtocol::F1_release (Button &b)
645 MackieControlProtocol::F2_press (Button &)
650 MackieControlProtocol::F2_release (Button &b)
655 MackieControlProtocol::F3_press (Button &)
660 MackieControlProtocol::F3_release (Button &b)
665 MackieControlProtocol::F4_press (Button &)
670 MackieControlProtocol::F4_release (Button &b)
675 MackieControlProtocol::F5_press (Button &)
680 MackieControlProtocol::F5_release (Button &)
685 MackieControlProtocol::F6_press (Button &)
690 MackieControlProtocol::F6_release (Button &)
695 MackieControlProtocol::F7_press (Button &)
700 MackieControlProtocol::F7_release (Button &)
705 MackieControlProtocol::F8_press (Button &)
710 MackieControlProtocol::F8_release (Button &)
720 MackieControlProtocol::pan_press (Button &)
722 /* XXX eventually pan may have its own subview mode */
723 set_subview_mode (MackieControlProtocol::None, boost::shared_ptr<Stripable>());
727 MackieControlProtocol::pan_release (Button &)
732 MackieControlProtocol::plugin_press (Button &)
737 MackieControlProtocol::plugin_release (Button &)
739 // Do not do this yet, since it does nothing
740 // set_view_mode (Plugins);
741 return none; /* LED state set by set_view_mode */
744 MackieControlProtocol::eq_press (Button &)
746 set_subview_mode (EQ, first_selected_stripable ());
747 return none; /* led state handled by set_subview_mode() */
751 MackieControlProtocol::eq_release (Button &)
756 MackieControlProtocol::dyn_press (Button &)
758 set_subview_mode (Dynamics, first_selected_stripable ());
759 return none; /* led state handled by set_subview_mode() */
763 MackieControlProtocol::dyn_release (Button &)
768 MackieControlProtocol::flip_press (Button &)
770 if (subview_mode() == MackieControlProtocol::Sends) {
771 if (_flip_mode != Normal) {
772 set_flip_mode (Normal);
774 set_flip_mode (Mirror);
776 return ((_flip_mode != Normal) ? on : off);
783 MackieControlProtocol::flip_release (Button &)
788 MackieControlProtocol::name_value_press (Button &)
793 MackieControlProtocol::name_value_release (Button &)
798 MackieControlProtocol::touch_press (Button &)
803 MackieControlProtocol::touch_release (Button &)
805 set_automation_state (ARDOUR::Touch);
809 MackieControlProtocol::cancel_press (Button &)
811 if (main_modifier_state() & MODIFIER_SHIFT) {
812 access_action ("Transport/ToggleExternalSync");
814 access_action ("Main/Escape");
819 MackieControlProtocol::cancel_release (Button &)
824 MackieControlProtocol::user_a_press (Button &)
826 transport_play (session->transport_speed() == 1.0);
830 MackieControlProtocol::user_a_release (Button &)
835 MackieControlProtocol::user_b_press (Button &)
841 MackieControlProtocol::user_b_release (Button &)
847 MackieControlProtocol::master_fader_touch_press (Mackie::Button &)
849 DEBUG_TRACE (DEBUG::MackieControl, "MackieControlProtocol::master_fader_touch_press\n");
851 Fader* master_fader = _master_surface->master_fader();
853 boost::shared_ptr<AutomationControl> ac = master_fader->control ();
855 master_fader->set_in_use (true);
856 master_fader->start_touch (transport_sample());
861 MackieControlProtocol::master_fader_touch_release (Mackie::Button &)
863 DEBUG_TRACE (DEBUG::MackieControl, "MackieControlProtocol::master_fader_touch_release\n");
865 Fader* master_fader = _master_surface->master_fader();
867 master_fader->set_in_use (false);
868 master_fader->stop_touch (transport_sample());
874 MackieControlProtocol::read_press (Mackie::Button&)
880 MackieControlProtocol::read_release (Mackie::Button&)
882 set_automation_state (ARDOUR::Play);
886 MackieControlProtocol::write_press (Mackie::Button&)
891 MackieControlProtocol::write_release (Mackie::Button&)
893 set_automation_state (ARDOUR::Write);
898 MackieControlProtocol::clearsolo_press (Mackie::Button&)
900 // clears all solos and listens (pfl/afl)
902 if (main_modifier_state() & MODIFIER_SHIFT) {
903 access_action ("Editor/set-session-from-edit-range");
912 MackieControlProtocol::clearsolo_release (Mackie::Button&)
914 //return session->soloing();
919 MackieControlProtocol::track_press (Mackie::Button&)
921 set_subview_mode (TrackView, first_selected_stripable());
925 MackieControlProtocol::track_release (Mackie::Button&)
930 MackieControlProtocol::send_press (Mackie::Button&)
932 set_subview_mode (Sends, first_selected_stripable());
933 return none; /* led state handled by set_subview_mode() */
936 MackieControlProtocol::send_release (Mackie::Button&)
941 MackieControlProtocol::miditracks_press (Mackie::Button&)
946 MackieControlProtocol::miditracks_release (Mackie::Button&)
948 set_view_mode (MidiTracks);
952 MackieControlProtocol::inputs_press (Mackie::Button&)
955 set_view_mode (Mixer); //in Mixbus, this is the same as Global View (avoid dead buttons)
960 MackieControlProtocol::inputs_release (Mackie::Button&)
965 MackieControlProtocol::audiotracks_press (Mackie::Button&)
970 MackieControlProtocol::audiotracks_release (Mackie::Button&)
972 set_view_mode (AudioTracks);
976 MackieControlProtocol::audioinstruments_press (Mackie::Button& b)
979 set_view_mode (MidiTracks); //in Mixbus, we do the same thing as MIDI Tracks ( aviod dead buttons )
985 MackieControlProtocol::audioinstruments_release (Mackie::Button& b)
991 MackieControlProtocol::aux_press (Mackie::Button&)
996 MackieControlProtocol::aux_release (Mackie::Button&)
998 set_view_mode (Auxes);
1002 MackieControlProtocol::busses_press (Mackie::Button&)
1007 MackieControlProtocol::busses_release (Mackie::Button&)
1009 set_view_mode (Busses);
1013 MackieControlProtocol::outputs_press (Mackie::Button&)
1018 MackieControlProtocol::outputs_release (Mackie::Button&)
1020 set_view_mode (Hidden);
1024 MackieControlProtocol::user_press (Mackie::Button&)
1029 MackieControlProtocol::user_release (Mackie::Button&)
1031 set_view_mode (Selected);
1035 MackieControlProtocol::trim_press (Mackie::Button&)
1040 MackieControlProtocol::trim_release (Mackie::Button&)
1045 MackieControlProtocol::latch_press (Mackie::Button&)
1050 MackieControlProtocol::latch_release (Mackie::Button&)
1055 MackieControlProtocol::grp_press (Mackie::Button&)
1060 MackieControlProtocol::grp_release (Mackie::Button&)
1062 /* There is no "Off" button for automation,
1063 so we use Group for this purpose.
1065 set_automation_state (Off);
1069 MackieControlProtocol::nudge_press (Mackie::Button&)
1071 _modifier_state |= MODIFIER_NUDGE;
1072 nudge_modifier_consumed_by_button = false;
1076 MackieControlProtocol::nudge_release (Mackie::Button&)
1078 _modifier_state &= ~MODIFIER_NUDGE;
1080 /* XXX these action names are stupid, because the action can affect
1081 * regions, markers or the playhead depending on selection state.
1084 if (main_modifier_state() & MODIFIER_SHIFT) {
1085 access_action ("Region/nudge-backward");
1087 access_action ("Region/nudge-forward");
1093 MackieControlProtocol::replace_press (Mackie::Button&)
1095 if (main_modifier_state() == MODIFIER_SHIFT) {
1099 access_action ("Common/finish-range-from-playhead");
1104 MackieControlProtocol::replace_release (Mackie::Button&)
1109 MackieControlProtocol::click_press (Mackie::Button&)
1111 if (main_modifier_state() & MODIFIER_SHIFT) {
1112 access_action ("Editor/set-punch-from-edit-range");
1115 bool state = !Config->get_clicking();
1116 Config->set_clicking (state);
1121 MackieControlProtocol::click_release (Mackie::Button&)
1126 MackieControlProtocol::view_press (Mackie::Button&)
1128 set_view_mode (Mixer);
1132 MackieControlProtocol::view_release (Mackie::Button&)