FilterConfig.cxx 2.02 KB
Newer Older
1
/*
2
 * Copyright 2003-2016 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 "FilterConfig.hxx"
22
#include "plugins/ChainFilterPlugin.hxx"
Max Kellermann's avatar
Max Kellermann committed
23
#include "FilterPlugin.hxx"
24
#include "config/Param.hxx"
25 26 27
#include "config/ConfigOption.hxx"
#include "config/ConfigGlobal.hxx"
#include "config/ConfigError.hxx"
28
#include "config/Block.hxx"
29
#include "util/RuntimeError.hxx"
30

31
#include <algorithm>
32

33 34
#include <string.h>

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

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

	const char *plugin_name = cfg->GetBlockValue("plugin",
						     "unknown");
	filter_chain_append(chain, plugin_name, f);
}

52 53
void
filter_chain_parse(PreparedFilter &chain, const char *spec)
54
{
55 56 57 58 59 60
	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);
61
			filter_chain_append_new(chain, name.c_str());
62
		}
63

64 65
		if (comma == end)
			break;
66

67
		spec = comma + 1;
68 69
	}
}