annotate src/libid3tag-0.15.1b/genre.c @ 23:619f715526df sv_v2.1

Update Vamp plugin SDK to 2.5
author Chris Cannam
date Thu, 09 May 2013 10:52:46 +0100
parents c7265573341e
children
rev   line source
Chris@0 1 /*
Chris@0 2 * libid3tag - ID3 tag manipulation library
Chris@0 3 * Copyright (C) 2000-2004 Underbit Technologies, Inc.
Chris@0 4 *
Chris@0 5 * This program is free software; you can redistribute it and/or modify
Chris@0 6 * it under the terms of the GNU General Public License as published by
Chris@0 7 * the Free Software Foundation; either version 2 of the License, or
Chris@0 8 * (at your option) any later version.
Chris@0 9 *
Chris@0 10 * This program is distributed in the hope that it will be useful,
Chris@0 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@0 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@0 13 * GNU General Public License for more details.
Chris@0 14 *
Chris@0 15 * You should have received a copy of the GNU General Public License
Chris@0 16 * along with this program; if not, write to the Free Software
Chris@0 17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Chris@0 18 *
Chris@0 19 * $Id: genre.c,v 1.8 2004/01/23 09:41:32 rob Exp $
Chris@0 20 */
Chris@0 21
Chris@0 22 # ifdef HAVE_CONFIG_H
Chris@0 23 # include "config.h"
Chris@0 24 # endif
Chris@0 25
Chris@0 26 # include "global.h"
Chris@0 27
Chris@0 28 # include "id3tag.h"
Chris@0 29 # include "ucs4.h"
Chris@0 30
Chris@0 31 /* genres are stored in ucs4 format */
Chris@0 32 # include "genre.dat"
Chris@0 33
Chris@0 34 # define NGENRES (sizeof(genre_table) / sizeof(genre_table[0]))
Chris@0 35
Chris@0 36 /*
Chris@0 37 * NAME: genre->index()
Chris@0 38 * DESCRIPTION: return an ID3v1 genre string indexed by number
Chris@0 39 */
Chris@0 40 id3_ucs4_t const *id3_genre_index(unsigned int index)
Chris@0 41 {
Chris@0 42 return (index < NGENRES) ? genre_table[index] : 0;
Chris@0 43 }
Chris@0 44
Chris@0 45 /*
Chris@0 46 * NAME: genre->name()
Chris@0 47 * DESCRIPTION: translate an ID3v2 genre number/keyword to its full name
Chris@0 48 */
Chris@0 49 id3_ucs4_t const *id3_genre_name(id3_ucs4_t const *string)
Chris@0 50 {
Chris@0 51 id3_ucs4_t const *ptr;
Chris@0 52 static id3_ucs4_t const genre_remix[] = { 'R', 'e', 'm', 'i', 'x', 0 };
Chris@0 53 static id3_ucs4_t const genre_cover[] = { 'C', 'o', 'v', 'e', 'r', 0 };
Chris@0 54 unsigned long number;
Chris@0 55
Chris@0 56 if (string == 0 || *string == 0)
Chris@0 57 return id3_ucs4_empty;
Chris@0 58
Chris@0 59 if (string[0] == 'R' && string[1] == 'X' && string[2] == 0)
Chris@0 60 return genre_remix;
Chris@0 61 if (string[0] == 'C' && string[1] == 'R' && string[2] == 0)
Chris@0 62 return genre_cover;
Chris@0 63
Chris@0 64 for (ptr = string; *ptr; ++ptr) {
Chris@0 65 if (*ptr < '0' || *ptr > '9')
Chris@0 66 return string;
Chris@0 67 }
Chris@0 68
Chris@0 69 number = id3_ucs4_getnumber(string);
Chris@0 70
Chris@0 71 return (number < NGENRES) ? genre_table[number] : string;
Chris@0 72 }
Chris@0 73
Chris@0 74 /*
Chris@0 75 * NAME: translate()
Chris@0 76 * DESCRIPTION: return a canonicalized character for testing genre equivalence
Chris@0 77 */
Chris@0 78 static
Chris@0 79 id3_ucs4_t translate(id3_ucs4_t ch)
Chris@0 80 {
Chris@0 81 if (ch) {
Chris@0 82 if (ch >= 'A' && ch <= 'Z')
Chris@0 83 ch += 'a' - 'A';
Chris@0 84
Chris@0 85 if (ch < 'a' || ch > 'z')
Chris@0 86 ch = ID3_UCS4_REPLACEMENTCHAR;
Chris@0 87 }
Chris@0 88
Chris@0 89 return ch;
Chris@0 90 }
Chris@0 91
Chris@0 92 /*
Chris@0 93 * NAME: compare()
Chris@0 94 * DESCRIPTION: test two ucs4 genre strings for equivalence
Chris@0 95 */
Chris@0 96 static
Chris@0 97 int compare(id3_ucs4_t const *str1, id3_ucs4_t const *str2)
Chris@0 98 {
Chris@0 99 id3_ucs4_t c1, c2;
Chris@0 100
Chris@0 101 if (str1 == str2)
Chris@0 102 return 1;
Chris@0 103
Chris@0 104 do {
Chris@0 105 do
Chris@0 106 c1 = translate(*str1++);
Chris@0 107 while (c1 == ID3_UCS4_REPLACEMENTCHAR);
Chris@0 108
Chris@0 109 do
Chris@0 110 c2 = translate(*str2++);
Chris@0 111 while (c2 == ID3_UCS4_REPLACEMENTCHAR);
Chris@0 112 }
Chris@0 113 while (c1 && c1 == c2);
Chris@0 114
Chris@0 115 return c1 == c2;
Chris@0 116 }
Chris@0 117
Chris@0 118 /*
Chris@0 119 * NAME: genre->number()
Chris@0 120 * DESCRIPTION: translate an ID3v2 genre name/number to its ID3v1 index number
Chris@0 121 */
Chris@0 122 int id3_genre_number(id3_ucs4_t const *string)
Chris@0 123 {
Chris@0 124 id3_ucs4_t const *ptr;
Chris@0 125 int i;
Chris@0 126
Chris@0 127 if (string == 0 || *string == 0)
Chris@0 128 return -1;
Chris@0 129
Chris@0 130 for (ptr = string; *ptr; ++ptr) {
Chris@0 131 if (*ptr < '0' || *ptr > '9')
Chris@0 132 break;
Chris@0 133 }
Chris@0 134
Chris@0 135 if (*ptr == 0) {
Chris@0 136 unsigned long number;
Chris@0 137
Chris@0 138 number = id3_ucs4_getnumber(string);
Chris@0 139
Chris@0 140 return (number <= 0xff) ? number : -1;
Chris@0 141 }
Chris@0 142
Chris@0 143 for (i = 0; i < NGENRES; ++i) {
Chris@0 144 if (compare(string, genre_table[i]))
Chris@0 145 return i;
Chris@0 146 }
Chris@0 147
Chris@0 148 /* no equivalent */
Chris@0 149
Chris@0 150 return -1;
Chris@0 151 }