From 4edbd69fa7ab56cf56454846232ec13b9fe487e4 Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Sat, 29 Nov 2014 10:17:21 -0500 Subject: [PATCH] Track: Change constructor to take relative paths I'm going to need to split this value earlier to do a unique lookup when inserting, so the constructor can take the relative path to make things easier. Signed-off-by: Anna Schumaker --- core/tags.cpp | 3 ++- core/tags/track.cpp | 3 +-- include/core/tags/track.h | 2 +- tests/core/tags/track.cpp | 6 +++--- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/core/tags.cpp b/core/tags.cpp index 7095076a..3e729b88 100644 --- a/core/tags.cpp +++ b/core/tags.cpp @@ -37,6 +37,7 @@ Track *tagdb :: add_track(const std::string &filepath, Library *library) TagLib :: Tag *tag; TagLib :: AudioProperties *audio; TagLib :: FileRef ref(filepath.c_str(), true, TagLib::AudioProperties::Fast); + std::string path = filepath.substr(library->primary_key().size() + 1); if (ref.isNull()) { print("WARNING: Could not read tags for file %s\n", filepath.c_str()); @@ -50,7 +51,7 @@ Track *tagdb :: add_track(const std::string &filepath, Library *library) tags :: get_album(tag->album().stripWhiteSpace().to8Bit(true), tag->year()), tags :: get_artist(tag->artist().stripWhiteSpace().to8Bit(true)), tags :: get_genre(tag->genre().stripWhiteSpace().to8Bit(true)), - library, filepath, + library, path, tag->title().stripWhiteSpace().to8Bit(true), audio->length(), tag->track()) ); diff --git a/core/tags/track.cpp b/core/tags/track.cpp index 39815d10..1d518bca 100644 --- a/core/tags/track.cpp +++ b/core/tags/track.cpp @@ -19,8 +19,7 @@ Track :: Track(Album *album, Artist *artist, Genre *genre, Library *library, unsigned int length, unsigned int track) : GenericTag(name), _album(album), _artist(artist), _genre(genre), _library(library), - _count(0), _length(length), _track(track), - _path(filepath.substr(library->primary_key().size() + 1)) + _count(0), _length(length), _track(track), _path(filepath) { //filter :: add(name(), index()); //filter :: add(_artist->name(), index()); diff --git a/include/core/tags/track.h b/include/core/tags/track.h index cffa015d..9c59659a 100644 --- a/include/core/tags/track.h +++ b/include/core/tags/track.h @@ -46,7 +46,7 @@ public: * @param artist The artist performing this track. * @param genre The genre describing this track. * @param library The library containing this track. - * @param filepath The full filepath of 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. diff --git a/tests/core/tags/track.cpp b/tests/core/tags/track.cpp index 2bfc745d..c6e7e45f 100644 --- a/tests/core/tags/track.cpp +++ b/tests/core/tags/track.cpp @@ -59,7 +59,7 @@ static void test_track_tag_constructor() { File f("track_tag", 0); Track a(album, artist, genre, library, - MUSIC_DIR + "/Hyrule Symphony/13 - Legend of Zelda Medley.mp3", + "Hyrule Symphony/13 - Legend of Zelda Medley.mp3", "Legend of Zelda Medley", 288, 13); Track b; @@ -89,7 +89,7 @@ static void test_track_tag_functional() Track track1, track2, track3; track1 = Track(album, artist, genre, library, - MUSIC_DIR + "/Hyrule Symphony/6 - Kakariko Village.mp3", + "Hyrule Symphony/6 - Kakariko Village.mp3", "Kakariko Village", 186, 6); track1.played(); test_equal(track1.length_str(), (std::string)"3:06"); @@ -119,7 +119,7 @@ static void test_track_tag_functional() /* Not an actual track on the album, I just needed something < 1 min. */ track2 = Track(album, artist, genre, library, - MUSIC_DIR + "/Hyrule Symphony/0 - intro.mp3", + "Hyrule Symphony/0 - intro.mp3", "Intro", 56, 0); test_equal(track2.length_str(), (std::string)"0:56");