Merging from trunk
[ardour.git] / libs / ardour / ardour / osc.h
1 /*
2  * Copyright (C) 2006 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  * $Id$
19  */
20
21 #ifndef ardour_osc_h
22 #define ardour_osc_h
23
24 #include <string>
25
26 #include <sys/time.h>
27 #include <pthread.h>
28
29 #include <lo/lo.h>
30
31 #include <sigc++/sigc++.h>
32
33 #include <ardour/types.h>
34
35 #include <control_protocol/basic_ui.h>
36
37 namespace ARDOUR {
38         class Session;
39         class Route;
40
41 class OSC : public BasicUI, public sigc::trackable
42 {
43   public:
44         OSC (uint32_t port);
45         virtual ~OSC();
46         
47         void set_session (ARDOUR::Session&);
48         int start ();
49         int stop ();
50
51   private:
52         uint32_t _port;
53         volatile bool _ok;
54         volatile bool _shutdown;
55         lo_server _osc_server;
56         lo_server _osc_unix_server;
57         std::string _osc_unix_socket_path;
58         pthread_t _osc_thread;
59         int _request_pipe[2];
60
61         static void * _osc_receiver(void * arg);
62         void osc_receiver();
63
64         bool init_osc_thread ();
65         void terminate_osc_thread ();
66         void poke_osc_thread ();
67
68         void register_callbacks ();
69
70         void session_going_away ();
71
72         std::string get_server_url ();
73         std::string get_unix_server_url ();
74
75         int current_value (const char *path, const char *types, lo_arg **argv, int argc, void *data, void *user_data);
76
77 #define PATH_CALLBACK(name) \
78         static int _ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *data, void *user_data) { \
79                 return static_cast<OSC*>(user_data)->cb_ ## name (path, types, argv, argc, data); \
80         } \
81         int cb_ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *data) { \
82                 name (); \
83                 return 0; \
84         }
85
86         PATH_CALLBACK(add_marker);
87         PATH_CALLBACK(loop_toggle);
88         PATH_CALLBACK(goto_start);
89         PATH_CALLBACK(goto_end);
90         PATH_CALLBACK(rewind);
91         PATH_CALLBACK(ffwd);
92         PATH_CALLBACK(transport_stop);
93         PATH_CALLBACK(transport_play);
94         PATH_CALLBACK(save_state);
95         PATH_CALLBACK(prev_marker);
96         PATH_CALLBACK(next_marker);
97         PATH_CALLBACK(undo);
98         PATH_CALLBACK(redo);
99         PATH_CALLBACK(toggle_punch_in);
100         PATH_CALLBACK(toggle_punch_out);
101         PATH_CALLBACK(rec_enable_toggle);
102         PATH_CALLBACK(toggle_all_rec_enables);
103
104 #define PATH_CALLBACK1(name,type) \
105         static int _ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *data, void *user_data) { \
106                 return static_cast<OSC*>(user_data)->cb_ ## name (path, types, argv, argc, data); \
107         } \
108         int cb_ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *data) { \
109                 if (argc > 0) { \
110                         name (argv[0]->type); \
111                 }\
112                 return 0; \
113         }
114
115         PATH_CALLBACK1(set_transport_speed,f);
116 };
117
118 }
119
120 #endif // ardour_osc_h