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"
25 #include "ardour/solo_isolate_control.h"
27 #include "launch_control_xl.h"
29 using namespace ArdourSurface;
30 using namespace ARDOUR;
35 LaunchControlXL::build_maps ()
41 #define MAKE_KNOB(i,cc, index) \
42 knob = new Knob ((i), (cc), (index), (*this)); \
43 cc_knob_map.insert (std::make_pair (knob->controller_number(), knob)); \
44 id_knob_map.insert (std::make_pair (knob->id(), knob))
46 for (uint8_t n = 0; n < 8; ++n) {
47 MAKE_KNOB (static_cast<KnobID>(n), (n + 13), n);
48 MAKE_KNOB (static_cast<KnobID>(n + 8), (n + 29), (n + 8));
49 MAKE_KNOB (static_cast<KnobID>(n + 16), (n + 49), (n + 16));
56 #define MAKE_FADER(i,cc) \
57 fader = new Fader ((i), (cc)); \
58 cc_fader_map.insert (std::make_pair (fader->controller_number(), fader)); \
59 id_fader_map.insert (std::make_pair (fader->id(), fader))
61 for (uint8_t n = 0; n < 8; ++n) {
62 MAKE_FADER (static_cast<FaderID>(n), (n + 77) );
67 ControllerButton *controller_button;
68 NoteButton *note_button;
71 #define MAKE_TRACK_BUTTON_PRESS(i,nn,index,color,p) \
72 note_button = new TrackButton ((i), (nn), (index), (color), (p), (*this)); \
73 nn_note_button_map.insert (std::make_pair (note_button->note_number(), note_button)); \
74 id_note_button_map.insert (std::make_pair (note_button->id(), note_button))
75 #define MAKE_SELECT_BUTTON_PRESS(i,cc,index,p) \
76 controller_button = new SelectButton ((i), (cc), (index), (p), (*this)); \
77 cc_controller_button_map.insert (std::make_pair (controller_button->controller_number(), controller_button)); \
78 id_controller_button_map.insert (std::make_pair (controller_button->id(), controller_button))
79 #define MAKE_SELECT_BUTTON_PRESS_RELEASE_LONG(i,cc,index,p,r,l) \
80 controller_button = new SelectButton ((i), (cc), (index), (p), (r), (l), (*this)); \
81 cc_controller_button_map.insert (std::make_pair (controller_button->controller_number(), controller_button)); \
82 id_controller_button_map.insert (std::make_pair (controller_button->id(), controller_button))
83 #define MAKE_TRACK_STATE_BUTTON_PRESS(i,nn,index,p) \
84 note_button = new TrackStateButton ((i), (nn), (index), (p), (*this)); \
85 nn_note_button_map.insert (std::make_pair (note_button->note_number(), note_button)); \
86 id_note_button_map.insert (std::make_pair (note_button->id(), note_button))
87 #define MAKE_TRACK_STATE_BUTTON_PRESS_RELEASE_LONG(i,nn,index,p,r,l) \
88 note_button = new TrackStateButton ((i), (nn), (index), (p), (r), (l), (*this)); \
89 nn_note_button_map.insert (std::make_pair (note_button->note_number(), note_button)); \
90 id_note_button_map.insert (std::make_pair (note_button->id(), note_button))
93 MAKE_TRACK_BUTTON_PRESS(Focus1, 41, 24, YellowLow, &LaunchControlXL::button_track_focus_1);
94 MAKE_TRACK_BUTTON_PRESS(Focus2, 42, 25, YellowLow, &LaunchControlXL::button_track_focus_2);
95 MAKE_TRACK_BUTTON_PRESS(Focus3, 43, 26, YellowLow, &LaunchControlXL::button_track_focus_3);
96 MAKE_TRACK_BUTTON_PRESS(Focus4, 44, 27, YellowLow, &LaunchControlXL::button_track_focus_4);
97 MAKE_TRACK_BUTTON_PRESS(Focus5, 57, 28, YellowLow, &LaunchControlXL::button_track_focus_5);
98 MAKE_TRACK_BUTTON_PRESS(Focus6, 58, 29, YellowLow, &LaunchControlXL::button_track_focus_6);
99 MAKE_TRACK_BUTTON_PRESS(Focus7, 59, 30, YellowLow, &LaunchControlXL::button_track_focus_7);
100 MAKE_TRACK_BUTTON_PRESS(Focus8, 60, 31, YellowLow, &LaunchControlXL::button_track_focus_8);
101 MAKE_TRACK_BUTTON_PRESS(Control1, 73, 32, AmberLow, &LaunchControlXL::button_track_control_1);
102 MAKE_TRACK_BUTTON_PRESS(Control2, 74, 33, AmberLow, &LaunchControlXL::button_track_control_2);
103 MAKE_TRACK_BUTTON_PRESS(Control3, 75, 34, AmberLow, &LaunchControlXL::button_track_control_3);
104 MAKE_TRACK_BUTTON_PRESS(Control4, 76, 35, AmberLow, &LaunchControlXL::button_track_control_4);
105 MAKE_TRACK_BUTTON_PRESS(Control5, 89, 36, AmberLow, &LaunchControlXL::button_track_control_5);
106 MAKE_TRACK_BUTTON_PRESS(Control6, 90, 37, AmberLow, &LaunchControlXL::button_track_control_6);
107 MAKE_TRACK_BUTTON_PRESS(Control7, 91, 38, AmberLow, &LaunchControlXL::button_track_control_7);
108 MAKE_TRACK_BUTTON_PRESS(Control8, 92, 39, AmberLow, &LaunchControlXL::button_track_control_8);
110 MAKE_SELECT_BUTTON_PRESS(SelectUp, 104, 44, &LaunchControlXL::button_select_up);
111 MAKE_SELECT_BUTTON_PRESS(SelectDown, 105, 45, &LaunchControlXL::button_select_down);
112 MAKE_SELECT_BUTTON_PRESS_RELEASE_LONG(SelectLeft, 106, 46, &LaunchControlXL::relax, &LaunchControlXL::button_select_left, &LaunchControlXL::button_select_left_long_press);
113 MAKE_SELECT_BUTTON_PRESS_RELEASE_LONG(SelectRight, 107, 47, &LaunchControlXL::relax, &LaunchControlXL::button_select_right, &LaunchControlXL::button_select_right_long_press);
115 MAKE_TRACK_STATE_BUTTON_PRESS_RELEASE_LONG(Device, 105, 40, &LaunchControlXL::relax, &LaunchControlXL::button_device, &LaunchControlXL::button_device_long_press);
116 MAKE_TRACK_STATE_BUTTON_PRESS(Mute, 106, 41, &LaunchControlXL::button_mute);
117 MAKE_TRACK_STATE_BUTTON_PRESS(Solo, 107, 42, &LaunchControlXL::button_solo);
118 MAKE_TRACK_STATE_BUTTON_PRESS(Record, 108, 43, &LaunchControlXL::button_record);
123 LaunchControlXL::button_name_by_id (ButtonID id)
137 return "Select Down";
139 return "Select Right";
141 return "Select Left";
182 LaunchControlXL::knob_name_by_id (KnobID id)
241 LaunchControlXL::fader_name_by_id (FaderID id)
267 LaunchControlXL::TrackButton*
268 LaunchControlXL::track_button_by_range(uint8_t n, uint8_t first, uint8_t middle)
270 NNNoteButtonMap::iterator b;
272 b = nn_note_button_map.find (first + n);
274 b = nn_note_button_map.find (middle + n - 4);
277 TrackButton* button = 0;
279 if (b != nn_note_button_map.end()) {
280 button = static_cast<TrackButton*>(b->second);
288 LaunchControlXL::update_track_focus_led(uint8_t n)
290 TrackButton* b = focus_button_by_column(n);
297 if ( stripable[n]->is_selected() ) {
298 b->set_color(YellowFull);
300 b->set_color(AmberLow);
306 write (b->state_msg());
310 LaunchControlXL::button_track_focus(uint8_t n)
312 if (buttons_down.find(Device) != buttons_down.end()) {
313 DEBUG_TRACE (DEBUG::LaunchControlXL, "DEVICE BUTTON HOLD\n");
314 stripable[n]->solo_isolate_control()->set_value (!stripable[n]->solo_isolate_control()->get_value(), PBD::Controllable::UseGroup);
319 if ( stripable[n]->is_selected() ) {
320 ControlProtocol::RemoveStripableFromSelection (stripable[n]);
322 ControlProtocol::AddStripableToSelection (stripable[n]);
331 boost::shared_ptr<AutomationControl>
332 LaunchControlXL::get_ac_by_state(uint8_t n) {
333 boost::shared_ptr<AutomationControl> ac;
335 switch(track_mode()) {
337 ac = stripable[n]->mute_control();
341 ac = stripable[n]->solo_control();
345 ac = stripable[n]->rec_enable_control();
354 LaunchControlXL::Knob**
355 LaunchControlXL::knobs_by_column(uint8_t col, Knob** knob_col)
357 for (uint8_t n = 0; n < 3; ++n) {
358 knob_col[n] = id_knob_map.find(static_cast<KnobID>(col+n*8))->second;
365 LaunchControlXL::update_knob_led(uint8_t n)
369 uint32_t absolute_strip_num = (n + bank_start) % 8;
371 switch (absolute_strip_num) {
374 if (stripable[n] && stripable[n]->is_selected()) {
383 if (stripable[n] && stripable[n]->is_selected()) {
392 if (stripable[n] && stripable[n]->is_selected()) {
401 if (stripable[n] && stripable[n]->is_selected()) {
409 knobs_by_column(n, knobs_col);
411 for (uint8_t s = 0; s < 3; ++s)
414 knobs_col[s]->set_color(color);
416 knobs_col[s]->set_color(Off);
418 write (knobs_col[s]->state_msg());
423 LaunchControlXL::update_track_control_led(uint8_t n)
425 TrackButton* b = control_button_by_column(n);
432 boost::shared_ptr<AutomationControl> ac = get_ac_by_state(n);
434 switch(track_mode()) {
436 if (ac->get_value()) {
437 b->set_color(YellowFull);
439 b->set_color(AmberLow);
443 if (ac && stripable[n] != master ) {
444 if (ac->get_value()) {
445 b->set_color(GreenFull);
447 b->set_color(GreenLow);
455 if (ac->get_value()) {
456 b->set_color(RedFull);
458 b->set_color(RedLow);
472 write (b->state_msg());
476 LaunchControlXL::solo_mute_rec_changed(uint32_t n) {
480 update_track_control_led(n);
484 LaunchControlXL::button_track_control(uint8_t n) {
488 boost::shared_ptr<AutomationControl> ac = get_ac_by_state(n);
491 session->set_control (ac, !ac->get_value(), PBD::Controllable::UseGroup);
496 LaunchControlXL::button_track_mode(TrackMode state)
498 set_track_mode(state);
499 for (uint8_t n = 0; n < 8; ++n) {
500 update_track_control_led(n);
503 TrackStateButton* mute = static_cast<TrackStateButton*>(id_note_button_map[Mute]);
504 TrackStateButton* solo = static_cast<TrackStateButton*>(id_note_button_map[Solo]);
505 TrackStateButton* record = static_cast<TrackStateButton*>(id_note_button_map[Record]);
507 write(mute->state_msg((state == TrackMute)));
508 write(solo->state_msg((state == TrackSolo)));
509 write(record->state_msg((state == TrackRecord)));
513 LaunchControlXL::button_select_left()
515 switch_bank (max (0, bank_start - 1));
519 LaunchControlXL::button_select_right()
521 switch_bank (max (0, bank_start + 1));
525 LaunchControlXL::button_select_left_long_press()
531 LaunchControlXL::button_select_right_long_press()
533 switch_bank (session->get_stripables().size() - 3);
537 LaunchControlXL::button_select_up()
543 LaunchControlXL::button_select_down()
549 LaunchControlXL::button_device()
555 LaunchControlXL::button_device_long_press()
561 LaunchControlXL::button_mute()
563 if (buttons_down.find(Device) != buttons_down.end()) {
564 access_action ("Editor/track-mute-toggle");
566 button_track_mode(TrackMute);
571 LaunchControlXL::button_solo()
573 if (buttons_down.find(Device) != buttons_down.end()) {
574 access_action ("Editor/track-solo-toggle");
576 button_track_mode(TrackSolo);
581 LaunchControlXL::button_record()
583 if (buttons_down.find(Device) != buttons_down.end()) {
584 access_action ("Editor/track-record-enable-toggle");
586 button_track_mode(TrackRecord);
591 LaunchControlXL::button_long_press_timeout (ButtonID id, Button* button)
593 if (buttons_down.find (id) != buttons_down.end()) {
594 DEBUG_TRACE (DEBUG::LaunchControlXL, string_compose ("long press timeout for %1, invoking method\n", id));
595 (this->*button->long_press_method) ();
597 DEBUG_TRACE (DEBUG::LaunchControlXL, string_compose ("long press timeout for %1, expired/cancelled\n", id));
598 /* release happened and somehow we were not cancelled */
601 /* whichever button this was, we've used it ... don't invoke the
604 consumed.insert (id);
606 return false; /* don't get called again */
611 LaunchControlXL::start_press_timeout (Button* button, ButtonID id)
613 Glib::RefPtr<Glib::TimeoutSource> timeout = Glib::TimeoutSource::create (500); // milliseconds
614 button->timeout_connection = timeout->connect (sigc::bind (sigc::mem_fun (*this, &LaunchControlXL::button_long_press_timeout), id, button));
615 timeout->attach (main_loop()->get_context());