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