From 554895f0f1f07d034be9d5bb93b1a638783ef6c0 Mon Sep 17 00:00:00 2001 From: Andrzej Rybczak Date: Sun, 26 Mar 2017 09:08:32 +0200 Subject: [PATCH] Media library: add songs to playlist in the same order they are displayed in --- NEWS | 1 + src/screens/media_library.cpp | 28 +++++++++++++--------------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/NEWS b/NEWS index 470c570b..3c28c398 100644 --- a/NEWS +++ b/NEWS @@ -28,6 +28,7 @@ ncmpcpp-0.8 (????-??-??) * Added support for locating current song in playlist editor. * Disable autocenter mode while searching and filtering. * Added '--quiet' comand line argument that supresses messages shown at startup. +* Multiple songs in Media library are now added to playlist in the same order they are displayed. ncmpcpp-0.7.7 (2016-10-31) * Fixed compilation on 32bit platforms. diff --git a/src/screens/media_library.cpp b/src/screens/media_library.cpp index 9e5c17a2..31efb57e 100644 --- a/src/screens/media_library.cpp +++ b/src/screens/media_library.cpp @@ -93,7 +93,7 @@ struct SortSongs { std::ptrdiff_t m_offset; public: - SortSongs(bool disc_only) + SortSongs(bool disc_only = false) : m_cmp(std::locale(), Config.ignore_leading_the), m_offset(disc_only ? 2 : 0) { } bool operator()(const SongItem &a, const SongItem &b) { @@ -690,25 +690,23 @@ bool MediaLibrary::addItemToPlaylist(bool play) Mpd.AddSearch(Config.media_lib_primary_tag, Tags.current()->value().tag()); std::vector list( std::make_move_iterator(Mpd.CommitSearchSongs()), - std::make_move_iterator(MPD::SongIterator()) - ); + std::make_move_iterator(MPD::SongIterator())); + std::sort(list.begin(), list.end(), SortSongs()); result = addSongsToPlaylist(list.begin(), list.end(), play, -1); std::string tag_type = boost::locale::to_lower( tagTypeToString(Config.media_lib_primary_tag)); Statusbar::printf("Songs with %1% \"%2%\" added%3%", - tag_type, Tags.current()->value().tag(), withErrors(result) - ); + tag_type, Tags.current()->value().tag(), withErrors(result)); } else if (isActiveWindow(Albums)) { std::vector list( std::make_move_iterator(getSongsFromAlbum(Albums.current()->value())), - std::make_move_iterator(MPD::SongIterator()) - ); + std::make_move_iterator(MPD::SongIterator())); + std::sort(list.begin(), list.end(), SortSongs()); result = addSongsToPlaylist(list.begin(), list.end(), play, -1); Statusbar::printf("Songs from album \"%1%\" added%2%", - Albums.current()->value().entry().album(), withErrors(result) - ); + Albums.current()->value().entry().album(), withErrors(result)); } } return result; @@ -722,11 +720,12 @@ std::vector MediaLibrary::getSelectedSongs() auto tag_handler = [&result](const std::string &tag) { Mpd.StartSearch(true); Mpd.AddSearch(Config.media_lib_primary_tag, tag); + size_t begin = result.size(); std::copy( std::make_move_iterator(Mpd.CommitSearchSongs()), std::make_move_iterator(MPD::SongIterator()), - std::back_inserter(result) - ); + std::back_inserter(result)); + std::sort(result.begin()+begin, result.end(), SortSongs()); }; bool any_selected = false; for (auto &e : Tags) @@ -762,9 +761,8 @@ std::vector MediaLibrary::getSelectedSongs() std::copy( std::make_move_iterator(Mpd.CommitSearchSongs()), std::make_move_iterator(MPD::SongIterator()), - std::back_inserter(result) - ); - std::sort(result.begin()+begin, result.end(), SortSongs(false)); + std::back_inserter(result)); + std::sort(result.begin()+begin, result.end(), SortSongs()); } } // if no item is selected, add songs from right column @@ -777,7 +775,7 @@ std::vector MediaLibrary::getSelectedSongs() std::make_move_iterator(MPD::SongIterator()), std::back_inserter(result) ); - std::sort(result.begin()+begin, result.end(), SortSongs(false)); + std::sort(result.begin()+begin, result.end(), SortSongs()); } } else if (isActiveWindow(Songs))