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