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 void control_base::set_visibilty(bool state
)
90 gtk_widget_show(widget
);
92 gtk_widget_show(GTK_WIDGET(container
));
95 gtk_widget_hide(widget
);
97 gtk_widget_hide(GTK_WIDGET(container
));
100 /******************************** container base class **********************/
102 void control_container::set_std_properties()
104 if (attribs
.find("widget-name") != attribs
.end())
106 string name
= attribs
["widget-name"];
108 gtk_widget_set_name(GTK_WIDGET(container
), name
.c_str());
113 /************************* param-associated control base class **************/
115 param_control::param_control()
120 old_displayed_value
= -1.f
;
125 void param_control::set_std_properties()
127 if (attribs
.find("widget-name") != attribs
.end())
129 string name
= attribs
["widget-name"];
131 gtk_widget_set_name(widget
, name
.c_str());
136 void param_control::hook_params()
138 if (param_no
!= -1) {
139 gui
->add_param_ctl(param_no
, this);
141 gui
->params
.push_back(this);
144 param_control::~param_control()
146 //if (GTK_IS_WIDGET(widget))
147 // gtk_widget_destroy(widget);
150 void param_control::add_context_menu_handler()
154 g_signal_connect(GTK_OBJECT(widget
), "button-press-event", (GCallback
)on_button_press_event
, this);
158 gboolean
param_control::on_button_press_event(GtkWidget
*widget
, GdkEventButton
*event
, void *user_data
)
160 param_control
*self
= (param_control
*)user_data
;
161 const parameter_properties
&props
= self
->get_props();
162 if (event
->button
== 3 && !(props
.flags
& PF_PROP_OUTPUT
))
164 self
->do_popup_menu();
167 else if (event
->button
== 2)
169 self
->create_value_entry(widget
, event
->x_root
, event
->y_root
);
175 void param_control::do_popup_menu()
178 gui
->on_control_popup(this, param_no
);
181 void param_control::destroy_value_entry ()
183 // remove the window containing the entry
184 gtk_widget_destroy(GTK_WIDGET(entrywin
));
187 gboolean
param_control::value_entry_unfocus(GtkWidget
*widget
, GdkEventFocus
*event
, void *user_data
)
189 // destroy window if it looses focus
190 param_control
*self
= (param_control
*)user_data
;
191 self
->destroy_value_entry();
194 gboolean
param_control::value_entry_action(GtkEntry
*widget
, GdkEvent
*event
, void *user_data
)
196 // called when a key was hit, sorts out and treats RETURN and ESC
197 param_control
*self
= (param_control
*)user_data
;
198 const parameter_properties
&props
= self
->get_props();
199 GdkEventKey
*key
= (GdkEventKey
*)event
;
200 if(key
->keyval
== GDK_Escape
)
201 self
->destroy_value_entry();
202 else if (key
->keyval
== GDK_Return
) {
203 float val
= props
.string_to_value(gtk_entry_get_text(widget
));
204 self
->gui
->plugin
->set_param_value(self
->param_no
, val
);
206 self
->destroy_value_entry();
210 void param_control::create_value_entry(GtkWidget
*widget
, int x
, int y
)
213 // kill an existing entry window on re-trigger
214 destroy_value_entry();
221 const parameter_properties
&props
= get_props();
222 float value
= gui
->plugin
->get_param_value(param_no
);
224 // no chance for a menu, so we have to do everything by hand
225 entrywin
= gtk_window_new(GTK_WINDOW_TOPLEVEL
);
226 gtk_widget_set_name(GTK_WIDGET(entrywin
), "Calf-Value-Entry");
227 gtk_window_set_title (GTK_WINDOW(entrywin
), "Calf Value Entry");
228 gtk_window_set_resizable (GTK_WINDOW(entrywin
), FALSE
);
229 gtk_window_set_decorated (GTK_WINDOW(entrywin
), FALSE
);
230 gtk_window_set_skip_taskbar_hint (GTK_WINDOW(entrywin
), TRUE
);
231 gtk_window_set_skip_pager_hint (GTK_WINDOW(entrywin
), TRUE
);
232 gtk_window_set_transient_for (GTK_WINDOW(entrywin
), GTK_WINDOW (gui
->window
->toplevel
));
233 gtk_window_set_gravity(GTK_WINDOW(entrywin
), GDK_GRAVITY_CENTER
);
234 gtk_widget_set_events (GTK_WIDGET(entrywin
), GDK_FOCUS_CHANGE_MASK
);
235 g_signal_connect (G_OBJECT(entrywin
), "focus-out-event", G_CALLBACK (value_entry_unfocus
), this);
237 // create the text entry
238 GtkWidget
*entry
= gtk_entry_new();
239 gtk_widget_set_name(GTK_WIDGET(entry
), "Calf-Entry");
240 gtk_entry_set_width_chars(GTK_ENTRY(entry
), props
.get_char_count());
241 gtk_entry_set_text(GTK_ENTRY(entry
), props
.to_string(value
).c_str());
242 gtk_widget_add_events (entry
, GDK_KEY_PRESS_MASK
);
243 g_signal_connect (entry
, "key-press-event", (GCallback
)value_entry_action
, this);
245 // stitch together and show
246 gtk_container_add(GTK_CONTAINER (entrywin
), entry
);
247 gtk_widget_show_all(entrywin
);
248 gtk_window_move(GTK_WINDOW (entrywin
), x
, y
);
254 /******************************** Combo Box ********************************/
256 GtkWidget
*combo_box_param_control::create(plugin_gui
*_gui
, int _param_no
)
259 param_no
= _param_no
;
260 lstore
= gtk_list_store_new(2, G_TYPE_STRING
, G_TYPE_STRING
); // value, key
262 const parameter_properties
&props
= get_props();
263 widget
= calf_combobox_new ();
264 if (param_no
!= -1 && props
.choices
)
266 for (int j
= (int)props
.min
; j
<= (int)props
.max
; j
++)
267 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);
269 gtk_combo_box_set_model (GTK_COMBO_BOX(widget
), GTK_TREE_MODEL(lstore
));
270 g_signal_connect (GTK_OBJECT (widget
), "changed", G_CALLBACK (combo_value_changed
), (gpointer
)this);
271 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-Combobox");
275 void combo_box_param_control::set()
280 const parameter_properties
&props
= get_props();
281 gtk_combo_box_set_active (GTK_COMBO_BOX (widget
), (int)gui
->plugin
->get_param_value(param_no
) - (int)props
.min
);
285 void combo_box_param_control::get()
289 const parameter_properties
&props
= get_props();
290 gui
->set_param_value(param_no
, gtk_combo_box_get_active (GTK_COMBO_BOX(widget
)) + props
.min
, this);
294 void combo_box_param_control::combo_value_changed(GtkComboBox
*widget
, gpointer value
)
296 combo_box_param_control
*jhp
= (combo_box_param_control
*)value
;
297 if (jhp
->attribs
.count("setter-key"))
301 if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (jhp
->widget
), &iter
))
303 gtk_tree_model_get (GTK_TREE_MODEL (jhp
->lstore
), &iter
, 1, &key
, -1);
305 jhp
->gui
->plugin
->configure(jhp
->attribs
["setter-key"].c_str(), key
);
314 void combo_box_param_control::send_status(const char *key
, const char *value
)
316 if (attribs
.count("key") && key
== attribs
["key"])
318 gtk_list_store_clear (lstore
);
320 std::string v
= value
;
323 while (pos
< v
.length()) {
324 size_t endpos
= v
.find("\n", pos
);
325 if (endpos
== string::npos
)
327 string line
= v
.substr(pos
, endpos
- pos
);
329 size_t tabpos
= line
.find('\t');
330 if (tabpos
== string::npos
)
333 key
= line
.substr(0, tabpos
);
334 label
= line
.substr(tabpos
+ 1);
337 gtk_list_store_insert_with_values (lstore
, >i
, i
, 0, label
.c_str(), 1, key
.c_str(), -1);
344 if (attribs
.count("current-key") && key
== attribs
["current-key"])
351 void combo_box_param_control::set_to_last_key()
353 map
<string
, GtkTreeIter
>::iterator i
= key2pos
.find(last_key
);
354 if (i
!= key2pos
.end())
356 gtk_combo_box_set_active_iter (GTK_COMBO_BOX (widget
), &i
->second
);
360 gtk_combo_box_set_active (GTK_COMBO_BOX (widget
), -1);
363 /******************************** Horizontal Fader ********************************/
366 scale_to_default (gpointer data
)
368 hscale_param_control
*jhp
= (hscale_param_control
*)data
;
369 const parameter_properties
&props
= jhp
->get_props();
370 gtk_range_set_value (GTK_RANGE (jhp
->widget
), props
.to_01(props
.def_value
));
376 scale_button_press (GtkWidget
*widget
, GdkEventKey
*event
, gpointer
*user_data
)
378 if (event
->type
== GDK_2BUTTON_PRESS
) {
379 // this actually creates a harmless race condition, but diving deep
380 // into gtk signal handling code wouldn't and the resulting complexity
381 // would not really be worth the effort
382 // The timeout is set high enough that most of the time the race
383 // will turn out in our/the users favor
384 g_timeout_add (200, (GSourceFunc
)scale_to_default
, user_data
);
391 GtkWidget
*hscale_param_control::create(plugin_gui
*_gui
, int _param_no
)
394 param_no
= _param_no
;
396 widget
= calf_fader_new(1, get_int("size", 2), 0, 1, get_props().get_increment());
398 g_signal_connect (GTK_OBJECT (widget
), "value-changed", G_CALLBACK (hscale_value_changed
), (gpointer
)this);
399 g_signal_connect (GTK_OBJECT (widget
), "format-value", G_CALLBACK (hscale_format_value
), (gpointer
)this);
400 g_signal_connect (GTK_OBJECT (widget
), "button-press-event", G_CALLBACK (scale_button_press
), (gpointer
)this);
402 if(get_int("inverted", 0) > 0) {
403 gtk_range_set_inverted(GTK_RANGE(widget
), TRUE
);
405 int size
= get_int("size", 2);
406 char *name
= g_strdup_printf("Calf-HScale%i", size
);
407 gtk_widget_set_name(GTK_WIDGET(widget
), name
);
408 gtk_widget_set_size_request (widget
, size
* 100, -1);
413 void hscale_param_control::init_xml(const char *element
)
415 if (attribs
.count("width"))
416 gtk_widget_set_size_request (widget
, get_int("width", 200), -1);
417 if (attribs
.count("position"))
419 string v
= attribs
["position"];
420 if (v
== "top") gtk_scale_set_value_pos(GTK_SCALE(widget
), GTK_POS_TOP
);
421 if (v
== "bottom") gtk_scale_set_value_pos(GTK_SCALE(widget
), GTK_POS_BOTTOM
);
425 void hscale_param_control::set()
428 const parameter_properties
&props
= get_props();
429 gtk_range_set_value (GTK_RANGE (widget
), props
.to_01 (gui
->plugin
->get_param_value(param_no
)));
430 // hscale_value_changed (GTK_HSCALE (widget), (gpointer)this);
433 void hscale_param_control::get()
435 const parameter_properties
&props
= get_props();
436 float cvalue
= props
.from_01 (gtk_range_get_value (GTK_RANGE (widget
)));
437 gui
->set_param_value(param_no
, cvalue
, this);
440 void hscale_param_control::hscale_value_changed(GtkHScale
*widget
, gpointer value
)
442 hscale_param_control
*jhp
= (hscale_param_control
*)value
;
446 gchar
*hscale_param_control::hscale_format_value(GtkScale
*widget
, double arg1
, gpointer value
)
448 hscale_param_control
*jhp
= (hscale_param_control
*)value
;
449 const parameter_properties
&props
= jhp
->get_props();
450 float cvalue
= props
.from_01 (arg1
);
453 // return g_strdup_printf ("%s = %g", props.to_string (cvalue).c_str(), arg1);
454 return g_strdup (props
.to_string (cvalue
).c_str());
457 /******************************** Vertical Fader ********************************/
459 GtkWidget
*vscale_param_control::create(plugin_gui
*_gui
, int _param_no
)
462 param_no
= _param_no
;
463 widget
= calf_fader_new(0, get_int("size", 2), 0, 1, get_props().get_increment());
464 g_signal_connect (GTK_OBJECT (widget
), "value-changed", G_CALLBACK (vscale_value_changed
), (gpointer
)this);
465 g_signal_connect (GTK_OBJECT (widget
), "button-press-event", G_CALLBACK (scale_button_press
), (gpointer
)this);
467 gtk_scale_set_draw_value(GTK_SCALE(widget
), FALSE
);
469 if(get_int("inverted", 0) > 0) {
470 gtk_range_set_inverted(GTK_RANGE(widget
), TRUE
);
472 int size
= get_int("size", 2);
473 char *name
= g_strdup_printf("Calf-VScale%i", size
);
474 gtk_widget_set_size_request (widget
, -1, size
* 100);
475 gtk_widget_set_name(GTK_WIDGET(widget
), name
);
480 void vscale_param_control::init_xml(const char *element
)
482 if (attribs
.count("height"))
483 gtk_widget_set_size_request (widget
, -1, get_int("height", 200));
486 void vscale_param_control::set()
489 const parameter_properties
&props
= get_props();
490 gtk_range_set_value (GTK_RANGE (widget
), props
.to_01 (gui
->plugin
->get_param_value(param_no
)));
491 // vscale_value_changed (GTK_HSCALE (widget), (gpointer)this);
494 void vscale_param_control::get()
496 const parameter_properties
&props
= get_props();
497 float cvalue
= props
.from_01 (gtk_range_get_value (GTK_RANGE (widget
)));
498 gui
->set_param_value(param_no
, cvalue
, this);
501 void vscale_param_control::vscale_value_changed(GtkHScale
*widget
, gpointer value
)
503 vscale_param_control
*jhp
= (vscale_param_control
*)value
;
507 /******************************** Label ********************************/
509 GtkWidget
*label_param_control::create(plugin_gui
*_gui
, int _param_no
)
511 gui
= _gui
, param_no
= _param_no
;
513 if (param_no
!= -1 && !attribs
.count("text"))
514 text
= get_props().name
;
516 text
= attribs
["text"];
517 widget
= gtk_label_new(text
.c_str());
518 gtk_misc_set_alignment (GTK_MISC (widget
), get_float("align-x", 0.5), get_float("align-y", 0.5));
519 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-Label");
523 /******************************** Value ********************************/
525 GtkWidget
*value_param_control::create(plugin_gui
*_gui
, int _param_no
)
528 param_no
= _param_no
;
530 widget
= gtk_label_new ("");
533 const parameter_properties
&props
= get_props();
534 gtk_label_set_width_chars (GTK_LABEL (widget
), props
.get_char_count());
538 require_attribute("key");
539 require_int_attribute("width");
540 param_variable
= attribs
["key"];
541 gtk_label_set_width_chars (GTK_LABEL (widget
), get_int("width"));
543 gtk_misc_set_alignment (GTK_MISC (widget
), get_float("align-x", 0.5), get_float("align-y", 0.5));
544 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-Value");
548 void value_param_control::set()
554 const parameter_properties
&props
= get_props();
555 string value
= props
.to_string(gui
->plugin
->get_param_value(param_no
));
557 if (value
== old_value
)
560 gtk_label_set_text (GTK_LABEL (widget
), value
.c_str());
563 void value_param_control::send_status(const char *key
, const char *value
)
565 if (key
== param_variable
)
567 gtk_label_set_text (GTK_LABEL (widget
), value
);
571 /******************************** VU Meter ********************************/
573 GtkWidget
*vumeter_param_control::create(plugin_gui
*_gui
, int _param_no
)
575 gui
= _gui
, param_no
= _param_no
;
576 // const parameter_properties &props = get_props();
577 widget
= calf_vumeter_new ();
578 gtk_widget_set_name(GTK_WIDGET(widget
), "calf-vumeter");
579 calf_vumeter_set_mode (CALF_VUMETER (widget
), (CalfVUMeterMode
)get_int("mode", 0));
580 CALF_VUMETER(widget
)->vumeter_hold
= get_float("hold", 0);
581 CALF_VUMETER(widget
)->vumeter_falloff
= get_float("falloff", 0.f
);
582 CALF_VUMETER(widget
)->vumeter_width
= get_int("width", 80);
583 CALF_VUMETER(widget
)->vumeter_height
= get_int("height", 18);
584 CALF_VUMETER(widget
)->vumeter_position
= get_int("position", 0);
585 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-VUMeter");
589 void vumeter_param_control::set()
592 // const parameter_properties &props = get_props();
593 calf_vumeter_set_value (CALF_VUMETER (widget
), gui
->plugin
->get_param_value(param_no
));
598 GtkWidget
*led_param_control::create(plugin_gui
*_gui
, int _param_no
)
600 gui
= _gui
, param_no
= _param_no
;
601 // const parameter_properties &props = get_props();
602 widget
= calf_led_new ();
603 gtk_widget_set_name(GTK_WIDGET(widget
), "calf-led");
604 CALF_LED(widget
)->led_mode
= get_int("mode", 0);
605 CALF_LED(widget
)->size
= get_int("size", 1);
606 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-LED");
610 void led_param_control::set()
613 // const parameter_properties &props = get_props();
614 calf_led_set_value (CALF_LED (widget
), gui
->plugin
->get_param_value(param_no
));
619 GtkWidget
*tube_param_control::create(plugin_gui
*_gui
, int _param_no
)
621 gui
= _gui
, param_no
= _param_no
;
622 // const parameter_properties &props = get_props();
623 widget
= calf_tube_new ();
624 gtk_widget_set_name(GTK_WIDGET(widget
), "calf-tube");
625 CALF_TUBE(widget
)->size
= get_int("size", 2);
626 CALF_TUBE(widget
)->direction
= get_int("direction", 2);
627 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-Tube");
631 void tube_param_control::set()
634 // const parameter_properties &props = get_props();
635 calf_tube_set_value (CALF_TUBE (widget
), gui
->plugin
->get_param_value(param_no
));
638 /******************************** Check Box ********************************/
640 GtkWidget
*check_param_control::create(plugin_gui
*_gui
, int _param_no
)
643 param_no
= _param_no
;
645 widget
= gtk_check_button_new ();
646 g_signal_connect (GTK_OBJECT (widget
), "toggled", G_CALLBACK (check_value_changed
), (gpointer
)this);
647 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-Checkbox");
651 void check_param_control::check_value_changed(GtkCheckButton
*widget
, gpointer value
)
653 param_control
*jhp
= (param_control
*)value
;
657 void check_param_control::get()
659 const parameter_properties
&props
= get_props();
660 gui
->set_param_value(param_no
, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widget
)) + props
.min
, this);
663 void check_param_control::set()
666 const parameter_properties
&props
= get_props();
667 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget
), (int)gui
->plugin
->get_param_value(param_no
) - (int)props
.min
);
670 /******************************** Radio Button ********************************/
672 GtkWidget
*radio_param_control::create(plugin_gui
*_gui
, int _param_no
)
675 param_no
= _param_no
;
676 require_attribute("value");
678 string value_name
= attribs
["value"];
679 const parameter_properties
&props
= get_props();
680 if (props
.choices
&& (value_name
< "0" || value_name
> "9"))
682 for (int i
= 0; props
.choices
[i
]; i
++)
684 if (value_name
== props
.choices
[i
])
686 value
= i
+ (int)props
.min
;
692 value
= get_int("value");
694 if (attribs
.count("label"))
695 widget
= gtk_radio_button_new_with_label (gui
->get_radio_group(param_no
), attribs
["label"].c_str());
697 widget
= gtk_radio_button_new_with_label (gui
->get_radio_group(param_no
), props
.choices
[value
- (int)props
.min
]);
698 gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (widget
), FALSE
);
700 gui
->set_radio_group(param_no
, gtk_radio_button_get_group (GTK_RADIO_BUTTON (widget
)));
701 g_signal_connect (GTK_OBJECT (widget
), "clicked", G_CALLBACK (radio_clicked
), (gpointer
)this);
702 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-RadioButton");
706 void radio_param_control::radio_clicked(GtkRadioButton
*widget
, gpointer value
)
708 param_control
*jhp
= (param_control
*)value
;
712 void radio_param_control::get()
714 // const parameter_properties &props = get_props();
715 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget
)))
716 gui
->set_param_value(param_no
, value
, this);
719 void radio_param_control::set()
722 const parameter_properties
&props
= get_props();
723 float pv
= gui
->plugin
->get_param_value(param_no
);
724 if (fabs(value
-pv
) < 0.5)
725 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget
), value
== ((int)gui
->plugin
->get_param_value(param_no
) - (int)props
.min
));
728 /******************************** Spin Button ********************************/
730 GtkWidget
*spin_param_control::create(plugin_gui
*_gui
, int _param_no
)
733 param_no
= _param_no
;
735 const parameter_properties
&props
= get_props();
737 widget
= gtk_spin_button_new_with_range (props
.min
, props
.max
, (props
.max
- props
.min
) / (props
.step
- 1));
739 widget
= gtk_spin_button_new_with_range (props
.min
, props
.max
, props
.step
);
741 widget
= gtk_spin_button_new_with_range (props
.min
, props
.max
, 1);
742 gtk_spin_button_set_digits (GTK_SPIN_BUTTON(widget
), get_int("digits", 0));
743 g_signal_connect (GTK_OBJECT (widget
), "value-changed", G_CALLBACK (value_changed
), (gpointer
)this);
744 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-SpinButton");
748 void spin_param_control::value_changed(GtkSpinButton
*widget
, gpointer value
)
750 param_control
*jhp
= (param_control
*)value
;
754 void spin_param_control::get()
756 // const parameter_properties &props = get_props();
757 gui
->set_param_value(param_no
, gtk_spin_button_get_value_as_float (GTK_SPIN_BUTTON (widget
)), this);
760 void spin_param_control::set()
763 // const parameter_properties &props = get_props();
764 gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget
), gui
->plugin
->get_param_value(param_no
));
767 /******************************** Button ********************************/
769 GtkWidget
*button_param_control::create(plugin_gui
*_gui
, int _param_no
)
772 param_no
= _param_no
;
773 widget
= calf_button_new ((gchar
*)get_props().name
);
774 g_signal_connect (GTK_OBJECT (widget
), "pressed", G_CALLBACK (button_clicked
), (gpointer
)this);
775 g_signal_connect (GTK_OBJECT (widget
), "released", G_CALLBACK (button_clicked
), (gpointer
)this);
776 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-Button");
780 void button_param_control::button_clicked(GtkButton
*widget
, gpointer value
)
782 param_control
*jhp
= (param_control
*)value
;
786 void button_param_control::get()
788 const parameter_properties
&props
= get_props();
789 gui
->set_param_value(param_no
, gtk_widget_get_state(widget
) == GTK_STATE_ACTIVE
? props
.max
: props
.min
, this);
792 void button_param_control::set()
795 const parameter_properties
&props
= get_props();
796 if (gui
->plugin
->get_param_value(param_no
) - props
.min
>= 0.5)
797 gtk_button_clicked (GTK_BUTTON (widget
));
800 /******************************** Knob ********************************/
802 GtkWidget
*knob_param_control::create(plugin_gui
*_gui
, int _param_no
)
805 param_no
= _param_no
;
806 const parameter_properties
&props
= get_props();
808 //widget = calf_knob_new_with_range (props.to_01 (gui->plugin->get_param_value(param_no)), 0, 1, 0.01);
809 widget
= calf_knob_new();
810 float increment
= props
.get_increment();
811 gtk_range_get_adjustment(GTK_RANGE(widget
))->step_increment
= increment
;
812 CALF_KNOB(widget
)->default_value
= props
.to_01(props
.def_value
);
813 CALF_KNOB(widget
)->knob_type
= get_int("type");
814 CALF_KNOB(widget
)->knob_size
= get_int("size", 2);
815 if(CALF_KNOB(widget
)->knob_size
> 5) {
816 CALF_KNOB(widget
)->knob_size
= 5;
817 } else if (CALF_KNOB(widget
)->knob_size
< 1) {
818 CALF_KNOB(widget
)->knob_size
= 1;
820 g_signal_connect(GTK_OBJECT(widget
), "value-changed", G_CALLBACK(knob_value_changed
), (gpointer
)this);
821 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-Knob");
825 void knob_param_control::get()
827 const parameter_properties
&props
= get_props();
828 float value
= props
.from_01(gtk_range_get_value(GTK_RANGE(widget
)));
829 gui
->set_param_value(param_no
, value
, this);
832 void knob_param_control::set()
835 const parameter_properties
&props
= get_props();
836 gtk_range_set_value(GTK_RANGE(widget
), props
.to_01 (gui
->plugin
->get_param_value(param_no
)));
839 void knob_param_control::knob_value_changed(GtkWidget
*widget
, gpointer value
)
841 param_control
*jhp
= (param_control
*)value
;
845 /******************************** Toggle Button ********************************/
847 GtkWidget
*toggle_param_control::create(plugin_gui
*_gui
, int _param_no
)
850 param_no
= _param_no
;
851 widget
= calf_toggle_new ();
853 CALF_TOGGLE(widget
)->size
= get_int("size", 2);
855 g_signal_connect (GTK_OBJECT (widget
), "value-changed", G_CALLBACK (toggle_value_changed
), (gpointer
)this);
856 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-ToggleButton");
860 void toggle_param_control::get()
862 const parameter_properties
&props
= get_props();
863 float value
= props
.from_01(gtk_range_get_value(GTK_RANGE(widget
)));
864 gui
->set_param_value(param_no
, value
, this);
867 void toggle_param_control::set()
870 const parameter_properties
&props
= get_props();
871 gtk_range_set_value(GTK_RANGE(widget
), props
.to_01 (gui
->plugin
->get_param_value(param_no
)));
874 void toggle_param_control::toggle_value_changed(GtkWidget
*widget
, gpointer value
)
876 param_control
*jhp
= (param_control
*)value
;
880 /******************************** Tap Button ********************************/
882 GtkWidget
*tap_button_param_control::create(plugin_gui
*_gui
, int _param_no
)
885 param_no
= _param_no
;
890 widget
= calf_tap_button_new ();
891 //CALF_TAP(widget)->size = get_int("size", 2);
892 g_signal_connect (GTK_OBJECT (widget
), "button-press-event", G_CALLBACK (tap_button_pressed
), (gpointer
)this);
893 g_signal_connect (GTK_OBJECT (widget
), "released", G_CALLBACK (tap_button_released
), (gpointer
)this);
894 g_signal_connect (GTK_OBJECT (widget
), "leave", G_CALLBACK (tap_button_released
), (gpointer
)this);
895 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-TapButton");
899 void tap_button_param_control::get()
901 gui
->set_param_value(param_no
, value
, this);
904 void tap_button_param_control::set()
909 gettimeofday(&tv
, 0);
910 unsigned long _now
= tv
.tv_sec
* 1000;
911 if(_now
> init_time
+ 2000) {
912 // user stopped tapping
916 CALF_TAP_BUTTON(widget
)->state
= 0;
917 gtk_widget_queue_draw(widget
);
922 gboolean
tap_button_param_control::tap_button_pressed(GtkWidget
*widget
, GdkEventButton
*event
, gpointer value
)
924 tap_button_param_control
*ctl
= (tap_button_param_control
*)value
;
925 CalfTapButton
*tap
= CALF_TAP_BUTTON(widget
);
928 if (event
->type
== GDK_BUTTON_PRESS
and event
->button
== 1)
931 gettimeofday(&tv
, 0);
932 ctl
->init_time
= tv
.tv_sec
* 1000;
938 ctl
->avg_value
= (ctl
->avg_value
* 3 + (time
- ctl
->last_time
)) / 4.f
;
940 ctl
->avg_value
= time
- ctl
->last_time
;
941 ctl
->value
= 60.f
/ (float)(ctl
->avg_value
/ 1000.f
);
943 if (ctl
->value
> 30 and ctl
->value
< 300)
946 ctl
->last_time
= time
;
947 gtk_widget_queue_draw(widget
);
951 gboolean
tap_button_param_control::tap_button_released(GtkWidget
*widget
, gpointer value
)
953 tap_button_param_control
*ctl
= (tap_button_param_control
*)value
;
954 CalfTapButton
*tap
= CALF_TAP_BUTTON(widget
);
955 tap
->state
= ctl
->last_time
? 1 : 0;
956 gtk_widget_queue_draw(widget
);
960 /******************************** Keyboard ********************************/
962 GtkWidget
*keyboard_param_control::create(plugin_gui
*_gui
, int _param_no
)
965 param_no
= _param_no
;
966 // const parameter_properties &props = get_props();
968 widget
= calf_keyboard_new();
969 kb
= CALF_KEYBOARD(widget
);
970 kb
->nkeys
= get_int("octaves", 4) * 7 + 1;
971 kb
->sink
= new CalfKeyboard::EventAdapter
;
972 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-Keyboard");
976 /******************************** Curve ********************************/
978 struct curve_param_control_callback
: public CalfCurve::EventAdapter
980 curve_param_control
*ctl
;
982 curve_param_control_callback(curve_param_control
*_ctl
)
985 virtual void curve_changed(CalfCurve
*src
, const CalfCurve::point_vector
&data
) {
987 ss
<< data
.size() << endl
;
988 for (size_t i
= 0; i
< data
.size(); i
++)
989 ss
<< data
[i
].first
<< " " << data
[i
].second
<< endl
;
990 ctl
->gui
->plugin
->configure(ctl
->attribs
["key"].c_str(), ss
.str().c_str());
992 virtual void clip(CalfCurve
*src
, int pt
, float &x
, float &y
, bool &hide
)
994 // int gridpt = floor(x * 71 * 2);
995 // clip to the middle of the nearest white key
996 x
= (floor(x
* 71) + 0.5)/ 71.0;
1000 GtkWidget
*curve_param_control::create(plugin_gui
*_gui
, int _param_no
)
1003 param_no
= _param_no
;
1004 require_attribute("key");
1006 widget
= calf_curve_new(get_int("maxpoints", -1));
1007 curve
= CALF_CURVE(widget
);
1008 curve
->sink
= new curve_param_control_callback(this);
1009 // gtk_curve_set_curve_type(curve, GTK_CURVE_TYPE_LINEAR);
1010 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-Curve");
1014 void curve_param_control::send_configure(const char *key
, const char *value
)
1016 // cout << "send conf " << key << endl;
1017 if (attribs
["key"] == key
)
1019 stringstream
ss(value
);
1020 CalfCurve::point_vector pts
;
1023 unsigned int npoints
= 0;
1027 for (i
= 0; i
< npoints
&& i
< curve
->point_limit
; i
++)
1030 pts
.push_back(CalfCurve::point(x
, y
));
1032 calf_curve_set_points(widget
, pts
);
1037 /******************************** Entry ********************************/
1039 GtkWidget
*entry_param_control::create(plugin_gui
*_gui
, int _param_no
)
1042 param_no
= _param_no
;
1043 require_attribute("key");
1045 widget
= gtk_entry_new();
1046 entry
= GTK_ENTRY(widget
);
1047 g_signal_connect(GTK_OBJECT(widget
), "changed", G_CALLBACK(entry_value_changed
), (gpointer
)this);
1048 gtk_editable_set_editable(GTK_EDITABLE(entry
), get_int("editable", 1));
1049 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-Entry");
1053 void entry_param_control::send_configure(const char *key
, const char *value
)
1055 // cout << "send conf " << key << endl;
1056 if (attribs
["key"] == key
)
1058 gtk_entry_set_text(entry
, value
);
1062 void entry_param_control::entry_value_changed(GtkWidget
*widget
, gpointer value
)
1064 entry_param_control
*ctl
= (entry_param_control
*)value
;
1065 ctl
->gui
->plugin
->configure(ctl
->attribs
["key"].c_str(), gtk_entry_get_text(ctl
->entry
));
1068 /******************************** File Chooser ********************************/
1070 GtkWidget
*filechooser_param_control::create(plugin_gui
*_gui
, int _param_no
)
1073 param_no
= _param_no
;
1074 require_attribute("key");
1075 require_attribute("title");
1077 widget
= gtk_file_chooser_button_new(attribs
["title"].c_str(), GTK_FILE_CHOOSER_ACTION_OPEN
);
1078 filechooser
= GTK_FILE_CHOOSER_BUTTON(widget
);
1079 // XXXKF this is GTK+ 2.12 function, does any replacement exist?
1080 // MS: switched from g_signal_connect to g_signal_connect for better emission of signals
1081 g_signal_connect(GTK_OBJECT(widget
), "file-set", G_CALLBACK(filechooser_value_changed
), (gpointer
)this);
1082 if (attribs
.count("width"))
1083 gtk_widget_set_size_request (widget
, get_int("width", 200), -1);
1084 if (attribs
.count("width_chars"))
1085 gtk_file_chooser_button_set_width_chars (filechooser
, get_int("width_chars"));
1086 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-FileButton");
1090 void filechooser_param_control::send_configure(const char *key
, const char *value
)
1092 // cout << "send conf " << key << endl;
1093 if (attribs
["key"] == key
)
1095 gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(filechooser
), value
);
1099 void filechooser_param_control::filechooser_value_changed(GtkWidget
*widget
, gpointer value
)
1101 filechooser_param_control
*ctl
= (filechooser_param_control
*)value
;
1102 const char *filename
= gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(ctl
->filechooser
));
1104 ctl
->gui
->plugin
->configure(ctl
->attribs
["key"].c_str(), filename
);
1107 /******************************** Line Graph ********************************/
1109 void line_graph_param_control::on_idle()
1111 if (get_int("refresh", 0))
1115 static float to_x_pos(float freq
)
1117 return log(freq
/ 20.0) / log(1000);
1120 static float from_x_pos(float pos
)
1122 float a
= pos
* 3.0;
1123 float b
= powf(10.0, a
);
1128 static float to_y_pos(CalfLineGraph
*lg
, float gain
)
1130 //log(gain) * (1.0 / log(32));
1131 return 0.5 - dB_grid(gain
, 128 * lg
->zoom
, lg
->offset
) / 2.0;
1134 static float from_y_pos(CalfLineGraph
*lg
, float pos
)
1136 float gain
= powf(128.0 * lg
->zoom
, (0.5 - pos
) * 2.0 - lg
->offset
);
1140 GtkWidget
*line_graph_param_control::create(plugin_gui
*a_gui
, int a_param_no
)
1143 param_no
= a_param_no
;
1144 //last_generation = -1;
1146 widget
= calf_line_graph_new ();
1148 gtk_widget_set_name(GTK_WIDGET(widget
), "calf-graph");
1150 CalfLineGraph
*clg
= CALF_LINE_GRAPH(widget
);
1151 widget
->requisition
.width
= get_int("width", 40);
1152 widget
->requisition
.height
= get_int("height", 40);
1154 calf_line_graph_set_square(clg
, get_int("square", 0));
1156 clg
->source
= gui
->plugin
->get_line_graph_iface();
1157 clg
->source_id
= param_no
;
1158 clg
->fade
= get_float("fade", 1.0);
1159 clg
->mode
= get_int("mode", 0);
1160 clg
->use_crosshairs
= get_int("crosshairs", 0);
1161 clg
->freqhandles
= get_int("freqhandles", 0);
1162 clg
->enforce_handle_order
= get_int("enforce-handle-order", 0);
1163 clg
->min_handle_distance
= get_float("min-handle-distance", 0.01);
1165 const string
&zoom_name
= attribs
["zoom"];
1166 if (zoom_name
!= "")
1167 clg
->param_zoom
= gui
->get_param_no_by_name(zoom_name
);
1169 const string
&offset_name
= attribs
["offset"];
1170 if (offset_name
!= "")
1171 clg
->param_offset
= gui
->get_param_no_by_name(offset_name
);
1173 if (clg
->freqhandles
> 0)
1175 for(int i
= 0; i
< clg
->freqhandles
; i
++)
1177 FreqHandle
*handle
= &clg
->freq_handles
[i
];
1179 stringstream handle_x_attribute
;
1180 handle_x_attribute
<< "handle" << i
+ 1 << "-x";
1181 const string
¶m_x_name
= attribs
[handle_x_attribute
.str()];
1182 if(param_x_name
== "")
1185 int param_x_no
= gui
->get_param_no_by_name(param_x_name
);
1186 const parameter_properties
&handle_x_props
= *gui
->plugin
->get_metadata_iface()->get_param_props(param_x_no
);
1187 handle
->dimensions
= 1;
1188 handle
->param_x_no
= param_x_no
;
1189 handle
->value_x
= to_x_pos(gui
->plugin
->get_param_value(param_x_no
));
1190 handle
->default_value_x
= to_x_pos(handle_x_props
.def_value
);
1192 stringstream handle_y_attribute
;
1193 handle_y_attribute
<< "handle" << i
+ 1 << "-y";
1194 const string
¶m_y_name
= attribs
[handle_y_attribute
.str()];
1195 if(param_y_name
!= "") {
1196 int param_y_no
= gui
->get_param_no_by_name(param_y_name
);
1197 const parameter_properties
&handle_y_props
= *gui
->plugin
->get_metadata_iface()->get_param_props(param_y_no
);
1198 handle
->dimensions
= 2;
1199 handle
->param_y_no
= param_y_no
;
1200 handle
->value_y
= to_y_pos(clg
, gui
->plugin
->get_param_value(param_y_no
));
1201 handle
->default_value_y
= to_y_pos(clg
, handle_y_props
.def_value
);
1203 handle
->param_y_no
= -1;
1206 stringstream handle_z_attribute
;
1207 handle_z_attribute
<< "handle" << i
+ 1 << "-z";
1208 const string
¶m_z_name
= attribs
[handle_z_attribute
.str()];
1209 if(param_z_name
!= "") {
1210 int param_z_no
= gui
->get_param_no_by_name(param_z_name
);
1211 const parameter_properties
&handle_z_props
= *gui
->plugin
->get_metadata_iface()->get_param_props(param_z_no
);
1212 handle
->dimensions
= 3;
1213 handle
->param_z_no
= param_z_no
;
1214 handle
->value_z
= handle_z_props
.to_01(gui
->plugin
->get_param_value(param_z_no
));
1215 handle
->default_value_z
= handle_z_props
.to_01(handle_z_props
.def_value
);
1217 handle
->param_z_no
= -1;
1220 stringstream label_attribute
;
1221 label_attribute
<< "label" << i
+ 1;
1222 string label
= attribs
[label_attribute
.str()];
1223 if (!label
.empty()) {
1224 handle
->label
= strdup(label
.c_str());
1227 stringstream active_attribute
;
1228 active_attribute
<< "active" << i
+ 1;
1229 const string
&active_name
= attribs
[active_attribute
.str()];
1230 if (active_name
!= "") {
1231 handle
->param_active_no
= gui
->get_param_no_by_name(active_name
);
1233 handle
->param_active_no
= -1;
1236 stringstream style_attribute
;
1237 style_attribute
<< "style" << i
+ 1;
1238 const string style
= style_attribute
.str();
1239 clg
->freq_handles
[i
].style
= get_int(style
.c_str(), 0);
1240 if(clg
->freq_handles
[i
].style
== 1 or clg
->freq_handles
[i
].style
== 4) {
1241 clg
->freq_handles
[i
].dimensions
= 1;
1243 handle
->data
= (gpointer
) this;
1245 g_signal_connect(G_OBJECT(widget
), "freqhandle-changed", G_CALLBACK(freqhandle_value_changed
), this);
1248 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-LineGraph");
1252 void line_graph_param_control::get()
1254 GtkWidget
*tw
= gtk_widget_get_toplevel(widget
);
1255 CalfLineGraph
*clg
= CALF_LINE_GRAPH(widget
);
1257 if (tw
&& GTK_WIDGET_TOPLEVEL(tw
) && widget
->window
)
1259 int ws
= gdk_window_get_state(widget
->window
);
1260 if (ws
& (GDK_WINDOW_STATE_WITHDRAWN
| GDK_WINDOW_STATE_ICONIFIED
))
1263 if(clg
->handle_grabbed
>= 0) {
1264 FreqHandle
*handle
= &clg
->freq_handles
[clg
->handle_grabbed
];
1265 if(handle
->dimensions
>= 2) {
1266 float value_y
= from_y_pos(clg
, handle
->value_y
);
1267 gui
->set_param_value(handle
->param_y_no
, value_y
, this);
1270 float value_x
= from_x_pos(handle
->value_x
);
1271 gui
->set_param_value(handle
->param_x_no
, value_x
, this);
1272 } else if(clg
->handle_hovered
>= 0) {
1273 FreqHandle
*handle
= &clg
->freq_handles
[clg
->handle_hovered
];
1275 if(handle
->dimensions
== 3) {
1276 const parameter_properties
&handle_z_props
= *gui
->plugin
->get_metadata_iface()->get_param_props(handle
->param_z_no
);
1277 float value_z
= handle_z_props
.from_01(handle
->value_z
);
1278 gui
->set_param_value(handle
->param_z_no
, value_z
, this);
1284 void line_graph_param_control::set()
1287 GtkWidget
*tw
= gtk_widget_get_toplevel(widget
);
1288 CalfLineGraph
*clg
= CALF_LINE_GRAPH(widget
);
1289 if (tw
&& GTK_WIDGET_TOPLEVEL(tw
) && widget
->window
)
1292 int ws
= gdk_window_get_state(widget
->window
);
1293 if (ws
& (GDK_WINDOW_STATE_WITHDRAWN
| GDK_WINDOW_STATE_ICONIFIED
))
1296 if (clg
->param_zoom
>= 0) {
1297 float _z
= gui
->plugin
->get_param_value(clg
->param_zoom
);
1298 if (_z
!= clg
->zoom
) {
1301 clg
->force_redraw
= true;
1305 if (clg
->param_offset
>= 0) {
1306 float _z
= gui
->plugin
->get_param_value(clg
->param_offset
);
1307 if (_z
!= clg
->offset
) {
1310 clg
->force_redraw
= true;
1314 for (int i
= 0; i
< clg
->freqhandles
; i
++) {
1315 FreqHandle
*handle
= &clg
->freq_handles
[i
];
1317 if (handle
->param_x_no
>= 0)
1319 float value_x
= gui
->plugin
->get_param_value(handle
->param_x_no
);
1320 handle
->value_x
= to_x_pos(value_x
);
1321 if (dsp::_sanitize(handle
->value_x
- handle
->last_value_x
)) {
1322 clg
->handle_redraw
= 1;
1324 handle
->last_value_x
= handle
->value_x
;
1325 if(handle
->dimensions
>= 2 && handle
->param_y_no
>= 0) {
1326 float value_y
= gui
->plugin
->get_param_value(handle
->param_y_no
);
1327 handle
->value_y
= to_y_pos(clg
, value_y
);
1328 if (dsp::_sanitize(handle
->value_y
- handle
->last_value_y
)) {
1329 clg
->handle_redraw
= 1;
1331 handle
->last_value_y
= handle
->value_y
;
1335 if(handle
->dimensions
== 3 && handle
->param_z_no
>= 0) {
1336 const parameter_properties
&handle_z_props
= *gui
->plugin
->get_metadata_iface()->get_param_props(handle
->param_z_no
);
1337 float value_z
= gui
->plugin
->get_param_value(handle
->param_z_no
);
1338 handle
->value_z
= handle_z_props
.to_01(value_z
);
1339 if (dsp::_sanitize(handle
->value_z
- handle
->last_value_z
)) {
1340 clg
->handle_redraw
= 1;
1342 handle
->last_value_z
= handle
->value_z
;
1344 bool _a
= handle
->active
;
1345 if(handle
->param_active_no
>= 0) {
1346 handle
->active
= bool(gui
->plugin
->get_param_value(handle
->param_active_no
));
1348 handle
->active
= true;
1350 if (handle
->active
!= _a
) {
1352 clg
->handle_redraw
= true;
1355 calf_line_graph_expose_request(widget
, force
);
1359 void line_graph_param_control::freqhandle_value_changed(GtkWidget
*widget
, gpointer p
)
1362 FreqHandle
*handle
= (FreqHandle
*)p
;
1363 param_control
*jhp
= (param_control
*)handle
->data
;
1368 line_graph_param_control::~line_graph_param_control()
1373 /******************************** Phase Graph ********************************/
1375 void phase_graph_param_control::on_idle()
1377 if (get_int("refresh", 0))
1381 GtkWidget
*phase_graph_param_control::create(plugin_gui
*_gui
, int _param_no
)
1384 param_no
= _param_no
;
1385 widget
= calf_phase_graph_new ();
1386 gtk_widget_set_name(GTK_WIDGET(widget
), "calf-phase");
1387 CalfPhaseGraph
*clg
= CALF_PHASE_GRAPH(widget
);
1388 widget
->requisition
.width
= get_int("size", 40);
1389 widget
->requisition
.height
= get_int("size", 40);
1390 clg
->source
= gui
->plugin
->get_phase_graph_iface();
1391 clg
->source_id
= param_no
;
1392 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-PhaseGraph");
1396 void phase_graph_param_control::set()
1399 GtkWidget
*tw
= gtk_widget_get_toplevel(widget
);
1400 if (tw
&& GTK_WIDGET_TOPLEVEL(tw
) && widget
->window
) {
1401 gtk_widget_queue_draw(widget
);
1405 phase_graph_param_control::~phase_graph_param_control()
1409 /******************************** List View ********************************/
1411 GtkWidget
*listview_param_control::create(plugin_gui
*_gui
, int _param_no
)
1414 param_no
= _param_no
;
1416 string key
= attribs
["key"];
1417 tmif
= gui
->plugin
->get_metadata_iface()->get_table_metadata_iface(key
.c_str());
1420 g_error("Missing table_metadata_iface for variable '%s'", key
.c_str());
1424 const table_column_info
*tci
= tmif
->get_table_columns();
1427 while (tci
[cols
].name
!= NULL
)
1430 GType
*p
= new GType
[cols
];
1431 for (int i
= 0; i
< cols
; i
++)
1432 p
[i
] = G_TYPE_STRING
;
1433 lstore
= gtk_list_store_newv(cols
, p
);
1434 if (tmif
->get_table_rows() != 0)
1435 set_rows(tmif
->get_table_rows());
1436 widget
= gtk_tree_view_new_with_model(GTK_TREE_MODEL(lstore
));
1438 tree
= GTK_TREE_VIEW (widget
);
1439 g_object_set (G_OBJECT (tree
), "enable-search", FALSE
, "rules-hint", TRUE
, "enable-grid-lines", TRUE
, NULL
);
1441 for (int i
= 0; i
< cols
; i
++)
1443 GtkCellRenderer
*cr
= NULL
;
1445 if (tci
[i
].type
== TCT_ENUM
) {
1446 cr
= gtk_cell_renderer_combo_new ();
1447 GtkListStore
*cls
= gtk_list_store_new(2, G_TYPE_INT
, G_TYPE_STRING
);
1448 for (int j
= 0; tci
[i
].values
[j
]; j
++)
1449 gtk_list_store_insert_with_values(cls
, NULL
, j
, 0, j
, 1, tci
[i
].values
[j
], -1);
1450 g_object_set(cr
, "model", cls
, "editable", TRUE
, "has-entry", FALSE
, "text-column", 1, "mode", GTK_CELL_RENDERER_MODE_EDITABLE
, NULL
);
1453 bool editable
= tci
[i
].type
!= TCT_LABEL
;
1454 cr
= gtk_cell_renderer_text_new ();
1456 g_object_set(cr
, "editable", TRUE
, "mode", GTK_CELL_RENDERER_MODE_EDITABLE
, NULL
);
1458 g_object_set_data (G_OBJECT(cr
), "column", (void *)&tci
[i
]);
1459 g_signal_connect (GTK_OBJECT (cr
), "edited", G_CALLBACK (on_edited
), (gpointer
)this);
1460 g_signal_connect (GTK_OBJECT (cr
), "editing-canceled", G_CALLBACK (on_editing_canceled
), (gpointer
)this);
1461 gtk_tree_view_insert_column_with_attributes(tree
, i
, tci
[i
].name
, cr
, "text", i
, NULL
);
1463 gtk_tree_view_set_headers_visible(tree
, TRUE
);
1464 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-ListView");
1468 void listview_param_control::set_rows(unsigned int needed_rows
)
1470 while(positions
.size() < needed_rows
)
1473 gtk_list_store_insert(lstore
, &iter
, positions
.size());
1474 for (int j
= 0; j
< cols
; j
++)
1476 gtk_list_store_set(lstore
, &iter
, j
, "", -1);
1478 positions
.push_back(iter
);
1482 void listview_param_control::send_configure(const char *key
, const char *value
)
1484 string orig_key
= attribs
["key"] + ":";
1485 bool is_rows
= false;
1486 int row
= -1, col
= -1;
1487 if (parse_table_key(key
, orig_key
.c_str(), is_rows
, row
, col
))
1489 string suffix
= string(key
+ orig_key
.length());
1490 if (is_rows
&& tmif
->get_table_rows() == 0)
1492 int rows
= atoi(value
);
1497 if (row
!= -1 && col
!= -1)
1499 int max_rows
= tmif
->get_table_rows();
1500 if (col
< 0 || col
>= cols
)
1502 g_warning("Invalid column %d in key %s", col
, key
);
1505 if (max_rows
&& (row
< 0 || row
>= max_rows
))
1507 g_warning("Invalid row %d in key %s, this is a fixed table with row count = %d", row
, key
, max_rows
);
1511 if (row
>= (int)positions
.size())
1514 gtk_list_store_set(lstore
, &positions
[row
], col
, value
, -1);
1520 void listview_param_control::on_edited(GtkCellRenderer
*renderer
, gchar
*path
, gchar
*new_text
, listview_param_control
*pThis
)
1522 const table_column_info
*tci
= pThis
->tmif
->get_table_columns();
1523 int column
= ((table_column_info
*)g_object_get_data(G_OBJECT(renderer
), "column")) - tci
;
1524 string key
= pThis
->attribs
["key"] + ":" + i2s(atoi(path
)) + "," + i2s(column
);
1526 const char *error_or_null
= pThis
->gui
->plugin
->configure(key
.c_str(), new_text
);
1528 error
= error_or_null
;
1530 if (error
.empty()) {
1531 pThis
->send_configure(key
.c_str(), new_text
);
1532 gtk_widget_grab_focus(pThis
->widget
);
1533 GtkTreePath
*gpath
= gtk_tree_path_new_from_string (path
);
1534 gtk_tree_view_set_cursor_on_cell (GTK_TREE_VIEW (pThis
->widget
), gpath
, NULL
, NULL
, FALSE
);
1535 gtk_tree_path_free (gpath
);
1539 GtkWidget
*dialog
= gtk_message_dialog_new(pThis
->gui
->window
->toplevel
, GTK_DIALOG_DESTROY_WITH_PARENT
, GTK_MESSAGE_ERROR
, GTK_BUTTONS_OK
,
1540 "%s", error
.c_str());
1541 gtk_dialog_run(GTK_DIALOG(dialog
));
1542 gtk_widget_destroy(dialog
);
1543 gtk_widget_grab_focus(pThis
->widget
);
1547 void listview_param_control::on_editing_canceled(GtkCellRenderer
*renderer
, listview_param_control
*pThis
)
1549 gtk_widget_grab_focus(pThis
->widget
);
1552 /******************************** GtkNotebook control ********************************/
1554 GtkWidget
*notebook_param_control::create(plugin_gui
*_gui
, int _param_no
)
1557 param_no
= _param_no
;
1558 //const parameter_properties &props = get_props();
1562 page
= gui
->plugin
->get_param_value(param_no
);
1563 GtkWidget
*nb
= calf_notebook_new();
1564 widget
= GTK_WIDGET(nb
);
1565 container
= GTK_CONTAINER(nb
);
1566 gtk_widget_set_name(GTK_WIDGET(nb
), "Calf-Notebook");
1567 gtk_notebook_set_current_page(GTK_NOTEBOOK(widget
), page
);
1570 void notebook_param_control::created() {
1571 g_signal_connect (GTK_OBJECT (widget
), "switch-page", G_CALLBACK (notebook_page_changed
), (gpointer
)this);
1574 void notebook_param_control::get()
1577 gui
->set_param_value(param_no
, page
, this);
1579 void notebook_param_control::set()
1584 page
= (gint
)gui
->plugin
->get_param_value(param_no
);
1585 gtk_notebook_set_current_page(GTK_NOTEBOOK(widget
), page
);
1587 void notebook_param_control::add(GtkWidget
*w
, control_base
*base
)
1589 gtk_notebook_append_page(GTK_NOTEBOOK(widget
), w
, gtk_label_new_with_mnemonic(base
->attribs
["page"].c_str()));
1591 void notebook_param_control::notebook_page_changed(GtkWidget
*widget
, GtkWidget
*page
, guint id
, gpointer user
)
1593 notebook_param_control
*jhp
= (notebook_param_control
*)user
;
1594 jhp
->page
= (int)id
;
1598 /******************************** GtkTable container ********************************/
1600 GtkWidget
*table_container::create(plugin_gui
*_gui
, const char *element
, xml_attribute_map
&attributes
)
1602 require_int_attribute("rows");
1603 require_int_attribute("cols");
1604 int homog
= get_int("homogeneous", 0);
1605 int sx
= get_int("spacing-x", 2);
1606 int sy
= get_int("spacing-y", 2);
1607 GtkWidget
*table
= gtk_table_new(get_int("rows", 1), get_int("cols", 1), false);
1609 gtk_table_set_homogeneous(GTK_TABLE(table
), TRUE
);
1611 gtk_table_set_col_spacings(GTK_TABLE(table
), sx
);
1612 gtk_table_set_row_spacings(GTK_TABLE(table
), sy
);
1613 container
= GTK_CONTAINER(table
);
1614 gtk_widget_set_name(GTK_WIDGET(table
), "Calf-Table");
1618 void table_container::add(GtkWidget
*widget
, control_base
*base
)
1620 base
->require_int_attribute("attach-x");
1621 base
->require_int_attribute("attach-y");
1622 int x
= base
->get_int("attach-x"), y
= base
->get_int("attach-y");
1623 int w
= base
->get_int("attach-w", 1), h
= base
->get_int("attach-h", 1);
1624 int shrinkx
= base
->get_int("shrink-x", 0);
1625 int shrinky
= base
->get_int("shrink-y", 0);
1626 int fillx
= (base
->get_int("fill-x", !shrinkx
) ? GTK_FILL
: 0) | (base
->get_int("expand-x", !shrinkx
) ? GTK_EXPAND
: 0) | (shrinkx
? GTK_SHRINK
: 0);
1627 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);
1628 int padx
= base
->get_int("pad-x", 2);
1629 int pady
= base
->get_int("pad-y", 2);
1630 gtk_table_attach(GTK_TABLE(container
), widget
, x
, x
+ w
, y
, y
+ h
, (GtkAttachOptions
)fillx
, (GtkAttachOptions
)filly
, padx
, pady
);
1633 /******************************** alignment container ********************************/
1635 GtkWidget
*alignment_container::create(plugin_gui
*_gui
, const char *element
, xml_attribute_map
&attributes
)
1637 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));
1638 container
= GTK_CONTAINER(align
);
1639 gtk_widget_set_name(GTK_WIDGET(align
), "Calf-Align");
1643 /******************************** GtkFrame container ********************************/
1645 GtkWidget
*frame_container::create(plugin_gui
*_gui
, const char *element
, xml_attribute_map
&attributes
)
1647 GtkWidget
*widget
= calf_frame_new(attribs
["label"].c_str());
1648 container
= GTK_CONTAINER(widget
);
1649 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-Frame");
1653 /******************************** GtkBox type of containers ********************************/
1655 void box_container::add(GtkWidget
*w
, control_base
*base
)
1657 gtk_container_add_with_properties(container
, w
, "expand", get_int("expand", 1), "fill", get_int("fill", 1), NULL
);
1660 /******************************** GtkHBox container ********************************/
1662 GtkWidget
*hbox_container::create(plugin_gui
*_gui
, const char *element
, xml_attribute_map
&attributes
)
1664 GtkWidget
*hbox
= gtk_hbox_new(get_int("homogeneous") >= 1, get_int("spacing", 2));
1665 container
= GTK_CONTAINER(hbox
);
1666 gtk_widget_set_name(GTK_WIDGET(hbox
), "Calf-HBox");
1670 /******************************** GtkVBox container ********************************/
1672 GtkWidget
*vbox_container::create(plugin_gui
*_gui
, const char *element
, xml_attribute_map
&attributes
)
1674 GtkWidget
*vbox
= gtk_vbox_new(get_int("homogeneous") >= 1, get_int("spacing", 2));
1675 container
= GTK_CONTAINER(vbox
);
1676 gtk_widget_set_name(GTK_WIDGET(vbox
), "Calf-VBox");
1680 /******************************** GtkNotebook container ********************************/
1682 GtkWidget
*scrolled_container::create(plugin_gui
*_gui
, const char *element
, xml_attribute_map
&attributes
)
1684 GtkAdjustment
*horiz
= NULL
, *vert
= NULL
;
1685 int width
= get_int("width", 0), height
= get_int("height", 0);
1687 horiz
= GTK_ADJUSTMENT(gtk_adjustment_new(get_int("x", 0), 0, width
, get_int("step-x", 1), get_int("page-x", width
/ 10), 100));
1689 vert
= GTK_ADJUSTMENT(gtk_adjustment_new(get_int("y", 0), 0, width
, get_int("step-y", 1), get_int("page-y", height
/ 10), 10));
1690 GtkWidget
*sw
= gtk_scrolled_window_new(horiz
, vert
);
1691 gtk_widget_set_size_request(sw
, get_int("req-x", -1), get_int("req-y", -1));
1692 container
= GTK_CONTAINER(sw
);
1693 gtk_widget_set_name(GTK_WIDGET(sw
), "Calf-ScrolledWindow");
1697 void scrolled_container::add(GtkWidget
*w
, control_base
*base
)
1699 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(container
), w
);