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.
19 #include <cairomm/context.h>
20 #include <cairomm/surface.h>
21 #include <pangomm/layout.h>
23 #include "pbd/compose.h"
24 #include "pbd/convert.h"
25 #include "pbd/debug.h"
26 #include "pbd/failed_constructor.h"
27 #include "pbd/file_utils.h"
28 #include "pbd/search_path.h"
29 #include "pbd/enumwriter.h"
31 #include "midi++/parser.h"
32 #include "timecode/time.h"
33 #include "timecode/bbt_time.h"
35 #include "ardour/async_midi_port.h"
36 #include "ardour/audioengine.h"
37 #include "ardour/debug.h"
38 #include "ardour/filesystem_paths.h"
39 #include "ardour/midiport_manager.h"
40 #include "ardour/midi_track.h"
41 #include "ardour/midi_port.h"
42 #include "ardour/session.h"
43 #include "ardour/tempo.h"
48 using namespace ARDOUR;
52 using namespace ArdourSurface;
56 #include "pbd/abstract_ui.cc" // instantiate template
58 const int Push2::cols = 960;
59 const int Push2::rows = 160;
60 const int Push2::pixels_per_row = 1024;
62 #define ABLETON 0x2982
65 __attribute__((constructor)) static void
68 EnumWriter& enum_writer (EnumWriter::instance());
72 MusicalMode::Type mode;
74 #define REGISTER(e) enum_writer.register_distinct (typeid(e).name(), i, s); i.clear(); s.clear()
75 #define REGISTER_CLASS_ENUM(t,e) i.push_back (t::e); s.push_back (#e)
77 REGISTER_CLASS_ENUM (MusicalMode,Dorian);
78 REGISTER_CLASS_ENUM (MusicalMode, IonianMajor);
79 REGISTER_CLASS_ENUM (MusicalMode, Minor);
80 REGISTER_CLASS_ENUM (MusicalMode, HarmonicMinor);
81 REGISTER_CLASS_ENUM (MusicalMode, MelodicMinorAscending);
82 REGISTER_CLASS_ENUM (MusicalMode, MelodicMinorDescending);
83 REGISTER_CLASS_ENUM (MusicalMode, Phrygian);
84 REGISTER_CLASS_ENUM (MusicalMode, Lydian);
85 REGISTER_CLASS_ENUM (MusicalMode, Mixolydian);
86 REGISTER_CLASS_ENUM (MusicalMode, Aeolian);
87 REGISTER_CLASS_ENUM (MusicalMode, Locrian);
88 REGISTER_CLASS_ENUM (MusicalMode, PentatonicMajor);
89 REGISTER_CLASS_ENUM (MusicalMode, PentatonicMinor);
90 REGISTER_CLASS_ENUM (MusicalMode, Chromatic);
91 REGISTER_CLASS_ENUM (MusicalMode, BluesScale);
92 REGISTER_CLASS_ENUM (MusicalMode, NeapolitanMinor);
93 REGISTER_CLASS_ENUM (MusicalMode, NeapolitanMajor);
94 REGISTER_CLASS_ENUM (MusicalMode, Oriental);
95 REGISTER_CLASS_ENUM (MusicalMode, DoubleHarmonic);
96 REGISTER_CLASS_ENUM (MusicalMode, Enigmatic);
97 REGISTER_CLASS_ENUM (MusicalMode, Hirajoshi);
98 REGISTER_CLASS_ENUM (MusicalMode, HungarianMinor);
99 REGISTER_CLASS_ENUM (MusicalMode, HungarianMajor);
100 REGISTER_CLASS_ENUM (MusicalMode, Kumoi);
101 REGISTER_CLASS_ENUM (MusicalMode, Iwato);
102 REGISTER_CLASS_ENUM (MusicalMode, Hindu);
103 REGISTER_CLASS_ENUM (MusicalMode, Spanish8Tone);
104 REGISTER_CLASS_ENUM (MusicalMode, Pelog);
105 REGISTER_CLASS_ENUM (MusicalMode, HungarianGypsy);
106 REGISTER_CLASS_ENUM (MusicalMode, Overtone);
107 REGISTER_CLASS_ENUM (MusicalMode, LeadingWholeTone);
108 REGISTER_CLASS_ENUM (MusicalMode, Arabian);
109 REGISTER_CLASS_ENUM (MusicalMode, Balinese);
110 REGISTER_CLASS_ENUM (MusicalMode, Gypsy);
111 REGISTER_CLASS_ENUM (MusicalMode, Mohammedan);
112 REGISTER_CLASS_ENUM (MusicalMode, Javanese);
113 REGISTER_CLASS_ENUM (MusicalMode, Persian);
114 REGISTER_CLASS_ENUM (MusicalMode, Algerian);
118 Push2::Push2 (ARDOUR::Session& s)
119 : ControlProtocol (s, string (X_("Ableton Push 2")))
120 , AbstractUI<Push2Request> (name())
123 , frame_buffer (Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, cols, rows))
124 , modifier_state (None)
127 , connection_state (ConnectionState (0))
129 , _mode (MusicalMode::IonianMajor)
135 context = Cairo::Context::create (frame_buffer);
136 tc_clock_layout = Pango::Layout::create (context);
137 bbt_clock_layout = Pango::Layout::create (context);
139 Pango::FontDescription fd ("Sans Bold 24");
140 tc_clock_layout->set_font_description (fd);
141 bbt_clock_layout->set_font_description (fd);
143 Pango::FontDescription fd2 ("Sans 10");
144 for (int n = 0; n < 8; ++n) {
145 upper_layout[n] = Pango::Layout::create (context);
146 upper_layout[n]->set_font_description (fd2);
147 upper_layout[n]->set_text ("solo");
148 lower_layout[n] = Pango::Layout::create (context);
149 lower_layout[n]->set_font_description (fd2);
150 lower_layout[n]->set_text ("mute");
153 Pango::FontDescription fd3 ("Sans Bold 10");
154 for (int n = 0; n < 8; ++n) {
155 mid_layout[n] = Pango::Layout::create (context);
156 mid_layout[n]->set_font_description (fd3);
163 throw failed_constructor ();
166 StripableSelectionChanged.connect (selection_connection, MISSING_INVALIDATOR, boost::bind (&Push2::stripable_selection_change, this, _1), this);
168 /* catch arrival and departure of Push2 itself */
169 ARDOUR::AudioEngine::instance()->PortRegisteredOrUnregistered.connect (port_reg_connection, MISSING_INVALIDATOR, boost::bind (&Push2::port_registration_handler, this), this);
171 /* Catch port connections and disconnections */
172 ARDOUR::AudioEngine::instance()->PortConnectedOrDisconnected.connect (port_connection, MISSING_INVALIDATOR, boost::bind (&Push2::connection_handler, this, _1, _2, _3, _4, _5), this);
174 /* ports might already be there */
175 port_registration_handler ();
184 Push2::port_registration_handler ()
186 if (_async_in->connected() && _async_out->connected()) {
187 /* don't waste cycles here */
191 string input_port_name = X_("Ableton Push 2 MIDI 1 in");
192 string output_port_name = X_("Ableton Push 2 MIDI 1 out");
196 AudioEngine::instance()->get_ports (string_compose (".*%1", input_port_name), DataType::MIDI, PortFlags (IsPhysical|IsOutput|ControlOnly), in);
197 AudioEngine::instance()->get_ports (string_compose (".*%1", output_port_name), DataType::MIDI, PortFlags (IsPhysical|IsInput|ControlOnly), out);
199 if (!in.empty() && !out.empty()) {
200 cerr << "Push2: both ports found\n";
201 cerr << "\tconnecting to " << in.front() << " + " << out.front() << endl;
202 if (!_async_in->connected()) {
203 AudioEngine::instance()->connect (_async_in->name(), in.front());
205 if (!_async_out->connected()) {
206 AudioEngine::instance()->connect (_async_out->name(), out.front());
221 if ((handle = libusb_open_device_with_vid_pid (NULL, ABLETON, PUSH2)) == 0) {
225 if ((err = libusb_claim_interface (handle, 0x00))) {
229 device_frame_buffer = new uint16_t[rows*pixels_per_row];
231 memset (device_frame_buffer, 0, sizeof (uint16_t) * rows * pixels_per_row);
233 frame_header[0] = 0xef;
234 frame_header[1] = 0xcd;
235 frame_header[2] = 0xab;
236 frame_header[3] = 0x89;
237 memset (&frame_header[4], 0, 12);
241 _async_in = AudioEngine::instance()->register_input_port (DataType::MIDI, X_("Push 2 in"), true);
242 _async_out = AudioEngine::instance()->register_output_port (DataType::MIDI, X_("Push 2 out"), true);
244 if (_async_in == 0 || _async_out == 0) {
248 /* We do not add our ports to the input/output bundles because we don't
249 * want users wiring them by hand. They could use JACK tools if they
250 * really insist on that.
253 _input_port = boost::dynamic_pointer_cast<AsyncMIDIPort>(_async_in).get();
254 _output_port = boost::dynamic_pointer_cast<AsyncMIDIPort>(_async_out).get();
256 /* Create a shadow port where, depending on the state of the surface,
257 * we will make pad note on/off events appear. The surface code will
258 * automatically this port to the first selected MIDI track.
261 boost::dynamic_pointer_cast<AsyncMIDIPort>(_async_in)->add_shadow_port (string_compose (_("%1 Pads"), X_("Push 2")), boost::bind (&Push2::pad_filter, this, _1, _2));
262 boost::shared_ptr<MidiPort> shadow_port = boost::dynamic_pointer_cast<AsyncMIDIPort>(_async_in)->shadow_port();
266 _output_bundle.reset (new ARDOUR::Bundle (_("Push 2 Pads"), false));
268 _output_bundle->add_channel (
270 ARDOUR::DataType::MIDI,
271 session->engine().make_port_name_non_relative (shadow_port->name())
275 session->BundleAddedOrRemoved ();
277 connect_to_parser ();
282 list<boost::shared_ptr<ARDOUR::Bundle> >
285 list<boost::shared_ptr<ARDOUR::Bundle> > b;
287 if (_output_bundle) {
288 b.push_back (_output_bundle);
297 init_buttons (false);
299 /* wait for button data to be flushed */
301 asp = dynamic_cast<AsyncMIDIPort*> (_output_port);
302 asp->drain (10000, 500000);
304 AudioEngine::instance()->unregister_port (_async_in);
305 AudioEngine::instance()->unregister_port (_async_out);
307 _async_in.reset ((ARDOUR::Port*) 0);
308 _async_out.reset ((ARDOUR::Port*) 0);
312 vblank_connection.disconnect ();
313 periodic_connection.disconnect ();
314 session_connections.drop_connections ();
315 stripable_connections.drop_connections ();
318 libusb_release_interface (handle, 0x00);
319 libusb_close (handle);
323 for (int n = 0; n < 8; ++n) {
324 stripable[n].reset ();
327 delete [] device_frame_buffer;
328 device_frame_buffer = 0;
334 Push2::init_buttons (bool startup)
336 /* This is a list of buttons that we want lit because they do something
337 in ardour related (loosely, sometimes) to their illuminated label.
340 ButtonID buttons[] = { Mute, Solo, Master, Up, Right, Left, Down, Note, Session, Mix, AddTrack, Delete, Undo,
341 Metronome, Shift, Select, Play, RecordEnable, Automate, Repeat, Note, Session, DoubleLoop,
342 Quantize, Duplicate, Browse, PageRight, PageLeft, OctaveUp, OctaveDown
345 for (size_t n = 0; n < sizeof (buttons) / sizeof (buttons[0]); ++n) {
346 Button* b = id_button_map[buttons[n]];
349 b->set_color (LED::White);
351 b->set_color (LED::Black);
353 b->set_state (LED::OneShot24th);
354 write (b->state_msg());
357 /* Strip buttons should all be off (black) by default. They will change
358 * color to reflect various conditions
361 ButtonID strip_buttons[] = { Upper1, Upper2, Upper3, Upper4, Upper5, Upper6, Upper7, Upper8,
362 Lower1, Lower2, Lower3, Lower4, Lower5, Lower6, Lower7, Lower8, };
364 for (size_t n = 0; n < sizeof (strip_buttons) / sizeof (strip_buttons[0]); ++n) {
365 Button* b = id_button_map[strip_buttons[n]];
367 b->set_color (LED::Black);
368 b->set_state (LED::OneShot24th);
369 write (b->state_msg());
374 /* all other buttons are off (black) */
376 ButtonID off_buttons[] = { TapTempo, Setup, User, Stop, Convert, New, FixedLength,
377 Fwd32ndT, Fwd32nd, Fwd16thT, Fwd16th, Fwd8thT, Fwd8th, Fwd4trT, Fwd4tr,
378 Accent, Scale, Layout, Note, Session, };
380 for (size_t n = 0; n < sizeof (off_buttons) / sizeof (off_buttons[0]); ++n) {
381 Button* b = id_button_map[off_buttons[n]];
383 b->set_color (LED::Black);
384 b->set_state (LED::OneShot24th);
385 write (b->state_msg());
390 for (NNPadMap::iterator pi = nn_pad_map.begin(); pi != nn_pad_map.end(); ++pi) {
391 Pad* pad = pi->second;
393 pad->set_color (LED::Black);
394 pad->set_state (LED::OneShot24th);
395 write (pad->state_msg());
403 libusb_device_handle *h;
406 if ((h = libusb_open_device_with_vid_pid (NULL, ABLETON, PUSH2)) == 0) {
407 DEBUG_TRACE (DEBUG::Push2, "no Push2 device found\n");
412 DEBUG_TRACE (DEBUG::Push2, "Push2 device located\n");
417 Push2::request_factory (uint32_t num_requests)
419 /* AbstractUI<T>::request_buffer_factory() is a template method only
420 instantiated in this source module. To provide something visible for
421 use in the interface/descriptor, we have this static method that is
424 return request_buffer_factory (num_requests);
428 Push2::do_request (Push2Request * req)
430 DEBUG_TRACE (DEBUG::Push2, string_compose ("doing request type %1\n", req->type));
431 if (req->type == CallSlot) {
433 call_slot (MISSING_INVALIDATOR, req->the_slot);
435 } else if (req->type == Quit) {
449 /** render host-side frame buffer (a Cairo ImageSurface) to the current
450 * device-side frame buffer. The device frame buffer will be pushed to the
451 * device on the next call to vblank()
455 Push2::blit_to_device_frame_buffer ()
457 /* ensure that all drawing has been done before we fetch pixel data */
459 frame_buffer->flush ();
461 const int stride = 3840; /* bytes per row for Cairo::FORMAT_ARGB32 */
462 const uint8_t* data = frame_buffer->get_data ();
464 /* fill frame buffer (320kB) */
466 uint16_t* fb = (uint16_t*) device_frame_buffer;
468 for (int row = 0; row < rows; ++row) {
470 const uint8_t* dp = data + row * stride;
472 for (int col = 0; col < cols; ++col) {
474 /* fetch r, g, b (range 0..255). Ignore alpha */
476 const int r = (*((const uint32_t*)dp) >> 16) & 0xff;
477 const int g = (*((const uint32_t*)dp) >> 8) & 0xff;
478 const int b = *((const uint32_t*)dp) & 0xff;
480 /* convert to 5 bits, 6 bits, 5 bits, respectively */
481 /* generate 16 bit BGB565 value */
483 *fb++ = (r >> 3) | ((g & 0xfc) << 3) | ((b & 0xf8) << 8);
485 /* the push2 docs state that we should xor the pixel
486 * data. Doing so doesn't work correctly, and not doing
487 * so seems to work fine (colors roughly match intended
494 /* skip 128 bytes to next line. This is filler, used to avoid line borders occuring in the middle of 512
498 fb += 64; /* 128 bytes = 64 int16_t */
507 string tc_clock_text;
508 string bbt_clock_text;
511 if (get_microseconds() - splash_start > 4000000) {
519 framepos_t audible = session->audible_frame();
521 bool negative = false;
528 session->timecode_time (audible, TC);
530 TC.negative = TC.negative || negative;
532 tc_clock_text = Timecode::timecode_format_time(TC);
534 Timecode::BBT_Time bbt = session->tempo_map().bbt_at_frame (audible);
537 #define BBT_BAR_CHAR "|"
540 snprintf (buf, sizeof (buf), "-%03" PRIu32 BBT_BAR_CHAR "%02" PRIu32 BBT_BAR_CHAR "%04" PRIu32,
541 bbt.bars, bbt.beats, bbt.ticks);
543 snprintf (buf, sizeof (buf), " %03" PRIu32 BBT_BAR_CHAR "%02" PRIu32 BBT_BAR_CHAR "%04" PRIu32,
544 bbt.bars, bbt.beats, bbt.ticks);
547 bbt_clock_text = buf;
552 if (tc_clock_text != tc_clock_layout->get_text()) {
554 tc_clock_layout->set_text (tc_clock_text);
557 if (bbt_clock_text != tc_clock_layout->get_text()) {
559 bbt_clock_layout->set_text (bbt_clock_text);
564 for (int n = 0; n < 8; ++n) {
566 mid_text = short_version (stripable[n]->name(), 10);
567 if (mid_text != mid_layout[n]->get_text()) {
568 mid_layout[n]->set_text (mid_text);
578 context->set_source_rgb (0.764, 0.882, 0.882);
579 context->rectangle (0, 0, 960, 160);
581 context->set_source_rgb (0.23, 0.0, 0.349);
582 context->move_to (650, 25);
583 tc_clock_layout->update_from_cairo_context (context);
584 tc_clock_layout->show_in_cairo_context (context);
585 context->move_to (650, 60);
586 bbt_clock_layout->update_from_cairo_context (context);
587 bbt_clock_layout->show_in_cairo_context (context);
589 for (int n = 0; n < 8; ++n) {
590 context->move_to (10 + (n*120), 2);
591 upper_layout[n]->update_from_cairo_context (context);
592 upper_layout[n]->show_in_cairo_context (context);
595 for (int n = 0; n < 8; ++n) {
596 context->move_to (10 + (n*120), 140);
597 lower_layout[n]->update_from_cairo_context (context);
598 lower_layout[n]->show_in_cairo_context (context);
601 for (int n = 0; n < 8; ++n) {
602 if (stripable[n] && stripable[n]->presentation_info().selected()) {
603 context->rectangle (10 + (n*120) - 5, 115, 120, 22);
604 context->set_source_rgb (1.0, 0.737, 0.172);
607 context->set_source_rgb (0.0, 0.0, 0.0);
608 context->move_to (10 + (n*120), 120);
609 mid_layout[n]->update_from_cairo_context (context);
610 mid_layout[n]->show_in_cairo_context (context);
624 const int timeout_msecs = 1000;
627 if ((err = libusb_bulk_transfer (handle, 0x01, frame_header, sizeof (frame_header), &transferred, timeout_msecs))) {
633 blit_to_device_frame_buffer ();
636 if ((err = libusb_bulk_transfer (handle, 0x01, (uint8_t*) device_frame_buffer , 2 * rows * pixels_per_row, &transferred, timeout_msecs))) {
644 Push2::set_active (bool yn)
646 DEBUG_TRACE (DEBUG::Push2, string_compose("Push2Protocol::set_active init with yn: '%1'\n", yn));
648 if (yn == active()) {
654 /* start event loop */
659 DEBUG_TRACE (DEBUG::Push2, "device open failed\n");
664 /* Connect input port to event loop */
668 asp = dynamic_cast<AsyncMIDIPort*> (_input_port);
669 asp->xthread().set_receive_handler (sigc::bind (sigc::mem_fun (this, &Push2::midi_input_handler), _input_port));
670 asp->xthread().attach (main_loop()->get_context());
672 connect_session_signals ();
674 /* set up periodic task used to push a frame buffer to the
675 * device (25fps). The device can handle 60fps, but we don't
676 * need that frame rate.
679 Glib::RefPtr<Glib::TimeoutSource> vblank_timeout = Glib::TimeoutSource::create (40); // milliseconds
680 vblank_connection = vblank_timeout->connect (sigc::mem_fun (*this, &Push2::vblank));
681 vblank_timeout->attach (main_loop()->get_context());
684 Glib::RefPtr<Glib::TimeoutSource> periodic_timeout = Glib::TimeoutSource::create (1000); // milliseconds
685 periodic_connection = periodic_timeout->connect (sigc::mem_fun (*this, &Push2::periodic));
686 periodic_timeout->attach (main_loop()->get_context());
690 set_pad_scale (_scale_root, _root_octave, _mode, _in_key);
700 ControlProtocol::set_active (yn);
702 DEBUG_TRACE (DEBUG::Push2, string_compose("Push2Protocol::set_active done with yn: '%1'\n", yn));
708 Push2::init_touch_strip ()
710 MidiByteArray msg (9, 0xf0, 0x00, 0x21, 0x1d, 0x01, 0x01, 0x17, 0x00, 0xf7);
711 /* flags are the final byte (ignore end-of-sysex */
713 /* show bar, not point
717 msg[7] = (1<<4) | (1<<5) | (1<<6);
722 Push2::write (const MidiByteArray& data)
724 /* immediate delivery */
725 _output_port->write (&data[0], data.size(), 0);
729 Push2::midi_input_handler (IOCondition ioc, MIDI::Port* port)
732 DEBUG_TRACE (DEBUG::Push2, "MIDI port closed\n");
738 // DEBUG_TRACE (DEBUG::Push2, string_compose ("something happend on %1\n", port->name()));
740 AsyncMIDIPort* asp = dynamic_cast<AsyncMIDIPort*>(port);
745 //DEBUG_TRACE (DEBUG::Push2, string_compose ("data available on %1\n", port->name()));
746 framepos_t now = AudioEngine::instance()->sample_time();
760 Push2::connect_to_parser ()
762 DEBUG_TRACE (DEBUG::Push2, string_compose ("Connecting to signals on port %2\n", _input_port->name()));
764 MIDI::Parser* p = _input_port->parser();
767 p->sysex.connect_same_thread (*this, boost::bind (&Push2::handle_midi_sysex, this, _1, _2, _3));
768 /* V-Pot messages are Controller */
769 p->controller.connect_same_thread (*this, boost::bind (&Push2::handle_midi_controller_message, this, _1, _2));
770 /* Button messages are NoteOn */
771 p->note_on.connect_same_thread (*this, boost::bind (&Push2::handle_midi_note_on_message, this, _1, _2));
772 /* Button messages are NoteOn but libmidi++ sends note-on w/velocity = 0 as note-off so catch them too */
773 p->note_off.connect_same_thread (*this, boost::bind (&Push2::handle_midi_note_on_message, this, _1, _2));
774 /* Fader messages are Pitchbend */
775 p->channel_pitchbend[0].connect_same_thread (*this, boost::bind (&Push2::handle_midi_pitchbend_message, this, _1, _2));
779 Push2::handle_midi_sysex (MIDI::Parser&, MIDI::byte* raw_bytes, size_t sz)
781 DEBUG_TRACE (DEBUG::Push2, string_compose ("Sysex, %1 bytes\n", sz));
785 Push2::handle_midi_controller_message (MIDI::Parser&, MIDI::EventTwoBytes* ev)
787 DEBUG_TRACE (DEBUG::Push2, string_compose ("CC %1 (value %2)\n", (int) ev->controller_number, (int) ev->value));
789 CCButtonMap::iterator b = cc_button_map.find (ev->controller_number);
792 /* any press cancels any pending long press timeouts */
793 for (set<ButtonID>::iterator x = buttons_down.begin(); x != buttons_down.end(); ++x) {
794 Button* bb = id_button_map[*x];
795 bb->timeout_connection.disconnect ();
799 if (b != cc_button_map.end()) {
801 Button* button = b->second;
804 buttons_down.insert (button->id);
805 start_press_timeout (*button, button->id);
807 buttons_down.erase (button->id);
808 button->timeout_connection.disconnect ();
812 set<ButtonID>::iterator c = consumed.find (button->id);
814 if (c == consumed.end()) {
815 if (ev->value == 0) {
816 (this->*button->release_method)();
818 (this->*button->press_method)();
821 DEBUG_TRACE (DEBUG::Push2, "button was consumed, ignored\n");
829 int delta = ev->value;
832 delta = -(128 - delta);
835 switch (ev->controller_number) {
837 strip_vpot (0, delta);
840 strip_vpot (1, delta);
843 strip_vpot (2, delta);
846 strip_vpot (3, delta);
849 strip_vpot (4, delta);
852 strip_vpot (5, delta);
855 strip_vpot (6, delta);
858 strip_vpot (7, delta);
863 strip_vpot (8, delta);
866 other_vpot (1, delta);
871 other_vpot (2, delta);
878 Push2::handle_midi_note_on_message (MIDI::Parser& parser, MIDI::EventTwoBytes* ev)
880 DEBUG_TRACE (DEBUG::Push2, string_compose ("Note On %1 (velocity %2)\n", (int) ev->note_number, (int) ev->velocity));
882 if (ev->velocity == 0) {
883 handle_midi_note_off_message (parser, ev);
887 switch (ev->note_number) {
889 strip_vpot_touch (0, ev->velocity > 64);
892 strip_vpot_touch (1, ev->velocity > 64);
895 strip_vpot_touch (2, ev->velocity > 64);
898 strip_vpot_touch (3, ev->velocity > 64);
901 strip_vpot_touch (4, ev->velocity > 64);
904 strip_vpot_touch (5, ev->velocity > 64);
907 strip_vpot_touch (6, ev->velocity > 64);
910 strip_vpot_touch (7, ev->velocity > 64);
915 other_vpot_touch (0, ev->velocity > 64);
918 other_vpot_touch (1, ev->velocity > 64);
923 other_vpot_touch (3, ev->velocity > 64);
928 if (ev->velocity < 64) {
934 if (ev->note_number < 11) {
940 NNPadMap::iterator pi = nn_pad_map.find (ev->note_number);
942 if (pi == nn_pad_map.end()) {
946 Pad* pad = pi->second;
948 if (pad->do_when_pressed == Pad::FlashOn) {
949 pad->set_color (LED::White);
950 pad->set_state (LED::OneShot24th);
951 write (pad->state_msg());
952 } else if (pad->do_when_pressed == Pad::FlashOff) {
953 pad->set_color (LED::Black);
954 pad->set_state (LED::OneShot24th);
955 write (pad->state_msg());
960 Push2::handle_midi_note_off_message (MIDI::Parser&, MIDI::EventTwoBytes* ev)
962 DEBUG_TRACE (DEBUG::Push2, string_compose ("Note Off %1 (velocity %2)\n", (int) ev->note_number, (int) ev->velocity));
964 if (ev->note_number < 11) {
965 /* theoretically related to encoder touch start/end, but
966 * actually they send note on with two different velocity
972 NNPadMap::iterator pi = nn_pad_map.find (ev->note_number);
974 if (pi == nn_pad_map.end()) {
978 Pad* pad = pi->second;
980 if (pad->do_when_pressed == Pad::FlashOn) {
981 pad->set_color (LED::Black);
982 pad->set_state (LED::OneShot24th);
983 write (pad->state_msg());
984 } else if (pad->do_when_pressed == Pad::FlashOff) {
985 pad->set_color (pad->perma_color);
986 pad->set_state (LED::OneShot24th);
987 write (pad->state_msg());
992 Push2::handle_midi_pitchbend_message (MIDI::Parser&, MIDI::pitchbend_t pb)
1000 /* range of +1 .. -1 */
1001 speed = ((int32_t) pb - 8192) / 8192.0;
1002 /* convert to range of +3 .. -3 */
1003 session->request_transport_speed (speed * 3.0);
1007 Push2::thread_init ()
1009 struct sched_param rtparam;
1011 pthread_set_name (event_loop_name().c_str());
1013 PBD::notify_event_loops_about_thread_creation (pthread_self(), event_loop_name(), 2048);
1014 ARDOUR::SessionEvent::create_per_thread_pool (event_loop_name(), 128);
1016 memset (&rtparam, 0, sizeof (rtparam));
1017 rtparam.sched_priority = 9; /* XXX should be relative to audio (JACK) thread */
1019 if (pthread_setschedparam (pthread_self(), SCHED_FIFO, &rtparam) != 0) {
1020 // do we care? not particularly.
1025 Push2::connect_session_signals()
1027 // receive routes added
1028 //session->RouteAdded.connect(session_connections, MISSING_INVALIDATOR, boost::bind (&MackieControlProtocol::notify_routes_added, this, _1), this);
1029 // receive VCAs added
1030 //session->vca_manager().VCAAdded.connect(session_connections, MISSING_INVALIDATOR, boost::bind (&Push2::notify_vca_added, this, _1), this);
1032 // receive record state toggled
1033 session->RecordStateChanged.connect(session_connections, MISSING_INVALIDATOR, boost::bind (&Push2::notify_record_state_changed, this), this);
1034 // receive transport state changed
1035 session->TransportStateChange.connect(session_connections, MISSING_INVALIDATOR, boost::bind (&Push2::notify_transport_state_changed, this), this);
1036 session->TransportLooped.connect (session_connections, MISSING_INVALIDATOR, boost::bind (&Push2::notify_loop_state_changed, this), this);
1037 // receive punch-in and punch-out
1038 Config->ParameterChanged.connect(session_connections, MISSING_INVALIDATOR, boost::bind (&Push2::notify_parameter_changed, this, _1), this);
1039 session->config.ParameterChanged.connect (session_connections, MISSING_INVALIDATOR, boost::bind (&Push2::notify_parameter_changed, this, _1), this);
1040 // receive rude solo changed
1041 session->SoloActive.connect(session_connections, MISSING_INVALIDATOR, boost::bind (&Push2::notify_solo_active_changed, this, _1), this);
1045 Push2::notify_record_state_changed ()
1047 IDButtonMap::iterator b = id_button_map.find (RecordEnable);
1049 if (b == id_button_map.end()) {
1053 switch (session->record_status ()) {
1054 case Session::Disabled:
1055 b->second->set_color (LED::White);
1056 b->second->set_state (LED::NoTransition);
1058 case Session::Enabled:
1059 b->second->set_color (LED::Red);
1060 b->second->set_state (LED::Blinking4th);
1062 case Session::Recording:
1063 b->second->set_color (LED::Red);
1064 b->second->set_state (LED::OneShot24th);
1068 write (b->second->state_msg());
1072 Push2::notify_transport_state_changed ()
1074 Button* b = id_button_map[Play];
1076 if (session->transport_rolling()) {
1077 b->set_state (LED::OneShot24th);
1078 b->set_color (LED::Green);
1081 /* disable any blink on FixedLength from pending edit range op */
1082 Button* fl = id_button_map[FixedLength];
1084 fl->set_color (LED::Black);
1085 fl->set_state (LED::NoTransition);
1086 write (fl->state_msg());
1088 b->set_color (LED::White);
1089 b->set_state (LED::NoTransition);
1092 write (b->state_msg());
1096 Push2::notify_loop_state_changed ()
1101 Push2::notify_parameter_changed (std::string param)
1103 IDButtonMap::iterator b;
1105 if (param == "clicking") {
1106 if ((b = id_button_map.find (Metronome)) == id_button_map.end()) {
1109 if (Config->get_clicking()) {
1110 b->second->set_state (LED::Blinking4th);
1111 b->second->set_color (LED::White);
1113 b->second->set_color (LED::White);
1114 b->second->set_state (LED::NoTransition);
1116 write (b->second->state_msg ());
1121 Push2::notify_solo_active_changed (bool yn)
1123 IDButtonMap::iterator b = id_button_map.find (Solo);
1125 if (b == id_button_map.end()) {
1130 b->second->set_state (LED::Blinking4th);
1131 b->second->set_color (LED::Red);
1133 b->second->set_state (LED::NoTransition);
1134 b->second->set_color (LED::White);
1137 write (b->second->state_msg());
1143 XMLNode& node (ControlProtocol::get_state());
1146 child = new XMLNode (X_("Input"));
1147 child->add_child_nocopy (_async_in->get_state());
1148 node.add_child_nocopy (*child);
1149 child = new XMLNode (X_("Output"));
1150 child->add_child_nocopy (_async_out->get_state());
1151 node.add_child_nocopy (*child);
1153 node.add_property (X_("root"), to_string (_scale_root, std::dec));
1154 node.add_property (X_("root_octave"), to_string (_root_octave, std::dec));
1155 node.add_property (X_("in_key"), _in_key ? X_("yes") : X_("no"));
1156 node.add_property (X_("mode"), enum_2_string (_mode));
1162 Push2::set_state (const XMLNode & node, int version)
1164 DEBUG_TRACE (DEBUG::Push2, string_compose ("Push2::set_state: active %1\n", active()));
1168 if (ControlProtocol::set_state (node, version)) {
1174 if ((child = node.child (X_("Input"))) != 0) {
1175 XMLNode* portnode = child->child (Port::state_node_name.c_str());
1177 _async_in->set_state (*portnode, version);
1181 if ((child = node.child (X_("Output"))) != 0) {
1182 XMLNode* portnode = child->child (Port::state_node_name.c_str());
1184 _async_out->set_state (*portnode, version);
1188 XMLProperty const* prop;
1190 if ((prop = node.property (X_("root"))) != 0) {
1191 _scale_root = atoi (prop->value());
1194 if ((prop = node.property (X_("root_octave"))) != 0) {
1195 _root_octave = atoi (prop->value());
1198 if ((prop = node.property (X_("in_key"))) != 0) {
1199 _in_key = string_is_affirmative (prop->value());
1202 if ((prop = node.property (X_("mode"))) != 0) {
1203 _mode = (MusicalMode::Type) string_2_enum (prop->value(), _mode);
1210 Push2::switch_bank (uint32_t base)
1216 stripable_connections.drop_connections ();
1218 /* try to get the first stripable for the requested bank */
1220 stripable[0] = session->get_remote_nth_stripable (base, PresentationInfo::Flag (PresentationInfo::Route|PresentationInfo::VCA));
1222 if (!stripable[0]) {
1226 /* at least one stripable in this bank */
1229 stripable[1] = session->get_remote_nth_stripable (base+1, PresentationInfo::Flag (PresentationInfo::Route|PresentationInfo::VCA));
1230 stripable[2] = session->get_remote_nth_stripable (base+2, PresentationInfo::Flag (PresentationInfo::Route|PresentationInfo::VCA));
1231 stripable[3] = session->get_remote_nth_stripable (base+3, PresentationInfo::Flag (PresentationInfo::Route|PresentationInfo::VCA));
1232 stripable[4] = session->get_remote_nth_stripable (base+4, PresentationInfo::Flag (PresentationInfo::Route|PresentationInfo::VCA));
1233 stripable[5] = session->get_remote_nth_stripable (base+5, PresentationInfo::Flag (PresentationInfo::Route|PresentationInfo::VCA));
1234 stripable[6] = session->get_remote_nth_stripable (base+6, PresentationInfo::Flag (PresentationInfo::Route|PresentationInfo::VCA));
1235 stripable[7] = session->get_remote_nth_stripable (base+7, PresentationInfo::Flag (PresentationInfo::Route|PresentationInfo::VCA));
1238 for (int n = 0; n < 8; ++n) {
1239 if (!stripable[n]) {
1243 /* stripable goes away? refill the bank, starting at the same point */
1245 stripable[n]->DropReferences.connect (stripable_connections, MISSING_INVALIDATOR, boost::bind (&Push2::switch_bank, this, bank_start), this);
1246 boost::shared_ptr<AutomationControl> sc = stripable[n]->solo_control();
1248 sc->Changed.connect (stripable_connections, MISSING_INVALIDATOR, boost::bind (&Push2::solo_change, this, n), this);
1251 boost::shared_ptr<AutomationControl> mc = stripable[n]->mute_control();
1253 mc->Changed.connect (stripable_connections, MISSING_INVALIDATOR, boost::bind (&Push2::mute_change, this, n), this);
1256 stripable[n]->presentation_info().PropertyChanged.connect (stripable_connections, MISSING_INVALIDATOR, boost::bind (&Push2::stripable_property_change, this, _1, n), this);
1263 /* master cannot be removed, so no need to connect to going-away signal */
1264 master = session->master_out ();
1268 Push2::stripable_property_change (PropertyChange const& what_changed, int which)
1270 if (what_changed.contains (Properties::selected)) {
1271 if (!stripable[which]) {
1275 /* cancel string, which will cause a redraw on the next update
1276 * cycle. The redraw will reflect selected status
1279 mid_layout[which]->set_text (string());
1284 Push2::stripable_selection_change (StripableNotificationListPtr selected)
1287 boost::shared_ptr<MidiPort> pad_port = boost::dynamic_pointer_cast<AsyncMIDIPort>(_async_in)->shadow_port();
1288 boost::shared_ptr<MidiTrack> current_midi_track = current_pad_target.lock();
1289 boost::shared_ptr<MidiTrack> new_pad_target;
1291 /* See if there's a MIDI track selected */
1293 for (StripableNotificationList::iterator si = selected->begin(); si != selected->end(); ++si) {
1295 new_pad_target = boost::dynamic_pointer_cast<MidiTrack> ((*si).lock());
1297 if (new_pad_target) {
1302 if (new_pad_target) {
1303 cerr << "new midi pad target " << new_pad_target->name() << endl;
1305 cerr << "no midi pad target\n";
1308 if (current_midi_track == new_pad_target) {
1313 if (!new_pad_target) {
1314 /* leave existing connection alone */
1318 /* disconnect from pad port, if appropriate */
1320 if (current_midi_track && pad_port) {
1321 cerr << "Disconnect pads from " << current_midi_track->name() << endl;
1322 current_midi_track->input()->disconnect (current_midi_track->input()->nth(0), pad_port->name(), this);
1325 /* now connect the pad port to this (newly) selected midi
1326 * track, if indeed there is one.
1329 if (new_pad_target && pad_port) {
1330 cerr << "Reconnect pads to " << new_pad_target->name() << endl;
1331 new_pad_target->input()->connect (new_pad_target->input()->nth (0), pad_port->name(), this);
1332 current_pad_target = new_pad_target;
1334 current_pad_target.reset ();
1340 Push2::solo_change (int n)
1373 boost::shared_ptr<SoloControl> ac = stripable[n]->solo_control ();
1378 Button* b = id_button_map[bid];
1381 b->set_color (LED::Green);
1383 b->set_color (LED::Black);
1386 if (ac->soloed_by_others_upstream() || ac->soloed_by_others_downstream()) {
1387 b->set_state (LED::Blinking4th);
1389 b->set_state (LED::OneShot24th);
1392 write (b->state_msg());
1396 Push2::mute_change (int n)
1400 if (!stripable[n]) {
1404 cerr << "Mute changed on " << n << ' ' << stripable[n]->name() << endl;
1435 boost::shared_ptr<MuteControl> mc = stripable[n]->mute_control ();
1441 Button* b = id_button_map[bid];
1443 if (Config->get_show_solo_mutes() && !Config->get_solo_control_is_listen_control ()) {
1445 if (mc->muted_by_self ()) {
1447 b->set_color (LED::Blue);
1448 b->set_state (LED::OneShot24th);
1449 cerr << "FULL MUTE1\n";
1450 } else if (mc->muted_by_others_soloing () || mc->muted_by_masters ()) {
1451 /* this will reflect both solo mutes AND master mutes */
1452 b->set_color (LED::Blue);
1453 b->set_state (LED::Blinking4th);
1454 cerr << "OTHER MUTE1\n";
1456 /* no mute at all */
1457 b->set_color (LED::Black);
1458 b->set_state (LED::OneShot24th);
1459 cerr << "NO MUTE1\n";
1464 if (mc->muted_by_self()) {
1466 b->set_color (LED::Blue);
1467 b->set_state (LED::OneShot24th);
1468 cerr << "FULL MUTE2\n";
1469 } else if (mc->muted_by_masters ()) {
1470 /* this shows only master mutes, not mute-by-others-soloing */
1471 b->set_color (LED::Blue);
1472 b->set_state (LED::Blinking4th);
1473 cerr << "OTHER MUTE1\n";
1475 /* no mute at all */
1476 b->set_color (LED::Black);
1477 b->set_state (LED::OneShot24th);
1478 cerr << "NO MUTE2\n";
1482 write (b->state_msg());
1486 Push2::strip_vpot (int n, int delta)
1489 boost::shared_ptr<AutomationControl> ac = stripable[n]->gain_control();
1491 ac->set_value (ac->get_value() + ((2.0/64.0) * delta), PBD::Controllable::UseGroup);
1497 Push2::strip_vpot_touch (int n, bool touching)
1500 boost::shared_ptr<AutomationControl> ac = stripable[n]->gain_control();
1503 ac->start_touch (session->audible_frame());
1505 ac->stop_touch (true, session->audible_frame());
1512 Push2::other_vpot (int n, int delta)
1520 /* master gain control */
1522 boost::shared_ptr<AutomationControl> ac = master->gain_control();
1524 ac->set_value (ac->get_value() + ((2.0/64.0) * delta), PBD::Controllable::UseGroup);
1532 Push2::other_vpot_touch (int n, bool touching)
1541 boost::shared_ptr<AutomationControl> ac = master->gain_control();
1544 ac->start_touch (session->audible_frame());
1546 ac->stop_touch (true, session->audible_frame());
1554 Push2::start_shift ()
1556 cerr << "start shift\n";
1557 modifier_state = ModifierState (modifier_state | ModShift);
1558 Button* b = id_button_map[Shift];
1559 b->set_color (LED::White);
1560 b->set_state (LED::Blinking16th);
1561 write (b->state_msg());
1567 if (modifier_state & ModShift) {
1568 cerr << "end shift\n";
1569 modifier_state = ModifierState (modifier_state & ~(ModShift));
1570 Button* b = id_button_map[Shift];
1571 b->timeout_connection.disconnect ();
1572 b->set_color (LED::White);
1573 b->set_state (LED::OneShot24th);
1574 write (b->state_msg());
1579 Push2::start_select ()
1581 cerr << "start select\n";
1582 modifier_state = ModifierState (modifier_state | ModSelect);
1583 Button* b = id_button_map[Select];
1584 b->set_color (LED::White);
1585 b->set_state (LED::Blinking16th);
1586 write (b->state_msg());
1590 Push2::end_select ()
1592 if (modifier_state & ModSelect) {
1593 cerr << "end select\n";
1594 modifier_state = ModifierState (modifier_state & ~(ModSelect));
1595 Button* b = id_button_map[Select];
1596 b->timeout_connection.disconnect ();
1597 b->set_color (LED::White);
1598 b->set_state (LED::OneShot24th);
1599 write (b->state_msg());
1606 std::string splash_file;
1608 Searchpath rc (ARDOUR::ardour_data_search_path());
1609 rc.add_subdirectory_to_paths ("resources");
1611 if (!find_file (rc, PROGRAM_NAME "-splash.png", splash_file)) {
1612 cerr << "Cannot find splash screen image file\n";
1613 throw failed_constructor();
1616 Cairo::RefPtr<Cairo::ImageSurface> img = Cairo::ImageSurface::create_from_png (splash_file);
1618 double x_ratio = (double) img->get_width() / (cols - 20);
1619 double y_ratio = (double) img->get_height() / (rows - 20);
1620 double scale = min (x_ratio, y_ratio);
1624 context->set_source_rgb (0.764, 0.882, 0.882);
1630 context->translate (5, 5);
1631 context->scale (scale, scale);
1632 context->set_source (img, 0, 0);
1634 context->restore ();
1638 Glib::RefPtr<Pango::Layout> some_text = Pango::Layout::create (context);
1640 Pango::FontDescription fd ("Sans 38");
1641 some_text->set_font_description (fd);
1642 some_text->set_text (string_compose ("%1 %2", PROGRAM_NAME, VERSIONSTRING));
1644 context->move_to (200, 10);
1645 context->set_source_rgb (0, 0, 0);
1646 some_text->update_from_cairo_context (context);
1647 some_text->show_in_cairo_context (context);
1649 Pango::FontDescription fd2 ("Sans Italic 18");
1650 some_text->set_font_description (fd2);
1651 some_text->set_text (_("Ableton Push 2 Support"));
1653 context->move_to (200, 80);
1654 context->set_source_rgb (0, 0, 0);
1655 some_text->update_from_cairo_context (context);
1656 some_text->show_in_cairo_context (context);
1658 splash_start = get_microseconds ();
1659 blit_to_device_frame_buffer ();
1663 Push2::pad_filter (MidiBuffer& in, MidiBuffer& out) const
1665 /* This filter is called asynchronously from a realtime process
1666 context. It must use atomics to check state, and must not block.
1669 bool matched = false;
1671 for (MidiBuffer::iterator ev = in.begin(); ev != in.end(); ++ev) {
1672 if ((*ev).is_note_on() || (*ev).is_note_off()) {
1674 /* encoder touch start/touch end use note
1675 * 0-10. touchstrip uses note 12
1678 if ((*ev).note() > 10 && (*ev).note() != 12) {
1680 const int n = (*ev).note ();
1681 NNPadMap::const_iterator nni = nn_pad_map.find (n);
1683 if (nni != nn_pad_map.end()) {
1684 Pad const * pad = nni->second;
1685 /* shift for output to the shadow port */
1686 if (pad->filtered >= 0) {
1687 (*ev).set_note (pad->filtered);
1688 out.push_back (*ev);
1689 /* shift back so that the pads light correctly */
1692 /* no mapping, don't send event */
1695 out.push_back (*ev);
1707 Push2::connection_handler (boost::weak_ptr<ARDOUR::Port>, std::string name1, boost::weak_ptr<ARDOUR::Port>, std::string name2, bool yn)
1709 DEBUG_TRACE (DEBUG::FaderPort, "FaderPort::connection_handler start\n");
1710 if (!_input_port || !_output_port) {
1714 string ni = ARDOUR::AudioEngine::instance()->make_port_name_non_relative (boost::shared_ptr<ARDOUR::Port>(_async_in)->name());
1715 string no = ARDOUR::AudioEngine::instance()->make_port_name_non_relative (boost::shared_ptr<ARDOUR::Port>(_async_out)->name());
1717 if (ni == name1 || ni == name2) {
1719 connection_state |= InputConnected;
1721 connection_state &= ~InputConnected;
1723 } else if (no == name1 || no == name2) {
1725 connection_state |= OutputConnected;
1727 connection_state &= ~OutputConnected;
1730 DEBUG_TRACE (DEBUG::FaderPort, string_compose ("Connections between %1 and %2 changed, but I ignored it\n", name1, name2));
1735 if ((connection_state & (InputConnected|OutputConnected)) == (InputConnected|OutputConnected)) {
1737 /* XXX this is a horrible hack. Without a short sleep here,
1738 something prevents the device wakeup messages from being
1739 sent and/or the responses from being received.
1743 DEBUG_TRACE (DEBUG::FaderPort, "device now connected for both input and output\n");
1747 DEBUG_TRACE (DEBUG::FaderPort, "Device disconnected (input or output or both) or not yet fully connected\n");
1750 ConnectionChange (); /* emit signal for our GUI */
1752 DEBUG_TRACE (DEBUG::FaderPort, "FaderPort::connection_handler end\n");
1754 return true; /* connection status changed */
1757 boost::shared_ptr<Port>
1758 Push2::output_port()
1763 boost::shared_ptr<Port>
1770 Push2::build_pad_table ()
1772 for (int n = 36; n < 100; ++n) {
1773 pad_map[n] = n + (octave_shift*12);
1776 PadChange (); /* emit signal */
1780 Push2::pad_note (int row, int col) const
1782 NNPadMap::const_iterator nni = nn_pad_map.find (36+(row*8)+col);
1784 if (nni != nn_pad_map.end()) {
1785 return nni->second->filtered;
1792 Push2::set_pad_scale (int root, int octave, MusicalMode::Type mode, bool inkey)
1794 MusicalMode m (mode);
1795 vector<float>::iterator interval;
1797 const int original_root = root;
1799 interval = m.steps.begin();
1800 root += (octave*12);
1803 const int root_start = root;
1805 set<int> mode_map; /* contains only notes in mode, O(logN) lookup */
1806 vector<int> mode_vector; /* sorted in note order */
1808 mode_map.insert (note);
1809 mode_vector.push_back (note);
1811 /* build a map of all notes in the mode, from the root to 127 */
1813 while (note < 128) {
1815 if (interval == m.steps.end()) {
1817 /* last distance was the end of the scale,
1818 so wrap, adding the next note at one
1819 octave above the last root.
1822 interval = m.steps.begin();
1824 mode_map.insert (root);
1825 mode_vector.push_back (root);
1828 note = (int) floor (root + (2.0 * (*interval)));
1830 mode_map.insert (note);
1831 mode_vector.push_back (note);
1837 vector<int>::iterator notei;
1839 for (int row = 0; row < 8; ++row) {
1841 /* Ableton's grid layout wraps the available notes in the scale
1842 * by offsetting 3 notes per row (from the bottom)
1845 notei = mode_vector.begin();
1846 notei += row_offset;
1849 for (int col = 0; col < 8; ++col) {
1850 int index = 36 + (row*8) + col;
1851 Pad* pad = nn_pad_map[index];
1853 if (notei != mode_vector.end()) {
1856 pad->filtered = notenum;
1858 if ((notenum % 12) == original_root) {
1859 pad->set_color (LED::Green);
1860 pad->perma_color = LED::Green;
1862 pad->set_color (LED::White);
1863 pad->perma_color = LED::White;
1866 pad->do_when_pressed = Pad::FlashOff;
1871 pad->set_color (LED::Black);
1872 pad->do_when_pressed = Pad::Nothing;
1876 write (pad->state_msg());
1882 /* chromatic: all notes available, but highlight those in the scale */
1884 for (note = 36; note < 100; ++note) {
1886 Pad* pad = nn_pad_map[note];
1888 /* Chromatic: all pads play, half-tone steps. Light
1889 * those in the scale, and highlight root notes
1892 pad->filtered = root_start + (note - 36);
1894 if (mode_map.find (note) != mode_map.end()) {
1896 if ((note % 12) == original_root) {
1897 pad->set_color (LED::Green);
1898 pad->perma_color = LED::Green;
1900 pad->set_color (LED::White);
1901 pad->perma_color = LED::White;
1904 pad->do_when_pressed = Pad::FlashOff;
1908 /* note is not in mode, turn it off */
1910 pad->do_when_pressed = Pad::FlashOn;
1911 pad->set_color (LED::Black);
1915 write (pad->state_msg());
1919 PadChange (); /* EMIT SIGNAL */
1923 _scale_root = original_root;
1924 _root_octave = octave;