BEAST/BSE - Better Audio System and Sound Engine  0.8.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
bsestorage.hh
Go to the documentation of this file.
00001  // Licensed GNU LGPL v2.1 or later: http://www.gnu.org/licenses/lgpl.html
00002 #ifndef __BSE_STORAGE_H__
00003 #define __BSE_STORAGE_H__
00004 
00005 #include <bse/bseobject.hh>
00006 #include <bse/gsldefs.hh>
00007 
00008 G_BEGIN_DECLS
00009 
00010 /* --- object type macros --- */
00011 #define BSE_TYPE_STORAGE                 (BSE_TYPE_ID (BseStorage))
00012 #define BSE_STORAGE(object)              (G_TYPE_CHECK_INSTANCE_CAST ((object), BSE_TYPE_STORAGE, BseStorage))
00013 #define BSE_STORAGE_CLASS(class)         (G_TYPE_CHECK_CLASS_CAST ((class), BSE_TYPE_STORAGE, BseStorageClass))
00014 #define BSE_IS_STORAGE(object)           (G_TYPE_CHECK_INSTANCE_TYPE ((object), BSE_TYPE_STORAGE))
00015 #define BSE_IS_STORAGE_CLASS(class)      (G_TYPE_CHECK_CLASS_TYPE ((class), BSE_TYPE_STORAGE))
00016 #define BSE_STORAGE_GET_CLASS(object)    (G_TYPE_INSTANCE_GET_CLASS ((object), BSE_TYPE_STORAGE, BseStorageClass))
00017 
00018 
00019 /* --- macros --- */
00020 #define BSE_STORAGE_VERSION(self, vmaj, min, vmic)      ( /* whether file uses >=vARGS features */ \
00021   BSE_VERSION_CMP (self->major_version, self->minor_version, self->micro_version, vmaj, min, vmic) >= 0)
00022 #define BSE_STORAGE_COMPAT(self, vmaj, min, vmic)       ( /* whether file needs <=vARGS compat code */ \
00023   BSE_VERSION_CMP (self->major_version, self->minor_version, self->micro_version, vmaj, min, vmic) <= 0)
00024 #define BSE_STORAGE_SELF_CONTAINED(st)   ((BSE_OBJECT_FLAGS (st) & BSE_STORAGE_SELF_CONTAINED) != 0)
00025 #define BSE_STORAGE_DBLOCK_CONTAINED(st) ((BSE_OBJECT_FLAGS (st) & BSE_STORAGE_DBLOCK_CONTAINED) != 0)
00026 #define BSE_STORAGE_IS_UNDO(st)          BSE_STORAGE_DBLOCK_CONTAINED (st)
00027 typedef enum    /*< skip >*/
00028 {
00029   BSE_STORAGE_SELF_CONTAINED      = 1 << (BSE_OBJECT_FLAGS_USHIFT + 0),
00030   BSE_STORAGE_DBLOCK_CONTAINED    = 1 << (BSE_OBJECT_FLAGS_USHIFT + 1)
00031 } BseStorageMode;
00032 #define BSE_STORAGE_FLAGS_USHIFT         (BSE_OBJECT_FLAGS_USHIFT + 2)
00033 #define BSE_STORAGE_MODE_MASK            (BSE_STORAGE_SELF_CONTAINED | BSE_STORAGE_DBLOCK_CONTAINED)
00034 
00035 
00036 /* --- compatibility --- */
00037 #define bse_storage_scanner_parse_or_return     sfi_scanner_parse_or_return
00038 #define bse_storage_scanner_peek_or_return      sfi_scanner_peek_or_return
00039 
00040 
00041 /* --- BseStorage --- */
00042 typedef struct _BseStorageDBlock   BseStorageDBlock;
00043 typedef struct _BseStorageItemLink BseStorageItemLink;
00044 typedef void (*BseStorageRestoreLink)   (gpointer        data,
00045                                          BseStorage     *storage,
00046                                          BseItem        *from_item,
00047                                          BseItem        *to_item,
00048                                          const gchar    *error);
00049 struct BseStorage : BseObject {
00050   /* writing */
00051   SfiWStore             *wstore;
00052   SfiPPool              *stored_items;
00053   SfiPPool              *referenced_items;
00054   /* parsing */
00055   SfiRStore             *rstore;
00056   guint                  major_version;
00057   guint                  minor_version;
00058   guint                  micro_version;
00059   GHashTable            *path_table;
00060   SfiRing               *item_links;
00061   SfiPPool              *restorable_objects;
00062   /* internal data */
00063   guint                  n_dblocks;
00064   BseStorageDBlock      *dblocks;
00065   gchar                 *free_me;
00066   /* compat */ // VERSION-FIXME: needed only for <= 0.5.1
00067   gfloat                 mix_freq;
00068   gfloat                 osc_freq;
00069   guint                  n_channels;
00070 };
00071 struct BseStorageClass : BseObjectClass
00072 {};
00073 
00074 /* --- compatibility file parsing --- */
00075 void         bse_storage_compat_dhreset         (BseStorage             *self);
00076 void         bse_storage_compat_dhmixf          (BseStorage             *self,
00077                                                  gfloat                  mix_freq);
00078 void         bse_storage_compat_dhoscf          (BseStorage             *self,
00079                                                  gfloat                  osc_freq);
00080 void         bse_storage_compat_dhchannels      (BseStorage             *self,
00081                                                  guint                   n_channels);
00082 
00083 
00084 /* --- prototypes -- */
00085 void         bse_storage_reset                  (BseStorage             *self);
00086 void         bse_storage_prepare_write          (BseStorage             *self,
00087                                                  BseStorageMode          mode);
00088 void         bse_storage_turn_readable          (BseStorage             *self,
00089                                                  const gchar            *storage_name);
00090 BseErrorType bse_storage_input_file             (BseStorage             *self,
00091                                                  const gchar            *file_name);
00092 void         bse_storage_input_text             (BseStorage             *self,
00093                                                  const gchar            *text,
00094                                                  const gchar            *text_name);
00095 GTokenType   bse_storage_restore_item           (BseStorage             *self,
00096                                                  gpointer                item);
00097 void         bse_storage_store_item             (BseStorage             *self,
00098                                                  BseItem                *item);
00099 void         bse_storage_store_child            (BseStorage             *self,
00100                                                  BseItem                *item);
00101 const gchar* bse_storage_item_get_compat_type   (BseItem                *item);
00102 
00103 
00104 /* --- writing --- */
00105 void         bse_storage_putf                   (BseStorage             *self,
00106                                                  gfloat                  vfloat);
00107 void         bse_storage_putd                   (BseStorage             *self,
00108                                                  gdouble                 vdouble);
00109 void         bse_storage_putr                   (BseStorage             *self,
00110                                                  SfiReal                 vreal,
00111                                                  const gchar            *hints);
00112 void         bse_storage_put_param              (BseStorage             *self,
00113                                                  const GValue           *value,
00114                                                  GParamSpec             *pspec);
00115 void         bse_storage_put_item_link          (BseStorage             *self,
00116                                                  BseItem                *from_item,
00117                                                  BseItem                *to_item);
00118 void         bse_storage_put_data_handle        (BseStorage             *self,
00119                                                  guint                   significant_bits,
00120                                                  GslDataHandle          *dhandle);
00121 void         bse_storage_put_xinfos             (BseStorage             *self,
00122                                                  gchar                 **xinfos);
00123 BseErrorType bse_storage_flush_fd               (BseStorage             *self,
00124                                                  gint                    fd);
00125 
00126 
00127 /* --- reading --- */
00128 #define      bse_storage_error(s, ...)          bse_storage_error_str (s, Rapicorn::string_format (__VA_ARGS__).c_str())
00129 void         bse_storage_error_str              (BseStorage *self, const std::string &string);
00130 #define      bse_storage_warn(s, ...)           bse_storage_warn_str (s, Rapicorn::string_format (__VA_ARGS__).c_str())
00131 void         bse_storage_warn_str               (BseStorage *self, const std::string &string);
00132 #define      bse_storage_warn_skip(s, ...)      bse_storage_skip (s, Rapicorn::string_format (__VA_ARGS__).c_str())
00133 GTokenType   bse_storage_skip                   (BseStorage *self, const std::string &string);
00134 GTokenType   bse_storage_parse_param_value      (BseStorage             *self,
00135                                                  GValue                 *value,
00136                                                  GParamSpec             *pspec);
00137 GTokenType   bse_storage_parse_item_link        (BseStorage             *self,
00138                                                  BseItem                *from_item,
00139                                                  BseStorageRestoreLink   restore_link,
00140                                                  gpointer                data);
00141 void         bse_storage_add_restorable         (BseStorage             *self,
00142                                                  BseObject              *object);
00143 void         bse_storage_finish_parsing         (BseStorage             *self);
00144 GTokenType   bse_storage_parse_data_handle      (BseStorage             *self,
00145                                                  GslDataHandle         **data_handle_p,
00146                                                  guint                  *n_channels_p,
00147                                                  gfloat                 *mix_freq_p,
00148                                                  gfloat                 *osc_freq_p);
00149 gboolean     bse_storage_match_data_handle      (BseStorage             *self,
00150                                                  GQuark                  quark);
00151 GTokenType   bse_storage_parse_data_handle_rest (BseStorage             *self,
00152                                                  GslDataHandle         **data_handle_p,
00153                                                  guint                  *n_channels_p,
00154                                                  gfloat                 *mix_freq_p,
00155                                                  gfloat                 *osc_freq_p);
00156 GTokenType   bse_storage_parse_xinfos           (BseStorage             *self,
00157                                                  gchar                ***xinfosp);
00158 GTokenType   bse_storage_parse_rest             (BseStorage             *self,
00159                                                  gpointer                context_data,
00160                                                  BseTryStatement         try_statement,
00161                                                  gpointer                user_data);
00162 gboolean     bse_storage_check_parse_negate     (BseStorage             *self);
00163 
00164 
00165 /* --- short-hands --- */
00166 #define bse_storage_get_scanner(s)      ((s)->rstore->scanner)
00167 #define bse_storage_unexp_token(s,et)   sfi_rstore_unexp_token ((s)->rstore, et)
00168 #define bse_storage_push_level(s)       sfi_wstore_push_level ((s)->wstore)
00169 #define bse_storage_pop_level(s)        sfi_wstore_pop_level ((s)->wstore)
00170 #define bse_storage_break(s)            sfi_wstore_break ((s)->wstore)
00171 #define bse_storage_putc(s,c)           sfi_wstore_putc ((s)->wstore, c)
00172 #define bse_storage_puts(s,b)           sfi_wstore_puts ((s)->wstore, b)
00173 #define bse_storage_printf(s, ...)      bse_storage_puts (s, Rapicorn::string_format (__VA_ARGS__).c_str())
00174 
00175 G_END_DECLS
00176 
00177 #endif /* __BSE_STORAGE_H__ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines