BEAST - Free Software Audio Synthesizer and Tracker  0.9.2
sfiparams.hh
Go to the documentation of this file.
1  // Licensed GNU LGPL v2.1 or later: http://www.gnu.org/licenses/lgpl.html
2 #ifndef __SFI_PARAMS_H__
3 #define __SFI_PARAMS_H__
4 
5 #include <sfi/sfivalues.hh>
6 #include <sfi/sfiprimitives.hh>
7 
8 G_BEGIN_DECLS
9 
10 
11 /* --- Sfi param spec macros --- */
12 #define SFI_TYPE_PARAM_BOOL (G_TYPE_PARAM_BOOLEAN)
13 #define SFI_IS_PSPEC_BOOL(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), SFI_TYPE_PARAM_BOOL))
14 #define SFI_PSPEC_BOOL(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), SFI_TYPE_PARAM_BOOL, SfiParamSpecBool))
15 #define SFI_TYPE_PARAM_INT (G_TYPE_PARAM_INT)
16 #define SFI_IS_PSPEC_INT(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), SFI_TYPE_PARAM_INT))
17 #define SFI_PSPEC_INT(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), SFI_TYPE_PARAM_INT, SfiParamSpecInt))
18 #define SFI_TYPE_PARAM_NUM (G_TYPE_PARAM_INT64)
19 #define SFI_IS_PSPEC_NUM(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), SFI_TYPE_PARAM_NUM))
20 #define SFI_PSPEC_NUM(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), SFI_TYPE_PARAM_NUM, SfiParamSpecNum))
21 #define SFI_TYPE_PARAM_REAL (G_TYPE_PARAM_DOUBLE)
22 #define SFI_IS_PSPEC_REAL(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), SFI_TYPE_PARAM_REAL))
23 #define SFI_PSPEC_REAL(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), SFI_TYPE_PARAM_REAL, SfiParamSpecReal))
24 #define SFI_TYPE_PARAM_STRING (G_TYPE_PARAM_STRING)
25 #define SFI_IS_PSPEC_STRING(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), SFI_TYPE_PARAM_STRING))
26 #define SFI_PSPEC_STRING(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), SFI_TYPE_PARAM_STRING, SfiParamSpecString))
27 #define SFI_TYPE_PARAM_CHOICE (sfi__param_spec_types[0])
28 #define SFI_IS_PSPEC_CHOICE(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), SFI_TYPE_PARAM_CHOICE))
29 #define SFI_PSPEC_CHOICE(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), SFI_TYPE_PARAM_CHOICE, SfiParamSpecChoice))
30 #define SFI_TYPE_PARAM_BBLOCK (sfi__param_spec_types[1])
31 #define SFI_IS_PSPEC_BBLOCK(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), SFI_TYPE_PARAM_BBLOCK))
32 #define SFI_PSPEC_BBLOCK(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), SFI_TYPE_PARAM_BBLOCK, SfiParamSpecBBlock))
33 #define SFI_TYPE_PARAM_FBLOCK (sfi__param_spec_types[2])
34 #define SFI_IS_PSPEC_FBLOCK(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), SFI_TYPE_PARAM_FBLOCK))
35 #define SFI_PSPEC_FBLOCK(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), SFI_TYPE_PARAM_FBLOCK, SfiParamSpecFBlock))
36 #define SFI_TYPE_PARAM_PSPEC (G_TYPE_PARAM_PARAM)
37 #define SFI_IS_PSPEC_PSPEC(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), SFI_TYPE_PARAM_PSPEC))
38 #define SFI_PSPEC_PSPEC(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), SFI_TYPE_PARAM_PSPEC, SfiParamSpecPSpec))
39 #define SFI_TYPE_PARAM_SEQ (sfi__param_spec_types[3])
40 #define SFI_IS_PSPEC_SEQ(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), SFI_TYPE_PARAM_SEQ))
41 #define SFI_PSPEC_SEQ(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), SFI_TYPE_PARAM_SEQ, SfiParamSpecSeq))
42 #define SFI_TYPE_PARAM_REC (sfi__param_spec_types[4])
43 #define SFI_IS_PSPEC_REC(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), SFI_TYPE_PARAM_REC))
44 #define SFI_PSPEC_REC(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), SFI_TYPE_PARAM_REC, SfiParamSpecRec))
45 #define SFI_TYPE_PARAM_PROXY (sfi__param_spec_types[5])
46 #define SFI_IS_PSPEC_PROXY(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), SFI_TYPE_PARAM_PROXY))
47 #define SFI_PSPEC_PROXY(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), SFI_TYPE_PARAM_PROXY, SfiParamSpecProxy))
48 #define SFI_TYPE_PARAM_NOTE (sfi__param_spec_types[6])
49 #define SFI_IS_PSPEC_NOTE(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), SFI_TYPE_PARAM_NOTE))
50 #define SFI_PSPEC_NOTE(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), SFI_TYPE_PARAM_NOTE, SfiParamSpecNote))
51 
52 
53 /* --- Sfi param spec aliases --- */
54 typedef GParamSpecBoolean SfiParamSpecBool;
55 typedef GParamSpecInt SfiParamSpecInt;
56 typedef GParamSpecInt64 SfiParamSpecNum;
57 typedef GParamSpecDouble SfiParamSpecReal;
58 typedef GParamSpecString SfiParamSpecString;
59 typedef GParamSpecParam SfiParamSpecPSpec;
60 
61 
62 /* --- Sfi param specs --- */
63 struct SfiChoiceValue { // auxillary
64  const gchar *choice_ident;
65  const gchar *choice_label;
66  const gchar *choice_blurb;
67  SfiChoiceValue (const char *ident = NULL, const char *label = NULL, const char *blurb = NULL) :
68  choice_ident (ident), choice_label (label), choice_blurb (blurb)
69  {}
70 };
71 struct SfiChoiceValues { // auxillary
72  guint n_values;
73  const SfiChoiceValue *values;
74  SfiChoiceValues (uint nv = 0, const SfiChoiceValue *vl = NULL) :
75  n_values (nv), values (vl)
76  {}
77 };
78 typedef struct {
79  GParamSpecString pspec;
80  SfiChoiceValues cvalues;
82 typedef struct {
83  GParamSpecBoxed pspec;
85 typedef struct {
86  GParamSpecBoxed pspec;
88 typedef struct {
89  GParamSpecBoxed pspec;
90  GParamSpec *element;
92 typedef struct {
93  GParamSpecBoxed pspec;
94  SfiRecFields fields;
96 typedef struct {
97  GParamSpecPointer pspec;
99 typedef struct {
100  GParamSpecInt pspec;
101  gboolean allow_void;
103 
104 
105 /* --- Sfi GParamSpec constructors --- */
106 GParamSpec* sfi_pspec_bool (const gchar *name,
107  const gchar *nick,
108  const gchar *blurb,
109  SfiBool default_value,
110  const gchar *hints);
111 GParamSpec* sfi_pspec_int (const gchar *name,
112  const gchar *nick,
113  const gchar *blurb,
114  SfiInt default_value,
115  SfiInt minimum_value,
116  SfiInt maximum_value,
117  SfiInt stepping,
118  const gchar *hints);
119 GParamSpec* sfi_pspec_num (const gchar *name,
120  const gchar *nick,
121  const gchar *blurb,
122  SfiNum default_value,
123  SfiNum minimum_value,
124  SfiNum maximum_value,
125  SfiNum stepping,
126  const gchar *hints);
127 GParamSpec* sfi_pspec_real (const gchar *name,
128  const gchar *nick,
129  const gchar *blurb,
130  SfiReal default_value,
131  SfiReal minimum_value,
132  SfiReal maximum_value,
133  SfiReal stepping,
134  const gchar *hints);
135 GParamSpec* sfi_pspec_log_scale (const gchar *name,
136  const gchar *nick,
137  const gchar *blurb,
138  SfiReal default_value,
139  SfiReal minimum_value,
140  SfiReal maximum_value,
141  SfiReal stepping,
142  SfiReal center,
143  SfiReal base,
144  SfiReal n_steps,
145  const gchar *hints);
146 GParamSpec* sfi_pspec_string (const gchar *name,
147  const gchar *nick,
148  const gchar *blurb,
149  const gchar *default_value,
150  const gchar *hints);
151 GParamSpec* sfi_pspec_choice (const gchar *name,
152  const gchar *nick,
153  const gchar *blurb,
154  const gchar *default_value,
155  SfiChoiceValues static_const_evalues,
156  const gchar *hints);
157 GParamSpec* sfi_pspec_bblock (const gchar *name,
158  const gchar *nick,
159  const gchar *blurb,
160  const gchar *hints);
161 GParamSpec* sfi_pspec_fblock (const gchar *name,
162  const gchar *nick,
163  const gchar *blurb,
164  const gchar *hints);
165 GParamSpec* sfi_pspec_pspec (const gchar *name,
166  const gchar *nick,
167  const gchar *blurb,
168  const gchar *hints);
169 GParamSpec* sfi_pspec_seq (const gchar *name,
170  const gchar *nick,
171  const gchar *blurb,
172  GParamSpec *element_spec,
173  const gchar *hints);
174 GParamSpec* sfi_pspec_rec (const gchar *name,
175  const gchar *nick,
176  const gchar *blurb,
177  SfiRecFields static_const_fields,
178  const gchar *hints);
179 GParamSpec* sfi_pspec_rec_generic (const gchar *name,
180  const gchar *nick,
181  const gchar *blurb,
182  const gchar *hints);
183 GParamSpec* sfi_pspec_proxy (const gchar *name,
184  const gchar *nick,
185  const gchar *blurb,
186  const gchar *hints);
187 
188 
189 /* --- pspec wrappers --- */
190 #define sfi_pspec_ref g_param_spec_ref
191 #define sfi_pspec_unref g_param_spec_unref
192 #define sfi_pspec_sink g_param_spec_sink
193 #define sfi_pspec_get_qdata g_param_spec_get_qdata
194 #define sfi_pspec_set_qdata g_param_spec_set_qdata
195 #define sfi_pspec_set_qdata_full g_param_spec_set_qdata_full
196 #define sfi_pspec_steal_qdata g_param_spec_steal_qdata
197 #define sfi_pspec_get_name g_param_spec_get_name
198 #define sfi_pspec_get_nick g_param_spec_get_nick
199 #define sfi_pspec_get_blurb g_param_spec_get_blurb
200 
201 
202 /* --- conversion --- */
203 typedef SfiChoiceValues (*SfiChoiceValueGetter) (GType enum_type);
204 GParamSpec* sfi_pspec_to_serializable (GParamSpec *pspec);
205 GParamSpec* sfi_pspec_choice_from_enum (GParamSpec *enum_pspec);
206 GParamSpec* sfi_pspec_proxy_from_object (GParamSpec *object_pspec);
207 void sfi_enum_type_set_choice_value_getter (GType gtype,
208  SfiChoiceValueGetter cvgetter);
209 void sfi_boxed_type_set_rec_fields (GType boxed_type,
210  const SfiRecFields static_const_fields);
211 SfiRecFields sfi_boxed_type_get_rec_fields (GType boxed_type);
212 void sfi_boxed_type_set_seq_element (GType boxed_type,
213  GParamSpec *element);
214 GParamSpec* sfi_boxed_type_get_seq_element (GType boxed_type);
215 
216 
217 /* --- Sfi PSpec Options --- */
218 /* provide common option combinations: */
219 #define SFI_PARAM_READWRITE ":r:w:"
220 #define SFI_PARAM_STORAGE ":r:w:S:"
221 #define SFI_PARAM_STANDARD ":r:w:S:G:"
222 #define SFI_PARAM_STANDARD_RDONLY ":r:w:S:G:ro:"
223 #define SFI_PARAM_GUI ":r:w:G:"
224 #define SFI_PARAM_GUI_RDONLY ":r:w:G:ro:"
225 #define SFI_PARAM_GUI_READABLE ":r:G:"
226 
227 
228 /* --- serializable categories --- */
229 typedef enum /*< skip >*/
230 {
231  SFI_SCAT_INVAL = 0,
232  SFI_SCAT_BOOL = 'b',
233  SFI_SCAT_INT = 'i',
234  SFI_SCAT_NUM = 'n',
235  SFI_SCAT_REAL = 'r',
236  SFI_SCAT_STRING = 's',
237  SFI_SCAT_CHOICE = 'C',
238  SFI_SCAT_BBLOCK = 'B',
239  SFI_SCAT_FBLOCK = 'F',
240  SFI_SCAT_PSPEC = 'P',
241  SFI_SCAT_SEQ = 'Q',
242  SFI_SCAT_REC = 'R',
243  SFI_SCAT_PROXY = 'p',
244  SFI_SCAT_TYPE_MASK = 0x00ff,
245  SFI_SCAT_NOTE = 0x0100 | SFI_SCAT_INT,
246  SFI_SCAT_TIME = 0x0200 | SFI_SCAT_NUM,
247 } SfiSCategory;
248 
249 SfiSCategory sfi_categorize_type (GType value_type);
250 SfiSCategory sfi_categorize_pspec (GParamSpec *pspec);
251 GType sfi_category_type (SfiSCategory pspec_cat);
252 GType sfi_category_param_type (SfiSCategory pspec_cat);
253 
254 
255 /* --- convenience aliases --- */
256 GParamSpec* sfi_pspec_note (const gchar *name,
257  const gchar *nick,
258  const gchar *blurb,
259  SfiInt default_value,
260  SfiInt min_note,
261  SfiInt max_note,
262  gboolean allow_void,
263  const gchar *hints);
264 #define SFI_IS_PSPEC_TIME SFI_IS_PSPEC_TIME
265 GParamSpec* sfi_pspec_time (const gchar *name,
266  const gchar *nick,
267  const gchar *blurb,
268  const gchar *hints);
269 
270 
271 /* --- pspec accessors --- */
272 GParamSpec* sfi_pspec_set_group (GParamSpec *pspec,
273  const gchar *group);
274 const gchar* sfi_pspec_get_group (GParamSpec *pspec);
275 void sfi_pspec_set_owner (GParamSpec *pspec,
276  const gchar *owner);
277 const gchar* sfi_pspec_get_owner (GParamSpec *pspec);
278 #define sfi_pspec_set_options(pspec, opts) g_param_spec_set_options (pspec, opts)
279 #define sfi_pspec_add_option(pspec, opt, val) g_param_spec_add_option (pspec, opt, val)
280 #define sfi_pspec_check_option(pspec, opt) g_param_spec_check_option (pspec, opt)
281 #define sfi_pspec_provides_options(pspec, opts) g_param_spec_provides_options (pspec, opts)
282 #define sfi_pspec_get_options(pspec) g_param_spec_get_options (pspec)
283 SfiBool sfi_pspec_get_bool_default (GParamSpec *pspec);
284 SfiInt sfi_pspec_get_int_default (GParamSpec *pspec);
285 void sfi_pspec_get_int_range (GParamSpec *pspec,
286  SfiInt *minimum_value,
287  SfiInt *maximum_value,
288  SfiInt *stepping);
289 gboolean sfi_pspec_allows_void_note (GParamSpec *pspec);
290 #define sfi_pspec_get_note_default sfi_pspec_get_int_default
291 #define sfi_pspec_get_note_range sfi_pspec_get_int_range
292 SfiNum sfi_pspec_get_num_default (GParamSpec *pspec);
293 void sfi_pspec_get_num_range (GParamSpec *pspec,
294  SfiNum *minimum_value,
295  SfiNum *maximum_value,
296  SfiNum *stepping);
297 SfiReal sfi_pspec_get_real_default (GParamSpec *pspec);
298 void sfi_pspec_get_real_range (GParamSpec *pspec,
299  SfiReal *minimum_value,
300  SfiReal *maximum_value,
301  SfiReal *stepping);
302 #define sfi_pspec_set_log_scale(p, c, b, n) g_param_spec_set_log_scale (p, c, b, n)
303 #define sfi_pspec_get_log_scale(p, c, b, n) g_param_spec_get_log_scale (p, c, b, n)
304 const gchar* sfi_pspec_get_string_default (GParamSpec *pspec);
305 const gchar* sfi_pspec_get_choice_default (GParamSpec *pspec);
306 SfiChoiceValues sfi_pspec_get_choice_values (GParamSpec *pspec);
307 guint64 sfi_pspec_get_choice_hash (GParamSpec *pspec);
308 GParamSpec* sfi_pspec_get_seq_element (GParamSpec *pspec);
309 SfiRecFields sfi_pspec_get_rec_fields (GParamSpec *pspec);
310 GParamSpec* sfi_pspec_get_rec_field (GParamSpec *pspec,
311  const gchar *field_name);
312 
313 
314 /* --- internal --- */
315 void _sfi_init_params (void);
316 extern GType* sfi__param_spec_types;
317 SfiRec* sfi_pspec_to_rec (GParamSpec *pspec);
318 GParamSpec* sfi_pspec_from_rec (SfiRec *prec);
319 
320 G_END_DECLS
321 
322 namespace Bse { // bsecore
323 
324 SfiChoiceValues choice_values_from_enum_values (const String &enumname, size_t n, const ::Rapicorn::Aida::EnumValue *values);
325 template<class EnumType> SfiChoiceValues
326 choice_values_from_enum ()
327 {
328  ::Rapicorn::Aida::EnumInfo einfo = ::Rapicorn::Aida::enum_info<EnumType>();
329  return choice_values_from_enum_values (einfo.name(), einfo.n_values(), einfo.values());
330 }
331 
332 } // Bse
333 
334 
335 #endif /* __SFI_PARAMS_H__ */
336 
337 /* vim:set ts=8 sts=2 sw=2: */
The Bse namespace contains all functions of the synthesis engine.
Definition: bstbseutils.cc:67
STL class.
Definition: sfiparams.hh:63
Definition: sfiparams.hh:99
Definition: sfitypes.hh:31
Definition: sfiparams.hh:71
Definition: sfiparams.hh:88
Definition: sfiparams.hh:78
Definition: sfiparams.hh:92
Definition: sfiparams.hh:82
Definition: sfiparams.hh:85
Definition: sfiparams.hh:96