libsaria: Remove old TrackTag() class
It was basically a layer of misdirection that made it harder to use Tracks. The Track() class now does everything that the TrackTag() one did.
This commit is contained in:
parent
11e3d77dca
commit
a74cea2e71
|
@ -29,7 +29,7 @@ namespace libsaria
|
|||
void remove_path(string);
|
||||
void play_id(sid_t &);
|
||||
string find_filepath(sid_t &);
|
||||
TrackTag *get_info(sid_t &);
|
||||
Track *get_info(sid_t &);
|
||||
void for_each(SourceModel *);
|
||||
void for_each_path(void (*)(struct PathInfo &));
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ namespace libsaria
|
|||
void init(int, char **);
|
||||
void quit();
|
||||
|
||||
void current_track(void (*)(Track &));
|
||||
void current_track(void (*)(Track *));
|
||||
}
|
||||
|
||||
#endif /* LIBSARIA_H */
|
||||
|
|
|
@ -12,7 +12,7 @@ namespace libsaria
|
|||
SourceModel();
|
||||
virtual ~SourceModel() = 0;
|
||||
|
||||
virtual void insert(Track &) = 0;
|
||||
virtual void insert(libsaria::Track *) = 0;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -1,58 +0,0 @@
|
|||
#ifndef LIBSARIA_TAGS_H
|
||||
#define LIBSARIA_TAGS_H
|
||||
|
||||
#include <libsaria/files.h>
|
||||
#include <libsaria/track.h>
|
||||
|
||||
#include <list>
|
||||
#include <string>
|
||||
using namespace std;
|
||||
|
||||
class TrackTag
|
||||
{
|
||||
private:
|
||||
string filepath;
|
||||
string title;
|
||||
string artist;
|
||||
string album;
|
||||
string comment;
|
||||
string genre;
|
||||
string lenstr;
|
||||
unsigned int year;
|
||||
unsigned int track;
|
||||
int length;
|
||||
int bitrate;
|
||||
int sample;
|
||||
int channels;
|
||||
sid_t inode;
|
||||
|
||||
list<string> title_words;
|
||||
list<string> artist_words;
|
||||
list<string> album_words;
|
||||
|
||||
void make_lenstr();
|
||||
void format_tags();
|
||||
|
||||
public:
|
||||
TrackTag();
|
||||
TrackTag(const TrackTag &);
|
||||
TrackTag(string, sid_t);
|
||||
TrackTag(InFile &);
|
||||
~TrackTag();
|
||||
void save(OutFile &);
|
||||
|
||||
sid_t get_songid();
|
||||
unsigned int get_track();
|
||||
string get_title();
|
||||
string get_lenstr();
|
||||
string get_artist();
|
||||
string get_album();
|
||||
string get_filepath();
|
||||
unsigned int get_year();
|
||||
|
||||
list<string> *get_title_words();
|
||||
list<string> *get_artist_words();
|
||||
list<string> *get_album_words();
|
||||
};
|
||||
|
||||
#endif /* LIBSARIA_TAGS_H */
|
|
@ -5,25 +5,54 @@
|
|||
/* Set up song id type */
|
||||
typedef ino_t sid_t;
|
||||
|
||||
#include <libsaria/tags.h>
|
||||
#include <libsaria/files.h>
|
||||
#include <string>
|
||||
using namespace std;
|
||||
|
||||
class Track
|
||||
namespace libsaria
|
||||
{
|
||||
private:
|
||||
TrackTag *tags;
|
||||
|
||||
public:
|
||||
Track();
|
||||
Track(TrackTag *);
|
||||
~Track();
|
||||
class Track
|
||||
{
|
||||
private:
|
||||
string filepath;
|
||||
string title;
|
||||
string artist;
|
||||
string album;
|
||||
string comment;
|
||||
string genre;
|
||||
string lenstr;
|
||||
unsigned int year;
|
||||
unsigned int track;
|
||||
int length;
|
||||
int bitrate;
|
||||
int sample;
|
||||
int channels;
|
||||
sid_t songid;
|
||||
|
||||
sid_t get_songid();
|
||||
unsigned int get_track();
|
||||
string get_title();
|
||||
string get_lenstr();
|
||||
string get_artist();
|
||||
string get_album();
|
||||
unsigned int get_year();
|
||||
};
|
||||
void make_lenstr();
|
||||
|
||||
public:
|
||||
Track();
|
||||
Track(string, sid_t);
|
||||
Track(InFile &);
|
||||
~Track();
|
||||
void save(OutFile &);
|
||||
|
||||
string get_filepath();
|
||||
string get_title();
|
||||
string get_artist();
|
||||
string get_album();
|
||||
string get_comment();
|
||||
string get_genre();
|
||||
string get_lenstr();
|
||||
unsigned int get_year();
|
||||
unsigned int get_track();
|
||||
int get_length();
|
||||
int get_bitrate();
|
||||
int get_channels();
|
||||
sid_t get_songid();
|
||||
};
|
||||
|
||||
} /* Namespace: libsaria */
|
||||
#endif /* LIBSARIA_TRACK_H */
|
||||
|
|
|
@ -15,22 +15,16 @@ static int current_inode(sid_t &inode)
|
|||
namespace libsaria
|
||||
{
|
||||
|
||||
void current_track(void (*func)(Track &))
|
||||
void current_track(void (*func)(Track *))
|
||||
{
|
||||
sid_t inode;
|
||||
TrackTag *tag;
|
||||
Track blank, *current;
|
||||
|
||||
if (current_inode(inode) < 0) {
|
||||
Track blank;
|
||||
func(blank);
|
||||
return;
|
||||
}
|
||||
|
||||
tag = libsaria::library::get_info(inode);
|
||||
if (tag != NULL) {
|
||||
Track track(tag);
|
||||
func(track);
|
||||
}
|
||||
if (current_inode(inode) < 0)
|
||||
current = ␣
|
||||
else
|
||||
current = libsaria::library::get_info(inode);
|
||||
func(current);
|
||||
}
|
||||
|
||||
};
|
||||
|
|
|
@ -15,12 +15,12 @@ LibraryPath::LibraryPath(InFile &in, string dir)
|
|||
println("Library path size: %d", size);
|
||||
|
||||
for (unsigned int i = 0; i < size; i++)
|
||||
file_list.push_back(TrackTag(in));
|
||||
file_list.push_back(libsaria::Track(in));
|
||||
}
|
||||
|
||||
void LibraryPath::save(OutFile &out)
|
||||
{
|
||||
list<TrackTag>::iterator it;
|
||||
list<libsaria::Track>::iterator it;
|
||||
|
||||
out << path << file_list.size() << "\n";
|
||||
for (it = file_list.begin(); it != file_list.end(); it++)
|
||||
|
|
|
@ -44,39 +44,41 @@ static void index_word(sid_t &inode, string &word)
|
|||
}
|
||||
}
|
||||
|
||||
static void index_tag(sid_t &inode, list<string> *word_list)
|
||||
static void index_tag(sid_t &inode, string tag)
|
||||
{
|
||||
list<string> word_list;
|
||||
list<string>::iterator it;
|
||||
for (it = word_list->begin(); it != word_list->end(); it++)
|
||||
libsaria::format_text(tag, word_list);
|
||||
for (it = word_list.begin(); it != word_list.end(); it++)
|
||||
index_word(inode, *it);
|
||||
}
|
||||
|
||||
IndexTask::IndexTask() {};
|
||||
IndexTask::~IndexTask() {};
|
||||
|
||||
void IndexTask::index_track(TrackTag *tag)
|
||||
void IndexTask::index_track(libsaria::Track *tag)
|
||||
{
|
||||
track_list.push_back(tag);
|
||||
}
|
||||
|
||||
void IndexTask::run_task()
|
||||
{
|
||||
list<TrackTag *>::iterator it;
|
||||
list<libsaria::Track *>::iterator it;
|
||||
sid_t inode;
|
||||
|
||||
for (it = track_list.begin(); it != track_list.end(); it++) {
|
||||
inode = (*it)->get_songid();
|
||||
index_tag(inode, (*it)->get_title_words());
|
||||
index_tag(inode, (*it)->get_artist_words());
|
||||
index_tag(inode, (*it)->get_album_words());
|
||||
index_tag(inode, (*it)->get_title());
|
||||
index_tag(inode, (*it)->get_artist());
|
||||
index_tag(inode, (*it)->get_album());
|
||||
}
|
||||
if (cur_filter != "")
|
||||
libsaria::library::filter(cur_filter);
|
||||
}
|
||||
|
||||
static void reindex_path(list<TrackTag> *tag_list)
|
||||
static void reindex_path(list<libsaria::Track> *tag_list)
|
||||
{
|
||||
list<TrackTag>::iterator it;
|
||||
list<libsaria::Track>::iterator it;
|
||||
unsigned int i = 0, j = 0;
|
||||
IndexTask *task = new IndexTask();
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include <string>
|
||||
using namespace std;
|
||||
|
||||
#include <libsaria/track.h>
|
||||
#include <libsaria/library.h>
|
||||
#include <libsaria/model.h>
|
||||
#include <libsaria/path.h>
|
||||
|
@ -13,19 +14,19 @@ class LibraryPath
|
|||
{
|
||||
private:
|
||||
string path;
|
||||
list<TrackTag> file_list;
|
||||
list<libsaria::Track> file_list;
|
||||
|
||||
list<TrackTag>::iterator find_id(sid_t &);
|
||||
list<libsaria::Track>::iterator find_id(sid_t &);
|
||||
|
||||
public:
|
||||
LibraryPath(string);
|
||||
LibraryPath(InFile &, string);
|
||||
~LibraryPath();
|
||||
|
||||
list<TrackTag> *get_list();
|
||||
list<libsaria::Track> *get_list();
|
||||
string get_path();
|
||||
void get_info(void (*)(struct libsaria::library::PathInfo &));
|
||||
void insert_track(sid_t &inode, TrackTag &);
|
||||
void insert_track(sid_t &inode, libsaria::Track &);
|
||||
void save(OutFile &);
|
||||
void update();
|
||||
unsigned int size();
|
||||
|
@ -56,12 +57,12 @@ class ScanTask : public IdleTask
|
|||
class IndexTask : public IdleTask
|
||||
{
|
||||
private:
|
||||
list<TrackTag *> track_list;
|
||||
list<libsaria::Track *> track_list;
|
||||
|
||||
public:
|
||||
IndexTask();
|
||||
~IndexTask();
|
||||
void index_track(TrackTag *);
|
||||
void index_track(libsaria::Track *);
|
||||
void run_task();
|
||||
};
|
||||
|
||||
|
|
|
@ -9,8 +9,8 @@ using namespace std;
|
|||
#include <libsaria/print.h>
|
||||
#include "library.h"
|
||||
|
||||
static list<TrackTag *> play_list;
|
||||
static list<TrackTag *>::iterator cur_track = play_list.end();
|
||||
static list<libsaria::Track *> play_list;
|
||||
static list<libsaria::Track *>::iterator cur_track = play_list.end();
|
||||
|
||||
static string format(string s)
|
||||
{
|
||||
|
@ -34,12 +34,12 @@ static string format(string s)
|
|||
return res;
|
||||
}
|
||||
|
||||
static inline bool compare_tracks(TrackTag *one, TrackTag *two)
|
||||
static inline bool compare_tracks(libsaria::Track *one, libsaria::Track *two)
|
||||
{
|
||||
return one->get_track() < two->get_track();
|
||||
}
|
||||
|
||||
static inline bool compare_albums(TrackTag *one, TrackTag *two)
|
||||
static inline bool compare_albums(libsaria::Track *one, libsaria::Track *two)
|
||||
{
|
||||
string s_one = format(one->get_album());
|
||||
string s_two = format(two->get_album());
|
||||
|
@ -50,7 +50,7 @@ static inline bool compare_albums(TrackTag *one, TrackTag *two)
|
|||
return false;
|
||||
}
|
||||
|
||||
static bool compare_tracktags(TrackTag *one, TrackTag *two)
|
||||
static bool compare_tracktags(libsaria::Track *one, libsaria::Track *two)
|
||||
{
|
||||
string s_one = format(one->get_artist());
|
||||
string s_two = format(two->get_artist());
|
||||
|
@ -63,7 +63,7 @@ static bool compare_tracktags(TrackTag *one, TrackTag *two)
|
|||
return false;
|
||||
}
|
||||
|
||||
static bool find_id(sid_t &inode, list<TrackTag *>::iterator &it)
|
||||
static bool find_id(sid_t &inode, list<libsaria::Track *>::iterator &it)
|
||||
{
|
||||
for (it = play_list.begin(); it != play_list.end(); it++) {
|
||||
if ((*it)->get_songid() == inode)
|
||||
|
@ -72,9 +72,9 @@ static bool find_id(sid_t &inode, list<TrackTag *>::iterator &it)
|
|||
return false;
|
||||
}
|
||||
|
||||
static void insert_list(list<TrackTag> *tag_list)
|
||||
static void insert_list(list<libsaria::Track> *tag_list)
|
||||
{
|
||||
list<TrackTag>::iterator it;
|
||||
list<libsaria::Track>::iterator it;
|
||||
for (it = tag_list->begin(); it != tag_list->end(); it++)
|
||||
play_list.push_back(&(*it));
|
||||
}
|
||||
|
@ -140,16 +140,14 @@ namespace libsaria
|
|||
|
||||
void library::for_each(SourceModel *model)
|
||||
{
|
||||
list<TrackTag *>::iterator it;
|
||||
for (it = play_list.begin(); it != play_list.end(); it++) {
|
||||
Track track = Track(*it);
|
||||
model->insert(track);
|
||||
}
|
||||
list<libsaria::Track *>::iterator it;
|
||||
for (it = play_list.begin(); it != play_list.end(); it++)
|
||||
model->insert(*it);
|
||||
}
|
||||
|
||||
void library::play_id(sid_t &id)
|
||||
{
|
||||
list<TrackTag *>::iterator it;
|
||||
list<libsaria::Track *>::iterator it;
|
||||
if (find_id(id, it)) {
|
||||
cur_track = it;
|
||||
libsaria::audio::load((*it)->get_filepath());
|
||||
|
@ -159,15 +157,15 @@ namespace libsaria
|
|||
|
||||
string library::find_filepath(sid_t &id)
|
||||
{
|
||||
list<TrackTag *>::iterator it;
|
||||
list<libsaria::Track *>::iterator it;
|
||||
if (find_id(id, it))
|
||||
return (*it)->get_filepath();
|
||||
return "";
|
||||
}
|
||||
|
||||
TrackTag *library::get_info(sid_t &id)
|
||||
Track *library::get_info(sid_t &id)
|
||||
{
|
||||
list<TrackTag *>::iterator it;
|
||||
list<libsaria::Track *>::iterator it;
|
||||
if (find_id(id, it))
|
||||
return *it;
|
||||
return NULL;
|
||||
|
|
|
@ -19,7 +19,7 @@ string LibraryPath::get_path()
|
|||
return path;
|
||||
}
|
||||
|
||||
list<TrackTag> *LibraryPath::get_list()
|
||||
list<libsaria::Track> *LibraryPath::get_list()
|
||||
{
|
||||
return &file_list;
|
||||
}
|
||||
|
@ -37,9 +37,9 @@ void LibraryPath::get_info(void (*info_func)(struct libsaria::library::PathInfo
|
|||
info_func(info);
|
||||
}
|
||||
|
||||
list<TrackTag>::iterator LibraryPath::find_id(sid_t &id)
|
||||
list<libsaria::Track>::iterator LibraryPath::find_id(sid_t &id)
|
||||
{
|
||||
list<TrackTag>::iterator it;
|
||||
list<libsaria::Track>::iterator it;
|
||||
for (it = file_list.begin(); it != file_list.end(); it++) {
|
||||
if (it->get_songid() == id)
|
||||
break;
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
|
||||
#include <libsaria/track.h>
|
||||
#include <libsaria/tags.h>
|
||||
#include <libsaria/library.h>
|
||||
#include "library.h"
|
||||
|
||||
void LibraryPath::insert_track(sid_t &inode, TrackTag &tag)
|
||||
void LibraryPath::insert_track(sid_t &inode, libsaria::Track &tag)
|
||||
{
|
||||
if (find_id(inode) == file_list.end())
|
||||
file_list.push_back(tag);
|
||||
|
@ -32,7 +31,7 @@ ScanTask::~ScanTask()
|
|||
void ScanTask::tag_file(file filepath)
|
||||
{
|
||||
try {
|
||||
TrackTag tag(dir + "/" + filepath.name, filepath.d_sid);
|
||||
libsaria::Track tag(dir + "/" + filepath.name, filepath.d_sid);
|
||||
library->insert_track(filepath.d_sid, tag);
|
||||
} catch (string message) {
|
||||
println(message);
|
||||
|
|
|
@ -1,189 +0,0 @@
|
|||
|
||||
#include <libsaria/track.h>
|
||||
#include <libsaria/tags.h>
|
||||
#include <libsaria/format.h>
|
||||
#include <libsaria/print.h>
|
||||
|
||||
#include <taglib/tag.h>
|
||||
#include <taglib/fileref.h>
|
||||
using namespace TagLib;
|
||||
|
||||
#include <sstream>
|
||||
using namespace std;
|
||||
|
||||
TrackTag::TrackTag()
|
||||
{
|
||||
}
|
||||
|
||||
TrackTag::TrackTag(const TrackTag &tag)
|
||||
{
|
||||
inode = tag.inode;
|
||||
filepath = tag.filepath;
|
||||
title = tag.title;
|
||||
artist = tag.artist;
|
||||
album = tag.album;
|
||||
comment = tag.comment;
|
||||
genre = tag.genre;
|
||||
lenstr = tag.lenstr;
|
||||
year = tag.year;
|
||||
track = tag.track;
|
||||
length = tag.length;
|
||||
bitrate = tag.bitrate;
|
||||
sample = tag.sample;
|
||||
channels = tag.channels;
|
||||
|
||||
title_words = tag.title_words;
|
||||
artist_words = tag.artist_words;
|
||||
album_words = tag.album_words;
|
||||
}
|
||||
|
||||
TrackTag::TrackTag(string file, sid_t ino)
|
||||
{
|
||||
Tag *tag;
|
||||
AudioProperties *prop;
|
||||
FileRef ref(file.c_str());
|
||||
|
||||
if (ref.isNull())
|
||||
throw "Error tagging file: " + file;
|
||||
filepath = file;
|
||||
inode = ino;
|
||||
|
||||
/* Extract tags */
|
||||
tag = ref.tag();
|
||||
title = tag->title().to8Bit(true);
|
||||
artist = tag->artist().to8Bit(true);
|
||||
album = tag->album().to8Bit(true);
|
||||
comment = tag->comment().to8Bit(true);
|
||||
genre = tag->genre().to8Bit(true);
|
||||
year = tag->year();
|
||||
track = tag->track();
|
||||
|
||||
/* Extract audio properties */
|
||||
prop = ref.audioProperties();
|
||||
length = prop->length();
|
||||
bitrate = prop->bitrate();
|
||||
sample = prop->sampleRate();
|
||||
channels = prop->channels();
|
||||
|
||||
make_lenstr();
|
||||
format_tags();
|
||||
}
|
||||
|
||||
TrackTag::TrackTag(InFile &in)
|
||||
{
|
||||
in >> inode;
|
||||
in >> filepath;
|
||||
in >> title;
|
||||
in >> artist;
|
||||
in >> album;
|
||||
in >> comment;
|
||||
in >> genre;
|
||||
in >> lenstr;
|
||||
in >> year;
|
||||
in >> track;
|
||||
in >> length;
|
||||
in >> bitrate;
|
||||
in >> sample;
|
||||
in >> channels;
|
||||
format_tags();
|
||||
}
|
||||
|
||||
TrackTag::~TrackTag()
|
||||
{
|
||||
}
|
||||
|
||||
void TrackTag::save(OutFile &out)
|
||||
{
|
||||
out << inode;
|
||||
out << filepath;
|
||||
out << title;
|
||||
out << artist;
|
||||
out << album;
|
||||
out << comment;
|
||||
out << genre;
|
||||
out << lenstr;
|
||||
out << year;
|
||||
out << track;
|
||||
out << length;
|
||||
out << bitrate;
|
||||
out << sample;
|
||||
out << channels << "\n";
|
||||
}
|
||||
|
||||
void TrackTag::make_lenstr()
|
||||
{
|
||||
int minutes;
|
||||
int seconds;
|
||||
stringstream stream;
|
||||
|
||||
/* Convert length into mm:ss format */
|
||||
minutes = length / 60;
|
||||
seconds = length - (minutes * 60);
|
||||
stream << minutes << ":";
|
||||
if (seconds < 10)
|
||||
stream << "0";
|
||||
stream << seconds;
|
||||
lenstr = stream.str();
|
||||
}
|
||||
|
||||
void TrackTag::format_tags()
|
||||
{
|
||||
libsaria::format_text(title, title_words);
|
||||
libsaria::format_text(artist, artist_words);
|
||||
libsaria::format_text(album, album_words);
|
||||
}
|
||||
|
||||
sid_t TrackTag::get_songid()
|
||||
{
|
||||
return inode;
|
||||
}
|
||||
|
||||
unsigned int TrackTag::get_track()
|
||||
{
|
||||
return track;
|
||||
}
|
||||
|
||||
string TrackTag::get_title()
|
||||
{
|
||||
return title;
|
||||
}
|
||||
|
||||
string TrackTag::get_lenstr()
|
||||
{
|
||||
return lenstr;
|
||||
}
|
||||
|
||||
string TrackTag::get_artist()
|
||||
{
|
||||
return artist;
|
||||
}
|
||||
|
||||
string TrackTag::get_album()
|
||||
{
|
||||
return album;
|
||||
}
|
||||
|
||||
unsigned int TrackTag::get_year()
|
||||
{
|
||||
return year;
|
||||
}
|
||||
|
||||
string TrackTag::get_filepath()
|
||||
{
|
||||
return filepath;
|
||||
}
|
||||
|
||||
list<string> *TrackTag::get_title_words()
|
||||
{
|
||||
return &title_words;
|
||||
}
|
||||
|
||||
list<string> *TrackTag::get_artist_words()
|
||||
{
|
||||
return &artist_words;
|
||||
}
|
||||
|
||||
list<string> *TrackTag::get_album_words()
|
||||
{
|
||||
return &album_words;
|
||||
}
|
|
@ -31,8 +31,7 @@ namespace libsaria
|
|||
deque<sid_t>::iterator it;
|
||||
for (it = playqueue.begin(); it != playqueue.end(); it++)
|
||||
{
|
||||
TrackTag *tag = libsaria::library::get_info(*it);
|
||||
Track track = Track(tag);
|
||||
libsaria::Track *track = libsaria::library::get_info(*it);
|
||||
model->insert(track);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,66 +0,0 @@
|
|||
|
||||
#include <libsaria/track.h>
|
||||
#include <libsaria/tags.h>
|
||||
|
||||
Track::Track()
|
||||
{
|
||||
tags = NULL;
|
||||
}
|
||||
|
||||
Track::Track(TrackTag *tag)
|
||||
{
|
||||
tags = tag;
|
||||
}
|
||||
|
||||
Track::~Track()
|
||||
{
|
||||
}
|
||||
|
||||
sid_t Track::get_songid()
|
||||
{
|
||||
if (tags)
|
||||
return tags->get_songid();
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned int Track::get_track()
|
||||
{
|
||||
if (tags)
|
||||
return tags->get_track();
|
||||
return 0;
|
||||
}
|
||||
|
||||
string Track::get_title()
|
||||
{
|
||||
if (tags)
|
||||
return tags->get_title();
|
||||
return "";
|
||||
}
|
||||
|
||||
string Track::get_lenstr()
|
||||
{
|
||||
if (tags)
|
||||
return tags->get_lenstr();
|
||||
return "";
|
||||
}
|
||||
|
||||
string Track::get_artist()
|
||||
{
|
||||
if (tags)
|
||||
return tags->get_artist();
|
||||
return "";
|
||||
}
|
||||
|
||||
string Track::get_album()
|
||||
{
|
||||
if (tags)
|
||||
return tags->get_album();
|
||||
return "";
|
||||
}
|
||||
|
||||
unsigned int Track::get_year()
|
||||
{
|
||||
if (tags)
|
||||
return tags->get_year();
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
|
||||
#include <libsaria/track.h>
|
||||
|
||||
namespace libsaria
|
||||
{
|
||||
|
||||
string Track::get_filepath()
|
||||
{
|
||||
return filepath;
|
||||
}
|
||||
|
||||
string Track::get_title()
|
||||
{
|
||||
return title;
|
||||
}
|
||||
|
||||
string Track::get_artist()
|
||||
{
|
||||
return artist;
|
||||
}
|
||||
|
||||
string Track::get_album()
|
||||
{
|
||||
return album;
|
||||
}
|
||||
|
||||
string Track::get_comment()
|
||||
{
|
||||
return comment;
|
||||
}
|
||||
|
||||
string Track::get_genre()
|
||||
{
|
||||
return genre;
|
||||
}
|
||||
|
||||
string Track::get_lenstr()
|
||||
{
|
||||
return lenstr;
|
||||
}
|
||||
|
||||
unsigned int Track::get_year()
|
||||
{
|
||||
return year;
|
||||
}
|
||||
|
||||
unsigned int Track::get_track()
|
||||
{
|
||||
return track;
|
||||
}
|
||||
|
||||
int Track::get_length()
|
||||
{
|
||||
return length;
|
||||
}
|
||||
|
||||
int Track::get_bitrate()
|
||||
{
|
||||
return bitrate;
|
||||
}
|
||||
|
||||
int Track::get_channels()
|
||||
{
|
||||
return channels;
|
||||
}
|
||||
|
||||
sid_t Track::get_songid()
|
||||
{
|
||||
return songid;
|
||||
}
|
||||
|
||||
} /* Namespace: libsaria */
|
|
@ -0,0 +1,104 @@
|
|||
|
||||
#include <libsaria/track.h>
|
||||
|
||||
#include <taglib/tag.h>
|
||||
#include <taglib/fileref.h>
|
||||
#include <sstream>
|
||||
|
||||
namespace libsaria
|
||||
{
|
||||
|
||||
Track::Track()
|
||||
{
|
||||
}
|
||||
|
||||
Track::Track(string file, sid_t sid)
|
||||
{
|
||||
TagLib::Tag *tag;
|
||||
TagLib::AudioProperties *prop;
|
||||
TagLib::FileRef ref(file.c_str());
|
||||
|
||||
if (ref.isNull())
|
||||
throw "Error tagging file: " + file;
|
||||
|
||||
filepath = file;
|
||||
songid = sid;
|
||||
|
||||
/* Extract tags */
|
||||
tag = ref.tag();
|
||||
title = tag->title().to8Bit(true);
|
||||
artist = tag->artist().to8Bit(true);
|
||||
album = tag->album().to8Bit(true);
|
||||
comment = tag->comment().to8Bit(true);
|
||||
genre = tag->genre().to8Bit(true);
|
||||
year = tag->year();
|
||||
track = tag->track();
|
||||
|
||||
/* Extract audio properties */
|
||||
prop = ref.audioProperties();
|
||||
length = prop->length();
|
||||
bitrate = prop->bitrate();
|
||||
sample = prop->sampleRate();
|
||||
channels = prop->channels();
|
||||
|
||||
make_lenstr();
|
||||
}
|
||||
|
||||
Track::Track(InFile &in)
|
||||
{
|
||||
in >> songid;
|
||||
in >> filepath;
|
||||
in >> title;
|
||||
in >> artist;
|
||||
in >> album;
|
||||
in >> comment;
|
||||
in >> genre;
|
||||
in >> lenstr;
|
||||
in >> year;
|
||||
in >> track;
|
||||
in >> length;
|
||||
in >> bitrate;
|
||||
in >> sample;
|
||||
in >> channels;
|
||||
}
|
||||
|
||||
Track::~Track()
|
||||
{
|
||||
}
|
||||
|
||||
void Track::save(OutFile &out)
|
||||
{
|
||||
out << songid;
|
||||
out << filepath;
|
||||
out << title;
|
||||
out << artist;
|
||||
out << album;
|
||||
out << comment;
|
||||
out << genre;
|
||||
out << lenstr;
|
||||
out << year;
|
||||
out << track;
|
||||
out << length;
|
||||
out << bitrate;
|
||||
out << sample;
|
||||
out << channels;
|
||||
out << "\n";
|
||||
}
|
||||
|
||||
void Track::make_lenstr()
|
||||
{
|
||||
int minutes;
|
||||
int seconds;
|
||||
stringstream stream;
|
||||
|
||||
/* Convert length into mm:ss format */
|
||||
minutes = length / 60;
|
||||
seconds = length - (minutes * 60);
|
||||
stream << minutes << ":";
|
||||
if (seconds < 10)
|
||||
stream << "0";
|
||||
stream << seconds;
|
||||
lenstr = stream.str();
|
||||
}
|
||||
|
||||
} /* Namespace: libsaria */
|
Loading…
Reference in New Issue