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 <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2014-11-29 10:17:21 -05:00
parent cfef5c07a0
commit 4edbd69fa7
4 changed files with 7 additions and 7 deletions

View File

@ -37,6 +37,7 @@ Track *tagdb :: add_track(const std::string &filepath, Library *library)
TagLib :: Tag *tag; TagLib :: Tag *tag;
TagLib :: AudioProperties *audio; TagLib :: AudioProperties *audio;
TagLib :: FileRef ref(filepath.c_str(), true, TagLib::AudioProperties::Fast); TagLib :: FileRef ref(filepath.c_str(), true, TagLib::AudioProperties::Fast);
std::string path = filepath.substr(library->primary_key().size() + 1);
if (ref.isNull()) { if (ref.isNull()) {
print("WARNING: Could not read tags for file %s\n", filepath.c_str()); 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_album(tag->album().stripWhiteSpace().to8Bit(true), tag->year()),
tags :: get_artist(tag->artist().stripWhiteSpace().to8Bit(true)), tags :: get_artist(tag->artist().stripWhiteSpace().to8Bit(true)),
tags :: get_genre(tag->genre().stripWhiteSpace().to8Bit(true)), tags :: get_genre(tag->genre().stripWhiteSpace().to8Bit(true)),
library, filepath, library, path,
tag->title().stripWhiteSpace().to8Bit(true), tag->title().stripWhiteSpace().to8Bit(true),
audio->length(), tag->track()) audio->length(), tag->track())
); );

View File

@ -19,8 +19,7 @@ Track :: Track(Album *album, Artist *artist, Genre *genre, Library *library,
unsigned int length, unsigned int track) unsigned int length, unsigned int track)
: GenericTag(name), : GenericTag(name),
_album(album), _artist(artist), _genre(genre), _library(library), _album(album), _artist(artist), _genre(genre), _library(library),
_count(0), _length(length), _track(track), _count(0), _length(length), _track(track), _path(filepath)
_path(filepath.substr(library->primary_key().size() + 1))
{ {
//filter :: add(name(), index()); //filter :: add(name(), index());
//filter :: add(_artist->name(), index()); //filter :: add(_artist->name(), index());

View File

@ -46,7 +46,7 @@ public:
* @param artist The artist performing this track. * @param artist The artist performing this track.
* @param genre The genre describing this track. * @param genre The genre describing this track.
* @param library The library containing 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 name The name (title) of this track.
* @param length The length of this track (in seconds). * @param length The length of this track (in seconds).
* @param track The track number of this track. * @param track The track number of this track.

View File

@ -59,7 +59,7 @@ static void test_track_tag_constructor()
{ {
File f("track_tag", 0); File f("track_tag", 0);
Track a(album, artist, genre, library, 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); "Legend of Zelda Medley", 288, 13);
Track b; Track b;
@ -89,7 +89,7 @@ static void test_track_tag_functional()
Track track1, track2, track3; Track track1, track2, track3;
track1 = Track(album, artist, genre, library, track1 = Track(album, artist, genre, library,
MUSIC_DIR + "/Hyrule Symphony/6 - Kakariko Village.mp3", "Hyrule Symphony/6 - Kakariko Village.mp3",
"Kakariko Village", 186, 6); "Kakariko Village", 186, 6);
track1.played(); track1.played();
test_equal(track1.length_str(), (std::string)"3:06"); 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. */ /* Not an actual track on the album, I just needed something < 1 min. */
track2 = Track(album, artist, genre, library, track2 = Track(album, artist, genre, library,
MUSIC_DIR + "/Hyrule Symphony/0 - intro.mp3", "Hyrule Symphony/0 - intro.mp3",
"Intro", 56, 0); "Intro", 56, 0);
test_equal(track2.length_str(), (std::string)"0:56"); test_equal(track2.length_str(), (std::string)"0:56");