OSC: check controllable exists before using
[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 "ardour/session.h"
24 #include "ardour/track.h"
25 #include "ardour/monitor_control.h"
26 #include "ardour/dB.h"
27 #include "ardour/meter.h"
28 #include "ardour/phase_control.h"
29 #include "ardour/solo_isolate_control.h"
30 #include "ardour/solo_safe_control.h"
31 #include "ardour/route.h"
32 #include "ardour/send.h"
33 #include "ardour/processor.h"
34 #include "ardour/readonly_control.h"
35
36 #include "osc.h"
37 #include "osc_select_observer.h"
38
39 #include <glibmm.h>
40
41 #include "pbd/i18n.h"
42
43 using namespace std;
44 using namespace PBD;
45 using namespace ARDOUR;
46 using namespace ArdourSurface;
47
48 OSCSelectObserver::OSCSelectObserver (boost::shared_ptr<Stripable> s, lo_address a, uint32_t gm, std::bitset<32> fb)
49         : _strip (s)
50         ,gainmode (gm)
51         ,feedback (fb)
52         ,nsends (0)
53         ,_last_gain (0.0)
54 {
55         addr = lo_address_new (lo_address_get_hostname(a) , lo_address_get_port(a));
56         as = ARDOUR::Off;
57
58         if (feedback[0]) { // buttons are separate feedback
59                 _strip->PropertyChanged.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::name_changed, this, boost::lambda::_1), OSC::instance());
60                 name_changed (ARDOUR::Properties::name);
61
62                 _strip->mute_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::change_message, this, X_("/select/mute"), _strip->mute_control()), OSC::instance());
63                 change_message ("/select/mute", _strip->mute_control());
64
65                 _strip->solo_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::change_message, this, X_("/select/solo"), _strip->solo_control()), OSC::instance());
66                 change_message ("/select/solo", _strip->solo_control());
67
68                 if (_strip->solo_isolate_control()) {
69                         _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());
70                         change_message ("/select/solo_iso", _strip->solo_isolate_control());
71                 }
72
73                 if (_strip->solo_safe_control()) {
74                         _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());
75                         change_message ("/select/solo_safe", _strip->solo_safe_control());
76                 }
77
78                 boost::shared_ptr<Track> track = boost::dynamic_pointer_cast<Track> (_strip);
79                 if (track) {
80                         track->monitoring_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::monitor_status, this, track->monitoring_control()), OSC::instance());
81                         monitor_status (track->monitoring_control());
82                 }
83
84                 boost::shared_ptr<AutomationControl> rec_controllable = _strip->rec_enable_control ();
85                 if (rec_controllable) {
86                         rec_controllable->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::change_message, this, X_("/select/recenable"), _strip->rec_enable_control()), OSC::instance());
87                         change_message ("/select/recenable", _strip->rec_enable_control());
88                 }
89
90                 boost::shared_ptr<AutomationControl> recsafe_controllable = _strip->rec_safe_control ();
91                 if (recsafe_controllable) {
92                         recsafe_controllable->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::change_message, this, X_("/select/record_safe"), _strip->rec_safe_control()), OSC::instance());
93                         change_message ("/select/record_safe", _strip->rec_safe_control());
94                 }
95
96                 boost::shared_ptr<AutomationControl> phase_controllable = _strip->phase_control ();
97                 if (phase_controllable) {
98                         phase_controllable->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::change_message, this, X_("/select/polarity"), _strip->phase_control()), OSC::instance());
99                         change_message ("/select/polarity", _strip->phase_control());
100                 }
101
102         }
103
104         if (feedback[1]) { // level controls
105                 _strip->gain_control()->alist()->automation_state_changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::gain_automation, this), OSC::instance());
106                 _strip->gain_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::gain_message, this), OSC::instance());
107                 gain_automation ();
108
109                 boost::shared_ptr<Controllable> trim_controllable = boost::dynamic_pointer_cast<Controllable>(_strip->trim_control());
110                 if (trim_controllable) {
111                         trim_controllable->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::trim_message, this, X_("/select/trimdB"), _strip->trim_control()), OSC::instance());
112                         trim_message ("/select/trimdB", _strip->trim_control());
113                 }
114
115                 boost::shared_ptr<Controllable> pan_controllable = boost::dynamic_pointer_cast<Controllable>(_strip->pan_azimuth_control());
116                 if (pan_controllable) {
117                         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());
118                         change_message ("/select/pan_stereo_position", _strip->pan_azimuth_control());
119                 }
120
121                 boost::shared_ptr<Controllable> width_controllable = boost::dynamic_pointer_cast<Controllable>(_strip->pan_width_control());
122                 if (width_controllable) {
123                         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());
124                         change_message ("/select/pan_stereo_width", _strip->pan_width_control());
125                 }
126
127         }
128         if (feedback[13]) { // Well known controls
129                 // Rest of possible pan controls... Untested because I can't find a way to get them in the GUI :)
130                 if (_strip->pan_elevation_control ()) {
131                         _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());
132                         change_message ("/select/pan_elevation_position", _strip->pan_elevation_control());
133                 }
134                 if (_strip->pan_frontback_control ()) {
135                         _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());
136                         change_message ("/select/pan_frontback_position", _strip->pan_frontback_control());
137                 }
138                 if (_strip->pan_lfe_control ()) {
139                         _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());
140                         change_message ("/select/pan_lfe_control", _strip->pan_lfe_control());
141                 }
142
143                 // sends and eq
144                 // detecting processor changes requires cast to route
145                 boost::shared_ptr<Route> r = boost::dynamic_pointer_cast<Route>(_strip);
146                 if (r) {
147                         r->processors_changed.connect  (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::send_restart, this, -1), OSC::instance());
148                         send_init();
149                         eq_init();
150                 }
151
152                 // Compressor
153                 if (_strip->comp_enable_controllable ()) {
154                         _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());
155                         enable_message ("/select/comp_enable", _strip->comp_enable_controllable());
156                 }
157                 if (_strip->comp_threshold_controllable ()) {
158                         _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());
159                         change_message ("/select/comp_threshold", _strip->comp_threshold_controllable());
160                 }
161                 if (_strip->comp_speed_controllable ()) {
162                         _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());
163                         change_message ("/select/comp_speed", _strip->comp_speed_controllable());
164                 }
165                 if (_strip->comp_mode_controllable ()) {
166                         _strip->comp_mode_controllable ()->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::comp_mode, this), OSC::instance());
167                         comp_mode ();
168                 }
169                 if (_strip->comp_makeup_controllable ()) {
170                         _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());
171                         change_message ("/select/comp_makeup", _strip->comp_makeup_controllable());
172                 }
173
174         }
175
176         tick();
177 }
178
179 OSCSelectObserver::~OSCSelectObserver ()
180 {
181         strip_connections.drop_connections ();
182         // all strip buttons should be off and faders 0 and etc.
183         if (feedback[0]) { // buttons are separate feedback
184                 send_float ("/select/expand", 0);
185                 text_message ("/select/name", " ");
186                 text_message ("/select/comment", " ");
187                 send_float ("/select/mute", 0);
188                 send_float ("/select/solo", 0);
189                 send_float ("/select/recenable", 0);
190                 send_float ("/select/record_safe", 0);
191                 send_float ("/select/monitor_input", 0);
192                 send_float ("/select/monitor_disk", 0);
193                 send_float ("/select/polarity", 0);
194                 send_float ("/select/n_inputs", 0);
195                 send_float ("/select/n_outputs", 0);
196         }
197         if (feedback[1]) { // level controls
198                 if (gainmode) {
199                         send_float ("/select/fader", 0);
200                 } else {
201                         send_float ("/select/gain", -193);
202                 }
203                 send_float ("/select/trimdB", 0);
204                 send_float ("/select/pan_stereo_position", 0.5);
205                 send_float ("/select/pan_stereo_width", 1);
206         }
207         if (feedback[9]) {
208                 send_float ("/select/signal", 0);
209         }
210         if (feedback[7]) {
211                 if (gainmode) {
212                         send_float ("/select/meter", 0);
213                 } else {
214                         send_float ("/select/meter", -193);
215                 }
216         }else if (feedback[8]) {
217                 send_float ("/select/meter", 0);
218         }
219         if (feedback[13]) { // Well known controls
220                 send_float ("/select/pan_elevation_position", 0);
221                 send_float ("/select/pan_frontback_position", .5);
222                 send_float ("/select/pan_lfe_control", 0);
223                 send_float ("/select/comp_enable", 0);
224                 send_float ("/select/comp_threshold", 0);
225                 send_float ("/select/comp_speed", 0);
226                 send_float ("/select/comp_mode", 0);
227                 text_message ("/select/comp_mode_name", " ");
228                 text_message ("/select/comp_speed_name", " ");
229                 send_float ("/select/comp_makeup", 0);
230         }
231         send_end();
232         eq_end();
233
234         lo_address_free (addr);
235 }
236
237 void
238 OSCSelectObserver::send_init()
239 {
240         // we don't know how many there are, so find out.
241         bool sends;
242         do {
243                 sends = false;
244                 if (_strip->send_level_controllable (nsends)) {
245                         _strip->send_level_controllable(nsends)->Changed.connect (send_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::send_gain, this, nsends, _strip->send_level_controllable(nsends)), OSC::instance());
246                         send_timeout.push_back (0);
247                         send_gain (nsends, _strip->send_level_controllable(nsends));
248                         sends = true;
249                 }
250
251                 if (_strip->send_enable_controllable (nsends)) {
252                         _strip->send_enable_controllable(nsends)->Changed.connect (send_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::enable_message_with_id, this, X_("/select/send_enable"), nsends + 1, _strip->send_enable_controllable(nsends)), OSC::instance());
253                         enable_message_with_id ("/select/send_enable", nsends + 1, _strip->send_enable_controllable(nsends));
254                         sends = true;
255                 } else if (sends) {
256                         boost::shared_ptr<Route> r = boost::dynamic_pointer_cast<Route> (_strip);
257                         if (!r) {
258                                 // should never get here
259                                 send_float_with_id ("/select/send_enable", nsends + 1, 0);
260                         }
261                         boost::shared_ptr<Send> snd = boost::dynamic_pointer_cast<Send> (r->nth_send(nsends));
262                         if (snd) {
263                                 boost::shared_ptr<Processor> proc = boost::dynamic_pointer_cast<Processor> (snd);
264                                 proc->ActiveChanged.connect (send_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::send_enable, this, X_("/select/send_enable"), nsends + 1, proc), OSC::instance());
265                                 send_float_with_id ("/select/send_enable", nsends + 1, proc->enabled());
266                         }
267                 }
268                 // this should get signalled by the route the send goes to, (TODO)
269                 if (!gainmode && sends) { // if the gain control is there, this is too
270                         text_with_id ("/select/send_name", nsends + 1, _strip->send_name(nsends));
271                 }
272                 // Send numbers are 0 based, OSC is 1 based so this gets incremented at the end
273                 if (sends) {
274                         nsends++;
275                 }
276         } while (sends);
277 }
278
279 void
280 OSCSelectObserver::send_end ()
281 {
282         send_connections.drop_connections ();
283         for (uint32_t i = 1; i <= nsends; i++) {
284                 if (gainmode) {
285                         send_float_with_id ("/select/send_fader", i, 0);
286                 } else {
287                         send_float_with_id ("/select/send_gain", i, -193);
288                 }
289                 // next enable
290                 send_float_with_id ("/select/send_enable", i, 0);
291                 // next name
292                 text_with_id ("/select/send_name", i, " ");
293         }
294         nsends = 0;
295 }
296
297 void
298 OSCSelectObserver::send_restart(int x)
299 {
300         send_end();
301         send_init();
302 }
303
304 void
305 OSCSelectObserver::tick ()
306 {
307         if (feedback[7] || feedback[8] || feedback[9]) { // meters enabled
308                 float now_meter;
309                 if (_strip->peak_meter()) {
310                         now_meter = _strip->peak_meter()->meter_level(0, MeterMCP);
311                 } else {
312                         now_meter = -193;
313                 }
314                 if (now_meter < -144) now_meter = -193;
315                 if (_last_meter != now_meter) {
316                         if (feedback[7] || feedback[8]) {
317                                 string path = "/select/meter";
318                                 lo_message msg = lo_message_new ();
319                                 if (gainmode && feedback[7]) {
320                                         lo_message_add_float (msg, ((now_meter + 94) / 100));
321                                         lo_send_message (addr, path.c_str(), msg);
322                                 } else if ((!gainmode) && feedback[7]) {
323                                         lo_message_add_float (msg, now_meter);
324                                         lo_send_message (addr, path.c_str(), msg);
325                                 } else if (feedback[8]) {
326                                         uint32_t ledlvl = (uint32_t)(((now_meter + 54) / 3.75)-1);
327                                         uint16_t ledbits = ~(0xfff<<ledlvl);
328                                         lo_message_add_int32 (msg, ledbits);
329                                         lo_send_message (addr, path.c_str(), msg);
330                                 }
331                                 lo_message_free (msg);
332                         }
333                         if (feedback[9]) {
334                                 string path = "/select/signal";
335                                 lo_message msg = lo_message_new ();
336                                 float signal;
337                                 if (now_meter < -40) {
338                                         signal = 0;
339                                 } else {
340                                         signal = 1;
341                                 }
342                                 lo_message_add_float (msg, signal);
343                                 lo_send_message (addr, path.c_str(), msg);
344                                 lo_message_free (msg);
345                         }
346                 }
347                 _last_meter = now_meter;
348
349         }
350         if (feedback[1]) {
351                 if (gain_timeout) {
352                         if (gain_timeout == 1) {
353                                 text_message ("/select/name", _strip->name());
354                         }
355                         gain_timeout--;
356                 }
357
358                 if (as == ARDOUR::Play ||  as == ARDOUR::Touch) {
359                         if(_last_gain != _strip->gain_control()->get_value()) {
360                                 _last_gain = _strip->gain_control()->get_value();
361                                         gain_message ();
362                         }
363                 }
364         }
365         if (feedback[13]) {
366                 if (_strip->comp_redux_controllable()) {
367                         if (_strip->comp_redux_controllable()->get_parameter()) {
368                                 send_float ("/select/comp_redux", (float) _strip->comp_redux_controllable()->get_parameter ());
369                         }
370                 }
371                 for (uint32_t i = 0; i < send_timeout.size(); i++) {
372                         if (send_timeout[i]) {
373                                 if (send_timeout[i] == 1) {
374                                         text_with_id ("/select/send_name", i + 1, _strip->send_name(i));
375                                 }
376                                 send_timeout[i]--;
377                         }
378                 }
379         }
380
381 }
382
383 void
384 OSCSelectObserver::name_changed (const PBD::PropertyChange& what_changed)
385 {
386         if (!what_changed.contains (ARDOUR::Properties::name)) {
387                 return;
388         }
389
390         if (!_strip) {
391                 return;
392         }
393
394         text_message ("/select/name", _strip->name());
395         boost::shared_ptr<Route> route = boost::dynamic_pointer_cast<Route> (_strip);
396         if (route) {
397                 //spit out the comment at the same time
398                 text_message ("/select/comment", route->comment());
399                 // lets tell the surface how many inputs this strip has
400                 send_float ("/select/n_inputs", (float) route->n_inputs().n_total());
401                 // lets tell the surface how many outputs this strip has
402                 send_float ("/select/n_outputs", (float) route->n_outputs().n_total());
403         }
404 }
405
406 void
407 OSCSelectObserver::change_message (string path, boost::shared_ptr<Controllable> controllable)
408 {
409         lo_message msg = lo_message_new ();
410         float val = controllable->get_value();
411
412         lo_message_add_float (msg, (float) controllable->internal_to_interface (val));
413
414         lo_send_message (addr, path.c_str(), msg);
415         lo_message_free (msg);
416 }
417
418 void
419 OSCSelectObserver::enable_message (string path, boost::shared_ptr<Controllable> controllable)
420 {
421         float val = controllable->get_value();
422         if (val) {
423                 send_float (path, 1);
424         } else {
425                 send_float (path, 0);
426         }
427
428 }
429
430 void
431 OSCSelectObserver::change_message_with_id (string path, uint32_t id, boost::shared_ptr<Controllable> controllable)
432 {
433         lo_message msg = lo_message_new ();
434         float val = controllable->get_value();
435         if (feedback[2]) {
436                 path = set_path (path, id);
437         } else {
438                 lo_message_add_int32 (msg, id);
439         }
440
441         lo_message_add_float (msg, (float) controllable->internal_to_interface (val));
442
443         lo_send_message (addr, path.c_str(), msg);
444         lo_message_free (msg);
445 }
446
447 void
448 OSCSelectObserver::enable_message_with_id (string path, uint32_t id, boost::shared_ptr<Controllable> controllable)
449 {
450         float val = controllable->get_value();
451         if (val) {
452                 send_float_with_id (path, id, 1);
453         } else {
454                 send_float_with_id (path, id, 0);
455         }
456 }
457
458 void
459 OSCSelectObserver::text_message (string path, std::string text)
460 {
461         lo_message msg = lo_message_new ();
462
463         lo_message_add_string (msg, text.c_str());
464
465         lo_send_message (addr, path.c_str(), msg);
466         lo_message_free (msg);
467 }
468
469 void
470 OSCSelectObserver::monitor_status (boost::shared_ptr<Controllable> controllable)
471 {
472         int disk, input;
473         float val = controllable->get_value();
474         switch ((int) val) {
475                 case 1:
476                         disk = 0;
477                         input = 1;
478                         break;
479                 case 2:
480                         disk = 1;
481                         input = 0;
482                         break;
483                 default:
484                         disk = 0;
485                         input = 0;
486         }
487
488         send_float ("/select/monitor_input", (float) input);
489         send_float ("/select/monitor_disk", (float) disk);
490 }
491
492 void
493 OSCSelectObserver::trim_message (string path, boost::shared_ptr<Controllable> controllable)
494 {
495         lo_message msg = lo_message_new ();
496
497         lo_message_add_float (msg, (float) accurate_coefficient_to_dB (controllable->get_value()));
498
499         lo_send_message (addr, path.c_str(), msg);
500         lo_message_free (msg);
501 }
502
503 void
504 OSCSelectObserver::gain_message ()
505 {
506         float value = _strip->gain_control()->get_value();
507
508         if (gainmode) {
509                 text_message ("/select/name", string_compose ("%1%2%3", std::fixed, std::setprecision(2), accurate_coefficient_to_dB (value)));
510                 gain_timeout = 8;
511                 send_float ("/select/fader", gain_to_slider_position (value));
512         } else {
513                 if (value < 1e-15) {
514                         send_float ("/select/gain", -200);
515                 } else {
516                         send_float ("/select/gain", accurate_coefficient_to_dB (value));
517                 }
518         }
519 }
520
521 void
522 OSCSelectObserver::gain_automation ()
523 {
524         float output;
525         as = _strip->gain_control()->alist()->automation_state();
526         string auto_name;
527         switch (as) {
528                 case ARDOUR::Off:
529                         output = 0;
530                         auto_name = "Manual";
531                         break;
532                 case ARDOUR::Play:
533                         output = 1;
534                         auto_name = "Play";
535                         break;
536                 case ARDOUR::Write:
537                         output = 2;
538                         auto_name = "Write";
539                         break;
540                 case ARDOUR::Touch:
541                         output = 3;
542                         auto_name = "Touch";
543                         break;
544                 default:
545                         break;
546         }
547
548         if (gainmode) {
549                 send_float ("/select/fader/automation", output);
550                 text_message ("/select/fader/automation_name", auto_name);
551         } else {
552                 send_float ("/select/gain/automation", output);
553                 text_message ("/select/gain/automation_name", auto_name);
554         }
555
556         gain_message ();
557 }
558
559 void
560 OSCSelectObserver::send_gain (uint32_t id, boost::shared_ptr<PBD::Controllable> controllable)
561 {
562         lo_message msg = lo_message_new ();
563         string path;
564         float value;
565         float db;
566 #ifdef MIXBUS
567                 db = controllable->get_value();
568 #else
569                 if (controllable->get_value() < 1e-15) {
570                         db = -193;
571                 } else {
572                         db = accurate_coefficient_to_dB (controllable->get_value());
573                 }
574 #endif
575
576         if (gainmode) {
577                 path = "/select/send_fader";
578 #ifdef MIXBUS
579                 value = controllable->internal_to_interface (controllable->get_value());
580 #else
581                 value = gain_to_slider_position (controllable->get_value());
582 #endif
583         text_with_id ("/select/send_name" , id + 1, string_compose ("%1%2%3", std::fixed, std::setprecision(2), db));
584         if (send_timeout.size() > id) {
585                 send_timeout[id] = 8;
586         }
587         } else {
588                 path = "/select/send_gain";
589                 value = db;
590         }
591
592         if (feedback[2]) {
593                 path = set_path (path, id + 1);
594         } else {
595                 lo_message_add_int32 (msg, id + 1);
596         }
597
598         lo_message_add_float (msg, value);
599         lo_send_message (addr, path.c_str(), msg);
600         lo_message_free (msg);
601 }
602
603 void
604 OSCSelectObserver::send_enable (string path, uint32_t id, boost::shared_ptr<Processor> proc)
605 {
606         // with no delay value is wrong
607         Glib::usleep(10);
608
609         send_float_with_id ("/select/send_enable", id, proc->enabled());
610 }
611
612 void
613 OSCSelectObserver::text_with_id (string path, uint32_t id, string name)
614 {
615         lo_message msg = lo_message_new ();
616         if (feedback[2]) {
617                 path = set_path (path, id);
618         } else {
619                 lo_message_add_int32 (msg, id);
620         }
621
622         lo_message_add_string (msg, name.c_str());
623
624         lo_send_message (addr, path.c_str(), msg);
625         lo_message_free (msg);
626 }
627
628 void
629 OSCSelectObserver::comp_mode ()
630 {
631         change_message ("/select/comp_mode", _strip->comp_mode_controllable());
632         text_message ("/select/comp_mode_name", _strip->comp_mode_name(_strip->comp_mode_controllable()->get_value()));
633         text_message ("/select/comp_speed_name", _strip->comp_speed_name(_strip->comp_mode_controllable()->get_value()));
634 }
635
636 void
637 OSCSelectObserver::eq_init()
638 {
639         // HPF and enable are special case, rest are in bands
640         if (_strip->filter_enable_controllable (true)) {
641                 _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());
642                 change_message ("/select/eq_hpf/enable", _strip->filter_enable_controllable(true));
643         }
644
645         if (_strip->filter_enable_controllable (false)) {
646                 _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());
647                 change_message ("/select/eq_lpf/enable", _strip->filter_enable_controllable(false));
648         }
649
650         if (_strip->filter_freq_controllable (true)) {
651                 _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());
652                 change_message ("/select/eq_hpf/freq", _strip->filter_freq_controllable(true));
653         }
654
655         if (_strip->filter_freq_controllable (false)) {
656                 _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());
657                 change_message ("/select/eq_lpf/freq", _strip->filter_freq_controllable(false));
658         }
659
660         if (_strip->filter_slope_controllable (true)) {
661                 _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());
662                 change_message ("/select/eq_hpf/slope", _strip->filter_slope_controllable(true));
663         }
664
665         if (_strip->filter_slope_controllable (false)) {
666                 _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());
667                 change_message ("/select/eq_lpf/slope", _strip->filter_slope_controllable(false));
668         }
669
670         if (_strip->eq_enable_controllable ()) {
671                 _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());
672                 enable_message ("/select/eq_enable", _strip->eq_enable_controllable());
673         }
674
675         uint32_t eq_bands = _strip->eq_band_cnt ();
676         if (!eq_bands) {
677                 return;
678         }
679
680         for (uint32_t i = 0; i < eq_bands; i++) {
681                 if (_strip->eq_band_name(i).size()) {
682                         text_with_id ("/select/eq_band_name", i + 1, _strip->eq_band_name (i));
683                 }
684                 if (_strip->eq_gain_controllable (i)) {
685                         _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());
686                         change_message_with_id ("/select/eq_gain", i + 1, _strip->eq_gain_controllable(i));
687                 }
688                 if (_strip->eq_freq_controllable (i)) {
689                         _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());
690                         change_message_with_id ("/select/eq_freq", i + 1, _strip->eq_freq_controllable(i));
691                 }
692                 if (_strip->eq_q_controllable (i)) {
693                         _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());
694                         change_message_with_id ("/select/eq_q", i + 1, _strip->eq_q_controllable(i));
695                 }
696                 if (_strip->eq_shape_controllable (i)) {
697                         _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());
698                         change_message_with_id ("/select/eq_shape", i + 1, _strip->eq_shape_controllable(i));
699                 }
700         }
701 }
702
703 void
704 OSCSelectObserver::eq_end ()
705 {
706         //need to check feedback for [13]
707         eq_connections.drop_connections ();
708         if (_strip->filter_freq_controllable (true)) {
709                 send_float ("/select/eq_hpf", 0);
710         }
711         if (_strip->eq_enable_controllable ()) {
712                 send_float ("/select/eq_enable", 0);
713         }
714
715         for (uint32_t i = 1; i <= _strip->eq_band_cnt (); i++) {
716                 text_with_id ("/select/eq_band_name", i, " ");
717                 send_float_with_id ("/select/eq_gain", i, 0);
718                 send_float_with_id ("/select/eq_freq", i, 0);
719                 send_float_with_id ("/select/eq_q", i, 0);
720                 send_float_with_id ("/select/eq_shape", i, 0);
721
722
723         }
724 }
725
726 void
727 OSCSelectObserver::eq_restart(int x)
728 {
729         eq_end();
730         eq_init();
731 }
732
733 string
734 OSCSelectObserver::set_path (string path, uint32_t id)
735 {
736         if (feedback[2]) {
737                 path = string_compose ("%1/%2", path, id);
738         }
739         return path;
740 }
741
742 void
743 OSCSelectObserver::send_float (string path, float val)
744 {
745         lo_message msg = lo_message_new ();
746         lo_message_add_float (msg, val);
747
748         lo_send_message (addr, path.c_str(), msg);
749         lo_message_free (msg);
750
751 }
752
753 void
754 OSCSelectObserver::send_float_with_id (string path, uint32_t id, float val)
755 {
756         lo_message msg = lo_message_new ();
757         if (feedback[2]) {
758                 path = set_path (path, id);
759         } else {
760                 lo_message_add_int32 (msg, id);
761         }
762
763         lo_message_add_float (msg, val);
764
765         lo_send_message (addr, path.c_str(), msg);
766         lo_message_free (msg);
767
768 }
769