Add Trim to Mackie controls.
[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 "pbd/signals.h"
7 #include "pbd/xml++.h"
8 #include "midi++/types.h"
9
10 #include "ardour/types.h"
11
12 #include "control_protocol/types.h"
13
14 #include "controls.h"
15 #include "types.h"
16 #include "jog_wheel.h"
17
18 namespace MIDI {
19         class Parser;
20 }
21
22 namespace ARDOUR {
23         class Route;
24         class Port;
25 }
26
27 class MidiByteArray;
28
29 namespace ArdourSurface {
30
31 class MackieControlProtocol;
32
33 namespace Mackie
34 {
35
36 class MackieButtonHandler;
37 class SurfacePort;
38 class MackieMidiBuilder;
39 class Button;
40 class Meter;
41 class Fader;
42 class Jog;
43 class Pot;
44 class Led;
45
46 class Surface : public PBD::ScopedConnectionList
47 {
48 public:
49         Surface (MackieControlProtocol&, const std::string& name, uint32_t number, surface_type_t stype);
50         virtual ~Surface();
51
52         surface_type_t type() const { return _stype; }
53         uint32_t number() const { return _number; }
54         const std::string& name() { return _name; }
55
56         void connected ();
57
58         bool active() const { return _active; }
59
60         typedef std::vector<Control*> Controls;
61         Controls controls;
62
63         std::map<int,Fader*> faders;
64         std::map<int,Pot*> pots;
65         std::map<int,Button*> buttons; // index is device-DEPENDENT
66         std::map<int,Led*> leds;
67         std::map<int,Meter*> meters;
68         std::map<int,Control*> controls_by_device_independent_id;
69
70         Mackie::JogWheel* jog_wheel() const { return _jog_wheel; }
71         Fader* master_fader() const { return _master_fader; }
72
73         /// The collection of all numbered strips.
74         typedef std::vector<Strip*> Strips;
75         Strips strips;
76
77         uint32_t n_strips (bool with_locked_strips = true) const;
78         Strip* nth_strip (uint32_t n) const;
79
80         bool route_is_locked_to_strip (boost::shared_ptr<ARDOUR::Route>) const;
81
82         /// This collection owns the groups
83         typedef std::map<std::string,Group*> Groups;
84         Groups groups;
85
86         SurfacePort& port() const { return *_port; }
87
88         void map_routes (const std::vector<boost::shared_ptr<ARDOUR::Route> >& routes);
89
90         const MidiByteArray& sysex_hdr() const;
91
92         void periodic (uint64_t now_usecs);
93         void redisplay ();
94         void hui_heartbeat ();
95
96         void handle_midi_pitchbend_message (MIDI::Parser&, MIDI::pitchbend_t, uint32_t channel_id);
97         void handle_midi_controller_message (MIDI::Parser&, MIDI::EventTwoBytes*);
98         void handle_midi_note_on_message (MIDI::Parser&, MIDI::EventTwoBytes*);
99
100         /// Connect the any signal from the parser to handle_midi_any
101         /// unless it's already connected
102         void connect_to_signals ();
103
104         /// write a sysex message
105         void write_sysex (const MidiByteArray& mba);
106         void write_sysex (MIDI::byte msg);
107         /// proxy write for port
108         void write (const MidiByteArray&);
109
110         /// display an indicator of the first switched-in Route. Do nothing by default.
111         void display_bank_start (uint32_t /*current_bank*/);
112
113         /// called from MackieControlProtocol::zero_all to turn things off
114         void zero_all ();
115         void zero_controls ();
116
117         /// turn off leds around the jog wheel. This is for surfaces that use a pot
118         /// pretending to be a jog wheel.
119         void blank_jog_ring ();
120
121         void display_timecode (const std::string & /*timecode*/, const std::string & /*timecode_last*/);
122
123         /// sends MCP "reset" message to surface
124         void reset ();
125
126         void recalibrate_faders ();
127         void toggle_backlight ();
128         void set_touch_sensitivity (int);
129
130         /**
131                 This is used to calculate the clicks per second that define
132                 a transport speed of 1.0 for the jog wheel. 100.0 is 10 clicks
133                 per second, 50.5 is 5 clicks per second.
134         */
135         float scrub_scaling_factor() const;
136
137         /**
138                 The scaling factor function for speed increase and decrease. At
139                 low transport speeds this should return a small value, for high transport
140                 speeds, this should return an exponentially larger value. This provides
141                 high definition control at low speeds and quick speed changes to/from
142                 higher speeds.
143         */
144         float scaled_delta (float delta, float current_speed);
145
146         // display the first 2 chars of the msg in the 2 char display
147         // . is appended to the previous character, so A.B. would
148         // be two characters
149         void show_two_char_display (const std::string & msg, const std::string & dots = "  ");
150         void show_two_char_display (unsigned int value, const std::string & dots = "  ");
151
152         void update_view_mode_display ();
153         void update_flip_mode_display ();
154         void update_potmode ();
155
156         void gui_selection_changed (const ARDOUR::StrongRouteNotificationList&);
157
158         MackieControlProtocol& mcp() const { return _mcp; }
159
160         void next_jog_mode ();
161         void set_jog_mode (Mackie::JogWheel::Mode);
162
163         void notify_metering_state_changed();
164         void turn_it_on ();
165
166         XMLNode& get_state ();
167         int set_state (const XMLNode&, int version);
168
169   protected:
170
171   private:
172         MackieControlProtocol& _mcp;
173         SurfacePort*           _port;
174         surface_type_t         _stype;
175         uint32_t               _number;
176         std::string            _name;
177         bool                   _active;
178         bool                   _connected;
179         Mackie::JogWheel*      _jog_wheel;
180         Fader*                 _master_fader;
181         float                  _last_master_gain_written;
182         PBD::ScopedConnection   port_connection;
183
184         void handle_midi_sysex (MIDI::Parser&, MIDI::byte *, size_t count);
185         MidiByteArray host_connection_query (MidiByteArray& bytes);
186         MidiByteArray host_connection_confirmation (const MidiByteArray& bytes);
187
188         void say_hello ();
189         void init_controls ();
190         void init_strips (uint32_t n);
191         void setup_master ();
192         void master_gain_changed ();
193         void connection_handler (boost::weak_ptr<ARDOUR::Port>, std::string name1, boost::weak_ptr<ARDOUR::Port>, std::string name2, bool);
194
195         enum ConnectionState {
196                 InputConnected = 0x1,
197                 OutputConnected = 0x2
198         };
199
200         int connection_state;
201
202         /* this times the duration between press+release events for all
203            possible 127 buttons on THIS surface (not all surfaces).
204         */
205
206         ARDOUR::microseconds_t button_timer[127];
207 };
208
209 }
210 }
211
212 #endif