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/route.h"
32 #include "ardour/route_group.h"
33 #include "ardour/solo_isolate_control.h"
36 #include "osc_route_observer.h"
42 using namespace ARDOUR;
43 using namespace ArdourSurface;
45 OSCRouteObserver::OSCRouteObserver (OSC& o, uint32_t ss, ArdourSurface::OSC::OSCSurface* su)
54 addr = lo_address_new_from_url (sur->remote_url.c_str());
55 gainmode = sur->gainmode;
56 feedback = sur->feedback;
57 in_line = feedback[2];
58 uint32_t sid = sur->bank + ssid - 2;
59 uint32_t not_ready = 0;
61 not_ready = _osc.link_sets[sur->linkset].not_ready;
64 set_link_ready (not_ready);
65 } else if (sid >= sur->strips.size ()) {
66 // this _should_ only occure if the number of strips is less than banksize
67 _strip = boost::shared_ptr<ARDOUR::Stripable>();
70 _strip = sur->strips[sid];
71 refresh_strip (_strip, true);
73 if (sur->expand_enable) {
74 set_expand (sur->expand);
80 OSCRouteObserver::~OSCRouteObserver ()
83 strip_connections.drop_connections ();
85 lo_address_free (addr);
89 OSCRouteObserver::no_strip ()
91 // This gets called on drop references
94 strip_connections.drop_connections ();
96 * The strip will sit idle at this point doing nothing until
97 * the surface has recalculated it's strip list and then calls
98 * refresh_strip. Otherwise refresh strip will get a strip address
99 * that does not exist... Crash
104 OSCRouteObserver::refresh_strip (boost::shared_ptr<ARDOUR::Stripable> new_strip, bool force)
108 Glib::usleep(100); // let tick finish
113 send_select_status (ARDOUR::Properties::selected);
115 if ((new_strip == _strip) && !force) {
116 // no change don't send feedback
120 strip_connections.drop_connections ();
123 // this strip is blank and should be cleared
127 _strip->DropReferences.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCRouteObserver::no_strip, this), OSC::instance());
130 if (feedback[0]) { // buttons are separate feedback
131 _strip->PropertyChanged.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCRouteObserver::name_changed, this, boost::lambda::_1), OSC::instance());
132 name_changed (ARDOUR::Properties::name);
134 boost::shared_ptr<Route> rt = boost::dynamic_pointer_cast<Route> (_strip);
135 rt->route_group_changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCRouteObserver::group_name, this), OSC::instance());
138 _strip->presentation_info().PropertyChanged.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCRouteObserver::pi_changed, this, _1), OSC::instance());
139 _osc.int_message_with_id (X_("/strip/hide"), ssid, _strip->is_hidden (), in_line, addr);
141 _strip->mute_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCRouteObserver::send_change_message, this, X_("/strip/mute"), _strip->mute_control()), OSC::instance());
142 send_change_message (X_("/strip/mute"), _strip->mute_control());
144 _strip->solo_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCRouteObserver::send_change_message, this, X_("/strip/solo"), _strip->solo_control()), OSC::instance());
145 send_change_message (X_("/strip/solo"), _strip->solo_control());
147 if (_strip->solo_isolate_control()) {
148 _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());
149 send_change_message (X_("/strip/solo_iso"), _strip->solo_isolate_control());
152 if (_strip->solo_safe_control()) {
153 _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());
154 send_change_message (X_("/strip/solo_safe"), _strip->solo_safe_control());
157 boost::shared_ptr<Track> track = boost::dynamic_pointer_cast<Track> (_strip);
159 track->monitoring_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCRouteObserver::send_monitor_status, this, track->monitoring_control()), OSC::instance());
160 send_monitor_status (track->monitoring_control());
163 boost::shared_ptr<AutomationControl> rec_controllable = _strip->rec_enable_control ();
164 if (rec_controllable) {
165 rec_controllable->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCRouteObserver::send_change_message, this, X_("/strip/recenable"), _strip->rec_enable_control()), OSC::instance());
166 send_change_message (X_("/strip/recenable"), _strip->rec_enable_control());
168 boost::shared_ptr<AutomationControl> recsafe_controllable = _strip->rec_safe_control ();
169 if (rec_controllable) {
170 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());
171 send_change_message (X_("/strip/record_safe"), _strip->rec_safe_control());
173 _strip->presentation_info().PropertyChanged.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCRouteObserver::send_select_status, this, _1), OSC::instance());
174 send_select_status (ARDOUR::Properties::selected);
177 if (feedback[1]) { // level controls
178 boost::shared_ptr<GainControl> gain_cont = _strip->gain_control();
179 gain_cont->alist()->automation_state_changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCRouteObserver::gain_automation, this), OSC::instance());
180 gain_cont->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCRouteObserver::send_gain_message, this), OSC::instance());
183 boost::shared_ptr<Controllable> trim_controllable = boost::dynamic_pointer_cast<Controllable>(_strip->trim_control());
184 if (trim_controllable) {
185 trim_controllable->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCRouteObserver::send_trim_message, this), OSC::instance());
186 send_trim_message ();
189 boost::shared_ptr<Controllable> pan_controllable = boost::dynamic_pointer_cast<Controllable>(_strip->pan_azimuth_control());
190 if (pan_controllable) {
191 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());
192 send_change_message (X_("/strip/pan_stereo_position"), _strip->pan_azimuth_control());
201 OSCRouteObserver::set_expand (uint32_t expand)
203 if (expand != _expand) {
205 if (expand == ssid) {
206 _osc.float_message_with_id (X_("/strip/expand"), ssid, 1.0, in_line, addr);
208 _osc.float_message_with_id (X_("/strip/expand"), ssid, 0.0, in_line, addr);
214 OSCRouteObserver::set_link_ready (uint32_t not_ready)
220 _osc.text_message_with_id (X_("/strip/name"), ssid, "Device", in_line, addr);
223 _osc.text_message_with_id (X_("/strip/name"), ssid, string_compose ("%1", not_ready), in_line, addr);
226 _osc.text_message_with_id (X_("/strip/name"), ssid, "Missing", in_line, addr);
229 _osc.text_message_with_id (X_("/strip/name"), ssid, "from", in_line, addr);
232 _osc.text_message_with_id (X_("/strip/name"), ssid, "Linkset", in_line, addr);
238 refresh_strip (_strip, true);
243 OSCRouteObserver::clear_strip ()
247 strip_connections.drop_connections ();
249 // all strip buttons should be off and faders 0 and etc.
250 _osc.float_message_with_id (X_("/strip/expand"), ssid, 0, in_line, addr);
251 if (feedback[0]) { // buttons are separate feedback
252 _osc.text_message_with_id (X_("/strip/name"), ssid, " ", in_line, addr);
253 _osc.text_message_with_id (X_("/strip/group"), ssid, "none", in_line, addr);
254 _osc.float_message_with_id (X_("/strip/mute"), ssid, 0, in_line, addr);
255 _osc.float_message_with_id (X_("/strip/solo"), ssid, 0, in_line, addr);
256 _osc.float_message_with_id (X_("/strip/recenable"), ssid, 0, in_line, addr);
257 _osc.float_message_with_id (X_("/strip/record_safe"), ssid, 0, in_line, addr);
258 _osc.float_message_with_id (X_("/strip/monitor_input"), ssid, 0, in_line, addr);
259 _osc.float_message_with_id (X_("/strip/monitor_disk"), ssid, 0, in_line, addr);
260 _osc.float_message_with_id (X_("/strip/gui_select"), ssid, 0, in_line, addr);
261 _osc.float_message_with_id (X_("/strip/select"), ssid, 0, in_line, addr);
263 if (feedback[1]) { // level controls
265 _osc.float_message_with_id (X_("/strip/fader"), ssid, 0, in_line, addr);
267 _osc.float_message_with_id (X_("/strip/gain"), ssid, -193, in_line, addr);
269 _osc.float_message_with_id (X_("/strip/trimdB"), ssid, 0, in_line, addr);
270 _osc.float_message_with_id (X_("/strip/pan_stereo_position"), ssid, 0.5, in_line, addr);
273 _osc.float_message_with_id (X_("/strip/signal"), ssid, 0, in_line, addr);
277 _osc.float_message_with_id (X_("/strip/meter"), ssid, 0, in_line, addr);
279 _osc.float_message_with_id (X_("/strip/meter"), ssid, -193, in_line, addr);
281 }else if (feedback[8]) {
282 _osc.float_message_with_id (X_("/strip/meter"), ssid, 0, in_line, addr);
288 OSCRouteObserver::tick ()
294 if (feedback[7] || feedback[8] || feedback[9]) { // meters enabled
295 // the only meter here is master
297 if (_strip->peak_meter()) {
298 now_meter = _strip->peak_meter()->meter_level(0, MeterMCP);
302 if (now_meter < -120) now_meter = -193;
303 if (_last_meter != now_meter) {
304 if (feedback[7] || feedback[8]) {
305 if (gainmode && feedback[7]) {
306 _osc.float_message_with_id (X_("/strip/meter"), ssid, ((now_meter + 94) / 100), in_line, addr);
307 } else if ((!gainmode) && feedback[7]) {
308 _osc.float_message_with_id (X_("/strip/meter"), ssid, now_meter, in_line, addr);
309 } else if (feedback[8]) {
310 uint32_t ledlvl = (uint32_t)(((now_meter + 54) / 3.75)-1);
311 uint16_t ledbits = ~(0xfff<<ledlvl);
312 _osc.int_message_with_id (X_("/strip/meter"), ssid, ledbits, in_line, addr);
317 if (now_meter < -40) {
322 _osc.float_message_with_id (X_("/strip/signal"), ssid, signal, in_line, addr);
325 _last_meter = now_meter;
330 if (gain_timeout == 1) {
331 _osc.text_message_with_id (X_("/strip/name"), ssid, _strip->name(), in_line, addr);
335 if (as == ARDOUR::Play || as == ARDOUR::Touch) {
336 if(_last_gain != _strip->gain_control()->get_value()) {
337 _last_gain = _strip->gain_control()->get_value();
338 send_gain_message ();
346 OSCRouteObserver::name_changed (const PBD::PropertyChange& what_changed)
348 if (!what_changed.contains (ARDOUR::Properties::name)) {
353 _osc.text_message_with_id (X_("/strip/name"), ssid, _strip->name(), in_line, addr);
358 OSCRouteObserver::group_name ()
360 boost::shared_ptr<Route> rt = boost::dynamic_pointer_cast<Route> (_strip);
362 RouteGroup *rg = rt->route_group();
364 _osc.text_message_with_id (X_("/strip/group"), ssid, rg->name(), in_line, addr);
366 _osc.text_message_with_id (X_("/strip/group"), ssid, " ", in_line, addr);
371 OSCRouteObserver::pi_changed (PBD::PropertyChange const& what_changed)
373 _osc.int_message_with_id (X_("/strip/hide"), ssid, _strip->is_hidden (), in_line, addr);
377 OSCRouteObserver::send_change_message (string path, boost::shared_ptr<Controllable> controllable)
379 float val = controllable->get_value();
380 _osc.float_message_with_id (path, ssid, (float) controllable->internal_to_interface (val), in_line, addr);
384 OSCRouteObserver::send_monitor_status (boost::shared_ptr<Controllable> controllable)
387 float val = controllable->get_value();
405 _osc.int_message_with_id (X_("/strip/monitor_input"), ssid, input, in_line, addr);
406 _osc.int_message_with_id (X_("/strip/monitor_disk"), ssid, disk, in_line, addr);
411 OSCRouteObserver::send_trim_message ()
413 if (_last_trim != _strip->trim_control()->get_value()) {
414 _last_trim = _strip->trim_control()->get_value();
418 _osc.float_message_with_id (X_("/strip/trimdB"), ssid, (float) accurate_coefficient_to_dB (_last_trim), in_line, addr);
422 OSCRouteObserver::send_gain_message ()
424 boost::shared_ptr<Controllable> controllable = _strip->gain_control();
425 if (_last_gain != controllable->get_value()) {
426 _last_gain = controllable->get_value();
432 _osc.float_message_with_id (X_("/strip/fader"), ssid, controllable->internal_to_interface (_last_gain), in_line, addr);
434 _osc.text_message_with_id (X_("/strip/name"), ssid, string_compose ("%1%2%3", std::fixed, std::setprecision(2), accurate_coefficient_to_dB (controllable->get_value())), in_line, addr);
438 if (!gainmode || gainmode == 2) {
439 if (controllable->get_value() < 1e-15) {
440 _osc.float_message_with_id (X_("/strip/gain"), ssid, -200, in_line, addr);
442 _osc.float_message_with_id (X_("/strip/gain"), ssid, accurate_coefficient_to_dB (_last_gain), in_line, addr);
448 OSCRouteObserver::gain_automation ()
450 string path = X_("/strip/gain");
452 path = X_("/strip/fader");
454 send_gain_message ();
455 as = _strip->gain_control()->alist()->automation_state();
461 auto_name = "Manual";
482 _osc.float_message_with_id (string_compose (X_("%1/automation"), path), ssid, output, in_line, addr);
483 _osc.text_message_with_id (string_compose (X_("%1/automation_name"), path), ssid, auto_name, in_line, addr);
487 OSCRouteObserver::send_select_status (const PropertyChange& what)
489 if (what == PropertyChange(ARDOUR::Properties::selected)) {
491 _osc.float_message_with_id (X_("/strip/select"), ssid, _strip->is_selected(), in_line, addr);