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