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
25 #include <glibmm/threads.h>
27 #define ABSTRACT_UI_EXPORTS
28 #include "pbd/abstract_ui.h"
30 #include "ardour/types.h"
32 #include "control_protocol/control_protocol.h"
36 class ControllableDescriptor;
39 #include <midi++/types.h>
41 //#include "pbd/signals.h"
44 //#include "midi_byte_array.h"
47 #include "glibmm/main.h"
63 class MIDIControllable;
67 namespace ArdourSurface {
69 struct FaderPortRequest : public BaseUI::BaseRequestObject {
71 FaderPortRequest () {}
72 ~FaderPortRequest () {}
75 class FaderPort : public ARDOUR::ControlProtocol, public AbstractUI<FaderPortRequest> {
77 FaderPort (ARDOUR::Session&);
80 int set_active (bool yn);
82 /* we probe for a device when our ports are connected. Before that,
83 there's no way to know if the device exists or not.
85 static bool probe() { return true; }
87 XMLNode& get_state ();
88 int set_state (const XMLNode&, int version);
90 bool has_editor () const { return true; }
91 void* get_gui () const;
92 void tear_down_gui ();
94 /* Note: because the FaderPort speaks an inherently duplex protocol,
95 we do not implement get/set_feedback() since this aspect of
96 support for the protocol is not optional.
99 void do_request (FaderPortRequest*);
104 PBD::Signal0<void> ConnectionChange;
106 boost::shared_ptr<ARDOUR::Port> input_port();
107 boost::shared_ptr<ARDOUR::Port> output_port();
144 void set_action (ButtonID, std::string const& action_name, bool on_press, FaderPort::ButtonState = ButtonState (0));
147 boost::shared_ptr<ARDOUR::Route> _current_route;
148 boost::weak_ptr<ARDOUR::Route> pre_master_route;
149 boost::weak_ptr<ARDOUR::Route> pre_monitor_route;
151 boost::shared_ptr<ARDOUR::AsyncMIDIPort> _input_port;
152 boost::shared_ptr<ARDOUR::AsyncMIDIPort> _output_port;
154 PBD::ScopedConnectionList midi_connections;
156 bool midi_input_handler (Glib::IOCondition ioc, boost::shared_ptr<ARDOUR::AsyncMIDIPort> port);
161 bool connection_handler (boost::weak_ptr<ARDOUR::Port>, std::string name1, boost::weak_ptr<ARDOUR::Port>, std::string name2, bool yn);
162 PBD::ScopedConnection port_connection;
164 enum ConnectionState {
165 InputConnected = 0x1,
166 OutputConnected = 0x2
169 int connection_state;
174 bool fader_is_touched;
176 ARDOUR::microseconds_t last_encoder_time;
177 int last_good_encoder_delta;
178 int last_encoder_delta, last_last_encoder_delta;
180 void sysex_handler (MIDI::Parser &p, MIDI::byte *, size_t);
181 void switch_handler (MIDI::Parser &, MIDI::EventTwoBytes* tb);
182 void encoder_handler (MIDI::Parser &, MIDI::pitchbend_t pb);
183 void fader_handler (MIDI::Parser &, MIDI::EventTwoBytes* tb);
185 ButtonState button_state;
187 friend class ButtonInfo;
197 ButtonInfo (FaderPort& f, std::string const& str, ButtonID i, int o)
207 void set_action (std::string const& action_name, bool on_press, FaderPort::ButtonState = ButtonState (0));
208 void set_action (boost::function<void()> function, bool on_press, FaderPort::ButtonState = ButtonState (0));
209 void set_led_state (boost::shared_ptr<MIDI::Port>, int onoff, bool force = false);
210 void invoke (ButtonState bs, bool press);
211 bool uses_flash () const { return flash; }
212 void set_flash (bool yn) { flash = yn; }
223 /* could be a union if boost::function didn't require a
227 std::string action_name;
228 boost::function<void()> function;
231 typedef std::map<FaderPort::ButtonState,ToDo> ToDoMap;
236 typedef std::map<ButtonID,ButtonInfo> ButtonMap;
239 ButtonInfo& button_info (ButtonID) const;
241 void all_lights_out ();
243 void start_midi_handling ();
244 void stop_midi_handling ();
246 PBD::ScopedConnectionList session_connections;
247 void connect_session_signals ();
248 void notify_record_state_changed ();
249 void notify_transport_state_changed ();
251 sigc::connection blink_connection;
252 typedef std::list<ButtonID> Blinkers;
257 void set_current_route (boost::shared_ptr<ARDOUR::Route>);
258 void drop_current_route ();
261 void gui_track_selection_changed (ARDOUR::RouteNotificationListPtr);
262 PBD::ScopedConnection selection_connection;
263 PBD::ScopedConnectionList route_connections;
265 void map_route_state ();
266 void map_solo (bool,void*,bool);
267 void map_listen (void*,bool);
268 void map_mute (void*);
269 void map_recenable ();
273 /* operations (defined in operations.cc) */
290 void ardour_pan_azimuth (int);
291 void ardour_pan_width (int);
292 void mixbus_pan (int);
297 #endif /* ardour_surface_faderport_h */