Vital
Loading...
Searching...
No Matches
value_switch.cpp
Go to the documentation of this file.
1
6#include "value_switch.h"
7#include "utils.h"
8
9namespace vital {
10
12 // Ensure both outputs (kValue, kSwitch) exist.
13 while (numOutputs() < kNumOutputs)
14 addOutput();
15
16 // By default, the ValueSwitch is not enabled since it simply
17 // passes through an input based on the set value.
18 enable(false);
19 }
20
23 // Update the output source based on the first voice's integer value.
24 setSource(value[0]);
25 }
26
27 void ValueSwitch::setOversampleAmount(int oversample) {
29 int num_inputs = numInputs();
30 // Update oversampling for all inputs' owners.
31 for (int i = 0; i < num_inputs; ++i) {
32 input(i)->source->owner->setOversampleAmount(oversample);
33 }
34 // Reset the buffer to match the currently set value.
35 setBuffer(value_[0]);
36 }
37
38 force_inline void ValueSwitch::setBuffer(int source) {
39 // Clamp the source index to the available inputs.
40 source = utils::iclamp(source, 0, numInputs() - 1);
41
42 // Route the selected input buffer directly to the kSwitch output.
43 output(kSwitch)->buffer = input(source)->source->buffer;
45 }
46
47 force_inline void ValueSwitch::setSource(int source) {
48 // Set the new buffer based on the source index.
49 setBuffer(source);
50
51 // Enable or disable linked processors based on the chosen source.
52 bool enable_processors = (source != 0);
53 for (Processor* processor : processors_)
54 processor->enable(enable_processors);
55 }
56} // namespace vital
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 setOversampleAmount(int oversample)
Sets the oversampling amount and updates the effective sample rate.
Definition processor.h:293
force_inline Input * input(unsigned int index=0) const
Retrieves the Input pointer at a given index.
Definition processor.h:587
Output * addOutput(int oversample=1)
Creates and registers a new Output. Handles control rate vs. audio rate.
Definition processor.cpp:231
force_inline Output * output(unsigned int index=0) const
Retrieves the Output pointer at a given index.
Definition processor.h:616
virtual void enable(bool enable)
Enables or disables this Processor.
Definition processor.h:318
A Processor that maintains and outputs a constant poly_float value.
Definition value.h:24
virtual void set(poly_float value)
Sets the internal value to a new poly_float.
Definition value.cpp:17
poly_float value_
The constant output value.
Definition value.h:69
force_inline mono_float value() const
Returns the current mono_float value of the first lane.
Definition value.h:60
ValueSwitch(mono_float value=0.0f)
Constructs a new ValueSwitch with an initial value.
Definition value_switch.cpp:11
@ kNumOutputs
Definition value_switch.h:37
@ kSwitch
The selected input signal output.
Definition value_switch.h:36
virtual void setOversampleAmount(int oversample) override
Sets the oversampling amount for this ValueSwitch and all connected sources.
Definition value_switch.cpp:27
virtual void set(poly_float value) override
Sets the control value, selecting the corresponding input as the output.
Definition value_switch.cpp:21
#define force_inline
Definition common.h:23
force_inline int iclamp(int value, int min_val, int max_val)
Clamps an integer between [min_val, max_val].
Definition utils.h:250
Contains classes and functions used within the Vital synthesizer framework.
float mono_float
Definition common.h:33
const Output * source
The output from which this input reads samples.
Definition processor.h:134
poly_float * buffer
Pointer to the output buffer.
Definition processor.h:110
Processor * owner
Owning processor.
Definition processor.h:112
int buffer_size
Current buffer size in samples.
Definition processor.h:114
Represents a vector of floating-point values using SIMD instructions.
Definition poly_values.h:600
Provides various utility functions, classes, and constants for audio, math, and general-purpose opera...
Declares the ValueSwitch class, which allows switching the output buffer based on a control value.