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