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 Sorted sorted = get_sorted_routes();
102 uint32_t strip_cnt = n_strips ();
104 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("bank left with current initial = %1 nstrips = %2 tracks/busses = %3\n",
105 _current_initial_bank, strip_cnt, sorted.size()));
106 if (_current_initial_bank > 0) {
107 switch_banks ((_current_initial_bank - 1) / strip_cnt * strip_cnt);
117 MackieControlProtocol::left_release (Button &)
123 MackieControlProtocol::right_press (Button &)
125 Sorted sorted = get_sorted_routes();
126 uint32_t strip_cnt = n_strips();
127 uint32_t route_cnt = sorted.size();
128 uint32_t max_bank = route_cnt / strip_cnt * strip_cnt;
131 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("bank right with current initial = %1 nstrips = %2 tracks/busses = %3\n",
132 _current_initial_bank, strip_cnt, route_cnt));
134 if (_current_initial_bank < max_bank) {
135 uint32_t new_initial = (_current_initial_bank / strip_cnt * strip_cnt) + strip_cnt;
137 switch_banks (new_initial);
139 switch_banks (max_bank);
146 MackieControlProtocol::right_release (Button &)
156 MackieControlProtocol::cursor_left_press (Button& )
160 if (main_modifier_state() & MODIFIER_OPTION) {
161 /* reset selected tracks to default vertical zoom */
163 ZoomOut (); /* EMIT SIGNAL */
167 if (main_modifier_state() == MODIFIER_CONTROL) {
169 } else if (main_modifier_state() == MODIFIER_OPTION) {
171 } else if (main_modifier_state() == MODIFIER_SHIFT) {
174 page_fraction = 0.25;
177 ScrollTimeline (-page_fraction);
184 MackieControlProtocol::cursor_left_release (Button&)
190 MackieControlProtocol::cursor_right_press (Button& )
194 if (main_modifier_state() & MODIFIER_OPTION) {
195 /* reset selected tracks to default vertical zoom */
197 ZoomIn (); /* EMIT SIGNAL */
201 if (main_modifier_state() == MODIFIER_CONTROL) {
203 } else if (main_modifier_state() == MODIFIER_OPTION) {
205 } else if (main_modifier_state() == MODIFIER_SHIFT) {
208 page_fraction = 0.25;
211 ScrollTimeline (page_fraction);
218 MackieControlProtocol::cursor_right_release (Button&)
224 MackieControlProtocol::cursor_up_press (Button&)
228 if (main_modifier_state() & MODIFIER_CONTROL) {
229 VerticalZoomInSelected (); /* EMIT SIGNAL */
231 VerticalZoomInAll (); /* EMIT SIGNAL */
234 StepTracksUp (); /* EMIT SIGNAL */
240 MackieControlProtocol::cursor_up_release (Button&)
246 MackieControlProtocol::cursor_down_press (Button&)
249 if (main_modifier_state() & MODIFIER_OPTION) {
250 VerticalZoomOutSelected (); /* EMIT SIGNAL */
252 VerticalZoomOutAll (); /* EMIT SIGNAL */
255 StepTracksDown (); /* EMIT SIGNAL */
261 MackieControlProtocol::cursor_down_release (Button&)
267 MackieControlProtocol::channel_left_press (Button &)
269 Sorted sorted = get_sorted_routes();
270 if (sorted.size() > n_strips()) {
279 MackieControlProtocol::channel_left_release (Button &)
285 MackieControlProtocol::channel_right_press (Button &)
287 Sorted sorted = get_sorted_routes();
288 if (sorted.size() > n_strips()) {
297 MackieControlProtocol::channel_right_release (Button &)
303 MackieControlProtocol::zoom_press (Mackie::Button &)
309 MackieControlProtocol::zoom_release (Mackie::Button &)
311 if (_modifier_state & MODIFIER_ZOOM) {
312 _modifier_state &= ~MODIFIER_ZOOM;
314 _modifier_state |= MODIFIER_ZOOM;
317 return (zoom_mode() ? on : off);
321 MackieControlProtocol::scrub_press (Mackie::Button &)
323 if (!surfaces.empty()) {
324 // surfaces.front()->next_jog_mode ();
325 _master_surface->next_jog_mode ();
331 MackieControlProtocol::scrub_release (Mackie::Button &)
337 MackieControlProtocol::undo_press (Button&)
339 if (main_modifier_state() & MODIFIER_SHIFT) {
340 Redo(); /* EMIT SIGNAL */
342 Undo(); /* EMIT SIGNAL */
348 MackieControlProtocol::undo_release (Button&)
354 MackieControlProtocol::drop_press (Button &)
356 session->remove_last_capture();
361 MackieControlProtocol::drop_release (Button &)
367 MackieControlProtocol::save_press (Button &)
369 session->save_state ("");
374 MackieControlProtocol::save_release (Button &)
380 MackieControlProtocol::timecode_beats_press (Button &)
382 switch (_timecode_type) {
383 case ARDOUR::AnyTime::BBT:
384 _timecode_type = ARDOUR::AnyTime::Timecode;
386 case ARDOUR::AnyTime::Timecode:
387 _timecode_type = ARDOUR::AnyTime::BBT;
393 update_timecode_beats_led();
399 MackieControlProtocol::timecode_beats_release (Button &)
404 /////////////////////////////////////
406 /////////////////////////////////////
408 MackieControlProtocol::marker_press (Button &)
412 /* Don't add another mark if one exists within 1/100th of a second of
413 * the current position and we're not rolling.
417 framepos_t where = session->audible_frame();
419 if (session->transport_stopped() && session->locations()->mark_at (where, session->frame_rate() / 100.0)) {
423 session->locations()->next_available_name (markername,"marker");
424 add_marker (markername);
430 MackieControlProtocol::marker_release (Button &)
435 /////////////////////////////////////
437 /////////////////////////////////////
440 MackieControlProtocol::stop_press (Button &)
447 MackieControlProtocol::stop_release (Button &)
449 return session->transport_stopped();
453 MackieControlProtocol::play_press (Button &)
455 /* if we're already rolling at normal speed, and we're pressed
456 again, jump back to where we started last time
459 transport_play (session->transport_speed() == 1.0);
464 MackieControlProtocol::play_release (Button &)
470 MackieControlProtocol::record_press (Button &)
472 rec_enable_toggle ();
477 MackieControlProtocol::record_release (Button &)
483 MackieControlProtocol::rewind_press (Button &)
485 if (main_modifier_state() == MODIFIER_CONTROL) {
494 MackieControlProtocol::rewind_release (Button &)
500 MackieControlProtocol::ffwd_press (Button &)
502 if (main_modifier_state() == MODIFIER_CONTROL) {
511 MackieControlProtocol::ffwd_release (Button &)
517 MackieControlProtocol::loop_press (Button &)
519 bool was_on = session->get_play_loop();
520 session->request_play_loop (!was_on);
521 return was_on ? off : on;
525 MackieControlProtocol::loop_release (Button &)
531 MackieControlProtocol::clicking_press (Button &)
533 bool state = !Config->get_clicking();
534 Config->set_clicking (state);
539 MackieControlProtocol::clicking_release (Button &)
541 return Config->get_clicking();
544 LedState MackieControlProtocol::global_solo_press (Button &)
546 bool state = !session->soloing();
547 session->set_solo (session->get_routes(), state);
551 LedState MackieControlProtocol::global_solo_release (Button &)
553 return session->soloing();
557 MackieControlProtocol::enter_press (Button &)
559 Enter(); /* EMIT SIGNAL */
564 MackieControlProtocol::enter_release (Button &)
570 MackieControlProtocol::bank_release (Button& b, uint32_t basic_bank_num)
572 uint32_t bank_num = basic_bank_num;
574 if (b.long_press_count() > 0) {
575 bank_num = 8 + basic_bank_num;
578 switch_banks (n_strips() * bank_num);
584 MackieControlProtocol::F1_press (Button &b)
589 MackieControlProtocol::F1_release (Button &b)
591 return bank_release (b, 0);
594 MackieControlProtocol::F2_press (Button &)
599 MackieControlProtocol::F2_release (Button &b)
601 return bank_release (b, 1);
604 MackieControlProtocol::F3_press (Button &)
609 MackieControlProtocol::F3_release (Button &b)
611 return bank_release (b, 2);
614 MackieControlProtocol::F4_press (Button &)
619 MackieControlProtocol::F4_release (Button &b)
621 return bank_release (b, 3);
624 MackieControlProtocol::F5_press (Button &)
629 MackieControlProtocol::F5_release (Button &)
634 MackieControlProtocol::F6_press (Button &)
639 MackieControlProtocol::F6_release (Button &)
644 MackieControlProtocol::F7_press (Button &)
649 MackieControlProtocol::F7_release (Button &)
654 MackieControlProtocol::F8_press (Button &)
656 CloseDialog (); /* EMIT SIGNAL */
660 MackieControlProtocol::F8_release (Button &)
668 MackieControlProtocol::pan_press (Button &)
674 MackieControlProtocol::pan_release (Button &)
679 MackieControlProtocol::plugin_press (Button &)
684 MackieControlProtocol::plugin_release (Button &)
686 set_view_mode (Plugins);
687 return none; /* LED state set by set_view_mode */
690 MackieControlProtocol::eq_press (Button &)
692 if (Profile->get_mixbus()) {
693 if (_last_selected_routes.size() == 1) {
694 set_subview_mode (EQ);
702 MackieControlProtocol::eq_release (Button &)
707 MackieControlProtocol::dyn_press (Button &)
709 if (Profile->get_mixbus()) {
710 set_subview_mode (Dynamics);
716 MackieControlProtocol::dyn_release (Button &)
721 MackieControlProtocol::flip_press (Button &)
723 if (_flip_mode != Normal) {
724 set_flip_mode (Normal);
726 set_flip_mode (Mirror);
728 return ((_flip_mode != Normal) ? on : off);
731 MackieControlProtocol::flip_release (Button &)
736 MackieControlProtocol::name_value_press (Button &)
741 MackieControlProtocol::name_value_release (Button &)
746 MackieControlProtocol::touch_press (Button &)
751 MackieControlProtocol::touch_release (Button &)
756 MackieControlProtocol::cancel_press (Button &)
761 MackieControlProtocol::cancel_release (Button &)
766 MackieControlProtocol::user_a_press (Button &)
768 transport_play (session->transport_speed() == 1.0);
772 MackieControlProtocol::user_a_release (Button &)
777 MackieControlProtocol::user_b_press (Button &)
783 MackieControlProtocol::user_b_release (Button &)
789 MackieControlProtocol::master_fader_touch_press (Mackie::Button &)
791 DEBUG_TRACE (DEBUG::MackieControl, "MackieControlProtocol::master_fader_touch_press\n");
793 Fader* master_fader = _master_surface->master_fader();
795 boost::shared_ptr<AutomationControl> ac = master_fader->control ();
797 master_fader->set_in_use (true);
798 master_fader->start_touch (transport_frame());
803 MackieControlProtocol::master_fader_touch_release (Mackie::Button &)
805 DEBUG_TRACE (DEBUG::MackieControl, "MackieControlProtocol::master_fader_touch_release\n");
807 Fader* master_fader = _master_surface->master_fader();
809 master_fader->set_in_use (false);
810 master_fader->stop_touch (transport_frame(), true);
816 MackieControlProtocol::read_press (Mackie::Button&)
818 _metering_active = !_metering_active;
819 notify_metering_state_changed ();
820 return _metering_active;
823 MackieControlProtocol::read_release (Mackie::Button&)
825 return _metering_active;
828 MackieControlProtocol::write_press (Mackie::Button&)
833 MackieControlProtocol::write_release (Mackie::Button&)
838 MackieControlProtocol::clearsolo_press (Mackie::Button&)
843 MackieControlProtocol::clearsolo_release (Mackie::Button&)
848 MackieControlProtocol::track_press (Mackie::Button&)
854 MackieControlProtocol::track_release (Mackie::Button&)
859 MackieControlProtocol::send_press (Mackie::Button&)
865 MackieControlProtocol::send_release (Mackie::Button&)
870 MackieControlProtocol::miditracks_press (Mackie::Button&)
875 MackieControlProtocol::miditracks_release (Mackie::Button&)
877 set_view_mode (MidiTracks);
881 MackieControlProtocol::inputs_press (Mackie::Button&)
886 MackieControlProtocol::inputs_release (Mackie::Button&)
891 MackieControlProtocol::audiotracks_press (Mackie::Button&)
896 MackieControlProtocol::audiotracks_release (Mackie::Button&)
898 set_view_mode (AudioTracks);
902 MackieControlProtocol::audioinstruments_press (Mackie::Button&)
907 MackieControlProtocol::audioinstruments_release (Mackie::Button&)
912 MackieControlProtocol::aux_press (Mackie::Button&)
917 MackieControlProtocol::aux_release (Mackie::Button&)
919 set_view_mode (Auxes);
923 MackieControlProtocol::busses_press (Mackie::Button&)
928 MackieControlProtocol::busses_release (Mackie::Button&)
930 set_view_mode (Busses);
934 MackieControlProtocol::outputs_press (Mackie::Button&)
939 MackieControlProtocol::outputs_release (Mackie::Button&)
944 MackieControlProtocol::user_press (Mackie::Button&)
949 MackieControlProtocol::user_release (Mackie::Button&)
951 set_view_mode (Selected);
955 MackieControlProtocol::trim_press (Mackie::Button&)
960 MackieControlProtocol::trim_release (Mackie::Button&)
965 MackieControlProtocol::latch_press (Mackie::Button&)
970 MackieControlProtocol::latch_release (Mackie::Button&)
975 MackieControlProtocol::grp_press (Mackie::Button&)
980 MackieControlProtocol::grp_release (Mackie::Button&)
985 MackieControlProtocol::nudge_press (Mackie::Button&)
990 MackieControlProtocol::nudge_release (Mackie::Button&)
995 MackieControlProtocol::replace_press (Mackie::Button&)
1000 MackieControlProtocol::replace_release (Mackie::Button&)
1005 MackieControlProtocol::click_press (Mackie::Button&)
1010 MackieControlProtocol::click_release (Mackie::Button&)
1015 MackieControlProtocol::view_press (Mackie::Button&)
1017 set_view_mode (Mixer);
1021 MackieControlProtocol::view_release (Mackie::Button&)