1 /* GSequencer - Advanced GTK Sequencer 2 * Copyright (C) 2005-2020 Joël Krähemann 3 * 4 * This file is part of GSequencer. 5 * 6 * GSequencer is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation, either version 3 of the License, or 9 * (at your option) any later version. 10 * 11 * GSequencer is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with GSequencer. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 #ifndef __AGS_FILE_H__ 21 #define __AGS_FILE_H__ 22 23 #include <glib.h> 24 #include <glib-object.h> 25 26 #include <libxml/tree.h> 27 28 #include <unistd.h> 29 30 G_BEGIN_DECLS 31 32 #define AGS_TYPE_FILE (ags_file_get_type()) 33 #define AGS_TYPE_FILE_FLAGS (ags_file_flags_get_type()) 34 #define AGS_FILE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), AGS_TYPE_FILE, AgsFile)) 35 #define AGS_FILE_CLASS(class) (G_TYPE_CHECK_CLASS_CAST((class), AGS_TYPE_FILE, AgsFileClass)) 36 #define AGS_IS_FILE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), AGS_TYPE_FILE)) 37 #define AGS_IS_FILE_CLASS(class) (G_TYPE_CHECK_CLASS_TYPE ((class), AGS_TYPE_FILE)) 38 #define AGS_FILE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), AGS_TYPE_FILE, AgsFileClass)) 39 40 #define AGS_FILE_GET_OBJ_MUTEX(obj) (&(((AgsFile *) obj)->obj_mutex)) 41 42 #define AGS_FILE_DEFAULT_ENCODING "UTF-8" 43 #define AGS_FILE_DEFAULT_DTD "ags_file.dtd" 44 45 #define AGS_FILE_CHECKSUM_LENGTH (32) 46 47 #define AGS_FILE_DEFAULT_AUDIO_FORMAT "raw" 48 #define AGS_FILE_DEFAULT_AUDIO_ENCODING "base64" 49 50 typedef struct _AgsFile AgsFile; 51 typedef struct _AgsFileClass AgsFileClass; 52 53 /** 54 * AgsFileFlags: 55 * @AGS_FILE_READ: opened file for reading 56 * @AGS_FILE_READ_AUDIO_SIGNAL: read audio signal 57 * @AGS_FILE_READ_EMBEDDED_AUDIO: read embedded audio data 58 * @AGS_FILE_WRITE: opened file for writing 59 * @AGS_FILE_WRITE_AUDIO_SIGNAL: write audio signal 60 * @AGS_FILE_WRITE_EMBEDDED_AUDIO: write embedded audio data 61 * 62 * Enum values to control the behavior or indicate internal state of #AgsFile by 63 * enable/disable as flags. 64 */ 65 typedef enum{ 66 AGS_FILE_READ = 1, 67 AGS_FILE_READ_AUDIO_SIGNAL = 1 << 1, 68 AGS_FILE_READ_EMBEDDED_AUDIO = 1 << 2, 69 AGS_FILE_WRITE = 1 << 3, 70 AGS_FILE_WRITE_AUDIO_SIGNAL = 1 << 4, 71 AGS_FILE_WRITE_EMBEDDED_AUDIO = 1 << 5, 72 }AgsFileFlags; 73 74 #define AGS_FILE_ERROR (ags_file_error_quark()) 75 76 /** 77 * AgsFileError: 78 * @AGS_FILE_ERROR_PARSER_FAILURE: the parser failed 79 * 80 * Enum values to indicated failures to used with #GError-struct. 81 */ 82 typedef enum{ 83 AGS_FILE_ERROR_PARSER_FAILURE, 84 }AgsFileError; 85 86 struct _AgsFile 87 { 88 GObject gobject; 89 90 guint flags; 91 92 GRecMutex obj_mutex; 93 94 FILE *out; 95 xmlChar *buffer; 96 97 gchar *filename; 98 gchar *encoding; 99 gchar *dtd; 100 101 gchar *audio_format; 102 gchar *audio_encoding; 103 104 xmlDoc *doc; 105 xmlNode *root_node; 106 107 GList *id_refs; 108 GList *lookup; 109 GList *launch; 110 111 GObject *clipboard; 112 GList *property; 113 GList *script; 114 GObject *cluster; 115 GObject *client; 116 GObject *server; 117 118 GObject *history; 119 120 GList *embedded_audio; 121 GList *file_link; 122 }; 123 124 struct _AgsFileClass 125 { 126 GObjectClass gobject; 127 128 void (*open)(AgsFile *file, 129 GError **error); 130 void (*open_from_data)(AgsFile *file, 131 gchar *data, guint length, 132 GError **error); 133 void (*rw_open)(AgsFile *file, 134 gboolean create, 135 GError **error); 136 137 void (*write)(AgsFile *file); 138 void (*write_concurrent)(AgsFile *file); 139 void (*write_resolve)(AgsFile *file); 140 141 void (*read)(AgsFile *file); 142 void (*read_resolve)(AgsFile *file); 143 void (*read_start)(AgsFile *file); 144 }; 145 146 GType ags_file_get_type(void); 147 GType ags_file_flags_get_type(); 148 149 void ags_file_set_filename(AgsFile *file, 150 gchar *filename); 151 gchar* ags_file_get_filename(AgsFile *file); 152 153 void ags_file_set_encoding(AgsFile *file, 154 gchar *encoding); 155 gchar* ags_file_get_encoding(AgsFile *file); 156 157 void ags_file_set_audio_format(AgsFile *file, 158 gchar *audio_format); 159 gchar* ags_file_get_audio_format(AgsFile *file); 160 161 void ags_file_set_audio_encoding(AgsFile *file, 162 gchar *audio_encoding); 163 gchar* ags_file_get_audio_encoding(AgsFile *file); 164 165 void ags_file_set_xml_doc(AgsFile *file, 166 xmlDoc *xml_doc); 167 xmlDoc* ags_file_get_xml_doc(AgsFile *file); 168 169 gchar* ags_file_str2md5(gchar *content, guint content_length); 170 171 void ags_file_add_id_ref(AgsFile *file, GObject *id_ref); 172 173 GObject* ags_file_find_id_ref_by_node(AgsFile *file, xmlNode *node); 174 GObject* ags_file_find_id_ref_by_xpath(AgsFile *file, gchar *xpath); 175 GObject* ags_file_find_id_ref_by_reference(AgsFile *file, gpointer ref); 176 177 void ags_file_add_lookup(AgsFile *file, GObject *file_lookup); 178 179 void ags_file_add_launch(AgsFile *file, GObject *file_launch); 180 181 /* */ 182 void ags_file_open(AgsFile *file, 183 GError **error); 184 void ags_file_open_from_data(AgsFile *file, 185 gchar *data, guint length, 186 GError **error); 187 void ags_file_rw_open(AgsFile *file, 188 gboolean create, 189 GError **error); 190 191 void ags_file_open_filename(AgsFile *file, 192 gchar *filename); 193 void ags_file_close(AgsFile *file); 194 195 /* */ 196 void ags_file_write(AgsFile *file); 197 void ags_file_write_concurrent(AgsFile *file); 198 void ags_file_write_resolve(AgsFile *file); 199 200 void ags_file_read(AgsFile *file); 201 void ags_file_read_resolve(AgsFile *file); 202 void ags_file_read_start(AgsFile *file); 203 204 void ags_file_read_config(AgsFile *file, xmlNode *node, GObject **ags_config); 205 void ags_file_write_config(AgsFile *file, xmlNode *parent, GObject *ags_config); 206 207 /* */ 208 void ags_file_read_application_context(AgsFile *file, xmlNode *node, GObject **application_context); 209 void ags_file_write_application_context(AgsFile *file, xmlNode *parent, GObject *application_context); 210 211 /* */ 212 AgsFile* ags_file_new(); 213 214 G_END_DECLS 215 216 #endif /*__AGS_FILE_H__*/ 217