Track: Hide the album tag from the public

And set it using the new constructor.

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2014-11-21 08:11:03 -05:00
parent 0a6ace3c14
commit c6029f13f2
6 changed files with 24 additions and 19 deletions

View File

@ -22,7 +22,7 @@ Database<Track> track_db("track.db", false);
*/ */
Track :: Track(const std::string &f, Library *library) Track :: Track(const std::string &f, Library *library)
: _artist(NULL), _library(library), album(NULL), genre(NULL), : _album(NULL), _artist(NULL), _library(library), genre(NULL),
play_count(0), last_year(0), last_month(0), last_day(0), play_count(0), last_year(0), last_month(0), last_day(0),
filepath(f.substr(library->primary_key().size() + 1)) filepath(f.substr(library->primary_key().size() + 1))
{ {
@ -53,12 +53,12 @@ void Track :: read(File &f)
_library = tags :: get_library(library_id); _library = tags :: get_library(library_id);
_artist = tags :: get_artist(artist_id); _artist = tags :: get_artist(artist_id);
album = tags :: get_album(album_id); _album = tags :: get_album(album_id);
genre = tags :: get_genre(genre_id); genre = tags :: get_genre(genre_id);
title_lower = filter :: add(title, index()); title_lower = filter :: add(title, index());
filter :: add(_artist->name(), index()); filter :: add(_artist->name(), index());
filter :: add(album->name(), index()); filter :: add(_album->name(), index());
_library->inc_size(); _library->inc_size();
set_length_str(); set_length_str();
} }
@ -66,7 +66,7 @@ void Track :: read(File &f)
void Track :: write(File &f) void Track :: write(File &f)
{ {
f << _library->index() << " " << _artist->index() << " "; f << _library->index() << " " << _artist->index() << " ";
f << album->index() << " " << genre->index() << " " << track << " "; f << _album->index() << " " << genre->index() << " " << track << " ";
f << last_year << " " << last_month << " " << last_day << " "; f << last_year << " " << last_month << " " << last_day << " ";
f << play_count << " " << length << " " << title << std::endl; f << play_count << " " << length << " " << title << std::endl;
f << filepath << std::endl; f << filepath << std::endl;
@ -115,7 +115,7 @@ bool Track :: tag()
audio = ref.audioProperties(); audio = ref.audioProperties();
_artist = tags :: get_artist(format_tag(tag->artist())); _artist = tags :: get_artist(format_tag(tag->artist()));
album = tags :: get_album(format_tag(tag->album()), tag->year()); _album = tags :: get_album(format_tag(tag->album()), tag->year());
genre = tags :: get_genre(format_tag(tag->genre())); genre = tags :: get_genre(format_tag(tag->genre()));
track = tag->track(); track = tag->track();
length = audio->length(); length = audio->length();
@ -125,7 +125,7 @@ bool Track :: tag()
set_length_str(); set_length_str();
filter :: add(_artist->name(), index()); filter :: add(_artist->name(), index());
filter :: add(album->name(), index()); filter :: add(_album->name(), index());
return true; return true;
} }
@ -181,7 +181,7 @@ int Track :: less_than(Track *rhs, sort_t field)
case SORT_ARTIST: case SORT_ARTIST:
return _artist->compare(rhs->artist()); return _artist->compare(rhs->artist());
case SORT_ALBUM: case SORT_ALBUM:
return album->compare(rhs->album); return _album->compare(rhs->album());
case SORT_COUNT: case SORT_COUNT:
return compare_uint(play_count, rhs->play_count); return compare_uint(play_count, rhs->play_count);
case SORT_GENRE: case SORT_GENRE:
@ -201,7 +201,7 @@ int Track :: less_than(Track *rhs, sort_t field)
case SORT_TRACK: case SORT_TRACK:
return compare_uint(track, rhs->track); return compare_uint(track, rhs->track);
case SORT_YEAR: case SORT_YEAR:
return compare_uint(album->year(), rhs->album->year()); return compare_uint(_album->year(), rhs->album()->year());
} }
return 0; return 0;
} }

View File

@ -7,15 +7,17 @@
Track :: Track() Track :: Track()
: GenericTag(), : GenericTag(),
_artist(NULL), _library(NULL), album(NULL), genre(NULL), _album(NULL), _artist(NULL), _library(NULL), genre(NULL),
track(0), length(0), play_count(0), last_year(0), last_month(0), last_day(0) track(0), length(0), play_count(0), last_year(0), last_month(0), last_day(0)
{} {}
Track :: Track(Artist *artist, Library *library) Track :: Track(Album *album, Artist *artist, Library *library)
: _artist(artist), _library(library) : _album(album), _artist(artist), _library(library)
{ {
_library->inc_size(); _library->inc_size();
} }
Album *Track :: album() { return _album; }
Artist *Track :: artist() { return _artist; } Artist *Track :: artist() { return _artist; }
Library *Track :: library() { return _library; } Library *Track :: library() { return _library; }

View File

@ -48,7 +48,7 @@ static void on_track_loaded(Track *track)
set_label_text(title, "xx-large", track->title); set_label_text(title, "xx-large", track->title);
set_label_text(artist, "x-large", "By: " + track->artist()->name()); set_label_text(artist, "x-large", "By: " + track->artist()->name());
set_label_text(album, "x-large", "From: " + track->album->name()); set_label_text(album, "x-large", "From: " + track->album()->name());
duration->set_text(track->length_str); duration->set_text(track->length_str);
bool banned = playlist :: has(track, "Banned"); bool banned = playlist :: has(track, "Banned");

View File

@ -39,14 +39,13 @@ enum sort_t {
class Track : public GenericTag { class Track : public GenericTag {
private: private:
Album *_album; /**< Pointer to the Album containing this track. */
Artist *_artist; /**< Pointer to the Artist performing this track. */ Artist *_artist; /**< Pointer to the Artist performing this track. */
Library *_library; /**< Pointer to the Library containing this track. */ Library *_library; /**< Pointer to the Library containing this track. */
void set_length_str(); void set_length_str();
public: public:
/** Pointer to this track's album information */
Album *album;
/** Pointer to this track's genre information */ /** Pointer to this track's genre information */
Genre *genre; Genre *genre;
@ -78,10 +77,11 @@ public:
/** /**
* Track constructor * Track constructor
* *
* @param album The album containing this track.
* @param artist The artist performing this track. * @param artist The artist performing this track.
* @param library The library containing this track. * @param library The library containing this track.
*/ */
Track(Artist *, Library *); Track(Album *, Artist *, Library *);
/** /**
* Track constructor * Track constructor
@ -94,6 +94,7 @@ public:
~Track(); ~Track();
Album *album(); /**< @return Track::_album. */
Artist *artist(); /**< @return Track::_artist. */ Artist *artist(); /**< @return Track::_artist. */
Library *library(); /**< @return Track::_library. */ Library *library(); /**< @return Track::_library. */

View File

@ -121,7 +121,7 @@ void QueueModel::get_value_uint(Track *track, int column,
specific.set(track->track); specific.set(track->track);
break; break;
case 5: case 5:
specific.set(track->album->year()); specific.set(track->album()->year());
break; break;
case 7: case 7:
specific.set(track->play_count); specific.set(track->play_count);
@ -149,7 +149,7 @@ void QueueModel::get_value_str(Track *track, int column,
specific.set(track->artist()->name()); specific.set(track->artist()->name());
break; break;
case 4: case 4:
specific.set(track->album->name()); specific.set(track->album()->name());
break; break;
case 6: case 6:
specific.set(track->genre->name()); specific.set(track->genre->name());

View File

@ -9,9 +9,9 @@ static void test_track_tag_default()
{ {
Track track; Track track;
test_equal(track.album(), (Album *)NULL);
test_equal(track.artist(), (Artist *)NULL); test_equal(track.artist(), (Artist *)NULL);
test_equal(track.library(), (Library *)NULL); test_equal(track.library(), (Library *)NULL);
test_equal(track.album, (Album *)NULL);
test_equal(track.genre, (Genre *)NULL); test_equal(track.genre, (Genre *)NULL);
test_equal(track.name(), (std::string)""); test_equal(track.name(), (std::string)"");
@ -32,10 +32,12 @@ static void test_track_tag_default()
static void test_track_tag_constructor() static void test_track_tag_constructor()
{ {
Album *album = tags :: get_album("Hyrule Symphony", 1998);
Artist *artist = tags :: get_artist("Koji Kondo"); Artist *artist = tags :: get_artist("Koji Kondo");
Library *library = tags :: get_library("/home/Zelda/Music"); Library *library = tags :: get_library("/home/Zelda/Music");
Track track(artist, library); Track track(album, artist, library);
test_equal(track.album(), album);
test_equal(track.artist(), artist); test_equal(track.artist(), artist);
test_equal(track.library(), library); test_equal(track.library(), library);
test_equal(track.library()->size(), (unsigned)1); test_equal(track.library()->size(), (unsigned)1);