2 * Copyright (C) 2006-2007 John Anderson
3 * Copyright (C) 2012-2015 Paul Davis <paul@linuxaudiosystems.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #ifndef mackie_surface_h
21 #define mackie_surface_h
25 #include <sigc++/trackable.h>
27 #include "pbd/signals.h"
28 #include "pbd/xml++.h"
29 #include "midi++/types.h"
31 #include "ardour/types.h"
33 #include "control_protocol/types.h"
37 #include "jog_wheel.h"
50 namespace ArdourSurface {
52 class MackieControlProtocol;
57 class MackieButtonHandler;
59 class MackieMidiBuilder;
67 class Surface : public PBD::ScopedConnectionList, public sigc::trackable
70 Surface (MackieControlProtocol&, const std::string& name, uint32_t number, surface_type_t stype);
73 surface_type_t type() const { return _stype; }
74 uint32_t number() const { return _number; }
75 const std::string& name() { return _name; }
79 bool active() const { return _active; }
81 typedef std::vector<Control*> Controls;
84 std::map<int,Fader*> faders;
85 std::map<int,Pot*> pots;
86 std::map<int,Button*> buttons; // index is device-DEPENDENT
87 std::map<int,Led*> leds;
88 std::map<int,Meter*> meters;
89 std::map<int,Control*> controls_by_device_independent_id;
91 Mackie::JogWheel* jog_wheel() const { return _jog_wheel; }
92 Fader* master_fader() const { return _master_fader; }
94 /// The collection of all numbered strips.
95 typedef std::vector<Strip*> Strips;
98 uint32_t n_strips (bool with_locked_strips = true) const;
99 Strip* nth_strip (uint32_t n) const;
101 bool stripable_is_locked_to_strip (boost::shared_ptr<ARDOUR::Stripable>) const;
102 bool stripable_is_mapped (boost::shared_ptr<ARDOUR::Stripable>) const;
104 /// This collection owns the groups
105 typedef std::map<std::string,Group*> Groups;
108 SurfacePort& port() const { return *_port; }
110 void map_stripables (const std::vector<boost::shared_ptr<ARDOUR::Stripable> >&);
112 void update_strip_selection ();
114 const MidiByteArray& sysex_hdr() const;
116 void periodic (ARDOUR::microseconds_t now_usecs);
117 void redisplay (ARDOUR::microseconds_t now_usecs, bool force);
118 void hui_heartbeat ();
120 void handle_midi_pitchbend_message (MIDI::Parser&, MIDI::pitchbend_t, uint32_t channel_id);
121 void handle_midi_controller_message (MIDI::Parser&, MIDI::EventTwoBytes*);
122 void handle_midi_note_on_message (MIDI::Parser&, MIDI::EventTwoBytes*);
124 /// Connect the any signal from the parser to handle_midi_any
125 /// unless it's already connected
126 void connect_to_signals ();
128 /// write a sysex message
129 void write_sysex (const MidiByteArray& mba);
130 void write_sysex (MIDI::byte msg);
131 /// proxy write for port
132 void write (const MidiByteArray&);
134 /// display an indicator of the first switched-in Route. Do nothing by default.
135 void display_bank_start (uint32_t /*current_bank*/);
137 /// called from MackieControlProtocol::zero_all to turn things off
139 void zero_controls ();
141 /// turn off leds around the jog wheel. This is for surfaces that use a pot
142 /// pretending to be a jog wheel.
143 void blank_jog_ring ();
145 void display_timecode (const std::string & /*timecode*/, const std::string & /*timecode_last*/);
147 /// sends MCP "reset" message to surface
150 void recalibrate_faders ();
151 void toggle_backlight ();
152 void set_touch_sensitivity (int);
155 This is used to calculate the clicks per second that define
156 a transport speed of 1.0 for the jog wheel. 100.0 is 10 clicks
157 per second, 50.5 is 5 clicks per second.
159 float scrub_scaling_factor() const;
162 The scaling factor function for speed increase and decrease. At
163 low transport speeds this should return a small value, for high transport
164 speeds, this should return an exponentially larger value. This provides
165 high definition control at low speeds and quick speed changes to/from
168 float scaled_delta (float delta, float current_speed);
170 // display the first 2 chars of the msg in the 2 char display
171 // . is appended to the previous character, so A.B. would
173 void show_two_char_display (const std::string & msg, const std::string & dots = " ");
174 void show_two_char_display (unsigned int value, const std::string & dots = " ");
176 void update_view_mode_display (bool with_helpful_text);
177 void update_flip_mode_display ();
179 void subview_mode_changed ();
181 MackieControlProtocol& mcp() const { return _mcp; }
183 void next_jog_mode ();
184 void set_jog_mode (Mackie::JogWheel::Mode);
186 void notify_metering_state_changed();
189 void display_message_for (std::string const& msg, uint64_t msecs);
191 bool connection_handler (boost::weak_ptr<ARDOUR::Port>, std::string name1, boost::weak_ptr<ARDOUR::Port>, std::string name2, bool);
193 void master_monitor_may_have_changed ();
195 XMLNode& get_state ();
196 int set_state (const XMLNode&, int version);
198 bool get_qcon_flag() { return is_qcon; }
201 MackieControlProtocol& _mcp;
203 surface_type_t _stype;
208 Mackie::JogWheel* _jog_wheel;
209 Fader* _master_fader;
210 float _last_master_gain_written;
211 PBD::ScopedConnection master_connection;
213 void handle_midi_sysex (MIDI::Parser&, MIDI::byte *, size_t count);
214 MidiByteArray host_connection_query (MidiByteArray& bytes);
215 MidiByteArray host_connection_confirmation (const MidiByteArray& bytes);
218 void init_controls ();
219 void init_strips (uint32_t n);
220 void setup_master ();
221 void master_gain_changed ();
223 enum ConnectionState {
224 InputConnected = 0x1,
225 OutputConnected = 0x2
228 int connection_state;
233 MidiByteArray display_line (std::string const& msg, int line_num);
236 /* IP MIDI devices need to keep a handle on this and destroy it */
237 GSource* input_source;