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"
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; }
88 XMLNode& get_state ();
89 int set_state (const XMLNode&, int version);
91 bool has_editor () const { return true; }
92 void* get_gui () const;
93 void tear_down_gui ();
95 /* Note: because the FaderPort speaks an inherently duplex protocol,
96 we do not implement get/set_feedback() since this aspect of
97 support for the protocol is not optional.
100 void do_request (FaderPortRequest*);
105 PBD::Signal0<void> ConnectionChange;
107 boost::shared_ptr<ARDOUR::Port> input_port();
108 boost::shared_ptr<ARDOUR::Port> output_port();
110 /* In a feat of engineering brilliance, the Presonus Faderport sends
111 * one button identifier when the button is pressed/released, but
112 * responds to another button identifier as a command to light the LED
113 * corresponding to the button. These ID's define what is sent
114 * for press/release; a separate data structure contains information
115 * on what to send to turn the LED on/off.
117 * One can only conclude that Presonus just didn't want to fix this
118 * issue because it contradicts their own documentation and is more or
119 * less the first thing you discover when programming the device.
158 void set_action (ButtonID, std::string const& action_name, bool on_press, FaderPort::ButtonState = ButtonState (0));
159 std::string get_action (ButtonID, bool on_press, FaderPort::ButtonState = ButtonState (0));
162 boost::shared_ptr<ARDOUR::Route> _current_route;
163 boost::weak_ptr<ARDOUR::Route> pre_master_route;
164 boost::weak_ptr<ARDOUR::Route> pre_monitor_route;
166 boost::shared_ptr<ARDOUR::AsyncMIDIPort> _input_port;
167 boost::shared_ptr<ARDOUR::AsyncMIDIPort> _output_port;
169 PBD::ScopedConnectionList midi_connections;
171 bool midi_input_handler (Glib::IOCondition ioc, boost::shared_ptr<ARDOUR::AsyncMIDIPort> port);
176 bool connection_handler (boost::weak_ptr<ARDOUR::Port>, std::string name1, boost::weak_ptr<ARDOUR::Port>, std::string name2, bool yn);
177 PBD::ScopedConnection port_connection;
179 enum ConnectionState {
180 InputConnected = 0x1,
181 OutputConnected = 0x2
184 int connection_state;
189 bool fader_is_touched;
191 ARDOUR::microseconds_t last_encoder_time;
192 int last_good_encoder_delta;
193 int last_encoder_delta, last_last_encoder_delta;
195 void sysex_handler (MIDI::Parser &p, MIDI::byte *, size_t);
196 void button_handler (MIDI::Parser &, MIDI::EventTwoBytes* tb);
197 void encoder_handler (MIDI::Parser &, MIDI::pitchbend_t pb);
198 void fader_handler (MIDI::Parser &, MIDI::EventTwoBytes* tb);
200 ButtonState button_state;
212 Button (FaderPort& f, std::string const& str, ButtonID i, int o)
221 void set_action (std::string const& action_name, bool on_press, FaderPort::ButtonState = ButtonState (0));
222 void set_action (boost::function<void()> function, bool on_press, FaderPort::ButtonState = ButtonState (0));
223 std::string get_action (bool press, FaderPort::ButtonState bs = ButtonState (0));
225 void set_led_state (boost::shared_ptr<MIDI::Port>, int onoff, bool force = false);
226 void invoke (ButtonState bs, bool press);
227 bool uses_flash () const { return flash; }
228 void set_flash (bool yn) { flash = yn; }
230 XMLNode& get_state () const;
231 int set_state (XMLNode const&);
233 sigc::connection timeout_connection;
245 /* could be a union if boost::function didn't require a
248 std::string action_name;
249 boost::function<void()> function;
252 typedef std::map<FaderPort::ButtonState,ToDo> ToDoMap;
257 typedef std::map<ButtonID,Button> ButtonMap;
260 Button& get_button (ButtonID) const;
262 std::set<ButtonID> buttons_down;
264 bool button_long_press_timeout (ButtonID id);
265 void start_press_timeout (Button&, ButtonID);
267 void all_lights_out ();
269 void start_midi_handling ();
270 void stop_midi_handling ();
272 PBD::ScopedConnectionList session_connections;
273 void connect_session_signals ();
274 void notify_record_state_changed ();
275 void notify_transport_state_changed ();
277 sigc::connection blink_connection;
278 typedef std::list<ButtonID> Blinkers;
283 void set_current_route (boost::shared_ptr<ARDOUR::Route>);
284 void drop_current_route ();
287 void gui_track_selection_changed (ARDOUR::RouteNotificationListPtr);
288 PBD::ScopedConnection selection_connection;
289 PBD::ScopedConnectionList route_connections;
291 void map_route_state ();
292 void map_solo (bool,void*,bool);
293 void map_listen (void*,bool);
294 void map_mute (void*);
295 void map_recenable ();
298 void parameter_changed (std::string);
300 /* operations (defined in operations.cc) */
317 void ardour_pan_azimuth (int);
318 void ardour_pan_width (int);
319 void mixbus_pan (int);
326 #endif /* ardour_surface_faderport_h */