/* * Copyright (C) 2016-2018 Paul Davis * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef __ardour_push2_h__ #define __ardour_push2_h__ #include #include #include #include #include #include #define ABSTRACT_UI_EXPORTS #include "pbd/abstract_ui.h" #include "midi++/types.h" #include "ardour/mode.h" #include "ardour/types.h" #include "control_protocol/control_protocol.h" #include "control_protocol/types.h" #include "gtkmm2ext/colors.h" #include "midi_byte_array.h" namespace Pango { class Layout; } namespace MIDI { class Parser; class Port; } namespace ARDOUR { class AsyncMIDIPort; class Port; class MidiBuffer; class MidiTrack; } namespace ArdourSurface { struct Push2Request : public BaseUI::BaseRequestObject { public: Push2Request () {} ~Push2Request () {} }; class P2GUI; class Push2Menu; class Push2Layout; class Push2Canvas; class Push2 : public ARDOUR::ControlProtocol , public AbstractUI { public: enum ButtonID { TapTempo, Metronome, Upper1, Upper2, Upper3, Upper4, Upper5, Upper6, Upper7, Upper8, Setup, User, Delete, AddDevice, Device, Mix, Undo, AddTrack, Browse, Clip, Mute, Solo, Stop, Lower1, Lower2, Lower3, Lower4, Lower5, Lower6, Lower7, Lower8, Master, Convert, DoubleLoop, Quantize, Duplicate, New, FixedLength, Automate, RecordEnable, Play, Fwd32ndT, Fwd32nd, Fwd16thT, Fwd16th, Fwd8thT, Fwd8th, Fwd4trT, Fwd4tr, Up, Right, Down, Left, Repeat, Accent, Scale, Layout, Note, Session, OctaveUp, PageRight, OctaveDown, PageLeft, Shift, Select }; struct LED { enum State { NoTransition, OneShot24th, OneShot16th, OneShot8th, OneShot4th, OneShot2th, Pulsing24th, Pulsing16th, Pulsing8th, Pulsing4th, Pulsing2th, Blinking24th, Blinking16th, Blinking8th, Blinking4th, Blinking2th }; enum Colors { Black = 0, Red = 127, Green = 126, Blue = 125, DarkGray = 124, LightGray = 123, White = 122 }; LED (uint8_t e) : _extra (e), _color_index (Black), _state (NoTransition) {} virtual ~LED() {} uint8_t extra () const { return _extra; } uint8_t color_index () const { return _color_index; } State state () const { return _state; } void set_color (uint8_t color_index); void set_state (State state); virtual MidiByteArray state_msg() const = 0; protected: uint8_t _extra; uint8_t _color_index; State _state; }; struct Pad : public LED { enum WhenPressed { Nothing, FlashOn, FlashOff, }; Pad (int xx, int yy, uint8_t ex) : LED (ex) , x (xx) , y (yy) , do_when_pressed (FlashOn) , filtered (ex) , perma_color (LED::Black) {} MidiByteArray state_msg () const { return MidiByteArray (3, 0x90|_state, _extra, _color_index); } int coord () const { return (y * 8) + x; } int note_number() const { return extra(); } int x; int y; int do_when_pressed; int filtered; int perma_color; }; struct Button : public LED { Button (ButtonID bb, uint8_t ex) : LED (ex) , id (bb) , press_method (&Push2::relax) , release_method (&Push2::relax) , long_press_method (&Push2::relax) {} Button (ButtonID bb, uint8_t ex, void (Push2::*press)()) : LED (ex) , id (bb) , press_method (press) , release_method (&Push2::relax) , long_press_method (&Push2::relax) {} Button (ButtonID bb, uint8_t ex, void (Push2::*press)(), void (Push2::*release)()) : LED (ex) , id (bb) , press_method (press) , release_method (release) , long_press_method (&Push2::relax) {} Button (ButtonID bb, uint8_t ex, void (Push2::*press)(), void (Push2::*release)(), void (Push2::*long_press)()) : LED (ex) , id (bb) , press_method (press) , release_method (release) , long_press_method (long_press) {} MidiByteArray state_msg () const { return MidiByteArray (3, 0xb0|_state, _extra, _color_index); } int controller_number() const { return extra(); } ButtonID id; void (Push2::*press_method)(); void (Push2::*release_method)(); void (Push2::*long_press_method)(); sigc::connection timeout_connection; }; struct ColorButton : public Button { ColorButton (ButtonID bb, uint8_t ex) : Button (bb, ex) {} ColorButton (ButtonID bb, uint8_t ex, void (Push2::*press)()) : Button (bb, ex, press) {} ColorButton (ButtonID bb, uint8_t ex, void (Push2::*press)(), void (Push2::*release)()) : Button (bb, ex, press, release) {} ColorButton (ButtonID bb, uint8_t ex, void (Push2::*press)(), void (Push2::*release)(), void (Push2::*long_press)()) : Button (bb, ex, press, release, long_press) {} }; struct WhiteButton : public Button { WhiteButton (ButtonID bb, uint8_t ex) : Button (bb, ex) {} WhiteButton (ButtonID bb, uint8_t ex, void (Push2::*press)()) : Button (bb, ex, press) {} WhiteButton (ButtonID bb, uint8_t ex, void (Push2::*press)(), void (Push2::*release)()) : Button (bb, ex, press, release) {} WhiteButton (ButtonID bb, uint8_t ex, void (Push2::*press)(), void (Push2::*release)(), void (Push2::*long_press)()) : Button (bb, ex, press, release, long_press) {} }; enum ColorName { DarkBackground, LightBackground, ParameterName, StripableName, ClockText, KnobArcBackground, KnobArcStart, KnobArcEnd, KnobLine, KnobLineShadow, KnobForeground, KnobBackground, KnobShadow, KnobBorder, }; enum PressureMode { AfterTouch, PolyPressure, }; public: Push2 (ARDOUR::Session&); ~Push2 (); static bool probe (); static void* request_factory (uint32_t); std::list > bundles (); bool has_editor () const { return true; } void* get_gui () const; void tear_down_gui (); int set_active (bool yn); XMLNode& get_state(); int set_state (const XMLNode & node, int version); PBD::Signal0 ConnectionChange; boost::shared_ptr input_port(); boost::shared_ptr output_port(); int pad_note (int row, int col) const; PBD::Signal0 PadChange; void update_selection_color (); void set_pad_scale (int root, int octave, MusicalMode::Type mode, bool inkey); PBD::Signal0 ScaleChange; MusicalMode::Type mode() const { return _mode; } int scale_root() const { return _scale_root; } int root_octave() const { return _root_octave; } bool in_key() const { return _in_key; } Push2Layout* current_layout() const; void use_previous_layout (); Push2Canvas* canvas() const { return _canvas; } enum ModifierState { None = 0, ModShift = 0x1, ModSelect = 0x2, }; ModifierState modifier_state() const { return _modifier_state; } boost::shared_ptr