Zrythm
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
yaml.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: © 2019-2023 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
10#ifndef __UTILS_YAML_H__
11#define __UTILS_YAML_H__
12
13#include "zrythm-config.h"
14
15#ifdef HAVE_CYAML
16
17# include <gtk/gtk.h>
18
19# include <cyaml/cyaml.h>
20
30# define YAML_FIELD_IGNORE_OPT(key) \
31 CYAML_FIELD_IGNORE (key, CYAML_FLAG_OPTIONAL)
32
36# define YAML_FIELD_MAPPING_EMBEDDED(owner, member, schema) \
37 CYAML_FIELD_MAPPING (#member, CYAML_FLAG_DEFAULT, owner, member, schema)
38
42# define YAML_FIELD_MAPPING_PTR(owner, member, schema) \
43 CYAML_FIELD_MAPPING_PTR (#member, CYAML_FLAG_POINTER, owner, member, schema)
44
48# define YAML_FIELD_MAPPING_PTR_OPTIONAL(owner, member, schema) \
49 CYAML_FIELD_MAPPING_PTR ( \
50 #member, CYAML_FLAG_POINTER | CYAML_FLAG_OPTIONAL, owner, member, schema)
51
60# define YAML_FIELD_FIXED_SIZE_PTR_ARRAY_VAR_COUNT(owner, member, schema) \
61 CYAML_FIELD_SEQUENCE_COUNT ( \
62 #member, CYAML_FLAG_DEFAULT, owner, member, num_##member, &schema, 0, \
63 CYAML_UNLIMITED)
64
72# define YAML_FIELD_FIXED_SIZE_PTR_ARRAY(owner, member, schema, size) \
73 CYAML_FIELD_SEQUENCE_FIXED ( \
74 #member, CYAML_FLAG_DEFAULT, owner, member, &schema, size)
75
86# define YAML_FIELD_DYN_PTR_ARRAY_VAR_COUNT(owner, member, schema) \
87 CYAML_FIELD_SEQUENCE_COUNT ( \
88 #member, CYAML_FLAG_POINTER, owner, member, num_##member, &schema, 0, \
89 CYAML_UNLIMITED)
90
99# define YAML_FIELD_DYN_FIXED_SIZE_PTR_ARRAY( \
100 owner, member, schema, fixed_size) \
101 CYAML_FIELD_SEQUENCE_FIXED ( \
102 #member, CYAML_FLAG_POINTER, owner, member, &schema, fixed_size)
103
118# define YAML_FIELD_DYN_ARRAY_VAR_COUNT(owner, member, schema) \
119 CYAML_FIELD_SEQUENCE_COUNT ( \
120 #member, CYAML_FLAG_POINTER | CYAML_FLAG_OPTIONAL, owner, member, \
121 num_##member, &schema, 0, CYAML_UNLIMITED)
122
133# define YAML_FIELD_DYN_PTR_ARRAY_VAR_COUNT_OPT(owner, member, schema) \
134 YAML_FIELD_DYN_ARRAY_VAR_COUNT (owner, member, schema)
135
144# define YAML_FIELD_DYN_FIXED_SIZE_PTR_ARRAY_OPT( \
145 owner, member, schema, fixed_size) \
146 CYAML_FIELD_SEQUENCE_FIXED ( \
147 #member, CYAML_FLAG_POINTER | CYAML_FLAG_OPTIONAL, owner, member, \
148 &schema, fixed_size)
149
164# define YAML_FIELD_DYN_ARRAY_VAR_COUNT_PRIMITIVES(owner, member, schema) \
165 YAML_FIELD_DYN_ARRAY_VAR_COUNT (owner, member, schema)
166
170# define YAML_FIELD_SEQUENCE_FIXED(owner, member, schema, size) \
171 CYAML_FIELD_SEQUENCE_FIXED ( \
172 #member, CYAML_FLAG_DEFAULT, owner, member, &schema, size)
173
174# define YAML_FIELD_INT(owner, member) \
175 CYAML_FIELD_INT (#member, CYAML_FLAG_DEFAULT, owner, member)
176
177# define YAML_FIELD_INT_OPT(owner, member) \
178 CYAML_FIELD_INT (#member, CYAML_FLAG_OPTIONAL, owner, member)
179
180# define YAML_FIELD_UINT(owner, member) \
181 CYAML_FIELD_UINT (#member, CYAML_FLAG_DEFAULT, owner, member)
182
183# define YAML_FIELD_FLOAT(owner, member) \
184 CYAML_FIELD_FLOAT (#member, CYAML_FLAG_DEFAULT, owner, member)
185
186# define YAML_FIELD_STRING_PTR(owner, member) \
187 CYAML_FIELD_STRING_PTR ( \
188 #member, CYAML_FLAG_POINTER, owner, member, 0, CYAML_UNLIMITED)
189
190# define YAML_FIELD_STRING_PTR_OPTIONAL(owner, member) \
191 CYAML_FIELD_STRING_PTR ( \
192 #member, CYAML_FLAG_POINTER | CYAML_FLAG_OPTIONAL, owner, member, 0, \
193 CYAML_UNLIMITED)
194
195# define YAML_FIELD_ENUM(owner, member, strings) \
196 CYAML_FIELD_ENUM ( \
197 #member, CYAML_FLAG_DEFAULT, owner, member, strings, \
198 CYAML_ARRAY_LEN (strings))
199
200# define YAML_FIELD_BITFIELD(owner, member, bitvals) \
201 CYAML_FIELD_BITFIELD ( \
202 #member, CYAML_FLAG_DEFAULT, owner, member, bitvals, \
203 CYAML_ARRAY_LEN (bitvals))
204
208# define YAML_VALUE_PTR(cc, fields_schema) \
209 CYAML_VALUE_MAPPING (CYAML_FLAG_POINTER, cc, fields_schema)
210
215# define YAML_VALUE_PTR_NULLABLE(cc, fields_schema) \
216 CYAML_VALUE_MAPPING (CYAML_FLAG_POINTER_NULL_STR, cc, fields_schema)
217
224# define YAML_VALUE_DEFAULT(cc, fields_schema) \
225 CYAML_VALUE_MAPPING (CYAML_FLAG_DEFAULT, cc, fields_schema)
226
227# define YAML_BITVAL(_name, _offset) \
228 { \
229 .name = _name, .offset = _offset, .bits = 1 \
230 }
231
238NONNULL_ARGS (1, 2)
239char * yaml_serialize (
240 void * data,
241 const cyaml_schema_value_t * schema,
242 GError ** error);
243
244NONNULL_ARGS (1, 2)
245void * yaml_deserialize (
246 const char * yaml,
247 const cyaml_schema_value_t * schema,
248 GError ** error);
249
250NONNULL void
251yaml_print (void * data, const cyaml_schema_value_t * schema);
252
256void
257yaml_cyaml_log_func (
258 cyaml_log_t level,
259 void * ctxt,
260 const char * format,
261 va_list args);
262
263void
264yaml_set_log_level (cyaml_log_t level);
265
266void
267yaml_get_cyaml_config (cyaml_config_t * cyaml_config);
268
269static const cyaml_schema_value_t int_schema = {
270 CYAML_VALUE_INT (CYAML_FLAG_DEFAULT, int),
271};
272
273static const cyaml_schema_value_t unsigned_int_schema = {
274 CYAML_VALUE_UINT (CYAML_FLAG_DEFAULT, unsigned int),
275};
276
277static const cyaml_schema_value_t uint8_t_schema = {
278 CYAML_VALUE_UINT (CYAML_FLAG_DEFAULT, typeof (uint8_t)),
279};
280
281static const cyaml_schema_value_t float_schema = {
282 CYAML_VALUE_FLOAT (CYAML_FLAG_DEFAULT, typeof (float)),
283};
284
285static const cyaml_schema_field_t gdk_rgba_fields_schema[] = {
286 CYAML_FIELD_FLOAT ("red", CYAML_FLAG_DEFAULT, GdkRGBA, red),
287 CYAML_FIELD_FLOAT ("green", CYAML_FLAG_DEFAULT, GdkRGBA, green),
288 CYAML_FIELD_FLOAT ("blue", CYAML_FLAG_DEFAULT, GdkRGBA, blue),
289 CYAML_FIELD_FLOAT ("alpha", CYAML_FLAG_DEFAULT, GdkRGBA, alpha),
290
291 CYAML_FIELD_END
292};
293
294static const cyaml_schema_value_t gdk_rgba_schema_default = {
295 YAML_VALUE_DEFAULT (GdkRGBA, gdk_rgba_fields_schema),
296};
297
298static const cyaml_schema_value_t gdk_rgba_schema = {
299 YAML_VALUE_PTR (GdkRGBA, gdk_rgba_fields_schema),
300};
301
302typedef enum YamlDummyEnum
303{
304 YAML_DUMMY_ENUM1,
305} YamlDummyEnum;
306
311#endif /* HAVE_CYAML */
312
313#endif
NONNULL_ARGS(1) int undo_manager_undo(UndoManager *self
Undo last action.