Vital
Loading...
Searching...
No Matches
synth_module.h
Go to the documentation of this file.
1
12#pragma once
13
14#include "synth_types.h"
15#include "processor_router.h"
16
17#include <climits>
18#include <vector>
19#include <map>
20#include <memory>
21#include <string>
22
23namespace vital {
24 class ValueSwitch;
25 class SynthModule;
26
36 public:
37 static constexpr float kClearValue = INT_MIN;
38
43 StatusOutput(Output* source) : source_(source), value_(0.0f) { }
44
49 force_inline poly_float value() const { return value_; }
50
57 force_inline void update(poly_mask voice_mask) {
58 poly_float masked_value = source_->buffer[0] & voice_mask;
59 value_ = masked_value + utils::swapVoices(masked_value);
60 }
61
68 value_ = source_->buffer[0];
69 }
70
74 force_inline void clear() { value_ = kClearValue; }
75
82
88 force_inline bool isClearValue(float value) const { return value == kClearValue; }
89
90 private:
91 Output* source_;
92 poly_float value_;
93
94 JUCE_LEAK_DETECTOR(StatusOutput)
95 };
96
104 struct ModuleData {
105 std::vector<Processor*> owned_mono_processors;
106 std::vector<SynthModule*> sub_modules;
107
110 std::map<std::string, std::unique_ptr<StatusOutput>> status_outputs;
115 std::map<std::string, ValueSwitch*> mono_modulation_switches;
116 std::map<std::string, ValueSwitch*> poly_modulation_switches;
117
118 JUCE_LEAK_DETECTOR(ModuleData)
119 };
120
130 public:
137 SynthModule(int num_inputs, int num_outputs, bool control_rate = false) :
138 ProcessorRouter(num_inputs, num_outputs, control_rate) {
139 data_ = std::make_shared<ModuleData>();
140 }
141
145 virtual ~SynthModule() { }
146
152
158 Output* getModulationSource(std::string name);
159
165 const StatusOutput* getStatusOutput(std::string name) const;
166
173 Processor* getModulationDestination(std::string name, bool poly);
174
180 Processor* getMonoModulationDestination(std::string name);
181
187 Processor* getPolyModulationDestination(std::string name);
188
195 ValueSwitch* getModulationSwitch(std::string name, bool poly);
196
202 ValueSwitch* getMonoModulationSwitch(std::string name);
203
209 ValueSwitch* getPolyModulationSwitch(std::string name);
210
215
221
227
233
239
245
252 virtual void correctToTime(double seconds) { }
253
258 void enableOwnedProcessors(bool enable);
259
264 virtual void enable(bool enable) override;
265
271 void addMonoProcessor(Processor* processor, bool own = true);
272
277 void addIdleMonoProcessor(Processor* processor);
278
283 virtual Processor* clone() const override { return new SynthModule(*this); }
284
289 void addSubmodule(SynthModule* module) { data_->sub_modules.push_back(module); }
290
291 protected:
299 Value* createBaseControl(std::string name, bool audio_rate = false, bool smooth_value = false);
300
309 Output* createBaseModControl(std::string name, bool audio_rate = false,
310 bool smooth_value = false, Output* internal_modulation = nullptr);
311
320 Output* createMonoModControl(std::string name, bool audio_rate = false,
321 bool smooth_value = false, Output* internal_modulation = nullptr);
322
332 Output* createPolyModControl(std::string name, bool audio_rate = false,
333 bool smooth_value = false, Output* internal_modulation = nullptr, Input* reset = nullptr);
334
344 Output* createTempoSyncSwitch(std::string name, Processor* frequency,
345 const Output* beats_per_second, bool poly, Input* midi = nullptr);
346
352 void createStatusOutput(std::string name, Output* source);
353
354 std::shared_ptr<ModuleData> data_;
355
356 JUCE_LEAK_DETECTOR(SynthModule)
357 };
358} // namespace vital
Base class for all signal-processing units in Vital.
Definition processor.h:212
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
A helper class to track the "status" of a particular Output as a poly_float value.
Definition synth_module.h:35
force_inline void clear()
Clears the stored status value.
Definition synth_module.h:74
static constexpr float kClearValue
Special "clear" value indicating no status.
Definition synth_module.h:37
force_inline void update()
Updates the status value without masking.
Definition synth_module.h:67
force_inline bool isClearValue(float value) const
Checks if a given float is the special "clear" value.
Definition synth_module.h:88
force_inline bool isClearValue(poly_float value) const
Checks if a given poly_float is the special "clear" value.
Definition synth_module.h:81
force_inline poly_float value() const
Returns the current status value.
Definition synth_module.h:49
StatusOutput(Output *source)
Constructor.
Definition synth_module.h:43
force_inline void update(poly_mask voice_mask)
Updates the status value using the provided mask.
Definition synth_module.h:57
A ProcessorRouter that encapsulates a cohesive unit of functionality in the synthesizer.
Definition synth_module.h:129
Processor * getPolyModulationDestination(std::string name)
Retrieves a poly modulation destination by name.
Definition synth_module.cpp:394
output_map & getModulationSources()
Returns a reference to the map of modulation sources.
Definition synth_module.cpp:454
virtual Processor * clone() const override
Clones this SynthModule.
Definition synth_module.h:283
Output * createPolyModControl(std::string name, bool audio_rate=false, bool smooth_value=false, Output *internal_modulation=nullptr, Input *reset=nullptr)
Creates a polyphonic mod control, including applying parameter scaling.
Definition synth_module.cpp:173
virtual output_map & getMonoModulations()
Returns a reference to the map of mono modulation readouts.
Definition synth_module.cpp:481
void addMonoProcessor(Processor *processor, bool own=true)
Adds a mono processor to this module.
Definition synth_module.cpp:529
Value * createBaseControl(std::string name, bool audio_rate=false, bool smooth_value=false)
Creates a simple control processor for a given parameter name.
Definition synth_module.cpp:22
void addIdleMonoProcessor(Processor *processor)
Adds a mono processor that is considered idle (not part of main processing chain).
Definition synth_module.cpp:540
std::shared_ptr< ModuleData > data_
Shared data storage for this SynthModule.
Definition synth_module.h:354
ValueSwitch * getMonoModulationSwitch(std::string name)
Retrieves a mono modulation switch by name.
Definition synth_module.cpp:412
input_map & getPolyModulationDestinations()
Returns a reference to the map of poly modulation destinations.
Definition synth_module.cpp:472
control_map getControls()
Returns a map of all controls from this module and its submodules.
Definition synth_module.cpp:341
ValueSwitch * getPolyModulationSwitch(std::string name)
Retrieves a poly modulation switch by name.
Definition synth_module.cpp:424
Processor * getMonoModulationDestination(std::string name)
Retrieves a mono modulation destination by name.
Definition synth_module.cpp:382
virtual ~SynthModule()
Destructor.
Definition synth_module.h:145
SynthModule(int num_inputs, int num_outputs, bool control_rate=false)
Constructs a SynthModule with specified I/O and control rate.
Definition synth_module.h:137
Processor * getModulationDestination(std::string name, bool poly)
Retrieves a modulation destination Processor by name and poly mode.
Definition synth_module.cpp:374
virtual output_map & getPolyModulations()
Returns a reference to the map of poly modulation readouts.
Definition synth_module.cpp:490
Output * createTempoSyncSwitch(std::string name, Processor *frequency, const Output *beats_per_second, bool poly, Input *midi=nullptr)
Creates a tempo sync switch that toggles between tempo-based frequency and free-running frequency.
Definition synth_module.cpp:289
Output * getModulationSource(std::string name)
Retrieves a modulation source output by name.
Definition synth_module.cpp:350
input_map & getMonoModulationDestinations()
Returns a reference to the map of mono modulation destinations.
Definition synth_module.cpp:463
ValueSwitch * getModulationSwitch(std::string name, bool poly)
Retrieves a modulation switch by name and poly mode.
Definition synth_module.cpp:406
Output * createBaseModControl(std::string name, bool audio_rate=false, bool smooth_value=false, Output *internal_modulation=nullptr)
Creates a base mod control, which is a control combined with a modulation input.
Definition synth_module.cpp:59
void updateAllModulationSwitches()
Updates all modulation switches based on whether their destinations have inputs.
Definition synth_module.cpp:436
virtual void correctToTime(double seconds)
Allows correction of module state to a given time (if needed).
Definition synth_module.h:252
void addSubmodule(SynthModule *module)
Adds a submodule to this SynthModule.
Definition synth_module.h:289
void createStatusOutput(std::string name, Output *source)
Creates a status output associated with a given Output.
Definition synth_module.cpp:337
void enableOwnedProcessors(bool enable)
Enables or disables all owned processors.
Definition synth_module.cpp:503
virtual void enable(bool enable) override
Enables or disables this SynthModule and its owned processors.
Definition synth_module.cpp:516
Output * createMonoModControl(std::string name, bool audio_rate=false, bool smooth_value=false, Output *internal_modulation=nullptr)
Creates a monophonic mod control, including applying parameter scaling.
Definition synth_module.cpp:104
const StatusOutput * getStatusOutput(std::string name) const
Retrieves a StatusOutput by name.
Definition synth_module.cpp:362
A Processor that maintains and outputs a constant poly_float value.
Definition value.h:24
A specialized Value processor that selects one of multiple input sources to pass through,...
Definition value_switch.h:28
#define force_inline
Definition common.h:23
force_inline poly_float swapVoices(poly_float value)
Swaps the first half of the lanes with the second half.
Definition poly_utils.h:437
Contains classes and functions used within the Vital synthesizer framework.
std::map< std::string, Output * > output_map
Maps parameter names to Output pointers, representing output signals from various modules.
Definition synth_types.h:229
std::map< std::string, Value * > control_map
Maps parameter names to Value pointers representing synth control parameters.
Definition synth_types.h:214
std::map< std::string, Processor * > input_map
Maps parameter names to Processor pointers, representing input processors for signals.
Definition synth_types.h:224
Declares the ProcessorRouter class, which manages a graph of Processors and their dependencies.
Represents a connection to an Output from another Processor.
Definition processor.h:128
Holds various data structures that define the internal state of a SynthModule.
Definition synth_module.h:104
input_map poly_mod_destinations
Map of poly modulation destinations.
Definition synth_module.h:112
std::map< std::string, std::unique_ptr< StatusOutput > > status_outputs
Map of status outputs.
Definition synth_module.h:110
output_map poly_modulation_readout
Outputs used to read poly modulation totals.
Definition synth_module.h:114
input_map mono_mod_destinations
Map of mono modulation destinations.
Definition synth_module.h:111
std::vector< Processor * > owned_mono_processors
Processors owned by this module (mono).
Definition synth_module.h:105
std::vector< SynthModule * > sub_modules
Nested submodules.
Definition synth_module.h:106
std::map< std::string, ValueSwitch * > poly_modulation_switches
Poly modulation switches.
Definition synth_module.h:116
output_map mono_modulation_readout
Outputs used to read mono modulation totals.
Definition synth_module.h:113
output_map mod_sources
Map of modulation source names to Outputs.
Definition synth_module.h:109
control_map controls
Map of control parameter names to Value Processors.
Definition synth_module.h:108
std::map< std::string, ValueSwitch * > mono_modulation_switches
Mono modulation switches.
Definition synth_module.h:115
Holds and manages a buffer of samples (poly_float) for a Processor's output.
Definition processor.h:35
poly_float * buffer
Pointer to the output buffer.
Definition processor.h:110
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