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"
31 #define ui_bind(f, ...) boost::protect (boost::bind (f, __VA_ARGS__))
36 using namespace ARDOUR
;
37 using namespace boost
;
40 OSCRouteObserver::OSCRouteObserver (boost::shared_ptr
<Route
> r
, lo_address a
)
43 addr
= lo_address_new (lo_address_get_hostname(a
) , lo_address_get_port(a
));
45 _route
->PropertyChanged
.connect (name_changed_connection
, MISSING_INVALIDATOR
, ui_bind (&OSCRouteObserver::name_changed
, this, boost::lambda::_1
), OSC::instance());
47 if (dynamic_pointer_cast
<AudioTrack
>(_route
) || dynamic_pointer_cast
<MidiTrack
>(_route
)) {
49 boost::shared_ptr
<Track
> track
= dynamic_pointer_cast
<Track
>(r
);
50 boost::shared_ptr
<Controllable
> rec_controllable
= dynamic_pointer_cast
<Controllable
>(track
->rec_enable_control());
52 rec_controllable
->Changed
.connect (rec_changed_connection
, MISSING_INVALIDATOR
, bind (&OSCRouteObserver::send_change_message
, this, X_("/route/rec"), track
->rec_enable_control()), OSC::instance());
55 boost::shared_ptr
<Controllable
> mute_controllable
= dynamic_pointer_cast
<Controllable
>(_route
->mute_control());
56 mute_controllable
->Changed
.connect (mute_changed_connection
, MISSING_INVALIDATOR
, bind (&OSCRouteObserver::send_change_message
, this, X_("/route/mute"), _route
->mute_control()), OSC::instance());
58 boost::shared_ptr
<Controllable
> solo_controllable
= dynamic_pointer_cast
<Controllable
>(_route
->solo_control());
59 solo_controllable
->Changed
.connect (solo_changed_connection
, MISSING_INVALIDATOR
, bind (&OSCRouteObserver::send_change_message
, this, X_("/route/solo"), _route
->solo_control()), OSC::instance());
61 boost::shared_ptr
<Controllable
> gain_controllable
= dynamic_pointer_cast
<Controllable
>(_route
->gain_control());
62 gain_controllable
->Changed
.connect (gain_changed_connection
, MISSING_INVALIDATOR
, bind (&OSCRouteObserver::send_change_message
, this, X_("/route/gain"), _route
->gain_control()), OSC::instance());
65 OSCRouteObserver::~OSCRouteObserver ()
67 name_changed_connection
.disconnect();
68 rec_changed_connection
.disconnect();
69 mute_changed_connection
.disconnect();
70 solo_changed_connection
.disconnect();
71 gain_changed_connection
.disconnect();
73 lo_address_free (addr
);
77 OSCRouteObserver::name_changed (const PBD::PropertyChange
& what_changed
)
79 if (!what_changed
.contains (ARDOUR::Properties::name
)) {
87 lo_message msg
= lo_message_new ();
89 lo_message_add_int32 (msg
, _route
->remote_control_id());
90 lo_message_add_string (msg
, _route
->name().c_str());
92 lo_send_message (addr
, "/route/name", msg
);
93 lo_message_free (msg
);
97 OSCRouteObserver::send_change_message (string path
, boost::shared_ptr
<Controllable
> controllable
)
99 lo_message msg
= lo_message_new ();
101 lo_message_add_int32 (msg
, _route
->remote_control_id());
102 lo_message_add_float (msg
, (float) controllable
->get_value());
104 /* XXX thread issues */
106 //std::cerr << "ORC: send " << path << " = " << controllable->get_value() << std::endl;
108 lo_send_message (addr
, path
.c_str(), msg
);
109 lo_message_free (msg
);