From 2dfa9bf168acf196cc5e2283716cdd0ba70a5619 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Fri, 21 Nov 2014 08:25:35 -0500 Subject: [PATCH] Track: Hide the genre tag from the public And set it using the new constructor. Signed-off-by: Anna Schumaker --- core/tags.cpp | 10 +++++----- core/tags/track.cpp | 8 ++++---- include/core/tags/track.h | 8 ++++---- lib/model.cpp | 2 +- tests/core/tags/track.cpp | 6 ++++-- 5 files changed, 18 insertions(+), 16 deletions(-) diff --git a/core/tags.cpp b/core/tags.cpp index 159753fd..11ef54ad 100644 --- a/core/tags.cpp +++ b/core/tags.cpp @@ -22,7 +22,7 @@ Database track_db("track.db", false); */ Track :: Track(const std::string &f, Library *library) - : _album(NULL), _artist(NULL), _library(library), genre(NULL), + : _album(NULL), _artist(NULL), _genre(NULL), _library(library), play_count(0), last_year(0), last_month(0), last_day(0), filepath(f.substr(library->primary_key().size() + 1)) { @@ -54,7 +54,7 @@ void Track :: read(File &f) _library = tags :: get_library(library_id); _artist = tags :: get_artist(artist_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()); filter :: add(_artist->name(), index()); @@ -66,7 +66,7 @@ void Track :: read(File &f) void Track :: write(File &f) { 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 << play_count << " " << length << " " << title << std::endl; f << filepath << std::endl; @@ -116,7 +116,7 @@ bool Track :: tag() _artist = tags :: get_artist(format_tag(tag->artist())); _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(); length = audio->length(); title = format_tag(tag->title()); @@ -185,7 +185,7 @@ int Track :: less_than(Track *rhs, sort_t field) case SORT_COUNT: return compare_uint(play_count, rhs->play_count); case SORT_GENRE: - return genre->compare(rhs->genre); + return _genre->compare(rhs->genre()); case SORT_LENGTH: return compare_uint(length, rhs->length); case SORT_PLAYED: diff --git a/core/tags/track.cpp b/core/tags/track.cpp index 149b347d..d8b6cdf0 100644 --- a/core/tags/track.cpp +++ b/core/tags/track.cpp @@ -7,17 +7,17 @@ Track :: Track() : GenericTag(), - _album(NULL), _artist(NULL), _library(NULL), genre(NULL), + _album(NULL), _artist(NULL), _genre(NULL), _library(NULL), track(0), length(0), play_count(0), last_year(0), last_month(0), last_day(0) {} -Track :: Track(Album *album, Artist *artist, Library *library) - : _album(album), _artist(artist), _library(library) - +Track :: Track(Album *album, Artist *artist, Genre *genre, Library *library) + : _album(album), _artist(artist), _genre(genre), _library(library) { _library->inc_size(); } Album *Track :: album() { return _album; } Artist *Track :: artist() { return _artist; } +Genre *Track :: genre() { return _genre; } Library *Track :: library() { return _library; } diff --git a/include/core/tags/track.h b/include/core/tags/track.h index b344c25d..36786365 100644 --- a/include/core/tags/track.h +++ b/include/core/tags/track.h @@ -41,14 +41,12 @@ 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. */ void set_length_str(); public: - /** Pointer to this track's genre information */ - Genre *genre; - /** Track number of this track */ unsigned int track; /** Length of this track (in seconds) */ @@ -79,9 +77,10 @@ public: * * @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. */ - Track(Album *, Artist *, Library *); + Track(Album *, Artist *, Genre *, Library *); /** * Track constructor @@ -96,6 +95,7 @@ public: Album *album(); /**< @return Track::_album. */ Artist *artist(); /**< @return Track::_artist. */ + Genre *genre(); /**< @return Track::_genre. */ Library *library(); /**< @return Track::_library. */ diff --git a/lib/model.cpp b/lib/model.cpp index a2ed1891..3b153e80 100644 --- a/lib/model.cpp +++ b/lib/model.cpp @@ -152,7 +152,7 @@ void QueueModel::get_value_str(Track *track, int column, specific.set(track->album()->name()); break; case 6: - specific.set(track->genre->name()); + specific.set(track->genre()->name()); break; case 8: if (track->play_count == 0) diff --git a/tests/core/tags/track.cpp b/tests/core/tags/track.cpp index d0e5febb..f7707056 100644 --- a/tests/core/tags/track.cpp +++ b/tests/core/tags/track.cpp @@ -11,8 +11,8 @@ static void test_track_tag_default() test_equal(track.album(), (Album *)NULL); test_equal(track.artist(), (Artist *)NULL); + test_equal(track.genre(), (Genre *)NULL); test_equal(track.library(), (Library *)NULL); - test_equal(track.genre, (Genre *)NULL); test_equal(track.name(), (std::string)""); test_equal(track.lowercase(), (std::string)""); @@ -34,11 +34,13 @@ static void test_track_tag_constructor() { Album *album = tags :: get_album("Hyrule Symphony", 1998); Artist *artist = tags :: get_artist("Koji Kondo"); + Genre *genre = tags :: get_genre("Video Game Music"); Library *library = tags :: get_library("/home/Zelda/Music"); - Track track(album, artist, library); + Track track(album, artist, genre, library); test_equal(track.album(), album); test_equal(track.artist(), artist); + test_equal(track.genre(), genre); test_equal(track.library(), library); test_equal(track.library()->size(), (unsigned)1); }