noop OSC: path strings should not get tranlated
[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 "pbd/control_math.h"
24
25 #include "ardour/session.h"
26 #include "ardour/track.h"
27 #include "ardour/monitor_control.h"
28 #include "ardour/dB.h"
29 #include "ardour/meter.h"
30 #include "ardour/phase_control.h"
31 #include "ardour/solo_isolate_control.h"
32 #include "ardour/solo_safe_control.h"
33 #include "ardour/route.h"
34 #include "ardour/route_group.h"
35 #include "ardour/send.h"
36 #include "ardour/plugin.h"
37 #include "ardour/plugin_insert.h"
38 #include "ardour/processor.h"
39 #include "ardour/readonly_control.h"
40
41 #include "osc.h"
42 #include "osc_select_observer.h"
43
44 #include <glibmm.h>
45
46 #include "pbd/i18n.h"
47
48 using namespace std;
49 using namespace PBD;
50 using namespace ARDOUR;
51 using namespace ArdourSurface;
52
53 OSCSelectObserver::OSCSelectObserver (OSC& o, ArdourSurface::OSC::OSCSurface* su)
54         : _osc (o)
55         ,sur (su)
56         ,nsends (0)
57         ,_last_gain (-1.0)
58         ,_last_trim (-1.0)
59         ,_init (true)
60         ,eq_bands (0)
61         ,_expand (2048)
62 {
63         addr = lo_address_new_from_url  (sur->remote_url.c_str());
64         gainmode = sur->gainmode;
65         feedback = sur->feedback;
66         in_line = feedback[2];
67         send_page_size = sur->send_page_size;
68         send_size = send_page_size;
69         send_page = sur->send_page;
70         plug_page_size = sur->plug_page_size;
71         plug_size = plug_page_size;
72         plug_page = sur->plug_page;
73         if (sur->plugins.size () > 0) {
74                 plug_id = sur->plugins[sur->plugin_id - 1];
75         } else {
76                 plug_id = -1;
77         }
78         refresh_strip (sur->select, sur->nsends, gainmode, true);
79         set_expand (sur->expand_enable);
80 }
81
82 OSCSelectObserver::~OSCSelectObserver ()
83 {
84         _init = true;
85         no_strip ();
86         lo_address_free (addr);
87 }
88
89 void
90 OSCSelectObserver::no_strip ()
91 {
92         // This gets called on drop references
93         _init = true;
94
95         strip_connections.drop_connections ();
96         send_connections.drop_connections ();
97         plugin_connections.drop_connections ();
98         eq_connections.drop_connections ();
99         /*
100          * The strip will sit idle at this point doing nothing until
101          * the surface has recalculated it's strip list and then calls
102          * refresh_strip. Otherwise refresh strip will get a strip address
103          * that does not exist... Crash
104          */
105  }
106
107 void
108 OSCSelectObserver::refresh_strip (boost::shared_ptr<ARDOUR::Stripable> new_strip, uint32_t s_nsends, uint32_t gm, bool force)
109 {
110         _init = true;
111         if (_tick_busy) {
112                 Glib::usleep(100); // let tick finish
113         }
114         gainmode = gm;
115
116         if (_strip && (new_strip == _strip) && !force) {
117                 _init = false;
118                 return;
119         }
120
121         _strip = new_strip;
122         if (!_strip) {
123                 clear_observer ();
124                 return;
125         }
126
127         _strip->DropReferences.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::no_strip, this), OSC::instance());
128         as = ARDOUR::Off;
129         _comp_redux = 1;
130         nsends = s_nsends;
131         _last_gain = -1.0;
132         _last_trim = -1.0;
133
134         _strip->PropertyChanged.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::name_changed, this, boost::lambda::_1), OSC::instance());
135         name_changed (ARDOUR::Properties::name);
136
137         boost::shared_ptr<Route> rt = boost::dynamic_pointer_cast<Route> (_strip);
138         rt->route_group_changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::group_name, this), OSC::instance());
139         group_name ();
140
141         _strip->presentation_info().PropertyChanged.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::pi_changed, this, _1), OSC::instance());
142         _osc.float_message (X_("/select/hide"), _strip->is_hidden (), addr);
143
144         _strip->mute_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::change_message, this, X_("/select/mute"), _strip->mute_control()), OSC::instance());
145         change_message (X_("/select/mute"), _strip->mute_control());
146
147         _strip->solo_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::change_message, this, X_("/select/solo"), _strip->solo_control()), OSC::instance());
148         change_message (X_("/select/solo"), _strip->solo_control());
149
150         if (_strip->solo_isolate_control()) {
151                 _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());
152                 change_message (X_("/select/solo_iso"), _strip->solo_isolate_control());
153         }
154
155         if (_strip->solo_safe_control()) {
156                 _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());
157                 change_message (X_("/select/solo_safe"), _strip->solo_safe_control());
158         }
159
160         boost::shared_ptr<Track> track = boost::dynamic_pointer_cast<Track> (_strip);
161         if (track) {
162                 track->monitoring_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::monitor_status, this, track->monitoring_control()), OSC::instance());
163                 monitor_status (track->monitoring_control());
164         }
165
166         boost::shared_ptr<AutomationControl> rec_controllable = _strip->rec_enable_control ();
167         if (rec_controllable) {
168                 rec_controllable->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::change_message, this, X_("/select/recenable"), _strip->rec_enable_control()), OSC::instance());
169                 change_message (X_("/select/recenable"), _strip->rec_enable_control());
170         }
171
172         boost::shared_ptr<AutomationControl> recsafe_controllable = _strip->rec_safe_control ();
173         if (recsafe_controllable) {
174                 recsafe_controllable->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::change_message, this, X_("/select/record_safe"), _strip->rec_safe_control()), OSC::instance());
175                 change_message (X_("/select/record_safe"), _strip->rec_safe_control());
176         }
177
178         boost::shared_ptr<AutomationControl> phase_controllable = _strip->phase_control ();
179         if (phase_controllable) {
180                 phase_controllable->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::change_message, this, X_("/select/polarity"), _strip->phase_control()), OSC::instance());
181                 change_message (X_("/select/polarity"), _strip->phase_control());
182         }
183
184         _strip->gain_control()->alist()->automation_state_changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::gain_automation, this), OSC::instance());
185         _strip->gain_control()->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::gain_message, this), OSC::instance());
186         gain_automation ();
187
188         boost::shared_ptr<Controllable> trim_controllable = boost::dynamic_pointer_cast<Controllable>(_strip->trim_control());
189         if (trim_controllable) {
190                 trim_controllable->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::trim_message, this, X_("/select/trimdB"), _strip->trim_control()), OSC::instance());
191                 trim_message (X_("/select/trimdB"), _strip->trim_control());
192         }
193
194         boost::shared_ptr<Controllable> pan_controllable = boost::dynamic_pointer_cast<Controllable>(_strip->pan_azimuth_control());
195         if (pan_controllable) {
196                 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());
197                 change_message (X_("/select/pan_stereo_position"), _strip->pan_azimuth_control());
198         }
199
200         boost::shared_ptr<Controllable> width_controllable = boost::dynamic_pointer_cast<Controllable>(_strip->pan_width_control());
201         if (width_controllable) {
202                 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());
203                 change_message (X_("/select/pan_stereo_width"), _strip->pan_width_control());
204         }
205
206         // Rest of possible pan controls... Untested because I can't find a way to get them in the GUI :)
207         if (_strip->pan_elevation_control ()) {
208                 _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());
209                 change_message (X_("/select/pan_elevation_position"), _strip->pan_elevation_control());
210         }
211         if (_strip->pan_frontback_control ()) {
212                 _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());
213                 change_message (X_("/select/pan_frontback_position"), _strip->pan_frontback_control());
214         }
215         if (_strip->pan_lfe_control ()) {
216                 _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());
217                 change_message (X_("/select/pan_lfe_control"), _strip->pan_lfe_control());
218         }
219
220         // sends, plugins and eq
221         // detecting processor changes is now in osc.cc
222
223         // but... MB master send enable is different
224         if (_strip->master_send_enable_controllable ()) {
225                 _strip->master_send_enable_controllable ()->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::enable_message, this, X_("/select/master_send_enable"), _strip->master_send_enable_controllable()), OSC::instance());
226                 enable_message (X_("/select/master_send_enable"), _strip->master_send_enable_controllable());
227         }
228
229         // Compressor
230         if (_strip->comp_enable_controllable ()) {
231                 _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());
232                 enable_message (X_("/select/comp_enable"), _strip->comp_enable_controllable());
233         }
234         if (_strip->comp_threshold_controllable ()) {
235                 _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());
236                 change_message (X_("/select/comp_threshold"), _strip->comp_threshold_controllable());
237         }
238         if (_strip->comp_speed_controllable ()) {
239                 _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());
240                 change_message (X_("/select/comp_speed"), _strip->comp_speed_controllable());
241         }
242         if (_strip->comp_mode_controllable ()) {
243                 _strip->comp_mode_controllable ()->Changed.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::comp_mode, this), OSC::instance());
244                 comp_mode ();
245         }
246         if (_strip->comp_makeup_controllable ()) {
247                 _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());
248                 change_message (X_("/select/comp_makeup"), _strip->comp_makeup_controllable());
249         }
250         renew_sends ();
251         renew_plugin ();
252         eq_restart(0);
253         _init = false;
254
255         tick();
256 }
257
258 void
259 OSCSelectObserver::set_expand (uint32_t expand)
260 {
261         if (expand != _expand) {
262                 _expand = expand;
263                 if (expand) {
264                         _osc.float_message (X_("/select/expand"), 1.0, addr);
265                 } else {
266                         _osc.float_message (X_("/select/expand"), 0.0, addr);
267                 }
268         }
269 }
270
271 void
272 OSCSelectObserver::clear_observer ()
273 {
274         _init = true;
275         strip_connections.drop_connections ();
276         // all strip buttons should be off and faders 0 and etc.
277         _osc.float_message (X_("/select/expand"), 0, addr);
278         _osc.text_message (X_("/select/name"), " ", addr);
279         _osc.text_message (X_("/select/group/name"), " ", addr);
280         _osc.text_message (X_("/select/comment"), " ", addr);
281         _osc.float_message (X_("/select/mute"), 0, addr);
282         _osc.float_message (X_("/select/solo"), 0, addr);
283         _osc.float_message (X_("/select/recenable"), 0, addr);
284         _osc.float_message (X_("/select/record_safe"), 0, addr);
285         _osc.float_message (X_("/select/monitor_input"), 0, addr);
286         _osc.float_message (X_("/select/monitor_disk"), 0, addr);
287         _osc.float_message (X_("/select/polarity"), 0, addr);
288         _osc.float_message (X_("/select/n_inputs"), 0, addr);
289         _osc.float_message (X_("/select/n_outputs"), 0, addr);
290         if (gainmode) {
291                 _osc.float_message (X_("/select/fader"), 0, addr);
292         } else {
293                 _osc.float_message (X_("/select/gain"), -193, addr);
294         }
295         _osc.float_message (X_("/select/trimdB"), 0, addr);
296         _osc.float_message (X_("/select/pan_stereo_position"), 0.5, addr);
297         _osc.float_message (X_("/select/pan_stereo_width"), 1, addr);
298         if (feedback[9]) {
299                 _osc.float_message (X_("/select/signal"), 0, addr);
300         }
301         if (feedback[7]) {
302                 if (gainmode) {
303                         _osc.float_message (X_("/select/meter"), 0, addr);
304                 } else {
305                         _osc.float_message (X_("/select/meter"), -193, addr);
306                 }
307         }else if (feedback[8]) {
308                 _osc.float_message (X_("/select/meter"), 0, addr);
309         }
310         _osc.float_message (X_("/select/pan_elevation_position"), 0, addr);
311         _osc.float_message (X_("/select/pan_frontback_position"), .5, addr);
312         _osc.float_message (X_("/select/pan_lfe_control"), 0, addr);
313         _osc.float_message (X_("/select/comp_enable"), 0, addr);
314         _osc.float_message (X_("/select/comp_threshold"), 0, addr);
315         _osc.float_message (X_("/select/comp_speed"), 0, addr);
316         _osc.float_message (X_("/select/comp_mode"), 0, addr);
317         _osc.text_message (X_("/select/comp_mode_name"), " ", addr);
318         _osc.text_message (X_("/select/comp_speed_name"), " ", addr);
319         _osc.float_message (X_("/select/comp_makeup"), 0, addr);
320         _osc.float_message (X_("/select/expand"), 0.0, addr);
321         send_end();
322         plugin_end();
323         eq_end();
324 }
325
326 void
327 OSCSelectObserver::set_send_page (uint32_t page)
328 {
329         if (send_page != page) {
330                 send_page = page;
331                 renew_sends ();
332         }
333 }
334
335 void
336 OSCSelectObserver::set_send_size (uint32_t size)
337 {
338         send_page_size = size;
339         renew_sends ();
340 }
341
342 void
343 OSCSelectObserver::renew_sends () {
344         send_connections.drop_connections ();
345         send_timeout.clear();
346         send_init();
347 }
348
349 void
350 OSCSelectObserver::send_init()
351 {
352         send_size = nsends;
353         if (send_page_size) {
354                 send_size = send_page_size;
355         }
356         if (!send_size) {
357                 return;
358         }
359         uint32_t page_start = ((send_page - 1) * send_size);
360         uint32_t last_send = send_page * send_size;
361         uint32_t c = 1;
362         send_timeout.push_back (2);
363         _last_send.clear();
364         _last_send.push_back (0.0);
365
366         for (uint32_t s = page_start; s < last_send; ++s, ++c) {
367
368                 bool send_valid = false;
369                 if (_strip->send_level_controllable (s)) {
370                         _strip->send_level_controllable(s)->Changed.connect (send_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::send_gain, this, c, _strip->send_level_controllable(s)), OSC::instance());
371                         send_timeout.push_back (2);
372                         _last_send.push_back (20.0);
373                         send_gain (c, _strip->send_level_controllable(s));
374                         send_valid = true;
375                 } else {
376                         send_gain (c, _strip->send_level_controllable(s));
377                         _osc.float_message_with_id (X_("/select/send_enable"), c, 0, in_line, addr);
378                         _osc.text_message_with_id (X_("/select/send_name"), c, " ", in_line, addr);
379                 }
380
381                 if (_strip->send_enable_controllable (s)) {
382                         _strip->send_enable_controllable(s)->Changed.connect (send_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::enable_message_with_id, this, X_("/select/send_enable"), c, _strip->send_enable_controllable(s)), OSC::instance());
383                         enable_message_with_id (X_("/select/send_enable"), c, _strip->send_enable_controllable(s));
384                 } else if (send_valid) {
385                         boost::shared_ptr<Route> r = boost::dynamic_pointer_cast<Route> (_strip);
386                         if (!r) {
387                                 // should never get here
388                                 _osc.float_message_with_id (X_("/select/send_enable"), c, 0, in_line, addr);
389                         }
390                         boost::shared_ptr<Send> snd = boost::dynamic_pointer_cast<Send> (r->nth_send(s));
391                         if (snd) {
392                                 boost::shared_ptr<Processor> proc = boost::dynamic_pointer_cast<Processor> (snd);
393                                 proc->ActiveChanged.connect (send_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::send_enable, this, X_("/select/send_enable"), c, proc), OSC::instance());
394                                 _osc.float_message_with_id (X_("/select/send_enable"), c, proc->enabled(), in_line, addr);
395                         }
396                 }
397                 if ((gainmode != 1) && send_valid) {
398                         _osc.text_message_with_id (X_("/select/send_name"), c, _strip->send_name(s), in_line, addr);
399                 }
400         }
401 }
402
403 void
404 OSCSelectObserver::send_end ()
405 {
406         send_connections.drop_connections ();
407         for (uint32_t i = 1; i <= send_size; i++) {
408                 if (gainmode) {
409                         _osc.float_message_with_id (X_("/select/send_fader"), i, 0, in_line, addr);
410                 } else {
411                         _osc.float_message_with_id (X_("/select/send_gain"), i, -193, in_line, addr);
412                 }
413                 // next enable
414                 _osc.float_message_with_id (X_("/select/send_enable"), i, 0, in_line, addr);
415                 // next name
416                 _osc.text_message_with_id (X_("/select/send_name"), i, " ", in_line, addr);
417         }
418         // need to delete or clear send_timeout
419         send_size = 0;
420         send_timeout.clear();
421 }
422
423 void
424 OSCSelectObserver::set_plugin_id (int id, uint32_t page)
425 {
426         plug_id = id;
427         plug_page = page;
428         renew_plugin ();
429 }
430
431 void
432 OSCSelectObserver::set_plugin_page (uint32_t page)
433 {
434         plug_page = page;
435         renew_plugin ();
436 }
437
438 void
439 OSCSelectObserver::set_plugin_size (uint32_t size)
440 {
441         plug_page_size = size;
442         renew_plugin ();
443 }
444
445 void
446 OSCSelectObserver::renew_plugin () {
447         plugin_connections.drop_connections ();
448         plugin_init();
449 }
450
451 void
452 OSCSelectObserver::plugin_init()
453 {
454         if (plug_id < 0) {
455                 plugin_end ();
456                 return;
457         }
458         boost::shared_ptr<Route> r = boost::dynamic_pointer_cast<Route>(_strip);
459         if (!r) {
460                 plugin_end ();
461                 return;
462         }
463
464         // we have a plugin number now get the processor
465         boost::shared_ptr<Processor> proc = r->nth_plugin (plug_id);
466         boost::shared_ptr<PluginInsert> pi;
467         if (!(pi = boost::dynamic_pointer_cast<PluginInsert>(proc))) {
468                 plugin_end ();
469                 return;
470         }
471         boost::shared_ptr<ARDOUR::Plugin> pip = pi->plugin();
472         // we have a plugin we can ask if it is activated
473         proc->ActiveChanged.connect (plugin_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::plug_enable, this, X_("/select/plugin/activate"), proc), OSC::instance());
474         _osc.float_message (X_("/select/plugin/activate"), proc->enabled(), addr);
475
476         bool ok = false;
477         // put only input controls into a vector
478         plug_params.clear ();
479         uint32_t nplug_params  = pip->parameter_count();
480         for ( uint32_t ppi = 0;  ppi < nplug_params; ++ppi) {
481                 uint32_t controlid = pip->nth_parameter(ppi, ok);
482                 if (!ok) {
483                         continue;
484                 }
485                 if (pip->parameter_is_input(controlid)) {
486                         plug_params.push_back (ppi);
487                 }
488         }
489         nplug_params = plug_params.size ();
490
491         // default of 0 page size means show all
492         plug_size = nplug_params;
493         if (plug_page_size) {
494                 plug_size = plug_page_size;
495         }
496         _osc.text_message (X_("/select/plugin/name"), pip->name(), addr);
497         uint32_t page_start = plug_page - 1;
498         uint32_t page_end = page_start + plug_size;
499
500         int pid = 1;
501         for ( uint32_t ppi = page_start;  ppi < page_end; ++ppi, ++pid) {
502                 if (ppi >= nplug_params) {
503                         _osc.text_message_with_id (X_("/select/plugin/parameter/name"), pid, " ", in_line, addr);
504                         _osc.float_message_with_id (X_("/select/plugin/parameter"), pid, 0, in_line, addr);
505                         continue;
506                 }
507
508                 uint32_t controlid = pip->nth_parameter(plug_params[ppi], ok);
509                 if (!ok) {
510                         continue;
511                 }
512                 ParameterDescriptor pd;
513                 pip->get_parameter_descriptor(controlid, pd);
514                 _osc.text_message_with_id (X_("/select/plugin/parameter/name"), pid, pd.label, in_line, addr);
515                 if ( pip->parameter_is_input(controlid)) {
516                         boost::shared_ptr<AutomationControl> c = pi->automation_control(Evoral::Parameter(PluginAutomation, 0, controlid));
517                         if (c) {
518                                 bool swtch = false;
519                                 if (pd.integer_step && pd.upper == 1) {
520                                         swtch = true;
521                                 }
522                                 c->Changed.connect (plugin_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::plugin_parameter_changed, this, pid, swtch, c), OSC::instance());
523                                 plugin_parameter_changed (pid, swtch, c);
524                         }
525                 }
526         }
527 }
528
529 void
530 OSCSelectObserver::plugin_parameter_changed (int pid, bool swtch, boost::shared_ptr<PBD::Controllable> controllable)
531 {
532         if (swtch) {
533                 enable_message_with_id (X_("/select/plugin/parameter"), pid, controllable);
534         } else {
535                 change_message_with_id (X_("/select/plugin/parameter"), pid, controllable);
536         }
537 }
538
539 void
540 OSCSelectObserver::plugin_end ()
541 {
542         plugin_connections.drop_connections ();
543         _osc.float_message (X_("/select/plugin/activate"), 0, addr);
544         _osc.text_message (X_("/select/plugin/name"), " ", addr);
545         for (uint32_t i = 1; i <= plug_size; i++) {
546                 _osc.float_message_with_id (X_("/select/plugin/parameter"), i, 0, in_line, addr);
547                 // next name
548                 _osc.text_message_with_id (X_("/select/plugin/parameter/name"), i, " ", in_line, addr);
549         }
550         plug_size = 0;
551         nplug_params = 0;
552 }
553
554 void
555 OSCSelectObserver::tick ()
556 {
557         if (_init) {
558                 return;
559         }
560         _tick_busy = true;
561         if (feedback[7] || feedback[8] || feedback[9]) { // meters enabled
562                 float now_meter;
563                 if (_strip->peak_meter()) {
564                         now_meter = _strip->peak_meter()->meter_level(0, MeterMCP);
565                 } else {
566                         now_meter = -193;
567                 }
568                 if (now_meter < -144) now_meter = -193;
569                 if (_last_meter != now_meter) {
570                         if (feedback[7] || feedback[8]) {
571                                 string path = X_("/select/meter");
572                                 if (gainmode && feedback[7]) {
573                                         _osc.float_message (path, ((now_meter + 94) / 100), addr);
574                                 } else if ((!gainmode) && feedback[7]) {
575                                         _osc.float_message (path, now_meter, addr);
576                                 } else if (feedback[8]) {
577                                         uint32_t ledlvl = (uint32_t)(((now_meter + 54) / 3.75)-1);
578                                         uint16_t ledbits = ~(0xfff<<ledlvl);
579                                         _osc.float_message (path, ledbits, addr);
580                                 }
581                         }
582                         if (feedback[9]) {
583                                 string path = X_("/select/signal");
584                                 float signal;
585                                 if (now_meter < -40) {
586                                         signal = 0;
587                                 } else {
588                                         signal = 1;
589                                 }
590                                 _osc.float_message (path, signal, addr);
591                         }
592                 }
593                 _last_meter = now_meter;
594
595         }
596         if (gain_timeout) {
597                 if (gain_timeout == 1) {
598                         _osc.text_message (X_("/select/name"), _strip->name(), addr);
599                 }
600                 gain_timeout--;
601         }
602
603         if (as == ARDOUR::Play ||  as == ARDOUR::Touch) {
604                 if(_last_gain != _strip->gain_control()->get_value()) {
605                         _last_gain = _strip->gain_control()->get_value();
606                                 gain_message ();
607                 }
608         }
609         if (_strip->comp_redux_controllable() && _strip->comp_enable_controllable() && _strip->comp_enable_controllable()->get_value()) {
610                 float new_value = _strip->comp_redux_controllable()->get_parameter();
611                 if (_comp_redux != new_value) {
612                         _osc.float_message (X_("/select/comp_redux"), new_value, addr);
613                         _comp_redux = new_value;
614                 }
615         }
616         for (uint32_t i = 1; i <= send_timeout.size(); i++) {
617                 if (send_timeout[i]) {
618                         if (send_timeout[i] == 1) {
619                                 uint32_t pg_offset = (send_page - 1) * send_page_size;
620                                 _osc.text_message_with_id (X_("/select/send_name"), i, _strip->send_name(pg_offset + i - 1), in_line, addr);
621                         }
622                         send_timeout[i]--;
623                 }
624         }
625         _tick_busy = false;
626 }
627
628 void
629 OSCSelectObserver::name_changed (const PBD::PropertyChange& what_changed)
630 {
631         if (!what_changed.contains (ARDOUR::Properties::name)) {
632                 return;
633         }
634
635         if (!_strip) {
636                 return;
637         }
638
639         _osc.text_message (X_("/select/name"), _strip->name(), addr);
640         boost::shared_ptr<Route> route = boost::dynamic_pointer_cast<Route> (_strip);
641         if (route) {
642                 //spit out the comment at the same time
643                 _osc.text_message (X_("/select/comment"), route->comment(), addr);
644                 // lets tell the surface how many inputs this strip has
645                 _osc.float_message (X_("/select/n_inputs"), (float) route->n_inputs().n_total(), addr);
646                 // lets tell the surface how many outputs this strip has
647                 _osc.float_message (X_("/select/n_outputs"), (float) route->n_outputs().n_total(), addr);
648         }
649 }
650
651 void
652 OSCSelectObserver::group_name ()
653 {
654         boost::shared_ptr<Route> rt = boost::dynamic_pointer_cast<Route> (_strip);
655
656         RouteGroup *rg = rt->route_group();
657         if (rg) {
658                 _osc.text_message (X_("/select/group/name"), rg->name(), addr);
659         } else {
660                 _osc.text_message (X_("/select/group/name"), " ", addr);
661         }
662 }
663
664 void
665 OSCSelectObserver::pi_changed (PBD::PropertyChange const& what_changed)
666 {
667         _osc.float_message (X_("/select/hide"), _strip->is_hidden (), addr);
668 }
669
670 void
671 OSCSelectObserver::change_message (string path, boost::shared_ptr<Controllable> controllable)
672 {
673         float val = controllable->get_value();
674
675         _osc.float_message (path, (float) controllable->internal_to_interface (val), addr);
676 }
677
678 void
679 OSCSelectObserver::enable_message (string path, boost::shared_ptr<Controllable> controllable)
680 {
681         float val = controllable->get_value();
682         if (val) {
683                 _osc.float_message (path, 1, addr);
684         } else {
685                 _osc.float_message (path, 0, addr);
686         }
687
688 }
689
690 void
691 OSCSelectObserver::plug_enable (string path, boost::shared_ptr<Processor> proc)
692 {
693         // with no delay value is wrong
694         Glib::usleep(10);
695
696         _osc.float_message (path, proc->enabled(), addr);
697 }
698
699 void
700 OSCSelectObserver::change_message_with_id (string path, uint32_t id, boost::shared_ptr<Controllable> controllable)
701 {
702         float val = controllable->get_value();
703
704         _osc.float_message_with_id (path, id, (float) controllable->internal_to_interface (val), in_line, addr);
705 }
706
707 void
708 OSCSelectObserver::enable_message_with_id (string path, uint32_t id, boost::shared_ptr<Controllable> controllable)
709 {
710         float val = controllable->get_value();
711         if (val) {
712                 _osc.float_message_with_id (path, id, 1, in_line, addr);
713         } else {
714                 _osc.float_message_with_id (path, id, 0, in_line, addr);
715         }
716 }
717
718 void
719 OSCSelectObserver::monitor_status (boost::shared_ptr<Controllable> controllable)
720 {
721         int disk, input;
722         float val = controllable->get_value();
723         switch ((int) val) {
724                 case 1:
725                         disk = 0;
726                         input = 1;
727                         break;
728                 case 2:
729                         disk = 1;
730                         input = 0;
731                         break;
732                 default:
733                         disk = 0;
734                         input = 0;
735         }
736
737         _osc.float_message (X_("/select/monitor_input"), (float) input, addr);
738         _osc.float_message (X_("/select/monitor_disk"), (float) disk, addr);
739 }
740
741 void
742 OSCSelectObserver::trim_message (string path, boost::shared_ptr<Controllable> controllable)
743 {
744         if (_last_trim != controllable->get_value()) {
745                 _last_trim = controllable->get_value();
746         } else {
747                 return;
748         }
749
750         _osc.float_message (path, (float) accurate_coefficient_to_dB (controllable->get_value()), addr);
751 }
752
753 void
754 OSCSelectObserver::gain_message ()
755 {
756         float value = _strip->gain_control()->get_value();
757         if (_last_gain != value) {
758                 _last_gain = value;
759         } else {
760                 return;
761         }
762
763         if (gainmode) {
764                 _osc.float_message (X_("/select/fader"), _strip->gain_control()->internal_to_interface (value), addr);
765                 if (gainmode == 1) {
766                         _osc.text_message (X_("/select/name"), string_compose ("%1%2%3", std::fixed, std::setprecision(2), accurate_coefficient_to_dB (value)), addr);
767                         gain_timeout = 8;
768                 }
769         }
770         if (!gainmode || gainmode == 2) {
771                 if (value < 1e-15) {
772                         _osc.float_message (X_("/select/gain"), -200, addr);
773                 } else {
774                         _osc.float_message (X_("/select/gain"), accurate_coefficient_to_dB (value), addr);
775                 }
776         }
777 }
778
779 void
780 OSCSelectObserver::gain_automation ()
781 {
782         float output = 0;
783         as = _strip->gain_control()->alist()->automation_state();
784         string auto_name;
785         switch (as) {
786                 case ARDOUR::Off:
787                         output = 0;
788                         auto_name = "Manual";
789                         break;
790                 case ARDOUR::Play:
791                         output = 1;
792                         auto_name = "Play";
793                         break;
794                 case ARDOUR::Write:
795                         output = 2;
796                         auto_name = "Write";
797                         break;
798                 case ARDOUR::Touch:
799                         output = 3;
800                         auto_name = "Touch";
801                         break;
802                 default:
803                         break;
804         }
805
806         if (gainmode) {
807                 _osc.float_message (X_("/select/fader/automation"), output, addr);
808                 _osc.text_message (X_("/select/fader/automation_name"), auto_name, addr);
809         } else {
810                 _osc.float_message (X_("/select/gain/automation"), output, addr);
811                 _osc.text_message (X_("/select/gain/automation_name"), auto_name, addr);
812         }
813
814         gain_message ();
815 }
816
817 void
818 OSCSelectObserver::send_gain (uint32_t id, boost::shared_ptr<PBD::Controllable> controllable)
819 {
820         float raw_value = 0.0;
821         if (controllable) {
822                 raw_value = controllable->get_value();
823         }
824         if (_last_send[id] != raw_value) {
825                 _last_send[id] = raw_value;
826         } else {
827                 return;
828         }
829         string path;
830         float value = 0.0;
831         float db;
832 #ifdef MIXBUS
833         if (controllable) {
834                 db = raw_value;
835         } else {
836                 db = -193;
837         }
838 #else
839         if (raw_value < 1e-15) {
840                 db = -193;
841         } else {
842                 db = accurate_coefficient_to_dB (raw_value);
843         }
844 #endif
845
846         if (gainmode) {
847                 if (controllable) {
848                         value = controllable->internal_to_interface (raw_value);
849                 }
850                 _osc.float_message_with_id (X_("/select/send_fader"), id, value, in_line, addr);
851                 if (gainmode == 1) {
852                         _osc.text_message_with_id (X_("/select/send_name") , id, string_compose ("%1%2%3", std::fixed, std::setprecision(2), db), in_line, addr);
853                         if (send_timeout.size() > id) {
854                                 send_timeout[id] = 8;
855                         }
856                 }
857         }
858         if (!gainmode || gainmode == 2) {
859                 _osc.float_message_with_id (X_("/select/send_gain"), id, db, in_line, addr);
860         }
861
862 }
863
864 void
865 OSCSelectObserver::send_enable (string path, uint32_t id, boost::shared_ptr<Processor> proc)
866 {
867         // with no delay value is wrong
868         Glib::usleep(10);
869
870         _osc.float_message_with_id (X_("/select/send_enable"), id, proc->enabled(), in_line, addr);
871 }
872
873 void
874 OSCSelectObserver::comp_mode ()
875 {
876         change_message (X_("/select/comp_mode"), _strip->comp_mode_controllable());
877         _osc.text_message (X_("/select/comp_mode_name"), _strip->comp_mode_name(_strip->comp_mode_controllable()->get_value()), addr);
878         _osc.text_message (X_("/select/comp_speed_name"), _strip->comp_speed_name(_strip->comp_mode_controllable()->get_value()), addr);
879 }
880
881 void
882 OSCSelectObserver::eq_init()
883 {
884         // HPF and enable are special case, rest are in bands
885         if (_strip->filter_enable_controllable (true)) {
886                 _strip->filter_enable_controllable (true)->Changed.connect (eq_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::change_message, this, X_("/select/eq_hpf/enable"), _strip->filter_enable_controllable (true)), OSC::instance());
887                 change_message (X_("/select/eq_hpf/enable"), _strip->filter_enable_controllable(true));
888         }
889
890         if (_strip->filter_enable_controllable (false)) {
891                 _strip->filter_enable_controllable (false)->Changed.connect (eq_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::change_message, this, X_("/select/eq_lpf/enable"), _strip->filter_enable_controllable (false)), OSC::instance());
892                 change_message (X_("/select/eq_lpf/enable"), _strip->filter_enable_controllable(false));
893         }
894
895         if (_strip->filter_freq_controllable (true)) {
896                 _strip->filter_freq_controllable (true)->Changed.connect (eq_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::change_message, this, X_("/select/eq_hpf/freq"), _strip->filter_freq_controllable (true)), OSC::instance());
897                 change_message (X_("/select/eq_hpf/freq"), _strip->filter_freq_controllable(true));
898         }
899
900         if (_strip->filter_freq_controllable (false)) {
901                 _strip->filter_freq_controllable (false)->Changed.connect (eq_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::change_message, this, X_("/select/eq_lpf/freq"), _strip->filter_freq_controllable (false)), OSC::instance());
902                 change_message (X_("/select/eq_lpf/freq"), _strip->filter_freq_controllable(false));
903         }
904
905         if (_strip->filter_slope_controllable (true)) {
906                 _strip->filter_slope_controllable (true)->Changed.connect (eq_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::change_message, this, X_("/select/eq_hpf/slope"), _strip->filter_slope_controllable (true)), OSC::instance());
907                 change_message (X_("/select/eq_hpf/slope"), _strip->filter_slope_controllable(true));
908         }
909
910         if (_strip->filter_slope_controllable (false)) {
911                 _strip->filter_slope_controllable (false)->Changed.connect (eq_connections, MISSING_INVALIDATOR, boost::bind (&OSCSelectObserver::change_message, this, X_("/select/eq_lpf/slope"), _strip->filter_slope_controllable (false)), OSC::instance());
912                 change_message (X_("/select/eq_lpf/slope"), _strip->filter_slope_controllable(false));
913         }
914
915         if (_strip->eq_enable_controllable ()) {
916                 _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());
917                 enable_message (X_("/select/eq_enable"), _strip->eq_enable_controllable());
918         }
919
920         eq_bands = _strip->eq_band_cnt ();
921         if (eq_bands < 0) {
922                 eq_bands = 0;
923         }
924         if (!eq_bands) {
925                 return;
926         }
927
928         for (int i = 0; i < eq_bands; i++) {
929                 if (_strip->eq_band_name(i).size()) {
930                         _osc.text_message_with_id (X_("/select/eq_band_name"), i + 1, _strip->eq_band_name (i), in_line, addr);
931                 }
932                 if (_strip->eq_gain_controllable (i)) {
933                         _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());
934                         change_message_with_id (X_("/select/eq_gain"), i + 1, _strip->eq_gain_controllable(i));
935                 }
936                 if (_strip->eq_freq_controllable (i)) {
937                         _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());
938                         change_message_with_id (X_("/select/eq_freq"), i + 1, _strip->eq_freq_controllable(i));
939                 }
940                 if (_strip->eq_q_controllable (i)) {
941                         _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());
942                         change_message_with_id (X_("/select/eq_q"), i + 1, _strip->eq_q_controllable(i));
943                 }
944                 if (_strip->eq_shape_controllable (i)) {
945                         _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());
946                         change_message_with_id (X_("/select/eq_shape"), i + 1, _strip->eq_shape_controllable(i));
947                 }
948         }
949 }
950
951 void
952 OSCSelectObserver::eq_end ()
953 {
954         eq_connections.drop_connections ();
955                 _osc.float_message (X_("/select/eq_hpf"), 0, addr);
956                 _osc.float_message (X_("/select/eq_enable"), 0, addr);
957
958         for (int i = 1; i <= eq_bands; i++) {
959                 _osc.text_message_with_id (X_("/select/eq_band_name"), i, " ", in_line, addr);
960                 _osc.float_message_with_id (X_("/select/eq_gain"), i, 0, in_line, addr);
961                 _osc.float_message_with_id (X_("/select/eq_freq"), i, 0, in_line, addr);
962                 _osc.float_message_with_id (X_("/select/eq_q"), i, 0, in_line, addr);
963                 _osc.float_message_with_id (X_("/select/eq_shape"), i, 0, in_line, addr);
964
965
966         }
967 }
968
969 void
970 OSCSelectObserver::eq_restart(int x)
971 {
972         eq_connections.drop_connections ();
973         //eq_end();
974         eq_init();
975 }