Track: Create an add_track() function

We return a new Track tag or NULL if we have already tagged this track.

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2014-11-29 10:38:27 -05:00
parent d7ceadafb3
commit a30f5ef794
3 changed files with 52 additions and 0 deletions

View File

@ -8,6 +8,9 @@
#include <stdlib.h>
static Database<Track> track_db("track.db", false);
Track :: Track()
: GenericTag(),
_album(NULL), _artist(NULL), _genre(NULL), _library(NULL),
@ -150,3 +153,14 @@ void Track :: write(File &f)
GenericTag :: write(f);
f << std::endl << _path << std::endl;
}
Track *tags :: add_track(Album *album, Artist *artist, Genre *genre,
Library *library, const std::string &filepath,
const std::string &name, unsigned int length,
unsigned int track)
{
std::string path = filepath.substr(library->primary_key().size() + 1);
return track_db.insert(Track(album, artist, genre, library, path,
name, length, track));
}

View File

@ -123,4 +123,25 @@ public:
void write(File &);
};
namespace tags
{
/**
* Called to create a new Track tag.
*
* @param album The album containing this track.
* @param artist The artist performing this track.
* @param genre The genre describing this track.
* @param library The library containing 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.
* @return A new Track tag, or NULL if this Track is already in
* the track_db.
*/
Track *add_track(Album *, Artist *, Genre *, Library *,
const std::string &, const std::string &,
unsigned int, unsigned int);
}
#endif /* OCARINA_CORE_TAGS_TRACK_H */

View File

@ -81,6 +81,22 @@ static void test_track_tag_destructor()
test_equal(library->size(), (unsigned)0);
}
static void test_track_tag_lookup()
{
Track *a, *b;
a = tags :: add_track(album, artist, genre, library,
MUSIC_DIR + "/Hyrule Symphony/13 - Legend of Zelda Medley.mp3",
"Legend of Zelda Medley", 288, 13);
test_not_equal(a, (Track *)NULL);
verify_track_tag(a, 1);
b = tags :: add_track(album, artist, genre, library,
MUSIC_DIR + "/Hyrule Symphony/13 - Legend of Zelda Medley.mp3",
"Legend of Zelda Medley", 288, 13);
test_equal(b, (Track *)NULL);
}
static void test_track_tag_functional()
{
time_t rawtime = time(NULL);
@ -139,6 +155,7 @@ int main(int argc, char **argv)
run_test("Track Tag Default Constructor Test", test_track_tag_default);
run_test("Track Tag Constructor Test", test_track_tag_constructor);
run_test("Track Tag Destructor Test", test_track_tag_destructor);
run_test("Track Tag Lookup Test", test_track_tag_lookup);
run_test("Track Tag Functional Test", test_track_tag_functional);
return 0;
}