~ubuntu-branches/ubuntu/wily/kid3/wily-proposed

« back to all changes in this revision

Viewing changes to kid3/genres.cpp

  • Committer: Package Import Robot
  • Author(s): Ana Beatriz Guerrero Lopez, Patrick Matthäi, Ana Beatriz Guerrero Lopez
  • Date: 2011-11-13 16:34:13 UTC
  • mfrom: (1.1.13) (2.1.11 sid)
  • Revision ID: package-import@ubuntu.com-20111113163413-5y0anlc4dqf511uh
Tags: 2.0.1-1
* New upstream release.

[ Patrick Matthäi ]
* Adjust build system.
* Add build dependency xsltproc.

[ Ana Beatriz Guerrero Lopez ]
* Some more adjustments to the build system taken from upstream's deb/
* directory.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/**
2
 
 * \file genres.cpp
3
 
 * Alphabetical list of genres.
4
 
 *
5
 
 * \b Project: Kid3
6
 
 * \author Urs Fleisch
7
 
 * \date 9 Jan 2003
8
 
 *
9
 
 * Copyright (C) 2003-2007  Urs Fleisch
10
 
 *
11
 
 * This file is part of Kid3.
12
 
 *
13
 
 * Kid3 is free software; you can redistribute it and/or modify
14
 
 * it under the terms of the GNU General Public License as published by
15
 
 * the Free Software Foundation; either version 2 of the License, or
16
 
 * (at your option) any later version.
17
 
 *
18
 
 * Kid3 is distributed in the hope that it will be useful,
19
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
 
 * GNU General Public License for more details.
22
 
 *
23
 
 * You should have received a copy of the GNU General Public License
24
 
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
25
 
 */
26
 
 
27
 
#include <qstring.h>
28
 
#include <qmap.h>
29
 
#include "qtcompatmac.h"
30
 
#include "genres.h"
31
 
 
32
 
/**
33
 
 * Alphabetic list of genres, starts with unknown (empty) entry.
34
 
 *
35
 
 * 125: Last ID3v1, 142: WinAmp 1.91, 145: WinAmp 1.92, 255: unknown
36
 
 */
37
 
const char* Genres::s_genre[Genres::count + 3] = {
38
 
        "",                       // 255,
39
 
        "A Cappella",             // 123,
40
 
        "Acid",                   // 34,
41
 
        "Acid Jazz",              // 74, 
42
 
        "Acid Punk",              // 73, 
43
 
        "Acoustic",               // 99, 
44
 
        "Alternative",            // 20,
45
 
        "Alternative Rock",       // 40,
46
 
        "Ambient",                // 26,
47
 
        "Anime",                  // 145, 
48
 
        "Avantgarde",             // 90, 
49
 
        "Ballad",                 // 116,
50
 
        "Bass",                   // 41, 
51
 
        "Beat",                   // 135,
52
 
        "Bebob",                  // 85, 
53
 
        "Big Band",               // 96, 
54
 
        "Black Metal",            // 138,
55
 
        "Bluegrass",              // 89, 
56
 
        "Blues",                  // 0,
57
 
        "Booty Bass",             // 107,
58
 
        "BritPop",                // 132,
59
 
        "Cabaret",                // 65, 
60
 
        "Celtic",                 // 88, 
61
 
        "Chamber Music",          // 104,
62
 
        "Chanson",                // 102,
63
 
        "Chorus",                 // 97, 
64
 
        "Christian Gangsta Rap",  // 136,
65
 
        "Christian Rap",          // 61, 
66
 
        "Christian Rock",         // 141,
67
 
        "Classic Rock",           // 1,
68
 
        "Classical",              // 32,
69
 
        "Club",                   // 112,
70
 
        "Club-House",             // 128,
71
 
        "Comedy",                 // 57, 
72
 
        "Contemporary Christian", // 140,
73
 
        "Country",                // 2,
74
 
        "Crossover",              // 139,
75
 
        "Cult",                   // 58, 
76
 
        "Dance Hall",             // 125,
77
 
        "Dance",                  // 3,
78
 
        "Darkwave",               // 50, 
79
 
        "Death Metal",            // 22,
80
 
        "Disco",                  // 4,
81
 
        "Dream",                  // 55, 
82
 
        "Drum & Bass",            // 127,
83
 
        "Drum Solo",              // 122,
84
 
        "Duet",                   // 120,
85
 
        "Easy Listening",         // 98, 
86
 
        "Electronic",             // 52, 
87
 
        "Ethnic",                 // 48, 
88
 
        "Euro-House",             // 124,
89
 
        "Euro-Techno",            // 25,
90
 
        "Eurodance",              // 54, 
91
 
        "Folk",                   // 80,
92
 
        "Folk/Rock",              // 81, 
93
 
        "Folklore",               // 115,
94
 
        "Freestyle",              // 119,
95
 
        "Funk",                   // 5,
96
 
        "Fusion",                 // 30,
97
 
        "Fusion",                 // 84, 
98
 
        "Game",                   // 36,
99
 
        "Gangsta",                // 59, 
100
 
        "Goa",                    // 126,
101
 
        "Gospel",                 // 38,
102
 
        "Gothic",                 // 49, 
103
 
        "Gothic Rock",            // 91, 
104
 
        "Grunge",                 // 6,
105
 
        "Hard Rock",              // 79, 
106
 
        "Hardcore",               // 129,
107
 
        "Heavy Metal",            // 137,
108
 
        "Hip-Hop",                // 7,
109
 
        "House",                  // 35,
110
 
        "Humour",                 // 100,
111
 
        "Indie",                  // 131,
112
 
        "Industrial",             // 19,
113
 
        "Instrumental",           // 33,
114
 
        "Instrumental Pop",       // 46, 
115
 
        "Instrumental Rock",      // 47, 
116
 
        "Jazz",                   // 8,
117
 
        "Jazz+Funk",              // 29,
118
 
        "Jpop",                   // 146,
119
 
        "Jungle",                 // 63, 
120
 
        "Latin",                  // 86, 
121
 
        "Lo-Fi",                  // 71, 
122
 
        "Meditative",             // 45, 
123
 
        "Merengue",               // 142,
124
 
        "Metal",                  // 9,
125
 
        "Musical",                // 77, 
126
 
        "National Folk",          // 82, 
127
 
        "Native American",        // 64, 
128
 
        "Negerpunk",              // 133,
129
 
        "New Age",                // 10,
130
 
        "New Wave",               // 66, 
131
 
        "Noise",                  // 39,
132
 
        "Oldies",                 // 11,
133
 
        "Opera",                  // 103,
134
 
        "Other",                  // 12,
135
 
        "Polka",                  // 75, 
136
 
        "Polsk Punk",             // 134,
137
 
        "Pop",                    // 13,
138
 
        "Pop-Folk",               // 53, 
139
 
        "Pop/Funk",               // 62, 
140
 
        "Porn Groove",            // 109,
141
 
        "Power Ballad",           // 117,
142
 
        "Pranks",                 // 23,
143
 
        "Primus",                 // 108,
144
 
        "Progressive Rock",       // 92, 
145
 
        "Psychedelic",            // 67, 
146
 
        "Psychedelic Rock",       // 93, 
147
 
        "Punk",                   // 43, 
148
 
        "Punk Rock",              // 121,
149
 
        "R&B",                    // 14,
150
 
        "Rap",                    // 15,
151
 
        "Rave",                   // 68, 
152
 
        "Reggae",                 // 16,
153
 
        "Retro",                  // 76, 
154
 
        "Revival",                // 87, 
155
 
        "Rhythmic Soul",          // 118,
156
 
        "Rock",                   // 17,
157
 
        "Rock & Roll",            // 78, 
158
 
        "Salsa",                  // 143,
159
 
        "Samba",                  // 114,
160
 
        "Satire",                 // 110,
161
 
        "Showtunes",              // 69, 
162
 
        "Ska",                    // 21,
163
 
        "Slow Jam",               // 111,
164
 
        "Slow Rock",              // 95, 
165
 
        "Sonata",                 // 105,
166
 
        "Soul",                   // 42, 
167
 
        "Sound Clip",             // 37,
168
 
        "Soundtrack",             // 24,
169
 
        "Southern Rock",          // 56, 
170
 
        "Space",                  // 44, 
171
 
        "Speech",                 // 101,
172
 
        "Swing",                  // 83, 
173
 
        "Symphonic Rock",         // 94, 
174
 
        "Symphony",               // 106,
175
 
        "Synthpop",               // 147,
176
 
        "Tango",                  // 113,
177
 
        "Techno",                 // 18,
178
 
        "Techno-Industrial",      // 51, 
179
 
        "Terror",                 // 130,
180
 
        "Thrash Metal",           // 144,
181
 
        "Top 40",                 // 60,
182
 
        "Trailer",                // 70, 
183
 
        "Trance",                 // 31,
184
 
        "Tribal",                 // 72, 
185
 
        "Trip-Hop",               // 27,
186
 
        "Vocal",                  // 28,
187
 
        "Custom",                 // place for temporary custom genres
188
 
        0                         // end of StrList
189
 
};
190
 
 
191
 
/**
192
 
 * s_genreNum[n] gives the number of the n-th genre
193
 
 * in the alphabetically sorted list.
194
 
 */
195
 
const unsigned char Genres::s_genreNum[Genres::count + 1] = {
196
 
        255,
197
 
        123,
198
 
        34,
199
 
        74, 
200
 
        73, 
201
 
        99, 
202
 
        20,
203
 
        40,
204
 
        26,
205
 
        145, 
206
 
        90, 
207
 
        116,
208
 
        41, 
209
 
        135,
210
 
        85, 
211
 
        96, 
212
 
        138,
213
 
        89, 
214
 
        0,
215
 
        107,
216
 
        132,
217
 
        65, 
218
 
        88, 
219
 
        104,
220
 
        102,
221
 
        97, 
222
 
        136,
223
 
        61, 
224
 
        141,
225
 
        1,
226
 
        32,
227
 
        112,
228
 
        128,
229
 
        57, 
230
 
        140,
231
 
        2,
232
 
        139,
233
 
        58, 
234
 
        125,
235
 
        3,
236
 
        50, 
237
 
        22,
238
 
        4,
239
 
        55, 
240
 
        127,
241
 
        122,
242
 
        120,
243
 
        98, 
244
 
        52, 
245
 
        48, 
246
 
        124,
247
 
        25,
248
 
        54, 
249
 
        80,
250
 
        81, 
251
 
        115,
252
 
        119,
253
 
        5,
254
 
        30,
255
 
        84, 
256
 
        36,
257
 
        59, 
258
 
        126,
259
 
        38,
260
 
        49, 
261
 
        91, 
262
 
        6,
263
 
        79, 
264
 
        129,
265
 
        137,
266
 
        7,
267
 
        35,
268
 
        100,
269
 
        131,
270
 
        19,
271
 
        33,
272
 
        46, 
273
 
        47, 
274
 
        8,
275
 
        29,
276
 
        146,
277
 
        63, 
278
 
        86, 
279
 
        71, 
280
 
        45, 
281
 
        142,
282
 
        9,
283
 
        77, 
284
 
        82, 
285
 
        64, 
286
 
        133,
287
 
        10,
288
 
        66, 
289
 
        39,
290
 
        11,
291
 
        103,
292
 
        12,
293
 
        75, 
294
 
        134,
295
 
        13,
296
 
        53, 
297
 
        62, 
298
 
        109,
299
 
        117,
300
 
        23,
301
 
        108,
302
 
        92, 
303
 
        67, 
304
 
        93, 
305
 
        43, 
306
 
        121,
307
 
        14,
308
 
        15,
309
 
        68, 
310
 
        16,
311
 
        76, 
312
 
        87, 
313
 
        118,
314
 
        17,
315
 
        78, 
316
 
        143,
317
 
        114,
318
 
        110,
319
 
        69, 
320
 
        21,
321
 
        111,
322
 
        95, 
323
 
        105,
324
 
        42, 
325
 
        37,
326
 
        24,
327
 
        56, 
328
 
        44, 
329
 
        101,
330
 
        83, 
331
 
        94, 
332
 
        106,
333
 
        147,
334
 
        113,
335
 
        18,
336
 
        51, 
337
 
        130,
338
 
        144,
339
 
        60,
340
 
        70, 
341
 
        31,
342
 
        72, 
343
 
        27,
344
 
        28
345
 
};
346
 
 
347
 
const char** Genres::s_strList = &s_genre[0];
348
 
 
349
 
/**
350
 
 * Get name assigned to genre number.
351
 
 *
352
 
 * @param num genre number
353
 
 *
354
 
 * @return name, empty string for unknown number.
355
 
 */
356
 
const char* Genres::getName(int num)
357
 
{
358
 
        return s_genre[getIndex(num)];
359
 
}
360
 
 
361
 
/**
362
 
 * Get the index in the alphabethically sorted list from the genre number.
363
 
 *
364
 
 * @param num genre number
365
 
 *
366
 
 * @return index, 0 for unknown number.
367
 
 */
368
 
int Genres::getIndex(int num)
369
 
{
370
 
        int i;
371
 
        for (i = 0; i < Genres::count + 1; i++) {
372
 
                if (s_genreNum[i] == num) {
373
 
                        return i;
374
 
                }
375
 
        }
376
 
        return 0; // 0 for unknown entry
377
 
}
378
 
 
379
 
/**
380
 
 * Get the genre number from a string containing a genre text.
381
 
 *
382
 
 * @param str string with genre
383
 
 *
384
 
 * @return genre number, 255 for unknown index.
385
 
 */
386
 
int Genres::getNumber(const QString& str)
387
 
{
388
 
        static QMap<QString, int> strNumMap;
389
 
        if (strNumMap.empty()) {
390
 
                // first time initialization
391
 
                for (int i = 0; i < Genres::count + 1; i++) {
392
 
                        strNumMap.insert(s_genre[i], s_genreNum[i]);
393
 
                }
394
 
        }
395
 
        QMap<QString, int>::const_iterator it = strNumMap.find(str);
396
 
        if (it != strNumMap.end()) {
397
 
                return *it;
398
 
        }
399
 
        return 255; // 255 for unknown
400
 
}
401
 
 
402
 
/**
403
 
 * Get a name string from a string with a number or a name.
404
 
 * ID3v2 genres can be stored as "9", "(9)", "(9)Metal" or "Metal".
405
 
 *
406
 
 * @param str genre string.
407
 
 */
408
 
QString Genres::getNameString(const QString& str)
409
 
{
410
 
        if (!str.isEmpty()) {
411
 
                int cpPos, n;
412
 
                bool ok;
413
 
                if ((str[0] == '(') && ((cpPos = str.QCM_indexOf(')', 2)) > 1)) {
414
 
                        n = str.mid(1, cpPos - 1).toInt(&ok);
415
 
                        if (ok && n <= 0xff) {
416
 
                                return getName(n);
417
 
                        }
418
 
                } else if ((n = str.toInt(&ok)) >= 0 && n <= 0xff && ok) {
419
 
                        return getName(n);
420
 
                }
421
 
        }
422
 
        return str;
423
 
}
424
 
 
425
 
/**
426
 
 * Get a number representation of a genre name if possible.
427
 
 *
428
 
 * @param str         string with genre name
429
 
 * @param parentheses true to put the number in parentheses
430
 
 *
431
 
 * @return genre string.
432
 
 */
433
 
QString Genres::getNumberString(const QString& str, bool parentheses)
434
 
{
435
 
        int n = getNumber(str);
436
 
        if (n < 0xff) {
437
 
                if (parentheses) {
438
 
                        QString s("(");
439
 
                        s += QString::number(n);
440
 
                        s += ')';
441
 
                        return s;
442
 
                } else {
443
 
                        return QString::number(n);
444
 
                }
445
 
        }
446
 
        return str;
447
 
}