Merge branch 'master' of ssh://repo.or.cz/srv/git/calf
[calf.git] / src / calf / gui.h
blobf92a6b00efa24a753da61a3aef4c266c6632fe27
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 GtkWidget *label, *widget;
55 int in_change;
57 struct guard_change {
58 param_control *pc;
59 guard_change(param_control *_pc) : pc(_pc) { pc->in_change++; }
60 ~guard_change() { pc->in_change--; }
63 param_control() { gui = NULL; param_no = -1; label = NULL; in_change = 0;}
64 inline parameter_properties &get_props();
66 virtual void init_xml(const char *element) {}
67 virtual GtkWidget *create_label();
68 virtual void update_label();
69 /// called to create a widget for a control
70 virtual GtkWidget *create(plugin_gui *_gui, int _param_no)=0;
71 /// called to transfer the value from control to parameter(s)
72 virtual void get()=0;
73 /// called to transfer the value from parameter(s) to control
74 virtual void set()=0;
75 /// called on DSSI configure()
76 virtual void configure(const char *key, const char *value) {}
77 virtual void hook_params();
78 virtual void on_idle() {}
79 virtual ~param_control();
82 struct control_container: public control_base
84 GtkContainer *container;
86 virtual GtkWidget *create(plugin_gui *_gui, const char *element, xml_attribute_map &attributes)=0;
87 virtual void add(GtkWidget *w, control_base *base) { gtk_container_add(container, w); }
88 virtual ~control_container() {}
91 struct table_container: public control_container
93 virtual GtkWidget *create(plugin_gui *_gui, const char *element, xml_attribute_map &attributes);
94 virtual void add(GtkWidget *w, control_base *base);
97 struct alignment_container: public control_container
99 virtual GtkWidget *create(plugin_gui *_gui, const char *element, xml_attribute_map &attributes);
102 struct frame_container: public control_container
104 virtual GtkWidget *create(plugin_gui *_gui, const char *element, xml_attribute_map &attributes);
107 struct box_container: public control_container
109 virtual void add(GtkWidget *w, control_base *base);
112 struct vbox_container: public box_container
114 virtual GtkWidget *create(plugin_gui *_gui, const char *element, xml_attribute_map &attributes);
117 struct hbox_container: public box_container
119 virtual GtkWidget *create(plugin_gui *_gui, const char *element, xml_attribute_map &attributes);
122 struct notebook_container: public control_container
124 virtual void add(GtkWidget *w, control_base *base);
125 virtual GtkWidget *create(plugin_gui *_gui, const char *element, xml_attribute_map &attributes);
128 struct scrolled_container: public control_container
130 virtual void add(GtkWidget *w, control_base *base);
131 virtual GtkWidget *create(plugin_gui *_gui, const char *element, xml_attribute_map &attributes);
134 /// Display-only control: static text
135 struct label_param_control: public param_control
137 virtual GtkWidget *create(plugin_gui *_gui, int _param_no);
138 virtual void get() {}
139 virtual void set() {}
142 /// Display-only control: value text
143 struct value_param_control: public param_control
145 virtual GtkWidget *create(plugin_gui *_gui, int _param_no);
146 virtual void get() {}
147 virtual void set();
150 /// Display-only control: volume meter
151 struct vumeter_param_control: public param_control
153 CalfVUMeter *meter;
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 CalfLed *meter;
165 virtual GtkWidget *create(plugin_gui *_gui, int _param_no);
166 virtual void get() {}
167 virtual void set();
170 /// Horizontal slider
171 struct hscale_param_control: public param_control
173 GtkHScale *scale;
175 virtual GtkWidget *create(plugin_gui *_gui, int _param_no);
176 virtual void get();
177 virtual void set();
178 virtual void init_xml(const char *element);
179 static void hscale_value_changed(GtkHScale *widget, gpointer value);
180 static gchar *hscale_format_value(GtkScale *widget, double arg1, gpointer value);
183 /// Vertical slider
184 struct vscale_param_control: public param_control
186 GtkVScale *scale;
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 struct toggle_param_control: public param_control
206 GtkCheckButton *scale;
208 virtual GtkWidget *create(plugin_gui *_gui, int _param_no);
209 virtual void get();
210 virtual void set();
211 static void toggle_value_changed(GtkCheckButton *widget, gpointer value);
214 struct button_param_control: public param_control
216 GtkCheckButton *scale;
218 virtual GtkWidget *create(plugin_gui *_gui, int _param_no);
219 virtual void get();
220 virtual void set();
221 static void button_clicked(GtkButton *widget, gpointer value);
224 struct combo_box_param_control: public param_control
226 GtkComboBox *scale;
228 virtual GtkWidget *create(plugin_gui *_gui, int _param_no);
229 virtual void get();
230 virtual void set();
231 static void combo_value_changed(GtkComboBox *widget, gpointer value);
234 struct line_graph_param_control: public param_control
236 CalfLineGraph *graph;
238 virtual GtkWidget *create(plugin_gui *_gui, int _param_no);
239 virtual void get() {}
240 virtual void set();
241 virtual void on_idle();
242 virtual ~line_graph_param_control();
245 struct knob_param_control: public param_control
247 CalfKnob *knob;
249 virtual GtkWidget *create(plugin_gui *_gui, int _param_no);
250 virtual void get();
251 virtual void set();
252 static void knob_value_changed(GtkWidget *widget, gpointer value);
255 struct keyboard_param_control: public param_control
257 CalfKeyboard *kb;
259 virtual GtkWidget *create(plugin_gui *_gui, int _param_no);
260 virtual void get() {}
261 virtual void set() {}
264 struct curve_param_control: public param_control, public send_configure_iface
266 CalfCurve *curve;
268 virtual GtkWidget *create(plugin_gui *_gui, int _param_no);
269 virtual void get() {}
270 virtual void set() {}
271 virtual void send_configure(const char *key, const char *value);
274 class plugin_gui_window;
276 class plugin_gui: public send_configure_iface
278 protected:
279 int param_count;
280 std::multimap<int, param_control *> par2ctl;
281 XML_Parser parser;
282 param_control *current_control;
283 std::vector<control_container *> container_stack;
284 control_container *top_container;
285 std::map<std::string, int> param_name_map;
286 int ignore_stack;
287 public:
288 plugin_gui_window *window;
289 GtkWidget *container;
290 const char *effect_name;
291 plugin_ctl_iface *plugin;
292 std::vector<param_control *> params;
294 plugin_gui(plugin_gui_window *_window);
295 GtkWidget *create_from_xml(plugin_ctl_iface *_plugin, const char *xml);
296 param_control *create_control_from_xml(const char *element, const char *attributes[]);
297 control_container *create_container_from_xml(const char *element, const char *attributes[]);
299 void add_param_ctl(int param, param_control *ctl) { par2ctl.insert(std::pair<int, param_control *>(param, ctl)); }
300 void refresh();
301 void refresh(int param_no, param_control *originator = NULL);
302 void xml_element_start(const char *element, const char *attributes[]);
303 void set_param_value(int param_no, float value, param_control *originator = NULL);
304 void send_configure(const char *key, const char *value);
305 void on_idle();
306 ~plugin_gui();
307 static void xml_element_start(void *data, const char *element, const char *attributes[]);
308 static void xml_element_end(void *data, const char *element);
311 class main_window_owner_iface;
313 class main_window_iface
315 public:
316 virtual void set_owner(main_window_owner_iface *owner)=0;
318 virtual void add_plugin(plugin_ctl_iface *plugin)=0;
319 virtual void del_plugin(plugin_ctl_iface *plugin)=0;
321 virtual void set_window(plugin_ctl_iface *plugin, plugin_gui_window *window)=0;
322 virtual void refresh_all_presets(bool builtin_too)=0;
323 virtual bool check_condition(const char *name)=0;
324 virtual ~main_window_iface() {}
327 class main_window_owner_iface
329 public:
330 virtual void new_plugin(const char *name) = 0;
331 virtual void remove_plugin(plugin_ctl_iface *plugin) = 0;
332 virtual ~main_window_owner_iface() {}
335 class plugin_gui_window
337 public:
338 plugin_gui *gui;
339 GtkWindow *toplevel;
340 GtkUIManager *ui_mgr;
341 GtkActionGroup *std_actions, *builtin_preset_actions, *user_preset_actions, *command_actions;
342 main_window_iface *main;
343 int source_id;
345 plugin_gui_window(main_window_iface *_main);
346 std::string make_gui_preset_list(GtkActionGroup *grp, bool builtin, char &ch);
347 std::string make_gui_command_list(GtkActionGroup *grp);
348 void fill_gui_presets(bool builtin, char &ch);
349 void create(plugin_ctl_iface *_plugin, const char *title, const char *effect);
350 void close();
351 static gboolean on_idle(void *data);
352 ~plugin_gui_window();
356 inline parameter_properties &param_control::get_props()
358 return *gui->plugin->get_param_props(param_no);
361 class null_audio_module;
363 struct activate_command_params
365 typedef void (*CommandFunc)(null_audio_module *);
366 plugin_gui *gui;
367 int function_idx;
369 activate_command_params(plugin_gui *_gui, int _idx)
370 : gui(_gui), function_idx(_idx)
375 void activate_command(GtkAction *action, activate_command_params *params);
379 #endif