tagdb: Add information about tag database layer
This layer will be separate from the library updating code. This will give me a place to manage the various databases without extra code to scan and update paths. Signed-off-by: Anna Schumaker <anna@ocarinaproject.net>
This commit is contained in:
parent
89fd79e079
commit
0fee94f76a
142
DESIGN
142
DESIGN
|
@ -528,6 +528,75 @@ Idle queue:
|
|||
|
||||
|
||||
|
||||
Tag Database:
|
||||
The tag database is actually several databases that describe every
|
||||
track added by the user. I do not expect the artist_db, album_db,
|
||||
genre_db and library_db to change often, so they can be created as
|
||||
autosaving databases that will write to disk whenever they are changed.
|
||||
The track_db can have several additions and removals in a row, so the
|
||||
commit() function is used to control when this db is written to disk,
|
||||
avoiding the huge performance hit that would come with saving on EVERY
|
||||
change.
|
||||
|
||||
Tags are defined in the sections below.
|
||||
|
||||
- Import data:
|
||||
struct ImportData {
|
||||
std::string filepath;
|
||||
unsigned int last_day;
|
||||
unsigned int last_month;
|
||||
unsigned int last_year;
|
||||
unsigned int count;
|
||||
};
|
||||
|
||||
- Databases:
|
||||
Database<Artist> artist_db;
|
||||
Database<Album> album_db;
|
||||
Database<Genre> genre_db;
|
||||
Database<Library> library_db;
|
||||
Database<Track> track_db;
|
||||
|
||||
- API:
|
||||
void tagdb :: init();
|
||||
Load all databases from disk.
|
||||
|
||||
void tagdb :: commit();
|
||||
Write track_db to disk.
|
||||
|
||||
Track *tagdb :: add_track(const std::string &filepath, Library *library);
|
||||
Add a new track to the track_db and return a pointer to it.
|
||||
Return NULL if this track is already in the database.
|
||||
|
||||
Check the database size both before and after to see if a new
|
||||
track has been added.
|
||||
|
||||
Track *tagdb :: import_track(const std::string &filepath,
|
||||
Library *library, ImportData *import);
|
||||
Use add_track() to add a new track to the database. If the
|
||||
return values != NULL, then use the import information to set
|
||||
last played variables.
|
||||
|
||||
Library *tagdb :: add_library(const std::string &filepath);
|
||||
Add a new path to library_db and return its library_id.
|
||||
|
||||
void tagdb :: remove_track(unsigned int track_id);
|
||||
Remove the track with id equal to track_id from the track_db.
|
||||
|
||||
void tagdb :: remove_library(unsigned int library_id);
|
||||
Remove the library with id equal to library_id from the
|
||||
library_db.
|
||||
|
||||
Track *tagdb :: lookup(unsigned int track_id);
|
||||
Look up the track_id in the track database.
|
||||
|
||||
const Database<Track> &tagdb :: get_track_db();
|
||||
Return a reference to the track_db.
|
||||
|
||||
const Database<Library> &tagdb :: get_library_db();
|
||||
Return a reference to the library_db.
|
||||
|
||||
|
||||
|
||||
Artist Tag:
|
||||
The arist tag is used to collect basic information about the various
|
||||
artists that have been added to the library.
|
||||
|
@ -553,7 +622,7 @@ Artist Tag:
|
|||
Initialize an invalid Artist instance.
|
||||
|
||||
Artist(const std::string &artist_name);
|
||||
Use artist_name to set name and lower.
|
||||
Set artist_name and add to the filter.
|
||||
|
||||
const std::string Artist :: primary_key();
|
||||
Use artist name as primary key.
|
||||
|
@ -572,35 +641,33 @@ Album Tag:
|
|||
- Album:
|
||||
class Album : public DatabaseEntry {
|
||||
public:
|
||||
std::string name;
|
||||
std::string lower;
|
||||
std::string name;
|
||||
std::string lower;
|
||||
unsigned int year;
|
||||
unsigned int artist_id;
|
||||
|
||||
Album();
|
||||
Album(const std::string &, unsigned int, unsigned int);
|
||||
Album(const std::string &, unsigned int);
|
||||
const std::string primary_key();
|
||||
void read(File &);
|
||||
void write(File &);
|
||||
};
|
||||
|
||||
- File Format:
|
||||
File << artist_id << year << name;
|
||||
File << year << name;
|
||||
|
||||
- API:
|
||||
Album();
|
||||
Initialize an invalid Album instance.
|
||||
|
||||
Album(const std::string &album_name, unsigned int album_year,
|
||||
unsigned int album_artist);
|
||||
Set name from album name and find the lowercased form.
|
||||
Set year from album_year and artist_id from album_artist.
|
||||
Album(const std::string &album_name, unsigned int album_year);
|
||||
Set name and year from album name and album_year. Add album
|
||||
name to the filter.
|
||||
|
||||
const std::string Album :: primary_key();
|
||||
Return the string: "$name.$year.$artist_id"
|
||||
Return the string: "$year.$name"
|
||||
|
||||
void Album :: read(File &f);
|
||||
Read artist_id, year, and name from file. Then add album name
|
||||
Read year, and name from file. Then add album name
|
||||
to the filter.
|
||||
|
||||
void Artist :: write(File &f);
|
||||
|
@ -633,7 +700,7 @@ Genre Tag:
|
|||
Initialize an invalid Genre instance.
|
||||
|
||||
Genre(const std::string &genre_name);
|
||||
Use genre_name to set genre and lower.
|
||||
Set genre from genre name and add to the filter.
|
||||
|
||||
const std::string Genre :: primary_key();
|
||||
Use genre as primary key.
|
||||
|
@ -649,12 +716,13 @@ Genre Tag:
|
|||
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
|
||||
internally to keep track of paths added by the user.
|
||||
internally to keep track of paths added by the user. The count field
|
||||
will be managed by the Track tag class.
|
||||
|
||||
- Library:
|
||||
class library :: Library : public DatabaseEntry {
|
||||
class Library : public DatabaseEntry {
|
||||
public:
|
||||
string root_path; /* primary_key */
|
||||
std::string root_path;
|
||||
unsigned int count;
|
||||
bool enabled;
|
||||
|
||||
|
@ -675,12 +743,13 @@ Library Tag:
|
|||
Library(const std::string &path);
|
||||
Set root_path from the provided path.
|
||||
Set enabled = true.
|
||||
Set count = 0.
|
||||
|
||||
const std::string Library :: primary_key();
|
||||
Use root_path as the primary key,
|
||||
|
||||
void read(File &f);
|
||||
Read a library path from file.
|
||||
Read a library path from file, set count = 0.
|
||||
|
||||
void write(File &f);
|
||||
Write a library path to file.
|
||||
|
@ -712,18 +781,17 @@ Track Tag:
|
|||
std :: string length_str;
|
||||
|
||||
Track();
|
||||
Track(Library *, Artist *, Album *, Genre *, unsigned int,
|
||||
unsigned int, const std::string &, const std::string &);
|
||||
Track(Library *, const std::string &);
|
||||
const std::string primary_key();
|
||||
const std::string path();
|
||||
void tag();
|
||||
void read(File &);
|
||||
void write(File &);
|
||||
};
|
||||
|
||||
- File Format:
|
||||
File << library->id << artist->id << album->id << genre->id;
|
||||
File << track << last_year << last_month << last_day << play_count;
|
||||
File << length << length_str << endl
|
||||
File << library->id << artist->id << album->id << genre->id << track;
|
||||
File << last_year << last_month << last_day << play_count << length;
|
||||
File << title << endl;
|
||||
File << filepath << endl;
|
||||
|
||||
|
@ -731,16 +799,13 @@ Track Tag:
|
|||
Track();
|
||||
Initialize an invalid Track instance.
|
||||
|
||||
Track(Library *lib, Artist *art, Album *alb, Genre *gen,
|
||||
unsigned int track, unsigned int length,
|
||||
const std::string &track_title, const std::string &full_path);
|
||||
- Set Library, Artist, Album and Genre pointers.
|
||||
- Set track and length variables.
|
||||
- Set play_count, last_year, last_month and last_day = 0.
|
||||
- Set title from track_title.
|
||||
- Strip library path from prams.full_path and use the result to
|
||||
set filepath.
|
||||
- Set lowercase title and find the string form of length.
|
||||
Track(const std::string &full_path, Library *lib);
|
||||
This function will only set up the primary key, and the tag()
|
||||
function must be called to find audio tags.
|
||||
|
||||
- Strip library path from the beginning of full_path and use
|
||||
the result to set filepath.
|
||||
- Set library = lib.
|
||||
|
||||
const std::string Track :: primary_key();
|
||||
return path();
|
||||
|
@ -749,10 +814,19 @@ Track Tag:
|
|||
Combine library->path and filepath to find the full path to
|
||||
the audio file.
|
||||
|
||||
void Track :: tag();
|
||||
Use TagLib to find tags and audio properties for this file.
|
||||
|
||||
- Insert Artist, Album, and Genre into their databases and
|
||||
set the corresponding pointers.
|
||||
- Find title, track number, and length.
|
||||
- Set play_count, last_year, last_month and last_day = 0.
|
||||
- Set lowercase title and find the string form of length.
|
||||
|
||||
void read(File &f);
|
||||
Read track information from file. Look up the corresponding
|
||||
Library, Artist, Album and Genre pointers and add title to
|
||||
the filter.
|
||||
Library, Artist, Album and Genre pointers. Add title to the
|
||||
filter and find the string version of length.
|
||||
|
||||
void write(File &f);
|
||||
Write track information to file.
|
||||
|
|
Loading…
Reference in New Issue