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"
35 #include "pbd/scoped_connections.h"
37 #include "ardour/types.h"
38 #include "control_protocol/control_protocol.h"
40 class OSCControllable;
47 /* this is mostly a placeholder because I suspect that at some
48 point we will want to add more members to accomodate
49 certain types of requests to the MIDI UI
52 struct OSCUIRequest : public BaseUI::BaseRequestObject {
58 class OSC : public ARDOUR::ControlProtocol, public PBD::ScopedConnectionList, public AbstractUI<OSCUIRequest>
61 OSC (ARDOUR::Session&, uint32_t port);
64 XMLNode& get_state ();
65 int set_state (const XMLNode&, int version);
67 int set_active (bool yn);
68 bool get_active () const;
69 int set_feedback (bool yn);
70 bool get_feedback () const;
72 void set_namespace_root (std::string);
79 void do_request (OSCUIRequest*);
81 GSource* local_server;
82 GSource* remote_server;
84 bool osc_input_handler (Glib::IOCondition, lo_server);
89 volatile bool _shutdown;
90 lo_server _osc_server;
91 lo_server _osc_unix_server;
92 std::string _osc_unix_socket_path;
93 std::string _osc_url_file;
94 std::string _namespace_root;
95 bool _send_route_changes;
97 void register_callbacks ();
99 void route_added (ARDOUR::RouteList&);
101 // Handlers for "Application Hook" signals
102 void session_loaded (ARDOUR::Session&);
103 void session_exported (std::string, std::string);
105 // end "Application Hook" handles
107 std::string get_server_url ();
108 std::string get_unix_server_url ();
110 void send_current_value (const char* path, lo_arg** argv, int argc, lo_message msg);
111 void current_value_query (const char* path, size_t len, lo_arg **argv, int argc, lo_message msg);
112 int catchall (const char *path, const char *types, lo_arg **argv, int argc, void *data);
113 static int _catchall (const char *path, const char *types, lo_arg **argv, int argc, void *data, void *user_data);
115 int current_value (const char *path, const char *types, lo_arg **argv, int argc, void *data, void *user_data);
117 #define PATH_CALLBACK(name) \
118 static int _ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *data, void *user_data) { \
119 return static_cast<OSC*>(user_data)->cb_ ## name (path, types, argv, argc, data); \
121 int cb_ ## name (const char *, const char *, lo_arg **, int, void *) { \
126 PATH_CALLBACK(add_marker);
127 PATH_CALLBACK(loop_toggle);
128 PATH_CALLBACK(goto_start);
129 PATH_CALLBACK(goto_end);
130 PATH_CALLBACK(rewind);
132 PATH_CALLBACK(transport_stop);
133 PATH_CALLBACK(transport_play);
134 PATH_CALLBACK(save_state);
135 PATH_CALLBACK(prev_marker);
136 PATH_CALLBACK(next_marker);
139 PATH_CALLBACK(toggle_punch_in);
140 PATH_CALLBACK(toggle_punch_out);
141 PATH_CALLBACK(rec_enable_toggle);
142 PATH_CALLBACK(toggle_all_rec_enables);
144 #define PATH_CALLBACK1(name,type,optional) \
145 static int _ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *data, void *user_data) { \
146 return static_cast<OSC*>(user_data)->cb_ ## name (path, types, argv, argc, data); \
148 int cb_ ## name (const char *, const char *, lo_arg **argv, int argc, void *) { \
150 name (optional argv[0]->type); \
155 PATH_CALLBACK1(set_transport_speed,f,);
156 PATH_CALLBACK1(access_action,s,&);
158 #define PATH_CALLBACK2(name,arg1type,arg2type) \
159 static int _ ## name (const char *path, const char *types, lo_arg **argv, int argc, void *data, void *user_data) { \
160 return static_cast<OSC*>(user_data)->cb_ ## name (path, types, argv, argc, data); \
162 int cb_ ## name (const char *, const char *, lo_arg **argv, int argc, void *) { \
164 name (argv[0]->arg1type, argv[1]->arg2type); \
169 PATH_CALLBACK2(route_mute,i,i);
170 PATH_CALLBACK2(route_solo,i,i);
171 PATH_CALLBACK2(route_recenable,i,i);
172 PATH_CALLBACK2(route_set_gain_abs,i,f);
173 PATH_CALLBACK2(route_set_gain_dB,i,f);
175 int route_mute (int rid, int yn);
176 int route_solo (int rid, int yn);
177 int route_recenable (int rid, int yn);
178 int route_set_gain_abs (int rid, float level);
179 int route_set_gain_dB (int rid, float dB);
181 void listen_to_route (boost::shared_ptr<ARDOUR::Route>, lo_address);
182 void end_listen (boost::shared_ptr<ARDOUR::Route>, lo_address);
183 void drop_route (boost::weak_ptr<ARDOUR::Route>);
185 typedef std::list<OSCControllable*> Controllables;
187 Controllables controllables;
190 #endif // ardour_osc_h