Track: Remove old constructor and tag() function

The new constructor covers these cases without needing to do taglib
stuff inside the Track class.

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2014-11-28 09:46:22 -05:00
parent a2b3ca1292
commit de1b5fcef3
3 changed files with 24 additions and 69 deletions

View File

@ -20,13 +20,6 @@ Database<Track> track_db("track.db", false);
*
*/
Track :: Track(const std::string &f, Library *library)
: _album(NULL), _artist(NULL), _genre(NULL), _library(library),
_count(0), _path(f.substr(library->primary_key().size() + 1))
{
library->inc_size();
}
void Track :: read(File &f)
{
unsigned int library_id, artist_id, album_id, genre_id;
@ -59,50 +52,6 @@ void Track :: write(File &f)
f << std::endl << _path << std::endl;
}
static inline const std::string format_tag(const TagLib::String &str)
{
return str.stripWhiteSpace().to8Bit(true);
}
template <class T>
static T *find_or_insert(const T &tag, Database<T> &db)
{
T *ret = db.find(tag.primary_key());
if (!ret)
ret = db.insert(tag);
return ret;
}
bool Track :: tag()
{
TagLib :: Tag *tag;
TagLib :: AudioProperties *audio;
TagLib :: FileRef ref(path().c_str(), true, TagLib::AudioProperties::Fast);
_library->inc_size();
if (ref.isNull()) {
print("WARNING: Could not read tags for file %s\n", path().c_str());
return false;
}
tag = ref.tag();
audio = ref.audioProperties();
_artist = tags :: get_artist(format_tag(tag->artist()));
_album = tags :: get_album(format_tag(tag->album()), tag->year());
_genre = tags :: get_genre(format_tag(tag->genre()));
_track = tag->track();
_length = audio->length();
//_title = format_tag(tag->title());
//title_lower = filter :: add(title, index());
filter :: add(_artist->name(), index());
filter :: add(_album->name(), index());
return true;
}
/*
* Returns:
@ -181,11 +130,28 @@ void tagdb :: commit()
Track *tagdb :: add_track(const std::string &filepath, Library *library)
{
Track *track = track_db.insert(Track(filepath, library));
if (track && !track->tag()) {
remove_track(track->index());
track = NULL;
Track *track;
TagLib :: Tag *tag;
TagLib :: AudioProperties *audio;
TagLib :: FileRef ref(filepath.c_str(), true, TagLib::AudioProperties::Fast);
if (ref.isNull()) {
print("WARNING: Could not read tags for file %s\n", filepath.c_str());
return NULL;
}
tag = ref.tag();
audio = ref.audioProperties();
track = track_db.insert(Track(
tags :: get_album(tag->album().stripWhiteSpace().to8Bit(true), tag->year()),
tags :: get_artist(tag->artist().stripWhiteSpace().to8Bit(true)),
tags :: get_genre(tag->genre().stripWhiteSpace().to8Bit(true)),
library, filepath,
tag->title().stripWhiteSpace().to8Bit(true),
audio->length(), tag->track())
);
return track;
}

View File

@ -22,6 +22,9 @@ Track :: Track(Album *album, Artist *artist, Genre *genre, Library *library,
_count(0), _length(length), _track(track),
_path(filepath.substr(library->primary_key().size() + 1))
{
//filter :: add(name(), index());
//filter :: add(_artist->name(), index());
//filter :: add(_album->name(), index());
_library->inc_size();
}

View File

@ -79,13 +79,6 @@ public:
Track(Album *, Artist *, Genre *, Library *, const std::string &,
const std::string &, unsigned int, unsigned int);
/**
* Track constructor
* @param filepath Filepath of the track
* @param library Library containing the track
*/
Track(const std::string &, Library *);
/** Track destructor */
~Track();
@ -137,13 +130,6 @@ public:
*/
void write(File &);
/**
* Read the tags associated with this track
* @return True on success
*/
bool tag();
/**
* Compare two tracks based on a specific field.
* @param rhs The other track to compare.