add /ardour/locate <frame> <roll-after-locate> command to OSC API
[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  */
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 <lo/lo.h>
29
30 #include <sigc++/sigc++.h>
31
32 #include <ardour/types.h>
33
34 #include <control_protocol/basic_ui.h>
35
36 namespace ARDOUR {
37         class Session;
38         class Route;
39
40 class OSC : public BasicUI, public sigc::trackable
41 {
42   public:
43         OSC (uint32_t port);
44         virtual ~OSC();
45         
46         void set_session (ARDOUR::Session&);
47         int start ();
48         int stop ();
49
50   private:
51         uint32_t _port;
52         volatile bool _ok;
53         volatile bool _shutdown;
54         lo_server _osc_server;
55         lo_server _osc_unix_server;
56         std::string _osc_unix_socket_path;
57         std::string _osc_url_file;
58         pthread_t _osc_thread;
59         int _request_pipe[2];
60
61         static void * _osc_receiver(void * arg);
62         void osc_receiver();
63         void send(); // This should accept an OSC payload
64
65         bool init_osc_thread ();
66         void terminate_osc_thread ();
67         void poke_osc_thread ();
68
69         void register_callbacks ();
70
71         void session_going_away ();
72
73         // Handlers for "Application Hook" signals
74         void session_loaded( ARDOUR::Session& );
75         void session_exported( std::string, std::string );
76         // end "Application Hook" handles
77
78         std::string get_server_url ();
79         std::string get_unix_server_url ();
80
81         int current_value (const char *path, const char *types, lo_arg **argv, int argc, void *data, void *user_data);
82
83 #define PATH_CALLBACK(name) \
84         static int _ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *data, void *user_data) { \
85                 return static_cast<OSC*>(user_data)->cb_ ## name (path, types, argv, argc, data); \
86         } \
87         int cb_ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *data) { \
88                 name (); \
89                 return 0; \
90         }
91
92         PATH_CALLBACK(add_marker);
93         PATH_CALLBACK(loop_toggle);
94         PATH_CALLBACK(goto_start);
95         PATH_CALLBACK(goto_end);
96         PATH_CALLBACK(rewind);
97         PATH_CALLBACK(ffwd);
98         PATH_CALLBACK(transport_stop);
99         PATH_CALLBACK(transport_play);
100         PATH_CALLBACK(save_state);
101         PATH_CALLBACK(prev_marker);
102         PATH_CALLBACK(next_marker);
103         PATH_CALLBACK(undo);
104         PATH_CALLBACK(redo);
105         PATH_CALLBACK(toggle_punch_in);
106         PATH_CALLBACK(toggle_punch_out);
107         PATH_CALLBACK(rec_enable_toggle);
108         PATH_CALLBACK(toggle_all_rec_enables);
109
110 #define PATH_CALLBACK1(name,type,optional)                                      \
111         static int _ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *data, void *user_data) { \
112                 return static_cast<OSC*>(user_data)->cb_ ## name (path, types, argv, argc, data); \
113         } \
114         int cb_ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *data) { \
115                 if (argc > 0) {                                         \
116                         name (optional argv[0]->type);          \
117                 }                                                       \
118                 return 0;                                               \
119         }
120
121         PATH_CALLBACK1(set_transport_speed,f,);
122         PATH_CALLBACK1(access_action,s,&);
123
124 #define PATH_CALLBACK2(name,arg1type,arg2type)                  \
125         static int _ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *data, void *user_data) { \
126                 return static_cast<OSC*>(user_data)->cb_ ## name (path, types, argv, argc, data); \
127         } \
128         int cb_ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *data) { \
129                 if (argc > 1) {                                         \
130                         name (argv[0]->arg1type, argv[1]->arg2type); \
131                 }                                                       \
132                 return 0;                                               \
133         }
134
135         PATH_CALLBACK2(locate,i,i);
136         PATH_CALLBACK2(route_mute,i,i);
137         PATH_CALLBACK2(route_solo,i,i);
138         PATH_CALLBACK2(route_recenable,i,i);
139         PATH_CALLBACK2(route_set_gain_abs,i,f);
140         PATH_CALLBACK2(route_set_gain_dB,i,f);
141
142         int route_mute (int rid, int yn);
143         int route_solo (int rid, int yn);
144         int route_recenable (int rid, int yn);
145         int route_set_gain_abs (int rid, float level);
146         int route_set_gain_dB (int rid, float dB);
147 };
148
149 }
150
151 #endif // ardour_osc_h