2 * GUI widget object implementations.
3 * Copyright (C) 2007-2009 Krzysztof Foltman
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General
16 * Public License along with this program; if not, write to the
17 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301 USA
24 #include <calf/ctl_curve.h>
25 #include <calf/ctl_keyboard.h>
26 #include <calf/ctl_knob.h>
27 #include <calf/ctl_led.h>
28 #include <calf/ctl_tube.h>
29 #include <calf/ctl_vumeter.h>
30 #include <calf/custom_ctl.h>
31 #include <calf/giface.h>
33 #include <calf/gui_controls.h>
34 #include <calf/utils.h>
36 #include <gdk/gdkkeysyms.h>
37 #include <calf/ctl_linegraph.h>
40 using namespace calf_plugins
;
41 using namespace calf_utils
;
44 #define SANITIZE(value) (std::abs(value) < small_value<float>()) ? 0.f : value
46 /******************************** control/container base class **********************/
48 void control_base::require_attribute(const char *name
)
50 if (attribs
.count(name
) == 0) {
51 g_error("Missing attribute '%s' in control '%s'", name
, control_name
.c_str());
55 void control_base::require_int_attribute(const char *name
)
57 require_attribute(name
);
58 if (attribs
[name
].empty() || attribs
[name
].find_first_not_of("0123456789") != string::npos
) {
59 g_error("Wrong data type on attribute '%s' in control '%s' (required integer)", name
, control_name
.c_str());
63 int control_base::get_int(const char *name
, int def_value
)
65 if (attribs
.count(name
) == 0)
67 const std::string
&v
= attribs
[name
];
68 if (v
.empty() || v
.find_first_not_of("-+0123456789") != string::npos
)
70 return atoi(v
.c_str());
73 float control_base::get_float(const char *name
, float def_value
)
75 if (attribs
.count(name
) == 0)
77 const std::string
&v
= attribs
[name
];
78 if (v
.empty() || v
.find_first_not_of("-+0123456789.") != string::npos
)
86 /******************************** container base class **********************/
88 void control_container::set_std_properties()
90 if (attribs
.find("widget-name") != attribs
.end())
92 string name
= attribs
["widget-name"];
94 gtk_widget_set_name(GTK_WIDGET(container
), name
.c_str());
99 /************************* param-associated control base class **************/
101 param_control::param_control()
106 old_displayed_value
= -1.f
;
111 void param_control::set_std_properties()
113 if (attribs
.find("widget-name") != attribs
.end())
115 string name
= attribs
["widget-name"];
117 gtk_widget_set_name(widget
, name
.c_str());
122 void param_control::hook_params()
124 if (param_no
!= -1) {
125 gui
->add_param_ctl(param_no
, this);
127 gui
->params
.push_back(this);
130 param_control::~param_control()
132 //if (GTK_IS_WIDGET(widget))
133 // gtk_widget_destroy(widget);
136 void param_control::add_context_menu_handler()
140 g_signal_connect(GTK_OBJECT(widget
), "button-press-event", (GCallback
)on_button_press_event
, this);
144 gboolean
param_control::on_button_press_event(GtkWidget
*widget
, GdkEventButton
*event
, void *user_data
)
146 param_control
*self
= (param_control
*)user_data
;
147 const parameter_properties
&props
= self
->get_props();
148 if (event
->button
== 3 && !(props
.flags
& PF_PROP_OUTPUT
))
150 self
->do_popup_menu();
153 else if (event
->button
== 2)
155 self
->create_value_entry(widget
, event
->x_root
, event
->y_root
);
161 void param_control::do_popup_menu()
164 gui
->on_control_popup(this, param_no
);
167 void param_control::destroy_value_entry ()
169 // remove the window containing the entry
170 gtk_widget_destroy(GTK_WIDGET(entrywin
));
173 gboolean
param_control::value_entry_unfocus(GtkWidget
*widget
, GdkEventFocus
*event
, void *user_data
)
175 // destroy window if it looses focus
176 param_control
*self
= (param_control
*)user_data
;
177 self
->destroy_value_entry();
180 gboolean
param_control::value_entry_action(GtkEntry
*widget
, GdkEvent
*event
, void *user_data
)
182 // called when a key was hit, sorts out and treats RETURN and ESC
183 param_control
*self
= (param_control
*)user_data
;
184 const parameter_properties
&props
= self
->get_props();
185 GdkEventKey
*key
= (GdkEventKey
*)event
;
186 if(key
->keyval
== GDK_Escape
)
187 self
->destroy_value_entry();
188 else if (key
->keyval
== GDK_Return
) {
189 float val
= props
.string_to_value(gtk_entry_get_text(widget
));
190 self
->gui
->plugin
->set_param_value(self
->param_no
, val
);
192 self
->destroy_value_entry();
196 void param_control::create_value_entry(GtkWidget
*widget
, int x
, int y
)
199 // kill an existing entry window on re-trigger
200 destroy_value_entry();
207 const parameter_properties
&props
= get_props();
208 float value
= gui
->plugin
->get_param_value(param_no
);
210 // no chance for a menu, so we have to do everything by hand
211 entrywin
= gtk_window_new(GTK_WINDOW_TOPLEVEL
);
212 gtk_widget_set_name(GTK_WIDGET(entrywin
), "Calf-Value-Entry");
213 gtk_window_set_title (GTK_WINDOW(entrywin
), "Calf Value Entry");
214 gtk_window_set_resizable (GTK_WINDOW(entrywin
), FALSE
);
215 gtk_window_set_decorated (GTK_WINDOW(entrywin
), FALSE
);
216 gtk_window_set_skip_taskbar_hint (GTK_WINDOW(entrywin
), TRUE
);
217 gtk_window_set_skip_pager_hint (GTK_WINDOW(entrywin
), TRUE
);
218 gtk_window_set_transient_for (GTK_WINDOW(entrywin
), GTK_WINDOW (gui
->window
->toplevel
));
219 gtk_window_set_gravity(GTK_WINDOW(entrywin
), GDK_GRAVITY_CENTER
);
220 gtk_widget_set_events (GTK_WIDGET(entrywin
), GDK_FOCUS_CHANGE_MASK
);
221 g_signal_connect (G_OBJECT(entrywin
), "focus-out-event", G_CALLBACK (value_entry_unfocus
), this);
223 // create the text entry
224 GtkWidget
*entry
= gtk_entry_new();
225 gtk_widget_set_name(GTK_WIDGET(entry
), "Calf-Entry");
226 gtk_entry_set_width_chars(GTK_ENTRY(entry
), props
.get_char_count());
227 gtk_entry_set_text(GTK_ENTRY(entry
), props
.to_string(value
).c_str());
228 gtk_widget_add_events (entry
, GDK_KEY_PRESS_MASK
);
229 g_signal_connect (entry
, "key-press-event", (GCallback
)value_entry_action
, this);
231 // stitch together and show
232 gtk_container_add(GTK_CONTAINER (entrywin
), entry
);
233 gtk_widget_show_all(entrywin
);
234 gtk_window_move(GTK_WINDOW (entrywin
), x
, y
);
240 /******************************** Combo Box ********************************/
242 GtkWidget
*combo_box_param_control::create(plugin_gui
*_gui
, int _param_no
)
245 param_no
= _param_no
;
246 lstore
= gtk_list_store_new(2, G_TYPE_STRING
, G_TYPE_STRING
); // value, key
248 const parameter_properties
&props
= get_props();
249 widget
= calf_combobox_new ();
250 if (param_no
!= -1 && props
.choices
)
252 for (int j
= (int)props
.min
; j
<= (int)props
.max
; j
++)
253 gtk_list_store_insert_with_values (lstore
, NULL
, j
- (int)props
.min
, 0, props
.choices
[j
- (int)props
.min
], 1, calf_utils::i2s(j
).c_str(), -1);
255 gtk_combo_box_set_model (GTK_COMBO_BOX(widget
), GTK_TREE_MODEL(lstore
));
256 g_signal_connect (GTK_OBJECT (widget
), "changed", G_CALLBACK (combo_value_changed
), (gpointer
)this);
257 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-Combobox");
261 void combo_box_param_control::set()
266 const parameter_properties
&props
= get_props();
267 gtk_combo_box_set_active (GTK_COMBO_BOX (widget
), (int)gui
->plugin
->get_param_value(param_no
) - (int)props
.min
);
271 void combo_box_param_control::get()
275 const parameter_properties
&props
= get_props();
276 gui
->set_param_value(param_no
, gtk_combo_box_get_active (GTK_COMBO_BOX(widget
)) + props
.min
, this);
280 void combo_box_param_control::combo_value_changed(GtkComboBox
*widget
, gpointer value
)
282 combo_box_param_control
*jhp
= (combo_box_param_control
*)value
;
283 if (jhp
->attribs
.count("setter-key"))
287 if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (jhp
->widget
), &iter
))
289 gtk_tree_model_get (GTK_TREE_MODEL (jhp
->lstore
), &iter
, 1, &key
, -1);
291 jhp
->gui
->plugin
->configure(jhp
->attribs
["setter-key"].c_str(), key
);
300 void combo_box_param_control::send_status(const char *key
, const char *value
)
302 if (attribs
.count("key") && key
== attribs
["key"])
304 gtk_list_store_clear (lstore
);
306 std::string v
= value
;
309 while (pos
< v
.length()) {
310 size_t endpos
= v
.find("\n", pos
);
311 if (endpos
== string::npos
)
313 string line
= v
.substr(pos
, endpos
- pos
);
315 size_t tabpos
= line
.find('\t');
316 if (tabpos
== string::npos
)
319 key
= line
.substr(0, tabpos
);
320 label
= line
.substr(tabpos
+ 1);
323 gtk_list_store_insert_with_values (lstore
, >i
, i
, 0, label
.c_str(), 1, key
.c_str(), -1);
330 if (attribs
.count("current-key") && key
== attribs
["current-key"])
337 void combo_box_param_control::set_to_last_key()
339 map
<string
, GtkTreeIter
>::iterator i
= key2pos
.find(last_key
);
340 if (i
!= key2pos
.end())
342 gtk_combo_box_set_active_iter (GTK_COMBO_BOX (widget
), &i
->second
);
346 gtk_combo_box_set_active (GTK_COMBO_BOX (widget
), -1);
349 /******************************** Horizontal Fader ********************************/
352 scale_to_default (gpointer data
)
354 hscale_param_control
*jhp
= (hscale_param_control
*)data
;
355 const parameter_properties
&props
= jhp
->get_props();
356 gtk_range_set_value (GTK_RANGE (jhp
->widget
), props
.to_01(props
.def_value
));
362 scale_button_press (GtkWidget
*widget
, GdkEventKey
*event
, gpointer
*user_data
)
364 if (event
->type
== GDK_2BUTTON_PRESS
) {
365 // this actually creates a harmless race condition, but diving deep
366 // into gtk signal handling code wouldn't and the resulting complexity
367 // would not really be worth the effort
368 // The timeout is set high enough that most of the time the race
369 // will turn out in our/the users favor
370 g_timeout_add (200, (GSourceFunc
)scale_to_default
, user_data
);
377 GtkWidget
*hscale_param_control::create(plugin_gui
*_gui
, int _param_no
)
380 param_no
= _param_no
;
382 widget
= calf_fader_new(1, get_int("size", 2), 0, 1, get_props().get_increment());
384 g_signal_connect (GTK_OBJECT (widget
), "value-changed", G_CALLBACK (hscale_value_changed
), (gpointer
)this);
385 g_signal_connect (GTK_OBJECT (widget
), "format-value", G_CALLBACK (hscale_format_value
), (gpointer
)this);
386 g_signal_connect (GTK_OBJECT (widget
), "button-press-event", G_CALLBACK (scale_button_press
), (gpointer
)this);
388 if(get_int("inverted", 0) > 0) {
389 gtk_range_set_inverted(GTK_RANGE(widget
), TRUE
);
391 int size
= get_int("size", 2);
392 char *name
= g_strdup_printf("Calf-HScale%i", size
);
393 gtk_widget_set_name(GTK_WIDGET(widget
), name
);
394 gtk_widget_set_size_request (widget
, size
* 100, -1);
399 void hscale_param_control::init_xml(const char *element
)
401 if (attribs
.count("width"))
402 gtk_widget_set_size_request (widget
, get_int("width", 200), -1);
403 if (attribs
.count("position"))
405 string v
= attribs
["position"];
406 if (v
== "top") gtk_scale_set_value_pos(GTK_SCALE(widget
), GTK_POS_TOP
);
407 if (v
== "bottom") gtk_scale_set_value_pos(GTK_SCALE(widget
), GTK_POS_BOTTOM
);
411 void hscale_param_control::set()
414 const parameter_properties
&props
= get_props();
415 gtk_range_set_value (GTK_RANGE (widget
), props
.to_01 (gui
->plugin
->get_param_value(param_no
)));
416 // hscale_value_changed (GTK_HSCALE (widget), (gpointer)this);
419 void hscale_param_control::get()
421 const parameter_properties
&props
= get_props();
422 float cvalue
= props
.from_01 (gtk_range_get_value (GTK_RANGE (widget
)));
423 gui
->set_param_value(param_no
, cvalue
, this);
426 void hscale_param_control::hscale_value_changed(GtkHScale
*widget
, gpointer value
)
428 hscale_param_control
*jhp
= (hscale_param_control
*)value
;
432 gchar
*hscale_param_control::hscale_format_value(GtkScale
*widget
, double arg1
, gpointer value
)
434 hscale_param_control
*jhp
= (hscale_param_control
*)value
;
435 const parameter_properties
&props
= jhp
->get_props();
436 float cvalue
= props
.from_01 (arg1
);
439 // return g_strdup_printf ("%s = %g", props.to_string (cvalue).c_str(), arg1);
440 return g_strdup (props
.to_string (cvalue
).c_str());
443 /******************************** Vertical Fader ********************************/
445 GtkWidget
*vscale_param_control::create(plugin_gui
*_gui
, int _param_no
)
448 param_no
= _param_no
;
449 widget
= calf_fader_new(0, get_int("size", 2), 0, 1, get_props().get_increment());
450 g_signal_connect (GTK_OBJECT (widget
), "value-changed", G_CALLBACK (vscale_value_changed
), (gpointer
)this);
451 g_signal_connect (GTK_OBJECT (widget
), "button-press-event", G_CALLBACK (scale_button_press
), (gpointer
)this);
453 gtk_scale_set_draw_value(GTK_SCALE(widget
), FALSE
);
455 if(get_int("inverted", 0) > 0) {
456 gtk_range_set_inverted(GTK_RANGE(widget
), TRUE
);
458 int size
= get_int("size", 2);
459 char *name
= g_strdup_printf("Calf-VScale%i", size
);
460 gtk_widget_set_size_request (widget
, -1, size
* 100);
461 gtk_widget_set_name(GTK_WIDGET(widget
), name
);
466 void vscale_param_control::init_xml(const char *element
)
468 if (attribs
.count("height"))
469 gtk_widget_set_size_request (widget
, -1, get_int("height", 200));
472 void vscale_param_control::set()
475 const parameter_properties
&props
= get_props();
476 gtk_range_set_value (GTK_RANGE (widget
), props
.to_01 (gui
->plugin
->get_param_value(param_no
)));
477 // vscale_value_changed (GTK_HSCALE (widget), (gpointer)this);
480 void vscale_param_control::get()
482 const parameter_properties
&props
= get_props();
483 float cvalue
= props
.from_01 (gtk_range_get_value (GTK_RANGE (widget
)));
484 gui
->set_param_value(param_no
, cvalue
, this);
487 void vscale_param_control::vscale_value_changed(GtkHScale
*widget
, gpointer value
)
489 vscale_param_control
*jhp
= (vscale_param_control
*)value
;
493 /******************************** Label ********************************/
495 GtkWidget
*label_param_control::create(plugin_gui
*_gui
, int _param_no
)
497 gui
= _gui
, param_no
= _param_no
;
499 if (param_no
!= -1 && !attribs
.count("text"))
500 text
= get_props().name
;
502 text
= attribs
["text"];
503 widget
= gtk_label_new(text
.c_str());
504 gtk_misc_set_alignment (GTK_MISC (widget
), get_float("align-x", 0.5), get_float("align-y", 0.5));
505 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-Label");
509 /******************************** Value ********************************/
511 GtkWidget
*value_param_control::create(plugin_gui
*_gui
, int _param_no
)
514 param_no
= _param_no
;
516 widget
= gtk_label_new ("");
519 const parameter_properties
&props
= get_props();
520 gtk_label_set_width_chars (GTK_LABEL (widget
), props
.get_char_count());
524 require_attribute("key");
525 require_int_attribute("width");
526 param_variable
= attribs
["key"];
527 gtk_label_set_width_chars (GTK_LABEL (widget
), get_int("width"));
529 gtk_misc_set_alignment (GTK_MISC (widget
), get_float("align-x", 0.5), get_float("align-y", 0.5));
530 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-Value");
534 void value_param_control::set()
540 const parameter_properties
&props
= get_props();
541 string value
= props
.to_string(gui
->plugin
->get_param_value(param_no
));
543 if (value
== old_value
)
546 gtk_label_set_text (GTK_LABEL (widget
), value
.c_str());
549 void value_param_control::send_status(const char *key
, const char *value
)
551 if (key
== param_variable
)
553 gtk_label_set_text (GTK_LABEL (widget
), value
);
557 /******************************** VU Meter ********************************/
559 GtkWidget
*vumeter_param_control::create(plugin_gui
*_gui
, int _param_no
)
561 gui
= _gui
, param_no
= _param_no
;
562 // const parameter_properties &props = get_props();
563 widget
= calf_vumeter_new ();
564 gtk_widget_set_name(GTK_WIDGET(widget
), "calf-vumeter");
565 calf_vumeter_set_mode (CALF_VUMETER (widget
), (CalfVUMeterMode
)get_int("mode", 0));
566 CALF_VUMETER(widget
)->vumeter_hold
= get_float("hold", 0);
567 CALF_VUMETER(widget
)->vumeter_falloff
= get_float("falloff", 0.f
);
568 CALF_VUMETER(widget
)->vumeter_width
= get_int("width", 80);
569 CALF_VUMETER(widget
)->vumeter_height
= get_int("height", 18);
570 CALF_VUMETER(widget
)->vumeter_position
= get_int("position", 0);
571 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-VUMeter");
575 void vumeter_param_control::set()
578 // const parameter_properties &props = get_props();
579 calf_vumeter_set_value (CALF_VUMETER (widget
), gui
->plugin
->get_param_value(param_no
));
584 GtkWidget
*led_param_control::create(plugin_gui
*_gui
, int _param_no
)
586 gui
= _gui
, param_no
= _param_no
;
587 // const parameter_properties &props = get_props();
588 widget
= calf_led_new ();
589 gtk_widget_set_name(GTK_WIDGET(widget
), "calf-led");
590 CALF_LED(widget
)->led_mode
= get_int("mode", 0);
591 CALF_LED(widget
)->size
= get_int("size", 1);
592 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-LED");
596 void led_param_control::set()
599 // const parameter_properties &props = get_props();
600 calf_led_set_value (CALF_LED (widget
), gui
->plugin
->get_param_value(param_no
));
605 GtkWidget
*tube_param_control::create(plugin_gui
*_gui
, int _param_no
)
607 gui
= _gui
, param_no
= _param_no
;
608 // const parameter_properties &props = get_props();
609 widget
= calf_tube_new ();
610 gtk_widget_set_name(GTK_WIDGET(widget
), "calf-tube");
611 CALF_TUBE(widget
)->size
= get_int("size", 2);
612 CALF_TUBE(widget
)->direction
= get_int("direction", 2);
613 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-Tube");
617 void tube_param_control::set()
620 // const parameter_properties &props = get_props();
621 calf_tube_set_value (CALF_TUBE (widget
), gui
->plugin
->get_param_value(param_no
));
624 /******************************** Check Box ********************************/
626 GtkWidget
*check_param_control::create(plugin_gui
*_gui
, int _param_no
)
629 param_no
= _param_no
;
631 widget
= gtk_check_button_new ();
632 g_signal_connect (GTK_OBJECT (widget
), "toggled", G_CALLBACK (check_value_changed
), (gpointer
)this);
633 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-Checkbox");
637 void check_param_control::check_value_changed(GtkCheckButton
*widget
, gpointer value
)
639 param_control
*jhp
= (param_control
*)value
;
643 void check_param_control::get()
645 const parameter_properties
&props
= get_props();
646 gui
->set_param_value(param_no
, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widget
)) + props
.min
, this);
649 void check_param_control::set()
652 const parameter_properties
&props
= get_props();
653 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget
), (int)gui
->plugin
->get_param_value(param_no
) - (int)props
.min
);
656 /******************************** Radio Button ********************************/
658 GtkWidget
*radio_param_control::create(plugin_gui
*_gui
, int _param_no
)
661 param_no
= _param_no
;
662 require_attribute("value");
664 string value_name
= attribs
["value"];
665 const parameter_properties
&props
= get_props();
666 if (props
.choices
&& (value_name
< "0" || value_name
> "9"))
668 for (int i
= 0; props
.choices
[i
]; i
++)
670 if (value_name
== props
.choices
[i
])
672 value
= i
+ (int)props
.min
;
678 value
= get_int("value");
680 if (attribs
.count("label"))
681 widget
= gtk_radio_button_new_with_label (gui
->get_radio_group(param_no
), attribs
["label"].c_str());
683 widget
= gtk_radio_button_new_with_label (gui
->get_radio_group(param_no
), props
.choices
[value
- (int)props
.min
]);
684 gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (widget
), FALSE
);
686 gui
->set_radio_group(param_no
, gtk_radio_button_get_group (GTK_RADIO_BUTTON (widget
)));
687 g_signal_connect (GTK_OBJECT (widget
), "clicked", G_CALLBACK (radio_clicked
), (gpointer
)this);
688 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-RadioButton");
692 void radio_param_control::radio_clicked(GtkRadioButton
*widget
, gpointer value
)
694 param_control
*jhp
= (param_control
*)value
;
698 void radio_param_control::get()
700 // const parameter_properties &props = get_props();
701 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget
)))
702 gui
->set_param_value(param_no
, value
, this);
705 void radio_param_control::set()
708 const parameter_properties
&props
= get_props();
709 float pv
= gui
->plugin
->get_param_value(param_no
);
710 if (fabs(value
-pv
) < 0.5)
711 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget
), value
== ((int)gui
->plugin
->get_param_value(param_no
) - (int)props
.min
));
714 /******************************** Spin Button ********************************/
716 GtkWidget
*spin_param_control::create(plugin_gui
*_gui
, int _param_no
)
719 param_no
= _param_no
;
721 const parameter_properties
&props
= get_props();
723 widget
= gtk_spin_button_new_with_range (props
.min
, props
.max
, (props
.max
- props
.min
) / (props
.step
- 1));
725 widget
= gtk_spin_button_new_with_range (props
.min
, props
.max
, props
.step
);
727 widget
= gtk_spin_button_new_with_range (props
.min
, props
.max
, 1);
728 gtk_spin_button_set_digits (GTK_SPIN_BUTTON(widget
), get_int("digits", 0));
729 g_signal_connect (GTK_OBJECT (widget
), "value-changed", G_CALLBACK (value_changed
), (gpointer
)this);
730 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-SpinButton");
734 void spin_param_control::value_changed(GtkSpinButton
*widget
, gpointer value
)
736 param_control
*jhp
= (param_control
*)value
;
740 void spin_param_control::get()
742 // const parameter_properties &props = get_props();
743 gui
->set_param_value(param_no
, gtk_spin_button_get_value_as_float (GTK_SPIN_BUTTON (widget
)), this);
746 void spin_param_control::set()
749 // const parameter_properties &props = get_props();
750 gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget
), gui
->plugin
->get_param_value(param_no
));
753 /******************************** Button ********************************/
755 GtkWidget
*button_param_control::create(plugin_gui
*_gui
, int _param_no
)
758 param_no
= _param_no
;
760 widget
= calf_button_new ((gchar
*)get_props().name
);
761 g_signal_connect (GTK_OBJECT (widget
), "clicked", G_CALLBACK (button_clicked
), (gpointer
)this);
762 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-Button");
766 void button_param_control::button_clicked(GtkButton
*widget
, gpointer value
)
768 param_control
*jhp
= (param_control
*)value
;
772 void button_param_control::get()
774 const parameter_properties
&props
= get_props();
775 gui
->set_param_value(param_no
, props
.max
, this);
778 void button_param_control::set()
781 const parameter_properties
&props
= get_props();
782 if (gui
->plugin
->get_param_value(param_no
) - props
.min
>= 0.5)
783 gtk_button_clicked (GTK_BUTTON (widget
));
786 /******************************** Knob ********************************/
788 GtkWidget
*knob_param_control::create(plugin_gui
*_gui
, int _param_no
)
791 param_no
= _param_no
;
792 const parameter_properties
&props
= get_props();
794 //widget = calf_knob_new_with_range (props.to_01 (gui->plugin->get_param_value(param_no)), 0, 1, 0.01);
795 widget
= calf_knob_new();
796 float increment
= props
.get_increment();
797 gtk_range_get_adjustment(GTK_RANGE(widget
))->step_increment
= increment
;
798 CALF_KNOB(widget
)->default_value
= props
.to_01(props
.def_value
);
799 CALF_KNOB(widget
)->knob_type
= get_int("type");
800 CALF_KNOB(widget
)->knob_size
= get_int("size", 2);
801 if(CALF_KNOB(widget
)->knob_size
> 5) {
802 CALF_KNOB(widget
)->knob_size
= 5;
803 } else if (CALF_KNOB(widget
)->knob_size
< 1) {
804 CALF_KNOB(widget
)->knob_size
= 1;
806 g_signal_connect(GTK_OBJECT(widget
), "value-changed", G_CALLBACK(knob_value_changed
), (gpointer
)this);
807 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-Knob");
811 void knob_param_control::get()
813 const parameter_properties
&props
= get_props();
814 float value
= props
.from_01(gtk_range_get_value(GTK_RANGE(widget
)));
815 gui
->set_param_value(param_no
, value
, this);
818 void knob_param_control::set()
821 const parameter_properties
&props
= get_props();
822 gtk_range_set_value(GTK_RANGE(widget
), props
.to_01 (gui
->plugin
->get_param_value(param_no
)));
825 void knob_param_control::knob_value_changed(GtkWidget
*widget
, gpointer value
)
827 param_control
*jhp
= (param_control
*)value
;
831 /******************************** Toggle Button ********************************/
833 GtkWidget
*toggle_param_control::create(plugin_gui
*_gui
, int _param_no
)
836 param_no
= _param_no
;
837 widget
= calf_toggle_new ();
839 CALF_TOGGLE(widget
)->size
= get_int("size", 2);
841 g_signal_connect (GTK_OBJECT (widget
), "value-changed", G_CALLBACK (toggle_value_changed
), (gpointer
)this);
842 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-ToggleButton");
846 void toggle_param_control::get()
848 const parameter_properties
&props
= get_props();
849 float value
= props
.from_01(gtk_range_get_value(GTK_RANGE(widget
)));
850 gui
->set_param_value(param_no
, value
, this);
853 void toggle_param_control::set()
856 const parameter_properties
&props
= get_props();
857 gtk_range_set_value(GTK_RANGE(widget
), props
.to_01 (gui
->plugin
->get_param_value(param_no
)));
860 void toggle_param_control::toggle_value_changed(GtkWidget
*widget
, gpointer value
)
862 param_control
*jhp
= (param_control
*)value
;
866 /******************************** Tap Button ********************************/
868 GtkWidget
*tap_button_param_control::create(plugin_gui
*_gui
, int _param_no
)
871 param_no
= _param_no
;
876 widget
= calf_tap_button_new ();
877 //CALF_TAP(widget)->size = get_int("size", 2);
878 g_signal_connect (GTK_OBJECT (widget
), "button-press-event", G_CALLBACK (tap_button_pressed
), (gpointer
)this);
879 g_signal_connect (GTK_OBJECT (widget
), "released", G_CALLBACK (tap_button_released
), (gpointer
)this);
880 g_signal_connect (GTK_OBJECT (widget
), "leave", G_CALLBACK (tap_button_released
), (gpointer
)this);
881 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-TapButton");
885 void tap_button_param_control::get()
887 gui
->set_param_value(param_no
, value
, this);
890 void tap_button_param_control::set()
895 gettimeofday(&tv
, 0);
896 unsigned long _now
= tv
.tv_sec
* 1000;
897 if(_now
> init_time
+ 2000) {
898 // user stopped tapping
902 CALF_TAP_BUTTON(widget
)->state
= 0;
903 gtk_widget_queue_draw(widget
);
908 gboolean
tap_button_param_control::tap_button_pressed(GtkWidget
*widget
, GdkEventButton
*event
, gpointer value
)
910 tap_button_param_control
*ctl
= (tap_button_param_control
*)value
;
911 CalfTapButton
*tap
= CALF_TAP_BUTTON(widget
);
914 if (event
->type
== GDK_BUTTON_PRESS
and event
->button
== 1)
917 gettimeofday(&tv
, 0);
918 ctl
->init_time
= tv
.tv_sec
* 1000;
924 ctl
->avg_value
= (ctl
->avg_value
* 3 + (time
- ctl
->last_time
)) / 4.f
;
926 ctl
->avg_value
= time
- ctl
->last_time
;
927 ctl
->value
= 60.f
/ (float)(ctl
->avg_value
/ 1000.f
);
929 if (ctl
->value
> 30 and ctl
->value
< 300)
932 ctl
->last_time
= time
;
933 gtk_widget_queue_draw(widget
);
937 gboolean
tap_button_param_control::tap_button_released(GtkWidget
*widget
, gpointer value
)
939 tap_button_param_control
*ctl
= (tap_button_param_control
*)value
;
940 CalfTapButton
*tap
= CALF_TAP_BUTTON(widget
);
941 tap
->state
= ctl
->last_time
? 1 : 0;
942 gtk_widget_queue_draw(widget
);
946 /******************************** Keyboard ********************************/
948 GtkWidget
*keyboard_param_control::create(plugin_gui
*_gui
, int _param_no
)
951 param_no
= _param_no
;
952 // const parameter_properties &props = get_props();
954 widget
= calf_keyboard_new();
955 kb
= CALF_KEYBOARD(widget
);
956 kb
->nkeys
= get_int("octaves", 4) * 7 + 1;
957 kb
->sink
= new CalfKeyboard::EventAdapter
;
958 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-Keyboard");
962 /******************************** Curve ********************************/
964 struct curve_param_control_callback
: public CalfCurve::EventAdapter
966 curve_param_control
*ctl
;
968 curve_param_control_callback(curve_param_control
*_ctl
)
971 virtual void curve_changed(CalfCurve
*src
, const CalfCurve::point_vector
&data
) {
973 ss
<< data
.size() << endl
;
974 for (size_t i
= 0; i
< data
.size(); i
++)
975 ss
<< data
[i
].first
<< " " << data
[i
].second
<< endl
;
976 ctl
->gui
->plugin
->configure(ctl
->attribs
["key"].c_str(), ss
.str().c_str());
978 virtual void clip(CalfCurve
*src
, int pt
, float &x
, float &y
, bool &hide
)
980 // int gridpt = floor(x * 71 * 2);
981 // clip to the middle of the nearest white key
982 x
= (floor(x
* 71) + 0.5)/ 71.0;
986 GtkWidget
*curve_param_control::create(plugin_gui
*_gui
, int _param_no
)
989 param_no
= _param_no
;
990 require_attribute("key");
992 widget
= calf_curve_new(get_int("maxpoints", -1));
993 curve
= CALF_CURVE(widget
);
994 curve
->sink
= new curve_param_control_callback(this);
995 // gtk_curve_set_curve_type(curve, GTK_CURVE_TYPE_LINEAR);
996 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-Curve");
1000 void curve_param_control::send_configure(const char *key
, const char *value
)
1002 // cout << "send conf " << key << endl;
1003 if (attribs
["key"] == key
)
1005 stringstream
ss(value
);
1006 CalfCurve::point_vector pts
;
1009 unsigned int npoints
= 0;
1013 for (i
= 0; i
< npoints
&& i
< curve
->point_limit
; i
++)
1016 pts
.push_back(CalfCurve::point(x
, y
));
1018 calf_curve_set_points(widget
, pts
);
1023 /******************************** Entry ********************************/
1025 GtkWidget
*entry_param_control::create(plugin_gui
*_gui
, int _param_no
)
1028 param_no
= _param_no
;
1029 require_attribute("key");
1031 widget
= gtk_entry_new();
1032 entry
= GTK_ENTRY(widget
);
1033 g_signal_connect(GTK_OBJECT(widget
), "changed", G_CALLBACK(entry_value_changed
), (gpointer
)this);
1034 gtk_editable_set_editable(GTK_EDITABLE(entry
), get_int("editable", 1));
1035 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-Entry");
1039 void entry_param_control::send_configure(const char *key
, const char *value
)
1041 // cout << "send conf " << key << endl;
1042 if (attribs
["key"] == key
)
1044 gtk_entry_set_text(entry
, value
);
1048 void entry_param_control::entry_value_changed(GtkWidget
*widget
, gpointer value
)
1050 entry_param_control
*ctl
= (entry_param_control
*)value
;
1051 ctl
->gui
->plugin
->configure(ctl
->attribs
["key"].c_str(), gtk_entry_get_text(ctl
->entry
));
1054 /******************************** File Chooser ********************************/
1056 GtkWidget
*filechooser_param_control::create(plugin_gui
*_gui
, int _param_no
)
1059 param_no
= _param_no
;
1060 require_attribute("key");
1061 require_attribute("title");
1063 widget
= gtk_file_chooser_button_new(attribs
["title"].c_str(), GTK_FILE_CHOOSER_ACTION_OPEN
);
1064 filechooser
= GTK_FILE_CHOOSER_BUTTON(widget
);
1065 // XXXKF this is GTK+ 2.12 function, does any replacement exist?
1066 // MS: switched from g_signal_connect to g_signal_connect for better emission of signals
1067 g_signal_connect(GTK_OBJECT(widget
), "file-set", G_CALLBACK(filechooser_value_changed
), (gpointer
)this);
1068 if (attribs
.count("width"))
1069 gtk_widget_set_size_request (widget
, get_int("width", 200), -1);
1070 if (attribs
.count("width_chars"))
1071 gtk_file_chooser_button_set_width_chars (filechooser
, get_int("width_chars"));
1072 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-FileButton");
1076 void filechooser_param_control::send_configure(const char *key
, const char *value
)
1078 // cout << "send conf " << key << endl;
1079 if (attribs
["key"] == key
)
1081 gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(filechooser
), value
);
1085 void filechooser_param_control::filechooser_value_changed(GtkWidget
*widget
, gpointer value
)
1087 filechooser_param_control
*ctl
= (filechooser_param_control
*)value
;
1088 const char *filename
= gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(ctl
->filechooser
));
1090 ctl
->gui
->plugin
->configure(ctl
->attribs
["key"].c_str(), filename
);
1093 /******************************** Line Graph ********************************/
1095 void line_graph_param_control::on_idle()
1097 if (get_int("refresh", 0))
1101 static float to_x_pos(float freq
)
1103 return log(freq
/ 20.0) / log(1000);
1106 static float from_x_pos(float pos
)
1108 float a
= pos
* 3.0;
1109 float b
= powf(10.0, a
);
1114 static float to_y_pos(CalfLineGraph
*lg
, float gain
)
1116 //log(gain) * (1.0 / log(32));
1117 return 0.5 - dB_grid(gain
, 128 * lg
->zoom
, lg
->offset
) / 2.0;
1120 static float from_y_pos(CalfLineGraph
*lg
, float pos
)
1122 float gain
= powf(128.0 * lg
->zoom
, (0.5 - pos
) * 2.0 - lg
->offset
);
1126 GtkWidget
*line_graph_param_control::create(plugin_gui
*a_gui
, int a_param_no
)
1129 param_no
= a_param_no
;
1130 //last_generation = -1;
1132 widget
= calf_line_graph_new ();
1134 gtk_widget_set_name(GTK_WIDGET(widget
), "calf-graph");
1136 CalfLineGraph
*clg
= CALF_LINE_GRAPH(widget
);
1137 widget
->requisition
.width
= get_int("width", 40);
1138 widget
->requisition
.height
= get_int("height", 40);
1140 calf_line_graph_set_square(clg
, get_int("square", 0));
1142 clg
->source
= gui
->plugin
->get_line_graph_iface();
1143 clg
->source_id
= param_no
;
1144 clg
->fade
= get_float("fade", 1.0);
1145 clg
->mode
= get_int("mode", 0);
1146 clg
->use_crosshairs
= get_int("crosshairs", 0);
1147 clg
->freqhandles
= get_int("freqhandles", 0);
1148 clg
->enforce_handle_order
= get_int("enforce-handle-order", 0);
1149 clg
->min_handle_distance
= get_float("min-handle-distance", 0.01);
1151 const string
&zoom_name
= attribs
["zoom"];
1152 if (zoom_name
!= "")
1153 clg
->param_zoom
= gui
->get_param_no_by_name(zoom_name
);
1155 const string
&offset_name
= attribs
["offset"];
1156 if (offset_name
!= "")
1157 clg
->param_offset
= gui
->get_param_no_by_name(offset_name
);
1159 if (clg
->freqhandles
> 0)
1161 for(int i
= 0; i
< clg
->freqhandles
; i
++)
1163 FreqHandle
*handle
= &clg
->freq_handles
[i
];
1165 stringstream handle_x_attribute
;
1166 handle_x_attribute
<< "handle" << i
+ 1 << "-x";
1167 const string
¶m_x_name
= attribs
[handle_x_attribute
.str()];
1168 if(param_x_name
== "")
1171 int param_x_no
= gui
->get_param_no_by_name(param_x_name
);
1172 const parameter_properties
&handle_x_props
= *gui
->plugin
->get_metadata_iface()->get_param_props(param_x_no
);
1173 handle
->dimensions
= 1;
1174 handle
->param_x_no
= param_x_no
;
1175 handle
->value_x
= to_x_pos(gui
->plugin
->get_param_value(param_x_no
));
1176 handle
->default_value_x
= to_x_pos(handle_x_props
.def_value
);
1178 stringstream handle_y_attribute
;
1179 handle_y_attribute
<< "handle" << i
+ 1 << "-y";
1180 const string
¶m_y_name
= attribs
[handle_y_attribute
.str()];
1181 if(param_y_name
!= "") {
1182 int param_y_no
= gui
->get_param_no_by_name(param_y_name
);
1183 const parameter_properties
&handle_y_props
= *gui
->plugin
->get_metadata_iface()->get_param_props(param_y_no
);
1184 handle
->dimensions
= 2;
1185 handle
->param_y_no
= param_y_no
;
1186 handle
->value_y
= to_y_pos(clg
, gui
->plugin
->get_param_value(param_y_no
));
1187 handle
->default_value_y
= to_y_pos(clg
, handle_y_props
.def_value
);
1189 handle
->param_y_no
= -1;
1192 stringstream handle_z_attribute
;
1193 handle_z_attribute
<< "handle" << i
+ 1 << "-z";
1194 const string
¶m_z_name
= attribs
[handle_z_attribute
.str()];
1195 if(param_z_name
!= "") {
1196 int param_z_no
= gui
->get_param_no_by_name(param_z_name
);
1197 const parameter_properties
&handle_z_props
= *gui
->plugin
->get_metadata_iface()->get_param_props(param_z_no
);
1198 handle
->dimensions
= 3;
1199 handle
->param_z_no
= param_z_no
;
1200 handle
->value_z
= handle_z_props
.to_01(gui
->plugin
->get_param_value(param_z_no
));
1201 handle
->default_value_z
= handle_z_props
.to_01(handle_z_props
.def_value
);
1203 handle
->param_z_no
= -1;
1206 stringstream label_attribute
;
1207 label_attribute
<< "label" << i
+ 1;
1208 string label
= attribs
[label_attribute
.str()];
1209 if (!label
.empty()) {
1210 handle
->label
= strdup(label
.c_str());
1213 stringstream active_attribute
;
1214 active_attribute
<< "active" << i
+ 1;
1215 const string
&active_name
= attribs
[active_attribute
.str()];
1216 if (active_name
!= "") {
1217 handle
->param_active_no
= gui
->get_param_no_by_name(active_name
);
1219 handle
->param_active_no
= -1;
1222 stringstream style_attribute
;
1223 style_attribute
<< "style" << i
+ 1;
1224 const string style
= style_attribute
.str();
1225 clg
->freq_handles
[i
].style
= get_int(style
.c_str(), 0);
1226 if(clg
->freq_handles
[i
].style
== 1 or clg
->freq_handles
[i
].style
== 4) {
1227 clg
->freq_handles
[i
].dimensions
= 1;
1229 handle
->data
= (gpointer
) this;
1231 g_signal_connect(G_OBJECT(widget
), "freqhandle-changed", G_CALLBACK(freqhandle_value_changed
), this);
1234 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-LineGraph");
1238 void line_graph_param_control::get()
1240 GtkWidget
*tw
= gtk_widget_get_toplevel(widget
);
1241 CalfLineGraph
*clg
= CALF_LINE_GRAPH(widget
);
1243 if (tw
&& GTK_WIDGET_TOPLEVEL(tw
) && widget
->window
)
1245 int ws
= gdk_window_get_state(widget
->window
);
1246 if (ws
& (GDK_WINDOW_STATE_WITHDRAWN
| GDK_WINDOW_STATE_ICONIFIED
))
1249 if(clg
->handle_grabbed
>= 0) {
1250 FreqHandle
*handle
= &clg
->freq_handles
[clg
->handle_grabbed
];
1251 if(handle
->dimensions
>= 2) {
1252 float value_y
= from_y_pos(clg
, handle
->value_y
);
1253 gui
->set_param_value(handle
->param_y_no
, value_y
, this);
1256 float value_x
= from_x_pos(handle
->value_x
);
1257 gui
->set_param_value(handle
->param_x_no
, value_x
, this);
1258 } else if(clg
->handle_hovered
>= 0) {
1259 FreqHandle
*handle
= &clg
->freq_handles
[clg
->handle_hovered
];
1261 if(handle
->dimensions
== 3) {
1262 const parameter_properties
&handle_z_props
= *gui
->plugin
->get_metadata_iface()->get_param_props(handle
->param_z_no
);
1263 float value_z
= handle_z_props
.from_01(handle
->value_z
);
1264 gui
->set_param_value(handle
->param_z_no
, value_z
, this);
1270 void line_graph_param_control::set()
1273 GtkWidget
*tw
= gtk_widget_get_toplevel(widget
);
1274 CalfLineGraph
*clg
= CALF_LINE_GRAPH(widget
);
1275 if (tw
&& GTK_WIDGET_TOPLEVEL(tw
) && widget
->window
)
1278 int ws
= gdk_window_get_state(widget
->window
);
1279 if (ws
& (GDK_WINDOW_STATE_WITHDRAWN
| GDK_WINDOW_STATE_ICONIFIED
))
1282 if (clg
->param_zoom
>= 0) {
1283 float _z
= gui
->plugin
->get_param_value(clg
->param_zoom
);
1284 if (_z
!= clg
->zoom
) {
1287 clg
->force_redraw
= true;
1291 if (clg
->param_offset
>= 0) {
1292 float _z
= gui
->plugin
->get_param_value(clg
->param_offset
);
1293 if (_z
!= clg
->offset
) {
1296 clg
->force_redraw
= true;
1300 for (int i
= 0; i
< clg
->freqhandles
; i
++) {
1301 FreqHandle
*handle
= &clg
->freq_handles
[i
];
1303 if (handle
->param_x_no
>= 0)
1305 float value_x
= gui
->plugin
->get_param_value(handle
->param_x_no
);
1306 handle
->value_x
= to_x_pos(value_x
);
1307 if (dsp::_sanitize(handle
->value_x
- handle
->last_value_x
)) {
1308 clg
->handle_redraw
= 1;
1310 handle
->last_value_x
= handle
->value_x
;
1311 if(handle
->dimensions
>= 2 && handle
->param_y_no
>= 0) {
1312 float value_y
= gui
->plugin
->get_param_value(handle
->param_y_no
);
1313 handle
->value_y
= to_y_pos(clg
, value_y
);
1314 if (dsp::_sanitize(handle
->value_y
- handle
->last_value_y
)) {
1315 clg
->handle_redraw
= 1;
1317 handle
->last_value_y
= handle
->value_y
;
1321 if(handle
->dimensions
== 3 && handle
->param_z_no
>= 0) {
1322 const parameter_properties
&handle_z_props
= *gui
->plugin
->get_metadata_iface()->get_param_props(handle
->param_z_no
);
1323 float value_z
= gui
->plugin
->get_param_value(handle
->param_z_no
);
1324 handle
->value_z
= handle_z_props
.to_01(value_z
);
1325 if (dsp::_sanitize(handle
->value_z
- handle
->last_value_z
)) {
1326 clg
->handle_redraw
= 1;
1328 handle
->last_value_z
= handle
->value_z
;
1330 bool _a
= handle
->active
;
1331 if(handle
->param_active_no
>= 0) {
1332 handle
->active
= bool(gui
->plugin
->get_param_value(handle
->param_active_no
));
1334 handle
->active
= true;
1336 if (handle
->active
!= _a
) {
1338 clg
->handle_redraw
= true;
1341 calf_line_graph_expose_request(widget
, force
);
1345 void line_graph_param_control::freqhandle_value_changed(GtkWidget
*widget
, gpointer p
)
1348 FreqHandle
*handle
= (FreqHandle
*)p
;
1349 param_control
*jhp
= (param_control
*)handle
->data
;
1354 line_graph_param_control::~line_graph_param_control()
1359 /******************************** Phase Graph ********************************/
1361 void phase_graph_param_control::on_idle()
1363 if (get_int("refresh", 0))
1367 GtkWidget
*phase_graph_param_control::create(plugin_gui
*_gui
, int _param_no
)
1370 param_no
= _param_no
;
1371 widget
= calf_phase_graph_new ();
1372 gtk_widget_set_name(GTK_WIDGET(widget
), "calf-phase");
1373 CalfPhaseGraph
*clg
= CALF_PHASE_GRAPH(widget
);
1374 widget
->requisition
.width
= get_int("size", 40);
1375 widget
->requisition
.height
= get_int("size", 40);
1376 clg
->source
= gui
->plugin
->get_phase_graph_iface();
1377 clg
->source_id
= param_no
;
1378 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-PhaseGraph");
1382 void phase_graph_param_control::set()
1385 GtkWidget
*tw
= gtk_widget_get_toplevel(widget
);
1386 if (tw
&& GTK_WIDGET_TOPLEVEL(tw
) && widget
->window
) {
1387 gtk_widget_queue_draw(widget
);
1391 phase_graph_param_control::~phase_graph_param_control()
1395 /******************************** List View ********************************/
1397 GtkWidget
*listview_param_control::create(plugin_gui
*_gui
, int _param_no
)
1400 param_no
= _param_no
;
1402 string key
= attribs
["key"];
1403 tmif
= gui
->plugin
->get_metadata_iface()->get_table_metadata_iface(key
.c_str());
1406 g_error("Missing table_metadata_iface for variable '%s'", key
.c_str());
1410 const table_column_info
*tci
= tmif
->get_table_columns();
1413 while (tci
[cols
].name
!= NULL
)
1416 GType
*p
= new GType
[cols
];
1417 for (int i
= 0; i
< cols
; i
++)
1418 p
[i
] = G_TYPE_STRING
;
1419 lstore
= gtk_list_store_newv(cols
, p
);
1420 if (tmif
->get_table_rows() != 0)
1421 set_rows(tmif
->get_table_rows());
1422 widget
= gtk_tree_view_new_with_model(GTK_TREE_MODEL(lstore
));
1424 tree
= GTK_TREE_VIEW (widget
);
1425 g_object_set (G_OBJECT (tree
), "enable-search", FALSE
, "rules-hint", TRUE
, "enable-grid-lines", TRUE
, NULL
);
1427 for (int i
= 0; i
< cols
; i
++)
1429 GtkCellRenderer
*cr
= NULL
;
1431 if (tci
[i
].type
== TCT_ENUM
) {
1432 cr
= gtk_cell_renderer_combo_new ();
1433 GtkListStore
*cls
= gtk_list_store_new(2, G_TYPE_INT
, G_TYPE_STRING
);
1434 for (int j
= 0; tci
[i
].values
[j
]; j
++)
1435 gtk_list_store_insert_with_values(cls
, NULL
, j
, 0, j
, 1, tci
[i
].values
[j
], -1);
1436 g_object_set(cr
, "model", cls
, "editable", TRUE
, "has-entry", FALSE
, "text-column", 1, "mode", GTK_CELL_RENDERER_MODE_EDITABLE
, NULL
);
1439 bool editable
= tci
[i
].type
!= TCT_LABEL
;
1440 cr
= gtk_cell_renderer_text_new ();
1442 g_object_set(cr
, "editable", TRUE
, "mode", GTK_CELL_RENDERER_MODE_EDITABLE
, NULL
);
1444 g_object_set_data (G_OBJECT(cr
), "column", (void *)&tci
[i
]);
1445 g_signal_connect (GTK_OBJECT (cr
), "edited", G_CALLBACK (on_edited
), (gpointer
)this);
1446 g_signal_connect (GTK_OBJECT (cr
), "editing-canceled", G_CALLBACK (on_editing_canceled
), (gpointer
)this);
1447 gtk_tree_view_insert_column_with_attributes(tree
, i
, tci
[i
].name
, cr
, "text", i
, NULL
);
1449 gtk_tree_view_set_headers_visible(tree
, TRUE
);
1450 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-ListView");
1454 void listview_param_control::set_rows(unsigned int needed_rows
)
1456 while(positions
.size() < needed_rows
)
1459 gtk_list_store_insert(lstore
, &iter
, positions
.size());
1460 for (int j
= 0; j
< cols
; j
++)
1462 gtk_list_store_set(lstore
, &iter
, j
, "", -1);
1464 positions
.push_back(iter
);
1468 void listview_param_control::send_configure(const char *key
, const char *value
)
1470 string orig_key
= attribs
["key"] + ":";
1471 bool is_rows
= false;
1472 int row
= -1, col
= -1;
1473 if (parse_table_key(key
, orig_key
.c_str(), is_rows
, row
, col
))
1475 string suffix
= string(key
+ orig_key
.length());
1476 if (is_rows
&& tmif
->get_table_rows() == 0)
1478 int rows
= atoi(value
);
1483 if (row
!= -1 && col
!= -1)
1485 int max_rows
= tmif
->get_table_rows();
1486 if (col
< 0 || col
>= cols
)
1488 g_warning("Invalid column %d in key %s", col
, key
);
1491 if (max_rows
&& (row
< 0 || row
>= max_rows
))
1493 g_warning("Invalid row %d in key %s, this is a fixed table with row count = %d", row
, key
, max_rows
);
1497 if (row
>= (int)positions
.size())
1500 gtk_list_store_set(lstore
, &positions
[row
], col
, value
, -1);
1506 void listview_param_control::on_edited(GtkCellRenderer
*renderer
, gchar
*path
, gchar
*new_text
, listview_param_control
*pThis
)
1508 const table_column_info
*tci
= pThis
->tmif
->get_table_columns();
1509 int column
= ((table_column_info
*)g_object_get_data(G_OBJECT(renderer
), "column")) - tci
;
1510 string key
= pThis
->attribs
["key"] + ":" + i2s(atoi(path
)) + "," + i2s(column
);
1512 const char *error_or_null
= pThis
->gui
->plugin
->configure(key
.c_str(), new_text
);
1514 error
= error_or_null
;
1516 if (error
.empty()) {
1517 pThis
->send_configure(key
.c_str(), new_text
);
1518 gtk_widget_grab_focus(pThis
->widget
);
1519 GtkTreePath
*gpath
= gtk_tree_path_new_from_string (path
);
1520 gtk_tree_view_set_cursor_on_cell (GTK_TREE_VIEW (pThis
->widget
), gpath
, NULL
, NULL
, FALSE
);
1521 gtk_tree_path_free (gpath
);
1525 GtkWidget
*dialog
= gtk_message_dialog_new(pThis
->gui
->window
->toplevel
, GTK_DIALOG_DESTROY_WITH_PARENT
, GTK_MESSAGE_ERROR
, GTK_BUTTONS_OK
,
1526 "%s", error
.c_str());
1527 gtk_dialog_run(GTK_DIALOG(dialog
));
1528 gtk_widget_destroy(dialog
);
1529 gtk_widget_grab_focus(pThis
->widget
);
1533 void listview_param_control::on_editing_canceled(GtkCellRenderer
*renderer
, listview_param_control
*pThis
)
1535 gtk_widget_grab_focus(pThis
->widget
);
1538 /******************************** GtkNotebook control ********************************/
1540 GtkWidget
*notebook_param_control::create(plugin_gui
*_gui
, int _param_no
)
1543 param_no
= _param_no
;
1544 //const parameter_properties &props = get_props();
1545 page
= gui
->plugin
->get_param_value(param_no
);
1546 GtkWidget
*nb
= calf_notebook_new();
1547 widget
= GTK_WIDGET(nb
);
1548 container
= GTK_CONTAINER(nb
);
1549 gtk_widget_set_name(GTK_WIDGET(nb
), "Calf-Notebook");
1550 gtk_notebook_set_current_page(GTK_NOTEBOOK(widget
), page
);
1553 void notebook_param_control::created() {
1554 g_signal_connect (GTK_OBJECT (widget
), "switch-page", G_CALLBACK (notebook_page_changed
), (gpointer
)this);
1557 void notebook_param_control::get()
1560 gui
->set_param_value(param_no
, page
, this);
1562 void notebook_param_control::set()
1567 page
= (gint
)gui
->plugin
->get_param_value(param_no
);
1568 gtk_notebook_set_current_page(GTK_NOTEBOOK(widget
), page
);
1570 void notebook_param_control::add(GtkWidget
*w
, control_base
*base
)
1572 gtk_notebook_append_page(GTK_NOTEBOOK(widget
), w
, gtk_label_new_with_mnemonic(base
->attribs
["page"].c_str()));
1574 void notebook_param_control::notebook_page_changed(GtkWidget
*widget
, GtkWidget
*page
, guint id
, gpointer user
)
1576 notebook_param_control
*jhp
= (notebook_param_control
*)user
;
1577 jhp
->page
= (int)id
;
1581 /******************************** GtkTable container ********************************/
1583 GtkWidget
*table_container::create(plugin_gui
*_gui
, const char *element
, xml_attribute_map
&attributes
)
1585 require_int_attribute("rows");
1586 require_int_attribute("cols");
1587 int homog
= get_int("homogeneous", 0);
1588 int sx
= get_int("spacing-x", 2);
1589 int sy
= get_int("spacing-y", 2);
1590 GtkWidget
*table
= gtk_table_new(get_int("rows", 1), get_int("cols", 1), false);
1592 gtk_table_set_homogeneous(GTK_TABLE(table
), TRUE
);
1594 gtk_table_set_col_spacings(GTK_TABLE(table
), sx
);
1595 gtk_table_set_row_spacings(GTK_TABLE(table
), sy
);
1596 container
= GTK_CONTAINER(table
);
1597 gtk_widget_set_name(GTK_WIDGET(table
), "Calf-Table");
1601 void table_container::add(GtkWidget
*widget
, control_base
*base
)
1603 base
->require_int_attribute("attach-x");
1604 base
->require_int_attribute("attach-y");
1605 int x
= base
->get_int("attach-x"), y
= base
->get_int("attach-y");
1606 int w
= base
->get_int("attach-w", 1), h
= base
->get_int("attach-h", 1);
1607 int shrinkx
= base
->get_int("shrink-x", 0);
1608 int shrinky
= base
->get_int("shrink-y", 0);
1609 int fillx
= (base
->get_int("fill-x", !shrinkx
) ? GTK_FILL
: 0) | (base
->get_int("expand-x", !shrinkx
) ? GTK_EXPAND
: 0) | (shrinkx
? GTK_SHRINK
: 0);
1610 int filly
= (base
->get_int("fill-y", !shrinky
) ? GTK_FILL
: 0) | (base
->get_int("expand-y", !shrinky
) ? GTK_EXPAND
: 0) | (base
->get_int("shrink-y", 0) ? GTK_SHRINK
: 0);
1611 int padx
= base
->get_int("pad-x", 2);
1612 int pady
= base
->get_int("pad-y", 2);
1613 gtk_table_attach(GTK_TABLE(container
), widget
, x
, x
+ w
, y
, y
+ h
, (GtkAttachOptions
)fillx
, (GtkAttachOptions
)filly
, padx
, pady
);
1616 /******************************** alignment container ********************************/
1618 GtkWidget
*alignment_container::create(plugin_gui
*_gui
, const char *element
, xml_attribute_map
&attributes
)
1620 GtkWidget
*align
= gtk_alignment_new(get_float("align-x", 0.5), get_float("align-y", 0.5), get_float("scale-x", 0), get_float("scale-y", 0));
1621 container
= GTK_CONTAINER(align
);
1622 gtk_widget_set_name(GTK_WIDGET(align
), "Calf-Align");
1626 /******************************** GtkFrame container ********************************/
1628 GtkWidget
*frame_container::create(plugin_gui
*_gui
, const char *element
, xml_attribute_map
&attributes
)
1630 GtkWidget
*widget
= calf_frame_new(attribs
["label"].c_str());
1631 container
= GTK_CONTAINER(widget
);
1632 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-Frame");
1636 /******************************** GtkBox type of containers ********************************/
1638 void box_container::add(GtkWidget
*w
, control_base
*base
)
1640 gtk_container_add_with_properties(container
, w
, "expand", get_int("expand", 1), "fill", get_int("fill", 1), NULL
);
1643 /******************************** GtkHBox container ********************************/
1645 GtkWidget
*hbox_container::create(plugin_gui
*_gui
, const char *element
, xml_attribute_map
&attributes
)
1647 GtkWidget
*hbox
= gtk_hbox_new(get_int("homogeneous") >= 1, get_int("spacing", 2));
1648 container
= GTK_CONTAINER(hbox
);
1649 gtk_widget_set_name(GTK_WIDGET(hbox
), "Calf-HBox");
1653 /******************************** GtkVBox container ********************************/
1655 GtkWidget
*vbox_container::create(plugin_gui
*_gui
, const char *element
, xml_attribute_map
&attributes
)
1657 GtkWidget
*vbox
= gtk_vbox_new(get_int("homogeneous") >= 1, get_int("spacing", 2));
1658 container
= GTK_CONTAINER(vbox
);
1659 gtk_widget_set_name(GTK_WIDGET(vbox
), "Calf-VBox");
1663 /******************************** GtkNotebook container ********************************/
1665 GtkWidget
*scrolled_container::create(plugin_gui
*_gui
, const char *element
, xml_attribute_map
&attributes
)
1667 GtkAdjustment
*horiz
= NULL
, *vert
= NULL
;
1668 int width
= get_int("width", 0), height
= get_int("height", 0);
1670 horiz
= GTK_ADJUSTMENT(gtk_adjustment_new(get_int("x", 0), 0, width
, get_int("step-x", 1), get_int("page-x", width
/ 10), 100));
1672 vert
= GTK_ADJUSTMENT(gtk_adjustment_new(get_int("y", 0), 0, width
, get_int("step-y", 1), get_int("page-y", height
/ 10), 10));
1673 GtkWidget
*sw
= gtk_scrolled_window_new(horiz
, vert
);
1674 gtk_widget_set_size_request(sw
, get_int("req-x", -1), get_int("req-y", -1));
1675 container
= GTK_CONTAINER(sw
);
1676 gtk_widget_set_name(GTK_WIDGET(sw
), "Calf-ScrolledWindow");
1680 void scrolled_container::add(GtkWidget
*w
, control_base
*base
)
1682 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(container
), w
);