ocarina/include/core/tags/track.h

130 lines
4.4 KiB
C

/*
* Copyright 2014 (c) Anna Schumaker.
*
* The Track tag is used to store information about tracks
* that have been added to the tag database.
*
* When writing a Track tag to disk, write as many fields as
* possible on one line before spilling over to a second:
*
* library number count
* | artist | year | length
* | | album| | month | | title
* | | | genre | | day| | | path
* | | | | | | | | | | | |
* ... 0 1 2 1 12 2015 10 15 13 232 Ocarina Medley |
* Hyrule Symphony/12 - Ocarina Medley.mp3 <---
* ... 0 1 2 1 13 2015 10 15 10 288 Legend of Zelda Medley
* Hyrule Symphony/13 - Legend of Zelda Medly.mp3
*/
#ifndef OCARINA_CORE_TAGS_TRACK_H
#define OCARINA_CORE_TAGS_TRACK_H
#include <core/database.h>
#include <core/date.h>
#include <core/tags/album.h>
#include <core/tags/artist.h>
#include <core/tags/genre.h>
#include <core/tags/library.h>
enum compare_t {
COMPARE_ARTIST = 1, /* Compare tracks by artist name. */
COMPARE_ALBUM = 2, /* Compare tracks by album name. */
COMPARE_COUNT = 3, /* Compare tracks by play count. */
COMPARE_GENRE = 4, /* Compare tracks by genre. */
COMPARE_LENGTH = 5, /* Compare tracks by length. */
COMPARE_PLAYED = 6, /* Compare tracks by last played date. */
COMPARE_TITLE = 7, /* Compare tracks by title. */
COMPARE_TRACK = 8, /* Compare tracks by track number. */
COMPARE_YEAR = 9, /* Compare tracks by year. */
};
struct track {
struct album *tr_album; /* This track's associated album. */
struct artist *tr_artist; /* This track's associated artist. */
struct genre *tr_genre; /* This track's associated genre. */
struct library *tr_library; /* This track's associated library. */
unsigned short int tr_count; /* This track's play count. */
unsigned short int tr_length; /* This track's length, in seconds. */
unsigned short int tr_track; /* This track's track number. */
struct date tr_date; /* This track's last-played date. */
gchar *tr_path; /* This track's path, relative to the library. */
gchar *tr_title; /* This track's title. */
gchar **tr_tokens; /* This track's tokenized strings. */
gchar **tr_alts; /* This track's alternate ascii tokens. */
struct db_entry tr_dbe;
};
#define TRACK(dbe) ((struct track *)DBE_DATA(dbe))
/* Called to initialize the track database. */
void track_db_init();
/* Called to clean up the track database. */
void track_db_deinit();
/* Called to commit the track database. */
void track_db_commit();
/* Called to access the track database. */
const struct database *track_db_get();
/* Called to find the number of unplayed tracks in the database. */
unsigned int track_db_count_unplayed();
/* Called to find the total play count of all tracks in the database. */
unsigned int track_db_count_plays();
/* Called to find the average play count of tracks in the database. */
unsigned int track_db_average_plays();
/* Called to add a track tag to the database. */
struct track *track_add(struct library *, const gchar *);
/* Called to remove a specific track tag. */
void track_remove(struct track *);
/* Called to remove all tracks associated with a specific library. */
void track_remove_all(struct library *);
/* Called to get a track tag with a specific index. */
struct track *track_get(const unsigned int);
/* Called to compare two track tags */
int track_compare(struct track *, struct track *, enum compare_t);
/* Called to check if a track has a token that matches the given string */
bool track_match_token(struct track *, const gchar *);
/* Called to find the database index of the track tag. */
static inline unsigned int track_index(struct track *track)
{
return track->tr_dbe.dbe_index;
}
/*
* Called to find the full path of the track tag.
* This function returns a new string that MUST be freed with g_free().
*/
gchar *track_path(struct track *);
/* Called to mark a track tag as played. */
void track_played(struct track *);
/*
* Called to find the date that this track was last played.
* This function returns a new string that MUST be freed with g_free().
*/
gchar *track_last_play(struct track *);
#ifdef CONFIG_TESTING
const struct db_ops *test_track_ops();
#endif /* CONFIG_TESTING */
#endif /* OCARINA_CORE_TAGS_TRACK_H */