2 * Copyright (C) 2006-2009 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
30 #include <boost/shared_ptr.hpp>
34 #include <glibmm/main.h>
36 #define ABSTRACT_UI_EXPORTS
37 #include "pbd/abstract_ui.h"
39 #include "ardour/types.h"
40 #include "control_protocol/control_protocol.h"
44 class OSCControllable;
45 class OSCRouteObserver;
46 class OSCGlobalObserver;
53 /* this is mostly a placeholder because I suspect that at some
54 point we will want to add more members to accomodate
55 certain types of requests to the OSC UI
58 namespace ArdourSurface {
60 struct OSCUIRequest : public BaseUI::BaseRequestObject {
66 class OSC : public ARDOUR::ControlProtocol, public AbstractUI<OSCUIRequest>
69 OSC (ARDOUR::Session&, uint32_t port);
72 static OSC* instance() { return _instance; }
74 XMLNode& get_state ();
75 int set_state (const XMLNode&, int version);
77 bool has_editor () const { return true; }
78 void* get_gui () const;
79 void tear_down_gui ();
81 int set_active (bool yn);
82 bool get_active () const;
83 int set_feedback (bool yn);
84 bool get_feedback () const;
90 static void* request_factory (uint32_t);
98 // keep a surface's global setup by remote server url
101 std::string remote_url; // the url these setting belong to
102 uint32_t bank; // current bank
103 uint32_t bank_size; // size of banks for this surface
104 std::bitset<32> strip_types; // what strip types are a part of this bank
105 std::bitset<32> feedback; // What is fed back? strips/meters/timecode/bar_beat/global
106 int gainmode; // what kind of faders do we have Gain db or position 0 to 1023?
107 uint32_t surface_sel; // which strip within the bank is locally selected
108 //StripableList strips; //list of stripables for the current bank
111 * Reminder of what strip_types there are
125 * [0] - Strips - buttons
126 * [1] - Strips - variables (pots/faders)
127 * [2] - Strips - Send SSID as path extension
128 * [3] - Send heart beat to surface
129 * [4] - Send feedback for master/global buttons/variables
130 * [5] - Send Bar and Beat
131 * [6] - Send Time code
132 * [7] - Send metering as dB or positional depending on gainmode
133 * [8] - Send metering as 16 bits (led strip)
134 * [9] - Send signal present (signal greater than -20dB)
138 // storage for each surface's settings
139 typedef std::vector<OSCSurface> Surface;
142 std::string get_server_url ();
143 void set_debug_mode (OSCDebugMode m) { _debugmode = m; }
144 OSCDebugMode get_debug_mode () { return _debugmode; }
148 void do_request (OSCUIRequest*);
150 GSource* local_server;
151 GSource* remote_server;
153 bool osc_input_handler (Glib::IOCondition, lo_server);
158 volatile bool _shutdown;
159 lo_server _osc_server;
160 lo_server _osc_unix_server;
161 std::string _osc_unix_socket_path;
162 std::string _osc_url_file;
163 bool _send_route_changes;
164 OSCDebugMode _debugmode;
166 void register_callbacks ();
168 void route_added (ARDOUR::RouteList&);
170 // Handlers for "Application Hook" signals
171 void session_loaded (ARDOUR::Session&);
172 void session_exported (std::string, std::string);
174 // end "Application Hook" handles
176 std::string get_unix_server_url ();
177 OSCSurface * get_surface (lo_address addr);
178 uint32_t get_sid (uint32_t rid, lo_address addr);
179 uint32_t get_rid (uint32_t sid, lo_address addr);
180 void global_feedback (std::bitset<32> feedback, lo_address msg, uint32_t gainmode);
182 void send_current_value (const char* path, lo_arg** argv, int argc, lo_message msg);
183 void current_value_query (const char* path, size_t len, lo_arg **argv, int argc, lo_message msg);
185 int current_value (const char *path, const char *types, lo_arg **argv, int argc, void *data, void *user_data);
187 int catchall (const char *path, const char *types, lo_arg **argv, int argc, void *data);
188 static int _catchall (const char *path, const char *types, lo_arg **argv, int argc, void *data, void *user_data);
190 void routes_list (lo_message msg);
191 void transport_frame (lo_message msg);
192 void transport_speed (lo_message msg);
193 void record_enabled (lo_message msg);
196 if (_debugmode == All) { \
197 debugmsg (dgettext(PACKAGE, "OSC"), path, types, argv, argc); \
200 #define PATH_CALLBACK_MSG(name) \
201 static int _ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *data, void *user_data) { \
202 return static_cast<OSC*>(user_data)->cb_ ## name (path, types, argv, argc, data); \
204 int cb_ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *data) { \
206 if (argc > 0 && !strcmp (types, "f") && argv[0]->f != 1.0) { return 0; } \
211 PATH_CALLBACK_MSG(routes_list);
212 PATH_CALLBACK_MSG(transport_frame);
213 PATH_CALLBACK_MSG(transport_speed);
214 PATH_CALLBACK_MSG(record_enabled);
215 PATH_CALLBACK_MSG(bank_up);
216 PATH_CALLBACK_MSG(bank_down);
218 #define PATH_CALLBACK(name) \
219 static int _ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *data, void *user_data) { \
220 return static_cast<OSC*>(user_data)->cb_ ## name (path, types, argv, argc, data); \
222 int cb_ ## name (const char *path, const char *types, lo_arg ** argv, int argc, void *) { \
224 if (argc > 0 && !strcmp (types, "f") && argv[0]->f != 1.0) { return 0; } \
229 PATH_CALLBACK(add_marker);
230 PATH_CALLBACK(loop_toggle);
231 PATH_CALLBACK(goto_start);
232 PATH_CALLBACK(goto_end);
233 PATH_CALLBACK(rewind);
235 PATH_CALLBACK(transport_stop);
236 PATH_CALLBACK(transport_play);
237 PATH_CALLBACK(save_state);
238 PATH_CALLBACK(prev_marker);
239 PATH_CALLBACK(next_marker);
242 PATH_CALLBACK(toggle_punch_in);
243 PATH_CALLBACK(toggle_punch_out);
244 PATH_CALLBACK(rec_enable_toggle);
245 PATH_CALLBACK(toggle_all_rec_enables);
246 PATH_CALLBACK(all_tracks_rec_in);
247 PATH_CALLBACK(all_tracks_rec_out);
248 PATH_CALLBACK(remove_marker_at_playhead);
249 PATH_CALLBACK(mark_in);
250 PATH_CALLBACK(mark_out);
251 PATH_CALLBACK(toggle_click);
252 PATH_CALLBACK(midi_panic);
253 PATH_CALLBACK(toggle_roll);
254 PATH_CALLBACK(stop_forget);
255 PATH_CALLBACK(set_punch_range);
256 PATH_CALLBACK(set_loop_range);
257 PATH_CALLBACK(set_session_range);
258 PATH_CALLBACK(toggle_monitor_mute);
259 PATH_CALLBACK(toggle_monitor_dim);
260 PATH_CALLBACK(toggle_monitor_mono);
261 PATH_CALLBACK(quick_snapshot_stay);
262 PATH_CALLBACK(quick_snapshot_switch);
263 PATH_CALLBACK(fit_1_track);
264 PATH_CALLBACK(fit_2_tracks);
265 PATH_CALLBACK(fit_4_tracks);
266 PATH_CALLBACK(fit_8_tracks);
267 PATH_CALLBACK(fit_16_tracks);
268 PATH_CALLBACK(fit_32_tracks);
269 PATH_CALLBACK(fit_all_tracks);
270 PATH_CALLBACK(zoom_100_ms);
271 PATH_CALLBACK(zoom_1_sec);
272 PATH_CALLBACK(zoom_10_sec);
273 PATH_CALLBACK(zoom_1_min);
274 PATH_CALLBACK(zoom_5_min);
275 PATH_CALLBACK(zoom_10_min);
276 PATH_CALLBACK(zoom_to_session);
277 PATH_CALLBACK(temporal_zoom_in);
278 PATH_CALLBACK(temporal_zoom_out);
279 PATH_CALLBACK(scroll_up_1_track);
280 PATH_CALLBACK(scroll_dn_1_track);
281 PATH_CALLBACK(scroll_up_1_page);
282 PATH_CALLBACK(scroll_dn_1_page);
284 #define PATH_CALLBACK1(name,type,optional) \
285 static int _ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *data, void *user_data) { \
286 return static_cast<OSC*>(user_data)->cb_ ## name (path, types, argv, argc, data); \
288 int cb_ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *) { \
291 name (optional argv[0]->type); \
296 PATH_CALLBACK1(set_transport_speed,f,);
297 PATH_CALLBACK1(access_action,s,&);
299 PATH_CALLBACK1(jump_by_bars,f,);
300 PATH_CALLBACK1(jump_by_seconds,f,);
301 PATH_CALLBACK1(master_set_gain,f,);
302 PATH_CALLBACK1(master_set_fader,i,);
303 PATH_CALLBACK1(master_set_trim,f,);
304 PATH_CALLBACK1(master_set_pan_stereo_position,f,);
305 PATH_CALLBACK1(master_set_mute,i,);
306 PATH_CALLBACK1(monitor_set_gain,f,);
307 PATH_CALLBACK1(monitor_set_fader,i,);
309 #define PATH_CALLBACK1_MSG(name,arg1type) \
310 static int _ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *data, void *user_data) { \
311 return static_cast<OSC*>(user_data)->cb_ ## name (path, types, argv, argc, data); \
313 int cb_ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *data) { \
316 name (argv[0]->arg1type, data); \
321 PATH_CALLBACK1_MSG(set_surface_feedback,i);
323 #define PATH_CALLBACK2(name,arg1type,arg2type) \
324 static int _ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *data, void *user_data) { \
325 return static_cast<OSC*>(user_data)->cb_ ## name (path, types, argv, argc, data); \
327 int cb_ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *) { \
330 name (argv[0]->arg1type, argv[1]->arg2type); \
335 #define PATH_CALLBACK2_MSG(name,arg1type,arg2type) \
336 static int _ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *data, void *user_data) { \
337 return static_cast<OSC*>(user_data)->cb_ ## name (path, types, argv, argc, data); \
339 int cb_ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *data) { \
342 name (argv[0]->arg1type, argv[1]->arg2type, data); \
347 #define PATH_CALLBACK3(name,arg1type,arg2type,arg3type) \
348 static int _ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *data, void *user_data) { \
349 return static_cast<OSC*>(user_data)->cb_ ## name (path, types, argv, argc, data); \
351 int cb_ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *data) { \
354 name (argv[0]->arg1type, argv[1]->arg2type,argv[2]->arg3type, data); \
359 #define PATH_CALLBACK4(name,arg1type,arg2type,arg3type,arg4type) \
360 static int _ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *data, void *user_data) { \
361 return static_cast<OSC*>(user_data)->cb_ ## name (path, types, argv, argc, data); \
363 int cb_ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *data) { \
366 name (argv[0]->arg1type, argv[1]->arg2type,argv[2]->arg3type,argv[3]->arg4type, data); \
371 PATH_CALLBACK4(set_surface,i,i,i,i);
372 PATH_CALLBACK2(locate,i,i);
373 PATH_CALLBACK2(loop_location,i,i);
374 PATH_CALLBACK2_MSG(route_mute,i,i);
375 PATH_CALLBACK2_MSG(route_solo,i,i);
376 PATH_CALLBACK2_MSG(route_recenable,i,i);
377 PATH_CALLBACK2_MSG(route_recsafe,i,i);
378 PATH_CALLBACK2_MSG(route_monitor_input,i,i);
379 PATH_CALLBACK2_MSG(route_monitor_disk,i,i);
380 PATH_CALLBACK2_MSG(route_set_gain_abs,i,f);
381 PATH_CALLBACK2_MSG(route_set_gain_dB,i,f);
382 PATH_CALLBACK2_MSG(route_set_gain_fader,i,f);
383 PATH_CALLBACK2_MSG(route_set_trim_abs,i,f);
384 PATH_CALLBACK2_MSG(route_set_trim_dB,i,f);
385 PATH_CALLBACK2_MSG(route_set_pan_stereo_position,i,f);
386 PATH_CALLBACK2_MSG(route_set_pan_stereo_width,i,f);
387 PATH_CALLBACK3(route_set_send_gain_abs,i,i,f);
388 PATH_CALLBACK3(route_set_send_gain_dB,i,i,f);
389 PATH_CALLBACK4(route_plugin_parameter,i,i,i,f);
390 PATH_CALLBACK3(route_plugin_parameter_print,i,i,i);
392 int route_mute (int rid, int yn, lo_message msg);
393 int route_solo (int rid, int yn, lo_message msg);
394 int route_recenable (int rid, int yn, lo_message msg);
395 int route_recsafe (int ssid, int yn, lo_message msg);
396 int route_monitor_input (int rid, int yn, lo_message msg);
397 int route_monitor_disk (int rid, int yn, lo_message msg);
398 int route_set_gain_abs (int rid, float level, lo_message msg);
399 int route_set_gain_dB (int rid, float dB, lo_message msg);
400 int route_set_gain_fader (int rid, float pos, lo_message msg);
401 int route_set_trim_abs (int rid, float level, lo_message msg);
402 int route_set_trim_dB (int rid, float dB, lo_message msg);
403 int route_set_pan_stereo_position (int rid, float left_right_fraction, lo_message msg);
404 int route_set_pan_stereo_width (int rid, float percent, lo_message msg);
405 int route_set_send_gain_abs (int rid, int sid, float val, lo_message msg);
406 int route_set_send_gain_dB (int rid, int sid, float val, lo_message msg);
407 int route_plugin_parameter (int rid, int piid,int par, float val, lo_message msg);
408 int route_plugin_parameter_print (int rid, int piid,int par, lo_message msg);
411 int set_bank (uint32_t bank_start, lo_message msg);
412 int bank_up (lo_message msg);
413 int bank_down (lo_message msg);
414 int set_surface (uint32_t b_size, uint32_t strips, uint32_t fb, uint32_t gmode, lo_message msg);
415 int set_surface_feedback (uint32_t fb, lo_message msg);
417 int master_set_gain (float dB);
418 int master_set_fader (uint32_t position);
419 int master_set_trim (float dB);
420 int master_set_pan_stereo_position (float position);
421 int master_set_mute (uint32_t state);
422 int monitor_set_gain (float dB);
423 int monitor_set_fader (uint32_t position);
425 void listen_to_route (boost::shared_ptr<ARDOUR::Stripable>, lo_address);
426 void end_listen (boost::shared_ptr<ARDOUR::Stripable>, lo_address);
427 void drop_route (boost::weak_ptr<ARDOUR::Stripable>);
429 void route_name_changed (const PBD::PropertyChange&, boost::weak_ptr<ARDOUR::Route> r, lo_address addr);
431 void update_clock ();
432 bool periodic (void);
433 sigc::connection periodic_connection;
435 int route_send_fail (std::string path, uint32_t ssid, lo_message msg);
437 typedef std::list<OSCRouteObserver*> RouteObservers;
439 RouteObservers route_observers;
441 typedef std::list<OSCGlobalObserver*> GlobalObservers;
442 GlobalObservers global_observers;
444 void debugmsg (const char *prefix, const char *path, const char* types, lo_arg **argv, int argc);
446 static OSC* _instance;
454 #endif // ardour_osc_h