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 init_buttons (false);
154 /* wait for button data to be flushed */
156 asp = dynamic_cast<AsyncMIDIPort*> (_output_port);
157 asp->drain (10000, 500000);
159 AudioEngine::instance()->unregister_port (_async_in);
160 AudioEngine::instance()->unregister_port (_async_out);
162 _async_in.reset ((ARDOUR::Port*) 0);
163 _async_out.reset ((ARDOUR::Port*) 0);
167 vblank_connection.disconnect ();
168 periodic_connection.disconnect ();
169 session_connections.drop_connections ();
170 stripable_connections.drop_connections ();
173 libusb_release_interface (handle, 0x00);
174 libusb_close (handle);
178 for (int n = 0; n < 8; ++n) {
179 stripable[n].reset ();
182 delete [] device_frame_buffer;
183 device_frame_buffer = 0;
189 Push2::init_buttons (bool startup)
191 ButtonID buttons[] = { Mute, Solo, Master, Up, Right, Left, Down, Note, Session, Mix, AddTrack, Delete, Undo,
192 Metronome, Shift, Select, Play, RecordEnable, Automate, Repeat, Note, Session, DoubleLoop,
196 for (size_t n = 0; n < sizeof (buttons) / sizeof (buttons[0]); ++n) {
197 Button* b = id_button_map[buttons[n]];
200 b->set_color (LED::White);
202 b->set_color (LED::Black);
204 b->set_state (LED::OneShot24th);
205 write (b->state_msg());
208 ButtonID strip_buttons[] = { Upper1, Upper2, Upper3, Upper4, Upper5, Upper6, Upper7, Upper8,
209 Lower1, Lower2, Lower3, Lower4, Lower5, Lower6, Lower7, Lower8 };
211 for (size_t n = 0; n < sizeof (strip_buttons) / sizeof (strip_buttons[0]); ++n) {
212 Button* b = id_button_map[strip_buttons[n]];
214 b->set_color (LED::Black);
215 b->set_state (LED::OneShot24th);
216 write (b->state_msg());
223 libusb_device_handle *h;
226 if ((h = libusb_open_device_with_vid_pid (NULL, ABLETON, PUSH2)) == 0) {
227 DEBUG_TRACE (DEBUG::Push2, "no Push2 device found\n");
232 DEBUG_TRACE (DEBUG::Push2, "Push2 device located\n");
237 Push2::request_factory (uint32_t num_requests)
239 /* AbstractUI<T>::request_buffer_factory() is a template method only
240 instantiated in this source module. To provide something visible for
241 use in the interface/descriptor, we have this static method that is
244 return request_buffer_factory (num_requests);
248 Push2::do_request (Push2Request * req)
250 DEBUG_TRACE (DEBUG::Push2, string_compose ("doing request type %1\n", req->type));
251 if (req->type == CallSlot) {
253 call_slot (MISSING_INVALIDATOR, req->the_slot);
255 } else if (req->type == Quit) {
269 /** render host-side frame buffer (a Cairo ImageSurface) to the current
270 * device-side frame buffer. The device frame buffer will be pushed to the
271 * device on the next call to vblank()
275 Push2::bitblt_to_device_frame_buffer ()
277 /* ensure that all drawing has been done before we fetch pixel data */
279 frame_buffer->flush ();
281 const int stride = 3840; /* bytes per row for Cairo::FORMAT_ARGB32 */
282 const uint8_t* data = frame_buffer->get_data ();
284 /* fill frame buffer (320kB) */
286 uint16_t* fb = (uint16_t*) device_frame_buffer;
288 for (int row = 0; row < rows; ++row) {
290 const uint8_t* dp = data + row * stride;
292 for (int col = 0; col < cols; ++col) {
294 /* fetch r, g, b (range 0..255). Ignore alpha */
296 const int r = (*((const uint32_t*)dp) >> 16) & 0xff;
297 const int g = (*((const uint32_t*)dp) >> 8) & 0xff;
298 const int b = *((const uint32_t*)dp) & 0xff;
300 /* convert to 5 bits, 6 bits, 5 bits, respectively */
301 /* generate 16 bit BGB565 value */
303 *fb++ = (r >> 3) | ((g & 0xfc) << 3) | ((b & 0xf8) << 8);
308 /* skip 128 bytes to next line. This is filler, used to avoid line borders occuring in the middle of 512
312 fb += 64; /* 128 bytes = 64 int16_t */
321 string tc_clock_text;
322 string bbt_clock_text;
325 framepos_t audible = session->audible_frame();
327 bool negative = false;
334 session->timecode_time (audible, TC);
336 TC.negative = TC.negative || negative;
338 tc_clock_text = Timecode::timecode_format_time(TC);
340 Timecode::BBT_Time bbt = session->tempo_map().bbt_at_frame (audible);
343 #define BBT_BAR_CHAR "|"
346 snprintf (buf, sizeof (buf), "-%03" PRIu32 BBT_BAR_CHAR "%02" PRIu32 BBT_BAR_CHAR "%04" PRIu32,
347 bbt.bars, bbt.beats, bbt.ticks);
349 snprintf (buf, sizeof (buf), " %03" PRIu32 BBT_BAR_CHAR "%02" PRIu32 BBT_BAR_CHAR "%04" PRIu32,
350 bbt.bars, bbt.beats, bbt.ticks);
353 bbt_clock_text = buf;
358 if (tc_clock_text != tc_clock_layout->get_text()) {
360 tc_clock_layout->set_text (tc_clock_text);
363 if (bbt_clock_text != tc_clock_layout->get_text()) {
365 bbt_clock_layout->set_text (bbt_clock_text);
370 for (int n = 0; n < 8; ++n) {
372 mid_text = short_version (stripable[n]->name(), 10);
373 if (mid_text != mid_layout[n]->get_text()) {
374 mid_layout[n]->set_text (mid_text);
384 context->set_source_rgb (0.764, 0.882, 0.882);
385 context->rectangle (0, 0, 960, 160);
387 context->set_source_rgb (0.23, 0.0, 0.349);
388 context->move_to (650, 25);
389 tc_clock_layout->update_from_cairo_context (context);
390 tc_clock_layout->show_in_cairo_context (context);
391 context->move_to (650, 60);
392 bbt_clock_layout->update_from_cairo_context (context);
393 bbt_clock_layout->show_in_cairo_context (context);
395 for (int n = 0; n < 8; ++n) {
396 context->move_to (10 + (n*120), 2);
397 upper_layout[n]->update_from_cairo_context (context);
398 upper_layout[n]->show_in_cairo_context (context);
401 for (int n = 0; n < 8; ++n) {
402 context->move_to (10 + (n*120), 140);
403 lower_layout[n]->update_from_cairo_context (context);
404 lower_layout[n]->show_in_cairo_context (context);
407 for (int n = 0; n < 8; ++n) {
408 context->move_to (10 + (n*120), 120);
409 context->set_source_rgb (0.0, 0.0, 0.0);
410 mid_layout[n]->update_from_cairo_context (context);
411 mid_layout[n]->show_in_cairo_context (context);
425 const int timeout_msecs = 1000;
428 if ((err = libusb_bulk_transfer (handle, 0x01, frame_header, sizeof (frame_header), &transferred, timeout_msecs))) {
434 bitblt_to_device_frame_buffer ();
437 if ((err = libusb_bulk_transfer (handle, 0x01, (uint8_t*) device_frame_buffer , 2 * rows * pixels_per_row, &transferred, timeout_msecs))) {
445 Push2::set_active (bool yn)
447 DEBUG_TRACE (DEBUG::Push2, string_compose("Push2Protocol::set_active init with yn: '%1'\n", yn));
449 if (yn == active()) {
455 /* start event loop */
460 DEBUG_TRACE (DEBUG::Push2, "device open failed\n");
465 /* Connect input port to event loop */
469 asp = dynamic_cast<AsyncMIDIPort*> (_input_port);
470 asp->xthread().set_receive_handler (sigc::bind (sigc::mem_fun (this, &Push2::midi_input_handler), _input_port));
471 asp->xthread().attach (main_loop()->get_context());
473 connect_session_signals ();
475 /* set up periodic task used to push a frame buffer to the
476 * device (25fps). The device can handle 60fps, but we don't
477 * need that frame rate.
480 Glib::RefPtr<Glib::TimeoutSource> vblank_timeout = Glib::TimeoutSource::create (40); // milliseconds
481 vblank_connection = vblank_timeout->connect (sigc::mem_fun (*this, &Push2::vblank));
482 vblank_timeout->attach (main_loop()->get_context());
485 Glib::RefPtr<Glib::TimeoutSource> periodic_timeout = Glib::TimeoutSource::create (1000); // milliseconds
486 periodic_connection = periodic_timeout->connect (sigc::mem_fun (*this, &Push2::periodic));
487 periodic_timeout->attach (main_loop()->get_context());
499 ControlProtocol::set_active (yn);
501 DEBUG_TRACE (DEBUG::Push2, string_compose("Push2Protocol::set_active done with yn: '%1'\n", yn));
507 Push2::init_touch_strip ()
509 MidiByteArray msg (9, 0xf0, 0x00, 0x21, 0x1d, 0x01, 0x01, 0x17, 0x00, 0xf7);
510 /* flags are the final byte (ignore end-of-sysex */
512 /* show bar, not point
516 msg[7] = (1<<4) | (1<<5) | (1<<6);
521 Push2::write (const MidiByteArray& data)
523 cerr << data << endl;
524 /* immediate delivery */
525 _output_port->write (&data[0], data.size(), 0);
529 Push2::midi_input_handler (IOCondition ioc, MIDI::Port* port)
532 DEBUG_TRACE (DEBUG::Push2, "MIDI port closed\n");
538 // DEBUG_TRACE (DEBUG::Push2, string_compose ("something happend on %1\n", port->name()));
540 AsyncMIDIPort* asp = dynamic_cast<AsyncMIDIPort*>(port);
545 //DEBUG_TRACE (DEBUG::Push2, string_compose ("data available on %1\n", port->name()));
546 framepos_t now = AudioEngine::instance()->sample_time();
560 Push2::connect_to_parser ()
562 DEBUG_TRACE (DEBUG::Push2, string_compose ("Connecting to signals on port %2\n", _input_port->name()));
564 MIDI::Parser* p = _input_port->parser();
567 p->sysex.connect_same_thread (*this, boost::bind (&Push2::handle_midi_sysex, this, _1, _2, _3));
568 /* V-Pot messages are Controller */
569 p->controller.connect_same_thread (*this, boost::bind (&Push2::handle_midi_controller_message, this, _1, _2));
570 /* Button messages are NoteOn */
571 p->note_on.connect_same_thread (*this, boost::bind (&Push2::handle_midi_note_on_message, this, _1, _2));
572 /* Button messages are NoteOn but libmidi++ sends note-on w/velocity = 0 as note-off so catch them too */
573 p->note_off.connect_same_thread (*this, boost::bind (&Push2::handle_midi_note_on_message, this, _1, _2));
574 /* Fader messages are Pitchbend */
575 p->channel_pitchbend[0].connect_same_thread (*this, boost::bind (&Push2::handle_midi_pitchbend_message, this, _1, _2));
579 Push2::handle_midi_sysex (MIDI::Parser&, MIDI::byte* raw_bytes, size_t sz)
581 cerr << "sysex, " << sz << " bytes\n";
585 Push2::handle_midi_controller_message (MIDI::Parser&, MIDI::EventTwoBytes* ev)
587 CCButtonMap::iterator b = cc_button_map.find (ev->controller_number);
589 if (b != cc_button_map.end()) {
590 if (ev->value == 0) {
591 (this->*b->second->release_method)();
593 (this->*b->second->press_method)();
599 int delta = ev->value;
602 delta = -(128 - delta);
605 switch (ev->controller_number) {
607 strip_vpot (0, delta);
610 strip_vpot (1, delta);
613 strip_vpot (2, delta);
616 strip_vpot (3, delta);
619 strip_vpot (4, delta);
622 strip_vpot (5, delta);
625 strip_vpot (6, delta);
628 strip_vpot (7, delta);
633 strip_vpot (8, delta);
636 other_vpot (1, delta);
641 other_vpot (2, delta);
648 Push2::handle_midi_note_on_message (MIDI::Parser&, MIDI::EventTwoBytes* ev)
650 switch (ev->note_number) {
652 strip_vpot_touch (0, ev->velocity > 64);
655 strip_vpot_touch (1, ev->velocity > 64);
658 strip_vpot_touch (2, ev->velocity > 64);
661 strip_vpot_touch (3, ev->velocity > 64);
664 strip_vpot_touch (4, ev->velocity > 64);
667 strip_vpot_touch (5, ev->velocity > 64);
670 strip_vpot_touch (6, ev->velocity > 64);
673 strip_vpot_touch (7, ev->velocity > 64);
678 other_vpot_touch (0, ev->velocity > 64);
681 other_vpot_touch (1, ev->velocity > 64);
686 other_vpot_touch (3, ev->velocity > 64);
691 if (ev->velocity < 64) {
700 Push2::handle_midi_note_off_message (MIDI::Parser&, MIDI::EventTwoBytes* ev)
705 Push2::handle_midi_pitchbend_message (MIDI::Parser&, MIDI::pitchbend_t pb)
712 /* range of +1 .. -1 */
713 speed = ((int32_t) pb - 8192) / 8192.0;
714 /* convert to range of +3 .. -3 */
715 session->request_transport_speed (speed * 3.0);
725 #define MAKE_PAD(x,y,nn) \
726 pad = new Pad ((x), (y), (nn)); \
727 nn_pad_map.insert (make_pair (pad->extra(), pad)); \
728 coord_pad_map.insert (make_pair (pad->coord(), pad));
794 /* Now color buttons */
798 #define MAKE_COLOR_BUTTON(i,cc) \
799 button = new ColorButton ((i), (cc)); \
800 cc_button_map.insert (make_pair (button->controller_number(), button)); \
801 id_button_map.insert (make_pair (button->id, button));
802 #define MAKE_COLOR_BUTTON_PRESS(i,cc,p)\
803 button = new ColorButton ((i), (cc), (p)); \
804 cc_button_map.insert (make_pair (button->controller_number(), button)); \
805 id_button_map.insert (make_pair (button->id, button))
807 MAKE_COLOR_BUTTON_PRESS (Upper1, 102, &Push2::button_upper_1);
808 MAKE_COLOR_BUTTON_PRESS (Upper2, 103, &Push2::button_upper_2);
809 MAKE_COLOR_BUTTON_PRESS (Upper3, 104, &Push2::button_upper_3);
810 MAKE_COLOR_BUTTON_PRESS (Upper4, 105, &Push2::button_upper_4);
811 MAKE_COLOR_BUTTON_PRESS (Upper5, 106, &Push2::button_upper_5);
812 MAKE_COLOR_BUTTON_PRESS (Upper6, 107, &Push2::button_upper_6);
813 MAKE_COLOR_BUTTON_PRESS (Upper7, 108, &Push2::button_upper_7);
814 MAKE_COLOR_BUTTON_PRESS (Upper8, 109, &Push2::button_upper_8);
815 MAKE_COLOR_BUTTON_PRESS (Lower1, 20, &Push2::button_lower_1);
816 MAKE_COLOR_BUTTON_PRESS (Lower2, 21, &Push2::button_lower_2);
817 MAKE_COLOR_BUTTON_PRESS (Lower3, 22, &Push2::button_lower_3);
818 MAKE_COLOR_BUTTON_PRESS (Lower4, 23, &Push2::button_lower_4);
819 MAKE_COLOR_BUTTON_PRESS (Lower5, 24, &Push2::button_lower_5);
820 MAKE_COLOR_BUTTON_PRESS (Lower6, 25, &Push2::button_lower_6);
821 MAKE_COLOR_BUTTON_PRESS (Lower7, 26, &Push2::button_lower_7);
822 MAKE_COLOR_BUTTON_PRESS (Lower8, 27, &Push2::button_lower_8);
823 MAKE_COLOR_BUTTON (Master, 28);
824 MAKE_COLOR_BUTTON (Mute, 60);
825 MAKE_COLOR_BUTTON_PRESS (Solo, 61, &Push2::button_solo);
826 MAKE_COLOR_BUTTON (Stop, 29);
827 MAKE_COLOR_BUTTON_PRESS (Fwd32ndT, 43, &Push2::button_fwd32t);
828 MAKE_COLOR_BUTTON_PRESS (Fwd32nd,42 , &Push2::button_fwd32);
829 MAKE_COLOR_BUTTON_PRESS (Fwd16thT, 41, &Push2::button_fwd16t);
830 MAKE_COLOR_BUTTON_PRESS (Fwd16th, 40, &Push2::button_fwd16);
831 MAKE_COLOR_BUTTON_PRESS (Fwd8thT, 39 , &Push2::button_fwd8t);
832 MAKE_COLOR_BUTTON_PRESS (Fwd8th, 38, &Push2::button_fwd8);
833 MAKE_COLOR_BUTTON_PRESS (Fwd4trT, 37, &Push2::button_fwd4t);
834 MAKE_COLOR_BUTTON_PRESS (Fwd4tr, 36, &Push2::button_fwd4);
835 MAKE_COLOR_BUTTON (Automate, 89);
836 MAKE_COLOR_BUTTON_PRESS (RecordEnable, 86, &Push2::button_recenable);
837 MAKE_COLOR_BUTTON_PRESS (Play, 85, &Push2::button_play);
839 #define MAKE_WHITE_BUTTON(i,cc)\
840 button = new WhiteButton ((i), (cc)); \
841 cc_button_map.insert (make_pair (button->controller_number(), button)); \
842 id_button_map.insert (make_pair (button->id, button))
843 #define MAKE_WHITE_BUTTON_PRESS(i,cc,p)\
844 button = new WhiteButton ((i), (cc), (p)); \
845 cc_button_map.insert (make_pair (button->controller_number(), button)); \
846 id_button_map.insert (make_pair (button->id, button))
847 #define MAKE_WHITE_BUTTON_PRESS_RELEASE(i,cc,p,r) \
848 button = new WhiteButton ((i), (cc), (p), (r)); \
849 cc_button_map.insert (make_pair (button->controller_number(), button)); \
850 id_button_map.insert (make_pair (button->id, button))
852 MAKE_WHITE_BUTTON (TapTempo, 3);
853 MAKE_WHITE_BUTTON_PRESS (Metronome, 9, &Push2::button_metronome);
854 MAKE_WHITE_BUTTON (Setup, 30);
855 MAKE_WHITE_BUTTON (User, 59);
856 MAKE_WHITE_BUTTON (Delete, 118);
857 MAKE_WHITE_BUTTON (AddDevice, 52);
858 MAKE_WHITE_BUTTON (Device, 110);
859 MAKE_WHITE_BUTTON (Mix, 112);
860 MAKE_WHITE_BUTTON_PRESS (Undo, 119, &Push2::button_undo);
861 MAKE_WHITE_BUTTON (AddTrack, 53);
862 MAKE_WHITE_BUTTON_PRESS (Browse, 111, &Push2::button_browse);
863 MAKE_WHITE_BUTTON_PRESS (Clip, 113, &Push2::button_clip);
864 MAKE_WHITE_BUTTON (Convert, 35);
865 MAKE_WHITE_BUTTON (DoubleLoop, 117);
866 MAKE_WHITE_BUTTON (Quantize, 116);
867 MAKE_WHITE_BUTTON (Duplicate, 88);
868 MAKE_WHITE_BUTTON_PRESS (New, 87, &Push2::button_new);
869 MAKE_WHITE_BUTTON_PRESS (FixedLength, 90, &Push2::button_fixed_length);
870 MAKE_WHITE_BUTTON_PRESS (Up, 46, &Push2::button_up);
871 MAKE_WHITE_BUTTON_PRESS (Right, 45, &Push2::button_right);
872 MAKE_WHITE_BUTTON_PRESS (Down, 47, &Push2::button_down);
873 MAKE_WHITE_BUTTON_PRESS (Left, 44, &Push2::button_left);
874 MAKE_WHITE_BUTTON_PRESS (Repeat, 56, &Push2::button_repeat);
875 MAKE_WHITE_BUTTON (Accent, 57);
876 MAKE_WHITE_BUTTON (Scale, 58);
877 MAKE_WHITE_BUTTON (Layout, 31);
878 MAKE_WHITE_BUTTON (Note, 50);
879 MAKE_WHITE_BUTTON (Session, 51);
880 MAKE_WHITE_BUTTON (Layout, 31);
881 MAKE_WHITE_BUTTON (OctaveUp, 55);
882 MAKE_WHITE_BUTTON (PageRight, 63);
883 MAKE_WHITE_BUTTON (OctaveDown, 54);
884 MAKE_WHITE_BUTTON (PageLeft, 62);
885 MAKE_WHITE_BUTTON_PRESS_RELEASE (Shift, 49, &Push2::button_shift_press, &Push2::button_shift_release);
886 MAKE_WHITE_BUTTON (Select, 48);
890 Push2::thread_init ()
892 struct sched_param rtparam;
894 pthread_set_name (event_loop_name().c_str());
896 PBD::notify_event_loops_about_thread_creation (pthread_self(), event_loop_name(), 2048);
897 ARDOUR::SessionEvent::create_per_thread_pool (event_loop_name(), 128);
899 memset (&rtparam, 0, sizeof (rtparam));
900 rtparam.sched_priority = 9; /* XXX should be relative to audio (JACK) thread */
902 if (pthread_setschedparam (pthread_self(), SCHED_FIFO, &rtparam) != 0) {
903 // do we care? not particularly.
908 Push2::connect_session_signals()
910 // receive routes added
911 //session->RouteAdded.connect(session_connections, MISSING_INVALIDATOR, boost::bind (&MackieControlProtocol::notify_routes_added, this, _1), this);
912 // receive VCAs added
913 //session->vca_manager().VCAAdded.connect(session_connections, MISSING_INVALIDATOR, boost::bind (&Push2::notify_vca_added, this, _1), this);
915 // receive record state toggled
916 session->RecordStateChanged.connect(session_connections, MISSING_INVALIDATOR, boost::bind (&Push2::notify_record_state_changed, this), this);
917 // receive transport state changed
918 session->TransportStateChange.connect(session_connections, MISSING_INVALIDATOR, boost::bind (&Push2::notify_transport_state_changed, this), this);
919 session->TransportLooped.connect (session_connections, MISSING_INVALIDATOR, boost::bind (&Push2::notify_loop_state_changed, this), this);
920 // receive punch-in and punch-out
921 Config->ParameterChanged.connect(session_connections, MISSING_INVALIDATOR, boost::bind (&Push2::notify_parameter_changed, this, _1), this);
922 session->config.ParameterChanged.connect (session_connections, MISSING_INVALIDATOR, boost::bind (&Push2::notify_parameter_changed, this, _1), this);
923 // receive rude solo changed
924 session->SoloActive.connect(session_connections, MISSING_INVALIDATOR, boost::bind (&Push2::notify_solo_active_changed, this, _1), this);
928 Push2::notify_record_state_changed ()
930 IDButtonMap::iterator b = id_button_map.find (RecordEnable);
932 if (b == id_button_map.end()) {
936 switch (session->record_status ()) {
937 case Session::Disabled:
938 b->second->set_color (LED::White);
939 b->second->set_state (LED::NoTransition);
941 case Session::Enabled:
942 b->second->set_color (LED::Red);
943 b->second->set_state (LED::Blinking4th);
945 case Session::Recording:
946 b->second->set_color (LED::Red);
947 b->second->set_state (LED::OneShot24th);
951 write (b->second->state_msg());
955 Push2::notify_transport_state_changed ()
957 Button* b = id_button_map[Play];
959 if (session->transport_rolling()) {
960 b->set_state (LED::OneShot24th);
961 b->set_color (LED::Green);
964 /* disable any blink on FixedLength from pending edit range op */
965 Button* fl = id_button_map[FixedLength];
967 fl->set_color (LED::Black);
968 fl->set_state (LED::NoTransition);
969 write (fl->state_msg());
971 b->set_color (LED::White);
972 b->set_state (LED::NoTransition);
975 write (b->state_msg());
979 Push2::notify_loop_state_changed ()
984 Push2::notify_parameter_changed (std::string param)
986 IDButtonMap::iterator b;
988 if (param == "clicking") {
989 if ((b = id_button_map.find (Metronome)) == id_button_map.end()) {
992 if (Config->get_clicking()) {
993 b->second->set_state (LED::Blinking4th);
994 b->second->set_color (LED::White);
996 b->second->set_color (LED::White);
997 b->second->set_state (LED::NoTransition);
999 write (b->second->state_msg ());
1004 Push2::notify_solo_active_changed (bool yn)
1006 IDButtonMap::iterator b = id_button_map.find (Solo);
1008 if (b == id_button_map.end()) {
1013 b->second->set_state (LED::Blinking4th);
1014 b->second->set_color (LED::Red);
1016 b->second->set_state (LED::NoTransition);
1017 b->second->set_color (LED::White);
1020 write (b->second->state_msg());
1026 XMLNode& node (ControlProtocol::get_state());
1029 child = new XMLNode (X_("Input"));
1030 child->add_child_nocopy (_async_in->get_state());
1031 node.add_child_nocopy (*child);
1032 child = new XMLNode (X_("Output"));
1033 child->add_child_nocopy (_async_out->get_state());
1034 node.add_child_nocopy (*child);
1040 Push2::set_state (const XMLNode & node, int version)
1042 DEBUG_TRACE (DEBUG::Push2, string_compose ("Push2::set_state: active %1\n", active()));
1046 if (ControlProtocol::set_state (node, version)) {
1052 if ((child = node.child (X_("Input"))) != 0) {
1053 XMLNode* portnode = child->child (Port::state_node_name.c_str());
1055 _async_in->set_state (*portnode, version);
1059 if ((child = node.child (X_("Output"))) != 0) {
1060 XMLNode* portnode = child->child (Port::state_node_name.c_str());
1062 _async_out->set_state (*portnode, version);
1070 Push2::switch_bank (uint32_t base)
1076 stripable_connections.drop_connections ();
1078 /* try to get the first stripable for the requested bank */
1080 stripable[0] = session->get_nth_stripable (base+0);
1082 if (!stripable[0]) {
1086 /* at least one stripable in this bank */
1089 stripable[1] = session->get_nth_stripable (base+1);
1090 stripable[2] = session->get_nth_stripable (base+2);
1091 stripable[3] = session->get_nth_stripable (base+3);
1092 stripable[4] = session->get_nth_stripable (base+4);
1093 stripable[5] = session->get_nth_stripable (base+5);
1094 stripable[6] = session->get_nth_stripable (base+6);
1095 stripable[7] = session->get_nth_stripable (base+7);
1097 for (int n = 0; n < 8; ++n) {
1098 if (!stripable[n]) {
1102 /* stripable goes away? refill the bank, starting at the same point */
1104 stripable[n]->DropReferences.connect (stripable_connections, MISSING_INVALIDATOR, boost::bind (&Push2::switch_bank, this, bank_start), this);
1105 boost::shared_ptr<AutomationControl> sc = stripable[n]->solo_control();
1107 sc->Changed.connect (stripable_connections, MISSING_INVALIDATOR, boost::bind (&Push2::solo_change, this, n), this);
1110 boost::shared_ptr<AutomationControl> mc = stripable[n]->mute_control();
1112 mc->Changed.connect (stripable_connections, MISSING_INVALIDATOR, boost::bind (&Push2::mute_change, this, n), this);
1120 /* master cannot be removed, so no need to connect to going-away signal */
1121 master = session->master_out ();
1125 Push2::solo_change (int n)
1158 boost::shared_ptr<AutomationControl> ac = stripable[n]->solo_control ();
1163 Button* b = id_button_map[bid];
1164 if (ac->get_value()) {
1165 b->set_color (LED::Red);
1167 b->set_color (LED::Black);
1169 b->set_state (LED::OneShot24th);
1170 write (b->state_msg());
1174 Push2::mute_change (int n)
1207 boost::shared_ptr<AutomationControl> ac = stripable[n]->mute_control ();
1212 Button* b = id_button_map[bid];
1214 if (ac->get_value ()) {
1215 b->set_color (LED::Blue);
1217 b->set_color (LED::Black);
1219 b->set_state (LED::OneShot24th);
1220 write (b->state_msg());
1224 Push2::strip_vpot (int n, int delta)
1227 boost::shared_ptr<AutomationControl> ac = stripable[n]->gain_control();
1229 ac->set_value (ac->get_value() + ((2.0/64.0) * delta), PBD::Controllable::UseGroup);
1235 Push2::strip_vpot_touch (int n, bool touching)
1238 boost::shared_ptr<AutomationControl> ac = stripable[n]->gain_control();
1241 ac->start_touch (session->audible_frame());
1243 ac->stop_touch (true, session->audible_frame());
1250 Push2::other_vpot (int n, int delta)
1258 /* master gain control */
1260 boost::shared_ptr<AutomationControl> ac = master->gain_control();
1262 ac->set_value (ac->get_value() + ((2.0/64.0) * delta), PBD::Controllable::UseGroup);
1270 Push2::other_vpot_touch (int n, bool touching)
1279 boost::shared_ptr<AutomationControl> ac = master->gain_control();
1282 ac->start_touch (session->audible_frame());
1284 ac->stop_touch (true, session->audible_frame());