ocarina/include/core/tags/track.h

183 lines
5.1 KiB
C++

/**
* Copyright 2014 (c) Anna Schumaker.
*/
#ifndef OCARINA_CORE_TAGS_TRACK_H
#define OCARINA_CORE_TAGS_TRACK_H
#include <core/tags/generic.h>
#include <core/tags/artist.h>
#include <core/tags/album.h>
#include <core/tags/genre.h>
#include <core/tags/library.h>
/** Structure used to represent dates. */
struct date {
unsigned int day; /**< Day of the month (1 - 31). */
unsigned int month; /**< Month of the year (1 - 12). */
unsigned int year; /**< Number of years, Commen Era. */
date() : day(0), month(0), year(0) {};
};
/**
* The Track tag is used to store information about tracks that
* have been added to the tag database.
*/
class Track : public GenericTag {
private:
Album *_album; /**< Pointer to the Album containing this track. */
Artist *_artist; /**< Pointer to the Artist performing this track. */
Genre *_genre; /**< Pointer to the Genre describing this track. */
Library *_library; /**< Pointer to the Library containing this track. */
unsigned int _count; /**< Number of times this track has been played.*/
unsigned int _length; /**< Length of this track (in seconds). */
unsigned int _track; /**< Track number of this track. */
struct date _date; /**< Date that we last played this track. */
std::string _path; /**< Path of this track, relative to the Library. */
public:
/**
* Track constructor
*
* @param album The album containing this track.
* @param artist The artist performing this track.
* @param genre The genre describing this track.
* @param library The library containing this track.
* @param filepath The path of this track, relative to the library root.
* @param name The name (title) of this track.
* @param length The length of this track (in seconds).
* @param track The track number of this track.
*/
Track(Album *, Artist *, Genre *, Library *, const std::string &,
const std::string &, unsigned int, unsigned int);
/**
* Track copy constructor
*
* @param track The Track tag that should be copied.
*/
Track(const Track &);
Track(); /**< Track constructor. */
~Track(); /**< Track destructor. */
Album *album(); /**< @return Track::_album. */
Artist *artist(); /**< @return Track::_artist. */
Genre *genre(); /**< @return Track::_genre. */
Library *library(); /**< @return Track::_library. */
unsigned int count(); /**< @return Track::_count. */
unsigned int length(); /**< @return Track::_length. */
unsigned int track(); /**< @return Track::_track. */
/**
* @return A locale-dependent string containing the day this
* track was last played, or "Never" if the track has
* never been played.
*/
const std::string date() const;
/** @return The full path of this track. */
const std::string path() const;
/**
* A track's primary key is the concatenation of the library index
* and the relative path.
*
* @return Track::_library->index() / Track::_path.
*/
const std::string primary_key() const;
/** Increment Track::_count and set Track::_date to today's date. */
void played();
/**
* Compare two tracks based on last played date.
*
* @param rhs The other track to compare.
* @return < 0: lhs < rhs.
* @return 0: lhs == rhs.
* @return > 0: lhs > rhs;
*/
int compare_date(const Track *);
/**
* Read track data from file.
*
* @param file The file to read from.
*/
void read(File &);
/**
* Write track data to file.
*
* @param file The file to write to.
*/
void write(File &);
};
namespace tags
{
/** Called to read the track_db from disk. */
void init_track_db();
/**
* Called to create a new Track tag.
*
* @param album The album containing this track.
* @param artist The artist performing this track.
* @param genre The genre describing this track.
* @param library The library containing this track.
* @param filepath The path of this track, relative to the library root.
* @param name The name (title) of this track.
* @param length The length of this track (in seconds).
* @param track The track number of this track.
* @return A new Track tag, or NULL if this Track is already in
* the track_db.
*/
Track *add_track(Album *, Artist *, Genre *, Library *,
const std::string &, const std::string &,
unsigned int, unsigned int);
/**
* Called to look up a Track tag by tag index.
*
* @param index The index of the Track tag.
* @return A matching Track tag, or NULL.
*/
Track *get_track(const unsigned int);
/**
* Called to remove a Track tag from the database.
*
* @param track The Track tag to be removed.
*/
void remove_track(Track *);
/**
* Called to remove all tracks associated with a specific Library.
*
* @param library The Library tag that will be matched.
*/
void remove_library_tracks(Library *);
/**
* Called to find the number of rows in the track_db,
* including NULL rows.
*
* @return The Database::actual_size() of the track_db.
*/
unsigned int track_size();
/** Called to write the track_db to disk. */
void commit_track_db();
}
#endif /* OCARINA_CORE_TAGS_TRACK_H */