2 Copyright (C) 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., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include "boost/lambda/lambda.hpp"
22 #include "ardour/route.h"
23 #include "ardour/audio_track.h"
24 #include "ardour/midi_track.h"
27 #include "osc_route_observer.h"
29 #define ui_bind(f, ...) boost::protect (boost::bind (f, __VA_ARGS__))
34 using namespace ARDOUR;
35 using namespace boost;
38 OSCRouteObserver::OSCRouteObserver (shared_ptr<Route> r, lo_address a)
41 addr = lo_address_new (lo_address_get_hostname(a) , lo_address_get_port(a));
43 _route->PropertyChanged.connect (name_changed_connection, MISSING_INVALIDATOR, ui_bind (&OSCRouteObserver::name_changed, this, boost::lambda::_1), OSC::instance());
45 if (dynamic_pointer_cast<AudioTrack>(_route) || dynamic_pointer_cast<MidiTrack>(_route)) {
47 shared_ptr<Track> track = dynamic_pointer_cast<Track>(r);
48 shared_ptr<Controllable> rec_controllable = dynamic_pointer_cast<Controllable>(track->rec_enable_control());
50 rec_controllable->Changed.connect (rec_changed_connection, MISSING_INVALIDATOR, bind (&OSCRouteObserver::send_change_message, this, X_("/route/rec"), track->rec_enable_control()), OSC::instance());
53 shared_ptr<Controllable> mute_controllable = dynamic_pointer_cast<Controllable>(_route->mute_control());
54 mute_controllable->Changed.connect (mute_changed_connection, MISSING_INVALIDATOR, bind (&OSCRouteObserver::send_change_message, this, X_("/route/mute"), _route->mute_control()), OSC::instance());
56 shared_ptr<Controllable> solo_controllable = dynamic_pointer_cast<Controllable>(_route->solo_control());
57 solo_controllable->Changed.connect (solo_changed_connection, MISSING_INVALIDATOR, bind (&OSCRouteObserver::send_change_message, this, X_("/route/solo"), _route->solo_control()), OSC::instance());
59 shared_ptr<Controllable> gain_controllable = dynamic_pointer_cast<Controllable>(_route->gain_control());
60 gain_controllable->Changed.connect (gain_changed_connection, MISSING_INVALIDATOR, bind (&OSCRouteObserver::send_change_message, this, X_("/route/gain"), _route->gain_control()), OSC::instance());
63 OSCRouteObserver::~OSCRouteObserver ()
65 name_changed_connection.disconnect();
66 rec_changed_connection.disconnect();
67 mute_changed_connection.disconnect();
68 solo_changed_connection.disconnect();
69 gain_changed_connection.disconnect();
71 lo_address_free (addr);
75 OSCRouteObserver::name_changed (const PBD::PropertyChange& what_changed)
77 if (!what_changed.contains (ARDOUR::Properties::name)) {
85 lo_message msg = lo_message_new ();
87 lo_message_add_int32 (msg, _route->remote_control_id());
88 lo_message_add_string (msg, _route->name().c_str());
90 lo_send_message (addr, "/route/name", msg);
91 lo_message_free (msg);
95 OSCRouteObserver::send_change_message (string path, shared_ptr<Controllable> controllable)
97 lo_message msg = lo_message_new ();
99 lo_message_add_int32 (msg, _route->remote_control_id());
100 lo_message_add_float (msg, (float) controllable->get_value());
102 /* XXX thread issues */
104 //std::cerr << "ORC: send " << path << " = " << controllable->get_value() << std::endl;
106 lo_send_message (addr, path.c_str(), msg);
107 lo_message_free (msg);