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