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