+ GUI: more style related work (doesn't fully work yet)
[calf.git] / src / calf / gui.h
blob0d46efe6f3dcbc05901e0908c703a6aeeefb7f45
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);
47 /// called after creation, so that all standard properties can be set
48 virtual void set_std_properties() = 0;
51 #define _GUARD_CHANGE_ if (in_change) return; guard_change __gc__(this);
53 struct param_control: public control_base
55 int param_no;
56 std::string param_variable;
57 GtkWidget *label, *widget;
58 int in_change;
60 struct guard_change {
61 param_control *pc;
62 guard_change(param_control *_pc) : pc(_pc) { pc->in_change++; }
63 ~guard_change() { pc->in_change--; }
66 param_control() { gui = NULL; param_no = -1; label = NULL; in_change = 0;}
67 inline parameter_properties &get_props();
69 virtual void init_xml(const char *element) {}
70 virtual GtkWidget *create_label();
71 virtual void update_label();
72 /// called to create a widget for a control
73 virtual GtkWidget *create(plugin_gui *_gui, int _param_no)=0;
74 /// called to transfer the value from control to parameter(s)
75 virtual void get()=0;
76 /// called to transfer the value from parameter(s) to control
77 virtual void set()=0;
78 /// called on DSSI configure()
79 virtual void configure(const char *key, const char *value) {}
80 virtual void hook_params();
81 virtual void on_idle() {}
82 virtual void set_std_properties();
83 virtual ~param_control();
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 void set_std_properties();
93 virtual ~control_container() {}
96 class plugin_gui_window;
98 class plugin_gui: public send_configure_iface, public send_updates_iface
100 protected:
101 int param_count;
102 std::multimap<int, param_control *> par2ctl;
103 XML_Parser parser;
104 param_control *current_control;
105 std::vector<control_container *> container_stack;
106 control_container *top_container;
107 std::map<std::string, int> param_name_map;
108 int ignore_stack;
109 int last_status_serial_no;
110 public:
111 plugin_gui_window *window;
112 GtkWidget *container;
113 const char *effect_name;
114 plugin_ctl_iface *plugin;
115 std::vector<param_control *> params;
117 plugin_gui(plugin_gui_window *_window);
118 GtkWidget *create_from_xml(plugin_ctl_iface *_plugin, const char *xml);
119 param_control *create_control_from_xml(const char *element, const char *attributes[]);
120 control_container *create_container_from_xml(const char *element, const char *attributes[]);
122 void add_param_ctl(int param, param_control *ctl) { par2ctl.insert(std::pair<int, param_control *>(param, ctl)); }
123 void refresh();
124 void refresh(int param_no, param_control *originator = NULL);
125 void xml_element_start(const char *element, const char *attributes[]);
126 void set_param_value(int param_no, float value, param_control *originator = NULL);
127 /// Called on change of configure variable
128 void send_configure(const char *key, const char *value);
129 /// Called on change of status variable
130 void send_status(const char *key, const char *value);
131 void on_idle();
132 ~plugin_gui();
133 static void xml_element_start(void *data, const char *element, const char *attributes[]);
134 static void xml_element_end(void *data, const char *element);
137 class main_window_owner_iface;
139 class main_window_iface
141 public:
142 virtual void set_owner(main_window_owner_iface *owner)=0;
144 virtual void add_plugin(plugin_ctl_iface *plugin)=0;
145 virtual void del_plugin(plugin_ctl_iface *plugin)=0;
147 virtual void set_window(plugin_ctl_iface *plugin, plugin_gui_window *window)=0;
148 virtual void refresh_all_presets(bool builtin_too)=0;
149 virtual bool check_condition(const char *name)=0;
150 virtual ~main_window_iface() {}
153 class main_window_owner_iface
155 public:
156 virtual void new_plugin(const char *name) = 0;
157 virtual void remove_plugin(plugin_ctl_iface *plugin) = 0;
158 virtual ~main_window_owner_iface() {}
161 class plugin_gui_window
163 public:
164 plugin_gui *gui;
165 GtkWindow *toplevel;
166 GtkUIManager *ui_mgr;
167 GtkActionGroup *std_actions, *builtin_preset_actions, *user_preset_actions, *command_actions;
168 main_window_iface *main;
169 int source_id;
171 plugin_gui_window(main_window_iface *_main);
172 std::string make_gui_preset_list(GtkActionGroup *grp, bool builtin, char &ch);
173 std::string make_gui_command_list(GtkActionGroup *grp);
174 void fill_gui_presets(bool builtin, char &ch);
175 void create(plugin_ctl_iface *_plugin, const char *title, const char *effect);
176 void close();
177 static gboolean on_idle(void *data);
178 ~plugin_gui_window();
182 inline parameter_properties &param_control::get_props()
184 return *gui->plugin->get_param_props(param_no);
187 class null_audio_module;
189 struct activate_command_params
191 typedef void (*CommandFunc)(null_audio_module *);
192 plugin_gui *gui;
193 int function_idx;
195 activate_command_params(plugin_gui *_gui, int _idx)
196 : gui(_gui), function_idx(_idx)
201 void activate_command(GtkAction *action, activate_command_params *params);
205 #endif