OSC add feedback for extra comp and eq controls
[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_enable_controllable()->get_value()) {
367                         send_float ("/select/comp_redux", (float) _strip->comp_redux_controllable()->get_parameter ());
368                 }
369                 for (uint32_t i = 0; i < send_timeout.size(); i++) {
370                         if (send_timeout[i]) {
371                                 if (send_timeout[i] == 1) {
372                                         text_with_id ("/select/send_name", i + 1, _strip->send_name(i));
373                                 }
374                                 send_timeout[i]--;
375                         }
376                 }
377         }
378
379 }
380
381 void
382 OSCSelectObserver::name_changed (const PBD::PropertyChange& what_changed)
383 {
384         if (!what_changed.contains (ARDOUR::Properties::name)) {
385                 return;
386         }
387
388         if (!_strip) {
389                 return;
390         }
391
392         text_message ("/select/name", _strip->name());
393         boost::shared_ptr<Route> route = boost::dynamic_pointer_cast<Route> (_strip);
394         if (route) {
395                 //spit out the comment at the same time
396                 text_message ("/select/comment", route->comment());
397                 // lets tell the surface how many inputs this strip has
398                 send_float ("/select/n_inputs", (float) route->n_inputs().n_total());
399                 // lets tell the surface how many outputs this strip has
400                 send_float ("/select/n_outputs", (float) route->n_outputs().n_total());
401         }
402 }
403
404 void
405 OSCSelectObserver::change_message (string path, boost::shared_ptr<Controllable> controllable)
406 {
407         lo_message msg = lo_message_new ();
408         float val = controllable->get_value();
409
410         lo_message_add_float (msg, (float) controllable->internal_to_interface (val));
411
412         lo_send_message (addr, path.c_str(), msg);
413         lo_message_free (msg);
414 }
415
416 void
417 OSCSelectObserver::enable_message (string path, boost::shared_ptr<Controllable> controllable)
418 {
419         float val = controllable->get_value();
420         if (val) {
421                 send_float (path, 1);
422         } else {
423                 send_float (path, 0);
424         }
425
426 }
427
428 void
429 OSCSelectObserver::change_message_with_id (string path, uint32_t id, boost::shared_ptr<Controllable> controllable)
430 {
431         lo_message msg = lo_message_new ();
432         float val = controllable->get_value();
433         if (feedback[2]) {
434                 path = set_path (path, id);
435         } else {
436                 lo_message_add_int32 (msg, id);
437         }
438
439         lo_message_add_float (msg, (float) controllable->internal_to_interface (val));
440
441         lo_send_message (addr, path.c_str(), msg);
442         lo_message_free (msg);
443 }
444
445 void
446 OSCSelectObserver::enable_message_with_id (string path, uint32_t id, boost::shared_ptr<Controllable> controllable)
447 {
448         float val = controllable->get_value();
449         if (val) {
450                 send_float_with_id (path, id, 1);
451         } else {
452                 send_float_with_id (path, id, 0);
453         }
454 }
455
456 void
457 OSCSelectObserver::text_message (string path, std::string text)
458 {
459         lo_message msg = lo_message_new ();
460
461         lo_message_add_string (msg, text.c_str());
462
463         lo_send_message (addr, path.c_str(), msg);
464         lo_message_free (msg);
465 }
466
467 void
468 OSCSelectObserver::monitor_status (boost::shared_ptr<Controllable> controllable)
469 {
470         int disk, input;
471         float val = controllable->get_value();
472         switch ((int) val) {
473                 case 1:
474                         disk = 0;
475                         input = 1;
476                         break;
477                 case 2:
478                         disk = 1;
479                         input = 0;
480                         break;
481                 default:
482                         disk = 0;
483                         input = 0;
484         }
485
486         send_float ("/select/monitor_input", (float) input);
487         send_float ("/select/monitor_disk", (float) disk);
488 }
489
490 void
491 OSCSelectObserver::trim_message (string path, boost::shared_ptr<Controllable> controllable)
492 {
493         lo_message msg = lo_message_new ();
494
495         lo_message_add_float (msg, (float) accurate_coefficient_to_dB (controllable->get_value()));
496
497         lo_send_message (addr, path.c_str(), msg);
498         lo_message_free (msg);
499 }
500
501 void
502 OSCSelectObserver::gain_message ()
503 {
504         float value = _strip->gain_control()->get_value();
505
506         if (gainmode) {
507                 text_message ("/select/name", string_compose ("%1%2%3", std::fixed, std::setprecision(2), accurate_coefficient_to_dB (value)));
508                 gain_timeout = 8;
509                 send_float ("/select/fader", gain_to_slider_position (value));
510         } else {
511                 if (value < 1e-15) {
512                         send_float ("/select/gain", -200);
513                 } else {
514                         send_float ("/select/gain", accurate_coefficient_to_dB (value));
515                 }
516         }
517 }
518
519 void
520 OSCSelectObserver::gain_automation ()
521 {
522         float output;
523         as = _strip->gain_control()->alist()->automation_state();
524         string auto_name;
525         switch (as) {
526                 case ARDOUR::Off:
527                         output = 0;
528                         auto_name = "Manual";
529                         break;
530                 case ARDOUR::Play:
531                         output = 1;
532                         auto_name = "Play";
533                         break;
534                 case ARDOUR::Write:
535                         output = 2;
536                         auto_name = "Write";
537                         break;
538                 case ARDOUR::Touch:
539                         output = 3;
540                         auto_name = "Touch";
541                         break;
542                 default:
543                         break;
544         }
545
546         if (gainmode) {
547                 send_float ("/select/fader/automation", output);
548                 text_message ("/select/fader/automation_name", auto_name);
549         } else {
550                 send_float ("/select/gain/automation", output);
551                 text_message ("/select/gain/automation_name", auto_name);
552         }
553
554         gain_message ();
555 }
556
557 void
558 OSCSelectObserver::send_gain (uint32_t id, boost::shared_ptr<PBD::Controllable> controllable)
559 {
560         lo_message msg = lo_message_new ();
561         string path;
562         float value;
563         float db;
564 #ifdef MIXBUS
565                 db = controllable->get_value();
566 #else
567                 if (controllable->get_value() < 1e-15) {
568                         db = -193;
569                 } else {
570                         db = accurate_coefficient_to_dB (controllable->get_value());
571                 }
572 #endif
573
574         if (gainmode) {
575                 path = "/select/send_fader";
576 #ifdef MIXBUS
577                 value = controllable->internal_to_interface (controllable->get_value());
578 #else
579                 value = gain_to_slider_position (controllable->get_value());
580 #endif
581         text_with_id ("/select/send_name" , id + 1, string_compose ("%1%2%3", std::fixed, std::setprecision(2), db));
582         if (send_timeout.size() > id) {
583                 send_timeout[id] = 8;
584         }
585         } else {
586                 path = "/select/send_gain";
587                 value = db;
588         }
589
590         if (feedback[2]) {
591                 path = set_path (path, id + 1);
592         } else {
593                 lo_message_add_int32 (msg, id + 1);
594         }
595
596         lo_message_add_float (msg, value);
597         lo_send_message (addr, path.c_str(), msg);
598         lo_message_free (msg);
599 }
600
601 void
602 OSCSelectObserver::send_enable (string path, uint32_t id, boost::shared_ptr<Processor> proc)
603 {
604         // with no delay value is wrong
605         Glib::usleep(10);
606
607         send_float_with_id ("/select/send_enable", id, proc->enabled());
608 }
609
610 void
611 OSCSelectObserver::text_with_id (string path, uint32_t id, string name)
612 {
613         lo_message msg = lo_message_new ();
614         if (feedback[2]) {
615                 path = set_path (path, id);
616         } else {
617                 lo_message_add_int32 (msg, id);
618         }
619
620         lo_message_add_string (msg, name.c_str());
621
622         lo_send_message (addr, path.c_str(), msg);
623         lo_message_free (msg);
624 }
625
626 void
627 OSCSelectObserver::comp_mode ()
628 {
629         change_message ("/select/comp_mode", _strip->comp_mode_controllable());
630         text_message ("/select/comp_mode_name", _strip->comp_mode_name(_strip->comp_mode_controllable()->get_value()));
631         text_message ("/select/comp_speed_name", _strip->comp_speed_name(_strip->comp_mode_controllable()->get_value()));
632 }
633
634 void
635 OSCSelectObserver::eq_init()
636 {
637         // HPF and enable are special case, rest are in bands
638         if (_strip->filter_enable_controllable (true)) {
639                 _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());
640                 change_message ("/select/eq_hpf/enable", _strip->filter_enable_controllable(true));
641         }
642
643         if (_strip->filter_enable_controllable (false)) {
644                 _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());
645                 change_message ("/select/eq_lpf/enable", _strip->filter_enable_controllable(false));
646         }
647
648         if (_strip->filter_freq_controllable (true)) {
649                 _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());
650                 change_message ("/select/eq_hpf/freq", _strip->filter_freq_controllable(true));
651         }
652
653         if (_strip->filter_freq_controllable (false)) {
654                 _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());
655                 change_message ("/select/eq_lpf/freq", _strip->filter_freq_controllable(false));
656         }
657
658         if (_strip->filter_slope_controllable (true)) {
659                 _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());
660                 change_message ("/select/eq_hpf/slope", _strip->filter_slope_controllable(true));
661         }
662
663         if (_strip->filter_slope_controllable (false)) {
664                 _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());
665                 change_message ("/select/eq_lpf/slope", _strip->filter_slope_controllable(false));
666         }
667
668         if (_strip->eq_enable_controllable ()) {
669                 _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());
670                 enable_message ("/select/eq_enable", _strip->eq_enable_controllable());
671         }
672
673         uint32_t eq_bands = _strip->eq_band_cnt ();
674         if (!eq_bands) {
675                 return;
676         }
677
678         for (uint32_t i = 0; i < eq_bands; i++) {
679                 if (_strip->eq_band_name(i).size()) {
680                         text_with_id ("/select/eq_band_name", i + 1, _strip->eq_band_name (i));
681                 }
682                 if (_strip->eq_gain_controllable (i)) {
683                         _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());
684                         change_message_with_id ("/select/eq_gain", i + 1, _strip->eq_gain_controllable(i));
685                 }
686                 if (_strip->eq_freq_controllable (i)) {
687                         _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());
688                         change_message_with_id ("/select/eq_freq", i + 1, _strip->eq_freq_controllable(i));
689                 }
690                 if (_strip->eq_q_controllable (i)) {
691                         _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());
692                         change_message_with_id ("/select/eq_q", i + 1, _strip->eq_q_controllable(i));
693                 }
694                 if (_strip->eq_shape_controllable (i)) {
695                         _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());
696                         change_message_with_id ("/select/eq_shape", i + 1, _strip->eq_shape_controllable(i));
697                 }
698         }
699 }
700
701 void
702 OSCSelectObserver::eq_end ()
703 {
704         //need to check feedback for [13]
705         eq_connections.drop_connections ();
706         if (_strip->filter_freq_controllable (true)) {
707                 send_float ("/select/eq_hpf", 0);
708         }
709         if (_strip->eq_enable_controllable ()) {
710                 send_float ("/select/eq_enable", 0);
711         }
712
713         for (uint32_t i = 1; i <= _strip->eq_band_cnt (); i++) {
714                 text_with_id ("/select/eq_band_name", i, " ");
715                 send_float_with_id ("/select/eq_gain", i, 0);
716                 send_float_with_id ("/select/eq_freq", i, 0);
717                 send_float_with_id ("/select/eq_q", i, 0);
718                 send_float_with_id ("/select/eq_shape", i, 0);
719
720
721         }
722 }
723
724 void
725 OSCSelectObserver::eq_restart(int x)
726 {
727         eq_end();
728         eq_init();
729 }
730
731 string
732 OSCSelectObserver::set_path (string path, uint32_t id)
733 {
734         if (feedback[2]) {
735                 path = string_compose ("%1/%2", path, id);
736         }
737         return path;
738 }
739
740 void
741 OSCSelectObserver::send_float (string path, float val)
742 {
743         lo_message msg = lo_message_new ();
744         lo_message_add_float (msg, val);
745
746         lo_send_message (addr, path.c_str(), msg);
747         lo_message_free (msg);
748
749 }
750
751 void
752 OSCSelectObserver::send_float_with_id (string path, uint32_t id, float val)
753 {
754         lo_message msg = lo_message_new ();
755         if (feedback[2]) {
756                 path = set_path (path, id);
757         } else {
758                 lo_message_add_int32 (msg, id);
759         }
760
761         lo_message_add_float (msg, val);
762
763         lo_send_message (addr, path.c_str(), msg);
764         lo_message_free (msg);
765
766 }
767