aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/libapetag/apetaglib.h
blob: 15ec6e917abceb419fa0ac16255aeb42e835bdc1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
/********************************************************************
*    
* Copyright (c) 2002 Artur Polaczynski (Ar't)  All rights reserved.
*            <artii@o2.pl>        LGPL-2.1
*       $ArtId: apetaglib.h,v 1.30 2003/04/16 21:06:27 art Exp $
********************************************************************/
/*
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as 
 * published by the Free Software Foundation; either version 2.1 
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */


#ifndef _APETAGLIB_H
#define _APETAGLIB_H

/** \file
    \brief All function related to apetag
*/

// Uncomment this line to enable debug messages
//#define APE_TAG_DEBUG

#ifdef __WATCOMC__  // Watcom don't like || in ifdef and use #if define() || define()
#define USE_CHSIZE
#define strcasecmp(a,b) stricmp(a,b)
#define index(a,b) strchr(a,b)
#endif

#ifdef __WIN32__
#define USE_CHSIZE
#define strcasecmp(a,b) stricmp(a,b)
#define index(a,b) strchr(a,b)
#define S_IRGRP S_IRUSR
#define S_IWGRP S_IWUSR
#endif

/**\{*/
#ifdef APE_TAG_DEBUG
#define PRINT_D(x) fprintf( stdout, x )
#define PRINT_D1(x,a) fprintf( stdout, x, a )
#define PRINT_D2(x,a,b) fprintf( stdout, x, a,b)
#define PRINT_D3(x,a,b,c) fprintf( stdout, x, a,b,c)
#define PRINT_D4(x,a,b,c,d) fprintf( stdout, x, a,b,c,d)
#define PRINT_D5(x,a,b,c,d,e) fprintf( stdout, x, a,b,c,d,e)
#define PRINT_D6(x,a,b,c,d,e,f) fprintf( stdout, x, a,b,c,d,e,f)
#define PRINT_D7(x,a,b,c,d,e,f,g) fprintf( stdout, x, a,b,c,d,e,f,g)
#define PRINT_D8(x,a,b,c,d,e,f,g,i) fprintf( stdout, x, a,b,c,d,e,f,g,i)
#define PRINT_D9(x,a,b,c,d,e,f,g,i,j) fprintf( stdout, x ,a,b,c,d,e,f,g,i,j )
#else
#define PRINT_D(x) 
#define PRINT_D1(x,a)
#define PRINT_D2(x,a,b) 
#define PRINT_D3(x,a,b,c)
#define PRINT_D4(x,a,b,c,d) 
#define PRINT_D5(x,a,b,c,d,e) 
#define PRINT_D6(x,a,b,c,d,e,f)
#define PRINT_D7(x,a,b,c,d,e,f,g) 
#define PRINT_D8(x,a,b,c,d,e,f,g,i) 
#define PRINT_D9(x,a,b,c,d,e,f,g,i,j) 
#endif /*APE_TAG_DEBUG*/

#define PRINT_ERR(x) fprintf( stderr, x )
#define PRINT_ERR1(x, a) fprintf( stderr, x ,a)
/**\}*/

/** version of apetaglib defined in one place */
#define APETAGLIB_VERSION "0.5pre1"


/*from winamp mpc plugin*/
/** \name frame names */
/**\{*/
#define APE_TAG_FIELD_TITLE             "Title"
#define APE_TAG_FIELD_SUBTITLE          "Subtitle"
#define APE_TAG_FIELD_ARTIST            "Artist"
#define APE_TAG_FIELD_ALBUM             "Album"
#define APE_TAG_FIELD_DEBUTALBUM        "Debut Album"
#define APE_TAG_FIELD_PUBLISHER         "Publisher"
#define APE_TAG_FIELD_CONDUCTOR         "Conductor"
#define APE_TAG_FIELD_COMPOSER          "Composer"
#define APE_TAG_FIELD_COMMENT           "Comment"
#define APE_TAG_FIELD_YEAR              "Year"
#define APE_TAG_FIELD_RECORDDATE        "Record Date"
#define APE_TAG_FIELD_RECORDLOCATION    "Record Location"
#define APE_TAG_FIELD_TRACK             "Track"
#define APE_TAG_FIELD_GENRE             "Genre"
#define APE_TAG_FIELD_COVER_ART_FRONT   "Cover Art (front)"
#define APE_TAG_FIELD_NOTES             "Notes"
#define APE_TAG_FIELD_LYRICS            "Lyrics"
#define APE_TAG_FIELD_COPYRIGHT         "Copyright"
#define APE_TAG_FIELD_PUBLICATIONRIGHT  "Publicationright"
#define APE_TAG_FIELD_FILE              "File"
#define APE_TAG_FIELD_MEDIA             "Media"
#define APE_TAG_FIELD_EANUPC            "EAN/UPC"
#define APE_TAG_FIELD_ISRC              "ISRC"
#define APE_TAG_FIELD_RELATED_URL       "Related"
#define APE_TAG_FIELD_ABSTRACT_URL      "Abstract"
#define APE_TAG_FIELD_BIBLIOGRAPHY_URL  "Bibliography"
#define APE_TAG_FIELD_BUY_URL           "Buy URL"
#define APE_TAG_FIELD_ARTIST_URL        "Artist URL"
#define APE_TAG_FIELD_PUBLISHER_URL     "Publisher URL"
#define APE_TAG_FIELD_FILE_URL          "File URL"
#define APE_TAG_FIELD_COPYRIGHT_URL     "Copyright URL"
#define APE_TAG_FIELD_INDEX             "Index"
#define APE_TAG_FIELD_INTROPLAY         "Introplay"
#define APE_TAG_FIELD_MJ_METADATA       "Media Jukebox Metadata"
#define APE_TAG_FIELD_DUMMY             "Dummy"
/**\}*/

#define APE_TAG_LIB_FIRST   "\02"    /**< is using by #apefrm_get to get first frame */
#define APE_TAG_LIB_NEXT    "\03"    /**< is using by #apefrm_get to get next frame you may check all frames this way */
#define APE_TAG_LIB_DEL_ALL "\04"    /**< is using by #apefrm_remove_real for removing all frames */


/** 
    \name #apetag_save flags
    \note default is #APE_TAG_V2 + #SAVE_NEW_OLD_APE_TAG + #SAVE_REMOVE_ID3V1
*/
/**\{*/
#define APE_TAG_V1            (1 <<  1)
#define APE_TAG_V2            (1 <<  2)
#define SAVE_NEW_APE_TAG      (1 <<  3)
#define SAVE_NEW_OLD_APE_TAG  (1 <<  4)
#define SAVE_REMOVE_ID3V1     (1 <<  5)
#define SAVE_CREATE_ID3V1_TAG (1 <<  6)
#define SAVE_FAKE_SAVE        (1 <<  7)
/* apetag_read(_fp) flags - default read all (ape,id3v1,id3v2(if compiled)) */
#define DONT_READ_TAG_APE     (1 <<  8)
#define DONT_READ_TAG_ID3V1   (1 <<  9)
#define DONT_READ_TAG_ID3V2   (1 << 10)
/**\}*/


/**
    \name #atl_return
    \brief return codes from all functions
    \{
*/
#define     ATL_OK        0    /**< not using :) */
#define     ATL_FOPEN     1    /**< can't open file */
#define     ATL_FREAD     2    /**< can't read from file */
#define     ATL_FWRITE    3    /**< can't write to file (written bytes != bytes to write) */
#define     ATL_MALOC     4    /**< can't allocate memory */
#define     ATL_BADARG    5    /**< bad function argument */
#define     ATL_NOINIT    6    /**< not inited struct by apetag_init */
/** \} */

/** 
    \struct tag
    \brief tag  structure 

    i you get this <b>don't</b> change anything. copy all values/strings  
*/
struct tag
{
    char *name;          /**< name of tag */
    char *value;         /**< value of tag */
    size_t sizeName;     /**< size of name in tag */
    size_t sizeValue;    /**< size of value in tag */
    unsigned long flags; /**< flags of tag */
};


/** 
    object apetag used to store information about tag.
    main object store **#tag , number of frames, current position for 
    APE_TAG_LIB_NEXT, etc
    \brief object apetag used to store information about tag
**/
typedef struct _ape_mem_cnt  apetag;


/* 
 *  function:
 *  apetag_*: for load/save/init file and structure
 *  apefrm_*: for add del edit one (or more) 
 *          frame(, field, entry) in tag 
 */

/* read file and add frames */
int
apetag_read (apetag *mem_cnt, char *filename, int flag) ;

/* read file and add frames */
int 
apetag_read_fp (apetag *mem_cnt, FILE * fp, char *filename, int flag) ;

/* initialise new object #apetag and return */
apetag * 
apetag_init (void) ;

/* free #apetag object */
void 
apetag_free (apetag *mem_cnt) ;

/* save apetag to file */
int
apetag_save (char *filename, apetag *mem_cnt, int flag) ;


/* Add text frame */
int
apefrm_add (apetag *mem_cnt, unsigned long flags, char *name, char *value) ;

/* add binary frame */
int
apefrm_add_bin (apetag *mem_cnt, unsigned long flags,
                long sizeName, char *name, long sizeValue, char *value);

/* add frame if other (the same name) no exist */
int
apefrm_add_noreplace (apetag *mem_cnt, unsigned long flags, char *name, char *value) ;

/* search in apetag for name and return tag */
struct tag * 
apefrm_get (apetag *mem_cnt, char *name) ;

/* search in apetag for name and return string */
char * 
apefrm_getstr (apetag *mem_cnt, char *name) ;

/* remove frame from memory */
void 
apefrm_remove_real (apetag *mem_cnt, char *name) ;


/**
    \def apefrm_fake_remove(mem_cnt,name)
    \brief set frame to remove 
    \deprecated remove in 0.5
*/
#define     apefrm_fake_remove(mem_cnt,name)  apefrm_remove(mem_cnt,name)

/* set frame to remove */
void
apefrm_remove (apetag *mem_cnt, char *name);

/* read id3v1 and add frames */
int 
readtag_id3v1_fp (apetag *mem_cnt, FILE * fp) ;

/** \name flags in frames and headers */ 
/**\{*/
//================================
#define HEADER_IS        0x80000000   
#define HEADER_NOT       0x00000000 
#define HEADER_THIS_IS   0x20000000  
//================================
#define FOOTER_IS        0x00000000
#define FOOTER_NOT       0x40000000
#define FOOTER_THIS_IS   0x00000000
//================================
#define ITEM_TEXT        0x00000000
#define ITEM_BIN         0x00000002   
#define ITEM_LINK        0x00000004
#define ITEM_URL         0x00000004 // for compability ITEM_LINK
//================================
#define TAG_RW           0x00000000
#define TAG_RO           0x00000001
/**\}*/

/* debug function print all tags exclude bin (print only size for bin) */
void
libapetag_print_mem_cnt (apetag *mem_cnt);

#endif /* _APETAGLIB_H */