LMMS
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
27{
28namespace dsp
29{
30
41template <typename MonoProcessorType, typename StateType>
43{
44 ProcessorDuplicator() : state (new StateType()) {}
45 ProcessorDuplicator (StateType* stateToUse) : state (stateToUse) {}
46 ProcessorDuplicator (typename StateType::Ptr stateToUse) : state (std::move (stateToUse)) {}
49
50 void prepare (const ProcessSpec& spec)
51 {
52 processors.removeRange ((int) spec.numChannels, processors.size());
53
54 while (static_cast<size_t> (processors.size()) < spec.numChannels)
55 processors.add (new MonoProcessorType (state));
56
57 auto monoSpec = spec;
58 monoSpec.numChannels = 1;
59
60 for (auto* p : processors)
61 p->prepare (monoSpec);
62 }
63
64 void reset() noexcept { for (auto* p : processors) p->reset(); }
65
66 template <typename ProcessContext>
67 void process (const ProcessContext& context) noexcept
68 {
69 jassert ((int) context.getInputBlock().getNumChannels() <= processors.size());
70 jassert ((int) context.getOutputBlock().getNumChannels() <= processors.size());
71
72 auto numChannels = static_cast<size_t> (jmin (context.getInputBlock().getNumChannels(),
73 context.getOutputBlock().getNumChannels()));
74
75 for (size_t chan = 0; chan < numChannels; ++chan)
76 processors[(int) chan]->process (MonoProcessContext<ProcessContext> (context, chan));
77 }
78
79 typename StateType::Ptr state;
80
81private:
82 template <typename ProcessContext>
83 struct MonoProcessContext : public ProcessContext
84 {
85 MonoProcessContext (const ProcessContext& multiChannelContext, size_t channelToUse)
86 : ProcessContext (multiChannelContext), channel (channelToUse)
87 {}
88
89 size_t channel;
90
91 typename ProcessContext::ConstAudioBlockType getInputBlock() const noexcept { return ProcessContext::getInputBlock() .getSingleChannelBlock (channel); }
92 typename ProcessContext::AudioBlockType getOutputBlock() const noexcept { return ProcessContext::getOutputBlock().getSingleChannelBlock (channel); }
93 };
94
95 juce::OwnedArray<MonoProcessorType> processors;
96};
97
98} // namespace dsp
99} // namespace juce
Type jmin(const Type a, const Type b)
Definition MathsFunctions.h:60
#define noexcept
Definition DistrhoDefines.h:72
#define jassert(expression)
Definition juce_AudioBlock.h:29
Definition carla_juce.cpp:31
Definition juce_Uuid.h:141
Definition juce_ProcessContext.h:38
uint32 numChannels
Definition juce_ProcessContext.h:46
Definition juce_ProcessorDuplicator.h:84
ProcessContext::ConstAudioBlockType getInputBlock() const noexcept
Definition juce_ProcessorDuplicator.h:91
MonoProcessContext(const ProcessContext &multiChannelContext, size_t channelToUse)
Definition juce_ProcessorDuplicator.h:85
ProcessContext::AudioBlockType getOutputBlock() const noexcept
Definition juce_ProcessorDuplicator.h:92
size_t channel
Definition juce_ProcessorDuplicator.h:89
ProcessorDuplicator(StateType *stateToUse)
Definition juce_ProcessorDuplicator.h:45
void process(const ProcessContext &context) noexcept
Definition juce_ProcessorDuplicator.h:67
ProcessorDuplicator()
Definition juce_ProcessorDuplicator.h:44
void reset() noexcept
Definition juce_ProcessorDuplicator.h:64
void prepare(const ProcessSpec &spec)
Definition juce_ProcessorDuplicator.h:50
StateType::Ptr state
Definition juce_ProcessorDuplicator.h:79
ProcessorDuplicator(const ProcessorDuplicator &)=default
ProcessorDuplicator(ProcessorDuplicator &&)=default
ProcessorDuplicator(typename StateType::Ptr stateToUse)
Definition juce_ProcessorDuplicator.h:46
juce::OwnedArray< MonoProcessorType > processors
Definition juce_ProcessorDuplicator.h:95
uch * p
Definition crypt.c:594
#define const
Definition zconf.h:137