Waf: install stuff
[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
25 #include <sys/time.h>
26 #include <pthread.h>
27
28 #include <boost/shared_ptr.hpp>
29
30 #include <lo/lo.h>
31
32 #include <sigc++/sigc++.h>
33
34 #include <ardour/types.h>
35 #include <ardour/session.h>
36 #include <control_protocol/control_protocol.h>
37
38 class OSCControllable;
39
40 namespace ARDOUR {
41 class Session;
42 class Route;
43 }
44         
45 class OSC : public ARDOUR::ControlProtocol
46 {
47   public:
48         OSC (ARDOUR::Session&, uint32_t port);
49         virtual ~OSC();
50
51         XMLNode& get_state ();
52         int set_state (const XMLNode&);
53
54         int set_active (bool yn);
55         bool get_active () const;
56         int set_feedback (bool yn);
57         bool get_feedback () const;
58
59         void set_namespace_root (std::string);
60
61         int start ();
62         int stop ();
63
64   private:
65         uint32_t _port;
66         volatile bool _ok;
67         volatile bool _shutdown;
68         lo_server _osc_server;
69         lo_server _osc_unix_server;
70         std::string _osc_unix_socket_path;
71         std::string _osc_url_file;
72         std::string _namespace_root;
73         bool _send_route_changes;
74         pthread_t _osc_thread;
75         int _request_pipe[2];
76
77         static void * _osc_receiver(void * arg);
78         void osc_receiver();
79         void send(); // This should accept an OSC payload
80
81         bool init_osc_thread ();
82         void terminate_osc_thread ();
83         void poke_osc_thread ();
84
85         void register_callbacks ();
86
87         void route_added (ARDOUR::RouteList&);
88                 
89         // Handlers for "Application Hook" signals
90         void session_loaded (ARDOUR::Session&);
91         void session_exported (std::string, std::string);
92
93         // end "Application Hook" handles
94
95         std::string get_server_url ();
96         std::string get_unix_server_url ();
97
98         void send_current_value (const char* path, lo_arg** argv, int argc, lo_message msg);
99         void current_value_query (const char* path, size_t len, lo_arg **argv, int argc, lo_message msg);
100         int catchall (const char *path, const char *types, lo_arg **argv, int argc, void *data);
101         static int _catchall (const char *path, const char *types, lo_arg **argv, int argc, void *data, void *user_data);
102
103         int current_value (const char *path, const char *types, lo_arg **argv, int argc, void *data, void *user_data);
104
105 #define PATH_CALLBACK(name) \
106         static int _ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *data, void *user_data) { \
107                 return static_cast<OSC*>(user_data)->cb_ ## name (path, types, argv, argc, data); \
108         } \
109         int cb_ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *data) { \
110                 name (); \
111                 return 0; \
112         }
113
114         PATH_CALLBACK(add_marker);
115         PATH_CALLBACK(loop_toggle);
116         PATH_CALLBACK(goto_start);
117         PATH_CALLBACK(goto_end);
118         PATH_CALLBACK(rewind);
119         PATH_CALLBACK(ffwd);
120         PATH_CALLBACK(transport_stop);
121         PATH_CALLBACK(transport_play);
122         PATH_CALLBACK(save_state);
123         PATH_CALLBACK(prev_marker);
124         PATH_CALLBACK(next_marker);
125         PATH_CALLBACK(undo);
126         PATH_CALLBACK(redo);
127         PATH_CALLBACK(toggle_punch_in);
128         PATH_CALLBACK(toggle_punch_out);
129         PATH_CALLBACK(rec_enable_toggle);
130         PATH_CALLBACK(toggle_all_rec_enables);
131
132 #define PATH_CALLBACK1(name,type,optional)                                      \
133         static int _ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *data, void *user_data) { \
134                 return static_cast<OSC*>(user_data)->cb_ ## name (path, types, argv, argc, data); \
135         } \
136         int cb_ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *data) { \
137                 if (argc > 0) {                                         \
138                         name (optional argv[0]->type);          \
139                 }                                                       \
140                 return 0;                                               \
141         }
142
143         PATH_CALLBACK1(set_transport_speed,f,);
144         PATH_CALLBACK1(access_action,s,&);
145
146 #define PATH_CALLBACK2(name,arg1type,arg2type)                  \
147         static int _ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *data, void *user_data) { \
148                 return static_cast<OSC*>(user_data)->cb_ ## name (path, types, argv, argc, data); \
149         } \
150         int cb_ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *data) { \
151                 if (argc > 1) {                                         \
152                         name (argv[0]->arg1type, argv[1]->arg2type); \
153                 }                                                       \
154                 return 0;                                               \
155         }
156
157         PATH_CALLBACK2(route_mute,i,i);
158         PATH_CALLBACK2(route_solo,i,i);
159         PATH_CALLBACK2(route_recenable,i,i);
160         PATH_CALLBACK2(route_set_gain_abs,i,f);
161         PATH_CALLBACK2(route_set_gain_dB,i,f);
162
163         int route_mute (int rid, int yn);
164         int route_solo (int rid, int yn);
165         int route_recenable (int rid, int yn);
166         int route_set_gain_abs (int rid, float level);
167         int route_set_gain_dB (int rid, float dB);
168
169         void listen_to_route (boost::shared_ptr<ARDOUR::Route>, lo_address);
170         void end_listen (boost::shared_ptr<ARDOUR::Route>, lo_address);
171         void drop_route (boost::weak_ptr<ARDOUR::Route>);
172
173         typedef std::list<OSCControllable*> Controllables;
174
175         Controllables controllables;
176 };
177
178 #endif // ardour_osc_h