core/tags/album: Add Genre ID to album keys
This allows for representing albums with multiple genres. I know this doesn't happen too often, but it doesn't hurt to be covered. At the very least, now we have a genre id for constructing new albums! Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
a85a1df7de
commit
ffd09d410c
|
@ -5,6 +5,7 @@
|
||||||
#include <core/string.h>
|
#include <core/string.h>
|
||||||
#include <core/version.h>
|
#include <core/version.h>
|
||||||
#include <core/tags/album.h>
|
#include <core/tags/album.h>
|
||||||
|
#include <core/tags/genre.h>
|
||||||
#include <coverart/caa_c.h>
|
#include <coverart/caa_c.h>
|
||||||
#include <musicbrainz5/mb5_c.h>
|
#include <musicbrainz5/mb5_c.h>
|
||||||
|
|
||||||
|
@ -163,12 +164,13 @@ static bool __album_fetch_artwork(struct album *album)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static gchar *__album_key(struct artist *artist, const gchar *name,
|
static gchar *__album_key(struct artist *artist, struct genre *genre,
|
||||||
unsigned int year)
|
const gchar *name, unsigned int year)
|
||||||
{
|
{
|
||||||
if (!artist)
|
if (!artist || !genre)
|
||||||
return g_strdup_printf("%u/%s", year, name);
|
return g_strdup_printf("%u/%s", year, name);
|
||||||
return g_strdup_printf("%u/%u/%s", artist_index(artist), year, name);
|
return g_strdup_printf("%u/%u/%u/%s", artist_index(artist),
|
||||||
|
genre_index(genre), year, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct album *__album_alloc(gchar *name, unsigned int year)
|
static struct album *__album_alloc(gchar *name, unsigned int year)
|
||||||
|
@ -208,8 +210,8 @@ static void album_free(struct db_entry *dbe)
|
||||||
|
|
||||||
static gchar *album_key(struct db_entry *dbe)
|
static gchar *album_key(struct db_entry *dbe)
|
||||||
{
|
{
|
||||||
return __album_key(ALBUM(dbe)->al_artist, ALBUM(dbe)->al_name,
|
return __album_key(ALBUM(dbe)->al_artist, ALBUM(dbe)->al_genre,
|
||||||
ALBUM(dbe)->al_year);
|
ALBUM(dbe)->al_name, ALBUM(dbe)->al_year);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct db_entry *album_read(struct file *file)
|
static struct db_entry *album_read(struct file *file)
|
||||||
|
@ -254,7 +256,7 @@ void album_db_deinit()
|
||||||
|
|
||||||
struct album *album_find(const gchar *name, unsigned int year)
|
struct album *album_find(const gchar *name, unsigned int year)
|
||||||
{
|
{
|
||||||
gchar *key = __album_key(NULL, name, year);
|
gchar *key = __album_key(NULL, NULL, name, year);
|
||||||
struct album *album = ALBUM(db_find(&album_db, key));
|
struct album *album = ALBUM(db_find(&album_db, key));
|
||||||
g_free(key);
|
g_free(key);
|
||||||
return album;
|
return album;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
artist
|
artist
|
||||||
album
|
|
||||||
genre
|
genre
|
||||||
|
album
|
||||||
library
|
library
|
||||||
track
|
track
|
||||||
|
|
|
@ -5,7 +5,7 @@ function(tag_unit_test name)
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
tag_unit_test(Artist)
|
tag_unit_test(Artist)
|
||||||
tag_unit_test(Album)
|
|
||||||
tag_unit_test(Genre)
|
tag_unit_test(Genre)
|
||||||
|
tag_unit_test(Album)
|
||||||
tag_unit_test(Library)
|
tag_unit_test(Library)
|
||||||
tag_unit_test(Track)
|
tag_unit_test(Track)
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
*/
|
*/
|
||||||
#include <core/idle.h>
|
#include <core/idle.h>
|
||||||
#include <core/tags/album.h>
|
#include <core/tags/album.h>
|
||||||
|
#include <core/tags/genre.h>
|
||||||
#include <tests/test.h>
|
#include <tests/test.h>
|
||||||
|
|
||||||
static void test_verify_empty(struct album *album)
|
static void test_verify_empty(struct album *album)
|
||||||
|
@ -29,7 +30,7 @@ static void test_verify_hyrule(struct album *album)
|
||||||
|
|
||||||
key = album_ops->dbe_key(&album->al_dbe);
|
key = album_ops->dbe_key(&album->al_dbe);
|
||||||
if (album->al_artist)
|
if (album->al_artist)
|
||||||
g_assert_cmpstr_free(key, ==, "0/1998/Hyrule Symphony");
|
g_assert_cmpstr_free(key, ==, "0/0/1998/Hyrule Symphony");
|
||||||
else
|
else
|
||||||
g_assert_cmpstr_free(key, ==, "1998/Hyrule Symphony");
|
g_assert_cmpstr_free(key, ==, "1998/Hyrule Symphony");
|
||||||
}
|
}
|
||||||
|
@ -39,14 +40,18 @@ static void test_album()
|
||||||
const struct db_ops *album_ops = test_album_ops();
|
const struct db_ops *album_ops = test_album_ops();
|
||||||
struct album *album;
|
struct album *album;
|
||||||
struct artist *koji;
|
struct artist *koji;
|
||||||
|
struct genre *genre;
|
||||||
struct file f;
|
struct file f;
|
||||||
|
|
||||||
idle_init();
|
idle_init();
|
||||||
|
|
||||||
koji = artist_find("Koji Kondo");
|
koji = artist_find("Koji Kondo");
|
||||||
|
genre = genre_find("Video Game Music");
|
||||||
|
|
||||||
album = ALBUM(album_ops->dbe_alloc("1998/Hyrule Symphony"));
|
album = ALBUM(album_ops->dbe_alloc("1998/Hyrule Symphony"));
|
||||||
test_verify_hyrule(album);
|
test_verify_hyrule(album);
|
||||||
album->al_artist = koji;
|
album->al_artist = koji;
|
||||||
|
album->al_genre = genre;
|
||||||
test_verify_hyrule(album);
|
test_verify_hyrule(album);
|
||||||
g_assert_true( album_match_token(album, "hyrule"));
|
g_assert_true( album_match_token(album, "hyrule"));
|
||||||
g_assert_true( album_match_token(album, "symphony"));
|
g_assert_true( album_match_token(album, "symphony"));
|
||||||
|
@ -173,6 +178,7 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
idle_init();
|
idle_init();
|
||||||
artist_db_init();
|
artist_db_init();
|
||||||
|
genre_db_init();
|
||||||
album_db_init();
|
album_db_init();
|
||||||
g_test_init(&argc, &argv, NULL);
|
g_test_init(&argc, &argv, NULL);
|
||||||
g_test_add_func("/Core/Tags/Album", test_album);
|
g_test_add_func("/Core/Tags/Album", test_album);
|
||||||
|
|
Loading…
Reference in New Issue