From 2540a6aa7a7f0b607daa7430227b6ec380b7aed0 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Wed, 26 Nov 2014 08:23:20 -0500 Subject: [PATCH] Track: Use GenericTag's _name and _lowercase fields This lets me remove the duplicate title and title_lowercase fields from the Track tag. Signed-off-by: Anna Schumaker --- core/tags.cpp | 15 ++++++++------- core/tags/track.cpp | 5 +++-- gui/gui.cpp | 2 +- include/core/tags/track.h | 8 +++----- lib/model.cpp | 2 +- tests/core/tags/track.cpp | 7 ++++--- 6 files changed, 20 insertions(+), 19 deletions(-) diff --git a/core/tags.cpp b/core/tags.cpp index 256f63af..036fc7b1 100644 --- a/core/tags.cpp +++ b/core/tags.cpp @@ -42,7 +42,7 @@ void Track :: read(File &f) f >> _track >> last_year >> last_month >> last_day; f >> _count >> _length; - title = f.getline(); + GenericTag :: read(f); filepath = f.getline(); _library = tags :: get_library(library_id); @@ -50,7 +50,7 @@ void Track :: read(File &f) _album = tags :: get_album(album_id); _genre = tags :: get_genre(genre_id); - title_lower = filter :: add(title, index()); + filter :: add(name(), index()); filter :: add(_artist->name(), index()); filter :: add(_album->name(), index()); _library->inc_size(); @@ -62,8 +62,9 @@ void Track :: write(File &f) f << _library->index() << " " << _artist->index() << " "; f << _album->index() << " " << _genre->index() << " " << _track << " "; f << last_year << " " << last_month << " " << last_day << " "; - f << _count << " " << _length << " " << title << std::endl; - f << filepath << std::endl; + f << _count << " " << _length << " "; + GenericTag :: write(f); + f << std::endl << filepath << std::endl; } void Track :: set_length_str() @@ -113,9 +114,9 @@ bool Track :: tag() _genre = tags :: get_genre(format_tag(tag->genre())); _track = tag->track(); _length = audio->length(); - title = format_tag(tag->title()); + //_title = format_tag(tag->title()); - title_lower = filter :: add(title, index()); + //title_lower = filter :: add(title, index()); set_length_str(); filter :: add(_artist->name(), index()); @@ -191,7 +192,7 @@ int Track :: less_than(Track *rhs, sort_t field) } return ret; case SORT_TITLE: - return compare_string(title_lower, rhs->title_lower); + return compare(rhs); case SORT_TRACK: return compare_uint(_track, rhs->_track); case SORT_YEAR: diff --git a/core/tags/track.cpp b/core/tags/track.cpp index a28e8914..23013caf 100644 --- a/core/tags/track.cpp +++ b/core/tags/track.cpp @@ -12,8 +12,9 @@ Track :: Track() {} Track :: Track(Album *album, Artist *artist, Genre *genre, Library *library, - unsigned int length, unsigned int track) - : _album(album), _artist(artist), _genre(genre), _library(library), + const std::string &name, unsigned int length, unsigned int track) + : GenericTag(name), + _album(album), _artist(artist), _genre(genre), _library(library), _count(0), _length(length), _track(track) { _library->inc_size(); diff --git a/gui/gui.cpp b/gui/gui.cpp index 58117384..06745bc8 100644 --- a/gui/gui.cpp +++ b/gui/gui.cpp @@ -46,7 +46,7 @@ static void on_track_loaded(Track *track) Gtk::Label *album = lib :: get_widget("o_album"); Gtk::Label *duration = lib :: get_widget("o_total_time"); - set_label_text(title, "xx-large", track->title); + set_label_text(title, "xx-large", track->name()); set_label_text(artist, "x-large", "By: " + track->artist()->name()); set_label_text(album, "x-large", "From: " + track->album()->name()); duration->set_text(track->length_str); diff --git a/include/core/tags/track.h b/include/core/tags/track.h index a118c64c..8a2cc81c 100644 --- a/include/core/tags/track.h +++ b/include/core/tags/track.h @@ -58,10 +58,6 @@ public: /** The day this track was last played */ unsigned int last_day; - /** The title of this track */ - std :: string title; - /** The title of this track (in lowercase) */ - std :: string title_lower; /** The filepath of this track, relative to the library root */ std :: string filepath; /** The length of this track in a human readable string */ @@ -77,10 +73,12 @@ public: * @param artist The artist performing this track. * @param genre The genre describing this track. * @param library The library containing this track. + * @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 *, unsigned int, unsigned int); + Track(Album *, Artist *, Genre *, Library *, const std::string &, + unsigned int, unsigned int); /** * Track constructor diff --git a/lib/model.cpp b/lib/model.cpp index 09efe46d..e642be0f 100644 --- a/lib/model.cpp +++ b/lib/model.cpp @@ -140,7 +140,7 @@ void QueueModel::get_value_str(Track *track, int column, switch (column) { case 1: - specific.set(track->title); + specific.set(track->name()); break; case 2: specific.set(track->length_str); diff --git a/tests/core/tags/track.cpp b/tests/core/tags/track.cpp index 08ae0a60..3300d140 100644 --- a/tests/core/tags/track.cpp +++ b/tests/core/tags/track.cpp @@ -17,8 +17,6 @@ static void test_track_tag_default() test_equal(track.name(), (std::string)""); test_equal(track.lowercase(), (std::string)""); test_equal(track.primary_key(), (std::string)""); - test_equal(track.title, (std::string)""); - test_equal(track.title_lower, (std::string)""); test_equal(track.filepath, (std::string)""); test_equal(track.length_str, (std::string)""); @@ -36,7 +34,7 @@ static void test_track_tag_constructor() 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, genre, library, 288, 13); + Track track(album, artist, genre, library, "Legend of Zelda Medley", 288, 13); test_equal(track.album(), album); test_equal(track.artist(), artist); @@ -44,6 +42,9 @@ static void test_track_tag_constructor() test_equal(track.library(), library); test_equal(library->size(), (unsigned)1); + test_equal(track.name(), (std::string)"Legend of Zelda Medley"); + test_equal(track.lowercase(), (std::string)"legend of zelda medley"); + test_equal(track.track(), (unsigned)13); test_equal(track.length(), (unsigned)288); test_equal(track.count(), (unsigned)0);