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 (OctaveUp, 55);
201 MAKE_WHITE_BUTTON (PageRight, 63);
202 MAKE_WHITE_BUTTON (OctaveDown, 54);
203 MAKE_WHITE_BUTTON (PageLeft, 62);
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_right ()
248 ScrollTimeline (0.75);
252 Push2::button_left ()
254 ScrollTimeline (-0.75);
258 Push2::button_repeat ()
264 Push2::button_metronome ()
270 Push2::button_solo ()
278 access_action ("Editor/start-range-from-playhead");
280 id_button_map[New]->set_color (LED::White);
281 id_button_map[New]->set_state (LED::NoTransition);
282 write (id_button_map[New]->state_msg());
284 /* blink the button for the other half of this operation */
286 id_button_map[FixedLength]->set_color (LED::White);
287 id_button_map[FixedLength]->set_state (LED::Blinking4th);
288 write (id_button_map[FixedLength]->state_msg());
293 Push2::button_fixed_length ()
295 access_action ("Editor/finish-range-from-playhead");
297 /* turn off both buttons for this operation */
299 id_button_map[New]->set_color (LED::Black);
300 id_button_map[New]->set_state (LED::NoTransition);
301 write (id_button_map[New]->state_msg());
302 id_button_map[FixedLength]->set_color (LED::Black);
303 id_button_map[FixedLength]->set_state (LED::NoTransition);
304 write (id_button_map[FixedLength]->state_msg());
308 Push2::button_browse ()
310 if (modifier_state & ModShift) {
311 access_action ("Editor/addExistingAudioFiles");
313 switch_bank (max (0, bank_start - 8));
318 Push2::button_clip ()
320 switch_bank (max (0, bank_start + 8));
324 Push2::button_upper (uint32_t n)
330 if (modifier_state & ModShift) {
331 boost::shared_ptr<AutomationControl> sc = stripable[n]->rec_enable_control ();
333 sc->set_value (!sc->get_value(), PBD::Controllable::UseGroup);
336 boost::shared_ptr<SoloControl> sc = stripable[n]->solo_control ();
338 sc->set_value (!sc->get_value(), PBD::Controllable::UseGroup);
344 Push2::button_lower (uint32_t n)
350 if (modifier_state & ModSelect) {
351 stripable[n]->presentation_info().set_selected (!stripable[n]->presentation_info().selected());
353 cerr << "select not set\n";
354 boost::shared_ptr<MuteControl> mc = stripable[n]->mute_control ();
357 mc->set_value (!mc->get_value(), PBD::Controllable::UseGroup);
363 Push2::button_undo ()
365 if (modifier_state & ModShift) {
366 ControlProtocol::Redo ();
368 ControlProtocol::Undo ();
373 Push2::button_fwd32t ()
375 const int n = (modifier_state & ModShift) ? 8 : 0;
376 goto_nth_marker (0+n);
380 Push2::button_fwd32 ()
382 const int n = (modifier_state & ModShift) ? 8 : 0;
383 goto_nth_marker (1+n);
387 Push2::button_fwd16t ()
389 const int n = (modifier_state & ModShift) ? 8 : 0;
390 goto_nth_marker (2+n);
394 Push2::button_fwd16 ()
396 const int n = (modifier_state & ModShift) ? 8 : 0;
397 goto_nth_marker (3+n);
401 Push2::button_fwd8t ()
403 const int n = (modifier_state & ModShift) ? 8 : 0;
404 goto_nth_marker (4+n);
408 Push2::button_fwd8 ()
410 const int n = (modifier_state & ModShift) ? 8 : 0;
411 goto_nth_marker (5+n);
415 Push2::button_fwd4t ()
417 const int n = (modifier_state & ModShift) ? 8 : 0;
418 goto_nth_marker (6+n);
422 Push2::button_fwd4 ()
424 const int n = (modifier_state & ModShift) ? 8 : 0;
425 goto_nth_marker (7+n);
429 Push2::button_add_track ()
431 access_action ("Main/AddTrackBus");
435 Push2::button_stop ()
437 /* close current window */
438 access_action ("Main/close-current-dialog");
442 Push2::button_shift_press ()
448 Push2::button_shift_release ()
454 Push2::button_shift_long_press ()
456 access_action ("Main/close-current-dialog");
460 Push2::button_select_press ()
466 Push2::button_select_release ()
468 if (!(modifier_state & ModSelect)) {
469 /* somebody else used us as a modifier */
477 for (int n = 0; n < 8; ++n) {
479 if (stripable[n]->presentation_info().selected()) {
488 /* no visible track selected, select first (if any) */
491 stripable[0]->presentation_info().set_selected (true);
496 if (modifier_state & ModShift) {
497 std::cerr << "select prev\n";
501 /* current selected is leftmost ... cancel selection,
502 switch banks by one, and select leftmost
504 if (bank_start != 0) {
505 stripable[selected]->presentation_info().set_selected (false);
506 switch_bank (bank_start-1);
508 stripable[0]->presentation_info().set_selected (true);
512 /* select prev, if any */
513 int n = selected - 1;
514 while (n >= 0 && !stripable[n]) {
518 stripable[selected]->presentation_info().set_selected (false);
519 stripable[n]->presentation_info().set_selected (true);
525 std::cerr << "select next\n";
529 /* current selected is rightmost ... cancel selection,
530 switch banks by one, and select righmost
532 stripable[selected]->presentation_info().set_selected (false);
533 switch_bank (bank_start+1);
535 stripable[7]->presentation_info().set_selected (true);
538 /* select next, if any */
539 int n = selected + 1;
540 while (n < 8 && !stripable[n]) {
545 stripable[selected]->presentation_info().set_selected (false);
546 stripable[n]->presentation_info().set_selected (true);
554 Push2::button_select_long_press ()
556 access_action ("Main/Escape");
560 Push2::button_long_press_timeout (ButtonID id)
562 if (buttons_down.find (id) != buttons_down.end()) {
563 DEBUG_TRACE (DEBUG::Push2, string_compose ("long press timeout for %1, invoking method\n", id));
564 Button* button = id_button_map[id];
565 (this->*button->long_press_method) ();
567 DEBUG_TRACE (DEBUG::Push2, string_compose ("long press timeout for %1, expired/cancelled\n", id));
568 /* release happened and somehow we were not cancelled */
571 /* whichever button this was, we've used it ... don't invoke the
574 consumed.insert (id);
576 return false; /* don't get called again */
580 Push2::start_press_timeout (Button& button, ButtonID id)
582 Glib::RefPtr<Glib::TimeoutSource> timeout = Glib::TimeoutSource::create (500); // milliseconds
583 button.timeout_connection = timeout->connect (sigc::bind (sigc::mem_fun (*this, &Push2::button_long_press_timeout), id));
584 timeout->attach (main_loop()->get_context());