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 gui_invoke ("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 gui_invoke ("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 gui_invoke ("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&)
349 if (main_modifier_state() & MODIFIER_SHIFT) {
350 Redo(); /* EMIT SIGNAL */
352 Undo(); /* EMIT SIGNAL */
358 MackieControlProtocol::undo_release (Button&)
364 MackieControlProtocol::drop_press (Button &)
366 gui_invoke ("Editor/start-range-from-playhead");
367 update_global_button (Button::Replace, flashing);
372 MackieControlProtocol::drop_release (Button &)
378 MackieControlProtocol::save_press (Button &)
380 session->save_state ("");
385 MackieControlProtocol::save_release (Button &)
391 MackieControlProtocol::timecode_beats_press (Button &)
393 switch (_timecode_type) {
394 case ARDOUR::AnyTime::BBT:
395 _timecode_type = ARDOUR::AnyTime::Timecode;
397 case ARDOUR::AnyTime::Timecode:
398 _timecode_type = ARDOUR::AnyTime::BBT;
404 update_timecode_beats_led();
410 MackieControlProtocol::timecode_beats_release (Button &)
415 /////////////////////////////////////
417 /////////////////////////////////////
419 MackieControlProtocol::marker_press (Button &)
421 _modifier_state |= MODIFIER_MARKER;
422 marker_modifier_consumed_by_button = false;
427 MackieControlProtocol::marker_release (Button &)
429 if (marker_modifier_consumed_by_button) {
430 /* marker was used a modifier for some other button(s), so do
438 _modifier_state &= ~MODIFIER_MARKER;
440 /* Don't add another mark if one exists within 1/100th of a second of
441 * the current position and we're not rolling.
444 framepos_t where = session->audible_frame();
446 if (session->transport_stopped() && session->locations()->mark_at (where, session->frame_rate() / 100.0)) {
450 session->locations()->next_available_name (markername,"marker");
451 add_marker (markername);
456 /////////////////////////////////////
458 /////////////////////////////////////
461 MackieControlProtocol::stop_press (Button &)
465 if (main_modifier_state() == MODIFIER_SHIFT) {
466 session->midi_panic();
473 MackieControlProtocol::stop_release (Button &)
475 return session->transport_stopped();
479 MackieControlProtocol::play_press (Button &)
481 /* if we're already rolling at normal speed, and we're pressed
482 again, jump back to where we started last time
485 transport_play (session->transport_speed() == 1.0);
490 MackieControlProtocol::play_release (Button &)
496 MackieControlProtocol::record_press (Button &)
498 rec_enable_toggle ();
503 MackieControlProtocol::record_release (Button &)
509 MackieControlProtocol::rewind_press (Button &)
511 if (modifier_state() & MODIFIER_MARKER) {
513 } else if (modifier_state() & MODIFIER_NUDGE) {
514 gui_invoke ("Editor/nudge-playhead-backward");
515 } else if (main_modifier_state() == MODIFIER_SHIFT) {
524 MackieControlProtocol::rewind_release (Button &)
530 MackieControlProtocol::ffwd_press (Button &)
532 if (modifier_state() & MODIFIER_MARKER) {
534 } else if (modifier_state() & MODIFIER_NUDGE) {
535 gui_invoke ("Editor/nudge-playhead-forward");
536 } else if (main_modifier_state() == MODIFIER_SHIFT) {
545 MackieControlProtocol::ffwd_release (Button &)
551 MackieControlProtocol::loop_press (Button &)
553 bool was_on = session->get_play_loop();
554 session->request_play_loop (!was_on);
555 return was_on ? off : on;
559 MackieControlProtocol::loop_release (Button &)
565 MackieControlProtocol::clicking_press (Button &)
567 bool state = !Config->get_clicking();
568 Config->set_clicking (state);
573 MackieControlProtocol::clicking_release (Button &)
575 return Config->get_clicking();
579 MackieControlProtocol::enter_press (Button &)
581 Enter(); /* EMIT SIGNAL */
586 MackieControlProtocol::enter_release (Button &)
592 MackieControlProtocol::bank_release (Button& b, uint32_t basic_bank_num)
594 if (_subview_mode != None) {
598 uint32_t bank_num = basic_bank_num;
600 if (b.long_press_count() > 0) {
601 bank_num = 8 + basic_bank_num;
604 (void) switch_banks (n_strips() * bank_num);
610 MackieControlProtocol::F1_press (Button &b)
615 MackieControlProtocol::F1_release (Button &b)
617 return bank_release (b, 0);
620 MackieControlProtocol::F2_press (Button &)
625 MackieControlProtocol::F2_release (Button &b)
627 return bank_release (b, 1);
630 MackieControlProtocol::F3_press (Button &)
635 MackieControlProtocol::F3_release (Button &b)
637 return bank_release (b, 2);
640 MackieControlProtocol::F4_press (Button &)
645 MackieControlProtocol::F4_release (Button &b)
647 return bank_release (b, 3);
650 MackieControlProtocol::F5_press (Button &)
655 MackieControlProtocol::F5_release (Button &)
660 MackieControlProtocol::F6_press (Button &)
665 MackieControlProtocol::F6_release (Button &)
670 MackieControlProtocol::F7_press (Button &)
675 MackieControlProtocol::F7_release (Button &)
680 MackieControlProtocol::F8_press (Button &)
682 CloseDialog (); /* EMIT SIGNAL */
686 MackieControlProtocol::F8_release (Button &)
694 MackieControlProtocol::pan_press (Button &)
700 MackieControlProtocol::pan_release (Button &)
705 MackieControlProtocol::plugin_press (Button &)
710 MackieControlProtocol::plugin_release (Button &)
712 // Do not do this yet, since it does nothing
713 // set_view_mode (Plugins);
714 return none; /* LED state set by set_view_mode */
717 MackieControlProtocol::eq_press (Button &)
719 boost::shared_ptr<Route> r = first_selected_route ();
720 set_subview_mode (EQ, r);
721 return none; /* led state handled by set_subview_mode() */
725 MackieControlProtocol::eq_release (Button &)
730 MackieControlProtocol::dyn_press (Button &)
732 boost::shared_ptr<Route> r = first_selected_route ();
733 set_subview_mode (Dynamics, r);
734 return none; /* led state handled by set_subview_mode() */
738 MackieControlProtocol::dyn_release (Button &)
743 MackieControlProtocol::flip_press (Button &)
745 if (_flip_mode != Normal) {
746 set_flip_mode (Normal);
748 set_flip_mode (Mirror);
750 return ((_flip_mode != Normal) ? on : off);
753 MackieControlProtocol::flip_release (Button &)
758 MackieControlProtocol::name_value_press (Button &)
763 MackieControlProtocol::name_value_release (Button &)
768 MackieControlProtocol::touch_press (Button &)
773 MackieControlProtocol::touch_release (Button &)
775 set_automation_state (ARDOUR::Touch);
779 MackieControlProtocol::cancel_press (Button &)
784 MackieControlProtocol::cancel_release (Button &)
789 MackieControlProtocol::user_a_press (Button &)
791 transport_play (session->transport_speed() == 1.0);
795 MackieControlProtocol::user_a_release (Button &)
800 MackieControlProtocol::user_b_press (Button &)
806 MackieControlProtocol::user_b_release (Button &)
812 MackieControlProtocol::master_fader_touch_press (Mackie::Button &)
814 DEBUG_TRACE (DEBUG::MackieControl, "MackieControlProtocol::master_fader_touch_press\n");
816 Fader* master_fader = _master_surface->master_fader();
818 boost::shared_ptr<AutomationControl> ac = master_fader->control ();
820 master_fader->set_in_use (true);
821 master_fader->start_touch (transport_frame());
826 MackieControlProtocol::master_fader_touch_release (Mackie::Button &)
828 DEBUG_TRACE (DEBUG::MackieControl, "MackieControlProtocol::master_fader_touch_release\n");
830 Fader* master_fader = _master_surface->master_fader();
832 master_fader->set_in_use (false);
833 master_fader->stop_touch (transport_frame(), true);
839 MackieControlProtocol::read_press (Mackie::Button&)
845 MackieControlProtocol::read_release (Mackie::Button&)
847 set_automation_state (ARDOUR::Play);
851 MackieControlProtocol::write_press (Mackie::Button&)
856 MackieControlProtocol::write_release (Mackie::Button&)
858 set_automation_state (ARDOUR::Write);
863 MackieControlProtocol::clearsolo_press (Mackie::Button&)
865 // clears all solos and listens (pfl/afl)
868 if (session->soloing()) {
869 session->set_solo (session->get_routes(), false);
870 } else if (session->listening()) {
871 session->set_listen (session->get_routes(), false);
874 session->clear_all_solo_state (session->get_routes()); // safeguard, ideally this won't do anything, check the log-window
880 MackieControlProtocol::clearsolo_release (Mackie::Button&)
882 //return session->soloing();
887 MackieControlProtocol::track_press (Mackie::Button&)
893 MackieControlProtocol::track_release (Mackie::Button&)
898 MackieControlProtocol::send_press (Mackie::Button&)
900 boost::shared_ptr<Route> r = first_selected_route ();
901 set_subview_mode (Sends, r);
902 return none; /* led state handled by set_subview_mode() */
905 MackieControlProtocol::send_release (Mackie::Button&)
910 MackieControlProtocol::miditracks_press (Mackie::Button&)
915 MackieControlProtocol::miditracks_release (Mackie::Button&)
917 set_view_mode (MidiTracks);
921 MackieControlProtocol::inputs_press (Mackie::Button&)
926 MackieControlProtocol::inputs_release (Mackie::Button&)
931 MackieControlProtocol::audiotracks_press (Mackie::Button&)
936 MackieControlProtocol::audiotracks_release (Mackie::Button&)
938 set_view_mode (AudioTracks);
942 MackieControlProtocol::audioinstruments_press (Mackie::Button& b)
948 MackieControlProtocol::audioinstruments_release (Mackie::Button& b)
954 MackieControlProtocol::aux_press (Mackie::Button&)
959 MackieControlProtocol::aux_release (Mackie::Button&)
961 set_view_mode (Auxes);
965 MackieControlProtocol::busses_press (Mackie::Button&)
970 MackieControlProtocol::busses_release (Mackie::Button&)
972 set_view_mode (Busses);
976 MackieControlProtocol::outputs_press (Mackie::Button&)
981 MackieControlProtocol::outputs_release (Mackie::Button&)
983 set_view_mode (Hidden);
987 MackieControlProtocol::user_press (Mackie::Button&)
992 MackieControlProtocol::user_release (Mackie::Button&)
994 set_view_mode (Selected);
998 MackieControlProtocol::trim_press (Mackie::Button&)
1003 MackieControlProtocol::trim_release (Mackie::Button&)
1008 MackieControlProtocol::latch_press (Mackie::Button&)
1013 MackieControlProtocol::latch_release (Mackie::Button&)
1018 MackieControlProtocol::grp_press (Mackie::Button&)
1023 MackieControlProtocol::grp_release (Mackie::Button&)
1025 /* There is no "Off" button for automation,
1026 so we use Group for this purpose.
1028 set_automation_state (Off);
1032 MackieControlProtocol::nudge_press (Mackie::Button&)
1034 _modifier_state |= MODIFIER_NUDGE;
1035 nudge_modifier_consumed_by_button = false;
1039 MackieControlProtocol::nudge_release (Mackie::Button&)
1041 _modifier_state &= ~MODIFIER_NUDGE;
1043 /* XXX these action names are stupid, because the action can affect
1044 * regions, markers or the playhead depending on selection state.
1047 if (main_modifier_state() & MODIFIER_SHIFT) {
1048 gui_invoke ("Region/nudge-backward");
1050 gui_invoke ("Region/nudge-forward");
1056 MackieControlProtocol::replace_press (Mackie::Button&)
1058 gui_invoke ("Editor/finish-range-from-playhead");
1059 update_global_button (Button::Drop, off);
1063 MackieControlProtocol::replace_release (Mackie::Button&)
1068 MackieControlProtocol::click_press (Mackie::Button&)
1073 MackieControlProtocol::click_release (Mackie::Button&)
1078 MackieControlProtocol::view_press (Mackie::Button&)
1080 set_view_mode (Mixer);
1084 MackieControlProtocol::view_release (Mackie::Button&)