From c46483a4ab2fe0f206473f4907ec35044d18c30a Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 10 Aug 2018 18:31:05 +0200 Subject: [PATCH] tag/Config: support incremental "metadata_to_use" setting With a "+" or "-" prefix, the "metadata_to_use" setting can manipulate the existing default. This way, one can enable `TAG_COMMENT` without having to list all the other tags. --- NEWS | 1 + doc/mpdconf.example | 4 ++++ doc/user.rst | 11 ++++++++++- src/tag/Config.cxx | 25 +++++++++++++++++++++---- 4 files changed, 36 insertions(+), 5 deletions(-) diff --git a/NEWS b/NEWS index 761bad5c2..0c092b2cb 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,7 @@ ver 0.21 (not yet released) * configuration - add "include" directive, allows including config files + - incremental "metadata_to_use" setting * protocol - "tagtypes" can be used to hide tags - "find" and "search" can sort diff --git a/doc/mpdconf.example b/doc/mpdconf.example index 4684c7c37..e3a7b024c 100644 --- a/doc/mpdconf.example +++ b/doc/mpdconf.example @@ -111,6 +111,10 @@ # found in the user manual. #metadata_to_use "artist,album,title,track,name,genre,date,composer,performer,disc" # +# This example just enables the "comment" tag without disabling all +# the other supported tags: +#metadata_to_use "+comment" +# # This setting enables automatic update of MPD's database when files in # music_directory are changed. # diff --git a/doc/user.rst b/doc/user.rst index bb8e52be5..6292ddf54 100644 --- a/doc/user.rst +++ b/doc/user.rst @@ -494,7 +494,16 @@ Other Settings setting can reduce the database size and :program:`MPD`'s memory usage by omitting unused tags. By default, all tags but comment are enabled. The special value "none" disables all - tags. Section :ref:`tags` contains a list of supported tags. + tags. + + If the setting starts with ``+`` or ``-``, then the following + tags will be added or remoted to/from the current set of tags. + This example just enables the "comment" tag without disabling all + the other supported tags + + metadata_to_use "+comment" + + Section :ref:`tags` contains a list of supported tags. The State File ~~~~~~~~~~~~~~ diff --git a/src/tag/Config.cxx b/src/tag/Config.cxx index 94899df14..29967dde9 100644 --- a/src/tag/Config.cxx +++ b/src/tag/Config.cxx @@ -34,19 +34,36 @@ TagLoadConfig(const ConfigData &config) if (value == nullptr) return; - global_tag_mask = TagMask::None(); - - if (StringEqualsCaseASCII(value, "none")) + if (StringEqualsCaseASCII(value, "none")) { + global_tag_mask = TagMask::None(); return; + } + + bool plus = true; + + if (*value != '+' && *value != '-') + /* no "+-": not incremental */ + global_tag_mask = TagMask::None(); for (const auto &i : SplitString(value, ',')) { const char *name = i.c_str(); + if (*name == '+') { + plus = true; + ++name; + } else if (*name == '-') { + plus = false; + ++name; + } + const auto type = tag_name_parse_i(name); if (type == TAG_NUM_OF_ITEM_TYPES) throw FormatRuntimeError("error parsing metadata item \"%s\"", name); - global_tag_mask |= type; + if (plus) + global_tag_mask.Set(type); + else + global_tag_mask.Unset(type); } }