Track: Move read and write code into tags/track.cpp

Sadly, this patch disables filtering for tracks.  This will be reenabled
sometime soon!

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2014-11-28 21:18:36 -05:00
parent 39cc10bb3e
commit 2578cdadfe
3 changed files with 59 additions and 40 deletions

View File

@ -14,45 +14,6 @@
Database<Track> track_db("track.db", false);
/**
*
* Track tag
*
*/
void Track :: read(File &f)
{
unsigned int library_id, artist_id, album_id, genre_id;
f >> library_id >> artist_id >> album_id >> genre_id;
f >> _track >> _date.year >> _date.month >> _date.day;
f >> _count >> _length;
GenericTag :: read(f);
_path = f.getline();
_library = tags :: get_library(library_id);
_artist = tags :: get_artist(artist_id);
_album = tags :: get_album(album_id);
_genre = tags :: get_genre(genre_id);
filter :: add(name(), index());
filter :: add(_artist->name(), index());
filter :: add(_album->name(), index());
_library->inc_size();
}
void Track :: write(File &f)
{
f << _library->index() << " " << _artist->index() << " ";
f << _album->index() << " " << _genre->index() << " " << _track << " ";
f << _date.year << " " << _date.month << " " << _date.day << " ";
f << _count << " " << _length << " ";
GenericTag :: write(f);
f << std::endl << _path << std::endl;
}
/**
*
* Tagdb functions

View File

@ -110,3 +110,35 @@ int Track :: compare_date(const Track *rhs)
}
return ret;
}
void Track :: read(File &f)
{
unsigned int library_id, artist_id, album_id, genre_id;
f >> library_id >> artist_id >> album_id >> genre_id;
f >> _track >> _date.year >> _date.month >> _date.day;
f >> _count >> _length;
GenericTag :: read(f);
_path = f.getline();
_library = tags :: get_library(library_id);
_artist = tags :: get_artist(artist_id);
_album = tags :: get_album(album_id);
_genre = tags :: get_genre(genre_id);
//filter :: add(name(), index());
//filter :: add(_artist->name(), index());
//filter :: add(_album->name(), index());
_library->inc_size();
}
void Track :: write(File &f)
{
f << _library->index() << " " << _artist->index() << " ";
f << _album->index() << " " << _genre->index() << " " << _track << " ";
f << _date.year << " " << _date.month << " " << _date.day << " ";
f << _count << " " << _length << " ";
GenericTag :: write(f);
f << std::endl << _path << std::endl;
}

View File

@ -66,10 +66,11 @@ static void test_track_tag_destructor()
static void test_track_tag_functional()
{
File f("track_tag", 0);
time_t rawtime = time(NULL);
struct tm *now = localtime(&rawtime);
std::stringstream ss;
Track track1, track2;
Track track1, track2, track3;
track1 = Track(album, artist, genre, library,
MUSIC_DIR + "/Hyrule Symphony/6 - Kakariko Village.mp3",
@ -109,6 +110,31 @@ static void test_track_tag_functional()
test_equal(track1.compare_date(&track1), 0);
test_equal(track1.compare_date(&track2), 2014);
test_equal(track2.compare_date(&track1), -2014);
f.open(OPEN_WRITE);
track1.write(f);
f.close();
f.open(OPEN_READ);
track3.read(f);
f.close();
test_equal(track1.album(), track3.album());
test_equal(track1.artist(), track3.artist());
test_equal(track1.genre(), track3.genre());
test_equal(track1.library(), track3.library());
test_equal(track1.name(), track3.name());
test_equal(track1.lowercase(), track3.lowercase());
test_equal(track1.primary_key(), track3.primary_key());
test_equal(track1.date(), track3.date());
test_equal(track1.path(), track3.path());
test_equal(track1.length_str(), track3.length_str());
test_equal(track1.track(), track3.track());
test_equal(track1.length(), track3.length());
test_equal(track1.count(), track3.count());
}
int main(int argc, char **argv)