LoadChain.cxx 2.1 KB
Newer Older
1
/*
Max Kellermann's avatar
Max Kellermann committed
2
 * Copyright 2003-2017 The Music Player Daemon Project
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
 * http://www.musicpd.org
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#include "config.h"
21
#include "LoadChain.hxx"
22
#include "LoadOne.hxx"
23
#include "Prepared.hxx"
24
#include "plugins/ChainFilterPlugin.hxx"
25
#include "config/Param.hxx"
26
#include "config/Option.hxx"
27
#include "config/Data.hxx"
28
#include "config/Domain.hxx"
29
#include "config/Block.hxx"
30
#include "util/RuntimeError.hxx"
31

32
#include <algorithm>
33

34 35
#include <string.h>

36
static void
37 38
filter_chain_append_new(PreparedFilter &chain, const ConfigData &config,
			const char *template_name)
39
{
40 41
	const auto *cfg = config.FindBlock(ConfigBlockOption::AUDIO_FILTER,
					   "name", template_name);
42 43 44
	if (cfg == nullptr)
		throw FormatRuntimeError("Filter template not found: %s",
					 template_name);
45

46 47
	cfg->SetUsed();

48
	// Instantiate one of those filter plugins with the template name as a hint
49
	auto f = filter_configured_new(*cfg);
50 51 52

	const char *plugin_name = cfg->GetBlockValue("plugin",
						     "unknown");
53
	filter_chain_append(chain, plugin_name, std::move(f));
54 55
}

56
void
57 58 59
filter_chain_parse(PreparedFilter &chain,
		   const ConfigData &config,
		   const char *spec)
60
{
61 62 63 64 65 66
	const char *const end = spec + strlen(spec);

	while (true) {
		const char *comma = std::find(spec, end, ',');
		if (comma > spec) {
			const std::string name(spec, comma);
67
			filter_chain_append_new(chain, config, name.c_str());
68
		}
69

70 71
		if (comma == end)
			break;
72

73
		spec = comma + 1;
74 75
	}
}