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; }
88 static void* request_factory (uint32_t);
90 XMLNode& get_state ();
91 int set_state (const XMLNode&, int version);
93 bool has_editor () const { return true; }
94 void* get_gui () const;
95 void tear_down_gui ();
97 /* Note: because the FaderPort speaks an inherently duplex protocol,
98 we do not implement get/set_feedback() since this aspect of
99 support for the protocol is not optional.
102 void do_request (FaderPortRequest*);
107 PBD::Signal0<void> ConnectionChange;
109 boost::shared_ptr<ARDOUR::Port> input_port();
110 boost::shared_ptr<ARDOUR::Port> output_port();
112 /* In a feat of engineering brilliance, the Presonus Faderport sends
113 * one button identifier when the button is pressed/released, but
114 * responds to another button identifier as a command to light the LED
115 * corresponding to the button. These ID's define what is sent
116 * for press/release; a separate data structure contains information
117 * on what to send to turn the LED on/off.
119 * One can only conclude that Presonus just didn't want to fix this
120 * issue because it contradicts their own documentation and is more or
121 * less the first thing you discover when programming the device.
161 void set_action (ButtonID, std::string const& action_name, bool on_press, FaderPort::ButtonState = ButtonState (0));
162 std::string get_action (ButtonID, bool on_press, FaderPort::ButtonState = ButtonState (0));
164 std::list<boost::shared_ptr<ARDOUR::Bundle> > bundles ();
167 boost::shared_ptr<ARDOUR::Stripable> _current_stripable;
168 boost::weak_ptr<ARDOUR::Stripable> pre_master_stripable;
169 boost::weak_ptr<ARDOUR::Stripable> pre_monitor_stripable;
171 boost::shared_ptr<ARDOUR::AsyncMIDIPort> _input_port;
172 boost::shared_ptr<ARDOUR::AsyncMIDIPort> _output_port;
174 // Bundle to represent our input ports
175 boost::shared_ptr<ARDOUR::Bundle> _input_bundle;
176 // Bundle to represent our output ports
177 boost::shared_ptr<ARDOUR::Bundle> _output_bundle;
179 PBD::ScopedConnectionList midi_connections;
181 bool midi_input_handler (Glib::IOCondition ioc, boost::shared_ptr<ARDOUR::AsyncMIDIPort> port);
186 bool connection_handler (boost::weak_ptr<ARDOUR::Port>, std::string name1, boost::weak_ptr<ARDOUR::Port>, std::string name2, bool yn);
187 PBD::ScopedConnection port_connection;
189 enum ConnectionState {
190 InputConnected = 0x1,
191 OutputConnected = 0x2
194 int connection_state;
199 bool fader_is_touched;
201 ARDOUR::microseconds_t last_encoder_time;
202 int last_good_encoder_delta;
203 int last_encoder_delta, last_last_encoder_delta;
205 void sysex_handler (MIDI::Parser &p, MIDI::byte *, size_t);
206 void button_handler (MIDI::Parser &, MIDI::EventTwoBytes* tb);
207 void encoder_handler (MIDI::Parser &, MIDI::pitchbend_t pb);
208 void fader_handler (MIDI::Parser &, MIDI::EventTwoBytes* tb);
210 ButtonState button_state;
222 Button (FaderPort& f, std::string const& str, ButtonID i, int o)
230 void set_action (std::string const& action_name, bool on_press, FaderPort::ButtonState = ButtonState (0));
231 void set_action (boost::function<void()> function, bool on_press, FaderPort::ButtonState = ButtonState (0));
232 std::string get_action (bool press, FaderPort::ButtonState bs = ButtonState (0));
234 void set_led_state (boost::shared_ptr<MIDI::Port>, bool onoff);
235 void invoke (ButtonState bs, bool press);
236 bool uses_flash () const { return flash; }
237 void set_flash (bool yn) { flash = yn; }
239 XMLNode& get_state () const;
240 int set_state (XMLNode const&);
242 sigc::connection timeout_connection;
253 /* could be a union if boost::function didn't require a
256 std::string action_name;
257 boost::function<void()> function;
260 typedef std::map<FaderPort::ButtonState,ToDo> ToDoMap;
265 typedef std::map<ButtonID,Button> ButtonMap;
268 Button& get_button (ButtonID) const;
270 std::set<ButtonID> buttons_down;
271 std::set<ButtonID> consumed;
273 bool button_long_press_timeout (ButtonID id);
274 void start_press_timeout (Button&, ButtonID);
276 void all_lights_out ();
278 void start_midi_handling ();
279 void stop_midi_handling ();
281 PBD::ScopedConnectionList session_connections;
282 void connect_session_signals ();
283 void map_recenable_state ();
284 void map_transport_state ();
286 sigc::connection periodic_connection;
289 sigc::connection blink_connection;
290 typedef std::list<ButtonID> Blinkers;
294 void start_blinking (ButtonID);
295 void stop_blinking (ButtonID);
297 void set_current_stripable (boost::shared_ptr<ARDOUR::Stripable>);
298 void drop_current_stripable ();
301 void gui_track_selection_changed (ARDOUR::StripableNotificationListPtr);
302 PBD::ScopedConnection selection_connection;
303 PBD::ScopedConnectionList stripable_connections;
305 void map_stripable_state ();
308 bool rec_enable_state;
309 void map_recenable ();
313 void parameter_changed (std::string);
315 /* operations (defined in operations.cc) */
332 void ardour_pan_azimuth (int);
333 void ardour_pan_width (int);
334 void mixbus_pan (int);
341 #endif /* ardour_surface_faderport_h */