Optimize deletion/cropping of main playlist by using ranges
This commit is contained in:
@@ -681,8 +681,7 @@ void DeletePlaylistItems::run()
|
||||
if (myScreen == myPlaylist)
|
||||
{
|
||||
Statusbar::print("Deleting items...");
|
||||
auto delete_fun = std::bind(&MPD::Connection::Delete, ph::_1, ph::_2);
|
||||
deleteSelectedSongs(myPlaylist->main(), delete_fun);
|
||||
deleteSelectedSongsFromPlaylist(myPlaylist->main());
|
||||
Statusbar::print("Item(s) deleted");
|
||||
}
|
||||
else if (myScreen->isActiveWindow(myPlaylistEditor->Content))
|
||||
@@ -1926,7 +1925,8 @@ void CropMainPlaylist::run()
|
||||
confirmAction("Do you really want to crop main playlist?");
|
||||
Statusbar::print("Cropping playlist...");
|
||||
selectCurrentIfNoneSelected(w);
|
||||
cropPlaylist(w, std::bind(&MPD::Connection::Delete, ph::_1, ph::_2));
|
||||
reverseSelectionHelper(w.begin(), w.end());
|
||||
deleteSelectedSongsFromPlaylist(w);
|
||||
Statusbar::print("Playlist cropped");
|
||||
}
|
||||
|
||||
|
||||
@@ -76,6 +76,30 @@ MPD::SongIterator getDatabaseIterator(MPD::Connection &mpd)
|
||||
return result;
|
||||
}
|
||||
|
||||
void deleteSelectedSongsFromPlaylist(NC::Menu<MPD::Song> &playlist)
|
||||
{
|
||||
selectCurrentIfNoneSelected(playlist);
|
||||
boost::optional<int> range_end;
|
||||
Mpd.StartCommandsList();
|
||||
for (auto &s : boost::adaptors::reverse(playlist))
|
||||
{
|
||||
if (s.isSelected())
|
||||
{
|
||||
s.setSelected(false);
|
||||
if (range_end == boost::none)
|
||||
range_end = s.value().getPosition() + 1;
|
||||
}
|
||||
else if (range_end != boost::none)
|
||||
{
|
||||
Mpd.DeleteRange(s.value().getPosition() + 1, *range_end);
|
||||
range_end.reset();
|
||||
}
|
||||
}
|
||||
if (range_end != boost::none)
|
||||
Mpd.DeleteRange(0, *range_end);
|
||||
Mpd.CommitCommandsList();
|
||||
}
|
||||
|
||||
void removeSongFromPlaylist(const SongMenu &playlist, const MPD::Song &s)
|
||||
{
|
||||
Mpd.StartCommandsList();
|
||||
|
||||
@@ -528,6 +528,8 @@ inline const char *withErrors(bool success)
|
||||
return success ? "" : " " "(with errors)";
|
||||
}
|
||||
|
||||
void deleteSelectedSongsFromPlaylist(NC::Menu<MPD::Song> &playlist);
|
||||
|
||||
bool addSongToPlaylist(const MPD::Song &s, bool play, int position = -1);
|
||||
|
||||
const MPD::Song *currentSong(const BaseScreen *screen);
|
||||
|
||||
@@ -655,6 +655,17 @@ void Connection::Delete(unsigned pos)
|
||||
}
|
||||
}
|
||||
|
||||
void Connection::DeleteRange(unsigned begin, unsigned end)
|
||||
{
|
||||
prechecks();
|
||||
mpd_send_delete_range(m_connection.get(), begin, end);
|
||||
if (!m_command_list_active)
|
||||
{
|
||||
mpd_response_finish(m_connection.get());
|
||||
checkErrors();
|
||||
}
|
||||
}
|
||||
|
||||
void Connection::PlaylistDelete(const std::string &playlist, unsigned pos)
|
||||
{
|
||||
prechecks();
|
||||
|
||||
@@ -550,6 +550,7 @@ struct Connection
|
||||
bool AddRandomSongs(size_t number, const std::string &random_exclude_pattern, std::mt19937 &rng);
|
||||
bool Add(const std::string &path);
|
||||
void Delete(unsigned int pos);
|
||||
void DeleteRange(unsigned begin, unsigned end);
|
||||
void PlaylistDelete(const std::string &playlist, unsigned int pos);
|
||||
void StartCommandsList();
|
||||
void CommitCommandsList();
|
||||
|
||||
Reference in New Issue
Block a user