patch from brian to get consistent menu behaviour
[ardour.git] / gtk2_ardour / ladspa_pluginui.cc
1 /*
2     Copyright (C) 2000 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 <climits>
21 #include <cerrno>
22 #include <cmath>
23 #include <string>
24
25 #include <pbd/stl_delete.h>
26 #include <pbd/xml++.h>
27 #include <pbd/failed_constructor.h>
28
29 #include <gtkmm2ext/click_box.h>
30 #include <gtkmm2ext/fastmeter.h>
31 #include <gtkmm2ext/barcontroller.h>
32 #include <gtkmm2ext/utils.h>
33 #include <gtkmm2ext/doi.h>
34 #include <gtkmm2ext/slider_controller.h>
35
36 #include <midi++/manager.h>
37
38 #include <ardour/plugin.h>
39 #include <ardour/insert.h>
40 #include <ardour/ladspa_plugin.h>
41
42 #include <lrdf.h>
43
44 #include "ardour_ui.h"
45 #include "prompter.h"
46 #include "plugin_ui.h"
47 #include "utils.h"
48 #include "gui_thread.h"
49
50 #include "i18n.h"
51
52 using namespace std;
53 using namespace ARDOUR;
54 using namespace PBD;
55 using namespace Gtkmm2ext;
56 using namespace Gtk;
57 using namespace sigc;
58
59 LadspaPluginUI::LadspaPluginUI (boost::shared_ptr<PluginInsert> pi, bool scrollable)
60         : PlugUIBase (pi),
61           button_table (initial_button_rows, initial_button_cols),
62           output_table (initial_output_rows, initial_output_cols),
63           hAdjustment(0.0, 0.0, 0.0),
64           vAdjustment(0.0, 0.0, 0.0),
65           scroller_view(hAdjustment, vAdjustment),
66           automation_menu (0),
67           is_scrollable(scrollable)
68 {
69         set_name ("PluginEditor");
70         set_border_width (10);
71         set_homogeneous (false);
72
73         settings_box.set_homogeneous (false);
74
75         HBox* constraint_hbox = manage (new HBox);
76         HBox* smaller_hbox = manage (new HBox);
77         Label* combo_label = manage (new Label (_("<span size=\"large\">Presets</span>")));
78         combo_label->set_use_markup (true);
79
80         smaller_hbox->pack_start (*combo_label, false, false, 10);
81         smaller_hbox->pack_start (combo, false, false);
82         smaller_hbox->pack_start (save_button, false, false);
83
84         constraint_hbox->set_spacing (5);
85         constraint_hbox->pack_start (*smaller_hbox, true, false);
86         constraint_hbox->pack_end (bypass_button, false, false);
87
88         settings_box.pack_end (*constraint_hbox, false, false);
89
90         pack_start (settings_box, false, false);
91
92         if ( is_scrollable ) {
93                 scroller.set_policy (Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
94                 scroller.set_name ("PluginEditor");
95                 scroller_view.set_name("PluginEditor");
96                 scroller_view.add (hpacker);
97                 scroller.add (scroller_view);
98                 
99                 pack_start (scroller, true, true);
100
101         }
102         else {
103                 pack_start (hpacker, false, false);
104         }
105
106         insert->active_changed.connect (mem_fun(*this, &LadspaPluginUI::redirect_active_changed));
107         bypass_button.set_active (!insert->active());
108         
109         build ();
110 }
111
112 LadspaPluginUI::~LadspaPluginUI ()
113 {
114         if (output_controls.size() > 0) {
115                 screen_update_connection.disconnect();
116         }
117 }
118
119 void
120 LadspaPluginUI::build ()
121
122 {
123         guint32 i = 0;
124         guint32 x = 0;
125         Frame* frame;
126         Frame* bt_frame;
127         VBox* box;
128         int output_row, output_col;
129         int button_row, button_col;
130         int output_rows, output_cols;
131         int button_rows, button_cols;
132         guint32 n_ins=0, n_outs = 0;
133
134         prefheight = 30;
135         hpacker.set_spacing (10);
136
137         output_rows = initial_output_rows;
138         output_cols = initial_output_cols;
139         button_rows = initial_button_rows;
140         button_cols = initial_button_cols;
141         output_row = 0;
142         button_row = 0;
143         output_col = 0;
144         button_col = 0;
145
146         button_table.set_homogeneous (false);
147         button_table.set_row_spacings (2);
148         button_table.set_col_spacings (2);
149         output_table.set_homogeneous (true);
150         output_table.set_row_spacings (2);
151         output_table.set_col_spacings (2);
152         button_table.set_border_width (5);
153         output_table.set_border_width (5);
154
155         hpacker.set_border_width (10);
156
157         bt_frame = manage (new Frame);
158         bt_frame->set_name ("BaseFrame");
159         bt_frame->add (button_table);
160         hpacker.pack_start(*bt_frame, true, true);
161
162         box = manage (new VBox);
163         box->set_border_width (5);
164         box->set_spacing (1);
165
166         frame = manage (new Frame);
167         frame->set_name ("BaseFrame");
168         frame->set_label (_("Controls"));
169         frame->add (*box);
170         hpacker.pack_start(*frame, true, true);
171
172         /* find all ports. build control elements for all appropriate control ports */
173
174         for (i = 0; i < plugin->parameter_count(); ++i) {
175
176                 if (plugin->parameter_is_control (i)) {
177                         
178                         /* Don't show latency control ports */
179
180                         if (plugin->describe_parameter (i) == X_("latency")) {
181                                 continue;
182                         }
183
184                         ControlUI* cui;
185         
186                         /* if we are scrollable, just use one long column */
187
188                         if (!is_scrollable) {
189                                 if (x++ > 7){
190                                         frame = manage (new Frame);
191                                         frame->set_name ("BaseFrame");
192                                         box = manage (new VBox);
193                                         
194                                         box->set_border_width (5);
195                                         box->set_spacing (1);
196
197                                         frame->add (*box);
198                                         hpacker.pack_start(*frame,true,true);
199
200                                         x = 0;
201                                 }
202                         }
203
204                         if ((cui = build_control_ui (i, plugin->get_nth_control (i))) == 0) {
205                                 error << string_compose(_("Plugin Editor: could not build control element for port %1"), i) << endmsg;
206                                 continue;
207                         }
208                                 
209                         if (cui->control || cui->clickbox || cui->combo) {
210
211                                 box->pack_start (*cui, false, false);
212
213                         } else if (cui->button) {
214
215                                 if (button_row == button_rows) {
216                                         button_row = 0;
217                                         if (++button_col == button_cols) {
218                                                 button_cols += 2;
219                                                 button_table.resize (button_rows, button_cols);
220                                         }
221                                 }
222
223                                 button_table.attach (*cui, button_col, button_col + 1, button_row, button_row+1, 
224                                                      FILL|EXPAND, FILL);
225                                 button_row++;
226
227                         } else if (cui->display) {
228
229                                 output_table.attach (*cui, output_col, output_col + 1, output_row, output_row+1, 
230                                                      FILL|EXPAND, FILL);
231                                 
232                                 // TODO: The meters should be divided into multiple rows 
233                                 
234                                 if (++output_col == output_cols) {
235                                         output_cols ++;
236                                         output_table.resize (output_rows, output_cols);
237                                 }
238                                 
239                                 /* old code, which divides meters into
240                                  * columns first, rows later. New code divides into one row
241                                  
242                                 if (output_row == output_rows) {
243                                         output_row = 0;
244                                         if (++output_col == output_cols) {
245                                                 output_cols += 2;
246                                                 output_table.resize (output_rows, output_cols);
247                                         }
248                                 }
249                                 
250                                 output_table.attach (*cui, output_col, output_col + 1, output_row, output_row+1, 
251                                                      FILL|EXPAND, FILL);
252  
253                                 output_row++;
254                                 */
255                         }
256                                 
257                         /* HACK: ideally the preferred height would be queried from
258                            the complete hpacker, but I can't seem to get that
259                            information in time, so this is an estimation 
260                         */
261
262                         prefheight += 30;
263
264                 } 
265         }
266
267         n_ins = plugin->get_info()->n_inputs;
268         n_outs = plugin->get_info()->n_outputs;
269
270         if (box->children().empty()) {
271                 hpacker.remove (*frame);
272         }
273
274         if (button_table.children().empty()) {
275                 hpacker.remove (*bt_frame);
276         }
277
278         if (!output_table.children().empty()) {
279                 frame = manage (new Frame);
280                 frame->set_name ("BaseFrame");
281                 frame->add (output_table);
282                 hpacker.pack_end (*frame, true, true);
283         }
284
285         output_update ();
286
287         output_table.show_all ();
288         button_table.show_all ();
289 }
290
291 LadspaPluginUI::ControlUI::ControlUI ()
292         : automate_button (X_("")) // force creation of a label 
293 {
294         automate_button.set_name ("PluginAutomateButton");
295         ARDOUR_UI::instance()->tooltips().set_tip (automate_button,
296                                                    _("Automation control"));
297
298         /* don't fix the height, it messes up the bar controllers */
299
300         set_size_request_to_display_given_text (automate_button, X_("lngnuf"), 2, 2);
301
302         ignore_change = 0;
303         display = 0;
304         button = 0;
305         control = 0;
306         clickbox = 0;
307         adjustment = 0;
308         meterinfo = 0;
309 }
310
311 LadspaPluginUI::ControlUI::~ControlUI() 
312 {
313         if (adjustment) {
314                 delete adjustment;
315         }
316
317         if (meterinfo) {
318                 delete meterinfo->meter;
319                 delete meterinfo;
320         }
321 }
322
323 void
324 LadspaPluginUI::automation_state_changed (ControlUI* cui)
325 {
326         /* update button label */
327
328         switch (insert->get_port_automation_state (cui->port_index) & (Off|Play|Touch|Write)) {
329         case Off:
330                 cui->automate_button.set_label (_("Off"));
331                 break;
332         case Play:
333                 cui->automate_button.set_label (_("Play"));
334                 break;
335         case Write:
336                 cui->automate_button.set_label (_("Write"));
337                 break;
338         case Touch:
339                 cui->automate_button.set_label (_("Touch"));
340                 break;
341         default:
342                 cui->automate_button.set_label (_("???"));
343                 break;
344         }
345 }
346
347
348 static void integer_printer (char buf[32], Adjustment &adj, void *arg)
349 {
350         snprintf (buf, 32, "%.0f", adj.get_value());
351 }
352
353 void
354 LadspaPluginUI::print_parameter (char *buf, uint32_t len, uint32_t param)
355 {
356         plugin->print_parameter (param, buf, len);
357 }
358
359 LadspaPluginUI::ControlUI*
360 LadspaPluginUI::build_control_ui (guint32 port_index, PBD::Controllable* mcontrol)
361
362 {
363         ControlUI* control_ui;
364         Plugin::ParameterDescriptor desc;
365
366         plugin->get_parameter_descriptor (port_index, desc);
367
368         control_ui = manage (new ControlUI ());
369         control_ui->adjustment = 0;
370         control_ui->combo = 0;
371         control_ui->combo_map = 0;
372         control_ui->port_index = port_index;
373         control_ui->update_pending = false;
374         control_ui->label.set_text (desc.label);
375         control_ui->label.set_alignment (0.0, 0.5);
376         control_ui->label.set_name ("PluginParameterLabel");
377
378         control_ui->set_spacing (5);
379
380         if (plugin->parameter_is_input (port_index)) {
381
382                 boost::shared_ptr<LadspaPlugin> lp;
383
384                 if ((lp = boost::dynamic_pointer_cast<LadspaPlugin>(plugin)) != 0) {
385                         
386                         lrdf_defaults* defaults = lrdf_get_scale_values(lp->unique_id(), port_index);
387                         
388                         if (defaults && defaults->count > 0)    {
389                                 
390                                 control_ui->combo = new Gtk::ComboBoxText;
391                                 //control_ui->combo->set_value_in_list(true, false);
392                                 set_popdown_strings (*control_ui->combo, setup_scale_values(port_index, control_ui));
393                                 control_ui->combo->signal_changed().connect (bind (mem_fun(*this, &LadspaPluginUI::control_combo_changed), control_ui));
394                                 plugin->ParameterChanged.connect (bind (mem_fun (*this, &LadspaPluginUI::parameter_changed), control_ui));
395                                 control_ui->pack_start(control_ui->label, true, true);
396                                 control_ui->pack_start(*control_ui->combo, false, true);
397                                 
398                                 update_control_display(control_ui);
399                                 
400                                 lrdf_free_setting_values(defaults);
401                                 return control_ui;
402                         }
403                 }
404                         
405                 if (desc.toggled) {
406
407                         /* Build a button */
408                 
409                         control_ui->button = manage (new ToggleButton ());
410                         control_ui->button->set_name ("PluginEditorButton");
411                         control_ui->button->set_size_request (20, 20);
412
413                         control_ui->pack_start (control_ui->label, true, true);
414                         control_ui->pack_start (*control_ui->button, false, true);
415                         control_ui->pack_start (control_ui->automate_button, false, false);
416
417                         control_ui->button->signal_clicked().connect (bind (mem_fun(*this, &LadspaPluginUI::control_port_toggled), control_ui));
418                 
419                         if(plugin->get_parameter (port_index) == 1){
420                                 control_ui->button->set_active(true);
421                         }
422
423                         return control_ui;
424                 }
425         
426                 control_ui->adjustment = new Adjustment (0, 0, 0, 0, 0);
427
428                 /* XXX this code is not right yet, because it doesn't handle
429                    the absence of bounds in any sensible fashion.
430                 */
431
432                 control_ui->adjustment->set_lower (desc.lower);
433                 control_ui->adjustment->set_upper (desc.upper);
434
435                 control_ui->logarithmic = desc.logarithmic;
436                 if (control_ui->logarithmic) {
437                         if (control_ui->adjustment->get_lower() == 0.0) {
438                                 control_ui->adjustment->set_lower (control_ui->adjustment->get_upper()/10000);
439                         }
440                         control_ui->adjustment->set_upper (log(control_ui->adjustment->get_upper()));
441                         control_ui->adjustment->set_lower (log(control_ui->adjustment->get_lower()));
442                 }
443         
444                 float delta = desc.upper - desc.lower;
445
446                 control_ui->adjustment->set_page_size (delta/100.0);
447                 control_ui->adjustment->set_step_increment (desc.step);
448                 control_ui->adjustment->set_page_increment (desc.largestep);
449
450                 if (desc.integer_step) {
451                         control_ui->clickbox = new ClickBox (control_ui->adjustment, "PluginUIClickBox");
452                         Gtkmm2ext::set_size_request_to_display_given_text (*control_ui->clickbox, "g9999999", 2, 2);
453                         control_ui->clickbox->set_print_func (integer_printer, 0);
454                 } else {
455                         sigc::slot<void,char*,uint32_t> pslot = sigc::bind (mem_fun(*this, &LadspaPluginUI::print_parameter), (uint32_t) port_index);
456
457                         control_ui->control = new BarController (*control_ui->adjustment, *mcontrol, pslot);
458                         // should really match the height of the text in the automation button+label
459                         control_ui->control->set_size_request (200, 22);
460                         control_ui->control->set_name (X_("PluginSlider"));
461                         control_ui->control->set_style (BarController::LeftToRight);
462                         control_ui->control->set_use_parent (true);
463
464                         control_ui->control->StartGesture.connect (bind (mem_fun(*this, &LadspaPluginUI::start_touch), control_ui));
465                         control_ui->control->StopGesture.connect (bind (mem_fun(*this, &LadspaPluginUI::stop_touch), control_ui));
466                         
467                 }
468
469                 if (control_ui->logarithmic) {
470                         control_ui->adjustment->set_value(log(plugin->get_parameter(port_index)));
471                 } else{
472                         control_ui->adjustment->set_value(plugin->get_parameter(port_index));
473                 }
474
475                 /* XXX memory leak: SliderController not destroyed by ControlUI
476                    destructor, and manage() reports object hierarchy
477                    ambiguity.
478                 */
479
480                 control_ui->pack_start (control_ui->label, true, true);
481                 if (desc.integer_step) {
482                         control_ui->pack_start (*control_ui->clickbox, false, false);
483                 } else {
484                         control_ui->pack_start (*control_ui->control, false, false);
485                 }
486
487                 control_ui->pack_start (control_ui->automate_button, false, false);
488                 control_ui->adjustment->signal_value_changed().connect (bind (mem_fun(*this, &LadspaPluginUI::control_adjustment_changed), control_ui));
489                 control_ui->automate_button.signal_clicked().connect (bind (mem_fun(*this, &LadspaPluginUI::astate_clicked), control_ui, (uint32_t) port_index));
490
491                 automation_state_changed (control_ui);
492
493                 plugin->ParameterChanged.connect (bind (mem_fun(*this, &LadspaPluginUI::parameter_changed), control_ui));
494                 insert->automation_list (port_index).automation_state_changed.connect 
495                         (bind (mem_fun(*this, &LadspaPluginUI::automation_state_changed), control_ui));
496
497         } else if (plugin->parameter_is_output (port_index)) {
498
499                 control_ui->display = manage (new EventBox);
500                 control_ui->display->set_name ("ParameterValueDisplay");
501
502                 control_ui->display_label = manage (new Label);
503
504                 control_ui->display_label->set_name ("ParameterValueDisplay");
505
506                 control_ui->display->add (*control_ui->display_label);
507                 Gtkmm2ext::set_size_request_to_display_given_text (*control_ui->display, "-99,99", 2, 2);
508
509                 control_ui->display->show_all ();
510
511                 /* set up a meter */
512                 /* TODO: only make a meter if the port is Hinted for it */
513
514                 MeterInfo * info = new MeterInfo(port_index);
515                 control_ui->meterinfo = info;
516                 
517                 info->meter = new FastMeter (5, 100, FastMeter::Vertical);
518
519                 info->min_unbound = desc.min_unbound;
520                 info->max_unbound = desc.max_unbound;
521
522                 info->min = desc.lower;
523                 info->max = desc.upper;
524
525                 control_ui->vbox = manage (new VBox);
526                 control_ui->hbox = manage (new HBox);
527                 
528                 control_ui->label.set_angle(90);
529                 control_ui->hbox->pack_start (control_ui->label, false, false);
530                 control_ui->hbox->pack_start (*info->meter, false, false);
531
532                 control_ui->vbox->pack_start (*control_ui->hbox, false, false);
533                 
534                 control_ui->vbox->pack_start (*control_ui->display, false, false);
535
536                 control_ui->pack_start (*control_ui->vbox);
537
538                 control_ui->meterinfo->meter->show_all();
539                 control_ui->meterinfo->packed = true;
540                 
541                 output_controls.push_back (control_ui);
542         }
543         
544         plugin->ParameterChanged.connect (bind (mem_fun(*this, &LadspaPluginUI::parameter_changed), control_ui));
545         return control_ui;
546 }
547
548 void
549 LadspaPluginUI::start_touch (LadspaPluginUI::ControlUI* cui)
550 {
551         insert->automation_list (cui->port_index).start_touch ();
552 }
553
554 void
555 LadspaPluginUI::stop_touch (LadspaPluginUI::ControlUI* cui)
556 {
557         insert->automation_list (cui->port_index).stop_touch ();
558 }
559
560 void
561 LadspaPluginUI::astate_clicked (ControlUI* cui, uint32_t port)
562 {
563         using namespace Menu_Helpers;
564
565         if (automation_menu == 0) {
566                 automation_menu = manage (new Menu);
567                 automation_menu->set_name ("ArdourContextMenu");
568         } 
569
570         MenuList& items (automation_menu->items());
571
572         items.clear ();
573         items.push_back (MenuElem (_("Off"), 
574                                    bind (mem_fun(*this, &LadspaPluginUI::set_automation_state), (AutoState) Off, cui)));
575         items.push_back (MenuElem (_("Play"),
576                                    bind (mem_fun(*this, &LadspaPluginUI::set_automation_state), (AutoState) Play, cui)));
577         items.push_back (MenuElem (_("Write"),
578                                    bind (mem_fun(*this, &LadspaPluginUI::set_automation_state), (AutoState) Write, cui)));
579         items.push_back (MenuElem (_("Touch"),
580                                    bind (mem_fun(*this, &LadspaPluginUI::set_automation_state), (AutoState) Touch, cui)));
581
582         automation_menu->popup (1, gtk_get_current_event_time());
583 }
584
585 void
586 LadspaPluginUI::set_automation_state (AutoState state, ControlUI* cui)
587 {
588         insert->set_port_automation_state (cui->port_index, state);
589 }
590
591 void
592 LadspaPluginUI::control_adjustment_changed (ControlUI* cui)
593 {
594         if (cui->ignore_change) {
595                 return;
596         }
597
598         double value = cui->adjustment->get_value();
599
600         if (cui->logarithmic) {
601                 value = exp(value);
602         }
603
604         insert->set_parameter (cui->port_index, (float) value);
605 }
606
607 void
608 LadspaPluginUI::parameter_changed (uint32_t abs_port_id, float val, ControlUI* cui)
609 {
610         if (cui->port_index == abs_port_id) {
611                 if (!cui->update_pending) {
612                         cui->update_pending = true;
613                         Gtkmm2ext::UI::instance()->call_slot (bind (mem_fun(*this, &LadspaPluginUI::update_control_display), cui));
614                 }
615         }
616 }
617
618 void
619 LadspaPluginUI::update_control_display (ControlUI* cui) 
620 {
621         /* XXX how do we handle logarithmic stuff here ? */
622         
623         cui->update_pending = false;
624
625         float val = plugin->get_parameter (cui->port_index);
626
627         cui->ignore_change++;
628         if (cui->combo) {
629                 std::map<string,float>::iterator it;
630                 for (it = cui->combo_map->begin(); it != cui->combo_map->end(); ++it) {
631                         if (it->second == val) {
632                                 cui->combo->set_active_text(it->first);
633                                 break;
634                         }
635                 }
636         } else if (cui->adjustment == 0) {
637
638                 if (val > 0.5) {
639                         cui->button->set_active (true);
640                 } else {
641                         cui->button->set_active (false);
642                 }
643
644         } else {
645                 if (cui->logarithmic) {
646                         val = log(val);
647                 }
648                 if (val != cui->adjustment->get_value()) {
649                         cui->adjustment->set_value (val);
650                 }
651         }
652         cui->ignore_change--;
653 }
654
655 void
656 LadspaPluginUI::control_port_toggled (ControlUI* cui)
657 {
658         if (!cui->ignore_change) {
659                 insert->set_parameter (cui->port_index, cui->button->get_active());
660         }
661 }
662
663 void
664 LadspaPluginUI::control_combo_changed (ControlUI* cui)
665 {
666         if (!cui->ignore_change) {
667                 string value = cui->combo->get_active_text();
668                 std::map<string,float> mapping = *cui->combo_map;
669                 insert->set_parameter (cui->port_index, mapping[value]);
670         }
671
672 }
673
674 void
675 LadspaPluginUI::redirect_active_changed (Redirect* r, void* src)
676 {
677         ENSURE_GUI_THREAD(bind (mem_fun(*this, &LadspaPluginUI::redirect_active_changed), r, src));
678         
679         bypass_button.set_active (!r->active());
680 }
681
682 bool
683 LadspaPluginUI::start_updating (GdkEventAny* ignored)
684 {
685         if (output_controls.size() > 0 ) {
686                 screen_update_connection.disconnect();
687                 screen_update_connection = ARDOUR_UI::instance()->RapidScreenUpdate.connect 
688                         (mem_fun(*this, &LadspaPluginUI::output_update));
689         }
690         return false;
691 }
692
693 bool
694 LadspaPluginUI::stop_updating (GdkEventAny* ignored)
695 {
696         if (output_controls.size() > 0 ) {
697                 screen_update_connection.disconnect();
698         }
699         return false;
700 }
701
702 void
703 LadspaPluginUI::output_update ()
704 {
705         for (vector<ControlUI*>::iterator i = output_controls.begin(); i != output_controls.end(); ++i) {
706                 float val = plugin->get_parameter ((*i)->port_index);
707                 char buf[32];
708                 snprintf (buf, sizeof(buf), "%.2f", val);
709                 (*i)->display_label->set_text (buf);
710
711                 /* autoscaling for the meter */
712                 if ((*i)->meterinfo && (*i)->meterinfo->packed) {
713                         
714                         if (val < (*i)->meterinfo->min) {
715                                 if ((*i)->meterinfo->min_unbound)
716                                         (*i)->meterinfo->min = val;
717                                 else
718                                         val = (*i)->meterinfo->min;
719                         }
720
721                         if (val > (*i)->meterinfo->max) {
722                                 if ((*i)->meterinfo->max_unbound)
723                                         (*i)->meterinfo->max = val;
724                                 else
725                                         val = (*i)->meterinfo->max;
726                         }
727                         
728                         if ((*i)->meterinfo->max > (*i)->meterinfo->min ) {
729                                 float lval = (val - (*i)->meterinfo->min) / ((*i)->meterinfo->max - (*i)->meterinfo->min) ;
730                                 (*i)->meterinfo->meter->set (lval );
731                         }
732                 }
733         }
734 }
735
736 vector<string> 
737 LadspaPluginUI::setup_scale_values(guint32 port_index, ControlUI* cui)
738 {
739         vector<string> enums;
740         boost::shared_ptr<LadspaPlugin> lp = boost::dynamic_pointer_cast<LadspaPlugin> (plugin);
741
742         cui->combo_map = new std::map<string, float>;
743         lrdf_defaults* defaults = lrdf_get_scale_values(lp->unique_id(), port_index);
744         if (defaults)   {
745                 for (uint32_t i = 0; i < defaults->count; ++i) {
746                         enums.push_back(defaults->items[i].label);
747                         pair<string, float> newpair;
748                         newpair.first = defaults->items[i].label;
749                         newpair.second = defaults->items[i].value;
750                         cui->combo_map->insert(newpair);
751                 }
752
753                 lrdf_free_setting_values(defaults);
754         }
755
756         return enums;
757 }