2 Copyright (C) 2006,2007 John Anderson
3 Copyright (C) 2012 Paul Davis
4 Copyright (C) 2017 Ben Loftis
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include "pbd/memento_command.h"
25 #include "ardour/debug.h"
26 #include "ardour/profile.h"
27 #include "ardour/session.h"
28 #include "ardour/route.h"
29 #include "ardour/location.h"
30 #include "ardour/rc_configuration.h"
32 #include "us2400_control_protocol.h"
38 /* handlers for all buttons, broken into a separate file to avoid clutter in
39 * us2400_control_protocol.cc
43 using namespace ARDOUR;
45 using namespace ArdourSurface;
46 using namespace US2400;
49 US2400Protocol::shift_press (Button &)
51 _modifier_state |= MODIFIER_SHIFT;
55 US2400Protocol::shift_release (Button &)
57 _modifier_state &= ~MODIFIER_SHIFT;
61 US2400Protocol::option_press (Button &)
63 _modifier_state |= MODIFIER_OPTION;
67 US2400Protocol::option_release (Button &)
69 _modifier_state &= ~MODIFIER_OPTION;
73 US2400Protocol::control_press (Button &)
75 _modifier_state |= MODIFIER_CONTROL;
76 DEBUG_TRACE (DEBUG::US2400, string_compose ("CONTROL Press: modifier state now set to %1\n", _modifier_state));
80 US2400Protocol::control_release (Button &)
82 _modifier_state &= ~MODIFIER_CONTROL;
83 DEBUG_TRACE (DEBUG::US2400, string_compose ("CONTROL Release: modifier state now set to %1\n", _modifier_state));
87 US2400Protocol::cmd_alt_press (Button &)
89 _modifier_state |= MODIFIER_CMDALT;
93 US2400Protocol::cmd_alt_release (Button &)
95 _modifier_state &= ~MODIFIER_CMDALT;
100 US2400Protocol::left_press (Button &)
102 if (_subview_mode != None) {
106 Sorted sorted = get_sorted_stripables();
107 uint32_t strip_cnt = n_strips ();
109 DEBUG_TRACE (DEBUG::US2400, string_compose ("bank left with current initial = %1 nstrips = %2 tracks/busses = %3\n",
110 _current_initial_bank, strip_cnt, sorted.size()));
111 if (_current_initial_bank > 0) {
112 (void) switch_banks ((_current_initial_bank - 1) / strip_cnt * strip_cnt);
114 (void) switch_banks (0);
122 US2400Protocol::left_release (Button &)
128 US2400Protocol::right_press (Button &)
130 if (_subview_mode != None) {
134 Sorted sorted = get_sorted_stripables();
135 uint32_t strip_cnt = n_strips();
136 uint32_t route_cnt = sorted.size();
137 uint32_t max_bank = route_cnt / strip_cnt * strip_cnt;
140 DEBUG_TRACE (DEBUG::US2400, string_compose ("bank right with current initial = %1 nstrips = %2 tracks/busses = %3\n",
141 _current_initial_bank, strip_cnt, route_cnt));
143 if (_current_initial_bank < max_bank) {
144 uint32_t new_initial = (_current_initial_bank / strip_cnt * strip_cnt) + strip_cnt;
145 (void) switch_banks (new_initial);
152 US2400Protocol::right_release (Button &)
158 US2400Protocol::cursor_left_press (Button& )
162 if (main_modifier_state() & MODIFIER_OPTION) {
163 /* reset selected tracks to default vertical zoom */
165 ZoomOut (); /* EMIT SIGNAL */
169 if (main_modifier_state() == MODIFIER_CONTROL) {
171 } else if (main_modifier_state() == MODIFIER_OPTION) {
173 } else if (main_modifier_state() == MODIFIER_SHIFT) {
176 page_fraction = 0.25;
179 ScrollTimeline (-page_fraction);
186 US2400Protocol::cursor_left_release (Button&)
192 US2400Protocol::cursor_right_press (Button& )
196 if (main_modifier_state() & MODIFIER_OPTION) {
197 /* reset selected tracks to default vertical zoom */
199 ZoomIn (); /* EMIT SIGNAL */
203 if (main_modifier_state() == MODIFIER_CONTROL) {
205 } else if (main_modifier_state() == MODIFIER_OPTION) {
207 } else if (main_modifier_state() == MODIFIER_SHIFT) {
210 page_fraction = 0.25;
213 ScrollTimeline (page_fraction);
220 US2400Protocol::cursor_right_release (Button&)
226 US2400Protocol::cursor_up_press (Button&)
230 if (main_modifier_state() & MODIFIER_CONTROL) {
231 VerticalZoomInSelected (); /* EMIT SIGNAL */
233 VerticalZoomInAll (); /* EMIT SIGNAL */
236 access_action ("Editor/select-prev-route");
242 US2400Protocol::cursor_up_release (Button&)
248 US2400Protocol::cursor_down_press (Button&)
251 if (main_modifier_state() & MODIFIER_OPTION) {
252 VerticalZoomOutSelected (); /* EMIT SIGNAL */
254 VerticalZoomOutAll (); /* EMIT SIGNAL */
257 access_action ("Editor/select-next-route");
263 US2400Protocol::cursor_down_release (Button&)
269 US2400Protocol::channel_left_press (Button &)
271 if (_subview_mode != None) {
274 Sorted sorted = get_sorted_stripables();
275 if (sorted.size() > n_strips()) {
284 US2400Protocol::channel_left_release (Button &)
290 US2400Protocol::channel_right_press (Button &)
292 if (_subview_mode != None) {
295 Sorted sorted = get_sorted_stripables();
296 if (sorted.size() > n_strips()) {
305 US2400Protocol::channel_right_release (Button &)
311 US2400Protocol::zoom_press (US2400::Button &)
317 US2400Protocol::zoom_release (US2400::Button &)
319 if (_modifier_state & MODIFIER_ZOOM) {
320 _modifier_state &= ~MODIFIER_ZOOM;
322 _modifier_state |= MODIFIER_ZOOM;
325 return (zoom_mode() ? on : off);
329 US2400Protocol::scrub_press (US2400::Button &)
331 if (!surfaces.empty()) {
332 // surfaces.front()->next_jog_mode ();
333 _master_surface->next_jog_mode ();
339 US2400Protocol::scrub_release (US2400::Button &)
345 US2400Protocol::undo_press (Button&)
347 if (main_modifier_state() == MODIFIER_SHIFT) {
356 US2400Protocol::undo_release (Button&)
362 US2400Protocol::drop_press (Button &)
364 _modifier_state |= MODIFIER_DROP;
365 printf("drop press, modifier drop state = %d\n", _modifier_state);
371 US2400Protocol::drop_release (Button &)
373 _modifier_state &= ~MODIFIER_DROP;
374 printf("drop release, modifier drop state = %d\n", _modifier_state);
380 US2400Protocol::save_press (Button &)
382 if (main_modifier_state() == MODIFIER_SHIFT) {
383 quick_snapshot_switch();
392 US2400Protocol::save_release (Button &)
398 US2400Protocol::timecode_beats_press (Button &)
400 switch (_timecode_type) {
401 case ARDOUR::AnyTime::BBT:
402 _timecode_type = ARDOUR::AnyTime::Timecode;
404 case ARDOUR::AnyTime::Timecode:
405 _timecode_type = ARDOUR::AnyTime::BBT;
411 update_timecode_beats_led();
417 US2400Protocol::timecode_beats_release (Button &)
422 /////////////////////////////////////
424 /////////////////////////////////////
426 US2400Protocol::marker_press (Button &)
428 if (main_modifier_state() & MODIFIER_SHIFT) {
429 access_action ("Common/remove-location-from-playhead");
432 _modifier_state |= MODIFIER_MARKER;
433 marker_modifier_consumed_by_button = false;
439 US2400Protocol::marker_release (Button &)
441 _modifier_state &= ~MODIFIER_MARKER;
443 if (main_modifier_state() & MODIFIER_SHIFT) {
444 return off; //if shift was held, we already did the action
447 if (marker_modifier_consumed_by_button) {
448 DEBUG_TRACE (DEBUG::US2400, "marked modifier consumed by button, ignored\n");
449 /* marker was used a modifier for some other button(s), so do
457 /* Don't add another mark if one exists within 1/100th of a second of
458 * the current position and we're not rolling.
461 samplepos_t where = session->audible_sample();
463 if (session->transport_stopped() && session->locations()->mark_at (where, session->sample_rate() / 100.0)) {
467 session->locations()->next_available_name (markername,"mark");
468 add_marker (markername);
473 /////////////////////////////////////
475 /////////////////////////////////////
478 US2400Protocol::stop_press (Button &)
482 if (main_modifier_state() == MODIFIER_SHIFT) {
483 session->midi_panic();
490 US2400Protocol::stop_release (Button &)
492 return session->transport_stopped();
496 US2400Protocol::play_press (Button &)
498 /* if we're already rolling at normal speed, and we're pressed
499 again, jump back to where we started last time
502 transport_play (session->transport_speed() == 1.0);
507 US2400Protocol::play_release (Button &)
513 US2400Protocol::record_press (Button &)
515 rec_enable_toggle ();
520 US2400Protocol::record_release (Button &)
526 US2400Protocol::rewind_press (Button &)
528 if (modifier_state() & MODIFIER_MARKER) {
530 } else if ( (_modifier_state & MODIFIER_DROP) == MODIFIER_DROP) {
531 access_action ("Common/start-range-from-playhead");
532 } else if (main_modifier_state() & MODIFIER_SHIFT) {
541 US2400Protocol::rewind_release (Button &)
547 US2400Protocol::ffwd_press (Button &)
549 if (modifier_state() & MODIFIER_MARKER) {
551 } else if ( (_modifier_state & MODIFIER_DROP) == MODIFIER_DROP) {
552 access_action ("Common/finish-range-from-playhead");
553 } else if (main_modifier_state() & MODIFIER_SHIFT) {
562 US2400Protocol::ffwd_release (Button &)
568 US2400Protocol::loop_press (Button &)
570 if (main_modifier_state() & MODIFIER_SHIFT) {
571 access_action ("Common/set-loop-from-edit-range");
574 bool was_on = session->get_play_loop();
576 return was_on ? off : on;
581 US2400Protocol::loop_release (Button &)
587 US2400Protocol::enter_press (Button &)
589 if (main_modifier_state() & MODIFIER_SHIFT) {
590 access_action ("Transport/ToggleFollowEdits");
592 access_action ("Editor/select-all-tracks");
598 US2400Protocol::enter_release (Button &)
604 US2400Protocol::bank_release (Button& b, uint32_t basic_bank_num)
606 if (_subview_mode != None) {
610 uint32_t bank_num = basic_bank_num;
612 if (b.long_press_count() > 0) {
613 bank_num = 8 + basic_bank_num;
616 (void) switch_banks (n_strips() * bank_num);
621 /* F-KEYS are only used for actions that are bound from the control panel; no need to address them here
623 US2400Protocol::F1_press (Button &b)
628 US2400Protocol::F1_release (Button &b)
633 US2400Protocol::F2_press (Button &)
638 US2400Protocol::F2_release (Button &b)
643 US2400Protocol::F3_press (Button &)
648 US2400Protocol::F3_release (Button &b)
653 US2400Protocol::F4_press (Button &)
658 US2400Protocol::F4_release (Button &b)
663 US2400Protocol::F5_press (Button &)
668 US2400Protocol::F5_release (Button &)
673 US2400Protocol::F6_press (Button &)
678 US2400Protocol::F6_release (Button &)
683 US2400Protocol::F7_press (Button &)
688 US2400Protocol::F7_release (Button &)
693 US2400Protocol::F8_press (Button &)
698 US2400Protocol::F8_release (Button &)
708 US2400Protocol::pan_press (Button &)
710 //US-2400: deselect all strips when the user asks for "Pan". This resets us to default showing the panner only
711 access_action ("Mixer/select-none");
716 US2400Protocol::pan_release (Button &)
721 US2400Protocol::plugin_press (Button &)
726 US2400Protocol::plugin_release (Button &)
728 // Do not do this yet, since it does nothing
729 // set_view_mode (Plugins);
730 return none; /* LED state set by set_view_mode */
733 US2400Protocol::eq_press (Button &)
735 return none; /* led state handled by set_subview_mode() */
739 US2400Protocol::eq_release (Button &)
744 US2400Protocol::dyn_press (Button &)
746 return none; /* led state handled by set_subview_mode() */
750 US2400Protocol::dyn_release (Button &)
756 US2400Protocol::flip_press (Button &)
758 if (_view_mode == Busses) {
759 set_view_mode (Mixer);
762 set_view_mode (Busses);
768 US2400Protocol::flip_release (Button &)
774 US2400Protocol::mstr_press (Button &)
776 // access_action("Mixer/select-none");
777 SetStripableSelection( session->master_out() );
782 US2400Protocol::mstr_release (Button &)
788 US2400Protocol::name_value_press (Button &)
793 US2400Protocol::name_value_release (Button &)
798 US2400Protocol::touch_press (Button &)
803 US2400Protocol::touch_release (Button &)
805 set_automation_state (ARDOUR::Touch);
809 US2400Protocol::cancel_press (Button &)
811 if (main_modifier_state() & MODIFIER_SHIFT) {
812 access_action ("Transport/ToggleExternalSync");
814 access_action ("Main/Escape");
819 US2400Protocol::cancel_release (Button &)
824 US2400Protocol::user_a_press (Button &)
826 transport_play (session->transport_speed() == 1.0);
830 US2400Protocol::user_a_release (Button &)
835 US2400Protocol::user_b_press (Button &)
841 US2400Protocol::user_b_release (Button &)
847 US2400Protocol::master_fader_touch_press (US2400::Button &)
849 DEBUG_TRACE (DEBUG::US2400, "US2400Protocol::master_fader_touch_press\n");
851 Fader* master_fader = _master_surface->master_fader();
853 boost::shared_ptr<AutomationControl> ac = master_fader->control ();
855 master_fader->set_in_use (true);
856 master_fader->start_touch (transport_frame());
861 US2400Protocol::master_fader_touch_release (US2400::Button &)
863 DEBUG_TRACE (DEBUG::US2400, "US2400Protocol::master_fader_touch_release\n");
865 Fader* master_fader = _master_surface->master_fader();
867 master_fader->set_in_use (false);
868 master_fader->stop_touch (transport_frame());
874 US2400Protocol::read_press (US2400::Button&)
880 US2400Protocol::read_release (US2400::Button&)
882 set_automation_state (ARDOUR::Play);
886 US2400Protocol::write_press (US2400::Button&)
891 US2400Protocol::write_release (US2400::Button&)
893 set_automation_state (ARDOUR::Write);
898 US2400Protocol::clearsolo_press (US2400::Button&)
900 // clears all solos and listens (pfl/afl)
901 if (main_modifier_state() & MODIFIER_OPTION) {
909 US2400Protocol::clearsolo_release (US2400::Button&)
911 //return session->soloing();
916 US2400Protocol::track_press (US2400::Button&)
918 set_subview_mode (TrackView, first_selected_stripable());
922 US2400Protocol::track_release (US2400::Button&)
927 US2400Protocol::send_press (US2400::Button&)
929 // _modifier_state |= MODIFIER_AUX; //US2400 ... AUX button is some kind of modifier
932 // set_subview_mode (Sends, first_selected_stripable());
936 return none; /* led state handled by set_subview_mode() */
939 US2400Protocol::send_release (US2400::Button&)
944 US2400Protocol::miditracks_press (US2400::Button&)
949 US2400Protocol::miditracks_release (US2400::Button&)
954 US2400Protocol::inputs_press (US2400::Button&)
959 US2400Protocol::inputs_release (US2400::Button&)
964 US2400Protocol::audiotracks_press (US2400::Button&)
969 US2400Protocol::audiotracks_release (US2400::Button&)
974 US2400Protocol::audioinstruments_press (US2400::Button& b)
980 US2400Protocol::audioinstruments_release (US2400::Button& b)
986 US2400Protocol::aux_press (US2400::Button&)
991 US2400Protocol::aux_release (US2400::Button&)
996 US2400Protocol::busses_press (US2400::Button&)
1001 US2400Protocol::busses_release (US2400::Button&)
1006 US2400Protocol::outputs_press (US2400::Button&)
1011 US2400Protocol::outputs_release (US2400::Button&)
1016 US2400Protocol::user_press (US2400::Button&)
1021 US2400Protocol::user_release (US2400::Button&)
1026 US2400Protocol::trim_press (US2400::Button&)
1031 US2400Protocol::trim_release (US2400::Button&)
1036 US2400Protocol::latch_press (US2400::Button&)
1041 US2400Protocol::latch_release (US2400::Button&)
1046 US2400Protocol::grp_press (US2400::Button&)
1051 US2400Protocol::grp_release (US2400::Button&)
1053 /* There is no "Off" button for automation,
1054 so we use Group for this purpose.
1056 set_automation_state (Off);
1060 US2400Protocol::nudge_press (US2400::Button&)
1062 // _modifier_state |= MODIFIER_NUDGE; //no such button on US2400
1063 nudge_modifier_consumed_by_button = false;
1067 US2400Protocol::nudge_release (US2400::Button&)
1069 // _modifier_state &= ~MODIFIER_NUDGE; //no such button on US2400
1071 /* XXX these action names are stupid, because the action can affect
1072 * regions, markers or the playhead depending on selection state.
1075 if (main_modifier_state() & MODIFIER_SHIFT) {
1076 access_action ("Region/nudge-backward");
1078 access_action ("Region/nudge-forward");
1084 US2400Protocol::replace_press (US2400::Button&)
1086 if (main_modifier_state() == MODIFIER_SHIFT) {
1090 access_action ("Common/finish-range-from-playhead");
1095 US2400Protocol::replace_release (US2400::Button&)
1100 US2400Protocol::click_press (US2400::Button&)
1102 if (main_modifier_state() & MODIFIER_SHIFT) {
1103 access_action ("Common/set-punch-from-edit-range");
1106 bool state = !Config->get_clicking();
1107 Config->set_clicking (state);
1112 US2400Protocol::click_release (US2400::Button&)
1117 US2400Protocol::view_press (US2400::Button&)
1119 set_view_mode (Mixer);
1123 US2400Protocol::view_release (US2400::Button&)