+ GUI: style changes
[calf.git] / src / calf / gui.h
blob6b70538eec767ad1ea33653519287a019f1bba9f
1 /* Calf DSP Library
2 * Universal GUI module
3 * Copyright (C) 2007 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 02111-1307, USA.
20 #ifndef __CALF_GUI_H
21 #define __CALF_GUI_H
23 #include <expat.h>
24 #include <map>
25 #include <set>
26 #include <vector>
27 #include <gtk/gtk.h>
28 #include "custom_ctl.h"
30 struct CalfCurve;
31 struct CalfKeyboard;
32 struct CalfLed;
34 namespace calf_plugins {
36 class plugin_gui;
38 struct control_base
40 typedef std::map<std::string, std::string> xml_attribute_map;
41 xml_attribute_map attribs;
42 plugin_gui *gui;
43 void require_attribute(const char *name);
44 void require_int_attribute(const char *name);
45 int get_int(const char *name, int def_value = 0);
46 float get_float(const char *name, float def_value = 0.f);
49 #define _GUARD_CHANGE_ if (in_change) return; guard_change __gc__(this);
51 struct param_control: public control_base
53 int param_no;
54 std::string param_variable;
55 GtkWidget *label, *widget;
56 int in_change;
58 struct guard_change {
59 param_control *pc;
60 guard_change(param_control *_pc) : pc(_pc) { pc->in_change++; }
61 ~guard_change() { pc->in_change--; }
64 param_control() { gui = NULL; param_no = -1; label = NULL; in_change = 0;}
65 inline parameter_properties &get_props();
67 virtual void init_xml(const char *element) {}
68 virtual GtkWidget *create_label();
69 virtual void update_label();
70 /// called to create a widget for a control
71 virtual GtkWidget *create(plugin_gui *_gui, int _param_no)=0;
72 /// called to transfer the value from control to parameter(s)
73 virtual void get()=0;
74 /// called to transfer the value from parameter(s) to control
75 virtual void set()=0;
76 /// called on DSSI configure()
77 virtual void configure(const char *key, const char *value) {}
78 virtual void hook_params();
79 virtual void on_idle() {}
80 virtual ~param_control();
83 /////////////////////////////////////////////////////////////////////////////////////////////
84 // containers
86 struct control_container: public control_base
88 GtkContainer *container;
90 virtual GtkWidget *create(plugin_gui *_gui, const char *element, xml_attribute_map &attributes)=0;
91 virtual void add(GtkWidget *w, control_base *base) { gtk_container_add(container, w); }
92 virtual ~control_container() {}
95 struct table_container: public control_container
97 virtual GtkWidget *create(plugin_gui *_gui, const char *element, xml_attribute_map &attributes);
98 virtual void add(GtkWidget *w, control_base *base);
101 struct alignment_container: public control_container
103 virtual GtkWidget *create(plugin_gui *_gui, const char *element, xml_attribute_map &attributes);
106 struct frame_container: public control_container
108 virtual GtkWidget *create(plugin_gui *_gui, const char *element, xml_attribute_map &attributes);
111 struct box_container: public control_container
113 virtual void add(GtkWidget *w, control_base *base);
116 struct vbox_container: public box_container
118 virtual GtkWidget *create(plugin_gui *_gui, const char *element, xml_attribute_map &attributes);
121 struct hbox_container: public box_container
123 virtual GtkWidget *create(plugin_gui *_gui, const char *element, xml_attribute_map &attributes);
126 struct notebook_container: public control_container
128 virtual void add(GtkWidget *w, control_base *base);
129 virtual GtkWidget *create(plugin_gui *_gui, const char *element, xml_attribute_map &attributes);
132 struct scrolled_container: public control_container
134 virtual void add(GtkWidget *w, control_base *base);
135 virtual GtkWidget *create(plugin_gui *_gui, const char *element, xml_attribute_map &attributes);
138 ////////////////////////////////////////////////////////////////////////////////////////////////////
139 // controls
141 /// Display-only control: static text
142 struct label_param_control: public param_control
144 virtual GtkWidget *create(plugin_gui *_gui, int _param_no);
145 virtual void get() {}
146 virtual void set() {}
149 /// Display-only control: value text
150 struct value_param_control: public param_control, public send_updates_iface
152 virtual GtkWidget *create(plugin_gui *_gui, int _param_no);
153 virtual void get() {}
154 virtual void set();
155 virtual void send_status(const char *key, const char *value);
158 /// Display-only control: volume meter
159 struct vumeter_param_control: public param_control
161 virtual GtkWidget *create(plugin_gui *_gui, int _param_no);
162 virtual void get() {}
163 virtual void set();
166 /// Display-only control: LED
167 struct led_param_control: public param_control
169 virtual GtkWidget *create(plugin_gui *_gui, int _param_no);
170 virtual void get() {}
171 virtual void set();
174 /// Horizontal slider
175 struct hscale_param_control: public param_control
177 virtual GtkWidget *create(plugin_gui *_gui, int _param_no);
178 virtual void get();
179 virtual void set();
180 virtual void init_xml(const char *element);
181 static void hscale_value_changed(GtkHScale *widget, gpointer value);
182 static gchar *hscale_format_value(GtkScale *widget, double arg1, gpointer value);
185 /// Vertical slider
186 struct vscale_param_control: public param_control
188 virtual GtkWidget *create(plugin_gui *_gui, int _param_no);
189 virtual void get();
190 virtual void set();
191 virtual void init_xml(const char *element);
192 static void vscale_value_changed(GtkHScale *widget, gpointer value);
195 /// Spin button
196 struct spin_param_control: public param_control
198 virtual GtkWidget *create(plugin_gui *_gui, int _param_no);
199 virtual void get();
200 virtual void set();
201 static void value_changed(GtkSpinButton *widget, gpointer value);
204 /// Check box (Markus Schmidt)
205 struct check_param_control: public param_control
207 virtual GtkWidget *create(plugin_gui *_gui, int _param_no);
208 virtual void get();
209 virtual void set();
211 static void check_value_changed(GtkCheckButton *widget, gpointer value);
214 /// Toggle Button
215 struct toggle_param_control: public param_control
217 virtual GtkWidget *create(plugin_gui *_gui, int _param_no);
218 virtual void get();
219 virtual void set();
221 static void toggle_value_changed(GtkWidget *widget, gpointer value);
224 /// Push button
225 struct button_param_control: public param_control
227 virtual GtkWidget *create(plugin_gui *_gui, int _param_no);
228 virtual void get();
229 virtual void set();
230 static void button_clicked(GtkButton *widget, gpointer value);
233 /// Combo list box
234 struct combo_box_param_control: public param_control, public send_updates_iface
236 GtkListStore *lstore;
237 std::map<std::string, GtkTreeIter> key2pos;
238 std::string last_key;
240 virtual GtkWidget *create(plugin_gui *_gui, int _param_no);
241 virtual void get();
242 virtual void set();
243 virtual void send_status(const char *key, const char *value);
244 void set_to_last_key();
245 static void combo_value_changed(GtkComboBox *widget, gpointer value);
248 /// Line graph
249 struct line_graph_param_control: public param_control
251 int last_generation;
253 virtual GtkWidget *create(plugin_gui *_gui, int _param_no);
254 virtual void get() {}
255 virtual void set();
256 virtual void on_idle();
257 virtual ~line_graph_param_control();
260 /// Knob
261 struct knob_param_control: public param_control
263 virtual GtkWidget *create(plugin_gui *_gui, int _param_no);
264 virtual void get();
265 virtual void set();
266 static void knob_value_changed(GtkWidget *widget, gpointer value);
269 /// Static keyboard image
270 struct keyboard_param_control: public param_control
272 CalfKeyboard *kb;
274 virtual GtkWidget *create(plugin_gui *_gui, int _param_no);
275 virtual void get() {}
276 virtual void set() {}
279 /// Curve editor
280 struct curve_param_control: public param_control, public send_configure_iface
282 CalfCurve *curve;
284 virtual GtkWidget *create(plugin_gui *_gui, int _param_no);
285 virtual void get() {}
286 virtual void set() {}
287 virtual void send_configure(const char *key, const char *value);
290 /// Text entry
291 struct entry_param_control: public param_control, public send_configure_iface
293 GtkEntry *entry;
295 virtual GtkWidget *create(plugin_gui *_gui, int _param_no);
296 virtual void get() {}
297 virtual void set() {}
298 virtual void send_configure(const char *key, const char *value);
299 static void entry_value_changed(GtkWidget *widget, gpointer value);
302 /// File chooser button
303 struct filechooser_param_control: public param_control, public send_configure_iface
305 GtkFileChooserButton *filechooser;
307 virtual GtkWidget *create(plugin_gui *_gui, int _param_no);
308 virtual void get() {}
309 virtual void set() {}
310 virtual void send_configure(const char *key, const char *value);
311 static void filechooser_value_changed(GtkWidget *widget, gpointer value);
314 /// List view used for variable-length tabular data
315 struct listview_param_control: public param_control, public send_configure_iface
317 GtkTreeView *tree;
318 GtkListStore *lstore;
319 calf_plugins::table_edit_iface *teif;
320 int cols;
321 std::vector<GtkTreeIter> positions;
323 virtual GtkWidget *create(plugin_gui *_gui, int _param_no);
324 virtual void get() {}
325 virtual void set() {}
326 virtual void send_configure(const char *key, const char *value);
327 void update_store();
328 static void on_edited(GtkCellRenderer *renderer, gchar *path, gchar *new_text, listview_param_control *pThis);
329 static void on_editing_canceled(GtkCellRenderer *renderer, listview_param_control *pThis);
332 class plugin_gui_window;
334 class plugin_gui: public send_configure_iface, public send_updates_iface
336 protected:
337 int param_count;
338 std::multimap<int, param_control *> par2ctl;
339 XML_Parser parser;
340 param_control *current_control;
341 std::vector<control_container *> container_stack;
342 control_container *top_container;
343 std::map<std::string, int> param_name_map;
344 int ignore_stack;
345 int last_status_serial_no;
346 public:
347 plugin_gui_window *window;
348 GtkWidget *container;
349 const char *effect_name;
350 plugin_ctl_iface *plugin;
351 std::vector<param_control *> params;
353 plugin_gui(plugin_gui_window *_window);
354 GtkWidget *create_from_xml(plugin_ctl_iface *_plugin, const char *xml);
355 param_control *create_control_from_xml(const char *element, const char *attributes[]);
356 control_container *create_container_from_xml(const char *element, const char *attributes[]);
358 void add_param_ctl(int param, param_control *ctl) { par2ctl.insert(std::pair<int, param_control *>(param, ctl)); }
359 void refresh();
360 void refresh(int param_no, param_control *originator = NULL);
361 void xml_element_start(const char *element, const char *attributes[]);
362 void set_param_value(int param_no, float value, param_control *originator = NULL);
363 /// Called on change of configure variable
364 void send_configure(const char *key, const char *value);
365 /// Called on change of status variable
366 void send_status(const char *key, const char *value);
367 void on_idle();
368 ~plugin_gui();
369 static void xml_element_start(void *data, const char *element, const char *attributes[]);
370 static void xml_element_end(void *data, const char *element);
373 class main_window_owner_iface;
375 class main_window_iface
377 public:
378 virtual void set_owner(main_window_owner_iface *owner)=0;
380 virtual void add_plugin(plugin_ctl_iface *plugin)=0;
381 virtual void del_plugin(plugin_ctl_iface *plugin)=0;
383 virtual void set_window(plugin_ctl_iface *plugin, plugin_gui_window *window)=0;
384 virtual void refresh_all_presets(bool builtin_too)=0;
385 virtual bool check_condition(const char *name)=0;
386 virtual ~main_window_iface() {}
389 class main_window_owner_iface
391 public:
392 virtual void new_plugin(const char *name) = 0;
393 virtual void remove_plugin(plugin_ctl_iface *plugin) = 0;
394 virtual ~main_window_owner_iface() {}
397 class plugin_gui_window
399 public:
400 plugin_gui *gui;
401 GtkWindow *toplevel;
402 GtkUIManager *ui_mgr;
403 GtkActionGroup *std_actions, *builtin_preset_actions, *user_preset_actions, *command_actions;
404 main_window_iface *main;
405 int source_id;
407 plugin_gui_window(main_window_iface *_main);
408 std::string make_gui_preset_list(GtkActionGroup *grp, bool builtin, char &ch);
409 std::string make_gui_command_list(GtkActionGroup *grp);
410 void fill_gui_presets(bool builtin, char &ch);
411 void create(plugin_ctl_iface *_plugin, const char *title, const char *effect);
412 void close();
413 static gboolean on_idle(void *data);
414 ~plugin_gui_window();
418 inline parameter_properties &param_control::get_props()
420 return *gui->plugin->get_param_props(param_no);
423 class null_audio_module;
425 struct activate_command_params
427 typedef void (*CommandFunc)(null_audio_module *);
428 plugin_gui *gui;
429 int function_idx;
431 activate_command_params(plugin_gui *_gui, int _idx)
432 : gui(_gui), function_idx(_idx)
437 void activate_command(GtkAction *action, activate_command_params *params);
441 #endif