BEAST - Free Software Audio Synthesizer and Tracker  0.10.0
bsestorage.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 __BSE_STORAGE_H__
3 #define __BSE_STORAGE_H__
4 
5 #include <bse/bseobject.hh>
6 #include <bse/gsldefs.hh>
7 
8 G_BEGIN_DECLS
9 
10 /* --- object type macros --- */
11 #define BSE_TYPE_STORAGE (BSE_TYPE_ID (BseStorage))
12 #define BSE_STORAGE(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), BSE_TYPE_STORAGE, BseStorage))
13 #define BSE_STORAGE_CLASS(class) (G_TYPE_CHECK_CLASS_CAST ((class), BSE_TYPE_STORAGE, BseStorageClass))
14 #define BSE_IS_STORAGE(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), BSE_TYPE_STORAGE))
15 #define BSE_IS_STORAGE_CLASS(class) (G_TYPE_CHECK_CLASS_TYPE ((class), BSE_TYPE_STORAGE))
16 #define BSE_STORAGE_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS ((object), BSE_TYPE_STORAGE, BseStorageClass))
17 
18 
19 /* --- macros --- */
20 #define BSE_STORAGE_VERSION(self, vmaj, min, vmic) ( /* whether file uses >=vARGS features */ \
21  BSE_VERSION_CMP (self->major_version, self->minor_version, self->micro_version, vmaj, min, vmic) >= 0)
22 #define BSE_STORAGE_COMPAT(self, vmaj, min, vmic) ( /* whether file needs <=vARGS compat code */ \
23  BSE_VERSION_CMP (self->major_version, self->minor_version, self->micro_version, vmaj, min, vmic) <= 0)
24 #define BSE_STORAGE_SELF_CONTAINED(st) ((BSE_OBJECT_FLAGS (st) & BSE_STORAGE_SELF_CONTAINED) != 0)
25 #define BSE_STORAGE_DBLOCK_CONTAINED(st) ((BSE_OBJECT_FLAGS (st) & BSE_STORAGE_DBLOCK_CONTAINED) != 0)
26 #define BSE_STORAGE_IS_UNDO(st) BSE_STORAGE_DBLOCK_CONTAINED (st)
27 typedef enum /*< skip >*/
28 {
29  BSE_STORAGE_SELF_CONTAINED = 1 << (BSE_OBJECT_FLAGS_USHIFT + 0),
30  BSE_STORAGE_DBLOCK_CONTAINED = 1 << (BSE_OBJECT_FLAGS_USHIFT + 1)
31 } BseStorageMode;
32 #define BSE_STORAGE_FLAGS_USHIFT (BSE_OBJECT_FLAGS_USHIFT + 2)
33 #define BSE_STORAGE_MODE_MASK (BSE_STORAGE_SELF_CONTAINED | BSE_STORAGE_DBLOCK_CONTAINED)
34 
35 
36 /* --- compatibility --- */
37 #define bse_storage_scanner_parse_or_return sfi_scanner_parse_or_return
38 #define bse_storage_scanner_peek_or_return sfi_scanner_peek_or_return
39 
40 
41 /* --- BseStorage --- */
42 typedef struct _BseStorageDBlock BseStorageDBlock;
43 typedef struct _BseStorageItemLink BseStorageItemLink;
44 typedef void (*BseStorageRestoreLink) (gpointer data,
45  BseStorage *storage,
46  BseItem *from_item,
47  BseItem *to_item,
48  const gchar *error);
50  /* writing */
51  SfiWStore *wstore;
52  SfiPPool *stored_items;
53  SfiPPool *referenced_items;
54  /* parsing */
55  SfiRStore *rstore;
56  guint major_version;
57  guint minor_version;
58  guint micro_version;
59  GHashTable *path_table;
60  SfiRing *item_links;
61  SfiPPool *restorable_objects;
62  /* internal data */
63  guint n_dblocks;
64  BseStorageDBlock *dblocks;
65  gchar *free_me;
66  /* compat */ // VERSION-FIXME: needed only for <= 0.5.1
67  gfloat mix_freq;
68  gfloat osc_freq;
69  guint n_channels;
70 };
72 {};
73 
74 /* --- compatibility file parsing --- */
75 void bse_storage_compat_dhreset (BseStorage *self);
76 void bse_storage_compat_dhmixf (BseStorage *self,
77  gfloat mix_freq);
78 void bse_storage_compat_dhoscf (BseStorage *self,
79  gfloat osc_freq);
80 void bse_storage_compat_dhchannels (BseStorage *self,
81  guint n_channels);
82 
83 
84 /* --- prototypes -- */
85 void bse_storage_reset (BseStorage *self);
86 void bse_storage_prepare_write (BseStorage *self,
87  BseStorageMode mode);
88 void bse_storage_turn_readable (BseStorage *self,
89  const gchar *storage_name);
90 Bse::Error bse_storage_input_file (BseStorage *self,
91  const gchar *file_name);
92 void bse_storage_input_text (BseStorage *self,
93  const gchar *text,
94  const gchar *text_name);
95 GTokenType bse_storage_restore_item (BseStorage *self,
96  gpointer item);
97 void bse_storage_store_item (BseStorage *self,
98  BseItem *item);
99 void bse_storage_store_child (BseStorage *self,
100  BseItem *item);
101 const gchar* bse_storage_item_get_compat_type (BseItem *item);
102 
103 
104 /* --- writing --- */
105 void bse_storage_putf (BseStorage *self,
106  gfloat vfloat);
107 void bse_storage_putd (BseStorage *self,
108  gdouble vdouble);
109 void bse_storage_putr (BseStorage *self,
110  SfiReal vreal,
111  const gchar *hints);
112 void bse_storage_put_param (BseStorage *self,
113  const GValue *value,
114  GParamSpec *pspec);
115 void bse_storage_put_item_link (BseStorage *self,
116  BseItem *from_item,
117  BseItem *to_item);
118 void bse_storage_put_data_handle (BseStorage *self,
119  guint significant_bits,
120  GslDataHandle *dhandle);
121 void bse_storage_put_xinfos (BseStorage *self,
122  gchar **xinfos);
123 Bse::Error bse_storage_flush_fd (BseStorage *self,
124  gint fd);
125 
126 
127 /* --- reading --- */
128 #define bse_storage_error(s, ...) bse_storage_error_str (s, Rapicorn::string_format (__VA_ARGS__).c_str())
129 void bse_storage_error_str (BseStorage *self, const std::string &string);
130 #define bse_storage_warn(s, ...) bse_storage_warn_str (s, Rapicorn::string_format (__VA_ARGS__).c_str())
131 void bse_storage_warn_str (BseStorage *self, const std::string &string);
132 #define bse_storage_warn_skip(s, ...) bse_storage_skip (s, Rapicorn::string_format (__VA_ARGS__).c_str())
133 GTokenType bse_storage_skip (BseStorage *self, const std::string &string);
134 GTokenType bse_storage_parse_param_value (BseStorage *self,
135  GValue *value,
136  GParamSpec *pspec);
137 GTokenType bse_storage_parse_item_link (BseStorage *self,
138  BseItem *from_item,
139  BseStorageRestoreLink restore_link,
140  gpointer data);
141 void bse_storage_add_restorable (BseStorage *self,
142  BseObject *object);
143 void bse_storage_finish_parsing (BseStorage *self);
144 GTokenType bse_storage_parse_data_handle (BseStorage *self,
145  GslDataHandle **data_handle_p,
146  guint *n_channels_p,
147  gfloat *mix_freq_p,
148  gfloat *osc_freq_p);
149 gboolean bse_storage_match_data_handle (BseStorage *self,
150  GQuark quark);
151 GTokenType bse_storage_parse_data_handle_rest (BseStorage *self,
152  GslDataHandle **data_handle_p,
153  guint *n_channels_p,
154  gfloat *mix_freq_p,
155  gfloat *osc_freq_p);
156 GTokenType bse_storage_parse_xinfos (BseStorage *self,
157  gchar ***xinfosp);
158 GTokenType bse_storage_parse_rest (BseStorage *self,
159  gpointer context_data,
160  BseTryStatement try_statement,
161  gpointer user_data);
162 gboolean bse_storage_check_parse_negate (BseStorage *self);
163 
164 
165 /* --- short-hands --- */
166 #define bse_storage_get_scanner(s) ((s)->rstore->scanner)
167 #define bse_storage_unexp_token(s,et) sfi_rstore_unexp_token ((s)->rstore, et)
168 #define bse_storage_push_level(s) sfi_wstore_push_level ((s)->wstore)
169 #define bse_storage_pop_level(s) sfi_wstore_pop_level ((s)->wstore)
170 #define bse_storage_break(s) sfi_wstore_break ((s)->wstore)
171 #define bse_storage_putc(s,c) sfi_wstore_putc ((s)->wstore, c)
172 #define bse_storage_puts(s,b) sfi_wstore_puts ((s)->wstore, b)
173 #define bse_storage_printf(s, ...) bse_storage_puts (s, Rapicorn::string_format (__VA_ARGS__).c_str())
174 
175 G_END_DECLS
176 
177 #endif /* __BSE_STORAGE_H__ */
Definition: bsestorage.hh:71
STL class.
Definition: bseobject.hh:61
Definition: bseobject.hh:94
Definition: sfiring.hh:23
Definition: bsestorage.hh:49
Definition: sfistore.hh:14
GTokenType bse_storage_parse_item_link(BseStorage *self, BseItem *from_item, BseStorageRestoreLink restore_link, gpointer data)
Definition: bsestorage.cc:1083
Definition: bseitem.hh:34