From 199037c6822c1f7cbaea551ca3949ce525e18fe8 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 12 Jul 2022 20:50:46 +0200 Subject: [PATCH] config: allow configuring partitions This just allows creating empty partitions. More features to come. --- NEWS | 1 + doc/user.rst | 32 ++++++++++++++++++++++++++++++++ src/Main.cxx | 9 +++++++++ src/config/Option.hxx | 1 + src/config/Templates.cxx | 1 + 5 files changed, 44 insertions(+) diff --git a/NEWS b/NEWS index 313b4a01c..2d335dfd5 100644 --- a/NEWS +++ b/NEWS @@ -15,6 +15,7 @@ ver 0.24 (not yet released) - new tag "Mood" * switch to C++20 - GCC 10 or clang 11 (or newer) recommended +* static partition configuration * remove Haiku support ver 0.23.9 (not yet released) diff --git a/doc/user.rst b/doc/user.rst index 1b01c64e3..5280bf659 100644 --- a/doc/user.rst +++ b/doc/user.rst @@ -297,6 +297,38 @@ configure this plugin, add a :code:`database` block to More information can be found in the :ref:`database_plugins` reference. + +Configuring Partitions +---------------------- + +:program:`MPD` can have multiple "partitions", that is, multiple +independent players, each with their own queue and outputs. All +partitions share one database. By default, there is only one +partition called "default". Additional partitions can be created in +the configuration file with ``partition`` blocks or at runtime with +the :ref:`newpartition ` command. + +Example for specifying an additional partition in the configuration +file: + +.. code-block:: none + + partition { + name "foo" + } + +The following options are available in ``partition`` blocks: + +.. list-table:: + :widths: 20 80 + :header-rows: 1 + + * - Name + - Description + * - **name** + - The name of the partition. + + Configuring neighbor plugins ---------------------------- diff --git a/src/Main.cxx b/src/Main.cxx index 2f951bbb6..de50c23be 100644 --- a/src/Main.cxx +++ b/src/Main.cxx @@ -410,6 +410,15 @@ MainConfigured(const CommandLineOptions &options, partition.UpdateEffectiveReplayGainMode(); } + raw_config.WithEach(ConfigBlockOption::PARTITION, [&](const auto &block){ + const char *name = block.GetBlockValue("name"); + if (name == nullptr) + throw std::runtime_error("Missing 'name'"); + + instance.partitions.emplace_back(instance, name, + partition_config); + }); + client_manager_init(raw_config); const ScopeInputPluginsInit input_plugins_init(raw_config, instance.io_thread.GetEventLoop()); diff --git a/src/config/Option.hxx b/src/config/Option.hxx index ba29a90a7..344530da7 100644 --- a/src/config/Option.hxx +++ b/src/config/Option.hxx @@ -97,6 +97,7 @@ enum class ConfigBlockOption { AUDIO_FILTER, DATABASE, NEIGHBORS, + PARTITION, MAX }; diff --git a/src/config/Templates.cxx b/src/config/Templates.cxx index aa696988d..e9f9ef780 100644 --- a/src/config/Templates.cxx +++ b/src/config/Templates.cxx @@ -96,6 +96,7 @@ const ConfigTemplate config_block_templates[] = { { "filter", true }, { "database" }, { "neighbors", true }, + { "partition", true }, }; static constexpr unsigned n_config_block_templates =