mpd: use lambda closures instead of passing vectors to functions
This commit is contained in:
@@ -290,7 +290,11 @@ void Browser::GetSelectedSongs(MPD::SongList &v)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
# endif // !WIN32
|
# endif // !WIN32
|
||||||
Mpd.GetDirectoryRecursive(locale_to_utf_cpy(item.name), v);
|
{
|
||||||
|
Mpd.GetDirectoryRecursive(locale_to_utf_cpy(item.name), [&v](MPD::Song &&s) {
|
||||||
|
v.push_back(s);
|
||||||
|
});
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case itSong:
|
case itSong:
|
||||||
@@ -300,7 +304,9 @@ void Browser::GetSelectedSongs(MPD::SongList &v)
|
|||||||
}
|
}
|
||||||
case itPlaylist:
|
case itPlaylist:
|
||||||
{
|
{
|
||||||
Mpd.GetPlaylistContent(locale_to_utf_cpy(item.name), v);
|
Mpd.GetPlaylistContent(locale_to_utf_cpy(item.name), [&v](MPD::Song &&s) {
|
||||||
|
v.push_back(s);
|
||||||
|
});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -370,9 +376,18 @@ void Browser::GetDirectory(std::string dir, std::string subdir)
|
|||||||
|
|
||||||
MPD::ItemList list;
|
MPD::ItemList list;
|
||||||
# ifndef WIN32
|
# ifndef WIN32
|
||||||
isLocal() ? GetLocalDirectory(list) : Mpd.GetDirectory(dir, list);
|
if (isLocal())
|
||||||
|
GetLocalDirectory(list);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Mpd.GetDirectory(dir, [&list](MPD::Item &&i) {
|
||||||
|
list.push_back(i);
|
||||||
|
});
|
||||||
|
}
|
||||||
# else
|
# else
|
||||||
Mpd.GetDirectory(dir, list);
|
Mpd.GetDirectory(dir, [&list](MPD::Item &&i) {
|
||||||
|
list.push_back(i);
|
||||||
|
});
|
||||||
# endif // !WIN32
|
# endif // !WIN32
|
||||||
if (!isLocal()) // local directory is already sorted
|
if (!isLocal()) // local directory is already sorted
|
||||||
std::sort(list.begin(), list.end(), CaseInsensitiveSorting());
|
std::sort(list.begin(), list.end(), CaseInsensitiveSorting());
|
||||||
|
|||||||
@@ -354,6 +354,12 @@ void Display::Tags(const MPD::Song &s, void *data, Menu<MPD::Song> *menu)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Display::Outputs (const MPD::Output &o, void * , Menu< MPD::Output > *menu)
|
||||||
|
{
|
||||||
|
*menu << o.name();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void Display::Items(const MPD::Item &item, void *data, Menu<MPD::Item> *menu)
|
void Display::Items(const MPD::Item &item, void *data, Menu<MPD::Item> *menu)
|
||||||
{
|
{
|
||||||
switch (item.type)
|
switch (item.type)
|
||||||
|
|||||||
@@ -53,6 +53,8 @@ namespace Display
|
|||||||
|
|
||||||
void Tags(const MPD::Song &, void *, Menu<MPD::Song> *);
|
void Tags(const MPD::Song &, void *, Menu<MPD::Song> *);
|
||||||
|
|
||||||
|
void Outputs(const MPD::Output &, void *, Menu<MPD::Output> *);
|
||||||
|
|
||||||
void SearchEngine(const SEItem &, void *, Menu<SEItem> *);
|
void SearchEngine(const SEItem &, void *, Menu<SEItem> *);
|
||||||
|
|
||||||
void Items(const MPD::Item &, void *, Menu<MPD::Item> *);
|
void Items(const MPD::Item &, void *, Menu<MPD::Item> *);
|
||||||
|
|||||||
@@ -226,28 +226,26 @@ void MediaLibrary::Update()
|
|||||||
locale_to_utf(Artists->Current());
|
locale_to_utf(Artists->Current());
|
||||||
Mpd.StartFieldSearch(MPD_TAG_ALBUM);
|
Mpd.StartFieldSearch(MPD_TAG_ALBUM);
|
||||||
Mpd.AddSearch(Config.media_lib_primary_tag, Artists->Current());
|
Mpd.AddSearch(Config.media_lib_primary_tag, Artists->Current());
|
||||||
Mpd.CommitSearch(list);
|
Mpd.CommitSearchTags([&list](std::string &&album) {
|
||||||
|
list.push_back(album);
|
||||||
for (MPD::TagList::iterator it = list.begin(); it != list.end(); ++it)
|
});
|
||||||
|
for (auto album = list.begin(); album != list.end(); ++album)
|
||||||
{
|
{
|
||||||
if (Config.media_library_display_date)
|
if (Config.media_library_display_date)
|
||||||
{
|
{
|
||||||
MPD::TagList l;
|
|
||||||
Mpd.StartFieldSearch(MPD_TAG_DATE);
|
Mpd.StartFieldSearch(MPD_TAG_DATE);
|
||||||
Mpd.AddSearch(Config.media_lib_primary_tag, Artists->Current());
|
Mpd.AddSearch(Config.media_lib_primary_tag, Artists->Current());
|
||||||
Mpd.AddSearch(MPD_TAG_ALBUM, *it);
|
Mpd.AddSearch(MPD_TAG_ALBUM, *album);
|
||||||
Mpd.CommitSearch(l);
|
utf_to_locale(*album);
|
||||||
utf_to_locale(*it);
|
Mpd.CommitSearchTags([this, &album](std::string &&date) {
|
||||||
for (MPD::TagList::iterator j = l.begin(); j != l.end(); ++j)
|
utf_to_locale(date);
|
||||||
{
|
Albums->AddOption(SearchConstraints(*album, date));
|
||||||
utf_to_locale(*j);
|
});
|
||||||
Albums->AddOption(SearchConstraints(*it, *j));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
utf_to_locale(*it);
|
utf_to_locale(*album);
|
||||||
Albums->AddOption(SearchConstraints(*it, ""));
|
Albums->AddOption(SearchConstraints(*album, ""));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
utf_to_locale(Artists->Current());
|
utf_to_locale(Artists->Current());
|
||||||
@@ -269,43 +267,42 @@ void MediaLibrary::Update()
|
|||||||
Albums->Window::Refresh();
|
Albums->Window::Refresh();
|
||||||
Mpd.BlockIdle(1);
|
Mpd.BlockIdle(1);
|
||||||
Mpd.GetList(artists, Config.media_lib_primary_tag);
|
Mpd.GetList(artists, Config.media_lib_primary_tag);
|
||||||
for (MPD::TagList::iterator i = artists.begin(); i != artists.end(); ++i)
|
for (auto artist = artists.begin(); artist != artists.end(); ++artist)
|
||||||
{
|
{
|
||||||
MPD::TagList albums;
|
MPD::TagList albums;
|
||||||
Mpd.StartFieldSearch(MPD_TAG_ALBUM);
|
Mpd.StartFieldSearch(MPD_TAG_ALBUM);
|
||||||
Mpd.AddSearch(Config.media_lib_primary_tag, *i);
|
Mpd.AddSearch(Config.media_lib_primary_tag, *artist);
|
||||||
Mpd.CommitSearch(albums);
|
Mpd.CommitSearchTags([&albums](std::string &&album) {
|
||||||
for (MPD::TagList::iterator j = albums.begin(); j != albums.end(); ++j)
|
albums.push_back(album);
|
||||||
|
});
|
||||||
|
for (auto album = albums.begin(); album != albums.end(); ++album)
|
||||||
{
|
{
|
||||||
if (Config.media_library_display_date)
|
if (Config.media_library_display_date)
|
||||||
{
|
{
|
||||||
if (Config.media_lib_primary_tag != MPD_TAG_DATE)
|
if (Config.media_lib_primary_tag != MPD_TAG_DATE)
|
||||||
{
|
{
|
||||||
MPD::TagList dates;
|
|
||||||
Mpd.StartFieldSearch(MPD_TAG_DATE);
|
Mpd.StartFieldSearch(MPD_TAG_DATE);
|
||||||
Mpd.AddSearch(Config.media_lib_primary_tag, *i);
|
Mpd.AddSearch(Config.media_lib_primary_tag, *artist);
|
||||||
Mpd.AddSearch(MPD_TAG_ALBUM, *j);
|
Mpd.AddSearch(MPD_TAG_ALBUM, *album);
|
||||||
Mpd.CommitSearch(dates);
|
utf_to_locale(*artist);
|
||||||
utf_to_locale(*i);
|
utf_to_locale(*album);
|
||||||
utf_to_locale(*j);
|
Mpd.CommitSearchTags([this, &artist, &album](std::string &&tag) {
|
||||||
for (MPD::TagList::iterator k = dates.begin(); k != dates.end(); ++k)
|
utf_to_locale(tag);
|
||||||
{
|
Albums->AddOption(SearchConstraints(*artist, *album, tag));
|
||||||
utf_to_locale(*k);
|
});
|
||||||
Albums->AddOption(SearchConstraints(*i, *j, *k));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
utf_to_locale(*i);
|
utf_to_locale(*artist);
|
||||||
utf_to_locale(*j);
|
utf_to_locale(*album);
|
||||||
Albums->AddOption(SearchConstraints(*i, *j, *i));
|
Albums->AddOption(SearchConstraints(*artist, *album, *artist));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
utf_to_locale(*i);
|
utf_to_locale(*artist);
|
||||||
utf_to_locale(*j);
|
utf_to_locale(*album);
|
||||||
Albums->AddOption(SearchConstraints(*i, *j, ""));
|
Albums->AddOption(SearchConstraints(*artist, *album, ""));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -335,24 +332,17 @@ void MediaLibrary::Update()
|
|||||||
if (Config.media_library_display_date)
|
if (Config.media_library_display_date)
|
||||||
Mpd.AddSearch(MPD_TAG_DATE, locale_to_utf_cpy(Albums->Current().Date));
|
Mpd.AddSearch(MPD_TAG_DATE, locale_to_utf_cpy(Albums->Current().Date));
|
||||||
}
|
}
|
||||||
Mpd.CommitSearch(list);
|
Mpd.CommitSearchSongs([&list](MPD::Song &&s) {
|
||||||
|
list.push_back(s);
|
||||||
|
});
|
||||||
|
|
||||||
std::sort(list.begin(), list.end(), Albums->Current().Date == AllTracksMarker ? SortAllTracks : SortSongsByTrack);
|
if (Albums->Current().Date == AllTracksMarker)
|
||||||
bool bold = 0;
|
std::sort(list.begin(), list.end(), SortAllTracks);
|
||||||
|
else
|
||||||
|
std::sort(list.begin(), list.end(), SortSongsByTrack);
|
||||||
|
|
||||||
for (MPD::SongList::const_iterator it = list.begin(); it != list.end(); ++it)
|
for (auto it = list.begin(); it != list.end(); ++it)
|
||||||
{
|
Songs->AddOption(*it, myPlaylist->checkForSong(*it));
|
||||||
for (size_t j = 0; j < myPlaylist->Items->Size(); ++j)
|
|
||||||
{
|
|
||||||
if (it->getHash() == myPlaylist->Items->at(j).getHash())
|
|
||||||
{
|
|
||||||
bold = 1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Songs->AddOption(*it, bold);
|
|
||||||
bold = 0;
|
|
||||||
}
|
|
||||||
Songs->Window::Clear();
|
Songs->Window::Clear();
|
||||||
Songs->Refresh();
|
Songs->Refresh();
|
||||||
}
|
}
|
||||||
@@ -493,7 +483,9 @@ void MediaLibrary::GetSelectedSongs(MPD::SongList &v)
|
|||||||
MPD::SongList list;
|
MPD::SongList list;
|
||||||
Mpd.StartSearch(1);
|
Mpd.StartSearch(1);
|
||||||
Mpd.AddSearch(Config.media_lib_primary_tag, locale_to_utf_cpy(Artists->at(*it)));
|
Mpd.AddSearch(Config.media_lib_primary_tag, locale_to_utf_cpy(Artists->at(*it)));
|
||||||
Mpd.CommitSearch(list);
|
Mpd.CommitSearchSongs([&list](MPD::Song &&s) {
|
||||||
|
list.push_back(s);
|
||||||
|
});
|
||||||
std::sort(list.begin(), list.end(), SortAllTracks);
|
std::sort(list.begin(), list.end(), SortAllTracks);
|
||||||
std::copy(list.begin(), list.end(), std::back_inserter(v));
|
std::copy(list.begin(), list.end(), std::back_inserter(v));
|
||||||
}
|
}
|
||||||
@@ -513,15 +505,15 @@ void MediaLibrary::GetSelectedSongs(MPD::SongList &v)
|
|||||||
{
|
{
|
||||||
for (auto it = selected.begin(); it != selected.end(); ++it)
|
for (auto it = selected.begin(); it != selected.end(); ++it)
|
||||||
{
|
{
|
||||||
MPD::SongList list;
|
|
||||||
Mpd.StartSearch(1);
|
Mpd.StartSearch(1);
|
||||||
Mpd.AddSearch(Config.media_lib_primary_tag, hasTwoColumns
|
Mpd.AddSearch(Config.media_lib_primary_tag, hasTwoColumns
|
||||||
? Albums->at(*it).PrimaryTag
|
? Albums->at(*it).PrimaryTag
|
||||||
: locale_to_utf_cpy(Artists->Current()));
|
: locale_to_utf_cpy(Artists->Current()));
|
||||||
Mpd.AddSearch(MPD_TAG_ALBUM, Albums->at(*it).Album);
|
Mpd.AddSearch(MPD_TAG_ALBUM, Albums->at(*it).Album);
|
||||||
Mpd.AddSearch(MPD_TAG_DATE, Albums->at(*it).Date);
|
Mpd.AddSearch(MPD_TAG_DATE, Albums->at(*it).Date);
|
||||||
Mpd.CommitSearch(list);
|
Mpd.CommitSearchSongs([&v](MPD::Song &&s) {
|
||||||
std::copy(list.begin(), list.end(), std::back_inserter(v));
|
v.push_back(s);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -621,17 +621,15 @@ bool MPD::Connection::Rename(const std::string &from, const std::string &to)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MPD::Connection::GetPlaylistChanges(unsigned version, SongList &v)
|
void MPD::Connection::GetPlaylistChanges(unsigned version, std::function<void(MPD::Song &&)> f)
|
||||||
{
|
{
|
||||||
if (!itsConnection)
|
if (!itsConnection)
|
||||||
return;
|
return;
|
||||||
assert(!isCommandsListEnabled);
|
assert(!isCommandsListEnabled);
|
||||||
if (!version)
|
|
||||||
v.reserve(GetPlaylistLength());
|
|
||||||
GoBusy();
|
GoBusy();
|
||||||
mpd_send_queue_changes_meta(itsConnection, version);
|
mpd_send_queue_changes_meta(itsConnection, version);
|
||||||
while (mpd_song *s = mpd_recv_song(itsConnection))
|
while (mpd_song *s = mpd_recv_song(itsConnection))
|
||||||
v.push_back(Song(s));
|
f(Song(s));
|
||||||
mpd_response_finish(itsConnection);
|
mpd_response_finish(itsConnection);
|
||||||
GoIdle();
|
GoIdle();
|
||||||
}
|
}
|
||||||
@@ -669,7 +667,7 @@ MPD::Song MPD::Connection::GetCurrentlyPlayingSong()
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MPD::Connection::GetPlaylistContent(const std::string &path, SongList &v)
|
void MPD::Connection::GetPlaylistContent(const std::string &path, std::function<void(MPD::Song &&)> f)
|
||||||
{
|
{
|
||||||
if (!itsConnection)
|
if (!itsConnection)
|
||||||
return;
|
return;
|
||||||
@@ -677,7 +675,7 @@ void MPD::Connection::GetPlaylistContent(const std::string &path, SongList &v)
|
|||||||
GoBusy();
|
GoBusy();
|
||||||
mpd_send_list_playlist_meta(itsConnection, path.c_str());
|
mpd_send_list_playlist_meta(itsConnection, path.c_str());
|
||||||
while (mpd_song *s = mpd_recv_song(itsConnection))
|
while (mpd_song *s = mpd_recv_song(itsConnection))
|
||||||
v.push_back(Song(s));
|
f(Song(s));
|
||||||
mpd_response_finish(itsConnection);
|
mpd_response_finish(itsConnection);
|
||||||
GoIdle();
|
GoIdle();
|
||||||
}
|
}
|
||||||
@@ -923,7 +921,9 @@ bool MPD::Connection::AddRandomTag(mpd_tag_type tag, size_t number)
|
|||||||
StartSearch(1);
|
StartSearch(1);
|
||||||
AddSearch(tag, *it++);
|
AddSearch(tag, *it++);
|
||||||
SongList list;
|
SongList list;
|
||||||
CommitSearch(list);
|
CommitSearchSongs([&list](MPD::Song &&s) {
|
||||||
|
list.push_back(s);
|
||||||
|
});
|
||||||
StartCommandsList();
|
StartCommandsList();
|
||||||
for (auto j = list.begin(); j != list.end(); ++j)
|
for (auto j = list.begin(); j != list.end(); ++j)
|
||||||
AddSong(*j);
|
AddSong(*j);
|
||||||
@@ -1079,11 +1079,10 @@ void MPD::Connection::GetPlaylists(TagList &v)
|
|||||||
{
|
{
|
||||||
if (!itsConnection)
|
if (!itsConnection)
|
||||||
return;
|
return;
|
||||||
ItemList list;
|
GetDirectory("/", [&v](Item &&it) {
|
||||||
GetDirectory("/", list);
|
if (it.type == itPlaylist)
|
||||||
for (ItemList::const_iterator it = list.begin(); it != list.end(); ++it)
|
v.push_back(it.name);
|
||||||
if (it->type == itPlaylist)
|
});
|
||||||
v.push_back(it->name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MPD::Connection::GetList(TagList &v, mpd_tag_type type)
|
void MPD::Connection::GetList(TagList &v, mpd_tag_type type)
|
||||||
@@ -1141,7 +1140,7 @@ void MPD::Connection::AddSearchURI(const std::string &str) const
|
|||||||
mpd_search_add_uri_constraint(itsConnection, MPD_OPERATOR_DEFAULT, str.c_str());
|
mpd_search_add_uri_constraint(itsConnection, MPD_OPERATOR_DEFAULT, str.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void MPD::Connection::CommitSearch(SongList &v)
|
void MPD::Connection::CommitSearchSongs(std::function<void(MPD::Song &&)> f)
|
||||||
{
|
{
|
||||||
if (!itsConnection)
|
if (!itsConnection)
|
||||||
return;
|
return;
|
||||||
@@ -1149,12 +1148,12 @@ void MPD::Connection::CommitSearch(SongList &v)
|
|||||||
GoBusy();
|
GoBusy();
|
||||||
mpd_search_commit(itsConnection);
|
mpd_search_commit(itsConnection);
|
||||||
while (mpd_song *s = mpd_recv_song(itsConnection))
|
while (mpd_song *s = mpd_recv_song(itsConnection))
|
||||||
v.push_back(Song(s));
|
f(Song(s));
|
||||||
mpd_response_finish(itsConnection);
|
mpd_response_finish(itsConnection);
|
||||||
GoIdle();
|
GoIdle();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MPD::Connection::CommitSearch(TagList &v)
|
void MPD::Connection::CommitSearchTags(std::function<void(std::string &&)> f)
|
||||||
{
|
{
|
||||||
if (!itsConnection)
|
if (!itsConnection)
|
||||||
return;
|
return;
|
||||||
@@ -1163,14 +1162,14 @@ void MPD::Connection::CommitSearch(TagList &v)
|
|||||||
mpd_search_commit(itsConnection);
|
mpd_search_commit(itsConnection);
|
||||||
while (mpd_pair *tag = mpd_recv_pair_tag(itsConnection, itsSearchedField))
|
while (mpd_pair *tag = mpd_recv_pair_tag(itsConnection, itsSearchedField))
|
||||||
{
|
{
|
||||||
v.push_back(tag->value);
|
f(tag->value);
|
||||||
mpd_return_pair(itsConnection, tag);
|
mpd_return_pair(itsConnection, tag);
|
||||||
}
|
}
|
||||||
mpd_response_finish(itsConnection);
|
mpd_response_finish(itsConnection);
|
||||||
GoIdle();
|
GoIdle();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MPD::Connection::GetDirectory(const std::string &path, ItemList &v)
|
void MPD::Connection::GetDirectory(const std::string &path, std::function<void(Item &&)> f)
|
||||||
{
|
{
|
||||||
if (!itsConnection)
|
if (!itsConnection)
|
||||||
return;
|
return;
|
||||||
@@ -1185,28 +1184,26 @@ void MPD::Connection::GetDirectory(const std::string &path, ItemList &v)
|
|||||||
case MPD_ENTITY_TYPE_DIRECTORY:
|
case MPD_ENTITY_TYPE_DIRECTORY:
|
||||||
it.name = mpd_directory_get_path(mpd_entity_get_directory(item));
|
it.name = mpd_directory_get_path(mpd_entity_get_directory(item));
|
||||||
it.type = itDirectory;
|
it.type = itDirectory;
|
||||||
goto WRITE;
|
break;
|
||||||
case MPD_ENTITY_TYPE_SONG:
|
case MPD_ENTITY_TYPE_SONG:
|
||||||
it.song = Song(mpd_song_dup(mpd_entity_get_song(item)));
|
it.song = Song(mpd_song_dup(mpd_entity_get_song(item)));
|
||||||
it.type = itSong;
|
it.type = itSong;
|
||||||
goto WRITE;
|
break;
|
||||||
case MPD_ENTITY_TYPE_PLAYLIST:
|
case MPD_ENTITY_TYPE_PLAYLIST:
|
||||||
it.name = mpd_playlist_get_path(mpd_entity_get_playlist(item));
|
it.name = mpd_playlist_get_path(mpd_entity_get_playlist(item));
|
||||||
it.type = itPlaylist;
|
it.type = itPlaylist;
|
||||||
goto WRITE;
|
|
||||||
WRITE:
|
|
||||||
v.push_back(it);
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
assert(false);
|
||||||
}
|
}
|
||||||
mpd_entity_free(item);
|
mpd_entity_free(item);
|
||||||
|
f(std::move(it));
|
||||||
}
|
}
|
||||||
mpd_response_finish(itsConnection);
|
mpd_response_finish(itsConnection);
|
||||||
GoIdle();
|
GoIdle();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MPD::Connection::GetDirectoryRecursive(const std::string &path, SongList &v)
|
void MPD::Connection::GetDirectoryRecursive(const std::string &path, std::function<void(MPD::Song &&)> f)
|
||||||
{
|
{
|
||||||
if (!itsConnection)
|
if (!itsConnection)
|
||||||
return;
|
return;
|
||||||
@@ -1214,20 +1211,7 @@ void MPD::Connection::GetDirectoryRecursive(const std::string &path, SongList &v
|
|||||||
GoBusy();
|
GoBusy();
|
||||||
mpd_send_list_all_meta(itsConnection, path.c_str());
|
mpd_send_list_all_meta(itsConnection, path.c_str());
|
||||||
while (mpd_song *s = mpd_recv_song(itsConnection))
|
while (mpd_song *s = mpd_recv_song(itsConnection))
|
||||||
v.push_back(Song(s));
|
f(Song(s));
|
||||||
mpd_response_finish(itsConnection);
|
|
||||||
GoIdle();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MPD::Connection::GetSongs(const std::string &path, SongList &v)
|
|
||||||
{
|
|
||||||
if (!itsConnection)
|
|
||||||
return;
|
|
||||||
assert(!isCommandsListEnabled);
|
|
||||||
GoBusy();
|
|
||||||
mpd_send_list_meta(itsConnection, path.c_str());
|
|
||||||
while (mpd_song *s = mpd_recv_song(itsConnection))
|
|
||||||
v.push_back(Song(s));
|
|
||||||
mpd_response_finish(itsConnection);
|
mpd_response_finish(itsConnection);
|
||||||
GoIdle();
|
GoIdle();
|
||||||
}
|
}
|
||||||
@@ -1248,7 +1232,7 @@ void MPD::Connection::GetDirectories(const std::string &path, TagList &v)
|
|||||||
GoIdle();
|
GoIdle();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MPD::Connection::GetOutputs(OutputList &v)
|
void MPD::Connection::GetOutputs(std::function<void(Output &&)> f)
|
||||||
{
|
{
|
||||||
if (!itsConnection)
|
if (!itsConnection)
|
||||||
return;
|
return;
|
||||||
@@ -1257,7 +1241,7 @@ void MPD::Connection::GetOutputs(OutputList &v)
|
|||||||
mpd_send_outputs(itsConnection);
|
mpd_send_outputs(itsConnection);
|
||||||
while (mpd_output *output = mpd_recv_output(itsConnection))
|
while (mpd_output *output = mpd_recv_output(itsConnection))
|
||||||
{
|
{
|
||||||
v.push_back(std::make_pair(mpd_output_get_name(output), mpd_output_get_enabled(output)));
|
f(Output(mpd_output_get_name(output), mpd_output_get_enabled(output)));
|
||||||
mpd_output_free(output);
|
mpd_output_free(output);
|
||||||
}
|
}
|
||||||
mpd_response_finish(itsConnection);
|
mpd_response_finish(itsConnection);
|
||||||
@@ -1296,7 +1280,7 @@ bool MPD::Connection::DisableOutput(int id)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MPD::Connection::GetURLHandlers(TagList &v)
|
void MPD::Connection::GetURLHandlers(std::function<void(std::string &&)> f)
|
||||||
{
|
{
|
||||||
if (!itsConnection)
|
if (!itsConnection)
|
||||||
return;
|
return;
|
||||||
@@ -1305,14 +1289,14 @@ void MPD::Connection::GetURLHandlers(TagList &v)
|
|||||||
mpd_send_list_url_schemes(itsConnection);
|
mpd_send_list_url_schemes(itsConnection);
|
||||||
while (mpd_pair *handler = mpd_recv_pair_named(itsConnection, "handler"))
|
while (mpd_pair *handler = mpd_recv_pair_named(itsConnection, "handler"))
|
||||||
{
|
{
|
||||||
v.push_back(handler->value);
|
f(handler->value);
|
||||||
mpd_return_pair(itsConnection, handler);
|
mpd_return_pair(itsConnection, handler);
|
||||||
}
|
}
|
||||||
mpd_response_finish(itsConnection);
|
mpd_response_finish(itsConnection);
|
||||||
GoIdle();
|
GoIdle();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MPD::Connection::GetTagTypes(TagList &v)
|
void MPD::Connection::GetTagTypes(std::function<void(std::string &&)> f)
|
||||||
{
|
{
|
||||||
if (!itsConnection)
|
if (!itsConnection)
|
||||||
return;
|
return;
|
||||||
@@ -1321,7 +1305,7 @@ void MPD::Connection::GetTagTypes(TagList &v)
|
|||||||
mpd_send_list_tag_types(itsConnection);
|
mpd_send_list_tag_types(itsConnection);
|
||||||
while (mpd_pair *tag_type = mpd_recv_pair_named(itsConnection, "tagtype"))
|
while (mpd_pair *tag_type = mpd_recv_pair_named(itsConnection, "tagtype"))
|
||||||
{
|
{
|
||||||
v.push_back(tag_type->value);
|
f(tag_type->value);
|
||||||
mpd_return_pair(itsConnection, tag_type);
|
mpd_return_pair(itsConnection, tag_type);
|
||||||
}
|
}
|
||||||
mpd_response_finish(itsConnection);
|
mpd_response_finish(itsConnection);
|
||||||
|
|||||||
31
src/mpdpp.h
31
src/mpdpp.h
@@ -59,7 +59,18 @@ namespace MPD
|
|||||||
bool Outputs:1;
|
bool Outputs:1;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::pair<std::string, bool> Output;
|
struct Output
|
||||||
|
{
|
||||||
|
Output(const std::string &name_, bool enabled) : m_name(name_), m_enabled(enabled) { }
|
||||||
|
|
||||||
|
const std::string &name() const { return m_name; }
|
||||||
|
bool isEnabled() const { return m_enabled; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::string m_name;
|
||||||
|
bool m_enabled;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
typedef std::vector<Item> ItemList;
|
typedef std::vector<Item> ItemList;
|
||||||
typedef std::vector<Song> SongList;
|
typedef std::vector<Song> SongList;
|
||||||
@@ -142,7 +153,7 @@ namespace MPD
|
|||||||
unsigned long DBPlayTime() const { return itsStats ? mpd_stats_get_db_play_time(itsStats) : 0; }
|
unsigned long DBPlayTime() const { return itsStats ? mpd_stats_get_db_play_time(itsStats) : 0; }
|
||||||
|
|
||||||
size_t GetPlaylistLength() const { return itsCurrentStatus ? mpd_status_get_queue_length(itsCurrentStatus) : 0; }
|
size_t GetPlaylistLength() const { return itsCurrentStatus ? mpd_status_get_queue_length(itsCurrentStatus) : 0; }
|
||||||
void GetPlaylistChanges(unsigned, SongList &);
|
void GetPlaylistChanges(unsigned, std::function<void(Song &&)> f);
|
||||||
|
|
||||||
const std::string & GetErrorMessage() const { return itsErrorMessage; }
|
const std::string & GetErrorMessage() const { return itsErrorMessage; }
|
||||||
|
|
||||||
@@ -150,7 +161,7 @@ namespace MPD
|
|||||||
int GetCurrentlyPlayingSongPos() const;
|
int GetCurrentlyPlayingSongPos() const;
|
||||||
int GetCurrentSongPos() const;
|
int GetCurrentSongPos() const;
|
||||||
Song GetSong(const std::string &);
|
Song GetSong(const std::string &);
|
||||||
void GetPlaylistContent(const std::string &, SongList &);
|
void GetPlaylistContent(const std::string &, std::function<void(Song &&)> f);
|
||||||
|
|
||||||
void GetSupportedExtensions(std::set<std::string> &);
|
void GetSupportedExtensions(std::set<std::string> &);
|
||||||
|
|
||||||
@@ -191,22 +202,22 @@ namespace MPD
|
|||||||
void AddSearch(mpd_tag_type, const std::string &) const;
|
void AddSearch(mpd_tag_type, const std::string &) const;
|
||||||
void AddSearchAny(const std::string &str) const;
|
void AddSearchAny(const std::string &str) const;
|
||||||
void AddSearchURI(const std::string &str) const;
|
void AddSearchURI(const std::string &str) const;
|
||||||
void CommitSearch(SongList &);
|
void CommitSearchSongs(std::function<void(Song &&)> f);
|
||||||
void CommitSearch(TagList &);
|
void CommitSearchTags(std::function<void(std::string &&)> f);
|
||||||
|
|
||||||
void GetPlaylists(TagList &);
|
void GetPlaylists(TagList &);
|
||||||
void GetList(TagList &, mpd_tag_type);
|
void GetList(TagList &, mpd_tag_type);
|
||||||
void GetDirectory(const std::string &, ItemList &);
|
void GetDirectory(const std::string &, std::function<void(Item &&)> f);
|
||||||
void GetDirectoryRecursive(const std::string &, SongList &);
|
void GetDirectoryRecursive(const std::string &, std::function<void(Song &&)> f);
|
||||||
void GetSongs(const std::string &, SongList &);
|
void GetSongs(const std::string &, SongList &);
|
||||||
void GetDirectories(const std::string &, TagList &);
|
void GetDirectories(const std::string &, TagList &);
|
||||||
|
|
||||||
void GetOutputs(OutputList &);
|
void GetOutputs(std::function<void(Output &&)> f);
|
||||||
bool EnableOutput(int);
|
bool EnableOutput(int);
|
||||||
bool DisableOutput(int);
|
bool DisableOutput(int);
|
||||||
|
|
||||||
void GetURLHandlers(TagList &v);
|
void GetURLHandlers(std::function<void(std::string &&)> f);
|
||||||
void GetTagTypes(TagList &v);
|
void GetTagTypes(std::function<void(std::string &&)> f);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void GoIdle();
|
void GoIdle();
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ void Outputs::Init()
|
|||||||
w->CyclicScrolling(Config.use_cyclic_scrolling);
|
w->CyclicScrolling(Config.use_cyclic_scrolling);
|
||||||
w->CenteredCursor(Config.centered_cursor);
|
w->CenteredCursor(Config.centered_cursor);
|
||||||
w->HighlightColor(Config.main_highlight_color);
|
w->HighlightColor(Config.main_highlight_color);
|
||||||
w->SetItemDisplayer(Display::Pairs);
|
w->SetItemDisplayer(Display::Outputs);
|
||||||
|
|
||||||
isInitialized = 1;
|
isInitialized = 1;
|
||||||
FetchList();
|
FetchList();
|
||||||
@@ -83,15 +83,15 @@ std::basic_string<my_char_t> Outputs::Title()
|
|||||||
|
|
||||||
void Outputs::EnterPressed()
|
void Outputs::EnterPressed()
|
||||||
{
|
{
|
||||||
if (w->Current().second)
|
if (w->Current().isEnabled())
|
||||||
{
|
{
|
||||||
if (Mpd.DisableOutput(w->Choice()))
|
if (Mpd.DisableOutput(w->Choice()))
|
||||||
ShowMessage("Output \"%s\" disabled", w->Current().first.c_str());
|
ShowMessage("Output \"%s\" disabled", w->Current().name().c_str());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (Mpd.EnableOutput(w->Choice()))
|
if (Mpd.EnableOutput(w->Choice()))
|
||||||
ShowMessage("Output \"%s\" enabled", w->Current().first.c_str());
|
ShowMessage("Output \"%s\" enabled", w->Current().name().c_str());
|
||||||
}
|
}
|
||||||
if (!Mpd.SupportsIdle())
|
if (!Mpd.SupportsIdle())
|
||||||
FetchList();
|
FetchList();
|
||||||
@@ -115,11 +115,10 @@ void Outputs::FetchList()
|
|||||||
{
|
{
|
||||||
if (!isInitialized)
|
if (!isInitialized)
|
||||||
return;
|
return;
|
||||||
MPD::OutputList ol;
|
|
||||||
Mpd.GetOutputs(ol);
|
|
||||||
w->Clear();
|
w->Clear();
|
||||||
for (MPD::OutputList::const_iterator it = ol.begin(); it != ol.end(); ++it)
|
Mpd.GetOutputs([this](MPD::Output &&o) {
|
||||||
w->AddOption(*it, it->second);
|
w->AddOption(o, o.isEnabled());
|
||||||
|
});
|
||||||
if (myScreen == this)
|
if (myScreen == this)
|
||||||
w->Refresh();
|
w->Refresh();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -605,3 +605,11 @@ void Playlist::SetSelectedItemsPriority(int prio)
|
|||||||
if (Mpd.CommitCommandsList())
|
if (Mpd.CommitCommandsList())
|
||||||
ShowMessage("Priority set");
|
ShowMessage("Priority set");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Playlist::checkForSong (const MPD::Song &s)
|
||||||
|
{
|
||||||
|
for (size_t i = 0; i < Items->Size(); ++i)
|
||||||
|
if (s.getHash() == (*Items)[i].getHash())
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|||||||
@@ -79,6 +79,8 @@ class Playlist : public Screen<Window>
|
|||||||
|
|
||||||
void SetSelectedItemsPriority(int prio);
|
void SetSelectedItemsPriority(int prio);
|
||||||
|
|
||||||
|
bool checkForSong(const MPD::Song &s);
|
||||||
|
|
||||||
static std::string SongToString(const MPD::Song &, void *);
|
static std::string SongToString(const MPD::Song &, void *);
|
||||||
static std::string SongInColumnsToString(const MPD::Song &, void *);
|
static std::string SongInColumnsToString(const MPD::Song &, void *);
|
||||||
|
|
||||||
|
|||||||
@@ -146,30 +146,20 @@ void PlaylistEditor::Update()
|
|||||||
if (!Playlists->Empty() && Content->ReallyEmpty())
|
if (!Playlists->Empty() && Content->ReallyEmpty())
|
||||||
{
|
{
|
||||||
Content->Reset();
|
Content->Reset();
|
||||||
MPD::SongList list;
|
size_t plsize = 0;
|
||||||
Mpd.GetPlaylistContent(locale_to_utf_cpy(Playlists->Current()), list);
|
Mpd.GetPlaylistContent(locale_to_utf_cpy(Playlists->Current()), [this, &plsize](MPD::Song &&s) {
|
||||||
if (!list.empty())
|
Content->AddOption(s, myPlaylist->checkForSong(s));
|
||||||
|
++plsize;
|
||||||
|
});
|
||||||
|
if (plsize > 0)
|
||||||
{
|
{
|
||||||
std::string title = Config.titles_visibility ? "Playlist's content (" + IntoStr(list.size()) + " item" + (list.size() == 1 ? ")" : "s)") : "";
|
std::string title = Config.titles_visibility ? "Playlist content (" + IntoStr(plsize) + " item" + (plsize == 1 ? ")" : "s)") : "";
|
||||||
title.resize(Content->GetWidth());
|
title.resize(Content->GetWidth());
|
||||||
Content->SetTitle(title);
|
Content->SetTitle(title);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
Content->SetTitle(Config.titles_visibility ? "Playlist's content" : "");
|
Content->SetTitle(Config.titles_visibility ? "Playlist content" : "");
|
||||||
bool bold = 0;
|
|
||||||
for (auto it = list.begin(); it != list.end(); ++it)
|
|
||||||
{
|
|
||||||
for (size_t j = 0; j < myPlaylist->Items->Size(); ++j)
|
|
||||||
{
|
|
||||||
if (it->getHash() == myPlaylist->Items->at(j).getHash())
|
|
||||||
{
|
|
||||||
bold = 1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Content->AddOption(*it, bold);
|
|
||||||
bold = 0;
|
|
||||||
}
|
|
||||||
Content->Window::Clear();
|
Content->Window::Clear();
|
||||||
Content->Display();
|
Content->Display();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -187,7 +187,7 @@ void SearchEngine::EnterPressed()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
bool res = myPlaylist->Add(w->Current().song(), 1, 1);
|
bool res = myPlaylist->Add(w->Current().song(), w->isBold(), 1);
|
||||||
w->Bold(w->Choice(), res);
|
w->Bold(w->Choice(), res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -207,7 +207,7 @@ void SearchEngine::SpacePressed()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool res = myPlaylist->Add(w->Current().song(), 0, 0);
|
bool res = myPlaylist->Add(w->Current().song(), w->isBold(), 0);
|
||||||
w->Bold(w->Choice(), res);
|
w->Bold(w->Choice(), res);
|
||||||
w->Scroll(wDown);
|
w->Scroll(wDown);
|
||||||
}
|
}
|
||||||
@@ -383,16 +383,19 @@ void SearchEngine::Search()
|
|||||||
Mpd.AddSearch(MPD_TAG_DATE, itsConstraints[9]);
|
Mpd.AddSearch(MPD_TAG_DATE, itsConstraints[9]);
|
||||||
if (!itsConstraints[10].empty())
|
if (!itsConstraints[10].empty())
|
||||||
Mpd.AddSearch(MPD_TAG_COMMENT, itsConstraints[10]);
|
Mpd.AddSearch(MPD_TAG_COMMENT, itsConstraints[10]);
|
||||||
MPD::SongList results;
|
Mpd.CommitSearchSongs([this](MPD::Song &&s) {
|
||||||
Mpd.CommitSearch(results);
|
w->AddOption(s);
|
||||||
for (auto it = results.begin(); it != results.end(); ++it)
|
});
|
||||||
w->AddOption(*it);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
MPD::SongList list;
|
MPD::SongList list;
|
||||||
if (Config.search_in_db)
|
if (Config.search_in_db)
|
||||||
Mpd.GetDirectoryRecursive("/", list);
|
{
|
||||||
|
Mpd.GetDirectoryRecursive("/", [&list](MPD::Song &&s) {
|
||||||
|
list.push_back(s);
|
||||||
|
});
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
list.reserve(myPlaylist->Items->Size());
|
list.reserve(myPlaylist->Items->Size());
|
||||||
|
|||||||
@@ -35,8 +35,12 @@ void ServerInfo::Init()
|
|||||||
SetDimensions();
|
SetDimensions();
|
||||||
w = new Scrollpad((COLS-itsWidth)/2, (MainHeight-itsHeight)/2+MainStartY, itsWidth, itsHeight, "MPD server info", Config.main_color, Config.window_border);
|
w = new Scrollpad((COLS-itsWidth)/2, (MainHeight-itsHeight)/2+MainStartY, itsWidth, itsHeight, "MPD server info", Config.main_color, Config.window_border);
|
||||||
|
|
||||||
Mpd.GetURLHandlers(itsURLHandlers);
|
Mpd.GetURLHandlers([this](std::string &&handler) {
|
||||||
Mpd.GetTagTypes(itsTagTypes);
|
itsURLHandlers.push_back(handler);
|
||||||
|
});
|
||||||
|
Mpd.GetTagTypes([this](std::string &&tag_type) {
|
||||||
|
itsTagTypes.push_back(tag_type);
|
||||||
|
});
|
||||||
|
|
||||||
isInitialized = 1;
|
isInitialized = 1;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -222,31 +222,28 @@ void NcmpcppStatusChanged(MPD::Connection *, MPD::StatusChanges changed, void *)
|
|||||||
|
|
||||||
if (changed.Playlist)
|
if (changed.Playlist)
|
||||||
{
|
{
|
||||||
bool was_filtered = myPlaylist->Items->isFiltered();
|
bool is_filtered = myPlaylist->Items->isFiltered();
|
||||||
myPlaylist->Items->ShowAll();
|
myPlaylist->Items->ShowAll();
|
||||||
MPD::SongList list;
|
|
||||||
|
|
||||||
size_t playlist_length = Mpd.GetPlaylistLength();
|
size_t playlist_length = Mpd.GetPlaylistLength();
|
||||||
if (playlist_length < myPlaylist->Items->Size())
|
if (playlist_length < myPlaylist->Items->Size())
|
||||||
myPlaylist->Items->ResizeList(playlist_length);
|
myPlaylist->Items->ResizeList(playlist_length);
|
||||||
|
|
||||||
Mpd.GetPlaylistChanges(Mpd.GetOldPlaylistID(), list);
|
Mpd.GetPlaylistChanges(Mpd.GetOldPlaylistID(), [](MPD::Song &&s) {
|
||||||
myPlaylist->Items->Reserve(playlist_length);
|
int pos = s.getPosition();
|
||||||
for (MPD::SongList::const_iterator it = list.begin(); it != list.end(); ++it)
|
|
||||||
{
|
|
||||||
int pos = it->getPosition();
|
|
||||||
if (pos < int(myPlaylist->Items->Size()))
|
if (pos < int(myPlaylist->Items->Size()))
|
||||||
{
|
{
|
||||||
// if song's already in playlist, replace it with a new one
|
// if song's already in playlist, replace it with a new one
|
||||||
myPlaylist->Items->at(pos) = *it;
|
myPlaylist->Items->at(pos) = s;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// otherwise just add it to playlist
|
// otherwise just add it to playlist
|
||||||
myPlaylist->Items->AddOption(*it);
|
myPlaylist->Items->AddOption(s);
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
if (was_filtered)
|
|
||||||
|
if (is_filtered)
|
||||||
{
|
{
|
||||||
myPlaylist->ApplyFilter(myPlaylist->Items->GetFilter());
|
myPlaylist->ApplyFilter(myPlaylist->Items->GetFilter());
|
||||||
if (myPlaylist->Items->Empty())
|
if (myPlaylist->Items->Empty())
|
||||||
|
|||||||
@@ -236,11 +236,12 @@ void Visualizer::FindOutputID()
|
|||||||
itsOutputID = -1;
|
itsOutputID = -1;
|
||||||
if (!Config.visualizer_output_name.empty())
|
if (!Config.visualizer_output_name.empty())
|
||||||
{
|
{
|
||||||
MPD::OutputList outputs;
|
size_t i = 0;
|
||||||
Mpd.GetOutputs(outputs);
|
Mpd.GetOutputs([this, &i](MPD::Output &&o) {
|
||||||
for (unsigned i = 0; i < outputs.size(); ++i)
|
if (o.name() == Config.visualizer_output_name)
|
||||||
if (outputs[i].first == Config.visualizer_output_name)
|
|
||||||
itsOutputID = i;
|
itsOutputID = i;
|
||||||
|
++i;
|
||||||
|
});
|
||||||
if (itsOutputID == -1)
|
if (itsOutputID == -1)
|
||||||
ShowMessage("There is no output named \"%s\"", Config.visualizer_output_name.c_str());
|
ShowMessage("There is no output named \"%s\"", Config.visualizer_output_name.c_str());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user