LoadChain.cxx 2.03 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 27 28
#include "config/ConfigOption.hxx"
#include "config/ConfigGlobal.hxx"
#include "config/ConfigError.hxx"
29
#include "config/Block.hxx"
30
#include "util/RuntimeError.hxx"
31

32
#include <algorithm>
33

34 35
#include <string.h>

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

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

	const char *plugin_name = cfg->GetBlockValue("plugin",
						     "unknown");
50
	filter_chain_append(chain, plugin_name, std::move(f));
51 52
}

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

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

68
		spec = comma + 1;
69 70
	}
}