Add option 'media_library_albums_split_by_date'

This commit is contained in:
Andrzej Rybczak
2017-03-28 09:01:33 +02:00
parent a22bad7ad5
commit 6f1e2d7516
7 changed files with 35 additions and 20 deletions

1
NEWS
View File

@@ -30,6 +30,7 @@ ncmpcpp-0.8 (????-??-??)
* 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.
* Added configuration options 'media_library_albums_split_by_date' that determines whether albums in media library should be split by date.
ncmpcpp-0.7.7 (2016-10-31)
* Fixed compilation on 32bit platforms.

View File

@@ -326,6 +326,8 @@
##
#media_library_primary_tag = artist
#
#media_library_albums_split_by_date = yes
#
## Available values: wrapped, normal.
##
#default_find_mode = wrapped

View File

@@ -219,6 +219,9 @@ If enabled, there will be a 250ms delay between refreshing position in media lib
.B media_library_primary_tag = artist/album_artist/date/genre/composer/performer
Default tag type for leftmost column in media library.
.TP
.B media_library_albums_split_by_date = yes/no
Determines whether albums in media library should be split by date.
.TP
.B default_find_mode = wrapped/normal
If set to "wrapped", going from last found position to next will take you to the first one (same goes for the first position and going to previous one), otherwise no actions will be performed.
.TP

View File

@@ -62,6 +62,13 @@ size_t itsRightColStartX;
typedef MediaLibrary::PrimaryTag PrimaryTag;
typedef MediaLibrary::AlbumEntry AlbumEntry;
std::string Date_(std::string date)
{
if (!Config.media_library_albums_split_by_date)
date.clear();
return date;
}
MPD::SongIterator getSongsFromAlbum(const AlbumEntry &album)
{
Mpd.StartSearch(true);
@@ -69,7 +76,8 @@ MPD::SongIterator getSongsFromAlbum(const AlbumEntry &album)
if (!album.isAllTracksEntry())
{
Mpd.AddSearch(MPD_TAG_ALBUM, album.entry().album());
Mpd.AddSearch(MPD_TAG_DATE, album.entry().date());
if (Config.media_library_albums_split_by_date)
Mpd.AddSearch(MPD_TAG_DATE, album.entry().date());
}
return Mpd.CommitSearchSongs();
}
@@ -290,7 +298,10 @@ void MediaLibrary::update()
unsigned idx = 0;
while (!(tag = s->get(Config.media_lib_primary_tag, idx++)).empty())
{
auto key = std::make_tuple(std::move(tag), s->getAlbum(), s->getDate());
auto key = std::make_tuple(
std::move(tag),
s->getAlbum(),
Date_(s->getDate()));
auto it = albums.find(key);
if (it == albums.end())
albums[std::move(key)] = s->getMTime();
@@ -378,7 +389,7 @@ void MediaLibrary::update()
std::map<std::tuple<std::string, std::string>, time_t> albums;
for (MPD::SongIterator s = Mpd.CommitSearchSongs(), end; s != end; ++s)
{
auto key = std::make_tuple(s->getAlbum(), s->getDate());
auto key = std::make_tuple(s->getAlbum(), Date_(s->getDate()));
auto it = albums.find(key);
if (it == albums.end())
albums[std::move(key)] = s->getMTime();
@@ -422,15 +433,9 @@ void MediaLibrary::update()
m_songs_update_request = false;
sunfilter_songs.set(ReapplyFilter::Yes, true);
auto &album = Albums.current()->value();
Mpd.StartSearch(true);
Mpd.AddSearch(Config.media_lib_primary_tag, album.entry().tag());
if (!album.isAllTracksEntry())
{
Mpd.AddSearch(MPD_TAG_ALBUM, album.entry().album());
Mpd.AddSearch(MPD_TAG_DATE, album.entry().date());
}
size_t idx = 0;
for (MPD::SongIterator s = Mpd.CommitSearchSongs(), end; s != end; ++s, ++idx)
for (MPD::SongIterator s = getSongsFromAlbum(album), end;
s != end; ++s, ++idx)
{
if (idx < Songs.size())
Songs[idx].value() = std::move(*s);
@@ -755,8 +760,9 @@ std::vector<MPD::Song> MediaLibrary::getSelectedSongs()
else
Mpd.AddSearch(Config.media_lib_primary_tag,
Tags.current()->value().tag());
Mpd.AddSearch(MPD_TAG_ALBUM, sc.entry().album());
Mpd.AddSearch(MPD_TAG_DATE, sc.entry().date());
Mpd.AddSearch(MPD_TAG_ALBUM, sc.entry().album());
if (Config.media_library_albums_split_by_date)
Mpd.AddSearch(MPD_TAG_DATE, sc.entry().date());
size_t begin = result.size();
std::copy(
std::make_move_iterator(Mpd.CommitSearchSongs()),
@@ -771,7 +777,7 @@ std::vector<MPD::Song> MediaLibrary::getSelectedSongs()
{
size_t begin = result.size();
std::copy(
std::make_move_iterator(getSongsFromAlbum(Albums.current()->value().entry())),
std::make_move_iterator(getSongsFromAlbum(Albums.current()->value())),
std::make_move_iterator(MPD::SongIterator()),
std::back_inserter(result)
);
@@ -1013,9 +1019,10 @@ void MediaLibrary::locateSong(const MPD::Song &s)
// The album could not be found, insert it if in two column mode.
// See comment about tags not found above. This is the equivalent
// for two column mode.
Albums.addItem(AlbumEntry(
Album(primary_tag, s.getAlbum(), s.getDate(), s.getMTime())
));
Albums.addItem(AlbumEntry(Album(primary_tag,
s.getAlbum(),
Date_(s.getDate()),
s.getMTime())));
std::sort(Albums.beginV(), Albums.endV(), SortAlbumEntries());
Albums.refresh();
MoveToAlbum(Albums, primary_tag, s);
@@ -1126,8 +1133,8 @@ bool MoveToAlbum(NC::Menu<AlbumEntry> &albums, const std::string &primary_tag, c
auto equals_fun_argument = [&](AlbumEntry &e) {
return (!hasTwoColumns || e.entry().tag() == primary_tag)
&& e.entry().album() == album
&& e.entry().date() == date;
&& e.entry().album() == album
&& (!Config.media_library_albums_split_by_date || e.entry().date() == date);
};
if (equals_fun_argument(*albums.currentV()))

View File

@@ -118,7 +118,7 @@ struct MediaLibrary: Screen<NC::Window *>, Filterable, HasColumns, HasSongs, Sea
struct AlbumEntry
{
AlbumEntry() : m_all_tracks_entry(false), m_album("", "", "", 0) { }
AlbumEntry(Album album_) : m_all_tracks_entry(false), m_album(album_) { }
explicit AlbumEntry(Album album_) : m_all_tracks_entry(false), m_album(album_) { }
const Album &entry() const { return m_album; }
bool isAllTracksEntry() const { return m_all_tracks_entry; }

View File

@@ -373,6 +373,7 @@ bool Configuration::read(const std::vector<std::string> &config_paths, bool igno
else
invalid_value(v);
});
p.add("media_library_albums_split_by_date", &media_library_albums_split_by_date, "yes", yes_no);
p.add("default_find_mode", &wrapped_search, "wrapped", [](std::string v) {
if (v == "wrapped")
return true;

View File

@@ -170,6 +170,7 @@ struct Configuration
bool generate_win32_compatible_filenames;
bool ask_for_locked_screen_width_part;
bool allow_for_physical_item_deletion;
bool media_library_albums_split_by_date;
bool startup_slave_screen_focus;
unsigned mpd_connection_timeout;