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"
34 #include "midi++/types.h"
36 #include "ardour/types.h"
38 #include "control_protocol/control_protocol.h"
39 #include "control_protocol/types.h"
41 #include "midi_byte_array.h"
65 namespace ArdourSurface {
67 struct Push2Request : public BaseUI::BaseRequestObject {
75 class Push2 : public ARDOUR::ControlProtocol
76 , public AbstractUI<Push2Request>
79 Push2 (ARDOUR::Session&);
83 static void* request_factory (uint32_t);
85 bool has_editor () const { return true; }
86 void* get_gui () const;
87 void tear_down_gui ();
89 int set_active (bool yn);
91 int set_state (const XMLNode & node, int version);
93 PBD::Signal0<void> ConnectionChange;
95 boost::shared_ptr<ARDOUR::Port> input_port();
96 boost::shared_ptr<ARDOUR::Port> output_port();
98 int pad_note (int row, int col) const;
99 PBD::Signal0<void> PadChange;
101 void set_pad_scale (int root, int octave, MusicalMode::Type mode, bool inkey);
104 libusb_device_handle *handle;
105 uint8_t frame_header[16];
106 uint16_t* device_frame_buffer;
108 Cairo::RefPtr<Cairo::ImageSurface> frame_buffer;
109 sigc::connection vblank_connection;
110 sigc::connection periodic_connection;
118 ModifierState modifier_state;
120 static const int cols;
121 static const int rows;
122 static const int pixels_per_row;
124 void do_request (Push2Request*);
129 int blit_to_device_frame_buffer ();
135 Upper1, Upper2, Upper3, Upper4, Upper5, Upper6, Upper7, Upper8,
149 Lower1, Lower2, Lower3, Lower4, Lower5, Lower6, Lower7, Lower8,
217 LED (uint8_t e) : _extra (e), _color_index (Black), _state (NoTransition) {}
220 uint8_t extra () const { return _extra; }
221 uint8_t color_index () const { return _color_index; }
222 State state () const { return _state; }
224 void set_color (uint8_t color_index);
225 void set_state (State state);
227 virtual MidiByteArray state_msg() const = 0;
231 uint8_t _color_index;
235 struct Pad : public LED {
242 Pad (int xx, int yy, uint8_t ex)
246 , do_when_pressed (FlashOn)
248 , perma_color (LED::Black)
251 MidiByteArray state_msg () const { return MidiByteArray (3, 0x90|_state, _extra, _color_index); }
253 int coord () const { return (y * 8) + x; }
254 int note_number() const { return extra(); }
263 struct Button : public LED {
264 Button (ButtonID bb, uint8_t ex)
267 , press_method (&Push2::relax)
268 , release_method (&Push2::relax)
269 , long_press_method (&Push2::relax)
272 Button (ButtonID bb, uint8_t ex, void (Push2::*press)())
275 , press_method (press)
276 , release_method (&Push2::relax)
277 , long_press_method (&Push2::relax)
280 Button (ButtonID bb, uint8_t ex, void (Push2::*press)(), void (Push2::*release)())
283 , press_method (press)
284 , release_method (release)
285 , long_press_method (&Push2::relax)
288 Button (ButtonID bb, uint8_t ex, void (Push2::*press)(), void (Push2::*release)(), void (Push2::*long_press)())
291 , press_method (press)
292 , release_method (release)
293 , long_press_method (long_press)
296 MidiByteArray state_msg () const { return MidiByteArray (3, 0xb0|_state, _extra, _color_index); }
297 int controller_number() const { return extra(); }
300 void (Push2::*press_method)();
301 void (Push2::*release_method)();
302 void (Push2::*long_press_method)();
303 sigc::connection timeout_connection;
306 struct ColorButton : public Button {
307 ColorButton (ButtonID bb, uint8_t ex)
311 ColorButton (ButtonID bb, uint8_t ex, void (Push2::*press)())
312 : Button (bb, ex, press) {}
314 ColorButton (ButtonID bb, uint8_t ex, void (Push2::*press)(), void (Push2::*release)())
315 : Button (bb, ex, press, release) {}
317 ColorButton (ButtonID bb, uint8_t ex, void (Push2::*press)(), void (Push2::*release)(), void (Push2::*long_press)())
318 : Button (bb, ex, press, release, long_press) {}
321 struct WhiteButton : public Button {
322 WhiteButton (ButtonID bb, uint8_t ex)
325 WhiteButton (ButtonID bb, uint8_t ex, void (Push2::*press)())
326 : Button (bb, ex, press) {}
328 WhiteButton (ButtonID bb, uint8_t ex, void (Push2::*press)(), void (Push2::*release)())
329 : Button (bb, ex, press, release) {}
331 WhiteButton (ButtonID bb, uint8_t ex, void (Push2::*press)(), void (Push2::*release)(), void (Push2::*long_press)())
332 : Button (bb, ex, press, release, long_press) {}
337 /* map of Buttons by CC */
338 typedef std::map<int,Button*> CCButtonMap;
339 CCButtonMap cc_button_map;
340 /* map of Buttons by ButtonID */
341 typedef std::map<ButtonID,Button*> IDButtonMap;
342 IDButtonMap id_button_map;
343 std::set<ButtonID> buttons_down;
344 std::set<ButtonID> consumed;
346 bool button_long_press_timeout (ButtonID id);
347 void start_press_timeout (Button&, ButtonID);
349 void init_buttons (bool startup);
350 void init_touch_strip ();
352 /* map of Pads by note number */
353 typedef std::map<int,Pad*> NNPadMap;
355 /* map of Pads by coordinate
357 * coord = row * 64 + column;
359 * rows start at top left
361 typedef std::map<int,Pad*> CoordPadMap;
362 CoordPadMap coord_pad_map;
364 void set_button_color (ButtonID, uint8_t color_index);
365 void set_button_state (ButtonID, LED::State);
366 void set_led_color (ButtonID, uint8_t color_index);
367 void set_led_state (ButtonID, LED::State);
371 MIDI::Port* _input_port;
372 MIDI::Port* _output_port;
373 boost::shared_ptr<ARDOUR::Port> _async_in;
374 boost::shared_ptr<ARDOUR::Port> _async_out;
376 void connect_to_parser ();
377 void handle_midi_pitchbend_message (MIDI::Parser&, MIDI::pitchbend_t);
378 void handle_midi_controller_message (MIDI::Parser&, MIDI::EventTwoBytes*);
379 void handle_midi_note_on_message (MIDI::Parser&, MIDI::EventTwoBytes*);
380 void handle_midi_note_off_message (MIDI::Parser&, MIDI::EventTwoBytes*);
381 void handle_midi_sysex (MIDI::Parser&, MIDI::byte *, size_t count);
383 void write (const MidiByteArray&);
384 bool midi_input_handler (Glib::IOCondition ioc, MIDI::Port* port);
389 PBD::ScopedConnectionList session_connections;
390 void connect_session_signals ();
391 void notify_record_state_changed ();
392 void notify_transport_state_changed ();
393 void notify_loop_state_changed ();
394 void notify_parameter_changed (std::string);
395 void notify_solo_active_changed (bool);
399 void button_recenable ();
402 void button_right ();
404 void button_metronome ();
405 void button_repeat ();
407 void button_fixed_length ();
409 void button_browse ();
411 void button_upper (uint32_t n);
412 void button_lower (uint32_t n);
413 void button_upper_1 () { button_upper (0); }
414 void button_upper_2 () { button_upper (1); }
415 void button_upper_3 () { button_upper (2); }
416 void button_upper_4 () { button_upper (3); }
417 void button_upper_5 () { button_upper (4); }
418 void button_upper_6 () { button_upper (5); }
419 void button_upper_7 () { button_upper (6); }
420 void button_upper_8 () { button_upper (7); }
421 void button_lower_1 () { button_lower (0); }
422 void button_lower_2 () { button_lower (1); }
423 void button_lower_3 () { button_lower (2); }
424 void button_lower_4 () { button_lower (3); }
425 void button_lower_5 () { button_lower (4); }
426 void button_lower_6 () { button_lower (5); }
427 void button_lower_7 () { button_lower (6); }
428 void button_lower_8 () { button_lower (7); }
430 void button_fwd32t ();
431 void button_fwd32 ();
432 void button_fwd16t ();
433 void button_fwd16 ();
434 void button_fwd8t ();
436 void button_fwd4t ();
438 void button_add_track ();
440 void button_shift_press ();
441 void button_shift_release ();
442 void button_shift_long_press ();
443 void button_select_press ();
444 void button_select_release ();
445 void button_select_long_press ();
446 void button_page_left ();
447 void button_page_right ();
448 void button_octave_up ();
449 void button_octave_down ();
453 void start_select ();
458 void strip_vpot (int, int);
459 void other_vpot (int, int);
460 void strip_vpot_touch (int, bool);
461 void other_vpot_touch (int, bool);
465 Cairo::RefPtr<Cairo::Context> context;
466 Glib::RefPtr<Pango::Layout> tc_clock_layout;
467 Glib::RefPtr<Pango::Layout> bbt_clock_layout;
468 Glib::RefPtr<Pango::Layout> upper_layout[8];
469 Glib::RefPtr<Pango::Layout> mid_layout[8];
470 Glib::RefPtr<Pango::Layout> lower_layout[8];
473 ARDOUR::microseconds_t splash_start;
478 PBD::ScopedConnectionList stripable_connections;
479 boost::shared_ptr<ARDOUR::Stripable> stripable[8];
480 boost::shared_ptr<ARDOUR::Stripable> master;
481 boost::shared_ptr<ARDOUR::Stripable> monitor;
483 void solo_change (int);
484 void mute_change (int);
485 void stripable_property_change (PBD::PropertyChange const& what_changed, int which);
487 void switch_bank (uint32_t base);
489 bool pad_filter (ARDOUR::MidiBuffer& in, ARDOUR::MidiBuffer& out) const;
491 boost::weak_ptr<ARDOUR::MidiTrack> current_pad_target;
492 PBD::ScopedConnection selection_connection;
493 void stripable_selection_change (ARDOUR::StripableNotificationListPtr);
495 PBD::ScopedConnection port_reg_connection;
496 void port_registration_handler ();
498 enum ConnectionState {
499 InputConnected = 0x1,
500 OutputConnected = 0x2
503 int connection_state;
504 bool connection_handler (boost::weak_ptr<ARDOUR::Port>, std::string name1, boost::weak_ptr<ARDOUR::Port>, std::string name2, bool yn);
505 PBD::ScopedConnection port_connection;
514 std::map<int,int> pad_map;
515 void build_pad_table();
517 MusicalMode::Type mode;
528 #endif /* __ardour_push2_h__ */