1
0
Fork 0
forked from len0rd/rockbox

remove numerical genre and use genre_string consistently:

- fix spurious display of "blues" genre for missing genre tag 
- simplify code/use less code
- numerical->string conversion only once instead of at every use

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@12552 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Robert Kukla 2007-03-02 21:49:42 +00:00
parent 2187e815e2
commit 79a2a936a2
6 changed files with 14 additions and 32 deletions

View file

@ -506,7 +506,7 @@ static char* get_tag(struct wps_data* wps_data,
return NULL;
case 'g': /* genre */
return id3_get_genre(id3);
return id3->genre_string;
case 'v': /* id3 version */
switch (id3->id3version)

View file

@ -305,8 +305,6 @@ static bool read_ape_tags(int fd, struct mp3entry* id3)
return false;
}
id3->genre = 0xff;
if ((header.version == 2000) && (header.item_count > 0)
&& (header.length > APETAG_HEADER_LENGTH))
{
@ -388,8 +386,6 @@ static bool read_vorbis_tags(int fd, struct mp3entry *id3,
int buf_remaining = sizeof(id3->id3v2buf) + sizeof(id3->id3v1buf);
int i;
id3->genre = 255;
if (ecread(fd, &len, 1, "l", IS_BIG_ENDIAN) < (long) sizeof(len))
{
return false;
@ -1355,7 +1351,7 @@ static bool read_mp4_tags(int fd, struct mp3entry* id3,
unsigned short genre;
read_mp4_tag(fd, size, (char*) &genre, sizeof(genre));
id3->genre = betoh16(genre);
id3->genre_string = id3_get_num_genre(betoh16(genre));
}
break;
@ -1591,7 +1587,6 @@ static bool read_mp4_container(int fd, struct mp3entry* id3,
static bool get_mp4_metadata(int fd, struct mp3entry* id3)
{
id3->codectype = AFMT_UNKNOWN;
id3->genre = 255;
id3->filesize = 0;
errno = 0;
@ -2179,7 +2174,7 @@ bool get_metadata(struct track_info* track, int fd, const char* trackname,
break;
case AFMT_SPC:
track->id3.filesize = filesize(fd);
track->id3.genre = 36;
track->id3.genre_string = id3_get_num_genre(36);
break;
case AFMT_ADX:
if (!get_adx_metadata(fd, &(track->id3)))

View file

@ -1181,7 +1181,7 @@ static char * id3_get_info(int selected_item, void* data, char *buffer)
info=id3->comment;
break;
case 6:/*LANG_ID3_GENRE*/
info = id3_get_genre(id3);
info = id3->genre_string;
break;
case 7:/*LANG_ID3_YEAR*/
if (id3->year_string)

View file

@ -1534,7 +1534,6 @@ static void add_tagcache(char *path)
bool ret;
int fd;
char tracknumfix[3];
char *genrestr;
int offset = 0;
int path_length = strlen(path);
@ -1620,8 +1619,6 @@ static void add_tagcache(char *path)
}
}
genrestr = id3_get_genre(&track.id3);
/* Numeric tags */
entry.tag_offset[tag_year] = track.id3.year;
entry.tag_offset[tag_tracknumber] = track.id3.tracknum;
@ -1633,7 +1630,7 @@ static void add_tagcache(char *path)
ADD_TAG(entry, tag_title, &track.id3.title);
ADD_TAG(entry, tag_artist, &track.id3.artist);
ADD_TAG(entry, tag_album, &track.id3.album);
ADD_TAG(entry, tag_genre, &genrestr);
ADD_TAG(entry, tag_genre, &track.id3.genre_string);
ADD_TAG(entry, tag_composer, &track.id3.composer);
ADD_TAG(entry, tag_comment, &track.id3.comment);
ADD_TAG(entry, tag_albumartist, &track.id3.albumartist);
@ -1647,7 +1644,7 @@ static void add_tagcache(char *path)
write_item(track.id3.title);
write_item(track.id3.artist);
write_item(track.id3.album);
write_item(genrestr);
write_item(track.id3.genre_string);
write_item(track.id3.composer);
write_item(track.id3.comment);
write_item(track.id3.albumartist);

View file

@ -153,7 +153,6 @@ struct mp3entry {
int layer;
int year;
unsigned char id3version;
unsigned char genre;
unsigned int codectype;
unsigned int bitrate;
unsigned long frequency;
@ -228,7 +227,7 @@ enum {
bool get_mp3_metadata(int fd, struct mp3entry *entry, const char *filename, bool v1first);
bool mp3info(struct mp3entry *entry, const char *filename, bool v1first);
char* id3_get_genre(const struct mp3entry* id3);
char* id3_get_num_genre(const unsigned int genre_num);
char* id3_get_codec(const struct mp3entry* id3);
int getid3v2len(int fd);
void adjust_mp3entry(struct mp3entry *entry, void *dest, void *orig);

View file

@ -179,13 +179,10 @@ static const char* const genres[] = {
"Synthpop"
};
char* id3_get_genre(const struct mp3entry* id3)
char* id3_get_num_genre(const unsigned int genre_num)
{
if( id3->genre_string )
return id3->genre_string ;
if (id3->genre < sizeof(genres)/sizeof(char*))
return (char*)genres[id3->genre];
if (genre_num < sizeof(genres)/sizeof(char*))
return (char*)genres[genre_num];
return NULL;
}
@ -364,23 +361,19 @@ static int parsegenre( struct mp3entry* entry, char* tag, int bufferpos )
/* Is it a number? */
if(isdigit(tag[0])) {
entry->genre = atoi( tag );
entry->genre_string = 0;
entry->genre_string = id3_get_num_genre(atoi( tag ));
return tag - entry->id3v2buf;
} else {
entry->genre_string = tag;
entry->genre = 0xff;
return bufferpos;
}
} else {
if( tag[0] == '(' && tag[1] != '(' ) {
entry->genre = atoi( tag + 1 );
entry->genre_string = 0;
entry->genre_string = id3_get_num_genre(atoi( tag + 1 ));
return tag - entry->id3v2buf;
}
else {
entry->genre_string = tag;
entry->genre = 0xff;
return bufferpos;
}
}
@ -616,7 +609,7 @@ static bool setid3v1title(int fd, struct mp3entry *entry)
case 6:
/* genre */
entry->genre = ptr[0];
entry->genre_string = id3_get_num_genre(ptr[0]);
break;
}
}
@ -695,8 +688,7 @@ static void setid3v2title(int fd, struct mp3entry *entry)
}
entry->id3version = version;
entry->tracknum = entry->year = 0;
entry->genre = 0xff;
entry->title = entry->artist = entry->album = NULL;
entry->title = entry->artist = entry->album = NULL; /* FIXME incomplete */
global_flags = header[5];
@ -1117,7 +1109,6 @@ bool get_mp3_metadata(int fd, struct mp3entry *entry, const char *filename, bool
entry->filesize = filesize(fd);
entry->id3v2len = getid3v2len(fd);
entry->tracknum = 0;
entry->genre = 0xff;
if(v1first)
v1found = setid3v1title(fd, entry);