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/session.h"
23 #include "ardour/track.h"
24 #include "ardour/monitor_control.h"
25 #include "ardour/dB.h"
26 #include "ardour/meter.h"
29 #include "osc_route_observer.h"
35 using namespace ARDOUR;
36 using namespace ArdourSurface;
38 OSCRouteObserver::OSCRouteObserver (boost::shared_ptr<Stripable> s, lo_address a, uint32_t ss, uint32_t gm, std::bitset<32> fb)
44 addr = lo_address_new (lo_address_get_hostname(a) , lo_address_get_port(a));
46 if (feedback[0]) { // buttons are separate feedback
47 _strip->PropertyChanged.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCRouteObserver::name_changed, this, boost::lambda::_1), OSC::instance());
48 name_changed (ARDOUR::Properties::name);
50 _strip->mute_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, bind (&OSCRouteObserver::send_change_message, this, X_("/strip/mute"), _strip->mute_control()), OSC::instance());
51 send_change_message ("/strip/mute", _strip->mute_control());
53 _strip->solo_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, bind (&OSCRouteObserver::send_change_message, this, X_("/strip/solo"), _strip->solo_control()), OSC::instance());
54 send_change_message ("/strip/solo", _strip->solo_control());
56 boost::shared_ptr<Track> track = boost::dynamic_pointer_cast<Track> (_strip);
58 track->monitoring_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, bind (&OSCRouteObserver::send_monitor_status, this, track->monitoring_control()), OSC::instance());
59 send_monitor_status (track->monitoring_control());
62 boost::shared_ptr<AutomationControl> rec_controllable = _strip->rec_enable_control ();
63 if (rec_controllable) {
64 rec_controllable->Changed.connect (strip_connections, MISSING_INVALIDATOR, bind (&OSCRouteObserver::send_change_message, this, X_("/strip/recenable"), _strip->rec_enable_control()), OSC::instance());
65 send_change_message ("/strip/recenable", _strip->rec_enable_control());
67 boost::shared_ptr<AutomationControl> recsafe_controllable = _strip->rec_safe_control ();
68 if (rec_controllable) {
69 recsafe_controllable->Changed.connect (strip_connections, MISSING_INVALIDATOR, bind (&OSCRouteObserver::send_change_message, this, X_("/strip/record_safe"), _strip->rec_safe_control()), OSC::instance());
70 send_change_message ("/strip/record_safe", _strip->rec_safe_control());
72 _strip->presentation_info().PropertyChanged.connect (strip_connections, MISSING_INVALIDATOR, bind (&OSCRouteObserver::send_select_status, this, _1), OSC::instance());
73 send_select_status (ARDOUR::Properties::selected);
76 if (feedback[1]) { // level controls
78 _strip->gain_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, bind (&OSCRouteObserver::send_gain_message, this, X_("/strip/fader"), _strip->gain_control()), OSC::instance());
79 send_gain_message ("/strip/fader", _strip->gain_control());
81 _strip->gain_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, bind (&OSCRouteObserver::send_gain_message, this, X_("/strip/gain"), _strip->gain_control()), OSC::instance());
82 send_gain_message ("/strip/gain", _strip->gain_control());
85 boost::shared_ptr<Controllable> trim_controllable = boost::dynamic_pointer_cast<Controllable>(_strip->trim_control());
86 if (trim_controllable) {
87 trim_controllable->Changed.connect (strip_connections, MISSING_INVALIDATOR, bind (&OSCRouteObserver::send_trim_message, this, X_("/strip/trimdB"), _strip->trim_control()), OSC::instance());
88 send_trim_message ("/strip/trimdB", _strip->trim_control());
91 boost::shared_ptr<Controllable> pan_controllable = boost::dynamic_pointer_cast<Controllable>(_strip->pan_azimuth_control());
92 if (pan_controllable) {
93 pan_controllable->Changed.connect (strip_connections, MISSING_INVALIDATOR, bind (&OSCRouteObserver::send_change_message, this, X_("/strip/pan_stereo_position"), _strip->pan_azimuth_control()), OSC::instance());
94 send_change_message ("/strip/pan_stereo_position", _strip->pan_azimuth_control());
100 OSCRouteObserver::~OSCRouteObserver ()
103 strip_connections.drop_connections ();
104 // all strip buttons should be off and faders 0 and etc.
105 clear_strip ("/strip/expand", 0);
106 if (feedback[0]) { // buttons are separate feedback
107 lo_message msg = lo_message_new ();
108 // name is a string do it first
109 string path = "/strip/name";
111 path = set_path (path);
113 lo_message_add_int32 (msg, ssid);
115 lo_message_add_string (msg, " ");
117 lo_send_message (addr, path.c_str(), msg);
118 lo_message_free (msg);
119 clear_strip ("/strip/mute", 0);
120 clear_strip ("/strip/solo", 0);
121 clear_strip ("/strip/recenable", 0);
122 clear_strip ("/strip/record_safe", 0);
123 clear_strip ("/strip/monitor_input", 0);
124 clear_strip ("/strip/monitor_disk", 0);
125 clear_strip ("/strip/gui_select", 0);
126 clear_strip ("/strip/select", 0);
128 if (feedback[1]) { // level controls
130 clear_strip ("/strip/fader", 0);
132 clear_strip ("/strip/gain", -193);
134 clear_strip ("/strip/trimdB", 0);
135 clear_strip ("/strip/pan_stereo_position", 0.5);
138 clear_strip ("/strip/signal", 0);
142 clear_strip ("/strip/meter", 0);
144 clear_strip ("/strip/meter", -193);
146 }else if (feedback[8]) {
147 clear_strip ("/strip/meter", 0);
150 lo_address_free (addr);
154 OSCRouteObserver::tick ()
156 if (feedback[7] || feedback[8] || feedback[9]) { // meters enabled
157 // the only meter here is master
159 if (_strip->peak_meter()) {
160 now_meter = _strip->peak_meter()->meter_level(0, MeterMCP);
164 if (now_meter < -193) now_meter = -193;
165 if (_last_meter != now_meter) {
166 if (feedback[7] || feedback[8]) {
167 string path = "/strip/meter";
168 lo_message msg = lo_message_new ();
170 path = set_path (path);
172 lo_message_add_int32 (msg, ssid);
174 if (gainmode && feedback[7]) {
175 uint32_t lev1023 = (uint32_t)((now_meter + 54) * 17.05);
176 lo_message_add_int32 (msg, lev1023);
177 lo_send_message (addr, path.c_str(), msg);
178 } else if ((!gainmode) && feedback[7]) {
179 lo_message_add_float (msg, now_meter);
180 lo_send_message (addr, path.c_str(), msg);
181 } else if (feedback[8]) {
182 uint32_t ledlvl = (uint32_t)(((now_meter + 54) / 3.75)-1);
183 uint16_t ledbits = ~(0xfff<<ledlvl);
184 lo_message_add_int32 (msg, ledbits);
185 lo_send_message (addr, path.c_str(), msg);
187 lo_message_free (msg);
190 string path = "/strip/signal";
191 lo_message msg = lo_message_new ();
193 path = set_path (path);
195 lo_message_add_int32 (msg, ssid);
198 if (now_meter < -40) {
203 lo_message_add_float (msg, signal);
204 lo_send_message (addr, path.c_str(), msg);
205 lo_message_free (msg);
208 _last_meter = now_meter;
215 OSCRouteObserver::name_changed (const PBD::PropertyChange& what_changed)
217 if (!what_changed.contains (ARDOUR::Properties::name)) {
225 lo_message msg = lo_message_new ();
227 // ssid is the strip on the surface this observer refers to
228 // not part of the internal ordering.
229 string path = "/strip/name";
231 path = set_path (path);
233 lo_message_add_int32 (msg, ssid);
235 lo_message_add_string (msg, _strip->name().c_str());
237 lo_send_message (addr, path.c_str(), msg);
238 lo_message_free (msg);
242 OSCRouteObserver::send_change_message (string path, boost::shared_ptr<Controllable> controllable)
244 lo_message msg = lo_message_new ();
247 path = set_path (path);
249 lo_message_add_int32 (msg, ssid);
251 lo_message_add_float (msg, (float) controllable->get_value());
253 lo_send_message (addr, path.c_str(), msg);
254 lo_message_free (msg);
258 OSCRouteObserver::send_monitor_status (boost::shared_ptr<Controllable> controllable)
261 float val = controllable->get_value();
276 lo_message msg = lo_message_new ();
277 string path = "/strip/monitor_input";
279 path = set_path (path);
281 lo_message_add_int32 (msg, ssid);
283 lo_message_add_int32 (msg, (float) input);
284 lo_send_message (addr, path.c_str(), msg);
285 lo_message_free (msg);
287 msg = lo_message_new ();
288 path = "/strip/monitor_disk";
290 path = set_path (path);
292 lo_message_add_int32 (msg, ssid);
294 lo_message_add_int32 (msg, (float) disk);
295 lo_send_message (addr, path.c_str(), msg);
296 lo_message_free (msg);
301 OSCRouteObserver::send_trim_message (string path, boost::shared_ptr<Controllable> controllable)
303 lo_message msg = lo_message_new ();
306 path = set_path (path);
308 lo_message_add_int32 (msg, ssid);
311 lo_message_add_float (msg, (float) accurate_coefficient_to_dB (controllable->get_value()));
313 lo_send_message (addr, path.c_str(), msg);
314 lo_message_free (msg);
318 OSCRouteObserver::send_gain_message (string path, boost::shared_ptr<Controllable> controllable)
320 lo_message msg = lo_message_new ();
323 path = set_path (path);
325 lo_message_add_int32 (msg, ssid);
329 if (controllable->get_value() == 1) {
330 lo_message_add_int32 (msg, 800);
332 lo_message_add_int32 (msg, gain_to_slider_position (controllable->get_value()) * 1023);
335 if (controllable->get_value() < 1e-15) {
336 lo_message_add_float (msg, -200);
338 lo_message_add_float (msg, accurate_coefficient_to_dB (controllable->get_value()));
342 lo_send_message (addr, path.c_str(), msg);
343 lo_message_free (msg);
347 OSCRouteObserver::set_path (string path)
351 os << path << "/" << ssid;
358 OSCRouteObserver::clear_strip (string path, float val)
360 lo_message msg = lo_message_new ();
362 path = set_path (path);
364 lo_message_add_int32 (msg, ssid);
366 lo_message_add_float (msg, val);
368 lo_send_message (addr, path.c_str(), msg);
369 lo_message_free (msg);
374 OSCRouteObserver::send_select_status (const PropertyChange& what)
376 if (what == PropertyChange(ARDOUR::Properties::selected)) {
378 string path = "/strip/select";
380 lo_message msg = lo_message_new ();
382 path = set_path (path);
384 lo_message_add_int32 (msg, ssid);
386 lo_message_add_float (msg, _strip->is_selected());
387 lo_send_message (addr, path.c_str(), msg);
388 lo_message_free (msg);