26 class ProcessorRouter;
105 if (buffer_is_original)
119 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(
Output)
154 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(
Input)
221 Processor(
int num_inputs,
int num_outputs,
bool control_rate =
false,
int max_oversample = 1);
260 state_->initialized =
true;
278 return state_->initialized;
286 state_->sample_rate = sample_rate *
state_->oversample_amount;
296 state_->oversample_amount = oversample;
327 return state_->sample_rate;
335 return state_->oversample_amount;
343 return state_->control_rate;
351 state_->control_rate = control_rate;
378 int num_samples_first = trigger_offset[0];
380 for (
int i = 0; i < num_samples_first; ++i)
381 audio_out[i] = audio_out[i] & mask;
384 int num_samples_second = trigger_offset[2];
385 for (
int i = 0; i < num_samples_second; ++i)
386 audio_out[i] = audio_out[i] & mask;
420 void plug(
const Output* source,
unsigned int input_index);
433 void plug(
const Processor* source,
unsigned int input_index);
483 virtual void unplugIndex(
unsigned int input_index);
558 return static_cast<int>(
inputs_->size());
565 return static_cast<int>(
outputs_->size());
Base class for all signal-processing units in Vital.
Definition processor.h:212
force_inline ProcessorRouter * router() const
Returns the ProcessorRouter that currently owns this Processor.
Definition processor.h:516
std::shared_ptr< ProcessorState > state_
Shared state (sample rate, oversample, etc.)
Definition processor.h:653
virtual void unplugIndex(unsigned int input_index)
Removes the connection at a specified input index, if any.
Definition processor.cpp:161
bool initialized()
Returns whether this Processor has been initialized.
Definition processor.h:277
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.
Definition processor.cpp:25
force_inline int numOutputs() const
Returns the total number of Output pointers (owned or otherwise).
Definition processor.h:564
force_inline int numInputs() const
Returns the total number of Input pointers (owned or otherwise).
Definition processor.h:557
virtual void setControlRate(bool control_rate)
Sets whether this Processor runs at control rate.
Definition processor.h:350
virtual void numInputsChanged()
Called when the number of inputs changes (e.g., new connections). Subclasses may override for dynamic...
Definition processor.h:501
virtual void setOversampleAmount(int oversample)
Sets the oversampling amount and updates the effective sample rate.
Definition processor.h:293
virtual Output * registerOutput(Output *output, int index)
Registers a new Output in the output list at a specified index.
Definition processor.cpp:223
void plugNext(const Output *source)
Connects an external Output to the first available (unplugged) input.
Definition processor.cpp:104
Input * addInput()
Creates and registers a new Input, initially connected to null_source_.
Definition processor.cpp:246
int plugging_start_
The index at which plugNext starts searching for an unplugged input.
Definition processor.h:655
virtual ~Processor()
Virtual destructor.
Definition processor.h:226
void useOutput(Output *output)
Uses an existing Output object as this Processor's first output.
Definition processor.cpp:138
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
force_inline int getSampleRate() const
Retrieves the current (effective) sample rate.
Definition processor.h:326
force_inline bool enabled() const
Checks if this Processor is enabled.
Definition processor.h:310
void useInput(Input *input)
Uses an existing Input object as this Processor's first input.
Definition processor.cpp:126
virtual void registerInput(Input *input, int index)
Registers a new input, appending it to the input list.
Definition processor.cpp:213
force_inline bool isControlRate() const
Checks if this Processor is running at control rate (buffer_size == 1).
Definition processor.h:342
bool inputMatchesBufferSize(int input=0)
Checks whether the buffer size of a particular input matches the size needed by this Processor.
Definition processor.cpp:42
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_valu...
Definition processor.h:360
static const Output null_source_
A null (dummy) source used for unconnected inputs.
Definition processor.h:665
ProcessorRouter * getTopLevelRouter() const
Gets the topmost (root) ProcessorRouter by traversing parent routers.
Definition processor.cpp:190
std::shared_ptr< std::vector< Input * > > inputs_
All inputs, owned or external.
Definition processor.h:660
bool checkInputAndOutputSize(int num_samples)
Checks if all inputs and outputs have buffers big enough for num_samples.
Definition processor.cpp:52
virtual void hardReset()
Called to perform a "hard" reset for all voices.
Definition processor.h:272
force_inline int numOwnedOutputs() const
Returns how many Output objects this Processor owns.
Definition processor.h:578
force_inline int getOversampleAmount() const
Retrieves the current oversampling factor.
Definition processor.h:334
std::vector< std::shared_ptr< Input > > owned_inputs_
Inputs owned by this Processor.
Definition processor.h:657
void plug(const Output *source)
Connects an external Output to this Processor's first input.
Definition processor.cpp:79
int connectedInputs()
Counts how many inputs are connected to a real source (not null_source_).
Definition processor.cpp:149
Output * addOutput(int oversample=1)
Creates and registers a new Output. Handles control rate vs. audio rate.
Definition processor.cpp:231
virtual void process(int num_samples)=0
Main processing function. Called by the ProcessorRouter.
force_inline Output * output(unsigned int index=0) const
Retrieves the Output pointer at a given index.
Definition processor.h:616
void setPluggingStart(int start)
Sets the position at which plugNext starts searching for an open input.
Definition processor.h:635
force_inline int numOwnedInputs() const
Returns how many Input objects this Processor owns.
Definition processor.h:571
virtual void enable(bool enable)
Enables or disables this Processor.
Definition processor.h:318
force_inline Output * ownedOutput(unsigned int index=0) const
Retrieves an owned Output pointer at a given index.
Definition processor.h:626
force_inline Input * ownedInput(unsigned int index=0) const
Retrieves an owned Input pointer at a given index.
Definition processor.h:606
virtual void unplug(const Output *source)
Removes a connection to a given Output from all inputs.
Definition processor.cpp:167
virtual void setSampleRate(int sample_rate)
Updates the sample rate of this Processor (scaled by oversampling).
Definition processor.h:285
std::shared_ptr< std::vector< Output * > > outputs_
All outputs, owned or external.
Definition processor.h:661
std::vector< std::shared_ptr< Output > > owned_outputs_
Outputs owned by this Processor.
Definition processor.h:658
force_inline bool isInputSourcePolyphonic(int index=0)
Checks if the input source at a given index is polyphonic.
Definition processor.h:597
ProcessorRouter * router_
The ProcessorRouter that manages this Processor.
Definition processor.h:663
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.
Definition processor.h:373
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
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 s...
Definition processor.h:252
A specialized Processor that manages a directed graph of Processors and ensures correct processing or...
Definition processor_router.h:34
#define VITAL_ASSERT(x)
Definition common.h:11
#define force_inline
Definition common.h:23
force_inline void zeroBuffer(mono_float *buffer, int size)
Zeros a mono buffer (standard array).
Definition poly_utils.h:570
force_inline poly_float maskLoad(poly_float zero_value, poly_float one_value, poly_mask reset_mask)
Selects between two values (zero_value or one_value) based on a mask in each lane.
Definition poly_utils.h:351
Contains classes and functions used within the Vital synthesizer framework.
@ kVoiceOn
Definition common.h:77
constexpr int kMaxBufferSize
Maximum buffer size for processing.
Definition common.h:39
constexpr int kDefaultSampleRate
Default sample rate in Hz.
Definition common.h:41
poly_int poly_mask
Alias for clarity; used as a mask type in poly_float.
Definition poly_values.h:590
Holds and manages a buffer of samples (poly_float) for a Processor's output.
Definition processor.h:35
void clearBuffer()
Zeros out the entire output buffer.
Definition processor.h:81
force_inline void trigger(poly_mask mask, poly_float value, poly_int offset)
Sets trigger values (mask, trigger value, and offset).
Definition processor.h:63
poly_float * buffer
Pointer to the output buffer.
Definition processor.h:110
poly_int trigger_offset
Sample offset (per voice) for triggers.
Definition processor.h:117
Processor * owner
Owning processor.
Definition processor.h:112
Output(int size=kMaxBufferSize, int max_oversample=1)
Constructs an Output with a specified buffer size and oversampling factor.
Definition processor.h:41
void ensureBufferSize(int new_max_buffer_size)
Ensures the buffer is large enough to hold new_max_buffer_size samples. This will reallocate if neces...
Definition processor.h:98
virtual ~Output()
Virtual destructor.
Definition processor.h:55
int buffer_size
Current buffer size in samples.
Definition processor.h:114
force_inline void clearTrigger()
Clears the trigger mask, value, and offset.
Definition processor.h:72
poly_mask trigger_mask
Mask for triggered voices.
Definition processor.h:115
force_inline bool isControlRate() const
Checks whether this output runs at control rate (buffer_size == 1).
Definition processor.h:89
std::unique_ptr< poly_float[]> owned_buffer
Owned memory for the output buffer.
Definition processor.h:111
poly_float trigger_value
Trigger values for voices.
Definition processor.h:116
Holds shared state regarding sample rate, oversampling, and other flags.
Definition processor.h:163
bool enabled
Whether this Processor is currently enabled or not.
Definition processor.h:178
int sample_rate
The current sample rate (may include oversampling factor).
Definition processor.h:175
int oversample_amount
Oversampling factor.
Definition processor.h:176
ProcessorState()
Default constructor, initializes to default sample rate and no oversampling.
Definition processor.h:167
bool initialized
Whether this Processor has been initialized.
Definition processor.h:179
bool control_rate
True if running at control rate (usually buffer_size == 1).
Definition processor.h:177
A specialized Output that always runs at control rate (buffer_size = 1).
Definition processor.h:189
Output()
Constructs a control-rate Output (always buffer_size = 1).
Definition processor.h:193
Represents a vector of floating-point values using SIMD instructions.
Definition poly_values.h:600
static force_inline mask_simd_type vector_call equal(simd_type one, simd_type two)
Compares two SIMD float registers for equality, element-wise.
Definition poly_values.h:954
Represents a vector of integer values using SIMD instructions.
Definition poly_values.h:56