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_AudioProcessorGraph.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{
28
29//==============================================================================
45class JUCE_API AudioProcessorGraph : public AudioProcessor,
47{
48public:
49 //==============================================================================
52
57
59 struct NodeID
60 {
61 NodeID() {}
62 explicit NodeID (uint32 i) : uid (i) {}
63
64 uint32 uid = 0;
65
66 bool operator== (const NodeID& other) const noexcept { return uid == other.uid; }
67 bool operator!= (const NodeID& other) const noexcept { return uid != other.uid; }
68 bool operator< (const NodeID& other) const noexcept { return uid < other.uid; }
69 };
70
71 //==============================================================================
77 enum { midiChannelIndex = 0x1000 };
78
79 //==============================================================================
84 {
85 auto tie() const { return std::tie (nodeID, channelIndex); }
86
87 public:
88 NodeID nodeID;
89 int channelIndex;
90
91 bool isMIDI() const noexcept { return channelIndex == midiChannelIndex; }
92
93 bool operator== (const NodeAndChannel& other) const noexcept { return tie() == other.tie(); }
94 bool operator!= (const NodeAndChannel& other) const noexcept { return tie() != other.tie(); }
95 bool operator< (const NodeAndChannel& other) const noexcept { return tie() < other.tie(); }
96 };
97
98 //==============================================================================
103 class JUCE_API Node : public ReferenceCountedObject
104 {
105 public:
106 //==============================================================================
111
113 AudioProcessor* getProcessor() const noexcept { return processor.get(); }
114
122
123 //==============================================================================
125 bool isBypassed() const noexcept
126 {
127 if (processor != nullptr)
128 {
129 if (auto* bypassParam = processor->getBypassParameter())
130 return ! approximatelyEqual (bypassParam->getValue(), 0.0f);
131 }
132
133 return bypassed;
134 }
135
137 void setBypassed (bool shouldBeBypassed) noexcept
138 {
139 if (processor != nullptr)
140 {
141 if (auto* bypassParam = processor->getBypassParameter())
142 bypassParam->setValueNotifyingHost (shouldBeBypassed ? 1.0f : 0.0f);
143 }
144
145 bypassed = shouldBeBypassed;
146 }
147
148 //==============================================================================
151
158 bool userRequestedBypass() const { return bypassed; }
159
165 : nodeID (n), processor (std::move (p))
166 {
167 jassert (processor != nullptr);
168 }
169
170 private:
171 //==============================================================================
173 std::atomic<bool> bypassed { false };
174
176 };
177
178 //==============================================================================
183 struct JUCE_API Connection
184 {
185 //==============================================================================
186 Connection() = default;
187 Connection (NodeAndChannel source, NodeAndChannel destination) noexcept;
188
189 Connection (const Connection&) = default;
190 Connection& operator= (const Connection&) = default;
191
192 bool operator== (const Connection&) const noexcept;
193 bool operator!= (const Connection&) const noexcept;
194 bool operator< (const Connection&) const noexcept;
195
196 //==============================================================================
198 NodeAndChannel source { {}, 0 };
199
201 NodeAndChannel destination { {}, 0 };
202 };
203
204 //==============================================================================
211 enum class UpdateKind
212 {
213 sync,
214 async,
216 none
218 };
219
220 //==============================================================================
224 void clear (UpdateKind = UpdateKind::sync);
225
227 const ReferenceCountedArray<Node>& getNodes() const noexcept;
228
230 int getNumNodes() const noexcept { return getNodes().size(); }
231
236 Node::Ptr getNode (int index) const noexcept { return getNodes()[index]; }
237
242 Node* getNodeForId (NodeID) const;
243
255 Node::Ptr addNode (std::unique_ptr<AudioProcessor> newProcessor, std::optional<NodeID> nodeId = std::nullopt, UpdateKind = UpdateKind::sync);
256
260 Node::Ptr removeNode (NodeID, UpdateKind = UpdateKind::sync);
261
265 Node::Ptr removeNode (Node*, UpdateKind = UpdateKind::sync);
266
268 std::vector<Connection> getConnections() const;
269
271 bool isConnected (const Connection&) const noexcept;
272
276 bool isConnected (NodeID possibleSourceNodeID, NodeID possibleDestNodeID) const noexcept;
277
281 bool isAnInputTo (const Node& source, const Node& destination) const noexcept;
282
286 bool isAnInputTo (NodeID source, NodeID destination) const noexcept;
287
289 bool canConnect (const Connection&) const;
290
296 bool addConnection (const Connection&, UpdateKind = UpdateKind::sync);
297
299 bool removeConnection (const Connection&, UpdateKind = UpdateKind::sync);
300
302 bool disconnectNode (NodeID, UpdateKind = UpdateKind::sync);
303
309 bool isConnectionLegal (const Connection&) const;
310
316 bool removeIllegalConnections (UpdateKind = UpdateKind::sync);
317
324 void rebuild();
325
326 //==============================================================================
341 {
342 public:
346 {
347 audioInputNode,
350 audioOutputNode,
353 midiInputNode,
356 midiOutputNode
359 };
360
361 //==============================================================================
363 IODeviceType getType() const noexcept { return type; }
364
367 AudioProcessorGraph* getParentGraph() const noexcept { return graph; }
368
370 bool isInput() const noexcept;
372 bool isOutput() const noexcept;
373
374 //==============================================================================
375 AudioGraphIOProcessor (IODeviceType);
376 ~AudioGraphIOProcessor() override;
377
378 const String getName() const override;
379 void fillInPluginDescription (PluginDescription&) const override;
380 void prepareToPlay (double newSampleRate, int estimatedSamplesPerBlock) override;
381 void releaseResources() override;
382 void processBlock (AudioBuffer<float>& , MidiBuffer&) override;
383 void processBlock (AudioBuffer<double>&, MidiBuffer&) override;
384 bool supportsDoublePrecisionProcessing() const override;
385
386 double getTailLengthSeconds() const override;
387 bool acceptsMidi() const override;
388 bool producesMidi() const override;
389
390 bool hasEditor() const override;
391 AudioProcessorEditor* createEditor() override;
392
393 int getNumPrograms() override;
394 int getCurrentProgram() override;
395 void setCurrentProgram (int) override;
396 const String getProgramName (int) override;
397 void changeProgramName (int, const String&) override;
398
399 void getStateInformation (juce::MemoryBlock& destData) override;
400 void setStateInformation (const void* data, int sizeInBytes) override;
401
403 void setParentGraph (AudioProcessorGraph*);
404
405 private:
406 const IODeviceType type;
407 AudioProcessorGraph* graph = nullptr;
408
410 };
411
412 //==============================================================================
413 const String getName() const override;
414 void prepareToPlay (double, int) override;
415 void releaseResources() override;
416 void processBlock (AudioBuffer<float>&, MidiBuffer&) override;
417 void processBlock (AudioBuffer<double>&, MidiBuffer&) override;
418 bool supportsDoublePrecisionProcessing() const override;
419
420 void reset() override;
421 void setNonRealtime (bool) noexcept override;
422
423 double getTailLengthSeconds() const override;
424 bool acceptsMidi() const override;
425 bool producesMidi() const override;
426
427 bool hasEditor() const override { return false; }
428 AudioProcessorEditor* createEditor() override { return nullptr; }
429 int getNumPrograms() override { return 0; }
430 int getCurrentProgram() override { return 0; }
431 void setCurrentProgram (int) override { }
432 const String getProgramName (int) override { return {}; }
433 void changeProgramName (int, const String&) override { }
434 void getStateInformation (juce::MemoryBlock&) override;
435 void setStateInformation (const void* data, int sizeInBytes) override;
436
437private:
438 class Pimpl;
440
442};
443
444} // namespace juce
A multi-channel buffer containing floating point audio samples.
Base class for an active instance of a plugin.
Base class for the component that acts as the GUI for an AudioProcessor.
A special type of AudioProcessor that can live inside an AudioProcessorGraph in order to use the audi...
AudioProcessorGraph * getParentGraph() const noexcept
Returns the parent graph to which this processor belongs, or nullptr if it hasn't yet been added to o...
IODeviceType getType() const noexcept
Returns the mode of this processor.
IODeviceType
Specifies the mode in which this processor will operate.
Represents an input or output channel of a node in an AudioProcessorGraph.
Represents one of the nodes, or processors, in an AudioProcessorGraph.
void setBypassed(bool shouldBeBypassed) noexcept
Tell this node to bypass processing.
bool isBypassed() const noexcept
Returns if the node is bypassed or not.
AudioProcessor * getProcessor() const noexcept
The actual processor object that this node represents.
NamedValueSet properties
A set of user-definable properties that are associated with this node.
const NodeID nodeID
The ID number assigned to this node.
A type of AudioProcessor which plays back a graph of other AudioProcessors.
int getNumPrograms() override
Returns the number of preset programs the processor supports.
void setCurrentProgram(int) override
Called by the host to change the current program.
Node::Ptr getNode(int index) const noexcept
Returns a pointer to one of the nodes in the graph.
void changeProgramName(int, const String &) override
Called by the host to rename a program.
int getCurrentProgram() override
Returns the number of the currently active program.
~AudioProcessorGraph() override
Destructor.
AudioProcessorEditor * createEditor() override
Creates the processor's GUI.
UpdateKind
Indicates how the graph should be updated after a change.
const String getProgramName(int) override
Must return the name of a given program.
Base class for audio processing classes or plugins.
Holds a list of ChangeListeners, and sends messages to them when instructed.
A class to hold a resizable block of raw data.
Holds a sequence of time-stamped midi events.
Holds a set of named var objects.
A small class to represent some facts about a particular type of plug-in.
Holds a list of objects derived from ReferenceCountedObject, or which implement basic reference-count...
int size() const noexcept
Returns the current number of objects in the array.
A smart-pointer class which points to a reference-counted object.
A base class which provides methods for reference-counting.
The JUCE String class!
Definition juce_String.h:53
#define jassert(expression)
Platform-independent assertion macro.
#define JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(className)
This is a shorthand way of writing both a JUCE_DECLARE_NON_COPYABLE and JUCE_LEAK_DETECTOR macro for ...
JUCE Namespace.
constexpr bool approximatelyEqual(Type a, Type b, Tolerance< Type > tolerance=Tolerance< Type >{} .withAbsolute(std::numeric_limits< Type >::min()) .withRelative(std::numeric_limits< Type >::epsilon()))
Returns true if the two floating-point numbers are approximately equal.
unsigned int uint32
A platform-independent 32-bit unsigned integer type.
Represents a connection between two channels of two nodes in an AudioProcessorGraph.
Each node in the graph has a UID of this type.
sync
T tie(T... args)