Loading...
Searching...
No Matches
juce_ProcessorChain.h
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2022 - Raw Material Software Limited
JUCE is an open source library subject to commercial or open-source
licensing.
By using JUCE, you agree to the terms of both the JUCE 7 End-User License
Agreement and JUCE Privacy Policy.
End User License Agreement: www.juce.com/juce-7-licence
Privacy Policy: www.juce.com/juce-privacy-policy
Or: You may also use this code under the terms of the GPL v3 (see
www.gnu.org/licenses).
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================
*/
namespace juce::dsp
{
//==============================================================================
#ifndef DOXYGEN
namespace detail
{
template <typename Fn, typename Tuple, size_t... Ix>
constexpr void forEachInTuple (Fn&& fn, Tuple&& tuple, std::index_sequence<Ix...>)
{
(fn (std::get<Ix> (tuple), std::integral_constant<size_t, Ix>()), ...);
}
template <typename T>
using TupleIndexSequence = std::make_index_sequence<std::tuple_size_v<std::remove_cv_t<std::remove_reference_t<T>>>>;
template <typename Fn, typename Tuple>
constexpr void forEachInTuple (Fn&& fn, Tuple&& tuple)
{
forEachInTuple (std::forward<Fn> (fn), std::forward<Tuple> (tuple), TupleIndexSequence<Tuple>{});
}
template <typename Context, size_t Ix>
inline constexpr auto useContextDirectly = ! Context::usesSeparateInputAndOutputBlocks() || Ix == 0;
}
#endif
template <typename... Processors>
class ProcessorChain
{
public:
template <int Index> auto& get() noexcept { return std::get<Index> (processors); }
template <int Index> const auto& get() const noexcept { return std::get<Index> (processors); }
template <int Index>
void setBypassed (bool b) noexcept { bypassed[(size_t) Index] = b; }
template <int Index>
bool isBypassed() const noexcept { return bypassed[(size_t) Index]; }
void prepare (const ProcessSpec& spec)
{
detail::forEachInTuple ([&] (auto& proc, auto) { proc.prepare (spec); }, processors);
}
void reset()
{
detail::forEachInTuple ([] (auto& proc, auto) { proc.reset(); }, processors);
}
template <typename ProcessContext>
void process (const ProcessContext& context) noexcept
{
detail::forEachInTuple ([this, &context] (auto& proc, auto index) noexcept { this->processOne (context, proc, index); },
processors);
}
private:
template <typename Context, typename Proc, size_t Ix>
void processOne (const Context& context, Proc& proc, std::integral_constant<size_t, Ix>) noexcept
{
if constexpr (detail::useContextDirectly<Context, Ix>)
{
auto contextCopy = context;
contextCopy.isBypassed = (bypassed[Ix] || context.isBypassed);
proc.process (contextCopy);
}
else
{
jassert (context.getOutputBlock().getNumChannels() == context.getInputBlock().getNumChannels());
ProcessContextReplacing<typename Context::SampleType> replacingContext (context.getOutputBlock());
replacingContext.isBypassed = (bypassed[Ix] || context.isBypassed);
proc.process (replacingContext);
}
}
std::tuple<Processors...> processors;
std::array<bool, sizeof... (Processors)> bypassed { {} };
};
template <int Index, typename... Processors>
inline auto& get (ProcessorChain<Processors...>& chain) noexcept
{
return chain.template get<Index>();
}
template <int Index, typename... Processors>
inline auto& get (const ProcessorChain<Processors...>& chain) noexcept
{
return chain.template get<Index>();
}
template <int Index, typename... Processors>
inline void setBypassed (ProcessorChain<Processors...>& chain, bool bypassed) noexcept
{
chain.template setBypassed<Index> (bypassed);
}
template <int Index, typename... Processors>
inline bool isBypassed (const ProcessorChain<Processors...>& chain) noexcept
{
return chain.template isBypassed<Index>();
}
} // namespace juce::dsp
#ifndef DOXYGEN
namespace std
{
JUCE_BEGIN_IGNORE_WARNINGS_GCC_LIKE ("-Wmismatched-tags")
template <typename... Processors>
struct tuple_size<::juce::dsp::ProcessorChain<Processors...>> : integral_constant<size_t, sizeof... (Processors)> {};
template <size_t I, typename... Processors>
struct tuple_element<I, ::juce::dsp::ProcessorChain<Processors...>> : tuple_element<I, tuple<Processors...>> {};
JUCE_END_IGNORE_WARNINGS_GCC_LIKE
} // namespace std
#endif
juce::dsp::ProcessorChain
Definition juce_ProcessorChain.h:63
juce::dsp::ProcessorChain::isBypassed
bool isBypassed() const noexcept
Definition juce_ProcessorChain.h:77
juce::dsp::ProcessorChain::setBypassed
void setBypassed(bool b) noexcept
Definition juce_ProcessorChain.h:73
juce::dsp::ProcessorChain::prepare
void prepare(const ProcessSpec &spec)
Definition juce_ProcessorChain.h:80
juce::dsp::ProcessorChain::reset
void reset()
Definition juce_ProcessorChain.h:86
juce::dsp::ProcessorChain::get
auto & get() noexcept
Definition juce_ProcessorChain.h:66
juce::dsp::ProcessorChain::get
const auto & get() const noexcept
Definition juce_ProcessorChain.h:69
juce::dsp::ProcessorChain::process
void process(const ProcessContext &context) noexcept
Definition juce_ProcessorChain.h:93
juce::dsp::detail
Definition juce_ProcessorChain.h:35
juce::dsp::ProcessSpec
Definition juce_ProcessContext.h:36