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/session.h"
26 #include "ardour/route.h"
27 #include "ardour/location.h"
28 #include "ardour/rc_configuration.h"
30 #include "mackie_control_protocol.h"
36 /* handlers for all buttons, broken into a separate file to avoid clutter in
37 * mackie_control_protocol.cc
41 using namespace ARDOUR;
43 using namespace ArdourSurface;
44 using namespace Mackie;
47 MackieControlProtocol::shift_press (Button &)
49 _modifier_state |= MODIFIER_SHIFT;
53 MackieControlProtocol::shift_release (Button &)
55 _modifier_state &= ~MODIFIER_SHIFT;
59 MackieControlProtocol::option_press (Button &)
61 _modifier_state |= MODIFIER_OPTION;
65 MackieControlProtocol::option_release (Button &)
67 _modifier_state &= ~MODIFIER_OPTION;
71 MackieControlProtocol::control_press (Button &)
73 _modifier_state |= MODIFIER_CONTROL;
74 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("CONTROL Press: modifier state now set to %1\n", _modifier_state));
78 MackieControlProtocol::control_release (Button &)
80 _modifier_state &= ~MODIFIER_CONTROL;
81 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("CONTROL Release: modifier state now set to %1\n", _modifier_state));
85 MackieControlProtocol::cmd_alt_press (Button &)
87 _modifier_state |= MODIFIER_CMDALT;
91 MackieControlProtocol::cmd_alt_release (Button &)
93 _modifier_state &= ~MODIFIER_CMDALT;
98 MackieControlProtocol::left_press (Button &)
100 Sorted sorted = get_sorted_routes();
101 uint32_t strip_cnt = n_strips ();
103 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("bank left with current initial = %1 nstrips = %2 tracks/busses = %3\n",
104 _current_initial_bank, strip_cnt, sorted.size()));
105 if (_current_initial_bank > 0) {
106 switch_banks ((_current_initial_bank - 1) / strip_cnt * strip_cnt);
116 MackieControlProtocol::left_release (Button &)
122 MackieControlProtocol::right_press (Button &)
124 Sorted sorted = get_sorted_routes();
125 uint32_t strip_cnt = n_strips();
126 uint32_t route_cnt = sorted.size();
127 uint32_t max_bank = route_cnt / strip_cnt * strip_cnt;
130 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("bank right with current initial = %1 nstrips = %2 tracks/busses = %3\n",
131 _current_initial_bank, strip_cnt, route_cnt));
133 if (_current_initial_bank < max_bank) {
134 uint32_t new_initial = (_current_initial_bank / strip_cnt * strip_cnt) + strip_cnt;
136 switch_banks (new_initial);
138 switch_banks (max_bank);
145 MackieControlProtocol::right_release (Button &)
155 MackieControlProtocol::cursor_left_press (Button& )
159 if (_modifier_state & MODIFIER_OPTION) {
160 /* reset selected tracks to default vertical zoom */
162 ZoomOut (); /* EMIT SIGNAL */
166 if (_modifier_state == MODIFIER_CONTROL) {
168 } else if (_modifier_state == MODIFIER_OPTION) {
170 } else if (_modifier_state == MODIFIER_SHIFT) {
173 page_fraction = 0.25;
176 ScrollTimeline (-page_fraction);
183 MackieControlProtocol::cursor_left_release (Button&)
189 MackieControlProtocol::cursor_right_press (Button& )
193 if (_modifier_state & MODIFIER_OPTION) {
194 /* reset selected tracks to default vertical zoom */
196 ZoomIn (); /* EMIT SIGNAL */
200 if (_modifier_state == MODIFIER_CONTROL) {
202 } else if (_modifier_state == MODIFIER_OPTION) {
204 } else if (_modifier_state == MODIFIER_SHIFT) {
207 page_fraction = 0.25;
210 ScrollTimeline (page_fraction);
217 MackieControlProtocol::cursor_right_release (Button&)
223 MackieControlProtocol::cursor_up_press (Button&)
227 if (_modifier_state & MODIFIER_CONTROL) {
228 VerticalZoomInSelected (); /* EMIT SIGNAL */
230 VerticalZoomInAll (); /* EMIT SIGNAL */
233 StepTracksUp (); /* EMIT SIGNAL */
239 MackieControlProtocol::cursor_up_release (Button&)
245 MackieControlProtocol::cursor_down_press (Button&)
248 if (_modifier_state & MODIFIER_OPTION) {
249 VerticalZoomOutSelected (); /* EMIT SIGNAL */
251 VerticalZoomOutAll (); /* EMIT SIGNAL */
254 StepTracksDown (); /* EMIT SIGNAL */
260 MackieControlProtocol::cursor_down_release (Button&)
266 MackieControlProtocol::channel_left_press (Button &)
268 Sorted sorted = get_sorted_routes();
269 if (sorted.size() > n_strips()) {
278 MackieControlProtocol::channel_left_release (Button &)
284 MackieControlProtocol::channel_right_press (Button &)
286 Sorted sorted = get_sorted_routes();
287 if (sorted.size() > n_strips()) {
296 MackieControlProtocol::channel_right_release (Button &)
302 MackieControlProtocol::zoom_press (Mackie::Button &)
304 _zoom_mode = !_zoom_mode;
305 return (_zoom_mode ? on : off);
309 MackieControlProtocol::zoom_release (Mackie::Button &)
311 return (_zoom_mode ? on : off);
315 MackieControlProtocol::scrub_press (Mackie::Button &)
317 if (!surfaces.empty()) {
318 surfaces.front()->next_jog_mode ();
324 MackieControlProtocol::scrub_release (Mackie::Button &)
330 MackieControlProtocol::undo_press (Button&)
332 if (_modifier_state & MODIFIER_SHIFT) {
333 Redo(); /* EMIT SIGNAL */
335 Undo(); /* EMIT SIGNAL */
341 MackieControlProtocol::undo_release (Button&)
347 MackieControlProtocol::redo_press (Button&)
349 Redo(); /* EMIT SIGNAL */
354 MackieControlProtocol::redo_release (Button&)
360 MackieControlProtocol::drop_press (Button &)
362 session->remove_last_capture();
367 MackieControlProtocol::drop_release (Button &)
373 MackieControlProtocol::save_press (Button &)
375 session->save_state ("");
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 &)
418 session->locations()->next_available_name (markername,"mcu");
419 add_marker (markername);
425 MackieControlProtocol::marker_release (Button &)
430 /////////////////////////////////////
432 /////////////////////////////////////
435 MackieControlProtocol::frm_left_press (Button &)
437 // can use first_mark_before/after as well
438 unsigned long elapsed = _frm_left_last.restart();
440 framepos_t pos = session->locations()->first_mark_before (session->transport_frame());
442 // allow a quick double to go past a previous mark
443 if (session->transport_rolling() && elapsed < 500 && pos >= 0) {
444 framepos_t pos_two_back = session->locations()->first_mark_before (pos);
445 if (pos_two_back >= 0) {
450 // move to the location, if it's valid
452 session->request_locate (pos, session->transport_rolling());
454 session->request_locate (session->current_start_frame(), session->transport_rolling());
461 MackieControlProtocol::frm_left_release (Button &)
467 MackieControlProtocol::frm_right_press (Button &)
469 // can use first_mark_before/after as well
470 framepos_t pos = session->locations()->first_mark_after (session->transport_frame());
473 session->request_locate (pos, session->transport_rolling());
475 session->request_locate (session->current_end_frame(), session->transport_rolling());
482 MackieControlProtocol::frm_right_release (Button &)
488 MackieControlProtocol::stop_press (Button &)
495 MackieControlProtocol::stop_release (Button &)
497 return session->transport_stopped();
501 MackieControlProtocol::play_press (Button &)
503 /* if we're already rolling at normal speed, and we're pressed
504 again, jump back to where we started last time
507 transport_play (session->transport_speed() == 1.0);
512 MackieControlProtocol::play_release (Button &)
518 MackieControlProtocol::record_press (Button &)
520 rec_enable_toggle ();
525 MackieControlProtocol::record_release (Button &)
531 MackieControlProtocol::rewind_press (Button &)
533 if (_modifier_state == MODIFIER_CONTROL) {
542 MackieControlProtocol::rewind_release (Button &)
548 MackieControlProtocol::ffwd_press (Button &)
550 if (_modifier_state == MODIFIER_CONTROL) {
559 MackieControlProtocol::ffwd_release (Button &)
565 MackieControlProtocol::loop_press (Button &)
567 if (_modifier_state & MODIFIER_CONTROL) {
568 set_view_mode (Loop);
571 session->request_play_loop (!session->get_play_loop());
577 MackieControlProtocol::loop_release (Button &)
583 MackieControlProtocol::punch_in_press (Button &)
585 bool const state = !session->config.get_punch_in();
586 session->config.set_punch_in (state);
591 MackieControlProtocol::punch_in_release (Button &)
593 return session->config.get_punch_in();
597 MackieControlProtocol::punch_out_press (Button &)
599 bool const state = !session->config.get_punch_out();
600 session->config.set_punch_out (state);
605 MackieControlProtocol::punch_out_release (Button &)
607 return session->config.get_punch_out();
611 MackieControlProtocol::home_press (Button &)
613 session->goto_start();
618 MackieControlProtocol::home_release (Button &)
624 MackieControlProtocol::end_press (Button &)
631 MackieControlProtocol::end_release (Button &)
637 MackieControlProtocol::clicking_press (Button &)
639 bool state = !Config->get_clicking();
640 Config->set_clicking (state);
645 MackieControlProtocol::clicking_release (Button &)
647 return Config->get_clicking();
650 LedState MackieControlProtocol::global_solo_press (Button &)
652 bool state = !session->soloing();
653 session->set_solo (session->get_routes(), state);
657 LedState MackieControlProtocol::global_solo_release (Button &)
659 return session->soloing();
663 MackieControlProtocol::enter_press (Button &)
665 Enter(); /* EMIT SIGNAL */
670 MackieControlProtocol::enter_release (Button &)
676 MackieControlProtocol::F1_press (Button &)
681 MackieControlProtocol::F1_release (Button &)
686 MackieControlProtocol::F2_press (Button &)
691 MackieControlProtocol::F2_release (Button &)
696 MackieControlProtocol::F3_press (Button &)
701 MackieControlProtocol::F3_release (Button &)
706 MackieControlProtocol::F4_press (Button &)
711 MackieControlProtocol::F4_release (Button &)
716 MackieControlProtocol::F5_press (Button &)
721 MackieControlProtocol::F5_release (Button &)
726 MackieControlProtocol::F6_press (Button &)
731 MackieControlProtocol::F6_release (Button &)
736 MackieControlProtocol::F7_press (Button &)
741 MackieControlProtocol::F7_release (Button &)
746 MackieControlProtocol::F8_press (Button &)
748 CloseDialog (); /* EMIT SIGNAL */
752 MackieControlProtocol::F8_release (Button &)
760 MackieControlProtocol::io_press (Button &)
765 MackieControlProtocol::io_release (Button &)
770 MackieControlProtocol::sends_press (Button &)
772 set_view_mode (Sends);
776 MackieControlProtocol::sends_release (Button &)
781 MackieControlProtocol::pan_press (Button &)
786 MackieControlProtocol::pan_release (Button &)
791 MackieControlProtocol::plugin_press (Button &)
796 MackieControlProtocol::plugin_release (Button &)
801 MackieControlProtocol::eq_press (Button &)
807 MackieControlProtocol::eq_release (Button &)
812 MackieControlProtocol::dyn_press (Button &)
814 set_view_mode (Dynamics);
818 MackieControlProtocol::dyn_release (Button &)
823 MackieControlProtocol::flip_press (Button &)
825 if (_flip_mode != Normal) {
826 set_flip_mode (Normal);
828 set_flip_mode (Mirror);
830 return ((_flip_mode != Normal) ? on : off);
833 MackieControlProtocol::flip_release (Button &)
838 MackieControlProtocol::edit_press (Button &)
843 MackieControlProtocol::edit_release (Button &)
848 MackieControlProtocol::name_value_press (Button &)
853 MackieControlProtocol::name_value_release (Button &)
858 MackieControlProtocol::F9_press (Button &)
863 MackieControlProtocol::F9_release (Button &)
868 MackieControlProtocol::F10_press (Button &)
873 MackieControlProtocol::F10_release (Button &)
878 MackieControlProtocol::F11_press (Button &)
883 MackieControlProtocol::F11_release (Button &)
888 MackieControlProtocol::F12_press (Button &)
893 MackieControlProtocol::F12_release (Button &)
898 MackieControlProtocol::F13_press (Button &)
903 MackieControlProtocol::F13_release (Button &)
908 MackieControlProtocol::F14_press (Button &)
913 MackieControlProtocol::F14_release (Button &)
918 MackieControlProtocol::F15_press (Button &)
923 MackieControlProtocol::F15_release (Button &)
928 MackieControlProtocol::F16_press (Button &)
933 MackieControlProtocol::F16_release (Button &)
938 MackieControlProtocol::on_press (Button &)
943 MackieControlProtocol::on_release (Button &)
948 MackieControlProtocol::rec_ready_press (Button &)
953 MackieControlProtocol::rec_ready_release (Button &)
958 MackieControlProtocol::touch_press (Button &)
963 MackieControlProtocol::touch_release (Button &)
968 MackieControlProtocol::cancel_press (Button &)
973 MackieControlProtocol::cancel_release (Button &)
978 MackieControlProtocol::mixer_press (Button &)
983 MackieControlProtocol::mixer_release (Button &)
988 MackieControlProtocol::user_a_press (Button &)
990 transport_play (session->transport_speed() == 1.0);
994 MackieControlProtocol::user_a_release (Button &)
999 MackieControlProtocol::user_b_press (Button &)
1005 MackieControlProtocol::user_b_release (Button &)
1011 MackieControlProtocol::master_fader_touch_press (Mackie::Button &)
1013 DEBUG_TRACE (DEBUG::MackieControl, "MackieControlProtocol::master_fader_touch_press\n");
1015 Fader* master_fader = surfaces.front()->master_fader();
1017 boost::shared_ptr<AutomationControl> ac = master_fader->control ();
1019 master_fader->set_in_use (true);
1020 master_fader->start_touch (transport_frame());
1025 MackieControlProtocol::master_fader_touch_release (Mackie::Button &)
1027 DEBUG_TRACE (DEBUG::MackieControl, "MackieControlProtocol::master_fader_touch_release\n");
1029 Fader* master_fader = surfaces.front()->master_fader();
1031 master_fader->set_in_use (false);
1032 master_fader->stop_touch (transport_frame(), true);
1038 MackieControlProtocol::snapshot_press (Mackie::Button&)
1043 MackieControlProtocol::snapshot_release (Mackie::Button&)
1048 MackieControlProtocol::read_press (Mackie::Button&)
1050 _metering_active = !_metering_active;
1051 notify_metering_state_changed ();
1052 return _metering_active;
1055 MackieControlProtocol::read_release (Mackie::Button&)
1057 return _metering_active;
1060 MackieControlProtocol::write_press (Mackie::Button&)
1065 MackieControlProtocol::write_release (Mackie::Button&)
1070 MackieControlProtocol::fdrgroup_press (Mackie::Button&)
1075 MackieControlProtocol::fdrgroup_release (Mackie::Button&)
1080 MackieControlProtocol::clearsolo_press (Mackie::Button&)
1085 MackieControlProtocol::clearsolo_release (Mackie::Button&)
1090 MackieControlProtocol::track_press (Mackie::Button&)
1095 MackieControlProtocol::track_release (Mackie::Button&)
1100 MackieControlProtocol::send_press (Mackie::Button&)
1105 MackieControlProtocol::send_release (Mackie::Button&)
1110 MackieControlProtocol::miditracks_press (Mackie::Button&)
1115 MackieControlProtocol::miditracks_release (Mackie::Button&)
1120 MackieControlProtocol::inputs_press (Mackie::Button&)
1125 MackieControlProtocol::inputs_release (Mackie::Button&)
1130 MackieControlProtocol::audiotracks_press (Mackie::Button&)
1135 MackieControlProtocol::audiotracks_release (Mackie::Button&)
1140 MackieControlProtocol::audioinstruments_press (Mackie::Button&)
1145 MackieControlProtocol::audioinstruments_release (Mackie::Button&)
1150 MackieControlProtocol::aux_press (Mackie::Button&)
1155 MackieControlProtocol::aux_release (Mackie::Button&)
1160 MackieControlProtocol::busses_press (Mackie::Button&)
1165 MackieControlProtocol::busses_release (Mackie::Button&)
1170 MackieControlProtocol::outputs_press (Mackie::Button&)
1175 MackieControlProtocol::outputs_release (Mackie::Button&)
1180 MackieControlProtocol::user_press (Mackie::Button&)
1185 MackieControlProtocol::user_release (Mackie::Button&)
1190 MackieControlProtocol::trim_press (Mackie::Button&)
1195 MackieControlProtocol::trim_release (Mackie::Button&)
1200 MackieControlProtocol::latch_press (Mackie::Button&)
1205 MackieControlProtocol::latch_release (Mackie::Button&)
1210 MackieControlProtocol::grp_press (Mackie::Button&)
1215 MackieControlProtocol::grp_release (Mackie::Button&)
1220 MackieControlProtocol::nudge_press (Mackie::Button&)
1225 MackieControlProtocol::nudge_release (Mackie::Button&)
1230 MackieControlProtocol::replace_press (Mackie::Button&)
1235 MackieControlProtocol::replace_release (Mackie::Button&)
1240 MackieControlProtocol::click_press (Mackie::Button&)
1245 MackieControlProtocol::click_release (Mackie::Button&)
1250 MackieControlProtocol::view_press (Mackie::Button&)
1255 MackieControlProtocol::view_release (Mackie::Button&)