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