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>
42 using namespace calf_plugins
;
43 using namespace calf_utils
;
46 #define SANITIZE(value) (std::abs(value) < small_value<float>()) ? 0.f : value
48 /******************************** control/container base class **********************/
50 void control_base::require_attribute(const char *name
)
52 if (attribs
.count(name
) == 0) {
53 g_error("Missing attribute '%s' in control '%s'", name
, control_name
.c_str());
57 void control_base::require_int_attribute(const char *name
)
59 require_attribute(name
);
60 if (attribs
[name
].empty() || attribs
[name
].find_first_not_of("0123456789") != string::npos
) {
61 g_error("Wrong data type on attribute '%s' in control '%s' (required integer)", name
, control_name
.c_str());
65 int control_base::get_int(const char *name
, int def_value
)
67 if (attribs
.count(name
) == 0)
69 const std::string
&v
= attribs
[name
];
70 if (v
.empty() || v
.find_first_not_of("-+0123456789") != string::npos
)
72 return atoi(v
.c_str());
75 float control_base::get_float(const char *name
, float def_value
)
77 if (attribs
.count(name
) == 0)
79 const std::string
&v
= attribs
[name
];
80 if (v
.empty() || v
.find_first_not_of("-+0123456789.") != string::npos
)
88 std::vector
<double> control_base::get_vector(const char *name
, std::string
&value
)
90 std::vector
<double> t
;
92 if (attribs
.count(name
)) {
93 value
= attribs
[name
];
96 string::size_type lpos
= value
.find_first_not_of(" ", 0);
97 string::size_type pos
= value
.find_first_of(" ", lpos
);
98 while (string::npos
!= pos
|| string::npos
!= lpos
) {
100 stringstream
stream(value
.substr(lpos
, pos
- lpos
).c_str());
103 lpos
= value
.find_first_not_of(" ", pos
);
104 pos
= value
.find_first_of(" ", lpos
);
109 void control_base::set_visibilty(bool state
)
112 gtk_widget_show(widget
);
114 gtk_widget_hide(widget
);
118 void control_base::set_std_properties()
120 if (widget
&& attribs
.find("widget-name") != attribs
.end())
122 string name
= attribs
["widget-name"];
123 gtk_widget_set_name(widget
, name
.c_str());
125 if (widget
&& GTK_IS_CONTAINER(widget
))
127 gtk_container_set_border_width(GTK_CONTAINER(widget
), get_int("border"));
131 static void on_control_destroy(GtkWidget
*w
, gpointer p
)
133 delete (control_base
*)p
;
136 void control_base::created()
138 set_std_properties();
139 g_signal_connect(GTK_OBJECT(widget
), "destroy", (GCallback
)on_control_destroy
, this);
142 /************************* param-associated control base class **************/
144 param_control::param_control()
149 old_displayed_value
= -1.f
;
153 GtkWidget
*param_control::create(plugin_gui
*_gui
)
155 if (attribs
.count("param"))
157 int pno
= _gui
->get_param_no_by_name(attribs
["param"]);
158 param_variable
= _gui
->plugin
->get_metadata_iface()->get_param_props(pno
)->short_name
;
159 return create(_gui
, pno
);
162 return create(_gui
, -1);
165 void param_control::hook_params()
167 if (param_no
!= -1) {
168 gui
->add_param_ctl(param_no
, this);
170 gui
->params
.push_back(this);
173 void param_control::created() {
174 control_base::created();
177 add_context_menu_handler();
180 param_control::~param_control()
183 gui
->remove_param_ctl(param_no
, this);
184 //if (GTK_IS_WIDGET(widget))
185 // gtk_widget_destroy(widget);
188 void param_control::add_context_menu_handler()
192 g_signal_connect(GTK_OBJECT(widget
), "button-press-event", (GCallback
)on_button_press_event
, this);
196 gboolean
param_control::on_button_press_event(GtkWidget
*widget
, GdkEventButton
*event
, void *user_data
)
198 param_control
*self
= (param_control
*)user_data
;
199 const parameter_properties
&props
= self
->get_props();
200 if (event
->button
== 3 && !(props
.flags
& PF_PROP_OUTPUT
))
202 self
->do_popup_menu();
205 else if (event
->button
== 2)
207 if (!strcmp(gtk_widget_get_name(widget
), "Calf-LineGraph")) {
208 CalfLineGraph
*clg
= CALF_LINE_GRAPH(widget
);
209 if (clg
->freqhandles
&& clg
->handle_hovered
>= 0) {
210 FreqHandle
* fh
= &clg
->freq_handles
[clg
->handle_hovered
];
211 self
->param_no
= fh
->param_x_no
;
215 self
->create_value_entry(widget
, event
->x_root
, event
->y_root
);
221 void param_control::do_popup_menu()
224 gui
->on_control_popup(this, param_no
);
227 void param_control::destroy_value_entry ()
229 // remove the window containing the entry
230 gtk_widget_destroy(GTK_WIDGET(entrywin
));
233 gboolean
param_control::value_entry_unfocus(GtkWidget
*widget
, GdkEventFocus
*event
, void *user_data
)
235 // destroy window if it looses focus
236 param_control
*self
= (param_control
*)user_data
;
237 self
->destroy_value_entry();
240 gboolean
param_control::value_entry_action(GtkEntry
*widget
, GdkEvent
*event
, void *user_data
)
242 // called when a key was hit, sorts out and treats RETURN and ESC
243 param_control
*self
= (param_control
*)user_data
;
244 const parameter_properties
&props
= self
->get_props();
245 GdkEventKey
*key
= (GdkEventKey
*)event
;
246 if(key
->keyval
== GDK_Escape
)
247 self
->destroy_value_entry();
248 else if (key
->keyval
== GDK_Return
) {
249 float val
= props
.string_to_value(gtk_entry_get_text(widget
));
250 self
->gui
->plugin
->set_param_value(self
->param_no
, val
);
252 self
->destroy_value_entry();
256 void param_control::create_value_entry(GtkWidget
*widget
, int x
, int y
)
259 // kill an existing entry window on re-trigger
260 destroy_value_entry();
267 const parameter_properties
&props
= get_props();
268 float value
= gui
->plugin
->get_param_value(param_no
);
270 // no chance for a menu, so we have to do everything by hand
271 entrywin
= gtk_window_new(GTK_WINDOW_TOPLEVEL
);
272 gtk_widget_set_name(GTK_WIDGET(entrywin
), "Calf-Value-Entry");
273 gtk_window_set_title (GTK_WINDOW(entrywin
), "Calf Value Entry");
274 gtk_window_set_resizable (GTK_WINDOW(entrywin
), FALSE
);
275 gtk_window_set_decorated (GTK_WINDOW(entrywin
), FALSE
);
276 gtk_window_set_skip_taskbar_hint (GTK_WINDOW(entrywin
), TRUE
);
277 gtk_window_set_skip_pager_hint (GTK_WINDOW(entrywin
), TRUE
);
278 gtk_window_set_transient_for (GTK_WINDOW(entrywin
), GTK_WINDOW (gui
->window
->toplevel
));
279 gtk_window_set_gravity(GTK_WINDOW(entrywin
), GDK_GRAVITY_CENTER
);
280 gtk_widget_set_events (GTK_WIDGET(entrywin
), GDK_FOCUS_CHANGE_MASK
);
281 g_signal_connect (G_OBJECT(entrywin
), "focus-out-event", G_CALLBACK (value_entry_unfocus
), this);
283 // create the text entry
284 GtkWidget
*entry
= gtk_entry_new();
285 gtk_widget_set_name(GTK_WIDGET(entry
), "Calf-Entry");
286 gtk_entry_set_width_chars(GTK_ENTRY(entry
), props
.get_char_count());
287 gtk_entry_set_text(GTK_ENTRY(entry
), props
.to_string(value
).c_str());
288 gtk_widget_add_events (entry
, GDK_KEY_PRESS_MASK
);
289 g_signal_connect (entry
, "key-press-event", (GCallback
)value_entry_action
, this);
291 // stitch together and show
292 gtk_container_add(GTK_CONTAINER (entrywin
), entry
);
293 gtk_widget_show_all(entrywin
);
294 gtk_window_move(GTK_WINDOW (entrywin
), x
, y
);
300 /******************************** Combo Box ********************************/
302 GtkWidget
*combo_box_param_control::create(plugin_gui
*_gui
, int _param_no
)
305 param_no
= _param_no
;
306 lstore
= gtk_list_store_new(2, G_TYPE_STRING
, G_TYPE_STRING
); // value, key
309 const parameter_properties
&props
= get_props();
310 widget
= calf_combobox_new ();
311 if (param_no
!= -1 && props
.choices
)
313 for (int j
= (int)props
.min
; j
<= (int)props
.max
; j
++)
314 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);
318 calf_combobox_set_arrow(CALF_COMBOBOX(widget
),
319 gui
->window
->environment
->get_image_factory()->get("combo_arrow"));
321 gtk_combo_box_set_model (GTK_COMBO_BOX(widget
), GTK_TREE_MODEL(lstore
));
322 g_signal_connect (GTK_OBJECT (widget
), "changed", G_CALLBACK (combo_value_changed
), (gpointer
)this);
323 gtk_widget_set_name(widget
, "Calf-Combobox");
327 void combo_box_param_control::set()
332 const parameter_properties
&props
= get_props();
333 gtk_combo_box_set_active (GTK_COMBO_BOX (widget
), (int)gui
->plugin
->get_param_value(param_no
) - (int)props
.min
);
337 void combo_box_param_control::get()
341 const parameter_properties
&props
= get_props();
342 gui
->set_param_value(param_no
, gtk_combo_box_get_active (GTK_COMBO_BOX(widget
)) + props
.min
, this);
346 void combo_box_param_control::combo_value_changed(GtkComboBox
*widget
, gpointer value
)
348 combo_box_param_control
*jhp
= (combo_box_param_control
*)value
;
351 if (jhp
->attribs
.count("setter-key"))
355 if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (jhp
->widget
), &iter
))
357 gtk_tree_model_get (GTK_TREE_MODEL (jhp
->lstore
), &iter
, 1, &key
, -1);
359 jhp
->gui
->plugin
->configure(jhp
->attribs
["setter-key"].c_str(), key
);
368 void combo_box_param_control::send_status(const char *key
, const char *value
)
370 if (attribs
.count("key") && key
== attribs
["key"])
372 if (value
== last_list
)
376 gtk_list_store_clear (lstore
);
378 std::string v
= value
;
381 while (pos
< v
.length()) {
382 size_t endpos
= v
.find("\n", pos
);
383 if (endpos
== string::npos
)
385 string line
= v
.substr(pos
, endpos
- pos
);
387 size_t tabpos
= line
.find('\t');
388 if (tabpos
== string::npos
)
391 key
= line
.substr(0, tabpos
);
392 label
= line
.substr(tabpos
+ 1);
395 gtk_list_store_insert_with_values (lstore
, >i
, i
, 0, label
.c_str(), 1, key
.c_str(), -1);
403 if (attribs
.count("current-key") && key
== attribs
["current-key"])
410 void combo_box_param_control::set_to_last_key()
412 map
<string
, GtkTreeIter
>::iterator i
= key2pos
.find(last_key
);
413 if (i
!= key2pos
.end())
415 gtk_combo_box_set_active_iter (GTK_COMBO_BOX (widget
), &i
->second
);
419 gtk_combo_box_set_active (GTK_COMBO_BOX (widget
), -1);
422 /******************************** Horizontal Fader ********************************/
425 scale_to_default (gpointer data
)
427 hscale_param_control
*jhp
= (hscale_param_control
*)data
;
428 const parameter_properties
&props
= jhp
->get_props();
429 gtk_range_set_value (GTK_RANGE (jhp
->widget
), props
.to_01(props
.def_value
));
435 scale_button_press (GtkWidget
*widget
, GdkEventKey
*event
, gpointer
*user_data
)
437 if (event
->type
== GDK_2BUTTON_PRESS
) {
438 // this actually creates a harmless race condition, but diving deep
439 // into gtk signal handling code wouldn't and the resulting complexity
440 // would not really be worth the effort
441 // The timeout is set high enough that most of the time the race
442 // will turn out in our/the users favor
443 g_timeout_add (200, (GSourceFunc
)scale_to_default
, user_data
);
450 GtkWidget
*hscale_param_control::create(plugin_gui
*_gui
, int _param_no
)
453 param_no
= _param_no
;
455 widget
= calf_fader_new(1, get_int("size", 2), 0, 1, get_props().get_increment());
457 g_signal_connect (GTK_OBJECT (widget
), "value-changed", G_CALLBACK (hscale_value_changed
), (gpointer
)this);
458 g_signal_connect (GTK_OBJECT (widget
), "format-value", G_CALLBACK (hscale_format_value
), (gpointer
)this);
459 g_signal_connect (GTK_OBJECT (widget
), "button-press-event", G_CALLBACK (scale_button_press
), (gpointer
)this);
461 if(get_int("inverted", 0) > 0) {
462 gtk_range_set_inverted(GTK_RANGE(widget
), TRUE
);
464 int size
= get_int("size", 2);
467 image_factory
*images
= gui
->window
->environment
->get_image_factory();
469 sprintf(iname
, "slider_%d_horiz", size
);
470 calf_fader_set_pixbuf(CALF_FADER(widget
), images
->get(iname
));
472 char *name
= g_strdup_printf("Calf-HScale%i", size
);
473 gtk_widget_set_name(GTK_WIDGET(widget
), name
);
474 gtk_widget_set_size_request (widget
, size
* 100, -1);
477 if (attribs
.count("width"))
478 gtk_widget_set_size_request (widget
, get_int("width", 200), -1);
479 if (attribs
.count("position")) {
480 string v
= attribs
["position"];
481 if (v
== "top") gtk_scale_set_value_pos(GTK_SCALE(widget
), GTK_POS_TOP
);
482 if (v
== "bottom") gtk_scale_set_value_pos(GTK_SCALE(widget
), GTK_POS_BOTTOM
);
483 if (v
== "left") gtk_scale_set_value_pos(GTK_SCALE(widget
), GTK_POS_LEFT
);
484 if (v
== "right") gtk_scale_set_value_pos(GTK_SCALE(widget
), GTK_POS_RIGHT
);
489 void hscale_param_control::set()
492 const parameter_properties
&props
= get_props();
493 gtk_range_set_value (GTK_RANGE (widget
), props
.to_01 (gui
->plugin
->get_param_value(param_no
)));
494 // hscale_value_changed (GTK_HSCALE (widget), (gpointer)this);
497 void hscale_param_control::get()
499 const parameter_properties
&props
= get_props();
500 float cvalue
= props
.from_01 (gtk_range_get_value (GTK_RANGE (widget
)));
501 gui
->set_param_value(param_no
, cvalue
, this);
504 void hscale_param_control::hscale_value_changed(GtkHScale
*widget
, gpointer value
)
506 hscale_param_control
*jhp
= (hscale_param_control
*)value
;
510 gchar
*hscale_param_control::hscale_format_value(GtkScale
*widget
, double arg1
, gpointer value
)
512 hscale_param_control
*jhp
= (hscale_param_control
*)value
;
513 const parameter_properties
&props
= jhp
->get_props();
514 float cvalue
= props
.from_01 (arg1
);
517 // return g_strdup_printf ("%s = %g", props.to_string (cvalue).c_str(), arg1);
518 return g_strdup (props
.to_string (cvalue
).c_str());
521 /******************************** Vertical Fader ********************************/
523 GtkWidget
*vscale_param_control::create(plugin_gui
*_gui
, int _param_no
)
526 param_no
= _param_no
;
527 widget
= calf_fader_new(0, get_int("size", 2), 0, 1, get_props().get_increment());
528 g_signal_connect (GTK_OBJECT (widget
), "value-changed", G_CALLBACK (vscale_value_changed
), (gpointer
)this);
529 g_signal_connect (GTK_OBJECT (widget
), "button-press-event", G_CALLBACK (scale_button_press
), (gpointer
)this);
531 gtk_scale_set_draw_value(GTK_SCALE(widget
), FALSE
);
533 if(get_int("inverted", 0) > 0) {
534 gtk_range_set_inverted(GTK_RANGE(widget
), TRUE
);
536 int size
= get_int("size", 2);
539 image_factory
*images
= gui
->window
->environment
->get_image_factory();
541 sprintf(iname
, "slider_%d_vert", size
);
542 calf_fader_set_pixbuf(CALF_FADER(widget
), images
->get(iname
));
544 char *name
= g_strdup_printf("Calf-VScale%i", size
);
545 gtk_widget_set_size_request (widget
, -1, size
* 100);
546 gtk_widget_set_name(GTK_WIDGET(widget
), name
);
549 if (attribs
.count("height"))
550 gtk_widget_set_size_request (widget
, -1, get_int("height", 200));
555 void vscale_param_control::set()
558 const parameter_properties
&props
= get_props();
559 gtk_range_set_value (GTK_RANGE (widget
), props
.to_01 (gui
->plugin
->get_param_value(param_no
)));
560 // vscale_value_changed (GTK_HSCALE (widget), (gpointer)this);
563 void vscale_param_control::get()
565 const parameter_properties
&props
= get_props();
566 float cvalue
= props
.from_01 (gtk_range_get_value (GTK_RANGE (widget
)));
567 gui
->set_param_value(param_no
, cvalue
, this);
570 void vscale_param_control::vscale_value_changed(GtkHScale
*widget
, gpointer value
)
572 vscale_param_control
*jhp
= (vscale_param_control
*)value
;
576 /******************************** Label ********************************/
578 GtkWidget
*label_param_control::create(plugin_gui
*_gui
, int _param_no
)
580 gui
= _gui
, param_no
= _param_no
;
582 if (param_no
!= -1 && !attribs
.count("text"))
583 text
= get_props().name
;
585 text
= attribs
["text"];
586 widget
= gtk_label_new(text
.c_str());
587 gtk_misc_set_alignment (GTK_MISC (widget
), get_float("align-x", 0.5), get_float("align-y", 0.5));
588 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-Label");
592 /******************************** Value ********************************/
594 GtkWidget
*value_param_control::create(plugin_gui
*_gui
, int _param_no
)
597 param_no
= _param_no
;
599 widget
= gtk_label_new ("");
602 const parameter_properties
&props
= get_props();
603 int width
= get_int("width", 0);
604 gtk_label_set_width_chars (GTK_LABEL (widget
),
605 width
? width
: props
.get_char_count());
609 require_attribute("key");
610 require_int_attribute("width");
611 param_variable
= attribs
["key"];
612 gtk_label_set_width_chars (GTK_LABEL (widget
), get_int("width"));
614 gtk_misc_set_alignment (GTK_MISC (widget
), get_float("align-x", 0.5), get_float("align-y", 0.5));
615 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-Value");
619 void value_param_control::set()
625 const parameter_properties
&props
= get_props();
626 string value
= props
.to_string(gui
->plugin
->get_param_value(param_no
));
628 if (value
== old_value
)
631 gtk_label_set_text (GTK_LABEL (widget
), value
.c_str());
634 void value_param_control::send_status(const char *key
, const char *value
)
636 if (key
== param_variable
)
638 gtk_label_set_text (GTK_LABEL (widget
), value
);
642 /******************************** VU Meter ********************************/
644 GtkWidget
*vumeter_param_control::create(plugin_gui
*_gui
, int _param_no
)
646 gui
= _gui
, param_no
= _param_no
;
647 // const parameter_properties &props = get_props();
648 widget
= calf_vumeter_new ();
649 CalfVUMeter
*vu
= CALF_VUMETER(widget
);
650 gtk_widget_set_name(GTK_WIDGET(widget
), "calf-vumeter");
651 calf_vumeter_set_mode (vu
, (CalfVUMeterMode
)get_int("mode", 0));
652 vu
->vumeter_hold
= get_float("hold", 0);
653 vu
->vumeter_falloff
= get_float("falloff", 0.f
);
654 vu
->vumeter_width
= get_int("width", 80);
655 vu
->vumeter_height
= get_int("height", 18);
656 vu
->vumeter_position
= get_int("position", 0);
657 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-VUMeter");
661 void vumeter_param_control::set()
664 // const parameter_properties &props = get_props();
665 calf_vumeter_set_value (CALF_VUMETER (widget
), gui
->plugin
->get_param_value(param_no
));
670 GtkWidget
*led_param_control::create(plugin_gui
*_gui
, int _param_no
)
672 gui
= _gui
, param_no
= _param_no
;
673 // const parameter_properties &props = get_props();
674 widget
= calf_led_new ();
675 gtk_widget_set_name(GTK_WIDGET(widget
), "calf-led");
676 CALF_LED(widget
)->led_mode
= get_int("mode", 0);
677 CALF_LED(widget
)->size
= get_int("size", 1);
678 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-LED");
682 void led_param_control::set()
685 // const parameter_properties &props = get_props();
686 calf_led_set_value (CALF_LED (widget
), gui
->plugin
->get_param_value(param_no
));
691 GtkWidget
*tube_param_control::create(plugin_gui
*_gui
, int _param_no
)
693 gui
= _gui
, param_no
= _param_no
;
694 // const parameter_properties &props = get_props();
695 GtkWidget
*widget
= calf_tube_new ();
696 CalfTube
*tube
= CALF_TUBE(widget
);
697 gtk_widget_set_name(widget
, "calf-tube");
698 tube
->size
= get_int("size", 2);
699 tube
->direction
= get_int("direction", 2);
700 gtk_widget_set_name(widget
, "Calf-Tube");
704 void tube_param_control::set()
707 // const parameter_properties &props = get_props();
708 calf_tube_set_value (CALF_TUBE (widget
), gui
->plugin
->get_param_value(param_no
));
711 /******************************** Check Box ********************************/
713 GtkWidget
*check_param_control::create(plugin_gui
*_gui
, int _param_no
)
716 param_no
= _param_no
;
718 widget
= gtk_check_button_new ();
719 g_signal_connect (GTK_OBJECT (widget
), "toggled", G_CALLBACK (check_value_changed
), (gpointer
)this);
720 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-Checkbox");
724 void check_param_control::check_value_changed(GtkCheckButton
*widget
, gpointer value
)
726 param_control
*jhp
= (param_control
*)value
;
730 void check_param_control::get()
732 const parameter_properties
&props
= get_props();
733 gui
->set_param_value(param_no
, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widget
)) + props
.min
, this);
736 void check_param_control::set()
739 const parameter_properties
&props
= get_props();
740 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget
), (int)gui
->plugin
->get_param_value(param_no
) - (int)props
.min
);
743 /******************************** Radio Button ********************************/
745 GtkWidget
*radio_param_control::create(plugin_gui
*_gui
, int _param_no
)
748 param_no
= _param_no
;
749 require_attribute("value");
751 string value_name
= attribs
["value"];
752 const parameter_properties
&props
= get_props();
753 if (props
.choices
&& (value_name
< "0" || value_name
> "9"))
755 for (int i
= 0; props
.choices
[i
]; i
++)
757 if (value_name
== props
.choices
[i
])
759 value
= i
+ (int)props
.min
;
765 value
= get_int("value");
767 if (attribs
.count("label"))
768 widget
= gtk_radio_button_new_with_label (gui
->get_radio_group(param_no
), attribs
["label"].c_str());
770 widget
= gtk_radio_button_new_with_label (gui
->get_radio_group(param_no
), props
.choices
[value
- (int)props
.min
]);
771 gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (widget
), FALSE
);
773 gui
->set_radio_group(param_no
, gtk_radio_button_get_group (GTK_RADIO_BUTTON (widget
)));
774 g_signal_connect (GTK_OBJECT (widget
), "clicked", G_CALLBACK (radio_clicked
), (gpointer
)this);
775 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-RadioButton");
779 void radio_param_control::radio_clicked(GtkRadioButton
*widget
, gpointer value
)
781 param_control
*jhp
= (param_control
*)value
;
785 void radio_param_control::get()
787 // const parameter_properties &props = get_props();
788 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget
)))
789 gui
->set_param_value(param_no
, value
, this);
792 void radio_param_control::set()
795 const parameter_properties
&props
= get_props();
796 float pv
= gui
->plugin
->get_param_value(param_no
);
797 if (fabs(value
-pv
) < 0.5)
798 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget
), value
== ((int)gui
->plugin
->get_param_value(param_no
) - (int)props
.min
));
801 /******************************** Spin Button ********************************/
803 GtkWidget
*spin_param_control::create(plugin_gui
*_gui
, int _param_no
)
806 param_no
= _param_no
;
808 const parameter_properties
&props
= get_props();
810 widget
= gtk_spin_button_new_with_range (props
.min
, props
.max
, (props
.max
- props
.min
) / (props
.step
- 1));
812 widget
= gtk_spin_button_new_with_range (props
.min
, props
.max
, props
.step
);
814 widget
= gtk_spin_button_new_with_range (props
.min
, props
.max
, 1);
815 gtk_spin_button_set_digits (GTK_SPIN_BUTTON(widget
), get_int("digits", 0));
816 g_signal_connect (GTK_OBJECT (widget
), "value-changed", G_CALLBACK (value_changed
), (gpointer
)this);
817 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-SpinButton");
821 void spin_param_control::value_changed(GtkSpinButton
*widget
, gpointer value
)
823 param_control
*jhp
= (param_control
*)value
;
827 void spin_param_control::get()
829 // const parameter_properties &props = get_props();
830 gui
->set_param_value(param_no
, gtk_spin_button_get_value_as_float (GTK_SPIN_BUTTON (widget
)), this);
833 void spin_param_control::set()
836 // const parameter_properties &props = get_props();
837 gtk_spin_button_set_value (GTK_SPIN_BUTTON (widget
), gui
->plugin
->get_param_value(param_no
));
840 /******************************** Button ********************************/
842 GtkWidget
*button_param_control::create(plugin_gui
*_gui
, int _param_no
)
845 param_no
= _param_no
;
846 widget
= calf_button_new ((gchar
*)get_props().name
);
847 g_signal_connect (GTK_OBJECT (widget
), "pressed", G_CALLBACK (button_clicked
), (gpointer
)this);
848 g_signal_connect (GTK_OBJECT (widget
), "released", G_CALLBACK (button_clicked
), (gpointer
)this);
849 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-Button");
853 void button_param_control::button_clicked(GtkButton
*widget
, gpointer value
)
855 param_control
*jhp
= (param_control
*)value
;
859 void button_param_control::get()
861 const parameter_properties
&props
= get_props();
862 gui
->set_param_value(param_no
, gtk_widget_get_state(widget
) == GTK_STATE_ACTIVE
? props
.max
: props
.min
, this);
865 void button_param_control::set()
868 const parameter_properties
&props
= get_props();
869 if (gui
->plugin
->get_param_value(param_no
) - props
.min
>= 0.5)
870 gtk_button_clicked (GTK_BUTTON (widget
));
873 /******************************** Knob ********************************/
875 GtkWidget
*knob_param_control::create(plugin_gui
*_gui
, int _param_no
)
878 param_no
= _param_no
;
879 const parameter_properties
&props
= get_props();
880 widget
= calf_knob_new();
881 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-Knob");
882 CalfKnob
* knob
= CALF_KNOB(widget
);
884 float increment
= props
.get_increment();
885 gtk_range_get_adjustment(GTK_RANGE(widget
))->step_increment
= increment
;
887 knob
->default_value
= props
.to_01(props
.def_value
);
888 knob
->type
= get_int("type");
889 calf_knob_set_size(knob
, get_int("size", 2));
893 sprintf(imgname
, "knob_%d", get_int("size", 2));
894 calf_knob_set_pixbuf(knob
, gui
->window
->environment
->get_image_factory()->get(imgname
));
897 std::ostringstream ticks_
;
898 //std::string str = ticks.str();
899 double min
= double(props
.min
);
900 double max
= double(props
.max
);
901 switch (knob
->type
) {
903 case 0: ticks_
<< min
<< " " << max
; break;
904 case 1: ticks_
<< min
<< " " << props
.from_01(0.5) << " " << max
; break;
905 case 2: ticks_
<< min
<< " " << max
; break;
906 case 3: ticks_
<< min
<< " " << props
.from_01(0.25) << " " << props
.from_01(0.5) << " " << props
.from_01(0.75) << " " << max
; break;
908 std::string ticks
= ticks_
.str();
909 vector
<double> t
= get_vector("ticks", ticks
);
910 std::sort(t
.begin(), t
.end());
911 for (unsigned int i
= 0; i
< t
.size(); i
++)
912 t
[i
] = props
.to_01(t
[i
]);
914 g_signal_connect(GTK_OBJECT(widget
), "value-changed", G_CALLBACK(knob_value_changed
), (gpointer
)this);
918 void knob_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 knob_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 knob_param_control::knob_value_changed(GtkWidget
*widget
, gpointer value
)
934 param_control
*jhp
= (param_control
*)value
;
938 /******************************** Toggle Button ********************************/
940 GtkWidget
*toggle_param_control::create(plugin_gui
*_gui
, int _param_no
)
943 param_no
= _param_no
;
944 widget
= calf_toggle_new ();
945 CalfToggle
* toggle
= CALF_TOGGLE(widget
);
946 calf_toggle_set_size(toggle
, get_int("size", 2));
949 image_factory
*images
= gui
->window
->environment
->get_image_factory();
951 if (attribs
.count("icon") != 0) {
952 sprintf(imgname
, "toggle_%d_%s", get_int("size", 2), attribs
["icon"].c_str());
953 if (!images
->available(imgname
))
954 sprintf(imgname
, "toggle_%d", get_int("size", 2));
956 sprintf(imgname
, "toggle_%d", get_int("size", 2));
957 calf_toggle_set_pixbuf(toggle
, images
->get(imgname
));
959 g_signal_connect (GTK_OBJECT (widget
), "value-changed", G_CALLBACK (toggle_value_changed
), (gpointer
)this);
960 //gtk_widget_set_name(GTK_WIDGET(widget), "Calf-ToggleButton");
964 void toggle_param_control::get()
966 const parameter_properties
&props
= get_props();
967 float value
= props
.from_01(gtk_range_get_value(GTK_RANGE(widget
)));
968 gui
->set_param_value(param_no
, value
, this);
971 void toggle_param_control::set()
974 const parameter_properties
&props
= get_props();
975 gtk_range_set_value(GTK_RANGE(widget
), props
.to_01 (gui
->plugin
->get_param_value(param_no
)));
978 void toggle_param_control::toggle_value_changed(GtkWidget
*widget
, gpointer value
)
980 param_control
*jhp
= (param_control
*)value
;
984 /******************************** Tap Button ********************************/
986 GtkWidget
*tap_button_param_control::create(plugin_gui
*_gui
, int _param_no
)
989 param_no
= _param_no
;
994 widget
= calf_tap_button_new ();
996 calf_tap_button_set_pixbufs(CALF_TAP_BUTTON(widget
),
997 gui
->window
->environment
->get_image_factory()->get("tap_inactive"),
998 gui
->window
->environment
->get_image_factory()->get("tap_prelight"),
999 gui
->window
->environment
->get_image_factory()->get("tap_active"));
1000 //CALF_TAP(widget)->size = get_int("size", 2);
1001 g_signal_connect (GTK_OBJECT (widget
), "button-press-event", G_CALLBACK (tap_button_pressed
), (gpointer
)this);
1002 g_signal_connect (GTK_OBJECT (widget
), "released", G_CALLBACK (tap_button_released
), (gpointer
)this);
1003 g_signal_connect (GTK_OBJECT (widget
), "leave", G_CALLBACK (tap_button_released
), (gpointer
)this);
1004 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-TapButton");
1008 void tap_button_param_control::get()
1010 gui
->set_param_value(param_no
, value
, this);
1013 void tap_button_param_control::set()
1018 gboolean
tap_button_param_control::tap_button_pressed(GtkWidget
*widget
, GdkEventButton
*event
, gpointer value
)
1020 tap_button_param_control
*ctl
= (tap_button_param_control
*)value
;
1021 CalfTapButton
*tap
= CALF_TAP_BUTTON(widget
);
1024 if (event
->type
== GDK_BUTTON_PRESS
and event
->button
== 1) {
1027 if(ctl
->last_time
) {
1029 ctl
->avg_value
= (ctl
->avg_value
* 3 + (time
- ctl
->last_time
)) / 4.f
;
1031 ctl
->avg_value
= time
- ctl
->last_time
;
1032 ctl
->value
= 60.f
/ (float)(ctl
->avg_value
/ 1000.f
);
1034 if (ctl
->value
> 30 and ctl
->value
< 300)
1037 ctl
->last_time
= time
;
1039 gtk_timeout_remove(ctl
->timer
);
1040 ctl
->timer
= gtk_timeout_add(2000, (GtkFunction
)tap_button_stop_waiting
, (gpointer
)ctl
);
1041 gtk_widget_queue_draw(widget
);
1045 void tap_button_param_control::tap_button_stop_waiting(gpointer data
)
1047 tap_button_param_control
*ctl
= (tap_button_param_control
*)data
;
1051 CALF_TAP_BUTTON(ctl
->widget
)->state
= 0;
1052 gtk_widget_queue_draw(ctl
->widget
);
1053 gtk_timeout_remove(ctl
->timer
);
1055 gtk_widget_queue_draw(ctl
->widget
);
1058 gboolean
tap_button_param_control::tap_button_released(GtkWidget
*widget
, gpointer value
)
1060 tap_button_param_control
*ctl
= (tap_button_param_control
*)value
;
1061 CalfTapButton
*tap
= CALF_TAP_BUTTON(widget
);
1062 tap
->state
= ctl
->last_time
? 1 : 0;
1063 gtk_widget_queue_draw(widget
);
1067 /******************************** Keyboard ********************************/
1069 GtkWidget
*keyboard_param_control::create(plugin_gui
*_gui
, int _param_no
)
1072 param_no
= _param_no
;
1073 // const parameter_properties &props = get_props();
1075 widget
= calf_keyboard_new();
1076 kb
= CALF_KEYBOARD(widget
);
1077 kb
->nkeys
= get_int("octaves", 4) * 7 + 1;
1078 kb
->sink
= new CalfKeyboard::EventAdapter
;
1079 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-Keyboard");
1083 /******************************** Curve ********************************/
1085 struct curve_param_control_callback
: public CalfCurve::EventAdapter
1087 curve_param_control
*ctl
;
1089 curve_param_control_callback(curve_param_control
*_ctl
)
1092 virtual void curve_changed(CalfCurve
*src
, const CalfCurve::point_vector
&data
) {
1094 ss
<< data
.size() << endl
;
1095 for (size_t i
= 0; i
< data
.size(); i
++)
1096 ss
<< data
[i
].first
<< " " << data
[i
].second
<< endl
;
1097 ctl
->gui
->plugin
->configure(ctl
->attribs
["key"].c_str(), ss
.str().c_str());
1099 virtual void clip(CalfCurve
*src
, int pt
, float &x
, float &y
, bool &hide
)
1101 // int gridpt = floor(x * 71 * 2);
1102 // clip to the middle of the nearest white key
1103 x
= (floor(x
* 71) + 0.5)/ 71.0;
1107 GtkWidget
*curve_param_control::create(plugin_gui
*_gui
, int _param_no
)
1110 param_no
= _param_no
;
1111 require_attribute("key");
1113 widget
= calf_curve_new(get_int("maxpoints", -1));
1114 curve
= CALF_CURVE(widget
);
1115 curve
->sink
= new curve_param_control_callback(this);
1116 // gtk_curve_set_curve_type(curve, GTK_CURVE_TYPE_LINEAR);
1117 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-Curve");
1121 void curve_param_control::send_configure(const char *key
, const char *value
)
1123 // cout << "send conf " << key << endl;
1124 if (attribs
["key"] == key
)
1126 stringstream
ss(value
);
1127 CalfCurve::point_vector pts
;
1130 unsigned int npoints
= 0;
1134 for (i
= 0; i
< npoints
&& i
< curve
->point_limit
; i
++)
1137 pts
.push_back(CalfCurve::point(x
, y
));
1139 calf_curve_set_points(widget
, pts
);
1144 /******************************** Meter Scale ********************************/
1146 GtkWidget
*meter_scale_param_control::create(plugin_gui
*_gui
, int _param_no
)
1149 param_no
= _param_no
;
1150 widget
= calf_meter_scale_new ();
1151 CalfMeterScale
*ms
= CALF_METER_SCALE(widget
);
1152 gtk_widget_set_name(widget
, "Calf-MeterScale");
1153 string str
= "0 0.5 1";
1154 ms
->marker
= get_vector("marker", str
);
1155 ms
->mode
= (CalfVUMeterMode
)get_int("mode", 0);
1156 ms
->position
= get_int("position", 0);
1157 ms
->dots
= get_int("dots", 0);
1161 /******************************** Entry ********************************/
1163 GtkWidget
*entry_param_control::create(plugin_gui
*_gui
, int _param_no
)
1166 param_no
= _param_no
;
1167 require_attribute("key");
1169 widget
= gtk_entry_new();
1170 entry
= GTK_ENTRY(widget
);
1171 g_signal_connect(GTK_OBJECT(widget
), "changed", G_CALLBACK(entry_value_changed
), (gpointer
)this);
1172 gtk_editable_set_editable(GTK_EDITABLE(entry
), get_int("editable", 1));
1173 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-Entry");
1177 void entry_param_control::send_configure(const char *key
, const char *value
)
1179 // cout << "send conf " << key << endl;
1180 if (attribs
["key"] == key
)
1182 gtk_entry_set_text(entry
, value
);
1186 void entry_param_control::entry_value_changed(GtkWidget
*widget
, gpointer value
)
1188 entry_param_control
*ctl
= (entry_param_control
*)value
;
1189 ctl
->gui
->plugin
->configure(ctl
->attribs
["key"].c_str(), gtk_entry_get_text(ctl
->entry
));
1192 /******************************** File Chooser ********************************/
1194 GtkWidget
*filechooser_param_control::create(plugin_gui
*_gui
, int _param_no
)
1197 param_no
= _param_no
;
1198 require_attribute("key");
1199 require_attribute("title");
1201 widget
= gtk_file_chooser_button_new(attribs
["title"].c_str(), GTK_FILE_CHOOSER_ACTION_OPEN
);
1202 filechooser
= GTK_FILE_CHOOSER_BUTTON(widget
);
1203 // XXXKF this is GTK+ 2.12 function, does any replacement exist?
1204 // MS: switched from g_signal_connect to g_signal_connect for better emission of signals
1205 g_signal_connect(GTK_OBJECT(widget
), "file-set", G_CALLBACK(filechooser_value_changed
), (gpointer
)this);
1206 if (attribs
.count("width"))
1207 gtk_widget_set_size_request (widget
, get_int("width", 200), -1);
1208 if (attribs
.count("width_chars"))
1209 gtk_file_chooser_button_set_width_chars (filechooser
, get_int("width_chars"));
1210 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-FileButton");
1214 void filechooser_param_control::send_configure(const char *key
, const char *value
)
1216 // cout << "send conf " << key << endl;
1217 if (attribs
["key"] == key
)
1219 gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(filechooser
), value
);
1223 void filechooser_param_control::filechooser_value_changed(GtkWidget
*widget
, gpointer value
)
1225 filechooser_param_control
*ctl
= (filechooser_param_control
*)value
;
1226 const char *filename
= gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(ctl
->filechooser
));
1228 ctl
->gui
->plugin
->configure(ctl
->attribs
["key"].c_str(), filename
);
1231 /******************************** Line Graph ********************************/
1233 void line_graph_param_control::on_idle()
1235 if (get_int("refresh", 0))
1239 static float to_x_pos(float freq
)
1241 return log(freq
/ 20.0) / log(1000);
1244 static float from_x_pos(float pos
)
1246 float a
= pos
* 3.0;
1247 float b
= powf(10.0, a
);
1252 static float to_y_pos(CalfLineGraph
*lg
, float gain
)
1254 //log(gain) * (1.0 / log(32));
1255 return 0.5 - dB_grid(gain
, 128 * lg
->zoom
, lg
->offset
) / 2.0;
1258 static float from_y_pos(CalfLineGraph
*lg
, float pos
)
1260 float gain
= powf(128.0 * lg
->zoom
, (0.5 - pos
) * 2.0 - lg
->offset
);
1264 GtkWidget
*line_graph_param_control::create(plugin_gui
*a_gui
, int a_param_no
)
1267 param_no
= a_param_no
;
1268 //last_generation = -1;
1270 widget
= calf_line_graph_new ();
1272 CalfLineGraph
*clg
= CALF_LINE_GRAPH(widget
);
1273 widget
->requisition
.width
= get_int("width", 40);
1274 widget
->requisition
.height
= get_int("height", 40);
1276 calf_line_graph_set_square(clg
, get_int("square", 0));
1278 clg
->source
= gui
->plugin
->get_line_graph_iface();
1279 clg
->source_id
= param_no
;
1280 clg
->fade
= get_float("fade", 1.0);
1281 clg
->mode
= get_int("mode", 0);
1282 clg
->use_crosshairs
= get_int("crosshairs", 0);
1283 clg
->freqhandles
= get_int("freqhandles", 0);
1284 clg
->enforce_handle_order
= get_int("enforce-handle-order", 0);
1285 clg
->min_handle_distance
= get_float("min-handle-distance", 0.01);
1287 const string
&zoom_name
= attribs
["zoom"];
1288 if (zoom_name
!= "")
1289 clg
->param_zoom
= gui
->get_param_no_by_name(zoom_name
);
1291 const string
&offset_name
= attribs
["offset"];
1292 if (offset_name
!= "")
1293 clg
->param_offset
= gui
->get_param_no_by_name(offset_name
);
1295 if (clg
->freqhandles
> 0)
1297 for(int i
= 0; i
< clg
->freqhandles
; i
++)
1299 FreqHandle
*handle
= &clg
->freq_handles
[i
];
1301 stringstream handle_x_attribute
;
1302 handle_x_attribute
<< "handle" << i
+ 1 << "-x";
1303 const string
¶m_x_name
= attribs
[handle_x_attribute
.str()];
1304 if(param_x_name
== "")
1307 int param_x_no
= gui
->get_param_no_by_name(param_x_name
);
1308 const parameter_properties
&handle_x_props
= *gui
->plugin
->get_metadata_iface()->get_param_props(param_x_no
);
1309 handle
->dimensions
= 1;
1310 handle
->param_x_no
= param_x_no
;
1311 handle
->value_x
= to_x_pos(gui
->plugin
->get_param_value(param_x_no
));
1312 handle
->default_value_x
= to_x_pos(handle_x_props
.def_value
);
1314 stringstream handle_y_attribute
;
1315 handle_y_attribute
<< "handle" << i
+ 1 << "-y";
1316 const string
¶m_y_name
= attribs
[handle_y_attribute
.str()];
1317 if(param_y_name
!= "") {
1318 int param_y_no
= gui
->get_param_no_by_name(param_y_name
);
1319 const parameter_properties
&handle_y_props
= *gui
->plugin
->get_metadata_iface()->get_param_props(param_y_no
);
1320 handle
->dimensions
= 2;
1321 handle
->param_y_no
= param_y_no
;
1322 handle
->value_y
= to_y_pos(clg
, gui
->plugin
->get_param_value(param_y_no
));
1323 handle
->default_value_y
= to_y_pos(clg
, handle_y_props
.def_value
);
1325 handle
->param_y_no
= -1;
1328 stringstream handle_z_attribute
;
1329 handle_z_attribute
<< "handle" << i
+ 1 << "-z";
1330 const string
¶m_z_name
= attribs
[handle_z_attribute
.str()];
1331 if(param_z_name
!= "") {
1332 int param_z_no
= gui
->get_param_no_by_name(param_z_name
);
1333 const parameter_properties
&handle_z_props
= *gui
->plugin
->get_metadata_iface()->get_param_props(param_z_no
);
1334 handle
->dimensions
= 3;
1335 handle
->param_z_no
= param_z_no
;
1336 handle
->value_z
= handle_z_props
.to_01(gui
->plugin
->get_param_value(param_z_no
));
1337 handle
->default_value_z
= handle_z_props
.to_01(handle_z_props
.def_value
);
1339 handle
->param_z_no
= -1;
1342 stringstream label_attribute
;
1343 label_attribute
<< "label" << i
+ 1;
1344 string label
= attribs
[label_attribute
.str()];
1345 if (!label
.empty()) {
1346 handle
->label
= strdup(label
.c_str());
1349 stringstream active_attribute
;
1350 active_attribute
<< "active" << i
+ 1;
1351 const string
&active_name
= attribs
[active_attribute
.str()];
1352 if (active_name
!= "") {
1353 handle
->param_active_no
= gui
->get_param_no_by_name(active_name
);
1355 handle
->param_active_no
= -1;
1358 stringstream style_attribute
;
1359 style_attribute
<< "style" << i
+ 1;
1360 const string style
= style_attribute
.str();
1361 clg
->freq_handles
[i
].style
= get_int(style
.c_str(), 0);
1362 if(clg
->freq_handles
[i
].style
== 1 or clg
->freq_handles
[i
].style
== 4) {
1363 clg
->freq_handles
[i
].dimensions
= 1;
1365 handle
->data
= (gpointer
) this;
1367 g_signal_connect(G_OBJECT(widget
), "freqhandle-changed", G_CALLBACK(freqhandle_value_changed
), this);
1370 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-LineGraph");
1374 void line_graph_param_control::get()
1376 GtkWidget
*tw
= gtk_widget_get_toplevel(widget
);
1377 CalfLineGraph
*clg
= CALF_LINE_GRAPH(widget
);
1379 if (tw
&& GTK_WIDGET_TOPLEVEL(tw
) && widget
->window
)
1381 int ws
= gdk_window_get_state(widget
->window
);
1382 if (ws
& (GDK_WINDOW_STATE_WITHDRAWN
| GDK_WINDOW_STATE_ICONIFIED
))
1385 if(clg
->handle_grabbed
>= 0) {
1386 FreqHandle
*handle
= &clg
->freq_handles
[clg
->handle_grabbed
];
1387 if(handle
->dimensions
>= 2) {
1388 float value_y
= from_y_pos(clg
, handle
->value_y
);
1389 gui
->set_param_value(handle
->param_y_no
, value_y
, this);
1392 float value_x
= from_x_pos(handle
->value_x
);
1393 gui
->set_param_value(handle
->param_x_no
, value_x
, this);
1394 } else if(clg
->handle_hovered
>= 0) {
1395 FreqHandle
*handle
= &clg
->freq_handles
[clg
->handle_hovered
];
1397 if(handle
->dimensions
== 3) {
1398 const parameter_properties
&handle_z_props
= *gui
->plugin
->get_metadata_iface()->get_param_props(handle
->param_z_no
);
1399 float value_z
= handle_z_props
.from_01(handle
->value_z
);
1400 gui
->set_param_value(handle
->param_z_no
, value_z
, this);
1406 void line_graph_param_control::set()
1409 GtkWidget
*tw
= gtk_widget_get_toplevel(widget
);
1410 CalfLineGraph
*clg
= CALF_LINE_GRAPH(widget
);
1411 if (tw
&& GTK_WIDGET_TOPLEVEL(tw
) && widget
->window
)
1414 int ws
= gdk_window_get_state(widget
->window
);
1415 if (ws
& (GDK_WINDOW_STATE_WITHDRAWN
| GDK_WINDOW_STATE_ICONIFIED
))
1418 if (clg
->param_zoom
>= 0) {
1419 float _z
= gui
->plugin
->get_param_value(clg
->param_zoom
);
1420 if (_z
!= clg
->zoom
) {
1423 clg
->force_redraw
= true;
1427 if (clg
->param_offset
>= 0) {
1428 float _z
= gui
->plugin
->get_param_value(clg
->param_offset
);
1429 if (_z
!= clg
->offset
) {
1432 clg
->force_redraw
= true;
1436 for (int i
= 0; i
< clg
->freqhandles
; i
++) {
1437 FreqHandle
*handle
= &clg
->freq_handles
[i
];
1439 if (handle
->param_x_no
>= 0)
1441 float value_x
= gui
->plugin
->get_param_value(handle
->param_x_no
);
1442 handle
->value_x
= to_x_pos(value_x
);
1443 if (dsp::_sanitize(handle
->value_x
- handle
->last_value_x
)) {
1444 clg
->handle_redraw
= 1;
1446 handle
->last_value_x
= handle
->value_x
;
1447 if(handle
->dimensions
>= 2 && handle
->param_y_no
>= 0) {
1448 float value_y
= gui
->plugin
->get_param_value(handle
->param_y_no
);
1449 handle
->value_y
= to_y_pos(clg
, value_y
);
1450 if (dsp::_sanitize(handle
->value_y
- handle
->last_value_y
)) {
1451 clg
->handle_redraw
= 1;
1453 handle
->last_value_y
= handle
->value_y
;
1457 if(handle
->dimensions
== 3 && handle
->param_z_no
>= 0) {
1458 const parameter_properties
&handle_z_props
= *gui
->plugin
->get_metadata_iface()->get_param_props(handle
->param_z_no
);
1459 float value_z
= gui
->plugin
->get_param_value(handle
->param_z_no
);
1460 handle
->value_z
= handle_z_props
.to_01(value_z
);
1461 if (dsp::_sanitize(handle
->value_z
- handle
->last_value_z
)) {
1462 clg
->handle_redraw
= 1;
1464 handle
->last_value_z
= handle
->value_z
;
1466 bool _a
= handle
->active
;
1467 if(handle
->param_active_no
>= 0) {
1468 handle
->active
= bool(gui
->plugin
->get_param_value(handle
->param_active_no
));
1470 handle
->active
= true;
1472 if (handle
->active
!= _a
) {
1474 clg
->handle_redraw
= true;
1477 calf_line_graph_expose_request(widget
, force
);
1481 void line_graph_param_control::freqhandle_value_changed(GtkWidget
*widget
, gpointer p
)
1484 FreqHandle
*handle
= (FreqHandle
*)p
;
1485 param_control
*jhp
= (param_control
*)handle
->data
;
1490 line_graph_param_control::~line_graph_param_control()
1495 /******************************** Phase Graph ********************************/
1497 void phase_graph_param_control::on_idle()
1499 if (get_int("refresh", 0))
1503 GtkWidget
*phase_graph_param_control::create(plugin_gui
*_gui
, int _param_no
)
1506 param_no
= _param_no
;
1507 widget
= calf_phase_graph_new ();
1508 CalfPhaseGraph
*clg
= CALF_PHASE_GRAPH(widget
);
1509 widget
->requisition
.width
= get_int("size", 40);
1510 widget
->requisition
.height
= get_int("size", 40);
1511 clg
->source
= gui
->plugin
->get_phase_graph_iface();
1512 clg
->source_id
= param_no
;
1513 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-PhaseGraph");
1517 void phase_graph_param_control::set()
1520 GtkWidget
*tw
= gtk_widget_get_toplevel(widget
);
1521 if (tw
&& GTK_WIDGET_TOPLEVEL(tw
) && widget
->window
) {
1522 gtk_widget_queue_draw(widget
);
1526 phase_graph_param_control::~phase_graph_param_control()
1531 /******************************** Tuner ********************************/
1533 void tuner_param_control::on_idle()
1535 if (get_int("refresh", 0))
1539 GtkWidget
*tuner_param_control::create(plugin_gui
*_gui
, int _param_no
)
1542 param_no
= _param_no
;
1543 widget
= calf_tuner_new ();
1544 //CalfTuner *tuner = CALF_TUNER(widget);
1545 widget
->requisition
.width
= get_int("width", 40);
1546 widget
->requisition
.height
= get_int("height", 40);
1547 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-Tuner");
1549 const string
¢s_name
= attribs
["param_cents"];
1550 if (cents_name
!= "")
1551 cents_no
= gui
->get_param_no_by_name(cents_name
);
1557 void tuner_param_control::set()
1560 GtkWidget
*tw
= gtk_widget_get_toplevel(widget
);
1561 CalfTuner
*tuner
= CALF_TUNER(widget
);
1562 tuner
->note
= gui
->plugin
->get_param_value(param_no
);
1563 tuner
->cents
= gui
->plugin
->get_param_value(cents_no
);
1564 if (tw
&& GTK_WIDGET_TOPLEVEL(tw
) && widget
->window
) {
1565 gtk_widget_queue_draw(widget
);
1569 tuner_param_control::~tuner_param_control()
1573 /******************************** List View ********************************/
1575 GtkWidget
*listview_param_control::create(plugin_gui
*_gui
, int _param_no
)
1578 param_no
= _param_no
;
1580 string key
= attribs
["key"];
1581 tmif
= gui
->plugin
->get_metadata_iface()->get_table_metadata_iface(key
.c_str());
1584 g_error("Missing table_metadata_iface for variable '%s'", key
.c_str());
1588 const table_column_info
*tci
= tmif
->get_table_columns();
1591 while (tci
[cols
].name
!= NULL
)
1594 GType
*p
= new GType
[cols
];
1595 for (int i
= 0; i
< cols
; i
++)
1596 p
[i
] = G_TYPE_STRING
;
1597 lstore
= gtk_list_store_newv(cols
, p
);
1598 if (tmif
->get_table_rows() != 0)
1599 set_rows(tmif
->get_table_rows());
1600 widget
= gtk_tree_view_new_with_model(GTK_TREE_MODEL(lstore
));
1602 tree
= GTK_TREE_VIEW (widget
);
1603 g_object_set (G_OBJECT (tree
), "enable-search", FALSE
, "rules-hint", TRUE
, "enable-grid-lines", TRUE
, NULL
);
1605 for (int i
= 0; i
< cols
; i
++)
1607 GtkCellRenderer
*cr
= NULL
;
1609 if (tci
[i
].type
== TCT_ENUM
) {
1610 cr
= gtk_cell_renderer_combo_new ();
1611 GtkListStore
*cls
= gtk_list_store_new(2, G_TYPE_INT
, G_TYPE_STRING
);
1612 for (int j
= 0; tci
[i
].values
[j
]; j
++)
1613 gtk_list_store_insert_with_values(cls
, NULL
, j
, 0, j
, 1, tci
[i
].values
[j
], -1);
1614 g_object_set(cr
, "model", cls
, "editable", TRUE
, "has-entry", FALSE
, "text-column", 1, "mode", GTK_CELL_RENDERER_MODE_EDITABLE
, NULL
);
1617 bool editable
= tci
[i
].type
!= TCT_LABEL
;
1618 cr
= gtk_cell_renderer_text_new ();
1620 g_object_set(cr
, "editable", TRUE
, "mode", GTK_CELL_RENDERER_MODE_EDITABLE
, NULL
);
1622 g_object_set_data (G_OBJECT(cr
), "column", (void *)&tci
[i
]);
1623 g_signal_connect (GTK_OBJECT (cr
), "edited", G_CALLBACK (on_edited
), (gpointer
)this);
1624 g_signal_connect (GTK_OBJECT (cr
), "editing-canceled", G_CALLBACK (on_editing_canceled
), (gpointer
)this);
1625 gtk_tree_view_insert_column_with_attributes(tree
, i
, tci
[i
].name
, cr
, "text", i
, NULL
);
1627 gtk_tree_view_set_headers_visible(tree
, TRUE
);
1628 gtk_widget_set_name(GTK_WIDGET(widget
), "Calf-ListView");
1632 void listview_param_control::set_rows(unsigned int needed_rows
)
1634 while(positions
.size() < needed_rows
)
1637 gtk_list_store_insert(lstore
, &iter
, positions
.size());
1638 for (int j
= 0; j
< cols
; j
++)
1640 gtk_list_store_set(lstore
, &iter
, j
, "", -1);
1642 positions
.push_back(iter
);
1646 void listview_param_control::send_configure(const char *key
, const char *value
)
1648 string orig_key
= attribs
["key"] + ":";
1649 bool is_rows
= false;
1650 int row
= -1, col
= -1;
1651 if (parse_table_key(key
, orig_key
.c_str(), is_rows
, row
, col
))
1653 if (is_rows
&& tmif
->get_table_rows() == 0)
1655 int rows
= atoi(value
);
1660 if (row
!= -1 && col
!= -1)
1662 int max_rows
= tmif
->get_table_rows();
1663 if (col
< 0 || col
>= cols
)
1665 g_warning("Invalid column %d in key %s", col
, key
);
1668 if (max_rows
&& (row
< 0 || row
>= max_rows
))
1670 g_warning("Invalid row %d in key %s, this is a fixed table with row count = %d", row
, key
, max_rows
);
1674 if (row
>= (int)positions
.size())
1677 gtk_list_store_set(lstore
, &positions
[row
], col
, value
, -1);
1683 void listview_param_control::on_edited(GtkCellRenderer
*renderer
, gchar
*path
, gchar
*new_text
, listview_param_control
*pThis
)
1685 const table_column_info
*tci
= pThis
->tmif
->get_table_columns();
1686 int column
= ((table_column_info
*)g_object_get_data(G_OBJECT(renderer
), "column")) - tci
;
1687 string key
= pThis
->attribs
["key"] + ":" + i2s(atoi(path
)) + "," + i2s(column
);
1689 const char *error_or_null
= pThis
->gui
->plugin
->configure(key
.c_str(), new_text
);
1691 error
= error_or_null
;
1693 if (error
.empty()) {
1694 pThis
->send_configure(key
.c_str(), new_text
);
1695 gtk_widget_grab_focus(pThis
->widget
);
1696 GtkTreePath
*gpath
= gtk_tree_path_new_from_string (path
);
1697 gtk_tree_view_set_cursor_on_cell (GTK_TREE_VIEW (pThis
->widget
), gpath
, NULL
, NULL
, FALSE
);
1698 gtk_tree_path_free (gpath
);
1702 GtkWidget
*dialog
= gtk_message_dialog_new(pThis
->gui
->window
->toplevel
, GTK_DIALOG_DESTROY_WITH_PARENT
, GTK_MESSAGE_ERROR
, GTK_BUTTONS_OK
,
1703 "%s", error
.c_str());
1704 gtk_dialog_run(GTK_DIALOG(dialog
));
1705 gtk_widget_destroy(dialog
);
1706 gtk_widget_grab_focus(pThis
->widget
);
1710 void listview_param_control::on_editing_canceled(GtkCellRenderer
*renderer
, listview_param_control
*pThis
)
1712 gtk_widget_grab_focus(pThis
->widget
);
1715 /******************************** GtkNotebook control ********************************/
1717 GtkWidget
*notebook_param_control::create(plugin_gui
*_gui
, int _param_no
)
1720 param_no
= _param_no
;
1721 //const parameter_properties &props = get_props();
1725 page
= gui
->plugin
->get_param_value(param_no
);
1726 GtkWidget
*nb
= calf_notebook_new();
1727 widget
= GTK_WIDGET(nb
);
1728 calf_notebook_set_pixbuf(CALF_NOTEBOOK(nb
),
1729 gui
->window
->environment
->get_image_factory()->get("notebook_screw"));
1730 gtk_widget_set_name(widget
, "Calf-Notebook");
1731 gtk_notebook_set_current_page(GTK_NOTEBOOK(widget
), page
);
1734 void notebook_param_control::created()
1736 g_signal_connect (GTK_OBJECT (widget
), "switch-page", G_CALLBACK (notebook_page_changed
), (gpointer
)this);
1739 void notebook_param_control::get()
1742 gui
->set_param_value(param_no
, page
, this);
1744 void notebook_param_control::set()
1749 page
= (gint
)gui
->plugin
->get_param_value(param_no
);
1750 gtk_notebook_set_current_page(GTK_NOTEBOOK(widget
), page
);
1752 void notebook_param_control::add(control_base
*base
)
1754 gtk_notebook_append_page(GTK_NOTEBOOK(widget
), base
->widget
, gtk_label_new_with_mnemonic(base
->attribs
["page"].c_str()));
1756 void notebook_param_control::notebook_page_changed(GtkWidget
*widget
, GtkWidget
*page
, guint id
, gpointer user
)
1758 notebook_param_control
*jhp
= (notebook_param_control
*)user
;
1759 jhp
->page
= (int)id
;
1763 /******************************** GtkTable container ********************************/
1765 GtkWidget
*table_container::create(plugin_gui
*_gui
)
1767 require_int_attribute("rows");
1768 require_int_attribute("cols");
1769 int homog
= get_int("homogeneous", 0);
1770 int sx
= get_int("spacing-x", 2);
1771 int sy
= get_int("spacing-y", 2);
1772 GtkWidget
*table
= gtk_table_new(get_int("rows", 1), get_int("cols", 1), false);
1774 gtk_table_set_homogeneous(GTK_TABLE(table
), TRUE
);
1776 gtk_table_set_col_spacings(GTK_TABLE(table
), sx
);
1777 gtk_table_set_row_spacings(GTK_TABLE(table
), sy
);
1779 gtk_widget_set_name(GTK_WIDGET(table
), "Calf-Table");
1783 void table_container::add(control_base
*base
)
1785 base
->require_int_attribute("attach-x");
1786 base
->require_int_attribute("attach-y");
1787 int x
= base
->get_int("attach-x"), y
= base
->get_int("attach-y");
1788 int w
= base
->get_int("attach-w", 1), h
= base
->get_int("attach-h", 1);
1789 int shrinkx
= base
->get_int("shrink-x", 0);
1790 int shrinky
= base
->get_int("shrink-y", 0);
1791 int fillx
= (base
->get_int("fill-x", !shrinkx
) ? GTK_FILL
: 0) | (base
->get_int("expand-x", !shrinkx
) ? GTK_EXPAND
: 0) | (shrinkx
? GTK_SHRINK
: 0);
1792 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);
1793 int padx
= base
->get_int("pad-x", 2);
1794 int pady
= base
->get_int("pad-y", 2);
1795 gtk_table_attach(GTK_TABLE(widget
), base
->widget
, x
, x
+ w
, y
, y
+ h
, (GtkAttachOptions
)fillx
, (GtkAttachOptions
)filly
, padx
, pady
);
1798 /******************************** alignment container ********************************/
1800 GtkWidget
*alignment_container::create(plugin_gui
*_gui
)
1802 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));
1803 gtk_widget_set_name(widget
, "Calf-Align");
1807 /******************************** GtkFrame container ********************************/
1809 GtkWidget
*frame_container::create(plugin_gui
*_gui
)
1811 widget
= calf_frame_new(attribs
["label"].c_str());
1812 gtk_widget_set_name(widget
, "Calf-Frame");
1816 /******************************** GtkBox type of containers ********************************/
1818 void box_container::add(control_base
*base
)
1820 gtk_container_add_with_properties(GTK_CONTAINER(widget
), base
->widget
, "expand", get_int("expand", 1), "fill", get_int("fill", 1), NULL
);
1823 /******************************** GtkHBox container ********************************/
1825 GtkWidget
*hbox_container::create(plugin_gui
*_gui
)
1827 widget
= gtk_hbox_new(get_int("homogeneous") >= 1, get_int("spacing", 2));
1828 gtk_widget_set_name(widget
, "Calf-HBox");
1832 /******************************** GtkVBox container ********************************/
1834 GtkWidget
*vbox_container::create(plugin_gui
*_gui
)
1836 widget
= gtk_vbox_new(get_int("homogeneous") >= 1, get_int("spacing", 2));
1837 gtk_widget_set_name(widget
, "Calf-VBox");
1841 /******************************** GtkNotebook container ********************************/
1843 GtkWidget
*scrolled_container::create(plugin_gui
*_gui
)
1845 GtkAdjustment
*horiz
= NULL
, *vert
= NULL
;
1846 int width
= get_int("width", 0), height
= get_int("height", 0);
1848 horiz
= GTK_ADJUSTMENT(gtk_adjustment_new(get_int("x", 0), 0, width
, get_int("step-x", 1), get_int("page-x", width
/ 10), 100));
1850 vert
= GTK_ADJUSTMENT(gtk_adjustment_new(get_int("y", 0), 0, width
, get_int("step-y", 1), get_int("page-y", height
/ 10), 10));
1851 widget
= gtk_scrolled_window_new(horiz
, vert
);
1852 gtk_widget_set_size_request(widget
, get_int("req-x", -1), get_int("req-y", -1));
1853 gtk_widget_set_name(widget
, "Calf-ScrolledWindow");
1857 void scrolled_container::add(control_base
*base
)
1859 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(widget
), base
->widget
);