2 Copyright (C) 2006,2007 John Anderson
3 Copyright (C) 2012 Paul Davis
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include "pbd/memento_command.h"
24 #include "ardour/debug.h"
25 #include "ardour/profile.h"
26 #include "ardour/session.h"
27 #include "ardour/route.h"
28 #include "ardour/location.h"
29 #include "ardour/rc_configuration.h"
31 #include "mackie_control_protocol.h"
37 /* handlers for all buttons, broken into a separate file to avoid clutter in
38 * mackie_control_protocol.cc
42 using namespace ARDOUR;
44 using namespace ArdourSurface;
45 using namespace Mackie;
48 MackieControlProtocol::shift_press (Button &)
50 _modifier_state |= MODIFIER_SHIFT;
54 MackieControlProtocol::shift_release (Button &)
56 _modifier_state &= ~MODIFIER_SHIFT;
60 MackieControlProtocol::option_press (Button &)
62 _modifier_state |= MODIFIER_OPTION;
66 MackieControlProtocol::option_release (Button &)
68 _modifier_state &= ~MODIFIER_OPTION;
72 MackieControlProtocol::control_press (Button &)
74 _modifier_state |= MODIFIER_CONTROL;
75 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("CONTROL Press: modifier state now set to %1\n", _modifier_state));
79 MackieControlProtocol::control_release (Button &)
81 _modifier_state &= ~MODIFIER_CONTROL;
82 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("CONTROL Release: modifier state now set to %1\n", _modifier_state));
86 MackieControlProtocol::cmd_alt_press (Button &)
88 _modifier_state |= MODIFIER_CMDALT;
92 MackieControlProtocol::cmd_alt_release (Button &)
94 _modifier_state &= ~MODIFIER_CMDALT;
99 MackieControlProtocol::left_press (Button &)
101 if (_subview_mode != None) {
105 Sorted sorted = get_sorted_stripables();
106 uint32_t strip_cnt = n_strips ();
108 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("bank left with current initial = %1 nstrips = %2 tracks/busses = %3\n",
109 _current_initial_bank, strip_cnt, sorted.size()));
110 if (_current_initial_bank > 0) {
111 (void) switch_banks ((_current_initial_bank - 1) / strip_cnt * strip_cnt);
113 (void) switch_banks (0);
121 MackieControlProtocol::left_release (Button &)
127 MackieControlProtocol::right_press (Button &)
129 if (_subview_mode != None) {
133 Sorted sorted = get_sorted_stripables();
134 uint32_t strip_cnt = n_strips();
135 uint32_t route_cnt = sorted.size();
136 uint32_t max_bank = route_cnt / strip_cnt * strip_cnt;
139 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("bank right with current initial = %1 nstrips = %2 tracks/busses = %3\n",
140 _current_initial_bank, strip_cnt, route_cnt));
142 if (_current_initial_bank < max_bank) {
143 uint32_t new_initial = (_current_initial_bank / strip_cnt * strip_cnt) + strip_cnt;
144 (void) switch_banks (new_initial);
151 MackieControlProtocol::right_release (Button &)
157 MackieControlProtocol::cursor_left_press (Button& )
161 if (main_modifier_state() & MODIFIER_OPTION) {
162 /* reset selected tracks to default vertical zoom */
164 ZoomOut (); /* EMIT SIGNAL */
168 if (main_modifier_state() == MODIFIER_CONTROL) {
170 } else if (main_modifier_state() == MODIFIER_OPTION) {
172 } else if (main_modifier_state() == MODIFIER_SHIFT) {
175 page_fraction = 0.25;
178 ScrollTimeline (-page_fraction);
185 MackieControlProtocol::cursor_left_release (Button&)
191 MackieControlProtocol::cursor_right_press (Button& )
195 if (main_modifier_state() & MODIFIER_OPTION) {
196 /* reset selected tracks to default vertical zoom */
198 ZoomIn (); /* EMIT SIGNAL */
202 if (main_modifier_state() == MODIFIER_CONTROL) {
204 } else if (main_modifier_state() == MODIFIER_OPTION) {
206 } else if (main_modifier_state() == MODIFIER_SHIFT) {
209 page_fraction = 0.25;
212 ScrollTimeline (page_fraction);
219 MackieControlProtocol::cursor_right_release (Button&)
225 MackieControlProtocol::cursor_up_press (Button&)
229 if (main_modifier_state() & MODIFIER_CONTROL) {
230 VerticalZoomInSelected (); /* EMIT SIGNAL */
232 VerticalZoomInAll (); /* EMIT SIGNAL */
235 access_action ("Editor/select-prev-route");
241 MackieControlProtocol::cursor_up_release (Button&)
247 MackieControlProtocol::cursor_down_press (Button&)
250 if (main_modifier_state() & MODIFIER_OPTION) {
251 VerticalZoomOutSelected (); /* EMIT SIGNAL */
253 VerticalZoomOutAll (); /* EMIT SIGNAL */
256 access_action ("Editor/select-next-route");
262 MackieControlProtocol::cursor_down_release (Button&)
268 MackieControlProtocol::channel_left_press (Button &)
270 if (_subview_mode != None) {
273 Sorted sorted = get_sorted_stripables();
274 if (sorted.size() > n_strips()) {
283 MackieControlProtocol::channel_left_release (Button &)
289 MackieControlProtocol::channel_right_press (Button &)
291 if (_subview_mode != None) {
294 Sorted sorted = get_sorted_stripables();
295 if (sorted.size() > n_strips()) {
304 MackieControlProtocol::channel_right_release (Button &)
310 MackieControlProtocol::zoom_press (Mackie::Button &)
316 MackieControlProtocol::zoom_release (Mackie::Button &)
318 if (_modifier_state & MODIFIER_ZOOM) {
319 _modifier_state &= ~MODIFIER_ZOOM;
321 _modifier_state |= MODIFIER_ZOOM;
324 return (zoom_mode() ? on : off);
328 MackieControlProtocol::scrub_press (Mackie::Button &)
330 if (!surfaces.empty()) {
331 // surfaces.front()->next_jog_mode ();
332 _master_surface->next_jog_mode ();
338 MackieControlProtocol::scrub_release (Mackie::Button &)
344 MackieControlProtocol::undo_press (Button&)
346 if (main_modifier_state() == MODIFIER_SHIFT) {
355 MackieControlProtocol::undo_release (Button&)
361 MackieControlProtocol::drop_press (Button &)
363 if (main_modifier_state() == MODIFIER_SHIFT) {
367 access_action ("Common/start-range-from-playhead");
373 MackieControlProtocol::drop_release (Button &)
379 MackieControlProtocol::save_press (Button &)
381 if (main_modifier_state() == MODIFIER_SHIFT) {
382 quick_snapshot_switch();
391 MackieControlProtocol::save_release (Button &)
397 MackieControlProtocol::timecode_beats_press (Button &)
399 switch (_timecode_type) {
400 case ARDOUR::AnyTime::BBT:
401 _timecode_type = ARDOUR::AnyTime::Timecode;
403 case ARDOUR::AnyTime::Timecode:
404 _timecode_type = ARDOUR::AnyTime::BBT;
410 update_timecode_beats_led();
416 MackieControlProtocol::timecode_beats_release (Button &)
421 /////////////////////////////////////
423 /////////////////////////////////////
425 MackieControlProtocol::marker_press (Button &)
427 if (main_modifier_state() & MODIFIER_SHIFT) {
428 access_action ("Common/remove-location-from-playhead");
431 _modifier_state |= MODIFIER_MARKER;
432 marker_modifier_consumed_by_button = false;
438 MackieControlProtocol::marker_release (Button &)
440 _modifier_state &= ~MODIFIER_MARKER;
442 if (main_modifier_state() & MODIFIER_SHIFT) {
443 return off; //if shift was held, we already did the action
446 if (marker_modifier_consumed_by_button) {
447 DEBUG_TRACE (DEBUG::MackieControl, "marked modifier consumed by button, ignored\n");
448 /* marker was used a modifier for some other button(s), so do
456 /* Don't add another mark if one exists within 1/100th of a second of
457 * the current position and we're not rolling.
460 samplepos_t where = session->audible_sample();
462 if (session->transport_stopped() && session->locations()->mark_at (where, session->sample_rate() / 100.0)) {
466 session->locations()->next_available_name (markername,"mark");
467 add_marker (markername);
472 /////////////////////////////////////
474 /////////////////////////////////////
477 MackieControlProtocol::stop_press (Button &)
481 if (main_modifier_state() == MODIFIER_SHIFT) {
482 session->midi_panic();
489 MackieControlProtocol::stop_release (Button &)
491 return session->transport_stopped();
495 MackieControlProtocol::play_press (Button &)
497 /* if we're already rolling at normal speed, and we're pressed
498 again, jump back to where we started last time
501 transport_play (session->transport_speed() == 1.0);
506 MackieControlProtocol::play_release (Button &)
512 MackieControlProtocol::record_press (Button &)
514 rec_enable_toggle ();
519 MackieControlProtocol::record_release (Button &)
525 MackieControlProtocol::rewind_press (Button &)
527 if (modifier_state() & MODIFIER_MARKER) {
529 } else if (modifier_state() & MODIFIER_NUDGE) {
530 access_action ("Common/nudge-playhead-backward");
531 } else if (main_modifier_state() & MODIFIER_SHIFT) {
540 MackieControlProtocol::rewind_release (Button &)
546 MackieControlProtocol::ffwd_press (Button &)
548 if (modifier_state() & MODIFIER_MARKER) {
550 } else if (modifier_state() & MODIFIER_NUDGE) {
551 access_action ("Common/nudge-playhead-forward");
552 } else if (main_modifier_state() & MODIFIER_SHIFT) {
561 MackieControlProtocol::ffwd_release (Button &)
567 MackieControlProtocol::loop_press (Button &)
569 if (main_modifier_state() & MODIFIER_SHIFT) {
570 access_action ("Editor/set-loop-from-edit-range");
573 bool was_on = session->get_play_loop();
575 return was_on ? off : on;
580 MackieControlProtocol::loop_release (Button &)
586 MackieControlProtocol::enter_press (Button &)
588 if (main_modifier_state() & MODIFIER_SHIFT) {
589 access_action ("Transport/ToggleFollowEdits");
591 access_action ("Common/select-all-tracks");
597 MackieControlProtocol::enter_release (Button &)
603 MackieControlProtocol::bank_release (Button& b, uint32_t basic_bank_num)
605 if (_subview_mode != None) {
609 uint32_t bank_num = basic_bank_num;
611 if (b.long_press_count() > 0) {
612 bank_num = 8 + basic_bank_num;
615 (void) switch_banks (n_strips() * bank_num);
620 /* F-KEYS are only used for actions that are bound from the control panel; no need to address them here
622 MackieControlProtocol::F1_press (Button &b)
627 MackieControlProtocol::F1_release (Button &b)
632 MackieControlProtocol::F2_press (Button &)
637 MackieControlProtocol::F2_release (Button &b)
642 MackieControlProtocol::F3_press (Button &)
647 MackieControlProtocol::F3_release (Button &b)
652 MackieControlProtocol::F4_press (Button &)
657 MackieControlProtocol::F4_release (Button &b)
662 MackieControlProtocol::F5_press (Button &)
667 MackieControlProtocol::F5_release (Button &)
672 MackieControlProtocol::F6_press (Button &)
677 MackieControlProtocol::F6_release (Button &)
682 MackieControlProtocol::F7_press (Button &)
687 MackieControlProtocol::F7_release (Button &)
692 MackieControlProtocol::F8_press (Button &)
697 MackieControlProtocol::F8_release (Button &)
707 MackieControlProtocol::pan_press (Button &)
709 /* XXX eventually pan may have its own subview mode */
710 set_subview_mode (MackieControlProtocol::None, boost::shared_ptr<Stripable>());
714 MackieControlProtocol::pan_release (Button &)
719 MackieControlProtocol::plugin_press (Button &)
724 MackieControlProtocol::plugin_release (Button &)
726 // Do not do this yet, since it does nothing
727 // set_view_mode (Plugins);
728 return none; /* LED state set by set_view_mode */
731 MackieControlProtocol::eq_press (Button &)
733 set_subview_mode (EQ, first_selected_stripable ());
734 return none; /* led state handled by set_subview_mode() */
738 MackieControlProtocol::eq_release (Button &)
743 MackieControlProtocol::dyn_press (Button &)
745 set_subview_mode (Dynamics, first_selected_stripable ());
746 return none; /* led state handled by set_subview_mode() */
750 MackieControlProtocol::dyn_release (Button &)
755 MackieControlProtocol::flip_press (Button &)
757 if (subview_mode() == MackieControlProtocol::Sends) {
758 if (_flip_mode != Normal) {
759 set_flip_mode (Normal);
761 set_flip_mode (Mirror);
763 return ((_flip_mode != Normal) ? on : off);
770 MackieControlProtocol::flip_release (Button &)
775 MackieControlProtocol::name_value_press (Button &)
780 MackieControlProtocol::name_value_release (Button &)
785 MackieControlProtocol::touch_press (Button &)
790 MackieControlProtocol::touch_release (Button &)
792 set_automation_state (ARDOUR::Touch);
796 MackieControlProtocol::cancel_press (Button &)
798 if (main_modifier_state() & MODIFIER_SHIFT) {
799 access_action ("Transport/ToggleExternalSync");
801 access_action ("Main/Escape");
806 MackieControlProtocol::cancel_release (Button &)
811 MackieControlProtocol::user_a_press (Button &)
813 transport_play (session->transport_speed() == 1.0);
817 MackieControlProtocol::user_a_release (Button &)
822 MackieControlProtocol::user_b_press (Button &)
828 MackieControlProtocol::user_b_release (Button &)
834 MackieControlProtocol::master_fader_touch_press (Mackie::Button &)
836 DEBUG_TRACE (DEBUG::MackieControl, "MackieControlProtocol::master_fader_touch_press\n");
838 Fader* master_fader = _master_surface->master_fader();
840 boost::shared_ptr<AutomationControl> ac = master_fader->control ();
842 master_fader->set_in_use (true);
843 master_fader->start_touch (transport_sample());
848 MackieControlProtocol::master_fader_touch_release (Mackie::Button &)
850 DEBUG_TRACE (DEBUG::MackieControl, "MackieControlProtocol::master_fader_touch_release\n");
852 Fader* master_fader = _master_surface->master_fader();
854 master_fader->set_in_use (false);
855 master_fader->stop_touch (transport_sample());
861 MackieControlProtocol::read_press (Mackie::Button&)
867 MackieControlProtocol::read_release (Mackie::Button&)
869 set_automation_state (ARDOUR::Play);
873 MackieControlProtocol::write_press (Mackie::Button&)
878 MackieControlProtocol::write_release (Mackie::Button&)
880 set_automation_state (ARDOUR::Write);
885 MackieControlProtocol::clearsolo_press (Mackie::Button&)
887 // clears all solos and listens (pfl/afl)
889 if (main_modifier_state() & MODIFIER_SHIFT) {
890 access_action ("Editor/set-session-from-edit-range");
899 MackieControlProtocol::clearsolo_release (Mackie::Button&)
901 //return session->soloing();
906 MackieControlProtocol::track_press (Mackie::Button&)
908 set_subview_mode (TrackView, first_selected_stripable());
912 MackieControlProtocol::track_release (Mackie::Button&)
917 MackieControlProtocol::send_press (Mackie::Button&)
919 set_subview_mode (Sends, first_selected_stripable());
920 return none; /* led state handled by set_subview_mode() */
923 MackieControlProtocol::send_release (Mackie::Button&)
928 MackieControlProtocol::miditracks_press (Mackie::Button&)
933 MackieControlProtocol::miditracks_release (Mackie::Button&)
935 set_view_mode (MidiTracks);
939 MackieControlProtocol::inputs_press (Mackie::Button&)
942 set_view_mode (Mixer); //in Mixbus, this is the same as Global View (avoid dead buttons)
947 MackieControlProtocol::inputs_release (Mackie::Button&)
952 MackieControlProtocol::audiotracks_press (Mackie::Button&)
957 MackieControlProtocol::audiotracks_release (Mackie::Button&)
959 set_view_mode (AudioTracks);
963 MackieControlProtocol::audioinstruments_press (Mackie::Button& b)
966 set_view_mode (MidiTracks); //in Mixbus, we do the same thing as MIDI Tracks ( aviod dead buttons )
972 MackieControlProtocol::audioinstruments_release (Mackie::Button& b)
978 MackieControlProtocol::aux_press (Mackie::Button&)
983 MackieControlProtocol::aux_release (Mackie::Button&)
985 set_view_mode (Auxes);
989 MackieControlProtocol::busses_press (Mackie::Button&)
994 MackieControlProtocol::busses_release (Mackie::Button&)
996 set_view_mode (Busses);
1000 MackieControlProtocol::outputs_press (Mackie::Button&)
1005 MackieControlProtocol::outputs_release (Mackie::Button&)
1007 set_view_mode (Hidden);
1011 MackieControlProtocol::user_press (Mackie::Button&)
1016 MackieControlProtocol::user_release (Mackie::Button&)
1018 set_view_mode (Selected);
1022 MackieControlProtocol::trim_press (Mackie::Button&)
1027 MackieControlProtocol::trim_release (Mackie::Button&)
1032 MackieControlProtocol::latch_press (Mackie::Button&)
1037 MackieControlProtocol::latch_release (Mackie::Button&)
1042 MackieControlProtocol::grp_press (Mackie::Button&)
1047 MackieControlProtocol::grp_release (Mackie::Button&)
1049 /* There is no "Off" button for automation,
1050 so we use Group for this purpose.
1052 set_automation_state (Off);
1056 MackieControlProtocol::nudge_press (Mackie::Button&)
1058 _modifier_state |= MODIFIER_NUDGE;
1059 nudge_modifier_consumed_by_button = false;
1063 MackieControlProtocol::nudge_release (Mackie::Button&)
1065 _modifier_state &= ~MODIFIER_NUDGE;
1067 /* XXX these action names are stupid, because the action can affect
1068 * regions, markers or the playhead depending on selection state.
1071 if (main_modifier_state() & MODIFIER_SHIFT) {
1072 access_action ("Region/nudge-backward");
1074 access_action ("Region/nudge-forward");
1080 MackieControlProtocol::replace_press (Mackie::Button&)
1082 if (main_modifier_state() == MODIFIER_SHIFT) {
1086 access_action ("Common/finish-range-from-playhead");
1091 MackieControlProtocol::replace_release (Mackie::Button&)
1096 MackieControlProtocol::click_press (Mackie::Button&)
1098 if (main_modifier_state() & MODIFIER_SHIFT) {
1099 access_action ("Editor/set-punch-from-edit-range");
1102 bool state = !Config->get_clicking();
1103 Config->set_clicking (state);
1108 MackieControlProtocol::click_release (Mackie::Button&)
1113 MackieControlProtocol::view_press (Mackie::Button&)
1115 set_view_mode (Mixer);
1119 MackieControlProtocol::view_release (Mackie::Button&)