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 {
77 class Push2 : public ARDOUR::ControlProtocol
78 , public AbstractUI<Push2Request>
84 Upper1, Upper2, Upper3, Upper4, Upper5, Upper6, Upper7, Upper8,
98 Lower1, Lower2, Lower3, Lower4, Lower5, Lower6, Lower7, Lower8,
166 LED (uint8_t e) : _extra (e), _color_index (Black), _state (NoTransition) {}
169 uint8_t extra () const { return _extra; }
170 uint8_t color_index () const { return _color_index; }
171 State state () const { return _state; }
173 void set_color (uint8_t color_index);
174 void set_state (State state);
176 virtual MidiByteArray state_msg() const = 0;
180 uint8_t _color_index;
184 struct Pad : public LED {
191 Pad (int xx, int yy, uint8_t ex)
195 , do_when_pressed (FlashOn)
197 , perma_color (LED::Black)
200 MidiByteArray state_msg () const { return MidiByteArray (3, 0x90|_state, _extra, _color_index); }
202 int coord () const { return (y * 8) + x; }
203 int note_number() const { return extra(); }
212 struct Button : public LED {
213 Button (ButtonID bb, uint8_t ex)
216 , press_method (&Push2::relax)
217 , release_method (&Push2::relax)
218 , long_press_method (&Push2::relax)
221 Button (ButtonID bb, uint8_t ex, void (Push2::*press)())
224 , press_method (press)
225 , release_method (&Push2::relax)
226 , long_press_method (&Push2::relax)
229 Button (ButtonID bb, uint8_t ex, void (Push2::*press)(), void (Push2::*release)())
232 , press_method (press)
233 , release_method (release)
234 , long_press_method (&Push2::relax)
237 Button (ButtonID bb, uint8_t ex, void (Push2::*press)(), void (Push2::*release)(), void (Push2::*long_press)())
240 , press_method (press)
241 , release_method (release)
242 , long_press_method (long_press)
245 MidiByteArray state_msg () const { return MidiByteArray (3, 0xb0|_state, _extra, _color_index); }
246 int controller_number() const { return extra(); }
249 void (Push2::*press_method)();
250 void (Push2::*release_method)();
251 void (Push2::*long_press_method)();
252 sigc::connection timeout_connection;
255 struct ColorButton : public Button {
256 ColorButton (ButtonID bb, uint8_t ex)
260 ColorButton (ButtonID bb, uint8_t ex, void (Push2::*press)())
261 : Button (bb, ex, press) {}
263 ColorButton (ButtonID bb, uint8_t ex, void (Push2::*press)(), void (Push2::*release)())
264 : Button (bb, ex, press, release) {}
266 ColorButton (ButtonID bb, uint8_t ex, void (Push2::*press)(), void (Push2::*release)(), void (Push2::*long_press)())
267 : Button (bb, ex, press, release, long_press) {}
270 struct WhiteButton : public Button {
271 WhiteButton (ButtonID bb, uint8_t ex)
274 WhiteButton (ButtonID bb, uint8_t ex, void (Push2::*press)())
275 : Button (bb, ex, press) {}
277 WhiteButton (ButtonID bb, uint8_t ex, void (Push2::*press)(), void (Push2::*release)())
278 : Button (bb, ex, press, release) {}
280 WhiteButton (ButtonID bb, uint8_t ex, void (Push2::*press)(), void (Push2::*release)(), void (Push2::*long_press)())
281 : Button (bb, ex, press, release, long_press) {}
285 Push2 (ARDOUR::Session&);
288 static bool probe ();
289 static void* request_factory (uint32_t);
291 std::list<boost::shared_ptr<ARDOUR::Bundle> > bundles ();
293 bool has_editor () const { return true; }
294 void* get_gui () const;
295 void tear_down_gui ();
297 int set_active (bool yn);
298 XMLNode& get_state();
299 int set_state (const XMLNode & node, int version);
301 PBD::Signal0<void> ConnectionChange;
303 boost::shared_ptr<ARDOUR::Port> input_port();
304 boost::shared_ptr<ARDOUR::Port> output_port();
306 int pad_note (int row, int col) const;
307 PBD::Signal0<void> PadChange;
309 void set_pad_scale (int root, int octave, MusicalMode::Type mode, bool inkey);
311 MusicalMode::Type mode() const { return _mode; }
312 int scale_root() const { return _scale_root; }
313 int root_octave() const { return _root_octave; }
314 bool in_key() const { return _in_key; }
316 Push2Layout* current_layout() const;
324 ModifierState modifier_state() const { return _modifier_state; }
326 Button* button_by_id (ButtonID);
328 void write (const MidiByteArray&);
330 static const int cols;
331 static const int rows;
334 libusb_device_handle *handle;
335 uint8_t frame_header[16];
336 uint16_t* device_frame_buffer;
338 Cairo::RefPtr<Cairo::ImageSurface> frame_buffer;
339 sigc::connection vblank_connection;
340 sigc::connection periodic_connection;
342 ModifierState _modifier_state;
344 static const int pixels_per_row;
346 void do_request (Push2Request*);
351 int blit_to_device_frame_buffer ();
356 /* map of Buttons by CC */
357 typedef std::map<int,Button*> CCButtonMap;
358 CCButtonMap cc_button_map;
359 /* map of Buttons by ButtonID */
360 typedef std::map<ButtonID,Button*> IDButtonMap;
361 IDButtonMap id_button_map;
362 std::set<ButtonID> buttons_down;
363 std::set<ButtonID> consumed;
365 bool button_long_press_timeout (ButtonID id);
366 void start_press_timeout (Button&, ButtonID);
368 void init_buttons (bool startup);
369 void init_touch_strip ();
371 /* map of Pads by note number */
372 typedef std::map<int,Pad*> NNPadMap;
375 void set_button_color (ButtonID, uint8_t color_index);
376 void set_button_state (ButtonID, LED::State);
377 void set_led_color (ButtonID, uint8_t color_index);
378 void set_led_state (ButtonID, LED::State);
382 // Bundle to represent our input ports
383 boost::shared_ptr<ARDOUR::Bundle> _input_bundle;
384 // Bundle to represent our output ports
385 boost::shared_ptr<ARDOUR::Bundle> _output_bundle;
387 MIDI::Port* _input_port;
388 MIDI::Port* _output_port;
389 boost::shared_ptr<ARDOUR::Port> _async_in;
390 boost::shared_ptr<ARDOUR::Port> _async_out;
392 void connect_to_parser ();
393 void handle_midi_pitchbend_message (MIDI::Parser&, MIDI::pitchbend_t);
394 void handle_midi_controller_message (MIDI::Parser&, MIDI::EventTwoBytes*);
395 void handle_midi_note_on_message (MIDI::Parser&, MIDI::EventTwoBytes*);
396 void handle_midi_note_off_message (MIDI::Parser&, MIDI::EventTwoBytes*);
397 void handle_midi_sysex (MIDI::Parser&, MIDI::byte *, size_t count);
399 bool midi_input_handler (Glib::IOCondition ioc, MIDI::Port* port);
404 PBD::ScopedConnectionList session_connections;
405 void connect_session_signals ();
406 void notify_record_state_changed ();
407 void notify_transport_state_changed ();
408 void notify_loop_state_changed ();
409 void notify_parameter_changed (std::string);
410 void notify_solo_active_changed (bool);
414 void button_recenable ();
417 void button_right ();
419 void button_metronome ();
420 void button_repeat ();
422 void button_fixed_length ();
424 void button_browse ();
427 void button_fwd32t ();
428 void button_fwd32 ();
429 void button_fwd16t ();
430 void button_fwd16 ();
431 void button_fwd8t ();
433 void button_fwd4t ();
435 void button_add_track ();
437 void button_shift_press ();
438 void button_shift_release ();
439 void button_shift_long_press ();
440 void button_select_press ();
441 void button_select_release ();
442 void button_select_long_press ();
443 void button_page_left ();
444 void button_page_right ();
445 void button_octave_up ();
446 void button_octave_down ();
447 void button_layout_press ();
448 void button_scale_press ();
450 void button_upper (uint32_t n);
451 void button_lower (uint32_t n);
453 void button_upper_1 () { button_upper (0); }
454 void button_upper_2 () { button_upper (1); }
455 void button_upper_3 () { button_upper (2); }
456 void button_upper_4 () { button_upper (3); }
457 void button_upper_5 () { button_upper (4); }
458 void button_upper_6 () { button_upper (5); }
459 void button_upper_7 () { button_upper (6); }
460 void button_upper_8 () { button_upper (7); }
461 void button_lower_1 () { button_lower (0); }
462 void button_lower_2 () { button_lower (1); }
463 void button_lower_3 () { button_lower (2); }
464 void button_lower_4 () { button_lower (3); }
465 void button_lower_5 () { button_lower (4); }
466 void button_lower_6 () { button_lower (5); }
467 void button_lower_7 () { button_lower (6); }
468 void button_lower_8 () { button_lower (7); }
473 /* non-strip encoders */
475 void other_vpot (int, int);
476 void other_vpot_touch (int, bool);
478 /* special Stripables */
480 boost::shared_ptr<ARDOUR::Stripable> master;
481 boost::shared_ptr<ARDOUR::Stripable> monitor;
483 /* Cairo graphics context */
485 Cairo::RefPtr<Cairo::Context> context;
488 ARDOUR::microseconds_t splash_start;
492 mutable Glib::Threads::Mutex layout_lock;
493 Push2Layout* _current_layout;
494 Push2Layout* drawn_layout;
495 Push2Layout* mix_layout;
496 Push2Layout* scale_layout;
498 bool pad_filter (ARDOUR::MidiBuffer& in, ARDOUR::MidiBuffer& out) const;
500 boost::weak_ptr<ARDOUR::MidiTrack> current_pad_target;
502 PBD::ScopedConnection port_reg_connection;
503 void port_registration_handler ();
505 enum ConnectionState {
506 InputConnected = 0x1,
507 OutputConnected = 0x2
510 int connection_state;
511 bool connection_handler (boost::weak_ptr<ARDOUR::Port>, std::string name1, boost::weak_ptr<ARDOUR::Port>, std::string name2, bool yn);
512 PBD::ScopedConnection port_connection;
521 PBD::ScopedConnection selection_connection;
522 void stripable_selection_change (ARDOUR::StripableNotificationListPtr);
524 MusicalMode::Type _mode;
532 void set_percussive_mode (bool);
538 Push2Layout (Push2& p, ARDOUR::Session& s);
539 virtual ~Push2Layout ();
543 virtual bool redraw (Cairo::RefPtr<Cairo::Context>) const = 0;
545 virtual void button_upper (uint32_t n) {}
546 virtual void button_lower (uint32_t n) {}
547 virtual void button_up () {}
548 virtual void button_down () {}
549 virtual void button_right () {}
550 virtual void button_left () {}
551 virtual void button_select_press () {}
552 virtual void button_select_release () {}
554 virtual void strip_vpot (int, int) = 0;
555 virtual void strip_vpot_touch (int, bool) = 0;
559 ARDOUR::Session& session;
563 class MixLayout : public Push2Layout
566 MixLayout (Push2& p, ARDOUR::Session&, Cairo::RefPtr<Cairo::Context>);
569 bool redraw (Cairo::RefPtr<Cairo::Context>) const;
571 void button_upper (uint32_t n);
572 void button_lower (uint32_t n);
574 void button_right ();
575 void button_select_press ();
576 void button_select_release ();
578 void strip_vpot (int, int);
579 void strip_vpot_touch (int, bool);
582 Glib::RefPtr<Pango::Layout> tc_clock_layout;
583 Glib::RefPtr<Pango::Layout> bbt_clock_layout;
584 Glib::RefPtr<Pango::Layout> upper_layout[8];
585 Glib::RefPtr<Pango::Layout> mid_layout[8];
586 Glib::RefPtr<Pango::Layout> lower_layout[8];
591 PBD::ScopedConnectionList stripable_connections;
592 boost::shared_ptr<ARDOUR::Stripable> stripable[8];
594 void solo_change (int);
595 void mute_change (int);
597 void stripable_property_change (PBD::PropertyChange const& what_changed, int which);
599 void switch_bank (uint32_t base);
602 class ScaleLayout : public Push2Layout
605 ScaleLayout (Push2& p, ARDOUR::Session&, Cairo::RefPtr<Cairo::Context>);
608 bool redraw (Cairo::RefPtr<Cairo::Context>) const;
610 void button_upper (uint32_t n);
611 void button_lower (uint32_t n);
613 void strip_vpot (int, int);
614 void strip_vpot_touch (int, bool);
617 Push2Menu* scale_menu;
618 void build_scale_menu (Cairo::RefPtr<Cairo::Context>);
623 #endif /* __ardour_push2_h__ */