2014-11-19 08:09:05 -05:00
|
|
|
/**
|
|
|
|
* Copyright 2014 (c) Anna Schumaker.
|
|
|
|
*/
|
|
|
|
#ifndef OCARINA_CORE_TAGS_TRACK_H
|
|
|
|
#define OCARINA_CORE_TAGS_TRACK_H
|
|
|
|
|
2015-10-27 18:30:49 -04:00
|
|
|
extern "C" {
|
|
|
|
#include <core/date.h>
|
|
|
|
}
|
2014-11-19 08:09:05 -05:00
|
|
|
#include <core/tags/generic.h>
|
2014-11-19 09:08:38 -05:00
|
|
|
#include <core/tags/artist.h>
|
|
|
|
#include <core/tags/album.h>
|
|
|
|
#include <core/tags/genre.h>
|
|
|
|
#include <core/tags/library.h>
|
2014-11-19 08:09:05 -05:00
|
|
|
|
|
|
|
|
2014-12-04 08:29:17 -05:00
|
|
|
/**
|
|
|
|
* The Track tag is used to store information about tracks that
|
|
|
|
* have been added to the tag database.
|
|
|
|
*/
|
2015-10-24 19:34:45 -04:00
|
|
|
struct track : public GenericTag {
|
|
|
|
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. */
|
2014-11-20 08:16:13 -05:00
|
|
|
|
2015-10-24 19:34:45 -04:00
|
|
|
unsigned int tr_count; /* This track's play count. */
|
|
|
|
unsigned int tr_length; /* This track's length, in seconds. */
|
|
|
|
unsigned int tr_track; /* This track's track number. */
|
2014-11-24 08:38:19 -05:00
|
|
|
|
2015-10-24 19:34:45 -04:00
|
|
|
struct date tr_date; /* This track's last-played date. */
|
|
|
|
std::string tr_path; /* This track's path, relative to the library. */
|
2014-11-26 21:25:39 -05:00
|
|
|
|
2014-11-20 08:22:50 -05:00
|
|
|
/**
|
|
|
|
* Track constructor
|
|
|
|
*
|
2014-11-21 08:11:03 -05:00
|
|
|
* @param album The album containing this track.
|
2014-11-20 08:41:18 -05:00
|
|
|
* @param artist The artist performing this track.
|
2014-11-21 08:25:35 -05:00
|
|
|
* @param genre The genre describing this track.
|
2014-11-20 08:22:50 -05:00
|
|
|
* @param library The library containing this track.
|
2014-11-29 10:17:21 -05:00
|
|
|
* @param filepath The path of this track, relative to the library root.
|
2014-11-26 08:23:20 -05:00
|
|
|
* @param name The name (title) of this track.
|
2014-11-24 16:25:50 -05:00
|
|
|
* @param length The length of this track (in seconds).
|
2014-11-24 08:38:19 -05:00
|
|
|
* @param track The track number of this track.
|
2014-11-20 08:22:50 -05:00
|
|
|
*/
|
2015-10-24 19:34:45 -04:00
|
|
|
track(struct album *, struct artist *, struct genre *, struct library *,
|
2015-10-22 11:28:45 -04:00
|
|
|
const std::string &, const std::string &, unsigned int,
|
|
|
|
unsigned int);
|
2014-11-20 08:22:50 -05:00
|
|
|
|
2014-11-29 10:50:23 -05:00
|
|
|
/**
|
|
|
|
* Track copy constructor
|
|
|
|
*
|
|
|
|
* @param track The Track tag that should be copied.
|
|
|
|
*/
|
2015-10-24 19:34:45 -04:00
|
|
|
track(const struct track &);
|
2014-11-29 10:50:23 -05:00
|
|
|
|
2015-10-24 19:34:45 -04:00
|
|
|
track(); /**< Track constructor. */
|
|
|
|
~track(); /**< Track destructor. */
|
2014-11-19 08:09:05 -05:00
|
|
|
|
2014-11-20 08:16:13 -05:00
|
|
|
|
2015-10-22 08:16:53 -04:00
|
|
|
struct album *album(); /**< @return Track::_album. */
|
2015-10-22 11:28:45 -04:00
|
|
|
struct artist *artist(); /**< @return Track::_artist. */
|
2015-10-23 08:19:26 -04:00
|
|
|
struct genre *genre(); /**< @return Track::_genre. */
|
2015-10-23 10:21:12 -04:00
|
|
|
struct library *library(); /**< @return Track::_library. */
|
2014-11-20 08:16:13 -05:00
|
|
|
|
2014-11-24 16:25:50 -05:00
|
|
|
unsigned int count(); /**< @return Track::_count. */
|
|
|
|
unsigned int length(); /**< @return Track::_length. */
|
2015-10-24 19:34:45 -04:00
|
|
|
unsigned int track_nr(); /**< @return Track::_track. */
|
2014-11-20 08:16:13 -05:00
|
|
|
|
2014-11-26 21:25:39 -05:00
|
|
|
|
2014-11-27 10:37:46 -05:00
|
|
|
/**
|
|
|
|
* @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;
|
|
|
|
|
2014-11-26 21:25:39 -05:00
|
|
|
/** @return The full path of this track. */
|
|
|
|
const std::string path() const;
|
|
|
|
|
2014-11-19 08:09:05 -05:00
|
|
|
/**
|
2014-11-26 21:25:39 -05:00
|
|
|
* A track's primary key is the concatenation of the library index
|
|
|
|
* and the relative path.
|
|
|
|
*
|
2014-12-04 08:29:17 -05:00
|
|
|
* @return Track::_library->index() / Track::_path.
|
2014-11-19 08:09:05 -05:00
|
|
|
*/
|
|
|
|
const std::string primary_key() const;
|
|
|
|
|
2014-11-27 10:37:46 -05:00
|
|
|
/** Increment Track::_count and set Track::_date to today's date. */
|
|
|
|
void played();
|
|
|
|
|
2014-11-28 10:21:35 -05:00
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
*/
|
2015-10-24 19:34:45 -04:00
|
|
|
int compare_date(const struct track *);
|
2014-11-28 10:21:35 -05:00
|
|
|
|
2014-11-26 21:25:39 -05:00
|
|
|
|
2014-11-19 08:09:05 -05:00
|
|
|
/**
|
2014-12-04 08:29:17 -05:00
|
|
|
* Read track data from file.
|
|
|
|
*
|
|
|
|
* @param file The file to read from.
|
2014-11-19 08:09:05 -05:00
|
|
|
*/
|
2015-09-10 08:00:42 -04:00
|
|
|
void read(file &);
|
2014-11-19 08:09:05 -05:00
|
|
|
|
|
|
|
/**
|
2014-12-04 08:29:17 -05:00
|
|
|
* Write track data to file.
|
|
|
|
*
|
|
|
|
* @param file The file to write to.
|
2014-11-19 08:09:05 -05:00
|
|
|
*/
|
2015-09-10 08:00:42 -04:00
|
|
|
void write(file &);
|
2014-11-19 08:09:05 -05:00
|
|
|
};
|
|
|
|
|
2014-11-29 10:38:27 -05:00
|
|
|
namespace tags
|
|
|
|
{
|
2014-12-02 08:16:22 -05:00
|
|
|
/** Called to read the track_db from disk. */
|
|
|
|
void init_track_db();
|
|
|
|
|
2014-11-29 10:38:27 -05:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2015-10-24 19:34:45 -04:00
|
|
|
struct track *add_track(struct album *, struct artist *, struct genre *,
|
2015-10-23 10:21:12 -04:00
|
|
|
struct library *, const std::string &,
|
|
|
|
const std::string &, unsigned int, unsigned int);
|
2014-11-29 11:11:49 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2015-10-24 19:34:45 -04:00
|
|
|
struct track *get_track(const unsigned int);
|
2014-11-29 11:16:21 -05:00
|
|
|
|
2014-12-01 08:24:56 -05:00
|
|
|
/**
|
|
|
|
* Called to remove a Track tag from the database.
|
|
|
|
*
|
|
|
|
* @param track The Track tag to be removed.
|
|
|
|
*/
|
2015-10-24 19:34:45 -04:00
|
|
|
void remove_track(struct track *);
|
2014-12-01 08:24:56 -05:00
|
|
|
|
2014-12-01 09:36:37 -05:00
|
|
|
/**
|
|
|
|
* Called to remove all tracks associated with a specific Library.
|
|
|
|
*
|
|
|
|
* @param library The Library tag that will be matched.
|
|
|
|
*/
|
2015-10-23 10:21:12 -04:00
|
|
|
void remove_library_tracks(struct library *);
|
2014-12-01 09:36:37 -05:00
|
|
|
|
2014-12-01 09:44:32 -05:00
|
|
|
/**
|
|
|
|
* 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();
|
|
|
|
|
2014-11-29 11:16:21 -05:00
|
|
|
/** Called to write the track_db to disk. */
|
|
|
|
void commit_track_db();
|
2014-11-29 10:38:27 -05:00
|
|
|
}
|
|
|
|
|
2014-11-19 08:09:05 -05:00
|
|
|
#endif /* OCARINA_CORE_TAGS_TRACK_H */
|