JUCE-7.0.12-0-g4f43011b96 JUCE-7.0.12-0-g4f43011b96
JUCE — C++ application framework with suport for VST, VST3, LV2 audio plug-ins

« « « Anklang Documentation
Loading...
Searching...
No Matches
juce_ProcessorDuplicator.h
Go to the documentation of this file.
1 /*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
12
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
15
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
18
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21 DISCLAIMED.
22
23 ==============================================================================
24*/
25
26namespace juce::dsp
27{
28
39template <typename MonoProcessorType, typename StateType>
41{
42 ProcessorDuplicator() : state (new StateType()) {}
44 ProcessorDuplicator (typename StateType::Ptr stateToUse) : state (std::move (stateToUse)) {}
47
48 void prepare (const ProcessSpec& spec)
49 {
50 processors.removeRange ((int) spec.numChannels, processors.size());
51
52 while (static_cast<size_t> (processors.size()) < spec.numChannels)
53 processors.add (new MonoProcessorType (state));
54
55 auto monoSpec = spec;
56 monoSpec.numChannels = 1;
57
58 for (auto* p : processors)
59 p->prepare (monoSpec);
60 }
61
62 void reset() noexcept { for (auto* p : processors) p->reset(); }
63
64 template <typename ProcessContext>
65 void process (const ProcessContext& context) noexcept
66 {
67 jassert ((int) context.getInputBlock().getNumChannels() <= processors.size());
68 jassert ((int) context.getOutputBlock().getNumChannels() <= processors.size());
69
70 auto numChannels = static_cast<size_t> (jmin (context.getInputBlock().getNumChannels(),
71 context.getOutputBlock().getNumChannels()));
72
73 for (size_t chan = 0; chan < numChannels; ++chan)
74 processors[(int) chan]->process (MonoProcessContext<ProcessContext> (context, chan));
75 }
76
77 typename StateType::Ptr state;
78
79private:
80 template <typename ProcessContext>
81 struct MonoProcessContext : public ProcessContext
82 {
83 MonoProcessContext (const ProcessContext& multiChannelContext, size_t channelToUse)
85 {}
86
87 size_t channel;
88
89 typename ProcessContext::ConstAudioBlockType getInputBlock() const noexcept { return ProcessContext::getInputBlock() .getSingleChannelBlock (channel); }
90 typename ProcessContext::AudioBlockType getOutputBlock() const noexcept { return ProcessContext::getOutputBlock().getSingleChannelBlock (channel); }
91 };
92
94};
95
96} // namespace juce::dsp
An array designed for holding objects.
int size() const noexcept
Returns the number of items currently in the array.
ObjectClass * add(ObjectClass *newObject)
Appends a new object to the end of the array.
void removeRange(int startIndex, int numberToRemove, bool deleteObjects=true)
Removes a range of objects from the array.
#define jassert(expression)
Platform-independent assertion macro.
constexpr Type jmin(Type a, Type b)
Returns the smaller of two values.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
Definition juce_Memory.h:88
This structure is passed into a DSP algorithm's prepare() method, and contains information about vari...
Converts a mono processor class into a multi-channel version by duplicating it and applying multichan...