/* * 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 datestamp * | album | count title * | | number | | length | path * | | | | | | | | * ... 0 2 12 3741780495 13 232 Ocarina Medley | * Hyrule Symphony/12 - Ocarina Medley.mp3 <--- * ... 0 2 13 3741780495 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 #include #include #include #include #include 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 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)) #define TRACK_IS_EXTERNAL(track) (track->tr_library == NULL) /* 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 defragment the track database. */ bool track_db_defrag(); /* Called to update track database keys. */ void track_db_rekey(); /* 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 allocate a track without adding it to the database. */ struct track *track_alloc_external(const gchar *); /* Called to free an external track. */ void track_free_external(struct track *); /* 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 look up a track tag using only a filepath. */ struct track *track_lookup(const gchar *); /* 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 */