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 using namespace ArdourSurface;
29 using namespace ARDOUR;
40 #define MAKE_PAD(x,y,nn) \
41 pad = new Pad ((x), (y), (nn)); \
42 nn_pad_map.insert (std::make_pair (pad->extra(), pad)); \
43 coord_pad_map.insert (std::make_pair (pad->coord(), pad));
109 /* Now color buttons */
113 #define MAKE_COLOR_BUTTON(i,cc) \
114 button = new ColorButton ((i), (cc)); \
115 cc_button_map.insert (std::make_pair (button->controller_number(), button)); \
116 id_button_map.insert (std::make_pair (button->id, button));
117 #define MAKE_COLOR_BUTTON_PRESS(i,cc,p)\
118 button = new ColorButton ((i), (cc), (p)); \
119 cc_button_map.insert (std::make_pair (button->controller_number(), button)); \
120 id_button_map.insert (std::make_pair (button->id, button))
122 MAKE_COLOR_BUTTON_PRESS (Upper1, 102, &Push2::button_upper_1);
123 MAKE_COLOR_BUTTON_PRESS (Upper2, 103, &Push2::button_upper_2);
124 MAKE_COLOR_BUTTON_PRESS (Upper3, 104, &Push2::button_upper_3);
125 MAKE_COLOR_BUTTON_PRESS (Upper4, 105, &Push2::button_upper_4);
126 MAKE_COLOR_BUTTON_PRESS (Upper5, 106, &Push2::button_upper_5);
127 MAKE_COLOR_BUTTON_PRESS (Upper6, 107, &Push2::button_upper_6);
128 MAKE_COLOR_BUTTON_PRESS (Upper7, 108, &Push2::button_upper_7);
129 MAKE_COLOR_BUTTON_PRESS (Upper8, 109, &Push2::button_upper_8);
130 MAKE_COLOR_BUTTON_PRESS (Lower1, 20, &Push2::button_lower_1);
131 MAKE_COLOR_BUTTON_PRESS (Lower2, 21, &Push2::button_lower_2);
132 MAKE_COLOR_BUTTON_PRESS (Lower3, 22, &Push2::button_lower_3);
133 MAKE_COLOR_BUTTON_PRESS (Lower4, 23, &Push2::button_lower_4);
134 MAKE_COLOR_BUTTON_PRESS (Lower5, 24, &Push2::button_lower_5);
135 MAKE_COLOR_BUTTON_PRESS (Lower6, 25, &Push2::button_lower_6);
136 MAKE_COLOR_BUTTON_PRESS (Lower7, 26, &Push2::button_lower_7);
137 MAKE_COLOR_BUTTON_PRESS (Lower8, 27, &Push2::button_lower_8);
138 MAKE_COLOR_BUTTON (Master, 28);
139 MAKE_COLOR_BUTTON (Mute, 60);
140 MAKE_COLOR_BUTTON_PRESS (Solo, 61, &Push2::button_solo);
141 MAKE_COLOR_BUTTON_PRESS (Stop, 29, &Push2::button_stop);
142 MAKE_COLOR_BUTTON_PRESS (Fwd32ndT, 43, &Push2::button_fwd32t);
143 MAKE_COLOR_BUTTON_PRESS (Fwd32nd,42 , &Push2::button_fwd32);
144 MAKE_COLOR_BUTTON_PRESS (Fwd16thT, 41, &Push2::button_fwd16t);
145 MAKE_COLOR_BUTTON_PRESS (Fwd16th, 40, &Push2::button_fwd16);
146 MAKE_COLOR_BUTTON_PRESS (Fwd8thT, 39 , &Push2::button_fwd8t);
147 MAKE_COLOR_BUTTON_PRESS (Fwd8th, 38, &Push2::button_fwd8);
148 MAKE_COLOR_BUTTON_PRESS (Fwd4trT, 37, &Push2::button_fwd4t);
149 MAKE_COLOR_BUTTON_PRESS (Fwd4tr, 36, &Push2::button_fwd4);
150 MAKE_COLOR_BUTTON (Automate, 89);
151 MAKE_COLOR_BUTTON_PRESS (RecordEnable, 86, &Push2::button_recenable);
152 MAKE_COLOR_BUTTON_PRESS (Play, 85, &Push2::button_play);
154 #define MAKE_WHITE_BUTTON(i,cc)\
155 button = new WhiteButton ((i), (cc)); \
156 cc_button_map.insert (std::make_pair (button->controller_number(), button)); \
157 id_button_map.insert (std::make_pair (button->id, button))
158 #define MAKE_WHITE_BUTTON_PRESS(i,cc,p)\
159 button = new WhiteButton ((i), (cc), (p)); \
160 cc_button_map.insert (std::make_pair (button->controller_number(), button)); \
161 id_button_map.insert (std::make_pair (button->id, button))
162 #define MAKE_WHITE_BUTTON_PRESS_RELEASE(i,cc,p,r) \
163 button = new WhiteButton ((i), (cc), (p), (r)); \
164 cc_button_map.insert (std::make_pair (button->controller_number(), button)); \
165 id_button_map.insert (std::make_pair (button->id, button))
166 #define MAKE_WHITE_BUTTON_PRESS_RELEASE_LONG(i,cc,p,r,l) \
167 button = new WhiteButton ((i), (cc), (p), (r), (l)); \
168 cc_button_map.insert (std::make_pair (button->controller_number(), button)); \
169 id_button_map.insert (std::make_pair (button->id, button))
171 MAKE_WHITE_BUTTON (TapTempo, 3);
172 MAKE_WHITE_BUTTON_PRESS (Metronome, 9, &Push2::button_metronome);
173 MAKE_WHITE_BUTTON (Setup, 30);
174 MAKE_WHITE_BUTTON (User, 59);
175 MAKE_WHITE_BUTTON (Delete, 118);
176 MAKE_WHITE_BUTTON (AddDevice, 52);
177 MAKE_WHITE_BUTTON (Device, 110);
178 MAKE_WHITE_BUTTON (Mix, 112);
179 MAKE_WHITE_BUTTON_PRESS (Undo, 119, &Push2::button_undo);
180 MAKE_WHITE_BUTTON_PRESS (AddTrack, 53, &Push2::button_add_track);
181 MAKE_WHITE_BUTTON_PRESS (Browse, 111, &Push2::button_browse);
182 MAKE_WHITE_BUTTON_PRESS (Clip, 113, &Push2::button_clip);
183 MAKE_WHITE_BUTTON (Convert, 35);
184 MAKE_WHITE_BUTTON (DoubleLoop, 117);
185 MAKE_WHITE_BUTTON (Quantize, 116);
186 MAKE_WHITE_BUTTON (Duplicate, 88);
187 MAKE_WHITE_BUTTON_PRESS (New, 87, &Push2::button_new);
188 MAKE_WHITE_BUTTON_PRESS (FixedLength, 90, &Push2::button_fixed_length);
189 MAKE_WHITE_BUTTON_PRESS (Up, 46, &Push2::button_up);
190 MAKE_WHITE_BUTTON_PRESS (Right, 45, &Push2::button_right);
191 MAKE_WHITE_BUTTON_PRESS (Down, 47, &Push2::button_down);
192 MAKE_WHITE_BUTTON_PRESS (Left, 44, &Push2::button_left);
193 MAKE_WHITE_BUTTON_PRESS (Repeat, 56, &Push2::button_repeat);
194 MAKE_WHITE_BUTTON (Accent, 57);
195 MAKE_WHITE_BUTTON (Scale, 58);
196 MAKE_WHITE_BUTTON (Layout, 31);
197 MAKE_WHITE_BUTTON (Note, 50);
198 MAKE_WHITE_BUTTON (Session, 51);
199 MAKE_WHITE_BUTTON (Layout, 31);
200 MAKE_WHITE_BUTTON_PRESS (OctaveUp, 55, &Push2::button_octave_up);
201 MAKE_WHITE_BUTTON_PRESS (PageRight, 63, &Push2::button_page_right);
202 MAKE_WHITE_BUTTON_PRESS (OctaveDown, 54, &Push2::button_octave_down);
203 MAKE_WHITE_BUTTON_PRESS (PageLeft, 62, &Push2::button_page_left);
204 MAKE_WHITE_BUTTON_PRESS_RELEASE_LONG (Shift, 49, &Push2::button_shift_press, &Push2::button_shift_release, &Push2::button_shift_long_press);
205 MAKE_WHITE_BUTTON_PRESS_RELEASE_LONG (Select, 48, &Push2::button_select_press, &Push2::button_select_release, &Push2::button_select_long_press);
209 Push2::button_play ()
215 if (modifier_state & ModShift) {
216 goto_start (session->transport_rolling());
220 if (session->transport_rolling ()) {
228 Push2::button_recenable ()
230 rec_enable_toggle ();
236 scroll_up_1_track ();
240 Push2::button_down ()
242 scroll_dn_1_track ();
246 Push2::button_page_right ()
248 ScrollTimeline (0.75);
252 Push2::button_page_left ()
254 ScrollTimeline (-0.75);
258 Push2::button_right ()
260 switch_bank (max (0, bank_start + 8));
264 Push2::button_left ()
266 switch_bank (max (0, bank_start - 8));
270 Push2::button_repeat ()
276 Push2::button_metronome ()
282 Push2::button_solo ()
290 access_action ("Editor/start-range-from-playhead");
292 id_button_map[New]->set_color (LED::White);
293 id_button_map[New]->set_state (LED::NoTransition);
294 write (id_button_map[New]->state_msg());
296 /* blink the button for the other half of this operation */
298 id_button_map[FixedLength]->set_color (LED::White);
299 id_button_map[FixedLength]->set_state (LED::Blinking4th);
300 write (id_button_map[FixedLength]->state_msg());
305 Push2::button_fixed_length ()
307 access_action ("Editor/finish-range-from-playhead");
309 /* turn off both buttons for this operation */
311 id_button_map[New]->set_color (LED::Black);
312 id_button_map[New]->set_state (LED::NoTransition);
313 write (id_button_map[New]->state_msg());
314 id_button_map[FixedLength]->set_color (LED::Black);
315 id_button_map[FixedLength]->set_state (LED::NoTransition);
316 write (id_button_map[FixedLength]->state_msg());
320 Push2::button_browse ()
322 access_action ("Editor/addExistingAudioFiles");
326 Push2::button_clip ()
331 Push2::button_upper (uint32_t n)
337 if (modifier_state & ModShift) {
338 boost::shared_ptr<AutomationControl> sc = stripable[n]->rec_enable_control ();
340 sc->set_value (!sc->get_value(), PBD::Controllable::UseGroup);
343 boost::shared_ptr<SoloControl> sc = stripable[n]->solo_control ();
345 sc->set_value (!sc->self_soloed(), PBD::Controllable::UseGroup);
351 Push2::button_lower (uint32_t n)
357 if (modifier_state & ModSelect) {
358 stripable[n]->presentation_info().set_selected (!stripable[n]->presentation_info().selected());
360 boost::shared_ptr<MuteControl> mc = stripable[n]->mute_control ();
363 mc->set_value (!mc->muted_by_self(), PBD::Controllable::UseGroup);
369 Push2::button_undo ()
371 if (modifier_state & ModShift) {
372 ControlProtocol::Redo ();
374 ControlProtocol::Undo ();
379 Push2::button_fwd32t ()
381 const int n = (modifier_state & ModShift) ? 8 : 0;
382 goto_nth_marker (0+n);
386 Push2::button_fwd32 ()
388 const int n = (modifier_state & ModShift) ? 8 : 0;
389 goto_nth_marker (1+n);
393 Push2::button_fwd16t ()
395 const int n = (modifier_state & ModShift) ? 8 : 0;
396 goto_nth_marker (2+n);
400 Push2::button_fwd16 ()
402 const int n = (modifier_state & ModShift) ? 8 : 0;
403 goto_nth_marker (3+n);
407 Push2::button_fwd8t ()
409 const int n = (modifier_state & ModShift) ? 8 : 0;
410 goto_nth_marker (4+n);
414 Push2::button_fwd8 ()
416 const int n = (modifier_state & ModShift) ? 8 : 0;
417 goto_nth_marker (5+n);
421 Push2::button_fwd4t ()
423 const int n = (modifier_state & ModShift) ? 8 : 0;
424 goto_nth_marker (6+n);
428 Push2::button_fwd4 ()
430 const int n = (modifier_state & ModShift) ? 8 : 0;
431 goto_nth_marker (7+n);
435 Push2::button_add_track ()
437 access_action ("Main/AddTrackBus");
441 Push2::button_stop ()
443 /* close current window */
444 access_action ("Main/close-current-dialog");
448 Push2::button_shift_press ()
454 Push2::button_shift_release ()
460 Push2::button_shift_long_press ()
462 access_action ("Main/close-current-dialog");
466 Push2::button_select_press ()
472 Push2::button_select_release ()
474 if (!(modifier_state & ModSelect)) {
475 /* somebody else used us as a modifier */
483 for (int n = 0; n < 8; ++n) {
485 if (stripable[n]->presentation_info().selected()) {
494 /* no visible track selected, select first (if any) */
497 stripable[0]->presentation_info().set_selected (true);
502 if (modifier_state & ModShift) {
503 std::cerr << "select prev\n";
507 /* current selected is leftmost ... cancel selection,
508 switch banks by one, and select leftmost
510 if (bank_start != 0) {
511 stripable[selected]->presentation_info().set_selected (false);
512 switch_bank (bank_start-1);
514 stripable[0]->presentation_info().set_selected (true);
518 /* select prev, if any */
519 int n = selected - 1;
520 while (n >= 0 && !stripable[n]) {
524 stripable[selected]->presentation_info().set_selected (false);
525 stripable[n]->presentation_info().set_selected (true);
531 std::cerr << "select next\n";
535 /* current selected is rightmost ... cancel selection,
536 switch banks by one, and select righmost
538 stripable[selected]->presentation_info().set_selected (false);
539 switch_bank (bank_start+1);
541 stripable[7]->presentation_info().set_selected (true);
544 /* select next, if any */
545 int n = selected + 1;
546 while (n < 8 && !stripable[n]) {
551 stripable[selected]->presentation_info().set_selected (false);
552 stripable[n]->presentation_info().set_selected (true);
560 Push2::button_select_long_press ()
562 access_action ("Main/Escape");
566 Push2::button_long_press_timeout (ButtonID id)
568 if (buttons_down.find (id) != buttons_down.end()) {
569 DEBUG_TRACE (DEBUG::Push2, string_compose ("long press timeout for %1, invoking method\n", id));
570 Button* button = id_button_map[id];
571 (this->*button->long_press_method) ();
573 DEBUG_TRACE (DEBUG::Push2, string_compose ("long press timeout for %1, expired/cancelled\n", id));
574 /* release happened and somehow we were not cancelled */
577 /* whichever button this was, we've used it ... don't invoke the
580 consumed.insert (id);
582 return false; /* don't get called again */
586 Push2::start_press_timeout (Button& button, ButtonID id)
588 Glib::RefPtr<Glib::TimeoutSource> timeout = Glib::TimeoutSource::create (500); // milliseconds
589 button.timeout_connection = timeout->connect (sigc::bind (sigc::mem_fun (*this, &Push2::button_long_press_timeout), id));
590 timeout->attach (main_loop()->get_context());
594 Push2::button_octave_down ()
596 int os = (max (-4, octave_shift - 1));
597 if (os != octave_shift) {
604 Push2::button_octave_up ()
606 int os = (min (4, octave_shift + 1));
607 if (os != octave_shift) {