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 (main_modifier_state() & MODIFIER_OPTION) {
160 /* reset selected tracks to default vertical zoom */
162 ZoomOut (); /* EMIT SIGNAL */
166 if (main_modifier_state() == MODIFIER_CONTROL) {
168 } else if (main_modifier_state() == MODIFIER_OPTION) {
170 } else if (main_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 (main_modifier_state() & MODIFIER_OPTION) {
194 /* reset selected tracks to default vertical zoom */
196 ZoomIn (); /* EMIT SIGNAL */
200 if (main_modifier_state() == MODIFIER_CONTROL) {
202 } else if (main_modifier_state() == MODIFIER_OPTION) {
204 } else if (main_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 (main_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 (main_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 &)
308 MackieControlProtocol::zoom_release (Mackie::Button &)
310 if (_modifier_state & MODIFIER_ZOOM) {
311 _modifier_state &= ~MODIFIER_ZOOM;
313 _modifier_state |= MODIFIER_ZOOM;
316 return (zoom_mode() ? on : off);
320 MackieControlProtocol::scrub_press (Mackie::Button &)
322 if (!surfaces.empty()) {
323 // surfaces.front()->next_jog_mode ();
324 _master_surface->next_jog_mode ();
330 MackieControlProtocol::scrub_release (Mackie::Button &)
336 MackieControlProtocol::undo_press (Button&)
338 if (main_modifier_state() & MODIFIER_SHIFT) {
339 Redo(); /* EMIT SIGNAL */
341 Undo(); /* EMIT SIGNAL */
347 MackieControlProtocol::undo_release (Button&)
353 MackieControlProtocol::drop_press (Button &)
355 session->remove_last_capture();
360 MackieControlProtocol::drop_release (Button &)
366 MackieControlProtocol::save_press (Button &)
368 session->save_state ("");
373 MackieControlProtocol::save_release (Button &)
379 MackieControlProtocol::timecode_beats_press (Button &)
381 switch (_timecode_type) {
382 case ARDOUR::AnyTime::BBT:
383 _timecode_type = ARDOUR::AnyTime::Timecode;
385 case ARDOUR::AnyTime::Timecode:
386 _timecode_type = ARDOUR::AnyTime::BBT;
392 update_timecode_beats_led();
398 MackieControlProtocol::timecode_beats_release (Button &)
403 /////////////////////////////////////
405 /////////////////////////////////////
407 MackieControlProtocol::marker_press (Button &)
411 session->locations()->next_available_name (markername,"mcu");
412 add_marker (markername);
418 MackieControlProtocol::marker_release (Button &)
423 /////////////////////////////////////
425 /////////////////////////////////////
428 MackieControlProtocol::stop_press (Button &)
435 MackieControlProtocol::stop_release (Button &)
437 return session->transport_stopped();
441 MackieControlProtocol::play_press (Button &)
443 /* if we're already rolling at normal speed, and we're pressed
444 again, jump back to where we started last time
447 transport_play (session->transport_speed() == 1.0);
452 MackieControlProtocol::play_release (Button &)
458 MackieControlProtocol::record_press (Button &)
460 rec_enable_toggle ();
465 MackieControlProtocol::record_release (Button &)
471 MackieControlProtocol::rewind_press (Button &)
473 if (main_modifier_state() == MODIFIER_CONTROL) {
482 MackieControlProtocol::rewind_release (Button &)
488 MackieControlProtocol::ffwd_press (Button &)
490 if (main_modifier_state() == MODIFIER_CONTROL) {
499 MackieControlProtocol::ffwd_release (Button &)
505 MackieControlProtocol::loop_press (Button &)
507 bool was_on = session->get_play_loop();
508 session->request_play_loop (!was_on);
509 return was_on ? off : on;
513 MackieControlProtocol::loop_release (Button &)
519 MackieControlProtocol::clicking_press (Button &)
521 bool state = !Config->get_clicking();
522 Config->set_clicking (state);
527 MackieControlProtocol::clicking_release (Button &)
529 return Config->get_clicking();
532 LedState MackieControlProtocol::global_solo_press (Button &)
534 bool state = !session->soloing();
535 session->set_solo (session->get_routes(), state);
539 LedState MackieControlProtocol::global_solo_release (Button &)
541 return session->soloing();
545 MackieControlProtocol::enter_press (Button &)
547 Enter(); /* EMIT SIGNAL */
552 MackieControlProtocol::enter_release (Button &)
558 MackieControlProtocol::bank_release (Button& b, uint32_t basic_bank_num)
560 uint32_t bank_num = basic_bank_num;
562 if (b.long_press_count() > 0) {
563 bank_num = 8 + basic_bank_num;
566 switch_banks (n_strips() * bank_num);
572 MackieControlProtocol::F1_press (Button &b)
577 MackieControlProtocol::F1_release (Button &b)
579 return bank_release (b, 0);
582 MackieControlProtocol::F2_press (Button &)
587 MackieControlProtocol::F2_release (Button &b)
589 return bank_release (b, 1);
592 MackieControlProtocol::F3_press (Button &)
597 MackieControlProtocol::F3_release (Button &b)
599 return bank_release (b, 2);
602 MackieControlProtocol::F4_press (Button &)
607 MackieControlProtocol::F4_release (Button &b)
609 return bank_release (b, 3);
612 MackieControlProtocol::F5_press (Button &)
617 MackieControlProtocol::F5_release (Button &)
622 MackieControlProtocol::F6_press (Button &)
627 MackieControlProtocol::F6_release (Button &)
632 MackieControlProtocol::F7_press (Button &)
637 MackieControlProtocol::F7_release (Button &)
642 MackieControlProtocol::F8_press (Button &)
644 CloseDialog (); /* EMIT SIGNAL */
648 MackieControlProtocol::F8_release (Button &)
656 MackieControlProtocol::pan_press (Button &)
662 MackieControlProtocol::pan_release (Button &)
667 MackieControlProtocol::plugin_press (Button &)
672 MackieControlProtocol::plugin_release (Button &)
674 set_view_mode (Plugins);
675 return none; /* LED state set by set_view_mode */
678 MackieControlProtocol::eq_press (Button &)
680 //set_view_mode (EQ);
681 // not implemented yet, turn off (see comments for send button)
685 MackieControlProtocol::eq_release (Button &)
690 MackieControlProtocol::dyn_press (Button &)
692 //set_view_mode (Dynamics);
697 MackieControlProtocol::dyn_release (Button &)
702 MackieControlProtocol::flip_press (Button &)
704 if (_flip_mode != Normal) {
705 set_flip_mode (Normal);
707 set_flip_mode (Mirror);
709 return ((_flip_mode != Normal) ? on : off);
712 MackieControlProtocol::flip_release (Button &)
717 MackieControlProtocol::name_value_press (Button &)
722 MackieControlProtocol::name_value_release (Button &)
727 MackieControlProtocol::touch_press (Button &)
732 MackieControlProtocol::touch_release (Button &)
737 MackieControlProtocol::cancel_press (Button &)
742 MackieControlProtocol::cancel_release (Button &)
747 MackieControlProtocol::user_a_press (Button &)
749 transport_play (session->transport_speed() == 1.0);
753 MackieControlProtocol::user_a_release (Button &)
758 MackieControlProtocol::user_b_press (Button &)
764 MackieControlProtocol::user_b_release (Button &)
770 MackieControlProtocol::master_fader_touch_press (Mackie::Button &)
772 DEBUG_TRACE (DEBUG::MackieControl, "MackieControlProtocol::master_fader_touch_press\n");
774 Fader* master_fader = _master_surface->master_fader();
776 boost::shared_ptr<AutomationControl> ac = master_fader->control ();
778 master_fader->set_in_use (true);
779 master_fader->start_touch (transport_frame());
784 MackieControlProtocol::master_fader_touch_release (Mackie::Button &)
786 DEBUG_TRACE (DEBUG::MackieControl, "MackieControlProtocol::master_fader_touch_release\n");
788 Fader* master_fader = _master_surface->master_fader();
790 master_fader->set_in_use (false);
791 master_fader->stop_touch (transport_frame(), true);
797 MackieControlProtocol::read_press (Mackie::Button&)
799 _metering_active = !_metering_active;
800 notify_metering_state_changed ();
801 return _metering_active;
804 MackieControlProtocol::read_release (Mackie::Button&)
806 return _metering_active;
809 MackieControlProtocol::write_press (Mackie::Button&)
814 MackieControlProtocol::write_release (Mackie::Button&)
819 MackieControlProtocol::clearsolo_press (Mackie::Button&)
824 MackieControlProtocol::clearsolo_release (Mackie::Button&)
829 MackieControlProtocol::track_press (Mackie::Button&)
835 MackieControlProtocol::track_release (Mackie::Button&)
840 MackieControlProtocol::send_press (Mackie::Button&)
843 // remove above line when sends implemented
848 MackieControlProtocol::send_release (Mackie::Button&)
853 MackieControlProtocol::miditracks_press (Mackie::Button&)
858 MackieControlProtocol::miditracks_release (Mackie::Button&)
860 set_view_mode (MidiTracks);
864 MackieControlProtocol::inputs_press (Mackie::Button&)
869 MackieControlProtocol::inputs_release (Mackie::Button&)
874 MackieControlProtocol::audiotracks_press (Mackie::Button&)
879 MackieControlProtocol::audiotracks_release (Mackie::Button&)
881 set_view_mode (AudioTracks);
885 MackieControlProtocol::audioinstruments_press (Mackie::Button&)
890 MackieControlProtocol::audioinstruments_release (Mackie::Button&)
895 MackieControlProtocol::aux_press (Mackie::Button&)
900 MackieControlProtocol::aux_release (Mackie::Button&)
902 set_view_mode (Auxes);
906 MackieControlProtocol::busses_press (Mackie::Button&)
911 MackieControlProtocol::busses_release (Mackie::Button&)
913 set_view_mode (Busses);
917 MackieControlProtocol::outputs_press (Mackie::Button&)
922 MackieControlProtocol::outputs_release (Mackie::Button&)
927 MackieControlProtocol::user_press (Mackie::Button&)
932 MackieControlProtocol::user_release (Mackie::Button&)
934 set_view_mode (Selected);
938 MackieControlProtocol::trim_press (Mackie::Button&)
943 MackieControlProtocol::trim_release (Mackie::Button&)
948 MackieControlProtocol::latch_press (Mackie::Button&)
953 MackieControlProtocol::latch_release (Mackie::Button&)
958 MackieControlProtocol::grp_press (Mackie::Button&)
963 MackieControlProtocol::grp_release (Mackie::Button&)
968 MackieControlProtocol::nudge_press (Mackie::Button&)
973 MackieControlProtocol::nudge_release (Mackie::Button&)
978 MackieControlProtocol::replace_press (Mackie::Button&)
983 MackieControlProtocol::replace_release (Mackie::Button&)
988 MackieControlProtocol::click_press (Mackie::Button&)
993 MackieControlProtocol::click_release (Mackie::Button&)
998 MackieControlProtocol::view_press (Mackie::Button&)
1000 set_view_mode (Mixer);
1004 MackieControlProtocol::view_release (Mackie::Button&)