OSC: logic thinko fix
[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         Glib::Threads::Mutex _lo_lock;
92         int float_message (std::string, float value, lo_address addr);
93         int int_message (std::string, int value, lo_address addr);
94         int text_message (std::string path, std::string val, lo_address addr);
95         int float_message_with_id (std::string, uint32_t ssid, float value, bool in_line, lo_address addr);
96         int int_message_with_id (std::string, uint32_t ssid, int value, bool in_line, lo_address addr);
97         int text_message_with_id (std::string path, uint32_t ssid, std::string val, bool in_line, lo_address addr);
98
99         int send_group_list (lo_address addr);
100
101         int start ();
102         int stop ();
103
104         static void* request_factory (uint32_t);
105
106         enum OSCDebugMode {
107                 Off,
108                 Unhandled,
109                 All
110         };
111
112         enum OSCTempMode {
113                 TempOff = 0,
114                 GroupOnly = 1,
115                 VCAOnly = 2,
116                 BusOnly = 3
117         };
118
119         typedef std::vector<boost::shared_ptr<ARDOUR::Stripable> > Sorted;
120         Sorted get_sorted_stripables(std::bitset<32> types, bool cue, uint32_t custom, Sorted my_list);
121         typedef std::map<boost::shared_ptr<ARDOUR::AutomationControl>, uint32_t> FakeTouchMap;
122         FakeTouchMap _touch_timeout;
123
124 // keep a surface's global setup by remote server url
125         struct OSCSurface {
126         public:
127                 //global
128                 std::string remote_url;         // the url these setting belong to
129                 bool no_clear;                          // don't send osc clear messages on strip change
130                 uint32_t jogmode;                       // current jogmode
131                 OSCGlobalObserver* global_obs;  // pointer to this surface's global observer
132                 uint32_t nstrips;                       // how many strips are there for strip_types
133                 std::bitset<32> feedback;       // What is fed back? strips/meters/timecode/bar_beat/global
134                 int gainmode;                           // what kind of faders do we have Gain db or position 0 to 1?
135                 PBD::Controllable::GroupControlDisposition usegroup;    // current group disposition
136                 Sorted custom_strips;           // a sorted list of user selected strips
137                 uint32_t custom_mode;           // use custom strip list
138                 OSCTempMode temp_mode;          // use temp strip list
139                 Sorted temp_strips;                     // temp strip list for grouponly, vcaonly, auxonly
140                 boost::shared_ptr<ARDOUR::Stripable> temp_master; // stripable this surface uses as temp master
141                 Sorted strips;                          // list of stripables for this surface
142                 // strips
143                 uint32_t bank;                          // current bank
144                 uint32_t bank_size;                     // size of banks for this surface
145                 std::vector<OSCRouteObserver*> observers;       // route observers for this surface
146                 std::bitset<32> strip_types;// what strip types are a part of this bank
147                 //select
148                 OSCSelectObserver* sel_obs;     // So we can sync select feedback with selected channel
149                 uint32_t expand;                        // Used by /select/select
150                 bool expand_enable;                     // use expand instead of select
151                 boost::shared_ptr<ARDOUR::Stripable> expand_strip; // stripable this surface uses for expand
152                 boost::shared_ptr<ARDOUR::Stripable> select; // stripable this surface uses as selected
153                 int plug_page;                          // current plugin page
154                 uint32_t plug_page_size;        // plugin page size (number of controls)
155                 int plugin_id;                  // id of current plugin
156                 std::vector<int> plug_params; // vector to store ports that are controls
157                 std::vector<int> plugins;       // stores allowable plugins with index (work around MB strip PIs)
158                 int send_page;                          // current send page
159                 uint32_t send_page_size;        // send page size in channels
160                 uint32_t nsends;                        // number of sends select has
161                 PBD::ScopedConnection proc_connection; // for processor signal monitoring
162                 // cue
163                 bool cue;                                       // is this a cue surface
164                 uint32_t aux;                           // aux index for this cue surface
165                 Sorted sends;                           // list of sends for cue aux
166                 OSCCueObserver* cue_obs;        // pointer to this surface's cue observer
167                 uint32_t linkset;                       // ID of a set of surfaces used as one
168                 uint32_t linkid;                        // ID of this surface within a linkset
169         };
170                 /*
171                  * feedback bits:
172                  * [0] - Strips - buttons
173                  * [1] - Strips - variables (pots/faders)
174                  * [2] - Strips - Send SSID as path extension
175                  * [3] - Send heart beat to surface
176                  * [4] - Send feedback for master/global buttons/variables
177                  * [5] - Send Bar and Beat
178                  * [6] - Send Time code
179                  * [7] - Send metering as dB or positional depending on gainmode
180                  * [8] - Send metering as 16 bits (led strip)
181                  * [9] - Send signal present (signal greater than -20dB)
182                  * [10] - Send Playhead position as samples
183                  * [11] - Send Playhead position as minutes seconds
184                  * [12] - Send Playhead position like primary/secondary GUI clocks
185                  * [13] - Send well known feedback (for /select/command
186                  * [14] - use OSC 1.0 only (#reply -> /reply)
187                  *
188                  * Strip_type bits:
189                  * [0] - Audio Tracks
190                  * [1] - Midi Tracks
191                  * [2] - Audio Bus
192                  * [3] - Midi Bus
193                  * [4] - VCAs
194                  * [5] - master
195                  * [6] - Monitor
196                  * [7] - Listen Bus
197                  * [8] - Selected
198                  * [9] - Hidden
199                  * [10] - Use Groups
200                  * [11] - Global Expand
201                  */
202
203 // storage for  each surface's settings
204         mutable Glib::Threads::Mutex surfaces_lock;
205         typedef std::vector<OSCSurface> Surface;
206         Surface _surface;
207
208 // linked surfaces
209         struct LinkSet {
210         public:
211                 std::vector<std::string> urls;  //urls of linked surfaces
212                 uint32_t banksize;                              // linkset banksize
213                 uint32_t bank;                                  // linkset current bank
214                 bool autobank;                                  // banksize is derived from total
215                 uint32_t not_ready;                             // number of 1st device, 0 = ready
216                 Sorted custom_strips;                   // a sorted list of user selected strips
217                 uint32_t custom_mode;                   // use custom strip list
218                 OSCTempMode temp_mode;                  // use custom strip list
219                 Sorted temp_strips;                             // temp strip list for grouponly, vcaonly, auxonly
220                 boost::shared_ptr<ARDOUR::Stripable> temp_master; // temp master stripable
221                 std::bitset<32> strip_types;    // strip_types for this linkset
222                 Sorted strips;                                  // list of valid strips in order for this set
223         };
224
225         std::map<uint32_t, LinkSet> link_sets;
226          // list of linksets
227
228         struct PortAdd {
229         public:
230                 std::string host;
231                 std::string port;
232         };
233
234         std::vector<PortAdd> _ports;
235
236 // GUI calls
237         std::string get_server_url ();
238         void set_debug_mode (OSCDebugMode m) { _debugmode = m; }
239         OSCDebugMode get_debug_mode () { return _debugmode; }
240         int get_portmode() { return address_only; }
241         void set_portmode (int pm) { address_only = pm; }
242         int get_banksize () { return default_banksize; }
243         void set_banksize (int bs) {default_banksize = bs; }
244         int get_gainmode() { return default_gainmode; }
245         void set_gainmode (int gm) { default_gainmode = gm; }
246         int get_defaultstrip() { return default_strip; }
247         void set_defaultstrip (int st) { default_strip = st; }
248         int get_defaultfeedback() { return default_feedback; }
249         void set_defaultfeedback (int fb) { default_feedback = fb; }
250         int get_send_size() { return default_send_size; }
251         void set_send_size (int ss) { default_send_size = ss; }
252         int get_plugin_size() { return default_plugin_size; }
253         void set_plugin_size (int ps) { default_plugin_size = ps; }
254         void clear_devices ();
255         void gui_changed ();
256         void get_surfaces ();
257         std::string get_remote_port () { return remote_port; }
258         void set_remote_port (std::string pt) { remote_port = pt; }
259
260   protected:
261         void thread_init ();
262         void do_request (OSCUIRequest*);
263
264         GSource* local_server;
265         GSource* remote_server;
266
267         bool osc_input_handler (Glib::IOCondition, lo_server);
268
269   private:
270         uint32_t _port;
271         volatile bool _ok;
272         volatile bool _shutdown;
273         lo_server _osc_server;
274         lo_server _osc_unix_server;
275         std::string _osc_unix_socket_path;
276         std::string _osc_url_file;
277         OSCDebugMode _debugmode;
278         bool address_only;
279         std::string remote_port;
280         uint32_t default_banksize;
281         uint32_t default_strip;
282         uint32_t default_feedback;
283         uint32_t default_gainmode;
284         uint32_t default_send_size;
285         uint32_t default_plugin_size;
286         bool tick;
287         bool bank_dirty;
288         bool observer_busy;
289         float scrub_speed;              // Current scrub speed
290         double scrub_place;             // place of play head at latest jog/scrub wheel tick
291         int64_t scrub_time;             // when did the wheel move last?
292         bool global_init;
293         boost::shared_ptr<ARDOUR::Stripable> _select;   // which stripable out of /surface/stripables is gui selected
294
295         void register_callbacks ();
296
297         void route_added (ARDOUR::RouteList&);
298
299         // Handlers for "Application Hook" signals
300         void session_loaded (ARDOUR::Session&);
301         void session_exported (std::string, std::string);
302
303         // end "Application Hook" handles
304
305         std::string get_unix_server_url ();
306         lo_address get_address (lo_message msg);
307         std::string get_port (std::string host);
308         OSCSurface * get_surface (lo_address addr, bool quiet = false);
309         int check_surface (lo_message msg);
310         uint32_t get_sid (boost::shared_ptr<ARDOUR::Stripable> strip, lo_address addr);
311         boost::shared_ptr<ARDOUR::Stripable> get_strip (uint32_t ssid, lo_address addr);
312         void global_feedback (OSCSurface* sur);
313         void strip_feedback (OSCSurface* sur, bool new_bank_size);
314         void surface_destroy (OSCSurface* sur);
315         uint32_t bank_limits_check (uint32_t bank, uint32_t size, uint32_t total);
316         void bank_leds (OSCSurface* sur);
317
318         void send_current_value (const char* path, lo_arg** argv, int argc, lo_message msg);
319         void current_value_query (const char* path, size_t len, lo_arg **argv, int argc, lo_message msg);
320
321         int current_value (const char *path, const char *types, lo_arg **argv, int argc, void *data, void *user_data);
322
323         int catchall (const char *path, const char *types, lo_arg **argv, int argc, void *data);
324         static int _catchall (const char *path, const char *types, lo_arg **argv, int argc, void *data, void *user_data);
325
326         int set_automation (const char *path, const char* types, lo_arg **argv, int argc, lo_message msg);
327         int touch_detect (const char *path, const char* types, lo_arg **argv, int argc, lo_message msg);
328         int fake_touch (boost::shared_ptr<ARDOUR::AutomationControl> ctrl);
329
330         int spill (const char *path, const char* types, lo_arg **argv, int argc, lo_message msg);
331
332         int route_get_sends (lo_message msg);
333         int route_get_receives(lo_message msg);
334         void routes_list (lo_message msg);
335         int group_list (lo_message msg);
336         void surface_list (lo_message msg);
337         void transport_sample (lo_message msg);
338         void transport_speed (lo_message msg);
339         void record_enabled (lo_message msg);
340
341         // cue
342         Sorted cue_get_sorted_stripables(boost::shared_ptr<ARDOUR::Stripable> aux, uint32_t id, lo_message msg);
343         int cue_parse (const char *path, const char* types, lo_arg **argv, int argc, lo_message msg);
344         int cue_set (uint32_t aux, lo_message msg);
345         int _cue_set (uint32_t aux, lo_address addr);
346         int cue_new_aux (std::string name, std::string dest_1, std::string dest_2, lo_message msg);
347         int cue_new_send (std::string rt_name, lo_message msg);
348         int cue_connect_aux (std::string dest, lo_message msg);
349         int cue_hide (float state, lo_message msg);
350         int cue_next (lo_message msg);
351         int cue_previous (lo_message msg);
352         int cue_send_fader (uint32_t id, float position, lo_message msg);
353         int cue_send_enable (uint32_t id, float state, lo_message msg);
354         int cue_aux_fader (float position, lo_message msg);
355         int cue_aux_mute (float state, lo_message msg);
356         void cue_set_aux (uint32_t aux, lo_message msg);
357         boost::shared_ptr<ARDOUR::Send> cue_get_send (uint32_t id, lo_address addr);
358         // end cue
359
360         // link
361         LinkSet * get_linkset (uint32_t set, lo_address addr);
362         int parse_link (const char *path, const char* types, lo_arg **argv, int argc, lo_message msg);
363         int link_check (uint32_t linkset);
364         int set_link (uint32_t set, uint32_t id, lo_address addr);
365         void surface_link_state (LinkSet * set);
366         void link_strip_types (uint32_t linkset, uint32_t striptypes);
367
368 #define OSC_DEBUG \
369         if (_debugmode == All) { \
370                 debugmsg (dgettext(PACKAGE, "OSC"), path, types, argv, argc); \
371         }
372
373 #define PATH_CALLBACK_MSG(name) \
374         static int _ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *data, void *user_data) { \
375                 return static_cast<OSC*>(user_data)->cb_ ## name (path, types, argv, argc, data); \
376         } \
377         int cb_ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *data) { \
378                 OSC_DEBUG; \
379                 if (argc > 0 && !strcmp (types, "f") && argv[0]->f != 1.0) { return 0; } \
380                 name (data); \
381                 return 0; \
382         }
383
384         PATH_CALLBACK_MSG(route_get_sends);
385         PATH_CALLBACK_MSG(route_get_receives);
386         PATH_CALLBACK_MSG(routes_list);
387         PATH_CALLBACK_MSG(group_list);
388         PATH_CALLBACK_MSG(sel_previous);
389         PATH_CALLBACK_MSG(sel_next);
390         PATH_CALLBACK_MSG(surface_list);
391         PATH_CALLBACK_MSG(transport_sample);
392         PATH_CALLBACK_MSG(transport_speed);
393         PATH_CALLBACK_MSG(record_enabled);
394         PATH_CALLBACK_MSG(refresh_surface);
395         PATH_CALLBACK_MSG(bank_up);
396         PATH_CALLBACK_MSG(bank_down);
397         PATH_CALLBACK_MSG(master_select);
398         PATH_CALLBACK_MSG(custom_clear);
399
400 #define PATH_CALLBACK(name) \
401         static int _ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *data, void *user_data) { \
402                 return static_cast<OSC*>(user_data)->cb_ ## name (path, types, argv, argc, data); \
403         } \
404         int cb_ ## name (const char *path, const char *types, lo_arg ** argv, int argc, void *data) { \
405                 OSC_DEBUG; \
406                 check_surface (data); \
407                 if (argc > 0 && !strcmp (types, "f") && argv[0]->f != 1.0) { return 0; } \
408                 name (); \
409                 return 0; \
410         }
411
412         PATH_CALLBACK(add_marker);
413         PATH_CALLBACK(loop_toggle);
414         PATH_CALLBACK(goto_start);
415         PATH_CALLBACK(goto_end);
416         PATH_CALLBACK(rewind);
417         PATH_CALLBACK(ffwd);
418         PATH_CALLBACK(transport_stop);
419         PATH_CALLBACK(transport_play);
420         PATH_CALLBACK(save_state);
421         PATH_CALLBACK(prev_marker);
422         PATH_CALLBACK(next_marker);
423         PATH_CALLBACK(undo);
424         PATH_CALLBACK(redo);
425         PATH_CALLBACK(toggle_punch_in);
426         PATH_CALLBACK(toggle_punch_out);
427         PATH_CALLBACK(rec_enable_toggle);
428         PATH_CALLBACK(toggle_all_rec_enables);
429         PATH_CALLBACK(all_tracks_rec_in);
430         PATH_CALLBACK(all_tracks_rec_out);
431         PATH_CALLBACK(cancel_all_solos);
432         PATH_CALLBACK(remove_marker_at_playhead);
433         PATH_CALLBACK(mark_in);
434         PATH_CALLBACK(mark_out);
435         PATH_CALLBACK(toggle_click);
436         PATH_CALLBACK(midi_panic);
437         PATH_CALLBACK(toggle_roll);
438         PATH_CALLBACK(stop_forget);
439         PATH_CALLBACK(set_punch_range);
440         PATH_CALLBACK(set_loop_range);
441         PATH_CALLBACK(set_session_range);
442         PATH_CALLBACK(toggle_monitor_mute);
443         PATH_CALLBACK(toggle_monitor_dim);
444         PATH_CALLBACK(toggle_monitor_mono);
445         PATH_CALLBACK(quick_snapshot_stay);
446         PATH_CALLBACK(quick_snapshot_switch);
447         PATH_CALLBACK(fit_1_track);
448         PATH_CALLBACK(fit_2_tracks);
449         PATH_CALLBACK(fit_4_tracks);
450         PATH_CALLBACK(fit_8_tracks);
451         PATH_CALLBACK(fit_16_tracks);
452         PATH_CALLBACK(fit_32_tracks);
453         PATH_CALLBACK(fit_all_tracks);
454         PATH_CALLBACK(zoom_100_ms);
455         PATH_CALLBACK(zoom_1_sec);
456         PATH_CALLBACK(zoom_10_sec);
457         PATH_CALLBACK(zoom_1_min);
458         PATH_CALLBACK(zoom_5_min);
459         PATH_CALLBACK(zoom_10_min);
460         PATH_CALLBACK(zoom_to_session);
461         PATH_CALLBACK(temporal_zoom_in);
462         PATH_CALLBACK(temporal_zoom_out);
463         PATH_CALLBACK(scroll_up_1_track);
464         PATH_CALLBACK(scroll_dn_1_track);
465         PATH_CALLBACK(scroll_up_1_page);
466         PATH_CALLBACK(scroll_dn_1_page);
467
468 #define PATH_CALLBACK1(name,type,optional) \
469         static int _ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *data, void *user_data) { \
470                 return static_cast<OSC*>(user_data)->cb_ ## name (path, types, argv, argc, data); \
471         } \
472         int cb_ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *data) { \
473                 OSC_DEBUG; \
474                 check_surface (data); \
475                 if (argc > 0) { \
476                         name (optional argv[0]->type); \
477                 } \
478                 return 0; \
479         }
480
481         PATH_CALLBACK1(set_transport_speed,f,);
482         PATH_CALLBACK1(access_action,s,&);
483
484         PATH_CALLBACK1(jump_by_bars,f,);
485         PATH_CALLBACK1(jump_by_seconds,f,);
486         PATH_CALLBACK1(master_set_gain,f,);
487         PATH_CALLBACK1(master_set_fader,f,);
488         PATH_CALLBACK1(master_delta_gain,f,);
489         PATH_CALLBACK1(master_set_trim,f,);
490         PATH_CALLBACK1(master_set_mute,i,);
491         PATH_CALLBACK1(monitor_set_gain,f,);
492         PATH_CALLBACK1(monitor_set_fader,f,);
493         PATH_CALLBACK1(monitor_delta_gain,f,);
494         PATH_CALLBACK1(monitor_set_mute,i,);
495         PATH_CALLBACK1(monitor_set_dim,i,);
496         PATH_CALLBACK1(monitor_set_mono,i,);
497         PATH_CALLBACK1(click_level,f,);
498
499 #define PATH_CALLBACK1_MSG(name,arg1type) \
500         static int _ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *data, void *user_data) { \
501                 return static_cast<OSC*>(user_data)->cb_ ## name (path, types, argv, argc, data); \
502         } \
503         int cb_ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *data) { \
504                 OSC_DEBUG; \
505                 if (argc > 0) { \
506                         name (argv[0]->arg1type, data); \
507                 } \
508                 return 0; \
509         }
510
511 #define PATH_CALLBACK1_MSG_s(name,arg1type) \
512         static int _ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *data, void *user_data) { \
513                 return static_cast<OSC*>(user_data)->cb_ ## name (path, types, argv, argc, data); \
514         } \
515         int cb_ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *data) { \
516                 OSC_DEBUG; \
517                 if (argc > 0) { \
518                         name (&argv[0]->arg1type, data); \
519                 } \
520                 return 0; \
521         }
522
523         // pan position needs message info to send feedback
524         PATH_CALLBACK1_MSG(master_set_pan_stereo_position,f);
525
526         PATH_CALLBACK1_MSG(scrub,f);
527         PATH_CALLBACK1_MSG(jog,f);
528         PATH_CALLBACK1_MSG(jog_mode,f);
529         PATH_CALLBACK1_MSG(bank_delta,f);
530         PATH_CALLBACK1_MSG(use_group,f);
531         PATH_CALLBACK1_MSG_s(name_session,s);
532         PATH_CALLBACK1_MSG_s(sel_rename,s);
533         PATH_CALLBACK1_MSG_s(sel_comment,s);
534         PATH_CALLBACK1_MSG_s(sel_new_personal_send,s);
535         PATH_CALLBACK1_MSG(sel_recenable,i);
536         PATH_CALLBACK1_MSG(sel_recsafe,i);
537         PATH_CALLBACK1_MSG(sel_mute,i);
538         PATH_CALLBACK1_MSG(sel_master_send_enable,i);
539         PATH_CALLBACK1_MSG(sel_solo,i);
540         PATH_CALLBACK1_MSG(sel_solo_iso,i);
541         PATH_CALLBACK1_MSG(sel_solo_safe,i);
542         PATH_CALLBACK1_MSG(sel_monitor_input,i);
543         PATH_CALLBACK1_MSG(sel_monitor_disk,i);
544         PATH_CALLBACK1_MSG(sel_phase,i);
545         PATH_CALLBACK1_MSG(sel_gain,f);
546         PATH_CALLBACK1_MSG(sel_fader,f);
547         PATH_CALLBACK1_MSG(sel_dB_delta,f);
548         PATH_CALLBACK1_MSG(sel_trim,f);
549         PATH_CALLBACK1_MSG(sel_hide,i);
550         PATH_CALLBACK1_MSG(sel_pan_position,f);
551         PATH_CALLBACK1_MSG(sel_pan_width,f);
552         PATH_CALLBACK1_MSG(sel_pan_elevation,f);
553         PATH_CALLBACK1_MSG(sel_pan_frontback,f);
554         PATH_CALLBACK1_MSG(sel_pan_lfe,f);
555         PATH_CALLBACK1_MSG(sel_send_page,f);
556         PATH_CALLBACK1_MSG(sel_plug_page,f);
557         PATH_CALLBACK1_MSG(sel_plugin,f);
558         PATH_CALLBACK1_MSG(sel_plugin_activate,f);
559         PATH_CALLBACK1_MSG(sel_comp_enable,f);
560         PATH_CALLBACK1_MSG(sel_comp_threshold,f);
561         PATH_CALLBACK1_MSG(sel_comp_speed,f);
562         PATH_CALLBACK1_MSG(sel_comp_mode,f);
563         PATH_CALLBACK1_MSG(sel_comp_makeup,f);
564         PATH_CALLBACK1_MSG(sel_eq_enable,f);
565         PATH_CALLBACK1_MSG(sel_eq_hpf_freq,f);
566         PATH_CALLBACK1_MSG(sel_eq_hpf_enable,f);
567         PATH_CALLBACK1_MSG(sel_eq_hpf_slope,f);
568         PATH_CALLBACK1_MSG(sel_eq_lpf_freq,f);
569         PATH_CALLBACK1_MSG(sel_eq_lpf_enable,f);
570         PATH_CALLBACK1_MSG(sel_eq_lpf_slope,f);
571         PATH_CALLBACK1_MSG(sel_expand,i);
572         PATH_CALLBACK1_MSG(custom_mode,f);
573
574 #define PATH_CALLBACK2(name,arg1type,arg2type) \
575         static int _ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *data, void *user_data) { \
576                 return static_cast<OSC*>(user_data)->cb_ ## name (path, types, argv, argc, data); \
577         } \
578         int cb_ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *data) { \
579                 OSC_DEBUG; \
580                 check_surface (data); \
581                 if (argc > 1) { \
582                         name (argv[0]->arg1type, argv[1]->arg2type); \
583                 } \
584                 return 0; \
585         }
586
587 #define PATH_CALLBACK2_MSG(name,arg1type,arg2type) \
588         static int _ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *data, void *user_data) { \
589                 return static_cast<OSC*>(user_data)->cb_ ## name (path, types, argv, argc, data); \
590         } \
591         int cb_ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *data) { \
592                 OSC_DEBUG; \
593                 if (argc > 1) { \
594                         name (argv[0]->arg1type, argv[1]->arg2type, data); \
595                 } \
596                 return 0; \
597         }
598
599 #define PATH_CALLBACK2_MSG_s(name,arg1type,arg2type) \
600         static int _ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *data, void *user_data) { \
601                 return static_cast<OSC*>(user_data)->cb_ ## name (path, types, argv, argc, data); \
602         } \
603         int cb_ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *data) { \
604                 OSC_DEBUG; \
605                 if (argc > 1) { \
606                         name (argv[0]->arg1type, &argv[1]->arg2type, data); \
607                 } \
608                 return 0; \
609         }
610
611 #define PATH_CALLBACK3(name,arg1type,arg2type,arg3type) \
612         static int _ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *data, void *user_data) { \
613                 return static_cast<OSC*>(user_data)->cb_ ## name (path, types, argv, argc, data); \
614         } \
615         int cb_ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *data) { \
616                 OSC_DEBUG; \
617                 if (argc > 1) { \
618                         name (argv[0]->arg1type, argv[1]->arg2type,argv[2]->arg3type, data); \
619                 } \
620                 return 0; \
621         }
622
623 #define PATH_CALLBACK4(name,arg1type,arg2type,arg3type,arg4type) \
624         static int _ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *data, void *user_data) { \
625                 return static_cast<OSC*>(user_data)->cb_ ## name (path, types, argv, argc, data); \
626         } \
627         int cb_ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *data) { \
628                 OSC_DEBUG; \
629                 if (argc > 1) { \
630                         name (argv[0]->arg1type, argv[1]->arg2type,argv[2]->arg3type,argv[3]->arg4type, data); \
631                 } \
632                 return 0; \
633         }
634
635         PATH_CALLBACK2_MSG(sel_sendgain,i,f);
636         PATH_CALLBACK2_MSG(sel_sendfader,i,f);
637         PATH_CALLBACK2_MSG(sel_sendenable,i,f);
638         PATH_CALLBACK2_MSG(sel_eq_gain,i,f);
639         PATH_CALLBACK2_MSG(sel_eq_freq,i,f);
640         PATH_CALLBACK2_MSG(sel_eq_q,i,f);
641         PATH_CALLBACK2_MSG(sel_eq_shape,i,f);
642
643         PATH_CALLBACK2(locate,i,i);
644         PATH_CALLBACK2(loop_location,i,i);
645         PATH_CALLBACK2_MSG_s(route_rename,i,s);
646         PATH_CALLBACK2_MSG_s(strip_group,i,s);
647         PATH_CALLBACK2_MSG(route_mute,i,i);
648         PATH_CALLBACK2_MSG(route_solo,i,i);
649         PATH_CALLBACK2_MSG(route_solo_iso,i,i);
650         PATH_CALLBACK2_MSG(route_solo_safe,i,i);
651         PATH_CALLBACK2_MSG(route_recenable,i,i);
652         PATH_CALLBACK2_MSG(route_recsafe,i,i);
653         PATH_CALLBACK2_MSG(route_monitor_input,i,i);
654         PATH_CALLBACK2_MSG(route_monitor_disk,i,i);
655         PATH_CALLBACK2_MSG(strip_phase,i,i);
656         PATH_CALLBACK2_MSG(strip_expand,i,i);
657         PATH_CALLBACK2_MSG(strip_hide,i,i);
658         PATH_CALLBACK2_MSG(strip_gui_select,i,i);
659         PATH_CALLBACK2_MSG(route_set_gain_dB,i,f);
660         PATH_CALLBACK2_MSG(route_set_gain_fader,i,f);
661         PATH_CALLBACK2_MSG(strip_db_delta,i,f);
662         PATH_CALLBACK2_MSG(route_set_trim_dB,i,f);
663         PATH_CALLBACK2_MSG(route_set_pan_stereo_position,i,f);
664         PATH_CALLBACK2_MSG(route_set_pan_stereo_width,i,f);
665         PATH_CALLBACK3(route_set_send_gain_dB,i,i,f);
666         PATH_CALLBACK3(route_set_send_fader,i,i,f);
667         PATH_CALLBACK3(route_set_send_enable,i,i,f);
668         PATH_CALLBACK4(route_plugin_parameter,i,i,i,f);
669         PATH_CALLBACK3(route_plugin_parameter_print,i,i,i);
670         PATH_CALLBACK2_MSG(route_plugin_activate,i,i);
671         PATH_CALLBACK2_MSG(route_plugin_deactivate,i,i);
672         PATH_CALLBACK1_MSG(route_plugin_list,i);
673         PATH_CALLBACK2_MSG(route_plugin_descriptor,i,i);
674         PATH_CALLBACK2_MSG(route_plugin_reset,i,i);
675
676         int route_rename (int rid, char *s, lo_message msg);
677         int strip_group (int ssid, char *g, lo_message msg);
678         int strip_select_group (boost::shared_ptr<ARDOUR::Stripable> s, char *g);
679         int route_mute (int rid, int yn, lo_message msg);
680         int route_solo (int rid, int yn, lo_message msg);
681         int route_solo_iso (int rid, int yn, lo_message msg);
682         int route_solo_safe (int rid, int yn, lo_message msg);
683         int route_recenable (int rid, int yn, lo_message msg);
684         int route_recsafe (int ssid, int yn, lo_message msg);
685         int route_monitor_input (int rid, int yn, lo_message msg);
686         int route_monitor_disk (int rid, int yn, lo_message msg);
687         int strip_phase (int rid, int yn, lo_message msg);
688         int strip_expand (int rid, int yn, lo_message msg);
689         int strip_hide (int ssid, int yn, lo_message msg);
690         int _strip_select (boost::shared_ptr<ARDOUR::Stripable> s, lo_address addr);
691         int strip_gui_select (int rid, int yn, lo_message msg);
692         int route_set_gain_dB (int rid, float dB, lo_message msg);
693         int route_set_gain_fader (int rid, float pos, lo_message msg);
694         int strip_db_delta (int ssid, float delta, lo_message msg);
695         int route_set_trim_abs (int rid, float level, lo_message msg);
696         int route_set_trim_dB (int rid, float dB, lo_message msg);
697         int route_set_pan_stereo_position (int rid, float left_right_fraction, lo_message msg);
698         int route_set_pan_stereo_width (int rid, float percent, lo_message msg);
699         int route_set_send_gain_dB (int rid, int sid, float val, lo_message msg);
700         int route_set_send_fader (int rid, int sid, float val, lo_message msg);
701         int route_set_send_enable (int rid, int sid, float val, lo_message msg);
702         int route_plugin_parameter (int rid, int piid,int par, float val, lo_message msg);
703         int route_plugin_parameter_print (int rid, int piid,int par, lo_message msg);
704         int route_plugin_activate (int rid, int piid, lo_message msg);
705         int route_plugin_deactivate (int rid, int piid, lo_message msg);
706         int route_plugin_list(int ssid, lo_message msg);
707         int route_plugin_descriptor(int ssid, int piid, lo_message msg);
708         int route_plugin_reset(int ssid, int piid, lo_message msg);
709
710         //banking functions
711         int set_bank (uint32_t bank_start, lo_message msg);
712         int _set_bank (uint32_t bank_start, lo_address addr);
713         int bank_up (lo_message msg);
714         int bank_delta (float delta, lo_message msg);
715         int use_group (float value, lo_message msg);
716         int bank_down (lo_message msg);
717         // surface set up
718         int surface_parse (const char *path, const char* types, lo_arg **argv, int argc, lo_message msg);
719         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);
720         int set_surface_bank_size (uint32_t bs, lo_message msg);
721         int set_surface_strip_types (uint32_t st, lo_message msg);
722         int set_surface_feedback (uint32_t fb, lo_message msg);
723         int set_surface_gainmode (uint32_t gm, lo_message msg);
724         int set_surface_port (uint32_t po, lo_message msg);
725         int refresh_surface (lo_message msg);
726         int custom_clear (lo_message msg);
727         int custom_mode (float state, lo_message msg);
728         int _custom_mode (uint32_t state, lo_address addr);
729         int name_session (char *n, lo_message msg);
730         // select
731         int sel_send_pagesize (uint32_t size, lo_message msg);
732         int sel_send_page (int page, lo_message msg);
733         int sel_plug_pagesize (uint32_t size, lo_message msg);
734         int sel_plug_page (int page, lo_message msg);
735         int sel_plugin (int delta, lo_message msg);
736         int _sel_plugin (int id, lo_address addr);
737         int sel_plugin_activate (float state, lo_message msg);
738         int select_plugin_parameter (const char *path, const char* types, lo_arg **argv, int argc, lo_message msg);
739         void processor_changed (std::string remote_url);
740
741         int scrub (float delta, lo_message msg);
742         int jog (float delta, lo_message msg);
743         int jog_mode (float mode, lo_message msg);
744         int set_marker (const char* types, lo_arg **argv, int argc, lo_message msg);
745         int click_level (float position);
746         int master_set_gain (float dB);
747         int master_set_fader (float position);
748         int master_delta_gain (float delta);
749         int master_set_trim (float dB);
750         int master_set_pan_stereo_position (float position, lo_message msg);
751         int master_set_mute (uint32_t state);
752         int master_select (lo_message msg);
753         int monitor_set_gain (float dB);
754         int monitor_set_fader (float position);
755         int monitor_delta_gain (float delta);
756         int monitor_set_mute (uint32_t state);
757         int monitor_set_dim (uint32_t state);
758         int monitor_set_mono (uint32_t state);
759         int sel_group (char *g, lo_message msg);
760         int sel_rename (char *n, lo_message msg);
761         int sel_comment (char *c, lo_message msg);
762         int sel_recenable (uint32_t state, lo_message msg);
763         int sel_recsafe (uint32_t state, lo_message msg);
764         int sel_mute (uint32_t state, lo_message msg);
765         int sel_solo (uint32_t state, lo_message msg);
766         int sel_solo_iso (uint32_t state, lo_message msg);
767         int sel_solo_safe (uint32_t state, lo_message msg);
768         int sel_monitor_input (uint32_t state, lo_message msg);
769         int sel_monitor_disk (uint32_t state, lo_message msg);
770         int sel_phase (uint32_t state, lo_message msg);
771         int sel_gain (float state, lo_message msg);
772         int sel_fader (float state, lo_message msg);
773         int sel_dB_delta (float delta, lo_message msg);
774         int sel_trim (float val, lo_message msg);
775         int sel_hide (uint32_t state, lo_message msg);
776         int sel_previous (lo_message msg);
777         int sel_next (lo_message msg);
778         int sel_delta (int delta, lo_message msg);
779         boost::shared_ptr<ARDOUR::Send> get_send (boost::shared_ptr<ARDOUR::Stripable> st, lo_address addr);
780         int sel_pan_position (float val, lo_message msg);
781         int sel_pan_width (float val, lo_message msg);
782         int sel_sendgain (int id, float dB, lo_message msg);
783         int sel_sendfader (int id, float pos, lo_message msg);
784         int sel_sendenable (int id, float pos, lo_message msg);
785         int sel_master_send_enable (int state, lo_message msg);
786         int sel_expand (uint32_t state, lo_message msg);
787         int sel_pan_elevation (float val, lo_message msg);
788         int sel_pan_frontback (float val, lo_message msg);
789         int sel_pan_lfe (float val, lo_message msg);
790         int sel_comp_enable (float val, lo_message msg);
791         int sel_comp_threshold (float val, lo_message msg);
792         int sel_comp_speed (float val, lo_message msg);
793         int sel_comp_mode (float val, lo_message msg);
794         int sel_comp_makeup (float val, lo_message msg);
795         int sel_eq_enable (float val, lo_message msg);
796         int sel_eq_hpf_freq (float val, lo_message msg);
797         int sel_eq_hpf_enable (float val, lo_message msg);
798         int sel_eq_hpf_slope (float val, lo_message msg);
799         int sel_eq_lpf_freq (float val, lo_message msg);
800         int sel_eq_lpf_enable (float val, lo_message msg);
801         int sel_eq_lpf_slope (float val, lo_message msg);
802         int sel_eq_gain (int id, float val, lo_message msg);
803         int sel_eq_freq (int id, float val, lo_message msg);
804         int sel_eq_q (int id, float val, lo_message msg);
805         int sel_eq_shape (int id, float val, lo_message msg);
806         int sel_new_personal_send (char *n, lo_message msg);
807         int set_temp_mode (lo_address addr);
808         int parse_sel_group (const char *path, const char* types, lo_arg **argv, int argc, lo_message msg);
809         int parse_sel_vca (const char *path, const char* types, lo_arg **argv, int argc, lo_message msg);
810         boost::shared_ptr<ARDOUR::VCA> get_vca_by_name (std::string vname);
811
812         void listen_to_route (boost::shared_ptr<ARDOUR::Stripable>, lo_address);
813
814         void route_name_changed (const PBD::PropertyChange&, boost::weak_ptr<ARDOUR::Route> r, lo_address addr);
815         void recalcbanks ();
816         void _recalcbanks ();
817         void notify_routes_added (ARDOUR::RouteList &);
818         void notify_vca_added (ARDOUR::VCAList &);
819
820         int cancel_all_solos ();
821         bool periodic (void);
822         sigc::connection periodic_connection;
823         PBD::ScopedConnectionList session_connections;
824
825         void debugmsg (const char *prefix, const char *path, const char* types, lo_arg **argv, int argc);
826
827         static OSC* _instance;
828
829         mutable void *gui;
830         void build_gui ();
831 };
832
833 } // namespace
834
835 #endif // ardour_osc_h