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 #ifndef __ardour_push2_h__
20 #define __ardour_push2_h__
29 #include <cairomm/refptr.h>
31 #define ABSTRACT_UI_EXPORTS
32 #include "pbd/abstract_ui.h"
33 #include "midi++/types.h"
34 #include "ardour/types.h"
35 #include "control_protocol/control_protocol.h"
37 #include "midi_byte_array.h"
59 namespace ArdourSurface {
61 struct Push2Request : public BaseUI::BaseRequestObject {
69 class Push2 : public ARDOUR::ControlProtocol
70 , public AbstractUI<Push2Request>
73 Push2 (ARDOUR::Session&);
77 static void* request_factory (uint32_t);
79 bool has_editor () const { return true; }
80 void* get_gui () const;
81 void tear_down_gui ();
83 int set_active (bool yn);
85 int set_state (const XMLNode & node, int version);
87 PBD::Signal0<void> ConnectionChange;
89 boost::shared_ptr<ARDOUR::Port> input_port();
90 boost::shared_ptr<ARDOUR::Port> output_port();
92 uint8_t pad_note (int row, int col) const;
93 PBD::Signal0<void> PadChange;
96 libusb_device_handle *handle;
97 uint8_t frame_header[16];
98 uint16_t* device_frame_buffer;
100 Cairo::RefPtr<Cairo::ImageSurface> frame_buffer;
101 sigc::connection vblank_connection;
102 sigc::connection periodic_connection;
110 ModifierState modifier_state;
112 static const int cols;
113 static const int rows;
114 static const int pixels_per_row;
116 void do_request (Push2Request*);
121 int blit_to_device_frame_buffer ();
127 Upper1, Upper2, Upper3, Upper4, Upper5, Upper6, Upper7, Upper8,
141 Lower1, Lower2, Lower3, Lower4, Lower5, Lower6, Lower7, Lower8,
209 LED (uint8_t e) : _extra (e), _color_index (0), _state (NoTransition) {}
212 uint8_t extra () const { return _extra; }
213 uint8_t color_index () const { return _color_index; }
214 State state () const { return _state; }
216 void set_color (uint8_t color_index);
217 void set_state (State state);
219 virtual MidiByteArray state_msg() const = 0;
223 uint8_t _color_index;
227 struct Pad : public LED {
228 Pad (int xx, int yy, uint8_t ex)
233 MidiByteArray state_msg () const { return MidiByteArray (3, 0x90|_state, _extra, _color_index); }
235 int coord () const { return (y * 8) + x; }
236 int note_number() const { return extra(); }
242 struct Button : public LED {
243 Button (ButtonID bb, uint8_t ex)
246 , press_method (&Push2::relax)
247 , release_method (&Push2::relax)
248 , long_press_method (&Push2::relax)
251 Button (ButtonID bb, uint8_t ex, void (Push2::*press)())
254 , press_method (press)
255 , release_method (&Push2::relax)
256 , long_press_method (&Push2::relax)
259 Button (ButtonID bb, uint8_t ex, void (Push2::*press)(), void (Push2::*release)())
262 , press_method (press)
263 , release_method (release)
264 , long_press_method (&Push2::relax)
267 Button (ButtonID bb, uint8_t ex, void (Push2::*press)(), void (Push2::*release)(), void (Push2::*long_press)())
270 , press_method (press)
271 , release_method (release)
272 , long_press_method (long_press)
275 MidiByteArray state_msg () const { return MidiByteArray (3, 0xb0|_state, _extra, _color_index); }
276 int controller_number() const { return extra(); }
279 void (Push2::*press_method)();
280 void (Push2::*release_method)();
281 void (Push2::*long_press_method)();
282 sigc::connection timeout_connection;
285 struct ColorButton : public Button {
286 ColorButton (ButtonID bb, uint8_t ex)
290 ColorButton (ButtonID bb, uint8_t ex, void (Push2::*press)())
291 : Button (bb, ex, press) {}
293 ColorButton (ButtonID bb, uint8_t ex, void (Push2::*press)(), void (Push2::*release)())
294 : Button (bb, ex, press, release) {}
296 ColorButton (ButtonID bb, uint8_t ex, void (Push2::*press)(), void (Push2::*release)(), void (Push2::*long_press)())
297 : Button (bb, ex, press, release, long_press) {}
300 struct WhiteButton : public Button {
301 WhiteButton (ButtonID bb, uint8_t ex)
304 WhiteButton (ButtonID bb, uint8_t ex, void (Push2::*press)())
305 : Button (bb, ex, press) {}
307 WhiteButton (ButtonID bb, uint8_t ex, void (Push2::*press)(), void (Push2::*release)())
308 : Button (bb, ex, press, release) {}
310 WhiteButton (ButtonID bb, uint8_t ex, void (Push2::*press)(), void (Push2::*release)(), void (Push2::*long_press)())
311 : Button (bb, ex, press, release, long_press) {}
316 /* map of Buttons by CC */
317 typedef std::map<int,Button*> CCButtonMap;
318 CCButtonMap cc_button_map;
319 /* map of Buttons by ButtonID */
320 typedef std::map<ButtonID,Button*> IDButtonMap;
321 IDButtonMap id_button_map;
322 std::set<ButtonID> buttons_down;
323 std::set<ButtonID> consumed;
325 bool button_long_press_timeout (ButtonID id);
326 void start_press_timeout (Button&, ButtonID);
328 void init_buttons (bool startup);
329 void init_touch_strip ();
331 /* map of Pads by note number */
332 typedef std::map<int,Pad*> NNPadMap;
334 /* map of Pads by coordinate
336 * coord = row * 64 + column;
338 * rows start at top left
340 typedef std::map<int,Pad*> CoordPadMap;
341 CoordPadMap coord_pad_map;
343 void set_button_color (ButtonID, uint8_t color_index);
344 void set_button_state (ButtonID, LED::State);
345 void set_led_color (ButtonID, uint8_t color_index);
346 void set_led_state (ButtonID, LED::State);
350 MIDI::Port* _input_port;
351 MIDI::Port* _output_port;
352 boost::shared_ptr<ARDOUR::Port> _async_in;
353 boost::shared_ptr<ARDOUR::Port> _async_out;
355 void connect_to_parser ();
356 void handle_midi_pitchbend_message (MIDI::Parser&, MIDI::pitchbend_t);
357 void handle_midi_controller_message (MIDI::Parser&, MIDI::EventTwoBytes*);
358 void handle_midi_note_on_message (MIDI::Parser&, MIDI::EventTwoBytes*);
359 void handle_midi_note_off_message (MIDI::Parser&, MIDI::EventTwoBytes*);
360 void handle_midi_sysex (MIDI::Parser&, MIDI::byte *, size_t count);
362 void write (const MidiByteArray&);
363 bool midi_input_handler (Glib::IOCondition ioc, MIDI::Port* port);
368 PBD::ScopedConnectionList session_connections;
369 void connect_session_signals ();
370 void notify_record_state_changed ();
371 void notify_transport_state_changed ();
372 void notify_loop_state_changed ();
373 void notify_parameter_changed (std::string);
374 void notify_solo_active_changed (bool);
378 void button_recenable ();
381 void button_right ();
383 void button_metronome ();
384 void button_repeat ();
386 void button_fixed_length ();
388 void button_browse ();
390 void button_upper (uint32_t n);
391 void button_lower (uint32_t n);
392 void button_upper_1 () { button_upper (0); }
393 void button_upper_2 () { button_upper (1); }
394 void button_upper_3 () { button_upper (2); }
395 void button_upper_4 () { button_upper (3); }
396 void button_upper_5 () { button_upper (4); }
397 void button_upper_6 () { button_upper (5); }
398 void button_upper_7 () { button_upper (6); }
399 void button_upper_8 () { button_upper (7); }
400 void button_lower_1 () { button_lower (0); }
401 void button_lower_2 () { button_lower (1); }
402 void button_lower_3 () { button_lower (2); }
403 void button_lower_4 () { button_lower (3); }
404 void button_lower_5 () { button_lower (4); }
405 void button_lower_6 () { button_lower (5); }
406 void button_lower_7 () { button_lower (6); }
407 void button_lower_8 () { button_lower (7); }
409 void button_fwd32t ();
410 void button_fwd32 ();
411 void button_fwd16t ();
412 void button_fwd16 ();
413 void button_fwd8t ();
415 void button_fwd4t ();
417 void button_add_track ();
419 void button_shift_press ();
420 void button_shift_release ();
421 void button_shift_long_press ();
422 void button_select_press ();
423 void button_select_release ();
424 void button_select_long_press ();
425 void button_page_left ();
426 void button_page_right ();
427 void button_octave_up ();
428 void button_octave_down ();
432 void start_select ();
437 void strip_vpot (int, int);
438 void other_vpot (int, int);
439 void strip_vpot_touch (int, bool);
440 void other_vpot_touch (int, bool);
444 Cairo::RefPtr<Cairo::Context> context;
445 Glib::RefPtr<Pango::Layout> tc_clock_layout;
446 Glib::RefPtr<Pango::Layout> bbt_clock_layout;
447 Glib::RefPtr<Pango::Layout> upper_layout[8];
448 Glib::RefPtr<Pango::Layout> mid_layout[8];
449 Glib::RefPtr<Pango::Layout> lower_layout[8];
452 ARDOUR::microseconds_t splash_start;
457 PBD::ScopedConnectionList stripable_connections;
458 boost::shared_ptr<ARDOUR::Stripable> stripable[8];
459 boost::shared_ptr<ARDOUR::Stripable> master;
460 boost::shared_ptr<ARDOUR::Stripable> monitor;
462 void solo_change (int);
463 void mute_change (int);
464 void stripable_property_change (PBD::PropertyChange const& what_changed, int which);
466 void switch_bank (uint32_t base);
468 bool pad_filter (ARDOUR::MidiBuffer& in, ARDOUR::MidiBuffer& out) const;
470 boost::weak_ptr<ARDOUR::Stripable> first_selected_stripable;
472 PBD::ScopedConnection port_reg_connection;
473 void port_registration_handler ();
475 enum ConnectionState {
476 InputConnected = 0x1,
477 OutputConnected = 0x2
480 int connection_state;
481 bool connection_handler (boost::weak_ptr<ARDOUR::Port>, std::string name1, boost::weak_ptr<ARDOUR::Port>, std::string name2, bool yn);
482 PBD::ScopedConnection port_connection;
491 uint8_t pad_table[8][8];
492 void build_pad_table();
499 #endif /* __ardour_push2_h__ */