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;
63 access_action ("Editor/set-loop-from-edit-range");
67 MackieControlProtocol::option_release (Button &)
69 _modifier_state &= ~MODIFIER_OPTION;
73 MackieControlProtocol::control_press (Button &)
75 _modifier_state |= MODIFIER_CONTROL;
76 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("CONTROL Press: modifier state now set to %1\n", _modifier_state));
77 access_action ("Editor/set-punch-from-edit-range");
81 MackieControlProtocol::control_release (Button &)
83 _modifier_state &= ~MODIFIER_CONTROL;
84 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("CONTROL Release: modifier state now set to %1\n", _modifier_state));
88 MackieControlProtocol::cmd_alt_press (Button &)
90 _modifier_state |= MODIFIER_CMDALT;
91 access_action ("Editor/set-session-from-edit-range");
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_routes();
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_routes();
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 StepTracksUp (); /* EMIT SIGNAL */
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 StepTracksDown (); /* EMIT SIGNAL */
265 MackieControlProtocol::cursor_down_release (Button&)
271 MackieControlProtocol::channel_left_press (Button &)
273 if (_subview_mode != None) {
276 Sorted sorted = get_sorted_routes();
277 if (sorted.size() > n_strips()) {
286 MackieControlProtocol::channel_left_release (Button &)
292 MackieControlProtocol::channel_right_press (Button &)
294 if (_subview_mode != None) {
297 Sorted sorted = get_sorted_routes();
298 if (sorted.size() > n_strips()) {
307 MackieControlProtocol::channel_right_release (Button &)
313 MackieControlProtocol::zoom_press (Mackie::Button &)
319 MackieControlProtocol::zoom_release (Mackie::Button &)
321 if (_modifier_state & MODIFIER_ZOOM) {
322 _modifier_state &= ~MODIFIER_ZOOM;
324 _modifier_state |= MODIFIER_ZOOM;
327 return (zoom_mode() ? on : off);
331 MackieControlProtocol::scrub_press (Mackie::Button &)
333 if (!surfaces.empty()) {
334 // surfaces.front()->next_jog_mode ();
335 _master_surface->next_jog_mode ();
341 MackieControlProtocol::scrub_release (Mackie::Button &)
347 MackieControlProtocol::undo_press (Button&)
354 MackieControlProtocol::undo_release (Button&)
360 MackieControlProtocol::drop_press (Button &)
362 access_action ("Editor/start-range-from-playhead");
367 MackieControlProtocol::drop_release (Button &)
373 MackieControlProtocol::save_press (Button &)
380 MackieControlProtocol::save_release (Button &)
386 MackieControlProtocol::timecode_beats_press (Button &)
388 switch (_timecode_type) {
389 case ARDOUR::AnyTime::BBT:
390 _timecode_type = ARDOUR::AnyTime::Timecode;
392 case ARDOUR::AnyTime::Timecode:
393 _timecode_type = ARDOUR::AnyTime::BBT;
399 update_timecode_beats_led();
405 MackieControlProtocol::timecode_beats_release (Button &)
410 /////////////////////////////////////
412 /////////////////////////////////////
414 MackieControlProtocol::marker_press (Button &)
416 _modifier_state |= MODIFIER_MARKER;
417 marker_modifier_consumed_by_button = false;
422 MackieControlProtocol::marker_release (Button &)
424 _modifier_state &= ~MODIFIER_MARKER;
426 if (marker_modifier_consumed_by_button) {
427 /* marker was used a modifier for some other button(s), so do
435 /* Don't add another mark if one exists within 1/100th of a second of
436 * the current position and we're not rolling.
439 framepos_t where = session->audible_frame();
441 if (session->transport_stopped() && session->locations()->mark_at (where, session->frame_rate() / 100.0)) {
445 session->locations()->next_available_name (markername,"marker");
446 add_marker (markername);
451 /////////////////////////////////////
453 /////////////////////////////////////
456 MackieControlProtocol::stop_press (Button &)
460 if (main_modifier_state() == MODIFIER_SHIFT) {
461 session->midi_panic();
468 MackieControlProtocol::stop_release (Button &)
470 return session->transport_stopped();
474 MackieControlProtocol::play_press (Button &)
476 /* if we're already rolling at normal speed, and we're pressed
477 again, jump back to where we started last time
480 transport_play (session->transport_speed() == 1.0);
485 MackieControlProtocol::play_release (Button &)
491 MackieControlProtocol::record_press (Button &)
493 rec_enable_toggle ();
498 MackieControlProtocol::record_release (Button &)
504 MackieControlProtocol::rewind_press (Button &)
506 if (modifier_state() & MODIFIER_MARKER) {
508 } else if (modifier_state() & MODIFIER_NUDGE) {
509 access_action ("Editor/nudge-playhead-backward");
510 } else if (main_modifier_state() & MODIFIER_SHIFT) {
519 MackieControlProtocol::rewind_release (Button &)
525 MackieControlProtocol::ffwd_press (Button &)
527 if (modifier_state() & MODIFIER_MARKER) {
529 } else if (modifier_state() & MODIFIER_NUDGE) {
530 access_action ("Editor/nudge-playhead-forward");
531 } else if (main_modifier_state() & MODIFIER_SHIFT) {
540 MackieControlProtocol::ffwd_release (Button &)
546 MackieControlProtocol::loop_press (Button &)
548 bool was_on = session->get_play_loop();
549 session->request_play_loop (!was_on);
550 return was_on ? off : on;
554 MackieControlProtocol::loop_release (Button &)
560 MackieControlProtocol::clicking_press (Button &)
562 bool state = !Config->get_clicking();
563 Config->set_clicking (state);
568 MackieControlProtocol::clicking_release (Button &)
570 return Config->get_clicking();
574 MackieControlProtocol::enter_press (Button &)
576 access_action ("Transport/ToggleFollowEdits");
581 MackieControlProtocol::enter_release (Button &)
587 MackieControlProtocol::bank_release (Button& b, uint32_t basic_bank_num)
589 if (_subview_mode != None) {
593 uint32_t bank_num = basic_bank_num;
595 if (b.long_press_count() > 0) {
596 bank_num = 8 + basic_bank_num;
599 (void) switch_banks (n_strips() * bank_num);
605 MackieControlProtocol::F1_press (Button &b)
610 MackieControlProtocol::F1_release (Button &b)
612 return bank_release (b, 0);
615 MackieControlProtocol::F2_press (Button &)
620 MackieControlProtocol::F2_release (Button &b)
622 return bank_release (b, 1);
625 MackieControlProtocol::F3_press (Button &)
630 MackieControlProtocol::F3_release (Button &b)
632 return bank_release (b, 2);
635 MackieControlProtocol::F4_press (Button &)
640 MackieControlProtocol::F4_release (Button &b)
642 return bank_release (b, 3);
645 MackieControlProtocol::F5_press (Button &)
650 MackieControlProtocol::F5_release (Button &)
655 MackieControlProtocol::F6_press (Button &)
660 MackieControlProtocol::F6_release (Button &)
665 MackieControlProtocol::F7_press (Button &)
670 MackieControlProtocol::F7_release (Button &)
675 MackieControlProtocol::F8_press (Button &)
677 CloseDialog (); /* EMIT SIGNAL */
681 MackieControlProtocol::F8_release (Button &)
689 MackieControlProtocol::pan_press (Button &)
691 /* XXX eventually pan may have its own subview mode */
692 set_subview_mode (MackieControlProtocol::None, boost::shared_ptr<Route>());
696 MackieControlProtocol::pan_release (Button &)
701 MackieControlProtocol::plugin_press (Button &)
706 MackieControlProtocol::plugin_release (Button &)
708 // Do not do this yet, since it does nothing
709 // set_view_mode (Plugins);
710 return none; /* LED state set by set_view_mode */
713 MackieControlProtocol::eq_press (Button &)
715 boost::shared_ptr<Route> r = first_selected_route ();
716 set_subview_mode (EQ, r);
717 return none; /* led state handled by set_subview_mode() */
721 MackieControlProtocol::eq_release (Button &)
726 MackieControlProtocol::dyn_press (Button &)
728 boost::shared_ptr<Route> r = first_selected_route ();
729 set_subview_mode (Dynamics, r);
730 return none; /* led state handled by set_subview_mode() */
734 MackieControlProtocol::dyn_release (Button &)
739 MackieControlProtocol::flip_press (Button &)
741 if (subview_mode() == MackieControlProtocol::Sends) {
742 if (_flip_mode != Normal) {
743 set_flip_mode (Normal);
745 set_flip_mode (Mirror);
747 return ((_flip_mode != Normal) ? on : off);
754 MackieControlProtocol::flip_release (Button &)
759 MackieControlProtocol::name_value_press (Button &)
764 MackieControlProtocol::name_value_release (Button &)
769 MackieControlProtocol::touch_press (Button &)
774 MackieControlProtocol::touch_release (Button &)
776 set_automation_state (ARDOUR::Touch);
780 MackieControlProtocol::cancel_press (Button &)
782 access_action ("Transport/ToggleExternalSync");
786 MackieControlProtocol::cancel_release (Button &)
791 MackieControlProtocol::user_a_press (Button &)
793 transport_play (session->transport_speed() == 1.0);
797 MackieControlProtocol::user_a_release (Button &)
802 MackieControlProtocol::user_b_press (Button &)
808 MackieControlProtocol::user_b_release (Button &)
814 MackieControlProtocol::master_fader_touch_press (Mackie::Button &)
816 DEBUG_TRACE (DEBUG::MackieControl, "MackieControlProtocol::master_fader_touch_press\n");
818 Fader* master_fader = _master_surface->master_fader();
820 boost::shared_ptr<AutomationControl> ac = master_fader->control ();
822 master_fader->set_in_use (true);
823 master_fader->start_touch (transport_frame());
828 MackieControlProtocol::master_fader_touch_release (Mackie::Button &)
830 DEBUG_TRACE (DEBUG::MackieControl, "MackieControlProtocol::master_fader_touch_release\n");
832 Fader* master_fader = _master_surface->master_fader();
834 master_fader->set_in_use (false);
835 master_fader->stop_touch (transport_frame(), true);
841 MackieControlProtocol::read_press (Mackie::Button&)
847 MackieControlProtocol::read_release (Mackie::Button&)
849 set_automation_state (ARDOUR::Play);
853 MackieControlProtocol::write_press (Mackie::Button&)
858 MackieControlProtocol::write_release (Mackie::Button&)
860 set_automation_state (ARDOUR::Write);
865 MackieControlProtocol::clearsolo_press (Mackie::Button&)
867 // clears all solos and listens (pfl/afl)
870 if (session->soloing()) {
871 session->set_solo (session->get_routes(), false);
872 } else if (session->listening()) {
873 session->set_listen (session->get_routes(), false);
876 session->clear_all_solo_state (session->get_routes()); // safeguard, ideally this won't do anything, check the log-window
882 MackieControlProtocol::clearsolo_release (Mackie::Button&)
884 //return session->soloing();
889 MackieControlProtocol::track_press (Mackie::Button&)
891 set_subview_mode (TrackView, first_selected_route());
895 MackieControlProtocol::track_release (Mackie::Button&)
900 MackieControlProtocol::send_press (Mackie::Button&)
902 boost::shared_ptr<Route> r = first_selected_route ();
903 set_subview_mode (Sends, r);
904 return none; /* led state handled by set_subview_mode() */
907 MackieControlProtocol::send_release (Mackie::Button&)
912 MackieControlProtocol::miditracks_press (Mackie::Button&)
917 MackieControlProtocol::miditracks_release (Mackie::Button&)
919 set_view_mode (MidiTracks);
923 MackieControlProtocol::inputs_press (Mackie::Button&)
928 MackieControlProtocol::inputs_release (Mackie::Button&)
933 MackieControlProtocol::audiotracks_press (Mackie::Button&)
938 MackieControlProtocol::audiotracks_release (Mackie::Button&)
940 set_view_mode (AudioTracks);
944 MackieControlProtocol::audioinstruments_press (Mackie::Button& b)
950 MackieControlProtocol::audioinstruments_release (Mackie::Button& b)
956 MackieControlProtocol::aux_press (Mackie::Button&)
961 MackieControlProtocol::aux_release (Mackie::Button&)
963 set_view_mode (Auxes);
967 MackieControlProtocol::busses_press (Mackie::Button&)
972 MackieControlProtocol::busses_release (Mackie::Button&)
974 set_view_mode (Busses);
978 MackieControlProtocol::outputs_press (Mackie::Button&)
983 MackieControlProtocol::outputs_release (Mackie::Button&)
985 set_view_mode (Hidden);
989 MackieControlProtocol::user_press (Mackie::Button&)
994 MackieControlProtocol::user_release (Mackie::Button&)
996 set_view_mode (Selected);
1000 MackieControlProtocol::trim_press (Mackie::Button&)
1005 MackieControlProtocol::trim_release (Mackie::Button&)
1010 MackieControlProtocol::latch_press (Mackie::Button&)
1015 MackieControlProtocol::latch_release (Mackie::Button&)
1020 MackieControlProtocol::grp_press (Mackie::Button&)
1025 MackieControlProtocol::grp_release (Mackie::Button&)
1027 /* There is no "Off" button for automation,
1028 so we use Group for this purpose.
1030 set_automation_state (Off);
1034 MackieControlProtocol::nudge_press (Mackie::Button&)
1036 _modifier_state |= MODIFIER_NUDGE;
1037 nudge_modifier_consumed_by_button = false;
1041 MackieControlProtocol::nudge_release (Mackie::Button&)
1043 _modifier_state &= ~MODIFIER_NUDGE;
1045 /* XXX these action names are stupid, because the action can affect
1046 * regions, markers or the playhead depending on selection state.
1049 if (main_modifier_state() & MODIFIER_SHIFT) {
1050 access_action ("Region/nudge-backward");
1052 access_action ("Region/nudge-forward");
1058 MackieControlProtocol::replace_press (Mackie::Button&)
1060 access_action ("Editor/finish-range-from-playhead");
1064 MackieControlProtocol::replace_release (Mackie::Button&)
1069 MackieControlProtocol::click_press (Mackie::Button&)
1074 MackieControlProtocol::click_release (Mackie::Button&)
1079 MackieControlProtocol::view_press (Mackie::Button&)
1081 set_view_mode (Mixer);
1085 MackieControlProtocol::view_release (Mackie::Button&)