File: genre.cpp

package info (click to toggle)
id3v2 0.1.11-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 296 kB
  • ctags: 76
  • sloc: cpp: 2,212; makefile: 123
file content (256 lines) | stat: -rw-r--r-- 7,803 bytes parent folder | download | duplicates (2)
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
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 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 General Public License for more details.
//  
// You should have received a copy of the GNU 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.

#if defined HAVE_CONFIG_H
#include <config.h>
#endif

#ifndef __GENRE_H__
#include "genre.h"
#endif

#ifdef SORT_RUNTIME
#include <stdlib.h>
#endif  // SORT_RUNTIME
#include <string.h>


char *genre_table[] = {"Blues",
                       "Classic Rock",
                       "Country",
                       "Dance",
                       "Disco",
                       "Funk",
                       "Grunge",
                       "Hip-Hop",
                       "Jazz",
                       "Metal",
                       "New Age",
                       "Oldies",
                       "Other",
                       "Pop",
                       "R&B",
                       "Rap",
                       "Reggae",
                       "Rock",
                       "Techno",
                       "Industrial",
                       "Alternative",
                       "Ska",
                       "Death Metal",
                       "Pranks",
                       "Soundtrack",
                       "Euro-Techno",
                       "Ambient",
                       "Trip-Hop",
                       "Vocal",
                       "Jazz+Funk",
                       "Fusion",
                       "Trance",
                       "Classical",
                       "Instrumental",
                       "Acid",
                       "House",
                       "Game",
                       "Sound Clip",
                       "Gospel",
                       "Noise",
                       "Alt. Rock",
                       "Bass",
                       "Soul",
                       "Punk",
                       "Space",
                       "Meditative",
                       "Instrum. Pop",
                       "Instrum. Rock",
                       "Ethnic",
                       "Gothic",
                       "Darkwave",
                       "Techno-Indust.",
                       "Electronic",
                       "Pop-Folk",
                       "Eurodance",
                       "Dream",
                       "Southern Rock",
                       "Comedy",
                       "Cult",
                       "Gangsta",
                       "Top 40",
                       "Christian Rap",
                       "Pop/Funk",
                       "Jungle",
                       "Native American",
                       "Cabaret",
                       "New Wave",
                       "Psychadelic",
                       "Rave",
                       "Showtunes",
                       "Trailer",
                       "Lo-Fi",
                       "Tribal",
                       "Acid Punk",
                       "Acid Jazz",
                       "Polka",
                       "Retro",
                       "Musical",
                       "Rock & Roll",
                       "Hard Rock",
                       "Folk",
                       "Folk/Rock",
                       "National Folk",
                       "Swing",
                       "Fusion",
                       "Bebob",
                       "Latin",
                       "Revival",
                       "Celtic",
                       "Bluegrass",
                       "Avantgarde",
                       "Gothic Rock",
                       "Progress. Rock",
                       "Psychadel. Rock",
                       "Symphonic Rock",
                       "Slow Rock",
                       "Big Band",
                       "Chorus",
                       "Easy Listening",
                       "Acoustic",
                       "Humour",
                       "Speech",
                       "Chanson",
                       "Opera",
                       "Chamber Music",
                       "Sonata",
                       "Symphony",
                       "Booty Bass",
                       "Primus",
                       "Porn Groove",
                       "Satire",
 /* The following were added 1999 26 Apr by Ben Gertzfield <che@debian.org> 
  * as per the list at http://mp3.musichall.cz/id3master/faq.htm but with a 
  * few spell-checks confirmed by running 'strings' on the in_mp3.dll file 
  * from winamp 2.10 (sorry :)
  */
		       "Slow Jam",
		       "Club",
		       "Tango",
		       "Samba",
		       "Folklore",
		       "Ballad",
		       "Power Ballad",
		       "Rhythmic Soul",
		       "Freestyle",
		       "Duet",
		       "Punk Rock",
		       "Drum Solo",
		       "A Capella",
		       "Euro-House",
		       "Dance Hall",
		       "Goa",
		       "Drum & Bass",
		       "Club-House",
		       "Hardcore",
		       "Terror",
		       "Indie",
		       "BritPop",
		       "Negerpunk",
		       "Polsk Punk",
		       "Beat",
		       "Christian Gangsta Rap",	/* DJ JC in da house */
		       "Heavy Metal",
		       "Black Metal",
		       "Crossover",
		       "Contemporary Christian",
		       "Christian Rock",
				/* winamp 1.91 genres */
		       "Merengue",
		       "Salsa",
		       "Thrash Metal",
				/* winamp 1.92 genres */
		       "Anime",
		       "Jpop",
		       "Synthpop",
                       };

const int genre_count = sizeof(genre_table) / sizeof(char*);

#ifdef SORT_RUNTIME
int genre_map[genre_count];
#else
int genre_map[genre_count] =
    { 123, 34, 74, 73, 99, 40, 20, 26, 145, 90, 116, 41, 135, 85, 96, 138, 89,
      0, 107, 132, 65, 88, 104, 102, 97, 136, 61, 141, 1, 32, 112, 128, 57,
      140, 2, 139, 58, 3, 125, 50, 22, 4, 55, 127, 122, 120, 98, 52, 48, 124,
      25, 54, 80, 81, 115, 119, 5, 30, 84, 36, 59, 126, 38, 49, 91, 6, 79, 129,
      137, 7, 35, 100, 131, 19, 46, 47, 33, 8, 29, 146, 63, 86, 71, 45, 142, 9,
      77, 82, 64, 133, 10, 66, 39, 11, 103, 12, 75, 134, 13, 53, 62, 109, 117,
      23, 108, 92, 93, 67, 43, 121, 14, 15, 68, 16, 76, 87, 118, 17, 78, 143,
      114, 110, 69, 21, 111, 95, 105, 42, 37, 24, 56, 44, 101, 83, 94, 106,
      147, 113, 18, 51, 130, 144, 60, 70, 31, 72, 27, 28 } ;
#endif  // SORT_RUNTIME

int GetGenreCount()
{
    return genre_count;
}

const char *GetGenreFromNum(int genre_id)
{
    if ((genre_id >= 0) && (genre_id < GetGenreCount()))
        return genre_table[genre_id];
    else
        return "Unknown";
}

int GetNumFromGenre(const char *genre)
{
    int a=0;
    int b=GetGenreCount()-1;
    int i;

    while(a <= b) {
        const int i = (a+b)/2;
        const int genre_id = genre_map[i];
        const int cmp = strcmp(GetGenreFromNum(genre_id), genre);

        if (cmp == 0)
            return genre_id;
        else if (cmp < 0)
            a = i+1;
        else
            b = i-1;
    }

    return 255;
}

#ifdef SORT_RUNTIME
int CompareGenres(const void *a, const void *b)
{
    int g1, g2;
    g1 = *((int*)a);
    g2 = *((int*)b);

    return strcmp(GetGenreFromNum(g1), GetGenreFromNum(g2));
}

void InitGenres()
{
    int i;
    for (i=0; i<GetGenreCount(); ++i)
        genre_map[i] = i;

    qsort(genre_map, GetGenreCount(), sizeof(int), &CompareGenres);
}
#endif  // SORT_RUNTIME