filter/TwoFilters: add ChainFilters()

This commit is contained in:
Max Kellermann 2021-08-26 17:24:14 +02:00
parent 49dcac5c21
commit bd79354f32
1 changed files with 19 additions and 0 deletions

View File

@ -65,4 +65,23 @@ public:
std::unique_ptr<Filter> Open(AudioFormat &audio_format) override;
};
/**
* Create a #PreparedTwoFilters instance, but only if both parameters
* are not nullptr.
*/
template<typename F, typename S, typename N>
static std::unique_ptr<PreparedFilter>
ChainFilters(F &&first, S &&second, N &&second_name) noexcept
{
if (!second)
return std::forward<F>(first);
if (!first)
return std::forward<S>(second);
return std::make_unique<PreparedTwoFilters>(std::forward<F>(first),
std::forward<S>(second),
std::forward<N>(second_name));
}
#endif