Vital
Loading...
Searching...
No Matches
processor_router.h
Go to the documentation of this file.
1
11#pragma once
12
13#include "processor.h"
14#include "circular_queue.h"
15
16#include <map>
17#include <set>
18#include <vector>
19
20namespace vital {
21
22 class Feedback;
23
34 class ProcessorRouter : public Processor {
35 public:
42 ProcessorRouter(int num_inputs = 0, int num_outputs = 0, bool control_rate = false);
43
48 ProcessorRouter(const ProcessorRouter& original);
49
53 virtual ~ProcessorRouter();
54
59 virtual Processor* clone() const override {
60 return new ProcessorRouter(*this);
61 }
62
70 virtual void process(int num_samples) override;
71
75 virtual void init() override;
76
83 virtual void setSampleRate(int sample_rate) override;
84
91 virtual void setOversampleAmount(int oversample) override;
92
100 virtual void addProcessor(Processor* processor);
101
106 virtual void addProcessorRealTime(Processor* processor);
107
112 virtual void addIdleProcessor(Processor* processor);
113
118 virtual void removeProcessor(Processor* processor);
119
120 // Any time new dependencies are added into the ProcessorRouter graph, we
121 // should call _connect_ on the destination Processor and source Output.
130 void connect(Processor* destination, const Output* source, int index);
131
137 void disconnect(const Processor* destination, const Output* source);
138
145 bool isDownstream(const Processor* first, const Processor* second) const;
146
153 bool areOrdered(const Processor* first, const Processor* second) const;
154
160 virtual bool isPolyphonic(const Processor* processor) const;
161
167
173
178 virtual void resetFeedbacks(poly_mask reset_mask);
179
180 protected:
181 // When we create a cycle into the ProcessorRouter graph, we must insert
182 // a Feedback node and add it here.
187 virtual void addFeedback(Feedback* feedback);
188
193 virtual void removeFeedback(Feedback* feedback);
194
195 // Makes sure _processor_ runs in a topologically sorted order in
196 // relation to all other Processors in _this_.
201 void reorder(Processor* processor);
202
203 // Ensures our local copies of all processors and feedback processors match the master order.
207 virtual void updateAllProcessors();
208
214
215 // Will create local copies of added processors.
219 virtual void createAddedProcessors();
220
221 // Will delete local copies of removed processors.
225 virtual void deleteRemovedProcessors();
226
227 // Returns the ancestor of _processor_ which is a child of _this_.
228 // Returns null if _processor_ is not a descendant of _this_.
234 const Processor* getContext(const Processor* processor) const;
235
240 void getDependencies(const Processor* processor) const;
241
242 // Returns the processor for this voice from the globally created one.
248 Processor* getLocalProcessor(const Processor* global_processor);
249
250 std::shared_ptr<CircularQueue<Processor*>> global_order_;
251 std::shared_ptr<CircularQueue<Processor*>> global_reorder_;
253
254 std::map<const Processor*, std::pair<int, std::unique_ptr<Processor>>> processors_;
255 std::map<const Processor*, std::unique_ptr<Processor>> idle_processors_;
256
257 std::shared_ptr<std::vector<const Feedback*>> global_feedback_order_;
258 std::vector<Feedback*> local_feedback_order_;
259 std::map<const Processor*, std::pair<int, std::unique_ptr<Feedback>>> feedback_processors_;
260
261 std::shared_ptr<int> global_changes_;
263
264 std::shared_ptr<CircularQueue<const Processor*>> dependencies_;
265 std::shared_ptr<CircularQueue<const Processor*>> dependencies_visited_;
266 std::shared_ptr<CircularQueue<const Processor*>> dependency_inputs_;
267
268 JUCE_LEAK_DETECTOR(ProcessorRouter)
269 };
270} // namespace vital
271
A generic circular buffer (FIFO) data structure that allows adding and removing elements efficiently.
Definition circular_queue.h:32
A processor that buffers and replays audio, providing a feedback loop mechanism.
Definition feedback.h:26
Base class for all signal-processing units in Vital.
Definition processor.h:212
virtual bool isPolyphonic() const
Checks if this Processor is polyphonic by querying its ProcessorRouter.
Definition processor.cpp:73
A specialized Processor that manages a directed graph of Processors and ensures correct processing or...
Definition processor_router.h:34
std::map< const Processor *, std::pair< int, std::unique_ptr< Feedback > > > feedback_processors_
Map of global to local Feedback processors.
Definition processor_router.h:259
virtual void updateAllProcessors()
Updates all processors to match the global order. Called when changes occur.
Definition processor_router.cpp:300
std::shared_ptr< CircularQueue< const Processor * > > dependencies_
Queue for dependencies calculations.
Definition processor_router.h:264
virtual Processor * clone() const override
Creates a copy of this ProcessorRouter.
Definition processor_router.h:59
int local_changes_
Local change counter to track synchronization with global changes.
Definition processor_router.h:262
virtual ~ProcessorRouter()
Destructor.
Definition processor_router.cpp:55
virtual void deleteRemovedProcessors()
Deletes any processors that were removed at the global level but not yet removed locally.
Definition processor_router.cpp:337
void disconnect(const Processor *destination, const Output *source)
Disconnects a source Output from a destination Processor.
Definition processor_router.cpp:182
virtual void removeProcessor(Processor *processor)
Removes a Processor from this router.
Definition processor_router.cpp:151
std::map< const Processor *, std::pair< int, std::unique_ptr< Processor > > > processors_
Map of global to local Processors.
Definition processor_router.h:254
virtual ProcessorRouter * getPolyRouter()
Gets the polyphonic router that corresponds to this ProcessorRouter.
Definition processor_router.cpp:269
ProcessorRouter(int num_inputs=0, int num_outputs=0, bool control_rate=false)
Constructs a ProcessorRouter with a specified number of inputs and outputs.
Definition processor_router.cpp:16
bool isDownstream(const Processor *first, const Processor *second) const
Checks if one Processor is downstream from another, i.e., if there's a path from the second to the fi...
Definition processor_router.cpp:233
std::shared_ptr< int > global_changes_
Global change counter.
Definition processor_router.h:261
virtual void setOversampleAmount(int oversample) override
Sets the oversampling amount for all Processors in this router.
Definition processor_router.cpp:104
virtual void addFeedback(Feedback *feedback)
Adds a Feedback node to handle a feedback loop introduced by a connection.
Definition processor_router.cpp:278
virtual void removeFeedback(Feedback *feedback)
Removes a previously added Feedback node.
Definition processor_router.cpp:285
virtual void init() override
Initializes the ProcessorRouter and all its Processors.
Definition processor_router.cpp:84
virtual ProcessorRouter * getMonoRouter()
Gets the mono router that corresponds to this ProcessorRouter.
Definition processor_router.cpp:263
virtual void setSampleRate(int sample_rate) override
Sets the sample rate for all Processors in this router.
Definition processor_router.cpp:90
std::shared_ptr< std::vector< const Feedback * > > global_feedback_order_
Global order of Feedback nodes.
Definition processor_router.h:257
std::shared_ptr< CircularQueue< Processor * > > global_order_
Global processing order reference.
Definition processor_router.h:250
std::vector< Feedback * > local_feedback_order_
Local copies of Feedback nodes.
Definition processor_router.h:258
virtual void createAddedProcessors()
Creates any processors that were added at the global level but not yet replicated locally.
Definition processor_router.cpp:309
virtual void addIdleProcessor(Processor *processor)
Adds a Processor that should remain idle (not processed) in the router.
Definition processor_router.cpp:146
bool areOrdered(const Processor *first, const Processor *second) const
Checks if the order of two Processors is fixed in the router's processing sequence.
Definition processor_router.cpp:238
std::shared_ptr< CircularQueue< const Processor * > > dependencies_visited_
Queue of visited processors for dependencies calc.
Definition processor_router.h:265
std::shared_ptr< CircularQueue< const Processor * > > dependency_inputs_
Queue of processors to check inputs for dependencies.
Definition processor_router.h:266
std::map< const Processor *, std::unique_ptr< Processor > > idle_processors_
Idle Processors that are not active in the graph.
Definition processor_router.h:255
virtual void resetFeedbacks(poly_mask reset_mask)
Resets all Feedback nodes within this router using a reset mask.
Definition processor_router.cpp:273
void reorder(Processor *processor)
Reorders the internal processing sequence to account for a Processor's dependencies.
Definition processor_router.cpp:197
force_inline bool shouldUpdate()
Checks if local changes need to be synchronized with global changes.
Definition processor_router.h:213
virtual void addProcessorRealTime(Processor *processor)
Adds a Processor to the router in real-time (no memory allocations).
Definition processor_router.cpp:129
void connect(Processor *destination, const Output *source, int index)
Connects a source Output to a destination Processor input by index.
Definition processor_router.cpp:168
CircularQueue< Processor * > local_order_
Local ordering of Processors.
Definition processor_router.h:252
std::shared_ptr< CircularQueue< Processor * > > global_reorder_
Temporary storage for reorder operations.
Definition processor_router.h:251
void getDependencies(const Processor *processor) const
Populates the internal dependencies structure for a given Processor.
Definition processor_router.cpp:380
virtual void process(int num_samples) override
Processes audio through all Processors managed by this router.
Definition processor_router.cpp:57
const Processor * getContext(const Processor *processor) const
Gets the processor context within this router for a global Processor reference.
Definition processor_router.cpp:366
Processor * getLocalProcessor(const Processor *global_processor)
Retrieves the local instance of a globally defined Processor.
Definition processor_router.cpp:376
virtual void addProcessor(Processor *processor)
Adds a Processor to be managed by this router.
Definition processor_router.cpp:121
#define force_inline
Definition common.h:23
Contains classes and functions used within the Vital synthesizer framework.
Declares the Processor class and related structures for handling audio processing in a polyphonic con...
Holds and manages a buffer of samples (poly_float) for a Processor's output.
Definition processor.h:35
Represents a vector of integer values using SIMD instructions.
Definition poly_values.h:56