diff --git a/taglib/mpeg/id3v1/id3v1genres.cpp b/taglib/mpeg/id3v1/id3v1genres.cpp index e2138976..d72a2a75 100644 --- a/taglib/mpeg/id3v1/id3v1genres.cpp +++ b/taglib/mpeg/id3v1/id3v1genres.cpp @@ -261,5 +261,26 @@ int ID3v1::genreIndex(const String &name) return i; } + // If the name was not found, try the names which have been changed + static const struct { + const wchar_t *genre; + int code; + } fixUpGenres[] = { + { L"Jazz+Funk", 29 }, + { L"Folk/Rock", 81 }, + { L"Bebob", 85 }, + { L"Avantgarde", 90 }, + { L"Dance Hall", 125 }, + { L"Hardcore", 129 }, + { L"BritPop", 132 }, + { L"Negerpunk", 133 } + }; + static const int fixUpGenresSize = + sizeof(fixUpGenres) / sizeof(fixUpGenres[0]); + for(int i = 0; i < fixUpGenresSize; ++i) { + if(name == fixUpGenres[i].genre) + return fixUpGenres[i].code; + } + return 255; } diff --git a/tests/test_id3v1.cpp b/tests/test_id3v1.cpp index 3358aead..c50c3428 100644 --- a/tests/test_id3v1.cpp +++ b/tests/test_id3v1.cpp @@ -40,6 +40,7 @@ class TestID3v1 : public CppUnit::TestFixture CPPUNIT_TEST_SUITE(TestID3v1); CPPUNIT_TEST(testStripWhiteSpace); CPPUNIT_TEST(testGenres); + CPPUNIT_TEST(testRenamedGenres); CPPUNIT_TEST_SUITE_END(); public: @@ -68,6 +69,18 @@ public: CPPUNIT_ASSERT_EQUAL(100, ID3v1::genreIndex("Humour")); } + void testRenamedGenres() + { + CPPUNIT_ASSERT_EQUAL(String("Bebop"), ID3v1::genre(85)); + CPPUNIT_ASSERT_EQUAL(85, ID3v1::genreIndex("Bebop")); + CPPUNIT_ASSERT_EQUAL(85, ID3v1::genreIndex("Bebob")); + + ID3v1::Tag tag; + tag.setGenre("Hardcore"); + CPPUNIT_ASSERT_EQUAL(String("Hardcore Techno"), tag.genre()); + CPPUNIT_ASSERT_EQUAL(129U, tag.genreNumber()); + } + }; CPPUNIT_TEST_SUITE_REGISTRATION(TestID3v1);