From 6ebf00eb5d3e6a66ad567aa09ca575f5e0c9a982 Mon Sep 17 00:00:00 2001 From: Andrzej Rybczak Date: Sun, 30 Oct 2016 19:01:11 +0100 Subject: [PATCH] Song: add support for hiding duplicate tags --- NEWS | 1 + doc/config | 2 ++ doc/ncmpcpp.1 | 3 +++ src/settings.cpp | 3 +++ src/song.cpp | 37 +++++++++++++++++++++++++++++++++---- src/song.h | 2 ++ 6 files changed, 44 insertions(+), 4 deletions(-) diff --git a/NEWS b/NEWS index f0485ac5..a65fe34c 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,6 @@ ncmpcpp-0.8 (????-??-??) * Configuration variable 'execute_on_player_state_change' was added. +* Support for controlling whether ncmpcpp should display multiple tags as-is or make an effort to hide duplicate values (show_duplicate_tags configuration variable, enabled by default). ncmpcpp-0.7.5 (2016-08-17) * Action chains can be now used for seeking. diff --git a/doc/config b/doc/config index db703c2a..d325df5d 100644 --- a/doc/config +++ b/doc/config @@ -316,6 +316,8 @@ # #discard_colors_if_item_is_selected = yes # +#show_duplicate_tags = true +# #incremental_seeking = yes # #seek_time = 1 diff --git a/doc/ncmpcpp.1 b/doc/ncmpcpp.1 index 33c94ea5..bfad8677 100644 --- a/doc/ncmpcpp.1 +++ b/doc/ncmpcpp.1 @@ -184,6 +184,9 @@ Default display mode for Playlist editor. .B discard_colors_if_item_is_selected = yes/no Indicates whether custom colors of tags have to be discarded if item is selected or not. .TP +.B show_duplicate_tags = yes/no +Indicates whether ncmpcpp should display multiple tags as-is or remove duplicates. +.TP .B incremental_seeking = yes/no If enabled, seek time will increment by one each second of seeking. .TP diff --git a/src/settings.cpp b/src/settings.cpp index d1bbdc14..779095e9 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -405,6 +405,9 @@ bool Configuration::read(const std::vector &config_paths, bool igno p.add("discard_colors_if_item_is_selected", yes_no( discard_colors_if_item_is_selected, true )); + p.add("show_duplicate_tags", yes_no( + MPD::Song::ShowDuplicateTags, true + )); p.add("incremental_seeking", yes_no( incremental_seeking, true )); diff --git a/src/song.cpp b/src/song.cpp index e8ea294d..87bcde5d 100644 --- a/src/song.cpp +++ b/src/song.cpp @@ -46,6 +46,8 @@ namespace MPD { std::string Song::TagsSeparator = " | "; +bool Song::ShowDuplicateTags = true; + std::string Song::get(mpd_tag_type type, unsigned idx) const { std::string result; @@ -206,11 +208,38 @@ std::string MPD::Song::getTags(GetFunction f) const assert(m_song); unsigned idx = 0; std::string result; - for (std::string tag; !(tag = (this->*f)(idx)).empty(); ++idx) + if (ShowDuplicateTags) + { + for (std::string tag; !(tag = (this->*f)(idx)).empty(); ++idx) + { + if (!result.empty()) + result += TagsSeparator; + result += tag; + } + } + else { - if (!result.empty()) - result += TagsSeparator; - result += tag; + bool already_present; + // This is O(n^2), but it doesn't really matter as a list of tags will have + // at most 2 or 3 items the vast majority of time. + for (std::string tag; !(tag = (this->*f)(idx)).empty(); ++idx) + { + already_present = false; + for (unsigned i = 0; i < idx; ++i) + { + if ((this->*f)(i) == tag) + { + already_present = true; + break; + } + } + if (!already_present) + { + if (idx > 0) + result += TagsSeparator; + result += tag; + } + } } return result; } diff --git a/src/song.h b/src/song.h index a649bf35..d0dfddce 100644 --- a/src/song.h +++ b/src/song.h @@ -103,6 +103,8 @@ struct Song static std::string TagsSeparator; + static bool ShowDuplicateTags; + private: std::shared_ptr m_song; size_t m_hash;