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 _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());
64 _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());
65 change_message ("/select/solo_safe", _strip->solo_safe_control());
67 boost::shared_ptr<Track> track = boost::dynamic_pointer_cast<Track> (_strip);
69 track->monitoring_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::monitor_status, this, track->monitoring_control()), OSC::instance());
70 monitor_status (track->monitoring_control());
73 boost::shared_ptr<AutomationControl> rec_controllable = _strip->rec_enable_control ();
74 if (rec_controllable) {
75 rec_controllable->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::change_message, this, X_("/select/recenable"), _strip->rec_enable_control()), OSC::instance());
76 change_message ("/select/recenable", _strip->rec_enable_control());
79 boost::shared_ptr<AutomationControl> recsafe_controllable = _strip->rec_safe_control ();
80 if (recsafe_controllable) {
81 recsafe_controllable->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::change_message, this, X_("/select/record_safe"), _strip->rec_safe_control()), OSC::instance());
82 change_message ("/select/record_safe", _strip->rec_safe_control());
85 boost::shared_ptr<AutomationControl> phase_controllable = _strip->phase_control ();
86 if (phase_controllable) {
87 phase_controllable->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::change_message, this, X_("/select/polarity"), _strip->phase_control()), OSC::instance());
88 change_message ("/select/polarity", _strip->phase_control());
93 if (feedback[1]) { // level controls
95 _strip->gain_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::gain_message, this, X_("/select/fader"), _strip->gain_control()), OSC::instance());
96 gain_message ("/select/fader", _strip->gain_control());
98 _strip->gain_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::gain_message, this, X_("/select/gain"), _strip->gain_control()), OSC::instance());
99 gain_message ("/select/gain", _strip->gain_control());
102 boost::shared_ptr<Controllable> trim_controllable = boost::dynamic_pointer_cast<Controllable>(_strip->trim_control());
103 if (trim_controllable) {
104 trim_controllable->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::trim_message, this, X_("/select/trimdB"), _strip->trim_control()), OSC::instance());
105 trim_message ("/select/trimdB", _strip->trim_control());
108 boost::shared_ptr<Controllable> pan_controllable = boost::dynamic_pointer_cast<Controllable>(_strip->pan_azimuth_control());
109 if (pan_controllable) {
110 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());
111 change_message ("/select/pan_stereo_position", _strip->pan_azimuth_control());
114 boost::shared_ptr<Controllable> width_controllable = boost::dynamic_pointer_cast<Controllable>(_strip->pan_width_control());
115 if (width_controllable) {
116 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());
117 change_message ("/select/pan_stereo_width", _strip->pan_width_control());
120 // detecting processor changes requires cast to route
121 boost::shared_ptr<Route> r = boost::dynamic_pointer_cast<Route>(_strip);
122 r->processors_changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::send_restart, this, -1), OSC::instance());
128 OSCSelectObserver::~OSCSelectObserver ()
131 strip_connections.drop_connections ();
132 // all strip buttons should be off and faders 0 and etc.
133 if (feedback[0]) { // buttons are separate feedback
134 lo_message msg = lo_message_new ();
135 // name is a string do it first
136 lo_message_add_string (msg, " ");
137 lo_send_message (addr, "/select/name", msg);
138 lo_message_free (msg);
139 msg = lo_message_new ();
140 lo_message_add_string (msg, " ");
141 lo_send_message (addr, "/select/comment", msg);
142 lo_message_free (msg);
143 clear_strip ("/select/mute", 0);
144 clear_strip ("/select/solo", 0);
145 clear_strip ("/select/recenable", 0);
146 clear_strip ("/select/record_safe", 0);
147 clear_strip ("/select/monitor_input", 0);
148 clear_strip ("/select/monitor_disk", 0);
149 clear_strip ("/select/polarity", 0);
150 clear_strip ("/select/n_inputs", 0);
151 clear_strip ("/select/n_outputs", 0);
153 if (feedback[1]) { // level controls
155 clear_strip ("/select/fader", 0);
157 clear_strip ("/select/gain", -193);
159 clear_strip ("/select/trimdB", 0);
160 clear_strip ("/select/pan_stereo_position", 0.5);
161 clear_strip ("/select/pan_stereo_width", 1);
164 clear_strip ("/select/signal", 0);
168 clear_strip ("/select/meter", 0);
170 clear_strip ("/select/meter", -193);
172 }else if (feedback[8]) {
173 clear_strip ("/select/meter", 0);
177 lo_address_free (addr);
181 OSCSelectObserver::send_init()
183 // we don't know how many there are, so find out.
187 if (_strip->send_level_controllable (nsends)) {
188 _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());
189 send_gain (nsends, _strip->send_level_controllable(nsends));
193 if (_strip->send_enable_controllable (nsends)) {
194 _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());
195 send_enable ("/select/send_enable", nsends, _strip->send_enable_controllable(nsends));
198 // not used by Ardour, just mixbus so in Ardour always true
199 lo_message msg = lo_message_new ();
200 path = "/select/send_enable";
202 path = set_path (path, nsends + 1);
204 lo_message_add_int32 (msg, nsends + 1);
206 lo_message_add_int32 (msg, 1);
207 lo_send_message (addr, path.c_str(), msg);
208 lo_message_free (msg);
210 // this should get signalled by the route the send goes to, (TODO)
211 if (sends) { // if the gain control is there, this is too
212 send_name ("/select/send_name", nsends, _strip->send_name(nsends));
214 // Send numbers are 0 based, OSC is 1 based so this gets incremented at the end
222 OSCSelectObserver::send_end ()
224 send_connections.drop_connections ();
225 for (uint32_t i = 1; i <= nsends; i++) {
226 lo_message msg = lo_message_new ();
227 string path = "/select/send_gain";
229 path = set_path (path, i);
231 lo_message_add_int32 (msg, i);
235 lo_message_add_int32 (msg, 0);
237 lo_message_add_float (msg, -193);
239 lo_send_message (addr, path.c_str(), msg);
240 lo_message_free (msg);
242 msg = lo_message_new ();
243 path = "/select/send_enable";
245 path = set_path (path, i);
247 lo_message_add_int32 (msg, i);
249 lo_message_add_int32 (msg, 0);
250 lo_send_message (addr, path.c_str(), msg);
251 lo_message_free (msg);
253 msg = lo_message_new ();
254 path = "/select/send_name";
256 path = set_path (path, i);
258 lo_message_add_int32 (msg, i);
260 lo_message_add_string (msg, " ");
261 lo_send_message (addr, path.c_str(), msg);
262 lo_message_free (msg);
268 OSCSelectObserver::send_restart(int x)
275 OSCSelectObserver::tick ()
277 if (feedback[7] || feedback[8] || feedback[9]) { // meters enabled
279 if (_strip->peak_meter()) {
280 now_meter = _strip->peak_meter()->meter_level(0, MeterMCP);
284 if (now_meter < -193) now_meter = -193;
285 if (_last_meter != now_meter) {
286 if (feedback[7] || feedback[8]) {
287 string path = "/select/meter";
288 lo_message msg = lo_message_new ();
289 if (gainmode && feedback[7]) {
290 uint32_t lev1023 = (uint32_t)((now_meter + 54) * 17.05);
291 lo_message_add_int32 (msg, lev1023);
292 lo_send_message (addr, path.c_str(), msg);
293 } else if ((!gainmode) && feedback[7]) {
294 lo_message_add_float (msg, now_meter);
295 lo_send_message (addr, path.c_str(), msg);
296 } else if (feedback[8]) {
297 uint32_t ledlvl = (uint32_t)(((now_meter + 54) / 3.75)-1);
298 uint16_t ledbits = ~(0xfff<<ledlvl);
299 lo_message_add_int32 (msg, ledbits);
300 lo_send_message (addr, path.c_str(), msg);
302 lo_message_free (msg);
305 string path = "/select/signal";
306 lo_message msg = lo_message_new ();
308 if (now_meter < -40) {
313 lo_message_add_float (msg, signal);
314 lo_send_message (addr, path.c_str(), msg);
315 lo_message_free (msg);
318 _last_meter = now_meter;
325 OSCSelectObserver::name_changed (const PBD::PropertyChange& what_changed)
327 if (!what_changed.contains (ARDOUR::Properties::name)) {
335 lo_message msg = lo_message_new ();
337 string path = "/select/name";
338 lo_message_add_string (msg, _strip->name().c_str());
340 lo_send_message (addr, path.c_str(), msg);
341 lo_message_free (msg);
343 //spit out the comment at the same time
344 msg = lo_message_new ();
345 path = "/select/comment";
346 boost::shared_ptr<Route> route = boost::dynamic_pointer_cast<Route> (_strip);
347 lo_message_add_string (msg, route->comment().c_str());
348 lo_send_message (addr, path.c_str(), msg);
349 lo_message_free (msg);
351 // lets tell the surface how many inputs this strip has
352 msg = lo_message_new ();
353 path = "/select/n_inputs";
354 lo_message_add_int32 (msg, route->n_inputs().n_total());
355 lo_send_message (addr, path.c_str(), msg);
356 lo_message_free (msg);
357 // lets tell the surface how many outputs this strip has
358 msg = lo_message_new ();
359 path = "/select/n_outputs";
360 lo_message_add_int32 (msg, route->n_outputs().n_total());
361 lo_send_message (addr, path.c_str(), msg);
362 lo_message_free (msg);
367 OSCSelectObserver::change_message (string path, boost::shared_ptr<Controllable> controllable)
369 lo_message msg = lo_message_new ();
371 lo_message_add_float (msg, (float) controllable->get_value());
373 lo_send_message (addr, path.c_str(), msg);
374 lo_message_free (msg);
378 OSCSelectObserver::monitor_status (boost::shared_ptr<Controllable> controllable)
381 float val = controllable->get_value();
396 lo_message msg = lo_message_new ();
397 string path = "/select/monitor_input";
398 lo_message_add_int32 (msg, (float) input);
399 lo_send_message (addr, path.c_str(), msg);
400 lo_message_free (msg);
402 msg = lo_message_new ();
403 path = "/select/monitor_disk";
404 lo_message_add_int32 (msg, (float) disk);
405 lo_send_message (addr, path.c_str(), msg);
406 lo_message_free (msg);
411 OSCSelectObserver::trim_message (string path, boost::shared_ptr<Controllable> controllable)
413 lo_message msg = lo_message_new ();
415 lo_message_add_float (msg, (float) accurate_coefficient_to_dB (controllable->get_value()));
417 lo_send_message (addr, path.c_str(), msg);
418 lo_message_free (msg);
422 OSCSelectObserver::gain_message (string path, boost::shared_ptr<Controllable> controllable)
424 lo_message msg = lo_message_new ();
427 if (controllable->get_value() == 1) {
428 lo_message_add_int32 (msg, 800);
430 lo_message_add_int32 (msg, gain_to_slider_position (controllable->get_value()) * 1023);
433 if (controllable->get_value() < 1e-15) {
434 lo_message_add_float (msg, -200);
436 lo_message_add_float (msg, accurate_coefficient_to_dB (controllable->get_value()));
440 lo_send_message (addr, path.c_str(), msg);
441 lo_message_free (msg);
445 OSCSelectObserver::send_gain (uint32_t id, boost::shared_ptr<PBD::Controllable> controllable)
447 lo_message msg = lo_message_new ();
452 path = "/select/send_fader";
453 if (controllable->get_value() == 1) {
456 value = gain_to_slider_position (controllable->get_value());
459 path = "/select/send_gain";
460 if (controllable->get_value() < 1e-15) {
463 value = accurate_coefficient_to_dB (controllable->get_value());
468 path = set_path (path, id + 1);
470 lo_message_add_int32 (msg, id + 1);
473 lo_message_add_float (msg, value);
474 lo_send_message (addr, path.c_str(), msg);
475 lo_message_free (msg);
479 OSCSelectObserver::send_enable (string path, uint32_t id, boost::shared_ptr<Controllable> controllable)
481 lo_message msg = lo_message_new ();
483 path = set_path (path, id + 1);
485 lo_message_add_int32 (msg, id + 1);
488 lo_message_add_float (msg, (float) controllable->get_value());
490 lo_send_message (addr, path.c_str(), msg);
491 lo_message_free (msg);
495 OSCSelectObserver::send_name (string path, uint32_t id, string name)
497 lo_message msg = lo_message_new ();
499 path = set_path (path, id + 1);
501 lo_message_add_int32 (msg, id + 1);
504 lo_message_add_string (msg, name.c_str());
506 lo_send_message (addr, path.c_str(), msg);
507 lo_message_free (msg);
511 OSCSelectObserver::set_path (string path, uint32_t id)
515 os << path << "/" << id;
522 OSCSelectObserver::clear_strip (string path, float val)
524 lo_message msg = lo_message_new ();
525 lo_message_add_float (msg, val);
527 lo_send_message (addr, path.c_str(), msg);
528 lo_message_free (msg);