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 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 if (_strip->solo_isolate_control()) {
61 _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());
62 change_message ("/select/solo_iso", _strip->solo_isolate_control());
65 if (_strip->solo_safe_control()) {
66 _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());
67 change_message ("/select/solo_safe", _strip->solo_safe_control());
70 boost::shared_ptr<Track> track = boost::dynamic_pointer_cast<Track> (_strip);
72 track->monitoring_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::monitor_status, this, track->monitoring_control()), OSC::instance());
73 monitor_status (track->monitoring_control());
76 boost::shared_ptr<AutomationControl> rec_controllable = _strip->rec_enable_control ();
77 if (rec_controllable) {
78 rec_controllable->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::change_message, this, X_("/select/recenable"), _strip->rec_enable_control()), OSC::instance());
79 change_message ("/select/recenable", _strip->rec_enable_control());
82 boost::shared_ptr<AutomationControl> recsafe_controllable = _strip->rec_safe_control ();
83 if (recsafe_controllable) {
84 recsafe_controllable->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::change_message, this, X_("/select/record_safe"), _strip->rec_safe_control()), OSC::instance());
85 change_message ("/select/record_safe", _strip->rec_safe_control());
88 boost::shared_ptr<AutomationControl> phase_controllable = _strip->phase_control ();
89 if (phase_controllable) {
90 phase_controllable->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::change_message, this, X_("/select/polarity"), _strip->phase_control()), OSC::instance());
91 change_message ("/select/polarity", _strip->phase_control());
96 if (feedback[1]) { // level controls
98 _strip->gain_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::gain_message, this, X_("/select/fader"), _strip->gain_control()), OSC::instance());
99 gain_message ("/select/fader", _strip->gain_control());
101 _strip->gain_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::gain_message, this, X_("/select/gain"), _strip->gain_control()), OSC::instance());
102 gain_message ("/select/gain", _strip->gain_control());
105 boost::shared_ptr<Controllable> trim_controllable = boost::dynamic_pointer_cast<Controllable>(_strip->trim_control());
106 if (trim_controllable) {
107 trim_controllable->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::trim_message, this, X_("/select/trimdB"), _strip->trim_control()), OSC::instance());
108 trim_message ("/select/trimdB", _strip->trim_control());
111 boost::shared_ptr<Controllable> pan_controllable = boost::dynamic_pointer_cast<Controllable>(_strip->pan_azimuth_control());
112 if (pan_controllable) {
113 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());
114 change_message ("/select/pan_stereo_position", _strip->pan_azimuth_control());
117 boost::shared_ptr<Controllable> width_controllable = boost::dynamic_pointer_cast<Controllable>(_strip->pan_width_control());
118 if (width_controllable) {
119 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());
120 change_message ("/select/pan_stereo_width", _strip->pan_width_control());
123 // detecting processor changes requires cast to route
124 boost::shared_ptr<Route> r = boost::dynamic_pointer_cast<Route>(_strip);
126 r->processors_changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::send_restart, this, -1), OSC::instance());
132 if (feedback[13]) { // Well known controls
133 // Rest of possible pan controls... Untested because I can't find a way to get them in the GUI :)
134 if (_strip->pan_elevation_control ()) {
135 _strip->pan_elevation_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::change_message, this, X_("/select/pan_elevation_position"), _strip->pan_elevation_control()), OSC::instance());
136 change_message ("/select/pan_elevation_position", _strip->pan_elevation_control());
138 if (_strip->pan_frontback_control ()) {
139 _strip->pan_frontback_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::change_message, this, X_("/select/pan_frontback_position"), _strip->pan_frontback_control()), OSC::instance());
140 change_message ("/select/pan_frontback_position", _strip->pan_frontback_control());
142 if (_strip->pan_lfe_control ()) {
143 _strip->pan_lfe_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::change_message, this, X_("/select/pan_lfe_control"), _strip->pan_lfe_control()), OSC::instance());
144 change_message ("/select/pan_lfe_control", _strip->pan_lfe_control());
147 if (_strip->comp_enable_controllable ()) {
148 _strip->comp_enable_controllable ()->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::change_message, this, X_("/select/comp_enable"), _strip->comp_enable_controllable()), OSC::instance());
149 change_message ("/select/comp_enable", _strip->comp_enable_controllable());
151 if (_strip->comp_threshold_controllable ()) {
152 _strip->comp_threshold_controllable ()->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::change_message, this, X_("/select/comp_threshold"), _strip->comp_threshold_controllable()), OSC::instance());
153 change_message ("/select/comp_threshold", _strip->comp_threshold_controllable());
155 if (_strip->comp_speed_controllable ()) {
156 _strip->comp_speed_controllable ()->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::change_message, this, X_("/select/comp_speed"), _strip->comp_speed_controllable()), OSC::instance());
157 change_message ("/select/comp_speed", _strip->comp_speed_controllable());
159 if (_strip->comp_mode_controllable ()) {
160 _strip->comp_mode_controllable ()->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::comp_mode, this), OSC::instance());
163 if (_strip->comp_makeup_controllable ()) {
164 _strip->comp_makeup_controllable ()->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::change_message, this, X_("/select/comp_makeup"), _strip->comp_makeup_controllable()), OSC::instance());
165 change_message ("/select/comp_makeup", _strip->comp_makeup_controllable());
173 OSCSelectObserver::~OSCSelectObserver ()
176 strip_connections.drop_connections ();
177 // all strip buttons should be off and faders 0 and etc.
178 clear_strip ("/select/expand", 0);
179 if (feedback[0]) { // buttons are separate feedback
180 text_message ("/select/name", " ");
181 text_message ("/select/comment", " ");
182 clear_strip ("/select/mute", 0);
183 clear_strip ("/select/solo", 0);
184 clear_strip ("/select/recenable", 0);
185 clear_strip ("/select/record_safe", 0);
186 clear_strip ("/select/monitor_input", 0);
187 clear_strip ("/select/monitor_disk", 0);
188 clear_strip ("/select/polarity", 0);
189 clear_strip ("/select/n_inputs", 0);
190 clear_strip ("/select/n_outputs", 0);
192 if (feedback[1]) { // level controls
194 clear_strip ("/select/fader", 0);
196 clear_strip ("/select/gain", -193);
198 clear_strip ("/select/trimdB", 0);
199 clear_strip ("/select/pan_stereo_position", 0.5);
200 clear_strip ("/select/pan_stereo_width", 1);
203 clear_strip ("/select/signal", 0);
207 clear_strip ("/select/meter", 0);
209 clear_strip ("/select/meter", -193);
211 }else if (feedback[8]) {
212 clear_strip ("/select/meter", 0);
214 if (feedback[13]) { // Well known controls
215 clear_strip ("/select/pan_elevation_position", 0);
216 clear_strip ("/select/pan_frontback_position", .5);
217 clear_strip ("/select/pan_lfe_control", 0);
218 clear_strip ("/select/comp_enable", 0);
219 clear_strip ("/select/comp_threshold", 0);
220 clear_strip ("/select/comp_speed", 0);
221 clear_strip ("/select/comp_mode", 0);
222 text_message ("/select/comp_mode_name", " ");
223 text_message ("/select/comp_speed_name", " ");
224 clear_strip ("/select/comp_makeup", 0);
229 lo_address_free (addr);
233 OSCSelectObserver::send_init()
235 // we don't know how many there are, so find out.
239 if (_strip->send_level_controllable (nsends)) {
240 _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());
241 send_gain (nsends, _strip->send_level_controllable(nsends));
245 if (_strip->send_enable_controllable (nsends)) {
246 _strip->send_enable_controllable(nsends)->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::change_message_with_id, this, X_("/select/send_enable"), nsends + 1, _strip->send_enable_controllable(nsends)), OSC::instance());
247 change_message_with_id ("/select/send_enable", nsends + 1, _strip->send_enable_controllable(nsends));
250 // not used by Ardour, just mixbus so in Ardour always true
251 clear_strip_with_id ("/select/send_enable", nsends + 1, 1);
253 // this should get signalled by the route the send goes to, (TODO)
254 if (sends) { // if the gain control is there, this is too
255 text_with_id ("/select/send_name", nsends + 1, _strip->send_name(nsends));
257 // Send numbers are 0 based, OSC is 1 based so this gets incremented at the end
265 OSCSelectObserver::send_end ()
267 send_connections.drop_connections ();
268 for (uint32_t i = 1; i <= nsends; i++) {
270 clear_strip_with_id ("/select/send_fader", i, 0);
272 clear_strip_with_id ("/select/send_gain", i, -193);
275 clear_strip_with_id ("/select/send_enable", i, 0);
277 text_with_id ("/select/send_name", i, " ");
283 OSCSelectObserver::send_restart(int x)
290 OSCSelectObserver::tick ()
292 if (feedback[7] || feedback[8] || feedback[9]) { // meters enabled
294 if (_strip->peak_meter()) {
295 now_meter = _strip->peak_meter()->meter_level(0, MeterMCP);
299 if (now_meter < -144) now_meter = -193;
300 if (_last_meter != now_meter) {
301 if (feedback[7] || feedback[8]) {
302 string path = "/select/meter";
303 lo_message msg = lo_message_new ();
304 if (gainmode && feedback[7]) {
305 lo_message_add_float (msg, ((now_meter + 94) / 100));
306 lo_send_message (addr, path.c_str(), msg);
307 } else if ((!gainmode) && feedback[7]) {
308 lo_message_add_float (msg, now_meter);
309 lo_send_message (addr, path.c_str(), msg);
310 } else if (feedback[8]) {
311 uint32_t ledlvl = (uint32_t)(((now_meter + 54) / 3.75)-1);
312 uint16_t ledbits = ~(0xfff<<ledlvl);
313 lo_message_add_int32 (msg, ledbits);
314 lo_send_message (addr, path.c_str(), msg);
316 lo_message_free (msg);
319 string path = "/select/signal";
320 lo_message msg = lo_message_new ();
322 if (now_meter < -40) {
327 lo_message_add_float (msg, signal);
328 lo_send_message (addr, path.c_str(), msg);
329 lo_message_free (msg);
332 _last_meter = now_meter;
339 OSCSelectObserver::name_changed (const PBD::PropertyChange& what_changed)
341 if (!what_changed.contains (ARDOUR::Properties::name)) {
349 text_message ("/select/name", _strip->name());
350 boost::shared_ptr<Route> route = boost::dynamic_pointer_cast<Route> (_strip);
352 //spit out the comment at the same time
353 text_message ("/select/comment", route->comment());
354 // lets tell the surface how many inputs this strip has
355 clear_strip ("/select/n_inputs", (float) route->n_inputs().n_total());
356 // lets tell the surface how many outputs this strip has
357 clear_strip ("/select/n_outputs", (float) route->n_outputs().n_total());
362 OSCSelectObserver::change_message (string path, boost::shared_ptr<Controllable> controllable)
364 lo_message msg = lo_message_new ();
365 float val = controllable->get_value();
367 lo_message_add_float (msg, (float) controllable->internal_to_interface (val));
369 lo_send_message (addr, path.c_str(), msg);
370 lo_message_free (msg);
374 OSCSelectObserver::change_message_with_id (string path, uint32_t id, boost::shared_ptr<Controllable> controllable)
376 lo_message msg = lo_message_new ();
377 float val = controllable->get_value();
379 path = set_path (path, id);
381 lo_message_add_int32 (msg, id);
384 lo_message_add_float (msg, (float) controllable->internal_to_interface (val));
386 lo_send_message (addr, path.c_str(), msg);
387 lo_message_free (msg);
391 OSCSelectObserver::text_message (string path, std::string text)
393 lo_message msg = lo_message_new ();
395 lo_message_add_string (msg, text.c_str());
397 lo_send_message (addr, path.c_str(), msg);
398 lo_message_free (msg);
402 OSCSelectObserver::monitor_status (boost::shared_ptr<Controllable> controllable)
405 float val = controllable->get_value();
420 clear_strip ("/select/monitor_input", (float) input);
421 clear_strip ("/select/monitor_disk", (float) disk);
425 OSCSelectObserver::trim_message (string path, boost::shared_ptr<Controllable> controllable)
427 lo_message msg = lo_message_new ();
429 lo_message_add_float (msg, (float) accurate_coefficient_to_dB (controllable->get_value()));
431 lo_send_message (addr, path.c_str(), msg);
432 lo_message_free (msg);
436 OSCSelectObserver::gain_message (string path, boost::shared_ptr<Controllable> controllable)
438 lo_message msg = lo_message_new ();
441 lo_message_add_float (msg, gain_to_slider_position (controllable->get_value()));
443 if (controllable->get_value() < 1e-15) {
444 lo_message_add_float (msg, -200);
446 lo_message_add_float (msg, accurate_coefficient_to_dB (controllable->get_value()));
450 lo_send_message (addr, path.c_str(), msg);
451 lo_message_free (msg);
455 OSCSelectObserver::send_gain (uint32_t id, boost::shared_ptr<PBD::Controllable> controllable)
457 lo_message msg = lo_message_new ();
462 path = "/select/send_fader";
464 value = controllable->internal_to_interface (controllable->get_value());
466 value = gain_to_slider_position (controllable->get_value());
469 path = "/select/send_gain";
471 value = controllable->get_value();
473 if (controllable->get_value() < 1e-15) {
476 value = accurate_coefficient_to_dB (controllable->get_value());
482 path = set_path (path, id + 1);
484 lo_message_add_int32 (msg, id + 1);
487 lo_message_add_float (msg, value);
488 lo_send_message (addr, path.c_str(), msg);
489 lo_message_free (msg);
493 OSCSelectObserver::text_with_id (string path, uint32_t id, string name)
495 lo_message msg = lo_message_new ();
497 path = set_path (path, id);
499 lo_message_add_int32 (msg, id);
502 lo_message_add_string (msg, name.c_str());
504 lo_send_message (addr, path.c_str(), msg);
505 lo_message_free (msg);
509 OSCSelectObserver::comp_mode ()
511 change_message ("/select/comp_mode", _strip->comp_mode_controllable());
512 text_message ("/select/comp_mode_name", _strip->comp_mode_name(_strip->comp_mode_controllable()->get_value()));
513 text_message ("/select/comp_speed_name", _strip->comp_speed_name(_strip->comp_mode_controllable()->get_value()));
517 OSCSelectObserver::eq_init()
519 // HPF and enable are special case, rest are in bands
520 if (_strip->eq_hpf_controllable ()) {
521 _strip->eq_hpf_controllable ()->Changed.connect (eq_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::change_message, this, X_("/select/eq_hpf"), _strip->eq_hpf_controllable()), OSC::instance());
522 change_message ("/select/eq_hpf", _strip->eq_hpf_controllable());
524 if (_strip->eq_enable_controllable ()) {
525 _strip->eq_enable_controllable ()->Changed.connect (eq_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::change_message, this, X_("/select/eq_enable"), _strip->eq_enable_controllable()), OSC::instance());
526 change_message ("/select/eq_enable", _strip->eq_enable_controllable());
529 uint32_t eq_bands = _strip->eq_band_cnt ();
534 for (uint32_t i = 0; i < eq_bands; i++) {
535 if (_strip->eq_band_name(i).size()) {
536 text_with_id ("/select/eq_band_name", i + 1, _strip->eq_band_name (i));
538 if (_strip->eq_gain_controllable (i)) {
539 _strip->eq_gain_controllable(i)->Changed.connect (eq_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::change_message_with_id, this, X_("/select/eq_gain"), i, _strip->eq_gain_controllable(i)), OSC::instance());
540 change_message_with_id ("/select/eq_gain", i + 1, _strip->eq_gain_controllable(i));
542 if (_strip->eq_freq_controllable (i)) {
543 _strip->eq_freq_controllable(i)->Changed.connect (eq_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::change_message_with_id, this, X_("/select/eq_freq"), i, _strip->eq_freq_controllable(i)), OSC::instance());
544 change_message_with_id ("/select/eq_freq", i + 1, _strip->eq_freq_controllable(i));
546 if (_strip->eq_q_controllable (i)) {
547 _strip->eq_q_controllable(i)->Changed.connect (eq_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::change_message_with_id, this, X_("/select/eq_q"), i, _strip->eq_q_controllable(i)), OSC::instance());
548 change_message_with_id ("/select/eq_q", i + 1, _strip->eq_q_controllable(i));
550 if (_strip->eq_shape_controllable (i)) {
551 _strip->eq_shape_controllable(i)->Changed.connect (eq_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::change_message_with_id, this, X_("/select/eq_shape"), i, _strip->eq_shape_controllable(i)), OSC::instance());
552 change_message_with_id ("/select/eq_shape", i + 1, _strip->eq_shape_controllable(i));
558 OSCSelectObserver::eq_end ()
560 //need to check feedback for [13]
561 eq_connections.drop_connections ();
562 clear_strip ("/select/eq_hpf", 0);
563 clear_strip ("/select/eq_enable", 0);
565 for (uint32_t i = 1; i <= _strip->eq_band_cnt (); i++) {
566 text_with_id ("/select/eq_band_name", i, " ");
567 clear_strip_with_id ("/select/eq_gain", i, 0);
568 clear_strip_with_id ("/select/eq_freq", i, 0);
569 clear_strip_with_id ("/select/eq_q", i, 0);
570 clear_strip_with_id ("/select/eq_shape", i, 0);
577 OSCSelectObserver::eq_restart(int x)
584 OSCSelectObserver::set_path (string path, uint32_t id)
588 os << path << "/" << id;
595 OSCSelectObserver::clear_strip (string path, float val)
597 lo_message msg = lo_message_new ();
598 lo_message_add_float (msg, val);
600 lo_send_message (addr, path.c_str(), msg);
601 lo_message_free (msg);
606 OSCSelectObserver::clear_strip_with_id (string path, uint32_t id, float val)
608 lo_message msg = lo_message_new ();
610 path = set_path (path, id);
612 lo_message_add_int32 (msg, id);
615 lo_message_add_float (msg, val);
617 lo_send_message (addr, path.c_str(), msg);
618 lo_message_free (msg);