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"
30 #include "ardour/route.h"
33 #include "osc_select_observer.h"
39 using namespace ARDOUR;
40 using namespace ArdourSurface;
42 OSCSelectObserver::OSCSelectObserver (boost::shared_ptr<Stripable> s, lo_address a, uint32_t ss, uint32_t gm, std::bitset<32> fb)
49 addr = lo_address_new (lo_address_get_hostname(a) , lo_address_get_port(a));
51 if (feedback[0]) { // buttons are separate feedback
52 _strip->PropertyChanged.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::name_changed, this, boost::lambda::_1), OSC::instance());
53 name_changed (ARDOUR::Properties::name);
55 _strip->mute_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::change_message, this, X_("/select/mute"), _strip->mute_control()), OSC::instance());
56 change_message ("/select/mute", _strip->mute_control());
58 _strip->solo_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::change_message, this, X_("/select/solo"), _strip->solo_control()), OSC::instance());
59 change_message ("/select/solo", _strip->solo_control());
61 if (_strip->solo_isolate_control()) {
62 _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());
63 change_message ("/select/solo_iso", _strip->solo_isolate_control());
66 if (_strip->solo_safe_control()) {
67 _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());
68 change_message ("/select/solo_safe", _strip->solo_safe_control());
71 boost::shared_ptr<Track> track = boost::dynamic_pointer_cast<Track> (_strip);
73 track->monitoring_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::monitor_status, this, track->monitoring_control()), OSC::instance());
74 monitor_status (track->monitoring_control());
77 boost::shared_ptr<AutomationControl> rec_controllable = _strip->rec_enable_control ();
78 if (rec_controllable) {
79 rec_controllable->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::change_message, this, X_("/select/recenable"), _strip->rec_enable_control()), OSC::instance());
80 change_message ("/select/recenable", _strip->rec_enable_control());
83 boost::shared_ptr<AutomationControl> recsafe_controllable = _strip->rec_safe_control ();
84 if (recsafe_controllable) {
85 recsafe_controllable->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::change_message, this, X_("/select/record_safe"), _strip->rec_safe_control()), OSC::instance());
86 change_message ("/select/record_safe", _strip->rec_safe_control());
89 boost::shared_ptr<AutomationControl> phase_controllable = _strip->phase_control ();
90 if (phase_controllable) {
91 phase_controllable->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::change_message, this, X_("/select/polarity"), _strip->phase_control()), OSC::instance());
92 change_message ("/select/polarity", _strip->phase_control());
97 if (feedback[1]) { // level controls
99 _strip->gain_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::gain_message, this, X_("/select/fader"), _strip->gain_control()), OSC::instance());
100 gain_message ("/select/fader", _strip->gain_control());
102 _strip->gain_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::gain_message, this, X_("/select/gain"), _strip->gain_control()), OSC::instance());
103 gain_message ("/select/gain", _strip->gain_control());
106 boost::shared_ptr<Controllable> trim_controllable = boost::dynamic_pointer_cast<Controllable>(_strip->trim_control());
107 if (trim_controllable) {
108 trim_controllable->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::trim_message, this, X_("/select/trimdB"), _strip->trim_control()), OSC::instance());
109 trim_message ("/select/trimdB", _strip->trim_control());
112 boost::shared_ptr<Controllable> pan_controllable = boost::dynamic_pointer_cast<Controllable>(_strip->pan_azimuth_control());
113 if (pan_controllable) {
114 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());
115 change_message ("/select/pan_stereo_position", _strip->pan_azimuth_control());
118 boost::shared_ptr<Controllable> width_controllable = boost::dynamic_pointer_cast<Controllable>(_strip->pan_width_control());
119 if (width_controllable) {
120 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());
121 change_message ("/select/pan_stereo_width", _strip->pan_width_control());
124 // detecting processor changes requires cast to route
125 boost::shared_ptr<Route> r = boost::dynamic_pointer_cast<Route>(_strip);
127 r->processors_changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::send_restart, this, -1), OSC::instance());
135 OSCSelectObserver::~OSCSelectObserver ()
138 strip_connections.drop_connections ();
139 // all strip buttons should be off and faders 0 and etc.
140 if (feedback[0]) { // buttons are separate feedback
141 lo_message msg = lo_message_new ();
142 // name is a string do it first
143 lo_message_add_string (msg, " ");
144 lo_send_message (addr, "/select/name", msg);
145 lo_message_free (msg);
146 msg = lo_message_new ();
147 lo_message_add_string (msg, " ");
148 lo_send_message (addr, "/select/comment", msg);
149 lo_message_free (msg);
150 clear_strip ("/select/mute", 0);
151 clear_strip ("/select/solo", 0);
152 clear_strip ("/select/recenable", 0);
153 clear_strip ("/select/record_safe", 0);
154 clear_strip ("/select/monitor_input", 0);
155 clear_strip ("/select/monitor_disk", 0);
156 clear_strip ("/select/polarity", 0);
157 clear_strip ("/select/n_inputs", 0);
158 clear_strip ("/select/n_outputs", 0);
160 if (feedback[1]) { // level controls
162 clear_strip ("/select/fader", 0);
164 clear_strip ("/select/gain", -193);
166 clear_strip ("/select/trimdB", 0);
167 clear_strip ("/select/pan_stereo_position", 0.5);
168 clear_strip ("/select/pan_stereo_width", 1);
171 clear_strip ("/select/signal", 0);
175 clear_strip ("/select/meter", 0);
177 clear_strip ("/select/meter", -193);
179 }else if (feedback[8]) {
180 clear_strip ("/select/meter", 0);
184 lo_address_free (addr);
188 OSCSelectObserver::send_init()
190 // we don't know how many there are, so find out.
194 if (_strip->send_level_controllable (nsends)) {
195 _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());
196 send_gain (nsends, _strip->send_level_controllable(nsends));
200 if (_strip->send_enable_controllable (nsends)) {
201 _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());
202 send_enable ("/select/send_enable", nsends, _strip->send_enable_controllable(nsends));
205 // not used by Ardour, just mixbus so in Ardour always true
206 lo_message msg = lo_message_new ();
207 path = "/select/send_enable";
209 path = set_path (path, nsends + 1);
211 lo_message_add_int32 (msg, nsends + 1);
213 lo_message_add_int32 (msg, 1);
214 lo_send_message (addr, path.c_str(), msg);
215 lo_message_free (msg);
217 // this should get signalled by the route the send goes to, (TODO)
218 if (sends) { // if the gain control is there, this is too
219 send_name ("/select/send_name", nsends, _strip->send_name(nsends));
221 // Send numbers are 0 based, OSC is 1 based so this gets incremented at the end
229 OSCSelectObserver::send_end ()
231 send_connections.drop_connections ();
232 for (uint32_t i = 1; i <= nsends; i++) {
233 lo_message msg = lo_message_new ();
234 string path = "/select/send_gain";
236 path = set_path (path, i);
238 lo_message_add_int32 (msg, i);
242 lo_message_add_int32 (msg, 0);
244 lo_message_add_float (msg, -193);
246 lo_send_message (addr, path.c_str(), msg);
247 lo_message_free (msg);
249 msg = lo_message_new ();
250 path = "/select/send_enable";
252 path = set_path (path, i);
254 lo_message_add_int32 (msg, i);
256 lo_message_add_int32 (msg, 0);
257 lo_send_message (addr, path.c_str(), msg);
258 lo_message_free (msg);
260 msg = lo_message_new ();
261 path = "/select/send_name";
263 path = set_path (path, i);
265 lo_message_add_int32 (msg, i);
267 lo_message_add_string (msg, " ");
268 lo_send_message (addr, path.c_str(), msg);
269 lo_message_free (msg);
275 OSCSelectObserver::send_restart(int x)
282 OSCSelectObserver::tick ()
284 if (feedback[7] || feedback[8] || feedback[9]) { // meters enabled
286 if (_strip->peak_meter()) {
287 now_meter = _strip->peak_meter()->meter_level(0, MeterMCP);
291 if (now_meter < -193) now_meter = -193;
292 if (_last_meter != now_meter) {
293 if (feedback[7] || feedback[8]) {
294 string path = "/select/meter";
295 lo_message msg = lo_message_new ();
296 if (gainmode && feedback[7]) {
297 uint32_t lev1023 = (uint32_t)((now_meter + 54) * 17.05);
298 lo_message_add_int32 (msg, lev1023);
299 lo_send_message (addr, path.c_str(), msg);
300 } else if ((!gainmode) && feedback[7]) {
301 lo_message_add_float (msg, now_meter);
302 lo_send_message (addr, path.c_str(), msg);
303 } else if (feedback[8]) {
304 uint32_t ledlvl = (uint32_t)(((now_meter + 54) / 3.75)-1);
305 uint16_t ledbits = ~(0xfff<<ledlvl);
306 lo_message_add_int32 (msg, ledbits);
307 lo_send_message (addr, path.c_str(), msg);
309 lo_message_free (msg);
312 string path = "/select/signal";
313 lo_message msg = lo_message_new ();
315 if (now_meter < -40) {
320 lo_message_add_float (msg, signal);
321 lo_send_message (addr, path.c_str(), msg);
322 lo_message_free (msg);
325 _last_meter = now_meter;
332 OSCSelectObserver::name_changed (const PBD::PropertyChange& what_changed)
334 if (!what_changed.contains (ARDOUR::Properties::name)) {
342 lo_message msg = lo_message_new ();
344 string path = "/select/name";
345 lo_message_add_string (msg, _strip->name().c_str());
347 lo_send_message (addr, path.c_str(), msg);
348 lo_message_free (msg);
350 boost::shared_ptr<Route> route = boost::dynamic_pointer_cast<Route> (_strip);
352 //spit out the comment at the same time
353 msg = lo_message_new ();
354 path = "/select/comment";
355 lo_message_add_string (msg, route->comment().c_str());
356 lo_send_message (addr, path.c_str(), msg);
357 lo_message_free (msg);
359 // lets tell the surface how many inputs this strip has
360 msg = lo_message_new ();
361 path = "/select/n_inputs";
362 lo_message_add_int32 (msg, route->n_inputs().n_total());
363 lo_send_message (addr, path.c_str(), msg);
364 lo_message_free (msg);
365 // lets tell the surface how many outputs this strip has
366 msg = lo_message_new ();
367 path = "/select/n_outputs";
368 lo_message_add_int32 (msg, route->n_outputs().n_total());
369 lo_send_message (addr, path.c_str(), msg);
370 lo_message_free (msg);
376 OSCSelectObserver::change_message (string path, boost::shared_ptr<Controllable> controllable)
378 lo_message msg = lo_message_new ();
380 lo_message_add_float (msg, (float) controllable->get_value());
382 lo_send_message (addr, path.c_str(), msg);
383 lo_message_free (msg);
387 OSCSelectObserver::monitor_status (boost::shared_ptr<Controllable> controllable)
390 float val = controllable->get_value();
405 lo_message msg = lo_message_new ();
406 string path = "/select/monitor_input";
407 lo_message_add_int32 (msg, (float) input);
408 lo_send_message (addr, path.c_str(), msg);
409 lo_message_free (msg);
411 msg = lo_message_new ();
412 path = "/select/monitor_disk";
413 lo_message_add_int32 (msg, (float) disk);
414 lo_send_message (addr, path.c_str(), msg);
415 lo_message_free (msg);
420 OSCSelectObserver::trim_message (string path, boost::shared_ptr<Controllable> controllable)
422 lo_message msg = lo_message_new ();
424 lo_message_add_float (msg, (float) accurate_coefficient_to_dB (controllable->get_value()));
426 lo_send_message (addr, path.c_str(), msg);
427 lo_message_free (msg);
431 OSCSelectObserver::gain_message (string path, boost::shared_ptr<Controllable> controllable)
433 lo_message msg = lo_message_new ();
436 if (controllable->get_value() == 1) {
437 lo_message_add_int32 (msg, 800);
439 lo_message_add_int32 (msg, gain_to_slider_position (controllable->get_value()) * 1023);
442 if (controllable->get_value() < 1e-15) {
443 lo_message_add_float (msg, -200);
445 lo_message_add_float (msg, accurate_coefficient_to_dB (controllable->get_value()));
449 lo_send_message (addr, path.c_str(), msg);
450 lo_message_free (msg);
454 OSCSelectObserver::send_gain (uint32_t id, boost::shared_ptr<PBD::Controllable> controllable)
456 lo_message msg = lo_message_new ();
461 path = "/select/send_fader";
462 if (controllable->get_value() == 1) {
465 value = gain_to_slider_position (controllable->get_value());
468 path = "/select/send_gain";
469 if (controllable->get_value() < 1e-15) {
472 value = accurate_coefficient_to_dB (controllable->get_value());
477 path = set_path (path, id + 1);
479 lo_message_add_int32 (msg, id + 1);
482 lo_message_add_float (msg, value);
483 lo_send_message (addr, path.c_str(), msg);
484 lo_message_free (msg);
488 OSCSelectObserver::send_enable (string path, uint32_t id, boost::shared_ptr<Controllable> controllable)
490 lo_message msg = lo_message_new ();
492 path = set_path (path, id + 1);
494 lo_message_add_int32 (msg, id + 1);
497 lo_message_add_float (msg, (float) controllable->get_value());
499 lo_send_message (addr, path.c_str(), msg);
500 lo_message_free (msg);
504 OSCSelectObserver::send_name (string path, uint32_t id, string name)
506 lo_message msg = lo_message_new ();
508 path = set_path (path, id + 1);
510 lo_message_add_int32 (msg, id + 1);
513 lo_message_add_string (msg, name.c_str());
515 lo_send_message (addr, path.c_str(), msg);
516 lo_message_free (msg);
520 OSCSelectObserver::set_path (string path, uint32_t id)
524 os << path << "/" << id;
531 OSCSelectObserver::clear_strip (string path, float val)
533 lo_message msg = lo_message_new ();
534 lo_message_add_float (msg, val);
536 lo_send_message (addr, path.c_str(), msg);
537 lo_message_free (msg);