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:
Anna Schumaker 2016-08-12 10:10:00 -04:00
parent a85a1df7de
commit ffd09d410c
4 changed files with 18 additions and 10 deletions

View File

@ -5,6 +5,7 @@
#include <core/string.h>
#include <core/version.h>
#include <core/tags/album.h>
#include <core/tags/genre.h>
#include <coverart/caa_c.h>
#include <musicbrainz5/mb5_c.h>
@ -163,12 +164,13 @@ static bool __album_fetch_artwork(struct album *album)
return true;
}
static gchar *__album_key(struct artist *artist, const gchar *name,
unsigned int year)
static gchar *__album_key(struct artist *artist, struct genre *genre,
const gchar *name, unsigned int year)
{
if (!artist)
if (!artist || !genre)
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)
@ -208,8 +210,8 @@ static void album_free(struct db_entry *dbe)
static gchar *album_key(struct db_entry *dbe)
{
return __album_key(ALBUM(dbe)->al_artist, ALBUM(dbe)->al_name,
ALBUM(dbe)->al_year);
return __album_key(ALBUM(dbe)->al_artist, ALBUM(dbe)->al_genre,
ALBUM(dbe)->al_name, ALBUM(dbe)->al_year);
}
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)
{
gchar *key = __album_key(NULL, name, year);
gchar *key = __album_key(NULL, NULL, name, year);
struct album *album = ALBUM(db_find(&album_db, key));
g_free(key);
return album;

View File

@ -1,5 +1,5 @@
artist
album
genre
album
library
track

View File

@ -5,7 +5,7 @@ function(tag_unit_test name)
endfunction()
tag_unit_test(Artist)
tag_unit_test(Album)
tag_unit_test(Genre)
tag_unit_test(Album)
tag_unit_test(Library)
tag_unit_test(Track)

View File

@ -3,6 +3,7 @@
*/
#include <core/idle.h>
#include <core/tags/album.h>
#include <core/tags/genre.h>
#include <tests/test.h>
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);
if (album->al_artist)
g_assert_cmpstr_free(key, ==, "0/1998/Hyrule Symphony");
g_assert_cmpstr_free(key, ==, "0/0/1998/Hyrule Symphony");
else
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();
struct album *album;
struct artist *koji;
struct genre *genre;
struct file f;
idle_init();
koji = artist_find("Koji Kondo");
genre = genre_find("Video Game Music");
album = ALBUM(album_ops->dbe_alloc("1998/Hyrule Symphony"));
test_verify_hyrule(album);
album->al_artist = koji;
album->al_genre = genre;
test_verify_hyrule(album);
g_assert_true( album_match_token(album, "hyrule"));
g_assert_true( album_match_token(album, "symphony"));
@ -173,6 +178,7 @@ int main(int argc, char **argv)
idle_init();
artist_db_init();
genre_db_init();
album_db_init();
g_test_init(&argc, &argv, NULL);
g_test_add_func("/Core/Tags/Album", test_album);