MCP: shift-select resets gain to unity; don't jump back to last transport start unles...
[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 at normal speed, and we're pressed
504            again, jump back to where we started last time
505         */
506
507         transport_play (session->transport_rolling() == 1.0);
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         rewind ();
534         return none;
535 }
536
537 LedState 
538 MackieControlProtocol::rewind_release (Button &)
539 {
540         return none;
541 }
542
543 LedState 
544 MackieControlProtocol::ffwd_press (Button &)
545 {
546         ffwd ();
547         return none;
548 }
549
550 LedState 
551 MackieControlProtocol::ffwd_release (Button &)
552 {
553         return none;
554 }
555
556 LedState 
557 MackieControlProtocol::loop_press (Button &)
558 {
559         if (_modifier_state & MODIFIER_CONTROL) {
560                 set_view_mode (Loop);
561                 return on;
562         } else {
563                 session->request_play_loop (!session->get_play_loop());
564                 return none;
565         }
566 }
567
568 LedState 
569 MackieControlProtocol::loop_release (Button &)
570 {
571         return none;
572 }
573
574 LedState 
575 MackieControlProtocol::punch_in_press (Button &)
576 {
577         bool const state = !session->config.get_punch_in();
578         session->config.set_punch_in (state);
579         return state;
580 }
581
582 LedState 
583 MackieControlProtocol::punch_in_release (Button &)
584 {
585         return session->config.get_punch_in();
586 }
587
588 LedState 
589 MackieControlProtocol::punch_out_press (Button &)
590 {
591         bool const state = !session->config.get_punch_out();
592         session->config.set_punch_out (state);
593         return state;
594 }
595
596 LedState 
597 MackieControlProtocol::punch_out_release (Button &)
598 {
599         return session->config.get_punch_out();
600 }
601
602 LedState 
603 MackieControlProtocol::home_press (Button &)
604 {
605         session->goto_start();
606         return on;
607 }
608
609 LedState 
610 MackieControlProtocol::home_release (Button &)
611 {
612         return off;
613 }
614
615 LedState 
616 MackieControlProtocol::end_press (Button &)
617 {
618         session->goto_end();
619         return on;
620 }
621
622 LedState 
623 MackieControlProtocol::end_release (Button &)
624 {
625         return off;
626 }
627
628 LedState 
629 MackieControlProtocol::clicking_press (Button &)
630 {
631         bool state = !Config->get_clicking();
632         Config->set_clicking (state);
633         return state;
634 }
635
636 LedState 
637 MackieControlProtocol::clicking_release (Button &)
638 {
639         return Config->get_clicking();
640 }
641
642 LedState MackieControlProtocol::global_solo_press (Button &)
643 {
644         bool state = !session->soloing();
645         session->set_solo (session->get_routes(), state);
646         return state;
647 }
648
649 LedState MackieControlProtocol::global_solo_release (Button &)
650 {
651         return session->soloing();
652 }
653
654 LedState
655 MackieControlProtocol::enter_press (Button &) 
656
657         Enter(); /* EMIT SIGNAL */
658         return off;
659 }
660
661 LedState
662 MackieControlProtocol::enter_release (Button &) 
663
664         return off;
665 }
666 LedState
667 MackieControlProtocol::F1_press (Button &) 
668
669         f_press (0);
670         return off; 
671 }
672 LedState
673 MackieControlProtocol::F1_release (Button &) 
674
675         return off; 
676 }
677 LedState
678 MackieControlProtocol::F2_press (Button &) 
679
680         f_press (1);
681         return off; 
682 }
683 LedState
684 MackieControlProtocol::F2_release (Button &) 
685
686         return off; 
687 }
688 LedState
689 MackieControlProtocol::F3_press (Button &) 
690
691         f_press (2);
692         return off; 
693 }
694 LedState
695 MackieControlProtocol::F3_release (Button &) 
696
697         return off; 
698 }
699 LedState
700 MackieControlProtocol::F4_press (Button &) 
701
702         f_press (3);
703         return off; 
704 }
705 LedState
706 MackieControlProtocol::F4_release (Button &) 
707
708         return off; 
709 }
710 LedState
711 MackieControlProtocol::F5_press (Button &) 
712
713         f_press (4);
714         return off; 
715 }
716 LedState
717 MackieControlProtocol::F5_release (Button &) 
718
719         return off; 
720 }
721 LedState
722 MackieControlProtocol::F6_press (Button &) 
723
724         f_press (5);
725         return off; 
726 }
727 LedState
728 MackieControlProtocol::F6_release (Button &) 
729
730         return off; 
731 }
732 LedState
733 MackieControlProtocol::F7_press (Button &) 
734
735         f_press (6);
736         return off; 
737 }
738 LedState
739 MackieControlProtocol::F7_release (Button &) 
740
741         return off; 
742 }
743 LedState
744 MackieControlProtocol::F8_press (Button &) 
745
746         CloseDialog (); /* EMIT SIGNAL */
747         return off; 
748 }
749 LedState
750 MackieControlProtocol::F8_release (Button &) 
751
752         return off; 
753 }
754
755 /* UNIMPLEMENTED */
756
757 LedState
758 MackieControlProtocol::io_press (Button &) 
759
760         return off; 
761 }
762 LedState
763 MackieControlProtocol::io_release (Button &) 
764
765         return off; 
766 }
767 LedState
768 MackieControlProtocol::sends_press (Button &) 
769
770         set_view_mode (Sends);
771         return on;
772 }
773 LedState
774 MackieControlProtocol::sends_release (Button &) 
775
776         return none; 
777 }
778 LedState
779 MackieControlProtocol::pan_press (Button &) 
780
781         return off; 
782 }
783 LedState
784 MackieControlProtocol::pan_release (Button &) 
785
786         return off; 
787 }
788 LedState
789 MackieControlProtocol::plugin_press (Button &) 
790
791         return off; 
792 }
793 LedState
794 MackieControlProtocol::plugin_release (Button &) 
795
796         return off; 
797 }
798 LedState
799 MackieControlProtocol::eq_press (Button &) 
800
801         set_view_mode (EQ);
802         return on;
803 }
804 LedState
805 MackieControlProtocol::eq_release (Button &) 
806
807         return none;
808 }
809 LedState
810 MackieControlProtocol::dyn_press (Button &) 
811
812         set_view_mode (Dynamics);
813         return on;
814 }
815 LedState
816 MackieControlProtocol::dyn_release (Button &) 
817
818         return none;
819 }
820 LedState
821 MackieControlProtocol::flip_press (Button &) 
822
823         FlipMode m;
824
825         if (_modifier_state == 0) {
826                 if (_flip_mode != Normal) {
827                         m = Normal;
828                 } else {
829                         m = Swap;
830                 }
831         } else if (_modifier_state & MODIFIER_CONTROL) {
832                 m = Zero;
833         }
834
835         set_flip_mode (m);
836
837         return (_flip_mode != Normal ? on : off);
838 }
839 LedState
840 MackieControlProtocol::flip_release (Button &) 
841
842         return none;
843 }
844 LedState
845 MackieControlProtocol::edit_press (Button &) 
846
847         return off; 
848 }
849 LedState
850 MackieControlProtocol::edit_release (Button &) 
851
852         return off; 
853 }
854 LedState
855 MackieControlProtocol::name_value_press (Button &) 
856
857         return off; 
858 }
859 LedState
860 MackieControlProtocol::name_value_release (Button &) 
861
862         return off; 
863 }
864 LedState
865 MackieControlProtocol::F9_press (Button &) 
866
867         return off; 
868 }
869 LedState
870 MackieControlProtocol::F9_release (Button &) 
871
872         return off; 
873 }
874 LedState
875 MackieControlProtocol::F10_press (Button &) 
876
877         return off; 
878 }
879 LedState
880 MackieControlProtocol::F10_release (Button &) 
881
882         return off; 
883 }
884 LedState
885 MackieControlProtocol::F11_press (Button &) 
886
887         return off; 
888 }
889 LedState
890 MackieControlProtocol::F11_release (Button &) 
891
892         return off; 
893 }
894 LedState
895 MackieControlProtocol::F12_press (Button &) 
896
897         return off; 
898 }
899 LedState
900 MackieControlProtocol::F12_release (Button &) 
901
902         return off; 
903 }
904 LedState
905 MackieControlProtocol::F13_press (Button &) 
906
907         return off; 
908 }
909 LedState
910 MackieControlProtocol::F13_release (Button &) 
911
912         return off; 
913 }
914 LedState
915 MackieControlProtocol::F14_press (Button &) 
916
917         return off; 
918 }
919 LedState
920 MackieControlProtocol::F14_release (Button &) 
921
922         return off; 
923 }
924 LedState
925 MackieControlProtocol::F15_press (Button &) 
926
927         return off; 
928 }
929 LedState
930 MackieControlProtocol::F15_release (Button &) 
931
932         return off; 
933 }
934 LedState
935 MackieControlProtocol::F16_press (Button &) 
936
937         return off; 
938 }
939 LedState
940 MackieControlProtocol::F16_release (Button &) 
941
942         return off; 
943 }
944 LedState
945 MackieControlProtocol::on_press (Button &) 
946
947         return off; 
948 }
949 LedState
950 MackieControlProtocol::on_release (Button &) 
951
952         return off; 
953 }
954 LedState
955 MackieControlProtocol::rec_ready_press (Button &) 
956
957         return off; 
958 }
959 LedState
960 MackieControlProtocol::rec_ready_release (Button &) 
961
962         return off; 
963 }
964 LedState
965 MackieControlProtocol::touch_press (Button &) 
966
967         return off; 
968 }
969 LedState
970 MackieControlProtocol::touch_release (Button &) 
971
972         return off; 
973 }
974 LedState
975 MackieControlProtocol::cancel_press (Button &) 
976
977         return off; 
978 }
979 LedState
980 MackieControlProtocol::cancel_release (Button &) 
981
982         return off; 
983 }
984 LedState
985 MackieControlProtocol::mixer_press (Button &) 
986
987         return off; 
988 }
989 LedState
990 MackieControlProtocol::mixer_release (Button &) 
991
992         return off; 
993 }
994 LedState
995 MackieControlProtocol::user_a_press (Button &) 
996
997         transport_play (session->transport_speed() == 1.0);
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         transport_stop();
1009         return off; 
1010 }
1011 LedState
1012 MackieControlProtocol::user_b_release (Button &) 
1013
1014         return off; 
1015 }