another action name fix for Push2 support
[ardour.git] / libs / surfaces / push2 / buttons.cc
1 /*
2   Copyright (C) 2016 Paul Davis
3
4   This program is free software; you can redistribute it and/or modify
5   it under the terms of the GNU General Public License as published by
6   the Free Software Foundation; either version 2 of the License, or
7   (at your option) any later version.
8
9   This program is distributed in the hope that it will be useful,
10   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12   GNU General Public License for more details.
13
14   You should have received a copy of the GNU General Public License
15   along with this program; if not, write to the Free Software
16   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18
19 #include <algorithm>
20
21 #include "ardour/debug.h"
22 #include "ardour/mute_control.h"
23 #include "ardour/session.h"
24 #include "ardour/solo_control.h"
25
26 #include "layout.h"
27 #include "push2.h"
28 #include "track_mix.h"
29
30 using namespace ArdourSurface;
31 using namespace ARDOUR;
32 using namespace PBD;
33 using std::cerr;
34
35 void
36 Push2::build_maps ()
37 {
38         /* Pads */
39
40         Pad* pad;
41
42 #define MAKE_PAD(x,y,nn) \
43         pad = new Pad ((x), (y), (nn)); \
44         nn_pad_map.insert (std::make_pair (pad->extra(), pad));
45
46         MAKE_PAD (0, 0, 92);
47         MAKE_PAD (0, 1, 93);
48         MAKE_PAD (0, 2, 94);
49         MAKE_PAD (0, 3, 95);
50         MAKE_PAD (0, 4, 96);
51         MAKE_PAD (0, 5, 97);
52         MAKE_PAD (0, 6, 98);
53         MAKE_PAD (0, 7, 99);
54         MAKE_PAD (1, 0, 84);
55         MAKE_PAD (1, 1, 85);
56         MAKE_PAD (1, 2, 86);
57         MAKE_PAD (1, 3, 87);
58         MAKE_PAD (1, 4, 88);
59         MAKE_PAD (1, 5, 89);
60         MAKE_PAD (1, 6, 90);
61         MAKE_PAD (1, 7, 91);
62         MAKE_PAD (2, 0, 76);
63         MAKE_PAD (2, 1, 77);
64         MAKE_PAD (2, 2, 78);
65         MAKE_PAD (2, 3, 79);
66         MAKE_PAD (2, 4, 80);
67         MAKE_PAD (2, 5, 81);
68         MAKE_PAD (2, 6, 82);
69         MAKE_PAD (2, 7, 83);
70         MAKE_PAD (3, 0, 68);
71         MAKE_PAD (3, 1, 69);
72         MAKE_PAD (3, 2, 70);
73         MAKE_PAD (3, 3, 71);
74         MAKE_PAD (3, 4, 72);
75         MAKE_PAD (3, 5, 73);
76         MAKE_PAD (3, 6, 74);
77         MAKE_PAD (3, 7, 75);
78         MAKE_PAD (4, 0, 60);
79         MAKE_PAD (4, 1, 61);
80         MAKE_PAD (4, 2, 62);
81         MAKE_PAD (4, 3, 63);
82         MAKE_PAD (4, 4, 64);
83         MAKE_PAD (4, 5, 65);
84         MAKE_PAD (4, 6, 66);
85         MAKE_PAD (4, 7, 67);
86         MAKE_PAD (5, 0, 52);
87         MAKE_PAD (5, 1, 53);
88         MAKE_PAD (5, 2, 54);
89         MAKE_PAD (5, 3, 55);
90         MAKE_PAD (5, 4, 56);
91         MAKE_PAD (5, 5, 57);
92         MAKE_PAD (5, 6, 58);
93         MAKE_PAD (5, 7, 59);
94         MAKE_PAD (6, 0, 44);
95         MAKE_PAD (6, 1, 45);
96         MAKE_PAD (6, 2, 46);
97         MAKE_PAD (6, 3, 47);
98         MAKE_PAD (6, 4, 48);
99         MAKE_PAD (6, 5, 49);
100         MAKE_PAD (6, 6, 50);
101         MAKE_PAD (6, 7, 51);
102         MAKE_PAD (7, 0, 36);
103         MAKE_PAD (7, 1, 37);
104         MAKE_PAD (7, 2, 38);
105         MAKE_PAD (7, 3, 39);
106         MAKE_PAD (7, 4, 40);
107         MAKE_PAD (7, 5, 41);
108         MAKE_PAD (7, 6, 42);
109         MAKE_PAD (7, 7, 43);
110
111         /* Now color buttons */
112
113         Button *button;
114
115 #define MAKE_COLOR_BUTTON(i,cc) \
116         button = new ColorButton ((i), (cc)); \
117         cc_button_map.insert (std::make_pair (button->controller_number(), button)); \
118         id_button_map.insert (std::make_pair (button->id, button));
119 #define MAKE_COLOR_BUTTON_PRESS(i,cc,p)\
120         button = new ColorButton ((i), (cc), (p)); \
121         cc_button_map.insert (std::make_pair (button->controller_number(), button)); \
122         id_button_map.insert (std::make_pair (button->id, button))
123 #define MAKE_COLOR_BUTTON_PRESS_RELEASE_LONG(i,cc,p,r,l)                      \
124         button = new ColorButton ((i), (cc), (p), (r), (l)); \
125         cc_button_map.insert (std::make_pair (button->controller_number(), button)); \
126         id_button_map.insert (std::make_pair (button->id, button))
127
128         MAKE_COLOR_BUTTON_PRESS (Upper1, 102, &Push2::button_upper_1);
129         MAKE_COLOR_BUTTON_PRESS (Upper2, 103, &Push2::button_upper_2);
130         MAKE_COLOR_BUTTON_PRESS (Upper3, 104, &Push2::button_upper_3);
131         MAKE_COLOR_BUTTON_PRESS (Upper4, 105, &Push2::button_upper_4);
132         MAKE_COLOR_BUTTON_PRESS (Upper5, 106, &Push2::button_upper_5);
133         MAKE_COLOR_BUTTON_PRESS (Upper6, 107, &Push2::button_upper_6);
134         MAKE_COLOR_BUTTON_PRESS (Upper7, 108, &Push2::button_upper_7);
135         MAKE_COLOR_BUTTON_PRESS (Upper8, 109, &Push2::button_upper_8);
136         MAKE_COLOR_BUTTON_PRESS (Lower1, 20, &Push2::button_lower_1);
137         MAKE_COLOR_BUTTON_PRESS (Lower2, 21, &Push2::button_lower_2);
138         MAKE_COLOR_BUTTON_PRESS (Lower3, 22, &Push2::button_lower_3);
139         MAKE_COLOR_BUTTON_PRESS (Lower4, 23, &Push2::button_lower_4);
140         MAKE_COLOR_BUTTON_PRESS (Lower5, 24, &Push2::button_lower_5);
141         MAKE_COLOR_BUTTON_PRESS (Lower6, 25, &Push2::button_lower_6);
142         MAKE_COLOR_BUTTON_PRESS (Lower7, 26, &Push2::button_lower_7);
143         MAKE_COLOR_BUTTON_PRESS (Lower8, 27, &Push2::button_lower_8);
144         MAKE_COLOR_BUTTON_PRESS (Master, 28, &Push2::button_master);
145         MAKE_COLOR_BUTTON_PRESS (Mute, 60, &Push2::button_mute);
146         MAKE_COLOR_BUTTON_PRESS_RELEASE_LONG (Solo, 61, &Push2::relax, &Push2::button_solo, &Push2::button_solo_long_press);
147         MAKE_COLOR_BUTTON_PRESS (Stop, 29, &Push2::button_stop);
148         MAKE_COLOR_BUTTON_PRESS (Fwd32ndT, 43, &Push2::button_fwd32t);
149         MAKE_COLOR_BUTTON_PRESS (Fwd32nd,42 , &Push2::button_fwd32);
150         MAKE_COLOR_BUTTON_PRESS (Fwd16thT, 41, &Push2::button_fwd16t);
151         MAKE_COLOR_BUTTON_PRESS (Fwd16th, 40, &Push2::button_fwd16);
152         MAKE_COLOR_BUTTON_PRESS (Fwd8thT, 39 , &Push2::button_fwd8t);
153         MAKE_COLOR_BUTTON_PRESS (Fwd8th, 38, &Push2::button_fwd8);
154         MAKE_COLOR_BUTTON_PRESS (Fwd4trT, 37, &Push2::button_fwd4t);
155         MAKE_COLOR_BUTTON_PRESS (Fwd4tr, 36, &Push2::button_fwd4);
156         MAKE_COLOR_BUTTON (Automate, 89);
157         MAKE_COLOR_BUTTON_PRESS (RecordEnable, 86, &Push2::button_recenable);
158         MAKE_COLOR_BUTTON_PRESS (Play, 85, &Push2::button_play);
159
160 #define MAKE_WHITE_BUTTON(i,cc)\
161         button = new WhiteButton ((i), (cc)); \
162         cc_button_map.insert (std::make_pair (button->controller_number(), button)); \
163         id_button_map.insert (std::make_pair (button->id, button))
164 #define MAKE_WHITE_BUTTON_PRESS(i,cc,p)\
165         button = new WhiteButton ((i), (cc), (p)); \
166         cc_button_map.insert (std::make_pair (button->controller_number(), button)); \
167         id_button_map.insert (std::make_pair (button->id, button))
168 #define MAKE_WHITE_BUTTON_PRESS_RELEASE(i,cc,p,r)                                \
169         button = new WhiteButton ((i), (cc), (p), (r)); \
170         cc_button_map.insert (std::make_pair (button->controller_number(), button)); \
171         id_button_map.insert (std::make_pair (button->id, button))
172 #define MAKE_WHITE_BUTTON_PRESS_RELEASE_LONG(i,cc,p,r,l)                      \
173         button = new WhiteButton ((i), (cc), (p), (r), (l)); \
174         cc_button_map.insert (std::make_pair (button->controller_number(), button)); \
175         id_button_map.insert (std::make_pair (button->id, button))
176
177         MAKE_WHITE_BUTTON (TapTempo, 3);
178         MAKE_WHITE_BUTTON_PRESS (Metronome, 9, &Push2::button_metronome);
179         MAKE_WHITE_BUTTON (Setup, 30);
180         MAKE_WHITE_BUTTON (User, 59);
181         MAKE_WHITE_BUTTON (Delete, 118);
182         MAKE_WHITE_BUTTON (AddDevice, 52);
183         MAKE_WHITE_BUTTON (Device, 110);
184         MAKE_WHITE_BUTTON_PRESS (Mix, 112, &Push2::button_mix_press);
185         MAKE_WHITE_BUTTON_PRESS (Undo, 119, &Push2::button_undo);
186         MAKE_WHITE_BUTTON_PRESS (AddTrack, 53, &Push2::button_add_track);
187         MAKE_WHITE_BUTTON_PRESS (Browse, 111, &Push2::button_browse);
188         MAKE_WHITE_BUTTON_PRESS (Clip, 113, &Push2::button_clip);
189         MAKE_WHITE_BUTTON (Convert, 35);
190         MAKE_WHITE_BUTTON (DoubleLoop, 117);
191         MAKE_WHITE_BUTTON_PRESS (Quantize, 116, &Push2::button_quantize);
192         MAKE_WHITE_BUTTON_PRESS (Duplicate, 88, &Push2::button_duplicate);
193         MAKE_WHITE_BUTTON_PRESS (New, 87, &Push2::button_new);
194         MAKE_WHITE_BUTTON_PRESS (FixedLength, 90, &Push2::button_fixed_length);
195         MAKE_WHITE_BUTTON_PRESS (Up, 46, &Push2::button_up);
196         MAKE_WHITE_BUTTON_PRESS (Right, 45, &Push2::button_right);
197         MAKE_WHITE_BUTTON_PRESS (Down, 47, &Push2::button_down);
198         MAKE_WHITE_BUTTON_PRESS (Left, 44, &Push2::button_left);
199         MAKE_WHITE_BUTTON_PRESS (Repeat, 56, &Push2::button_repeat);
200         MAKE_WHITE_BUTTON (Accent, 57);
201         MAKE_WHITE_BUTTON_PRESS (Scale, 58, &Push2::button_scale_press);
202         MAKE_WHITE_BUTTON_PRESS (Layout, 31, &Push2::button_layout_press);
203         MAKE_WHITE_BUTTON (Note, 50);
204         MAKE_WHITE_BUTTON (Session, 51);
205         MAKE_WHITE_BUTTON (Layout, 31);
206         MAKE_WHITE_BUTTON_PRESS (OctaveUp, 55, &Push2::button_octave_up);
207         MAKE_WHITE_BUTTON_PRESS (PageRight, 63, &Push2::button_page_right);
208         MAKE_WHITE_BUTTON_PRESS (OctaveDown, 54, &Push2::button_octave_down);
209         MAKE_WHITE_BUTTON_PRESS (PageLeft, 62, &Push2::button_page_left);
210         MAKE_WHITE_BUTTON_PRESS_RELEASE_LONG (Shift, 49, &Push2::button_shift_press, &Push2::button_shift_release, &Push2::button_shift_long_press);
211         MAKE_WHITE_BUTTON_PRESS_RELEASE_LONG (Select, 48, &Push2::button_select_press, &Push2::button_select_release, &Push2::button_select_long_press);
212 }
213
214 std::string
215 Push2::button_name_by_id (ButtonID id)
216 {
217         switch (id) {
218         case TapTempo:
219                 return "TapTempo";
220         case Metronome:
221                 return "Metronome";
222         case Upper1:
223                 return "Upper1";
224         case Upper2:
225                 return "Upper2";
226         case Upper3:
227                 return "Upper3";
228         case Upper4:
229                 return "Upper4";
230         case Upper5:
231                 return "Upper5";
232         case Upper6:
233                 return "Upper6";
234         case Upper7:
235                 return "Upper7";
236         case Upper8:
237                 return "Upper8";
238         case Setup:
239                 return "Setup";
240         case User:
241                 return "User";
242         case Delete:
243                 return "Delete";
244         case AddDevice:
245                 return "AddDevice";
246         case Device:
247                 return "Device";
248         case Mix:
249                 return "Mix";
250         case Undo:
251                 return "Undo";
252         case AddTrack:
253                 return "AddTrack";
254         case Browse:
255                 return "Browse";
256         case Clip:
257                 return "Clip";
258         case Mute:
259                 return "Mute";
260         case Solo:
261                 return "Solo";
262         case Stop:
263                 return "Stop";
264         case Lower1:
265                 return "Lower1";
266         case Lower2:
267                 return "Lower2";
268         case Lower3:
269                 return "Lower3";
270         case Lower4:
271                 return "Lower4";
272         case Lower5:
273                 return "Lower5";
274         case Lower6:
275                 return "Lower6";
276         case Lower7:
277                 return "Lower7";
278         case Lower8:
279                 return "Lower8";
280         case Master:
281                 return "Master";
282         case Convert:
283                 return "Convert";
284         case DoubleLoop:
285                 return "DoubleLoop";
286         case Quantize:
287                 return "Quantize";
288         case Duplicate:
289                 return "Duplicate";
290         case New:
291                 return "New";
292         case FixedLength:
293                 return "FixedLength";
294         case Automate:
295                 return "Automate";
296         case RecordEnable:
297                 return "RecordEnable";
298         case Play:
299                 return "Play";
300         case Fwd32ndT:
301                 return "Fwd32ndT";
302         case Fwd32nd:
303                 return "Fwd32nd";
304         case Fwd16thT:
305                 return "Fwd16thT";
306         case Fwd16th:
307                 return "Fwd16th";
308         case Fwd8thT:
309                 return "Fwd8thT";
310         case Fwd8th:
311                 return "Fwd8th";
312         case Fwd4trT:
313                 return "Fwd4trT";
314         case Fwd4tr:
315                 return "Fwd4tr";
316         case Up:
317                 return "Up";
318         case Right:
319                 return "Right";
320         case Down:
321                 return "Down";
322         case Left:
323                 return "Left";
324         case Repeat:
325                 return "Repeat";
326         case Accent:
327                 return "Accent";
328         case Scale:
329                 return "Scale";
330         case Layout:
331                 return "Layout";
332         case Note:
333                 return "Note";
334         case Session:
335                 return "Session";
336         case OctaveUp:
337                 return "OctaveUp";
338         case PageRight:
339                 return "PageRight";
340         case OctaveDown:
341                 return "OctaveDown";
342         case PageLeft:
343                 return "PageLeft";
344         case Shift:
345                 return "Shift";
346         case Select:
347                 return "Select";
348         default:
349                 break;
350         }
351
352         return "???";
353 }
354
355 void
356 Push2::button_play ()
357 {
358         if (!session) {
359                 return;
360         }
361
362         if (_modifier_state & ModShift) {
363                 goto_start (session->transport_rolling());
364                 return;
365         }
366
367         if (_modifier_state & ModSelect) {
368                 if (in_range_select) {
369                         in_range_select = true;
370                         access_action ("Common/start-range-from-playhead");
371                 } else {
372                         access_action ("Common/finish-range-from-playhead");
373                         in_range_select = false;
374                 }
375                 return;
376         }
377
378         if (session->transport_rolling ()) {
379                 transport_stop ();
380         } else {
381                 transport_play ();
382         }
383 }
384
385 void
386 Push2::button_recenable ()
387 {
388         rec_enable_toggle ();
389 }
390
391 void
392 Push2::button_up ()
393 {
394         _current_layout->button_up ();
395 }
396
397 void
398 Push2::button_down ()
399 {
400         _current_layout->button_down ();
401 }
402
403 void
404 Push2::button_page_right ()
405 {
406         ScrollTimeline (0.75);
407 }
408
409 void
410 Push2::button_page_left ()
411 {
412         ScrollTimeline (-0.75);
413 }
414
415 void
416 Push2::button_right ()
417 {
418         _current_layout->button_right ();
419 }
420
421 void
422 Push2::button_left ()
423 {
424         _current_layout->button_left ();
425 }
426
427 void
428 Push2::button_repeat ()
429 {
430         loop_toggle ();
431 }
432
433 void
434 Push2::button_metronome ()
435 {
436         toggle_click ();
437 }
438
439 void
440 Push2::button_solo_long_press ()
441 {
442         cancel_all_solo ();
443 }
444
445 void
446 Push2::button_mute ()
447 {
448         if (_current_layout) {
449                 _current_layout->button_mute ();
450         }
451 }
452
453 void
454 Push2::button_solo ()
455 {
456         if (_current_layout) {
457                 _current_layout->button_solo ();
458         }
459 }
460
461 void
462 Push2::button_new ()
463 {
464         access_action ("Common/start-range-from-playhead");
465
466         id_button_map[New]->set_color (LED::White);
467         id_button_map[New]->set_state (LED::NoTransition);
468         write (id_button_map[New]->state_msg());
469
470         /* blink the button for the other half of this operation */
471
472         id_button_map[FixedLength]->set_color (LED::White);
473         id_button_map[FixedLength]->set_state (LED::Blinking4th);
474         write (id_button_map[FixedLength]->state_msg());
475 }
476
477
478 void
479 Push2::button_fixed_length ()
480 {
481         access_action ("Common/finish-range-from-playhead");
482
483         /* turn off both buttons for this operation */
484
485         id_button_map[New]->set_color (LED::Black);
486         id_button_map[New]->set_state (LED::NoTransition);
487         write (id_button_map[New]->state_msg());
488         id_button_map[FixedLength]->set_color (LED::Black);
489         id_button_map[FixedLength]->set_state (LED::NoTransition);
490         write (id_button_map[FixedLength]->state_msg());
491 }
492
493 void
494 Push2::button_browse ()
495 {
496         access_action ("Common/addExistingAudioFiles");
497 }
498
499 void
500 Push2::button_clip ()
501 {
502 }
503
504 void
505 Push2::button_upper (uint32_t n)
506 {
507         _current_layout->button_upper (n);
508 }
509
510 void
511 Push2::button_lower (uint32_t n)
512 {
513         _current_layout->button_lower (n);
514 }
515
516 void
517 Push2::button_undo ()
518 {
519         if (_modifier_state & ModShift) {
520                 ControlProtocol::Redo ();
521         } else {
522                 ControlProtocol::Undo ();
523         }
524 }
525
526 void
527 Push2::button_fwd32t ()
528 {
529         const int n = (_modifier_state & ModShift) ? 8 : 0;
530         goto_nth_marker (0+n);
531 }
532
533 void
534 Push2::button_fwd32 ()
535 {
536         const int n = (_modifier_state & ModShift) ? 8 : 0;
537         goto_nth_marker (1+n);
538 }
539
540 void
541 Push2::button_fwd16t ()
542 {
543         const int n = (_modifier_state & ModShift) ? 8 : 0;
544         goto_nth_marker (2+n);
545 }
546
547 void
548 Push2::button_fwd16 ()
549 {
550         const int n = (_modifier_state & ModShift) ? 8 : 0;
551         goto_nth_marker (3+n);
552 }
553
554 void
555 Push2::button_fwd8t ()
556 {
557         const int n = (_modifier_state & ModShift) ? 8 : 0;
558         goto_nth_marker (4+n);
559 }
560
561 void
562 Push2::button_fwd8 ()
563 {
564         const int n = (_modifier_state & ModShift) ? 8 : 0;
565         goto_nth_marker (5+n);
566 }
567
568 void
569 Push2::button_fwd4t ()
570 {
571         const int n = (_modifier_state & ModShift) ? 8 : 0;
572         goto_nth_marker (6+n);
573 }
574
575 void
576 Push2::button_fwd4 ()
577 {
578         const int n = (_modifier_state & ModShift) ? 8 : 0;
579         goto_nth_marker (7+n);
580 }
581
582 void
583 Push2::button_add_track ()
584 {
585         access_action ("Main/AddTrackBus");
586 }
587
588 void
589 Push2::button_stop ()
590 {
591         /* close current window */
592         access_action ("Main/close-current-dialog");
593 }
594
595 void
596 Push2::button_shift_press ()
597 {
598         start_shift ();
599 }
600
601 void
602 Push2::button_shift_release ()
603 {
604         end_shift ();
605 }
606
607 void
608 Push2::button_shift_long_press ()
609 {
610         access_action ("Main/close-current-dialog");
611 }
612
613 void
614 Push2::button_select_press ()
615 {
616         cerr << "start select\n";
617         _modifier_state = ModifierState (_modifier_state | ModSelect);
618         Button* b = id_button_map[Select];
619         b->set_color (Push2::LED::White);
620         b->set_state (Push2::LED::Blinking16th);
621         write (b->state_msg());
622
623         _current_layout->button_select_press ();
624 }
625
626 void
627 Push2::button_select_release ()
628 {
629         if (_modifier_state & ModSelect) {
630                 cerr << "end select\n";
631                 _modifier_state = ModifierState (_modifier_state & ~(ModSelect));
632                 Button* b = id_button_map[Select];
633                 b->timeout_connection.disconnect ();
634                 b->set_color (Push2::LED::White);
635                 b->set_state (Push2::LED::OneShot24th);
636                 write (b->state_msg());
637         }
638
639         _current_layout->button_select_release ();
640 }
641
642 void
643 Push2::button_select_long_press ()
644 {
645         access_action ("Main/Escape");
646 }
647
648 bool
649 Push2::button_long_press_timeout (ButtonID id)
650 {
651         if (buttons_down.find (id) != buttons_down.end()) {
652                 DEBUG_TRACE (DEBUG::Push2, string_compose ("long press timeout for %1, invoking method\n", id));
653                 Button* button = id_button_map[id];
654                 (this->*button->long_press_method) ();
655         } else {
656                 DEBUG_TRACE (DEBUG::Push2, string_compose ("long press timeout for %1, expired/cancelled\n", id));
657                 /* release happened and somehow we were not cancelled */
658         }
659
660         /* whichever button this was, we've used it ... don't invoke the
661            release action.
662         */
663         consumed.insert (id);
664
665         return false; /* don't get called again */
666 }
667
668 void
669 Push2::start_press_timeout (Button& button, ButtonID id)
670 {
671         Glib::RefPtr<Glib::TimeoutSource> timeout = Glib::TimeoutSource::create (500); // milliseconds
672         button.timeout_connection = timeout->connect (sigc::bind (sigc::mem_fun (*this, &Push2::button_long_press_timeout), id));
673         timeout->attach (main_loop()->get_context());
674 }
675
676 void
677 Push2::button_octave_down ()
678 {
679         if (_modifier_state & ModShift) {
680                 octave_shift = 0;
681                 return;
682         }
683
684         int os = (max (-4, octave_shift - 1));
685         if (os != octave_shift) {
686                 octave_shift = os;
687         }
688 }
689
690 void
691 Push2::button_octave_up ()
692 {
693         if (_modifier_state & ModShift) {
694                 octave_shift = 0;
695                 return;
696         }
697
698         int os = (min (4, octave_shift + 1));
699         if (os != octave_shift) {
700                 octave_shift = os;
701         }
702 }
703
704 void
705 Push2::button_layout_press ()
706 {
707         if (percussion) {
708                 set_percussive_mode (false);
709         } else {
710                 set_percussive_mode (true);
711         }
712 }
713
714 void
715 Push2::button_scale_press ()
716 {
717         if (_current_layout != scale_layout) {
718                 set_current_layout (scale_layout);
719         } else {
720                 if (ControlProtocol::first_selected_stripable()) {
721                         set_current_layout (mix_layout);
722                 }
723         }
724 }
725
726 void
727 Push2::button_mix_press ()
728 {
729         if (_current_layout == track_mix_layout) {
730                 set_current_layout (mix_layout);
731         } else {
732                 if (ControlProtocol::first_selected_stripable()) {
733                         set_current_layout (track_mix_layout);
734                 }
735         }
736 }
737
738 void
739 Push2::button_master ()
740 {
741         boost::shared_ptr<Stripable> main_out = session->master_out ();
742
743         if (!main_out) {
744                 return;
745         }
746
747         if (_current_layout != track_mix_layout) {
748                 ControlProtocol::SetStripableSelection (main_out);
749                 set_current_layout (track_mix_layout);
750         } else {
751                 TrackMixLayout* tml = dynamic_cast<TrackMixLayout*> (_current_layout);
752                 if (tml->current_stripable() == main_out) {
753                         /* back to previous layout */
754                         set_current_layout (_previous_layout);
755                 } else {
756                         ControlProtocol::SetStripableSelection (main_out);
757                 }
758         }
759 }
760
761 void
762 Push2::button_quantize ()
763 {
764         access_action ("Editor/quantize");
765 }
766
767 void
768 Push2::button_duplicate ()
769 {
770         access_action ("Editor/duplicate-range");
771 }