remove debug output from last commit
[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 = 1;
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, _("Automation control"));
296
297         /* XXX translators: use a string here that will be at least as long
298            as the longest automation label (see ::automation_state_changed()
299            below). be sure to include a descender.
300         */
301
302         set_size_request_to_display_given_text (*automate_button.get_child(), _("Mgnual"), 5, 5);
303
304         ignore_change = 0;
305         display = 0;
306         button = 0;
307         control = 0;
308         clickbox = 0;
309         adjustment = 0;
310         meterinfo = 0;
311 }
312
313 LadspaPluginUI::ControlUI::~ControlUI() 
314 {
315         if (adjustment) {
316                 delete adjustment;
317         }
318
319         if (meterinfo) {
320                 delete meterinfo->meter;
321                 delete meterinfo;
322         }
323 }
324
325 void
326 LadspaPluginUI::automation_state_changed (ControlUI* cui)
327 {
328         /* update button label */
329
330         switch (insert->get_port_automation_state (cui->port_index) & (Off|Play|Touch|Write)) {
331         case Off:
332                 cui->automate_button.set_label (_("Manual"));
333                 break;
334         case Play:
335                 cui->automate_button.set_label (_("Play"));
336                 break;
337         case Write:
338                 cui->automate_button.set_label (_("Write"));
339                 break;
340         case Touch:
341                 cui->automate_button.set_label (_("Touch"));
342                 break;
343         default:
344                 cui->automate_button.set_label (_("???"));
345                 break;
346         }
347 }
348
349
350 static void integer_printer (char buf[32], Adjustment &adj, void *arg)
351 {
352         snprintf (buf, 32, "%.0f", adj.get_value());
353 }
354
355 void
356 LadspaPluginUI::print_parameter (char *buf, uint32_t len, uint32_t param)
357 {
358         plugin->print_parameter (param, buf, len);
359 }
360
361 LadspaPluginUI::ControlUI*
362 LadspaPluginUI::build_control_ui (guint32 port_index, PBD::Controllable* mcontrol)
363
364 {
365         ControlUI* control_ui;
366         Plugin::ParameterDescriptor desc;
367
368         plugin->get_parameter_descriptor (port_index, desc);
369
370         control_ui = manage (new ControlUI ());
371         control_ui->adjustment = 0;
372         control_ui->combo = 0;
373         control_ui->combo_map = 0;
374         control_ui->port_index = port_index;
375         control_ui->update_pending = false;
376         control_ui->label.set_text (desc.label);
377         control_ui->label.set_alignment (0.0, 0.5);
378         control_ui->label.set_name ("PluginParameterLabel");
379
380         control_ui->set_spacing (5);
381
382         Gtk::Requisition req (control_ui->automate_button.size_request());
383
384         if (plugin->parameter_is_input (port_index)) {
385
386                 boost::shared_ptr<LadspaPlugin> lp;
387
388                 if ((lp = boost::dynamic_pointer_cast<LadspaPlugin>(plugin)) != 0) {
389                         
390                         lrdf_defaults* defaults = lrdf_get_scale_values(lp->unique_id(), port_index);
391                         
392                         if (defaults && defaults->count > 0)    {
393                                 
394                                 control_ui->combo = new Gtk::ComboBoxText;
395                                 //control_ui->combo->set_value_in_list(true, false);
396                                 set_popdown_strings (*control_ui->combo, setup_scale_values(port_index, control_ui));
397                                 control_ui->combo->signal_changed().connect (bind (mem_fun(*this, &LadspaPluginUI::control_combo_changed), control_ui));
398                                 plugin->ParameterChanged.connect (bind (mem_fun (*this, &LadspaPluginUI::parameter_changed), control_ui));
399                                 control_ui->pack_start(control_ui->label, true, true);
400                                 control_ui->pack_start(*control_ui->combo, false, true);
401                                 
402                                 update_control_display(control_ui);
403                                 
404                                 lrdf_free_setting_values(defaults);
405                                 return control_ui;
406                         }
407                 }
408                         
409                 if (desc.toggled) {
410
411                         /* Build a button */
412                 
413                         control_ui->button = manage (new ToggleButton ());
414                         control_ui->button->set_name ("PluginEditorButton");
415                         control_ui->button->set_size_request (20, 20);
416
417                         control_ui->pack_start (control_ui->label, true, true);
418                         control_ui->pack_start (*control_ui->button, false, true);
419                         control_ui->pack_start (control_ui->automate_button, false, false);
420
421                         control_ui->button->signal_clicked().connect (bind (mem_fun(*this, &LadspaPluginUI::control_port_toggled), control_ui));
422                 
423                         if(plugin->get_parameter (port_index) == 1){
424                                 control_ui->button->set_active(true);
425                         }
426
427                         return control_ui;
428                 }
429         
430                 control_ui->adjustment = new Adjustment (0, 0, 0, 0, 0);
431
432                 /* XXX this code is not right yet, because it doesn't handle
433                    the absence of bounds in any sensible fashion.
434                 */
435
436                 control_ui->adjustment->set_lower (desc.lower);
437                 control_ui->adjustment->set_upper (desc.upper);
438
439                 control_ui->logarithmic = desc.logarithmic;
440                 if (control_ui->logarithmic) {
441                         if (control_ui->adjustment->get_lower() == 0.0) {
442                                 control_ui->adjustment->set_lower (control_ui->adjustment->get_upper()/10000);
443                         }
444                         control_ui->adjustment->set_upper (log(control_ui->adjustment->get_upper()));
445                         control_ui->adjustment->set_lower (log(control_ui->adjustment->get_lower()));
446                 }
447         
448                 float delta = desc.upper - desc.lower;
449
450                 control_ui->adjustment->set_page_size (delta/100.0);
451                 control_ui->adjustment->set_step_increment (desc.step);
452                 control_ui->adjustment->set_page_increment (desc.largestep);
453
454                 if (desc.integer_step) {
455                         control_ui->clickbox = new ClickBox (control_ui->adjustment, "PluginUIClickBox");
456                         Gtkmm2ext::set_size_request_to_display_given_text (*control_ui->clickbox, "g9999999", 2, 2);
457                         control_ui->clickbox->set_print_func (integer_printer, 0);
458                 } else {
459                         sigc::slot<void,char*,uint32_t> pslot = sigc::bind (mem_fun(*this, &LadspaPluginUI::print_parameter), (uint32_t) port_index);
460
461                         control_ui->control = new BarController (*control_ui->adjustment, *mcontrol, pslot);
462                         control_ui->control->set_size_request (200, req.height);
463                         control_ui->control->set_name (X_("PluginSlider"));
464                         control_ui->control->set_style (BarController::LeftToRight);
465                         control_ui->control->set_use_parent (true);
466
467                         control_ui->control->StartGesture.connect (bind (mem_fun(*this, &LadspaPluginUI::start_touch), control_ui));
468                         control_ui->control->StopGesture.connect (bind (mem_fun(*this, &LadspaPluginUI::stop_touch), control_ui));
469                         
470                 }
471
472                 if (control_ui->logarithmic) {
473                         control_ui->adjustment->set_value(log(plugin->get_parameter(port_index)));
474                 } else{
475                         control_ui->adjustment->set_value(plugin->get_parameter(port_index));
476                 }
477
478                 /* XXX memory leak: SliderController not destroyed by ControlUI
479                    destructor, and manage() reports object hierarchy
480                    ambiguity.
481                 */
482
483                 control_ui->pack_start (control_ui->label, true, true);
484                 if (desc.integer_step) {
485                         control_ui->pack_start (*control_ui->clickbox, false, false);
486                 } else {
487                         control_ui->pack_start (*control_ui->control, false, false);
488                 }
489
490                 control_ui->pack_start (control_ui->automate_button, false, false);
491                 control_ui->adjustment->signal_value_changed().connect (bind (mem_fun(*this, &LadspaPluginUI::control_adjustment_changed), control_ui));
492                 control_ui->automate_button.signal_clicked().connect (bind (mem_fun(*this, &LadspaPluginUI::astate_clicked), control_ui, (uint32_t) port_index));
493
494                 automation_state_changed (control_ui);
495
496                 plugin->ParameterChanged.connect (bind (mem_fun(*this, &LadspaPluginUI::parameter_changed), control_ui));
497                 insert->automation_list (port_index).automation_state_changed.connect 
498                         (bind (mem_fun(*this, &LadspaPluginUI::automation_state_changed), control_ui));
499
500         } else if (plugin->parameter_is_output (port_index)) {
501
502                 control_ui->display = manage (new EventBox);
503                 control_ui->display->set_name ("ParameterValueDisplay");
504
505                 control_ui->display_label = manage (new Label);
506
507                 control_ui->display_label->set_name ("ParameterValueDisplay");
508
509                 control_ui->display->add (*control_ui->display_label);
510                 Gtkmm2ext::set_size_request_to_display_given_text (*control_ui->display, "-99,99", 2, 2);
511
512                 control_ui->display->show_all ();
513
514                 /* set up a meter */
515                 /* TODO: only make a meter if the port is Hinted for it */
516
517                 MeterInfo * info = new MeterInfo(port_index);
518                 control_ui->meterinfo = info;
519                 
520                 info->meter = new FastMeter (5, 100, FastMeter::Vertical);
521
522                 info->min_unbound = desc.min_unbound;
523                 info->max_unbound = desc.max_unbound;
524
525                 info->min = desc.lower;
526                 info->max = desc.upper;
527
528                 control_ui->vbox = manage (new VBox);
529                 control_ui->hbox = manage (new HBox);
530                 
531                 control_ui->label.set_angle(90);
532                 control_ui->hbox->pack_start (control_ui->label, false, false);
533                 control_ui->hbox->pack_start (*info->meter, false, false);
534
535                 control_ui->vbox->pack_start (*control_ui->hbox, false, false);
536                 
537                 control_ui->vbox->pack_start (*control_ui->display, false, false);
538
539                 control_ui->pack_start (*control_ui->vbox);
540
541                 control_ui->meterinfo->meter->show_all();
542                 control_ui->meterinfo->packed = true;
543                 
544                 output_controls.push_back (control_ui);
545         }
546         
547         plugin->ParameterChanged.connect (bind (mem_fun(*this, &LadspaPluginUI::parameter_changed), control_ui));
548         return control_ui;
549 }
550
551 void
552 LadspaPluginUI::start_touch (LadspaPluginUI::ControlUI* cui)
553 {
554         insert->automation_list (cui->port_index).start_touch ();
555 }
556
557 void
558 LadspaPluginUI::stop_touch (LadspaPluginUI::ControlUI* cui)
559 {
560         insert->automation_list (cui->port_index).stop_touch ();
561 }
562
563 void
564 LadspaPluginUI::astate_clicked (ControlUI* cui, uint32_t port)
565 {
566         using namespace Menu_Helpers;
567
568         if (automation_menu == 0) {
569                 automation_menu = manage (new Menu);
570                 automation_menu->set_name ("ArdourContextMenu");
571         } 
572
573         MenuList& items (automation_menu->items());
574
575         items.clear ();
576         items.push_back (MenuElem (_("Manual"), 
577                                    bind (mem_fun(*this, &LadspaPluginUI::set_automation_state), (AutoState) Off, cui)));
578         items.push_back (MenuElem (_("Play"),
579                                    bind (mem_fun(*this, &LadspaPluginUI::set_automation_state), (AutoState) Play, cui)));
580         items.push_back (MenuElem (_("Write"),
581                                    bind (mem_fun(*this, &LadspaPluginUI::set_automation_state), (AutoState) Write, cui)));
582         items.push_back (MenuElem (_("Touch"),
583                                    bind (mem_fun(*this, &LadspaPluginUI::set_automation_state), (AutoState) Touch, cui)));
584
585         automation_menu->popup (1, gtk_get_current_event_time());
586 }
587
588 void
589 LadspaPluginUI::set_automation_state (AutoState state, ControlUI* cui)
590 {
591         insert->set_port_automation_state (cui->port_index, state);
592 }
593
594 void
595 LadspaPluginUI::control_adjustment_changed (ControlUI* cui)
596 {
597         if (cui->ignore_change) {
598                 return;
599         }
600
601         double value = cui->adjustment->get_value();
602
603         if (cui->logarithmic) {
604                 value = exp(value);
605         }
606
607         insert->set_parameter (cui->port_index, (float) value);
608 }
609
610 void
611 LadspaPluginUI::parameter_changed (uint32_t abs_port_id, float val, ControlUI* cui)
612 {
613         if (cui->port_index == abs_port_id) {
614                 if (!cui->update_pending) {
615                         cui->update_pending = true;
616                         Gtkmm2ext::UI::instance()->call_slot (bind (mem_fun(*this, &LadspaPluginUI::update_control_display), cui));
617                 }
618         }
619 }
620
621 void
622 LadspaPluginUI::update_control_display (ControlUI* cui) 
623 {
624         /* XXX how do we handle logarithmic stuff here ? */
625         
626         cui->update_pending = false;
627
628         float val = plugin->get_parameter (cui->port_index);
629
630         cui->ignore_change++;
631         if (cui->combo) {
632                 std::map<string,float>::iterator it;
633                 for (it = cui->combo_map->begin(); it != cui->combo_map->end(); ++it) {
634                         if (it->second == val) {
635                                 cui->combo->set_active_text(it->first);
636                                 break;
637                         }
638                 }
639         } else if (cui->adjustment == 0) {
640
641                 if (val > 0.5) {
642                         cui->button->set_active (true);
643                 } else {
644                         cui->button->set_active (false);
645                 }
646
647         } else {
648                 if (cui->logarithmic) {
649                         val = log(val);
650                 }
651                 if (val != cui->adjustment->get_value()) {
652                         cui->adjustment->set_value (val);
653                 }
654         }
655         cui->ignore_change--;
656 }
657
658 void
659 LadspaPluginUI::control_port_toggled (ControlUI* cui)
660 {
661         if (!cui->ignore_change) {
662                 insert->set_parameter (cui->port_index, cui->button->get_active());
663         }
664 }
665
666 void
667 LadspaPluginUI::control_combo_changed (ControlUI* cui)
668 {
669         if (!cui->ignore_change) {
670                 string value = cui->combo->get_active_text();
671                 std::map<string,float> mapping = *cui->combo_map;
672                 insert->set_parameter (cui->port_index, mapping[value]);
673         }
674
675 }
676
677 void
678 LadspaPluginUI::redirect_active_changed (Redirect* r, void* src)
679 {
680         ENSURE_GUI_THREAD(bind (mem_fun(*this, &LadspaPluginUI::redirect_active_changed), r, src));
681         
682         bypass_button.set_active (!r->active());
683 }
684
685 bool
686 LadspaPluginUI::start_updating (GdkEventAny* ignored)
687 {
688         if (output_controls.size() > 0 ) {
689                 screen_update_connection.disconnect();
690                 screen_update_connection = ARDOUR_UI::instance()->RapidScreenUpdate.connect 
691                         (mem_fun(*this, &LadspaPluginUI::output_update));
692         }
693         return false;
694 }
695
696 bool
697 LadspaPluginUI::stop_updating (GdkEventAny* ignored)
698 {
699         if (output_controls.size() > 0 ) {
700                 screen_update_connection.disconnect();
701         }
702         return false;
703 }
704
705 void
706 LadspaPluginUI::output_update ()
707 {
708         for (vector<ControlUI*>::iterator i = output_controls.begin(); i != output_controls.end(); ++i) {
709                 float val = plugin->get_parameter ((*i)->port_index);
710                 char buf[32];
711                 snprintf (buf, sizeof(buf), "%.2f", val);
712                 (*i)->display_label->set_text (buf);
713
714                 /* autoscaling for the meter */
715                 if ((*i)->meterinfo && (*i)->meterinfo->packed) {
716                         
717                         if (val < (*i)->meterinfo->min) {
718                                 if ((*i)->meterinfo->min_unbound)
719                                         (*i)->meterinfo->min = val;
720                                 else
721                                         val = (*i)->meterinfo->min;
722                         }
723
724                         if (val > (*i)->meterinfo->max) {
725                                 if ((*i)->meterinfo->max_unbound)
726                                         (*i)->meterinfo->max = val;
727                                 else
728                                         val = (*i)->meterinfo->max;
729                         }
730                         
731                         if ((*i)->meterinfo->max > (*i)->meterinfo->min ) {
732                                 float lval = (val - (*i)->meterinfo->min) / ((*i)->meterinfo->max - (*i)->meterinfo->min) ;
733                                 (*i)->meterinfo->meter->set (lval );
734                         }
735                 }
736         }
737 }
738
739 vector<string> 
740 LadspaPluginUI::setup_scale_values(guint32 port_index, ControlUI* cui)
741 {
742         vector<string> enums;
743         boost::shared_ptr<LadspaPlugin> lp = boost::dynamic_pointer_cast<LadspaPlugin> (plugin);
744
745         cui->combo_map = new std::map<string, float>;
746         lrdf_defaults* defaults = lrdf_get_scale_values(lp->unique_id(), port_index);
747         if (defaults)   {
748                 for (uint32_t i = 0; i < defaults->count; ++i) {
749                         enums.push_back(defaults->items[i].label);
750                         pair<string, float> newpair;
751                         newpair.first = defaults->items[i].label;
752                         newpair.second = defaults->items[i].value;
753                         cui->combo_map->insert(newpair);
754                 }
755
756                 lrdf_free_setting_values(defaults);
757         }
758
759         return enums;
760 }