1 #ifndef AUDIO_FILE_H
2 #define AUDIO_FILE_H
3 
4 #include <stdio.h>
5 
6 
7 /*** private stuff ******************************************************/
8 
9 /* file types */
10 #define AF_MPEG   0
11 #define AF_VORBIS 1
12 
13 typedef void		(*af_delete_func)	 (void*);
14 typedef const gchar *	(*af_get_desc_func)	 (void*);
15 typedef const gchar *	(*af_get_info_func)	 (void*);
16 typedef gboolean	(*af_has_tag_func)	 (void*);
17 typedef void		(*af_create_tag_func)	 (void*);
18 typedef void		(*af_remove_tag_func)	 (void*);
19 typedef int		(*af_write_changes_func) (void*);
20 typedef int		(*af_set_field_func)	 (void*, int, const char*);
21 typedef int		(*af_get_field_func)	 (void*, int, const char**);
22 typedef void		(*af_dump_func)		 (void*);
23 typedef void		(*af_edit_load_func)	 (void*);
24 typedef void		(*af_edit_unload_func)	 ();
25 
26 typedef struct {
27 	guint8 type;
28 	FILE *file;
29 	char *name;
30 	gboolean editable;
31 	gboolean changed;
32 
33 	af_delete_func		delete;
34 	af_get_desc_func	get_desc;
35 	af_get_info_func	get_info;
36 	af_has_tag_func		has_tag;
37 	af_create_tag_func	create_tag;
38 	af_remove_tag_func	remove_tag;
39 	af_write_changes_func	write_changes;
40 	af_set_field_func	set_field;
41 	af_get_field_func	get_field;
42 	af_dump_func		dump;
43 	af_edit_load_func	edit_load;
44 	af_edit_unload_func	edit_unload;
45 
46 } audio_file;
47 
48 
49 /*** public stuff ******************************************************/
50 
51 /* tag fields */
52 #define AF_TITLE	0
53 #define AF_ARTIST	1
54 #define AF_ALBUM	2
55 #define AF_YEAR		3
56 #define AF_GENRE	4
57 #define AF_COMMENT	5
58 #define AF_TRACK	6
59 
60 /* return codes */
61 #define AF_OK		0
62 #define AF_ERR_FILE	1
63 #define AF_ERR_FORMAT	2
64 #define AF_ERR_READONLY	3
65 #define AF_ERR_NO_TAG	4
66 #define AF_ERR_NO_FIELD	5
67 
68 
69 /*
70  * Creates an audio_file.
71  *
72  * <f>		Adress of the pointer that will hold the new audio_file
73  * <filename>	Name of the file to open
74  * <writable>	TRUE to open the file for writing, FALSE to open read-only.
75  *
76  * return	AF_OK on success
77  *		AF_ERR_FORMAT if file is not a recognized audio format
78  *		AF_ERR_FILE if there was a filesystem error (errno will be set)
79  */
80 int audio_file_new(audio_file **f, const char *filename, gboolean editable);
81 
82 /*
83  * Frees an audio_file and associated data.
84  */
85 void audio_file_delete(audio_file *f);
86 
87 /*
88  * Returns the file name.
89  * Return value points to an internal string and must not be modified.
90  */
91 const gchar *audio_file_get_name(audio_file *f);
92 
93 /*
94  * Returns the file name extension of this file (incl. dot), e.g. ".mp3"
95  * Return value points to an internal string and must not be modified.
96  */
97 const gchar *audio_file_get_extension(audio_file *f);
98 
99 /*
100  * Returns TRUE if the file was opened for editing, FALSE if it is read-only.
101  */
102 gboolean audio_file_is_editable(audio_file *f);
103 
104 /*
105  * Gets a string description of the file type, e.g. "MPEG Version 1, Layer 3"
106  *
107  * return	String description. Points to an internal buffer valid
108  * 		until the next call.
109  */
110 const gchar *audio_file_get_desc(audio_file *f);
111 
112 /*
113  * Gets a strings with a list of properties. The property names and values
114  * alternate, each on its own line, e.g. "NAME1\nVALUE1\nNAME2\nNAME2"
115  *
116  * return	String. Points to an internal buffer valid until the
117  *		next call.
118  */
119 const gchar *audio_file_get_info(audio_file *f);
120 
121 /*
122  * Returns TRUE if file has a tag.
123  */
124 gboolean audio_file_has_tag(audio_file *f);
125 
126 /*
127  * Returns TRUE if tag has changes that need to be saved.
128  */
129 gboolean audio_file_has_changes(audio_file *f);
130 
131 /*
132  * Creates the tag if it did not already exist. Nothing is written to file
133  * until audio_file_write_changes() is called.
134  */
135 void audio_file_create_tag(audio_file *f);
136 
137 /*
138  * Removes the tag. Nothing is written to file until audio_file_write_changes()
139  * is called.
140  */
141 void audio_file_remove_tag(audio_file *f);
142 
143 /*
144  * Writes tag changes to file.
145  *
146  * return	AF_OK on success
147  *		AF_ERR_READONLY if file was opened for reading
148  *		AF_ERR_FILE if there was a filesystem error (errno will be set)
149  */
150 int audio_file_write_changes(audio_file *f);
151 
152 /*
153  * Sets the value of a tag field. Nothing is written to file until
154  * audio_file_write_changes() is called.
155  *
156  * <field>	Tag field to set
157  * <value>	New value (will be copied)
158  *
159  * return	AF_OK on success
160  *		AF_ERR_NO_TAG if file has no tag
161  *		AF_ERR_NO_FIELD if <field> is invalid
162  */
163 int audio_file_set_field(audio_file *f, int field, const char *value);
164 
165 /*
166  * Gets the value of a tag field. The pointer stored in <value> will point
167  * to internal data and must not be modified.
168  *
169  * <field>	Tag field to get
170  * <value>	Adress of a pointer that will hold the adress of the data.
171  *		Valid only until the field is modified or audio_file_get_field()
172  *		is called again.
173  *
174  * return	AF_OK on success
175  *		AF_ERR_NO_TAG if file has no tag
176  *		AF_ERR_NO_FIELD if <field> is invalid
177  */
178 int audio_file_get_field(audio_file *f, int field, const char **value);
179 
180 /*
181  * Dumps all available information on an audio_file to stdout
182  */
183 void audio_file_dump(audio_file *f);
184 
185 /*
186  * Loads a file to be edited in the "Edit Tag" tab.
187  */
188 void audio_file_edit_load(audio_file *f);
189 
190 /*
191  * Unloads the file being edited in the "Edit Tag" tab.
192  */
193 void audio_file_edit_unload(audio_file *f);
194 
195 
196 #endif
197