1 #ifndef mackie_surface_h
2 #define mackie_surface_h
6 #include <sigc++/trackable.h>
8 #include "pbd/signals.h"
10 #include "midi++/types.h"
12 #include "ardour/types.h"
14 #include "control_protocol/types.h"
18 #include "jog_wheel.h"
31 namespace ArdourSurface {
33 class MackieControlProtocol;
38 class MackieButtonHandler;
40 class MackieMidiBuilder;
48 class Surface : public PBD::ScopedConnectionList, public sigc::trackable
51 Surface (MackieControlProtocol&, const std::string& name, uint32_t number, surface_type_t stype);
54 surface_type_t type() const { return _stype; }
55 uint32_t number() const { return _number; }
56 const std::string& name() { return _name; }
60 bool active() const { return _active; }
62 typedef std::vector<Control*> Controls;
65 std::map<int,Fader*> faders;
66 std::map<int,Pot*> pots;
67 std::map<int,Button*> buttons; // index is device-DEPENDENT
68 std::map<int,Led*> leds;
69 std::map<int,Meter*> meters;
70 std::map<int,Control*> controls_by_device_independent_id;
72 Mackie::JogWheel* jog_wheel() const { return _jog_wheel; }
73 Fader* master_fader() const { return _master_fader; }
75 /// The collection of all numbered strips.
76 typedef std::vector<Strip*> Strips;
79 uint32_t n_strips (bool with_locked_strips = true) const;
80 Strip* nth_strip (uint32_t n) const;
82 bool route_is_locked_to_strip (boost::shared_ptr<ARDOUR::Route>) const;
84 /// This collection owns the groups
85 typedef std::map<std::string,Group*> Groups;
88 SurfacePort& port() const { return *_port; }
90 void map_routes (const std::vector<boost::shared_ptr<ARDOUR::Route> >& routes);
92 const MidiByteArray& sysex_hdr() const;
94 void periodic (ARDOUR::microseconds_t now_usecs);
95 void redisplay (ARDOUR::microseconds_t now_usecs);
96 void hui_heartbeat ();
98 void handle_midi_pitchbend_message (MIDI::Parser&, MIDI::pitchbend_t, uint32_t channel_id);
99 void handle_midi_controller_message (MIDI::Parser&, MIDI::EventTwoBytes*);
100 void handle_midi_note_on_message (MIDI::Parser&, MIDI::EventTwoBytes*);
102 /// Connect the any signal from the parser to handle_midi_any
103 /// unless it's already connected
104 void connect_to_signals ();
106 /// write a sysex message
107 void write_sysex (const MidiByteArray& mba);
108 void write_sysex (MIDI::byte msg);
109 /// proxy write for port
110 void write (const MidiByteArray&);
112 /// display an indicator of the first switched-in Route. Do nothing by default.
113 void display_bank_start (uint32_t /*current_bank*/);
115 /// called from MackieControlProtocol::zero_all to turn things off
117 void zero_controls ();
119 /// turn off leds around the jog wheel. This is for surfaces that use a pot
120 /// pretending to be a jog wheel.
121 void blank_jog_ring ();
123 void display_timecode (const std::string & /*timecode*/, const std::string & /*timecode_last*/);
125 /// sends MCP "reset" message to surface
128 void recalibrate_faders ();
129 void toggle_backlight ();
130 void set_touch_sensitivity (int);
133 This is used to calculate the clicks per second that define
134 a transport speed of 1.0 for the jog wheel. 100.0 is 10 clicks
135 per second, 50.5 is 5 clicks per second.
137 float scrub_scaling_factor() const;
140 The scaling factor function for speed increase and decrease. At
141 low transport speeds this should return a small value, for high transport
142 speeds, this should return an exponentially larger value. This provides
143 high definition control at low speeds and quick speed changes to/from
146 float scaled_delta (float delta, float current_speed);
148 // display the first 2 chars of the msg in the 2 char display
149 // . is appended to the previous character, so A.B. would
151 void show_two_char_display (const std::string & msg, const std::string & dots = " ");
152 void show_two_char_display (unsigned int value, const std::string & dots = " ");
154 void update_view_mode_display ();
155 void update_flip_mode_display ();
156 void update_potmode ();
158 void gui_selection_changed (const ARDOUR::StrongRouteNotificationList&);
160 MackieControlProtocol& mcp() const { return _mcp; }
162 void next_jog_mode ();
163 void set_jog_mode (Mackie::JogWheel::Mode);
165 void notify_metering_state_changed();
168 void display_message_for (std::string const& msg, uint64_t msecs);
170 bool connection_handler (boost::weak_ptr<ARDOUR::Port>, std::string name1, boost::weak_ptr<ARDOUR::Port>, std::string name2, bool);
172 void master_monitor_may_have_changed ();
174 XMLNode& get_state ();
175 int set_state (const XMLNode&, int version);
178 MackieControlProtocol& _mcp;
180 surface_type_t _stype;
185 Mackie::JogWheel* _jog_wheel;
186 Fader* _master_fader;
187 float _last_master_gain_written;
188 PBD::ScopedConnection master_connection;
190 void handle_midi_sysex (MIDI::Parser&, MIDI::byte *, size_t count);
191 MidiByteArray host_connection_query (MidiByteArray& bytes);
192 MidiByteArray host_connection_confirmation (const MidiByteArray& bytes);
195 void init_controls ();
196 void init_strips (uint32_t n);
197 void setup_master ();
198 void master_gain_changed ();
200 enum ConnectionState {
201 InputConnected = 0x1,
202 OutputConnected = 0x2
205 int connection_state;
207 MidiByteArray display_line (std::string const& msg, int line_num);
210 /* IP MIDI devices need to keep a handle on this and destroy it */
211 GSource* input_source;