27c38c472db08e7dba5f9ff64e2217575d6a339d
[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/session.h"
23 #include "ardour/route.h"
24 #include "ardour/location.h"
25 #include "ardour/rc_configuration.h"
26
27 #include "mackie_control_protocol.h"
28
29 #include "i18n.h"
30
31 /* handlers for all buttons, broken into a separate file to avoid clutter in
32  * mackie_control_protocol.cc 
33  */
34
35 using namespace Mackie;
36 using namespace ARDOUR;
37 using std::string;
38
39 LedState
40 MackieControlProtocol::shift_press (Button &)
41 {
42         _modifier_state |= MODIFIER_SHIFT;
43         return on;
44 }
45 LedState
46 MackieControlProtocol::shift_release (Button &)
47 {
48         _modifier_state &= ~MODIFIER_SHIFT;
49         return on;
50 }
51 LedState
52 MackieControlProtocol::option_press (Button &)
53 {
54         _modifier_state |= MODIFIER_OPTION;
55         return on;
56 }
57 LedState
58 MackieControlProtocol::option_release (Button &)
59 {
60         _modifier_state &= ~MODIFIER_OPTION;
61         return on;
62 }
63 LedState
64 MackieControlProtocol::control_press (Button &)
65 {
66         _modifier_state |= MODIFIER_CONTROL;
67         return on;
68 }
69 LedState
70 MackieControlProtocol::control_release (Button &)
71 {
72         _modifier_state &= ~MODIFIER_CONTROL;
73         return on;
74 }
75 LedState
76 MackieControlProtocol::cmd_alt_press (Button &)
77 {
78         _modifier_state |= MODIFIER_CMDALT;
79         return on;
80 }
81 LedState
82 MackieControlProtocol::cmd_alt_release (Button &)
83 {
84         _modifier_state &= ~MODIFIER_CMDALT;
85         return on;
86 }
87
88 LedState 
89 MackieControlProtocol::left_press (Button &)
90 {
91         Sorted sorted = get_sorted_routes();
92         if (sorted.size() > route_table.size()) {
93                 int new_initial = _current_initial_bank - route_table.size();
94                 if (new_initial < 0) {
95                         new_initial = 0;
96                 }
97                 
98                 if (new_initial != int (_current_initial_bank)) {
99                         session->set_dirty();
100                         switch_banks (new_initial);
101                 }
102
103                 return on;
104         } else {
105                 return flashing;
106         }
107 }
108
109 LedState 
110 MackieControlProtocol::left_release (Button &)
111 {
112         return off;
113 }
114
115 LedState 
116 MackieControlProtocol::right_press (Button &)
117 {
118         return off;
119 }
120
121 LedState 
122 MackieControlProtocol::right_release (Button &)
123 {
124         if (_zoom_mode) {
125
126         }
127
128         return off;
129 }
130
131 LedState
132 MackieControlProtocol::cursor_left_press (Button& )
133 {
134         if (_zoom_mode) {
135
136                 if (_modifier_state & MODIFIER_OPTION) {
137                         /* reset selected tracks to default vertical zoom */
138                 } else {
139                         ZoomOut (); /* EMIT SIGNAL */
140                 }
141         }
142
143         return off;
144 }
145
146 LedState
147 MackieControlProtocol::cursor_left_release (Button&)
148 {
149         return off;
150 }
151
152 LedState
153 MackieControlProtocol::cursor_right_press (Button& )
154 {
155         if (_zoom_mode) {
156                 
157                 if (_modifier_state & MODIFIER_OPTION) {
158                         /* reset selected tracks to default vertical zoom */
159                 } else {
160                         ZoomIn (); /* EMIT SIGNAL */
161                 }
162         }
163
164         return off;
165 }
166
167 LedState
168 MackieControlProtocol::cursor_right_release (Button&)
169 {
170         return off;
171 }
172
173 LedState
174 MackieControlProtocol::cursor_up_press (Button&)
175 {
176         if (_zoom_mode) {
177                 if (_modifier_state & MODIFIER_OPTION) {
178                         VerticalZoomOutSelected (); /* EMIT SIGNAL */
179                 } else {
180                         VerticalZoomOutAll (); /* EMIT SIGNAL */
181                 }
182         }
183         return off;
184 }
185
186 LedState
187 MackieControlProtocol::cursor_up_release (Button&)
188 {
189         return off;
190 }
191
192 LedState
193 MackieControlProtocol::cursor_down_press (Button&)
194 {
195         if (_zoom_mode) {
196                 
197                 if (_modifier_state & MODIFIER_OPTION) {
198                         VerticalZoomInSelected (); /* EMIT SIGNAL */
199                 } else {
200                         VerticalZoomInAll (); /* EMIT SIGNAL */
201                 }
202         }
203         return off;
204 }
205
206 LedState
207 MackieControlProtocol::cursor_down_release (Button&)
208 {
209         return off;
210 }
211
212 LedState 
213 MackieControlProtocol::channel_left_press (Button &)
214 {
215         Sorted sorted = get_sorted_routes();
216         if (sorted.size() > route_table.size()) {
217                 prev_track();
218                 return on;
219         } else {
220                 return flashing;
221         }
222 }
223
224 LedState 
225 MackieControlProtocol::channel_left_release (Button &)
226 {
227         return off;
228 }
229
230 LedState 
231 MackieControlProtocol::channel_right_press (Button &)
232 {
233         Sorted sorted = get_sorted_routes();
234         if (sorted.size() > route_table.size()) {
235                 next_track();
236                 return on;
237         } else {
238                 return flashing;
239         }
240 }
241
242 LedState 
243 MackieControlProtocol::channel_right_release (Button &)
244 {
245         return off;
246 }
247
248 /////////////////////////////////////
249 // Functions
250 /////////////////////////////////////
251 LedState 
252 MackieControlProtocol::marker_press (Button &)
253 {
254         // cut'n'paste from LocationUI::add_new_location()
255         string markername;
256         framepos_t where = session->audible_frame();
257         session->locations()->next_available_name(markername,"mcu");
258         Location *location = new Location (*session, where, where, markername, Location::IsMark);
259         session->begin_reversible_command (_("add marker"));
260         XMLNode &before = session->locations()->get_state();
261         session->locations()->add (location, true);
262         XMLNode &after = session->locations()->get_state();
263         session->add_command (new MementoCommand<Locations>(*(session->locations()), &before, &after));
264         session->commit_reversible_command ();
265         return on;
266 }
267
268 LedState 
269 MackieControlProtocol::marker_release (Button &)
270 {
271         return off;
272 }
273
274 /////////////////////////////////////
275 // Transport Buttons
276 /////////////////////////////////////
277
278 LedState 
279 MackieControlProtocol::frm_left_press (Button &)
280 {
281         // can use first_mark_before/after as well
282         unsigned long elapsed = _frm_left_last.restart();
283
284         Location * loc = session->locations()->first_location_before (
285                 session->transport_frame()
286         );
287
288         // allow a quick double to go past a previous mark
289         if (session->transport_rolling() && elapsed < 500 && loc != 0) {
290                 Location * loc_two_back = session->locations()->first_location_before (loc->start());
291                 if (loc_two_back != 0)
292                 {
293                         loc = loc_two_back;
294                 }
295         }
296
297         // move to the location, if it's valid
298         if (loc != 0) {
299                 session->request_locate (loc->start(), session->transport_rolling());
300         }
301
302         return on;
303 }
304
305 LedState 
306 MackieControlProtocol::frm_left_release (Button &)
307 {
308         return off;
309 }
310
311 LedState 
312 MackieControlProtocol::frm_right_press (Button &)
313 {
314         // can use first_mark_before/after as well
315         Location * loc = session->locations()->first_location_after (session->transport_frame());
316         
317         if (loc != 0) {
318                 session->request_locate (loc->start(), session->transport_rolling());
319         }
320                 
321         return on;
322 }
323
324 LedState 
325 MackieControlProtocol::frm_right_release (Button &)
326 {
327         return off;
328 }
329
330 LedState 
331 MackieControlProtocol::stop_press (Button &)
332 {
333         session->request_stop();
334         return on;
335 }
336
337 LedState 
338 MackieControlProtocol::stop_release (Button &)
339 {
340         return session->transport_stopped();
341 }
342
343 LedState 
344 MackieControlProtocol::play_press (Button &)
345 {
346         session->request_transport_speed (1.0);
347         return on;
348 }
349
350 LedState 
351 MackieControlProtocol::play_release (Button &)
352 {
353         return session->transport_rolling();
354 }
355
356 LedState 
357 MackieControlProtocol::record_press (Button &)
358 {
359         if (session->get_record_enabled()) {
360                 session->disable_record (false);
361         } else {
362                 session->maybe_enable_record();
363         }
364         return on;
365 }
366
367 LedState 
368 MackieControlProtocol::record_release (Button &)
369 {
370         if (session->get_record_enabled()) {
371                 if (session->transport_rolling()) {
372                         return on;
373                 } else {
374                         return flashing;
375                 }
376         } else {
377                 return off;
378         }
379 }
380
381 LedState 
382 MackieControlProtocol::rewind_press (Button &)
383 {
384         _jog_wheel.push (JogWheel::speed);
385         _jog_wheel.transport_direction (-1);
386         session->request_transport_speed (-_jog_wheel.transport_speed());
387         return on;
388 }
389
390 LedState 
391 MackieControlProtocol::rewind_release (Button &)
392 {
393         _jog_wheel.pop();
394         _jog_wheel.transport_direction (0);
395         if (_transport_previously_rolling) {
396                 session->request_transport_speed (1.0);
397         } else {
398                 session->request_stop();
399         }
400         return off;
401 }
402
403 LedState 
404 MackieControlProtocol::ffwd_press (Button &)
405 {
406         _jog_wheel.push (JogWheel::speed);
407         _jog_wheel.transport_direction (1);
408         session->request_transport_speed (_jog_wheel.transport_speed());
409         return on;
410 }
411
412 LedState 
413 MackieControlProtocol::ffwd_release (Button &)
414 {
415         _jog_wheel.pop();
416         _jog_wheel.transport_direction (0);
417         if (_transport_previously_rolling) {
418                 session->request_transport_speed (1.0);
419         } else {
420                 session->request_stop();
421         }
422         return off;
423 }
424
425 LedState 
426 MackieControlProtocol::loop_press (Button &)
427 {
428         session->request_play_loop (!session->get_play_loop());
429         return on;
430 }
431
432 LedState 
433 MackieControlProtocol::loop_release (Button &)
434 {
435         return session->get_play_loop();
436 }
437
438 LedState 
439 MackieControlProtocol::punch_in_press (Button &)
440 {
441         bool const state = !session->config.get_punch_in();
442         session->config.set_punch_in (state);
443         return state;
444 }
445
446 LedState 
447 MackieControlProtocol::punch_in_release (Button &)
448 {
449         return session->config.get_punch_in();
450 }
451
452 LedState 
453 MackieControlProtocol::punch_out_press (Button &)
454 {
455         bool const state = !session->config.get_punch_out();
456         session->config.set_punch_out (state);
457         return state;
458 }
459
460 LedState 
461 MackieControlProtocol::punch_out_release (Button &)
462 {
463         return session->config.get_punch_out();
464 }
465
466 LedState 
467 MackieControlProtocol::home_press (Button &)
468 {
469         session->goto_start();
470         return on;
471 }
472
473 LedState 
474 MackieControlProtocol::home_release (Button &)
475 {
476         return off;
477 }
478
479 LedState 
480 MackieControlProtocol::end_press (Button &)
481 {
482         session->goto_end();
483         return on;
484 }
485
486 LedState 
487 MackieControlProtocol::end_release (Button &)
488 {
489         return off;
490 }
491
492 LedState 
493 MackieControlProtocol::clicking_press (Button &)
494 {
495         bool state = !Config->get_clicking();
496         Config->set_clicking (state);
497         return state;
498 }
499
500 LedState 
501 MackieControlProtocol::clicking_release (Button &)
502 {
503         return Config->get_clicking();
504 }
505
506 LedState MackieControlProtocol::global_solo_press (Button &)
507 {
508         bool state = !session->soloing();
509         session->set_solo (session->get_routes(), state);
510         return state;
511 }
512
513 LedState MackieControlProtocol::global_solo_release (Button &)
514 {
515         return session->soloing();
516 }
517
518 LedState
519 MackieControlProtocol::enter_press (Button &) 
520
521         Enter(); /* EMIT SIGNAL */
522         return off;
523 }
524
525 LedState
526 MackieControlProtocol::enter_release (Button &) 
527
528         return off;
529 }
530
531 /* UNIMPLEMENTED */
532
533 LedState
534 MackieControlProtocol::io_press (Button &) 
535
536         return off; 
537 }
538 LedState
539 MackieControlProtocol::io_release (Button &) 
540
541         return off; 
542 }
543 LedState
544 MackieControlProtocol::sends_press (Button &) 
545
546         return off; 
547 }
548 LedState
549 MackieControlProtocol::sends_release (Button &) 
550
551         return off; 
552 }
553 LedState
554 MackieControlProtocol::pan_press (Button &) 
555
556         return off; 
557 }
558 LedState
559 MackieControlProtocol::pan_release (Button &) 
560
561         return off; 
562 }
563 LedState
564 MackieControlProtocol::plugin_press (Button &) 
565
566         return off; 
567 }
568 LedState
569 MackieControlProtocol::plugin_release (Button &) 
570
571         return off; 
572 }
573 LedState
574 MackieControlProtocol::eq_press (Button &) 
575
576         return off; 
577 }
578 LedState
579 MackieControlProtocol::eq_release (Button &) 
580
581         return off; 
582 }
583 LedState
584 MackieControlProtocol::dyn_press (Button &) 
585
586         return off; 
587 }
588 LedState
589 MackieControlProtocol::dyn_release (Button &) 
590
591         return off; 
592 }
593 LedState
594 MackieControlProtocol::flip_press (Button &) 
595
596         return off; 
597 }
598 LedState
599 MackieControlProtocol::flip_release (Button &) 
600
601         return off; 
602 }
603 LedState
604 MackieControlProtocol::edit_press (Button &) 
605
606         return off; 
607 }
608 LedState
609 MackieControlProtocol::edit_release (Button &) 
610
611         return off; 
612 }
613 LedState
614 MackieControlProtocol::name_value_press (Button &) 
615
616         return off; 
617 }
618 LedState
619 MackieControlProtocol::name_value_release (Button &) 
620
621         return off; 
622 }
623 LedState
624 MackieControlProtocol::F1_press (Button &) 
625
626         GotoView (0); /* EMIT SIGNAL */
627         return off; 
628 }
629 LedState
630 MackieControlProtocol::F1_release (Button &) 
631
632         return off; 
633 }
634 LedState
635 MackieControlProtocol::F2_press (Button &) 
636
637         GotoView (1); /* EMIT SIGNAL */
638         return off; 
639 }
640 LedState
641 MackieControlProtocol::F2_release (Button &) 
642
643         return off; 
644 }
645 LedState
646 MackieControlProtocol::F3_press (Button &) 
647
648         GotoView (2); /* EMIT SIGNAL */
649         return off; 
650 }
651 LedState
652 MackieControlProtocol::F3_release (Button &) 
653
654         return off; 
655 }
656 LedState
657 MackieControlProtocol::F4_press (Button &) 
658
659         GotoView (3); /* EMIT SIGNAL */
660         return off; 
661 }
662 LedState
663 MackieControlProtocol::F4_release (Button &) 
664
665         return off; 
666 }
667 LedState
668 MackieControlProtocol::F5_press (Button &) 
669
670         GotoView (4); /* EMIT SIGNAL */
671         return off; 
672 }
673 LedState
674 MackieControlProtocol::F5_release (Button &) 
675
676         return off; 
677 }
678 LedState
679 MackieControlProtocol::F6_press (Button &) 
680
681         GotoView (5); /* EMIT SIGNAL */
682         return off; 
683 }
684 LedState
685 MackieControlProtocol::F6_release (Button &) 
686
687         return off; 
688 }
689 LedState
690 MackieControlProtocol::F7_press (Button &) 
691
692         GotoView (6); /* EMIT SIGNAL */
693         return off; 
694 }
695 LedState
696 MackieControlProtocol::F7_release (Button &) 
697
698         return off; 
699 }
700 LedState
701 MackieControlProtocol::F8_press (Button &) 
702
703         CloseDialog (); /* EMIT SIGNAL */
704         return off; 
705 }
706 LedState
707 MackieControlProtocol::F8_release (Button &) 
708
709         return off; 
710 }
711 LedState
712 MackieControlProtocol::F9_press (Button &) 
713
714         GotoView (8); /* EMIT SIGNAL */
715         return off; 
716 }
717 LedState
718 MackieControlProtocol::F9_release (Button &) 
719
720         return off; 
721 }
722 LedState
723 MackieControlProtocol::F10_press (Button &) 
724
725         return off; 
726 }
727 LedState
728 MackieControlProtocol::F10_release (Button &) 
729
730         return off; 
731 }
732 LedState
733 MackieControlProtocol::F11_press (Button &) 
734
735         return off; 
736 }
737 LedState
738 MackieControlProtocol::F11_release (Button &) 
739
740         return off; 
741 }
742 LedState
743 MackieControlProtocol::F12_press (Button &) 
744
745         return off; 
746 }
747 LedState
748 MackieControlProtocol::F12_release (Button &) 
749
750         return off; 
751 }
752 LedState
753 MackieControlProtocol::F13_press (Button &) 
754
755         return off; 
756 }
757 LedState
758 MackieControlProtocol::F13_release (Button &) 
759
760         return off; 
761 }
762 LedState
763 MackieControlProtocol::F14_press (Button &) 
764
765         return off; 
766 }
767 LedState
768 MackieControlProtocol::F14_release (Button &) 
769
770         return off; 
771 }
772 LedState
773 MackieControlProtocol::F15_press (Button &) 
774
775         return off; 
776 }
777 LedState
778 MackieControlProtocol::F15_release (Button &) 
779
780         return off; 
781 }
782 LedState
783 MackieControlProtocol::F16_press (Button &) 
784
785         return off; 
786 }
787 LedState
788 MackieControlProtocol::F16_release (Button &) 
789
790         return off; 
791 }
792 LedState
793 MackieControlProtocol::on_press (Button &) 
794
795         return off; 
796 }
797 LedState
798 MackieControlProtocol::on_release (Button &) 
799
800         return off; 
801 }
802 LedState
803 MackieControlProtocol::rec_ready_press (Button &) 
804
805         return off; 
806 }
807 LedState
808 MackieControlProtocol::rec_ready_release (Button &) 
809
810         return off; 
811 }
812 LedState
813 MackieControlProtocol::snapshot_press (Button &) 
814
815         return off; 
816 }
817 LedState
818 MackieControlProtocol::snapshot_release (Button &) 
819
820         return off; 
821 }
822 LedState
823 MackieControlProtocol::touch_press (Button &) 
824
825         return off; 
826 }
827 LedState
828 MackieControlProtocol::touch_release (Button &) 
829
830         return off; 
831 }
832 LedState
833 MackieControlProtocol::cancel_press (Button &) 
834
835         return off; 
836 }
837 LedState
838 MackieControlProtocol::cancel_release (Button &) 
839
840         return off; 
841 }
842 LedState
843 MackieControlProtocol::mixer_press (Button &) 
844
845         return off; 
846 }
847 LedState
848 MackieControlProtocol::mixer_release (Button &) 
849
850         return off; 
851 }
852 LedState
853 MackieControlProtocol::user_a_press (Button &) 
854
855         return off; 
856 }
857 LedState
858 MackieControlProtocol::user_a_release (Button &) 
859
860         return off; 
861 }
862 LedState
863 MackieControlProtocol::user_b_press (Button &) 
864
865         return off; 
866 }
867 LedState
868 MackieControlProtocol::user_b_release (Button &) 
869
870         return off; 
871 }
872 LedState
873 MackieControlProtocol::fader_touch_press (Button &) 
874
875         return off; 
876 }
877 LedState
878 MackieControlProtocol::fader_touch_release (Button &) 
879
880         return off; 
881 }