MCP: make v-pot press work; work ongoing on general keybindings
[ardour.git] / libs / surfaces / mackie / surface.h
1 #ifndef mackie_surface_h
2 #define mackie_surface_h
3
4 #include <stdint.h>
5
6 #include "midi++/types.h"
7
8 #include "control_protocol/types.h"
9
10 #include "controls.h"
11 #include "types.h"
12 #include "mackie_jog_wheel.h"
13
14 namespace MIDI {
15         class Parser;
16 }
17
18 namespace ARDOUR {
19         class Route;
20 }
21
22 class MidiByteArray;
23 class MackieControlProtocol;
24
25 namespace Mackie
26 {
27
28 class MackieButtonHandler;
29 class SurfacePort;
30 class MackieMidiBuilder;
31 class Button;
32 class Meter;
33 class Fader;
34 class Jog;
35 class Pot;
36 class Led;
37
38 class Surface : public PBD::ScopedConnectionList
39 {
40 public:
41         Surface (MackieControlProtocol&, const std::string& name, uint32_t number, surface_type_t stype);
42         virtual ~Surface();
43
44         surface_type_t type() const { return _stype; }
45         uint32_t number() const { return _number; }
46         const std::string& name() { return _name; }
47
48         bool active() const { return _active; }
49         void drop_routes ();
50
51         typedef std::vector<Control*> Controls;
52         Controls controls;
53
54         std::map<int,Fader*> faders;
55         std::map<int,Pot*> pots;
56         std::map<int,Button*> buttons; // index is device-DEPENDENT
57         std::map<int,Led*> leds;
58         std::map<int,Meter*> meters;
59         std::map<int,Control*> controls_by_device_independent_id;
60         
61         Mackie::JogWheel* jog_wheel() const { return _jog_wheel; }
62         Fader* master_fader() const { return _master_fader; }
63
64         /// The collection of all numbered strips.
65         typedef std::vector<Strip*> Strips;
66         Strips strips;
67
68         uint32_t n_strips () const;
69         Strip* nth_strip (uint32_t n) const;
70
71         /// This collection owns the groups
72         typedef std::map<std::string,Group*> Groups;
73         Groups groups;
74
75         SurfacePort& port() const { return *_port; }
76
77         void map_routes (const std::vector<boost::shared_ptr<ARDOUR::Route> >& routes);
78
79         const MidiByteArray& sysex_hdr() const;
80
81         void periodic (uint64_t now_usecs);
82
83         void handle_midi_pitchbend_message (MIDI::Parser&, MIDI::pitchbend_t, uint32_t channel_id);
84         void handle_midi_controller_message (MIDI::Parser&, MIDI::EventTwoBytes*);
85         void handle_midi_note_on_message (MIDI::Parser&, MIDI::EventTwoBytes*);
86
87         /// Connect the any signal from the parser to handle_midi_any
88         /// unless it's already connected
89         void connect_to_signals ();
90
91         /// notification from a MackiePort that it's now inactive
92         void handle_port_inactive(Mackie::SurfacePort *);
93
94         /// write a sysex message
95         void write_sysex (const MidiByteArray& mba);
96         void write_sysex (MIDI::byte msg);
97         /// proxy write for port
98         void write (const MidiByteArray&);
99
100         /// display an indicator of the first switched-in Route. Do nothing by default.
101         void display_bank_start (uint32_t /*current_bank*/);
102                 
103         /// called from MackieControlProtocol::zero_all to turn things off
104         void zero_all ();
105
106         /// turn off leds around the jog wheel. This is for surfaces that use a pot
107         /// pretending to be a jog wheel.
108         void blank_jog_ring ();
109
110         bool has_timecode_display() const;
111         void display_timecode (const std::string & /*timecode*/, const std::string & /*timecode_last*/);
112
113         /**
114                 This is used to calculate the clicks per second that define
115                 a transport speed of 1.0 for the jog wheel. 100.0 is 10 clicks
116                 per second, 50.5 is 5 clicks per second.
117         */
118         float scrub_scaling_factor() const;
119
120         /**
121                 The scaling factor function for speed increase and decrease. At
122                 low transport speeds this should return a small value, for high transport
123                 speeds, this should return an exponentially larger value. This provides
124                 high definition control at low speeds and quick speed changes to/from
125                 higher speeds.
126         */
127         float scaled_delta (float delta, float current_speed);
128
129         // display the first 2 chars of the msg in the 2 char display
130         // . is appended to the previous character, so A.B. would
131         // be two characters
132         MidiByteArray two_char_display (const std::string & msg, const std::string & dots = "  ");
133         MidiByteArray two_char_display (unsigned int value, const std::string & dots = "  ");
134         
135         /**
136                 Timecode display. Only the difference between timecode and last_timecode will
137                 be encoded, to save midi bandwidth. If they're the same, an empty array will
138                 be returned
139         */
140         MidiByteArray timecode_display (const std::string & timecode, const std::string & last_timecode = "");
141
142         void update_view_mode_display ();
143         void update_flip_mode_display ();
144
145         void gui_selection_changed (ARDOUR::RouteNotificationListPtr);
146
147         MackieControlProtocol& mcp() const { return _mcp; }
148
149   protected:
150         
151   private:
152         MackieControlProtocol& _mcp;
153         SurfacePort*           _port;
154         surface_type_t         _stype;
155         uint32_t               _number;
156         std::string            _name;
157         bool                   _active;
158         bool                   _connected;
159         Mackie::JogWheel*      _jog_wheel;
160         Fader*                 _master_fader;
161
162         void jog_wheel_state_display (Mackie::JogWheel::State state);
163         void handle_midi_sysex (MIDI::Parser&, MIDI::byte *, size_t count);
164         MidiByteArray host_connection_query (MidiByteArray& bytes);
165         MidiByteArray host_connection_confirmation (const MidiByteArray& bytes);
166
167         void init_controls();
168         void init_strips (uint32_t n);
169         void setup_master ();
170         void master_gain_changed ();
171 };
172
173 }
174
175 #endif