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);
136 rt->route_group_changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCRouteObserver::group_name, this), OSC::instance());
140 _strip->presentation_info().PropertyChanged.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCRouteObserver::pi_changed, this, _1), OSC::instance());
141 _osc.int_message_with_id (X_("/strip/hide"), ssid, _strip->is_hidden (), in_line, addr);
143 _strip->mute_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCRouteObserver::send_change_message, this, X_("/strip/mute"), _strip->mute_control()), OSC::instance());
144 send_change_message (X_("/strip/mute"), _strip->mute_control());
146 _strip->solo_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCRouteObserver::send_change_message, this, X_("/strip/solo"), _strip->solo_control()), OSC::instance());
147 send_change_message (X_("/strip/solo"), _strip->solo_control());
149 if (_strip->solo_isolate_control()) {
150 _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());
151 send_change_message (X_("/strip/solo_iso"), _strip->solo_isolate_control());
154 if (_strip->solo_safe_control()) {
155 _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());
156 send_change_message (X_("/strip/solo_safe"), _strip->solo_safe_control());
159 boost::shared_ptr<Track> track = boost::dynamic_pointer_cast<Track> (_strip);
161 track->monitoring_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCRouteObserver::send_monitor_status, this, track->monitoring_control()), OSC::instance());
162 send_monitor_status (track->monitoring_control());
165 boost::shared_ptr<AutomationControl> rec_controllable = _strip->rec_enable_control ();
166 if (rec_controllable) {
167 rec_controllable->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCRouteObserver::send_change_message, this, X_("/strip/recenable"), _strip->rec_enable_control()), OSC::instance());
168 send_change_message (X_("/strip/recenable"), _strip->rec_enable_control());
170 boost::shared_ptr<AutomationControl> recsafe_controllable = _strip->rec_safe_control ();
171 if (rec_controllable) {
172 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());
173 send_change_message (X_("/strip/record_safe"), _strip->rec_safe_control());
175 _strip->presentation_info().PropertyChanged.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCRouteObserver::send_select_status, this, _1), OSC::instance());
176 send_select_status (ARDOUR::Properties::selected);
179 if (feedback[1]) { // level controls
180 boost::shared_ptr<GainControl> gain_cont = _strip->gain_control();
181 gain_cont->alist()->automation_state_changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCRouteObserver::gain_automation, this), OSC::instance());
182 gain_cont->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCRouteObserver::send_gain_message, this), OSC::instance());
185 boost::shared_ptr<Controllable> trim_controllable = boost::dynamic_pointer_cast<Controllable>(_strip->trim_control());
186 if (trim_controllable) {
187 trim_controllable->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCRouteObserver::send_trim_message, this), OSC::instance());
188 send_trim_message ();
191 boost::shared_ptr<Controllable> pan_controllable = boost::dynamic_pointer_cast<Controllable>(_strip->pan_azimuth_control());
192 if (pan_controllable) {
193 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());
194 send_change_message (X_("/strip/pan_stereo_position"), _strip->pan_azimuth_control());
203 OSCRouteObserver::set_expand (uint32_t expand)
205 if (expand != _expand) {
207 if (expand == ssid) {
208 _osc.float_message_with_id (X_("/strip/expand"), ssid, 1.0, in_line, addr);
210 _osc.float_message_with_id (X_("/strip/expand"), ssid, 0.0, in_line, addr);
216 OSCRouteObserver::set_link_ready (uint32_t not_ready)
222 _osc.text_message_with_id (X_("/strip/name"), ssid, "Device", in_line, addr);
225 _osc.text_message_with_id (X_("/strip/name"), ssid, string_compose ("%1", not_ready), in_line, addr);
228 _osc.text_message_with_id (X_("/strip/name"), ssid, "Missing", in_line, addr);
231 _osc.text_message_with_id (X_("/strip/name"), ssid, "from", in_line, addr);
234 _osc.text_message_with_id (X_("/strip/name"), ssid, "Linkset", in_line, addr);
240 refresh_strip (_strip, true);
245 OSCRouteObserver::clear_strip ()
249 strip_connections.drop_connections ();
251 // all strip buttons should be off and faders 0 and etc.
252 _osc.float_message_with_id (X_("/strip/expand"), ssid, 0, in_line, addr);
253 if (feedback[0]) { // buttons are separate feedback
254 _osc.text_message_with_id (X_("/strip/name"), ssid, " ", in_line, addr);
255 _osc.text_message_with_id (X_("/strip/group"), ssid, "none", in_line, addr);
256 _osc.float_message_with_id (X_("/strip/mute"), ssid, 0, in_line, addr);
257 _osc.float_message_with_id (X_("/strip/solo"), ssid, 0, in_line, addr);
258 _osc.float_message_with_id (X_("/strip/recenable"), ssid, 0, in_line, addr);
259 _osc.float_message_with_id (X_("/strip/record_safe"), ssid, 0, in_line, addr);
260 _osc.float_message_with_id (X_("/strip/monitor_input"), ssid, 0, in_line, addr);
261 _osc.float_message_with_id (X_("/strip/monitor_disk"), ssid, 0, in_line, addr);
262 _osc.float_message_with_id (X_("/strip/gui_select"), ssid, 0, in_line, addr);
263 _osc.float_message_with_id (X_("/strip/select"), ssid, 0, in_line, addr);
265 if (feedback[1]) { // level controls
267 _osc.float_message_with_id (X_("/strip/fader"), ssid, 0, in_line, addr);
269 _osc.float_message_with_id (X_("/strip/gain"), ssid, -193, in_line, addr);
271 _osc.float_message_with_id (X_("/strip/trimdB"), ssid, 0, in_line, addr);
272 _osc.float_message_with_id (X_("/strip/pan_stereo_position"), ssid, 0.5, in_line, addr);
275 _osc.float_message_with_id (X_("/strip/signal"), ssid, 0, in_line, addr);
279 _osc.float_message_with_id (X_("/strip/meter"), ssid, 0, in_line, addr);
281 _osc.float_message_with_id (X_("/strip/meter"), ssid, -193, in_line, addr);
283 }else if (feedback[8]) {
284 _osc.float_message_with_id (X_("/strip/meter"), ssid, 0, in_line, addr);
290 OSCRouteObserver::tick ()
296 if (feedback[7] || feedback[8] || feedback[9]) { // meters enabled
297 // the only meter here is master
299 if (_strip->peak_meter()) {
300 now_meter = _strip->peak_meter()->meter_level(0, MeterMCP);
304 if (now_meter < -120) now_meter = -193;
305 if (_last_meter != now_meter) {
306 if (feedback[7] || feedback[8]) {
307 if (gainmode && feedback[7]) {
308 _osc.float_message_with_id (X_("/strip/meter"), ssid, ((now_meter + 94) / 100), in_line, addr);
309 } else if ((!gainmode) && feedback[7]) {
310 _osc.float_message_with_id (X_("/strip/meter"), ssid, now_meter, in_line, addr);
311 } else if (feedback[8]) {
312 uint32_t ledlvl = (uint32_t)(((now_meter + 54) / 3.75)-1);
313 uint16_t ledbits = ~(0xfff<<ledlvl);
314 _osc.int_message_with_id (X_("/strip/meter"), ssid, ledbits, in_line, addr);
319 if (now_meter < -40) {
324 _osc.float_message_with_id (X_("/strip/signal"), ssid, signal, in_line, addr);
327 _last_meter = now_meter;
332 if (gain_timeout == 1) {
333 _osc.text_message_with_id (X_("/strip/name"), ssid, _strip->name(), in_line, addr);
337 if (as == ARDOUR::Play || as == ARDOUR::Touch) {
338 if(_last_gain != _strip->gain_control()->get_value()) {
339 _last_gain = _strip->gain_control()->get_value();
340 send_gain_message ();
348 OSCRouteObserver::name_changed (const PBD::PropertyChange& what_changed)
350 if (!what_changed.contains (ARDOUR::Properties::name)) {
355 _osc.text_message_with_id (X_("/strip/name"), ssid, _strip->name(), in_line, addr);
360 OSCRouteObserver::group_name ()
362 boost::shared_ptr<Route> rt = boost::dynamic_pointer_cast<Route> (_strip);
364 RouteGroup *rg = rt->route_group();
366 _osc.text_message_with_id (X_("/strip/group"), ssid, rg->name(), in_line, addr);
368 _osc.text_message_with_id (X_("/strip/group"), ssid, " ", in_line, addr);
373 OSCRouteObserver::pi_changed (PBD::PropertyChange const& what_changed)
375 if (!what_changed.contains (ARDOUR::Properties::hidden)) {
378 _osc.int_message_with_id (X_("/strip/hide"), ssid, _strip->is_hidden (), in_line, addr);
382 OSCRouteObserver::send_change_message (string path, boost::shared_ptr<Controllable> controllable)
384 float val = controllable->get_value();
385 _osc.float_message_with_id (path, ssid, (float) controllable->internal_to_interface (val), in_line, addr);
389 OSCRouteObserver::send_monitor_status (boost::shared_ptr<Controllable> controllable)
392 float val = controllable->get_value();
410 _osc.int_message_with_id (X_("/strip/monitor_input"), ssid, input, in_line, addr);
411 _osc.int_message_with_id (X_("/strip/monitor_disk"), ssid, disk, in_line, addr);
416 OSCRouteObserver::send_trim_message ()
418 if (_last_trim != _strip->trim_control()->get_value()) {
419 _last_trim = _strip->trim_control()->get_value();
423 _osc.float_message_with_id (X_("/strip/trimdB"), ssid, (float) accurate_coefficient_to_dB (_last_trim), in_line, addr);
427 OSCRouteObserver::send_gain_message ()
429 boost::shared_ptr<Controllable> controllable = _strip->gain_control();
430 if (_last_gain != controllable->get_value()) {
431 _last_gain = controllable->get_value();
437 _osc.float_message_with_id (X_("/strip/fader"), ssid, controllable->internal_to_interface (_last_gain), in_line, addr);
439 _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);
443 if (!gainmode || gainmode == 2) {
444 if (controllable->get_value() < 1e-15) {
445 _osc.float_message_with_id (X_("/strip/gain"), ssid, -200, in_line, addr);
447 _osc.float_message_with_id (X_("/strip/gain"), ssid, accurate_coefficient_to_dB (_last_gain), in_line, addr);
453 OSCRouteObserver::gain_automation ()
455 string path = X_("/strip/gain");
457 path = X_("/strip/fader");
459 send_gain_message ();
460 as = _strip->gain_control()->alist()->automation_state();
466 auto_name = "Manual";
487 _osc.float_message_with_id (string_compose (X_("%1/automation"), path), ssid, output, in_line, addr);
488 _osc.text_message_with_id (string_compose (X_("%1/automation_name"), path), ssid, auto_name, in_line, addr);
492 OSCRouteObserver::send_select_status (const PropertyChange& what)
494 if (what == PropertyChange(ARDOUR::Properties::selected)) {
496 _osc.float_message_with_id (X_("/strip/select"), ssid, _strip->is_selected(), in_line, addr);