e3be1cc2660571efbcf64048c08a5281ad536dc7
[ardour.git] / gtk2_ardour / generic_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 GenericPluginUI::GenericPluginUI (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, &GenericPluginUI::redirect_active_changed));
107         bypass_button.set_active (!insert->active());
108         
109         build ();
110 }
111
112 GenericPluginUI::~GenericPluginUI ()
113 {
114         if (output_controls.size() > 0) {
115                 screen_update_connection.disconnect();
116         }
117 }
118
119 void
120 GenericPluginUI::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 GenericPluginUI::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 GenericPluginUI::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 GenericPluginUI::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 GenericPluginUI::print_parameter (char *buf, uint32_t len, uint32_t param)
357 {
358         plugin->print_parameter (param, buf, len);
359 }
360
361 GenericPluginUI::ControlUI*
362 GenericPluginUI::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                         // all LADPSA plugins have a numeric unique ID
391                         uint32_t id = atol (lp->unique_id().c_str());
392
393                         lrdf_defaults* defaults = lrdf_get_scale_values(id, port_index);
394                         
395                         if (defaults && defaults->count > 0)    {
396                                 
397                                 control_ui->combo = new Gtk::ComboBoxText;
398                                 //control_ui->combo->set_value_in_list(true, false);
399                                 set_popdown_strings (*control_ui->combo, setup_scale_values(port_index, control_ui));
400                                 control_ui->combo->signal_changed().connect (bind (mem_fun(*this, &GenericPluginUI::control_combo_changed), control_ui));
401                                 plugin->ParameterChanged.connect (bind (mem_fun (*this, &GenericPluginUI::parameter_changed), control_ui));
402                                 control_ui->pack_start(control_ui->label, true, true);
403                                 control_ui->pack_start(*control_ui->combo, false, true);
404                                 
405                                 update_control_display(control_ui);
406                                 
407                                 lrdf_free_setting_values(defaults);
408                                 return control_ui;
409                         }
410                 }
411                         
412                 if (desc.toggled) {
413
414                         /* Build a button */
415                 
416                         control_ui->button = manage (new ToggleButton ());
417                         control_ui->button->set_name ("PluginEditorButton");
418                         control_ui->button->set_size_request (20, 20);
419
420                         control_ui->pack_start (control_ui->label, true, true);
421                         control_ui->pack_start (*control_ui->button, false, true);
422                         control_ui->pack_start (control_ui->automate_button, false, false);
423
424                         control_ui->button->signal_clicked().connect (bind (mem_fun(*this, &GenericPluginUI::control_port_toggled), control_ui));
425                 
426                         if(plugin->get_parameter (port_index) == 1){
427                                 control_ui->button->set_active(true);
428                         }
429
430                         return control_ui;
431                 }
432         
433                 control_ui->adjustment = new Adjustment (0, 0, 0, 0, 0);
434
435                 /* XXX this code is not right yet, because it doesn't handle
436                    the absence of bounds in any sensible fashion.
437                 */
438
439                 control_ui->adjustment->set_lower (desc.lower);
440                 control_ui->adjustment->set_upper (desc.upper);
441
442                 control_ui->logarithmic = desc.logarithmic;
443                 if (control_ui->logarithmic) {
444                         if (control_ui->adjustment->get_lower() == 0.0) {
445                                 control_ui->adjustment->set_lower (control_ui->adjustment->get_upper()/10000);
446                         }
447                         control_ui->adjustment->set_upper (log(control_ui->adjustment->get_upper()));
448                         control_ui->adjustment->set_lower (log(control_ui->adjustment->get_lower()));
449                 }
450         
451                 float delta = desc.upper - desc.lower;
452
453                 control_ui->adjustment->set_page_size (delta/100.0);
454                 control_ui->adjustment->set_step_increment (desc.step);
455                 control_ui->adjustment->set_page_increment (desc.largestep);
456
457                 if (desc.integer_step) {
458                         control_ui->clickbox = new ClickBox (control_ui->adjustment, "PluginUIClickBox");
459                         Gtkmm2ext::set_size_request_to_display_given_text (*control_ui->clickbox, "g9999999", 2, 2);
460                         control_ui->clickbox->set_print_func (integer_printer, 0);
461                 } else {
462                         sigc::slot<void,char*,uint32_t> pslot = sigc::bind (mem_fun(*this, &GenericPluginUI::print_parameter), (uint32_t) port_index);
463
464                         control_ui->control = new BarController (*control_ui->adjustment, *mcontrol, pslot);
465                         control_ui->control->set_size_request (200, req.height);
466                         control_ui->control->set_name (X_("PluginSlider"));
467                         control_ui->control->set_style (BarController::LeftToRight);
468                         control_ui->control->set_use_parent (true);
469
470                         control_ui->control->StartGesture.connect (bind (mem_fun(*this, &GenericPluginUI::start_touch), control_ui));
471                         control_ui->control->StopGesture.connect (bind (mem_fun(*this, &GenericPluginUI::stop_touch), control_ui));
472                         
473                 }
474
475                 if (control_ui->logarithmic) {
476                         control_ui->adjustment->set_value(log(plugin->get_parameter(port_index)));
477                 } else{
478                         control_ui->adjustment->set_value(plugin->get_parameter(port_index));
479                 }
480
481                 /* XXX memory leak: SliderController not destroyed by ControlUI
482                    destructor, and manage() reports object hierarchy
483                    ambiguity.
484                 */
485
486                 control_ui->pack_start (control_ui->label, true, true);
487                 if (desc.integer_step) {
488                         control_ui->pack_start (*control_ui->clickbox, false, false);
489                 } else {
490                         control_ui->pack_start (*control_ui->control, false, false);
491                 }
492
493                 control_ui->pack_start (control_ui->automate_button, false, false);
494                 control_ui->adjustment->signal_value_changed().connect (bind (mem_fun(*this, &GenericPluginUI::control_adjustment_changed), control_ui));
495                 control_ui->automate_button.signal_clicked().connect (bind (mem_fun(*this, &GenericPluginUI::astate_clicked), control_ui, (uint32_t) port_index));
496
497                 automation_state_changed (control_ui);
498
499                 plugin->ParameterChanged.connect (bind (mem_fun(*this, &GenericPluginUI::parameter_changed), control_ui));
500                 insert->automation_list (port_index).automation_state_changed.connect 
501                         (bind (mem_fun(*this, &GenericPluginUI::automation_state_changed), control_ui));
502
503         } else if (plugin->parameter_is_output (port_index)) {
504
505                 control_ui->display = manage (new EventBox);
506                 control_ui->display->set_name ("ParameterValueDisplay");
507
508                 control_ui->display_label = manage (new Label);
509
510                 control_ui->display_label->set_name ("ParameterValueDisplay");
511
512                 control_ui->display->add (*control_ui->display_label);
513                 Gtkmm2ext::set_size_request_to_display_given_text (*control_ui->display, "-99,99", 2, 2);
514
515                 control_ui->display->show_all ();
516
517                 /* set up a meter */
518                 /* TODO: only make a meter if the port is Hinted for it */
519
520                 MeterInfo * info = new MeterInfo(port_index);
521                 control_ui->meterinfo = info;
522                 
523                 info->meter = new FastMeter (5, 100, FastMeter::Vertical);
524
525                 info->min_unbound = desc.min_unbound;
526                 info->max_unbound = desc.max_unbound;
527
528                 info->min = desc.lower;
529                 info->max = desc.upper;
530
531                 control_ui->vbox = manage (new VBox);
532                 control_ui->hbox = manage (new HBox);
533                 
534                 control_ui->label.set_angle(90);
535                 control_ui->hbox->pack_start (control_ui->label, false, false);
536                 control_ui->hbox->pack_start (*info->meter, false, false);
537
538                 control_ui->vbox->pack_start (*control_ui->hbox, false, false);
539                 
540                 control_ui->vbox->pack_start (*control_ui->display, false, false);
541
542                 control_ui->pack_start (*control_ui->vbox);
543
544                 control_ui->meterinfo->meter->show_all();
545                 control_ui->meterinfo->packed = true;
546                 
547                 output_controls.push_back (control_ui);
548         }
549         
550         plugin->ParameterChanged.connect (bind (mem_fun(*this, &GenericPluginUI::parameter_changed), control_ui));
551         return control_ui;
552 }
553
554 void
555 GenericPluginUI::start_touch (GenericPluginUI::ControlUI* cui)
556 {
557         insert->automation_list (cui->port_index).start_touch ();
558 }
559
560 void
561 GenericPluginUI::stop_touch (GenericPluginUI::ControlUI* cui)
562 {
563         insert->automation_list (cui->port_index).stop_touch ();
564 }
565
566 void
567 GenericPluginUI::astate_clicked (ControlUI* cui, uint32_t port)
568 {
569         using namespace Menu_Helpers;
570
571         if (automation_menu == 0) {
572                 automation_menu = manage (new Menu);
573                 automation_menu->set_name ("ArdourContextMenu");
574         } 
575
576         MenuList& items (automation_menu->items());
577
578         items.clear ();
579         items.push_back (MenuElem (_("Manual"), 
580                                    bind (mem_fun(*this, &GenericPluginUI::set_automation_state), (AutoState) Off, cui)));
581         items.push_back (MenuElem (_("Play"),
582                                    bind (mem_fun(*this, &GenericPluginUI::set_automation_state), (AutoState) Play, cui)));
583         items.push_back (MenuElem (_("Write"),
584                                    bind (mem_fun(*this, &GenericPluginUI::set_automation_state), (AutoState) Write, cui)));
585         items.push_back (MenuElem (_("Touch"),
586                                    bind (mem_fun(*this, &GenericPluginUI::set_automation_state), (AutoState) Touch, cui)));
587
588         automation_menu->popup (1, gtk_get_current_event_time());
589 }
590
591 void
592 GenericPluginUI::set_automation_state (AutoState state, ControlUI* cui)
593 {
594         insert->set_port_automation_state (cui->port_index, state);
595 }
596
597 void
598 GenericPluginUI::control_adjustment_changed (ControlUI* cui)
599 {
600         if (cui->ignore_change) {
601                 return;
602         }
603
604         double value = cui->adjustment->get_value();
605
606         if (cui->logarithmic) {
607                 value = exp(value);
608         }
609
610         insert->set_parameter (cui->port_index, (float) value);
611 }
612
613 void
614 GenericPluginUI::parameter_changed (uint32_t abs_port_id, float val, ControlUI* cui)
615 {
616         if (cui->port_index == abs_port_id) {
617                 if (!cui->update_pending) {
618                         cui->update_pending = true;
619                         Gtkmm2ext::UI::instance()->call_slot (bind (mem_fun(*this, &GenericPluginUI::update_control_display), cui));
620                 }
621         }
622 }
623
624 void
625 GenericPluginUI::update_control_display (ControlUI* cui)        
626 {
627         /* XXX how do we handle logarithmic stuff here ? */
628         
629         cui->update_pending = false;
630
631         float val = plugin->get_parameter (cui->port_index);
632
633         cui->ignore_change++;
634         if (cui->combo) {
635                 std::map<string,float>::iterator it;
636                 for (it = cui->combo_map->begin(); it != cui->combo_map->end(); ++it) {
637                         if (it->second == val) {
638                                 cui->combo->set_active_text(it->first);
639                                 break;
640                         }
641                 }
642         } else if (cui->adjustment == 0) {
643
644                 if (val > 0.5) {
645                         cui->button->set_active (true);
646                 } else {
647                         cui->button->set_active (false);
648                 }
649
650         } else {
651                 if (cui->logarithmic) {
652                         val = log(val);
653                 }
654                 if (val != cui->adjustment->get_value()) {
655                         cui->adjustment->set_value (val);
656                 }
657         }
658         cui->ignore_change--;
659 }
660
661 void
662 GenericPluginUI::control_port_toggled (ControlUI* cui)
663 {
664         if (!cui->ignore_change) {
665                 insert->set_parameter (cui->port_index, cui->button->get_active());
666         }
667 }
668
669 void
670 GenericPluginUI::control_combo_changed (ControlUI* cui)
671 {
672         if (!cui->ignore_change) {
673                 string value = cui->combo->get_active_text();
674                 std::map<string,float> mapping = *cui->combo_map;
675                 insert->set_parameter (cui->port_index, mapping[value]);
676         }
677
678 }
679
680 void
681 GenericPluginUI::redirect_active_changed (Redirect* r, void* src)
682 {
683         ENSURE_GUI_THREAD(bind (mem_fun(*this, &GenericPluginUI::redirect_active_changed), r, src));
684         
685         bypass_button.set_active (!r->active());
686 }
687
688 bool
689 GenericPluginUI::start_updating (GdkEventAny* ignored)
690 {
691         if (output_controls.size() > 0 ) {
692                 screen_update_connection.disconnect();
693                 screen_update_connection = ARDOUR_UI::instance()->RapidScreenUpdate.connect 
694                         (mem_fun(*this, &GenericPluginUI::output_update));
695         }
696         return false;
697 }
698
699 bool
700 GenericPluginUI::stop_updating (GdkEventAny* ignored)
701 {
702         if (output_controls.size() > 0 ) {
703                 screen_update_connection.disconnect();
704         }
705         return false;
706 }
707
708 void
709 GenericPluginUI::output_update ()
710 {
711         for (vector<ControlUI*>::iterator i = output_controls.begin(); i != output_controls.end(); ++i) {
712                 float val = plugin->get_parameter ((*i)->port_index);
713                 char buf[32];
714                 snprintf (buf, sizeof(buf), "%.2f", val);
715                 (*i)->display_label->set_text (buf);
716
717                 /* autoscaling for the meter */
718                 if ((*i)->meterinfo && (*i)->meterinfo->packed) {
719                         
720                         if (val < (*i)->meterinfo->min) {
721                                 if ((*i)->meterinfo->min_unbound)
722                                         (*i)->meterinfo->min = val;
723                                 else
724                                         val = (*i)->meterinfo->min;
725                         }
726
727                         if (val > (*i)->meterinfo->max) {
728                                 if ((*i)->meterinfo->max_unbound)
729                                         (*i)->meterinfo->max = val;
730                                 else
731                                         val = (*i)->meterinfo->max;
732                         }
733                         
734                         if ((*i)->meterinfo->max > (*i)->meterinfo->min ) {
735                                 float lval = (val - (*i)->meterinfo->min) / ((*i)->meterinfo->max - (*i)->meterinfo->min) ;
736                                 (*i)->meterinfo->meter->set (lval );
737                         }
738                 }
739         }
740 }
741
742 vector<string> 
743 GenericPluginUI::setup_scale_values(guint32 port_index, ControlUI* cui)
744 {
745         vector<string> enums;
746         boost::shared_ptr<LadspaPlugin> lp = boost::dynamic_pointer_cast<LadspaPlugin> (plugin);
747
748         if (!lp) {
749                 return enums;
750         }
751         
752         // all LADPSA plugins have a numeric unique ID
753         uint32_t id = atol (lp->unique_id().c_str());
754
755         cui->combo_map = new std::map<string, float>;
756                             lrdf_defaults* defaults = lrdf_get_scale_values(id, port_index);
757         if (defaults)   {
758                 for (uint32_t i = 0; i < defaults->count; ++i) {
759                         enums.push_back(defaults->items[i].label);
760                         pair<string, float> newpair;
761                         newpair.first = defaults->items[i].label;
762                         newpair.second = defaults->items[i].value;
763                         cui->combo_map->insert(newpair);
764                 }
765
766                 lrdf_free_setting_values(defaults);
767         }
768
769         return enums;
770 }