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 "pbd/control_math.h"
26 #include "ardour/session.h"
27 #include "ardour/track.h"
28 #include "ardour/monitor_control.h"
29 #include "ardour/dB.h"
30 #include "ardour/meter.h"
31 #include "ardour/panner.h"
32 #include "ardour/panner_shell.h"
33 #include "ardour/pannable.h"
34 #include "ardour/route.h"
35 #include "ardour/route_group.h"
36 #include "ardour/send.h"
37 #include "ardour/solo_isolate_control.h"
40 #include "osc_route_observer.h"
46 using namespace ARDOUR;
47 using namespace ArdourSurface;
49 OSCRouteObserver::OSCRouteObserver (OSC& o, uint32_t ss, ArdourSurface::OSC::OSCSurface* su)
58 addr = lo_address_new_from_url (sur->remote_url.c_str());
59 gainmode = sur->gainmode;
60 feedback = sur->feedback;
61 in_line = feedback[2];
62 uint32_t sid = sur->bank + ssid - 2;
63 uint32_t not_ready = 0;
65 not_ready = _osc.link_sets[sur->linkset].not_ready;
68 set_link_ready (not_ready);
69 } else if (sid >= sur->strips.size ()) {
70 // this _should_ only occure if the number of strips is less than banksize
71 _strip = boost::shared_ptr<ARDOUR::Stripable>();
74 _strip = sur->strips[sid];
75 refresh_strip (_strip, true);
77 if (sur->expand_enable) {
78 set_expand (sur->expand);
82 _send = boost::shared_ptr<ARDOUR::Send> ();
85 OSCRouteObserver::~OSCRouteObserver ()
88 strip_connections.drop_connections ();
90 lo_address_free (addr);
94 OSCRouteObserver::no_strip ()
96 // This gets called on drop references
99 strip_connections.drop_connections ();
100 _gain_control = boost::shared_ptr<ARDOUR::GainControl> ();
101 _send = boost::shared_ptr<ARDOUR::Send> ();
102 _strip = boost::shared_ptr<Stripable> ();
104 * The strip will sit idle at this point doing nothing until
105 * the surface has recalculated it's strip list and then calls
106 * refresh_strip. Otherwise refresh strip will get a strip address
107 * that does not exist... Crash
112 OSCRouteObserver::refresh_strip (boost::shared_ptr<ARDOUR::Stripable> new_strip, bool force)
116 Glib::usleep(100); // let tick finish
120 _send = boost::shared_ptr<ARDOUR::Send> ();
122 send_select_status (ARDOUR::Properties::selected);
124 if ((new_strip == _strip) && !force) {
125 // no change don't send feedback
129 strip_connections.drop_connections ();
132 // this strip is blank and should be cleared
136 _strip->DropReferences.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCRouteObserver::no_strip, this), OSC::instance());
139 if (feedback[0]) { // buttons are separate feedback
140 _strip->PropertyChanged.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCRouteObserver::name_changed, this, boost::lambda::_1), OSC::instance());
141 name_changed (ARDOUR::Properties::name);
143 boost::shared_ptr<Route> rt = boost::dynamic_pointer_cast<Route> (_strip);
145 rt->route_group_changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCRouteObserver::group_name, this), OSC::instance());
149 _strip->presentation_info().PropertyChanged.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCRouteObserver::pi_changed, this, _1), OSC::instance());
150 _osc.int_message_with_id (X_("/strip/hide"), ssid, _strip->is_hidden (), in_line, addr);
152 _strip->mute_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCRouteObserver::send_change_message, this, X_("/strip/mute"), _strip->mute_control()), OSC::instance());
153 send_change_message (X_("/strip/mute"), _strip->mute_control());
155 _strip->solo_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCRouteObserver::send_change_message, this, X_("/strip/solo"), _strip->solo_control()), OSC::instance());
156 send_change_message (X_("/strip/solo"), _strip->solo_control());
158 if (_strip->solo_isolate_control()) {
159 _strip->solo_isolate_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, bind (&OSCRouteObserver::send_change_message, this, X_("/strip/solo_iso"), _strip->solo_isolate_control()), OSC::instance());
160 send_change_message (X_("/strip/solo_iso"), _strip->solo_isolate_control());
163 if (_strip->solo_safe_control()) {
164 _strip->solo_safe_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, bind (&OSCRouteObserver::send_change_message, this, X_("/strip/solo_safe"), _strip->solo_safe_control()), OSC::instance());
165 send_change_message (X_("/strip/solo_safe"), _strip->solo_safe_control());
168 boost::shared_ptr<Track> track = boost::dynamic_pointer_cast<Track> (_strip);
170 track->monitoring_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCRouteObserver::send_monitor_status, this, track->monitoring_control()), OSC::instance());
171 send_monitor_status (track->monitoring_control());
174 boost::shared_ptr<AutomationControl> rec_controllable = _strip->rec_enable_control ();
175 if (rec_controllable) {
176 rec_controllable->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCRouteObserver::send_change_message, this, X_("/strip/recenable"), _strip->rec_enable_control()), OSC::instance());
177 send_change_message (X_("/strip/recenable"), _strip->rec_enable_control());
179 boost::shared_ptr<AutomationControl> recsafe_controllable = _strip->rec_safe_control ();
180 if (rec_controllable) {
181 recsafe_controllable->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCRouteObserver::send_change_message, this, X_("/strip/record_safe"), _strip->rec_safe_control()), OSC::instance());
182 send_change_message (X_("/strip/record_safe"), _strip->rec_safe_control());
184 _strip->presentation_info().PropertyChanged.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCRouteObserver::send_select_status, this, _1), OSC::instance());
185 send_select_status (ARDOUR::Properties::selected);
188 if (feedback[1]) { // level controls
189 _gain_control = _strip->gain_control();
190 _gain_control->alist()->automation_state_changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCRouteObserver::gain_automation, this), OSC::instance());
191 _gain_control->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCRouteObserver::send_gain_message, this), OSC::instance());
194 boost::shared_ptr<Controllable> trim_controllable = boost::dynamic_pointer_cast<Controllable>(_strip->trim_control());
195 if (trim_controllable) {
196 trim_controllable->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCRouteObserver::send_trim_message, this), OSC::instance());
197 send_trim_message ();
200 boost::shared_ptr<Controllable> pan_controllable = boost::dynamic_pointer_cast<Controllable>(_strip->pan_azimuth_control());
201 if (pan_controllable) {
202 pan_controllable->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCRouteObserver::send_change_message, this, X_("/strip/pan_stereo_position"), _strip->pan_azimuth_control()), OSC::instance());
203 send_change_message (X_("/strip/pan_stereo_position"), _strip->pan_azimuth_control());
212 OSCRouteObserver::refresh_send (boost::shared_ptr<ARDOUR::Send> new_send, bool force)
216 Glib::usleep(100); // let tick finish
221 send_select_status (ARDOUR::Properties::selected);
223 if ((new_send == _send) && !force) {
224 // no change don't send feedback
228 strip_connections.drop_connections ();
230 // this strip is blank and should be cleared
236 _strip->DropReferences.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCRouteObserver::no_strip, this), OSC::instance());
239 if (feedback[0]) { // buttons are separate feedback
240 _strip->PropertyChanged.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCRouteObserver::name_changed, this, boost::lambda::_1), OSC::instance());
241 name_changed (ARDOUR::Properties::name);
244 if (feedback[1]) { // level controls
245 _gain_control = _send->gain_control();
246 _gain_control->alist()->automation_state_changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCRouteObserver::gain_automation, this), OSC::instance());
247 _gain_control->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCRouteObserver::send_gain_message, this), OSC::instance());
250 if (_send->pan_outs() > 1) {
251 boost::shared_ptr<Controllable> pan_controllable = boost::dynamic_pointer_cast<Controllable>(_send->panner_shell()->panner()->pannable()->pan_azimuth_control);
252 if (pan_controllable) {
253 pan_controllable->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCRouteObserver::send_change_message, this, X_("/strip/pan_stereo_position"), pan_controllable), OSC::instance());
254 send_change_message (X_("/strip/pan_stereo_position"), pan_controllable);
257 _osc.float_message_with_id (X_("/strip/pan_stereo_position"), ssid, 0.5, in_line, addr);
266 OSCRouteObserver::set_expand (uint32_t expand)
268 if (expand != _expand) {
270 if (expand == ssid) {
271 _osc.float_message_with_id (X_("/strip/expand"), ssid, 1.0, in_line, addr);
273 _osc.float_message_with_id (X_("/strip/expand"), ssid, 0.0, in_line, addr);
279 OSCRouteObserver::set_link_ready (uint32_t not_ready)
285 _osc.text_message_with_id (X_("/strip/name"), ssid, "Device", in_line, addr);
288 _osc.text_message_with_id (X_("/strip/name"), ssid, string_compose ("%1", not_ready), in_line, addr);
291 _osc.text_message_with_id (X_("/strip/name"), ssid, "Missing", in_line, addr);
294 _osc.text_message_with_id (X_("/strip/name"), ssid, "from", in_line, addr);
297 _osc.text_message_with_id (X_("/strip/name"), ssid, "Linkset", in_line, addr);
303 refresh_strip (_strip, true);
308 OSCRouteObserver::clear_strip ()
311 if (feedback[0]) { // buttons are separate feedback
312 _osc.text_message_with_id (X_("/strip/name"), ssid, " ", in_line, addr);
314 if (feedback[1]) { // level controls
316 _osc.float_message_with_id (X_("/strip/fader"), ssid, 0, in_line, addr);
318 _osc.float_message_with_id (X_("/strip/gain"), ssid, -193, in_line, addr);
320 _osc.float_message_with_id (X_("/strip/pan_stereo_position"), ssid, 0.5, in_line, addr);
325 OSCRouteObserver::send_clear ()
329 strip_connections.drop_connections ();
331 // all strip buttons should be off and faders 0 and etc.
332 _osc.float_message_with_id (X_("/strip/expand"), ssid, 0, in_line, addr);
333 if (feedback[0]) { // buttons are separate feedback
334 _osc.text_message_with_id (X_("/strip/group"), ssid, "none", in_line, addr);
335 _osc.float_message_with_id (X_("/strip/mute"), ssid, 0, in_line, addr);
336 _osc.float_message_with_id (X_("/strip/solo"), ssid, 0, in_line, addr);
337 _osc.float_message_with_id (X_("/strip/recenable"), ssid, 0, in_line, addr);
338 _osc.float_message_with_id (X_("/strip/record_safe"), ssid, 0, in_line, addr);
339 _osc.float_message_with_id (X_("/strip/monitor_input"), ssid, 0, in_line, addr);
340 _osc.float_message_with_id (X_("/strip/monitor_disk"), ssid, 0, in_line, addr);
341 _osc.float_message_with_id (X_("/strip/gui_select"), ssid, 0, in_line, addr);
342 _osc.float_message_with_id (X_("/strip/select"), ssid, 0, in_line, addr);
344 if (feedback[1]) { // level controls
345 _osc.float_message_with_id (X_("/strip/trimdB"), ssid, 0, in_line, addr);
348 _osc.float_message_with_id (X_("/strip/signal"), ssid, 0, in_line, addr);
352 _osc.float_message_with_id (X_("/strip/meter"), ssid, 0, in_line, addr);
354 _osc.float_message_with_id (X_("/strip/meter"), ssid, -193, in_line, addr);
356 }else if (feedback[8]) {
357 _osc.float_message_with_id (X_("/strip/meter"), ssid, 0, in_line, addr);
363 OSCRouteObserver::tick ()
369 if (feedback[7] || feedback[8] || feedback[9]) { // meters enabled
370 // the only meter here is master
371 /* XXXX need to add send meter for send mode or
372 * disable for send mode
375 if (_strip->peak_meter()) {
376 now_meter = _strip->peak_meter()->meter_level(0, MeterMCP);
380 if (now_meter < -120) now_meter = -193;
381 if (_last_meter != now_meter) {
382 if (feedback[7] || feedback[8]) {
383 if (gainmode && feedback[7]) {
384 _osc.float_message_with_id (X_("/strip/meter"), ssid, ((now_meter + 94) / 100), in_line, addr);
385 } else if ((!gainmode) && feedback[7]) {
386 _osc.float_message_with_id (X_("/strip/meter"), ssid, now_meter, in_line, addr);
387 } else if (feedback[8]) {
388 uint32_t ledlvl = (uint32_t)(((now_meter + 54) / 3.75)-1);
389 uint16_t ledbits = ~(0xfff<<ledlvl);
390 _osc.int_message_with_id (X_("/strip/meter"), ssid, ledbits, in_line, addr);
395 if (now_meter < -40) {
400 _osc.float_message_with_id (X_("/strip/signal"), ssid, signal, in_line, addr);
403 _last_meter = now_meter;
408 if (gain_timeout == 1) {
409 name_changed (ARDOUR::Properties::name);
413 if (as == ARDOUR::Play || as == ARDOUR::Touch) {
414 if(_last_gain != _gain_control->get_value()) {
415 _last_gain = _gain_control->get_value();
416 send_gain_message ();
424 OSCRouteObserver::name_changed (const PBD::PropertyChange& what_changed)
426 if (!what_changed.contains (ARDOUR::Properties::name)) {
431 name = _strip->name();
433 name = string_compose ("%1-Send", _strip->name());
437 _osc.text_message_with_id (X_("/strip/name"), ssid, name, in_line, addr);
442 OSCRouteObserver::group_name ()
444 boost::shared_ptr<Route> rt = boost::dynamic_pointer_cast<Route> (_strip);
446 RouteGroup *rg = rt->route_group();
448 _osc.text_message_with_id (X_("/strip/group"), ssid, rg->name(), in_line, addr);
450 _osc.text_message_with_id (X_("/strip/group"), ssid, " ", in_line, addr);
455 OSCRouteObserver::pi_changed (PBD::PropertyChange const& what_changed)
457 if (!what_changed.contains (ARDOUR::Properties::hidden)) {
460 _osc.int_message_with_id (X_("/strip/hide"), ssid, _strip->is_hidden (), in_line, addr);
464 OSCRouteObserver::send_change_message (string path, boost::shared_ptr<Controllable> controllable)
466 float val = controllable->get_value();
467 _osc.float_message_with_id (path, ssid, (float) controllable->internal_to_interface (val), in_line, addr);
471 OSCRouteObserver::send_monitor_status (boost::shared_ptr<Controllable> controllable)
474 float val = controllable->get_value();
492 _osc.int_message_with_id (X_("/strip/monitor_input"), ssid, input, in_line, addr);
493 _osc.int_message_with_id (X_("/strip/monitor_disk"), ssid, disk, in_line, addr);
498 OSCRouteObserver::send_trim_message ()
500 if (_last_trim != _strip->trim_control()->get_value()) {
501 _last_trim = _strip->trim_control()->get_value();
505 _osc.float_message_with_id (X_("/strip/trimdB"), ssid, (float) accurate_coefficient_to_dB (_last_trim), in_line, addr);
509 OSCRouteObserver::send_gain_message ()
511 if (_last_gain != _gain_control->get_value()) {
512 _last_gain = _gain_control->get_value();
518 _osc.float_message_with_id (X_("/strip/fader"), ssid, _gain_control->internal_to_interface (_last_gain), in_line, addr);
520 _osc.text_message_with_id (X_("/strip/name"), ssid, string_compose ("%1%2%3", std::fixed, std::setprecision(2), accurate_coefficient_to_dB (_last_gain)), in_line, addr);
524 if (!gainmode || gainmode == 2) {
525 if (_last_gain < 1e-15) {
526 _osc.float_message_with_id (X_("/strip/gain"), ssid, -200, in_line, addr);
528 _osc.float_message_with_id (X_("/strip/gain"), ssid, accurate_coefficient_to_dB (_last_gain), in_line, addr);
534 OSCRouteObserver::gain_automation ()
536 string path = X_("/strip/gain");
538 path = X_("/strip/fader");
540 send_gain_message ();
541 as = _gain_control->alist()->automation_state();
547 auto_name = "Manual";
568 _osc.float_message_with_id (string_compose (X_("%1/automation"), path), ssid, output, in_line, addr);
569 _osc.text_message_with_id (string_compose (X_("%1/automation_name"), path), ssid, auto_name, in_line, addr);
573 OSCRouteObserver::send_select_status (const PropertyChange& what)
575 if (what == PropertyChange(ARDOUR::Properties::selected)) {
577 _osc.float_message_with_id (X_("/strip/select"), ssid, _strip->is_selected(), in_line, addr);