2 * libid3tag - ID3 tag manipulation library
3 * Copyright (C) 2000-2004 Underbit Technologies, Inc.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 * $Id: genre.c,v 1.8 2004/01/23 09:41:32 rob Exp $
31 /* genres are stored in ucs4 format */
34 # define NGENRES (sizeof(genre_table) / sizeof(genre_table[0]))
37 * NAME: genre->index()
38 * DESCRIPTION: return an ID3v1 genre string indexed by number
40 id3_ucs4_t
const *id3_genre_index(unsigned int index
)
42 return (index
< NGENRES
) ? genre_table
[index
] : 0;
47 * DESCRIPTION: translate an ID3v2 genre number/keyword to its full name
49 id3_ucs4_t
const *id3_genre_name(id3_ucs4_t
const *string
)
51 id3_ucs4_t
const *ptr
;
52 static id3_ucs4_t
const genre_remix
[] = { 'R', 'e', 'm', 'i', 'x', 0 };
53 static id3_ucs4_t
const genre_cover
[] = { 'C', 'o', 'v', 'e', 'r', 0 };
56 if (string
== 0 || *string
== 0)
57 return id3_ucs4_empty
;
59 if (string
[0] == 'R' && string
[1] == 'X' && string
[2] == 0)
61 if (string
[0] == 'C' && string
[1] == 'R' && string
[2] == 0)
64 for (ptr
= string
; *ptr
; ++ptr
) {
65 if (*ptr
< '0' || *ptr
> '9')
69 number
= id3_ucs4_getnumber(string
);
71 return (number
< NGENRES
) ? genre_table
[number
] : string
;
76 * DESCRIPTION: return a canonicalized character for testing genre equivalence
79 id3_ucs4_t
translate(id3_ucs4_t ch
)
82 if (ch
>= 'A' && ch
<= 'Z')
85 if (ch
< 'a' || ch
> 'z')
86 ch
= ID3_UCS4_REPLACEMENTCHAR
;
94 * DESCRIPTION: test two ucs4 genre strings for equivalence
97 int compare(id3_ucs4_t
const *str1
, id3_ucs4_t
const *str2
)
106 c1
= translate(*str1
++);
107 while (c1
== ID3_UCS4_REPLACEMENTCHAR
);
110 c2
= translate(*str2
++);
111 while (c2
== ID3_UCS4_REPLACEMENTCHAR
);
113 while (c1
&& c1
== c2
);
119 * NAME: genre->number()
120 * DESCRIPTION: translate an ID3v2 genre name/number to its ID3v1 index number
122 int id3_genre_number(id3_ucs4_t
const *string
)
124 id3_ucs4_t
const *ptr
;
127 if (string
== 0 || *string
== 0)
130 for (ptr
= string
; *ptr
; ++ptr
) {
131 if (*ptr
< '0' || *ptr
> '9')
136 unsigned long number
;
138 number
= id3_ucs4_getnumber(string
);
140 return (number
<= 0xff) ? number
: -1;
143 for (i
= 0; i
< NGENRES
; ++i
) {
144 if (compare(string
, genre_table
[i
]))