3
* Alphabetical list of genres.
9
* Copyright (C) 2003-2007 Urs Fleisch
11
* This file is part of Kid3.
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.
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.
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/>.
29
#include "qtcompatmac.h"
33
* Alphabetic list of genres, starts with unknown (empty) entry.
35
* 125: Last ID3v1, 142: WinAmp 1.91, 145: WinAmp 1.92, 255: unknown
37
const char* Genres::s_genre[Genres::count + 3] = {
45
"Alternative Rock", // 40,
54
"Black Metal", // 138,
61
"Chamber Music", // 104,
64
"Christian Gangsta Rap", // 136,
65
"Christian Rap", // 61,
66
"Christian Rock", // 141,
72
"Contemporary Christian", // 140,
82
"Drum & Bass", // 127,
85
"Easy Listening", // 98,
103
"Gothic Rock", // 91,
107
"Heavy Metal", // 137,
113
"Instrumental", // 33,
114
"Instrumental Pop", // 46,
115
"Instrumental Rock", // 47,
126
"National Folk", // 82,
127
"Native American", // 64,
136
"Polsk Punk", // 134,
140
"Porn Groove", // 109,
141
"Power Ballad", // 117,
144
"Progressive Rock", // 92,
145
"Psychedelic", // 67,
146
"Psychedelic Rock", // 93,
155
"Rhythmic Soul", // 118,
157
"Rock & Roll", // 78,
169
"Southern Rock", // 56,
173
"Symphonic Rock", // 94,
178
"Techno-Industrial", // 51,
180
"Thrash Metal", // 144,
187
"Custom", // place for temporary custom genres
192
* s_genreNum[n] gives the number of the n-th genre
193
* in the alphabetically sorted list.
195
const unsigned char Genres::s_genreNum[Genres::count + 1] = {
347
const char** Genres::s_strList = &s_genre[0];
350
* Get name assigned to genre number.
352
* @param num genre number
354
* @return name, empty string for unknown number.
356
const char* Genres::getName(int num)
358
return s_genre[getIndex(num)];
362
* Get the index in the alphabethically sorted list from the genre number.
364
* @param num genre number
366
* @return index, 0 for unknown number.
368
int Genres::getIndex(int num)
371
for (i = 0; i < Genres::count + 1; i++) {
372
if (s_genreNum[i] == num) {
376
return 0; // 0 for unknown entry
380
* Get the genre number from a string containing a genre text.
382
* @param str string with genre
384
* @return genre number, 255 for unknown index.
386
int Genres::getNumber(const QString& str)
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]);
395
QMap<QString, int>::const_iterator it = strNumMap.find(str);
396
if (it != strNumMap.end()) {
399
return 255; // 255 for unknown
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".
406
* @param str genre string.
408
QString Genres::getNameString(const QString& str)
410
if (!str.isEmpty()) {
413
if ((str[0] == '(') && ((cpPos = str.QCM_indexOf(')', 2)) > 1)) {
414
n = str.mid(1, cpPos - 1).toInt(&ok);
415
if (ok && n <= 0xff) {
418
} else if ((n = str.toInt(&ok)) >= 0 && n <= 0xff && ok) {
426
* Get a number representation of a genre name if possible.
428
* @param str string with genre name
429
* @param parentheses true to put the number in parentheses
431
* @return genre string.
433
QString Genres::getNumberString(const QString& str, bool parentheses)
435
int n = getNumber(str);
439
s += QString::number(n);
443
return QString::number(n);