fix broken compilation due to lack of setters for mpd_song
This commit is contained in:
@@ -82,8 +82,7 @@ namespace
|
|||||||
*outbuf = 0;
|
*outbuf = 0;
|
||||||
if (delete_old)
|
if (delete_old)
|
||||||
delete [] instart;
|
delete [] instart;
|
||||||
inbuf = strdup(outstart);
|
inbuf = outstart;
|
||||||
delete [] outstart;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -69,8 +69,6 @@ std::string IntoStr(mpd_tag_type tag) // this is only for left column's title in
|
|||||||
return "Comment";
|
return "Comment";
|
||||||
case MPD_TAG_DISC:
|
case MPD_TAG_DISC:
|
||||||
return "Disc";
|
return "Disc";
|
||||||
case MPD_TAG_FILE:
|
|
||||||
return "Filename";
|
|
||||||
default:
|
default:
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
@@ -170,8 +168,6 @@ MPD::Song::SetFunction IntoSetFunction(mpd_tag_type tag)
|
|||||||
return &MPD::Song::SetComment;
|
return &MPD::Song::SetComment;
|
||||||
case MPD_TAG_DISC:
|
case MPD_TAG_DISC:
|
||||||
return &MPD::Song::SetDisc;
|
return &MPD::Song::SetDisc;
|
||||||
case MPD_TAG_FILE:
|
|
||||||
return &MPD::Song::SetNewName;
|
|
||||||
default:
|
default:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -197,13 +197,14 @@ void MediaLibrary::Update()
|
|||||||
// <mpd-0.14 doesn't support searching for empty tag
|
// <mpd-0.14 doesn't support searching for empty tag
|
||||||
if (Mpd.Version() > 13)
|
if (Mpd.Version() > 13)
|
||||||
{
|
{
|
||||||
TagList noalbum_list;
|
SongList noalbum_list;
|
||||||
Mpd.StartFieldSearch(MPD_TAG_FILE);
|
Mpd.StartSearch(1);
|
||||||
Mpd.AddSearch(Config.media_lib_primary_tag, Artists->Current());
|
Mpd.AddSearch(Config.media_lib_primary_tag, Artists->Current());
|
||||||
Mpd.AddSearch(MPD_TAG_ALBUM, "");
|
Mpd.AddSearch(MPD_TAG_ALBUM, "");
|
||||||
Mpd.CommitSearch(noalbum_list);
|
Mpd.CommitSearch(noalbum_list);
|
||||||
if (!noalbum_list.empty())
|
if (!noalbum_list.empty())
|
||||||
Albums->AddOption(std::make_pair("<no album>", SearchConstraints("", "")));
|
Albums->AddOption(std::make_pair("<no album>", SearchConstraints("", "")));
|
||||||
|
FreeSongList(noalbum_list);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (TagList::const_iterator it = list.begin(); it != list.end(); ++it)
|
for (TagList::const_iterator it = list.begin(); it != list.end(); ++it)
|
||||||
|
|||||||
@@ -467,7 +467,7 @@ bool Connection::AddRandomSongs(size_t number)
|
|||||||
TagList files;
|
TagList files;
|
||||||
|
|
||||||
mpd_send_list_all(itsConnection, "/");
|
mpd_send_list_all(itsConnection, "/");
|
||||||
while (mpd_pair *item = mpd_recv_pair_tag(itsConnection, MPD_TAG_FILE))
|
while (mpd_pair *item = mpd_recv_pair_named(itsConnection, "file"))
|
||||||
{
|
{
|
||||||
files.push_back(item->value);
|
files.push_back(item->value);
|
||||||
mpd_return_pair(itsConnection, item);
|
mpd_return_pair(itsConnection, item);
|
||||||
@@ -598,7 +598,7 @@ void Connection::GetAlbums(const std::string &artist, TagList &v) const
|
|||||||
{
|
{
|
||||||
mpd_search_db_tags(itsConnection, MPD_TAG_ALBUM);
|
mpd_search_db_tags(itsConnection, MPD_TAG_ALBUM);
|
||||||
if (!artist.empty())
|
if (!artist.empty())
|
||||||
mpd_search_add_constraint(itsConnection, MPD_TAG_ARTIST, artist.c_str());
|
mpd_search_add_tag_constraint(itsConnection, MPD_OPERATOR_DEFAULT, MPD_TAG_ARTIST, artist.c_str());
|
||||||
mpd_search_commit(itsConnection);
|
mpd_search_commit(itsConnection);
|
||||||
while (mpd_pair *item = mpd_recv_pair_tag(itsConnection, MPD_TAG_ALBUM))
|
while (mpd_pair *item = mpd_recv_pair_tag(itsConnection, MPD_TAG_ALBUM))
|
||||||
{
|
{
|
||||||
@@ -631,7 +631,7 @@ void Connection::AddSearch(mpd_tag_type item, const std::string &str) const
|
|||||||
if (Version() < 14 && str.empty())
|
if (Version() < 14 && str.empty())
|
||||||
return;
|
return;
|
||||||
if (isConnected)
|
if (isConnected)
|
||||||
mpd_search_add_constraint(itsConnection, item, str.c_str());
|
mpd_search_add_tag_constraint(itsConnection, MPD_OPERATOR_DEFAULT, item, str.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Connection::CommitSearch(SongList &v) const
|
void Connection::CommitSearch(SongList &v) const
|
||||||
|
|||||||
178
src/song.cpp
178
src/song.cpp
@@ -45,6 +45,7 @@ namespace
|
|||||||
|
|
||||||
MPD::Song::Song(mpd_song *s, bool copy_ptr) : itsSong(s),
|
MPD::Song::Song(mpd_song *s, bool copy_ptr) : itsSong(s),
|
||||||
itsFile(0),
|
itsFile(0),
|
||||||
|
itsTags(0),
|
||||||
itsSlash(std::string::npos),
|
itsSlash(std::string::npos),
|
||||||
itsHash(0),
|
itsHash(0),
|
||||||
copyPtr(copy_ptr),
|
copyPtr(copy_ptr),
|
||||||
@@ -54,15 +55,15 @@ MPD::Song::Song(mpd_song *s, bool copy_ptr) : itsSong(s),
|
|||||||
SetHashAndSlash();
|
SetHashAndSlash();
|
||||||
}
|
}
|
||||||
|
|
||||||
MPD::Song::Song(const Song &s) : itsSong(0),
|
MPD::Song::Song(const Song &s) : itsSong(s.copyPtr ? s.itsSong : mpd_song_dup(s.itsSong)),
|
||||||
itsFile(s.itsFile ? strdup(s.itsFile) : 0),
|
itsFile(s.itsFile ? strdup(s.itsFile) : 0),
|
||||||
|
itsTags(s.itsTags ? new TagMap(*s.itsTags) : 0),
|
||||||
itsNewName(s.itsNewName),
|
itsNewName(s.itsNewName),
|
||||||
itsSlash(s.itsSlash),
|
itsSlash(s.itsSlash),
|
||||||
itsHash(s.itsHash),
|
itsHash(s.itsHash),
|
||||||
copyPtr(s.copyPtr),
|
copyPtr(s.copyPtr),
|
||||||
isLocalised(s.isLocalised)
|
isLocalised(s.isLocalised)
|
||||||
{
|
{
|
||||||
itsSong = s.copyPtr ? s.itsSong : mpd_song_dup(s.itsSong);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MPD::Song::~Song()
|
MPD::Song::~Song()
|
||||||
@@ -70,6 +71,7 @@ MPD::Song::~Song()
|
|||||||
if (itsSong)
|
if (itsSong)
|
||||||
mpd_song_free(itsSong);
|
mpd_song_free(itsSong);
|
||||||
delete [] itsFile;
|
delete [] itsFile;
|
||||||
|
delete itsTags;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string MPD::Song::GetLength() const
|
std::string MPD::Song::GetLength() const
|
||||||
@@ -93,13 +95,16 @@ void MPD::Song::Localize()
|
|||||||
}
|
}
|
||||||
for (unsigned t = MPD_TAG_ARTIST; t <= MPD_TAG_DISC; ++t)
|
for (unsigned t = MPD_TAG_ARTIST; t <= MPD_TAG_DISC; ++t)
|
||||||
{
|
{
|
||||||
tag = conv_tag = mpd_song_get_tag(itsSong, mpd_tag_type(t), 0);
|
unsigned pos = 0;
|
||||||
utf_to_locale(conv_tag, 0);
|
for (; (tag = mpd_song_get_tag(itsSong, mpd_tag_type(t), pos)); ++pos)
|
||||||
if (tag != conv_tag) // tag has been converted
|
|
||||||
{
|
{
|
||||||
mpd_song_clear_tag(itsSong, mpd_tag_type(t));
|
conv_tag = tag;
|
||||||
mpd_song_add_tag(itsSong, mpd_tag_type(t), conv_tag);
|
utf_to_locale(conv_tag, 0);
|
||||||
delete [] conv_tag;
|
if (tag != conv_tag) // tag has been converted
|
||||||
|
{
|
||||||
|
SetTag(mpd_tag_type(t), pos, conv_tag);
|
||||||
|
delete [] conv_tag;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
isLocalised = 1;
|
isLocalised = 1;
|
||||||
@@ -110,9 +115,14 @@ void MPD::Song::Clear()
|
|||||||
{
|
{
|
||||||
if (itsSong)
|
if (itsSong)
|
||||||
mpd_song_free(itsSong);
|
mpd_song_free(itsSong);
|
||||||
|
itsSong = 0;
|
||||||
|
|
||||||
delete [] itsFile;
|
delete [] itsFile;
|
||||||
itsFile = 0;
|
itsFile = 0;
|
||||||
itsSong = 0;
|
|
||||||
|
delete itsTags;
|
||||||
|
itsTags = 0;
|
||||||
|
|
||||||
itsNewName.clear();
|
itsNewName.clear();
|
||||||
itsSlash = std::string::npos;
|
itsSlash = std::string::npos;
|
||||||
itsHash = 0;
|
itsHash = 0;
|
||||||
@@ -142,7 +152,8 @@ std::string MPD::Song::GetFile() const
|
|||||||
|
|
||||||
std::string MPD::Song::GetName() const
|
std::string MPD::Song::GetName() const
|
||||||
{
|
{
|
||||||
if (const char *name = mpd_song_get_tag(itsSong, MPD_TAG_NAME, 0))
|
std::string name = GetTag(MPD_TAG_NAME, 0);
|
||||||
|
if (!name.empty())
|
||||||
return name;
|
return name;
|
||||||
else if (itsSlash != std::string::npos)
|
else if (itsSlash != std::string::npos)
|
||||||
return MyFilename()+itsSlash+1;
|
return MyFilename()+itsSlash+1;
|
||||||
@@ -162,184 +173,126 @@ std::string MPD::Song::GetDirectory() const
|
|||||||
|
|
||||||
std::string MPD::Song::GetArtist() const
|
std::string MPD::Song::GetArtist() const
|
||||||
{
|
{
|
||||||
if (const char *artist = mpd_song_get_tag(itsSong, MPD_TAG_ARTIST, 0))
|
return GetTag(MPD_TAG_ARTIST, 0);
|
||||||
return artist;
|
|
||||||
else
|
|
||||||
return "";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string MPD::Song::GetTitle() const
|
std::string MPD::Song::GetTitle() const
|
||||||
{
|
{
|
||||||
if (const char *title = mpd_song_get_tag(itsSong, MPD_TAG_TITLE, 0))
|
return GetTag(MPD_TAG_TITLE, 0);
|
||||||
return title;
|
|
||||||
else
|
|
||||||
return "";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string MPD::Song::GetAlbum() const
|
std::string MPD::Song::GetAlbum() const
|
||||||
{
|
{
|
||||||
if (const char *album = mpd_song_get_tag(itsSong, MPD_TAG_ALBUM, 0))
|
return GetTag(MPD_TAG_ALBUM, 0);
|
||||||
return album;
|
|
||||||
else
|
|
||||||
return "";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string MPD::Song::GetTrack() const
|
std::string MPD::Song::GetTrack() const
|
||||||
{
|
{
|
||||||
const char *track = mpd_song_get_tag(itsSong, MPD_TAG_TRACK, 0);
|
std::string track = GetTag(MPD_TAG_TRACK, 0);
|
||||||
if (!track)
|
return track.length() == 1 && track[0] != '0' ? "0"+track : track;
|
||||||
return "";
|
|
||||||
else if (track[0] != '0' && !track[1])
|
|
||||||
return "0"+std::string(track);
|
|
||||||
else
|
|
||||||
return track;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string MPD::Song::GetTrackNumber() const
|
std::string MPD::Song::GetTrackNumber() const
|
||||||
{
|
{
|
||||||
const char *track = mpd_song_get_tag(itsSong, MPD_TAG_TRACK, 0);
|
std::string track = GetTag(MPD_TAG_TRACK, 0);
|
||||||
if (!track)
|
size_t slash = track.find('/');
|
||||||
return "";
|
if (slash != std::string::npos)
|
||||||
const char *slash = strrchr(track, '/');
|
|
||||||
if (slash)
|
|
||||||
{
|
{
|
||||||
std::string result(track, slash-track);
|
track = track.substr(slash+1);
|
||||||
return result[0] != '0' && result.length() == 1 ? "0"+result : result;
|
return track.length() == 1 && track[0] != '0' ? "0"+track : track;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return GetTrack();
|
return track;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string MPD::Song::GetDate() const
|
std::string MPD::Song::GetDate() const
|
||||||
{
|
{
|
||||||
if (const char *date = mpd_song_get_tag(itsSong, MPD_TAG_DATE, 0))
|
return GetTag(MPD_TAG_DATE, 0);
|
||||||
return date;
|
|
||||||
else
|
|
||||||
return "";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string MPD::Song::GetGenre() const
|
std::string MPD::Song::GetGenre() const
|
||||||
{
|
{
|
||||||
if (const char *genre = mpd_song_get_tag(itsSong, MPD_TAG_GENRE, 0))
|
return GetTag(MPD_TAG_GENRE, 0);
|
||||||
return genre;
|
|
||||||
else
|
|
||||||
return "";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string MPD::Song::GetComposer() const
|
std::string MPD::Song::GetComposer() const
|
||||||
{
|
{
|
||||||
if (const char *composer = mpd_song_get_tag(itsSong, MPD_TAG_COMPOSER, 0))
|
return GetTag(MPD_TAG_COMPOSER, 0);
|
||||||
return composer;
|
|
||||||
else
|
|
||||||
return "";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string MPD::Song::GetPerformer() const
|
std::string MPD::Song::GetPerformer() const
|
||||||
{
|
{
|
||||||
if (const char *performer = mpd_song_get_tag(itsSong, MPD_TAG_PERFORMER, 0))
|
return GetTag(MPD_TAG_PERFORMER, 0);
|
||||||
return performer;
|
|
||||||
else
|
|
||||||
return "";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string MPD::Song::GetDisc() const
|
std::string MPD::Song::GetDisc() const
|
||||||
{
|
{
|
||||||
if (const char *disc = mpd_song_get_tag(itsSong, MPD_TAG_DISC, 0))
|
return GetTag(MPD_TAG_DISC, 0);
|
||||||
return disc;
|
|
||||||
else
|
|
||||||
return "";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string MPD::Song::GetComment() const
|
std::string MPD::Song::GetComment() const
|
||||||
{
|
{
|
||||||
if (const char *comment = mpd_song_get_tag(itsSong, MPD_TAG_COMMENT, 0))
|
return GetTag(MPD_TAG_COMMENT, 0);
|
||||||
return comment;
|
|
||||||
else
|
|
||||||
return "";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MPD::Song::SetArtist(const std::string &str)
|
void MPD::Song::SetArtist(const std::string &str)
|
||||||
{
|
{
|
||||||
mpd_song_clear_tag(itsSong, MPD_TAG_ARTIST);
|
SetTag(MPD_TAG_ARTIST, 0, str);
|
||||||
if (!str.empty())
|
|
||||||
mpd_song_add_tag(itsSong, MPD_TAG_ARTIST, str.c_str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MPD::Song::SetTitle(const std::string &str)
|
void MPD::Song::SetTitle(const std::string &str)
|
||||||
{
|
{
|
||||||
mpd_song_clear_tag(itsSong, MPD_TAG_TITLE);
|
SetTag(MPD_TAG_TITLE, 0, str);
|
||||||
if (!str.empty())
|
|
||||||
mpd_song_add_tag(itsSong, MPD_TAG_TITLE, str.c_str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MPD::Song::SetAlbum(const std::string &str)
|
void MPD::Song::SetAlbum(const std::string &str)
|
||||||
{
|
{
|
||||||
mpd_song_clear_tag(itsSong, MPD_TAG_ALBUM);
|
SetTag(MPD_TAG_ALBUM, 0, str);
|
||||||
if (!str.empty())
|
|
||||||
mpd_song_add_tag(itsSong, MPD_TAG_ALBUM, str.c_str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MPD::Song::SetTrack(const std::string &str)
|
void MPD::Song::SetTrack(const std::string &str)
|
||||||
{
|
{
|
||||||
mpd_song_clear_tag(itsSong, MPD_TAG_TRACK);
|
SetTag(MPD_TAG_TRACK, 0, str);
|
||||||
if (!str.empty())
|
|
||||||
mpd_song_add_tag(itsSong, MPD_TAG_TRACK, str.c_str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MPD::Song::SetTrack(unsigned track)
|
void MPD::Song::SetTrack(unsigned track)
|
||||||
{
|
{
|
||||||
mpd_song_clear_tag(itsSong, MPD_TAG_TRACK);
|
SetTag(MPD_TAG_ARTIST, 0, IntoStr(track));
|
||||||
if (track)
|
|
||||||
mpd_song_add_tag(itsSong, MPD_TAG_ARTIST, IntoStr(track).c_str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MPD::Song::SetDate(const std::string &str)
|
void MPD::Song::SetDate(const std::string &str)
|
||||||
{
|
{
|
||||||
mpd_song_clear_tag(itsSong, MPD_TAG_DATE);
|
SetTag(MPD_TAG_DATE, 0, str);
|
||||||
if (!str.empty())
|
|
||||||
mpd_song_add_tag(itsSong, MPD_TAG_DATE, str.c_str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MPD::Song::SetDate(unsigned year)
|
void MPD::Song::SetDate(unsigned year)
|
||||||
{
|
{
|
||||||
mpd_song_clear_tag(itsSong, MPD_TAG_DATE);
|
SetTag(MPD_TAG_TRACK, 0, IntoStr(year));
|
||||||
if (year)
|
|
||||||
mpd_song_add_tag(itsSong, MPD_TAG_DATE, IntoStr(year).c_str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MPD::Song::SetGenre(const std::string &str)
|
void MPD::Song::SetGenre(const std::string &str)
|
||||||
{
|
{
|
||||||
mpd_song_clear_tag(itsSong, MPD_TAG_GENRE);
|
SetTag(MPD_TAG_GENRE, 0, str);
|
||||||
if (!str.empty())
|
|
||||||
mpd_song_add_tag(itsSong, MPD_TAG_GENRE, str.c_str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MPD::Song::SetComposer(const std::string &str)
|
void MPD::Song::SetComposer(const std::string &str)
|
||||||
{
|
{
|
||||||
mpd_song_clear_tag(itsSong, MPD_TAG_COMPOSER);
|
SetTag(MPD_TAG_COMPOSER, 0, str);
|
||||||
if (!str.empty())
|
|
||||||
mpd_song_add_tag(itsSong, MPD_TAG_COMPOSER, str.c_str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MPD::Song::SetPerformer(const std::string &str)
|
void MPD::Song::SetPerformer(const std::string &str)
|
||||||
{
|
{
|
||||||
mpd_song_clear_tag(itsSong, MPD_TAG_PERFORMER);
|
SetTag(MPD_TAG_PERFORMER, 0, str);
|
||||||
if (!str.empty())
|
|
||||||
mpd_song_add_tag(itsSong, MPD_TAG_PERFORMER, str.c_str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MPD::Song::SetDisc(const std::string &str)
|
void MPD::Song::SetDisc(const std::string &str)
|
||||||
{
|
{
|
||||||
mpd_song_clear_tag(itsSong, MPD_TAG_DISC);
|
SetTag(MPD_TAG_DISC, 0, str);
|
||||||
if (!str.empty())
|
|
||||||
mpd_song_add_tag(itsSong, MPD_TAG_DISC, str.c_str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MPD::Song::SetComment(const std::string &str)
|
void MPD::Song::SetComment(const std::string &str)
|
||||||
{
|
{
|
||||||
mpd_song_clear_tag(itsSong, MPD_TAG_COMMENT);
|
SetTag(MPD_TAG_COMMENT, 0, str);
|
||||||
if (!str.empty())
|
|
||||||
mpd_song_add_tag(itsSong, MPD_TAG_COMMENT, str.c_str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MPD::Song::SetPosition(unsigned pos)
|
void MPD::Song::SetPosition(unsigned pos)
|
||||||
@@ -347,11 +300,6 @@ void MPD::Song::SetPosition(unsigned pos)
|
|||||||
mpd_song_set_pos(itsSong, pos);
|
mpd_song_set_pos(itsSong, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MPD::Song::SetLength(unsigned len)
|
|
||||||
{
|
|
||||||
mpd_song_set_duration(itsSong, len);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string MPD::Song::ParseFormat(std::string::const_iterator &it) const
|
std::string MPD::Song::ParseFormat(std::string::const_iterator &it) const
|
||||||
{
|
{
|
||||||
std::string result;
|
std::string result;
|
||||||
@@ -482,10 +430,11 @@ MPD::Song &MPD::Song::operator=(const MPD::Song &s)
|
|||||||
return *this;
|
return *this;
|
||||||
if (itsSong)
|
if (itsSong)
|
||||||
mpd_song_free(itsSong);
|
mpd_song_free(itsSong);
|
||||||
if (itsFile)
|
delete [] itsFile;
|
||||||
delete [] itsFile;
|
delete itsTags;
|
||||||
itsSong = s.copyPtr ? s.itsSong : (s.itsSong ? mpd_song_dup(s.itsSong) : 0);
|
itsSong = s.copyPtr ? s.itsSong : (s.itsSong ? mpd_song_dup(s.itsSong) : 0);
|
||||||
itsFile = s.itsFile ? strdup(s.itsFile) : 0;
|
itsFile = s.itsFile ? strdup(s.itsFile) : 0;
|
||||||
|
itsTags = s.itsTags ? new TagMap(*s.itsTags) : 0;
|
||||||
itsNewName = s.itsNewName;
|
itsNewName = s.itsNewName;
|
||||||
itsSlash = s.itsSlash;
|
itsSlash = s.itsSlash;
|
||||||
itsHash = s.itsHash;
|
itsHash = s.itsHash;
|
||||||
@@ -549,3 +498,24 @@ const char *MPD::Song::MyFilename() const
|
|||||||
return itsFile ? itsFile : mpd_song_get_uri(itsSong);
|
return itsFile ? itsFile : mpd_song_get_uri(itsSong);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MPD::Song::SetTag(mpd_tag_type type, unsigned pos, const std::string &value)
|
||||||
|
{
|
||||||
|
if (value.empty())
|
||||||
|
return;
|
||||||
|
if (!itsTags)
|
||||||
|
itsTags = new TagMap;
|
||||||
|
(*itsTags)[std::make_pair(type, pos)] = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string MPD::Song::GetTag(mpd_tag_type type, unsigned pos) const
|
||||||
|
{
|
||||||
|
if (itsTags)
|
||||||
|
{
|
||||||
|
TagMap::const_iterator it = itsTags->find(std::make_pair(type, pos));
|
||||||
|
if (it != itsTags->end())
|
||||||
|
return it->second;
|
||||||
|
}
|
||||||
|
const char *tag = mpd_song_get_tag(itsSong, type, pos);
|
||||||
|
return tag ? tag : "";
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
13
src/song.h
13
src/song.h
@@ -21,6 +21,7 @@
|
|||||||
#ifndef _SONG_H
|
#ifndef _SONG_H
|
||||||
#define _SONG_H
|
#define _SONG_H
|
||||||
|
|
||||||
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include <mpd/client.h>
|
#include <mpd/client.h>
|
||||||
@@ -29,13 +30,14 @@ namespace MPD
|
|||||||
{
|
{
|
||||||
class Song
|
class Song
|
||||||
{
|
{
|
||||||
|
typedef std::map<std::pair<mpd_tag_type, unsigned>, std::string> TagMap;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
typedef void (Song::*SetFunction)(const std::string &);
|
typedef void (Song::*SetFunction)(const std::string &);
|
||||||
typedef std::string (Song::*GetFunction)() const;
|
typedef std::string (Song::*GetFunction)() const;
|
||||||
|
|
||||||
Song() : itsSong(0), itsFile(0), itsSlash(std::string::npos), itsHash(0), copyPtr(0), isLocalised(0) { }
|
Song(mpd_song * = 0, bool = 0);
|
||||||
Song(mpd_song *, bool = 0);
|
|
||||||
Song(const Song &);
|
Song(const Song &);
|
||||||
~Song();
|
~Song();
|
||||||
|
|
||||||
@@ -73,7 +75,6 @@ namespace MPD
|
|||||||
void SetDisc(const std::string &);
|
void SetDisc(const std::string &);
|
||||||
void SetComment(const std::string &);
|
void SetComment(const std::string &);
|
||||||
void SetPosition(unsigned);
|
void SetPosition(unsigned);
|
||||||
void SetLength(unsigned);
|
|
||||||
|
|
||||||
void SetNewName(const std::string &name) { itsNewName = name == GetName() ? "" : name; }
|
void SetNewName(const std::string &name) { itsNewName = name == GetName() ? "" : name; }
|
||||||
std::string GetNewName() const { return itsNewName; }
|
std::string GetNewName() const { return itsNewName; }
|
||||||
@@ -99,6 +100,9 @@ namespace MPD
|
|||||||
void SetHashAndSlash();
|
void SetHashAndSlash();
|
||||||
std::string ParseFormat(std::string::const_iterator &it) const;
|
std::string ParseFormat(std::string::const_iterator &it) const;
|
||||||
|
|
||||||
|
void SetTag(mpd_tag_type, unsigned, const std::string &);
|
||||||
|
std::string GetTag(mpd_tag_type, unsigned) const;
|
||||||
|
|
||||||
/// Used internally for handling filename, since we don't have
|
/// Used internally for handling filename, since we don't have
|
||||||
/// write access to file string in mpd_song, manage our own if
|
/// write access to file string in mpd_song, manage our own if
|
||||||
/// localization was done and there is localized filename that
|
/// localization was done and there is localized filename that
|
||||||
@@ -112,6 +116,9 @@ namespace MPD
|
|||||||
/// localized version of filename
|
/// localized version of filename
|
||||||
const char *itsFile;
|
const char *itsFile;
|
||||||
|
|
||||||
|
/// map that contains localized tags or these set by tag editor
|
||||||
|
TagMap *itsTags;
|
||||||
|
|
||||||
std::string itsNewName;
|
std::string itsNewName;
|
||||||
|
|
||||||
size_t itsSlash;
|
size_t itsSlash;
|
||||||
|
|||||||
@@ -895,7 +895,6 @@ void TagEditor::ReadTags(MPD::Song &s)
|
|||||||
s.SetDisc(!mpegf->ID3v2Tag()->frameListMap()["TPOS"].isEmpty() ? mpegf->ID3v2Tag()->frameListMap()["TPOS"].front()->toString().to8Bit(1) : "");
|
s.SetDisc(!mpegf->ID3v2Tag()->frameListMap()["TPOS"].isEmpty() ? mpegf->ID3v2Tag()->frameListMap()["TPOS"].front()->toString().to8Bit(1) : "");
|
||||||
}
|
}
|
||||||
s.SetComment(f.tag()->comment().to8Bit(1));
|
s.SetComment(f.tag()->comment().to8Bit(1));
|
||||||
s.SetLength(f.audioProperties()->length());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
|
|||||||
Reference in New Issue
Block a user