09848577f6f2be2eb64c8bfbb34334caccc4b2ab
[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         // cut'n'paste from LocationUI::add_new_location()
390         string markername;
391         framepos_t where = session->audible_frame();
392         session->locations()->next_available_name(markername,"mcu");
393         Location *location = new Location (*session, where, where, markername, Location::IsMark);
394         session->begin_reversible_command (_("add marker"));
395         XMLNode &before = session->locations()->get_state();
396         session->locations()->add (location, true);
397         XMLNode &after = session->locations()->get_state();
398         session->add_command (new MementoCommand<Locations>(*(session->locations()), &before, &after));
399         session->commit_reversible_command ();
400         return on;
401 }
402
403 LedState 
404 MackieControlProtocol::marker_release (Button &)
405 {
406         return off;
407 }
408
409 /////////////////////////////////////
410 // Transport Buttons
411 /////////////////////////////////////
412
413 LedState 
414 MackieControlProtocol::frm_left_press (Button &)
415 {
416         // can use first_mark_before/after as well
417         unsigned long elapsed = _frm_left_last.restart();
418
419         Location * loc = session->locations()->first_location_before (
420                 session->transport_frame()
421         );
422
423         // allow a quick double to go past a previous mark
424         if (session->transport_rolling() && elapsed < 500 && loc != 0) {
425                 Location * loc_two_back = session->locations()->first_location_before (loc->start());
426                 if (loc_two_back != 0)
427                 {
428                         loc = loc_two_back;
429                 }
430         }
431
432         // move to the location, if it's valid
433         if (loc != 0) {
434                 session->request_locate (loc->start(), session->transport_rolling());
435         }
436
437         return on;
438 }
439
440 LedState 
441 MackieControlProtocol::frm_left_release (Button &)
442 {
443         return off;
444 }
445
446 LedState 
447 MackieControlProtocol::frm_right_press (Button &)
448 {
449         // can use first_mark_before/after as well
450         Location * loc = session->locations()->first_location_after (session->transport_frame());
451         
452         if (loc != 0) {
453                 session->request_locate (loc->start(), session->transport_rolling());
454         }
455                 
456         return on;
457 }
458
459 LedState 
460 MackieControlProtocol::frm_right_release (Button &)
461 {
462         return off;
463 }
464
465 LedState 
466 MackieControlProtocol::stop_press (Button &)
467 {
468         transport_stop ();
469         return on;
470 }
471
472 LedState 
473 MackieControlProtocol::stop_release (Button &)
474 {
475         return session->transport_stopped();
476 }
477
478 LedState 
479 MackieControlProtocol::play_press (Button &)
480 {
481         transport_play ();
482         return on;
483 }
484
485 LedState 
486 MackieControlProtocol::play_release (Button &)
487 {
488         return session->transport_rolling();
489 }
490
491 LedState 
492 MackieControlProtocol::record_press (Button &)
493 {
494         rec_enable_toggle ();
495         return off;
496 }
497
498 LedState 
499 MackieControlProtocol::record_release (Button &)
500 {
501         return off;
502 }
503
504 LedState 
505 MackieControlProtocol::rewind_press (Button &)
506 {
507         rewind ();
508         return off;
509 }
510
511 LedState 
512 MackieControlProtocol::rewind_release (Button &)
513 {
514         return off;
515 }
516
517 LedState 
518 MackieControlProtocol::ffwd_press (Button &)
519 {
520         ffwd ();
521         return off;
522 }
523
524 LedState 
525 MackieControlProtocol::ffwd_release (Button &)
526 {
527         return off;
528 }
529
530 LedState 
531 MackieControlProtocol::loop_press (Button &)
532 {
533         session->request_play_loop (!session->get_play_loop());
534         return off;
535 }
536
537 LedState 
538 MackieControlProtocol::loop_release (Button &)
539 {
540         return off;
541 }
542
543 LedState 
544 MackieControlProtocol::punch_in_press (Button &)
545 {
546         bool const state = !session->config.get_punch_in();
547         session->config.set_punch_in (state);
548         return state;
549 }
550
551 LedState 
552 MackieControlProtocol::punch_in_release (Button &)
553 {
554         return session->config.get_punch_in();
555 }
556
557 LedState 
558 MackieControlProtocol::punch_out_press (Button &)
559 {
560         bool const state = !session->config.get_punch_out();
561         session->config.set_punch_out (state);
562         return state;
563 }
564
565 LedState 
566 MackieControlProtocol::punch_out_release (Button &)
567 {
568         return session->config.get_punch_out();
569 }
570
571 LedState 
572 MackieControlProtocol::home_press (Button &)
573 {
574         session->goto_start();
575         return on;
576 }
577
578 LedState 
579 MackieControlProtocol::home_release (Button &)
580 {
581         return off;
582 }
583
584 LedState 
585 MackieControlProtocol::end_press (Button &)
586 {
587         session->goto_end();
588         return on;
589 }
590
591 LedState 
592 MackieControlProtocol::end_release (Button &)
593 {
594         return off;
595 }
596
597 LedState 
598 MackieControlProtocol::clicking_press (Button &)
599 {
600         bool state = !Config->get_clicking();
601         Config->set_clicking (state);
602         return state;
603 }
604
605 LedState 
606 MackieControlProtocol::clicking_release (Button &)
607 {
608         return Config->get_clicking();
609 }
610
611 LedState MackieControlProtocol::global_solo_press (Button &)
612 {
613         bool state = !session->soloing();
614         session->set_solo (session->get_routes(), state);
615         return state;
616 }
617
618 LedState MackieControlProtocol::global_solo_release (Button &)
619 {
620         return session->soloing();
621 }
622
623 LedState
624 MackieControlProtocol::enter_press (Button &) 
625
626         Enter(); /* EMIT SIGNAL */
627         return off;
628 }
629
630 LedState
631 MackieControlProtocol::enter_release (Button &) 
632
633         return off;
634 }
635
636 LedState
637 MackieControlProtocol::F1_press (Button &) 
638
639         GotoView (0); /* EMIT SIGNAL */
640         return off; 
641 }
642 LedState
643 MackieControlProtocol::F1_release (Button &) 
644
645         return off; 
646 }
647 LedState
648 MackieControlProtocol::F2_press (Button &) 
649
650         GotoView (1); /* EMIT SIGNAL */
651         return off; 
652 }
653 LedState
654 MackieControlProtocol::F2_release (Button &) 
655
656         return off; 
657 }
658 LedState
659 MackieControlProtocol::F3_press (Button &) 
660
661         GotoView (2); /* EMIT SIGNAL */
662         return off; 
663 }
664 LedState
665 MackieControlProtocol::F3_release (Button &) 
666
667         return off; 
668 }
669 LedState
670 MackieControlProtocol::F4_press (Button &) 
671
672         GotoView (3); /* EMIT SIGNAL */
673         return off; 
674 }
675 LedState
676 MackieControlProtocol::F4_release (Button &) 
677
678         return off; 
679 }
680 LedState
681 MackieControlProtocol::F5_press (Button &) 
682
683         GotoView (4); /* EMIT SIGNAL */
684         return off; 
685 }
686 LedState
687 MackieControlProtocol::F5_release (Button &) 
688
689         return off; 
690 }
691 LedState
692 MackieControlProtocol::F6_press (Button &) 
693
694         GotoView (5); /* EMIT SIGNAL */
695         return off; 
696 }
697 LedState
698 MackieControlProtocol::F6_release (Button &) 
699
700         return off; 
701 }
702 LedState
703 MackieControlProtocol::F7_press (Button &) 
704
705         GotoView (6); /* EMIT SIGNAL */
706         return off; 
707 }
708 LedState
709 MackieControlProtocol::F7_release (Button &) 
710
711         return off; 
712 }
713 LedState
714 MackieControlProtocol::F8_press (Button &) 
715
716         CloseDialog (); /* EMIT SIGNAL */
717         return off; 
718 }
719 LedState
720 MackieControlProtocol::F8_release (Button &) 
721
722         return off; 
723 }
724
725 /* UNIMPLEMENTED */
726
727 LedState
728 MackieControlProtocol::io_press (Button &) 
729
730         return off; 
731 }
732 LedState
733 MackieControlProtocol::io_release (Button &) 
734
735         return off; 
736 }
737 LedState
738 MackieControlProtocol::sends_press (Button &) 
739
740         return off; 
741 }
742 LedState
743 MackieControlProtocol::sends_release (Button &) 
744
745         return off; 
746 }
747 LedState
748 MackieControlProtocol::pan_press (Button &) 
749
750         return off; 
751 }
752 LedState
753 MackieControlProtocol::pan_release (Button &) 
754
755         return off; 
756 }
757 LedState
758 MackieControlProtocol::plugin_press (Button &) 
759
760         return off; 
761 }
762 LedState
763 MackieControlProtocol::plugin_release (Button &) 
764
765         return off; 
766 }
767 LedState
768 MackieControlProtocol::eq_press (Button &) 
769
770         return off; 
771 }
772 LedState
773 MackieControlProtocol::eq_release (Button &) 
774
775         return off; 
776 }
777 LedState
778 MackieControlProtocol::dyn_press (Button &) 
779
780         return off; 
781 }
782 LedState
783 MackieControlProtocol::dyn_release (Button &) 
784
785         return off; 
786 }
787 LedState
788 MackieControlProtocol::flip_press (Button &) 
789
790         _flip_mode = !_flip_mode;
791         return (_flip_mode ? on : off);
792 }
793 LedState
794 MackieControlProtocol::flip_release (Button &) 
795
796         return (_flip_mode ? on : off);
797 }
798 LedState
799 MackieControlProtocol::edit_press (Button &) 
800
801         return off; 
802 }
803 LedState
804 MackieControlProtocol::edit_release (Button &) 
805
806         return off; 
807 }
808 LedState
809 MackieControlProtocol::name_value_press (Button &) 
810
811         return off; 
812 }
813 LedState
814 MackieControlProtocol::name_value_release (Button &) 
815
816         return off; 
817 }
818 LedState
819 MackieControlProtocol::F9_press (Button &) 
820
821         return off; 
822 }
823 LedState
824 MackieControlProtocol::F9_release (Button &) 
825
826         return off; 
827 }
828 LedState
829 MackieControlProtocol::F10_press (Button &) 
830
831         return off; 
832 }
833 LedState
834 MackieControlProtocol::F10_release (Button &) 
835
836         return off; 
837 }
838 LedState
839 MackieControlProtocol::F11_press (Button &) 
840
841         return off; 
842 }
843 LedState
844 MackieControlProtocol::F11_release (Button &) 
845
846         return off; 
847 }
848 LedState
849 MackieControlProtocol::F12_press (Button &) 
850
851         return off; 
852 }
853 LedState
854 MackieControlProtocol::F12_release (Button &) 
855
856         return off; 
857 }
858 LedState
859 MackieControlProtocol::F13_press (Button &) 
860
861         return off; 
862 }
863 LedState
864 MackieControlProtocol::F13_release (Button &) 
865
866         return off; 
867 }
868 LedState
869 MackieControlProtocol::F14_press (Button &) 
870
871         return off; 
872 }
873 LedState
874 MackieControlProtocol::F14_release (Button &) 
875
876         return off; 
877 }
878 LedState
879 MackieControlProtocol::F15_press (Button &) 
880
881         return off; 
882 }
883 LedState
884 MackieControlProtocol::F15_release (Button &) 
885
886         return off; 
887 }
888 LedState
889 MackieControlProtocol::F16_press (Button &) 
890
891         return off; 
892 }
893 LedState
894 MackieControlProtocol::F16_release (Button &) 
895
896         return off; 
897 }
898 LedState
899 MackieControlProtocol::on_press (Button &) 
900
901         return off; 
902 }
903 LedState
904 MackieControlProtocol::on_release (Button &) 
905
906         return off; 
907 }
908 LedState
909 MackieControlProtocol::rec_ready_press (Button &) 
910
911         return off; 
912 }
913 LedState
914 MackieControlProtocol::rec_ready_release (Button &) 
915
916         return off; 
917 }
918 LedState
919 MackieControlProtocol::touch_press (Button &) 
920
921         return off; 
922 }
923 LedState
924 MackieControlProtocol::touch_release (Button &) 
925
926         return off; 
927 }
928 LedState
929 MackieControlProtocol::cancel_press (Button &) 
930
931         return off; 
932 }
933 LedState
934 MackieControlProtocol::cancel_release (Button &) 
935
936         return off; 
937 }
938 LedState
939 MackieControlProtocol::mixer_press (Button &) 
940
941         return off; 
942 }
943 LedState
944 MackieControlProtocol::mixer_release (Button &) 
945
946         return off; 
947 }
948 LedState
949 MackieControlProtocol::user_a_press (Button &) 
950
951         return off; 
952 }
953 LedState
954 MackieControlProtocol::user_a_release (Button &) 
955
956         return off; 
957 }
958 LedState
959 MackieControlProtocol::user_b_press (Button &) 
960
961         return off; 
962 }
963 LedState
964 MackieControlProtocol::user_b_release (Button &) 
965
966         return off; 
967 }