diff options
author | Robert Kukla <roolku@rockbox.org> | 2007-03-02 21:49:42 +0000 |
---|---|---|
committer | Robert Kukla <roolku@rockbox.org> | 2007-03-02 21:49:42 +0000 |
commit | 79a2a936a289ed7dc6e997b6f8fdd53d45a48b57 (patch) | |
tree | 32c00625190da49f11a0a274bed4f3bb7a6f118d | |
parent | 2187e815e20d8127df077ef02886867ff8dcaed4 (diff) | |
download | rockbox-79a2a936a289ed7dc6e997b6f8fdd53d45a48b57.tar.gz rockbox-79a2a936a289ed7dc6e997b6f8fdd53d45a48b57.zip |
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
-rw-r--r-- | apps/gui/gwps-common.c | 2 | ||||
-rw-r--r-- | apps/metadata.c | 9 | ||||
-rw-r--r-- | apps/screens.c | 2 | ||||
-rw-r--r-- | apps/tagcache.c | 7 | ||||
-rw-r--r-- | firmware/export/id3.h | 3 | ||||
-rw-r--r-- | firmware/id3.c | 23 |
6 files changed, 14 insertions, 32 deletions
diff --git a/apps/gui/gwps-common.c b/apps/gui/gwps-common.c index f5e3bc2489..d59ac130fc 100644 --- a/apps/gui/gwps-common.c +++ b/apps/gui/gwps-common.c | |||
@@ -506,7 +506,7 @@ static char* get_tag(struct wps_data* wps_data, | |||
506 | return NULL; | 506 | return NULL; |
507 | 507 | ||
508 | case 'g': /* genre */ | 508 | case 'g': /* genre */ |
509 | return id3_get_genre(id3); | 509 | return id3->genre_string; |
510 | 510 | ||
511 | case 'v': /* id3 version */ | 511 | case 'v': /* id3 version */ |
512 | switch (id3->id3version) | 512 | switch (id3->id3version) |
diff --git a/apps/metadata.c b/apps/metadata.c index f9c4e9441f..84ee37c2fe 100644 --- a/apps/metadata.c +++ b/apps/metadata.c | |||
@@ -305,8 +305,6 @@ static bool read_ape_tags(int fd, struct mp3entry* id3) | |||
305 | return false; | 305 | return false; |
306 | } | 306 | } |
307 | 307 | ||
308 | id3->genre = 0xff; | ||
309 | |||
310 | if ((header.version == 2000) && (header.item_count > 0) | 308 | if ((header.version == 2000) && (header.item_count > 0) |
311 | && (header.length > APETAG_HEADER_LENGTH)) | 309 | && (header.length > APETAG_HEADER_LENGTH)) |
312 | { | 310 | { |
@@ -388,8 +386,6 @@ static bool read_vorbis_tags(int fd, struct mp3entry *id3, | |||
388 | int buf_remaining = sizeof(id3->id3v2buf) + sizeof(id3->id3v1buf); | 386 | int buf_remaining = sizeof(id3->id3v2buf) + sizeof(id3->id3v1buf); |
389 | int i; | 387 | int i; |
390 | 388 | ||
391 | id3->genre = 255; | ||
392 | |||
393 | if (ecread(fd, &len, 1, "l", IS_BIG_ENDIAN) < (long) sizeof(len)) | 389 | if (ecread(fd, &len, 1, "l", IS_BIG_ENDIAN) < (long) sizeof(len)) |
394 | { | 390 | { |
395 | return false; | 391 | return false; |
@@ -1355,7 +1351,7 @@ static bool read_mp4_tags(int fd, struct mp3entry* id3, | |||
1355 | unsigned short genre; | 1351 | unsigned short genre; |
1356 | 1352 | ||
1357 | read_mp4_tag(fd, size, (char*) &genre, sizeof(genre)); | 1353 | read_mp4_tag(fd, size, (char*) &genre, sizeof(genre)); |
1358 | id3->genre = betoh16(genre); | 1354 | id3->genre_string = id3_get_num_genre(betoh16(genre)); |
1359 | } | 1355 | } |
1360 | break; | 1356 | break; |
1361 | 1357 | ||
@@ -1591,7 +1587,6 @@ static bool read_mp4_container(int fd, struct mp3entry* id3, | |||
1591 | static bool get_mp4_metadata(int fd, struct mp3entry* id3) | 1587 | static bool get_mp4_metadata(int fd, struct mp3entry* id3) |
1592 | { | 1588 | { |
1593 | id3->codectype = AFMT_UNKNOWN; | 1589 | id3->codectype = AFMT_UNKNOWN; |
1594 | id3->genre = 255; | ||
1595 | id3->filesize = 0; | 1590 | id3->filesize = 0; |
1596 | errno = 0; | 1591 | errno = 0; |
1597 | 1592 | ||
@@ -2179,7 +2174,7 @@ bool get_metadata(struct track_info* track, int fd, const char* trackname, | |||
2179 | break; | 2174 | break; |
2180 | case AFMT_SPC: | 2175 | case AFMT_SPC: |
2181 | track->id3.filesize = filesize(fd); | 2176 | track->id3.filesize = filesize(fd); |
2182 | track->id3.genre = 36; | 2177 | track->id3.genre_string = id3_get_num_genre(36); |
2183 | break; | 2178 | break; |
2184 | case AFMT_ADX: | 2179 | case AFMT_ADX: |
2185 | if (!get_adx_metadata(fd, &(track->id3))) | 2180 | if (!get_adx_metadata(fd, &(track->id3))) |
diff --git a/apps/screens.c b/apps/screens.c index 9835d28d8f..df1eb6a2f8 100644 --- a/apps/screens.c +++ b/apps/screens.c | |||
@@ -1181,7 +1181,7 @@ static char * id3_get_info(int selected_item, void* data, char *buffer) | |||
1181 | info=id3->comment; | 1181 | info=id3->comment; |
1182 | break; | 1182 | break; |
1183 | case 6:/*LANG_ID3_GENRE*/ | 1183 | case 6:/*LANG_ID3_GENRE*/ |
1184 | info = id3_get_genre(id3); | 1184 | info = id3->genre_string; |
1185 | break; | 1185 | break; |
1186 | case 7:/*LANG_ID3_YEAR*/ | 1186 | case 7:/*LANG_ID3_YEAR*/ |
1187 | if (id3->year_string) | 1187 | if (id3->year_string) |
diff --git a/apps/tagcache.c b/apps/tagcache.c index a0c6d66541..46614ef5df 100644 --- a/apps/tagcache.c +++ b/apps/tagcache.c | |||
@@ -1534,7 +1534,6 @@ static void add_tagcache(char *path) | |||
1534 | bool ret; | 1534 | bool ret; |
1535 | int fd; | 1535 | int fd; |
1536 | char tracknumfix[3]; | 1536 | char tracknumfix[3]; |
1537 | char *genrestr; | ||
1538 | int offset = 0; | 1537 | int offset = 0; |
1539 | int path_length = strlen(path); | 1538 | int path_length = strlen(path); |
1540 | 1539 | ||
@@ -1620,8 +1619,6 @@ static void add_tagcache(char *path) | |||
1620 | } | 1619 | } |
1621 | } | 1620 | } |
1622 | 1621 | ||
1623 | genrestr = id3_get_genre(&track.id3); | ||
1624 | |||
1625 | /* Numeric tags */ | 1622 | /* Numeric tags */ |
1626 | entry.tag_offset[tag_year] = track.id3.year; | 1623 | entry.tag_offset[tag_year] = track.id3.year; |
1627 | entry.tag_offset[tag_tracknumber] = track.id3.tracknum; | 1624 | entry.tag_offset[tag_tracknumber] = track.id3.tracknum; |
@@ -1633,7 +1630,7 @@ static void add_tagcache(char *path) | |||
1633 | ADD_TAG(entry, tag_title, &track.id3.title); | 1630 | ADD_TAG(entry, tag_title, &track.id3.title); |
1634 | ADD_TAG(entry, tag_artist, &track.id3.artist); | 1631 | ADD_TAG(entry, tag_artist, &track.id3.artist); |
1635 | ADD_TAG(entry, tag_album, &track.id3.album); | 1632 | ADD_TAG(entry, tag_album, &track.id3.album); |
1636 | ADD_TAG(entry, tag_genre, &genrestr); | 1633 | ADD_TAG(entry, tag_genre, &track.id3.genre_string); |
1637 | ADD_TAG(entry, tag_composer, &track.id3.composer); | 1634 | ADD_TAG(entry, tag_composer, &track.id3.composer); |
1638 | ADD_TAG(entry, tag_comment, &track.id3.comment); | 1635 | ADD_TAG(entry, tag_comment, &track.id3.comment); |
1639 | ADD_TAG(entry, tag_albumartist, &track.id3.albumartist); | 1636 | ADD_TAG(entry, tag_albumartist, &track.id3.albumartist); |
@@ -1647,7 +1644,7 @@ static void add_tagcache(char *path) | |||
1647 | write_item(track.id3.title); | 1644 | write_item(track.id3.title); |
1648 | write_item(track.id3.artist); | 1645 | write_item(track.id3.artist); |
1649 | write_item(track.id3.album); | 1646 | write_item(track.id3.album); |
1650 | write_item(genrestr); | 1647 | write_item(track.id3.genre_string); |
1651 | write_item(track.id3.composer); | 1648 | write_item(track.id3.composer); |
1652 | write_item(track.id3.comment); | 1649 | write_item(track.id3.comment); |
1653 | write_item(track.id3.albumartist); | 1650 | write_item(track.id3.albumartist); |
diff --git a/firmware/export/id3.h b/firmware/export/id3.h index 367854fdd1..d3d5dd35ce 100644 --- a/firmware/export/id3.h +++ b/firmware/export/id3.h | |||
@@ -153,7 +153,6 @@ struct mp3entry { | |||
153 | int layer; | 153 | int layer; |
154 | int year; | 154 | int year; |
155 | unsigned char id3version; | 155 | unsigned char id3version; |
156 | unsigned char genre; | ||
157 | unsigned int codectype; | 156 | unsigned int codectype; |
158 | unsigned int bitrate; | 157 | unsigned int bitrate; |
159 | unsigned long frequency; | 158 | unsigned long frequency; |
@@ -228,7 +227,7 @@ enum { | |||
228 | 227 | ||
229 | bool get_mp3_metadata(int fd, struct mp3entry *entry, const char *filename, bool v1first); | 228 | bool get_mp3_metadata(int fd, struct mp3entry *entry, const char *filename, bool v1first); |
230 | bool mp3info(struct mp3entry *entry, const char *filename, bool v1first); | 229 | bool mp3info(struct mp3entry *entry, const char *filename, bool v1first); |
231 | char* id3_get_genre(const struct mp3entry* id3); | 230 | char* id3_get_num_genre(const unsigned int genre_num); |
232 | char* id3_get_codec(const struct mp3entry* id3); | 231 | char* id3_get_codec(const struct mp3entry* id3); |
233 | int getid3v2len(int fd); | 232 | int getid3v2len(int fd); |
234 | void adjust_mp3entry(struct mp3entry *entry, void *dest, void *orig); | 233 | void adjust_mp3entry(struct mp3entry *entry, void *dest, void *orig); |
diff --git a/firmware/id3.c b/firmware/id3.c index ac9397a209..88bc399b71 100644 --- a/firmware/id3.c +++ b/firmware/id3.c | |||
@@ -179,13 +179,10 @@ static const char* const genres[] = { | |||
179 | "Synthpop" | 179 | "Synthpop" |
180 | }; | 180 | }; |
181 | 181 | ||
182 | char* id3_get_genre(const struct mp3entry* id3) | 182 | char* id3_get_num_genre(const unsigned int genre_num) |
183 | { | 183 | { |
184 | if( id3->genre_string ) | 184 | if (genre_num < sizeof(genres)/sizeof(char*)) |
185 | return id3->genre_string ; | 185 | return (char*)genres[genre_num]; |
186 | |||
187 | if (id3->genre < sizeof(genres)/sizeof(char*)) | ||
188 | return (char*)genres[id3->genre]; | ||
189 | return NULL; | 186 | return NULL; |
190 | } | 187 | } |
191 | 188 | ||
@@ -364,23 +361,19 @@ static int parsegenre( struct mp3entry* entry, char* tag, int bufferpos ) | |||
364 | 361 | ||
365 | /* Is it a number? */ | 362 | /* Is it a number? */ |
366 | if(isdigit(tag[0])) { | 363 | if(isdigit(tag[0])) { |
367 | entry->genre = atoi( tag ); | 364 | entry->genre_string = id3_get_num_genre(atoi( tag )); |
368 | entry->genre_string = 0; | ||
369 | return tag - entry->id3v2buf; | 365 | return tag - entry->id3v2buf; |
370 | } else { | 366 | } else { |
371 | entry->genre_string = tag; | 367 | entry->genre_string = tag; |
372 | entry->genre = 0xff; | ||
373 | return bufferpos; | 368 | return bufferpos; |
374 | } | 369 | } |
375 | } else { | 370 | } else { |
376 | if( tag[0] == '(' && tag[1] != '(' ) { | 371 | if( tag[0] == '(' && tag[1] != '(' ) { |
377 | entry->genre = atoi( tag + 1 ); | 372 | entry->genre_string = id3_get_num_genre(atoi( tag + 1 )); |
378 | entry->genre_string = 0; | ||
379 | return tag - entry->id3v2buf; | 373 | return tag - entry->id3v2buf; |
380 | } | 374 | } |
381 | else { | 375 | else { |
382 | entry->genre_string = tag; | 376 | entry->genre_string = tag; |
383 | entry->genre = 0xff; | ||
384 | return bufferpos; | 377 | return bufferpos; |
385 | } | 378 | } |
386 | } | 379 | } |
@@ -616,7 +609,7 @@ static bool setid3v1title(int fd, struct mp3entry *entry) | |||
616 | 609 | ||
617 | case 6: | 610 | case 6: |
618 | /* genre */ | 611 | /* genre */ |
619 | entry->genre = ptr[0]; | 612 | entry->genre_string = id3_get_num_genre(ptr[0]); |
620 | break; | 613 | break; |
621 | } | 614 | } |
622 | } | 615 | } |
@@ -695,8 +688,7 @@ static void setid3v2title(int fd, struct mp3entry *entry) | |||
695 | } | 688 | } |
696 | entry->id3version = version; | 689 | entry->id3version = version; |
697 | entry->tracknum = entry->year = 0; | 690 | entry->tracknum = entry->year = 0; |
698 | entry->genre = 0xff; | 691 | entry->title = entry->artist = entry->album = NULL; /* FIXME incomplete */ |
699 | entry->title = entry->artist = entry->album = NULL; | ||
700 | 692 | ||
701 | global_flags = header[5]; | 693 | global_flags = header[5]; |
702 | 694 | ||
@@ -1117,7 +1109,6 @@ bool get_mp3_metadata(int fd, struct mp3entry *entry, const char *filename, bool | |||
1117 | entry->filesize = filesize(fd); | 1109 | entry->filesize = filesize(fd); |
1118 | entry->id3v2len = getid3v2len(fd); | 1110 | entry->id3v2len = getid3v2len(fd); |
1119 | entry->tracknum = 0; | 1111 | entry->tracknum = 0; |
1120 | entry->genre = 0xff; | ||
1121 | 1112 | ||
1122 | if(v1first) | 1113 | if(v1first) |
1123 | v1found = setid3v1title(fd, entry); | 1114 | v1found = setid3v1title(fd, entry); |