OSC: Move observers to surface based for less traffic.
[ardour.git] / libs / surfaces / osc / osc_select_observer.cc
1 /*
2     Copyright (C) 2009 Paul Davis
3
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.
8
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.
13
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.
17
18 */
19
20 #include <vector>
21 #include "boost/lambda/lambda.hpp"
22
23 #include "pbd/control_math.h"
24
25 #include "ardour/session.h"
26 #include "ardour/track.h"
27 #include "ardour/monitor_control.h"
28 #include "ardour/dB.h"
29 #include "ardour/meter.h"
30 #include "ardour/phase_control.h"
31 #include "ardour/solo_isolate_control.h"
32 #include "ardour/solo_safe_control.h"
33 #include "ardour/route.h"
34 #include "ardour/send.h"
35 #include "ardour/plugin.h"
36 #include "ardour/plugin_insert.h"
37 #include "ardour/processor.h"
38 #include "ardour/readonly_control.h"
39
40 #include "osc.h"
41 #include "osc_select_observer.h"
42
43 #include <glibmm.h>
44
45 #include "pbd/i18n.h"
46
47 using namespace std;
48 using namespace PBD;
49 using namespace ARDOUR;
50 using namespace ArdourSurface;
51
52 OSCSelectObserver::OSCSelectObserver (OSC& o, ArdourSurface::OSC::OSCSurface* su)
53         : _osc (o)
54         ,sur (su)
55         ,nsends (0)
56         ,_last_gain (-1.0)
57         ,_last_trim (-1.0)
58         ,_init (true)
59 {
60         addr = lo_address_new_from_url  (sur->remote_url.c_str());
61         std::cout << "select observer created\n";
62         refresh_strip (true);
63 }
64
65 OSCSelectObserver::~OSCSelectObserver ()
66 {
67         _init = true;
68         no_strip ();
69         lo_address_free (addr);
70 }
71
72 void
73 OSCSelectObserver::no_strip ()
74 {
75         // This gets called on drop references
76         _init = true;
77
78         strip_connections.drop_connections ();
79         /*
80          * The strip will sit idle at this point doing nothing until
81          * the surface has recalculated it's strip list and then calls
82          * refresh_strip. Otherwise refresh strip will get a strip address
83          * that does not exist... Crash
84          */
85  }
86
87 void
88 OSCSelectObserver::refresh_strip (bool force)
89 {
90         _init = true;
91
92         boost::shared_ptr<ARDOUR::Stripable> new_strip = sur->select;
93         if (_strip && (new_strip == _strip) && !force) {
94                 _init = false;
95                 return;
96         }
97         std::cout << string_compose ("new select: %1\n", new_strip->name());
98
99         _strip = new_strip;
100         _strip->DropReferences.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::no_strip, this), OSC::instance());
101         as = ARDOUR::Off;
102         gainmode = sur->gainmode;
103         feedback = sur->feedback;
104         as = ARDOUR::Off;
105         send_size = 0;
106         plug_size = 0;
107         _comp_redux = 1;
108         nsends = 0;
109         _last_gain = -1.0;
110         _last_trim = -1.0;
111
112         _strip->PropertyChanged.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::name_changed, this, boost::lambda::_1), OSC::instance());
113         name_changed (ARDOUR::Properties::name);
114
115         _strip->mute_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::change_message, this, X_("/select/mute"), _strip->mute_control()), OSC::instance());
116         change_message ("/select/mute", _strip->mute_control());
117
118         _strip->solo_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::change_message, this, X_("/select/solo"), _strip->solo_control()), OSC::instance());
119         change_message ("/select/solo", _strip->solo_control());
120
121         if (_strip->solo_isolate_control()) {
122                 _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());
123                 change_message ("/select/solo_iso", _strip->solo_isolate_control());
124         }
125
126         if (_strip->solo_safe_control()) {
127                 _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());
128                 change_message ("/select/solo_safe", _strip->solo_safe_control());
129         }
130
131         boost::shared_ptr<Track> track = boost::dynamic_pointer_cast<Track> (_strip);
132         if (track) {
133                 track->monitoring_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::monitor_status, this, track->monitoring_control()), OSC::instance());
134                 monitor_status (track->monitoring_control());
135         }
136
137         boost::shared_ptr<AutomationControl> rec_controllable = _strip->rec_enable_control ();
138         if (rec_controllable) {
139                 rec_controllable->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::change_message, this, X_("/select/recenable"), _strip->rec_enable_control()), OSC::instance());
140                 change_message ("/select/recenable", _strip->rec_enable_control());
141         }
142
143         boost::shared_ptr<AutomationControl> recsafe_controllable = _strip->rec_safe_control ();
144         if (recsafe_controllable) {
145                 recsafe_controllable->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::change_message, this, X_("/select/record_safe"), _strip->rec_safe_control()), OSC::instance());
146                 change_message ("/select/record_safe", _strip->rec_safe_control());
147         }
148
149         boost::shared_ptr<AutomationControl> phase_controllable = _strip->phase_control ();
150         if (phase_controllable) {
151                 phase_controllable->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::change_message, this, X_("/select/polarity"), _strip->phase_control()), OSC::instance());
152                 change_message ("/select/polarity", _strip->phase_control());
153         }
154
155         _strip->gain_control()->alist()->automation_state_changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::gain_automation, this), OSC::instance());
156         _strip->gain_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::gain_message, this), OSC::instance());
157         gain_automation ();
158
159         boost::shared_ptr<Controllable> trim_controllable = boost::dynamic_pointer_cast<Controllable>(_strip->trim_control());
160         if (trim_controllable) {
161                 trim_controllable->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::trim_message, this, X_("/select/trimdB"), _strip->trim_control()), OSC::instance());
162                 trim_message ("/select/trimdB", _strip->trim_control());
163         }
164
165         boost::shared_ptr<Controllable> pan_controllable = boost::dynamic_pointer_cast<Controllable>(_strip->pan_azimuth_control());
166         if (pan_controllable) {
167                 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());
168                 change_message ("/select/pan_stereo_position", _strip->pan_azimuth_control());
169         }
170
171         boost::shared_ptr<Controllable> width_controllable = boost::dynamic_pointer_cast<Controllable>(_strip->pan_width_control());
172         if (width_controllable) {
173                 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());
174                 change_message ("/select/pan_stereo_width", _strip->pan_width_control());
175         }
176
177         // Rest of possible pan controls... Untested because I can't find a way to get them in the GUI :)
178         if (_strip->pan_elevation_control ()) {
179                 _strip->pan_elevation_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::change_message, this, X_("/select/pan_elevation_position"), _strip->pan_elevation_control()), OSC::instance());
180                 change_message ("/select/pan_elevation_position", _strip->pan_elevation_control());
181         }
182         if (_strip->pan_frontback_control ()) {
183                 _strip->pan_frontback_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::change_message, this, X_("/select/pan_frontback_position"), _strip->pan_frontback_control()), OSC::instance());
184                 change_message ("/select/pan_frontback_position", _strip->pan_frontback_control());
185         }
186         if (_strip->pan_lfe_control ()) {
187                 _strip->pan_lfe_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::change_message, this, X_("/select/pan_lfe_control"), _strip->pan_lfe_control()), OSC::instance());
188                 change_message ("/select/pan_lfe_control", _strip->pan_lfe_control());
189         }
190
191         // sends, plugins and eq
192         // detecting processor changes is now in osc.cc
193
194         // but... MB master send enable is different
195         if (_strip->master_send_enable_controllable ()) {
196                 _strip->master_send_enable_controllable ()->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::enable_message, this, X_("/select/master_send_enable"), _strip->master_send_enable_controllable()), OSC::instance());
197                 enable_message ("/select/master_send_enable", _strip->master_send_enable_controllable());
198         }
199
200         // Compressor
201         if (_strip->comp_enable_controllable ()) {
202                 _strip->comp_enable_controllable ()->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::enable_message, this, X_("/select/comp_enable"), _strip->comp_enable_controllable()), OSC::instance());
203                 enable_message ("/select/comp_enable", _strip->comp_enable_controllable());
204         }
205         if (_strip->comp_threshold_controllable ()) {
206                 _strip->comp_threshold_controllable ()->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::change_message, this, X_("/select/comp_threshold"), _strip->comp_threshold_controllable()), OSC::instance());
207                 change_message ("/select/comp_threshold", _strip->comp_threshold_controllable());
208         }
209         if (_strip->comp_speed_controllable ()) {
210                 _strip->comp_speed_controllable ()->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::change_message, this, X_("/select/comp_speed"), _strip->comp_speed_controllable()), OSC::instance());
211                 change_message ("/select/comp_speed", _strip->comp_speed_controllable());
212         }
213         if (_strip->comp_mode_controllable ()) {
214                 _strip->comp_mode_controllable ()->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::comp_mode, this), OSC::instance());
215                 comp_mode ();
216         }
217         if (_strip->comp_makeup_controllable ()) {
218                 _strip->comp_makeup_controllable ()->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::change_message, this, X_("/select/comp_makeup"), _strip->comp_makeup_controllable()), OSC::instance());
219                 change_message ("/select/comp_makeup", _strip->comp_makeup_controllable());
220         }
221
222         _init = false;
223
224         tick();
225 }
226
227 void
228 OSCSelectObserver::clear_observer ()
229 {
230         strip_connections.drop_connections ();
231         // all strip buttons should be off and faders 0 and etc.
232         _osc.float_message ("/select/expand", 0, addr);
233         _osc.text_message ("/select/name", " ", addr);
234         _osc.text_message ("/select/comment", " ", addr);
235         _osc.float_message ("/select/mute", 0, addr);
236         _osc.float_message ("/select/solo", 0, addr);
237         _osc.float_message ("/select/recenable", 0, addr);
238         _osc.float_message ("/select/record_safe", 0, addr);
239         _osc.float_message ("/select/monitor_input", 0, addr);
240         _osc.float_message ("/select/monitor_disk", 0, addr);
241         _osc.float_message ("/select/polarity", 0, addr);
242         _osc.float_message ("/select/n_inputs", 0, addr);
243         _osc.float_message ("/select/n_outputs", 0, addr);
244         if (gainmode) {
245                 _osc.float_message ("/select/fader", 0, addr);
246         } else {
247                 _osc.float_message ("/select/gain", -193, addr);
248         }
249         _osc.float_message ("/select/trimdB", 0, addr);
250         _osc.float_message ("/select/pan_stereo_position", 0.5, addr);
251         _osc.float_message ("/select/pan_stereo_width", 1, addr);
252         if (feedback[9]) {
253                 _osc.float_message ("/select/signal", 0, addr);
254         }
255         if (feedback[7]) {
256                 if (gainmode) {
257                         _osc.float_message ("/select/meter", 0, addr);
258                 } else {
259                         _osc.float_message ("/select/meter", -193, addr);
260                 }
261         }else if (feedback[8]) {
262                 _osc.float_message ("/select/meter", 0, addr);
263         }
264         _osc.float_message ("/select/pan_elevation_position", 0, addr);
265         _osc.float_message ("/select/pan_frontback_position", .5, addr);
266         _osc.float_message ("/select/pan_lfe_control", 0, addr);
267         _osc.float_message ("/select/comp_enable", 0, addr);
268         _osc.float_message ("/select/comp_threshold", 0, addr);
269         _osc.float_message ("/select/comp_speed", 0, addr);
270         _osc.float_message ("/select/comp_mode", 0, addr);
271         _osc.text_message ("/select/comp_mode_name", " ", addr);
272         _osc.text_message ("/select/comp_speed_name", " ", addr);
273         _osc.float_message ("/select/comp_makeup", 0, addr);
274         send_end();
275         plugin_end();
276         eq_end();
277 }
278
279 void
280 OSCSelectObserver::renew_sends () {
281         send_end();
282         send_init();
283 }
284
285 void
286 OSCSelectObserver::renew_plugin () {
287         plugin_end();
288         plugin_init();
289 }
290
291 void
292 OSCSelectObserver::send_init()
293 {
294         // we don't know how many there are, so find out.
295         bool sends;
296         nsends  = 0;
297         do {
298                 sends = false;
299                 if (_strip->send_level_controllable (nsends)) {
300                         sends = true;
301                         nsends++;
302                 }
303         } while (sends);
304         if (!nsends) {
305                 return;
306         }
307
308         // paging should be done in osc.cc in case there is no feedback
309         send_size = nsends;
310         if (sur->send_page_size) {
311                 send_size = sur->send_page_size;
312         }
313         // check limits
314         uint32_t max_page = (uint32_t)(nsends / send_size) + 1;
315         if (sur->send_page < 1) {
316                 sur->send_page = 1;
317         } else if ((uint32_t)sur->send_page > max_page) {
318                 sur->send_page = max_page;
319         }
320         uint32_t page_start = ((sur->send_page - 1) * send_size);
321         uint32_t last_send = sur->send_page * send_size;
322         uint32_t c = 1;
323         send_timeout.push_back (2);
324         _last_send.clear();
325         _last_send.push_back (0.0);
326
327         for (uint32_t s = page_start; s < last_send; ++s, ++c) {
328
329                 bool send_valid = false;
330                 if (_strip->send_level_controllable (s)) {
331                         _strip->send_level_controllable(s)->Changed.connect (send_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::send_gain, this, c, _strip->send_level_controllable(s)), OSC::instance());
332                         send_timeout.push_back (2);
333                         _last_send.push_back (0.0);
334                         send_gain (c, _strip->send_level_controllable(s));
335                         send_valid = true;
336                 }
337
338                 if (_strip->send_enable_controllable (s)) {
339                         _strip->send_enable_controllable(s)->Changed.connect (send_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::enable_message_with_id, this, X_("/select/send_enable"), c, _strip->send_enable_controllable(s)), OSC::instance());
340                         enable_message_with_id ("/select/send_enable", c, _strip->send_enable_controllable(s));
341                 } else if (send_valid) {
342                         boost::shared_ptr<Route> r = boost::dynamic_pointer_cast<Route> (_strip);
343                         if (!r) {
344                                 // should never get here
345                                 _osc.float_message_with_id ("/select/send_enable", c, 0, addr);
346                         }
347                         boost::shared_ptr<Send> snd = boost::dynamic_pointer_cast<Send> (r->nth_send(s));
348                         if (snd) {
349                                 boost::shared_ptr<Processor> proc = boost::dynamic_pointer_cast<Processor> (snd);
350                                 proc->ActiveChanged.connect (send_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::send_enable, this, X_("/select/send_enable"), c, proc), OSC::instance());
351                                 _osc.float_message_with_id ("/select/send_enable", c, proc->enabled(), addr);
352                         }
353                 }
354                 if (!gainmode && send_valid) {
355                         _osc.text_message_with_id ("/select/send_name", c, _strip->send_name(s), addr);
356                 }
357         }
358 }
359
360 void
361 OSCSelectObserver::plugin_init()
362 {
363         if (!sur->plugin_id) {
364                 return;
365         }
366
367         boost::shared_ptr<Route> r = boost::dynamic_pointer_cast<Route>(_strip);
368         if (!r) {
369                 return;
370         }
371
372         // we have a plugin number now get the processor
373         boost::shared_ptr<Processor> proc = r->nth_plugin (sur->plugins[sur->plugin_id - 1]);
374         boost::shared_ptr<PluginInsert> pi;
375         if (!(pi = boost::dynamic_pointer_cast<PluginInsert>(proc))) {
376                 return;
377         }
378         boost::shared_ptr<ARDOUR::Plugin> pip = pi->plugin();
379
380         bool ok = false;
381         nplug_params = sur->plug_params.size ();
382
383         // default of 0 page size means show all
384         plug_size = nplug_params;
385         if (sur->plug_page_size) {
386                 plug_size = sur->plug_page_size;
387         }
388         _osc.text_message ("/select/plugin/name", pip->name(), addr);
389         uint32_t page_end = nplug_params;
390         uint32_t max_page = 1;
391         if (plug_size && nplug_params) {
392                 max_page = (uint32_t)((nplug_params - 1) / plug_size) + 1;
393         }
394
395         if (sur->plug_page < 1) {
396                 sur->plug_page = 1;
397         }
398         if ((uint32_t)sur->plug_page > max_page) {
399                 sur->plug_page = max_page;
400         }
401         uint32_t page_start = ((sur->plug_page - 1) * plug_size);
402         page_end = sur->plug_page * plug_size;
403
404         int pid = 1;
405         for ( uint32_t ppi = page_start;  ppi < page_end; ++ppi, ++pid) {
406                 if (ppi >= nplug_params) {
407                         _osc.text_message_with_id ("/select/plugin/parameter/name", pid, " ", addr);
408                         _osc.float_message_with_id ("/select/plugin/parameter", pid, 0, addr);
409                         continue;
410                 }
411
412                 uint32_t controlid = pip->nth_parameter(sur->plug_params[ppi], ok);
413                 if (!ok) {
414                         continue;
415                 }
416                 ParameterDescriptor pd;
417                 pip->get_parameter_descriptor(controlid, pd);
418                 _osc.text_message_with_id ("/select/plugin/parameter/name", pid, pd.label, addr);
419                 if ( pip->parameter_is_input(controlid)) {
420                         boost::shared_ptr<AutomationControl> c = pi->automation_control(Evoral::Parameter(PluginAutomation, 0, controlid));
421                         if (c) {
422                                 bool swtch = false;
423                                 if (pd.integer_step && pd.upper == 1) {
424                                         swtch = true;
425                                 }
426                                 c->Changed.connect (plugin_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::plugin_parameter_changed, this, pid, swtch, c), OSC::instance());
427                                 plugin_parameter_changed (pid, swtch, c);
428                         }
429                 }
430         }
431 }
432
433 void
434 OSCSelectObserver::send_end ()
435 {
436         send_connections.drop_connections ();
437         for (uint32_t i = 1; i <= send_size; i++) {
438                 if (gainmode) {
439                         _osc.float_message_with_id ("/select/send_fader", i, 0, addr);
440                 } else {
441                         _osc.float_message_with_id ("/select/send_gain", i, -193, addr);
442                 }
443                 // next enable
444                 _osc.float_message_with_id ("/select/send_enable", i, 0, addr);
445                 // next name
446                 _osc.text_message_with_id ("/select/send_name", i, " ", addr);
447         }
448         // need to delete or clear send_timeout
449         send_timeout.clear();
450         nsends = 0;
451 }
452
453 void
454 OSCSelectObserver::plugin_parameter_changed (int pid, bool swtch, boost::shared_ptr<PBD::Controllable> controllable)
455 {
456         if (swtch) {
457                 enable_message_with_id ("/select/plugin/parameter", pid, controllable);
458         } else {
459                 change_message_with_id ("/select/plugin/parameter", pid, controllable);
460         }
461 }
462
463 void
464 OSCSelectObserver::plugin_end ()
465 {
466         plugin_connections.drop_connections ();
467         _osc.text_message ("/select/plugin/name", " ", addr);
468         for (uint32_t i = 1; i <= plug_size; i++) {
469                 _osc.float_message_with_id ("/select/plugin/parameter", i, 0, addr);
470                 // next name
471                 _osc.text_message_with_id ("/select/plugin/parameter/name", i, " ", addr);
472         }
473         nplug_params = 0;
474 }
475
476 void
477 OSCSelectObserver::tick ()
478 {
479         if (_init) {
480                 return;
481         }
482         if (feedback[7] || feedback[8] || feedback[9]) { // meters enabled
483                 float now_meter;
484                 if (_strip->peak_meter()) {
485                         now_meter = _strip->peak_meter()->meter_level(0, MeterMCP);
486                 } else {
487                         now_meter = -193;
488                 }
489                 if (now_meter < -144) now_meter = -193;
490                 if (_last_meter != now_meter) {
491                         if (feedback[7] || feedback[8]) {
492                                 string path = "/select/meter";
493                                 if (gainmode && feedback[7]) {
494                                         _osc.float_message (path, ((now_meter + 94) / 100), addr);
495                                 } else if ((!gainmode) && feedback[7]) {
496                                         _osc.float_message (path, now_meter, addr);
497                                 } else if (feedback[8]) {
498                                         uint32_t ledlvl = (uint32_t)(((now_meter + 54) / 3.75)-1);
499                                         uint16_t ledbits = ~(0xfff<<ledlvl);
500                                         _osc.float_message (path, ledbits, addr);
501                                 }
502                         }
503                         if (feedback[9]) {
504                                 string path = "/select/signal";
505                                 float signal;
506                                 if (now_meter < -40) {
507                                         signal = 0;
508                                 } else {
509                                         signal = 1;
510                                 }
511                                 _osc.float_message (path, signal, addr);
512                         }
513                 }
514                 _last_meter = now_meter;
515
516         }
517         if (gain_timeout) {
518                 if (gain_timeout == 1) {
519                         _osc.text_message ("/select/name", _strip->name(), addr);
520                 }
521                 gain_timeout--;
522         }
523
524         if (as == ARDOUR::Play ||  as == ARDOUR::Touch) {
525                 if(_last_gain != _strip->gain_control()->get_value()) {
526                         _last_gain = _strip->gain_control()->get_value();
527                                 gain_message ();
528                 }
529         }
530         if (_strip->comp_redux_controllable() && _strip->comp_enable_controllable() && _strip->comp_enable_controllable()->get_value()) {
531                 float new_value = _strip->comp_redux_controllable()->get_parameter();
532                 if (_comp_redux != new_value) {
533                         _osc.float_message ("/select/comp_redux", new_value, addr);
534                         _comp_redux = new_value;
535                 }
536         }
537         for (uint32_t i = 1; i <= send_timeout.size(); i++) {
538                 if (send_timeout[i]) {
539                         if (send_timeout[i] == 1) {
540                                 uint32_t pg_offset = (sur->send_page - 1) * sur->send_page_size;
541                                 _osc.text_message_with_id ("/select/send_name", i, _strip->send_name(pg_offset + i - 1), addr);
542                         }
543                         send_timeout[i]--;
544                 }
545         }
546 }
547
548 void
549 OSCSelectObserver::name_changed (const PBD::PropertyChange& what_changed)
550 {
551         if (!what_changed.contains (ARDOUR::Properties::name)) {
552                 return;
553         }
554
555         if (!_strip) {
556                 return;
557         }
558
559         _osc.text_message ("/select/name", _strip->name(), addr);
560         boost::shared_ptr<Route> route = boost::dynamic_pointer_cast<Route> (_strip);
561         if (route) {
562                 //spit out the comment at the same time
563                 _osc.text_message ("/select/comment", route->comment(), addr);
564                 // lets tell the surface how many inputs this strip has
565                 _osc.float_message ("/select/n_inputs", (float) route->n_inputs().n_total(), addr);
566                 // lets tell the surface how many outputs this strip has
567                 _osc.float_message ("/select/n_outputs", (float) route->n_outputs().n_total(), addr);
568         }
569 }
570
571 void
572 OSCSelectObserver::change_message (string path, boost::shared_ptr<Controllable> controllable)
573 {
574         float val = controllable->get_value();
575
576         _osc.float_message (path, (float) controllable->internal_to_interface (val), addr);
577 }
578
579 void
580 OSCSelectObserver::enable_message (string path, boost::shared_ptr<Controllable> controllable)
581 {
582         float val = controllable->get_value();
583         if (val) {
584                 _osc.float_message (path, 1, addr);
585         } else {
586                 _osc.float_message (path, 0, addr);
587         }
588
589 }
590
591 void
592 OSCSelectObserver::change_message_with_id (string path, uint32_t id, boost::shared_ptr<Controllable> controllable)
593 {
594         float val = controllable->get_value();
595
596         _osc.float_message_with_id (path, id, (float) controllable->internal_to_interface (val), addr);
597 }
598
599 void
600 OSCSelectObserver::enable_message_with_id (string path, uint32_t id, boost::shared_ptr<Controllable> controllable)
601 {
602         float val = controllable->get_value();
603         if (val) {
604                 _osc.float_message_with_id (path, id, 1, addr);
605         } else {
606                 _osc.float_message_with_id (path, id, 0, addr);
607         }
608 }
609
610 void
611 OSCSelectObserver::monitor_status (boost::shared_ptr<Controllable> controllable)
612 {
613         int disk, input;
614         float val = controllable->get_value();
615         switch ((int) val) {
616                 case 1:
617                         disk = 0;
618                         input = 1;
619                         break;
620                 case 2:
621                         disk = 1;
622                         input = 0;
623                         break;
624                 default:
625                         disk = 0;
626                         input = 0;
627         }
628
629         _osc.float_message ("/select/monitor_input", (float) input, addr);
630         _osc.float_message ("/select/monitor_disk", (float) disk, addr);
631 }
632
633 void
634 OSCSelectObserver::trim_message (string path, boost::shared_ptr<Controllable> controllable)
635 {
636         if (_last_trim != controllable->get_value()) {
637                 _last_trim = controllable->get_value();
638         } else {
639                 return;
640         }
641
642         _osc.float_message (path, (float) accurate_coefficient_to_dB (controllable->get_value()), addr);
643 }
644
645 void
646 OSCSelectObserver::gain_message ()
647 {
648         float value = _strip->gain_control()->get_value();
649         if (_last_gain != value) {
650                 _last_gain = value;
651         } else {
652                 return;
653         }
654
655         if (gainmode) {
656                 _osc.text_message ("/select/name", string_compose ("%1%2%3", std::fixed, std::setprecision(2), accurate_coefficient_to_dB (value)), addr);
657                 gain_timeout = 8;
658                 _osc.float_message ("/select/fader", _strip->gain_control()->internal_to_interface (value), addr);
659         } else {
660                 if (value < 1e-15) {
661                         _osc.float_message ("/select/gain", -200, addr);
662                 } else {
663                         _osc.float_message ("/select/gain", accurate_coefficient_to_dB (value), addr);
664                 }
665         }
666 }
667
668 void
669 OSCSelectObserver::gain_automation ()
670 {
671         float output = 0;
672         as = _strip->gain_control()->alist()->automation_state();
673         string auto_name;
674         switch (as) {
675                 case ARDOUR::Off:
676                         output = 0;
677                         auto_name = "Manual";
678                         break;
679                 case ARDOUR::Play:
680                         output = 1;
681                         auto_name = "Play";
682                         break;
683                 case ARDOUR::Write:
684                         output = 2;
685                         auto_name = "Write";
686                         break;
687                 case ARDOUR::Touch:
688                         output = 3;
689                         auto_name = "Touch";
690                         break;
691                 default:
692                         break;
693         }
694
695         if (gainmode) {
696                 _osc.float_message ("/select/fader/automation", output, addr);
697                 _osc.text_message ("/select/fader/automation_name", auto_name, addr);
698         } else {
699                 _osc.float_message ("/select/gain/automation", output, addr);
700                 _osc.text_message ("/select/gain/automation_name", auto_name, addr);
701         }
702
703         gain_message ();
704 }
705
706 void
707 OSCSelectObserver::send_gain (uint32_t id, boost::shared_ptr<PBD::Controllable> controllable)
708 {
709         if (_last_send[id] != controllable->get_value()) {
710                 _last_send[id] = controllable->get_value();
711         } else {
712                 return;
713         }
714         string path;
715         float value;
716         float db;
717 #ifdef MIXBUS
718                 db = controllable->get_value();
719 #else
720                 if (controllable->get_value() < 1e-15) {
721                         db = -193;
722                 } else {
723                         db = accurate_coefficient_to_dB (controllable->get_value());
724                 }
725 #endif
726
727         if (gainmode) {
728                 path = "/select/send_fader";
729                 value = controllable->internal_to_interface (controllable->get_value());
730         _osc.text_message_with_id ("/select/send_name" , id, string_compose ("%1%2%3", std::fixed, std::setprecision(2), db), addr);
731         if (send_timeout.size() > id) {
732                 send_timeout[id] = 8;
733         }
734         } else {
735                 path = "/select/send_gain";
736                 value = db;
737         }
738
739         _osc.float_message_with_id (path, id, value, addr);
740 }
741
742 void
743 OSCSelectObserver::send_enable (string path, uint32_t id, boost::shared_ptr<Processor> proc)
744 {
745         // with no delay value is wrong
746         Glib::usleep(10);
747
748         _osc.float_message_with_id ("/select/send_enable", id, proc->enabled(), addr);
749 }
750
751 void
752 OSCSelectObserver::comp_mode ()
753 {
754         change_message ("/select/comp_mode", _strip->comp_mode_controllable());
755         _osc.text_message ("/select/comp_mode_name", _strip->comp_mode_name(_strip->comp_mode_controllable()->get_value()), addr);
756         _osc.text_message ("/select/comp_speed_name", _strip->comp_speed_name(_strip->comp_mode_controllable()->get_value()), addr);
757 }
758
759 void
760 OSCSelectObserver::eq_init()
761 {
762         // HPF and enable are special case, rest are in bands
763         if (_strip->filter_enable_controllable (true)) {
764                 _strip->filter_enable_controllable (true)->Changed.connect (eq_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::change_message, this, X_("/select/eq_hpf/enable"), _strip->filter_enable_controllable (true)), OSC::instance());
765                 change_message ("/select/eq_hpf/enable", _strip->filter_enable_controllable(true));
766         }
767
768         if (_strip->filter_enable_controllable (false)) {
769                 _strip->filter_enable_controllable (false)->Changed.connect (eq_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::change_message, this, X_("/select/eq_lpf/enable"), _strip->filter_enable_controllable (false)), OSC::instance());
770                 change_message ("/select/eq_lpf/enable", _strip->filter_enable_controllable(false));
771         }
772
773         if (_strip->filter_freq_controllable (true)) {
774                 _strip->filter_freq_controllable (true)->Changed.connect (eq_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::change_message, this, X_("/select/eq_hpf/freq"), _strip->filter_freq_controllable (true)), OSC::instance());
775                 change_message ("/select/eq_hpf/freq", _strip->filter_freq_controllable(true));
776         }
777
778         if (_strip->filter_freq_controllable (false)) {
779                 _strip->filter_freq_controllable (false)->Changed.connect (eq_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::change_message, this, X_("/select/eq_lpf/freq"), _strip->filter_freq_controllable (false)), OSC::instance());
780                 change_message ("/select/eq_lpf/freq", _strip->filter_freq_controllable(false));
781         }
782
783         if (_strip->filter_slope_controllable (true)) {
784                 _strip->filter_slope_controllable (true)->Changed.connect (eq_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::change_message, this, X_("/select/eq_hpf/slope"), _strip->filter_slope_controllable (true)), OSC::instance());
785                 change_message ("/select/eq_hpf/slope", _strip->filter_slope_controllable(true));
786         }
787
788         if (_strip->filter_slope_controllable (false)) {
789                 _strip->filter_slope_controllable (false)->Changed.connect (eq_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::change_message, this, X_("/select/eq_lpf/slope"), _strip->filter_slope_controllable (false)), OSC::instance());
790                 change_message ("/select/eq_lpf/slope", _strip->filter_slope_controllable(false));
791         }
792
793         if (_strip->eq_enable_controllable ()) {
794                 _strip->eq_enable_controllable ()->Changed.connect (eq_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::enable_message, this, X_("/select/eq_enable"), _strip->eq_enable_controllable()), OSC::instance());
795                 enable_message ("/select/eq_enable", _strip->eq_enable_controllable());
796         }
797
798         uint32_t eq_bands = _strip->eq_band_cnt ();
799         if (!eq_bands) {
800                 return;
801         }
802
803         for (uint32_t i = 0; i < eq_bands; i++) {
804                 if (_strip->eq_band_name(i).size()) {
805                         _osc.text_message_with_id ("/select/eq_band_name", i + 1, _strip->eq_band_name (i), addr);
806                 }
807                 if (_strip->eq_gain_controllable (i)) {
808                         _strip->eq_gain_controllable(i)->Changed.connect (eq_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::change_message_with_id, this, X_("/select/eq_gain"), i + 1, _strip->eq_gain_controllable(i)), OSC::instance());
809                         change_message_with_id ("/select/eq_gain", i + 1, _strip->eq_gain_controllable(i));
810                 }
811                 if (_strip->eq_freq_controllable (i)) {
812                         _strip->eq_freq_controllable(i)->Changed.connect (eq_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::change_message_with_id, this, X_("/select/eq_freq"), i + 1, _strip->eq_freq_controllable(i)), OSC::instance());
813                         change_message_with_id ("/select/eq_freq", i + 1, _strip->eq_freq_controllable(i));
814                 }
815                 if (_strip->eq_q_controllable (i)) {
816                         _strip->eq_q_controllable(i)->Changed.connect (eq_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::change_message_with_id, this, X_("/select/eq_q"), i + 1, _strip->eq_q_controllable(i)), OSC::instance());
817                         change_message_with_id ("/select/eq_q", i + 1, _strip->eq_q_controllable(i));
818                 }
819                 if (_strip->eq_shape_controllable (i)) {
820                         _strip->eq_shape_controllable(i)->Changed.connect (eq_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::change_message_with_id, this, X_("/select/eq_shape"), i + 1, _strip->eq_shape_controllable(i)), OSC::instance());
821                         change_message_with_id ("/select/eq_shape", i + 1, _strip->eq_shape_controllable(i));
822                 }
823         }
824 }
825
826 void
827 OSCSelectObserver::eq_end ()
828 {
829         eq_connections.drop_connections ();
830         if (_strip->filter_freq_controllable (true)) {
831                 _osc.float_message ("/select/eq_hpf", 0, addr);
832         }
833         if (_strip->eq_enable_controllable ()) {
834                 _osc.float_message ("/select/eq_enable", 0, addr);
835         }
836
837         for (uint32_t i = 1; i <= _strip->eq_band_cnt (); i++) {
838                 _osc.text_message_with_id ("/select/eq_band_name", i, " ", addr);
839                 _osc.float_message_with_id ("/select/eq_gain", i, 0, addr);
840                 _osc.float_message_with_id ("/select/eq_freq", i, 0, addr);
841                 _osc.float_message_with_id ("/select/eq_q", i, 0, addr);
842                 _osc.float_message_with_id ("/select/eq_shape", i, 0, addr);
843
844
845         }
846 }
847
848 void
849 OSCSelectObserver::eq_restart(int x)
850 {
851         eq_end();
852         eq_init();
853 }
854
855 string
856 OSCSelectObserver::set_path (string path, uint32_t id)
857 {
858         if (feedback[2]) {
859                 path = string_compose ("%1/%2", path, id);
860         }
861         return path;
862 }