change internal storing of Song info (much less memory consumption)
This commit is contained in:
251
src/song.cpp
251
src/song.cpp
@@ -47,152 +47,263 @@ void DefineEmptyTags()
|
||||
}
|
||||
}
|
||||
|
||||
Song::Song(mpd_Song *s) : itsHash(0),
|
||||
itsLength(s->time),
|
||||
itsPosition(s->pos),
|
||||
itsID(s->id),
|
||||
itsGetEmptyFields(0)
|
||||
Song::Song(mpd_Song *s, bool copy_ptr) : itsSong(s),
|
||||
isStream(0),
|
||||
itsHash(0),
|
||||
copyPtr(copy_ptr),
|
||||
itsGetEmptyFields(0)
|
||||
{
|
||||
s->file ? itsFile = s->file : itsFile = "";
|
||||
s->artist ? itsArtist = s->artist : itsArtist = "";
|
||||
s->title ? itsTitle = s->title : itsTitle = "";
|
||||
s->album ? itsAlbum = s->album : itsAlbum = "";
|
||||
s->track ? itsTrack = IntoStr(atoi(s->track)) : itsTrack = "";
|
||||
//s->name ? itsName = s->name : itsName = "";
|
||||
s->date ? itsYear = s->date : itsYear = "";
|
||||
s->genre ? itsGenre = s->genre : itsGenre = "";
|
||||
s->composer ? itsComposer = s->composer : itsComposer = "";
|
||||
s->performer ? itsPerformer = s->performer : itsPerformer = "";
|
||||
s->disc ? itsDisc = s->disc : itsDisc = "";
|
||||
s->comment ? itsComment = s->comment : itsComment = "";
|
||||
string itsFile = itsSong->file ? itsSong->file : "";
|
||||
|
||||
int i = itsFile.find_last_of("/");
|
||||
itsSlash = itsFile.find_last_of("/");
|
||||
|
||||
if (itsFile.substr(0, 7) == "http://")
|
||||
{
|
||||
itsShortName = itsFile;
|
||||
}
|
||||
else if (i != string::npos)
|
||||
{
|
||||
itsDirectory = itsFile.substr(0, i);
|
||||
itsShortName = itsFile.substr(i+1);
|
||||
}
|
||||
else
|
||||
{
|
||||
itsDirectory = "/";
|
||||
itsShortName = itsFile;
|
||||
}
|
||||
isStream = 1;
|
||||
|
||||
// generate pseudo-hash
|
||||
i = 0;
|
||||
for (string::const_iterator it = itsFile.begin(); it != itsFile.end(); it++, i++)
|
||||
for (int i = 0; i < strlen(itsSong->file); i++)
|
||||
{
|
||||
itsHash += *it;
|
||||
itsHash += itsSong->file[i];
|
||||
if (i%2)
|
||||
itsHash *= *it;
|
||||
itsHash *= itsSong->file[i];
|
||||
}
|
||||
}
|
||||
|
||||
Song::Song(const Song &s) : itsSong(0),
|
||||
itsNewName(s.itsNewName),
|
||||
itsSlash(s.itsSlash),
|
||||
itsHash(s.itsHash),
|
||||
copyPtr(s.copyPtr),
|
||||
isStream(s.isStream),
|
||||
itsGetEmptyFields(s.itsGetEmptyFields)
|
||||
{
|
||||
itsSong = s.copyPtr ? s.itsSong : mpd_songDup(s.itsSong);
|
||||
}
|
||||
|
||||
Song::~Song()
|
||||
{
|
||||
if (itsSong)
|
||||
mpd_freeSong(itsSong);
|
||||
}
|
||||
|
||||
string Song::GetLength() const
|
||||
{
|
||||
if (!itsLength)
|
||||
if (!itsSong->time)
|
||||
return "-:--";
|
||||
return ShowTime(itsLength);
|
||||
return ShowTime(itsSong->time);
|
||||
}
|
||||
|
||||
void Song::Clear()
|
||||
{
|
||||
itsFile.clear();
|
||||
itsShortName.clear();
|
||||
itsDirectory.clear();
|
||||
itsArtist.clear();
|
||||
itsTitle.clear();
|
||||
itsAlbum.clear();
|
||||
itsTrack.clear();
|
||||
//itsName.clear();
|
||||
itsYear.clear();
|
||||
itsGenre.clear();
|
||||
itsComposer.clear();
|
||||
itsPerformer.clear();
|
||||
itsDisc.clear();
|
||||
itsComment.clear();
|
||||
itsLength = 0;
|
||||
itsPosition = 0;
|
||||
itsID = 0;
|
||||
if (itsSong)
|
||||
mpd_freeSong(itsSong);
|
||||
itsSong = mpd_newSong();
|
||||
itsNewName.clear();
|
||||
itsSlash = 0;
|
||||
itsHash = 0;
|
||||
copyPtr = 0;
|
||||
itsGetEmptyFields = 0;
|
||||
}
|
||||
|
||||
bool Song::Empty() const
|
||||
{
|
||||
return itsFile.empty() && itsShortName.empty() && itsArtist.empty() && itsTitle.empty() && itsAlbum.empty() && itsTrack.empty() && itsYear.empty() && itsGenre.empty() && itsComposer.empty() && itsPerformer.empty() && itsDisc.empty() && itsComment.empty();
|
||||
return !itsSong || (!itsSong->file && !itsSong->title && !itsSong->artist && !itsSong->album && !itsSong->date && !itsSong->track && !itsSong->genre && !itsSong->composer && !itsSong->performer && !itsSong->disc && !itsSong->comment);
|
||||
}
|
||||
|
||||
string Song::GetFile() const
|
||||
{
|
||||
return itsFile.empty() ? (itsGetEmptyFields ? "" : EMPTY_TAG) : itsFile;
|
||||
return !itsSong->file ? (itsGetEmptyFields ? "" : EMPTY_TAG) : itsSong->file;
|
||||
}
|
||||
|
||||
string Song::GetShortFilename() const
|
||||
{
|
||||
return itsShortName.empty() ? (itsGetEmptyFields ? "" : EMPTY_TAG) : itsShortName;
|
||||
return !itsSong->file ? (itsGetEmptyFields ? "" : EMPTY_TAG) : (itsSlash != string::npos && !isStream ? string(itsSong->file).substr(itsSlash+1) : itsSong->file);
|
||||
}
|
||||
|
||||
string Song::GetDirectory() const
|
||||
{
|
||||
return itsDirectory.empty() ? (itsGetEmptyFields ? "" : EMPTY_TAG) : itsDirectory;
|
||||
return !itsSong->file || isStream ? (itsGetEmptyFields ? "" : EMPTY_TAG) : itsSlash != string::npos ? string(itsSong->file).substr(0, itsSlash) : "/";
|
||||
}
|
||||
|
||||
string Song::GetArtist() const
|
||||
{
|
||||
return itsArtist.empty() ? (itsGetEmptyFields ? "" : UNKNOWN_ARTIST) : itsArtist;
|
||||
return !itsSong->artist ? (itsGetEmptyFields ? "" : UNKNOWN_ARTIST) : itsSong->artist;
|
||||
}
|
||||
|
||||
string Song::GetTitle() const
|
||||
{
|
||||
return itsTitle.empty() ? (itsGetEmptyFields ? "" : UNKNOWN_TITLE) : itsTitle;
|
||||
return !itsSong->title ? (itsGetEmptyFields ? "" : UNKNOWN_TITLE) : itsSong->title;
|
||||
}
|
||||
|
||||
string Song::GetAlbum() const
|
||||
{
|
||||
return itsAlbum.empty() ? (itsGetEmptyFields ? "" : UNKNOWN_ALBUM) : itsAlbum;
|
||||
return !itsSong->album ? (itsGetEmptyFields ? "" : UNKNOWN_ALBUM) : itsSong->album;
|
||||
}
|
||||
|
||||
string Song::GetTrack() const
|
||||
{
|
||||
return itsTrack.empty() ? (itsGetEmptyFields ? "" : EMPTY_TAG) : (StrToInt(itsTrack) < 10 && itsTrack[0] != '0' ? "0"+itsTrack : itsTrack);
|
||||
return !itsSong->track ? (itsGetEmptyFields ? "" : EMPTY_TAG) : (StrToInt(itsSong->track) < 10 && itsSong->track[0] != '0' ? "0"+string(itsSong->track) : itsSong->track);
|
||||
}
|
||||
|
||||
string Song::GetYear() const
|
||||
{
|
||||
return itsYear.empty() ? (itsGetEmptyFields ? "" : EMPTY_TAG) : itsYear;
|
||||
return !itsSong->date ? (itsGetEmptyFields ? "" : EMPTY_TAG) : itsSong->date;
|
||||
}
|
||||
|
||||
string Song::GetGenre() const
|
||||
{
|
||||
return itsGenre.empty() ? (itsGetEmptyFields ? "" : EMPTY_TAG) : itsGenre;
|
||||
return !itsSong->genre ? (itsGetEmptyFields ? "" : EMPTY_TAG) : itsSong->genre;
|
||||
}
|
||||
|
||||
string Song::GetComposer() const
|
||||
{
|
||||
return itsComposer.empty() ? (itsGetEmptyFields ? "" : EMPTY_TAG) : itsComposer;
|
||||
return !itsSong->composer ? (itsGetEmptyFields ? "" : EMPTY_TAG) : itsSong->composer;
|
||||
}
|
||||
|
||||
string Song::GetPerformer() const
|
||||
{
|
||||
return itsPerformer.empty() ? (itsGetEmptyFields ? "" : EMPTY_TAG) : itsPerformer;
|
||||
return !itsSong->performer ? (itsGetEmptyFields ? "" : EMPTY_TAG) : itsSong->performer;
|
||||
}
|
||||
|
||||
string Song::GetDisc() const
|
||||
{
|
||||
return itsDisc.empty() ? (itsGetEmptyFields ? "" : EMPTY_TAG) : itsDisc;
|
||||
return !itsSong->disc ? (itsGetEmptyFields ? "" : EMPTY_TAG) : itsSong->disc;
|
||||
}
|
||||
|
||||
string Song::GetComment() const
|
||||
{
|
||||
return itsComment.empty() ? (itsGetEmptyFields ? "" : EMPTY_TAG) : itsComment;
|
||||
return !itsSong->comment ? (itsGetEmptyFields ? "" : EMPTY_TAG) : itsSong->comment;
|
||||
}
|
||||
|
||||
void Song::SetFile(const string &str)
|
||||
{
|
||||
if (itsSong->file)
|
||||
str_pool_put(itsSong->file);
|
||||
itsSong->file = str.empty() ? 0 : str_pool_dup(str.c_str());
|
||||
}
|
||||
|
||||
void Song::SetArtist(const string &str)
|
||||
{
|
||||
if (itsSong->artist)
|
||||
str_pool_put(itsSong->artist);
|
||||
itsSong->artist = str.empty() ? 0 : str_pool_dup(str.c_str());
|
||||
}
|
||||
|
||||
void Song::SetTitle(const string &str)
|
||||
{
|
||||
if (itsSong->title)
|
||||
str_pool_put(itsSong->title);
|
||||
itsSong->title = str.empty() ? 0 : str_pool_dup(str.c_str());
|
||||
}
|
||||
|
||||
void Song::SetAlbum(const string &str)
|
||||
{
|
||||
if (itsSong->album)
|
||||
str_pool_put(itsSong->album);
|
||||
itsSong->album = str.empty() ? 0 : str_pool_dup(str.c_str());
|
||||
}
|
||||
|
||||
void Song::SetTrack(const string &str)
|
||||
{
|
||||
if (itsSong->track)
|
||||
str_pool_put(itsSong->track);
|
||||
itsSong->track = str.empty() ? 0 : str_pool_dup(IntoStr(StrToInt(str)).c_str());
|
||||
}
|
||||
|
||||
void Song::SetTrack(int track)
|
||||
{
|
||||
if (itsSong->track)
|
||||
str_pool_put(itsSong->track);
|
||||
itsSong->track = str_pool_dup(IntoStr(track).c_str());
|
||||
}
|
||||
|
||||
void Song::SetYear(const string &str)
|
||||
{
|
||||
if (itsSong->date)
|
||||
str_pool_put(itsSong->date);
|
||||
itsSong->date = str.empty() ? 0 : str_pool_dup(IntoStr(StrToInt(str)).c_str());
|
||||
}
|
||||
|
||||
void Song::SetYear(int year)
|
||||
{
|
||||
if (itsSong->date)
|
||||
str_pool_put(itsSong->date);
|
||||
itsSong->date = str_pool_dup(IntoStr(year).c_str());
|
||||
}
|
||||
|
||||
void Song::SetGenre(const string &str)
|
||||
{
|
||||
if (itsSong->genre)
|
||||
str_pool_put(itsSong->genre);
|
||||
itsSong->genre = str.empty() ? 0 : str_pool_dup(str.c_str());
|
||||
}
|
||||
|
||||
void Song::SetComment(const string &str)
|
||||
{
|
||||
if (itsSong->comment)
|
||||
str_pool_put(itsSong->comment);
|
||||
itsSong->comment = str.empty() ? 0 : str_pool_dup(str.c_str());
|
||||
}
|
||||
|
||||
void Song::SetPosition(int pos)
|
||||
{
|
||||
itsSong->pos = pos;
|
||||
}
|
||||
|
||||
Song & Song::operator=(const Song &s)
|
||||
{
|
||||
if (this == &s)
|
||||
return *this;
|
||||
if (itsSong)
|
||||
mpd_freeSong(itsSong);
|
||||
itsSong = s.copyPtr ? s.itsSong : mpd_songDup(s.itsSong);
|
||||
itsNewName = s.itsNewName;
|
||||
itsSlash = s.itsSlash;
|
||||
itsHash = s.itsHash;
|
||||
copyPtr = s.copyPtr;
|
||||
isStream = s.isStream;
|
||||
itsGetEmptyFields = s.itsGetEmptyFields;
|
||||
}
|
||||
|
||||
bool Song::operator==(const Song &s) const
|
||||
{
|
||||
return itsFile == s.itsFile && itsArtist == s.itsArtist && itsTitle == s.itsTitle && itsAlbum == s.itsAlbum && itsTrack == s.itsTrack && itsYear == s.itsYear && itsGenre == s.itsGenre && itsComposer == s.itsComposer && itsPerformer == s.itsPerformer && itsDisc == s.itsDisc && itsComment == s.itsComment && itsHash == s.itsHash && itsLength && s.itsLength && itsPosition == s.itsPosition && itsID == s.itsID;
|
||||
return (itsSong->file && s.itsSong->file
|
||||
? strcmp(itsSong->file, s.itsSong->file) == 0
|
||||
: !(itsSong->file || s.itsSong->file))
|
||||
&& (itsSong->title && s.itsSong->title
|
||||
? strcmp(itsSong->title, s.itsSong->title) == 0
|
||||
: !(itsSong->title || s.itsSong->title))
|
||||
&& (itsSong->artist && s.itsSong->artist
|
||||
? strcmp(itsSong->artist, s.itsSong->artist) == 0
|
||||
: !(itsSong->artist || s.itsSong->artist))
|
||||
&& (itsSong->album && s.itsSong->album
|
||||
? strcmp(itsSong->album, s.itsSong->album) == 0
|
||||
: !(itsSong->album || s.itsSong->album))
|
||||
&& (itsSong->track && s.itsSong->track
|
||||
? strcmp(itsSong->track, s.itsSong->track) == 0
|
||||
: !(itsSong->track || s.itsSong->track))
|
||||
&& (itsSong->date && s.itsSong->date
|
||||
? strcmp(itsSong->date, s.itsSong->date) == 0
|
||||
: !(itsSong->date || s.itsSong->date))
|
||||
&& (itsSong->genre && s.itsSong->genre
|
||||
? strcmp(itsSong->genre, s.itsSong->genre) == 0
|
||||
: !(itsSong->genre || s.itsSong->genre))
|
||||
&& (itsSong->composer && s.itsSong->composer
|
||||
? strcmp(itsSong->composer, s.itsSong->composer) == 0
|
||||
: !(itsSong->composer || s.itsSong->composer))
|
||||
&& (itsSong->performer && s.itsSong->performer
|
||||
? strcmp(itsSong->performer, s.itsSong->performer) == 0
|
||||
: !(itsSong->performer || s.itsSong->performer))
|
||||
&& (itsSong->disc && s.itsSong->disc
|
||||
? strcmp(itsSong->disc, s.itsSong->disc) == 0
|
||||
: !(itsSong->disc || s.itsSong->disc))
|
||||
&& (itsSong->comment && s.itsSong->comment
|
||||
? strcmp(itsSong->comment, s.itsSong->comment) == 0
|
||||
: !(itsSong->comment || s.itsSong->comment))
|
||||
&& itsSong->time == s.itsSong->time
|
||||
&& itsSong->pos == s.itsSong->pos
|
||||
&& itsSong->id == s.itsSong->id
|
||||
&& itsHash == itsHash;
|
||||
}
|
||||
|
||||
bool Song::operator!=(const Song &s) const
|
||||
@@ -202,7 +313,7 @@ bool Song::operator!=(const Song &s) const
|
||||
|
||||
bool Song::operator<(const Song &s) const
|
||||
{
|
||||
return itsPosition < s.itsPosition;
|
||||
return itsSong->pos < s.itsSong->pos;
|
||||
}
|
||||
|
||||
string Song::ShowTime(int length)
|
||||
|
||||
Reference in New Issue
Block a user