helpers: restore old behavior when playing a song already in playlist
This commit is contained in:
@@ -103,12 +103,20 @@ bool addSongToPlaylist(const MPD::Song &s, bool play, int position)
|
||||
{
|
||||
bool result = false;
|
||||
if (Config.space_add_mode == SpaceAddMode::AddRemove
|
||||
&& !play
|
||||
&& myPlaylist->checkForSong(s)
|
||||
)
|
||||
{
|
||||
result = true;
|
||||
removeSongFromPlaylist(myPlaylist->main(), s);
|
||||
if (play)
|
||||
{
|
||||
const auto begin = myPlaylist->main().beginV(), end = myPlaylist->main().endV();
|
||||
auto it = find_map_first(begin, end, s, [](const MPD::Song &found) {
|
||||
Mpd.PlayID(found.getID());
|
||||
});
|
||||
assert(it != end);
|
||||
}
|
||||
else
|
||||
removeSongFromPlaylist(myPlaylist->main(), s);
|
||||
return result;
|
||||
}
|
||||
int id = Mpd.AddSong(s, position);
|
||||
|
||||
@@ -61,6 +61,26 @@ struct pointer_extractor
|
||||
ValueT *operator()(ValueT &v) const { return &v; }
|
||||
};
|
||||
|
||||
/// Map over the first element in range satisfying the predicate.
|
||||
template <typename InputIterator, typename PredicateT, typename MapT>
|
||||
InputIterator find_map_first(InputIterator first, InputIterator last, PredicateT &&p, MapT &&f)
|
||||
{
|
||||
auto it = std::find(first, last, std::forward<PredicateT>(p));
|
||||
if (it != last)
|
||||
f(*it);
|
||||
return it;
|
||||
}
|
||||
|
||||
/// Map over all elements in range satisfying the predicate.
|
||||
template <typename InputIterator, typename PredicateT, typename MapT>
|
||||
void find_map_all(InputIterator first, InputIterator last, PredicateT &&p, MapT &&f)
|
||||
{
|
||||
InputIterator it = first;
|
||||
do
|
||||
it = find_map_first(it, last, p, f);
|
||||
while (it != last);
|
||||
}
|
||||
|
||||
// identity function object
|
||||
struct id_
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user