MCP: track control press/release events
[ardour.git] / libs / surfaces / mackie / mcp_buttons.cc
1 /*
2         Copyright (C) 2006,2007 John Anderson
3         Copyright (C) 2012 Paul Davis
4
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.
9
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.
14
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.
18 */
19
20 #include "pbd/memento_command.h"
21
22 #include "ardour/debug.h"
23 #include "ardour/session.h"
24 #include "ardour/route.h"
25 #include "ardour/location.h"
26 #include "ardour/rc_configuration.h"
27
28 #include "mackie_control_protocol.h"
29 #include "surface.h"
30
31 #include "i18n.h"
32
33 /* handlers for all buttons, broken into a separate file to avoid clutter in
34  * mackie_control_protocol.cc 
35  */
36
37 using namespace Mackie;
38 using namespace ARDOUR;
39 using namespace PBD;
40 using std::string;
41
42 LedState
43 MackieControlProtocol::shift_press (Button &)
44 {
45         _modifier_state |= MODIFIER_SHIFT;
46         return on;
47 }
48 LedState
49 MackieControlProtocol::shift_release (Button &)
50 {
51         _modifier_state &= ~MODIFIER_SHIFT;
52         return on;
53 }
54 LedState
55 MackieControlProtocol::option_press (Button &)
56 {
57         _modifier_state |= MODIFIER_OPTION;
58         return on;
59 }
60 LedState
61 MackieControlProtocol::option_release (Button &)
62 {
63         _modifier_state &= ~MODIFIER_OPTION;
64         return on;
65 }
66 LedState
67 MackieControlProtocol::control_press (Button &)
68 {
69         _modifier_state |= MODIFIER_CONTROL;
70         DEBUG_TRACE (DEBUG::MackieControl, string_compose ("CONTROL Press: modifier state now set to %1\n", _modifier_state));
71         return on;
72 }
73 LedState
74 MackieControlProtocol::control_release (Button &)
75 {
76         _modifier_state &= ~MODIFIER_CONTROL;
77         DEBUG_TRACE (DEBUG::MackieControl, string_compose ("CONTROL Release: modifier state now set to %1\n", _modifier_state));
78         return on;
79 }
80 LedState
81 MackieControlProtocol::cmd_alt_press (Button &)
82 {
83         _modifier_state |= MODIFIER_CMDALT;
84         return on;
85 }
86 LedState
87 MackieControlProtocol::cmd_alt_release (Button &)
88 {
89         _modifier_state &= ~MODIFIER_CMDALT;
90         return on;
91 }
92
93 LedState 
94 MackieControlProtocol::left_press (Button &)
95 {
96         Sorted sorted = get_sorted_routes();
97         uint32_t strip_cnt = n_strips ();
98
99         DEBUG_TRACE (DEBUG::MackieControl, string_compose ("bank left with current initial = %1 nstrips = %2 tracks/busses = %3\n",
100                                                            _current_initial_bank, strip_cnt, sorted.size()));
101
102         if (sorted.size() > strip_cnt) {
103                 int new_initial = _current_initial_bank - strip_cnt;
104                 if (new_initial < 0) {
105                         new_initial = 0;
106                 }
107                 
108                 if (new_initial != int (_current_initial_bank)) {
109                         switch_banks (new_initial);
110                 }
111
112                 return on;
113         } else {
114                 return flashing;
115         }
116 }
117
118 LedState 
119 MackieControlProtocol::left_release (Button &)
120 {
121         return off;
122 }
123
124 LedState 
125 MackieControlProtocol::right_press (Button &)
126 {
127         Sorted sorted = get_sorted_routes();
128         uint32_t strip_cnt = n_strips();
129
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, sorted.size()));
132
133         if (sorted.size() > strip_cnt) {
134                 uint32_t delta = sorted.size() - (strip_cnt + _current_initial_bank);
135
136                 if (delta > strip_cnt) {
137                         delta = strip_cnt;
138                 }
139                 
140                 if (delta > 0) {
141                         switch_banks (_current_initial_bank + delta);
142                 }
143
144                 return on;
145         } else {
146                 return flashing;
147         }
148         return off;
149 }
150
151 LedState 
152 MackieControlProtocol::right_release (Button &)
153 {
154         if (_zoom_mode) {
155
156         }
157
158         return off;
159 }
160
161 LedState
162 MackieControlProtocol::cursor_left_press (Button& )
163 {
164         if (_zoom_mode) {
165
166                 if (_modifier_state & MODIFIER_OPTION) {
167                         /* reset selected tracks to default vertical zoom */
168                 } else {
169                         ZoomOut (); /* EMIT SIGNAL */
170                 }
171         } else {
172                 float page_fraction;
173                 if (_modifier_state == MODIFIER_CONTROL) {
174                         page_fraction = 1.0;
175                 } else if (_modifier_state == MODIFIER_OPTION) {
176                         page_fraction = 0.1;
177                 } else if (_modifier_state == MODIFIER_SHIFT) {
178                         page_fraction = 2.0;
179                 } else {
180                         page_fraction = 0.25;
181                 }
182
183                 ScrollTimeline (-page_fraction);
184         }
185
186         return off;
187 }
188
189 LedState
190 MackieControlProtocol::cursor_left_release (Button&)
191 {
192         return off;
193 }
194
195 LedState
196 MackieControlProtocol::cursor_right_press (Button& )
197 {
198         if (_zoom_mode) {
199                 
200                 if (_modifier_state & MODIFIER_OPTION) {
201                         /* reset selected tracks to default vertical zoom */
202                 } else {
203                         ZoomIn (); /* EMIT SIGNAL */
204                 }
205         } else {
206                 float page_fraction;
207                 if (_modifier_state == MODIFIER_CONTROL) {
208                         page_fraction = 1.0;
209                 } else if (_modifier_state == MODIFIER_OPTION) {
210                         page_fraction = 0.1;
211                 } else if (_modifier_state == MODIFIER_SHIFT) {
212                         page_fraction = 2.0;
213                 } else {
214                         page_fraction = 0.25;
215                 }
216
217                 ScrollTimeline (page_fraction);
218         }
219                         
220         return off;
221 }
222
223 LedState
224 MackieControlProtocol::cursor_right_release (Button&)
225 {
226         return off;
227 }
228
229 LedState
230 MackieControlProtocol::cursor_up_press (Button&)
231 {
232         if (_zoom_mode) {
233                 
234                 if (_modifier_state & MODIFIER_CONTROL) {
235                         VerticalZoomInSelected (); /* EMIT SIGNAL */
236                 } else {
237                         VerticalZoomInAll (); /* EMIT SIGNAL */
238                 }
239         }
240         return off;
241 }
242
243 LedState
244 MackieControlProtocol::cursor_up_release (Button&)
245 {
246         return off;
247 }
248
249 LedState
250 MackieControlProtocol::cursor_down_press (Button&)
251 {
252         if (_zoom_mode) {
253                 if (_modifier_state & MODIFIER_OPTION) {
254                         VerticalZoomOutSelected (); /* EMIT SIGNAL */
255                 } else {
256                         VerticalZoomOutAll (); /* EMIT SIGNAL */
257                 }
258         }
259         return off;
260 }
261
262 LedState
263 MackieControlProtocol::cursor_down_release (Button&)
264 {
265         return off;
266 }
267
268 LedState 
269 MackieControlProtocol::channel_left_press (Button &)
270 {
271         Sorted sorted = get_sorted_routes();
272         if (sorted.size() > n_strips()) {
273                 prev_track();
274                 return on;
275         } else {
276                 return flashing;
277         }
278 }
279
280 LedState 
281 MackieControlProtocol::channel_left_release (Button &)
282 {
283         return off;
284 }
285
286 LedState 
287 MackieControlProtocol::channel_right_press (Button &)
288 {
289         Sorted sorted = get_sorted_routes();
290         if (sorted.size() > n_strips()) {
291                 next_track();
292                 return on;
293         } else {
294                 return flashing;
295         }
296 }
297
298 LedState 
299 MackieControlProtocol::channel_right_release (Button &)
300 {
301         return off;
302 }
303
304 Mackie::LedState 
305 MackieControlProtocol::zoom_press (Mackie::Button &)
306 {
307         _zoom_mode = !_zoom_mode;
308         return (_zoom_mode ? on : off);
309 }
310
311 Mackie::LedState 
312 MackieControlProtocol::zoom_release (Mackie::Button &)
313 {
314         return (_zoom_mode ? on : off);
315 }
316
317 Mackie::LedState 
318 MackieControlProtocol::scrub_press (Mackie::Button &)
319 {
320         _scrub_mode = !_scrub_mode;
321         return (_scrub_mode ? on : off);
322 }
323
324 Mackie::LedState 
325 MackieControlProtocol::scrub_release (Mackie::Button &)
326 {
327         return (_scrub_mode ? on : off);
328 }
329
330 LedState
331 MackieControlProtocol::undo_press (Button&)
332 {
333         if (_modifier_state & MODIFIER_SHIFT) {
334                 Redo(); /* EMIT SIGNAL */
335         } else {
336                 Undo(); /* EMIT SIGNAL */
337         }
338         return off;
339 }
340
341 LedState
342 MackieControlProtocol::undo_release (Button&)
343 {
344         return off;
345 }
346
347 LedState
348 MackieControlProtocol::redo_press (Button&)
349 {
350         Redo(); /* EMIT SIGNAL */
351         return off;
352 }
353
354 LedState
355 MackieControlProtocol::redo_release (Button&)
356 {
357         return off;
358 }
359
360 LedState 
361 MackieControlProtocol::drop_press (Button &)
362 {
363         session->remove_last_capture();
364         return on;
365 }
366
367 LedState 
368 MackieControlProtocol::drop_release (Button &)
369 {
370         return off;
371 }
372
373 LedState 
374 MackieControlProtocol::save_press (Button &)
375 {
376         session->save_state ("");
377         return on;
378 }
379
380 LedState 
381 MackieControlProtocol::save_release (Button &)
382 {
383         return off;
384 }
385
386 LedState 
387 MackieControlProtocol::timecode_beats_press (Button &)
388 {
389         switch (_timecode_type) {
390         case ARDOUR::AnyTime::BBT:
391                 _timecode_type = ARDOUR::AnyTime::Timecode;
392                 break;
393         case ARDOUR::AnyTime::Timecode:
394                 _timecode_type = ARDOUR::AnyTime::BBT;
395                 break;
396         default:
397                 return off;
398         }
399
400         update_timecode_beats_led();
401
402         return on;
403 }
404
405 LedState 
406 MackieControlProtocol::timecode_beats_release (Button &)
407 {
408         return off;
409 }
410
411 /////////////////////////////////////
412 // Functions
413 /////////////////////////////////////
414 LedState 
415 MackieControlProtocol::marker_press (Button &)
416 {
417         string markername;
418
419         session->locations()->next_available_name (markername,"mcu");
420         add_marker (markername);
421
422         return on;
423 }
424
425 LedState 
426 MackieControlProtocol::marker_release (Button &)
427 {
428         return off;
429 }
430
431 /////////////////////////////////////
432 // Transport Buttons
433 /////////////////////////////////////
434
435 LedState 
436 MackieControlProtocol::frm_left_press (Button &)
437 {
438         // can use first_mark_before/after as well
439         unsigned long elapsed = _frm_left_last.restart();
440
441         Location * loc = session->locations()->first_location_before (
442                 session->transport_frame()
443         );
444
445         // allow a quick double to go past a previous mark
446         if (session->transport_rolling() && elapsed < 500 && loc != 0) {
447                 Location * loc_two_back = session->locations()->first_location_before (loc->start());
448                 if (loc_two_back != 0)
449                 {
450                         loc = loc_two_back;
451                 }
452         }
453
454         // move to the location, if it's valid
455         if (loc != 0) {
456                 session->request_locate (loc->start(), session->transport_rolling());
457         }
458
459         return on;
460 }
461
462 LedState 
463 MackieControlProtocol::frm_left_release (Button &)
464 {
465         return off;
466 }
467
468 LedState 
469 MackieControlProtocol::frm_right_press (Button &)
470 {
471         // can use first_mark_before/after as well
472         Location * loc = session->locations()->first_location_after (session->transport_frame());
473         
474         if (loc != 0) {
475                 session->request_locate (loc->start(), session->transport_rolling());
476         }
477                 
478         return on;
479 }
480
481 LedState 
482 MackieControlProtocol::frm_right_release (Button &)
483 {
484         return off;
485 }
486
487 LedState 
488 MackieControlProtocol::stop_press (Button &)
489 {
490         transport_stop ();
491         return on;
492 }
493
494 LedState 
495 MackieControlProtocol::stop_release (Button &)
496 {
497         return session->transport_stopped();
498 }
499
500 LedState 
501 MackieControlProtocol::play_press (Button &)
502 {
503         /* if we're already rolling, and we're pressed
504            again, jump back to where we started last time
505         */
506
507         transport_play (session->transport_rolling());
508         return none;
509 }
510
511 LedState 
512 MackieControlProtocol::play_release (Button &)
513 {
514         return none;
515 }
516
517 LedState 
518 MackieControlProtocol::record_press (Button &)
519 {
520         rec_enable_toggle ();
521         return none;
522 }
523
524 LedState 
525 MackieControlProtocol::record_release (Button &)
526 {
527         return none;
528 }
529
530 LedState 
531 MackieControlProtocol::rewind_press (Button &)
532 {
533         DEBUG_TRACE (DEBUG::MackieControl, "REWIND PRESS\n");
534         rewind ();
535         return none;
536 }
537
538 LedState 
539 MackieControlProtocol::rewind_release (Button &)
540 {
541         return none;
542 }
543
544 LedState 
545 MackieControlProtocol::ffwd_press (Button &)
546 {
547         ffwd ();
548         return none;
549 }
550
551 LedState 
552 MackieControlProtocol::ffwd_release (Button &)
553 {
554         return none;
555 }
556
557 LedState 
558 MackieControlProtocol::loop_press (Button &)
559 {
560         if (_modifier_state & MODIFIER_CONTROL) {
561                 set_view_mode (Loop);
562                 return on;
563         } else {
564                 session->request_play_loop (!session->get_play_loop());
565                 return none;
566         }
567 }
568
569 LedState 
570 MackieControlProtocol::loop_release (Button &)
571 {
572         return none;
573 }
574
575 LedState 
576 MackieControlProtocol::punch_in_press (Button &)
577 {
578         bool const state = !session->config.get_punch_in();
579         session->config.set_punch_in (state);
580         return state;
581 }
582
583 LedState 
584 MackieControlProtocol::punch_in_release (Button &)
585 {
586         return session->config.get_punch_in();
587 }
588
589 LedState 
590 MackieControlProtocol::punch_out_press (Button &)
591 {
592         bool const state = !session->config.get_punch_out();
593         session->config.set_punch_out (state);
594         return state;
595 }
596
597 LedState 
598 MackieControlProtocol::punch_out_release (Button &)
599 {
600         return session->config.get_punch_out();
601 }
602
603 LedState 
604 MackieControlProtocol::home_press (Button &)
605 {
606         session->goto_start();
607         return on;
608 }
609
610 LedState 
611 MackieControlProtocol::home_release (Button &)
612 {
613         return off;
614 }
615
616 LedState 
617 MackieControlProtocol::end_press (Button &)
618 {
619         session->goto_end();
620         return on;
621 }
622
623 LedState 
624 MackieControlProtocol::end_release (Button &)
625 {
626         return off;
627 }
628
629 LedState 
630 MackieControlProtocol::clicking_press (Button &)
631 {
632         bool state = !Config->get_clicking();
633         Config->set_clicking (state);
634         return state;
635 }
636
637 LedState 
638 MackieControlProtocol::clicking_release (Button &)
639 {
640         return Config->get_clicking();
641 }
642
643 LedState MackieControlProtocol::global_solo_press (Button &)
644 {
645         bool state = !session->soloing();
646         session->set_solo (session->get_routes(), state);
647         return state;
648 }
649
650 LedState MackieControlProtocol::global_solo_release (Button &)
651 {
652         return session->soloing();
653 }
654
655 LedState
656 MackieControlProtocol::enter_press (Button &) 
657
658         Enter(); /* EMIT SIGNAL */
659         return off;
660 }
661
662 LedState
663 MackieControlProtocol::enter_release (Button &) 
664
665         return off;
666 }
667 LedState
668 MackieControlProtocol::F1_press (Button &) 
669
670         f_press (0);
671         return off; 
672 }
673 LedState
674 MackieControlProtocol::F1_release (Button &) 
675
676         return off; 
677 }
678 LedState
679 MackieControlProtocol::F2_press (Button &) 
680
681         f_press (1);
682         return off; 
683 }
684 LedState
685 MackieControlProtocol::F2_release (Button &) 
686
687         return off; 
688 }
689 LedState
690 MackieControlProtocol::F3_press (Button &) 
691
692         f_press (2);
693         return off; 
694 }
695 LedState
696 MackieControlProtocol::F3_release (Button &) 
697
698         return off; 
699 }
700 LedState
701 MackieControlProtocol::F4_press (Button &) 
702
703         f_press (3);
704         return off; 
705 }
706 LedState
707 MackieControlProtocol::F4_release (Button &) 
708
709         return off; 
710 }
711 LedState
712 MackieControlProtocol::F5_press (Button &) 
713
714         f_press (4);
715         return off; 
716 }
717 LedState
718 MackieControlProtocol::F5_release (Button &) 
719
720         return off; 
721 }
722 LedState
723 MackieControlProtocol::F6_press (Button &) 
724
725         f_press (5);
726         return off; 
727 }
728 LedState
729 MackieControlProtocol::F6_release (Button &) 
730
731         return off; 
732 }
733 LedState
734 MackieControlProtocol::F7_press (Button &) 
735
736         f_press (6);
737         return off; 
738 }
739 LedState
740 MackieControlProtocol::F7_release (Button &) 
741
742         return off; 
743 }
744 LedState
745 MackieControlProtocol::F8_press (Button &) 
746
747         CloseDialog (); /* EMIT SIGNAL */
748         return off; 
749 }
750 LedState
751 MackieControlProtocol::F8_release (Button &) 
752
753         return off; 
754 }
755
756 /* UNIMPLEMENTED */
757
758 LedState
759 MackieControlProtocol::io_press (Button &) 
760
761         return off; 
762 }
763 LedState
764 MackieControlProtocol::io_release (Button &) 
765
766         return off; 
767 }
768 LedState
769 MackieControlProtocol::sends_press (Button &) 
770
771         set_view_mode (Sends);
772         return on;
773 }
774 LedState
775 MackieControlProtocol::sends_release (Button &) 
776
777         return none; 
778 }
779 LedState
780 MackieControlProtocol::pan_press (Button &) 
781
782         return off; 
783 }
784 LedState
785 MackieControlProtocol::pan_release (Button &) 
786
787         return off; 
788 }
789 LedState
790 MackieControlProtocol::plugin_press (Button &) 
791
792         return off; 
793 }
794 LedState
795 MackieControlProtocol::plugin_release (Button &) 
796
797         return off; 
798 }
799 LedState
800 MackieControlProtocol::eq_press (Button &) 
801
802         set_view_mode (EQ);
803         return on;
804 }
805 LedState
806 MackieControlProtocol::eq_release (Button &) 
807
808         return none;
809 }
810 LedState
811 MackieControlProtocol::dyn_press (Button &) 
812
813         set_view_mode (Dynamics);
814         return on;
815 }
816 LedState
817 MackieControlProtocol::dyn_release (Button &) 
818
819         return none;
820 }
821 LedState
822 MackieControlProtocol::flip_press (Button &) 
823
824         FlipMode m;
825
826         if (_modifier_state == 0) {
827                 if (_flip_mode != Normal) {
828                         m = Normal;
829                 } else {
830                         m = Swap;
831                 }
832         } else if (_modifier_state & MODIFIER_CONTROL) {
833                 m = Zero;
834         }
835
836         set_flip_mode (m);
837
838         return (_flip_mode != Normal ? on : off);
839 }
840 LedState
841 MackieControlProtocol::flip_release (Button &) 
842
843         return none;
844 }
845 LedState
846 MackieControlProtocol::edit_press (Button &) 
847
848         return off; 
849 }
850 LedState
851 MackieControlProtocol::edit_release (Button &) 
852
853         return off; 
854 }
855 LedState
856 MackieControlProtocol::name_value_press (Button &) 
857
858         return off; 
859 }
860 LedState
861 MackieControlProtocol::name_value_release (Button &) 
862
863         return off; 
864 }
865 LedState
866 MackieControlProtocol::F9_press (Button &) 
867
868         return off; 
869 }
870 LedState
871 MackieControlProtocol::F9_release (Button &) 
872
873         return off; 
874 }
875 LedState
876 MackieControlProtocol::F10_press (Button &) 
877
878         return off; 
879 }
880 LedState
881 MackieControlProtocol::F10_release (Button &) 
882
883         return off; 
884 }
885 LedState
886 MackieControlProtocol::F11_press (Button &) 
887
888         return off; 
889 }
890 LedState
891 MackieControlProtocol::F11_release (Button &) 
892
893         return off; 
894 }
895 LedState
896 MackieControlProtocol::F12_press (Button &) 
897
898         return off; 
899 }
900 LedState
901 MackieControlProtocol::F12_release (Button &) 
902
903         return off; 
904 }
905 LedState
906 MackieControlProtocol::F13_press (Button &) 
907
908         return off; 
909 }
910 LedState
911 MackieControlProtocol::F13_release (Button &) 
912
913         return off; 
914 }
915 LedState
916 MackieControlProtocol::F14_press (Button &) 
917
918         return off; 
919 }
920 LedState
921 MackieControlProtocol::F14_release (Button &) 
922
923         return off; 
924 }
925 LedState
926 MackieControlProtocol::F15_press (Button &) 
927
928         return off; 
929 }
930 LedState
931 MackieControlProtocol::F15_release (Button &) 
932
933         return off; 
934 }
935 LedState
936 MackieControlProtocol::F16_press (Button &) 
937
938         return off; 
939 }
940 LedState
941 MackieControlProtocol::F16_release (Button &) 
942
943         return off; 
944 }
945 LedState
946 MackieControlProtocol::on_press (Button &) 
947
948         return off; 
949 }
950 LedState
951 MackieControlProtocol::on_release (Button &) 
952
953         return off; 
954 }
955 LedState
956 MackieControlProtocol::rec_ready_press (Button &) 
957
958         return off; 
959 }
960 LedState
961 MackieControlProtocol::rec_ready_release (Button &) 
962
963         return off; 
964 }
965 LedState
966 MackieControlProtocol::touch_press (Button &) 
967
968         return off; 
969 }
970 LedState
971 MackieControlProtocol::touch_release (Button &) 
972
973         return off; 
974 }
975 LedState
976 MackieControlProtocol::cancel_press (Button &) 
977
978         return off; 
979 }
980 LedState
981 MackieControlProtocol::cancel_release (Button &) 
982
983         return off; 
984 }
985 LedState
986 MackieControlProtocol::mixer_press (Button &) 
987
988         return off; 
989 }
990 LedState
991 MackieControlProtocol::mixer_release (Button &) 
992
993         return off; 
994 }
995 LedState
996 MackieControlProtocol::user_a_press (Button &) 
997
998         return off; 
999 }
1000 LedState
1001 MackieControlProtocol::user_a_release (Button &) 
1002
1003         return off; 
1004 }
1005 LedState
1006 MackieControlProtocol::user_b_press (Button &) 
1007
1008         return off; 
1009 }
1010 LedState
1011 MackieControlProtocol::user_b_release (Button &) 
1012
1013         return off; 
1014 }