With the current juce development tip, a specialisation of std::tuple_size
for juce::dsp::ProcessorChain
has been added. With that, you can build a bunch of helper functions to achieve something similar to what you want.
To iterate over a sequence of template indices, there is std::index_sequence
. This helper will create an appropriate index sequence for every type that works with std::tuple_size
:
template <class Tuple>
using makeTupleIndexSequence = std::make_index_sequence<std::tuple_size<std::remove_cvref_t<Tuple>>::value>;
Sidenote: std::remove_cvref
is a C++ 20 helper. You can achieve the same by chaining std::remove_cv_t
and std::remove_reference_t
.
Now you can build a helper function like
template <class ProcessorChain, size_t... i>
void setAllBypassedHelper (bool shouldBeBypassed, ProcessorChain& chain, std::index_sequence<i...>)
{
(chain.setBypassed<i> (shouldBeBypassed), ...);
}
template <class ProcessorChain>
void setAllBypassed (bool shouldBeBypassed, ProcessorChain& chain)
{
setAllBypassedHelper (shouldBeBypassed, chain, makeTupleIndexSequence<ProcessorChain>());
}
Sidenote: The syntax used in setAllBypassedHelper
is a C++ 17 fold expression, which is basically the loop thing you are looking for. It calls the expression passed in with all elements of the pack variable passed in, which is the index sequence in this case. There are ways to achieve the same in previous C++ standards, but they look extremely ugly
If you are forced to use an older standard, just do some research.
Now, with all that, you can ultimatively write this one liner:
setAllBypassed (true, chain);
If the bunch of helper classes are worth it is a question that you’ll have to answer yourself. But once you get started writing such helpers, you’ll maybe tend to re-use them in other contexts. Hope that helped
One last note: All the code above is untested, so no guarantee that I made some mistake – but the concept works for sure 