2 * Copyright (C) 2006 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 "pbd/gstdio_compat.h"
29 #include <glibmm/miscutils.h>
31 #include <pbd/convert.h>
32 #include <pbd/pthread_utils.h>
33 #include <pbd/file_utils.h>
34 #include <pbd/failed_constructor.h>
36 #include "ardour/amp.h"
37 #include "ardour/session.h"
38 #include "ardour/route.h"
39 #include "ardour/audio_track.h"
40 #include "ardour/midi_track.h"
41 #include "ardour/dB.h"
42 #include "ardour/filesystem_paths.h"
43 #include "ardour/panner.h"
44 #include "ardour/plugin.h"
45 #include "ardour/plugin_insert.h"
46 #include "ardour/send.h"
49 #include "osc_controllable.h"
50 #include "osc_route_observer.h"
53 using namespace ARDOUR;
56 using namespace ArdourSurface;
58 #include "pbd/abstract_ui.cc" // instantiate template
60 OSC* OSC::_instance = 0;
63 static void error_callback(int num, const char *m, const char *path)
65 fprintf(stderr, "liblo server error %d in path %s: %s\n", num, path, m);
68 static void error_callback(int, const char *, const char *)
74 OSC::OSC (Session& s, uint32_t port)
75 : ControlProtocol (s, X_("Open Sound Control (OSC)"))
76 , AbstractUI<OSCUIRequest> (name())
83 , _osc_unix_server (0)
84 , _namespace_root ("/ardour")
85 , _send_route_changes (true)
92 session->Exported.connect (*this, MISSING_INVALIDATOR, boost::bind (&OSC::session_exported, this, _1, _2), this);
102 OSC::request_factory (uint32_t num_requests)
104 /* AbstractUI<T>::request_buffer_factory() is a template method only
105 instantiated in this source module. To provide something visible for
106 use in the interface/descriptor, we have this static method that is
109 return request_buffer_factory (num_requests);
113 OSC::do_request (OSCUIRequest* req)
115 if (req->type == CallSlot) {
117 call_slot (MISSING_INVALIDATOR, req->the_slot);
119 } else if (req->type == Quit) {
126 OSC::set_active (bool yn)
128 if (yn != active()) {
142 return ControlProtocol::set_active (yn);
146 OSC::get_active () const
148 return _osc_server != 0;
152 OSC::set_feedback (bool yn)
154 _send_route_changes = yn;
159 OSC::get_feedback () const
161 return _send_route_changes;
170 /* already started */
174 for (int j=0; j < 20; ++j) {
175 snprintf(tmpstr, sizeof(tmpstr), "%d", _port);
177 //if ((_osc_server = lo_server_new_with_proto (tmpstr, LO_TCP, error_callback))) {
181 if ((_osc_server = lo_server_new (tmpstr, error_callback))) {
186 cerr << "can't get osc at port: " << _port << endl;
196 #ifdef ARDOUR_OSC_UNIX_SERVER
198 // APPEARS sluggish for now
200 // attempt to create unix socket server too
202 snprintf(tmpstr, sizeof(tmpstr), "/tmp/sooperlooper_XXXXXX");
203 int fd = mkstemp(tmpstr);
209 _osc_unix_server = lo_server_new (tmpstr, error_callback);
211 if (_osc_unix_server) {
212 _osc_unix_socket_path = tmpstr;
217 PBD::info << "OSC @ " << get_server_url () << endmsg;
219 std::string url_file;
221 if (find_file (ardour_config_search_path(), "osc_url", url_file)) {
222 _osc_url_file = url_file;
223 if (g_file_set_contents (_osc_url_file.c_str(), get_server_url().c_str(), -1, NULL)) {
224 cerr << "Couldn't write '" << _osc_url_file << "'" <<endl;
228 register_callbacks();
230 // lo_server_thread_add_method(_sthread, NULL, NULL, OSC::_dummy_handler, this);
232 /* startup the event loop thread */
242 pthread_set_name (event_loop_name().c_str());
244 if (_osc_unix_server) {
245 Glib::RefPtr<IOSource> src = IOSource::create (lo_server_get_socket_fd (_osc_unix_server), IO_IN|IO_HUP|IO_ERR);
246 src->connect (sigc::bind (sigc::mem_fun (*this, &OSC::osc_input_handler), _osc_unix_server));
247 src->attach (_main_loop->get_context());
248 local_server = src->gobj();
249 g_source_ref (local_server);
253 Glib::RefPtr<IOSource> src = IOSource::create (lo_server_get_socket_fd (_osc_server), IO_IN|IO_HUP|IO_ERR);
254 src->connect (sigc::bind (sigc::mem_fun (*this, &OSC::osc_input_handler), _osc_server));
255 src->attach (_main_loop->get_context());
256 remote_server = src->gobj();
257 g_source_ref (remote_server);
260 PBD::notify_event_loops_about_thread_creation (pthread_self(), event_loop_name(), 2048);
261 SessionEvent::create_per_thread_pool (event_loop_name(), 128);
270 g_source_destroy (local_server);
271 g_source_unref (local_server);
276 g_source_destroy (remote_server);
277 g_source_unref (remote_server);
284 lo_server_free (_osc_server);
288 if (_osc_unix_server) {
289 lo_server_free (_osc_unix_server);
290 _osc_unix_server = 0;
293 if (!_osc_unix_socket_path.empty()) {
294 ::g_unlink (_osc_unix_socket_path.c_str());
297 if (!_osc_url_file.empty() ) {
298 ::g_unlink (_osc_url_file.c_str() );
301 // Delete any active route observers
302 for (RouteObservers::iterator x = route_observers.begin(); x != route_observers.end();) {
304 OSCRouteObserver* rc;
306 if ((rc = dynamic_cast<OSCRouteObserver*>(*x)) != 0) {
308 x = route_observers.erase (x);
318 OSC::register_callbacks()
323 srvs[0] = _osc_server;
324 srvs[1] = _osc_unix_server;
326 for (size_t i = 0; i < 2; ++i) {
335 #define REGISTER_CALLBACK(serv,path,types, function) lo_server_add_method (serv, path, types, OSC::_ ## function, this)
337 REGISTER_CALLBACK (serv, "/routes/list", "", routes_list);
338 REGISTER_CALLBACK (serv, "/ardour/add_marker", "", add_marker);
339 REGISTER_CALLBACK (serv, "/ardour/access_action", "s", access_action);
340 REGISTER_CALLBACK (serv, "/ardour/loop_toggle", "", loop_toggle);
341 REGISTER_CALLBACK (serv, "/ardour/loop_location", "ii", loop_location);
342 REGISTER_CALLBACK (serv, "/ardour/goto_start", "", goto_start);
343 REGISTER_CALLBACK (serv, "/ardour/goto_end", "", goto_end);
344 REGISTER_CALLBACK (serv, "/ardour/rewind", "", rewind);
345 REGISTER_CALLBACK (serv, "/ardour/ffwd", "", ffwd);
346 REGISTER_CALLBACK (serv, "/ardour/transport_stop", "", transport_stop);
347 REGISTER_CALLBACK (serv, "/ardour/transport_play", "", transport_play);
348 REGISTER_CALLBACK (serv, "/ardour/transport_frame", "", transport_frame);
349 REGISTER_CALLBACK (serv, "/ardour/transport_speed", "", transport_speed);
350 REGISTER_CALLBACK (serv, "/ardour/record_enabled", "", record_enabled);
351 REGISTER_CALLBACK (serv, "/ardour/set_transport_speed", "f", set_transport_speed);
352 REGISTER_CALLBACK (serv, "/ardour/locate", "ii", locate);
353 REGISTER_CALLBACK (serv, "/ardour/save_state", "", save_state);
354 REGISTER_CALLBACK (serv, "/ardour/prev_marker", "", prev_marker);
355 REGISTER_CALLBACK (serv, "/ardour/next_marker", "", next_marker);
356 REGISTER_CALLBACK (serv, "/ardour/undo", "", undo);
357 REGISTER_CALLBACK (serv, "/ardour/redo", "", redo);
358 REGISTER_CALLBACK (serv, "/ardour/toggle_punch_in", "", toggle_punch_in);
359 REGISTER_CALLBACK (serv, "/ardour/toggle_punch_out", "", toggle_punch_out);
360 REGISTER_CALLBACK (serv, "/ardour/rec_enable_toggle", "", rec_enable_toggle);
361 REGISTER_CALLBACK (serv, "/ardour/toggle_all_rec_enables", "", toggle_all_rec_enables);
362 REGISTER_CALLBACK (serv, "/ardour/remove_marker", "", remove_marker_at_playhead);
363 REGISTER_CALLBACK (serv, "/ardour/jump_bars", "f", jump_by_bars);
364 REGISTER_CALLBACK (serv, "/ardour/jump_seconds", "f", jump_by_seconds);
365 REGISTER_CALLBACK (serv, "/ardour/mark_in", "", mark_in);
366 REGISTER_CALLBACK (serv, "/ardour/mark_out", "", mark_out);
367 REGISTER_CALLBACK (serv, "/ardour/toggle_click", "", toggle_click);
368 REGISTER_CALLBACK (serv, "/ardour/midi_panic", "", midi_panic);
369 REGISTER_CALLBACK (serv, "/ardour/toggle_roll", "", toggle_roll);
370 REGISTER_CALLBACK (serv, "/ardour/stop_forget", "", stop_forget);
371 REGISTER_CALLBACK (serv, "/ardour/set_punch_range", "", set_punch_range);
372 REGISTER_CALLBACK (serv, "/ardour/set_loop_range", "", set_loop_range);
373 REGISTER_CALLBACK (serv, "/ardour/set_session_range", "", set_session_range);
374 REGISTER_CALLBACK (serv, "/ardour/toggle_monitor_mute", "", toggle_monitor_mute);
375 REGISTER_CALLBACK (serv, "/ardour/toggle_monitor_dim", "", toggle_monitor_dim);
376 REGISTER_CALLBACK (serv, "/ardour/toggle_monitor_mono", "", toggle_monitor_mono);
377 REGISTER_CALLBACK (serv, "/ardour/quick_snapshot_switch", "", quick_snapshot_switch);
378 REGISTER_CALLBACK (serv, "/ardour/quick_snapshot_stay", "", quick_snapshot_stay);
382 * NOTE: these messages are provided for (arguably broken) apps
383 * that MUST send float args ( TouchOSC and Lemur ).
384 * Normally these ardour transport messages don't require an argument,
385 * so we're providing redundant calls with vestigial "float" args.
387 * These controls are active on 1.0 only (to prevent duplicate action on
388 * press "/button 1", and release "/button 0")
389 * http://hexler.net/docs/touchosc-controls-reference
391 REGISTER_CALLBACK (serv, "/ardour/pushbutton/loop_toggle", "f", loop_toggle);
392 REGISTER_CALLBACK (serv, "/ardour/pushbutton/add_marker", "f", add_marker);
393 REGISTER_CALLBACK (serv, "/ardour/pushbutton/goto_start", "f", goto_start);
394 REGISTER_CALLBACK (serv, "/ardour/pushbutton/goto_end", "f", goto_end);
395 REGISTER_CALLBACK (serv, "/ardour/pushbutton/rewind", "f", rewind);
396 REGISTER_CALLBACK (serv, "/ardour/pushbutton/ffwd", "f", ffwd);
397 REGISTER_CALLBACK (serv, "/ardour/pushbutton/transport_stop", "f", transport_stop);
398 REGISTER_CALLBACK (serv, "/ardour/pushbutton/transport_play", "f", transport_play);
399 REGISTER_CALLBACK (serv, "/ardour/pushbutton/save_state", "f", save_state);
400 REGISTER_CALLBACK (serv, "/ardour/pushbutton/prev_marker", "f", prev_marker);
401 REGISTER_CALLBACK (serv, "/ardour/pushbutton/next_marker", "f", next_marker);
402 REGISTER_CALLBACK (serv, "/ardour/pushbutton/undo", "f", undo);
403 REGISTER_CALLBACK (serv, "/ardour/pushbutton/redo", "f", redo);
404 REGISTER_CALLBACK (serv, "/ardour/pushbutton/toggle_punch_in", "f", toggle_punch_in);
405 REGISTER_CALLBACK (serv, "/ardour/pushbutton/toggle_punch_out", "f", toggle_punch_out);
406 REGISTER_CALLBACK (serv, "/ardour/pushbutton/rec_enable_toggle", "f", rec_enable_toggle);
407 REGISTER_CALLBACK (serv, "/ardour/pushbutton/toggle_all_rec_enables", "f", toggle_all_rec_enables);
408 REGISTER_CALLBACK (serv, "/ardour/pushbutton/remove_marker", "f", remove_marker_at_playhead);
409 REGISTER_CALLBACK (serv, "/ardour/pushbutton/mark_in", "f", mark_in);
410 REGISTER_CALLBACK (serv, "/ardour/pushbutton/mark_out", "f", mark_out);
411 REGISTER_CALLBACK (serv, "/ardour/pushbutton/toggle_click", "f", toggle_click);
412 REGISTER_CALLBACK (serv, "/ardour/pushbutton/midi_panic", "f", midi_panic);
413 REGISTER_CALLBACK (serv, "/ardour/pushbutton/toggle_roll", "f", toggle_roll);
414 REGISTER_CALLBACK (serv, "/ardour/pushbutton/stop_forget", "f", stop_forget);
415 REGISTER_CALLBACK (serv, "/ardour/pushbutton/set_punch_range", "f", set_punch_range);
416 REGISTER_CALLBACK (serv, "/ardour/pushbutton/set_loop_range", "f", set_loop_range);
417 REGISTER_CALLBACK (serv, "/ardour/pushbutton/set_session_range", "f", set_session_range);
418 REGISTER_CALLBACK (serv, "/ardour/pushbutton/toggle_monitor_mute", "f", toggle_monitor_mute);
419 REGISTER_CALLBACK (serv, "/ardour/pushbutton/toggle_monitor_dim", "f", toggle_monitor_dim);
420 REGISTER_CALLBACK (serv, "/ardour/pushbutton/toggle_monitor_mono", "f", toggle_monitor_mono);
421 REGISTER_CALLBACK (serv, "/ardour/pushbutton/quick_snapshot_switch", "f", quick_snapshot_switch);
422 REGISTER_CALLBACK (serv, "/ardour/pushbutton/quick_snapshot_stay", "f", quick_snapshot_stay);
424 /* These commands require the route index in addition to the arg; TouchOSC (et al) can't use these */
425 REGISTER_CALLBACK (serv, "/ardour/routes/mute", "ii", route_mute);
426 REGISTER_CALLBACK (serv, "/ardour/routes/solo", "ii", route_solo);
427 REGISTER_CALLBACK (serv, "/ardour/routes/recenable", "ii", route_recenable);
428 REGISTER_CALLBACK (serv, "/ardour/routes/gainabs", "if", route_set_gain_abs);
429 REGISTER_CALLBACK (serv, "/ardour/routes/gaindB", "if", route_set_gain_dB);
430 REGISTER_CALLBACK (serv, "/ardour/routes/trimabs", "if", route_set_trim_abs);
431 REGISTER_CALLBACK (serv, "/ardour/routes/trimdB", "if", route_set_trim_dB);
432 REGISTER_CALLBACK (serv, "/ardour/routes/pan_stereo_position", "if", route_set_pan_stereo_position);
433 REGISTER_CALLBACK (serv, "/ardour/routes/pan_stereo_width", "if", route_set_pan_stereo_width);
434 REGISTER_CALLBACK (serv, "/ardour/routes/plugin/parameter", "iiif", route_plugin_parameter);
435 REGISTER_CALLBACK (serv, "/ardour/routes/plugin/parameter/print", "iii", route_plugin_parameter_print);
436 REGISTER_CALLBACK (serv, "/ardour/routes/send/gainabs", "iif", route_set_send_gain_abs);
437 REGISTER_CALLBACK (serv, "/ardour/routes/send/gaindB", "iif", route_set_send_gain_dB);
439 /* still not-really-standardized query interface */
440 //REGISTER_CALLBACK (serv, "/ardour/*/#current_value", "", current_value);
441 //REGISTER_CALLBACK (serv, "/ardour/set", "", set);
443 // un/register_update args= s:ctrl s:returl s:retpath
444 //lo_server_add_method(serv, "/register_update", "sss", OSC::global_register_update_handler, this);
445 //lo_server_add_method(serv, "/unregister_update", "sss", OSC::global_unregister_update_handler, this);
446 //lo_server_add_method(serv, "/register_auto_update", "siss", OSC::global_register_auto_update_handler, this);
447 //lo_server_add_method(serv, "/unregister_auto_update", "sss", OSC::_global_unregister_auto_update_handler, this);
449 /* this is a special catchall handler,
450 * register at the end so this is only called if no
451 * other handler matches (used for debug) */
452 lo_server_add_method (serv, 0, 0, _catchall, this);
457 OSC::osc_input_handler (IOCondition ioc, lo_server srv)
464 lo_server_recv (srv);
471 OSC::get_server_url()
477 urlstr = lo_server_get_url (_osc_server);
486 OSC::get_unix_server_url()
491 if (_osc_unix_server) {
492 urlstr = lo_server_get_url (_osc_unix_server);
501 OSC::listen_to_route (boost::shared_ptr<Route> route, lo_address addr)
503 /* avoid duplicate listens */
505 for (RouteObservers::iterator x = route_observers.begin(); x != route_observers.end(); ++x) {
507 OSCRouteObserver* ro;
509 if ((ro = dynamic_cast<OSCRouteObserver*>(*x)) != 0) {
511 int res = strcmp(lo_address_get_hostname(ro->address()), lo_address_get_hostname(addr));
513 if (ro->route() == route && res == 0) {
519 OSCRouteObserver* o = new OSCRouteObserver (route, addr);
520 route_observers.push_back (o);
522 route->DropReferences.connect (*this, MISSING_INVALIDATOR, boost::bind (&OSC::drop_route, this, boost::weak_ptr<Route> (route)), this);
526 OSC::drop_route (boost::weak_ptr<Route> wr)
528 boost::shared_ptr<Route> r = wr.lock ();
534 for (RouteObservers::iterator x = route_observers.begin(); x != route_observers.end();) {
536 OSCRouteObserver* rc;
538 if ((rc = dynamic_cast<OSCRouteObserver*>(*x)) != 0) {
540 if (rc->route() == r) {
542 x = route_observers.erase (x);
553 OSC::end_listen (boost::shared_ptr<Route> r, lo_address addr)
555 RouteObservers::iterator x;
557 // Remove the route observers
558 for (x = route_observers.begin(); x != route_observers.end();) {
560 OSCRouteObserver* ro;
562 if ((ro = dynamic_cast<OSCRouteObserver*>(*x)) != 0) {
564 int res = strcmp(lo_address_get_hostname(ro->address()), lo_address_get_hostname(addr));
566 if (ro->route() == r && res == 0) {
568 x = route_observers.erase (x);
581 OSC::current_value_query (const char* path, size_t len, lo_arg **argv, int argc, lo_message msg)
585 subpath = (char*) malloc (len-15+1);
586 memcpy (subpath, path, len-15);
587 subpath[len-15] = '\0';
589 send_current_value (subpath, argv, argc, msg);
595 OSC::send_current_value (const char* path, lo_arg** argv, int argc, lo_message msg)
601 lo_message reply = lo_message_new ();
602 boost::shared_ptr<Route> r;
605 lo_message_add_string (reply, path);
608 lo_message_add_string (reply, "bad syntax");
611 r = session->route_by_remote_id (id);
614 lo_message_add_string (reply, "not found");
617 if (strcmp (path, "/routes/state") == 0) {
619 if (boost::dynamic_pointer_cast<AudioTrack>(r)) {
620 lo_message_add_string (reply, "AT");
621 } else if (boost::dynamic_pointer_cast<MidiTrack>(r)) {
622 lo_message_add_string (reply, "MT");
624 lo_message_add_string (reply, "B");
627 lo_message_add_string (reply, r->name().c_str());
628 lo_message_add_int32 (reply, r->n_inputs().n_audio());
629 lo_message_add_int32 (reply, r->n_outputs().n_audio());
630 lo_message_add_int32 (reply, r->muted());
631 lo_message_add_int32 (reply, r->soloed());
633 } else if (strcmp (path, "/routes/mute") == 0) {
635 lo_message_add_int32 (reply, (float) r->muted());
637 } else if (strcmp (path, "/routes/solo") == 0) {
639 lo_message_add_int32 (reply, r->soloed());
644 lo_send_message (lo_message_get_source (msg), "#reply", reply);
645 lo_message_free (reply);
649 OSC::_catchall (const char *path, const char *types, lo_arg **argv, int argc, void *data, void *user_data)
651 return ((OSC*)user_data)->catchall (path, types, argv, argc, data);
655 OSC::catchall (const char *path, const char* types, lo_arg **argv, int argc, lo_message msg)
658 int ret = 1; /* unhandled */
660 //cerr << "Received a message, path = " << path << " types = \""
661 // << (types ? types : "NULL") << '"' << endl;
663 /* 15 for /#current_value plus 2 for /<path> */
667 if (len >= 17 && !strcmp (&path[len-15], "/#current_value")) {
668 current_value_query (path, len, argv, argc, msg);
671 } else if (strcmp (path, "/routes/listen") == 0) {
673 cerr << "set up listener\n";
675 lo_message reply = lo_message_new ();
678 lo_message_add_string (reply, "syntax error");
680 for (int n = 0; n < argc; ++n) {
682 boost::shared_ptr<Route> r = session->route_by_remote_id (argv[n]->i);
685 lo_message_add_string (reply, "not found");
686 cerr << "no such route\n";
689 cerr << "add listener\n";
690 listen_to_route (r, lo_message_get_source (msg));
691 lo_message_add_int32 (reply, argv[n]->i);
696 lo_send_message (lo_message_get_source (msg), "#reply", reply);
697 lo_message_free (reply);
701 } else if (strcmp (path, "/routes/ignore") == 0) {
703 for (int n = 0; n < argc; ++n) {
705 boost::shared_ptr<Route> r = session->route_by_remote_id (argv[n]->i);
708 end_listen (r, lo_message_get_source (msg));
713 } else if (argc == 1 && types[0] == 'f') { // single float -- probably TouchOSC
714 if (!strncmp (path, "/ardour/routes/gainabs/", 23) && strlen (path) > 23) {
715 int rid = atoi (&path[23]);
716 // use some power-scale mapping??
717 route_set_gain_abs (rid, argv[0]->f);
720 else if (!strncmp (path, "/ardour/routes/trimabs/", 23) && strlen (path) > 23) {
721 int rid = atoi (&path[23]);
723 route_set_trim_abs (rid, argv[0]->f);
726 else if (!strncmp (path, "/ardour/routes/mute/", 20) && strlen (path) > 20) {
727 int rid = atoi (&path[20]);
728 route_mute (rid, argv[0]->f == 1.0);
731 else if (!strncmp (path, "/ardour/routes/solo/", 20) && strlen (path) > 20) {
732 int rid = atoi (&path[20]);
733 route_solo (rid, argv[0]->f == 1.0);
736 else if (!strncmp (path, "/ardour/routes/recenable/", 25) && strlen (path) > 25) {
737 int rid = atoi (&path[25]);
738 route_recenable (rid, argv[0]->f == 1.0);
743 if ((ret && _debugmode == Unhandled)) {
744 debugmsg (_("Unhandled OSC message"), path, types, argv, argc);
751 OSC::debugmsg (const char *prefix, const char *path, const char* types, lo_arg **argv, int argc)
753 std::stringstream ss;
754 for (int i = 0; i < argc; ++i) {
755 lo_type type = (lo_type)types[i];
759 ss << "i:" << argv[i]->i;
762 ss << "f:" << argv[i]->f;
765 ss << "d:" << argv[i]->d;
768 ss << "s:" << &argv[i]->s;
771 ss << "h:" << argv[i]->h;
774 ss << "c:" << argv[i]->s;
805 PBD::info << prefix << ": " << path << ss.str() << endmsg;
814 // "Application Hook" Handlers //
816 OSC::session_loaded (Session& s)
818 lo_address listener = lo_address_new (NULL, "7770");
819 lo_send (listener, "/session/loaded", "ss", s.path().c_str(), s.name().c_str());
823 OSC::session_exported (std::string path, std::string name)
825 lo_address listener = lo_address_new (NULL, "7770");
826 lo_send (listener, "/session/exported", "ss", path.c_str(), name.c_str());
829 // end "Application Hook" Handlers //
834 OSC::current_value (const char */*path*/, const char */*types*/, lo_arg **/*argv*/, int /*argc*/, void */*data*/, void* /*user_data*/)
839 if (argc < 3 || types == 0 || strlen (types) < 3 || types[0] != 's' || types[1] != 's' || types[2] != s) {
843 const char *returl = argv[1]->s;
844 lo_address addr = find_or_cache_addr (returl);
846 const char *retpath = argv[2]->s;
849 if (strcmp (argv[0]->s, "transport_frame") == 0) {
852 lo_send (addr, retpath, "i", session->transport_frame());
855 } else if (strcmp (argv[0]->s, "transport_speed") == 0) {
858 lo_send (addr, retpath, "i", session->transport_frame());
861 } else if (strcmp (argv[0]->s, "transport_locked") == 0) {
864 lo_send (addr, retpath, "i", session->transport_frame());
867 } else if (strcmp (argv[0]->s, "punch_in") == 0) {
870 lo_send (addr, retpath, "i", session->transport_frame());
873 } else if (strcmp (argv[0]->s, "punch_out") == 0) {
876 lo_send (addr, retpath, "i", session->transport_frame());
879 } else if (strcmp (argv[0]->s, "rec_enable") == 0) {
882 lo_send (addr, retpath, "i", session->transport_frame());
894 OSC::routes_list (lo_message msg)
899 for (int n = 0; n < (int) session->nroutes(); ++n) {
901 boost::shared_ptr<Route> r = session->route_by_remote_id (n);
905 lo_message reply = lo_message_new ();
907 if (boost::dynamic_pointer_cast<AudioTrack>(r)) {
908 lo_message_add_string (reply, "AT");
909 } else if (boost::dynamic_pointer_cast<MidiTrack>(r)) {
910 lo_message_add_string (reply, "MT");
912 lo_message_add_string (reply, "B");
915 lo_message_add_string (reply, r->name().c_str());
916 lo_message_add_int32 (reply, r->n_inputs().n_audio());
917 lo_message_add_int32 (reply, r->n_outputs().n_audio());
918 lo_message_add_int32 (reply, r->muted());
919 lo_message_add_int32 (reply, r->soloed());
920 lo_message_add_int32 (reply, r->remote_control_id());
922 if (boost::dynamic_pointer_cast<AudioTrack>(r)
923 || boost::dynamic_pointer_cast<MidiTrack>(r)) {
925 boost::shared_ptr<Track> t = boost::dynamic_pointer_cast<Track>(r);
926 lo_message_add_int32 (reply, t->record_enabled());
929 //Automatically listen to routes listed
930 listen_to_route(r, lo_message_get_source (msg));
932 lo_send_message (lo_message_get_source (msg), "#reply", reply);
933 lo_message_free (reply);
937 // Send end of listing message
938 lo_message reply = lo_message_new ();
940 lo_message_add_string (reply, "end_route_list");
941 lo_message_add_int64 (reply, session->frame_rate());
942 lo_message_add_int64 (reply, session->current_end_frame());
944 lo_send_message (lo_message_get_source (msg), "#reply", reply);
946 lo_message_free (reply);
950 OSC::transport_frame (lo_message msg)
955 framepos_t pos = session->transport_frame ();
957 lo_message reply = lo_message_new ();
958 lo_message_add_int64 (reply, pos);
960 lo_send_message (lo_message_get_source (msg), "/ardour/transport_frame", reply);
962 lo_message_free (reply);
966 OSC::transport_speed (lo_message msg)
971 double ts = session->transport_speed ();
973 lo_message reply = lo_message_new ();
974 lo_message_add_double (reply, ts);
976 lo_send_message (lo_message_get_source (msg), "/ardour/transport_speed", reply);
978 lo_message_free (reply);
982 OSC::record_enabled (lo_message msg)
987 int re = (int)session->get_record_enabled ();
989 lo_message reply = lo_message_new ();
990 lo_message_add_int32 (reply, re);
992 lo_send_message (lo_message_get_source (msg), "/ardour/record_enabled", reply);
994 lo_message_free (reply);
999 OSC::route_mute (int rid, int yn)
1001 if (!session) return -1;
1003 boost::shared_ptr<Route> r = session->route_by_remote_id (rid);
1006 r->set_mute (yn, this);
1013 OSC::route_solo (int rid, int yn)
1015 if (!session) return -1;
1017 boost::shared_ptr<Route> r = session->route_by_remote_id (rid);
1020 boost::shared_ptr<RouteList> rl (new RouteList);
1022 session->set_solo (rl, yn);
1029 OSC::route_recenable (int rid, int yn)
1031 if (!session) return -1;
1033 boost::shared_ptr<Route> r = session->route_by_remote_id (rid);
1036 r->set_record_enabled (yn, this);
1043 OSC::route_set_gain_abs (int rid, float level)
1045 if (!session) return -1;
1047 boost::shared_ptr<Route> r = session->route_by_remote_id (rid);
1050 r->set_gain (level, PBD::Controllable::NoGroup);
1057 OSC::route_set_gain_dB (int rid, float dB)
1059 return route_set_gain_abs (rid, dB_to_coefficient (dB));
1064 OSC::route_set_trim_abs (int rid, float level)
1066 if (!session) return -1;
1068 boost::shared_ptr<Route> r = session->route_by_remote_id (rid);
1071 r->set_trim (level, this);
1078 OSC::route_set_trim_dB (int rid, float dB)
1080 return route_set_trim_abs(rid, dB_to_coefficient (dB));
1085 OSC::route_set_pan_stereo_position (int rid, float pos)
1087 if (!session) return -1;
1089 boost::shared_ptr<Route> r = session->route_by_remote_id (rid);
1092 boost::shared_ptr<Panner> panner = r->panner();
1094 panner->set_position (pos);
1103 OSC::route_set_pan_stereo_width (int rid, float pos)
1105 if (!session) return -1;
1107 boost::shared_ptr<Route> r = session->route_by_remote_id (rid);
1110 boost::shared_ptr<Panner> panner = r->panner();
1112 panner->set_width (pos);
1121 OSC::route_set_send_gain_abs (int rid, int sid, float val)
1127 boost::shared_ptr<Route> r = session->route_by_remote_id (rid);
1133 /* revert to zero-based counting */
1139 boost::shared_ptr<Processor> p = r->nth_send (sid);
1142 boost::shared_ptr<Send> s = boost::dynamic_pointer_cast<Send>(p);
1143 boost::shared_ptr<Amp> a = s->amp();
1146 a->gain_control()->set_value (val, PBD::Controllable::NoGroup);
1153 OSC::route_set_send_gain_dB (int rid, int sid, float val)
1159 boost::shared_ptr<Route> r = session->route_by_remote_id (rid);
1165 /* revert to zero-based counting */
1171 boost::shared_ptr<Processor> p = r->nth_send (sid);
1174 boost::shared_ptr<Send> s = boost::dynamic_pointer_cast<Send>(p);
1175 boost::shared_ptr<Amp> a = s->amp();
1178 a->gain_control()->set_value (dB_to_coefficient (val), PBD::Controllable::NoGroup);
1185 OSC::route_plugin_parameter (int rid, int piid, int par, float val)
1190 boost::shared_ptr<Route> r = session->route_by_remote_id (rid);
1193 PBD::error << "OSC: Invalid Remote Control ID '" << rid << "'" << endmsg;
1197 boost::shared_ptr<Processor> redi=r->nth_plugin (piid);
1200 PBD::error << "OSC: cannot find plugin # " << piid << " for RID '" << rid << "'" << endmsg;
1204 boost::shared_ptr<PluginInsert> pi;
1206 if (!(pi = boost::dynamic_pointer_cast<PluginInsert>(redi))) {
1207 PBD::error << "OSC: given processor # " << piid << " on RID '" << rid << "' is not a Plugin." << endmsg;
1211 boost::shared_ptr<ARDOUR::Plugin> pip = pi->plugin();
1214 uint32_t controlid = pip->nth_parameter (par,ok);
1217 PBD::error << "OSC: Cannot find parameter # " << par << " for plugin # " << piid << " on RID '" << rid << "'" << endmsg;
1221 if (!pip->parameter_is_input(controlid)) {
1222 PBD::error << "OSC: Parameter # " << par << " for plugin # " << piid << " on RID '" << rid << "' is not a control input" << endmsg;
1226 ParameterDescriptor pd;
1227 pi->plugin()->get_parameter_descriptor (controlid,pd);
1229 if (val >= pd.lower && val < pd.upper) {
1231 boost::shared_ptr<AutomationControl> c = pi->automation_control (Evoral::Parameter(PluginAutomation, 0, controlid));
1232 // cerr << "parameter:" << redi->describe_parameter(controlid) << " val:" << val << "\n";
1233 c->set_value (val, PBD::Controllable::NoGroup);
1235 PBD::warning << "OSC: Parameter # " << par << " for plugin # " << piid << " on RID '" << rid << "' is out of range" << endmsg;
1236 PBD::info << "OSC: Valid range min=" << pd.lower << " max=" << pd.upper << endmsg;
1243 OSC::route_plugin_parameter_print (int rid, int piid, int par)
1249 boost::shared_ptr<Route> r = session->route_by_remote_id (rid);
1255 boost::shared_ptr<Processor> redi=r->nth_processor (piid);
1261 boost::shared_ptr<PluginInsert> pi;
1263 if (!(pi = boost::dynamic_pointer_cast<PluginInsert>(redi))) {
1267 boost::shared_ptr<ARDOUR::Plugin> pip = pi->plugin();
1270 uint32_t controlid = pip->nth_parameter (par,ok);
1276 ParameterDescriptor pd;
1278 if (pi->plugin()->get_parameter_descriptor (controlid, pd) == 0) {
1279 boost::shared_ptr<AutomationControl> c = pi->automation_control (Evoral::Parameter(PluginAutomation, 0, controlid));
1281 cerr << "parameter: " << redi->describe_parameter(controlid) << "\n";
1282 cerr << "current value: " << c->get_value ();
1283 cerr << "lower value: " << pd.lower << "\n";
1284 cerr << "upper value: " << pd.upper << "\n";
1293 XMLNode& node (ControlProtocol::get_state());
1294 node.add_property("debugmode", (int) _debugmode); // TODO: enum2str
1299 OSC::set_state (const XMLNode& node, int version)
1301 if (ControlProtocol::set_state (node, version)) {
1304 XMLProperty const * p = node.property (X_("debugmode"));
1306 _debugmode = OSCDebugMode (PBD::atoi(p->value ()));