OSC link: first working commit for linking two surfaces as one
[ardour.git] / libs / surfaces / osc / osc.h
1 /*
2  * Copyright (C) 2006-2009 Paul Davis
3  *
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.
8  *
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.
13  *
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.
17  *
18  */
19
20 #ifndef ardour_osc_h
21 #define ardour_osc_h
22
23 #include <string>
24 #include <vector>
25 #include <bitset>
26
27 #include <sys/time.h>
28 #include <pthread.h>
29
30 #include <boost/shared_ptr.hpp>
31
32 #include <lo/lo.h>
33
34 #include <glibmm/main.h>
35
36 #define ABSTRACT_UI_EXPORTS
37 #include "pbd/abstract_ui.h"
38
39 #include "ardour/types.h"
40 #include "ardour/send.h"
41 #include "ardour/plugin.h"
42 #include "control_protocol/control_protocol.h"
43
44 #include "pbd/i18n.h"
45
46 class OSCControllable;
47 class OSCRouteObserver;
48 class OSCGlobalObserver;
49 class OSCSelectObserver;
50 class OSCCueObserver;
51
52 namespace ARDOUR {
53 class Session;
54 class Route;
55 }
56
57 /* this is mostly a placeholder because I suspect that at some
58    point we will want to add more members to accomodate
59    certain types of requests to the OSC UI
60 */
61
62 namespace ArdourSurface {
63
64 struct OSCUIRequest : public BaseUI::BaseRequestObject {
65   public:
66         OSCUIRequest () {}
67         ~OSCUIRequest() {}
68 };
69
70 class OSC : public ARDOUR::ControlProtocol, public AbstractUI<OSCUIRequest>
71 {
72   public:
73         OSC (ARDOUR::Session&, uint32_t port);
74         virtual ~OSC();
75
76         static OSC* instance() { return _instance; }
77
78         XMLNode& get_state ();
79         int set_state (const XMLNode&, int version);
80
81         void stripable_selection_changed () {}
82
83         bool has_editor () const { return true; }
84         void* get_gui () const;
85         void  tear_down_gui ();
86
87         int set_active (bool yn);
88         bool get_active () const;
89
90         // generic osc send
91
92         int float_message (std::string, float value, lo_address addr);
93         int text_message (std::string path, std::string val, lo_address addr);
94         int float_message_with_id (std::string, uint32_t ssid, float value, bool in_line, lo_address addr);
95         int int_message_with_id (std::string, uint32_t ssid, int value, bool in_line, lo_address addr);
96         int text_message_with_id (std::string path, uint32_t ssid, std::string val, bool in_line, lo_address addr);
97
98         int start ();
99         int stop ();
100
101         static void* request_factory (uint32_t);
102
103         enum OSCDebugMode {
104                 Off,
105                 Unhandled,
106                 All
107         };
108
109         enum JogMode {
110                 JOG,
111                 NUDGE,
112                 SCRUB,
113                 SHUTTLE,
114                 MARKER,
115                 SCROLL,
116                 TRACK,
117                 BANK
118         };
119
120         typedef std::vector<boost::shared_ptr<ARDOUR::Stripable> > Sorted;
121         Sorted get_sorted_stripables(std::bitset<32> types, bool cue);
122         typedef std::map<boost::shared_ptr<ARDOUR::AutomationControl>, uint32_t> FakeTouchMap;
123         FakeTouchMap _touch_timeout;
124
125 // keep a surface's global setup by remote server url
126         struct OSCSurface {
127         public:
128                 //global
129                 std::string remote_url;         // the url these setting belong to
130                 bool no_clear;                          // don't send osc clear messages on strip change
131                 JogMode jogmode;                        // current jogmode
132                 OSCGlobalObserver* global_obs;  // pointer to this surface's global observer
133                 uint32_t nstrips;                       // how many strips are there for strip_types
134                 std::bitset<32> feedback;       // What is fed back? strips/meters/timecode/bar_beat/global
135                 int gainmode;                           // what kind of faders do we have Gain db or position 0 to 1?
136                 PBD::Controllable::GroupControlDisposition usegroup;    // current group disposition
137                 Sorted strips;                          // list of stripables for this surface
138                 // strips
139                 uint32_t bank;                          // current bank
140                 uint32_t bank_size;                     // size of banks for this surface
141                 std::vector<OSCRouteObserver*> observers;       // route observers for this surface
142                 std::bitset<32> strip_types;// what strip types are a part of this bank
143                 //select
144                 OSCSelectObserver* sel_obs;     // So we can sync select feedback with selected channel
145                 uint32_t expand;                        // Used by /select/select
146                 bool expand_enable;                     // use expand instead of select
147                 boost::shared_ptr<ARDOUR::Stripable> select; // stripable this surface uses (maybe expand strip)                
148                 int plug_page;                          // current plugin page
149                 uint32_t plug_page_size;        // plugin page size (number of controls)
150                 int plugin_id;                  // id of current plugin
151                 std::vector<int> plug_params; // vector to store ports that are controls
152                 std::vector<int> plugins;       // stores allowable plugins with index (work around MB strip PIs)
153                 int send_page;                          // current send page
154                 uint32_t send_page_size;        // send page size in channels
155                 PBD::ScopedConnection proc_connection; // for processor signal monitoring
156                 // cue
157                 bool cue;                                       // is this a cue surface
158                 uint32_t aux;                           // aux index for this cue surface
159                 Sorted sends;                           // list of sends for cue aux
160                 OSCCueObserver* cue_obs;        // pointer to this surface's cue observer
161                 uint32_t linkset;                       // ID of a set of surfaces used as one
162                 uint32_t linkid;                        // ID of this surface within a linkset
163         };
164                 /*
165                  * feedback bits:
166                  * [0] - Strips - buttons
167                  * [1] - Strips - variables (pots/faders)
168                  * [2] - Strips - Send SSID as path extension
169                  * [3] - Send heart beat to surface
170                  * [4] - Send feedback for master/global buttons/variables
171                  * [5] - Send Bar and Beat
172                  * [6] - Send Time code
173                  * [7] - Send metering as dB or positional depending on gainmode
174                  * [8] - Send metering as 16 bits (led strip)
175                  * [9] - Send signal present (signal greater than -20dB)
176                  * [10] - Send Playhead position as samples
177                  * [11] - Send Playhead position as minutes seconds
178                  * [12] - Send Playhead position like primary/secondary GUI clocks
179                  * [13] - Send well known feedback (for /select/command
180                  * [14] - use OSC 1.0 only (#reply -> /reply)
181                  */
182
183
184 // storage for  each surface's settings
185         mutable Glib::Threads::Mutex surfaces_lock;
186         typedef std::vector<OSCSurface> Surface;
187         Surface _surface;
188
189 // linked surfaces
190         struct LinkSet {
191         public:
192                 std::vector<OSCSurface*> linked;        //linked surfaces
193                 uint32_t banksize;                              // linkset banksize
194                 uint32_t bank;                                  // linkset current bank
195                 bool autobank;                                  // banksize is derived from total
196                 uint32_t not_ready;                             // number of 1st device, 0 = ready
197                 std::bitset<32> strip_types;    // strip_types for this linkset
198                 Sorted strips;                                  // list of valid strips in order for this set
199         };
200
201         std::map<uint32_t, LinkSet> link_sets;
202          // list of linksets
203
204 // GUI calls
205         std::string get_server_url ();
206         void set_debug_mode (OSCDebugMode m) { _debugmode = m; }
207         OSCDebugMode get_debug_mode () { return _debugmode; }
208         int get_portmode() { return address_only; }
209         void set_portmode (int pm) { address_only = pm; }
210         int get_banksize () { return default_banksize; }
211         void set_banksize (int bs) {default_banksize = bs; }
212         int get_gainmode() { return default_gainmode; }
213         void set_gainmode (int gm) { default_gainmode = gm; }
214         int get_defaultstrip() { return default_strip; }
215         void set_defaultstrip (int st) { default_strip = st; }
216         int get_defaultfeedback() { return default_feedback; }
217         void set_defaultfeedback (int fb) { default_feedback = fb; }
218         int get_send_size() { return default_send_size; }
219         void set_send_size (int ss) { default_send_size = ss; }
220         int get_plugin_size() { return default_plugin_size; }
221         void set_plugin_size (int ps) { default_plugin_size = ps; }
222         void clear_devices ();
223         void gui_changed ();
224         std::string get_remote_port () { return remote_port; }
225         void set_remote_port (std::string pt) { remote_port = pt; }
226
227   protected:
228         void thread_init ();
229         void do_request (OSCUIRequest*);
230
231         GSource* local_server;
232         GSource* remote_server;
233
234         bool osc_input_handler (Glib::IOCondition, lo_server);
235
236   private:
237         uint32_t _port;
238         volatile bool _ok;
239         volatile bool _shutdown;
240         lo_server _osc_server;
241         lo_server _osc_unix_server;
242         std::string _osc_unix_socket_path;
243         std::string _osc_url_file;
244         OSCDebugMode _debugmode;
245         bool address_only;
246         std::string remote_port;
247         uint32_t default_banksize;
248         uint32_t default_strip;
249         uint32_t default_feedback;
250         uint32_t default_gainmode;
251         uint32_t default_send_size;
252         uint32_t default_plugin_size;
253         bool tick;
254         bool bank_dirty;
255         bool observer_busy;
256         float scrub_speed;              // Current scrub speed
257         double scrub_place;             // place of play head at latest jog/scrub wheel tick
258         int64_t scrub_time;             // when did the wheel move last?
259         bool global_init;
260         boost::shared_ptr<ARDOUR::Stripable> _select;   // which stripable out of /surface/stripables is gui selected
261
262         void register_callbacks ();
263
264         void route_added (ARDOUR::RouteList&);
265
266         // Handlers for "Application Hook" signals
267         void session_loaded (ARDOUR::Session&);
268         void session_exported (std::string, std::string);
269
270         // end "Application Hook" handles
271
272         std::string get_unix_server_url ();
273         lo_address get_address (lo_message msg);
274         OSCSurface * get_surface (lo_address addr, bool quiet = false);
275         int check_surface (lo_message msg);
276         uint32_t get_sid (boost::shared_ptr<ARDOUR::Stripable> strip, lo_address addr);
277         boost::shared_ptr<ARDOUR::Stripable> get_strip (uint32_t ssid, lo_address addr);
278         void global_feedback (OSCSurface* sur);
279         void strip_feedback (OSCSurface* sur, bool new_bank_size);
280         void surface_destroy (OSCSurface* sur);
281         uint32_t bank_limits_check (uint32_t bank, uint32_t size, uint32_t total);
282         void bank_leds (OSCSurface* sur);
283
284         void send_current_value (const char* path, lo_arg** argv, int argc, lo_message msg);
285         void current_value_query (const char* path, size_t len, lo_arg **argv, int argc, lo_message msg);
286
287         int current_value (const char *path, const char *types, lo_arg **argv, int argc, void *data, void *user_data);
288
289         int catchall (const char *path, const char *types, lo_arg **argv, int argc, void *data);
290         static int _catchall (const char *path, const char *types, lo_arg **argv, int argc, void *data, void *user_data);
291
292         int set_automation (const char *path, const char* types, lo_arg **argv, int argc, lo_message msg);
293         int touch_detect (const char *path, const char* types, lo_arg **argv, int argc, lo_message msg);
294         int fake_touch (boost::shared_ptr<ARDOUR::AutomationControl> ctrl);
295
296         int route_get_sends (lo_message msg);
297         int route_get_receives(lo_message msg);
298         void routes_list (lo_message msg);
299         void surface_list (lo_message msg);
300         void transport_sample (lo_message msg);
301         void transport_speed (lo_message msg);
302         void record_enabled (lo_message msg);
303
304         // cue
305         Sorted cue_get_sorted_stripables(boost::shared_ptr<ARDOUR::Stripable> aux, uint32_t id, lo_message msg);
306         int cue_parse (const char *path, const char* types, lo_arg **argv, int argc, lo_message msg);
307         int cue_set (uint32_t aux, lo_message msg);
308         int _cue_set (uint32_t aux, lo_address addr);
309         int cue_next (lo_message msg);
310         int cue_previous (lo_message msg);
311         int cue_send_fader (uint32_t id, float position, lo_message msg);
312         int cue_send_enable (uint32_t id, float state, lo_message msg);
313         int cue_aux_fader (float position, lo_message msg);
314         int cue_aux_mute (float state, lo_message msg);
315         void cue_set_aux (uint32_t aux, lo_message msg);
316         boost::shared_ptr<ARDOUR::Send> cue_get_send (uint32_t id, lo_address addr);
317         // end cue
318
319         // link
320         int parse_link (const char *path, const char* types, lo_arg **argv, int argc, lo_message msg);
321         int link_check (uint32_t linkset);
322
323         int select_plugin_parameter (const char *path, const char* types, lo_arg **argv, int argc, lo_message msg);
324         int surface_parse (const char *path, const char* types, lo_arg **argv, int argc, lo_message msg);
325
326 #define OSC_DEBUG \
327         if (_debugmode == All) { \
328                 debugmsg (dgettext(PACKAGE, "OSC"), path, types, argv, argc); \
329         }
330
331 #define PATH_CALLBACK_MSG(name) \
332         static int _ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *data, void *user_data) { \
333                 return static_cast<OSC*>(user_data)->cb_ ## name (path, types, argv, argc, data); \
334         } \
335         int cb_ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *data) { \
336                 OSC_DEBUG; \
337                 if (argc > 0 && !strcmp (types, "f") && argv[0]->f != 1.0) { return 0; } \
338                 name (data); \
339                 return 0; \
340         }
341
342         PATH_CALLBACK_MSG(route_get_sends);
343         PATH_CALLBACK_MSG(route_get_receives);
344         PATH_CALLBACK_MSG(routes_list);
345         PATH_CALLBACK_MSG(surface_list);
346         PATH_CALLBACK_MSG(transport_sample);
347         PATH_CALLBACK_MSG(transport_speed);
348         PATH_CALLBACK_MSG(record_enabled);
349         PATH_CALLBACK_MSG(refresh_surface);
350         PATH_CALLBACK_MSG(bank_up);
351         PATH_CALLBACK_MSG(bank_down);
352         PATH_CALLBACK_MSG(master_select);
353
354 #define PATH_CALLBACK(name) \
355         static int _ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *data, void *user_data) { \
356                 return static_cast<OSC*>(user_data)->cb_ ## name (path, types, argv, argc, data); \
357         } \
358         int cb_ ## name (const char *path, const char *types, lo_arg ** argv, int argc, void *data) { \
359                 OSC_DEBUG; \
360                 check_surface (data); \
361                 if (argc > 0 && !strcmp (types, "f") && argv[0]->f != 1.0) { return 0; } \
362                 name (); \
363                 return 0; \
364         }
365
366         PATH_CALLBACK(add_marker);
367         PATH_CALLBACK(loop_toggle);
368         PATH_CALLBACK(goto_start);
369         PATH_CALLBACK(goto_end);
370         PATH_CALLBACK(rewind);
371         PATH_CALLBACK(ffwd);
372         PATH_CALLBACK(transport_stop);
373         PATH_CALLBACK(transport_play);
374         PATH_CALLBACK(save_state);
375         PATH_CALLBACK(prev_marker);
376         PATH_CALLBACK(next_marker);
377         PATH_CALLBACK(undo);
378         PATH_CALLBACK(redo);
379         PATH_CALLBACK(toggle_punch_in);
380         PATH_CALLBACK(toggle_punch_out);
381         PATH_CALLBACK(rec_enable_toggle);
382         PATH_CALLBACK(toggle_all_rec_enables);
383         PATH_CALLBACK(all_tracks_rec_in);
384         PATH_CALLBACK(all_tracks_rec_out);
385         PATH_CALLBACK(cancel_all_solos);
386         PATH_CALLBACK(remove_marker_at_playhead);
387         PATH_CALLBACK(mark_in);
388         PATH_CALLBACK(mark_out);
389         PATH_CALLBACK(toggle_click);
390         PATH_CALLBACK(midi_panic);
391         PATH_CALLBACK(toggle_roll);
392         PATH_CALLBACK(stop_forget);
393         PATH_CALLBACK(set_punch_range);
394         PATH_CALLBACK(set_loop_range);
395         PATH_CALLBACK(set_session_range);
396         PATH_CALLBACK(toggle_monitor_mute);
397         PATH_CALLBACK(toggle_monitor_dim);
398         PATH_CALLBACK(toggle_monitor_mono);
399         PATH_CALLBACK(quick_snapshot_stay);
400         PATH_CALLBACK(quick_snapshot_switch);
401         PATH_CALLBACK(fit_1_track);
402         PATH_CALLBACK(fit_2_tracks);
403         PATH_CALLBACK(fit_4_tracks);
404         PATH_CALLBACK(fit_8_tracks);
405         PATH_CALLBACK(fit_16_tracks);
406         PATH_CALLBACK(fit_32_tracks);
407         PATH_CALLBACK(fit_all_tracks);
408         PATH_CALLBACK(zoom_100_ms);
409         PATH_CALLBACK(zoom_1_sec);
410         PATH_CALLBACK(zoom_10_sec);
411         PATH_CALLBACK(zoom_1_min);
412         PATH_CALLBACK(zoom_5_min);
413         PATH_CALLBACK(zoom_10_min);
414         PATH_CALLBACK(zoom_to_session);
415         PATH_CALLBACK(temporal_zoom_in);
416         PATH_CALLBACK(temporal_zoom_out);
417         PATH_CALLBACK(scroll_up_1_track);
418         PATH_CALLBACK(scroll_dn_1_track);
419         PATH_CALLBACK(scroll_up_1_page);
420         PATH_CALLBACK(scroll_dn_1_page);
421
422 #define PATH_CALLBACK1(name,type,optional) \
423         static int _ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *data, void *user_data) { \
424                 return static_cast<OSC*>(user_data)->cb_ ## name (path, types, argv, argc, data); \
425         } \
426         int cb_ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *data) { \
427                 OSC_DEBUG; \
428                 check_surface (data); \
429                 if (argc > 0) { \
430                         name (optional argv[0]->type); \
431                 } \
432                 return 0; \
433         }
434
435         PATH_CALLBACK1(set_transport_speed,f,);
436         PATH_CALLBACK1(access_action,s,&);
437
438         PATH_CALLBACK1(jump_by_bars,f,);
439         PATH_CALLBACK1(jump_by_seconds,f,);
440         PATH_CALLBACK1(master_set_gain,f,);
441         PATH_CALLBACK1(master_set_fader,f,);
442         PATH_CALLBACK1(master_delta_gain,f,);
443         PATH_CALLBACK1(master_set_trim,f,);
444         PATH_CALLBACK1(master_set_mute,i,);
445         PATH_CALLBACK1(monitor_set_gain,f,);
446         PATH_CALLBACK1(monitor_set_fader,f,);
447         PATH_CALLBACK1(monitor_delta_gain,f,);
448         PATH_CALLBACK1(monitor_set_mute,i,);
449         PATH_CALLBACK1(monitor_set_dim,i,);
450         PATH_CALLBACK1(monitor_set_mono,i,);
451         PATH_CALLBACK1(click_level,f,);
452
453 #define PATH_CALLBACK1_MSG(name,arg1type) \
454         static int _ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *data, void *user_data) { \
455                 return static_cast<OSC*>(user_data)->cb_ ## name (path, types, argv, argc, data); \
456         } \
457         int cb_ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *data) { \
458                 OSC_DEBUG; \
459                 if (argc > 0) { \
460                         name (argv[0]->arg1type, data); \
461                 } \
462                 return 0; \
463         }
464
465         // pan position needs message info to send feedback
466         PATH_CALLBACK1_MSG(master_set_pan_stereo_position,f);
467
468         PATH_CALLBACK1_MSG(scrub,f);
469         PATH_CALLBACK1_MSG(jog,f);
470         PATH_CALLBACK1_MSG(jog_mode,f);
471         PATH_CALLBACK1_MSG(bank_delta,f);
472         PATH_CALLBACK1_MSG(use_group,f);
473         PATH_CALLBACK1_MSG(sel_recenable,i);
474         PATH_CALLBACK1_MSG(sel_recsafe,i);
475         PATH_CALLBACK1_MSG(sel_mute,i);
476         PATH_CALLBACK1_MSG(sel_master_send_enable,i);
477         PATH_CALLBACK1_MSG(sel_solo,i);
478         PATH_CALLBACK1_MSG(sel_solo_iso,i);
479         PATH_CALLBACK1_MSG(sel_solo_safe,i);
480         PATH_CALLBACK1_MSG(sel_monitor_input,i);
481         PATH_CALLBACK1_MSG(sel_monitor_disk,i);
482         PATH_CALLBACK1_MSG(sel_phase,i);
483         PATH_CALLBACK1_MSG(sel_gain,f);
484         PATH_CALLBACK1_MSG(sel_fader,f);
485         PATH_CALLBACK1_MSG(sel_dB_delta,f);
486         PATH_CALLBACK1_MSG(sel_trim,f);
487         PATH_CALLBACK1_MSG(sel_pan_position,f);
488         PATH_CALLBACK1_MSG(sel_pan_width,f);
489         PATH_CALLBACK1_MSG(sel_pan_elevation,f);
490         PATH_CALLBACK1_MSG(sel_pan_frontback,f);
491         PATH_CALLBACK1_MSG(sel_pan_lfe,f);
492         PATH_CALLBACK1_MSG(sel_send_page,f);
493         PATH_CALLBACK1_MSG(sel_plug_page,f);
494         PATH_CALLBACK1_MSG(sel_plugin,f);
495         PATH_CALLBACK1_MSG(sel_comp_enable,f);
496         PATH_CALLBACK1_MSG(sel_comp_threshold,f);
497         PATH_CALLBACK1_MSG(sel_comp_speed,f);
498         PATH_CALLBACK1_MSG(sel_comp_mode,f);
499         PATH_CALLBACK1_MSG(sel_comp_makeup,f);
500         PATH_CALLBACK1_MSG(sel_eq_enable,f);
501         PATH_CALLBACK1_MSG(sel_eq_hpf_freq,f);
502         PATH_CALLBACK1_MSG(sel_eq_hpf_enable,f);
503         PATH_CALLBACK1_MSG(sel_eq_hpf_slope,f);
504         PATH_CALLBACK1_MSG(sel_eq_lpf_freq,f);
505         PATH_CALLBACK1_MSG(sel_eq_lpf_enable,f);
506         PATH_CALLBACK1_MSG(sel_eq_lpf_slope,f);
507         PATH_CALLBACK1_MSG(sel_expand,i);
508
509 #define PATH_CALLBACK2(name,arg1type,arg2type) \
510         static int _ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *data, void *user_data) { \
511                 return static_cast<OSC*>(user_data)->cb_ ## name (path, types, argv, argc, data); \
512         } \
513         int cb_ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *data) { \
514                 OSC_DEBUG; \
515                 check_surface (data); \
516                 if (argc > 1) { \
517                         name (argv[0]->arg1type, argv[1]->arg2type); \
518                 } \
519                 return 0; \
520         }
521
522 #define PATH_CALLBACK2_MSG(name,arg1type,arg2type) \
523         static int _ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *data, void *user_data) { \
524                 return static_cast<OSC*>(user_data)->cb_ ## name (path, types, argv, argc, data); \
525         } \
526         int cb_ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *data) { \
527                 OSC_DEBUG; \
528                 if (argc > 1) { \
529                         name (argv[0]->arg1type, argv[1]->arg2type, data); \
530                 } \
531                 return 0; \
532         }
533
534 #define PATH_CALLBACK2_MSG_s(name,arg1type,arg2type) \
535         static int _ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *data, void *user_data) { \
536                 return static_cast<OSC*>(user_data)->cb_ ## name (path, types, argv, argc, data); \
537         } \
538         int cb_ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *data) { \
539                 OSC_DEBUG; \
540                 if (argc > 1) { \
541                         name (argv[0]->arg1type, &argv[1]->arg2type, data); \
542                 } \
543                 return 0; \
544         }
545
546 #define PATH_CALLBACK3(name,arg1type,arg2type,arg3type) \
547         static int _ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *data, void *user_data) { \
548                 return static_cast<OSC*>(user_data)->cb_ ## name (path, types, argv, argc, data); \
549         } \
550         int cb_ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *data) { \
551                 OSC_DEBUG; \
552                 if (argc > 1) { \
553                         name (argv[0]->arg1type, argv[1]->arg2type,argv[2]->arg3type, data); \
554                 } \
555                 return 0; \
556         }
557
558 #define PATH_CALLBACK4(name,arg1type,arg2type,arg3type,arg4type) \
559         static int _ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *data, void *user_data) { \
560                 return static_cast<OSC*>(user_data)->cb_ ## name (path, types, argv, argc, data); \
561         } \
562         int cb_ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *data) { \
563                 OSC_DEBUG; \
564                 if (argc > 1) { \
565                         name (argv[0]->arg1type, argv[1]->arg2type,argv[2]->arg3type,argv[3]->arg4type, data); \
566                 } \
567                 return 0; \
568         }
569
570         PATH_CALLBACK2_MSG(sel_sendgain,i,f);
571         PATH_CALLBACK2_MSG(sel_sendfader,i,f);
572         PATH_CALLBACK2_MSG(sel_sendenable,i,f);
573         PATH_CALLBACK2_MSG(sel_eq_gain,i,f);
574         PATH_CALLBACK2_MSG(sel_eq_freq,i,f);
575         PATH_CALLBACK2_MSG(sel_eq_q,i,f);
576         PATH_CALLBACK2_MSG(sel_eq_shape,i,f);
577
578         PATH_CALLBACK2(locate,i,i);
579         PATH_CALLBACK2(loop_location,i,i);
580         PATH_CALLBACK2_MSG_s(route_rename,i,s);
581         PATH_CALLBACK2_MSG(route_mute,i,i);
582         PATH_CALLBACK2_MSG(route_solo,i,i);
583         PATH_CALLBACK2_MSG(route_solo_iso,i,i);
584         PATH_CALLBACK2_MSG(route_solo_safe,i,i);
585         PATH_CALLBACK2_MSG(route_recenable,i,i);
586         PATH_CALLBACK2_MSG(route_recsafe,i,i);
587         PATH_CALLBACK2_MSG(route_monitor_input,i,i);
588         PATH_CALLBACK2_MSG(route_monitor_disk,i,i);
589         PATH_CALLBACK2_MSG(strip_phase,i,i);
590         PATH_CALLBACK2_MSG(strip_expand,i,i);
591         PATH_CALLBACK2_MSG(strip_gui_select,i,i);
592         PATH_CALLBACK2_MSG(route_set_gain_dB,i,f);
593         PATH_CALLBACK2_MSG(route_set_gain_fader,i,f);
594         PATH_CALLBACK2_MSG(route_set_trim_dB,i,f);
595         PATH_CALLBACK2_MSG(route_set_pan_stereo_position,i,f);
596         PATH_CALLBACK2_MSG(route_set_pan_stereo_width,i,f);
597         PATH_CALLBACK3(route_set_send_gain_dB,i,i,f);
598         PATH_CALLBACK3(route_set_send_fader,i,i,f);
599         PATH_CALLBACK3(route_set_send_enable,i,i,f);
600         PATH_CALLBACK4(route_plugin_parameter,i,i,i,f);
601         PATH_CALLBACK3(route_plugin_parameter_print,i,i,i);
602         PATH_CALLBACK2_MSG(route_plugin_activate,i,i);
603         PATH_CALLBACK2_MSG(route_plugin_deactivate,i,i);
604         PATH_CALLBACK1_MSG(route_plugin_list,i);
605         PATH_CALLBACK2_MSG(route_plugin_descriptor,i,i);
606         PATH_CALLBACK2_MSG(route_plugin_reset,i,i);
607
608         int route_rename (int rid, char *s, lo_message msg);
609         int route_mute (int rid, int yn, lo_message msg);
610         int route_solo (int rid, int yn, lo_message msg);
611         int route_solo_iso (int rid, int yn, lo_message msg);
612         int route_solo_safe (int rid, int yn, lo_message msg);
613         int route_recenable (int rid, int yn, lo_message msg);
614         int route_recsafe (int ssid, int yn, lo_message msg);
615         int route_monitor_input (int rid, int yn, lo_message msg);
616         int route_monitor_disk (int rid, int yn, lo_message msg);
617         int strip_phase (int rid, int yn, lo_message msg);
618         int strip_expand (int rid, int yn, lo_message msg);
619         int _strip_select (boost::shared_ptr<ARDOUR::Stripable> s, lo_address addr, bool quiet = false);
620         int strip_gui_select (int rid, int yn, lo_message msg);
621         int route_set_gain_abs (int rid, float level, lo_message msg);
622         int route_set_gain_dB (int rid, float dB, lo_message msg);
623         int route_set_gain_fader (int rid, float pos, lo_message msg);
624         int strip_db_delta (int ssid, float delta, lo_message msg);
625         int route_set_trim_abs (int rid, float level, lo_message msg);
626         int route_set_trim_dB (int rid, float dB, lo_message msg);
627         int route_set_pan_stereo_position (int rid, float left_right_fraction, lo_message msg);
628         int route_set_pan_stereo_width (int rid, float percent, lo_message msg);
629         int route_set_send_gain_dB (int rid, int sid, float val, lo_message msg);
630         int route_set_send_fader (int rid, int sid, float val, lo_message msg);
631         int route_set_send_enable (int rid, int sid, float val, lo_message msg);
632         int route_plugin_parameter (int rid, int piid,int par, float val, lo_message msg);
633         int route_plugin_parameter_print (int rid, int piid,int par, lo_message msg);
634         int route_plugin_activate (int rid, int piid, lo_message msg);
635         int route_plugin_deactivate (int rid, int piid, lo_message msg);
636         int route_plugin_list(int ssid, lo_message msg);
637         int route_plugin_descriptor(int ssid, int piid, lo_message msg);
638         int route_plugin_reset(int ssid, int piid, lo_message msg);
639
640         //banking functions
641         int set_bank (uint32_t bank_start, lo_message msg);
642         int _set_bank (uint32_t bank_start, lo_address addr);
643         int bank_up (lo_message msg);
644         int bank_delta (float delta, lo_message msg);
645         int use_group (float value, lo_message msg);
646         int bank_down (lo_message msg);
647         int set_surface (uint32_t b_size, uint32_t strips, uint32_t fb, uint32_t gmode, uint32_t se_size, uint32_t pi_size, lo_message msg);
648         int set_surface_bank_size (uint32_t bs, lo_message msg);
649         int set_surface_strip_types (uint32_t st, lo_message msg);
650         int set_surface_feedback (uint32_t fb, lo_message msg);
651         int set_surface_gainmode (uint32_t gm, lo_message msg);
652         int refresh_surface (lo_message msg);
653         int sel_send_pagesize (uint32_t size, lo_message msg);
654         int sel_send_page (int page, lo_message msg);
655         int sel_plug_pagesize (uint32_t size, lo_message msg);
656         int sel_plug_page (int page, lo_message msg);
657         int sel_plugin (int delta, lo_message msg);
658         int _sel_plugin (int id, lo_address addr);
659         void processor_changed (lo_address addr);
660
661         int scrub (float delta, lo_message msg);
662         int jog (float delta, lo_message msg);
663         int jog_mode (float mode, lo_message msg);
664         int click_level (float position);
665         int master_set_gain (float dB);
666         int master_set_fader (float position);
667         int master_delta_gain (float delta);
668         int master_set_trim (float dB);
669         int master_set_pan_stereo_position (float position, lo_message msg);
670         int master_set_mute (uint32_t state);
671         int master_select (lo_message msg);
672         int monitor_set_gain (float dB);
673         int monitor_set_fader (float position);
674         int monitor_delta_gain (float delta);
675         int monitor_set_mute (uint32_t state);
676         int monitor_set_dim (uint32_t state);
677         int monitor_set_mono (uint32_t state);
678         int sel_recenable (uint32_t state, lo_message msg);
679         int sel_recsafe (uint32_t state, lo_message msg);
680         int sel_mute (uint32_t state, lo_message msg);
681         int sel_solo (uint32_t state, lo_message msg);
682         int sel_solo_iso (uint32_t state, lo_message msg);
683         int sel_solo_safe (uint32_t state, lo_message msg);
684         int sel_monitor_input (uint32_t state, lo_message msg);
685         int sel_monitor_disk (uint32_t state, lo_message msg);
686         int sel_phase (uint32_t state, lo_message msg);
687         int sel_gain (float state, lo_message msg);
688         int sel_fader (float state, lo_message msg);
689         int sel_dB_delta (float delta, lo_message msg);
690         int sel_trim (float val, lo_message msg);
691         int sel_pan_position (float val, lo_message msg);
692         int sel_pan_width (float val, lo_message msg);
693         int sel_sendgain (int id, float dB, lo_message msg);
694         int sel_sendfader (int id, float pos, lo_message msg);
695         int sel_sendenable (int id, float pos, lo_message msg);
696         int sel_master_send_enable (int state, lo_message msg);
697         int sel_expand (uint32_t state, lo_message msg);
698         int sel_pan_elevation (float val, lo_message msg);
699         int sel_pan_frontback (float val, lo_message msg);
700         int sel_pan_lfe (float val, lo_message msg);
701         int sel_comp_enable (float val, lo_message msg);
702         int sel_comp_threshold (float val, lo_message msg);
703         int sel_comp_speed (float val, lo_message msg);
704         int sel_comp_mode (float val, lo_message msg);
705         int sel_comp_makeup (float val, lo_message msg);
706         int sel_eq_enable (float val, lo_message msg);
707         int sel_eq_hpf_freq (float val, lo_message msg);
708         int sel_eq_hpf_enable (float val, lo_message msg);
709         int sel_eq_hpf_slope (float val, lo_message msg);
710         int sel_eq_lpf_freq (float val, lo_message msg);
711         int sel_eq_lpf_enable (float val, lo_message msg);
712         int sel_eq_lpf_slope (float val, lo_message msg);
713         int sel_eq_gain (int id, float val, lo_message msg);
714         int sel_eq_freq (int id, float val, lo_message msg);
715         int sel_eq_q (int id, float val, lo_message msg);
716         int sel_eq_shape (int id, float val, lo_message msg);
717
718         void listen_to_route (boost::shared_ptr<ARDOUR::Stripable>, lo_address);
719
720         void route_name_changed (const PBD::PropertyChange&, boost::weak_ptr<ARDOUR::Route> r, lo_address addr);
721         void recalcbanks ();
722         void _recalcbanks ();
723         void notify_routes_added (ARDOUR::RouteList &);
724         void notify_vca_added (ARDOUR::VCAList &);
725
726         int cancel_all_solos ();
727         bool periodic (void);
728         sigc::connection periodic_connection;
729         PBD::ScopedConnectionList session_connections;
730
731         void debugmsg (const char *prefix, const char *path, const char* types, lo_arg **argv, int argc);
732
733         static OSC* _instance;
734
735         mutable void *gui;
736         void build_gui ();
737 };
738
739 } // namespace
740
741 #endif // ardour_osc_h