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());
131 if (feedback[13]) { // Well known controls
132 // Rest of possible pan controls... Untested because I can't find a way to get them in the GUI :)
133 if (_strip->pan_elevation_control ()) {
134 _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());
135 change_message ("/select/pan_elevation_position", _strip->pan_elevation_control());
137 if (_strip->pan_frontback_control ()) {
138 _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());
139 change_message ("/select/pan_frontback_position", _strip->pan_frontback_control());
141 if (_strip->pan_lfe_control ()) {
142 _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());
143 change_message ("/select/pan_lfe_position", _strip->pan_lfe_control());
146 if (_strip->comp_enable_controllable ()) {
147 _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());
148 change_message ("/select/comp_enable", _strip->comp_enable_controllable());
150 if (_strip->comp_threshold_controllable ()) {
151 _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());
152 change_message ("/select/comp_threshold", _strip->comp_threshold_controllable());
154 if (_strip->comp_speed_controllable ()) {
155 _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());
156 change_message ("/select/comp_speed", _strip->comp_speed_controllable());
158 if (_strip->comp_mode_controllable ()) {
159 _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());
160 change_message ("/select/comp_mode", _strip->comp_mode_controllable());
161 text_message ("/select/comp_mode_name", _strip->comp_mode_name(_strip->comp_mode_controllable()->get_value()));
162 text_message ("/select/comp_speed_name", _strip->comp_speed_name(_strip->comp_mode_controllable()->get_value()));
164 if (_strip->comp_makeup_controllable ()) {
165 _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());
166 change_message ("/select/comp_makeup", _strip->comp_makeup_controllable());
168 if (_strip->comp_redux_controllable ()) {
169 _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());
170 change_message ("/select/comp_redux", _strip->comp_redux_controllable());
178 OSCSelectObserver::~OSCSelectObserver ()
181 strip_connections.drop_connections ();
182 // all strip buttons should be off and faders 0 and etc.
183 clear_strip ("/select/expand", 0);
184 if (feedback[0]) { // buttons are separate feedback
185 lo_message msg = lo_message_new ();
186 // name is a string do it first
187 lo_message_add_string (msg, " ");
188 lo_send_message (addr, "/select/name", msg);
189 lo_message_free (msg);
190 msg = lo_message_new ();
191 lo_message_add_string (msg, " ");
192 lo_send_message (addr, "/select/comment", msg);
193 lo_message_free (msg);
194 clear_strip ("/select/mute", 0);
195 clear_strip ("/select/solo", 0);
196 clear_strip ("/select/recenable", 0);
197 clear_strip ("/select/record_safe", 0);
198 clear_strip ("/select/monitor_input", 0);
199 clear_strip ("/select/monitor_disk", 0);
200 clear_strip ("/select/polarity", 0);
201 clear_strip ("/select/n_inputs", 0);
202 clear_strip ("/select/n_outputs", 0);
204 if (feedback[1]) { // level controls
206 clear_strip ("/select/fader", 0);
208 clear_strip ("/select/gain", -193);
210 clear_strip ("/select/trimdB", 0);
211 clear_strip ("/select/pan_stereo_position", 0.5);
212 clear_strip ("/select/pan_stereo_width", 1);
215 clear_strip ("/select/signal", 0);
219 clear_strip ("/select/meter", 0);
221 clear_strip ("/select/meter", -193);
223 }else if (feedback[8]) {
224 clear_strip ("/select/meter", 0);
228 lo_address_free (addr);
232 OSCSelectObserver::send_init()
234 // we don't know how many there are, so find out.
238 if (_strip->send_level_controllable (nsends)) {
239 _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());
240 send_gain (nsends, _strip->send_level_controllable(nsends));
244 if (_strip->send_enable_controllable (nsends)) {
245 _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());
246 send_enable ("/select/send_enable", nsends, _strip->send_enable_controllable(nsends));
249 // not used by Ardour, just mixbus so in Ardour always true
250 lo_message msg = lo_message_new ();
251 path = "/select/send_enable";
253 path = set_path (path, nsends + 1);
255 lo_message_add_int32 (msg, nsends + 1);
257 lo_message_add_int32 (msg, 1);
258 lo_send_message (addr, path.c_str(), msg);
259 lo_message_free (msg);
261 // this should get signalled by the route the send goes to, (TODO)
262 if (sends) { // if the gain control is there, this is too
263 send_name ("/select/send_name", nsends, _strip->send_name(nsends));
265 // Send numbers are 0 based, OSC is 1 based so this gets incremented at the end
273 OSCSelectObserver::send_end ()
275 send_connections.drop_connections ();
276 for (uint32_t i = 1; i <= nsends; i++) {
277 lo_message msg = lo_message_new ();
278 string path = "/select/send_gain";
280 path = set_path (path, i);
282 lo_message_add_int32 (msg, i);
286 lo_message_add_int32 (msg, 0);
288 lo_message_add_float (msg, -193);
290 lo_send_message (addr, path.c_str(), msg);
291 lo_message_free (msg);
293 msg = lo_message_new ();
294 path = "/select/send_enable";
296 path = set_path (path, i);
298 lo_message_add_int32 (msg, i);
300 lo_message_add_int32 (msg, 0);
301 lo_send_message (addr, path.c_str(), msg);
302 lo_message_free (msg);
304 msg = lo_message_new ();
305 path = "/select/send_name";
307 path = set_path (path, i);
309 lo_message_add_int32 (msg, i);
311 lo_message_add_string (msg, " ");
312 lo_send_message (addr, path.c_str(), msg);
313 lo_message_free (msg);
319 OSCSelectObserver::send_restart(int x)
326 OSCSelectObserver::tick ()
328 if (feedback[7] || feedback[8] || feedback[9]) { // meters enabled
330 if (_strip->peak_meter()) {
331 now_meter = _strip->peak_meter()->meter_level(0, MeterMCP);
335 if (now_meter < -193) now_meter = -193;
336 if (_last_meter != now_meter) {
337 if (feedback[7] || feedback[8]) {
338 string path = "/select/meter";
339 lo_message msg = lo_message_new ();
340 if (gainmode && feedback[7]) {
341 uint32_t lev1023 = (uint32_t)((now_meter + 54) * 17.05);
342 lo_message_add_int32 (msg, lev1023);
343 lo_send_message (addr, path.c_str(), msg);
344 } else if ((!gainmode) && feedback[7]) {
345 lo_message_add_float (msg, now_meter);
346 lo_send_message (addr, path.c_str(), msg);
347 } else if (feedback[8]) {
348 uint32_t ledlvl = (uint32_t)(((now_meter + 54) / 3.75)-1);
349 uint16_t ledbits = ~(0xfff<<ledlvl);
350 lo_message_add_int32 (msg, ledbits);
351 lo_send_message (addr, path.c_str(), msg);
353 lo_message_free (msg);
356 string path = "/select/signal";
357 lo_message msg = lo_message_new ();
359 if (now_meter < -40) {
364 lo_message_add_float (msg, signal);
365 lo_send_message (addr, path.c_str(), msg);
366 lo_message_free (msg);
369 _last_meter = now_meter;
376 OSCSelectObserver::name_changed (const PBD::PropertyChange& what_changed)
378 if (!what_changed.contains (ARDOUR::Properties::name)) {
386 lo_message msg = lo_message_new ();
388 string path = "/select/name";
389 lo_message_add_string (msg, _strip->name().c_str());
391 lo_send_message (addr, path.c_str(), msg);
392 lo_message_free (msg);
394 boost::shared_ptr<Route> route = boost::dynamic_pointer_cast<Route> (_strip);
396 //spit out the comment at the same time
397 msg = lo_message_new ();
398 path = "/select/comment";
399 lo_message_add_string (msg, route->comment().c_str());
400 lo_send_message (addr, path.c_str(), msg);
401 lo_message_free (msg);
403 // lets tell the surface how many inputs this strip has
404 msg = lo_message_new ();
405 path = "/select/n_inputs";
406 lo_message_add_int32 (msg, route->n_inputs().n_total());
407 lo_send_message (addr, path.c_str(), msg);
408 lo_message_free (msg);
409 // lets tell the surface how many outputs this strip has
410 msg = lo_message_new ();
411 path = "/select/n_outputs";
412 lo_message_add_int32 (msg, route->n_outputs().n_total());
413 lo_send_message (addr, path.c_str(), msg);
414 lo_message_free (msg);
420 OSCSelectObserver::change_message (string path, boost::shared_ptr<Controllable> controllable)
422 lo_message msg = lo_message_new ();
424 lo_message_add_float (msg, (float) controllable->get_value());
426 lo_send_message (addr, path.c_str(), msg);
427 lo_message_free (msg);
431 OSCSelectObserver::text_message (string path, std::string text)
433 lo_message msg = lo_message_new ();
435 lo_message_add_string (msg, text.c_str());
437 lo_send_message (addr, path.c_str(), msg);
438 lo_message_free (msg);
442 OSCSelectObserver::monitor_status (boost::shared_ptr<Controllable> controllable)
445 float val = controllable->get_value();
460 lo_message msg = lo_message_new ();
461 string path = "/select/monitor_input";
462 lo_message_add_int32 (msg, (float) input);
463 lo_send_message (addr, path.c_str(), msg);
464 lo_message_free (msg);
466 msg = lo_message_new ();
467 path = "/select/monitor_disk";
468 lo_message_add_int32 (msg, (float) disk);
469 lo_send_message (addr, path.c_str(), msg);
470 lo_message_free (msg);
475 OSCSelectObserver::trim_message (string path, boost::shared_ptr<Controllable> controllable)
477 lo_message msg = lo_message_new ();
479 lo_message_add_float (msg, (float) accurate_coefficient_to_dB (controllable->get_value()));
481 lo_send_message (addr, path.c_str(), msg);
482 lo_message_free (msg);
486 OSCSelectObserver::gain_message (string path, boost::shared_ptr<Controllable> controllable)
488 lo_message msg = lo_message_new ();
491 if (controllable->get_value() == 1) {
492 lo_message_add_int32 (msg, 800);
494 lo_message_add_int32 (msg, gain_to_slider_position (controllable->get_value()) * 1023);
497 if (controllable->get_value() < 1e-15) {
498 lo_message_add_float (msg, -200);
500 lo_message_add_float (msg, accurate_coefficient_to_dB (controllable->get_value()));
504 lo_send_message (addr, path.c_str(), msg);
505 lo_message_free (msg);
509 OSCSelectObserver::send_gain (uint32_t id, boost::shared_ptr<PBD::Controllable> controllable)
511 lo_message msg = lo_message_new ();
516 path = "/select/send_fader";
517 if (controllable->get_value() == 1) {
520 value = gain_to_slider_position (controllable->get_value());
523 path = "/select/send_gain";
524 if (controllable->get_value() < 1e-15) {
527 value = accurate_coefficient_to_dB (controllable->get_value());
532 path = set_path (path, id + 1);
534 lo_message_add_int32 (msg, id + 1);
537 lo_message_add_float (msg, value);
538 lo_send_message (addr, path.c_str(), msg);
539 lo_message_free (msg);
543 OSCSelectObserver::send_enable (string path, uint32_t id, boost::shared_ptr<Controllable> controllable)
545 lo_message msg = lo_message_new ();
547 path = set_path (path, id + 1);
549 lo_message_add_int32 (msg, id + 1);
552 lo_message_add_float (msg, (float) controllable->get_value());
554 lo_send_message (addr, path.c_str(), msg);
555 lo_message_free (msg);
559 OSCSelectObserver::send_name (string path, uint32_t id, string name)
561 lo_message msg = lo_message_new ();
563 path = set_path (path, id + 1);
565 lo_message_add_int32 (msg, id + 1);
568 lo_message_add_string (msg, name.c_str());
570 lo_send_message (addr, path.c_str(), msg);
571 lo_message_free (msg);
575 OSCSelectObserver::set_path (string path, uint32_t id)
579 os << path << "/" << id;
586 OSCSelectObserver::clear_strip (string path, float val)
588 lo_message msg = lo_message_new ();
589 lo_message_add_float (msg, val);
591 lo_send_message (addr, path.c_str(), msg);
592 lo_message_free (msg);