mpdpp: make all consumers take values, not rvalue references
This commit is contained in:
@@ -1263,7 +1263,7 @@ void EditLibraryTag::run()
|
|||||||
assert(set);
|
assert(set);
|
||||||
bool success = true;
|
bool success = true;
|
||||||
std::string dir_to_update;
|
std::string dir_to_update;
|
||||||
Mpd.CommitSearchSongs([set, &dir_to_update, &new_tag, &success](MPD::Song &&s) {
|
Mpd.CommitSearchSongs([set, &dir_to_update, &new_tag, &success](MPD::Song s) {
|
||||||
if (!success)
|
if (!success)
|
||||||
return;
|
return;
|
||||||
MPD::MutableSong ms = s;
|
MPD::MutableSong ms = s;
|
||||||
|
|||||||
@@ -337,18 +337,14 @@ MPD::SongList Browser::getSelectedSongs()
|
|||||||
else
|
else
|
||||||
# endif // !WIN32
|
# endif // !WIN32
|
||||||
{
|
{
|
||||||
Mpd.GetDirectoryRecursive(item.name, [&result](MPD::Song &&s) {
|
Mpd.GetDirectoryRecursive(item.name, vectorMoveInserter(result));
|
||||||
result.push_back(s);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (item.type == itSong)
|
else if (item.type == itSong)
|
||||||
result.push_back(*item.song);
|
result.push_back(*item.song);
|
||||||
else if (item.type == itPlaylist)
|
else if (item.type == itPlaylist)
|
||||||
{
|
{
|
||||||
Mpd.GetPlaylistContent(item.name, [&result](MPD::Song &&s) {
|
Mpd.GetPlaylistContent(item.name, vectorMoveInserter(result));
|
||||||
result.push_back(s);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
for (auto it = w.begin(); it != w.end(); ++it)
|
for (auto it = w.begin(); it != w.end(); ++it)
|
||||||
@@ -415,9 +411,7 @@ void Browser::GetDirectory(std::string dir, std::string subdir)
|
|||||||
if (isLocal())
|
if (isLocal())
|
||||||
GetLocalDirectory(list, itsBrowsedDir, false);
|
GetLocalDirectory(list, itsBrowsedDir, false);
|
||||||
else
|
else
|
||||||
Mpd.GetDirectory(dir, [&list](MPD::Item &&item) {
|
Mpd.GetDirectory(dir, vectorMoveInserter(list));
|
||||||
list.push_back(item);
|
|
||||||
});
|
|
||||||
# else
|
# else
|
||||||
list = Mpd.GetDirectory(dir);
|
list = Mpd.GetDirectory(dir);
|
||||||
# endif // !WIN32
|
# endif // !WIN32
|
||||||
|
|||||||
@@ -334,6 +334,12 @@ void clearPlaylist(NC::Menu<MPD::Song> &m, F delete_fun, G clear_fun)
|
|||||||
clear_fun(Mpd);
|
clear_fun(Mpd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename ItemT>
|
||||||
|
std::function<void (ItemT)> vectorMoveInserter(std::vector<ItemT> &v)
|
||||||
|
{
|
||||||
|
return [&](ItemT item) { v.push_back(std::move(item)); };
|
||||||
|
}
|
||||||
|
|
||||||
template <typename Iterator> std::string getSharedDirectory(Iterator first, Iterator last)
|
template <typename Iterator> std::string getSharedDirectory(Iterator first, Iterator last)
|
||||||
{
|
{
|
||||||
assert(first != last);
|
assert(first != last);
|
||||||
|
|||||||
@@ -256,7 +256,7 @@ void MediaLibrary::update()
|
|||||||
Albums.clearSearchResults();
|
Albums.clearSearchResults();
|
||||||
m_albums_update_request = false;
|
m_albums_update_request = false;
|
||||||
std::map<std::tuple<std::string, std::string, std::string>, time_t> albums;
|
std::map<std::tuple<std::string, std::string, std::string>, time_t> albums;
|
||||||
Mpd.GetDirectoryRecursive("/", [&albums](MPD::Song &&s) {
|
Mpd.GetDirectoryRecursive("/", [&albums](MPD::Song s) {
|
||||||
unsigned idx = 0;
|
unsigned idx = 0;
|
||||||
std::string tag = s.get(Config.media_lib_primary_tag, idx);
|
std::string tag = s.get(Config.media_lib_primary_tag, idx);
|
||||||
do
|
do
|
||||||
@@ -298,7 +298,7 @@ void MediaLibrary::update()
|
|||||||
Tags.clearSearchResults();
|
Tags.clearSearchResults();
|
||||||
m_tags_update_request = false;
|
m_tags_update_request = false;
|
||||||
std::map<std::string, time_t> tags;
|
std::map<std::string, time_t> tags;
|
||||||
Mpd.GetDirectoryRecursive("/", [&tags](MPD::Song &&s) {
|
Mpd.GetDirectoryRecursive("/", [&tags](MPD::Song s) {
|
||||||
unsigned idx = 0;
|
unsigned idx = 0;
|
||||||
std::string tag = s.get(Config.media_lib_primary_tag, idx);
|
std::string tag = s.get(Config.media_lib_primary_tag, idx);
|
||||||
do
|
do
|
||||||
@@ -336,7 +336,7 @@ void MediaLibrary::update()
|
|||||||
Mpd.StartSearch(true);
|
Mpd.StartSearch(true);
|
||||||
Mpd.AddSearch(Config.media_lib_primary_tag, primary_tag);
|
Mpd.AddSearch(Config.media_lib_primary_tag, primary_tag);
|
||||||
std::map<std::tuple<std::string, std::string>, time_t> albums;
|
std::map<std::tuple<std::string, std::string>, time_t> albums;
|
||||||
Mpd.CommitSearchSongs([&albums](MPD::Song &&s) {
|
Mpd.CommitSearchSongs([&albums](MPD::Song s) {
|
||||||
auto key = std::make_tuple(s.getAlbum(), s.getDate());
|
auto key = std::make_tuple(s.getAlbum(), s.getDate());
|
||||||
auto it = albums.find(key);
|
auto it = albums.find(key);
|
||||||
if (it == albums.end())
|
if (it == albums.end())
|
||||||
@@ -388,7 +388,7 @@ void MediaLibrary::update()
|
|||||||
}
|
}
|
||||||
withUnfilteredMenuReapplyFilter(Songs, [this, &album]() {
|
withUnfilteredMenuReapplyFilter(Songs, [this, &album]() {
|
||||||
size_t idx = 0;
|
size_t idx = 0;
|
||||||
Mpd.CommitSearchSongs([this, &idx](MPD::Song &&s) {
|
Mpd.CommitSearchSongs([this, &idx](MPD::Song s) {
|
||||||
bool is_playlist = myPlaylist->checkForSong(s);
|
bool is_playlist = myPlaylist->checkForSong(s);
|
||||||
if (idx < Songs.size())
|
if (idx < Songs.size())
|
||||||
{
|
{
|
||||||
@@ -714,9 +714,7 @@ MPD::SongList MediaLibrary::getSelectedSongs()
|
|||||||
auto tag_handler = [&result](const std::string &tag) {
|
auto tag_handler = [&result](const std::string &tag) {
|
||||||
Mpd.StartSearch(true);
|
Mpd.StartSearch(true);
|
||||||
Mpd.AddSearch(Config.media_lib_primary_tag, tag);
|
Mpd.AddSearch(Config.media_lib_primary_tag, tag);
|
||||||
Mpd.CommitSearchSongs([&result](MPD::Song &&s) {
|
Mpd.CommitSearchSongs(vectorMoveInserter(result));
|
||||||
result.push_back(s);
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
for (auto it = Tags.begin(); it != Tags.end(); ++it)
|
for (auto it = Tags.begin(); it != Tags.end(); ++it)
|
||||||
if (it->isSelected())
|
if (it->isSelected())
|
||||||
@@ -741,9 +739,7 @@ MPD::SongList MediaLibrary::getSelectedSongs()
|
|||||||
Mpd.AddSearch(MPD_TAG_ALBUM, sc.entry().album());
|
Mpd.AddSearch(MPD_TAG_ALBUM, sc.entry().album());
|
||||||
Mpd.AddSearch(MPD_TAG_DATE, sc.entry().date());
|
Mpd.AddSearch(MPD_TAG_DATE, sc.entry().date());
|
||||||
size_t begin = result.size();
|
size_t begin = result.size();
|
||||||
Mpd.CommitSearchSongs([&result](MPD::Song &&s) {
|
Mpd.CommitSearchSongs(vectorMoveInserter(result));
|
||||||
result.push_back(s);
|
|
||||||
});
|
|
||||||
std::sort(result.begin()+begin, result.end(), SortSongs(false));
|
std::sort(result.begin()+begin, result.end(), SortSongs(false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -640,7 +640,7 @@ void Connection::Add(const std::string &path)
|
|||||||
bool Connection::AddRandomTag(mpd_tag_type tag, size_t number)
|
bool Connection::AddRandomTag(mpd_tag_type tag, size_t number)
|
||||||
{
|
{
|
||||||
StringList tags;
|
StringList tags;
|
||||||
GetList(tag, [&tags](std::string &&tag_name) {
|
GetList(tag, [&tags](std::string tag_name) {
|
||||||
tags.push_back(tag_name);
|
tags.push_back(tag_name);
|
||||||
});
|
});
|
||||||
if (number > tags.size())
|
if (number > tags.size())
|
||||||
@@ -658,7 +658,7 @@ bool Connection::AddRandomTag(mpd_tag_type tag, size_t number)
|
|||||||
StartSearch(1);
|
StartSearch(1);
|
||||||
AddSearch(tag, *it++);
|
AddSearch(tag, *it++);
|
||||||
SongList songs;
|
SongList songs;
|
||||||
CommitSearchSongs([&songs](MPD::Song &&s) {
|
CommitSearchSongs([&songs](MPD::Song s) {
|
||||||
songs.push_back(s);
|
songs.push_back(s);
|
||||||
});
|
});
|
||||||
StartCommandsList();
|
StartCommandsList();
|
||||||
|
|||||||
@@ -148,10 +148,10 @@ class Connection
|
|||||||
{
|
{
|
||||||
typedef void (*ErrorHandler) (Connection *, int, const char *, void *);
|
typedef void (*ErrorHandler) (Connection *, int, const char *, void *);
|
||||||
|
|
||||||
typedef std::function<void(Item &&)> ItemConsumer;
|
typedef std::function<void(Item)> ItemConsumer;
|
||||||
typedef std::function<void(Output &&)> OutputConsumer;
|
typedef std::function<void(Output)> OutputConsumer;
|
||||||
typedef std::function<void(Song &&)> SongConsumer;
|
typedef std::function<void(Song)> SongConsumer;
|
||||||
typedef std::function<void(std::string &&)> StringConsumer;
|
typedef std::function<void(std::string)> StringConsumer;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Connection();
|
Connection();
|
||||||
|
|||||||
@@ -200,7 +200,7 @@ void MutableSong::clearModifications()
|
|||||||
m_tags.clear();
|
m_tags.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MutableSong::replaceTag(mpd_tag_type tag_type, std::string &&orig_value, const std::string &value, unsigned idx)
|
void MutableSong::replaceTag(mpd_tag_type tag_type, std::string orig_value, const std::string &value, unsigned idx)
|
||||||
{
|
{
|
||||||
Tag tag(tag_type, idx);
|
Tag tag(tag_type, idx);
|
||||||
if (value == orig_value)
|
if (value == orig_value)
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ private:
|
|||||||
unsigned m_idx;
|
unsigned m_idx;
|
||||||
};
|
};
|
||||||
|
|
||||||
void replaceTag(mpd_tag_type tag_type, std::string &&orig_value,
|
void replaceTag(mpd_tag_type tag_type, std::string orig_value,
|
||||||
const std::string &value, unsigned idx);
|
const std::string &value, unsigned idx);
|
||||||
|
|
||||||
template <typename F>
|
template <typename F>
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ void Outputs::mouseButtonPressed(MEVENT me)
|
|||||||
void Outputs::FetchList()
|
void Outputs::FetchList()
|
||||||
{
|
{
|
||||||
w.clear();
|
w.clear();
|
||||||
Mpd.GetOutputs([this](MPD::Output &&output) {
|
Mpd.GetOutputs([this](MPD::Output output) {
|
||||||
w.addItem(output, output.isEnabled());
|
w.addItem(output, output.isEnabled());
|
||||||
});
|
});
|
||||||
if (myScreen == this)
|
if (myScreen == this)
|
||||||
|
|||||||
@@ -133,7 +133,7 @@ void PlaylistEditor::update()
|
|||||||
Playlists.clearSearchResults();
|
Playlists.clearSearchResults();
|
||||||
withUnfilteredMenuReapplyFilter(Playlists, [this]() {
|
withUnfilteredMenuReapplyFilter(Playlists, [this]() {
|
||||||
size_t idx = 0;
|
size_t idx = 0;
|
||||||
Mpd.GetPlaylists([this, &idx](std::string &&playlist) {
|
Mpd.GetPlaylists([this, &idx](std::string playlist) {
|
||||||
if (idx < Playlists.size())
|
if (idx < Playlists.size())
|
||||||
Playlists[idx].value() = playlist;
|
Playlists[idx].value() = playlist;
|
||||||
else
|
else
|
||||||
@@ -154,7 +154,7 @@ void PlaylistEditor::update()
|
|||||||
Content.clearSearchResults();
|
Content.clearSearchResults();
|
||||||
withUnfilteredMenuReapplyFilter(Content, [this]() {
|
withUnfilteredMenuReapplyFilter(Content, [this]() {
|
||||||
size_t idx = 0;
|
size_t idx = 0;
|
||||||
Mpd.GetPlaylistContent(Playlists.current().value(), [this, &idx](MPD::Song &&s) {
|
Mpd.GetPlaylistContent(Playlists.current().value(), [this, &idx](MPD::Song s) {
|
||||||
if (idx < Content.size())
|
if (idx < Content.size())
|
||||||
{
|
{
|
||||||
Content[idx].value() = s;
|
Content[idx].value() = s;
|
||||||
@@ -459,9 +459,7 @@ MPD::SongList PlaylistEditor::getSelectedSongs()
|
|||||||
if (it->isSelected())
|
if (it->isSelected())
|
||||||
{
|
{
|
||||||
any_selected = true;
|
any_selected = true;
|
||||||
Mpd.GetPlaylistContent(it->value(), [&result](MPD::Song &&s) {
|
Mpd.GetPlaylistContent(it->value(), vectorMoveInserter(result));
|
||||||
result.push_back(s);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// we don't check for empty result here as it's possible that
|
// we don't check for empty result here as it's possible that
|
||||||
|
|||||||
@@ -434,7 +434,7 @@ 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.CommitSearchSongs([this](MPD::Song &&s) {
|
Mpd.CommitSearchSongs([this](MPD::Song s) {
|
||||||
w.addItem(s);
|
w.addItem(s);
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
@@ -442,9 +442,7 @@ void SearchEngine::Search()
|
|||||||
|
|
||||||
MPD::SongList list;
|
MPD::SongList list;
|
||||||
if (Config.search_in_db)
|
if (Config.search_in_db)
|
||||||
Mpd.GetDirectoryRecursive("/", [&list](MPD::Song &&s) {
|
Mpd.GetDirectoryRecursive("/", vectorMoveInserter(list));
|
||||||
list.push_back(s);
|
|
||||||
});
|
|
||||||
else
|
else
|
||||||
list.insert(list.end(), myPlaylist->main().beginV(), myPlaylist->main().endV());
|
list.insert(list.end(), myPlaylist->main().beginV(), myPlaylist->main().endV());
|
||||||
|
|
||||||
|
|||||||
@@ -198,7 +198,7 @@ void SelectedItemsAdder::populatePlaylistSelector(BaseScreen *old_screen)
|
|||||||
if (old_screen != myBrowser || !myBrowser->isLocal())
|
if (old_screen != myBrowser || !myBrowser->isLocal())
|
||||||
{
|
{
|
||||||
size_t begin = m_playlist_selector.size();
|
size_t begin = m_playlist_selector.size();
|
||||||
Mpd.GetPlaylists([this](std::string &&playlist) {
|
Mpd.GetPlaylists([this](std::string playlist) {
|
||||||
m_playlist_selector.addItem(Entry(playlist,
|
m_playlist_selector.addItem(Entry(playlist,
|
||||||
std::bind(&Self::addToExistingPlaylist, this, playlist)
|
std::bind(&Self::addToExistingPlaylist, this, playlist)
|
||||||
));
|
));
|
||||||
|
|||||||
@@ -48,12 +48,8 @@ void ServerInfo::switchTo()
|
|||||||
itsURLHandlers.clear();
|
itsURLHandlers.clear();
|
||||||
itsTagTypes.clear();
|
itsTagTypes.clear();
|
||||||
|
|
||||||
Mpd.GetURLHandlers([this](std::string &&handler) {
|
Mpd.GetURLHandlers(vectorMoveInserter(itsURLHandlers));
|
||||||
itsURLHandlers.push_back(handler);
|
Mpd.GetTagTypes(vectorMoveInserter(itsTagTypes));
|
||||||
});
|
|
||||||
Mpd.GetTagTypes([this](std::string &&tag_type) {
|
|
||||||
itsTagTypes.push_back(tag_type);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
switchToPreviousScreen();
|
switchToPreviousScreen();
|
||||||
|
|||||||
@@ -272,7 +272,7 @@ void Status::Changes::playlist()
|
|||||||
myPlaylist->main().resizeList(playlist_length);
|
myPlaylist->main().resizeList(playlist_length);
|
||||||
}
|
}
|
||||||
|
|
||||||
Mpd.GetPlaylistChanges(myPlaylist->oldVersion(), [](MPD::Song &&s) {
|
Mpd.GetPlaylistChanges(myPlaylist->oldVersion(), [](MPD::Song s) {
|
||||||
size_t pos = s.getPosition();
|
size_t pos = s.getPosition();
|
||||||
if (pos < myPlaylist->main().size())
|
if (pos < myPlaylist->main().size())
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -238,7 +238,7 @@ void TagEditor::update()
|
|||||||
Dirs->addItem(std::make_pair("..", getParentDirectory(itsBrowsedDir)));
|
Dirs->addItem(std::make_pair("..", getParentDirectory(itsBrowsedDir)));
|
||||||
else
|
else
|
||||||
Dirs->addItem(std::make_pair(".", "/"));
|
Dirs->addItem(std::make_pair(".", "/"));
|
||||||
Mpd.GetDirectories(itsBrowsedDir, [this](std::string &&directory) {
|
Mpd.GetDirectories(itsBrowsedDir, [this](std::string directory) {
|
||||||
Dirs->addItem(std::make_pair(getBasename(directory), directory));
|
Dirs->addItem(std::make_pair(getBasename(directory), directory));
|
||||||
if (directory == itsHighlightedDir)
|
if (directory == itsHighlightedDir)
|
||||||
Dirs->highlight(Dirs->size()-1);
|
Dirs->highlight(Dirs->size()-1);
|
||||||
@@ -251,7 +251,7 @@ void TagEditor::update()
|
|||||||
if (Tags->reallyEmpty())
|
if (Tags->reallyEmpty())
|
||||||
{
|
{
|
||||||
Tags->reset();
|
Tags->reset();
|
||||||
Mpd.GetSongs(Dirs->current().value().second, [this](MPD::Song &&s) {
|
Mpd.GetSongs(Dirs->current().value().second, [this](MPD::Song s) {
|
||||||
Tags->addItem(s);
|
Tags->addItem(s);
|
||||||
});
|
});
|
||||||
std::sort(Tags->beginV(), Tags->endV(),
|
std::sort(Tags->beginV(), Tags->endV(),
|
||||||
@@ -277,7 +277,7 @@ void TagEditor::enterPressed()
|
|||||||
if (w == Dirs)
|
if (w == Dirs)
|
||||||
{
|
{
|
||||||
bool has_subdirs = false;
|
bool has_subdirs = false;
|
||||||
Mpd.GetDirectories(Dirs->current().value().second, [&has_subdirs](std::string &&) {
|
Mpd.GetDirectories(Dirs->current().value().second, [&has_subdirs](std::string) {
|
||||||
has_subdirs = true;
|
has_subdirs = true;
|
||||||
});
|
});
|
||||||
if (has_subdirs)
|
if (has_subdirs)
|
||||||
|
|||||||
@@ -216,7 +216,7 @@ void Visualizer::FindOutputID()
|
|||||||
if (!Config.visualizer_output_name.empty())
|
if (!Config.visualizer_output_name.empty())
|
||||||
{
|
{
|
||||||
size_t idx = 0;
|
size_t idx = 0;
|
||||||
Mpd.GetOutputs([this, &idx](MPD::Output &&output) {
|
Mpd.GetOutputs([this, &idx](MPD::Output output) {
|
||||||
if (output.name() == Config.visualizer_output_name)
|
if (output.name() == Config.visualizer_output_name)
|
||||||
m_output_id = idx;
|
m_output_id = idx;
|
||||||
++idx;
|
++idx;
|
||||||
|
|||||||
Reference in New Issue
Block a user