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"
27 #include "ardour/phase_control.h"
28 #include "ardour/solo_isolate_control.h"
29 #include "ardour/solo_safe_control.h"
32 #include "osc_select_observer.h"
38 using namespace ARDOUR;
39 using namespace ArdourSurface;
41 OSCSelectObserver::OSCSelectObserver (boost::shared_ptr<Stripable> s, lo_address a, uint32_t ss, uint32_t gm, std::bitset<32> fb)
48 addr = lo_address_new (lo_address_get_hostname(a) , lo_address_get_port(a));
50 if (feedback[0]) { // buttons are separate feedback
51 _strip->PropertyChanged.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::name_changed, this, boost::lambda::_1), OSC::instance());
52 name_changed (ARDOUR::Properties::name);
54 _strip->mute_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::change_message, this, X_("/select/mute"), _strip->mute_control()), OSC::instance());
55 change_message ("/select/mute", _strip->mute_control());
57 _strip->solo_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::change_message, this, X_("/select/solo"), _strip->solo_control()), OSC::instance());
58 change_message ("/select/solo", _strip->solo_control());
60 _strip->solo_isolate_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::change_message, this, X_("/select/solo_iso"), _strip->solo_isolate_control()), OSC::instance());
61 change_message ("/select/solo_iso", _strip->solo_isolate_control());
63 _strip->solo_safe_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::change_message, this, X_("/select/solo_safe"), _strip->solo_safe_control()), OSC::instance());
64 change_message ("/select/solo_safe", _strip->solo_safe_control());
66 boost::shared_ptr<Track> track = boost::dynamic_pointer_cast<Track> (_strip);
68 track->monitoring_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::monitor_status, this, track->monitoring_control()), OSC::instance());
69 monitor_status (track->monitoring_control());
72 boost::shared_ptr<AutomationControl> rec_controllable = _strip->rec_enable_control ();
73 if (rec_controllable) {
74 rec_controllable->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::change_message, this, X_("/select/recenable"), _strip->rec_enable_control()), OSC::instance());
75 change_message ("/select/recenable", _strip->rec_enable_control());
78 boost::shared_ptr<AutomationControl> recsafe_controllable = _strip->rec_safe_control ();
79 if (recsafe_controllable) {
80 recsafe_controllable->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::change_message, this, X_("/select/record_safe"), _strip->rec_safe_control()), OSC::instance());
81 change_message ("/select/record_safe", _strip->rec_safe_control());
84 boost::shared_ptr<AutomationControl> phase_controllable = _strip->phase_control ();
85 if (phase_controllable) {
86 phase_controllable->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::change_message, this, X_("/select/polarity"), _strip->phase_control()), OSC::instance());
87 change_message ("/select/polarity", _strip->phase_control());
92 if (feedback[1]) { // level controls
94 _strip->gain_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::gain_message, this, X_("/select/fader"), _strip->gain_control()), OSC::instance());
95 gain_message ("/select/fader", _strip->gain_control());
97 _strip->gain_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::gain_message, this, X_("/select/gain"), _strip->gain_control()), OSC::instance());
98 gain_message ("/select/gain", _strip->gain_control());
101 boost::shared_ptr<Controllable> trim_controllable = boost::dynamic_pointer_cast<Controllable>(_strip->trim_control());
102 if (trim_controllable) {
103 trim_controllable->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::trim_message, this, X_("/select/trimdB"), _strip->trim_control()), OSC::instance());
104 trim_message ("/select/trimdB", _strip->trim_control());
107 boost::shared_ptr<Controllable> pan_controllable = boost::dynamic_pointer_cast<Controllable>(_strip->pan_azimuth_control());
108 if (pan_controllable) {
109 pan_controllable->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::change_message, this, X_("/select/pan_stereo_position"), _strip->pan_azimuth_control()), OSC::instance());
110 change_message ("/select/pan_stereo_position", _strip->pan_azimuth_control());
113 boost::shared_ptr<Controllable> width_controllable = boost::dynamic_pointer_cast<Controllable>(_strip->pan_width_control());
114 if (width_controllable) {
115 width_controllable->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::change_message, this, X_("/select/pan_stereo_width"), _strip->pan_width_control()), OSC::instance());
116 change_message ("/select/pan_stereo_width", _strip->pan_width_control());
119 // detecting processor changes requires cast to route
120 boost::shared_ptr<Route> r = boost::dynamic_pointer_cast<Route>(_strip);
121 r->processors_changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::send_restart, this, -1), OSC::instance());
127 OSCSelectObserver::~OSCSelectObserver ()
130 strip_connections.drop_connections ();
131 // all strip buttons should be off and faders 0 and etc.
132 if (feedback[0]) { // buttons are separate feedback
133 lo_message msg = lo_message_new ();
134 // name is a string do it first
135 string path = "/select/name";
136 lo_message_add_string (msg, " ");
137 lo_send_message (addr, path.c_str(), msg);
138 lo_message_free (msg);
139 clear_strip ("/select/mute", 0);
140 clear_strip ("/select/solo", 0);
141 clear_strip ("/select/recenable", 0);
142 clear_strip ("/select/record_safe", 0);
143 clear_strip ("/select/monitor_input", 0);
144 clear_strip ("/select/monitor_disk", 0);
145 clear_strip ("/select/polarity", 0);
147 if (feedback[1]) { // level controls
149 clear_strip ("/select/fader", 0);
151 clear_strip ("/select/gain", -193);
153 clear_strip ("/select/trimdB", 0);
154 clear_strip ("/select/pan_stereo_position", 0.5);
155 clear_strip ("/select/pan_stereo_width", 1);
158 clear_strip ("/select/signal", 0);
162 clear_strip ("/select/meter", 0);
164 clear_strip ("/select/meter", -193);
166 }else if (feedback[8]) {
167 clear_strip ("/select/meter", 0);
171 lo_address_free (addr);
175 OSCSelectObserver::send_init()
177 // we don't know how many there are, so find out.
181 if (_strip->send_level_controllable (nsends)) {
182 _strip->send_level_controllable(nsends)->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::send_gain, this, nsends, _strip->send_level_controllable(nsends)), OSC::instance());
183 send_gain (nsends, _strip->send_level_controllable(nsends));
187 if (_strip->send_enable_controllable (nsends)) {
188 _strip->send_enable_controllable(nsends)->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::send_enable, this, X_("/select/send_enable"), nsends, _strip->send_enable_controllable(nsends)), OSC::instance());
189 send_enable ("/select/send_enable", nsends, _strip->send_enable_controllable(nsends));
192 // not used by Ardour, just mixbus so in Ardour always true
193 lo_message msg = lo_message_new ();
194 path = "/select/send_enable";
196 path = set_path (path, nsends + 1);
198 lo_message_add_int32 (msg, nsends + 1);
200 lo_message_add_int32 (msg, 1);
201 lo_send_message (addr, path.c_str(), msg);
202 lo_message_free (msg);
204 // this should get signalled by the route the send goes to, (TODO)
205 if (sends) { // if the gain control is there, this is too
206 send_name ("/select/send_name", nsends, _strip->send_name(nsends));
208 // Send numbers are 0 based, OSC is 1 based so this gets incremented at the end
216 OSCSelectObserver::send_end ()
218 send_connections.drop_connections ();
219 for (uint32_t i = 1; i <= nsends; i++) {
220 lo_message msg = lo_message_new ();
221 string path = "/select/send_gain";
223 path = set_path (path, i);
225 lo_message_add_int32 (msg, i);
229 lo_message_add_int32 (msg, 0);
231 lo_message_add_float (msg, -193);
233 lo_send_message (addr, path.c_str(), msg);
234 lo_message_free (msg);
236 msg = lo_message_new ();
237 path = "/select/send_enable";
239 path = set_path (path, i);
241 lo_message_add_int32 (msg, i);
243 lo_message_add_int32 (msg, 0);
244 lo_send_message (addr, path.c_str(), msg);
245 lo_message_free (msg);
247 msg = lo_message_new ();
248 path = "/select/send_name";
250 path = set_path (path, i);
252 lo_message_add_int32 (msg, i);
254 lo_message_add_string (msg, " ");
255 lo_send_message (addr, path.c_str(), msg);
256 lo_message_free (msg);
262 OSCSelectObserver::send_restart(int x)
269 OSCSelectObserver::tick ()
271 if (feedback[7] || feedback[8] || feedback[9]) { // meters enabled
273 float now_meter = _strip->peak_meter()->meter_level(0, MeterMCP);
274 if (now_meter < -193) now_meter = -193;
275 if (_last_meter != now_meter) {
276 if (feedback[7] || feedback[8]) {
277 string path = "/select/meter";
278 lo_message msg = lo_message_new ();
279 if (gainmode && feedback[7]) {
280 uint32_t lev1023 = (uint32_t)((now_meter + 54) * 17.05);
281 lo_message_add_int32 (msg, lev1023);
282 lo_send_message (addr, path.c_str(), msg);
283 } else if ((!gainmode) && feedback[7]) {
284 lo_message_add_float (msg, now_meter);
285 lo_send_message (addr, path.c_str(), msg);
286 } else if (feedback[8]) {
287 uint32_t ledlvl = (uint32_t)(((now_meter + 54) / 3.75)-1);
288 uint16_t ledbits = ~(0xfff<<ledlvl);
289 lo_message_add_int32 (msg, ledbits);
290 lo_send_message (addr, path.c_str(), msg);
292 lo_message_free (msg);
295 string path = "/select/signal";
296 lo_message msg = lo_message_new ();
298 if (now_meter < -40) {
303 lo_message_add_float (msg, signal);
304 lo_send_message (addr, path.c_str(), msg);
305 lo_message_free (msg);
308 _last_meter = now_meter;
315 OSCSelectObserver::name_changed (const PBD::PropertyChange& what_changed)
317 if (!what_changed.contains (ARDOUR::Properties::name)) {
325 lo_message msg = lo_message_new ();
327 // ssid is the strip on the surface this observer refers to
328 // not part of the internal ordering.
329 string path = "/select/name";
331 path = set_path (path);
333 lo_message_add_int32 (msg, ssid);
335 lo_message_add_string (msg, _strip->name().c_str());
337 lo_send_message (addr, path.c_str(), msg);
338 lo_message_free (msg);
342 OSCSelectObserver::change_message (string path, boost::shared_ptr<Controllable> controllable)
344 lo_message msg = lo_message_new ();
346 lo_message_add_float (msg, (float) controllable->get_value());
348 lo_send_message (addr, path.c_str(), msg);
349 lo_message_free (msg);
353 OSCSelectObserver::monitor_status (boost::shared_ptr<Controllable> controllable)
356 float val = controllable->get_value();
371 lo_message msg = lo_message_new ();
372 string path = "/select/monitor_input";
373 lo_message_add_int32 (msg, (float) input);
374 lo_send_message (addr, path.c_str(), msg);
375 lo_message_free (msg);
377 msg = lo_message_new ();
378 path = "/select/monitor_disk";
379 lo_message_add_int32 (msg, (float) disk);
380 lo_send_message (addr, path.c_str(), msg);
381 lo_message_free (msg);
386 OSCSelectObserver::trim_message (string path, boost::shared_ptr<Controllable> controllable)
388 lo_message msg = lo_message_new ();
390 lo_message_add_float (msg, (float) accurate_coefficient_to_dB (controllable->get_value()));
392 lo_send_message (addr, path.c_str(), msg);
393 lo_message_free (msg);
397 OSCSelectObserver::gain_message (string path, boost::shared_ptr<Controllable> controllable)
399 lo_message msg = lo_message_new ();
402 if (controllable->get_value() == 1) {
403 lo_message_add_int32 (msg, 800);
405 lo_message_add_int32 (msg, gain_to_slider_position (controllable->get_value()) * 1023);
408 if (controllable->get_value() < 1e-15) {
409 lo_message_add_float (msg, -200);
411 lo_message_add_float (msg, accurate_coefficient_to_dB (controllable->get_value()));
415 lo_send_message (addr, path.c_str(), msg);
416 lo_message_free (msg);
420 OSCSelectObserver::send_gain (uint32_t id, boost::shared_ptr<PBD::Controllable> controllable)
422 lo_message msg = lo_message_new ();
427 path = "/select/send_fader";
428 if (controllable->get_value() == 1) {
431 value = gain_to_slider_position (controllable->get_value());
434 path = "/select/send_gain";
435 if (controllable->get_value() < 1e-15) {
438 value = accurate_coefficient_to_dB (controllable->get_value());
443 path = set_path (path, id + 1);
445 lo_message_add_int32 (msg, id + 1);
448 lo_message_add_float (msg, value);
449 lo_send_message (addr, path.c_str(), msg);
450 lo_message_free (msg);
454 OSCSelectObserver::send_enable (string path, uint32_t id, boost::shared_ptr<Controllable> controllable)
456 lo_message msg = lo_message_new ();
458 path = set_path (path, id + 1);
460 lo_message_add_int32 (msg, id + 1);
463 lo_message_add_float (msg, (float) controllable->get_value());
465 lo_send_message (addr, path.c_str(), msg);
466 lo_message_free (msg);
470 OSCSelectObserver::send_name (string path, uint32_t id, string name)
472 lo_message msg = lo_message_new ();
474 path = set_path (path, id + 1);
476 lo_message_add_int32 (msg, id + 1);
479 lo_message_add_string (msg, name.c_str());
481 lo_send_message (addr, path.c_str(), msg);
482 lo_message_free (msg);
486 OSCSelectObserver::set_path (string path, uint32_t id)
490 os << path << "/" << id;
497 OSCSelectObserver::clear_strip (string path, float val)
499 lo_message msg = lo_message_new ();
500 lo_message_add_float (msg, val);
502 lo_send_message (addr, path.c_str(), msg);
503 lo_message_free (msg);