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__
30 #define ABSTRACT_UI_EXPORTS
31 #include "pbd/abstract_ui.h"
33 #include "midi++/types.h"
35 #include "ardour/types.h"
37 #include "control_protocol/control_protocol.h"
38 #include "control_protocol/types.h"
40 #include "canvas/colors.h"
42 #include "midi_byte_array.h"
61 namespace ArdourSurface {
63 struct Push2Request : public BaseUI::BaseRequestObject {
74 class Push2 : public ARDOUR::ControlProtocol
75 , public AbstractUI<Push2Request>
81 Upper1, Upper2, Upper3, Upper4, Upper5, Upper6, Upper7, Upper8,
95 Lower1, Lower2, Lower3, Lower4, Lower5, Lower6, Lower7, Lower8,
163 LED (uint8_t e) : _extra (e), _color_index (Black), _state (NoTransition) {}
166 uint8_t extra () const { return _extra; }
167 uint8_t color_index () const { return _color_index; }
168 State state () const { return _state; }
170 void set_color (uint8_t color_index);
171 void set_state (State state);
173 virtual MidiByteArray state_msg() const = 0;
177 uint8_t _color_index;
181 struct Pad : public LED {
188 Pad (int xx, int yy, uint8_t ex)
192 , do_when_pressed (FlashOn)
194 , perma_color (LED::Black)
197 MidiByteArray state_msg () const { return MidiByteArray (3, 0x90|_state, _extra, _color_index); }
199 int coord () const { return (y * 8) + x; }
200 int note_number() const { return extra(); }
209 struct Button : public LED {
210 Button (ButtonID bb, uint8_t ex)
213 , press_method (&Push2::relax)
214 , release_method (&Push2::relax)
215 , long_press_method (&Push2::relax)
218 Button (ButtonID bb, uint8_t ex, void (Push2::*press)())
221 , press_method (press)
222 , release_method (&Push2::relax)
223 , long_press_method (&Push2::relax)
226 Button (ButtonID bb, uint8_t ex, void (Push2::*press)(), void (Push2::*release)())
229 , press_method (press)
230 , release_method (release)
231 , long_press_method (&Push2::relax)
234 Button (ButtonID bb, uint8_t ex, void (Push2::*press)(), void (Push2::*release)(), void (Push2::*long_press)())
237 , press_method (press)
238 , release_method (release)
239 , long_press_method (long_press)
242 MidiByteArray state_msg () const { return MidiByteArray (3, 0xb0|_state, _extra, _color_index); }
243 int controller_number() const { return extra(); }
246 void (Push2::*press_method)();
247 void (Push2::*release_method)();
248 void (Push2::*long_press_method)();
249 sigc::connection timeout_connection;
252 struct ColorButton : public Button {
253 ColorButton (ButtonID bb, uint8_t ex)
257 ColorButton (ButtonID bb, uint8_t ex, void (Push2::*press)())
258 : Button (bb, ex, press) {}
260 ColorButton (ButtonID bb, uint8_t ex, void (Push2::*press)(), void (Push2::*release)())
261 : Button (bb, ex, press, release) {}
263 ColorButton (ButtonID bb, uint8_t ex, void (Push2::*press)(), void (Push2::*release)(), void (Push2::*long_press)())
264 : Button (bb, ex, press, release, long_press) {}
267 struct WhiteButton : public Button {
268 WhiteButton (ButtonID bb, uint8_t ex)
271 WhiteButton (ButtonID bb, uint8_t ex, void (Push2::*press)())
272 : Button (bb, ex, press) {}
274 WhiteButton (ButtonID bb, uint8_t ex, void (Push2::*press)(), void (Push2::*release)())
275 : Button (bb, ex, press, release) {}
277 WhiteButton (ButtonID bb, uint8_t ex, void (Push2::*press)(), void (Push2::*release)(), void (Push2::*long_press)())
278 : Button (bb, ex, press, release, long_press) {}
308 Push2 (ARDOUR::Session&);
311 static bool probe ();
312 static void* request_factory (uint32_t);
314 std::list<boost::shared_ptr<ARDOUR::Bundle> > bundles ();
316 bool has_editor () const { return true; }
317 void* get_gui () const;
318 void tear_down_gui ();
320 int set_active (bool yn);
321 XMLNode& get_state();
322 int set_state (const XMLNode & node, int version);
324 PBD::Signal0<void> ConnectionChange;
326 boost::shared_ptr<ARDOUR::Port> input_port();
327 boost::shared_ptr<ARDOUR::Port> output_port();
329 int pad_note (int row, int col) const;
330 PBD::Signal0<void> PadChange;
332 void update_selection_color ();
334 void set_pad_scale (int root, int octave, MusicalMode::Type mode, bool inkey);
335 PBD::Signal0<void> ScaleChange;
337 MusicalMode::Type mode() const { return _mode; }
338 int scale_root() const { return _scale_root; }
339 int root_octave() const { return _root_octave; }
340 bool in_key() const { return _in_key; }
342 Push2Layout* current_layout() const;
343 void use_previous_layout ();
345 Push2Canvas* canvas() const { return _canvas; }
353 ModifierState modifier_state() const { return _modifier_state; }
355 Button* button_by_id (ButtonID);
356 static std::string button_name_by_id (ButtonID);
358 void strip_buttons_off ();
360 void write (const MidiByteArray&);
362 uint8_t get_color_index (ArdourCanvas::Color rgba);
363 ArdourCanvas::Color get_color (ColorName);
365 PressureMode pressure_mode () const { return _pressure_mode; }
366 void set_pressure_mode (PressureMode);
367 PBD::Signal1<void,PressureMode> PressureModeChange;
369 libusb_device_handle* usb_handle() const { return handle; }
372 libusb_device_handle *handle;
373 ModifierState _modifier_state;
375 void do_request (Push2Request*);
382 /* map of Buttons by CC */
383 typedef std::map<int,Button*> CCButtonMap;
384 CCButtonMap cc_button_map;
385 /* map of Buttons by ButtonID */
386 typedef std::map<ButtonID,Button*> IDButtonMap;
387 IDButtonMap id_button_map;
388 std::set<ButtonID> buttons_down;
389 std::set<ButtonID> consumed;
391 bool button_long_press_timeout (ButtonID id);
392 void start_press_timeout (Button&, ButtonID);
394 void init_buttons (bool startup);
395 void init_touch_strip ();
397 /* map of Pads by note number (the "fixed" note number sent by the
398 * hardware, not the note number generated if the pad is touched)
400 typedef std::map<int,Pad*> NNPadMap;
403 /* map of Pads by note number they generate (their "filtered" value)
405 typedef std::multimap<int,Pad*> FNPadMap;
408 void set_button_color (ButtonID, uint8_t color_index);
409 void set_button_state (ButtonID, LED::State);
410 void set_led_color (ButtonID, uint8_t color_index);
411 void set_led_state (ButtonID, LED::State);
415 // Bundle to represent our input ports
416 boost::shared_ptr<ARDOUR::Bundle> _input_bundle;
417 // Bundle to represent our output ports
418 boost::shared_ptr<ARDOUR::Bundle> _output_bundle;
420 MIDI::Port* _input_port;
421 MIDI::Port* _output_port;
422 boost::shared_ptr<ARDOUR::Port> _async_in;
423 boost::shared_ptr<ARDOUR::Port> _async_out;
425 void connect_to_parser ();
426 void handle_midi_pitchbend_message (MIDI::Parser&, MIDI::pitchbend_t);
427 void handle_midi_controller_message (MIDI::Parser&, MIDI::EventTwoBytes*);
428 void handle_midi_note_on_message (MIDI::Parser&, MIDI::EventTwoBytes*);
429 void handle_midi_note_off_message (MIDI::Parser&, MIDI::EventTwoBytes*);
430 void handle_midi_sysex (MIDI::Parser&, MIDI::byte *, size_t count);
432 bool midi_input_handler (Glib::IOCondition ioc, MIDI::Port* port);
434 sigc::connection periodic_connection;
439 PBD::ScopedConnectionList session_connections;
440 void connect_session_signals ();
441 void notify_record_state_changed ();
442 void notify_transport_state_changed ();
443 void notify_loop_state_changed ();
444 void notify_parameter_changed (std::string);
445 void notify_solo_active_changed (bool);
449 void button_recenable ();
452 void button_right ();
454 void button_metronome ();
455 void button_repeat ();
458 void button_solo_long_press ();
459 void button_fixed_length ();
461 void button_browse ();
464 void button_fwd32t ();
465 void button_fwd32 ();
466 void button_fwd16t ();
467 void button_fwd16 ();
468 void button_fwd8t ();
470 void button_fwd4t ();
472 void button_add_track ();
474 void button_master ();
475 void button_quantize ();
476 void button_duplicate ();
477 void button_shift_press ();
478 void button_shift_release ();
479 void button_shift_long_press ();
480 void button_select_press ();
481 void button_select_release ();
482 void button_select_long_press ();
483 void button_page_left ();
484 void button_page_right ();
485 void button_octave_up ();
486 void button_octave_down ();
487 void button_layout_press ();
488 void button_scale_press ();
489 void button_mix_press ();
491 void button_upper (uint32_t n);
492 void button_lower (uint32_t n);
494 void button_upper_1 () { button_upper (0); }
495 void button_upper_2 () { button_upper (1); }
496 void button_upper_3 () { button_upper (2); }
497 void button_upper_4 () { button_upper (3); }
498 void button_upper_5 () { button_upper (4); }
499 void button_upper_6 () { button_upper (5); }
500 void button_upper_7 () { button_upper (6); }
501 void button_upper_8 () { button_upper (7); }
502 void button_lower_1 () { button_lower (0); }
503 void button_lower_2 () { button_lower (1); }
504 void button_lower_3 () { button_lower (2); }
505 void button_lower_4 () { button_lower (3); }
506 void button_lower_5 () { button_lower (4); }
507 void button_lower_6 () { button_lower (5); }
508 void button_lower_7 () { button_lower (6); }
509 void button_lower_8 () { button_lower (7); }
514 /* non-strip encoders */
516 void other_vpot (int, int);
517 void other_vpot_touch (int, bool);
519 /* special Stripables */
521 boost::shared_ptr<ARDOUR::Stripable> master;
522 boost::shared_ptr<ARDOUR::Stripable> monitor;
524 sigc::connection vblank_connection;
528 ARDOUR::microseconds_t splash_start;
532 Push2Canvas* _canvas;
536 mutable Glib::Threads::Mutex layout_lock;
537 Push2Layout* _current_layout;
538 Push2Layout* _previous_layout;
539 Push2Layout* mix_layout;
540 Push2Layout* scale_layout;
541 Push2Layout* track_mix_layout;
542 Push2Layout* splash_layout;
543 void set_current_layout (Push2Layout*);
545 bool pad_filter (ARDOUR::MidiBuffer& in, ARDOUR::MidiBuffer& out) const;
547 boost::weak_ptr<ARDOUR::MidiTrack> current_pad_target;
549 PBD::ScopedConnection port_reg_connection;
550 void port_registration_handler ();
552 enum ConnectionState {
553 InputConnected = 0x1,
554 OutputConnected = 0x2
557 int connection_state;
558 bool connection_handler (boost::weak_ptr<ARDOUR::Port>, std::string name1, boost::weak_ptr<ARDOUR::Port>, std::string name2, bool yn);
559 PBD::ScopedConnection port_connection;
569 PBD::ScopedConnection selection_connection;
570 void stripable_selection_change (ARDOUR::StripableNotificationListPtr);
572 MusicalMode::Type _mode;
580 void set_percussive_mode (bool);
582 /* color map (device side) */
584 typedef std::map<ArdourCanvas::Color,uint8_t> ColorMap;
585 typedef std::stack<uint8_t> ColorMapFreeList;
587 ColorMapFreeList color_map_free_list;
588 void build_color_map ();
592 typedef std::map<ColorName,ArdourCanvas::Color> Colors;
594 void fill_color_table ();
595 void reset_pad_colors ();
597 PressureMode _pressure_mode;
598 void request_pressure_mode ();
600 uint8_t selection_color;
601 uint8_t contrast_color;
606 #endif /* __ardour_push2_h__ */