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"
28 #include "midi++/parser.h"
29 #include "timecode/time.h"
30 #include "timecode/bbt_time.h"
32 #include "ardour/async_midi_port.h"
33 #include "ardour/audioengine.h"
34 #include "ardour/debug.h"
35 #include "ardour/midiport_manager.h"
36 #include "ardour/session.h"
37 #include "ardour/tempo.h"
41 using namespace ARDOUR;
45 using namespace ArdourSurface;
49 #include "pbd/abstract_ui.cc" // instantiate template
51 const int Push2::cols = 960;
52 const int Push2::rows = 160;
53 const int Push2::pixels_per_row = 1024;
55 #define ABLETON 0x2982
58 Push2::Push2 (ARDOUR::Session& s)
59 : ControlProtocol (s, string (X_("Ableton Push 2")))
60 , AbstractUI<Push2Request> (name())
63 , frame_buffer (Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, cols, rows))
64 , modifier_state (None)
67 context = Cairo::Context::create (frame_buffer);
68 tc_clock_layout = Pango::Layout::create (context);
69 bbt_clock_layout = Pango::Layout::create (context);
71 Pango::FontDescription fd ("Sans Bold 24");
72 tc_clock_layout->set_font_description (fd);
73 bbt_clock_layout->set_font_description (fd);
75 Pango::FontDescription fd2 ("Sans 10");
76 for (int n = 0; n < 8; ++n) {
77 upper_layout[n] = Pango::Layout::create (context);
78 upper_layout[n]->set_font_description (fd2);
79 upper_layout[n]->set_text ("solo");
80 lower_layout[n] = Pango::Layout::create (context);
81 lower_layout[n]->set_font_description (fd2);
82 lower_layout[n]->set_text ("mute");
85 Pango::FontDescription fd3 ("Sans Bold 10");
86 for (int n = 0; n < 8; ++n) {
87 mid_layout[n] = Pango::Layout::create (context);
88 mid_layout[n]->set_font_description (fd3);
94 throw failed_constructor ();
114 if ((handle = libusb_open_device_with_vid_pid (NULL, ABLETON, PUSH2)) == 0) {
118 if ((err = libusb_claim_interface (handle, 0x00))) {
122 device_frame_buffer = new uint16_t[rows*pixels_per_row];
124 memset (device_frame_buffer, 0, sizeof (uint16_t) * rows * pixels_per_row);
126 frame_header[0] = 0xef;
127 frame_header[1] = 0xcd;
128 frame_header[2] = 0xab;
129 frame_header[3] = 0x89;
130 memset (&frame_header[4], 0, 12);
134 _async_in = AudioEngine::instance()->register_input_port (DataType::MIDI, X_("push2 in"), true);
135 _async_out = AudioEngine::instance()->register_output_port (DataType::MIDI, X_("push2 out"), true);
137 if (_async_in == 0 || _async_out == 0) {
141 _input_port = boost::dynamic_pointer_cast<AsyncMIDIPort>(_async_in).get();
142 _output_port = boost::dynamic_pointer_cast<AsyncMIDIPort>(_async_out).get();
144 connect_to_parser ();
152 AudioEngine::instance()->unregister_port (_async_in);
153 AudioEngine::instance()->unregister_port (_async_out);
155 _async_in.reset ((ARDOUR::Port*) 0);
156 _async_out.reset ((ARDOUR::Port*) 0);
160 vblank_connection.disconnect ();
161 periodic_connection.disconnect ();
162 session_connections.drop_connections ();
163 stripable_connections.drop_connections ();
166 libusb_release_interface (handle, 0x00);
167 libusb_close (handle);
171 for (int n = 0; n < 8; ++n) {
172 stripable[n].reset ();
175 delete [] device_frame_buffer;
176 device_frame_buffer = 0;
182 Push2::init_buttons ()
184 ButtonID buttons[] = { Mute, Solo, Master, Up, Right, Left, Down, Note, Session, Mix, AddTrack, Delete, Undo,
185 Metronome, Shift, Select, Play, RecordEnable, Automate, Repeat, Note, Session, DoubleLoop,
189 for (size_t n = 0; n < sizeof (buttons) / sizeof (buttons[0]); ++n) {
190 Button* b = id_button_map[buttons[n]];
192 b->set_color (LED::White);
193 b->set_state (LED::OneShot24th);
194 write (b->state_msg());
201 libusb_device_handle *h;
204 if ((h = libusb_open_device_with_vid_pid (NULL, ABLETON, PUSH2)) == 0) {
205 DEBUG_TRACE (DEBUG::Push2, "no Push2 device found\n");
210 DEBUG_TRACE (DEBUG::Push2, "Push2 device located\n");
215 Push2::request_factory (uint32_t num_requests)
217 /* AbstractUI<T>::request_buffer_factory() is a template method only
218 instantiated in this source module. To provide something visible for
219 use in the interface/descriptor, we have this static method that is
222 return request_buffer_factory (num_requests);
226 Push2::do_request (Push2Request * req)
228 DEBUG_TRACE (DEBUG::Push2, string_compose ("doing request type %1\n", req->type));
229 if (req->type == CallSlot) {
231 call_slot (MISSING_INVALIDATOR, req->the_slot);
233 } else if (req->type == Quit) {
247 /** render host-side frame buffer (a Cairo ImageSurface) to the current
248 * device-side frame buffer. The device frame buffer will be pushed to the
249 * device on the next call to vblank()
253 Push2::bitblt_to_device_frame_buffer ()
255 /* ensure that all drawing has been done before we fetch pixel data */
257 frame_buffer->flush ();
259 const int stride = 3840; /* bytes per row for Cairo::FORMAT_ARGB32 */
260 const uint8_t* data = frame_buffer->get_data ();
262 /* fill frame buffer (320kB) */
264 uint16_t* fb = (uint16_t*) device_frame_buffer;
266 for (int row = 0; row < rows; ++row) {
268 const uint8_t* dp = data + row * stride;
270 for (int col = 0; col < cols; ++col) {
272 /* fetch r, g, b (range 0..255). Ignore alpha */
274 const int r = (*((const uint32_t*)dp) >> 16) & 0xff;
275 const int g = (*((const uint32_t*)dp) >> 8) & 0xff;
276 const int b = *((const uint32_t*)dp) & 0xff;
278 /* convert to 5 bits, 6 bits, 5 bits, respectively */
279 /* generate 16 bit BGB565 value */
281 *fb++ = (r >> 3) | ((g & 0xfc) << 3) | ((b & 0xf8) << 8);
286 /* skip 128 bytes to next line. This is filler, used to avoid line borders occuring in the middle of 512
290 fb += 64; /* 128 bytes = 64 int16_t */
299 string tc_clock_text;
300 string bbt_clock_text;
303 framepos_t audible = session->audible_frame();
305 bool negative = false;
312 session->timecode_time (audible, TC);
314 TC.negative = TC.negative || negative;
316 tc_clock_text = Timecode::timecode_format_time(TC);
318 Timecode::BBT_Time bbt = session->tempo_map().bbt_at_frame (audible);
321 #define BBT_BAR_CHAR "|"
324 snprintf (buf, sizeof (buf), "-%03" PRIu32 BBT_BAR_CHAR "%02" PRIu32 BBT_BAR_CHAR "%04" PRIu32,
325 bbt.bars, bbt.beats, bbt.ticks);
327 snprintf (buf, sizeof (buf), " %03" PRIu32 BBT_BAR_CHAR "%02" PRIu32 BBT_BAR_CHAR "%04" PRIu32,
328 bbt.bars, bbt.beats, bbt.ticks);
331 bbt_clock_text = buf;
336 if (tc_clock_text != tc_clock_layout->get_text()) {
338 tc_clock_layout->set_text (tc_clock_text);
341 if (bbt_clock_text != tc_clock_layout->get_text()) {
343 bbt_clock_layout->set_text (bbt_clock_text);
348 for (int n = 0; n < 8; ++n) {
350 mid_text = short_version (stripable[n]->name(), 10);
351 if (mid_text != mid_layout[n]->get_text()) {
352 mid_layout[n]->set_text (mid_text);
362 context->set_source_rgb (0.764, 0.882, 0.882);
363 context->rectangle (0, 0, 960, 160);
365 context->set_source_rgb (0.23, 0.0, 0.349);
366 context->move_to (650, 25);
367 tc_clock_layout->update_from_cairo_context (context);
368 tc_clock_layout->show_in_cairo_context (context);
369 context->move_to (650, 60);
370 bbt_clock_layout->update_from_cairo_context (context);
371 bbt_clock_layout->show_in_cairo_context (context);
373 for (int n = 0; n < 8; ++n) {
374 context->move_to (10 + (n*120), 2);
375 upper_layout[n]->update_from_cairo_context (context);
376 upper_layout[n]->show_in_cairo_context (context);
379 for (int n = 0; n < 8; ++n) {
380 context->move_to (10 + (n*120), 140);
381 lower_layout[n]->update_from_cairo_context (context);
382 lower_layout[n]->show_in_cairo_context (context);
385 for (int n = 0; n < 8; ++n) {
386 context->move_to (10 + (n*120), 120);
387 context->set_source_rgb (0.0, 0.0, 0.0);
388 mid_layout[n]->update_from_cairo_context (context);
389 mid_layout[n]->show_in_cairo_context (context);
403 const int timeout_msecs = 1000;
406 if ((err = libusb_bulk_transfer (handle, 0x01, frame_header, sizeof (frame_header), &transferred, timeout_msecs))) {
412 bitblt_to_device_frame_buffer ();
415 if ((err = libusb_bulk_transfer (handle, 0x01, (uint8_t*) device_frame_buffer , 2 * rows * pixels_per_row, &transferred, timeout_msecs))) {
423 Push2::set_active (bool yn)
425 DEBUG_TRACE (DEBUG::Push2, string_compose("Push2Protocol::set_active init with yn: '%1'\n", yn));
427 if (yn == active()) {
433 /* start event loop */
438 DEBUG_TRACE (DEBUG::Push2, "device open failed\n");
443 /* Connect input port to event loop */
447 asp = dynamic_cast<AsyncMIDIPort*> (_input_port);
448 asp->xthread().set_receive_handler (sigc::bind (sigc::mem_fun (this, &Push2::midi_input_handler), _input_port));
449 asp->xthread().attach (main_loop()->get_context());
451 connect_session_signals ();
453 /* set up periodic task used to push a frame buffer to the
454 * device (25fps). The device can handle 60fps, but we don't
455 * need that frame rate.
458 Glib::RefPtr<Glib::TimeoutSource> vblank_timeout = Glib::TimeoutSource::create (40); // milliseconds
459 vblank_connection = vblank_timeout->connect (sigc::mem_fun (*this, &Push2::vblank));
460 vblank_timeout->attach (main_loop()->get_context());
463 Glib::RefPtr<Glib::TimeoutSource> periodic_timeout = Glib::TimeoutSource::create (1000); // milliseconds
464 periodic_connection = periodic_timeout->connect (sigc::mem_fun (*this, &Push2::periodic));
465 periodic_timeout->attach (main_loop()->get_context());
477 ControlProtocol::set_active (yn);
479 DEBUG_TRACE (DEBUG::Push2, string_compose("Push2Protocol::set_active done with yn: '%1'\n", yn));
485 Push2::init_touch_strip ()
487 MidiByteArray msg (9, 0xf0, 0x00, 0x21, 0x1d, 0x01, 0x01, 0x17, 0x00, 0xf7);
488 /* flags are the final byte (ignore end-of-sysex */
490 /* show bar, not point
494 msg[7] = (1<<4) | (1<<5) | (1<<6);
499 Push2::write (const MidiByteArray& data)
501 cerr << data << endl;
502 /* immediate delivery */
503 _output_port->write (&data[0], data.size(), 0);
507 Push2::midi_input_handler (IOCondition ioc, MIDI::Port* port)
510 DEBUG_TRACE (DEBUG::Push2, "MIDI port closed\n");
516 // DEBUG_TRACE (DEBUG::Push2, string_compose ("something happend on %1\n", port->name()));
518 AsyncMIDIPort* asp = dynamic_cast<AsyncMIDIPort*>(port);
523 //DEBUG_TRACE (DEBUG::Push2, string_compose ("data available on %1\n", port->name()));
524 framepos_t now = AudioEngine::instance()->sample_time();
538 Push2::connect_to_parser ()
540 DEBUG_TRACE (DEBUG::Push2, string_compose ("Connecting to signals on port %2\n", _input_port->name()));
542 MIDI::Parser* p = _input_port->parser();
545 p->sysex.connect_same_thread (*this, boost::bind (&Push2::handle_midi_sysex, this, _1, _2, _3));
546 /* V-Pot messages are Controller */
547 p->controller.connect_same_thread (*this, boost::bind (&Push2::handle_midi_controller_message, this, _1, _2));
548 /* Button messages are NoteOn */
549 p->note_on.connect_same_thread (*this, boost::bind (&Push2::handle_midi_note_on_message, this, _1, _2));
550 /* Button messages are NoteOn but libmidi++ sends note-on w/velocity = 0 as note-off so catch them too */
551 p->note_off.connect_same_thread (*this, boost::bind (&Push2::handle_midi_note_on_message, this, _1, _2));
552 /* Fader messages are Pitchbend */
553 p->channel_pitchbend[0].connect_same_thread (*this, boost::bind (&Push2::handle_midi_pitchbend_message, this, _1, _2));
557 Push2::handle_midi_sysex (MIDI::Parser&, MIDI::byte* raw_bytes, size_t sz)
559 cerr << "sysex, " << sz << " bytes\n";
563 Push2::handle_midi_controller_message (MIDI::Parser&, MIDI::EventTwoBytes* ev)
565 CCButtonMap::iterator b = cc_button_map.find (ev->controller_number);
567 if (b != cc_button_map.end()) {
568 if (ev->value == 0) {
569 (this->*b->second->release_method)();
571 (this->*b->second->press_method)();
577 int delta = ev->value;
580 delta = -(128 - delta);
583 switch (ev->controller_number) {
585 strip_vpot (0, delta);
588 strip_vpot (1, delta);
591 strip_vpot (2, delta);
594 strip_vpot (3, delta);
597 strip_vpot (4, delta);
600 strip_vpot (5, delta);
603 strip_vpot (6, delta);
606 strip_vpot (7, delta);
611 strip_vpot (8, delta);
614 other_vpot (1, delta);
619 other_vpot (2, delta);
626 Push2::handle_midi_note_on_message (MIDI::Parser&, MIDI::EventTwoBytes* ev)
628 switch (ev->note_number) {
630 strip_vpot_touch (0, ev->velocity > 64);
633 strip_vpot_touch (1, ev->velocity > 64);
636 strip_vpot_touch (2, ev->velocity > 64);
639 strip_vpot_touch (3, ev->velocity > 64);
642 strip_vpot_touch (4, ev->velocity > 64);
645 strip_vpot_touch (5, ev->velocity > 64);
648 strip_vpot_touch (6, ev->velocity > 64);
651 strip_vpot_touch (7, ev->velocity > 64);
656 other_vpot_touch (0, ev->velocity > 64);
659 other_vpot_touch (1, ev->velocity > 64);
664 other_vpot_touch (3, ev->velocity > 64);
669 if (ev->velocity < 64) {
678 Push2::handle_midi_note_off_message (MIDI::Parser&, MIDI::EventTwoBytes* ev)
683 Push2::handle_midi_pitchbend_message (MIDI::Parser&, MIDI::pitchbend_t pb)
690 /* range of +1 .. -1 */
691 speed = ((int32_t) pb - 8192) / 8192.0;
692 /* convert to range of +3 .. -3 */
693 session->request_transport_speed (speed * 3.0);
703 #define MAKE_PAD(x,y,nn) \
704 pad = new Pad ((x), (y), (nn)); \
705 nn_pad_map.insert (make_pair (pad->extra(), pad)); \
706 coord_pad_map.insert (make_pair (pad->coord(), pad));
772 /* Now color buttons */
776 #define MAKE_COLOR_BUTTON(i,cc) \
777 button = new ColorButton ((i), (cc)); \
778 cc_button_map.insert (make_pair (button->controller_number(), button)); \
779 id_button_map.insert (make_pair (button->id, button));
780 #define MAKE_COLOR_BUTTON_PRESS(i,cc,p)\
781 button = new ColorButton ((i), (cc), (p)); \
782 cc_button_map.insert (make_pair (button->controller_number(), button)); \
783 id_button_map.insert (make_pair (button->id, button))
785 MAKE_COLOR_BUTTON_PRESS (Upper1, 102, &Push2::button_upper_1);
786 MAKE_COLOR_BUTTON_PRESS (Upper2, 103, &Push2::button_upper_2);
787 MAKE_COLOR_BUTTON_PRESS (Upper3, 104, &Push2::button_upper_3);
788 MAKE_COLOR_BUTTON_PRESS (Upper4, 105, &Push2::button_upper_4);
789 MAKE_COLOR_BUTTON_PRESS (Upper5, 106, &Push2::button_upper_5);
790 MAKE_COLOR_BUTTON_PRESS (Upper6, 107, &Push2::button_upper_6);
791 MAKE_COLOR_BUTTON_PRESS (Upper7, 108, &Push2::button_upper_7);
792 MAKE_COLOR_BUTTON_PRESS (Upper8, 109, &Push2::button_upper_8);
793 MAKE_COLOR_BUTTON_PRESS (Lower1, 20, &Push2::button_lower_1);
794 MAKE_COLOR_BUTTON_PRESS (Lower2, 21, &Push2::button_lower_2);
795 MAKE_COLOR_BUTTON_PRESS (Lower3, 22, &Push2::button_lower_3);
796 MAKE_COLOR_BUTTON_PRESS (Lower4, 23, &Push2::button_lower_4);
797 MAKE_COLOR_BUTTON_PRESS (Lower5, 24, &Push2::button_lower_5);
798 MAKE_COLOR_BUTTON_PRESS (Lower6, 25, &Push2::button_lower_6);
799 MAKE_COLOR_BUTTON_PRESS (Lower7, 26, &Push2::button_lower_7);
800 MAKE_COLOR_BUTTON_PRESS (Lower8, 27, &Push2::button_lower_8);
801 MAKE_COLOR_BUTTON (Master, 28);
802 MAKE_COLOR_BUTTON (Mute, 60);
803 MAKE_COLOR_BUTTON_PRESS (Solo, 61, &Push2::button_solo);
804 MAKE_COLOR_BUTTON (Stop, 29);
805 MAKE_COLOR_BUTTON_PRESS (Fwd32ndT, 43, &Push2::button_fwd32t);
806 MAKE_COLOR_BUTTON_PRESS (Fwd32nd,42 , &Push2::button_fwd32);
807 MAKE_COLOR_BUTTON_PRESS (Fwd16thT, 41, &Push2::button_fwd16t);
808 MAKE_COLOR_BUTTON_PRESS (Fwd16th, 40, &Push2::button_fwd16);
809 MAKE_COLOR_BUTTON_PRESS (Fwd8thT, 39 , &Push2::button_fwd8t);
810 MAKE_COLOR_BUTTON_PRESS (Fwd8th, 38, &Push2::button_fwd8);
811 MAKE_COLOR_BUTTON_PRESS (Fwd4trT, 37, &Push2::button_fwd4t);
812 MAKE_COLOR_BUTTON_PRESS (Fwd4tr, 36, &Push2::button_fwd4);
813 MAKE_COLOR_BUTTON (Automate, 89);
814 MAKE_COLOR_BUTTON_PRESS (RecordEnable, 86, &Push2::button_recenable);
815 MAKE_COLOR_BUTTON_PRESS (Play, 85, &Push2::button_play);
817 #define MAKE_WHITE_BUTTON(i,cc)\
818 button = new WhiteButton ((i), (cc)); \
819 cc_button_map.insert (make_pair (button->controller_number(), button)); \
820 id_button_map.insert (make_pair (button->id, button))
821 #define MAKE_WHITE_BUTTON_PRESS(i,cc,p)\
822 button = new WhiteButton ((i), (cc), (p)); \
823 cc_button_map.insert (make_pair (button->controller_number(), button)); \
824 id_button_map.insert (make_pair (button->id, button))
825 #define MAKE_WHITE_BUTTON_PRESS_RELEASE(i,cc,p,r) \
826 button = new WhiteButton ((i), (cc), (p), (r)); \
827 cc_button_map.insert (make_pair (button->controller_number(), button)); \
828 id_button_map.insert (make_pair (button->id, button))
830 MAKE_WHITE_BUTTON (TapTempo, 3);
831 MAKE_WHITE_BUTTON_PRESS (Metronome, 9, &Push2::button_metronome);
832 MAKE_WHITE_BUTTON (Setup, 30);
833 MAKE_WHITE_BUTTON (User, 59);
834 MAKE_WHITE_BUTTON (Delete, 118);
835 MAKE_WHITE_BUTTON (AddDevice, 52);
836 MAKE_WHITE_BUTTON (Device, 110);
837 MAKE_WHITE_BUTTON (Mix, 112);
838 MAKE_WHITE_BUTTON_PRESS (Undo, 119, &Push2::button_undo);
839 MAKE_WHITE_BUTTON (AddTrack, 53);
840 MAKE_WHITE_BUTTON_PRESS (Browse, 111, &Push2::button_browse);
841 MAKE_WHITE_BUTTON_PRESS (Clip, 113, &Push2::button_clip);
842 MAKE_WHITE_BUTTON (Convert, 35);
843 MAKE_WHITE_BUTTON (DoubleLoop, 117);
844 MAKE_WHITE_BUTTON (Quantize, 116);
845 MAKE_WHITE_BUTTON (Duplicate, 88);
846 MAKE_WHITE_BUTTON_PRESS (New, 87, &Push2::button_new);
847 MAKE_WHITE_BUTTON_PRESS (FixedLength, 90, &Push2::button_fixed_length);
848 MAKE_WHITE_BUTTON_PRESS (Up, 46, &Push2::button_up);
849 MAKE_WHITE_BUTTON_PRESS (Right, 45, &Push2::button_right);
850 MAKE_WHITE_BUTTON_PRESS (Down, 47, &Push2::button_down);
851 MAKE_WHITE_BUTTON_PRESS (Left, 44, &Push2::button_left);
852 MAKE_WHITE_BUTTON_PRESS (Repeat, 56, &Push2::button_repeat);
853 MAKE_WHITE_BUTTON (Accent, 57);
854 MAKE_WHITE_BUTTON (Scale, 58);
855 MAKE_WHITE_BUTTON (Layout, 31);
856 MAKE_WHITE_BUTTON (Note, 50);
857 MAKE_WHITE_BUTTON (Session, 51);
858 MAKE_WHITE_BUTTON (Layout, 31);
859 MAKE_WHITE_BUTTON (OctaveUp, 55);
860 MAKE_WHITE_BUTTON (PageRight, 63);
861 MAKE_WHITE_BUTTON (OctaveDown, 54);
862 MAKE_WHITE_BUTTON (PageLeft, 62);
863 MAKE_WHITE_BUTTON_PRESS_RELEASE (Shift, 49, &Push2::button_shift_press, &Push2::button_shift_release);
864 MAKE_WHITE_BUTTON (Select, 48);
868 Push2::thread_init ()
870 struct sched_param rtparam;
872 pthread_set_name (event_loop_name().c_str());
874 PBD::notify_event_loops_about_thread_creation (pthread_self(), event_loop_name(), 2048);
875 ARDOUR::SessionEvent::create_per_thread_pool (event_loop_name(), 128);
877 memset (&rtparam, 0, sizeof (rtparam));
878 rtparam.sched_priority = 9; /* XXX should be relative to audio (JACK) thread */
880 if (pthread_setschedparam (pthread_self(), SCHED_FIFO, &rtparam) != 0) {
881 // do we care? not particularly.
886 Push2::connect_session_signals()
888 // receive routes added
889 //session->RouteAdded.connect(session_connections, MISSING_INVALIDATOR, boost::bind (&MackieControlProtocol::notify_routes_added, this, _1), this);
890 // receive VCAs added
891 //session->vca_manager().VCAAdded.connect(session_connections, MISSING_INVALIDATOR, boost::bind (&Push2::notify_vca_added, this, _1), this);
893 // receive record state toggled
894 session->RecordStateChanged.connect(session_connections, MISSING_INVALIDATOR, boost::bind (&Push2::notify_record_state_changed, this), this);
895 // receive transport state changed
896 session->TransportStateChange.connect(session_connections, MISSING_INVALIDATOR, boost::bind (&Push2::notify_transport_state_changed, this), this);
897 session->TransportLooped.connect (session_connections, MISSING_INVALIDATOR, boost::bind (&Push2::notify_loop_state_changed, this), this);
898 // receive punch-in and punch-out
899 Config->ParameterChanged.connect(session_connections, MISSING_INVALIDATOR, boost::bind (&Push2::notify_parameter_changed, this, _1), this);
900 session->config.ParameterChanged.connect (session_connections, MISSING_INVALIDATOR, boost::bind (&Push2::notify_parameter_changed, this, _1), this);
901 // receive rude solo changed
902 session->SoloActive.connect(session_connections, MISSING_INVALIDATOR, boost::bind (&Push2::notify_solo_active_changed, this, _1), this);
906 Push2::notify_record_state_changed ()
908 IDButtonMap::iterator b = id_button_map.find (RecordEnable);
910 if (b == id_button_map.end()) {
914 switch (session->record_status ()) {
915 case Session::Disabled:
916 b->second->set_color (LED::White);
917 b->second->set_state (LED::NoTransition);
919 case Session::Enabled:
920 b->second->set_color (LED::Red);
921 b->second->set_state (LED::Blinking4th);
923 case Session::Recording:
924 b->second->set_color (LED::Red);
925 b->second->set_state (LED::OneShot24th);
929 write (b->second->state_msg());
933 Push2::notify_transport_state_changed ()
935 Button* b = id_button_map[Play];
937 if (session->transport_rolling()) {
938 b->set_state (LED::OneShot24th);
939 b->set_color (LED::Green);
942 /* disable any blink on FixedLength from pending edit range op */
943 Button* fl = id_button_map[FixedLength];
945 fl->set_color (LED::Black);
946 fl->set_state (LED::NoTransition);
947 write (fl->state_msg());
949 b->set_color (LED::White);
950 b->set_state (LED::NoTransition);
953 write (b->state_msg());
957 Push2::notify_loop_state_changed ()
962 Push2::notify_parameter_changed (std::string param)
964 IDButtonMap::iterator b;
966 if (param == "clicking") {
967 if ((b = id_button_map.find (Metronome)) == id_button_map.end()) {
970 if (Config->get_clicking()) {
971 b->second->set_state (LED::Blinking4th);
972 b->second->set_color (LED::White);
974 b->second->set_color (LED::White);
975 b->second->set_state (LED::NoTransition);
977 write (b->second->state_msg ());
982 Push2::notify_solo_active_changed (bool yn)
984 IDButtonMap::iterator b = id_button_map.find (Solo);
986 if (b == id_button_map.end()) {
991 b->second->set_state (LED::Blinking4th);
992 b->second->set_color (LED::Red);
994 b->second->set_state (LED::NoTransition);
995 b->second->set_color (LED::White);
998 write (b->second->state_msg());
1004 XMLNode& node (ControlProtocol::get_state());
1007 child = new XMLNode (X_("Input"));
1008 child->add_child_nocopy (_async_in->get_state());
1009 node.add_child_nocopy (*child);
1010 child = new XMLNode (X_("Output"));
1011 child->add_child_nocopy (_async_out->get_state());
1012 node.add_child_nocopy (*child);
1018 Push2::set_state (const XMLNode & node, int version)
1020 DEBUG_TRACE (DEBUG::Push2, string_compose ("Push2::set_state: active %1\n", active()));
1024 if (ControlProtocol::set_state (node, version)) {
1030 if ((child = node.child (X_("Input"))) != 0) {
1031 XMLNode* portnode = child->child (Port::state_node_name.c_str());
1033 _async_in->set_state (*portnode, version);
1037 if ((child = node.child (X_("Output"))) != 0) {
1038 XMLNode* portnode = child->child (Port::state_node_name.c_str());
1040 _async_out->set_state (*portnode, version);
1048 Push2::switch_bank (uint32_t base)
1054 stripable_connections.drop_connections ();
1056 /* try to get the first stripable for the requested bank */
1058 stripable[0] = session->get_nth_stripable (base+0);
1060 if (!stripable[0]) {
1064 /* at least one stripable in this bank */
1067 stripable[1] = session->get_nth_stripable (base+1);
1068 stripable[2] = session->get_nth_stripable (base+2);
1069 stripable[3] = session->get_nth_stripable (base+3);
1070 stripable[4] = session->get_nth_stripable (base+4);
1071 stripable[5] = session->get_nth_stripable (base+5);
1072 stripable[6] = session->get_nth_stripable (base+6);
1073 stripable[7] = session->get_nth_stripable (base+7);
1075 for (int n = 0; n < 8; ++n) {
1076 if (!stripable[n]) {
1080 /* stripable goes away? refill the bank, starting at the same point */
1082 stripable[n]->DropReferences.connect (stripable_connections, MISSING_INVALIDATOR, boost::bind (&Push2::switch_bank, this, bank_start), this);
1083 boost::shared_ptr<AutomationControl> sc = stripable[n]->solo_control();
1085 sc->Changed.connect (stripable_connections, MISSING_INVALIDATOR, boost::bind (&Push2::solo_change, this, n), this);
1088 boost::shared_ptr<AutomationControl> mc = stripable[n]->mute_control();
1090 mc->Changed.connect (stripable_connections, MISSING_INVALIDATOR, boost::bind (&Push2::mute_change, this, n), this);
1098 /* master cannot be removed, so no need to connect to going-away signal */
1099 master = session->master_out ();
1103 Push2::solo_change (int n)
1136 boost::shared_ptr<AutomationControl> ac = stripable[n]->solo_control ();
1141 Button* b = id_button_map[bid];
1142 if (ac->get_value()) {
1143 b->set_color (LED::Red);
1145 b->set_color (LED::Black);
1147 b->set_state (LED::OneShot24th);
1148 write (b->state_msg());
1152 Push2::mute_change (int n)
1185 boost::shared_ptr<AutomationControl> ac = stripable[n]->mute_control ();
1190 Button* b = id_button_map[bid];
1192 if (ac->get_value ()) {
1193 b->set_color (LED::Blue);
1195 b->set_color (LED::Black);
1197 b->set_state (LED::OneShot24th);
1198 write (b->state_msg());
1202 Push2::strip_vpot (int n, int delta)
1205 boost::shared_ptr<AutomationControl> ac = stripable[n]->gain_control();
1207 ac->set_value (ac->get_value() + ((2.0/64.0) * delta), PBD::Controllable::UseGroup);
1213 Push2::strip_vpot_touch (int n, bool touching)
1216 boost::shared_ptr<AutomationControl> ac = stripable[n]->gain_control();
1219 ac->start_touch (session->audible_frame());
1221 ac->stop_touch (true, session->audible_frame());
1228 Push2::other_vpot (int n, int delta)
1236 /* master gain control */
1238 boost::shared_ptr<AutomationControl> ac = master->gain_control();
1240 ac->set_value (ac->get_value() + ((2.0/64.0) * delta), PBD::Controllable::UseGroup);
1248 Push2::other_vpot_touch (int n, bool touching)
1257 boost::shared_ptr<AutomationControl> ac = master->gain_control();
1260 ac->start_touch (session->audible_frame());
1262 ac->stop_touch (true, session->audible_frame());