Fix MCP send display value scaling.
[ardour.git] / libs / surfaces / faderport / faderport.h
index 94ac2dcfede4dd3f0b53221497a6f0d22b24fd19..9227f1f39fce4c7636ea3c44c3f31ef9a7ecec8f 100644 (file)
@@ -22,6 +22,7 @@
 
 #include <list>
 #include <map>
+#include <set>
 #include <glibmm/threads.h>
 
 #define ABSTRACT_UI_EXPORTS
@@ -54,6 +55,7 @@ namespace MIDI {
 
 namespace ARDOUR {
        class AsyncMIDIPort;
+       class Bundle;
        class Port;
        class Session;
        class MidiPort;
@@ -79,19 +81,11 @@ class FaderPort : public ARDOUR::ControlProtocol, public AbstractUI<FaderPortReq
 
        int set_active (bool yn);
 
-       /* It would be nice to send a device query message here to see if
-        * faderport is out there. But the probe() API doesn't provide
-        * a set of ports to be checked, so there's really no nice
-        * way to do this. We would have to fall back on the PortManager
-        * and get a list of all physical ports. Could be done ....
+       /* we probe for a device when our ports are connected. Before that,
+          there's no way to know if the device exists or not.
         */
        static bool probe() { return true; }
 
-       void set_feedback_interval (ARDOUR::microseconds_t);
-
-       int set_feedback (bool yn);
-       bool get_feedback () const;
-
        XMLNode& get_state ();
        int set_state (const XMLNode&, int version);
 
@@ -99,78 +93,32 @@ class FaderPort : public ARDOUR::ControlProtocol, public AbstractUI<FaderPortReq
        void* get_gui () const;
        void  tear_down_gui ();
 
-       void set_current_bank (uint32_t);
-       void next_bank ();
-       void prev_bank ();
-
-       void reset_controllables ();
-
-       void set_motorised (bool);
-
-       bool motorised () const {
-               return _motorised;
-       }
-
-       void set_threshold (int);
-
-       int threshold () const {
-               return _threshold;
-       }
-
-       bool device_active() const { return _device_active; }
+       /* Note: because the FaderPort speaks an inherently duplex protocol,
+          we do not implement get/set_feedback() since this aspect of
+          support for the protocol is not optional.
+       */
 
        void do_request (FaderPortRequest*);
        int stop ();
 
        void thread_init ();
 
-  private:
-       boost::shared_ptr<ARDOUR::AsyncMIDIPort> _input_port;
-       boost::shared_ptr<ARDOUR::AsyncMIDIPort> _output_port;
-
-       ARDOUR::microseconds_t _feedback_interval;
-       ARDOUR::microseconds_t last_feedback_time;
-       int native_counter;
-
-       bool  do_feedback;
-       void  send_feedback ();
-
-       PBD::ScopedConnectionList midi_connections;
-
-       bool midi_input_handler (Glib::IOCondition ioc, boost::shared_ptr<ARDOUR::AsyncMIDIPort> port);
-
-       std::string _current_binding;
-       uint32_t _bank_size;
-       uint32_t _current_bank;
-       /** true if this surface is motorised.  If it is, we assume
-           that the surface's controls are never out of sync with
-           Ardour's state, so we don't have to take steps to avoid
-           values jumping around when things are not in sync.
-       */
-       bool _motorised;
-       int _threshold;
-
-       mutable void *gui;
-       void build_gui ();
-
-       bool connection_handler (boost::weak_ptr<ARDOUR::Port>, std::string name1, boost::weak_ptr<ARDOUR::Port>, std::string name2, bool yn);
-       PBD::ScopedConnection port_connection;
-
-       enum ConnectionState {
-               InputConnected = 0x1,
-               OutputConnected = 0x2
-       };
-
-       int connection_state;
-       void connected ();
-       bool _device_active;
-       int fader_msb;
-       int fader_lsb;
-
-       void sysex_handler (MIDI::Parser &p, MIDI::byte *, size_t);
-       void switch_handler (MIDI::Parser &, MIDI::EventTwoBytes* tb);
-       void encoder_handler (MIDI::Parser &, MIDI::pitchbend_t pb);
-       void fader_handler (MIDI::Parser &, MIDI::EventTwoBytes* tb);
+       PBD::Signal0<void> ConnectionChange;
+
+       boost::shared_ptr<ARDOUR::Port> input_port();
+       boost::shared_ptr<ARDOUR::Port> output_port();
+
+       /* In a feat of engineering brilliance, the Presonus Faderport sends
+        * one button identifier when the button is pressed/released, but
+        * responds to another button identifier as a command to light the LED
+        * corresponding to the button. These ID's define what is sent
+        * for press/release; a separate data structure contains information
+        * on what to send to turn the LED on/off.
+        *
+        * One can only conclude that Presonus just didn't want to fix this
+        * issue because it contradicts their own documentation and is more or
+        * less the first thing you discover when programming the device.
+        */
 
        enum ButtonID {
                Mute = 18,
@@ -180,10 +128,10 @@ class FaderPort : public ARDOUR::ControlProtocol, public AbstractUI<FaderPortReq
                Bank = 20,
                Right = 21,
                Output = 22,
-               Read = 10,
-               Write = 9,
-               Touch = 8,
-               Off = 23,
+               FP_Read = 10,
+               FP_Write = 9,
+               FP_Touch = 8,
+               FP_Off = 23,
                Mix = 11,
                Proj = 12,
                Trns = 13,
@@ -204,13 +152,64 @@ class FaderPort : public ARDOUR::ControlProtocol, public AbstractUI<FaderPortReq
                ShiftDown = 0x1,
                RewindDown = 0x2,
                StopDown = 0x4,
+               UserDown = 0x8,
+               LongPress = 0x10
        };
 
+       void set_action (ButtonID, std::string const& action_name, bool on_press, FaderPort::ButtonState = ButtonState (0));
+       std::string get_action (ButtonID, bool on_press, FaderPort::ButtonState = ButtonState (0));
+
+       std::list<boost::shared_ptr<ARDOUR::Bundle> > bundles ();
+       
+  private:
+       boost::shared_ptr<ARDOUR::Route> _current_route;
+       boost::weak_ptr<ARDOUR::Route> pre_master_route;
+       boost::weak_ptr<ARDOUR::Route> pre_monitor_route;
+
+       boost::shared_ptr<ARDOUR::AsyncMIDIPort> _input_port;
+       boost::shared_ptr<ARDOUR::AsyncMIDIPort> _output_port;
+
+       // Bundle to represent our input ports
+       boost::shared_ptr<ARDOUR::Bundle> _input_bundle;
+       // Bundle to represent our output ports
+       boost::shared_ptr<ARDOUR::Bundle> _output_bundle;
+
+       PBD::ScopedConnectionList midi_connections;
+
+       bool midi_input_handler (Glib::IOCondition ioc, boost::shared_ptr<ARDOUR::AsyncMIDIPort> port);
+
+       mutable void *gui;
+       void build_gui ();
+
+       bool connection_handler (boost::weak_ptr<ARDOUR::Port>, std::string name1, boost::weak_ptr<ARDOUR::Port>, std::string name2, bool yn);
+       PBD::ScopedConnection port_connection;
+
+       enum ConnectionState {
+               InputConnected = 0x1,
+               OutputConnected = 0x2
+       };
+
+       int connection_state;
+       void connected ();
+       bool _device_active;
+       int fader_msb;
+       int fader_lsb;
+       bool fader_is_touched;
+
+       ARDOUR::microseconds_t last_encoder_time;
+       int last_good_encoder_delta;
+       int last_encoder_delta, last_last_encoder_delta;
+
+       void sysex_handler (MIDI::Parser &p, MIDI::byte *, size_t);
+       void button_handler (MIDI::Parser &, MIDI::EventTwoBytes* tb);
+       void encoder_handler (MIDI::Parser &, MIDI::pitchbend_t pb);
+       void fader_handler (MIDI::Parser &, MIDI::EventTwoBytes* tb);
+
        ButtonState button_state;
 
-       friend class ButtonInfo;
+       friend class Button;
 
-       class ButtonInfo {
+       class Button {
          public:
 
                enum ActionType {
@@ -218,36 +217,40 @@ class FaderPort : public ARDOUR::ControlProtocol, public AbstractUI<FaderPortReq
                        InternalFunction,
                };
 
-               ButtonInfo (FaderPort& f, std::string const& str, ButtonID i, int o)
+               Button (FaderPort& f, std::string const& str, ButtonID i, int o)
                        : fp (f)
                        , name (str)
                        , id (i)
                        , out (o)
-                       , type (NamedAction)
-                       , led_on (false)
                        , flash (false)
                {}
 
                void set_action (std::string const& action_name, bool on_press, FaderPort::ButtonState = ButtonState (0));
                void set_action (boost::function<void()> function, bool on_press, FaderPort::ButtonState = ButtonState (0));
-               void set_led_state (boost::shared_ptr<MIDI::Port>, int onoff, bool force = false);
+               std::string get_action (bool press, FaderPort::ButtonState bs = ButtonState (0));
+
+               void set_led_state (boost::shared_ptr<MIDI::Port>, bool onoff);
                void invoke (ButtonState bs, bool press);
                bool uses_flash () const { return flash; }
                void set_flash (bool yn) { flash = yn; }
 
+               XMLNode& get_state () const;
+               int set_state (XMLNode const&);
+
+               sigc::connection timeout_connection;
+
          private:
                FaderPort& fp;
                std::string name;
                ButtonID id;
                int out;
-               ActionType type;
-               bool led_on;
                bool flash;
 
-               /* could be a union if boost::function didn't require a
-                * constructor
-                */
                struct ToDo {
+                       ActionType type;
+                       /* could be a union if boost::function didn't require a
+                        * constructor
+                        */
                        std::string action_name;
                        boost::function<void()> function;
                };
@@ -257,10 +260,16 @@ class FaderPort : public ARDOUR::ControlProtocol, public AbstractUI<FaderPortReq
                ToDoMap on_release;
        };
 
-       typedef std::map<ButtonID,ButtonInfo> ButtonMap;
+       typedef std::map<ButtonID,Button> ButtonMap;
 
        ButtonMap buttons;
-       ButtonInfo& button_info (ButtonID) const;
+       Button& get_button (ButtonID) const;
+
+       std::set<ButtonID> buttons_down;
+       std::set<ButtonID> consumed;
+
+       bool button_long_press_timeout (ButtonID id);
+       void start_press_timeout (Button&, ButtonID);
 
        void all_lights_out ();
        void close ();
@@ -269,19 +278,57 @@ class FaderPort : public ARDOUR::ControlProtocol, public AbstractUI<FaderPortReq
 
        PBD::ScopedConnectionList session_connections;
        void connect_session_signals ();
-       void notify_record_state_changed ();
-       void notify_transport_state_changed ();
+       void map_recenable_state ();
+       void map_transport_state ();
 
        sigc::connection blink_connection;
        typedef std::list<ButtonID> Blinkers;
        Blinkers blinkers;
        bool blink_state;
        bool blink ();
+       void start_blinking (ButtonID);
+       void stop_blinking (ButtonID);
+
+       void set_current_route (boost::shared_ptr<ARDOUR::Route>);
+       void drop_current_route ();
+       void use_master ();
+       void use_monitor ();
+       void gui_track_selection_changed (ARDOUR::RouteNotificationListPtr);
+       PBD::ScopedConnection selection_connection;
+       PBD::ScopedConnectionList route_connections;
+
+       void map_route_state ();
+       void map_solo (bool,void*,bool);
+       void map_listen (void*,bool);
+       void map_mute (void*);
+       void map_recenable ();
+       void map_gain ();
+       void map_cut ();
+       void map_auto ();
+       void parameter_changed (std::string);
 
        /* operations (defined in operations.cc) */
 
+       void read ();
+       void write ();
+
+       void left ();
+       void right ();
+
+       void touch ();
+       void off ();
+
        void undo ();
        void redo ();
+       void solo ();
+       void mute ();
+       void rec_enable ();
+
+       void ardour_pan_azimuth (int);
+       void ardour_pan_width (int);
+       void mixbus_pan (int);
+
+       void punch ();
 };
 
 }