1 #ifndef mackie_surface_h
2 #define mackie_surface_h
6 #include "pbd/signals.h"
8 #include "midi++/types.h"
10 #include "ardour/types.h"
12 #include "control_protocol/types.h"
16 #include "jog_wheel.h"
29 namespace ArdourSurface {
31 class MackieControlProtocol;
36 class MackieButtonHandler;
38 class MackieMidiBuilder;
46 class Surface : public PBD::ScopedConnectionList
49 Surface (MackieControlProtocol&, const std::string& name, uint32_t number, surface_type_t stype);
52 surface_type_t type() const { return _stype; }
53 uint32_t number() const { return _number; }
54 const std::string& name() { return _name; }
58 bool active() const { return _active; }
60 typedef std::vector<Control*> Controls;
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;
70 Mackie::JogWheel* jog_wheel() const { return _jog_wheel; }
71 Fader* master_fader() const { return _master_fader; }
73 /// The collection of all numbered strips.
74 typedef std::vector<Strip*> Strips;
77 uint32_t n_strips (bool with_locked_strips = true) const;
78 Strip* nth_strip (uint32_t n) const;
80 bool route_is_locked_to_strip (boost::shared_ptr<ARDOUR::Route>) const;
82 /// This collection owns the groups
83 typedef std::map<std::string,Group*> Groups;
86 SurfacePort& port() const { return *_port; }
88 void map_routes (const std::vector<boost::shared_ptr<ARDOUR::Route> >& routes);
90 const MidiByteArray& sysex_hdr() const;
92 void periodic (uint64_t now_usecs);
94 void hui_heartbeat ();
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*);
100 /// Connect the any signal from the parser to handle_midi_any
101 /// unless it's already connected
102 void connect_to_signals ();
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&);
110 /// display an indicator of the first switched-in Route. Do nothing by default.
111 void display_bank_start (uint32_t /*current_bank*/);
113 /// called from MackieControlProtocol::zero_all to turn things off
115 void zero_controls ();
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 ();
121 void display_timecode (const std::string & /*timecode*/, const std::string & /*timecode_last*/);
123 /// sends MCP "reset" message to surface
126 void recalibrate_faders ();
127 void toggle_backlight ();
128 void set_touch_sensitivity (int);
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.
135 float scrub_scaling_factor() const;
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
144 float scaled_delta (float delta, float current_speed);
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
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 = " ");
152 void update_view_mode_display ();
153 void update_flip_mode_display ();
155 void gui_selection_changed (const ARDOUR::StrongRouteNotificationList&);
157 MackieControlProtocol& mcp() const { return _mcp; }
159 void next_jog_mode ();
160 void set_jog_mode (Mackie::JogWheel::Mode);
162 void notify_metering_state_changed();
165 XMLNode& get_state ();
166 int set_state (const XMLNode&, int version);
171 MackieControlProtocol& _mcp;
173 surface_type_t _stype;
178 Mackie::JogWheel* _jog_wheel;
179 Fader* _master_fader;
180 float _last_master_gain_written;
181 PBD::ScopedConnection port_connection;
183 void handle_midi_sysex (MIDI::Parser&, MIDI::byte *, size_t count);
184 MidiByteArray host_connection_query (MidiByteArray& bytes);
185 MidiByteArray host_connection_confirmation (const MidiByteArray& bytes);
188 void init_controls ();
189 void init_strips (uint32_t n);
190 void setup_master ();
191 void master_gain_changed ();
192 void connection_handler (boost::weak_ptr<ARDOUR::Port>, std::string name1, boost::weak_ptr<ARDOUR::Port>, std::string name2, bool);
194 enum ConnectionState {
195 InputConnected = 0x1,
196 OutputConnected = 0x2
199 int connection_state;
201 /* this times the duration between press+release events for all
202 possible 127 buttons on THIS surface (not all surfaces).
205 ARDOUR::microseconds_t button_timer[127];