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 {
38 class MackieButtonHandler;
40 class MackieMidiBuilder;
48 class Surface : public PBD::ScopedConnectionList, public sigc::trackable
51 Surface (US2400Protocol&, 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 US2400::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 stripable_is_locked_to_strip (boost::shared_ptr<ARDOUR::Stripable>) const;
83 bool stripable_is_mapped (boost::shared_ptr<ARDOUR::Stripable>) const;
85 /// This collection owns the groups
86 typedef std::map<std::string,Group*> Groups;
89 SurfacePort& port() const { return *_port; }
91 void map_stripables (const std::vector<boost::shared_ptr<ARDOUR::Stripable> >&);
93 void update_strip_selection ();
95 const MidiByteArray& sysex_hdr() const;
97 void periodic (ARDOUR::microseconds_t now_usecs);
98 void redisplay (ARDOUR::microseconds_t now_usecs, bool force);
99 void hui_heartbeat ();
101 void handle_midi_pitchbend_message (MIDI::Parser&, MIDI::pitchbend_t, uint32_t channel_id);
102 void handle_midi_controller_message (MIDI::Parser&, MIDI::EventTwoBytes*);
103 void handle_midi_note_on_message (MIDI::Parser&, MIDI::EventTwoBytes*);
105 /// Connect the any signal from the parser to handle_midi_any
106 /// unless it's already connected
107 void connect_to_signals ();
109 /// write a sysex message
110 void write_sysex (const MidiByteArray& mba);
111 void write_sysex (MIDI::byte msg);
112 /// proxy write for port
113 void write (const MidiByteArray&);
115 /// display an indicator of the first switched-in Route. Do nothing by default.
116 void display_bank_start (uint32_t /*current_bank*/);
118 /// called from US2400Protocol::zero_all to turn things off
120 void zero_controls ();
122 /// turn off leds around the jog wheel. This is for surfaces that use a pot
123 /// pretending to be a jog wheel.
124 void blank_jog_ring ();
126 /// sends MCP "reset" message to surface
129 void recalibrate_faders ();
130 void toggle_backlight ();
131 void set_touch_sensitivity (int);
134 This is used to calculate the clicks per second that define
135 a transport speed of 1.0 for the jog wheel. 100.0 is 10 clicks
136 per second, 50.5 is 5 clicks per second.
138 float scrub_scaling_factor() const;
141 The scaling factor function for speed increase and decrease. At
142 low transport speeds this should return a small value, for high transport
143 speeds, this should return an exponentially larger value. This provides
144 high definition control at low speeds and quick speed changes to/from
147 float scaled_delta (float delta, float current_speed);
149 void subview_mode_changed ();
151 US2400Protocol& mcp() const { return _mcp; }
153 void next_jog_mode ();
154 void set_jog_mode (US2400::JogWheel::Mode);
156 void notify_metering_state_changed();
159 bool connection_handler (boost::weak_ptr<ARDOUR::Port>, std::string name1, boost::weak_ptr<ARDOUR::Port>, std::string name2, bool);
161 void master_monitor_may_have_changed ();
163 XMLNode& get_state ();
164 int set_state (const XMLNode&, int version);
167 US2400Protocol& _mcp;
169 surface_type_t _stype;
174 US2400::JogWheel* _jog_wheel;
175 Fader* _master_fader;
176 float _last_master_gain_written;
177 PBD::ScopedConnection master_connection;
179 void handle_midi_sysex (MIDI::Parser&, MIDI::byte *, size_t count);
180 MidiByteArray host_connection_query (MidiByteArray& bytes);
181 MidiByteArray host_connection_confirmation (const MidiByteArray& bytes);
184 void init_controls ();
185 void init_strips (uint32_t n);
186 void setup_master ();
187 void master_gain_changed ();
189 enum ConnectionState {
190 InputConnected = 0x1,
191 OutputConnected = 0x2
194 int connection_state;
197 /* IP MIDI devices need to keep a handle on this and destroy it */
198 GSource* input_source;