Added proper support for disc number as a first-class field on Track.

This commit is contained in:
casey 2016-06-03 22:22:45 -07:00
parent 52d01ffb7b
commit 4d7aa33075
7 changed files with 52 additions and 34 deletions

View File

@ -51,6 +51,7 @@
#include <taglib/mpeg/id3v2/frames/attachedpictureframe.h>
#include <taglib/mpeg/id3v2/frames/commentsframe.h>
#include <taglib/ogg/oggfile.h>
#include <taglib/toolkit/tpropertymap.h>
#else
#include <taglib/tlist.h>
#include <taglib/tfile.h>
@ -66,6 +67,7 @@
#include <taglib/attachedpictureframe.h>
#include <taglib/commentsframe.h>
#include <taglib/oggfile.h>
#include <taglib/tpropertymap.h>
#endif
#include <vector>
@ -162,6 +164,14 @@ bool TaglibMetadataReader::GetGenericTag(const char* uri, musik::core::IMetadata
this->SetTagValue("year", tag->year(), target);
}
TagLib::PropertyMap map = tag->properties();
if (map.contains("DISCNUMBER")) {
TagLib::StringList value = map["DISCNUMBER"];
if (value.size()) {
this->SetTagValue("disc", value[0], target);
}
}
TagLib::AudioProperties *audio = file.audioProperties();
this->SetAudioProperties(audio, target);
@ -228,6 +238,7 @@ bool TaglibMetadataReader::GetID3v2Tag(const char* uri, musik::core::IMetadataWr
this->SetTagValues("language", allTags["TLAN"], track);
this->SetTagValues("disc", allTags["TPOS"], track);
this->SetTagValues("lyrics", allTags["USLT"], track);
this->SetTagValues("disc", allTags["TPOS"], track);
/* genre. note that multiple genres may be present */

View File

@ -221,6 +221,7 @@ bool LocalLibrary::IsStaticMetaKey(std::string &metakey){
if (staticMetaKeys.empty()) {
staticMetaKeys.insert("track");
staticMetaKeys.insert("disc");
staticMetaKeys.insert("bpm");
staticMetaKeys.insert("duration");
staticMetaKeys.insert("filesize");
@ -275,6 +276,7 @@ void LocalLibrary::CreateDatabase(db::Connection &db){
db.Execute("CREATE TABLE IF NOT EXISTS tracks ("
"id INTEGER PRIMARY KEY AUTOINCREMENT,"
"track INTEGER DEFAULT 0,"
"disc TEXT DEFAULT '1',"
"bpm REAL DEFAULT 0,"
"duration INTEGER DEFAULT 0,"
"filesize INTEGER DEFAULT 0,"

View File

@ -43,6 +43,7 @@ namespace musik { namespace core { namespace library { namespace constants {
static const char* TABLE_NAME = "tracks";
static const char* ID = "id";
static const char* TRACK_NUM = "track";
static const char* DISC_NUM = "disc";
static const char* BPM = "bpm";
static const char* DURATION = "duration";
static const char* FILESIZE = "filesize";

View File

@ -179,18 +179,19 @@ static DBID writeToTracksTable(
IndexerTrack& track)
{
db::CachedStatement stmt("INSERT OR REPLACE INTO tracks " \
"(id, track, bpm, duration, filesize, year, title, filename, filetime, path_id) " \
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", dbConnection);
"(id, track, disc, bpm, duration, filesize, year, title, filename, filetime, path_id) " \
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", dbConnection);
stmt.BindText(1, track.GetValue("track"));
stmt.BindText(2, track.GetValue("bpm"));
stmt.BindText(3, track.GetValue("duration"));
stmt.BindText(4, track.GetValue("filesize"));
stmt.BindText(5, track.GetValue("year"));
stmt.BindText(6, track.GetValue("title"));
stmt.BindText(7, track.GetValue("filename"));
stmt.BindText(8, track.GetValue("filetime"));
stmt.BindText(9, track.GetValue("path_id"));
stmt.BindText(2, track.GetValue("disc"));
stmt.BindText(3, track.GetValue("bpm"));
stmt.BindText(4, track.GetValue("duration"));
stmt.BindText(5, track.GetValue("filesize"));
stmt.BindText(6, track.GetValue("year"));
stmt.BindText(7, track.GetValue("title"));
stmt.BindText(8, track.GetValue("filename"));
stmt.BindText(9, track.GetValue("filetime"));
stmt.BindText(10, track.GetValue("path_id"));
if (track.Id() != 0) {
stmt.BindInt(0, track.Id());
@ -218,6 +219,7 @@ static void removeRelation(
static void removeKnownFields(Track::MetadataMap& metadata) {
metadata.erase("track");
metadata.erase("disc");
metadata.erase("bpm");
metadata.erase("duration");
metadata.erase("year");

View File

@ -167,22 +167,23 @@ bool LibraryTrack::Load(Track *target, db::Connection &db) {
"ORDER BY tm.id", db);
db::Statement trackQuery(
"SELECT t.track, t.bpm, t.duration, t.filesize, t.year, t.title, t.filename, t.thumbnail_id, al.name, t.filetime " \
"SELECT t.track, t.disc, t.bpm, t.duration, t.filesize, t.year, t.title, t.filename, t.thumbnail_id, al.name, t.filetime " \
"FROM tracks t, paths p, albums al " \
"WHERE t.id=? AND t.album_id=al.id", db);
trackQuery.BindInt(0, target->Id());
if (trackQuery.Step() == db::Row) {
target->SetValue("track", trackQuery.ColumnText(0));
target->SetValue("bpm", trackQuery.ColumnText(1));
target->SetValue("duration", trackQuery.ColumnText(2));
target->SetValue("filesize", trackQuery.ColumnText(3));
target->SetValue("year", trackQuery.ColumnText(4));
target->SetValue("title", trackQuery.ColumnText(5));
target->SetValue("filename", trackQuery.ColumnText(6));
target->SetValue("thumbnail_id", trackQuery.ColumnText(7));
target->SetValue("album", trackQuery.ColumnText(8));
target->SetValue("filetime", trackQuery.ColumnText(9));
target->SetValue("disc", trackQuery.ColumnText(1));
target->SetValue("bpm", trackQuery.ColumnText(2));
target->SetValue("duration", trackQuery.ColumnText(3));
target->SetValue("filesize", trackQuery.ColumnText(4));
target->SetValue("year", trackQuery.ColumnText(5));
target->SetValue("title", trackQuery.ColumnText(6));
target->SetValue("filename", trackQuery.ColumnText(7));
target->SetValue("thumbnail_id", trackQuery.ColumnText(8));
target->SetValue("album", trackQuery.ColumnText(9));
target->SetValue("filetime", trackQuery.ColumnText(10));
genresQuery.BindInt(0, target->Id());
while (genresQuery.Step() == db::Row) {

View File

@ -214,7 +214,7 @@ int main(int argc, char* argv[])
#endif
#ifdef __PDCURSES__
PDC_set_resize_limits(26, 38, 100, 150);
PDC_set_resize_limits(12, 60, 60, 250);
PDC_set_title("musikbox ♫");
PDC_set_function_key(FUNCTION_KEY_SHUT_DOWN, 4);
#endif

View File

@ -69,10 +69,10 @@ bool CategoryTrackListQuery::OnRun(Connection& db) {
}
this->query = boost::str(boost::format(
"SELECT DISTINCT t.id, t.track, t.bpm, t.duration, t.filesize, t.year, t.title, t.filename, t.thumbnail_id, al.name AS album, gn.name AS genre, ar.name AS artist, t.filetime " \
"SELECT DISTINCT t.id, t.track, t.disc, t.bpm, t.duration, t.filesize, t.year, t.title, t.filename, t.thumbnail_id, al.name AS album, gn.name AS genre, ar.name AS artist, t.filetime " \
"FROM tracks t, paths p, albums al, artists ar, genres gn " \
"WHERE t.%s=? AND t.album_id=al.id AND t.visual_genre_id=gn.id AND t.visual_artist_id=ar.id "
"ORDER BY album, track, artist") % this->column);
"ORDER BY album, disc, track, artist") % this->column);
std::string lastAlbum;
size_t index = 0;
@ -81,7 +81,7 @@ bool CategoryTrackListQuery::OnRun(Connection& db) {
trackQuery.BindInt(0, this->id);
while (trackQuery.Step() == Row) {
std::string album = trackQuery.ColumnText(9);
std::string album = trackQuery.ColumnText(10);
DBID id = trackQuery.ColumnInt64(0);
if (album != lastAlbum) {
@ -91,17 +91,18 @@ bool CategoryTrackListQuery::OnRun(Connection& db) {
TrackPtr track = TrackPtr(new LibraryTrack(id, this->library));
track->SetValue(Track::TRACK_NUM, trackQuery.ColumnText(1));
track->SetValue(Track::BPM, trackQuery.ColumnText(2));
track->SetValue(Track::DURATION, trackQuery.ColumnText(3));
track->SetValue(Track::FILESIZE, trackQuery.ColumnText(4));
track->SetValue(Track::YEAR, trackQuery.ColumnText(5));
track->SetValue(Track::TITLE, trackQuery.ColumnText(6));
track->SetValue(Track::FILENAME, trackQuery.ColumnText(7));
track->SetValue(Track::THUMBNAIL_ID, trackQuery.ColumnText(8));
track->SetValue(Track::DISC_NUM, trackQuery.ColumnText(2));
track->SetValue(Track::BPM, trackQuery.ColumnText(3));
track->SetValue(Track::DURATION, trackQuery.ColumnText(4));
track->SetValue(Track::FILESIZE, trackQuery.ColumnText(5));
track->SetValue(Track::YEAR, trackQuery.ColumnText(6));
track->SetValue(Track::TITLE, trackQuery.ColumnText(7));
track->SetValue(Track::FILENAME, trackQuery.ColumnText(8));
track->SetValue(Track::THUMBNAIL_ID, trackQuery.ColumnText(9));
track->SetValue(Track::ALBUM, album.c_str());
track->SetValue(Track::GENRE, trackQuery.ColumnText(10));
track->SetValue(Track::ARTIST, trackQuery.ColumnText(11));
track->SetValue(Track::FILETIME, trackQuery.ColumnText(12));
track->SetValue(Track::GENRE, trackQuery.ColumnText(11));
track->SetValue(Track::ARTIST, trackQuery.ColumnText(12));
track->SetValue(Track::FILETIME, trackQuery.ColumnText(13));
result->push_back(track);
++index;