Vital
Loading...
Searching...
No Matches
vital::ProcessorRouter Class Reference

A specialized Processor that manages a directed graph of Processors and ensures correct processing order. More...

#include <processor_router.h>

Inheritance diagram for vital::ProcessorRouter:
vital::Processor vital::Decimator vital::FormantFilter vital::FormantManager vital::Phaser vital::SynthModule vital::Upsampler vital::VocalTract vital::ChorusModule vital::CombModule vital::CompressorModule vital::DelayModule vital::DistortionModule vital::EnvelopeModule vital::EqualizerModule vital::FilterFxModule vital::FilterModule vital::FiltersModule vital::FlangerModule vital::FormantModule vital::LfoModule vital::ModulationConnectionProcessor vital::OscillatorModule vital::PhaserModule vital::ProducersModule vital::RandomLfoModule vital::ReorderableEffectChain vital::ReverbModule vital::SampleModule vital::SoundEngine vital::SoundEngine vital::VoiceHandler

Public Member Functions

 ProcessorRouter (int num_inputs=0, int num_outputs=0, bool control_rate=false)
 Constructs a ProcessorRouter with a specified number of inputs and outputs.
 
 ProcessorRouter (const ProcessorRouter &original)
 Copy constructor. Creates a new ProcessorRouter from an existing one.
 
virtual ~ProcessorRouter ()
 Destructor.
 
virtual Processorclone () const override
 Creates a copy of this ProcessorRouter.
 
virtual void process (int num_samples) override
 Processes audio through all Processors managed by this router.
 
virtual void init () override
 Initializes the ProcessorRouter and all its Processors.
 
virtual void setSampleRate (int sample_rate) override
 Sets the sample rate for all Processors in this router.
 
virtual void setOversampleAmount (int oversample) override
 Sets the oversampling amount for all Processors in this router.
 
virtual void addProcessor (Processor *processor)
 Adds a Processor to be managed by this router.
 
virtual void addProcessorRealTime (Processor *processor)
 Adds a Processor to the router in real-time (no memory allocations).
 
virtual void addIdleProcessor (Processor *processor)
 Adds a Processor that should remain idle (not processed) in the router.
 
virtual void removeProcessor (Processor *processor)
 Removes a Processor from this router.
 
void connect (Processor *destination, const Output *source, int index)
 Connects a source Output to a destination Processor input by index.
 
void disconnect (const Processor *destination, const Output *source)
 Disconnects a source Output from a destination Processor.
 
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 first.
 
bool areOrdered (const Processor *first, const Processor *second) const
 Checks if the order of two Processors is fixed in the router's processing sequence.
 
virtual bool isPolyphonic (const Processor *processor) const
 Determines if a given Processor is polyphonic within this router.
 
virtual ProcessorRoutergetMonoRouter ()
 Gets the mono router that corresponds to this ProcessorRouter.
 
virtual ProcessorRoutergetPolyRouter ()
 Gets the polyphonic router that corresponds to this ProcessorRouter.
 
virtual void resetFeedbacks (poly_mask reset_mask)
 Resets all Feedback nodes within this router using a reset mask.
 
- Public Member Functions inherited from vital::Processor
 Processor (int num_inputs, int num_outputs, bool control_rate=false, int max_oversample=1)
 Constructs a Processor with a given number of inputs/outputs and oversampling.
 
virtual ~Processor ()
 Virtual destructor.
 
virtual bool hasState () const
 Indicates whether this Processor requires per-voice state.
 
virtual void processWithInput (const poly_float *audio_in, int num_samples)
 An optional processing function taking explicit input buffer. Fallback is an assertion failure (not supported).
 
virtual void reset (poly_mask reset_mask)
 Called to reset the Processor's per-voice state (e.g., on note-on).
 
virtual void hardReset ()
 Called to perform a "hard" reset for all voices.
 
bool initialized ()
 Returns whether this Processor has been initialized.
 
force_inline bool enabled () const
 Checks if this Processor is enabled.
 
virtual void enable (bool enable)
 Enables or disables this Processor.
 
force_inline int getSampleRate () const
 Retrieves the current (effective) sample rate.
 
force_inline int getOversampleAmount () const
 Retrieves the current oversampling factor.
 
force_inline bool isControlRate () const
 Checks if this Processor is running at control rate (buffer_size == 1).
 
virtual void setControlRate (bool control_rate)
 Sets whether this Processor runs at control rate.
 
force_inline poly_mask getResetMask (int input_index) const
 Retrieves a mask indicating which voices triggered a note-on event. Compares the input's trigger_value to kVoiceOn.
 
force_inline void clearOutputBufferForReset (poly_mask reset_mask, int input_index, int output_index) const
 Clears output samples for voices that are about to be reset, based on the trigger offset.
 
bool inputMatchesBufferSize (int input=0)
 Checks whether the buffer size of a particular input matches the size needed by this Processor.
 
bool checkInputAndOutputSize (int num_samples)
 Checks if all inputs and outputs have buffers big enough for num_samples.
 
virtual bool isPolyphonic () const
 Checks if this Processor is polyphonic by querying its ProcessorRouter.
 
void plug (const Output *source)
 Connects an external Output to this Processor's first input.
 
void plug (const Output *source, unsigned int input_index)
 Connects an external Output to a specified input index.
 
void plug (const Processor *source)
 Connects the first output of a Processor to this Processor's first input.
 
void plug (const Processor *source, unsigned int input_index)
 Connects the first output of a Processor to a specified input index.
 
void plugNext (const Output *source)
 Connects an external Output to the first available (unplugged) input.
 
void plugNext (const Processor *source)
 Connects the first output of a Processor to the first available (unplugged) input.
 
void useInput (Input *input)
 Uses an existing Input object as this Processor's first input.
 
void useInput (Input *input, int index)
 Uses an existing Input object at a specified input index.
 
void useOutput (Output *output)
 Uses an existing Output object as this Processor's first output.
 
void useOutput (Output *output, int index)
 Uses an existing Output object at a specified output index.
 
int connectedInputs ()
 Counts how many inputs are connected to a real source (not null_source_).
 
virtual void unplugIndex (unsigned int input_index)
 Removes the connection at a specified input index, if any.
 
virtual void unplug (const Output *source)
 Removes a connection to a given Output from all inputs.
 
virtual void unplug (const Processor *source)
 Removes connections to all outputs from a given Processor.
 
virtual void numInputsChanged ()
 Called when the number of inputs changes (e.g., new connections). Subclasses may override for dynamic behavior.
 
force_inline void router (ProcessorRouter *router)
 Sets the ProcessorRouter that owns or manages this Processor.
 
force_inline ProcessorRouterrouter () const
 Returns the ProcessorRouter that currently owns this Processor.
 
ProcessorRoutergetTopLevelRouter () const
 Gets the topmost (root) ProcessorRouter by traversing parent routers.
 
virtual void registerInput (Input *input, int index)
 Registers a new input, appending it to the input list.
 
virtual OutputregisterOutput (Output *output, int index)
 Registers a new Output in the output list at a specified index.
 
virtual void registerInput (Input *input)
 Registers a new Input by appending it to the end of the input list.
 
virtual OutputregisterOutput (Output *output)
 Registers a new Output by appending it to the end of the output list.
 
force_inline int numInputs () const
 Returns the total number of Input pointers (owned or otherwise).
 
force_inline int numOutputs () const
 Returns the total number of Output pointers (owned or otherwise).
 
force_inline int numOwnedInputs () const
 Returns how many Input objects this Processor owns.
 
force_inline int numOwnedOutputs () const
 Returns how many Output objects this Processor owns.
 
force_inline Inputinput (unsigned int index=0) const
 Retrieves the Input pointer at a given index.
 
force_inline bool isInputSourcePolyphonic (int index=0)
 Checks if the input source at a given index is polyphonic.
 
force_inline InputownedInput (unsigned int index=0) const
 Retrieves an owned Input pointer at a given index.
 
force_inline Outputoutput (unsigned int index=0) const
 Retrieves the Output pointer at a given index.
 
force_inline OutputownedOutput (unsigned int index=0) const
 Retrieves an owned Output pointer at a given index.
 
void setPluggingStart (int start)
 Sets the position at which plugNext starts searching for an open input.
 

Protected Member Functions

virtual void addFeedback (Feedback *feedback)
 Adds a Feedback node to handle a feedback loop introduced by a connection.
 
virtual void removeFeedback (Feedback *feedback)
 Removes a previously added Feedback node.
 
void reorder (Processor *processor)
 Reorders the internal processing sequence to account for a Processor's dependencies.
 
virtual void updateAllProcessors ()
 Updates all processors to match the global order. Called when changes occur.
 
force_inline bool shouldUpdate ()
 Checks if local changes need to be synchronized with global changes.
 
virtual void createAddedProcessors ()
 Creates any processors that were added at the global level but not yet replicated locally.
 
virtual void deleteRemovedProcessors ()
 Deletes any processors that were removed at the global level but not yet removed locally.
 
const ProcessorgetContext (const Processor *processor) const
 Gets the processor context within this router for a global Processor reference.
 
void getDependencies (const Processor *processor) const
 Populates the internal dependencies structure for a given Processor.
 
ProcessorgetLocalProcessor (const Processor *global_processor)
 Retrieves the local instance of a globally defined Processor.
 
- Protected Member Functions inherited from vital::Processor
OutputaddOutput (int oversample=1)
 Creates and registers a new Output. Handles control rate vs. audio rate.
 
InputaddInput ()
 Creates and registers a new Input, initially connected to null_source_.
 

Protected Attributes

std::shared_ptr< CircularQueue< Processor * > > global_order_
 Global processing order reference.
 
std::shared_ptr< CircularQueue< Processor * > > global_reorder_
 Temporary storage for reorder operations.
 
CircularQueue< Processor * > local_order_
 Local ordering of Processors.
 
std::map< const Processor *, std::pair< int, std::unique_ptr< Processor > > > processors_
 Map of global to local Processors.
 
std::map< const Processor *, std::unique_ptr< Processor > > idle_processors_
 Idle Processors that are not active in the graph.
 
std::shared_ptr< std::vector< const Feedback * > > global_feedback_order_
 Global order of Feedback nodes.
 
std::vector< Feedback * > local_feedback_order_
 Local copies of Feedback nodes.
 
std::map< const Processor *, std::pair< int, std::unique_ptr< Feedback > > > feedback_processors_
 Map of global to local Feedback processors.
 
std::shared_ptr< int > global_changes_
 Global change counter.
 
int local_changes_
 Local change counter to track synchronization with global changes.
 
std::shared_ptr< CircularQueue< const Processor * > > dependencies_
 Queue for dependencies calculations.
 
std::shared_ptr< CircularQueue< const Processor * > > dependencies_visited_
 Queue of visited processors for dependencies calc.
 
std::shared_ptr< CircularQueue< const Processor * > > dependency_inputs_
 Queue of processors to check inputs for dependencies.
 
- Protected Attributes inherited from vital::Processor
std::shared_ptr< ProcessorStatestate_
 Shared state (sample rate, oversample, etc.)
 
int plugging_start_
 The index at which plugNext starts searching for an unplugged input.
 
std::vector< std::shared_ptr< Input > > owned_inputs_
 Inputs owned by this Processor.
 
std::vector< std::shared_ptr< Output > > owned_outputs_
 Outputs owned by this Processor.
 
std::shared_ptr< std::vector< Input * > > inputs_
 All inputs, owned or external.
 
std::shared_ptr< std::vector< Output * > > outputs_
 All outputs, owned or external.
 
ProcessorRouterrouter_
 The ProcessorRouter that manages this Processor.
 

Additional Inherited Members

- Static Protected Attributes inherited from vital::Processor
static const Output null_source_
 A null (dummy) source used for unconnected inputs.
 

Detailed Description

A specialized Processor that manages a directed graph of Processors and ensures correct processing order.

ProcessorRouter maintains a list of Processors and Feedback objects, and ensures that the audio/control graph is executed in the correct order each audio block. It manages detection of cycles, insertion of Feedback nodes, and propagation of sample rate and oversampling changes.

This class is central to Vital's flexible and modular signal routing architecture.

Constructor & Destructor Documentation

◆ ProcessorRouter() [1/2]

vital::ProcessorRouter::ProcessorRouter ( int num_inputs = 0,
int num_outputs = 0,
bool control_rate = false )

Constructs a ProcessorRouter with a specified number of inputs and outputs.

Parameters
num_inputsNumber of initial inputs.
num_outputsNumber of initial outputs.
control_rateWhether this router runs at control rate or not.

◆ ProcessorRouter() [2/2]

vital::ProcessorRouter::ProcessorRouter ( const ProcessorRouter & original)

Copy constructor. Creates a new ProcessorRouter from an existing one.

Parameters
originalThe ProcessorRouter to copy.

◆ ~ProcessorRouter()

vital::ProcessorRouter::~ProcessorRouter ( )
virtual

Destructor.

Member Function Documentation

◆ addFeedback()

void vital::ProcessorRouter::addFeedback ( Feedback * feedback)
protectedvirtual

Adds a Feedback node to handle a feedback loop introduced by a connection.

Parameters
feedbackThe Feedback node to add.

◆ addIdleProcessor()

void vital::ProcessorRouter::addIdleProcessor ( Processor * processor)
virtual

Adds a Processor that should remain idle (not processed) in the router.

Parameters
processorThe idle Processor to add.

Reimplemented in vital::VoiceHandler.

◆ addProcessor()

void vital::ProcessorRouter::addProcessor ( Processor * processor)
virtual

Adds a Processor to be managed by this router.

Parameters
processorThe Processor to add.

The Processor becomes part of the routing graph. The router ensures that the Processor is run at the appropriate point in the signal flow.

Reimplemented in vital::VoiceHandler.

◆ addProcessorRealTime()

void vital::ProcessorRouter::addProcessorRealTime ( Processor * processor)
virtual

Adds a Processor to the router in real-time (no memory allocations).

Parameters
processorThe Processor to add.

◆ areOrdered()

bool vital::ProcessorRouter::areOrdered ( const Processor * first,
const Processor * second ) const

Checks if the order of two Processors is fixed in the router's processing sequence.

Parameters
firstThe first Processor.
secondThe second Processor.
Returns
True if first is processed before second in the current order, false otherwise.

◆ clone()

◆ connect()

void vital::ProcessorRouter::connect ( Processor * destination,
const Output * source,
int index )

Connects a source Output to a destination Processor input by index.

Parameters
destinationThe Processor to connect to.
sourceThe Output to connect from.
indexThe input index on the destination Processor.

If introducing a cycle, a Feedback node is created to handle it.

◆ createAddedProcessors()

void vital::ProcessorRouter::createAddedProcessors ( )
protectedvirtual

Creates any processors that were added at the global level but not yet replicated locally.

◆ deleteRemovedProcessors()

void vital::ProcessorRouter::deleteRemovedProcessors ( )
protectedvirtual

Deletes any processors that were removed at the global level but not yet removed locally.

◆ disconnect()

void vital::ProcessorRouter::disconnect ( const Processor * destination,
const Output * source )

Disconnects a source Output from a destination Processor.

Parameters
destinationThe Processor that was receiving the connection.
sourceThe source Output that was connected.

◆ getContext()

const Processor * vital::ProcessorRouter::getContext ( const Processor * processor) const
protected

Gets the processor context within this router for a global Processor reference.

Parameters
processorThe Processor to find the local context for.
Returns
The local Processor pointer or nullptr if not found.

◆ getDependencies()

void vital::ProcessorRouter::getDependencies ( const Processor * processor) const
protected

Populates the internal dependencies structure for a given Processor.

Parameters
processorThe Processor to analyze dependencies for.

◆ getLocalProcessor()

Processor * vital::ProcessorRouter::getLocalProcessor ( const Processor * global_processor)
protected

Retrieves the local instance of a globally defined Processor.

Parameters
global_processorThe global Processor pointer.
Returns
A pointer to the local Processor instance.

◆ getMonoRouter()

ProcessorRouter * vital::ProcessorRouter::getMonoRouter ( )
virtual

Gets the mono router that corresponds to this ProcessorRouter.

Returns
A pointer to a mono version of this router, if available, otherwise this router.

Reimplemented in vital::VoiceHandler.

◆ getPolyRouter()

ProcessorRouter * vital::ProcessorRouter::getPolyRouter ( )
virtual

Gets the polyphonic router that corresponds to this ProcessorRouter.

Returns
A pointer to the poly version of this router, which may be this router itself.

Reimplemented in vital::VoiceHandler.

◆ init()

◆ isDownstream()

bool vital::ProcessorRouter::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 first.

Parameters
firstThe Processor to check downstream.
secondThe Processor from which paths are checked.
Returns
True if first is downstream of second, false otherwise.

◆ isPolyphonic()

bool vital::ProcessorRouter::isPolyphonic ( const Processor * processor) const
virtual

Determines if a given Processor is polyphonic within this router.

Parameters
processorThe Processor to check.
Returns
True if the Processor is polyphonic, false otherwise.

Reimplemented in vital::VoiceHandler.

◆ process()

void vital::ProcessorRouter::process ( int num_samples)
overridevirtual

Processes audio through all Processors managed by this router.

Parameters
num_samplesThe number of samples to process.

This ensures all Feedback loops are refreshed and then processes all Processors in the correct order, respecting sample rates and oversampling factors.

Implements vital::Processor.

Reimplemented in vital::Decimator, vital::EffectsModulationHandler, vital::FilterModule, vital::FiltersModule, vital::FormantModule, vital::ModulationConnectionProcessor, vital::OscillatorModule, vital::Phaser, vital::ProducersModule, vital::ReorderableEffectChain, vital::SampleModule, vital::SoundEngine, vital::SynthVoiceHandler, vital::Upsampler, vital::VocalTract, and vital::VoiceHandler.

◆ removeFeedback()

void vital::ProcessorRouter::removeFeedback ( Feedback * feedback)
protectedvirtual

Removes a previously added Feedback node.

Parameters
feedbackThe Feedback node to remove.

◆ removeProcessor()

void vital::ProcessorRouter::removeProcessor ( Processor * processor)
virtual

Removes a Processor from this router.

Parameters
processorThe Processor to remove.

Reimplemented in vital::VoiceHandler.

◆ reorder()

void vital::ProcessorRouter::reorder ( Processor * processor)
protected

Reorders the internal processing sequence to account for a Processor's dependencies.

Parameters
processorThe Processor that may require reordering.

◆ resetFeedbacks()

void vital::ProcessorRouter::resetFeedbacks ( poly_mask reset_mask)
virtual

Resets all Feedback nodes within this router using a reset mask.

Parameters
reset_maskA poly_mask indicating which voices to reset.

Reimplemented in vital::VoiceHandler.

◆ setOversampleAmount()

void vital::ProcessorRouter::setOversampleAmount ( int oversample)
overridevirtual

Sets the oversampling amount for all Processors in this router.

Parameters
oversampleThe oversampling factor.

Updates all Processors and Feedback nodes accordingly.

Reimplemented from vital::Processor.

Reimplemented in vital::Decimator, vital::DelayModule, vital::FilterFxModule, vital::FiltersModule, vital::Phaser, and vital::VoiceHandler.

◆ setSampleRate()

void vital::ProcessorRouter::setSampleRate ( int sample_rate)
overridevirtual

Sets the sample rate for all Processors in this router.

Parameters
sample_rateThe sample rate in Hz.

Also updates the sample rates of all child Processors and Feedback loops.

Reimplemented from vital::Processor.

Reimplemented in vital::CompressorModule, vital::DelayModule, vital::DistortionModule, vital::EqualizerModule, vital::PhaserModule, vital::ReverbModule, and vital::VoiceHandler.

◆ shouldUpdate()

force_inline bool vital::ProcessorRouter::shouldUpdate ( )
inlineprotected

Checks if local changes need to be synchronized with global changes.

Returns
True if updates are required, false otherwise.

◆ updateAllProcessors()

void vital::ProcessorRouter::updateAllProcessors ( )
protectedvirtual

Updates all processors to match the global order. Called when changes occur.

Member Data Documentation

◆ dependencies_

std::shared_ptr<CircularQueue<const Processor*> > vital::ProcessorRouter::dependencies_
protected

Queue for dependencies calculations.

◆ dependencies_visited_

std::shared_ptr<CircularQueue<const Processor*> > vital::ProcessorRouter::dependencies_visited_
protected

Queue of visited processors for dependencies calc.

◆ dependency_inputs_

std::shared_ptr<CircularQueue<const Processor*> > vital::ProcessorRouter::dependency_inputs_
protected

Queue of processors to check inputs for dependencies.

◆ feedback_processors_

std::map<const Processor*, std::pair<int, std::unique_ptr<Feedback> > > vital::ProcessorRouter::feedback_processors_
protected

Map of global to local Feedback processors.

◆ global_changes_

std::shared_ptr<int> vital::ProcessorRouter::global_changes_
protected

Global change counter.

◆ global_feedback_order_

std::shared_ptr<std::vector<const Feedback*> > vital::ProcessorRouter::global_feedback_order_
protected

Global order of Feedback nodes.

◆ global_order_

std::shared_ptr<CircularQueue<Processor*> > vital::ProcessorRouter::global_order_
protected

Global processing order reference.

◆ global_reorder_

std::shared_ptr<CircularQueue<Processor*> > vital::ProcessorRouter::global_reorder_
protected

Temporary storage for reorder operations.

◆ idle_processors_

std::map<const Processor*, std::unique_ptr<Processor> > vital::ProcessorRouter::idle_processors_
protected

Idle Processors that are not active in the graph.

◆ local_changes_

int vital::ProcessorRouter::local_changes_
protected

Local change counter to track synchronization with global changes.

◆ local_feedback_order_

std::vector<Feedback*> vital::ProcessorRouter::local_feedback_order_
protected

Local copies of Feedback nodes.

◆ local_order_

CircularQueue<Processor*> vital::ProcessorRouter::local_order_
protected

Local ordering of Processors.

◆ processors_

std::map<const Processor*, std::pair<int, std::unique_ptr<Processor> > > vital::ProcessorRouter::processors_
protected

Map of global to local Processors.


The documentation for this class was generated from the following files: