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