tagdb: Begin the Track class
I properly initialize variables, and I created supporting databases that will be used to look up artist, album, genre and library information. Signed-off-by: Anna Schumaker <anna@ocarinaproject.net>
This commit is contained in:
parent
134348f253
commit
5d97c84d10
4
DESIGN
4
DESIGN
|
@ -796,14 +796,14 @@ Track Tag:
|
|||
std :: string length_str;
|
||||
|
||||
Track();
|
||||
Track(Library *, const std::string &);
|
||||
Track(const std::string &, Library *);
|
||||
const std::string primary_key();
|
||||
void read(File &);
|
||||
void write(File &);
|
||||
|
||||
void tag();
|
||||
const std::string path();
|
||||
bool less_than(Track *rhs, sort_t field);
|
||||
bool less_than(Track *, sort_t);
|
||||
};
|
||||
|
||||
- File Format:
|
||||
|
|
|
@ -7,6 +7,19 @@
|
|||
#include <database.h>
|
||||
|
||||
|
||||
enum sort_t {
|
||||
SORT_ARTIST,
|
||||
SORT_ALBUM,
|
||||
SORT_COUNT,
|
||||
SORT_GENRE,
|
||||
SORT_LENGTH,
|
||||
SORT_PLAYED,
|
||||
SORT_TITLE,
|
||||
SORT_TRACK,
|
||||
SORT_YEAR,
|
||||
};
|
||||
|
||||
|
||||
class Artist : public DatabaseEntry {
|
||||
public:
|
||||
std::string name;
|
||||
|
@ -60,4 +73,42 @@ public:
|
|||
void write(File &);
|
||||
};
|
||||
|
||||
|
||||
class Track : public DatabaseEntry {
|
||||
public:
|
||||
Library *library;
|
||||
Artist *artist;
|
||||
Album *album;
|
||||
Genre *genre;
|
||||
|
||||
unsigned int track;
|
||||
unsigned int length;
|
||||
unsigned int play_count;
|
||||
unsigned int last_year;
|
||||
unsigned int last_month;
|
||||
unsigned int last_day;
|
||||
|
||||
std :: string title;
|
||||
std :: string title_lower;
|
||||
std :: string filepath;
|
||||
std :: string length_str;
|
||||
|
||||
Track();
|
||||
Track(const std::string &, Library *);
|
||||
const std::string primary_key();
|
||||
void read(File &);
|
||||
void write(File &);
|
||||
|
||||
void tag();
|
||||
const std::string path();
|
||||
bool less_than(Track *, sort_t);
|
||||
};
|
||||
|
||||
|
||||
namespace tagdb {
|
||||
|
||||
Library *add_library(const std::string &);
|
||||
|
||||
}
|
||||
|
||||
#endif /* OCARINA_TAGS_H */
|
||||
|
|
63
lib/tags.cpp
63
lib/tags.cpp
|
@ -8,6 +8,12 @@
|
|||
#include <sstream>
|
||||
|
||||
|
||||
Database<Artist> artist_db("artist.db", true);
|
||||
Database<Album> album_db("album.db", true);
|
||||
Database<Genre> genre_db("genre.db", true);
|
||||
Database<Library> library_db("library.db", true);
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Artist tag
|
||||
|
@ -135,3 +141,60 @@ void Library :: write(File &f)
|
|||
{
|
||||
f << enabled << " " << root_path;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Track tag
|
||||
*
|
||||
*/
|
||||
|
||||
Track :: Track() {}
|
||||
|
||||
Track :: Track(const std::string &f, Library *l)
|
||||
: library(l), play_count(0), last_year(0), last_month(0), last_day(0),
|
||||
filepath(f.substr(l->root_path.size() + 1))
|
||||
{
|
||||
}
|
||||
|
||||
const std::string Track :: primary_key()
|
||||
{
|
||||
return path();
|
||||
}
|
||||
|
||||
void Track :: read(File &f)
|
||||
{
|
||||
}
|
||||
|
||||
void Track :: write(File &f)
|
||||
{
|
||||
}
|
||||
|
||||
void Track :: tag()
|
||||
{
|
||||
}
|
||||
|
||||
const std::string Track :: path()
|
||||
{
|
||||
return library->root_path + "/" + filepath;
|
||||
}
|
||||
|
||||
bool Track :: less_than(Track *rhs, sort_t field)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Tagdb functions
|
||||
*
|
||||
*/
|
||||
|
||||
Library *tagdb :: add_library(const std::string &filepath)
|
||||
{
|
||||
Database<Library>::iterator it = library_db.insert(Library(filepath));
|
||||
return &(*it);
|
||||
}
|
||||
|
|
Binary file not shown.
|
@ -42,6 +42,7 @@ void load_tag(const std::string &file, T &tag)
|
|||
f.close();
|
||||
}
|
||||
|
||||
|
||||
void artist_test_tags(Artist &artist)
|
||||
{
|
||||
test_results(artist.name == "Artist Name", __LINE__);
|
||||
|
@ -59,6 +60,7 @@ void artist_test()
|
|||
artist_test_tags(artist2);
|
||||
}
|
||||
|
||||
|
||||
void album_test_tags(Album &album)
|
||||
{
|
||||
test_results(album.name == "Album Name", __LINE__);
|
||||
|
@ -77,6 +79,7 @@ void album_test()
|
|||
album_test_tags(album2);
|
||||
}
|
||||
|
||||
|
||||
void genre_test_tags(Genre &genre)
|
||||
{
|
||||
test_results(genre.name == "Genre Name", __LINE__);
|
||||
|
@ -94,6 +97,7 @@ void genre_test()
|
|||
genre_test_tags(genre2);
|
||||
}
|
||||
|
||||
|
||||
void library_test_tags(Library &library)
|
||||
{
|
||||
test_results(library.root_path == "/home/user/Music", __LINE__);
|
||||
|
@ -113,11 +117,32 @@ void library_test()
|
|||
library_test_tags(library2);
|
||||
}
|
||||
|
||||
|
||||
void track_test_tags(Track &track)
|
||||
{
|
||||
test_results(track.filepath == "1.ogg", __LINE__);
|
||||
test_results(track.path() == "Music/1.ogg", __LINE__);
|
||||
test_results(track.primary_key() == "Music/1.ogg", __LINE__);
|
||||
test_results(track.play_count == 0, __LINE__);
|
||||
test_results(track.last_year == 0, __LINE__);
|
||||
test_results(track.last_month == 0, __LINE__);
|
||||
test_results(track.last_day == 0, __LINE__);
|
||||
}
|
||||
|
||||
void track_test()
|
||||
{
|
||||
Library *library = tagdb :: add_library("Music");
|
||||
Track track("Music/1.ogg", library);
|
||||
|
||||
track_test_tags(track);
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
char c;
|
||||
|
||||
while ((c = getopt(argc, argv, "aAgl")) != -1) {
|
||||
while ((c = getopt(argc, argv, "aAglt")) != -1) {
|
||||
switch (c) {
|
||||
case 'a':
|
||||
artist_test();
|
||||
|
@ -131,6 +156,9 @@ int main(int argc, char **argv)
|
|||
case 'l':
|
||||
library_test();
|
||||
break;
|
||||
case 't':
|
||||
track_test();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -16,3 +16,5 @@ echo
|
|||
test_tag "Genre" "-g"
|
||||
echo
|
||||
test_tag "Library" "-l"
|
||||
echo
|
||||
test_tag "Track" "-t"
|
||||
|
|
Loading…
Reference in New Issue