ptformat: Update the lib to 9d0b64f (upstream ptformat)
[ardour.git] / libs / surfaces / push2 / push2.h
index be4c116895e95fd9b9e80f06970a1c09211e6037..bb34f7c016d6cef14163ff48f9f4f2e4814dda96 100644 (file)
 
 #include <libusb.h>
 
-#include <cairomm/refptr.h>
-
 #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 "midi_byte_array.h"
-#include "mode.h"
+#include "canvas/colors.h"
 
-namespace Cairo {
-       class ImageSurface;
-       class Context;
-}
+#include "midi_byte_array.h"
 
 namespace Pango {
        class Layout;
@@ -74,6 +69,7 @@ public:
 class P2GUI;
 class Push2Menu;
 class Push2Layout;
+class Push2Canvas;
 
 class Push2 : public ARDOUR::ControlProtocol
             , public AbstractUI<Push2Request>
@@ -333,7 +329,10 @@ class Push2 : public ARDOUR::ControlProtocol
        int pad_note (int row, int col) const;
        PBD::Signal0<void> PadChange;
 
+       void update_selection_color ();
+
        void set_pad_scale (int root, int octave, MusicalMode::Type mode, bool inkey);
+       PBD::Signal0<void> ScaleChange;
 
        MusicalMode::Type mode() const { return  _mode; }
        int scale_root() const { return _scale_root; }
@@ -341,6 +340,9 @@ class Push2 : public ARDOUR::ControlProtocol
        bool in_key() const { return _in_key; }
 
        Push2Layout* current_layout() const;
+       void         use_previous_layout ();
+
+       Push2Canvas* canvas() const { return _canvas; }
 
        enum ModifierState {
                None = 0,
@@ -351,39 +353,36 @@ class Push2 : public ARDOUR::ControlProtocol
        ModifierState modifier_state() const { return _modifier_state; }
 
        Button* button_by_id (ButtonID);
+       static std::string button_name_by_id (ButtonID);
 
-       void write (const MidiByteArray&);
+       void strip_buttons_off ();
 
-       uint8_t get_color_index (uint32_t rgb);
-       uint32_t get_color (ColorName);
+       void write (const MidiByteArray&);
 
-       static const int cols;
-       static const int rows;
+       uint8_t get_color_index (ArdourCanvas::Color rgba);
+       ArdourCanvas::Color get_color (ColorName);
 
        PressureMode pressure_mode () const { return _pressure_mode; }
        void set_pressure_mode (PressureMode);
        PBD::Signal1<void,PressureMode> PressureModeChange;
-       
+
+       libusb_device_handle* usb_handle() const { return handle; }
+
   private:
        libusb_device_handle *handle;
-       uint8_t   frame_header[16];
-       uint16_t* device_frame_buffer;
-       int  device_buffer;
-       Cairo::RefPtr<Cairo::ImageSurface> frame_buffer;
-       sigc::connection vblank_connection;
-       sigc::connection periodic_connection;
-
+       bool in_use;
        ModifierState _modifier_state;
 
-       static const int pixels_per_row;
-
        void do_request (Push2Request*);
-       int stop ();
-       int open ();
-       int close ();
-       bool redraw ();
-       int blit_to_device_frame_buffer ();
-       bool vblank ();
+
+       int begin_using_device ();
+       int stop_using_device ();
+       int device_acquire ();
+       void device_release ();
+       int ports_acquire ();
+       void ports_release ();
+       void run_event_loop ();
+       void stop_event_loop ();
 
        void relax () {}
 
@@ -402,10 +401,17 @@ class Push2 : public ARDOUR::ControlProtocol
        void init_buttons (bool startup);
        void init_touch_strip ();
 
-       /* map of Pads by note number */
+       /* map of Pads by note number (the "fixed" note number sent by the
+        * hardware, not the note number generated if the pad is touched)
+        */
        typedef std::map<int,Pad*> NNPadMap;
        NNPadMap nn_pad_map;
 
+       /* map of Pads by note number they generate (their "filtered" value)
+        */
+       typedef std::multimap<int,Pad*> FNPadMap;
+       FNPadMap fn_pad_map;
+
        void set_button_color (ButtonID, uint8_t color_index);
        void set_button_state (ButtonID, LED::State);
        void set_led_color (ButtonID, uint8_t color_index);
@@ -431,7 +437,6 @@ class Push2 : public ARDOUR::ControlProtocol
        void handle_midi_sysex (MIDI::Parser&, MIDI::byte *, size_t count);
 
        bool midi_input_handler (Glib::IOCondition ioc, MIDI::Port* port);
-       bool periodic ();
 
        void thread_init ();
 
@@ -470,6 +475,9 @@ class Push2 : public ARDOUR::ControlProtocol
        void button_fwd4 ();
        void button_add_track ();
        void button_stop ();
+       void button_master ();
+       void button_quantize ();
+       void button_duplicate ();
        void button_shift_press ();
        void button_shift_release ();
        void button_shift_long_press ();
@@ -512,26 +520,29 @@ class Push2 : public ARDOUR::ControlProtocol
        void other_vpot (int, int);
        void other_vpot_touch (int, bool);
 
-       /* special Stripables */
+       /* special Stripable */
 
        boost::shared_ptr<ARDOUR::Stripable> master;
-       boost::shared_ptr<ARDOUR::Stripable> monitor;
-
-       /* Cairo graphics context */
 
-       Cairo::RefPtr<Cairo::Context> context;
+       sigc::connection vblank_connection;
+       bool vblank ();
 
        void splash ();
        ARDOUR::microseconds_t splash_start;
 
+       /* the canvas */
+
+       Push2Canvas* _canvas;
+
        /* Layouts */
 
        mutable Glib::Threads::Mutex layout_lock;
        Push2Layout* _current_layout;
-       Push2Layout* drawn_layout;
+       Push2Layout* _previous_layout;
        Push2Layout* mix_layout;
        Push2Layout* scale_layout;
        Push2Layout* track_mix_layout;
+       Push2Layout* splash_layout;
        void set_current_layout (Push2Layout*);
 
        bool pad_filter (ARDOUR::MidiBuffer& in, ARDOUR::MidiBuffer& out) const;
@@ -573,7 +584,7 @@ class Push2 : public ARDOUR::ControlProtocol
 
        /* color map (device side) */
 
-       typedef std::map<uint32_t,uint8_t> ColorMap;
+       typedef std::map<ArdourCanvas::Color,uint8_t> ColorMap;
        typedef std::stack<uint8_t> ColorMapFreeList;
        ColorMap color_map;
        ColorMapFreeList color_map_free_list;
@@ -581,12 +592,18 @@ class Push2 : public ARDOUR::ControlProtocol
 
        /* our own colors */
 
-       typedef std::map<ColorName,uint32_t> Colors;
+       typedef std::map<ColorName,ArdourCanvas::Color> Colors;
        Colors colors;
        void fill_color_table ();
+       void reset_pad_colors ();
 
        PressureMode _pressure_mode;
        void request_pressure_mode ();
+
+       uint8_t selection_color;
+       uint8_t contrast_color;
+
+       bool in_range_select;
 };
 
 } /* namespace */