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_position"), _strip->pan_lfe_control()), OSC::instance());
144 change_message ("/select/pan_lfe_position", _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::change_message, this, X_("/select/comp_mode"), _strip->comp_mode_controllable()), OSC::instance());
161 change_message ("/select/comp_mode", _strip->comp_mode_controllable());
162 text_message ("/select/comp_mode_name", _strip->comp_mode_name(_strip->comp_mode_controllable()->get_value()));
163 text_message ("/select/comp_speed_name", _strip->comp_speed_name(_strip->comp_mode_controllable()->get_value()));
165 if (_strip->comp_makeup_controllable ()) {
166 _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());
167 change_message ("/select/comp_makeup", _strip->comp_makeup_controllable());
169 if (_strip->comp_redux_controllable ()) {
170 _strip->comp_redux_controllable ()->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::change_message, this, X_("/select/comp_redux"), _strip->comp_redux_controllable()), OSC::instance());
171 change_message ("/select/comp_redux", _strip->comp_redux_controllable());
179 OSCSelectObserver::~OSCSelectObserver ()
182 strip_connections.drop_connections ();
183 // all strip buttons should be off and faders 0 and etc.
184 clear_strip ("/select/expand", 0);
185 if (feedback[0]) { // buttons are separate feedback
186 text_message ("/select/name", " ");
187 text_message ("/select/comment", " ");
188 clear_strip ("/select/mute", 0);
189 clear_strip ("/select/solo", 0);
190 clear_strip ("/select/recenable", 0);
191 clear_strip ("/select/record_safe", 0);
192 clear_strip ("/select/monitor_input", 0);
193 clear_strip ("/select/monitor_disk", 0);
194 clear_strip ("/select/polarity", 0);
195 clear_strip ("/select/n_inputs", 0);
196 clear_strip ("/select/n_outputs", 0);
198 if (feedback[1]) { // level controls
200 clear_strip ("/select/fader", 0);
202 clear_strip ("/select/gain", -193);
204 clear_strip ("/select/trimdB", 0);
205 clear_strip ("/select/pan_stereo_position", 0.5);
206 clear_strip ("/select/pan_stereo_width", 1);
209 clear_strip ("/select/signal", 0);
213 clear_strip ("/select/meter", 0);
215 clear_strip ("/select/meter", -193);
217 }else if (feedback[8]) {
218 clear_strip ("/select/meter", 0);
220 if (feedback[13]) { // Well known controls
221 clear_strip ("/select/pan_elevation_position", .5);
222 clear_strip ("/select/pan_frontback_position", .5);
223 clear_strip ("/select/pan_lfe_position", 0);
224 clear_strip ("/select/comp_enable", 0);
225 clear_strip ("/select/comp_threshold", 0);
226 clear_strip ("/select/comp_speed", 0);
227 clear_strip ("/select/comp_mode", 0);
228 text_message ("/select/comp_mode_name", " ");
229 text_message ("/select/comp_speed_name", " ");
230 clear_strip ("/select/comp_makeup", 0);
231 clear_strip ("/select/comp_redux", 0);
236 lo_address_free (addr);
240 OSCSelectObserver::send_init()
242 // we don't know how many there are, so find out.
246 if (_strip->send_level_controllable (nsends)) {
247 _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());
248 send_gain (nsends, _strip->send_level_controllable(nsends));
252 if (_strip->send_enable_controllable (nsends)) {
253 _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());
254 change_message_with_id ("/select/send_enable", nsends + 1, _strip->send_enable_controllable(nsends));
257 // not used by Ardour, just mixbus so in Ardour always true
258 clear_strip_with_id ("/select/send_enable", nsends + 1, 1);
260 // this should get signalled by the route the send goes to, (TODO)
261 if (sends) { // if the gain control is there, this is too
262 text_with_id ("/select/send_name", nsends + 1, _strip->send_name(nsends));
264 // Send numbers are 0 based, OSC is 1 based so this gets incremented at the end
272 OSCSelectObserver::send_end ()
274 send_connections.drop_connections ();
275 for (uint32_t i = 1; i <= nsends; i++) {
277 clear_strip_with_id ("/select/send_fader", i, 0);
279 clear_strip_with_id ("/select/send_gain", i, -193);
282 clear_strip_with_id ("/select/send_enable", i, 0);
284 text_with_id ("/select/send_name", i, " ");
290 OSCSelectObserver::send_restart(int x)
297 OSCSelectObserver::tick ()
299 if (feedback[7] || feedback[8] || feedback[9]) { // meters enabled
301 if (_strip->peak_meter()) {
302 now_meter = _strip->peak_meter()->meter_level(0, MeterMCP);
306 if (now_meter < -193) now_meter = -193;
307 if (_last_meter != now_meter) {
308 if (feedback[7] || feedback[8]) {
309 string path = "/select/meter";
310 lo_message msg = lo_message_new ();
311 if (gainmode && feedback[7]) {
312 uint32_t lev1023 = (uint32_t)((now_meter + 54) * 17.05);
313 lo_message_add_int32 (msg, lev1023);
314 lo_send_message (addr, path.c_str(), msg);
315 } else if ((!gainmode) && feedback[7]) {
316 lo_message_add_float (msg, now_meter);
317 lo_send_message (addr, path.c_str(), msg);
318 } else if (feedback[8]) {
319 uint32_t ledlvl = (uint32_t)(((now_meter + 54) / 3.75)-1);
320 uint16_t ledbits = ~(0xfff<<ledlvl);
321 lo_message_add_int32 (msg, ledbits);
322 lo_send_message (addr, path.c_str(), msg);
324 lo_message_free (msg);
327 string path = "/select/signal";
328 lo_message msg = lo_message_new ();
330 if (now_meter < -40) {
335 lo_message_add_float (msg, signal);
336 lo_send_message (addr, path.c_str(), msg);
337 lo_message_free (msg);
340 _last_meter = now_meter;
347 OSCSelectObserver::name_changed (const PBD::PropertyChange& what_changed)
349 if (!what_changed.contains (ARDOUR::Properties::name)) {
357 text_message ("/select/name", _strip->name());
358 boost::shared_ptr<Route> route = boost::dynamic_pointer_cast<Route> (_strip);
360 //spit out the comment at the same time
361 text_message ("/select/comment", route->comment());
362 // lets tell the surface how many inputs this strip has
363 clear_strip ("/select/n_inputs", (float) route->n_inputs().n_total());
364 // lets tell the surface how many outputs this strip has
365 clear_strip ("/select/n_outputs", (float) route->n_outputs().n_total());
370 OSCSelectObserver::change_message (string path, boost::shared_ptr<Controllable> controllable)
372 lo_message msg = lo_message_new ();
373 float val = controllable->get_value();
375 lo_message_add_float (msg, (float) controllable->internal_to_interface (val));
377 lo_send_message (addr, path.c_str(), msg);
378 lo_message_free (msg);
382 OSCSelectObserver::change_message_with_id (string path, uint32_t id, boost::shared_ptr<Controllable> controllable)
384 lo_message msg = lo_message_new ();
385 float val = controllable->get_value();
387 path = set_path (path, id);
389 lo_message_add_int32 (msg, id);
392 lo_message_add_float (msg, (float) controllable->internal_to_interface (val));
394 lo_send_message (addr, path.c_str(), msg);
395 lo_message_free (msg);
399 OSCSelectObserver::text_message (string path, std::string text)
401 lo_message msg = lo_message_new ();
403 lo_message_add_string (msg, text.c_str());
405 lo_send_message (addr, path.c_str(), msg);
406 lo_message_free (msg);
410 OSCSelectObserver::monitor_status (boost::shared_ptr<Controllable> controllable)
413 float val = controllable->get_value();
428 clear_strip ("/select/monitor_input", (float) input);
429 clear_strip ("/select/monitor_disk", (float) disk);
433 OSCSelectObserver::trim_message (string path, boost::shared_ptr<Controllable> controllable)
435 lo_message msg = lo_message_new ();
437 lo_message_add_float (msg, (float) accurate_coefficient_to_dB (controllable->get_value()));
439 lo_send_message (addr, path.c_str(), msg);
440 lo_message_free (msg);
444 OSCSelectObserver::gain_message (string path, boost::shared_ptr<Controllable> controllable)
446 lo_message msg = lo_message_new ();
449 if (controllable->get_value() == 1) {
450 lo_message_add_int32 (msg, 800);
452 lo_message_add_int32 (msg, gain_to_slider_position (controllable->get_value()) * 1023);
455 if (controllable->get_value() < 1e-15) {
456 lo_message_add_float (msg, -200);
458 lo_message_add_float (msg, accurate_coefficient_to_dB (controllable->get_value()));
462 lo_send_message (addr, path.c_str(), msg);
463 lo_message_free (msg);
467 OSCSelectObserver::send_gain (uint32_t id, boost::shared_ptr<PBD::Controllable> controllable)
469 lo_message msg = lo_message_new ();
474 path = "/select/send_fader";
475 if (controllable->get_value() == 1) {
478 value = gain_to_slider_position (controllable->get_value());
481 path = "/select/send_gain";
482 if (controllable->get_value() < 1e-15) {
485 value = accurate_coefficient_to_dB (controllable->get_value());
490 path = set_path (path, id + 1);
492 lo_message_add_int32 (msg, id + 1);
495 lo_message_add_float (msg, value);
496 lo_send_message (addr, path.c_str(), msg);
497 lo_message_free (msg);
501 OSCSelectObserver::text_with_id (string path, uint32_t id, string name)
503 lo_message msg = lo_message_new ();
505 path = set_path (path, id);
507 lo_message_add_int32 (msg, id);
510 lo_message_add_string (msg, name.c_str());
512 lo_send_message (addr, path.c_str(), msg);
513 lo_message_free (msg);
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 eq_connections.drop_connections ();
561 clear_strip ("/select/eq_hpf", 0);
562 clear_strip ("/select/eq_enable", 0);
564 for (uint32_t i = 1; i <= _strip->eq_band_cnt (); i++) {
565 text_with_id ("/select/eq_band_name", i, " ");
566 clear_strip_with_id ("/select/eq_gain", i, 0);
567 clear_strip_with_id ("/select/eq_freq", i, 0);
568 clear_strip_with_id ("/select/eq_q", i, 0);
569 clear_strip_with_id ("/select/eq_shape", i, 0);
576 OSCSelectObserver::eq_restart(int x)
583 OSCSelectObserver::set_path (string path, uint32_t id)
587 os << path << "/" << id;
594 OSCSelectObserver::clear_strip (string path, float val)
596 lo_message msg = lo_message_new ();
597 lo_message_add_float (msg, val);
599 lo_send_message (addr, path.c_str(), msg);
600 lo_message_free (msg);
605 OSCSelectObserver::clear_strip_with_id (string path, uint32_t id, float val)
607 lo_message msg = lo_message_new ();
609 path = set_path (path, id);
611 lo_message_add_int32 (msg, id);
614 lo_message_add_float (msg, val);
616 lo_send_message (addr, path.c_str(), msg);
617 lo_message_free (msg);