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