2009-12-14 21:09:28 +01:00
|
|
|
/*
|
2017-01-03 20:48:59 +01:00
|
|
|
* Copyright 2003-2017 The Music Player Daemon Project
|
2009-12-14 21:09:28 +01:00
|
|
|
* 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"
|
2013-01-30 17:22:44 +01:00
|
|
|
#include "FilterConfig.hxx"
|
2014-01-24 16:31:52 +01:00
|
|
|
#include "plugins/ChainFilterPlugin.hxx"
|
2013-02-01 17:47:09 +01:00
|
|
|
#include "FilterPlugin.hxx"
|
2015-01-21 21:14:25 +01:00
|
|
|
#include "config/Param.hxx"
|
2014-01-24 00:20:01 +01:00
|
|
|
#include "config/ConfigOption.hxx"
|
|
|
|
#include "config/ConfigGlobal.hxx"
|
|
|
|
#include "config/ConfigError.hxx"
|
2015-01-21 22:13:44 +01:00
|
|
|
#include "config/Block.hxx"
|
2016-09-04 20:07:05 +02:00
|
|
|
#include "util/RuntimeError.hxx"
|
2009-12-14 21:09:28 +01:00
|
|
|
|
2013-10-19 16:34:11 +02:00
|
|
|
#include <algorithm>
|
2013-01-30 22:39:19 +01:00
|
|
|
|
2009-12-14 21:09:28 +01:00
|
|
|
#include <string.h>
|
|
|
|
|
2016-09-04 20:07:05 +02:00
|
|
|
static void
|
|
|
|
filter_chain_append_new(PreparedFilter &chain, const char *template_name)
|
2013-10-19 16:26:51 +02:00
|
|
|
{
|
2015-01-21 22:13:44 +01:00
|
|
|
const auto *cfg = config_find_block(ConfigBlockOption::AUDIO_FILTER,
|
|
|
|
"name", template_name);
|
2016-09-04 20:07:05 +02:00
|
|
|
if (cfg == nullptr)
|
|
|
|
throw FormatRuntimeError("Filter template not found: %s",
|
|
|
|
template_name);
|
2013-10-19 16:26:51 +02:00
|
|
|
|
|
|
|
// Instantiate one of those filter plugins with the template name as a hint
|
2016-09-04 20:07:05 +02:00
|
|
|
PreparedFilter *f = filter_configured_new(*cfg);
|
2013-10-19 16:26:51 +02:00
|
|
|
|
|
|
|
const char *plugin_name = cfg->GetBlockValue("plugin",
|
|
|
|
"unknown");
|
|
|
|
filter_chain_append(chain, plugin_name, f);
|
|
|
|
}
|
|
|
|
|
2016-09-04 20:07:05 +02:00
|
|
|
void
|
|
|
|
filter_chain_parse(PreparedFilter &chain, const char *spec)
|
2009-12-14 21:09:28 +01:00
|
|
|
{
|
2013-10-19 16:34:11 +02:00
|
|
|
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);
|
2016-09-04 20:07:05 +02:00
|
|
|
filter_chain_append_new(chain, name.c_str());
|
2013-10-19 16:34:11 +02:00
|
|
|
}
|
2009-12-14 21:09:28 +01:00
|
|
|
|
2013-10-19 16:34:11 +02:00
|
|
|
if (comma == end)
|
|
|
|
break;
|
2009-12-14 21:09:28 +01:00
|
|
|
|
2013-10-19 16:34:11 +02:00
|
|
|
spec = comma + 1;
|
2009-12-14 21:09:28 +01:00
|
|
|
}
|
|
|
|
}
|