+ GUI: remove unused (and misleading) fields - the widget pointer is always stored...
[calf.git] / src / calf / gui.h
blobafd129c3453730dbd8fa89c88bbbf9d4f5b2b2f4
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., 59 Temple Place, Suite 330,
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 struct control_container: public control_base
85 GtkContainer *container;
87 virtual GtkWidget *create(plugin_gui *_gui, const char *element, xml_attribute_map &attributes)=0;
88 virtual void add(GtkWidget *w, control_base *base) { gtk_container_add(container, w); }
89 virtual ~control_container() {}
92 struct table_container: public control_container
94 virtual GtkWidget *create(plugin_gui *_gui, const char *element, xml_attribute_map &attributes);
95 virtual void add(GtkWidget *w, control_base *base);
98 struct alignment_container: public control_container
100 virtual GtkWidget *create(plugin_gui *_gui, const char *element, xml_attribute_map &attributes);
103 struct frame_container: public control_container
105 virtual GtkWidget *create(plugin_gui *_gui, const char *element, xml_attribute_map &attributes);
108 struct box_container: public control_container
110 virtual void add(GtkWidget *w, control_base *base);
113 struct vbox_container: public box_container
115 virtual GtkWidget *create(plugin_gui *_gui, const char *element, xml_attribute_map &attributes);
118 struct hbox_container: public box_container
120 virtual GtkWidget *create(plugin_gui *_gui, const char *element, xml_attribute_map &attributes);
123 struct notebook_container: public control_container
125 virtual void add(GtkWidget *w, control_base *base);
126 virtual GtkWidget *create(plugin_gui *_gui, const char *element, xml_attribute_map &attributes);
129 struct scrolled_container: public control_container
131 virtual void add(GtkWidget *w, control_base *base);
132 virtual GtkWidget *create(plugin_gui *_gui, const char *element, xml_attribute_map &attributes);
135 /// Display-only control: static text
136 struct label_param_control: public param_control
138 virtual GtkWidget *create(plugin_gui *_gui, int _param_no);
139 virtual void get() {}
140 virtual void set() {}
143 /// Display-only control: value text
144 struct value_param_control: public param_control, public send_updates_iface
146 virtual GtkWidget *create(plugin_gui *_gui, int _param_no);
147 virtual void get() {}
148 virtual void set();
149 virtual void send_status(const char *key, const char *value);
152 /// Display-only control: volume meter
153 struct vumeter_param_control: public param_control
155 virtual GtkWidget *create(plugin_gui *_gui, int _param_no);
156 virtual void get() {}
157 virtual void set();
160 /// Display-only control: LED
161 struct led_param_control: public param_control
163 virtual GtkWidget *create(plugin_gui *_gui, int _param_no);
164 virtual void get() {}
165 virtual void set();
168 /// Horizontal slider
169 struct hscale_param_control: public param_control
171 virtual GtkWidget *create(plugin_gui *_gui, int _param_no);
172 virtual void get();
173 virtual void set();
174 virtual void init_xml(const char *element);
175 static void hscale_value_changed(GtkHScale *widget, gpointer value);
176 static gchar *hscale_format_value(GtkScale *widget, double arg1, gpointer value);
179 /// Vertical slider
180 struct vscale_param_control: public param_control
182 virtual GtkWidget *create(plugin_gui *_gui, int _param_no);
183 virtual void get();
184 virtual void set();
185 virtual void init_xml(const char *element);
186 static void vscale_value_changed(GtkHScale *widget, gpointer value);
189 /// Spin button
190 struct spin_param_control: public param_control
192 virtual GtkWidget *create(plugin_gui *_gui, int _param_no);
193 virtual void get();
194 virtual void set();
195 static void value_changed(GtkSpinButton *widget, gpointer value);
198 struct toggle_param_control: public param_control
200 virtual GtkWidget *create(plugin_gui *_gui, int _param_no);
201 virtual void get();
202 virtual void set();
203 static void toggle_value_changed(GtkCheckButton *widget, gpointer value);
206 struct button_param_control: public param_control
208 virtual GtkWidget *create(plugin_gui *_gui, int _param_no);
209 virtual void get();
210 virtual void set();
211 static void button_clicked(GtkButton *widget, gpointer value);
214 struct combo_box_param_control: public param_control
216 virtual GtkWidget *create(plugin_gui *_gui, int _param_no);
217 virtual void get();
218 virtual void set();
219 static void combo_value_changed(GtkComboBox *widget, gpointer value);
222 struct line_graph_param_control: public param_control
224 CalfLineGraph *graph;
225 int last_generation;
227 virtual GtkWidget *create(plugin_gui *_gui, int _param_no);
228 virtual void get() {}
229 virtual void set();
230 virtual void on_idle();
231 virtual ~line_graph_param_control();
234 struct knob_param_control: public param_control
236 CalfKnob *knob;
238 virtual GtkWidget *create(plugin_gui *_gui, int _param_no);
239 virtual void get();
240 virtual void set();
241 static void knob_value_changed(GtkWidget *widget, gpointer value);
244 struct keyboard_param_control: public param_control
246 CalfKeyboard *kb;
248 virtual GtkWidget *create(plugin_gui *_gui, int _param_no);
249 virtual void get() {}
250 virtual void set() {}
253 struct curve_param_control: public param_control, public send_configure_iface
255 CalfCurve *curve;
257 virtual GtkWidget *create(plugin_gui *_gui, int _param_no);
258 virtual void get() {}
259 virtual void set() {}
260 virtual void send_configure(const char *key, const char *value);
263 struct entry_param_control: public param_control, public send_configure_iface
265 GtkEntry *entry;
267 virtual GtkWidget *create(plugin_gui *_gui, int _param_no);
268 virtual void get() {}
269 virtual void set() {}
270 virtual void send_configure(const char *key, const char *value);
271 static void entry_value_changed(GtkWidget *widget, gpointer value);
274 struct filechooser_param_control: public param_control, public send_configure_iface
276 GtkFileChooserButton *filechooser;
278 virtual GtkWidget *create(plugin_gui *_gui, int _param_no);
279 virtual void get() {}
280 virtual void set() {}
281 virtual void send_configure(const char *key, const char *value);
282 static void filechooser_value_changed(GtkWidget *widget, gpointer value);
285 class plugin_gui_window;
287 class plugin_gui: public send_configure_iface, public send_updates_iface
289 protected:
290 int param_count;
291 std::multimap<int, param_control *> par2ctl;
292 XML_Parser parser;
293 param_control *current_control;
294 std::vector<control_container *> container_stack;
295 control_container *top_container;
296 std::map<std::string, int> param_name_map;
297 int ignore_stack;
298 int last_status_serial_no;
299 public:
300 plugin_gui_window *window;
301 GtkWidget *container;
302 const char *effect_name;
303 plugin_ctl_iface *plugin;
304 std::vector<param_control *> params;
306 plugin_gui(plugin_gui_window *_window);
307 GtkWidget *create_from_xml(plugin_ctl_iface *_plugin, const char *xml);
308 param_control *create_control_from_xml(const char *element, const char *attributes[]);
309 control_container *create_container_from_xml(const char *element, const char *attributes[]);
311 void add_param_ctl(int param, param_control *ctl) { par2ctl.insert(std::pair<int, param_control *>(param, ctl)); }
312 void refresh();
313 void refresh(int param_no, param_control *originator = NULL);
314 void xml_element_start(const char *element, const char *attributes[]);
315 void set_param_value(int param_no, float value, param_control *originator = NULL);
316 /// Called on change of configure variable
317 void send_configure(const char *key, const char *value);
318 /// Called on change of status variable
319 void send_status(const char *key, const char *value);
320 void on_idle();
321 ~plugin_gui();
322 static void xml_element_start(void *data, const char *element, const char *attributes[]);
323 static void xml_element_end(void *data, const char *element);
326 class main_window_owner_iface;
328 class main_window_iface
330 public:
331 virtual void set_owner(main_window_owner_iface *owner)=0;
333 virtual void add_plugin(plugin_ctl_iface *plugin)=0;
334 virtual void del_plugin(plugin_ctl_iface *plugin)=0;
336 virtual void set_window(plugin_ctl_iface *plugin, plugin_gui_window *window)=0;
337 virtual void refresh_all_presets(bool builtin_too)=0;
338 virtual bool check_condition(const char *name)=0;
339 virtual ~main_window_iface() {}
342 class main_window_owner_iface
344 public:
345 virtual void new_plugin(const char *name) = 0;
346 virtual void remove_plugin(plugin_ctl_iface *plugin) = 0;
347 virtual ~main_window_owner_iface() {}
350 class plugin_gui_window
352 public:
353 plugin_gui *gui;
354 GtkWindow *toplevel;
355 GtkUIManager *ui_mgr;
356 GtkActionGroup *std_actions, *builtin_preset_actions, *user_preset_actions, *command_actions;
357 main_window_iface *main;
358 int source_id;
360 plugin_gui_window(main_window_iface *_main);
361 std::string make_gui_preset_list(GtkActionGroup *grp, bool builtin, char &ch);
362 std::string make_gui_command_list(GtkActionGroup *grp);
363 void fill_gui_presets(bool builtin, char &ch);
364 void create(plugin_ctl_iface *_plugin, const char *title, const char *effect);
365 void close();
366 static gboolean on_idle(void *data);
367 ~plugin_gui_window();
371 inline parameter_properties &param_control::get_props()
373 return *gui->plugin->get_param_props(param_no);
376 class null_audio_module;
378 struct activate_command_params
380 typedef void (*CommandFunc)(null_audio_module *);
381 plugin_gui *gui;
382 int function_idx;
384 activate_command_params(plugin_gui *_gui, int _idx)
385 : gui(_gui), function_idx(_idx)
390 void activate_command(GtkAction *action, activate_command_params *params);
394 #endif