annotate src/wavpack/tags.cxx @ 3052:95b34f46a231

Comment out MPEG2/MPEG4 determination using the variable id. It is not used anywhere. Code analysis run, unique ID 6nYoHM.
author Tony Vroon <chainsaw@gentoo.org>
date Sat, 18 Apr 2009 19:06:20 +0100
parents 3134a0987162
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
1 #include <stdlib.h>
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
2 #include <stdio.h>
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
3 #include <string.h>
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
4 #include <unistd.h>
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
5 #include <fcntl.h>
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
6 #include <wchar.h>
2971
3134a0987162 - changed include path from audacious to audlegacy.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 2576
diff changeset
7 #include <audlegacy/plugin.h>
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
8 #include "tags.h"
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
9
2233
0de647993c2a - make use of AUDDBG
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2001
diff changeset
10 static const char* GenreList [] = {
0de647993c2a - make use of AUDDBG
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2001
diff changeset
11 "Blues", "Classic Rock", "Country", "Dance", "Disco", "Funk", "Grunge",
0de647993c2a - make use of AUDDBG
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2001
diff changeset
12 "Hip-Hop", "Jazz", "Metal", "New Age", "Oldies", "Other", "Pop", "R&B",
0de647993c2a - make use of AUDDBG
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2001
diff changeset
13 "Rap", "Reggae", "Rock", "Techno", "Industrial", "Alternative", "Ska",
0de647993c2a - make use of AUDDBG
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2001
diff changeset
14 "Death Metal", "Pranks", "Soundtrack", "Euro-Techno", "Ambient",
0de647993c2a - make use of AUDDBG
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2001
diff changeset
15 "Trip-Hop", "Vocal", "Jazz+Funk", "Fusion", "Trance", "Classical",
0de647993c2a - make use of AUDDBG
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2001
diff changeset
16 "Instrumental", "Acid", "House", "Game", "Sound Clip", "Gospel", "Noise",
0de647993c2a - make use of AUDDBG
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2001
diff changeset
17 "AlternRock", "Bass", "Soul", "Punk", "Space", "Meditative",
0de647993c2a - make use of AUDDBG
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2001
diff changeset
18 "Instrumental Pop", "Instrumental Rock", "Ethnic", "Gothic", "Darkwave",
0de647993c2a - make use of AUDDBG
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2001
diff changeset
19 "Techno-Industrial", "Electronic", "Pop-Folk", "Eurodance", "Dream",
0de647993c2a - make use of AUDDBG
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2001
diff changeset
20 "Southern Rock", "Comedy", "Cult", "Gangsta", "Top 40", "Christian Rap",
0de647993c2a - make use of AUDDBG
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2001
diff changeset
21 "Pop/Funk", "Jungle", "Native American", "Cabaret", "New Wave",
0de647993c2a - make use of AUDDBG
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2001
diff changeset
22 "Psychadelic", "Rave", "Showtunes", "Trailer", "Lo-Fi", "Tribal",
0de647993c2a - make use of AUDDBG
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2001
diff changeset
23 "Acid Punk", "Acid Jazz", "Polka", "Retro", "Musical", "Rock & Roll",
0de647993c2a - make use of AUDDBG
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2001
diff changeset
24 "Hard Rock", "Folk", "Folk/Rock", "National Folk", "Swing", "Fast-Fusion",
0de647993c2a - make use of AUDDBG
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2001
diff changeset
25 "Bebob", "Latin", "Revival", "Celtic", "Bluegrass", "Avantgarde",
0de647993c2a - make use of AUDDBG
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2001
diff changeset
26 "Gothic Rock", "Progressive Rock", "Psychedelic Rock", "Symphonic Rock",
0de647993c2a - make use of AUDDBG
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2001
diff changeset
27 "Slow Rock", "Big Band", "Chorus", "Easy Listening", "Acoustic", "Humour",
0de647993c2a - make use of AUDDBG
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2001
diff changeset
28 "Speech", "Chanson", "Opera", "Chamber Music", "Sonata", "Symphony",
0de647993c2a - make use of AUDDBG
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2001
diff changeset
29 "Booty Bass", "Primus", "Porn Groove", "Satire", "Slow Jam", "Club",
0de647993c2a - make use of AUDDBG
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2001
diff changeset
30 "Tango", "Samba", "Folklore", "Ballad", "Power Ballad", "Rhythmic Soul",
0de647993c2a - make use of AUDDBG
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2001
diff changeset
31 "Freestyle", "Duet", "Punk Rock", "Drum Solo", "A capella", "Euro-House",
0de647993c2a - make use of AUDDBG
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2001
diff changeset
32 "Dance Hall", "Goa", "Drum & Bass", "Club House", "Hardcore", "Terror",
0de647993c2a - make use of AUDDBG
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2001
diff changeset
33 "Indie", "BritPop", "NegerPunk", "Polsk Punk", "Beat", "Christian Gangsta",
0de647993c2a - make use of AUDDBG
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2001
diff changeset
34 "Heavy Metal", "Black Metal", "Crossover", "Contemporary C",
0de647993c2a - make use of AUDDBG
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2001
diff changeset
35 "Christian Rock", "Merengue", "Salsa", "Thrash Metal", "Anime", "JPop",
0de647993c2a - make use of AUDDBG
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2001
diff changeset
36 "SynthPop"
0de647993c2a - make use of AUDDBG
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2001
diff changeset
37 };
0de647993c2a - make use of AUDDBG
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents: 2001
diff changeset
38
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
39 struct APETagFooterStruct {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
40 unsigned char ID[8];
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
41 unsigned char Version[4];
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
42 unsigned char Length[4];
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
43 unsigned char TagCount[4];
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
44 unsigned char Flags[4];
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
45 unsigned char Reserved[8];
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
46 };
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
47
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
48 typedef struct {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
49 char *key;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
50 size_t keylen;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
51 unsigned char *value;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
52 size_t valuelen;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
53 unsigned int flags;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
54 } TagItem;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
55
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
56 unsigned long
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
57 Read_LE_Uint32(const unsigned char *p)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
58 {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
59 return ((unsigned long) p[0] << 0) |
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
60 ((unsigned long) p[1] << 8) |
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
61 ((unsigned long) p[2] << 16) | ((unsigned long) p[3] << 24);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
62 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
63
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
64 // Convert UTF-8 coded string to UNICODE
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
65 // Return number of characters converted
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
66 int
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
67 utf8ToUnicode(const char *lpMultiByteStr, wchar_t * lpWideCharStr,
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
68 int cmbChars)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
69 {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
70 const unsigned char *pmb = (unsigned char *) lpMultiByteStr;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
71 unsigned short *pwc = (unsigned short *) lpWideCharStr;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
72 const unsigned char *pmbe;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
73 size_t cwChars = 0;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
74
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
75 if (cmbChars >= 0) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
76 pmbe = pmb + cmbChars;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
77 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
78 else {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
79 pmbe = NULL;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
80 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
81
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
82 while ((pmbe == NULL) || (pmb < pmbe)) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
83 char mb = *pmb++;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
84 unsigned int cc = 0;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
85 unsigned int wc;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
86
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
87 while ((cc < 7) && (mb & (1 << (7 - cc)))) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
88 cc++;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
89 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
90
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
91 if (cc == 1 || cc > 6) // illegal character combination for UTF-8
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
92 continue;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
93
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
94 if (cc == 0) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
95 wc = mb;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
96 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
97 else {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
98 wc = (mb & ((1 << (7 - cc)) - 1)) << ((cc - 1) * 6);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
99 while (--cc > 0) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
100 if (pmb == pmbe) // reached end of the buffer
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
101 return cwChars;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
102 mb = *pmb++;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
103 if (((mb >> 6) & 0x03) != 2) // not part of multibyte character
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
104 return cwChars;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
105 wc |= (mb & 0x3F) << ((cc - 1) * 6);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
106 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
107 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
108
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
109 if (wc & 0xFFFF0000)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
110 wc = L'?';
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
111 *pwc++ = wc;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
112 cwChars++;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
113 if (wc == L'\0')
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
114 return cwChars;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
115 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
116
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
117 return cwChars;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
118 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
119
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
120 void
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
121 tag_insert(char *buffer, const char *value, long unsigned int len,
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
122 long unsigned int maxlen, bool decode_utf8)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
123 {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
124 char *p;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
125 wchar_t wValue[MAX_LEN];
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
126 char temp[MAX_LEN];
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
127 long unsigned int c;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
128 const wchar_t *src = wValue;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
129
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
130 if (len >= maxlen)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
131 len = maxlen - 1;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
132 if (decode_utf8) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
133 if ((c = utf8ToUnicode(value, wValue, len)) <= 0)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
134 return;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
135 if (wValue[c] != L'\0')
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
136 wValue[c++] = L'\0';
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
137 if ((c = wcsrtombs(temp, &src, MAX_LEN, NULL)) == 0)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
138 return;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
139 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
140 else {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
141 c = len;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
142 strncpy(temp, value, len);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
143 while (temp[len - 1] == 0x20 || len < 1) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
144 len--;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
145 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
146 temp[len] = '\0';
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
147 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
148
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
149 //if ( *buffer == '\0' ) { // new value
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
150 p = buffer;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
151 //} else { // append to existing value
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
152 // p = strchr (buffer, '\0' );
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
153 // p += sprintf ( p, ", " );
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
154 //}
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
155
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
156 if ((p - buffer) + c >= maxlen)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
157 c = maxlen - (p - buffer) - 1;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
158 strncpy(p, temp, c);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
159 p[c] = '\0';
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
160 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
161
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
162 // Returns the Type of Tag (Ape or ID3)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
163 int
265
32de2fc2270a [svn] - use VFS here
nenolod
parents: 109
diff changeset
164 GetTageType(VFSFile * fp)
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
165 {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
166 struct APETagFooterStruct T;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
167 unsigned char tagheader[3];
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
168 int size;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
169
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
170 if (fp == NULL) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
171 return TAG_NONE;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
172 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
173
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1677
diff changeset
174 if (aud_vfs_fseek(fp, 0, SEEK_END) != 0)
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
175 return TAG_NONE;
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1677
diff changeset
176 size = aud_vfs_ftell(fp);
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1677
diff changeset
177 if (aud_vfs_fseek(fp, size - sizeof T, SEEK_SET) != 0)
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
178 return TAG_NONE;
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1677
diff changeset
179 if (aud_vfs_fread(&T, 1, sizeof T, fp) != sizeof T)
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
180 return TAG_NONE;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
181 if (memcmp(T.ID, "APETAGEX", sizeof T.ID) == 0)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
182 return TAG_APE;
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1677
diff changeset
183 if (aud_vfs_fseek(fp, -128L, SEEK_END) != 0)
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
184 return TAG_NONE;
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1677
diff changeset
185 if (aud_vfs_fread(tagheader, 1, 3, fp) != 3)
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
186 return TAG_NONE;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
187 if (0 == memcmp(tagheader, "TAG", 3))
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
188 return TAG_ID3;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
189 return TAG_NONE;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
190 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
191
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
192
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
193 int
265
32de2fc2270a [svn] - use VFS here
nenolod
parents: 109
diff changeset
194 ReadID3Tag(VFSFile * fp, ape_tag * Tag)
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
195 {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
196 char *tag;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
197 char *buff;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
198 unsigned int genre;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
199
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
200 buff = (char *) malloc(128);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
201
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
202 *(Tag->title) = '\0';
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
203 *(Tag->artist) = '\0';
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
204 *(Tag->album) = '\0';
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
205 *(Tag->comment) = '\0';
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
206 *(Tag->genre) = '\0';
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
207 *(Tag->track) = '\0';
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
208 *(Tag->year) = '\0';
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
209
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1677
diff changeset
210 if (aud_vfs_fseek(fp, -128L, SEEK_END) != 0)
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
211 return 0;
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1677
diff changeset
212 if (aud_vfs_fread(buff, 1, 128, fp) != 128)
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
213 return 0;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
214 tag = buff;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
215 tag_insert(Tag->title, (tag + 3), 30, 32, false);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
216 tag_insert(Tag->artist, (tag + 33), 30, 32, false);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
217 tag_insert(Tag->album, (tag + 63), 30, 32, false);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
218 tag_insert(Tag->year, (tag + 93), 4, 32, false);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
219 tag_insert(Tag->comment, (tag + 97), 30, 32, false);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
220 genre = (unsigned char) tag[127];
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
221 if (genre >= sizeof(GenreList) / sizeof(int))
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
222 genre = 12;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
223 tag_insert(Tag->genre, GenreList[genre], 30, 32, false);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
224 sprintf(tag, "%u", tag[126]);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
225 tag_insert(Tag->track, tag, 30, 32, false);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
226 free(buff);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
227 return 1;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
228 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
229
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
230 // Reads APE v2.0 tag
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
231 int
265
32de2fc2270a [svn] - use VFS here
nenolod
parents: 109
diff changeset
232 ReadAPE2Tag(VFSFile * fp, ape_tag * Tag)
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
233 {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
234 unsigned long vsize;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
235 unsigned long isize;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
236 unsigned long flags;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
237 unsigned char *buff;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
238 unsigned char *p;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
239 unsigned char *end;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
240 struct APETagFooterStruct T;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
241 unsigned long TagLen;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
242 unsigned long TagCount;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
243 long size;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
244
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
245 *(Tag->title) = '\0';
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
246 *(Tag->artist) = '\0';
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
247 *(Tag->album) = '\0';
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
248 *(Tag->comment) = '\0';
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
249 *(Tag->genre) = '\0';
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
250 *(Tag->track) = '\0';
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
251 *(Tag->year) = '\0';
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
252
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1677
diff changeset
253 if (aud_vfs_fseek(fp, 0, SEEK_END) != 0)
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
254 return 0;
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1677
diff changeset
255 size = aud_vfs_ftell(fp);
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1677
diff changeset
256 if (aud_vfs_fseek(fp, size - sizeof T, SEEK_SET) != 0)
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
257 return 0;
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1677
diff changeset
258 if (aud_vfs_fread(&T, 1, sizeof T, fp) != sizeof T)
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
259 return 0;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
260 if (memcmp(T.ID, "APETAGEX", sizeof T.ID) != 0)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
261 return 0;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
262 if (Read_LE_Uint32(T.Version) != 2000)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
263 return 0;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
264 TagLen = Read_LE_Uint32(T.Length);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
265 if (TagLen < sizeof T)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
266 return 0;
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1677
diff changeset
267 if (aud_vfs_fseek(fp, size - TagLen, SEEK_SET) != 0)
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
268 return 0;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
269 if ((buff = (unsigned char *) malloc(TagLen)) == NULL)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
270 return 0;
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1677
diff changeset
271 if (aud_vfs_fread(buff, 1, TagLen - sizeof T, fp) != TagLen - sizeof T) {
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
272 free(buff);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
273 return 0;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
274 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
275
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
276 TagCount = Read_LE_Uint32(T.TagCount);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
277 end = buff + TagLen - sizeof(T);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
278 for (p = buff; p < end && TagCount--;) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
279 vsize = Read_LE_Uint32(p);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
280 p += 4;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
281 flags = Read_LE_Uint32(p);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
282 p += 4;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
283 isize = strlen((char *) p);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
284
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
285 if (isize > 0 && vsize > 0) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
286 if (!(flags & 1 << 1)) { // insert UTF-8 string (skip binary values)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
287 if (!strcasecmp((char *) p, "Title")) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
288 tag_insert(Tag->title, (char *) (p + isize + 1), vsize,
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
289 MAX_LEN, false);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
290 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
291 else if (!strcasecmp((char *) p, "Artist")) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
292 tag_insert(Tag->artist, (char *) (p + isize + 1), vsize,
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
293 MAX_LEN, false);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
294 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
295 else if (!strcasecmp((char *) p, "Album")) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
296 tag_insert(Tag->album, (char *) (p + isize + 1), vsize,
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
297 MAX_LEN, false);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
298 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
299 else if (!strcasecmp((char *) p, "Comment")) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
300 tag_insert(Tag->comment, (char *) (p + isize + 1), vsize,
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
301 MAX_LEN, false);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
302 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
303 else if (!strcasecmp((char *) p, "Genre")) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
304 tag_insert(Tag->genre, (char *) (p + isize + 1), vsize,
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
305 MAX_LEN, false);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
306 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
307 else if (!strcasecmp((char *) p, "Track")) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
308 tag_insert(Tag->track, (char *) (p + isize + 1), vsize,
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
309 128, false);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
310 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
311 else if (!strcasecmp((char *) p, "Year")) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
312 tag_insert(Tag->year, (char *) (p + isize + 1), vsize,
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
313 128, false);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
314 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
315 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
316 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
317 p += isize + 1 + vsize;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
318 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
319 free(buff);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
320 return 1;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
321 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
322
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
323 int
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
324 DeleteTag(char *filename)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
325 {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
326
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1677
diff changeset
327 VFSFile *fp = aud_vfs_fopen(filename, "rb+");
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
328 int tagtype;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
329 int fd;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
330 long filelength = 0;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
331 long dellength = -1;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
332 char *tagheader;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
333 unsigned long *apelength;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
334 int res = -1;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
335
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
336 if (fp == NULL) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
337 char text[256];
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
338
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
339 sprintf(text, "File \"%s\" not found or is read protected!\n",
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
340 filename);
1677
f6f5603a0954 xmms_show_message() changed to audacious_info_dialog()
Matti Hamalainen <ccr@tnsp.org>
parents: 1159
diff changeset
341 audacious_info_dialog("File-Error", (gchar *) text, "Ok", FALSE, NULL,
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
342 NULL);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
343 return -1;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
344 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
345 tagtype = GetTageType(fp);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
346
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
347 // get Length of File
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1677
diff changeset
348 aud_vfs_fseek(fp, 0L, SEEK_END);
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1677
diff changeset
349 filelength = aud_vfs_ftell(fp);
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
350
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
351 apelength = (unsigned long *) malloc(4);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
352 tagheader = (char *) malloc(9);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
353
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
354 if (tagtype == TAG_ID3) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
355 dellength = 128L;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
356 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
357 else if (tagtype == TAG_APE) {
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1677
diff changeset
358 aud_vfs_fseek(fp, -32L, SEEK_END);
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1677
diff changeset
359 aud_vfs_fread(tagheader, 8, 1, fp);
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
360 if (0 == memcmp(tagheader, "APETAGEX", 8)) {
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1677
diff changeset
361 aud_vfs_fseek(fp, -20L, SEEK_END);
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1677
diff changeset
362 aud_vfs_fread(apelength, 4, 1, fp);
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
363 dellength = *apelength + 32;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
364 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
365 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
366
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
367
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
368 if (dellength > -1) //if TAG was found, delete it
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
369 {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
370 fd = open(filename, O_RDWR);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
371 res = ftruncate(fd, (off_t) (filelength - dellength));
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
372 close(fd);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
373 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
374
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
375 free(tagheader);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
376 free(apelength);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
377
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
378 //returns 0 if everything is ok
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
379 return res;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
380 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
381
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
382 // Returns bytes used in APE-Tag for this value
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
383 int
1044
b1128efde471 [svn] - get rid of all warnings gcc 4.2.0 emits with my build configuration.
yaz
parents: 265
diff changeset
384 addValue(TagItem * item, const char *key, char *value)
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
385 {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
386 item->keylen = strlen(key);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
387 item->valuelen = strlen(value);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
388 item->key = (char *) malloc(item->keylen + 1);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
389 item->value = (unsigned char *) malloc(item->valuelen + 1);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
390 strcpy((char *) item->value, value);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
391 strcpy(item->key, key);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
392 item->flags = 0;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
393 return (9 + item->keylen + item->valuelen);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
394 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
395
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
396 int
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
397 WriteAPE2Tag(char *filename, ape_tag * Tag)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
398 {
265
32de2fc2270a [svn] - use VFS here
nenolod
parents: 109
diff changeset
399 VFSFile *fp;
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
400 unsigned char H[32] = "APETAGEX";
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
401 unsigned long Version = 2000;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
402 unsigned char dw[8];
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
403 unsigned long estimatedbytes = 32; // 32 byte footer + all items, these are the 32 bytes footer, the items are added later
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
404 long writtenbytes = -32; // actually writtenbytes-32, which should be equal to estimatedbytes (= footer + all items)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
405 unsigned int TagCount = 0;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
406 TagItem T[7];
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
407
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
408
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
409 // Delete Tag if there is one
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1677
diff changeset
410 fp = aud_vfs_fopen(filename, "rb+");
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
411 if (fp == NULL) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
412 char text[256];
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
413
1159
a03aec49af4d [svn] Replace sprintf with snprintf.
js
parents: 1044
diff changeset
414 snprintf(text, 256, "File \"%s\" not found or is read protected!\n",
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
415 filename);
1677
f6f5603a0954 xmms_show_message() changed to audacious_info_dialog()
Matti Hamalainen <ccr@tnsp.org>
parents: 1159
diff changeset
416 audacious_info_dialog("File-Error", (gchar *) text, "Ok", FALSE, NULL,
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
417 NULL);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
418 return -1;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
419 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
420
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
421 int tagtype = GetTageType(fp);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
422
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
423 if (tagtype != TAG_NONE)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
424 if (DeleteTag(filename) != 0)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
425 return 0;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
426
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
427 // Produce TagItem-Array
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
428 if (strlen(Tag->title) > 0) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
429 char *value = (char *) malloc(strlen(Tag->title) + 1);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
430
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
431 strcpy(value, Tag->title);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
432 int res = addValue(&T[TagCount], "Title", value);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
433
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
434 estimatedbytes += res;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
435 if (res > 0)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
436 TagCount++;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
437 free(value);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
438 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
439
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
440 if (strlen(Tag->artist) > 0) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
441 char *value = (char *) malloc(strlen(Tag->artist) + 1);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
442
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
443 strcpy(value, Tag->artist);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
444 int res = addValue(&T[TagCount], "Artist", value);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
445
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
446 estimatedbytes += res;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
447 if (res > 0)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
448 TagCount++;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
449 free(value);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
450 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
451
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
452 if (strlen(Tag->album) > 0) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
453 char *value = (char *) malloc(strlen(Tag->album) + 1);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
454
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
455 strcpy(value, Tag->album);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
456 int res = addValue(&T[TagCount], "Album", value);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
457
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
458 estimatedbytes += res;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
459 if (res > 0)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
460 TagCount++;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
461 free(value);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
462 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
463
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
464 if (strlen(Tag->comment) > 0) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
465 char *value = (char *) malloc(strlen(Tag->comment) + 1);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
466
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
467 strcpy(value, Tag->comment);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
468 int res = addValue(&T[TagCount], "Comment", value);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
469
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
470 estimatedbytes += res;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
471 if (res > 0)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
472 TagCount++;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
473 free(value);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
474 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
475
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
476 if (strlen(Tag->genre) > 0) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
477 char *value = (char *) malloc(strlen(Tag->genre) + 1);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
478
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
479 strcpy(value, Tag->genre);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
480 int res = addValue(&T[TagCount], "Genre", value);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
481
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
482 estimatedbytes += res;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
483 if (res > 0)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
484 TagCount++;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
485 free(value);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
486 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
487
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
488 if (strlen(Tag->track) > 0) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
489 char *value = (char *) malloc(strlen(Tag->track) + 1);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
490
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
491 strcpy(value, Tag->track);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
492 int res = addValue(&T[TagCount], "Track", value);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
493
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
494 estimatedbytes += res;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
495 if (res > 0)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
496 TagCount++;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
497 free(value);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
498 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
499
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
500 if (strlen(Tag->year) > 0) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
501 char *value = (char *) malloc(strlen(Tag->year) + 1);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
502
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
503 strcpy(value, Tag->year);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
504 int res = addValue(&T[TagCount], "Year", value);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
505
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
506 estimatedbytes += res;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
507 if (res > 0)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
508 TagCount++;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
509 free(value);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
510 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
511 // Start writing the new Ape2 Tag
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1677
diff changeset
512 aud_vfs_fseek(fp, 0L, SEEK_END);
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
513
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
514 if (TagCount == 0) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
515 printf("no tag to write");
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
516 return 0;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
517 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
518
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
519 if (estimatedbytes >= 8192 + 103) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
520 printf
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
521 ("\nTag is %.1f Kbyte long. This is longer than the maximum recommended 8 KByte.\n\a",
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
522 estimatedbytes / 1024.);
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
523 return 0;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
524 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
525
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
526 H[8] = Version >> 0;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
527 H[9] = Version >> 8;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
528 H[10] = Version >> 16;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
529 H[11] = Version >> 24;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
530 H[12] = estimatedbytes >> 0;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
531 H[13] = estimatedbytes >> 8;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
532 H[14] = estimatedbytes >> 16;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
533 H[15] = estimatedbytes >> 24;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
534 H[16] = TagCount >> 0;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
535 H[17] = TagCount >> 8;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
536 H[18] = TagCount >> 16;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
537 H[19] = TagCount >> 24;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
538
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
539 H[23] = 0x80 | 0x20;
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1677
diff changeset
540 writtenbytes += aud_vfs_fwrite(H, 1, 32, fp);
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
541
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
542 for (unsigned int i = 0; i < TagCount; i++) {
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
543 dw[0] = T[i].valuelen >> 0;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
544 dw[1] = T[i].valuelen >> 8;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
545 dw[2] = T[i].valuelen >> 16;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
546 dw[3] = T[i].valuelen >> 24;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
547 dw[4] = T[i].flags >> 0;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
548 dw[5] = T[i].flags >> 8;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
549 dw[6] = T[i].flags >> 16;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
550 dw[7] = T[i].flags >> 24;
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1677
diff changeset
551 writtenbytes += aud_vfs_fwrite(dw, 1, 8, fp);
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1677
diff changeset
552 writtenbytes += aud_vfs_fwrite(T[i].key, 1, T[i].keylen, fp);
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1677
diff changeset
553 writtenbytes += aud_vfs_fwrite("", 1, 1, fp);
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
554 if (T[i].valuelen > 0)
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1677
diff changeset
555 writtenbytes += aud_vfs_fwrite(T[i].value, 1, T[i].valuelen, fp);
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
556 }
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
557
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
558 H[23] = 0x80;
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1677
diff changeset
559 writtenbytes += aud_vfs_fwrite(H, 1, 32, fp);
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
560
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
561 if (estimatedbytes != (unsigned long) writtenbytes)
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
562 printf("\nError writing APE tag.\n");
1978
fa9f85cebade s/vfs_/aud_vfs_/g
William Pitcock <nenolod@atheme.org>
parents: 1677
diff changeset
563 aud_vfs_fclose(fp);
109
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
564 TagCount = 0;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
565 return 0;
38ce41606f10 [svn] - wavpack input plugin -- under construction
nenolod
parents:
diff changeset
566 }