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 string path = "/select/name";
137 lo_message_add_string (msg, " ");
138 lo_send_message (addr, path.c_str(), msg);
139 lo_message_free (msg);
140 clear_strip ("/select/mute", 0);
141 clear_strip ("/select/solo", 0);
142 clear_strip ("/select/recenable", 0);
143 clear_strip ("/select/record_safe", 0);
144 clear_strip ("/select/monitor_input", 0);
145 clear_strip ("/select/monitor_disk", 0);
146 clear_strip ("/select/polarity", 0);
148 if (feedback[1]) { // level controls
150 clear_strip ("/select/fader", 0);
152 clear_strip ("/select/gain", -193);
154 clear_strip ("/select/trimdB", 0);
155 clear_strip ("/select/pan_stereo_position", 0.5);
156 clear_strip ("/select/pan_stereo_width", 1);
159 clear_strip ("/select/signal", 0);
163 clear_strip ("/select/meter", 0);
165 clear_strip ("/select/meter", -193);
167 }else if (feedback[8]) {
168 clear_strip ("/select/meter", 0);
172 lo_address_free (addr);
176 OSCSelectObserver::send_init()
178 // we don't know how many there are, so find out.
182 if (_strip->send_level_controllable (nsends)) {
183 _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());
184 send_gain (nsends, _strip->send_level_controllable(nsends));
188 if (_strip->send_enable_controllable (nsends)) {
189 _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());
190 send_enable ("/select/send_enable", nsends, _strip->send_enable_controllable(nsends));
193 // not used by Ardour, just mixbus so in Ardour always true
194 lo_message msg = lo_message_new ();
195 path = "/select/send_enable";
197 path = set_path (path, nsends + 1);
199 lo_message_add_int32 (msg, nsends + 1);
201 lo_message_add_int32 (msg, 1);
202 lo_send_message (addr, path.c_str(), msg);
203 lo_message_free (msg);
205 // this should get signalled by the route the send goes to, (TODO)
206 if (sends) { // if the gain control is there, this is too
207 send_name ("/select/send_name", nsends, _strip->send_name(nsends));
209 // Send numbers are 0 based, OSC is 1 based so this gets incremented at the end
217 OSCSelectObserver::send_end ()
219 send_connections.drop_connections ();
220 for (uint32_t i = 1; i <= nsends; i++) {
221 lo_message msg = lo_message_new ();
222 string path = "/select/send_gain";
224 path = set_path (path, i);
226 lo_message_add_int32 (msg, i);
230 lo_message_add_int32 (msg, 0);
232 lo_message_add_float (msg, -193);
234 lo_send_message (addr, path.c_str(), msg);
235 lo_message_free (msg);
237 msg = lo_message_new ();
238 path = "/select/send_enable";
240 path = set_path (path, i);
242 lo_message_add_int32 (msg, i);
244 lo_message_add_int32 (msg, 0);
245 lo_send_message (addr, path.c_str(), msg);
246 lo_message_free (msg);
248 msg = lo_message_new ();
249 path = "/select/send_name";
251 path = set_path (path, i);
253 lo_message_add_int32 (msg, i);
255 lo_message_add_string (msg, " ");
256 lo_send_message (addr, path.c_str(), msg);
257 lo_message_free (msg);
263 OSCSelectObserver::send_restart(int x)
270 OSCSelectObserver::tick ()
272 if (feedback[7] || feedback[8] || feedback[9]) { // meters enabled
274 float now_meter = _strip->peak_meter()->meter_level(0, MeterMCP);
275 if (now_meter < -193) now_meter = -193;
276 if (_last_meter != now_meter) {
277 if (feedback[7] || feedback[8]) {
278 string path = "/select/meter";
279 lo_message msg = lo_message_new ();
280 if (gainmode && feedback[7]) {
281 uint32_t lev1023 = (uint32_t)((now_meter + 54) * 17.05);
282 lo_message_add_int32 (msg, lev1023);
283 lo_send_message (addr, path.c_str(), msg);
284 } else if ((!gainmode) && feedback[7]) {
285 lo_message_add_float (msg, now_meter);
286 lo_send_message (addr, path.c_str(), msg);
287 } else if (feedback[8]) {
288 uint32_t ledlvl = (uint32_t)(((now_meter + 54) / 3.75)-1);
289 uint16_t ledbits = ~(0xfff<<ledlvl);
290 lo_message_add_int32 (msg, ledbits);
291 lo_send_message (addr, path.c_str(), msg);
293 lo_message_free (msg);
296 string path = "/select/signal";
297 lo_message msg = lo_message_new ();
299 if (now_meter < -40) {
304 lo_message_add_float (msg, signal);
305 lo_send_message (addr, path.c_str(), msg);
306 lo_message_free (msg);
309 _last_meter = now_meter;
316 OSCSelectObserver::name_changed (const PBD::PropertyChange& what_changed)
318 if (!what_changed.contains (ARDOUR::Properties::name)) {
326 lo_message msg = lo_message_new ();
328 string path = "/select/name";
329 lo_message_add_string (msg, _strip->name().c_str());
331 lo_send_message (addr, path.c_str(), msg);
332 lo_message_free (msg);
334 //spit out the comment at the same time
335 msg = lo_message_new ();
336 path = "/select/comment";
337 boost::shared_ptr<Route> route = boost::dynamic_pointer_cast<Route> (_strip);
338 lo_message_add_string (msg, route->comment().c_str());
339 lo_send_message (addr, path.c_str(), msg);
340 lo_message_free (msg);
342 // lets tell the surface how many inputs this strip has
343 msg = lo_message_new ();
344 path = "/select/n_inputs";
345 lo_message_add_int32 (msg, route->n_inputs().n_total());
346 lo_send_message (addr, path.c_str(), msg);
347 lo_message_free (msg);
348 // lets tell the surface how many outputs this strip has
349 msg = lo_message_new ();
350 path = "/select/n_outputs";
351 lo_message_add_int32 (msg, route->n_outputs().n_total());
352 lo_send_message (addr, path.c_str(), msg);
353 lo_message_free (msg);
358 OSCSelectObserver::change_message (string path, boost::shared_ptr<Controllable> controllable)
360 lo_message msg = lo_message_new ();
362 lo_message_add_float (msg, (float) controllable->get_value());
364 lo_send_message (addr, path.c_str(), msg);
365 lo_message_free (msg);
369 OSCSelectObserver::monitor_status (boost::shared_ptr<Controllable> controllable)
372 float val = controllable->get_value();
387 lo_message msg = lo_message_new ();
388 string path = "/select/monitor_input";
389 lo_message_add_int32 (msg, (float) input);
390 lo_send_message (addr, path.c_str(), msg);
391 lo_message_free (msg);
393 msg = lo_message_new ();
394 path = "/select/monitor_disk";
395 lo_message_add_int32 (msg, (float) disk);
396 lo_send_message (addr, path.c_str(), msg);
397 lo_message_free (msg);
402 OSCSelectObserver::trim_message (string path, boost::shared_ptr<Controllable> controllable)
404 lo_message msg = lo_message_new ();
406 lo_message_add_float (msg, (float) accurate_coefficient_to_dB (controllable->get_value()));
408 lo_send_message (addr, path.c_str(), msg);
409 lo_message_free (msg);
413 OSCSelectObserver::gain_message (string path, boost::shared_ptr<Controllable> controllable)
415 lo_message msg = lo_message_new ();
418 if (controllable->get_value() == 1) {
419 lo_message_add_int32 (msg, 800);
421 lo_message_add_int32 (msg, gain_to_slider_position (controllable->get_value()) * 1023);
424 if (controllable->get_value() < 1e-15) {
425 lo_message_add_float (msg, -200);
427 lo_message_add_float (msg, accurate_coefficient_to_dB (controllable->get_value()));
431 lo_send_message (addr, path.c_str(), msg);
432 lo_message_free (msg);
436 OSCSelectObserver::send_gain (uint32_t id, boost::shared_ptr<PBD::Controllable> controllable)
438 lo_message msg = lo_message_new ();
443 path = "/select/send_fader";
444 if (controllable->get_value() == 1) {
447 value = gain_to_slider_position (controllable->get_value());
450 path = "/select/send_gain";
451 if (controllable->get_value() < 1e-15) {
454 value = accurate_coefficient_to_dB (controllable->get_value());
459 path = set_path (path, id + 1);
461 lo_message_add_int32 (msg, id + 1);
464 lo_message_add_float (msg, value);
465 lo_send_message (addr, path.c_str(), msg);
466 lo_message_free (msg);
470 OSCSelectObserver::send_enable (string path, uint32_t id, boost::shared_ptr<Controllable> controllable)
472 lo_message msg = lo_message_new ();
474 path = set_path (path, id + 1);
476 lo_message_add_int32 (msg, id + 1);
479 lo_message_add_float (msg, (float) controllable->get_value());
481 lo_send_message (addr, path.c_str(), msg);
482 lo_message_free (msg);
486 OSCSelectObserver::send_name (string path, uint32_t id, string name)
488 lo_message msg = lo_message_new ();
490 path = set_path (path, id + 1);
492 lo_message_add_int32 (msg, id + 1);
495 lo_message_add_string (msg, name.c_str());
497 lo_send_message (addr, path.c_str(), msg);
498 lo_message_free (msg);
502 OSCSelectObserver::set_path (string path, uint32_t id)
506 os << path << "/" << id;
513 OSCSelectObserver::clear_strip (string path, float val)
515 lo_message msg = lo_message_new ();
516 lo_message_add_float (msg, val);
518 lo_send_message (addr, path.c_str(), msg);
519 lo_message_free (msg);