2 Copyright (C) 2006 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #ifndef ardour_surface_faderport_h
21 #define ardour_surface_faderport_h
26 #include <glibmm/threads.h>
28 #define ABSTRACT_UI_EXPORTS
29 #include "pbd/abstract_ui.h"
31 #include "ardour/types.h"
33 #include "control_protocol/control_protocol.h"
37 class ControllableDescriptor;
40 #include <midi++/types.h>
42 //#include "pbd/signals.h"
45 //#include "midi_byte_array.h"
48 #include "glibmm/main.h"
65 class MIDIControllable;
69 namespace ArdourSurface {
71 struct FaderPortRequest : public BaseUI::BaseRequestObject {
73 FaderPortRequest () {}
74 ~FaderPortRequest () {}
77 class FaderPort : public ARDOUR::ControlProtocol, public AbstractUI<FaderPortRequest> {
79 FaderPort (ARDOUR::Session&);
82 int set_active (bool yn);
84 /* we probe for a device when our ports are connected. Before that,
85 there's no way to know if the device exists or not.
87 static bool probe() { return true; }
89 XMLNode& get_state ();
90 int set_state (const XMLNode&, int version);
92 bool has_editor () const { return true; }
93 void* get_gui () const;
94 void tear_down_gui ();
96 /* Note: because the FaderPort speaks an inherently duplex protocol,
97 we do not implement get/set_feedback() since this aspect of
98 support for the protocol is not optional.
101 void do_request (FaderPortRequest*);
106 PBD::Signal0<void> ConnectionChange;
108 boost::shared_ptr<ARDOUR::Port> input_port();
109 boost::shared_ptr<ARDOUR::Port> output_port();
111 /* In a feat of engineering brilliance, the Presonus Faderport sends
112 * one button identifier when the button is pressed/released, but
113 * responds to another button identifier as a command to light the LED
114 * corresponding to the button. These ID's define what is sent
115 * for press/release; a separate data structure contains information
116 * on what to send to turn the LED on/off.
118 * One can only conclude that Presonus just didn't want to fix this
119 * issue because it contradicts their own documentation and is more or
120 * less the first thing you discover when programming the device.
159 void set_action (ButtonID, std::string const& action_name, bool on_press, FaderPort::ButtonState = ButtonState (0));
160 std::string get_action (ButtonID, bool on_press, FaderPort::ButtonState = ButtonState (0));
162 std::list<boost::shared_ptr<ARDOUR::Bundle> > bundles ();
165 boost::shared_ptr<ARDOUR::Route> _current_route;
166 boost::weak_ptr<ARDOUR::Route> pre_master_route;
167 boost::weak_ptr<ARDOUR::Route> pre_monitor_route;
169 boost::shared_ptr<ARDOUR::AsyncMIDIPort> _input_port;
170 boost::shared_ptr<ARDOUR::AsyncMIDIPort> _output_port;
172 // Bundle to represent our input ports
173 boost::shared_ptr<ARDOUR::Bundle> _input_bundle;
174 // Bundle to represent our output ports
175 boost::shared_ptr<ARDOUR::Bundle> _output_bundle;
177 PBD::ScopedConnectionList midi_connections;
179 bool midi_input_handler (Glib::IOCondition ioc, boost::shared_ptr<ARDOUR::AsyncMIDIPort> port);
184 bool connection_handler (boost::weak_ptr<ARDOUR::Port>, std::string name1, boost::weak_ptr<ARDOUR::Port>, std::string name2, bool yn);
185 PBD::ScopedConnection port_connection;
187 enum ConnectionState {
188 InputConnected = 0x1,
189 OutputConnected = 0x2
192 int connection_state;
197 bool fader_is_touched;
199 ARDOUR::microseconds_t last_encoder_time;
200 int last_good_encoder_delta;
201 int last_encoder_delta, last_last_encoder_delta;
203 void sysex_handler (MIDI::Parser &p, MIDI::byte *, size_t);
204 void button_handler (MIDI::Parser &, MIDI::EventTwoBytes* tb);
205 void encoder_handler (MIDI::Parser &, MIDI::pitchbend_t pb);
206 void fader_handler (MIDI::Parser &, MIDI::EventTwoBytes* tb);
208 ButtonState button_state;
220 Button (FaderPort& f, std::string const& str, ButtonID i, int o)
228 void set_action (std::string const& action_name, bool on_press, FaderPort::ButtonState = ButtonState (0));
229 void set_action (boost::function<void()> function, bool on_press, FaderPort::ButtonState = ButtonState (0));
230 std::string get_action (bool press, FaderPort::ButtonState bs = ButtonState (0));
232 void set_led_state (boost::shared_ptr<MIDI::Port>, bool onoff);
233 void invoke (ButtonState bs, bool press);
234 bool uses_flash () const { return flash; }
235 void set_flash (bool yn) { flash = yn; }
237 XMLNode& get_state () const;
238 int set_state (XMLNode const&);
240 sigc::connection timeout_connection;
251 /* could be a union if boost::function didn't require a
254 std::string action_name;
255 boost::function<void()> function;
258 typedef std::map<FaderPort::ButtonState,ToDo> ToDoMap;
263 typedef std::map<ButtonID,Button> ButtonMap;
266 Button& get_button (ButtonID) const;
268 std::set<ButtonID> buttons_down;
269 std::set<ButtonID> consumed;
271 bool button_long_press_timeout (ButtonID id);
272 void start_press_timeout (Button&, ButtonID);
274 void all_lights_out ();
276 void start_midi_handling ();
277 void stop_midi_handling ();
279 PBD::ScopedConnectionList session_connections;
280 void connect_session_signals ();
281 void map_recenable_state ();
282 void map_transport_state ();
284 sigc::connection blink_connection;
285 typedef std::list<ButtonID> Blinkers;
289 void start_blinking (ButtonID);
290 void stop_blinking (ButtonID);
292 void set_current_route (boost::shared_ptr<ARDOUR::Route>);
293 void drop_current_route ();
296 void gui_track_selection_changed (ARDOUR::RouteNotificationListPtr);
297 PBD::ScopedConnection selection_connection;
298 PBD::ScopedConnectionList route_connections;
300 void map_route_state ();
301 void map_solo (bool,void*,bool);
302 void map_listen (void*,bool);
303 void map_mute (void*);
304 void map_recenable ();
308 void parameter_changed (std::string);
310 /* operations (defined in operations.cc) */
327 void ardour_pan_azimuth (int);
328 void ardour_pan_width (int);
329 void mixbus_pan (int);
336 #endif /* ardour_surface_faderport_h */