major plugin revamp based on x-fixer's code
[flac.git] / src / plugin_common / id3v1.c
1 /* plugin_common - Routines common to several plugins\r
2  * Copyright (C) 2002,2003,2004  Josh Coalson\r
3  *\r
4  * This program is free software; you can redistribute it and/or\r
5  * modify it under the terms of the GNU General Public License\r
6  * as published by the Free Software Foundation; either version 2\r
7  * of the License, or (at your option) any later version.\r
8  *\r
9  * This program is distributed in the hope that it will be useful,\r
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
12  * GNU General Public License for more details.\r
13  *\r
14  * You should have received a copy of the GNU General Public License\r
15  * along with this program; if not, write to the Free Software\r
16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\r
17  */\r
18 \r
19 #include <stdio.h>\r
20 \r
21 #include "FLAC/assert.h"\r
22 #include "id3v1.h"\r
23 #include "locale_hack.h"\r
24 \r
25 \r
26 /*\r
27  * Do not sort genres!!\r
28  * Last Update: 2000/04/30\r
29  */\r
30 static const char * const FLAC_plugin__id3v1_tag_genre_table[] =\r
31 {\r
32         "Blues",                /* 0 */\r
33         "Classic Rock",\r
34         "Country",\r
35         "Dance",\r
36         "Disco",\r
37         "Funk",                 /* 5 */\r
38         "Grunge",\r
39         "Hip-Hop",\r
40         "Jazz",\r
41         "Metal",\r
42         "New Age",              /* 10 */                \r
43         "Oldies",\r
44         "Other",\r
45         "Pop",\r
46         "R&B",\r
47         "Rap",                  /* 15 */\r
48         "Reggae",\r
49         "Rock",\r
50         "Techno",\r
51         "Industrial",\r
52         "Alternative",          /* 20 */\r
53         "Ska",\r
54         "Death Metal",\r
55         "Pranks",\r
56         "Soundtrack",\r
57         "Euro-Techno",          /* 25 */\r
58         "Ambient",\r
59         "Trip-Hop",\r
60         "Vocal",\r
61         "Jazz+Funk",\r
62         "Fusion",               /* 30 */\r
63         "Trance",\r
64         "Classical",\r
65         "Instrumental",\r
66         "Acid",\r
67         "House",                /* 35 */\r
68         "Game",\r
69         "Sound Clip",\r
70         "Gospel",\r
71         "Noise",\r
72         "Altern Rock",          /* 40 */\r
73         "Bass",\r
74         "Soul",\r
75         "Punk",\r
76         "Space",\r
77         "Meditative",           /* 45 */\r
78         "Instrumental Pop",\r
79         "Instrumental Rock",\r
80         "Ethnic",\r
81         "Gothic",\r
82         "Darkwave",             /* 50 */\r
83         "Techno-Industrial",\r
84         "Electronic",\r
85         "Pop-Folk",\r
86         "Eurodance",\r
87         "Dream",                /* 55 */\r
88         "Southern Rock",\r
89         "Comedy",\r
90         "Cult",\r
91         "Gangsta",\r
92         "Top 40",               /* 60 */\r
93         "Christian Rap",\r
94         "Pop/Funk",\r
95         "Jungle",\r
96         "Native American",\r
97         "Cabaret",              /* 65 */\r
98         "New Wave",\r
99         "Psychadelic",\r
100         "Rave",\r
101         "Showtunes",\r
102         "Trailer",              /* 70 */\r
103         "Lo-Fi",\r
104         "Tribal",\r
105         "Acid Punk",\r
106         "Acid Jazz",\r
107         "Polka",                /* 75 */\r
108         "Retro",\r
109         "Musical",\r
110         "Rock & Roll",\r
111         "Hard Rock",\r
112         "Folk",                 /* 80 */\r
113         "Folk/Rock",\r
114         "National Folk",\r
115         "Fast Fusion",\r
116         "Swing",\r
117         "Bebob",                /* 85 */\r
118         "Latin",\r
119         "Revival",\r
120         "Celtic",\r
121         "Bluegrass",\r
122         "Avantgarde",           /* 90 */\r
123         "Gothic Rock",\r
124         "Progressive Rock",\r
125         "Psychedelic Rock",\r
126         "Symphonic Rock",\r
127         "Slow Rock",            /* 95 */\r
128         "Big Band",\r
129         "Chorus",\r
130         "Easy Listening",\r
131         "Acoustic",\r
132         "Humour",               /* 100 */\r
133         "Speech",\r
134         "Chanson",\r
135         "Opera",\r
136         "Chamber Music",\r
137         "Sonata",               /* 105 */\r
138         "Symphony",\r
139         "Booty Bass",\r
140         "Primus",\r
141         "Porn Groove",\r
142         "Satire",               /* 110 */\r
143         "Slow Jam",\r
144         "Club",\r
145         "Tango",\r
146         "Samba",\r
147         "Folklore",             /* 115 */\r
148         "Ballad",\r
149         "Power Ballad",\r
150         "Rhythmic Soul",\r
151         "Freestyle",\r
152         "Duet",                 /* 120 */\r
153         "Punk Rock",\r
154         "Drum Solo",\r
155         "A Capella",\r
156         "Euro-House",\r
157         "Dance Hall",           /* 125 */\r
158         "Goa",\r
159         "Drum & Bass",\r
160         "Club-House",\r
161         "Hardcore",\r
162         "Terror",               /* 130 */\r
163         "Indie",\r
164         "BritPop",\r
165         "Negerpunk",\r
166         "Polsk Punk",\r
167         "Beat",                 /* 135 */\r
168         "Christian Gangsta Rap",\r
169         "Heavy Metal",\r
170         "Black Metal",\r
171         "Crossover",\r
172         "Contemporary Christian",/* 140 */\r
173         "Christian Rock",\r
174         "Merengue",\r
175         "Salsa",\r
176         "Thrash Metal",\r
177         "Anime",                /* 145 */\r
178         "JPop",\r
179         "Synthpop"\r
180 };\r
181 \r
182 \r
183 FLAC__bool FLAC_plugin__id3v1_tag_get(const char *filename, FLAC_Plugin__Id3v1_Tag *tag)\r
184 {\r
185         FILE *f;\r
186         int res;\r
187 \r
188         FLAC__ASSERT(0 != filename);\r
189         FLAC__ASSERT(0 != tag);\r
190 \r
191         memset(tag, 0, sizeof(FLAC_Plugin__Id3v1_Tag));\r
192 \r
193         if(0 == (f = fopen(filename, "rb")))\r
194                 return false;\r
195         if(-1 == fseek(f, -128, SEEK_END)) {\r
196                 fclose(f);\r
197                 return false;\r
198         }\r
199         res = fread(tag, 128, 1, f);\r
200         fclose(f);\r
201         return res==1 && !strncmp(tag->tag, "TAG", 3);\r
202 }\r
203 \r
204 const char *FLAC_plugin__id3v1_tag_get_genre_as_string(unsigned char genre_code)\r
205 {\r
206         if (genre_code < (sizeof(FLAC_plugin__id3v1_tag_genre_table)/sizeof(FLAC_plugin__id3v1_tag_genre_table[0])))\r
207                 return gettext(FLAC_plugin__id3v1_tag_genre_table[genre_code]);\r
208         return "Unknown";\r
209 }\r
210 \r
211 unsigned FLAC_plugin__id3v1_tag_genre_table_max()\r
212 {\r
213         return sizeof(FLAC_plugin__id3v1_tag_genre_table) / sizeof(FLAC_plugin__id3v1_tag_genre_table[0]) - 1;\r
214 }\r