17 Processor(num_inputs, num_outputs, control_rate),
21 global_feedback_order_(new std::vector<const
Feedback*>()),
22 global_changes_(new int(0)), local_changes_(0),
29 global_order_(original.global_order_), global_reorder_(original.global_reorder_),
30 global_feedback_order_(original.global_feedback_order_),
31 global_changes_(original.global_changes_),
32 local_changes_(original.local_changes_) {
39 for (
int i = 0; i < num_processors; ++i) {
41 std::unique_ptr<Processor>
clone(next->
clone());
47 for (
int i = 0; i < num_feedbacks; ++i) {
63 for (
int i = 0; i < num_feedbacks; ++i)
69 if (processor->enabled()) {
70 int processor_samples = normal_samples * processor->getOversampleAmount();
71 VITAL_ASSERT(processor->checkInputAndOutputSize(processor_samples));
72 processor->process(processor_samples);
78 for (
int i = 0; i < num_feedbacks; ++i) {
95 int num_processors =
static_cast<int>(
local_order_.size());
96 for (
int i = 0; i < num_processors; ++i)
100 for (
int i = 0; i < num_feedbacks; ++i)
110 idle_processor.second->setOversampleAmount(oversample);
112 int num_processors =
static_cast<int>(
local_order_.size());
113 for (
int i = 0; i < num_processors; ++i)
117 for (
int i = 0; i < num_feedbacks; ++i)
131 (*global_changes_)++;
139 processors_[processor] = { 0, std::unique_ptr<Processor>(processor) };
142 for (
int i = 0; i < processor->
numInputs(); ++i)
152 for (
int i = 0; i < processor->
numInputs(); ++i)
156 (*global_changes_)++;
164 processor->
router(
nullptr);
172 feedback->
plug(source);
173 destination->
plug(feedback, index);
185 for (
int i = 0; i < destination->
numInputs(); ++i) {
198 (*global_changes_)++;
208 int num_processors =
static_cast<int>(
processors_.size());
211 for (
int i = 0; i < num_processors; ++i) {
213 if (current_processor != processor &&
dependencies_->contains(current_processor))
220 for (
int i = 0; i < num_processors; ++i) {
222 if (current_processor != processor && !
dependencies_->contains(current_processor))
226 for (
int i = 0; i < num_processors; ++i)
242 if (first_context && second_context) {
244 for (
size_t i = 0; i < num_processors; ++i) {
275 feedback->
reset(reset_mask);
286 (*global_changes_)++;
317 for (
int i = 0; i < num_processors; ++i) {
329 for (
int i = 0; i < num_feedbacks; ++i) {
360 for (
int i = 0; i < num_feedbacks; ++i) {
370 context = context->
router();
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
Processor * clone() const override
Clones this Processor for polyphonic expansion. Must be overridden by subclasses.
Definition feedback.h:42
Base class for all signal-processing units in Vital.
Definition processor.h:212
force_inline int numInputs() const
Returns the total number of Input pointers (owned or otherwise).
Definition processor.h:557
virtual void setOversampleAmount(int oversample)
Sets the oversampling amount and updates the effective sample rate.
Definition processor.h:293
virtual bool hasState() const
Indicates whether this Processor requires per-voice state.
Definition processor.h:238
virtual bool isPolyphonic() const
Checks if this Processor is polyphonic by querying its ProcessorRouter.
Definition processor.cpp:73
force_inline Input * input(unsigned int index=0) const
Retrieves the Input pointer at a given index.
Definition processor.h:587
static const Output null_source_
A null (dummy) source used for unconnected inputs.
Definition processor.h:665
force_inline int getOversampleAmount() const
Retrieves the current oversampling factor.
Definition processor.h:334
void plug(const Output *source)
Connects an external Output to this Processor's first input.
Definition processor.cpp:79
virtual void setSampleRate(int sample_rate)
Updates the sample rate of this Processor (scaled by oversampling).
Definition processor.h:285
ProcessorRouter * router_
The ProcessorRouter that manages this Processor.
Definition processor.h:663
virtual Processor * clone() const =0
Clones this Processor for polyphonic expansion. Must be overridden by subclasses.
force_inline void router(ProcessorRouter *router)
Sets the ProcessorRouter that owns or manages this Processor.
Definition processor.h:507
virtual void init()
Called after constructor, used for any additional initialization. Subclasses can override....
Definition processor.h:258
virtual void reset(poly_mask reset_mask)
Called to reset the Processor's per-voice state (e.g., on note-on).
Definition processor.h:267
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 bool isPolyphonic(const Processor *processor) const
Determines if a given Processor is polyphonic within this router.
Definition processor_router.cpp:257
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
A control-rate variant of the Feedback processor.
Definition feedback.h:86
#define UNUSED(x)
Definition common.h:15
#define VITAL_ASSERT(x)
Definition common.h:11
force_inline bool isFinite(poly_float value)
Checks if all lanes in a poly_float are finite.
Definition poly_utils.h:610
Contains classes and functions used within the Vital synthesizer framework.
constexpr int kMaxModulationConnections
Maximum number of modulation connections allowed.
Definition synth_constants.h:49
Declares the ProcessorRouter class, which manages a graph of Processors and their dependencies.
Holds and manages a buffer of samples (poly_float) for a Processor's output.
Definition processor.h:35
Processor * owner
Owning processor.
Definition processor.h:112
Represents a vector of integer values using SIMD instructions.
Definition poly_values.h:56