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_routes();
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_routes();
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_routes();
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_routes();
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) {
366 access_action ("Editor/start-range-from-playhead");
372 MackieControlProtocol::drop_release (Button &)
378 MackieControlProtocol::save_press (Button &)
380 if (main_modifier_state() == MODIFIER_SHIFT) {
381 quick_snapshot_switch();
390 MackieControlProtocol::save_release (Button &)
396 MackieControlProtocol::timecode_beats_press (Button &)
398 switch (_timecode_type) {
399 case ARDOUR::AnyTime::BBT:
400 _timecode_type = ARDOUR::AnyTime::Timecode;
402 case ARDOUR::AnyTime::Timecode:
403 _timecode_type = ARDOUR::AnyTime::BBT;
409 update_timecode_beats_led();
415 MackieControlProtocol::timecode_beats_release (Button &)
420 /////////////////////////////////////
422 /////////////////////////////////////
424 MackieControlProtocol::marker_press (Button &)
426 if (main_modifier_state() & MODIFIER_SHIFT) {
427 access_action ("Editor/set-session-from-edit-range");
430 _modifier_state |= MODIFIER_MARKER;
431 marker_modifier_consumed_by_button = false;
437 MackieControlProtocol::marker_release (Button &)
439 _modifier_state &= ~MODIFIER_MARKER;
441 if (marker_modifier_consumed_by_button) {
442 /* marker was used a modifier for some other button(s), so do
450 /* Don't add another mark if one exists within 1/100th of a second of
451 * the current position and we're not rolling.
454 framepos_t where = session->audible_frame();
456 if (session->transport_stopped() && session->locations()->mark_at (where, session->frame_rate() / 100.0)) {
460 session->locations()->next_available_name (markername,"marker");
461 add_marker (markername);
466 /////////////////////////////////////
468 /////////////////////////////////////
471 MackieControlProtocol::stop_press (Button &)
475 if (main_modifier_state() == MODIFIER_SHIFT) {
476 session->midi_panic();
483 MackieControlProtocol::stop_release (Button &)
485 return session->transport_stopped();
489 MackieControlProtocol::play_press (Button &)
491 /* if we're already rolling at normal speed, and we're pressed
492 again, jump back to where we started last time
495 transport_play (session->transport_speed() == 1.0);
500 MackieControlProtocol::play_release (Button &)
506 MackieControlProtocol::record_press (Button &)
508 rec_enable_toggle ();
513 MackieControlProtocol::record_release (Button &)
519 MackieControlProtocol::rewind_press (Button &)
521 if (modifier_state() & MODIFIER_MARKER) {
523 } else if (modifier_state() & MODIFIER_NUDGE) {
524 access_action ("Editor/nudge-playhead-backward");
525 } else if (main_modifier_state() & MODIFIER_SHIFT) {
534 MackieControlProtocol::rewind_release (Button &)
540 MackieControlProtocol::ffwd_press (Button &)
542 if (modifier_state() & MODIFIER_MARKER) {
544 } else if (modifier_state() & MODIFIER_NUDGE) {
545 access_action ("Editor/nudge-playhead-forward");
546 } else if (main_modifier_state() & MODIFIER_SHIFT) {
555 MackieControlProtocol::ffwd_release (Button &)
561 MackieControlProtocol::loop_press (Button &)
563 if (main_modifier_state() & MODIFIER_SHIFT) {
564 access_action ("Editor/set-loop-from-edit-range");
567 bool was_on = session->get_play_loop();
568 session->request_play_loop (!was_on);
569 return was_on ? off : on;
574 MackieControlProtocol::loop_release (Button &)
580 MackieControlProtocol::enter_press (Button &)
582 if (main_modifier_state() & MODIFIER_SHIFT) {
583 access_action ("Transport/ToggleFollowEdits");
585 access_action ("Editor/select-all-tracks");
591 MackieControlProtocol::enter_release (Button &)
597 MackieControlProtocol::bank_release (Button& b, uint32_t basic_bank_num)
599 if (_subview_mode != None) {
603 uint32_t bank_num = basic_bank_num;
605 if (b.long_press_count() > 0) {
606 bank_num = 8 + basic_bank_num;
609 (void) switch_banks (n_strips() * bank_num);
615 MackieControlProtocol::F1_press (Button &b)
620 MackieControlProtocol::F1_release (Button &b)
622 return bank_release (b, 0);
625 MackieControlProtocol::F2_press (Button &)
630 MackieControlProtocol::F2_release (Button &b)
632 return bank_release (b, 1);
635 MackieControlProtocol::F3_press (Button &)
640 MackieControlProtocol::F3_release (Button &b)
642 return bank_release (b, 2);
645 MackieControlProtocol::F4_press (Button &)
650 MackieControlProtocol::F4_release (Button &b)
652 return bank_release (b, 3);
655 MackieControlProtocol::F5_press (Button &)
660 MackieControlProtocol::F5_release (Button &)
665 MackieControlProtocol::F6_press (Button &)
670 MackieControlProtocol::F6_release (Button &)
675 MackieControlProtocol::F7_press (Button &)
680 MackieControlProtocol::F7_release (Button &)
685 MackieControlProtocol::F8_press (Button &)
687 CloseDialog (); /* EMIT SIGNAL */
691 MackieControlProtocol::F8_release (Button &)
699 MackieControlProtocol::pan_press (Button &)
701 /* XXX eventually pan may have its own subview mode */
702 set_subview_mode (MackieControlProtocol::None, boost::shared_ptr<Route>());
706 MackieControlProtocol::pan_release (Button &)
711 MackieControlProtocol::plugin_press (Button &)
716 MackieControlProtocol::plugin_release (Button &)
718 // Do not do this yet, since it does nothing
719 // set_view_mode (Plugins);
720 return none; /* LED state set by set_view_mode */
723 MackieControlProtocol::eq_press (Button &)
725 boost::shared_ptr<Route> r = first_selected_route ();
726 set_subview_mode (EQ, r);
727 return none; /* led state handled by set_subview_mode() */
731 MackieControlProtocol::eq_release (Button &)
736 MackieControlProtocol::dyn_press (Button &)
738 boost::shared_ptr<Route> r = first_selected_route ();
739 set_subview_mode (Dynamics, r);
740 return none; /* led state handled by set_subview_mode() */
744 MackieControlProtocol::dyn_release (Button &)
749 MackieControlProtocol::flip_press (Button &)
751 if (subview_mode() == MackieControlProtocol::Sends) {
752 if (_flip_mode != Normal) {
753 set_flip_mode (Normal);
755 set_flip_mode (Mirror);
757 return ((_flip_mode != Normal) ? on : off);
764 MackieControlProtocol::flip_release (Button &)
769 MackieControlProtocol::name_value_press (Button &)
774 MackieControlProtocol::name_value_release (Button &)
779 MackieControlProtocol::touch_press (Button &)
784 MackieControlProtocol::touch_release (Button &)
786 set_automation_state (ARDOUR::Touch);
790 MackieControlProtocol::cancel_press (Button &)
792 if (main_modifier_state() & MODIFIER_SHIFT) {
793 access_action ("Transport/ToggleExternalSync");
795 access_action ("Editor/escape");
800 MackieControlProtocol::cancel_release (Button &)
805 MackieControlProtocol::user_a_press (Button &)
807 transport_play (session->transport_speed() == 1.0);
811 MackieControlProtocol::user_a_release (Button &)
816 MackieControlProtocol::user_b_press (Button &)
822 MackieControlProtocol::user_b_release (Button &)
828 MackieControlProtocol::master_fader_touch_press (Mackie::Button &)
830 DEBUG_TRACE (DEBUG::MackieControl, "MackieControlProtocol::master_fader_touch_press\n");
832 Fader* master_fader = _master_surface->master_fader();
834 boost::shared_ptr<AutomationControl> ac = master_fader->control ();
836 master_fader->set_in_use (true);
837 master_fader->start_touch (transport_frame());
842 MackieControlProtocol::master_fader_touch_release (Mackie::Button &)
844 DEBUG_TRACE (DEBUG::MackieControl, "MackieControlProtocol::master_fader_touch_release\n");
846 Fader* master_fader = _master_surface->master_fader();
848 master_fader->set_in_use (false);
849 master_fader->stop_touch (transport_frame(), true);
855 MackieControlProtocol::read_press (Mackie::Button&)
861 MackieControlProtocol::read_release (Mackie::Button&)
863 set_automation_state (ARDOUR::Play);
867 MackieControlProtocol::write_press (Mackie::Button&)
872 MackieControlProtocol::write_release (Mackie::Button&)
874 set_automation_state (ARDOUR::Write);
879 MackieControlProtocol::clearsolo_press (Mackie::Button&)
881 // clears all solos and listens (pfl/afl)
884 if (session->soloing()) {
885 session->set_solo (session->get_routes(), false);
886 } else if (session->listening()) {
887 session->set_listen (session->get_routes(), false);
890 session->clear_all_solo_state (session->get_routes()); // safeguard, ideally this won't do anything, check the log-window
896 MackieControlProtocol::clearsolo_release (Mackie::Button&)
898 //return session->soloing();
903 MackieControlProtocol::track_press (Mackie::Button&)
905 set_subview_mode (TrackView, first_selected_route());
909 MackieControlProtocol::track_release (Mackie::Button&)
914 MackieControlProtocol::send_press (Mackie::Button&)
916 boost::shared_ptr<Route> r = first_selected_route ();
917 set_subview_mode (Sends, r);
918 return none; /* led state handled by set_subview_mode() */
921 MackieControlProtocol::send_release (Mackie::Button&)
926 MackieControlProtocol::miditracks_press (Mackie::Button&)
931 MackieControlProtocol::miditracks_release (Mackie::Button&)
933 set_view_mode (MidiTracks);
937 MackieControlProtocol::inputs_press (Mackie::Button&)
942 MackieControlProtocol::inputs_release (Mackie::Button&)
947 MackieControlProtocol::audiotracks_press (Mackie::Button&)
952 MackieControlProtocol::audiotracks_release (Mackie::Button&)
954 set_view_mode (AudioTracks);
958 MackieControlProtocol::audioinstruments_press (Mackie::Button& b)
964 MackieControlProtocol::audioinstruments_release (Mackie::Button& b)
970 MackieControlProtocol::aux_press (Mackie::Button&)
975 MackieControlProtocol::aux_release (Mackie::Button&)
977 set_view_mode (Auxes);
981 MackieControlProtocol::busses_press (Mackie::Button&)
986 MackieControlProtocol::busses_release (Mackie::Button&)
988 set_view_mode (Busses);
992 MackieControlProtocol::outputs_press (Mackie::Button&)
997 MackieControlProtocol::outputs_release (Mackie::Button&)
999 set_view_mode (Hidden);
1003 MackieControlProtocol::user_press (Mackie::Button&)
1008 MackieControlProtocol::user_release (Mackie::Button&)
1010 set_view_mode (Selected);
1014 MackieControlProtocol::trim_press (Mackie::Button&)
1019 MackieControlProtocol::trim_release (Mackie::Button&)
1024 MackieControlProtocol::latch_press (Mackie::Button&)
1029 MackieControlProtocol::latch_release (Mackie::Button&)
1034 MackieControlProtocol::grp_press (Mackie::Button&)
1039 MackieControlProtocol::grp_release (Mackie::Button&)
1041 /* There is no "Off" button for automation,
1042 so we use Group for this purpose.
1044 set_automation_state (Off);
1048 MackieControlProtocol::nudge_press (Mackie::Button&)
1050 _modifier_state |= MODIFIER_NUDGE;
1051 nudge_modifier_consumed_by_button = false;
1055 MackieControlProtocol::nudge_release (Mackie::Button&)
1057 _modifier_state &= ~MODIFIER_NUDGE;
1059 /* XXX these action names are stupid, because the action can affect
1060 * regions, markers or the playhead depending on selection state.
1063 if (main_modifier_state() & MODIFIER_SHIFT) {
1064 access_action ("Region/nudge-backward");
1066 access_action ("Region/nudge-forward");
1072 MackieControlProtocol::replace_press (Mackie::Button&)
1074 if (main_modifier_state() == MODIFIER_SHIFT) {
1077 access_action ("Editor/finish-range-from-playhead");
1082 MackieControlProtocol::replace_release (Mackie::Button&)
1087 MackieControlProtocol::click_press (Mackie::Button&)
1089 if (main_modifier_state() & MODIFIER_SHIFT) {
1090 access_action ("Editor/set-punch-from-edit-range");
1093 bool state = !Config->get_clicking();
1094 Config->set_clicking (state);
1099 MackieControlProtocol::click_release (Mackie::Button&)
1104 MackieControlProtocol::view_press (Mackie::Button&)
1106 set_view_mode (Mixer);
1110 MackieControlProtocol::view_release (Mackie::Button&)