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"
39 #include <midi++/types.h>
41 //#include "pbd/signals.h"
44 //#include "midi_byte_array.h"
47 #include "glibmm/main.h"
64 class MIDIControllable;
68 namespace ArdourSurface {
70 struct FaderPortRequest : public BaseUI::BaseRequestObject {
72 FaderPortRequest () {}
73 ~FaderPortRequest () {}
76 class FaderPort : public ARDOUR::ControlProtocol, public AbstractUI<FaderPortRequest> {
78 FaderPort (ARDOUR::Session&);
81 int set_active (bool yn);
83 /* we probe for a device when our ports are connected. Before that,
84 there's no way to know if the device exists or not.
86 static bool probe() { return true; }
87 static void* request_factory (uint32_t);
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.
160 void set_action (ButtonID, std::string const& action_name, bool on_press, FaderPort::ButtonState = ButtonState (0));
161 std::string get_action (ButtonID, bool on_press, FaderPort::ButtonState = ButtonState (0));
163 std::list<boost::shared_ptr<ARDOUR::Bundle> > bundles ();
166 boost::shared_ptr<ARDOUR::Stripable> _current_stripable;
167 boost::weak_ptr<ARDOUR::Stripable> pre_master_stripable;
168 boost::weak_ptr<ARDOUR::Stripable> pre_monitor_stripable;
170 boost::shared_ptr<ARDOUR::AsyncMIDIPort> _input_port;
171 boost::shared_ptr<ARDOUR::AsyncMIDIPort> _output_port;
173 // Bundle to represent our input ports
174 boost::shared_ptr<ARDOUR::Bundle> _input_bundle;
175 // Bundle to represent our output ports
176 boost::shared_ptr<ARDOUR::Bundle> _output_bundle;
178 PBD::ScopedConnectionList midi_connections;
180 bool midi_input_handler (Glib::IOCondition ioc, boost::weak_ptr<ARDOUR::AsyncMIDIPort> port);
185 bool connection_handler (boost::weak_ptr<ARDOUR::Port>, std::string name1, boost::weak_ptr<ARDOUR::Port>, std::string name2, bool yn);
186 PBD::ScopedConnection port_connection;
188 enum ConnectionState {
189 InputConnected = 0x1,
190 OutputConnected = 0x2
193 int connection_state;
198 bool fader_is_touched;
200 ARDOUR::microseconds_t last_encoder_time;
201 int last_good_encoder_delta;
202 int last_encoder_delta, last_last_encoder_delta;
204 void sysex_handler (MIDI::Parser &p, MIDI::byte *, size_t);
205 void button_handler (MIDI::Parser &, MIDI::EventTwoBytes* tb);
206 void encoder_handler (MIDI::Parser &, MIDI::pitchbend_t pb);
207 void fader_handler (MIDI::Parser &, MIDI::EventTwoBytes* tb);
209 ButtonState button_state;
221 Button (FaderPort& f, std::string const& str, ButtonID i, int o)
229 void set_action (std::string const& action_name, bool on_press, FaderPort::ButtonState = ButtonState (0));
230 void set_action (boost::function<void()> function, bool on_press, FaderPort::ButtonState = ButtonState (0));
231 std::string get_action (bool press, FaderPort::ButtonState bs = ButtonState (0));
233 void set_led_state (boost::shared_ptr<MIDI::Port>, bool onoff);
234 bool invoke (ButtonState bs, bool press);
235 bool uses_flash () const { return flash; }
236 void set_flash (bool yn) { flash = yn; }
238 XMLNode& get_state () const;
239 int set_state (XMLNode const&);
241 sigc::connection timeout_connection;
252 /* could be a union if boost::function didn't require a
255 std::string action_name;
256 boost::function<void()> function;
259 typedef std::map<FaderPort::ButtonState,ToDo> ToDoMap;
264 typedef std::map<ButtonID,Button> ButtonMap;
267 Button& get_button (ButtonID) const;
269 std::set<ButtonID> buttons_down;
270 std::set<ButtonID> consumed;
272 bool button_long_press_timeout (ButtonID id);
273 void start_press_timeout (Button&, ButtonID);
275 void all_lights_out ();
277 void start_midi_handling ();
278 void stop_midi_handling ();
280 PBD::ScopedConnectionList session_connections;
281 void connect_session_signals ();
282 void map_recenable_state ();
283 void map_transport_state ();
285 sigc::connection periodic_connection;
288 sigc::connection blink_connection;
289 typedef std::list<ButtonID> Blinkers;
293 void start_blinking (ButtonID);
294 void stop_blinking (ButtonID);
296 void set_current_stripable (boost::shared_ptr<ARDOUR::Stripable>);
297 void drop_current_stripable ();
300 void stripable_selection_changed ();
301 PBD::ScopedConnection selection_connection;
302 PBD::ScopedConnectionList stripable_connections;
304 void map_stripable_state ();
307 bool rec_enable_state;
308 void map_recenable ();
312 void parameter_changed (std::string);
314 /* operations (defined in operations.cc) */
331 void ardour_pan_azimuth (int);
332 void ardour_pan_width (int);
333 void mixbus_pan (int);
340 #endif /* ardour_surface_faderport_h */