tags: Begin creating the tag database
This patch adds classes for Artist, Album, Genre and Library. Signed-off-by: Anna Schumaker <anna@ocarinaproject.net>
This commit is contained in:
parent
d61dbae47f
commit
134348f253
22
DESIGN
22
DESIGN
|
@ -622,13 +622,13 @@ Artist Tag:
|
||||||
Initialize an invalid Artist instance.
|
Initialize an invalid Artist instance.
|
||||||
|
|
||||||
Artist(const std::string &artist_name);
|
Artist(const std::string &artist_name);
|
||||||
Set artist_name and add to the filter.
|
Set artist_name and find the lowercase form.
|
||||||
|
|
||||||
const std::string Artist :: primary_key();
|
const std::string Artist :: primary_key();
|
||||||
Use artist name as primary key.
|
Use artist name as primary key.
|
||||||
|
|
||||||
void Artist :: read(File &f);
|
void Artist :: read(File &f);
|
||||||
Read artist name from file and add to the filter.
|
Read artist name from file and find the lowercase form.
|
||||||
|
|
||||||
void Artist :: write(File &f);
|
void Artist :: write(File &f);
|
||||||
Write artist name to file.
|
Write artist name to file.
|
||||||
|
@ -660,15 +660,15 @@ Album Tag:
|
||||||
Initialize an invalid Album instance.
|
Initialize an invalid Album instance.
|
||||||
|
|
||||||
Album(const std::string &album_name, unsigned int album_year);
|
Album(const std::string &album_name, unsigned int album_year);
|
||||||
Set name and year from album name and album_year. Add album
|
Set name and year from album name and album_year. Find the
|
||||||
name to the filter.
|
lowercase form of the album name.
|
||||||
|
|
||||||
const std::string Album :: primary_key();
|
const std::string Album :: primary_key();
|
||||||
Return the string: "$year.$name"
|
Return the string: "$year.$name"
|
||||||
|
|
||||||
void Album :: read(File &f);
|
void Album :: read(File &f);
|
||||||
Read year, and name from file. Then add album name
|
Read year, and name from file. Then set the lowercase form
|
||||||
to the filter.
|
of the album name.
|
||||||
|
|
||||||
void Artist :: write(File &f);
|
void Artist :: write(File &f);
|
||||||
Write album information to file.
|
Write album information to file.
|
||||||
|
@ -700,13 +700,13 @@ Genre Tag:
|
||||||
Initialize an invalid Genre instance.
|
Initialize an invalid Genre instance.
|
||||||
|
|
||||||
Genre(const std::string &genre_name);
|
Genre(const std::string &genre_name);
|
||||||
Set genre from genre name and add to the filter.
|
Set genre from genre name and find the lowercase form.
|
||||||
|
|
||||||
const std::string Genre :: primary_key();
|
const std::string Genre :: primary_key();
|
||||||
Use genre as primary key.
|
Use genre as primary key.
|
||||||
|
|
||||||
void Genre :: read(File &f);
|
void Genre :: read(File &f);
|
||||||
Read genre from file and add to the filter.
|
Read genre from file and find the lowercase form.
|
||||||
|
|
||||||
void Genre :: write(File &f);
|
void Genre :: write(File &f);
|
||||||
Write genre to file.
|
Write genre to file.
|
||||||
|
@ -739,17 +739,19 @@ Library Tag:
|
||||||
- API:
|
- API:
|
||||||
Library();
|
Library();
|
||||||
Initialize an invalid Library instance.
|
Initialize an invalid Library instance.
|
||||||
|
Set count = 0.
|
||||||
|
Set enabled = false.
|
||||||
|
|
||||||
Library(const std::string &path);
|
Library(const std::string &path);
|
||||||
Set root_path from the provided path.
|
Set root_path from the provided path.
|
||||||
Set enabled = true.
|
|
||||||
Set count = 0.
|
Set count = 0.
|
||||||
|
Set enabled = true.
|
||||||
|
|
||||||
const std::string Library :: primary_key();
|
const std::string Library :: primary_key();
|
||||||
Use root_path as the primary key,
|
Use root_path as the primary key,
|
||||||
|
|
||||||
void read(File &f);
|
void read(File &f);
|
||||||
Read a library path from file, set count = 0.
|
Read a library path from file.
|
||||||
|
|
||||||
void write(File &f);
|
void write(File &f);
|
||||||
Write a library path to file.
|
Write a library path to file.
|
||||||
|
|
|
@ -0,0 +1,63 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2014 (c) Anna Schumaker.
|
||||||
|
*/
|
||||||
|
#ifndef OCARINA_TAGS_H
|
||||||
|
#define OCARINA_TAGS_H
|
||||||
|
|
||||||
|
#include <database.h>
|
||||||
|
|
||||||
|
|
||||||
|
class Artist : public DatabaseEntry {
|
||||||
|
public:
|
||||||
|
std::string name;
|
||||||
|
std::string lower;
|
||||||
|
|
||||||
|
Artist();
|
||||||
|
Artist(const std::string &);
|
||||||
|
const std::string primary_key();
|
||||||
|
void read(File &);
|
||||||
|
void write(File &);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
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();
|
||||||
|
void read(File &);
|
||||||
|
void write(File &);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class Genre : public DatabaseEntry {
|
||||||
|
public:
|
||||||
|
std::string name;
|
||||||
|
std::string lower;
|
||||||
|
|
||||||
|
Genre();
|
||||||
|
Genre(const std::string &);
|
||||||
|
const std::string primary_key();
|
||||||
|
void read(File &);
|
||||||
|
void write(File &);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class Library : public DatabaseEntry {
|
||||||
|
public:
|
||||||
|
std::string root_path;
|
||||||
|
unsigned int count;
|
||||||
|
bool enabled;
|
||||||
|
|
||||||
|
Library();
|
||||||
|
Library(const std::string &);
|
||||||
|
const std::string primary_key();
|
||||||
|
void read(File &);
|
||||||
|
void write(File &);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* OCARINA_TAGS_H */
|
|
@ -0,0 +1,137 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2014 (c) Anna Schumaker.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <tags.h>
|
||||||
|
#include <filter.h>
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Artist tag
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
Artist :: Artist() {}
|
||||||
|
|
||||||
|
Artist :: Artist(const std::string &s)
|
||||||
|
: name(s), lower(filter :: lowercase(name))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string Artist :: primary_key()
|
||||||
|
{
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Artist :: read(File &f)
|
||||||
|
{
|
||||||
|
name = f.getline();
|
||||||
|
lower = filter :: lowercase(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Artist :: write(File &f)
|
||||||
|
{
|
||||||
|
f << name;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* 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()
|
||||||
|
{
|
||||||
|
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
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
Genre :: Genre() {}
|
||||||
|
|
||||||
|
Genre :: Genre(const std::string &s)
|
||||||
|
: name(s), lower(filter :: lowercase(name))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string Genre :: primary_key()
|
||||||
|
{
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Genre :: read(File &f)
|
||||||
|
{
|
||||||
|
name = f.getline();
|
||||||
|
lower = filter :: lowercase(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Genre :: write(File &f)
|
||||||
|
{
|
||||||
|
f << name;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Library tag
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
Library :: Library()
|
||||||
|
: count(0), enabled(false)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Library :: Library(const std::string &s)
|
||||||
|
: root_path(s), count(0), enabled(true)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string Library :: primary_key()
|
||||||
|
{
|
||||||
|
return root_path;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Library :: read(File &f)
|
||||||
|
{
|
||||||
|
f >> enabled;
|
||||||
|
root_path = f.getline();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Library :: write(File &f)
|
||||||
|
{
|
||||||
|
f << enabled << " " << root_path;
|
||||||
|
}
|
|
@ -8,7 +8,8 @@ if sys.argv.count("tests") > 0:
|
||||||
|
|
||||||
src = SConscript("src/Sconscript")
|
src = SConscript("src/Sconscript")
|
||||||
|
|
||||||
tests = [ "version", "file", "db_entry", "database", "index", "filter", "idle" ]
|
tests = [ "version", "file", "db_entry", "database", "index",
|
||||||
|
"filter", "idle", "tag_db" ]
|
||||||
#scripts = [ "playlist", "library", "playqueue", "deck", "audio", "gui" ]
|
#scripts = [ "playlist", "library", "playqueue", "deck", "audio", "gui" ]
|
||||||
|
|
||||||
prev = None
|
prev = None
|
||||||
|
|
|
@ -0,0 +1,138 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2014 (c) Anna Schumaker.
|
||||||
|
* Test a DatabaseEntry
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <tags.h>
|
||||||
|
#include <print.h>
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
|
||||||
|
unsigned int test_num = 0;
|
||||||
|
|
||||||
|
void test_results(bool success, unsigned int line)
|
||||||
|
{
|
||||||
|
print(" %u: ", test_num);
|
||||||
|
if (success)
|
||||||
|
print("Success!\n");
|
||||||
|
else {
|
||||||
|
print("FAILED (%u) =(\n", line);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
test_num++;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
void save_tag(const std::string &file, T &tag)
|
||||||
|
{
|
||||||
|
File f(file, FILE_TYPE_DATA);
|
||||||
|
f.open(OPEN_WRITE);
|
||||||
|
tag.write(f);
|
||||||
|
f.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
void load_tag(const std::string &file, T &tag)
|
||||||
|
{
|
||||||
|
File f(file, FILE_TYPE_DATA);
|
||||||
|
f.open(OPEN_READ);
|
||||||
|
tag.read(f);
|
||||||
|
f.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
void artist_test_tags(Artist &artist)
|
||||||
|
{
|
||||||
|
test_results(artist.name == "Artist Name", __LINE__);
|
||||||
|
test_results(artist.lower == "artist name", __LINE__);
|
||||||
|
test_results(artist.primary_key() == "Artist Name", __LINE__);
|
||||||
|
}
|
||||||
|
|
||||||
|
void artist_test()
|
||||||
|
{
|
||||||
|
Artist artist("Artist Name"), artist2;
|
||||||
|
|
||||||
|
artist_test_tags(artist);
|
||||||
|
save_tag("artist.txt", artist);
|
||||||
|
load_tag("artist.txt", artist2);
|
||||||
|
artist_test_tags(artist2);
|
||||||
|
}
|
||||||
|
|
||||||
|
void album_test_tags(Album &album)
|
||||||
|
{
|
||||||
|
test_results(album.name == "Album Name", __LINE__);
|
||||||
|
test_results(album.lower == "album name", __LINE__);
|
||||||
|
test_results(album.year == 2014, __LINE__);
|
||||||
|
test_results(album.primary_key() == "2014.Album Name", __LINE__);
|
||||||
|
}
|
||||||
|
|
||||||
|
void album_test()
|
||||||
|
{
|
||||||
|
Album album("Album Name", 2014), album2;
|
||||||
|
|
||||||
|
album_test_tags(album);
|
||||||
|
save_tag("album.txt", album);
|
||||||
|
load_tag("album.txt", album2);
|
||||||
|
album_test_tags(album2);
|
||||||
|
}
|
||||||
|
|
||||||
|
void genre_test_tags(Genre &genre)
|
||||||
|
{
|
||||||
|
test_results(genre.name == "Genre Name", __LINE__);
|
||||||
|
test_results(genre.lower == "genre name", __LINE__);
|
||||||
|
test_results(genre.primary_key() == "Genre Name", __LINE__);
|
||||||
|
}
|
||||||
|
|
||||||
|
void genre_test()
|
||||||
|
{
|
||||||
|
Genre genre("Genre Name"), genre2;
|
||||||
|
|
||||||
|
genre_test_tags(genre);
|
||||||
|
save_tag("genre.txt", genre);
|
||||||
|
load_tag("genre.txt", genre2);
|
||||||
|
genre_test_tags(genre2);
|
||||||
|
}
|
||||||
|
|
||||||
|
void library_test_tags(Library &library)
|
||||||
|
{
|
||||||
|
test_results(library.root_path == "/home/user/Music", __LINE__);
|
||||||
|
test_results(library.count == 0, __LINE__);
|
||||||
|
test_results(library.enabled == true, __LINE__);
|
||||||
|
test_results(library.primary_key() == "/home/user/Music", __LINE__);
|
||||||
|
}
|
||||||
|
|
||||||
|
void library_test()
|
||||||
|
{
|
||||||
|
Library library("/home/user/Music"), library2;
|
||||||
|
|
||||||
|
library_test_tags(library);
|
||||||
|
test_results(library2.enabled == false, __LINE__);
|
||||||
|
save_tag("library.txt", library);
|
||||||
|
load_tag("library.txt", library2);
|
||||||
|
library_test_tags(library2);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
char c;
|
||||||
|
|
||||||
|
while ((c = getopt(argc, argv, "aAgl")) != -1) {
|
||||||
|
switch (c) {
|
||||||
|
case 'a':
|
||||||
|
artist_test();
|
||||||
|
break;
|
||||||
|
case 'A':
|
||||||
|
album_test();
|
||||||
|
break;
|
||||||
|
case 'g':
|
||||||
|
genre_test();
|
||||||
|
break;
|
||||||
|
case 'l':
|
||||||
|
library_test();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
#!/bin/bash
|
||||||
|
# Copyright 2014 (c) Anna Schumaker
|
||||||
|
|
||||||
|
. $(dirname $0)/_functions
|
||||||
|
|
||||||
|
function test_tag
|
||||||
|
{
|
||||||
|
new_test "Test $1 Tag"
|
||||||
|
./src/tags.run "$2"
|
||||||
|
}
|
||||||
|
|
||||||
|
test_tag "Artist" "-a"
|
||||||
|
echo
|
||||||
|
test_tag "Album" "-A"
|
||||||
|
echo
|
||||||
|
test_tag "Genre" "-g"
|
||||||
|
echo
|
||||||
|
test_tag "Library" "-l"
|
Loading…
Reference in New Issue