Genre: Move Genre tag into a new file
- This tag now inherits from GenericTag. - Add a Genre-specific unit test. - Remove the genre tag section of the DESIGN file. Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
2d9d87afc9
commit
1e6bcf7451
38
DESIGN
38
DESIGN
|
@ -120,44 +120,6 @@ Tag Database:
|
|||
|
||||
|
||||
|
||||
Genre Tag:
|
||||
The genre tag is used to collect basic information about the various
|
||||
genres of songs in the library.
|
||||
|
||||
- Genre:
|
||||
class Genre : public DatabaseEntry {
|
||||
public:
|
||||
std::string genre;
|
||||
std::string lower;
|
||||
|
||||
Genre();
|
||||
Genre(const std::string &);
|
||||
const std::string primary_key() const;
|
||||
void read(File &);
|
||||
void write(File &);
|
||||
};
|
||||
|
||||
- File Format:
|
||||
File << name;
|
||||
|
||||
- API:
|
||||
Genre();
|
||||
Initialize an invalid Genre instance.
|
||||
|
||||
Genre(const std::string &genre_name);
|
||||
Set genre from genre name and find the lowercase form.
|
||||
|
||||
const std::string Genre :: primary_key() const;
|
||||
Use genre as primary key.
|
||||
|
||||
void Genre :: read(File &f);
|
||||
Read genre from file and find the lowercase form.
|
||||
|
||||
void Genre :: write(File &f);
|
||||
Write genre to file.
|
||||
|
||||
|
||||
|
||||
Library Tag:
|
||||
The library tag is used to store a single directory added to Ocarina
|
||||
by the user. It is not an ID3 tag, and is instead something I use
|
||||
|
|
|
@ -18,37 +18,6 @@ Database<Library> library_db("library.db", true);
|
|||
Database<Track> track_db("track.db", false);
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Genre tag
|
||||
*
|
||||
*/
|
||||
|
||||
Genre :: Genre() {}
|
||||
|
||||
Genre :: Genre(const std::string &s)
|
||||
: name(s), lower(filter :: lowercase(name))
|
||||
{
|
||||
}
|
||||
|
||||
const std::string Genre :: primary_key() const
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
void Genre :: read(File &f)
|
||||
{
|
||||
name = f.getline();
|
||||
lower = filter :: lowercase(name);
|
||||
}
|
||||
|
||||
void Genre :: write(File &f)
|
||||
{
|
||||
f << name;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Library tag
|
||||
|
@ -253,7 +222,7 @@ int Track :: less_than(Track *rhs, sort_t field)
|
|||
case SORT_COUNT:
|
||||
return compare_uint(play_count, rhs->play_count);
|
||||
case SORT_GENRE:
|
||||
return compare_string(genre->lower, rhs->genre->lower);
|
||||
return compare_string(genre->lowercase(), rhs->genre->lowercase());
|
||||
case SORT_LENGTH:
|
||||
return compare_uint(length, rhs->length);
|
||||
case SORT_PLAYED:
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
/**
|
||||
* @file
|
||||
* Copyright 2014 (c) Anna Schumaker.
|
||||
*/
|
||||
#include <core/tags/genre.h>
|
||||
|
||||
Genre :: Genre() : GenericTag() {}
|
||||
|
||||
Genre :: Genre(const std::string &name)
|
||||
: GenericTag(name)
|
||||
{
|
||||
}
|
|
@ -8,6 +8,7 @@
|
|||
#include <core/database.h>
|
||||
#include <core/tags/album.h>
|
||||
#include <core/tags/artist.h>
|
||||
#include <core/tags/genre.h>
|
||||
|
||||
|
||||
/**
|
||||
|
@ -35,45 +36,6 @@ enum sort_t {
|
|||
};
|
||||
|
||||
|
||||
/**
|
||||
* Genre tag
|
||||
*/
|
||||
class Genre : public DatabaseEntry {
|
||||
public:
|
||||
/** Genre name */
|
||||
std::string name;
|
||||
/** Genre name (lowercase) */
|
||||
std::string lower;
|
||||
|
||||
/** Genre tag constructor */
|
||||
Genre();
|
||||
|
||||
/**
|
||||
* Genre tag constructor
|
||||
* @param name Genre name
|
||||
*/
|
||||
Genre(const std::string &);
|
||||
|
||||
/**
|
||||
* Called to access the artist tag's primary key
|
||||
* @return Genre::name
|
||||
*/
|
||||
const std::string primary_key() const;
|
||||
|
||||
/**
|
||||
* Read genre information from file.
|
||||
* @param file The file to read from.
|
||||
*/
|
||||
void read(File &);
|
||||
|
||||
/**
|
||||
* Write genre information to file.
|
||||
* @param file The file to write to.
|
||||
*/
|
||||
void write(File &);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Library tag
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
/**
|
||||
* @file
|
||||
* Copyright 2014 (c) Anna Schumaker.
|
||||
*/
|
||||
#ifndef OCARINA_CORE_TAGS_GENRE_H
|
||||
#define OCARINA_CORE_TAGS_GENRE_H
|
||||
|
||||
#include <core/tags/generic.h>
|
||||
|
||||
/**
|
||||
* The Genre tag is used to store the name of genres added
|
||||
* to the tag database.
|
||||
*/
|
||||
class Genre : public GenericTag {
|
||||
public:
|
||||
Genre(); /**< Genre tag constructor. */
|
||||
|
||||
/**
|
||||
* Genre tag constructor.
|
||||
*
|
||||
* @param name Genre name.
|
||||
*/
|
||||
Genre(const std::string &);
|
||||
};
|
||||
|
||||
#endif /* OCARINA_CORE_TAGS_GENRE_H */
|
|
@ -152,7 +152,7 @@ void QueueModel::get_value_str(Track *track, int column,
|
|||
specific.set(track->album->name());
|
||||
break;
|
||||
case 6:
|
||||
specific.set(track->genre->name);
|
||||
specific.set(track->genre->name());
|
||||
break;
|
||||
case 8:
|
||||
if (track->play_count == 0)
|
||||
|
|
|
@ -17,6 +17,7 @@ test( "idle" )
|
|||
test( "tags/generic" )
|
||||
test( "tags/artist" )
|
||||
test( "tags/album" )
|
||||
test( "tags/genre" )
|
||||
|
||||
test_env.UsePackage("taglib")
|
||||
objs += [ get_test_obj("tags", "core") ]
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
album
|
||||
artist
|
||||
generic
|
||||
genre
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
/**
|
||||
* @file
|
||||
* Copyright 2014 (c) Anna Schumaker.
|
||||
*/
|
||||
#include <core/tags/genre.h>
|
||||
#include <tests/test.h>
|
||||
|
||||
static void test_artist_tag()
|
||||
{
|
||||
Genre genre;
|
||||
test_equal(genre.name(), (std::string)"");
|
||||
test_equal(genre.lowercase(), (std::string)"");
|
||||
test_equal(genre.primary_key(), (std::string)"");
|
||||
|
||||
genre = Genre("Video Game Music");
|
||||
test_equal(genre.name(), (std::string)"Video Game Music");
|
||||
test_equal(genre.lowercase(), (std::string)"video game music");
|
||||
test_equal(genre.primary_key(), (std::string)"Video Game Music");
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
run_test("Genre Tag Test", test_artist_tag);
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue