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 ("Editor/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 ("Editor/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
445 if (marker_modifier_consumed_by_button) {
446 /* marker was used a modifier for some other button(s), so do
454 /* Don't add another mark if one exists within 1/100th of a second of
455 * the current position and we're not rolling.
458 framepos_t where = session->audible_frame();
460 if (session->transport_stopped() && session->locations()->mark_at (where, session->frame_rate() / 100.0)) {
464 session->locations()->next_available_name (markername,"marker");
465 add_marker (markername);
470 /////////////////////////////////////
472 /////////////////////////////////////
475 MackieControlProtocol::stop_press (Button &)
479 if (main_modifier_state() == MODIFIER_SHIFT) {
480 session->midi_panic();
487 MackieControlProtocol::stop_release (Button &)
489 return session->transport_stopped();
493 MackieControlProtocol::play_press (Button &)
495 /* if we're already rolling at normal speed, and we're pressed
496 again, jump back to where we started last time
499 transport_play (session->transport_speed() == 1.0);
504 MackieControlProtocol::play_release (Button &)
510 MackieControlProtocol::record_press (Button &)
512 rec_enable_toggle ();
517 MackieControlProtocol::record_release (Button &)
523 MackieControlProtocol::rewind_press (Button &)
525 if (modifier_state() & MODIFIER_MARKER) {
527 } else if (modifier_state() & MODIFIER_NUDGE) {
528 access_action ("Editor/nudge-playhead-backward");
529 } else if (main_modifier_state() & MODIFIER_SHIFT) {
538 MackieControlProtocol::rewind_release (Button &)
544 MackieControlProtocol::ffwd_press (Button &)
546 if (modifier_state() & MODIFIER_MARKER) {
548 } else if (modifier_state() & MODIFIER_NUDGE) {
549 access_action ("Editor/nudge-playhead-forward");
550 } else if (main_modifier_state() & MODIFIER_SHIFT) {
559 MackieControlProtocol::ffwd_release (Button &)
565 MackieControlProtocol::loop_press (Button &)
567 if (main_modifier_state() & MODIFIER_SHIFT) {
568 access_action ("Editor/set-loop-from-edit-range");
571 bool was_on = session->get_play_loop();
572 session->request_play_loop (!was_on);
573 return was_on ? off : on;
578 MackieControlProtocol::loop_release (Button &)
584 MackieControlProtocol::enter_press (Button &)
586 if (main_modifier_state() & MODIFIER_SHIFT) {
587 access_action ("Transport/ToggleFollowEdits");
589 access_action ("Editor/select-all-tracks");
595 MackieControlProtocol::enter_release (Button &)
601 MackieControlProtocol::bank_release (Button& b, uint32_t basic_bank_num)
603 if (_subview_mode != None) {
607 uint32_t bank_num = basic_bank_num;
609 if (b.long_press_count() > 0) {
610 bank_num = 8 + basic_bank_num;
613 (void) switch_banks (n_strips() * bank_num);
619 MackieControlProtocol::F1_press (Button &b)
624 MackieControlProtocol::F1_release (Button &b)
626 return bank_release (b, 0);
629 MackieControlProtocol::F2_press (Button &)
634 MackieControlProtocol::F2_release (Button &b)
636 return bank_release (b, 1);
639 MackieControlProtocol::F3_press (Button &)
644 MackieControlProtocol::F3_release (Button &b)
646 return bank_release (b, 2);
649 MackieControlProtocol::F4_press (Button &)
654 MackieControlProtocol::F4_release (Button &b)
656 return bank_release (b, 3);
659 MackieControlProtocol::F5_press (Button &)
664 MackieControlProtocol::F5_release (Button &)
669 MackieControlProtocol::F6_press (Button &)
674 MackieControlProtocol::F6_release (Button &)
679 MackieControlProtocol::F7_press (Button &)
684 MackieControlProtocol::F7_release (Button &)
689 MackieControlProtocol::F8_press (Button &)
691 CloseDialog (); /* EMIT SIGNAL */
695 MackieControlProtocol::F8_release (Button &)
703 MackieControlProtocol::pan_press (Button &)
705 /* XXX eventually pan may have its own subview mode */
706 set_subview_mode (MackieControlProtocol::None, boost::shared_ptr<Stripable>());
710 MackieControlProtocol::pan_release (Button &)
715 MackieControlProtocol::plugin_press (Button &)
720 MackieControlProtocol::plugin_release (Button &)
722 // Do not do this yet, since it does nothing
723 // set_view_mode (Plugins);
724 return none; /* LED state set by set_view_mode */
727 MackieControlProtocol::eq_press (Button &)
729 set_subview_mode (EQ, first_selected_stripable ());
730 return none; /* led state handled by set_subview_mode() */
734 MackieControlProtocol::eq_release (Button &)
739 MackieControlProtocol::dyn_press (Button &)
741 set_subview_mode (Dynamics, first_selected_stripable ());
742 return none; /* led state handled by set_subview_mode() */
746 MackieControlProtocol::dyn_release (Button &)
751 MackieControlProtocol::flip_press (Button &)
753 if (subview_mode() == MackieControlProtocol::Sends) {
754 if (_flip_mode != Normal) {
755 set_flip_mode (Normal);
757 set_flip_mode (Mirror);
759 return ((_flip_mode != Normal) ? on : off);
766 MackieControlProtocol::flip_release (Button &)
771 MackieControlProtocol::name_value_press (Button &)
776 MackieControlProtocol::name_value_release (Button &)
781 MackieControlProtocol::touch_press (Button &)
786 MackieControlProtocol::touch_release (Button &)
788 set_automation_state (ARDOUR::Touch);
792 MackieControlProtocol::cancel_press (Button &)
794 if (main_modifier_state() & MODIFIER_SHIFT) {
795 access_action ("Transport/ToggleExternalSync");
797 access_action ("Main/Escape");
802 MackieControlProtocol::cancel_release (Button &)
807 MackieControlProtocol::user_a_press (Button &)
809 transport_play (session->transport_speed() == 1.0);
813 MackieControlProtocol::user_a_release (Button &)
818 MackieControlProtocol::user_b_press (Button &)
824 MackieControlProtocol::user_b_release (Button &)
830 MackieControlProtocol::master_fader_touch_press (Mackie::Button &)
832 DEBUG_TRACE (DEBUG::MackieControl, "MackieControlProtocol::master_fader_touch_press\n");
834 Fader* master_fader = _master_surface->master_fader();
836 boost::shared_ptr<AutomationControl> ac = master_fader->control ();
838 master_fader->set_in_use (true);
839 master_fader->start_touch (transport_frame());
844 MackieControlProtocol::master_fader_touch_release (Mackie::Button &)
846 DEBUG_TRACE (DEBUG::MackieControl, "MackieControlProtocol::master_fader_touch_release\n");
848 Fader* master_fader = _master_surface->master_fader();
850 master_fader->set_in_use (false);
851 master_fader->stop_touch (transport_frame(), true);
857 MackieControlProtocol::read_press (Mackie::Button&)
863 MackieControlProtocol::read_release (Mackie::Button&)
865 set_automation_state (ARDOUR::Play);
869 MackieControlProtocol::write_press (Mackie::Button&)
874 MackieControlProtocol::write_release (Mackie::Button&)
876 set_automation_state (ARDOUR::Write);
881 MackieControlProtocol::clearsolo_press (Mackie::Button&)
883 // clears all solos and listens (pfl/afl)
885 if (main_modifier_state() & MODIFIER_SHIFT) {
886 access_action ("Editor/set-session-from-edit-range");
891 session->set_controls (route_list_to_control_list (session->get_routes(), &Stripable::solo_control), 0.0, Controllable::NoGroup);
892 session->clear_all_solo_state (session->get_routes());
898 MackieControlProtocol::clearsolo_release (Mackie::Button&)
900 //return session->soloing();
905 MackieControlProtocol::track_press (Mackie::Button&)
907 set_subview_mode (TrackView, first_selected_stripable());
911 MackieControlProtocol::track_release (Mackie::Button&)
916 MackieControlProtocol::send_press (Mackie::Button&)
918 set_subview_mode (Sends, first_selected_stripable());
919 return none; /* led state handled by set_subview_mode() */
922 MackieControlProtocol::send_release (Mackie::Button&)
927 MackieControlProtocol::miditracks_press (Mackie::Button&)
932 MackieControlProtocol::miditracks_release (Mackie::Button&)
934 set_view_mode (MidiTracks);
938 MackieControlProtocol::inputs_press (Mackie::Button&)
943 MackieControlProtocol::inputs_release (Mackie::Button&)
948 MackieControlProtocol::audiotracks_press (Mackie::Button&)
953 MackieControlProtocol::audiotracks_release (Mackie::Button&)
955 set_view_mode (AudioTracks);
959 MackieControlProtocol::audioinstruments_press (Mackie::Button& b)
965 MackieControlProtocol::audioinstruments_release (Mackie::Button& b)
971 MackieControlProtocol::aux_press (Mackie::Button&)
976 MackieControlProtocol::aux_release (Mackie::Button&)
978 set_view_mode (Auxes);
982 MackieControlProtocol::busses_press (Mackie::Button&)
987 MackieControlProtocol::busses_release (Mackie::Button&)
989 set_view_mode (Busses);
993 MackieControlProtocol::outputs_press (Mackie::Button&)
998 MackieControlProtocol::outputs_release (Mackie::Button&)
1000 set_view_mode (Hidden);
1004 MackieControlProtocol::user_press (Mackie::Button&)
1009 MackieControlProtocol::user_release (Mackie::Button&)
1011 set_view_mode (Selected);
1015 MackieControlProtocol::trim_press (Mackie::Button&)
1020 MackieControlProtocol::trim_release (Mackie::Button&)
1025 MackieControlProtocol::latch_press (Mackie::Button&)
1030 MackieControlProtocol::latch_release (Mackie::Button&)
1035 MackieControlProtocol::grp_press (Mackie::Button&)
1040 MackieControlProtocol::grp_release (Mackie::Button&)
1042 /* There is no "Off" button for automation,
1043 so we use Group for this purpose.
1045 set_automation_state (Off);
1049 MackieControlProtocol::nudge_press (Mackie::Button&)
1051 _modifier_state |= MODIFIER_NUDGE;
1052 nudge_modifier_consumed_by_button = false;
1056 MackieControlProtocol::nudge_release (Mackie::Button&)
1058 _modifier_state &= ~MODIFIER_NUDGE;
1060 /* XXX these action names are stupid, because the action can affect
1061 * regions, markers or the playhead depending on selection state.
1064 if (main_modifier_state() & MODIFIER_SHIFT) {
1065 access_action ("Region/nudge-backward");
1067 access_action ("Region/nudge-forward");
1073 MackieControlProtocol::replace_press (Mackie::Button&)
1075 if (main_modifier_state() == MODIFIER_SHIFT) {
1079 access_action ("Editor/finish-range-from-playhead");
1084 MackieControlProtocol::replace_release (Mackie::Button&)
1089 MackieControlProtocol::click_press (Mackie::Button&)
1091 if (main_modifier_state() & MODIFIER_SHIFT) {
1092 access_action ("Editor/set-punch-from-edit-range");
1095 bool state = !Config->get_clicking();
1096 Config->set_clicking (state);
1101 MackieControlProtocol::click_release (Mackie::Button&)
1106 MackieControlProtocol::view_press (Mackie::Button&)
1108 set_view_mode (Mixer);
1112 MackieControlProtocol::view_release (Mackie::Button&)