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 <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2014-11-26 08:23:20 -05:00
parent 1fdee864a2
commit 2540a6aa7a
6 changed files with 20 additions and 19 deletions

View File

@ -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:

View File

@ -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();

View File

@ -46,7 +46,7 @@ static void on_track_loaded(Track *track)
Gtk::Label *album = lib :: get_widget<Gtk::Label>("o_album");
Gtk::Label *duration = lib :: get_widget<Gtk::Label>("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);

View File

@ -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

View File

@ -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);

View File

@ -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);