OSC: issue 7116 fix send enable not working
[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
35 #include "osc.h"
36 #include "osc_select_observer.h"
37
38 #include "pbd/i18n.h"
39
40 using namespace std;
41 using namespace PBD;
42 using namespace ARDOUR;
43 using namespace ArdourSurface;
44
45 OSCSelectObserver::OSCSelectObserver (boost::shared_ptr<Stripable> s, lo_address a, uint32_t gm, std::bitset<32> fb)
46         : _strip (s)
47         ,gainmode (gm)
48         ,feedback (fb)
49         ,nsends (0)
50 {
51         addr = lo_address_new (lo_address_get_hostname(a) , lo_address_get_port(a));
52
53         if (feedback[0]) { // buttons are separate feedback
54                 _strip->PropertyChanged.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::name_changed, this, boost::lambda::_1), OSC::instance());
55                 name_changed (ARDOUR::Properties::name);
56
57                 _strip->mute_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::change_message, this, X_("/select/mute"), _strip->mute_control()), OSC::instance());
58                 change_message ("/select/mute", _strip->mute_control());
59
60                 _strip->solo_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::change_message, this, X_("/select/solo"), _strip->solo_control()), OSC::instance());
61                 change_message ("/select/solo", _strip->solo_control());
62
63                 if (_strip->solo_isolate_control()) {
64                         _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());
65                         change_message ("/select/solo_iso", _strip->solo_isolate_control());
66                 }
67
68                 if (_strip->solo_safe_control()) {
69                         _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());
70                         change_message ("/select/solo_safe", _strip->solo_safe_control());
71                 }
72
73                 boost::shared_ptr<Track> track = boost::dynamic_pointer_cast<Track> (_strip);
74                 if (track) {
75                         track->monitoring_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::monitor_status, this, track->monitoring_control()), OSC::instance());
76                         monitor_status (track->monitoring_control());
77                 }
78
79                 boost::shared_ptr<AutomationControl> rec_controllable = _strip->rec_enable_control ();
80                 if (rec_controllable) {
81                         rec_controllable->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::change_message, this, X_("/select/recenable"), _strip->rec_enable_control()), OSC::instance());
82                         change_message ("/select/recenable", _strip->rec_enable_control());
83                 }
84
85                 boost::shared_ptr<AutomationControl> recsafe_controllable = _strip->rec_safe_control ();
86                 if (recsafe_controllable) {
87                         recsafe_controllable->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::change_message, this, X_("/select/record_safe"), _strip->rec_safe_control()), OSC::instance());
88                         change_message ("/select/record_safe", _strip->rec_safe_control());
89                 }
90
91                 boost::shared_ptr<AutomationControl> phase_controllable = _strip->phase_control ();
92                 if (phase_controllable) {
93                         phase_controllable->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::change_message, this, X_("/select/polarity"), _strip->phase_control()), OSC::instance());
94                         change_message ("/select/polarity", _strip->phase_control());
95                 }
96
97         }
98
99         if (feedback[1]) { // level controls
100                 if (gainmode) {
101                         _strip->gain_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::gain_message, this, X_("/select/fader"), _strip->gain_control()), OSC::instance());
102                         gain_message ("/select/fader", _strip->gain_control());
103                 } else {
104                         _strip->gain_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::gain_message, this, X_("/select/gain"), _strip->gain_control()), OSC::instance());
105                         gain_message ("/select/gain", _strip->gain_control());
106                 }
107
108                 boost::shared_ptr<Controllable> trim_controllable = boost::dynamic_pointer_cast<Controllable>(_strip->trim_control());
109                 if (trim_controllable) {
110                         trim_controllable->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::trim_message, this, X_("/select/trimdB"), _strip->trim_control()), OSC::instance());
111                         trim_message ("/select/trimdB", _strip->trim_control());
112                 }
113
114                 boost::shared_ptr<Controllable> pan_controllable = boost::dynamic_pointer_cast<Controllable>(_strip->pan_azimuth_control());
115                 if (pan_controllable) {
116                         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());
117                         change_message ("/select/pan_stereo_position", _strip->pan_azimuth_control());
118                 }
119
120                 boost::shared_ptr<Controllable> width_controllable = boost::dynamic_pointer_cast<Controllable>(_strip->pan_width_control());
121                 if (width_controllable) {
122                         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());
123                         change_message ("/select/pan_stereo_width", _strip->pan_width_control());
124                 }
125
126         }
127         if (feedback[13]) { // Well known controls
128                 // Rest of possible pan controls... Untested because I can't find a way to get them in the GUI :)
129                 if (_strip->pan_elevation_control ()) {
130                         _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());
131                         change_message ("/select/pan_elevation_position", _strip->pan_elevation_control());
132                 }
133                 if (_strip->pan_frontback_control ()) {
134                         _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());
135                         change_message ("/select/pan_frontback_position", _strip->pan_frontback_control());
136                 }
137                 if (_strip->pan_lfe_control ()) {
138                         _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());
139                         change_message ("/select/pan_lfe_control", _strip->pan_lfe_control());
140                 }
141
142                 // sends and eq
143                 // detecting processor changes requires cast to route
144                 boost::shared_ptr<Route> r = boost::dynamic_pointer_cast<Route>(_strip);
145                 if (r) {
146                         r->processors_changed.connect  (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::send_restart, this, -1), OSC::instance());
147                         send_init();
148                         eq_init();
149                 }
150
151                 // Compressor
152                 if (_strip->comp_enable_controllable ()) {
153                         _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());
154                         enable_message ("/select/comp_enable", _strip->comp_enable_controllable());
155                 }
156                 if (_strip->comp_threshold_controllable ()) {
157                         _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());
158                         change_message ("/select/comp_threshold", _strip->comp_threshold_controllable());
159                 }
160                 if (_strip->comp_speed_controllable ()) {
161                         _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());
162                         change_message ("/select/comp_speed", _strip->comp_speed_controllable());
163                 }
164                 if (_strip->comp_mode_controllable ()) {
165                         _strip->comp_mode_controllable ()->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::comp_mode, this), OSC::instance());
166                         comp_mode ();
167                 }
168                 if (_strip->comp_makeup_controllable ()) {
169                         _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());
170                         change_message ("/select/comp_makeup", _strip->comp_makeup_controllable());
171                 }
172
173         }
174
175         tick();
176 }
177
178 OSCSelectObserver::~OSCSelectObserver ()
179 {
180
181         strip_connections.drop_connections ();
182         // all strip buttons should be off and faders 0 and etc.
183         clear_strip ("/select/expand", 0);
184         if (feedback[0]) { // buttons are separate feedback
185                 text_message ("/select/name", " ");
186                 text_message ("/select/comment", " ");
187                 clear_strip ("/select/mute", 0);
188                 clear_strip ("/select/solo", 0);
189                 clear_strip ("/select/recenable", 0);
190                 clear_strip ("/select/record_safe", 0);
191                 clear_strip ("/select/monitor_input", 0);
192                 clear_strip ("/select/monitor_disk", 0);
193                 clear_strip ("/select/polarity", 0);
194                 clear_strip ("/select/n_inputs", 0);
195                 clear_strip ("/select/n_outputs", 0);
196         }
197         if (feedback[1]) { // level controls
198                 if (gainmode) {
199                         clear_strip ("/select/fader", 0);
200                 } else {
201                         clear_strip ("/select/gain", -193);
202                 }
203                 clear_strip ("/select/trimdB", 0);
204                 clear_strip ("/select/pan_stereo_position", 0.5);
205                 clear_strip ("/select/pan_stereo_width", 1);
206         }
207         if (feedback[9]) {
208                 clear_strip ("/select/signal", 0);
209         }
210         if (feedback[7]) {
211                 if (gainmode) {
212                         clear_strip ("/select/meter", 0);
213                 } else {
214                         clear_strip ("/select/meter", -193);
215                 }
216         }else if (feedback[8]) {
217                 clear_strip ("/select/meter", 0);
218         }
219         if (feedback[13]) { // Well known controls
220                 clear_strip ("/select/pan_elevation_position", 0);
221                 clear_strip ("/select/pan_frontback_position", .5);
222                 clear_strip ("/select/pan_lfe_control", 0);
223                 clear_strip ("/select/comp_enable", 0);
224                 clear_strip ("/select/comp_threshold", 0);
225                 clear_strip ("/select/comp_speed", 0);
226                 clear_strip ("/select/comp_mode", 0);
227                 text_message ("/select/comp_mode_name", " ");
228                 text_message ("/select/comp_speed_name", " ");
229                 clear_strip ("/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 (strip_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 (strip_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                                 clear_strip_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 (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::send_enable, this, X_("/select/send_enable"), nsends + 1, proc), OSC::instance());
265                                 clear_strip_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                         clear_strip_with_id ("/select/send_fader", i, 0);
286                 } else {
287                         clear_strip_with_id ("/select/send_gain", i, -193);
288                 }
289                 // next enable
290                 clear_strip_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 (feedback[13]) {
359                 for (uint32_t i = 0; i < send_timeout.size(); i++) {
360                         if (send_timeout[i]) {
361                                 if (send_timeout[i] == 1) {
362                                         text_with_id ("/select/send_name", i + 1, _strip->send_name(i));
363                                 }
364                                 send_timeout[i]--;
365                         }
366                 }
367         }
368
369 }
370
371 void
372 OSCSelectObserver::name_changed (const PBD::PropertyChange& what_changed)
373 {
374         if (!what_changed.contains (ARDOUR::Properties::name)) {
375                 return;
376         }
377
378         if (!_strip) {
379                 return;
380         }
381
382         text_message ("/select/name", _strip->name());
383         boost::shared_ptr<Route> route = boost::dynamic_pointer_cast<Route> (_strip);
384         if (route) {
385                 //spit out the comment at the same time
386                 text_message ("/select/comment", route->comment());
387                 // lets tell the surface how many inputs this strip has
388                 clear_strip ("/select/n_inputs", (float) route->n_inputs().n_total());
389                 // lets tell the surface how many outputs this strip has
390                 clear_strip ("/select/n_outputs", (float) route->n_outputs().n_total());
391         }
392 }
393
394 void
395 OSCSelectObserver::change_message (string path, boost::shared_ptr<Controllable> controllable)
396 {
397         lo_message msg = lo_message_new ();
398         float val = controllable->get_value();
399
400         lo_message_add_float (msg, (float) controllable->internal_to_interface (val));
401
402         lo_send_message (addr, path.c_str(), msg);
403         lo_message_free (msg);
404 }
405
406 void
407 OSCSelectObserver::enable_message (string path, boost::shared_ptr<Controllable> controllable)
408 {
409         float val = controllable->get_value();
410         if (val) {
411                 clear_strip (path, 1);
412         } else {
413                 clear_strip (path, 0);
414         }
415
416 }
417
418 void
419 OSCSelectObserver::change_message_with_id (string path, uint32_t id, boost::shared_ptr<Controllable> controllable)
420 {
421         lo_message msg = lo_message_new ();
422         float val = controllable->get_value();
423         if (feedback[2]) {
424                 path = set_path (path, id);
425         } else {
426                 lo_message_add_int32 (msg, id);
427         }
428
429         lo_message_add_float (msg, (float) controllable->internal_to_interface (val));
430
431         lo_send_message (addr, path.c_str(), msg);
432         lo_message_free (msg);
433 }
434
435 void
436 OSCSelectObserver::enable_message_with_id (string path, uint32_t id, boost::shared_ptr<Controllable> controllable)
437 {
438         float val = controllable->get_value();
439         if (val) {
440                 clear_strip_with_id (path, id, 1);
441         } else {
442                 clear_strip_with_id (path, id, 0);
443         }
444 }
445
446 void
447 OSCSelectObserver::text_message (string path, std::string text)
448 {
449         lo_message msg = lo_message_new ();
450
451         lo_message_add_string (msg, text.c_str());
452
453         lo_send_message (addr, path.c_str(), msg);
454         lo_message_free (msg);
455 }
456
457 void
458 OSCSelectObserver::monitor_status (boost::shared_ptr<Controllable> controllable)
459 {
460         int disk, input;
461         float val = controllable->get_value();
462         switch ((int) val) {
463                 case 1:
464                         disk = 0;
465                         input = 1;
466                         break;
467                 case 2:
468                         disk = 1;
469                         input = 0;
470                         break;
471                 default:
472                         disk = 0;
473                         input = 0;
474         }
475
476         clear_strip ("/select/monitor_input", (float) input);
477         clear_strip ("/select/monitor_disk", (float) disk);
478 }
479
480 void
481 OSCSelectObserver::trim_message (string path, boost::shared_ptr<Controllable> controllable)
482 {
483         lo_message msg = lo_message_new ();
484
485         lo_message_add_float (msg, (float) accurate_coefficient_to_dB (controllable->get_value()));
486
487         lo_send_message (addr, path.c_str(), msg);
488         lo_message_free (msg);
489 }
490
491 void
492 OSCSelectObserver::gain_message (string path, boost::shared_ptr<Controllable> controllable)
493 {
494         lo_message msg = lo_message_new ();
495
496         if (gainmode) {
497                 lo_message_add_float (msg, gain_to_slider_position (controllable->get_value()));
498                 text_message ("/select/name", string_compose ("%1%2%3", std::fixed, std::setprecision(2), accurate_coefficient_to_dB (controllable->get_value())));
499                 gain_timeout = 8;
500         } else {
501                 if (controllable->get_value() < 1e-15) {
502                         lo_message_add_float (msg, -200);
503                 } else {
504                         lo_message_add_float (msg, accurate_coefficient_to_dB (controllable->get_value()));
505                 }
506         }
507
508         lo_send_message (addr, path.c_str(), msg);
509         lo_message_free (msg);
510 }
511
512 void
513 OSCSelectObserver::send_gain (uint32_t id, boost::shared_ptr<PBD::Controllable> controllable)
514 {
515         lo_message msg = lo_message_new ();
516         string path;
517         float value;
518         float db;
519 #ifdef MIXBUS
520                 db = controllable->get_value();
521 #else
522                 if (controllable->get_value() < 1e-15) {
523                         db = -193;
524                 } else {
525                         db = accurate_coefficient_to_dB (controllable->get_value());
526                 }
527 #endif
528
529         if (gainmode) {
530                 path = "/select/send_fader";
531 #ifdef MIXBUS
532                 value = controllable->internal_to_interface (controllable->get_value());
533 #else
534                 value = gain_to_slider_position (controllable->get_value());
535 #endif
536         text_with_id ("/select/send_name" , id + 1, string_compose ("%1%2%3", std::fixed, std::setprecision(2), db));
537         if (send_timeout.size() > id) {
538                 send_timeout[id] = 8;
539         }
540         } else {
541                 path = "/select/send_gain";
542                 value = db;
543         }
544
545         if (feedback[2]) {
546                 path = set_path (path, id + 1);
547         } else {
548                 lo_message_add_int32 (msg, id + 1);
549         }
550
551         lo_message_add_float (msg, value);
552         lo_send_message (addr, path.c_str(), msg);
553         lo_message_free (msg);
554 }
555
556 void
557 OSCSelectObserver::send_enable (string path, uint32_t id, boost::shared_ptr<Processor> proc)
558 {
559         // with no delay value is wrong
560         usleep(10);
561
562         clear_strip_with_id ("/select/send_enable", id, proc->enabled());
563 }
564
565 void
566 OSCSelectObserver::text_with_id (string path, uint32_t id, string name)
567 {
568         lo_message msg = lo_message_new ();
569         if (feedback[2]) {
570                 path = set_path (path, id);
571         } else {
572                 lo_message_add_int32 (msg, id);
573         }
574
575         lo_message_add_string (msg, name.c_str());
576
577         lo_send_message (addr, path.c_str(), msg);
578         lo_message_free (msg);
579 }
580
581 void
582 OSCSelectObserver::comp_mode ()
583 {
584         change_message ("/select/comp_mode", _strip->comp_mode_controllable());
585         text_message ("/select/comp_mode_name", _strip->comp_mode_name(_strip->comp_mode_controllable()->get_value()));
586         text_message ("/select/comp_speed_name", _strip->comp_speed_name(_strip->comp_mode_controllable()->get_value()));
587 }
588
589 void
590 OSCSelectObserver::eq_init()
591 {
592         // HPF and enable are special case, rest are in bands
593         if (_strip->eq_hpf_controllable ()) {
594                 _strip->eq_hpf_controllable ()->Changed.connect (eq_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::change_message, this, X_("/select/eq_hpf"), _strip->eq_hpf_controllable()), OSC::instance());
595                 change_message ("/select/eq_hpf", _strip->eq_hpf_controllable());
596         }
597         if (_strip->eq_enable_controllable ()) {
598                 _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());
599                 enable_message ("/select/eq_enable", _strip->eq_enable_controllable());
600         }
601
602         uint32_t eq_bands = _strip->eq_band_cnt ();
603         if (!eq_bands) {
604                 return;
605         }
606
607         for (uint32_t i = 0; i < eq_bands; i++) {
608                 if (_strip->eq_band_name(i).size()) {
609                         text_with_id ("/select/eq_band_name", i + 1, _strip->eq_band_name (i));
610                 }
611                 if (_strip->eq_gain_controllable (i)) {
612                         _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());
613                         change_message_with_id ("/select/eq_gain", i + 1, _strip->eq_gain_controllable(i));
614                 }
615                 if (_strip->eq_freq_controllable (i)) {
616                         _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());
617                         change_message_with_id ("/select/eq_freq", i + 1, _strip->eq_freq_controllable(i));
618                 }
619                 if (_strip->eq_q_controllable (i)) {
620                         _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());
621                         change_message_with_id ("/select/eq_q", i + 1, _strip->eq_q_controllable(i));
622                 }
623                 if (_strip->eq_shape_controllable (i)) {
624                         _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());
625                         change_message_with_id ("/select/eq_shape", i + 1, _strip->eq_shape_controllable(i));
626                 }
627         }
628 }
629
630 void
631 OSCSelectObserver::eq_end ()
632 {
633         //need to check feedback for [13]
634         eq_connections.drop_connections ();
635         clear_strip ("/select/eq_hpf", 0);
636         clear_strip ("/select/eq_enable", 0);
637
638         for (uint32_t i = 1; i <= _strip->eq_band_cnt (); i++) {
639                 text_with_id ("/select/eq_band_name", i, " ");
640                 clear_strip_with_id ("/select/eq_gain", i, 0);
641                 clear_strip_with_id ("/select/eq_freq", i, 0);
642                 clear_strip_with_id ("/select/eq_q", i, 0);
643                 clear_strip_with_id ("/select/eq_shape", i, 0);
644
645
646         }
647 }
648
649 void
650 OSCSelectObserver::eq_restart(int x)
651 {
652         eq_end();
653         eq_init();
654 }
655
656 string
657 OSCSelectObserver::set_path (string path, uint32_t id)
658 {
659         if (feedback[2]) {
660                 path = string_compose ("%1/%2", path, id);
661         }
662         return path;
663 }
664
665 void
666 OSCSelectObserver::clear_strip (string path, float val)
667 {
668         lo_message msg = lo_message_new ();
669         lo_message_add_float (msg, val);
670
671         lo_send_message (addr, path.c_str(), msg);
672         lo_message_free (msg);
673
674 }
675
676 void
677 OSCSelectObserver::clear_strip_with_id (string path, uint32_t id, float val)
678 {
679         lo_message msg = lo_message_new ();
680         if (feedback[2]) {
681                 path = set_path (path, id);
682         } else {
683                 lo_message_add_int32 (msg, id);
684         }
685
686         lo_message_add_float (msg, val);
687
688         lo_send_message (addr, path.c_str(), msg);
689         lo_message_free (msg);
690
691 }
692