2 Copyright (C) 2016 Paul Davis
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.
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.
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.
21 #include "ardour/debug.h"
22 #include "ardour/mute_control.h"
23 #include "ardour/session.h"
24 #include "ardour/solo_control.h"
28 #include "track_mix.h"
30 using namespace ArdourSurface;
31 using namespace ARDOUR;
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));
111 /* Now color buttons */
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))
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);
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))
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);
215 Push2::button_name_by_id (ButtonID id)
293 return "FixedLength";
297 return "RecordEnable";
356 Push2::button_play ()
362 if (_modifier_state & ModShift) {
363 goto_start (session->transport_rolling());
367 if (session->transport_rolling ()) {
375 Push2::button_recenable ()
377 rec_enable_toggle ();
383 _current_layout->button_up ();
387 Push2::button_down ()
389 _current_layout->button_down ();
393 Push2::button_page_right ()
395 ScrollTimeline (0.75);
399 Push2::button_page_left ()
401 ScrollTimeline (-0.75);
405 Push2::button_right ()
407 _current_layout->button_right ();
411 Push2::button_left ()
413 _current_layout->button_left ();
417 Push2::button_repeat ()
423 Push2::button_metronome ()
429 Push2::button_solo_long_press ()
435 Push2::button_mute ()
437 if (_current_layout) {
438 _current_layout->button_mute ();
443 Push2::button_solo ()
445 if (_current_layout) {
446 _current_layout->button_solo ();
453 access_action ("Editor/start-range-from-playhead");
455 id_button_map[New]->set_color (LED::White);
456 id_button_map[New]->set_state (LED::NoTransition);
457 write (id_button_map[New]->state_msg());
459 /* blink the button for the other half of this operation */
461 id_button_map[FixedLength]->set_color (LED::White);
462 id_button_map[FixedLength]->set_state (LED::Blinking4th);
463 write (id_button_map[FixedLength]->state_msg());
468 Push2::button_fixed_length ()
470 access_action ("Editor/finish-range-from-playhead");
472 /* turn off both buttons for this operation */
474 id_button_map[New]->set_color (LED::Black);
475 id_button_map[New]->set_state (LED::NoTransition);
476 write (id_button_map[New]->state_msg());
477 id_button_map[FixedLength]->set_color (LED::Black);
478 id_button_map[FixedLength]->set_state (LED::NoTransition);
479 write (id_button_map[FixedLength]->state_msg());
483 Push2::button_browse ()
485 access_action ("Editor/addExistingAudioFiles");
489 Push2::button_clip ()
494 Push2::button_upper (uint32_t n)
496 _current_layout->button_upper (n);
500 Push2::button_lower (uint32_t n)
502 _current_layout->button_lower (n);
506 Push2::button_undo ()
508 if (_modifier_state & ModShift) {
509 ControlProtocol::Redo ();
511 ControlProtocol::Undo ();
516 Push2::button_fwd32t ()
518 const int n = (_modifier_state & ModShift) ? 8 : 0;
519 goto_nth_marker (0+n);
523 Push2::button_fwd32 ()
525 const int n = (_modifier_state & ModShift) ? 8 : 0;
526 goto_nth_marker (1+n);
530 Push2::button_fwd16t ()
532 const int n = (_modifier_state & ModShift) ? 8 : 0;
533 goto_nth_marker (2+n);
537 Push2::button_fwd16 ()
539 const int n = (_modifier_state & ModShift) ? 8 : 0;
540 goto_nth_marker (3+n);
544 Push2::button_fwd8t ()
546 const int n = (_modifier_state & ModShift) ? 8 : 0;
547 goto_nth_marker (4+n);
551 Push2::button_fwd8 ()
553 const int n = (_modifier_state & ModShift) ? 8 : 0;
554 goto_nth_marker (5+n);
558 Push2::button_fwd4t ()
560 const int n = (_modifier_state & ModShift) ? 8 : 0;
561 goto_nth_marker (6+n);
565 Push2::button_fwd4 ()
567 const int n = (_modifier_state & ModShift) ? 8 : 0;
568 goto_nth_marker (7+n);
572 Push2::button_add_track ()
574 access_action ("Main/AddTrackBus");
578 Push2::button_stop ()
580 /* close current window */
581 access_action ("Main/close-current-dialog");
585 Push2::button_shift_press ()
591 Push2::button_shift_release ()
597 Push2::button_shift_long_press ()
599 access_action ("Main/close-current-dialog");
603 Push2::button_select_press ()
605 cerr << "start select\n";
606 _modifier_state = ModifierState (_modifier_state | ModSelect);
607 Button* b = id_button_map[Select];
608 b->set_color (Push2::LED::White);
609 b->set_state (Push2::LED::Blinking16th);
610 write (b->state_msg());
612 _current_layout->button_select_press ();
616 Push2::button_select_release ()
618 if (_modifier_state & ModSelect) {
619 cerr << "end select\n";
620 _modifier_state = ModifierState (_modifier_state & ~(ModSelect));
621 Button* b = id_button_map[Select];
622 b->timeout_connection.disconnect ();
623 b->set_color (Push2::LED::White);
624 b->set_state (Push2::LED::OneShot24th);
625 write (b->state_msg());
628 _current_layout->button_select_release ();
632 Push2::button_select_long_press ()
634 access_action ("Main/Escape");
638 Push2::button_long_press_timeout (ButtonID id)
640 if (buttons_down.find (id) != buttons_down.end()) {
641 DEBUG_TRACE (DEBUG::Push2, string_compose ("long press timeout for %1, invoking method\n", id));
642 Button* button = id_button_map[id];
643 (this->*button->long_press_method) ();
645 DEBUG_TRACE (DEBUG::Push2, string_compose ("long press timeout for %1, expired/cancelled\n", id));
646 /* release happened and somehow we were not cancelled */
649 /* whichever button this was, we've used it ... don't invoke the
652 consumed.insert (id);
654 return false; /* don't get called again */
658 Push2::start_press_timeout (Button& button, ButtonID id)
660 Glib::RefPtr<Glib::TimeoutSource> timeout = Glib::TimeoutSource::create (500); // milliseconds
661 button.timeout_connection = timeout->connect (sigc::bind (sigc::mem_fun (*this, &Push2::button_long_press_timeout), id));
662 timeout->attach (main_loop()->get_context());
666 Push2::button_octave_down ()
668 if (_modifier_state & ModShift) {
673 int os = (max (-4, octave_shift - 1));
674 if (os != octave_shift) {
680 Push2::button_octave_up ()
682 if (_modifier_state & ModShift) {
687 int os = (min (4, octave_shift + 1));
688 if (os != octave_shift) {
694 Push2::button_layout_press ()
697 set_percussive_mode (false);
699 set_percussive_mode (true);
704 Push2::button_scale_press ()
706 if (_current_layout != scale_layout) {
707 set_current_layout (scale_layout);
709 if (ControlProtocol::first_selected_stripable()) {
710 set_current_layout (mix_layout);
716 Push2::button_mix_press ()
718 if (_current_layout == track_mix_layout) {
719 set_current_layout (mix_layout);
721 if (ControlProtocol::first_selected_stripable()) {
722 set_current_layout (track_mix_layout);
728 Push2::button_master ()
730 boost::shared_ptr<Stripable> master = session->master_out();
736 ControlProtocol::SetStripableSelection (master);
738 if (_current_layout != track_mix_layout) {
739 set_current_layout (track_mix_layout);
744 Push2::button_quantize ()
746 access_action ("Editor/quantize");
750 Push2::button_duplicate ()
752 access_action ("Editor/duplicate-range");