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