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 std::vector
<double> control_base::get_vector(const char *name
, std::string
&value
, const parameter_properties
&props
)
88 std::vector
<double> t
;
90 if (attribs
.count(name
)) {
91 value
= attribs
[name
];
94 string::size_type lpos
= value
.find_first_not_of(" ", 0);
95 string::size_type pos
= value
.find_first_of(" ", lpos
);
96 while (string::npos
!= pos
|| string::npos
!= lpos
) {
98 stringstream
stream(value
.substr(lpos
, pos
- lpos
).c_str());
100 t
.push_back(props
.to_01(val
));
101 lpos
= value
.find_first_not_of(" ", pos
);
102 pos
= value
.find_first_of(" ", lpos
);
107 void control_base::set_visibilty(bool state
)
110 gtk_widget_show(widget
);
112 gtk_widget_hide(widget
);
116 void control_base::set_std_properties()
118 if (widget
&& attribs
.find("widget-name") != attribs
.end())
120 string name
= attribs
["widget-name"];
121 gtk_widget_set_name(widget
, name
.c_str());
123 if (widget
&& GTK_IS_CONTAINER(widget
))
125 gtk_container_set_border_width(GTK_CONTAINER(widget
), get_int("border"));
129 static void on_control_destroy(GtkWidget
*w
, gpointer p
)
131 delete (control_base
*)p
;
134 void control_base::created()
136 set_std_properties();
137 g_signal_connect(GTK_OBJECT(widget
), "destroy", (GCallback
)on_control_destroy
, this);
140 /************************* param-associated control base class **************/
142 param_control::param_control()
147 old_displayed_value
= -1.f
;
151 GtkWidget
*param_control::create(plugin_gui
*_gui
)
153 if (attribs
.count("param"))
155 int pno
= _gui
->get_param_no_by_name(attribs
["param"]);
156 param_variable
= _gui
->plugin
->get_metadata_iface()->get_param_props(pno
)->short_name
;
157 return create(_gui
, pno
);
160 return create(_gui
, -1);
163 void param_control::hook_params()
165 if (param_no
!= -1) {
166 gui
->add_param_ctl(param_no
, this);
168 gui
->params
.push_back(this);
171 void param_control::created() {
172 control_base::created();
175 add_context_menu_handler();
178 param_control::~param_control()
181 gui
->remove_param_ctl(param_no
, this);
182 //if (GTK_IS_WIDGET(widget))
183 // gtk_widget_destroy(widget);
186 void param_control::add_context_menu_handler()
190 g_signal_connect(GTK_OBJECT(widget
), "button-press-event", (GCallback
)on_button_press_event
, this);
194 gboolean
param_control::on_button_press_event(GtkWidget
*widget
, GdkEventButton
*event
, void *user_data
)
196 param_control
*self
= (param_control
*)user_data
;
197 const parameter_properties
&props
= self
->get_props();
198 if (event
->button
== 3 && !(props
.flags
& PF_PROP_OUTPUT
))
200 self
->do_popup_menu();
203 else if (event
->button
== 2)
205 if (!strcmp(gtk_widget_get_name(widget
), "Calf-LineGraph")) {
206 CalfLineGraph
*clg
= CALF_LINE_GRAPH(widget
);
207 if (clg
->freqhandles
&& clg
->handle_hovered
>= 0) {
208 FreqHandle
* fh
= &clg
->freq_handles
[clg
->handle_hovered
];
209 self
->param_no
= fh
->param_x_no
;
213 self
->create_value_entry(widget
, event
->x_root
, event
->y_root
);
219 void param_control::do_popup_menu()
222 gui
->on_control_popup(this, param_no
);
225 void param_control::destroy_value_entry ()
227 // remove the window containing the entry
228 gtk_widget_destroy(GTK_WIDGET(entrywin
));
231 gboolean
param_control::value_entry_unfocus(GtkWidget
*widget
, GdkEventFocus
*event
, void *user_data
)
233 // destroy window if it looses focus
234 param_control
*self
= (param_control
*)user_data
;
235 self
->destroy_value_entry();
238 gboolean
param_control::value_entry_action(GtkEntry
*widget
, GdkEvent
*event
, void *user_data
)
240 // called when a key was hit, sorts out and treats RETURN and ESC
241 param_control
*self
= (param_control
*)user_data
;
242 const parameter_properties
&props
= self
->get_props();
243 GdkEventKey
*key
= (GdkEventKey
*)event
;
244 if(key
->keyval
== GDK_Escape
)
245 self
->destroy_value_entry();
246 else if (key
->keyval
== GDK_Return
) {
247 float val
= props
.string_to_value(gtk_entry_get_text(widget
));
248 self
->gui
->plugin
->set_param_value(self
->param_no
, val
);
250 self
->destroy_value_entry();
254 void param_control::create_value_entry(GtkWidget
*widget
, int x
, int y
)
257 // kill an existing entry window on re-trigger
258 destroy_value_entry();
265 const parameter_properties
&props
= get_props();
266 float value
= gui
->plugin
->get_param_value(param_no
);
268 // no chance for a menu, so we have to do everything by hand
269 entrywin
= gtk_window_new(GTK_WINDOW_TOPLEVEL
);
270 gtk_widget_set_name(GTK_WIDGET(entrywin
), "Calf-Value-Entry");
271 gtk_window_set_title (GTK_WINDOW(entrywin
), "Calf Value Entry");
272 gtk_window_set_resizable (GTK_WINDOW(entrywin
), FALSE
);
273 gtk_window_set_decorated (GTK_WINDOW(entrywin
), FALSE
);
274 gtk_window_set_skip_taskbar_hint (GTK_WINDOW(entrywin
), TRUE
);
275 gtk_window_set_skip_pager_hint (GTK_WINDOW(entrywin
), TRUE
);
276 gtk_window_set_transient_for (GTK_WINDOW(entrywin
), GTK_WINDOW (gui
->window
->toplevel
));
277 gtk_window_set_gravity(GTK_WINDOW(entrywin
), GDK_GRAVITY_CENTER
);
278 gtk_widget_set_events (GTK_WIDGET(entrywin
), GDK_FOCUS_CHANGE_MASK
);
279 g_signal_connect (G_OBJECT(entrywin
), "focus-out-event", G_CALLBACK (value_entry_unfocus
), this);
281 // create the text entry
282 GtkWidget
*entry
= gtk_entry_new();
283 gtk_widget_set_name(GTK_WIDGET(entry
), "Calf-Entry");
284 gtk_entry_set_width_chars(GTK_ENTRY(entry
), props
.get_char_count());
285 gtk_entry_set_text(GTK_ENTRY(entry
), props
.to_string(value
).c_str());
286 gtk_widget_add_events (entry
, GDK_KEY_PRESS_MASK
);
287 g_signal_connect (entry
, "key-press-event", (GCallback
)value_entry_action
, this);
289 // stitch together and show
290 gtk_container_add(GTK_CONTAINER (entrywin
), entry
);
291 gtk_widget_show_all(entrywin
);
292 gtk_window_move(GTK_WINDOW (entrywin
), x
, y
);
298 /******************************** Combo Box ********************************/
300 GtkWidget
*combo_box_param_control::create(plugin_gui
*_gui
, int _param_no
)
303 param_no
= _param_no
;
304 lstore
= gtk_list_store_new(2, G_TYPE_STRING
, G_TYPE_STRING
); // value, key
307 const parameter_properties
&props
= get_props();
308 widget
= calf_combobox_new ();
309 if (param_no
!= -1 && props
.choices
)
311 for (int j
= (int)props
.min
; j
<= (int)props
.max
; j
++)
312 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);
314 gtk_combo_box_set_model (GTK_COMBO_BOX(widget
), GTK_TREE_MODEL(lstore
));
315 g_signal_connect (GTK_OBJECT (widget
), "changed", G_CALLBACK (combo_value_changed
), (gpointer
)this);
316 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-Combobox");
320 void combo_box_param_control::set()
325 const parameter_properties
&props
= get_props();
326 gtk_combo_box_set_active (GTK_COMBO_BOX (widget
), (int)gui
->plugin
->get_param_value(param_no
) - (int)props
.min
);
330 void combo_box_param_control::get()
334 const parameter_properties
&props
= get_props();
335 gui
->set_param_value(param_no
, gtk_combo_box_get_active (GTK_COMBO_BOX(widget
)) + props
.min
, this);
339 void combo_box_param_control::combo_value_changed(GtkComboBox
*widget
, gpointer value
)
341 combo_box_param_control
*jhp
= (combo_box_param_control
*)value
;
344 if (jhp
->attribs
.count("setter-key"))
348 if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (jhp
->widget
), &iter
))
350 gtk_tree_model_get (GTK_TREE_MODEL (jhp
->lstore
), &iter
, 1, &key
, -1);
352 jhp
->gui
->plugin
->configure(jhp
->attribs
["setter-key"].c_str(), key
);
361 void combo_box_param_control::send_status(const char *key
, const char *value
)
363 if (attribs
.count("key") && key
== attribs
["key"])
365 if (value
== last_list
)
369 gtk_list_store_clear (lstore
);
371 std::string v
= value
;
374 while (pos
< v
.length()) {
375 size_t endpos
= v
.find("\n", pos
);
376 if (endpos
== string::npos
)
378 string line
= v
.substr(pos
, endpos
- pos
);
380 size_t tabpos
= line
.find('\t');
381 if (tabpos
== string::npos
)
384 key
= line
.substr(0, tabpos
);
385 label
= line
.substr(tabpos
+ 1);
388 gtk_list_store_insert_with_values (lstore
, >i
, i
, 0, label
.c_str(), 1, key
.c_str(), -1);
396 if (attribs
.count("current-key") && key
== attribs
["current-key"])
403 void combo_box_param_control::set_to_last_key()
405 map
<string
, GtkTreeIter
>::iterator i
= key2pos
.find(last_key
);
406 if (i
!= key2pos
.end())
408 gtk_combo_box_set_active_iter (GTK_COMBO_BOX (widget
), &i
->second
);
412 gtk_combo_box_set_active (GTK_COMBO_BOX (widget
), -1);
415 /******************************** Horizontal Fader ********************************/
418 scale_to_default (gpointer data
)
420 hscale_param_control
*jhp
= (hscale_param_control
*)data
;
421 const parameter_properties
&props
= jhp
->get_props();
422 gtk_range_set_value (GTK_RANGE (jhp
->widget
), props
.to_01(props
.def_value
));
428 scale_button_press (GtkWidget
*widget
, GdkEventKey
*event
, gpointer
*user_data
)
430 if (event
->type
== GDK_2BUTTON_PRESS
) {
431 // this actually creates a harmless race condition, but diving deep
432 // into gtk signal handling code wouldn't and the resulting complexity
433 // would not really be worth the effort
434 // The timeout is set high enough that most of the time the race
435 // will turn out in our/the users favor
436 g_timeout_add (200, (GSourceFunc
)scale_to_default
, user_data
);
443 GtkWidget
*hscale_param_control::create(plugin_gui
*_gui
, int _param_no
)
446 param_no
= _param_no
;
448 widget
= calf_fader_new(1, get_int("size", 2), 0, 1, get_props().get_increment());
450 g_signal_connect (GTK_OBJECT (widget
), "value-changed", G_CALLBACK (hscale_value_changed
), (gpointer
)this);
451 g_signal_connect (GTK_OBJECT (widget
), "format-value", G_CALLBACK (hscale_format_value
), (gpointer
)this);
452 g_signal_connect (GTK_OBJECT (widget
), "button-press-event", G_CALLBACK (scale_button_press
), (gpointer
)this);
454 if(get_int("inverted", 0) > 0) {
455 gtk_range_set_inverted(GTK_RANGE(widget
), TRUE
);
457 int size
= get_int("size", 2);
458 char *name
= g_strdup_printf("Calf-HScale%i", size
);
459 gtk_widget_set_name(GTK_WIDGET(widget
), name
);
460 gtk_widget_set_size_request (widget
, size
* 100, -1);
463 if (attribs
.count("width"))
464 gtk_widget_set_size_request (widget
, get_int("width", 200), -1);
465 if (attribs
.count("position"))
467 string v
= attribs
["position"];
468 if (v
== "top") gtk_scale_set_value_pos(GTK_SCALE(widget
), GTK_POS_TOP
);
469 if (v
== "bottom") gtk_scale_set_value_pos(GTK_SCALE(widget
), GTK_POS_BOTTOM
);
474 void hscale_param_control::set()
477 const parameter_properties
&props
= get_props();
478 gtk_range_set_value (GTK_RANGE (widget
), props
.to_01 (gui
->plugin
->get_param_value(param_no
)));
479 // hscale_value_changed (GTK_HSCALE (widget), (gpointer)this);
482 void hscale_param_control::get()
484 const parameter_properties
&props
= get_props();
485 float cvalue
= props
.from_01 (gtk_range_get_value (GTK_RANGE (widget
)));
486 gui
->set_param_value(param_no
, cvalue
, this);
489 void hscale_param_control::hscale_value_changed(GtkHScale
*widget
, gpointer value
)
491 hscale_param_control
*jhp
= (hscale_param_control
*)value
;
495 gchar
*hscale_param_control::hscale_format_value(GtkScale
*widget
, double arg1
, gpointer value
)
497 hscale_param_control
*jhp
= (hscale_param_control
*)value
;
498 const parameter_properties
&props
= jhp
->get_props();
499 float cvalue
= props
.from_01 (arg1
);
502 // return g_strdup_printf ("%s = %g", props.to_string (cvalue).c_str(), arg1);
503 return g_strdup (props
.to_string (cvalue
).c_str());
506 /******************************** Vertical Fader ********************************/
508 GtkWidget
*vscale_param_control::create(plugin_gui
*_gui
, int _param_no
)
511 param_no
= _param_no
;
512 widget
= calf_fader_new(0, get_int("size", 2), 0, 1, get_props().get_increment());
513 g_signal_connect (GTK_OBJECT (widget
), "value-changed", G_CALLBACK (vscale_value_changed
), (gpointer
)this);
514 g_signal_connect (GTK_OBJECT (widget
), "button-press-event", G_CALLBACK (scale_button_press
), (gpointer
)this);
516 gtk_scale_set_draw_value(GTK_SCALE(widget
), FALSE
);
518 if(get_int("inverted", 0) > 0) {
519 gtk_range_set_inverted(GTK_RANGE(widget
), TRUE
);
521 int size
= get_int("size", 2);
522 char *name
= g_strdup_printf("Calf-VScale%i", size
);
523 gtk_widget_set_size_request (widget
, -1, size
* 100);
524 gtk_widget_set_name(GTK_WIDGET(widget
), name
);
527 if (attribs
.count("height"))
528 gtk_widget_set_size_request (widget
, -1, get_int("height", 200));
533 void vscale_param_control::set()
536 const parameter_properties
&props
= get_props();
537 gtk_range_set_value (GTK_RANGE (widget
), props
.to_01 (gui
->plugin
->get_param_value(param_no
)));
538 // vscale_value_changed (GTK_HSCALE (widget), (gpointer)this);
541 void vscale_param_control::get()
543 const parameter_properties
&props
= get_props();
544 float cvalue
= props
.from_01 (gtk_range_get_value (GTK_RANGE (widget
)));
545 gui
->set_param_value(param_no
, cvalue
, this);
548 void vscale_param_control::vscale_value_changed(GtkHScale
*widget
, gpointer value
)
550 vscale_param_control
*jhp
= (vscale_param_control
*)value
;
554 /******************************** Label ********************************/
556 GtkWidget
*label_param_control::create(plugin_gui
*_gui
, int _param_no
)
558 gui
= _gui
, param_no
= _param_no
;
560 if (param_no
!= -1 && !attribs
.count("text"))
561 text
= get_props().name
;
563 text
= attribs
["text"];
564 widget
= gtk_label_new(text
.c_str());
565 gtk_misc_set_alignment (GTK_MISC (widget
), get_float("align-x", 0.5), get_float("align-y", 0.5));
566 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-Label");
570 /******************************** Value ********************************/
572 GtkWidget
*value_param_control::create(plugin_gui
*_gui
, int _param_no
)
575 param_no
= _param_no
;
577 widget
= gtk_label_new ("");
580 const parameter_properties
&props
= get_props();
581 int width
= get_int("width", 0);
582 gtk_label_set_width_chars (GTK_LABEL (widget
),
583 width
? width
: props
.get_char_count());
587 require_attribute("key");
588 require_int_attribute("width");
589 param_variable
= attribs
["key"];
590 gtk_label_set_width_chars (GTK_LABEL (widget
), get_int("width"));
592 gtk_misc_set_alignment (GTK_MISC (widget
), get_float("align-x", 0.5), get_float("align-y", 0.5));
593 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-Value");
597 void value_param_control::set()
603 const parameter_properties
&props
= get_props();
604 string value
= props
.to_string(gui
->plugin
->get_param_value(param_no
));
606 if (value
== old_value
)
609 gtk_label_set_text (GTK_LABEL (widget
), value
.c_str());
612 void value_param_control::send_status(const char *key
, const char *value
)
614 if (key
== param_variable
)
616 gtk_label_set_text (GTK_LABEL (widget
), value
);
620 /******************************** VU Meter ********************************/
622 GtkWidget
*vumeter_param_control::create(plugin_gui
*_gui
, int _param_no
)
624 gui
= _gui
, param_no
= _param_no
;
625 // const parameter_properties &props = get_props();
626 widget
= calf_vumeter_new ();
627 CalfVUMeter
*vu
= CALF_VUMETER(widget
);
628 gtk_widget_set_name(GTK_WIDGET(widget
), "calf-vumeter");
629 calf_vumeter_set_mode (vu
, (CalfVUMeterMode
)get_int("mode", 0));
630 vu
->vumeter_hold
= get_float("hold", 0);
631 vu
->vumeter_falloff
= get_float("falloff", 0.f
);
632 vu
->vumeter_width
= get_int("width", 80);
633 vu
->vumeter_height
= get_int("height", 18);
634 vu
->vumeter_position
= get_int("position", 0);
635 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-VUMeter");
639 void vumeter_param_control::set()
642 // const parameter_properties &props = get_props();
643 calf_vumeter_set_value (CALF_VUMETER (widget
), gui
->plugin
->get_param_value(param_no
));
648 GtkWidget
*led_param_control::create(plugin_gui
*_gui
, int _param_no
)
650 gui
= _gui
, param_no
= _param_no
;
651 // const parameter_properties &props = get_props();
652 widget
= calf_led_new ();
653 gtk_widget_set_name(GTK_WIDGET(widget
), "calf-led");
654 CALF_LED(widget
)->led_mode
= get_int("mode", 0);
655 CALF_LED(widget
)->size
= get_int("size", 1);
656 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-LED");
660 void led_param_control::set()
663 // const parameter_properties &props = get_props();
664 calf_led_set_value (CALF_LED (widget
), gui
->plugin
->get_param_value(param_no
));
669 GtkWidget
*tube_param_control::create(plugin_gui
*_gui
, int _param_no
)
671 gui
= _gui
, param_no
= _param_no
;
672 // const parameter_properties &props = get_props();
673 GtkWidget
*widget
= calf_tube_new ();
674 CalfTube
*tube
= CALF_TUBE(widget
);
675 gtk_widget_set_name(widget
, "calf-tube");
676 tube
->size
= get_int("size", 2);
677 tube
->direction
= get_int("direction", 2);
678 gtk_widget_set_name(widget
, "Calf-Tube");
682 void tube_param_control::set()
685 // const parameter_properties &props = get_props();
686 calf_tube_set_value (CALF_TUBE (widget
), gui
->plugin
->get_param_value(param_no
));
689 /******************************** Check Box ********************************/
691 GtkWidget
*check_param_control::create(plugin_gui
*_gui
, int _param_no
)
694 param_no
= _param_no
;
696 widget
= gtk_check_button_new ();
697 g_signal_connect (GTK_OBJECT (widget
), "toggled", G_CALLBACK (check_value_changed
), (gpointer
)this);
698 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-Checkbox");
702 void check_param_control::check_value_changed(GtkCheckButton
*widget
, gpointer value
)
704 param_control
*jhp
= (param_control
*)value
;
708 void check_param_control::get()
710 const parameter_properties
&props
= get_props();
711 gui
->set_param_value(param_no
, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widget
)) + props
.min
, this);
714 void check_param_control::set()
717 const parameter_properties
&props
= get_props();
718 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget
), (int)gui
->plugin
->get_param_value(param_no
) - (int)props
.min
);
721 /******************************** Radio Button ********************************/
723 GtkWidget
*radio_param_control::create(plugin_gui
*_gui
, int _param_no
)
726 param_no
= _param_no
;
727 require_attribute("value");
729 string value_name
= attribs
["value"];
730 const parameter_properties
&props
= get_props();
731 if (props
.choices
&& (value_name
< "0" || value_name
> "9"))
733 for (int i
= 0; props
.choices
[i
]; i
++)
735 if (value_name
== props
.choices
[i
])
737 value
= i
+ (int)props
.min
;
743 value
= get_int("value");
745 if (attribs
.count("label"))
746 widget
= gtk_radio_button_new_with_label (gui
->get_radio_group(param_no
), attribs
["label"].c_str());
748 widget
= gtk_radio_button_new_with_label (gui
->get_radio_group(param_no
), props
.choices
[value
- (int)props
.min
]);
749 gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (widget
), FALSE
);
751 gui
->set_radio_group(param_no
, gtk_radio_button_get_group (GTK_RADIO_BUTTON (widget
)));
752 g_signal_connect (GTK_OBJECT (widget
), "clicked", G_CALLBACK (radio_clicked
), (gpointer
)this);
753 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-RadioButton");
757 void radio_param_control::radio_clicked(GtkRadioButton
*widget
, gpointer value
)
759 param_control
*jhp
= (param_control
*)value
;
763 void radio_param_control::get()
765 // const parameter_properties &props = get_props();
766 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget
)))
767 gui
->set_param_value(param_no
, value
, this);
770 void radio_param_control::set()
773 const parameter_properties
&props
= get_props();
774 float pv
= gui
->plugin
->get_param_value(param_no
);
775 if (fabs(value
-pv
) < 0.5)
776 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget
), value
== ((int)gui
->plugin
->get_param_value(param_no
) - (int)props
.min
));
779 /******************************** Spin Button ********************************/
781 GtkWidget
*spin_param_control::create(plugin_gui
*_gui
, int _param_no
)
784 param_no
= _param_no
;
786 const parameter_properties
&props
= get_props();
788 widget
= gtk_spin_button_new_with_range (props
.min
, props
.max
, (props
.max
- props
.min
) / (props
.step
- 1));
790 widget
= gtk_spin_button_new_with_range (props
.min
, props
.max
, props
.step
);
792 widget
= gtk_spin_button_new_with_range (props
.min
, props
.max
, 1);
793 gtk_spin_button_set_digits (GTK_SPIN_BUTTON(widget
), get_int("digits", 0));
794 g_signal_connect (GTK_OBJECT (widget
), "value-changed", G_CALLBACK (value_changed
), (gpointer
)this);
795 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-SpinButton");
799 void spin_param_control::value_changed(GtkSpinButton
*widget
, gpointer value
)
801 param_control
*jhp
= (param_control
*)value
;
805 void spin_param_control::get()
807 // const parameter_properties &props = get_props();
808 gui
->set_param_value(param_no
, gtk_spin_button_get_value_as_float (GTK_SPIN_BUTTON (widget
)), this);
811 void spin_param_control::set()
814 // const parameter_properties &props = get_props();
815 gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget
), gui
->plugin
->get_param_value(param_no
));
818 /******************************** Button ********************************/
820 GtkWidget
*button_param_control::create(plugin_gui
*_gui
, int _param_no
)
823 param_no
= _param_no
;
824 widget
= calf_button_new ((gchar
*)get_props().name
);
825 g_signal_connect (GTK_OBJECT (widget
), "pressed", G_CALLBACK (button_clicked
), (gpointer
)this);
826 g_signal_connect (GTK_OBJECT (widget
), "released", G_CALLBACK (button_clicked
), (gpointer
)this);
827 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-Button");
831 void button_param_control::button_clicked(GtkButton
*widget
, gpointer value
)
833 param_control
*jhp
= (param_control
*)value
;
837 void button_param_control::get()
839 const parameter_properties
&props
= get_props();
840 gui
->set_param_value(param_no
, gtk_widget_get_state(widget
) == GTK_STATE_ACTIVE
? props
.max
: props
.min
, this);
843 void button_param_control::set()
846 const parameter_properties
&props
= get_props();
847 if (gui
->plugin
->get_param_value(param_no
) - props
.min
>= 0.5)
848 gtk_button_clicked (GTK_BUTTON (widget
));
851 /******************************** Knob ********************************/
853 GtkWidget
*knob_param_control::create(plugin_gui
*_gui
, int _param_no
)
856 param_no
= _param_no
;
857 const parameter_properties
&props
= get_props();
858 widget
= calf_knob_new();
859 float increment
= props
.get_increment();
860 gtk_range_get_adjustment(GTK_RANGE(widget
))->step_increment
= increment
;
861 CalfKnob
* knob
= CALF_KNOB(widget
);
862 knob
->default_value
= props
.to_01(props
.def_value
);
863 knob
->type
= get_int("type");
864 knob
->size
= min(5, max(1, get_int("size", 2)));
867 double min
= double(props
.min
);
868 double max
= double(props
.max
);
869 switch (knob
->type
) {
871 case 0: sprintf(ticks
, "%f %f", min
, max
); break;
872 case 1: sprintf(ticks
, "%f %f %f", min
, props
.from_01(0.5), max
); break;
873 case 2: sprintf(ticks
, "%f %f", min
, max
); break;
874 case 3: sprintf(ticks
, "%f %f", min
, max
); break;
876 string t_
= string(ticks
);
877 knob
->ticks
= get_vector("ticks", t_
, props
);
878 g_signal_connect(GTK_OBJECT(widget
), "value-changed", G_CALLBACK(knob_value_changed
), (gpointer
)this);
879 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-Knob");
883 void knob_param_control::get()
885 const parameter_properties
&props
= get_props();
886 float value
= props
.from_01(gtk_range_get_value(GTK_RANGE(widget
)));
887 gui
->set_param_value(param_no
, value
, this);
890 void knob_param_control::set()
893 const parameter_properties
&props
= get_props();
894 gtk_range_set_value(GTK_RANGE(widget
), props
.to_01 (gui
->plugin
->get_param_value(param_no
)));
897 void knob_param_control::knob_value_changed(GtkWidget
*widget
, gpointer value
)
899 param_control
*jhp
= (param_control
*)value
;
903 /******************************** Toggle Button ********************************/
905 GtkWidget
*toggle_param_control::create(plugin_gui
*_gui
, int _param_no
)
908 param_no
= _param_no
;
909 widget
= calf_toggle_new ();
911 CALF_TOGGLE(widget
)->size
= get_int("size", 2);
913 g_signal_connect (GTK_OBJECT (widget
), "value-changed", G_CALLBACK (toggle_value_changed
), (gpointer
)this);
914 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-ToggleButton");
918 void toggle_param_control::get()
920 const parameter_properties
&props
= get_props();
921 float value
= props
.from_01(gtk_range_get_value(GTK_RANGE(widget
)));
922 gui
->set_param_value(param_no
, value
, this);
925 void toggle_param_control::set()
928 const parameter_properties
&props
= get_props();
929 gtk_range_set_value(GTK_RANGE(widget
), props
.to_01 (gui
->plugin
->get_param_value(param_no
)));
932 void toggle_param_control::toggle_value_changed(GtkWidget
*widget
, gpointer value
)
934 param_control
*jhp
= (param_control
*)value
;
938 /******************************** Tap Button ********************************/
940 GtkWidget
*tap_button_param_control::create(plugin_gui
*_gui
, int _param_no
)
943 param_no
= _param_no
;
948 widget
= calf_tap_button_new ();
949 //CALF_TAP(widget)->size = get_int("size", 2);
950 g_signal_connect (GTK_OBJECT (widget
), "button-press-event", G_CALLBACK (tap_button_pressed
), (gpointer
)this);
951 g_signal_connect (GTK_OBJECT (widget
), "released", G_CALLBACK (tap_button_released
), (gpointer
)this);
952 g_signal_connect (GTK_OBJECT (widget
), "leave", G_CALLBACK (tap_button_released
), (gpointer
)this);
953 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-TapButton");
957 void tap_button_param_control::get()
959 gui
->set_param_value(param_no
, value
, this);
962 void tap_button_param_control::set()
967 gettimeofday(&tv
, 0);
968 unsigned long _now
= tv
.tv_sec
* 1000;
969 if(_now
> init_time
+ 2000) {
970 // user stopped tapping
974 CALF_TAP_BUTTON(widget
)->state
= 0;
975 gtk_widget_queue_draw(widget
);
980 gboolean
tap_button_param_control::tap_button_pressed(GtkWidget
*widget
, GdkEventButton
*event
, gpointer value
)
982 tap_button_param_control
*ctl
= (tap_button_param_control
*)value
;
983 CalfTapButton
*tap
= CALF_TAP_BUTTON(widget
);
986 if (event
->type
== GDK_BUTTON_PRESS
and event
->button
== 1)
989 gettimeofday(&tv
, 0);
990 ctl
->init_time
= tv
.tv_sec
* 1000;
996 ctl
->avg_value
= (ctl
->avg_value
* 3 + (time
- ctl
->last_time
)) / 4.f
;
998 ctl
->avg_value
= time
- ctl
->last_time
;
999 ctl
->value
= 60.f
/ (float)(ctl
->avg_value
/ 1000.f
);
1001 if (ctl
->value
> 30 and ctl
->value
< 300)
1004 ctl
->last_time
= time
;
1005 gtk_widget_queue_draw(widget
);
1009 gboolean
tap_button_param_control::tap_button_released(GtkWidget
*widget
, gpointer value
)
1011 tap_button_param_control
*ctl
= (tap_button_param_control
*)value
;
1012 CalfTapButton
*tap
= CALF_TAP_BUTTON(widget
);
1013 tap
->state
= ctl
->last_time
? 1 : 0;
1014 gtk_widget_queue_draw(widget
);
1018 /******************************** Keyboard ********************************/
1020 GtkWidget
*keyboard_param_control::create(plugin_gui
*_gui
, int _param_no
)
1023 param_no
= _param_no
;
1024 // const parameter_properties &props = get_props();
1026 widget
= calf_keyboard_new();
1027 kb
= CALF_KEYBOARD(widget
);
1028 kb
->nkeys
= get_int("octaves", 4) * 7 + 1;
1029 kb
->sink
= new CalfKeyboard::EventAdapter
;
1030 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-Keyboard");
1034 /******************************** Curve ********************************/
1036 struct curve_param_control_callback
: public CalfCurve::EventAdapter
1038 curve_param_control
*ctl
;
1040 curve_param_control_callback(curve_param_control
*_ctl
)
1043 virtual void curve_changed(CalfCurve
*src
, const CalfCurve::point_vector
&data
) {
1045 ss
<< data
.size() << endl
;
1046 for (size_t i
= 0; i
< data
.size(); i
++)
1047 ss
<< data
[i
].first
<< " " << data
[i
].second
<< endl
;
1048 ctl
->gui
->plugin
->configure(ctl
->attribs
["key"].c_str(), ss
.str().c_str());
1050 virtual void clip(CalfCurve
*src
, int pt
, float &x
, float &y
, bool &hide
)
1052 // int gridpt = floor(x * 71 * 2);
1053 // clip to the middle of the nearest white key
1054 x
= (floor(x
* 71) + 0.5)/ 71.0;
1058 GtkWidget
*curve_param_control::create(plugin_gui
*_gui
, int _param_no
)
1061 param_no
= _param_no
;
1062 require_attribute("key");
1064 widget
= calf_curve_new(get_int("maxpoints", -1));
1065 curve
= CALF_CURVE(widget
);
1066 curve
->sink
= new curve_param_control_callback(this);
1067 // gtk_curve_set_curve_type(curve, GTK_CURVE_TYPE_LINEAR);
1068 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-Curve");
1072 void curve_param_control::send_configure(const char *key
, const char *value
)
1074 // cout << "send conf " << key << endl;
1075 if (attribs
["key"] == key
)
1077 stringstream
ss(value
);
1078 CalfCurve::point_vector pts
;
1081 unsigned int npoints
= 0;
1085 for (i
= 0; i
< npoints
&& i
< curve
->point_limit
; i
++)
1088 pts
.push_back(CalfCurve::point(x
, y
));
1090 calf_curve_set_points(widget
, pts
);
1095 /******************************** Meter Scale ********************************/
1097 GtkWidget
*meter_scale_param_control::create(plugin_gui
*_gui
, int _param_no
)
1100 param_no
= _param_no
;
1101 widget
= calf_meter_scale_new ();
1102 const parameter_properties
&props
= get_props();
1103 CalfMeterScale
*ms
= CALF_METER_SCALE(widget
);
1104 gtk_widget_set_name(widget
, "Calf-MeterScale");
1105 string str
= "0 0.5 1";
1106 ms
->marker
= get_vector("marker", str
, props
);
1107 ms
->mode
= (CalfVUMeterMode
)get_int("mode", 0);
1108 ms
->position
= get_int("position", 0);
1109 ms
->dots
= get_int("dots", 0);
1113 /******************************** Entry ********************************/
1115 GtkWidget
*entry_param_control::create(plugin_gui
*_gui
, int _param_no
)
1118 param_no
= _param_no
;
1119 require_attribute("key");
1121 widget
= gtk_entry_new();
1122 entry
= GTK_ENTRY(widget
);
1123 g_signal_connect(GTK_OBJECT(widget
), "changed", G_CALLBACK(entry_value_changed
), (gpointer
)this);
1124 gtk_editable_set_editable(GTK_EDITABLE(entry
), get_int("editable", 1));
1125 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-Entry");
1129 void entry_param_control::send_configure(const char *key
, const char *value
)
1131 // cout << "send conf " << key << endl;
1132 if (attribs
["key"] == key
)
1134 gtk_entry_set_text(entry
, value
);
1138 void entry_param_control::entry_value_changed(GtkWidget
*widget
, gpointer value
)
1140 entry_param_control
*ctl
= (entry_param_control
*)value
;
1141 ctl
->gui
->plugin
->configure(ctl
->attribs
["key"].c_str(), gtk_entry_get_text(ctl
->entry
));
1144 /******************************** File Chooser ********************************/
1146 GtkWidget
*filechooser_param_control::create(plugin_gui
*_gui
, int _param_no
)
1149 param_no
= _param_no
;
1150 require_attribute("key");
1151 require_attribute("title");
1153 widget
= gtk_file_chooser_button_new(attribs
["title"].c_str(), GTK_FILE_CHOOSER_ACTION_OPEN
);
1154 filechooser
= GTK_FILE_CHOOSER_BUTTON(widget
);
1155 // XXXKF this is GTK+ 2.12 function, does any replacement exist?
1156 // MS: switched from g_signal_connect to g_signal_connect for better emission of signals
1157 g_signal_connect(GTK_OBJECT(widget
), "file-set", G_CALLBACK(filechooser_value_changed
), (gpointer
)this);
1158 if (attribs
.count("width"))
1159 gtk_widget_set_size_request (widget
, get_int("width", 200), -1);
1160 if (attribs
.count("width_chars"))
1161 gtk_file_chooser_button_set_width_chars (filechooser
, get_int("width_chars"));
1162 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-FileButton");
1166 void filechooser_param_control::send_configure(const char *key
, const char *value
)
1168 // cout << "send conf " << key << endl;
1169 if (attribs
["key"] == key
)
1171 gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(filechooser
), value
);
1175 void filechooser_param_control::filechooser_value_changed(GtkWidget
*widget
, gpointer value
)
1177 filechooser_param_control
*ctl
= (filechooser_param_control
*)value
;
1178 const char *filename
= gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(ctl
->filechooser
));
1180 ctl
->gui
->plugin
->configure(ctl
->attribs
["key"].c_str(), filename
);
1183 /******************************** Line Graph ********************************/
1185 void line_graph_param_control::on_idle()
1187 if (get_int("refresh", 0))
1191 static float to_x_pos(float freq
)
1193 return log(freq
/ 20.0) / log(1000);
1196 static float from_x_pos(float pos
)
1198 float a
= pos
* 3.0;
1199 float b
= powf(10.0, a
);
1204 static float to_y_pos(CalfLineGraph
*lg
, float gain
)
1206 //log(gain) * (1.0 / log(32));
1207 return 0.5 - dB_grid(gain
, 128 * lg
->zoom
, lg
->offset
) / 2.0;
1210 static float from_y_pos(CalfLineGraph
*lg
, float pos
)
1212 float gain
= powf(128.0 * lg
->zoom
, (0.5 - pos
) * 2.0 - lg
->offset
);
1216 GtkWidget
*line_graph_param_control::create(plugin_gui
*a_gui
, int a_param_no
)
1219 param_no
= a_param_no
;
1220 //last_generation = -1;
1222 widget
= calf_line_graph_new ();
1224 gtk_widget_set_name(GTK_WIDGET(widget
), "calf-graph");
1226 CalfLineGraph
*clg
= CALF_LINE_GRAPH(widget
);
1227 widget
->requisition
.width
= get_int("width", 40);
1228 widget
->requisition
.height
= get_int("height", 40);
1230 calf_line_graph_set_square(clg
, get_int("square", 0));
1232 clg
->source
= gui
->plugin
->get_line_graph_iface();
1233 clg
->source_id
= param_no
;
1234 clg
->fade
= get_float("fade", 1.0);
1235 clg
->mode
= get_int("mode", 0);
1236 clg
->use_crosshairs
= get_int("crosshairs", 0);
1237 clg
->freqhandles
= get_int("freqhandles", 0);
1238 clg
->enforce_handle_order
= get_int("enforce-handle-order", 0);
1239 clg
->min_handle_distance
= get_float("min-handle-distance", 0.01);
1241 const string
&zoom_name
= attribs
["zoom"];
1242 if (zoom_name
!= "")
1243 clg
->param_zoom
= gui
->get_param_no_by_name(zoom_name
);
1245 const string
&offset_name
= attribs
["offset"];
1246 if (offset_name
!= "")
1247 clg
->param_offset
= gui
->get_param_no_by_name(offset_name
);
1249 if (clg
->freqhandles
> 0)
1251 for(int i
= 0; i
< clg
->freqhandles
; i
++)
1253 FreqHandle
*handle
= &clg
->freq_handles
[i
];
1255 stringstream handle_x_attribute
;
1256 handle_x_attribute
<< "handle" << i
+ 1 << "-x";
1257 const string
¶m_x_name
= attribs
[handle_x_attribute
.str()];
1258 if(param_x_name
== "")
1261 int param_x_no
= gui
->get_param_no_by_name(param_x_name
);
1262 const parameter_properties
&handle_x_props
= *gui
->plugin
->get_metadata_iface()->get_param_props(param_x_no
);
1263 handle
->dimensions
= 1;
1264 handle
->param_x_no
= param_x_no
;
1265 handle
->value_x
= to_x_pos(gui
->plugin
->get_param_value(param_x_no
));
1266 handle
->default_value_x
= to_x_pos(handle_x_props
.def_value
);
1268 stringstream handle_y_attribute
;
1269 handle_y_attribute
<< "handle" << i
+ 1 << "-y";
1270 const string
¶m_y_name
= attribs
[handle_y_attribute
.str()];
1271 if(param_y_name
!= "") {
1272 int param_y_no
= gui
->get_param_no_by_name(param_y_name
);
1273 const parameter_properties
&handle_y_props
= *gui
->plugin
->get_metadata_iface()->get_param_props(param_y_no
);
1274 handle
->dimensions
= 2;
1275 handle
->param_y_no
= param_y_no
;
1276 handle
->value_y
= to_y_pos(clg
, gui
->plugin
->get_param_value(param_y_no
));
1277 handle
->default_value_y
= to_y_pos(clg
, handle_y_props
.def_value
);
1279 handle
->param_y_no
= -1;
1282 stringstream handle_z_attribute
;
1283 handle_z_attribute
<< "handle" << i
+ 1 << "-z";
1284 const string
¶m_z_name
= attribs
[handle_z_attribute
.str()];
1285 if(param_z_name
!= "") {
1286 int param_z_no
= gui
->get_param_no_by_name(param_z_name
);
1287 const parameter_properties
&handle_z_props
= *gui
->plugin
->get_metadata_iface()->get_param_props(param_z_no
);
1288 handle
->dimensions
= 3;
1289 handle
->param_z_no
= param_z_no
;
1290 handle
->value_z
= handle_z_props
.to_01(gui
->plugin
->get_param_value(param_z_no
));
1291 handle
->default_value_z
= handle_z_props
.to_01(handle_z_props
.def_value
);
1293 handle
->param_z_no
= -1;
1296 stringstream label_attribute
;
1297 label_attribute
<< "label" << i
+ 1;
1298 string label
= attribs
[label_attribute
.str()];
1299 if (!label
.empty()) {
1300 handle
->label
= strdup(label
.c_str());
1303 stringstream active_attribute
;
1304 active_attribute
<< "active" << i
+ 1;
1305 const string
&active_name
= attribs
[active_attribute
.str()];
1306 if (active_name
!= "") {
1307 handle
->param_active_no
= gui
->get_param_no_by_name(active_name
);
1309 handle
->param_active_no
= -1;
1312 stringstream style_attribute
;
1313 style_attribute
<< "style" << i
+ 1;
1314 const string style
= style_attribute
.str();
1315 clg
->freq_handles
[i
].style
= get_int(style
.c_str(), 0);
1316 if(clg
->freq_handles
[i
].style
== 1 or clg
->freq_handles
[i
].style
== 4) {
1317 clg
->freq_handles
[i
].dimensions
= 1;
1319 handle
->data
= (gpointer
) this;
1321 g_signal_connect(G_OBJECT(widget
), "freqhandle-changed", G_CALLBACK(freqhandle_value_changed
), this);
1324 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-LineGraph");
1328 void line_graph_param_control::get()
1330 GtkWidget
*tw
= gtk_widget_get_toplevel(widget
);
1331 CalfLineGraph
*clg
= CALF_LINE_GRAPH(widget
);
1333 if (tw
&& GTK_WIDGET_TOPLEVEL(tw
) && widget
->window
)
1335 int ws
= gdk_window_get_state(widget
->window
);
1336 if (ws
& (GDK_WINDOW_STATE_WITHDRAWN
| GDK_WINDOW_STATE_ICONIFIED
))
1339 if(clg
->handle_grabbed
>= 0) {
1340 FreqHandle
*handle
= &clg
->freq_handles
[clg
->handle_grabbed
];
1341 if(handle
->dimensions
>= 2) {
1342 float value_y
= from_y_pos(clg
, handle
->value_y
);
1343 gui
->set_param_value(handle
->param_y_no
, value_y
, this);
1346 float value_x
= from_x_pos(handle
->value_x
);
1347 gui
->set_param_value(handle
->param_x_no
, value_x
, this);
1348 } else if(clg
->handle_hovered
>= 0) {
1349 FreqHandle
*handle
= &clg
->freq_handles
[clg
->handle_hovered
];
1351 if(handle
->dimensions
== 3) {
1352 const parameter_properties
&handle_z_props
= *gui
->plugin
->get_metadata_iface()->get_param_props(handle
->param_z_no
);
1353 float value_z
= handle_z_props
.from_01(handle
->value_z
);
1354 gui
->set_param_value(handle
->param_z_no
, value_z
, this);
1360 void line_graph_param_control::set()
1363 GtkWidget
*tw
= gtk_widget_get_toplevel(widget
);
1364 CalfLineGraph
*clg
= CALF_LINE_GRAPH(widget
);
1365 if (tw
&& GTK_WIDGET_TOPLEVEL(tw
) && widget
->window
)
1368 int ws
= gdk_window_get_state(widget
->window
);
1369 if (ws
& (GDK_WINDOW_STATE_WITHDRAWN
| GDK_WINDOW_STATE_ICONIFIED
))
1372 if (clg
->param_zoom
>= 0) {
1373 float _z
= gui
->plugin
->get_param_value(clg
->param_zoom
);
1374 if (_z
!= clg
->zoom
) {
1377 clg
->force_redraw
= true;
1381 if (clg
->param_offset
>= 0) {
1382 float _z
= gui
->plugin
->get_param_value(clg
->param_offset
);
1383 if (_z
!= clg
->offset
) {
1386 clg
->force_redraw
= true;
1390 for (int i
= 0; i
< clg
->freqhandles
; i
++) {
1391 FreqHandle
*handle
= &clg
->freq_handles
[i
];
1393 if (handle
->param_x_no
>= 0)
1395 float value_x
= gui
->plugin
->get_param_value(handle
->param_x_no
);
1396 handle
->value_x
= to_x_pos(value_x
);
1397 if (dsp::_sanitize(handle
->value_x
- handle
->last_value_x
)) {
1398 clg
->handle_redraw
= 1;
1400 handle
->last_value_x
= handle
->value_x
;
1401 if(handle
->dimensions
>= 2 && handle
->param_y_no
>= 0) {
1402 float value_y
= gui
->plugin
->get_param_value(handle
->param_y_no
);
1403 handle
->value_y
= to_y_pos(clg
, value_y
);
1404 if (dsp::_sanitize(handle
->value_y
- handle
->last_value_y
)) {
1405 clg
->handle_redraw
= 1;
1407 handle
->last_value_y
= handle
->value_y
;
1411 if(handle
->dimensions
== 3 && handle
->param_z_no
>= 0) {
1412 const parameter_properties
&handle_z_props
= *gui
->plugin
->get_metadata_iface()->get_param_props(handle
->param_z_no
);
1413 float value_z
= gui
->plugin
->get_param_value(handle
->param_z_no
);
1414 handle
->value_z
= handle_z_props
.to_01(value_z
);
1415 if (dsp::_sanitize(handle
->value_z
- handle
->last_value_z
)) {
1416 clg
->handle_redraw
= 1;
1418 handle
->last_value_z
= handle
->value_z
;
1420 bool _a
= handle
->active
;
1421 if(handle
->param_active_no
>= 0) {
1422 handle
->active
= bool(gui
->plugin
->get_param_value(handle
->param_active_no
));
1424 handle
->active
= true;
1426 if (handle
->active
!= _a
) {
1428 clg
->handle_redraw
= true;
1431 calf_line_graph_expose_request(widget
, force
);
1435 void line_graph_param_control::freqhandle_value_changed(GtkWidget
*widget
, gpointer p
)
1438 FreqHandle
*handle
= (FreqHandle
*)p
;
1439 param_control
*jhp
= (param_control
*)handle
->data
;
1444 line_graph_param_control::~line_graph_param_control()
1449 /******************************** Phase Graph ********************************/
1451 void phase_graph_param_control::on_idle()
1453 if (get_int("refresh", 0))
1457 GtkWidget
*phase_graph_param_control::create(plugin_gui
*_gui
, int _param_no
)
1460 param_no
= _param_no
;
1461 widget
= calf_phase_graph_new ();
1462 gtk_widget_set_name(GTK_WIDGET(widget
), "calf-phase");
1463 CalfPhaseGraph
*clg
= CALF_PHASE_GRAPH(widget
);
1464 widget
->requisition
.width
= get_int("size", 40);
1465 widget
->requisition
.height
= get_int("size", 40);
1466 clg
->source
= gui
->plugin
->get_phase_graph_iface();
1467 clg
->source_id
= param_no
;
1468 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-PhaseGraph");
1472 void phase_graph_param_control::set()
1475 GtkWidget
*tw
= gtk_widget_get_toplevel(widget
);
1476 if (tw
&& GTK_WIDGET_TOPLEVEL(tw
) && widget
->window
) {
1477 gtk_widget_queue_draw(widget
);
1481 phase_graph_param_control::~phase_graph_param_control()
1485 /******************************** List View ********************************/
1487 GtkWidget
*listview_param_control::create(plugin_gui
*_gui
, int _param_no
)
1490 param_no
= _param_no
;
1492 string key
= attribs
["key"];
1493 tmif
= gui
->plugin
->get_metadata_iface()->get_table_metadata_iface(key
.c_str());
1496 g_error("Missing table_metadata_iface for variable '%s'", key
.c_str());
1500 const table_column_info
*tci
= tmif
->get_table_columns();
1503 while (tci
[cols
].name
!= NULL
)
1506 GType
*p
= new GType
[cols
];
1507 for (int i
= 0; i
< cols
; i
++)
1508 p
[i
] = G_TYPE_STRING
;
1509 lstore
= gtk_list_store_newv(cols
, p
);
1510 if (tmif
->get_table_rows() != 0)
1511 set_rows(tmif
->get_table_rows());
1512 widget
= gtk_tree_view_new_with_model(GTK_TREE_MODEL(lstore
));
1514 tree
= GTK_TREE_VIEW (widget
);
1515 g_object_set (G_OBJECT (tree
), "enable-search", FALSE
, "rules-hint", TRUE
, "enable-grid-lines", TRUE
, NULL
);
1517 for (int i
= 0; i
< cols
; i
++)
1519 GtkCellRenderer
*cr
= NULL
;
1521 if (tci
[i
].type
== TCT_ENUM
) {
1522 cr
= gtk_cell_renderer_combo_new ();
1523 GtkListStore
*cls
= gtk_list_store_new(2, G_TYPE_INT
, G_TYPE_STRING
);
1524 for (int j
= 0; tci
[i
].values
[j
]; j
++)
1525 gtk_list_store_insert_with_values(cls
, NULL
, j
, 0, j
, 1, tci
[i
].values
[j
], -1);
1526 g_object_set(cr
, "model", cls
, "editable", TRUE
, "has-entry", FALSE
, "text-column", 1, "mode", GTK_CELL_RENDERER_MODE_EDITABLE
, NULL
);
1529 bool editable
= tci
[i
].type
!= TCT_LABEL
;
1530 cr
= gtk_cell_renderer_text_new ();
1532 g_object_set(cr
, "editable", TRUE
, "mode", GTK_CELL_RENDERER_MODE_EDITABLE
, NULL
);
1534 g_object_set_data (G_OBJECT(cr
), "column", (void *)&tci
[i
]);
1535 g_signal_connect (GTK_OBJECT (cr
), "edited", G_CALLBACK (on_edited
), (gpointer
)this);
1536 g_signal_connect (GTK_OBJECT (cr
), "editing-canceled", G_CALLBACK (on_editing_canceled
), (gpointer
)this);
1537 gtk_tree_view_insert_column_with_attributes(tree
, i
, tci
[i
].name
, cr
, "text", i
, NULL
);
1539 gtk_tree_view_set_headers_visible(tree
, TRUE
);
1540 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-ListView");
1544 void listview_param_control::set_rows(unsigned int needed_rows
)
1546 while(positions
.size() < needed_rows
)
1549 gtk_list_store_insert(lstore
, &iter
, positions
.size());
1550 for (int j
= 0; j
< cols
; j
++)
1552 gtk_list_store_set(lstore
, &iter
, j
, "", -1);
1554 positions
.push_back(iter
);
1558 void listview_param_control::send_configure(const char *key
, const char *value
)
1560 string orig_key
= attribs
["key"] + ":";
1561 bool is_rows
= false;
1562 int row
= -1, col
= -1;
1563 if (parse_table_key(key
, orig_key
.c_str(), is_rows
, row
, col
))
1565 if (is_rows
&& tmif
->get_table_rows() == 0)
1567 int rows
= atoi(value
);
1572 if (row
!= -1 && col
!= -1)
1574 int max_rows
= tmif
->get_table_rows();
1575 if (col
< 0 || col
>= cols
)
1577 g_warning("Invalid column %d in key %s", col
, key
);
1580 if (max_rows
&& (row
< 0 || row
>= max_rows
))
1582 g_warning("Invalid row %d in key %s, this is a fixed table with row count = %d", row
, key
, max_rows
);
1586 if (row
>= (int)positions
.size())
1589 gtk_list_store_set(lstore
, &positions
[row
], col
, value
, -1);
1595 void listview_param_control::on_edited(GtkCellRenderer
*renderer
, gchar
*path
, gchar
*new_text
, listview_param_control
*pThis
)
1597 const table_column_info
*tci
= pThis
->tmif
->get_table_columns();
1598 int column
= ((table_column_info
*)g_object_get_data(G_OBJECT(renderer
), "column")) - tci
;
1599 string key
= pThis
->attribs
["key"] + ":" + i2s(atoi(path
)) + "," + i2s(column
);
1601 const char *error_or_null
= pThis
->gui
->plugin
->configure(key
.c_str(), new_text
);
1603 error
= error_or_null
;
1605 if (error
.empty()) {
1606 pThis
->send_configure(key
.c_str(), new_text
);
1607 gtk_widget_grab_focus(pThis
->widget
);
1608 GtkTreePath
*gpath
= gtk_tree_path_new_from_string (path
);
1609 gtk_tree_view_set_cursor_on_cell (GTK_TREE_VIEW (pThis
->widget
), gpath
, NULL
, NULL
, FALSE
);
1610 gtk_tree_path_free (gpath
);
1614 GtkWidget
*dialog
= gtk_message_dialog_new(pThis
->gui
->window
->toplevel
, GTK_DIALOG_DESTROY_WITH_PARENT
, GTK_MESSAGE_ERROR
, GTK_BUTTONS_OK
,
1615 "%s", error
.c_str());
1616 gtk_dialog_run(GTK_DIALOG(dialog
));
1617 gtk_widget_destroy(dialog
);
1618 gtk_widget_grab_focus(pThis
->widget
);
1622 void listview_param_control::on_editing_canceled(GtkCellRenderer
*renderer
, listview_param_control
*pThis
)
1624 gtk_widget_grab_focus(pThis
->widget
);
1627 /******************************** GtkNotebook control ********************************/
1629 GtkWidget
*notebook_param_control::create(plugin_gui
*_gui
, int _param_no
)
1632 param_no
= _param_no
;
1633 //const parameter_properties &props = get_props();
1637 page
= gui
->plugin
->get_param_value(param_no
);
1638 GtkWidget
*nb
= calf_notebook_new();
1639 widget
= GTK_WIDGET(nb
);
1640 gtk_widget_set_name(GTK_WIDGET(nb
), "Calf-Notebook");
1641 gtk_notebook_set_current_page(GTK_NOTEBOOK(widget
), page
);
1644 void notebook_param_control::created()
1646 g_signal_connect (GTK_OBJECT (widget
), "switch-page", G_CALLBACK (notebook_page_changed
), (gpointer
)this);
1649 void notebook_param_control::get()
1652 gui
->set_param_value(param_no
, page
, this);
1654 void notebook_param_control::set()
1659 page
= (gint
)gui
->plugin
->get_param_value(param_no
);
1660 gtk_notebook_set_current_page(GTK_NOTEBOOK(widget
), page
);
1662 void notebook_param_control::add(control_base
*base
)
1664 gtk_notebook_append_page(GTK_NOTEBOOK(widget
), base
->widget
, gtk_label_new_with_mnemonic(base
->attribs
["page"].c_str()));
1666 void notebook_param_control::notebook_page_changed(GtkWidget
*widget
, GtkWidget
*page
, guint id
, gpointer user
)
1668 notebook_param_control
*jhp
= (notebook_param_control
*)user
;
1669 jhp
->page
= (int)id
;
1673 /******************************** GtkTable container ********************************/
1675 GtkWidget
*table_container::create(plugin_gui
*_gui
)
1677 require_int_attribute("rows");
1678 require_int_attribute("cols");
1679 int homog
= get_int("homogeneous", 0);
1680 int sx
= get_int("spacing-x", 2);
1681 int sy
= get_int("spacing-y", 2);
1682 GtkWidget
*table
= gtk_table_new(get_int("rows", 1), get_int("cols", 1), false);
1684 gtk_table_set_homogeneous(GTK_TABLE(table
), TRUE
);
1686 gtk_table_set_col_spacings(GTK_TABLE(table
), sx
);
1687 gtk_table_set_row_spacings(GTK_TABLE(table
), sy
);
1689 gtk_widget_set_name(GTK_WIDGET(table
), "Calf-Table");
1693 void table_container::add(control_base
*base
)
1695 base
->require_int_attribute("attach-x");
1696 base
->require_int_attribute("attach-y");
1697 int x
= base
->get_int("attach-x"), y
= base
->get_int("attach-y");
1698 int w
= base
->get_int("attach-w", 1), h
= base
->get_int("attach-h", 1);
1699 int shrinkx
= base
->get_int("shrink-x", 0);
1700 int shrinky
= base
->get_int("shrink-y", 0);
1701 int fillx
= (base
->get_int("fill-x", !shrinkx
) ? GTK_FILL
: 0) | (base
->get_int("expand-x", !shrinkx
) ? GTK_EXPAND
: 0) | (shrinkx
? GTK_SHRINK
: 0);
1702 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);
1703 int padx
= base
->get_int("pad-x", 2);
1704 int pady
= base
->get_int("pad-y", 2);
1705 gtk_table_attach(GTK_TABLE(widget
), base
->widget
, x
, x
+ w
, y
, y
+ h
, (GtkAttachOptions
)fillx
, (GtkAttachOptions
)filly
, padx
, pady
);
1708 /******************************** alignment container ********************************/
1710 GtkWidget
*alignment_container::create(plugin_gui
*_gui
)
1712 widget
= 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));
1713 gtk_widget_set_name(widget
, "Calf-Align");
1717 /******************************** GtkFrame container ********************************/
1719 GtkWidget
*frame_container::create(plugin_gui
*_gui
)
1721 widget
= calf_frame_new(attribs
["label"].c_str());
1722 gtk_widget_set_name(widget
, "Calf-Frame");
1726 /******************************** GtkBox type of containers ********************************/
1728 void box_container::add(control_base
*base
)
1730 gtk_container_add_with_properties(GTK_CONTAINER(widget
), base
->widget
, "expand", get_int("expand", 1), "fill", get_int("fill", 1), NULL
);
1733 /******************************** GtkHBox container ********************************/
1735 GtkWidget
*hbox_container::create(plugin_gui
*_gui
)
1737 widget
= gtk_hbox_new(get_int("homogeneous") >= 1, get_int("spacing", 2));
1738 gtk_widget_set_name(widget
, "Calf-HBox");
1742 /******************************** GtkVBox container ********************************/
1744 GtkWidget
*vbox_container::create(plugin_gui
*_gui
)
1746 widget
= gtk_vbox_new(get_int("homogeneous") >= 1, get_int("spacing", 2));
1747 gtk_widget_set_name(widget
, "Calf-VBox");
1751 /******************************** GtkNotebook container ********************************/
1753 GtkWidget
*scrolled_container::create(plugin_gui
*_gui
)
1755 GtkAdjustment
*horiz
= NULL
, *vert
= NULL
;
1756 int width
= get_int("width", 0), height
= get_int("height", 0);
1758 horiz
= GTK_ADJUSTMENT(gtk_adjustment_new(get_int("x", 0), 0, width
, get_int("step-x", 1), get_int("page-x", width
/ 10), 100));
1760 vert
= GTK_ADJUSTMENT(gtk_adjustment_new(get_int("y", 0), 0, width
, get_int("step-y", 1), get_int("page-y", height
/ 10), 10));
1761 widget
= gtk_scrolled_window_new(horiz
, vert
);
1762 gtk_widget_set_size_request(widget
, get_int("req-x", -1), get_int("req-y", -1));
1763 gtk_widget_set_name(widget
, "Calf-ScrolledWindow");
1767 void scrolled_container::add(control_base
*base
)
1769 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(widget
), base
->widget
);