2 * Copyright (C) 2006-2009 Paul Davis
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.
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.
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.
28 #include <boost/shared_ptr.hpp>
32 #include <glibmm/main.h>
34 #include "pbd/abstract_ui.h"
36 #include "ardour/types.h"
37 #include "control_protocol/control_protocol.h"
39 class OSCControllable;
46 /* this is mostly a placeholder because I suspect that at some
47 point we will want to add more members to accomodate
48 certain types of requests to the MIDI UI
51 struct OSCUIRequest : public BaseUI::BaseRequestObject {
57 class OSC : public ARDOUR::ControlProtocol, public AbstractUI<OSCUIRequest>
60 OSC (ARDOUR::Session&, uint32_t port);
63 static OSC* instance() { return _instance; }
65 XMLNode& get_state ();
66 int set_state (const XMLNode&, int version);
68 int set_active (bool yn);
69 bool get_active () const;
70 int set_feedback (bool yn);
71 bool get_feedback () const;
73 void set_namespace_root (std::string);
80 void do_request (OSCUIRequest*);
82 GSource* local_server;
83 GSource* remote_server;
85 bool osc_input_handler (Glib::IOCondition, lo_server);
90 volatile bool _shutdown;
91 lo_server _osc_server;
92 lo_server _osc_unix_server;
93 std::string _osc_unix_socket_path;
94 std::string _osc_url_file;
95 std::string _namespace_root;
96 bool _send_route_changes;
98 void register_callbacks ();
100 void route_added (ARDOUR::RouteList&);
102 // Handlers for "Application Hook" signals
103 void session_loaded (ARDOUR::Session&);
104 void session_exported (std::string, std::string);
106 // end "Application Hook" handles
108 std::string get_server_url ();
109 std::string get_unix_server_url ();
111 void send_current_value (const char* path, lo_arg** argv, int argc, lo_message msg);
112 void current_value_query (const char* path, size_t len, lo_arg **argv, int argc, lo_message msg);
113 int catchall (const char *path, const char *types, lo_arg **argv, int argc, void *data);
114 static int _catchall (const char *path, const char *types, lo_arg **argv, int argc, void *data, void *user_data);
116 int current_value (const char *path, const char *types, lo_arg **argv, int argc, void *data, void *user_data);
118 #define PATH_CALLBACK(name) \
119 static int _ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *data, void *user_data) { \
120 return static_cast<OSC*>(user_data)->cb_ ## name (path, types, argv, argc, data); \
122 int cb_ ## name (const char *, const char *, lo_arg **, int, void *) { \
127 PATH_CALLBACK(add_marker);
128 PATH_CALLBACK(loop_toggle);
129 PATH_CALLBACK(goto_start);
130 PATH_CALLBACK(goto_end);
131 PATH_CALLBACK(rewind);
133 PATH_CALLBACK(transport_stop);
134 PATH_CALLBACK(transport_play);
135 PATH_CALLBACK(save_state);
136 PATH_CALLBACK(prev_marker);
137 PATH_CALLBACK(next_marker);
140 PATH_CALLBACK(toggle_punch_in);
141 PATH_CALLBACK(toggle_punch_out);
142 PATH_CALLBACK(rec_enable_toggle);
143 PATH_CALLBACK(toggle_all_rec_enables);
145 #define PATH_CALLBACK1(name,type,optional) \
146 static int _ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *data, void *user_data) { \
147 return static_cast<OSC*>(user_data)->cb_ ## name (path, types, argv, argc, data); \
149 int cb_ ## name (const char *, const char *, lo_arg **argv, int argc, void *) { \
151 name (optional argv[0]->type); \
156 PATH_CALLBACK1(set_transport_speed,f,);
157 PATH_CALLBACK1(access_action,s,&);
159 #define PATH_CALLBACK2(name,arg1type,arg2type) \
160 static int _ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *data, void *user_data) { \
161 return static_cast<OSC*>(user_data)->cb_ ## name (path, types, argv, argc, data); \
163 int cb_ ## name (const char *, const char *, lo_arg **argv, int argc, void *) { \
165 name (argv[0]->arg1type, argv[1]->arg2type); \
170 PATH_CALLBACK2(locate,i,i);
171 PATH_CALLBACK2(route_mute,i,i);
172 PATH_CALLBACK2(route_solo,i,i);
173 PATH_CALLBACK2(route_recenable,i,i);
174 PATH_CALLBACK2(route_set_gain_abs,i,f);
175 PATH_CALLBACK2(route_set_gain_dB,i,f);
177 int route_mute (int rid, int yn);
178 int route_solo (int rid, int yn);
179 int route_recenable (int rid, int yn);
180 int route_set_gain_abs (int rid, float level);
181 int route_set_gain_dB (int rid, float dB);
183 void listen_to_route (boost::shared_ptr<ARDOUR::Route>, lo_address);
184 void end_listen (boost::shared_ptr<ARDOUR::Route>, lo_address);
185 void drop_route (boost::weak_ptr<ARDOUR::Route>);
187 typedef std::list<OSCControllable*> Controllables;
189 Controllables controllables;
191 static OSC* _instance;
194 #endif // ardour_osc_h