Album: Move Album tag into a new file
Also make it inherit from the GenericTag base class. Also also, add a unit test specific to Album tags. Finally, I remove the corresponding section of the DESIGN file since it is no longer needed. Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
a9fc53964c
commit
2d9d87afc9
40
DESIGN
40
DESIGN
|
@ -120,46 +120,6 @@ Tag Database:
|
|||
|
||||
|
||||
|
||||
Album Tag:
|
||||
The album tag is used to collect information about each artist's albums.
|
||||
|
||||
- Album:
|
||||
class Album : public DatabaseEntry {
|
||||
public:
|
||||
std::string name;
|
||||
std::string lower;
|
||||
unsigned int year;
|
||||
|
||||
Album();
|
||||
Album(const std::string &, unsigned int);
|
||||
const std::string primary_key() const;
|
||||
void read(File &);
|
||||
void write(File &);
|
||||
};
|
||||
|
||||
- File Format:
|
||||
File << year << name;
|
||||
|
||||
- API:
|
||||
Album();
|
||||
Initialize an invalid Album instance.
|
||||
|
||||
Album(const std::string &album_name, unsigned int album_year);
|
||||
Set name and year from album name and album_year. Find the
|
||||
lowercase form of the album name.
|
||||
|
||||
const std::string Album :: primary_key() const;
|
||||
Return the string: "$year.$name"
|
||||
|
||||
void Album :: read(File &f);
|
||||
Read year, and name from file. Then set the lowercase form
|
||||
of the album name.
|
||||
|
||||
void Artist :: write(File &f);
|
||||
Write album information to file.
|
||||
|
||||
|
||||
|
||||
Genre Tag:
|
||||
The genre tag is used to collect basic information about the various
|
||||
genres of songs in the library.
|
||||
|
|
|
@ -18,40 +18,6 @@ Database<Library> library_db("library.db", true);
|
|||
Database<Track> track_db("track.db", false);
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Album tag
|
||||
*
|
||||
*/
|
||||
|
||||
Album :: Album() {}
|
||||
|
||||
Album :: Album(const std::string &s, unsigned int y)
|
||||
: name(s), lower(filter :: lowercase(name)), year(y)
|
||||
{
|
||||
}
|
||||
|
||||
const std::string Album :: primary_key() const
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << year << "." << name;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
void Album :: read(File &f)
|
||||
{
|
||||
f >> year;
|
||||
name = f.getline();
|
||||
lower = filter :: lowercase(name);
|
||||
}
|
||||
|
||||
void Album :: write(File &f)
|
||||
{
|
||||
f << year << " " << name;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Genre tag
|
||||
|
@ -162,7 +128,7 @@ void Track :: read(File &f)
|
|||
|
||||
title_lower = filter :: add(title, index());
|
||||
filter :: add(artist->name(), index());
|
||||
filter :: add(album->name, index());
|
||||
filter :: add(album->name(), index());
|
||||
library->count++;
|
||||
set_length_str();
|
||||
}
|
||||
|
@ -229,7 +195,7 @@ bool Track :: tag()
|
|||
set_length_str();
|
||||
|
||||
filter :: add(artist->name(), index());
|
||||
filter :: add(album->name, index());
|
||||
filter :: add(album->name(), index());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -283,7 +249,7 @@ int Track :: less_than(Track *rhs, sort_t field)
|
|||
case SORT_ARTIST:
|
||||
return compare_string(artist->lowercase(), rhs->artist->lowercase());
|
||||
case SORT_ALBUM:
|
||||
return compare_string(album->lower, rhs->album->lower);
|
||||
return compare_string(album->lowercase(), rhs->album->lowercase());
|
||||
case SORT_COUNT:
|
||||
return compare_uint(play_count, rhs->play_count);
|
||||
case SORT_GENRE:
|
||||
|
@ -303,7 +269,7 @@ int Track :: less_than(Track *rhs, sort_t field)
|
|||
case SORT_TRACK:
|
||||
return compare_uint(track, rhs->track);
|
||||
case SORT_YEAR:
|
||||
return compare_uint(album->year, rhs->album->year);
|
||||
return compare_uint(album->year(), rhs->album->year());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
/**
|
||||
* @file
|
||||
* Copyright 2014 (c) Anna Schumaker.
|
||||
*/
|
||||
#include <core/tags/album.h>
|
||||
#include <sstream>
|
||||
|
||||
Album :: Album() : GenericTag(), _year(0) {}
|
||||
|
||||
Album :: Album(const std::string &name, unsigned int year)
|
||||
: GenericTag(name), _year(year)
|
||||
{
|
||||
}
|
||||
|
||||
const std::string Album :: primary_key() const
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << _year << "/" << GenericTag :: primary_key();
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
void Album :: read(File &file)
|
||||
{
|
||||
file >> _year;
|
||||
GenericTag :: read(file);
|
||||
}
|
||||
|
||||
void Album :: write(File &file)
|
||||
{
|
||||
file << _year << " ";
|
||||
GenericTag :: write(file);
|
||||
}
|
||||
|
||||
unsigned int Album :: year()
|
||||
{
|
||||
return _year;
|
||||
}
|
|
@ -28,7 +28,7 @@ void GenericTag :: write(File &file)
|
|||
file << _name;
|
||||
}
|
||||
|
||||
const std::string &GenericTag :: name()
|
||||
const std::string &GenericTag :: name() const
|
||||
{
|
||||
return _name;
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ static void on_track_loaded(Track *track)
|
|||
|
||||
set_label_text(title, "xx-large", track->title);
|
||||
set_label_text(artist, "x-large", "By: " + track->artist->name());
|
||||
set_label_text(album, "x-large", "From: " + track->album->name);
|
||||
set_label_text(album, "x-large", "From: " + track->album->name());
|
||||
duration->set_text(track->length_str);
|
||||
|
||||
bool banned = playlist :: has(track, "Banned");
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#define OCARINA_CORE_TAGS_H
|
||||
|
||||
#include <core/database.h>
|
||||
#include <core/tags/album.h>
|
||||
#include <core/tags/artist.h>
|
||||
|
||||
|
||||
|
@ -34,48 +35,6 @@ enum sort_t {
|
|||
};
|
||||
|
||||
|
||||
/**
|
||||
* Album tag
|
||||
*/
|
||||
class Album : public DatabaseEntry {
|
||||
public:
|
||||
/** Album name */
|
||||
std::string name;
|
||||
/** Album name (lowercase) */
|
||||
std::string lower;
|
||||
/** Album year */
|
||||
unsigned int year;
|
||||
|
||||
/** Album tag constructor */
|
||||
Album();
|
||||
|
||||
/**
|
||||
* Album tag constructor
|
||||
* @param name Album name
|
||||
* @param year Album year
|
||||
*/
|
||||
Album(const std::string &, unsigned int);
|
||||
|
||||
/**
|
||||
* Called to access the artist tag's primary key
|
||||
* @return "Album::year"."Album::name" (Example: 1968.White Album)
|
||||
*/
|
||||
const std::string primary_key() const;
|
||||
|
||||
/**
|
||||
* Read album information from file.
|
||||
* @param file The file to read from.
|
||||
*/
|
||||
void read(File &);
|
||||
|
||||
/**
|
||||
* Write album information to file.
|
||||
* @param file The file to write to.
|
||||
*/
|
||||
void write(File &);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Genre tag
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
/**
|
||||
* @file
|
||||
* Copyright 2014 (c) Anna Schumaker.
|
||||
*/
|
||||
#ifndef OCARINA_CORE_TAGS_ALBUM_H
|
||||
#define OCARINA_CORE_TAGS_ALBUM_H
|
||||
|
||||
#include <core/tags/generic.h>
|
||||
|
||||
/**
|
||||
* The Album tag is used to store the name and year of albums
|
||||
* added to the tag database.
|
||||
*
|
||||
* When writing an Album tag to disk, write out the _year field and
|
||||
* then call GenericTag to write anything else.
|
||||
*
|
||||
* ... << year1 << GenericTag::write()
|
||||
* ... << year2 << GenericTag::write()
|
||||
* ... << year3 << GenericTag::write()
|
||||
*/
|
||||
class Album : public GenericTag {
|
||||
private:
|
||||
unsigned int _year; /**< The year associated with this Album. */
|
||||
|
||||
public:
|
||||
Album(); /**< Album tag constructor */
|
||||
|
||||
/**
|
||||
* Album tag constructor
|
||||
*
|
||||
* @param name Album name
|
||||
* @param year Album year
|
||||
*/
|
||||
Album(const std::string &, unsigned int);
|
||||
|
||||
/**
|
||||
* The album's primary key is the concatenation of year
|
||||
* and name, allowing for multiple albums with the same
|
||||
* name but released at different times.
|
||||
*
|
||||
* @return Album::_year / GenericTag::primary_key() (Example: "1998/Hyrule Symphony")
|
||||
*/
|
||||
const std::string primary_key() const;
|
||||
|
||||
/**
|
||||
* Read album information from file.
|
||||
*
|
||||
* @param file The file to read from.
|
||||
*/
|
||||
void read(File &);
|
||||
|
||||
/**
|
||||
* Write album information to file.
|
||||
*
|
||||
* @param file The file to write to.
|
||||
*/
|
||||
void write(File &);
|
||||
|
||||
/**
|
||||
* Called to access the year associated with this album.
|
||||
*
|
||||
* @return Album::_year.
|
||||
*/
|
||||
unsigned int year();
|
||||
};
|
||||
|
||||
#endif /* OCARINA_CORE_TAGS_ALBUM_H */
|
|
@ -61,7 +61,7 @@ public:
|
|||
*
|
||||
* @return GenericTag::_name.
|
||||
*/
|
||||
const std::string &name();
|
||||
const std::string &name() const;
|
||||
|
||||
/**
|
||||
* Called to access the lowercase form of ::_name.
|
||||
|
|
|
@ -121,7 +121,7 @@ void QueueModel::get_value_uint(Track *track, int column,
|
|||
specific.set(track->track);
|
||||
break;
|
||||
case 5:
|
||||
specific.set(track->album->year);
|
||||
specific.set(track->album->year());
|
||||
break;
|
||||
case 7:
|
||||
specific.set(track->play_count);
|
||||
|
@ -149,7 +149,7 @@ void QueueModel::get_value_str(Track *track, int column,
|
|||
specific.set(track->artist->name());
|
||||
break;
|
||||
case 4:
|
||||
specific.set(track->album->name);
|
||||
specific.set(track->album->name());
|
||||
break;
|
||||
case 6:
|
||||
specific.set(track->genre->name);
|
||||
|
|
|
@ -16,6 +16,7 @@ test( "idle" )
|
|||
|
||||
test( "tags/generic" )
|
||||
test( "tags/artist" )
|
||||
test( "tags/album" )
|
||||
|
||||
test_env.UsePackage("taglib")
|
||||
objs += [ get_test_obj("tags", "core") ]
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
album
|
||||
artist
|
||||
generic
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
/**
|
||||
* @file
|
||||
* Copyright 2014 (c) Anna Schumaker.
|
||||
*/
|
||||
#include <core/tags/album.h>
|
||||
#include <tests/test.h>
|
||||
|
||||
static void test_album_tag()
|
||||
{
|
||||
Album album("Hyrule Symphony", 1998);
|
||||
File f("album_tag", 0);
|
||||
|
||||
test_equal(album.name(), (std::string)"Hyrule Symphony");
|
||||
test_equal(album.lowercase(), (std::string)"hyrule symphony");
|
||||
test_equal(album.year(), (unsigned int)1998);
|
||||
test_equal(album.primary_key(), (std::string)"1998/Hyrule Symphony");
|
||||
|
||||
f.open(OPEN_WRITE);
|
||||
album.write(f);
|
||||
f.close();
|
||||
|
||||
album = Album();
|
||||
test_equal(album.name(), (std::string)"");
|
||||
test_equal(album.lowercase(), (std::string)"");
|
||||
test_equal(album.year(), (unsigned int)0);
|
||||
test_equal(album.primary_key(), (std::string)"0/");
|
||||
|
||||
f.open(OPEN_READ);
|
||||
album.read(f);
|
||||
f.close();
|
||||
|
||||
test_equal(album.name(), (std::string)"Hyrule Symphony");
|
||||
test_equal(album.lowercase(), (std::string)"hyrule symphony");
|
||||
test_equal(album.year(), (unsigned int)1998);
|
||||
test_equal(album.primary_key(), (std::string)"1998/Hyrule Symphony");
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
run_test("Album Tag Test", test_album_tag);
|
||||
return 0;
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
lib
|
||||
colmgr
|
||||
model
|
||||
tags/
|
||||
|
|
Loading…
Reference in New Issue