25 beats_per_second_(beats_per_second),
26 note_from_reference_(nullptr),
27 midi_offset_output_(nullptr),
29 current_midi_note_(nullptr),
30 filters_module_(nullptr),
36 note_mapping_(nullptr),
37 velocity_mapping_(nullptr),
38 aftertouch_mapping_(nullptr),
39 slide_mapping_(nullptr),
40 lift_mapping_(nullptr),
41 mod_wheel_mapping_(nullptr),
42 pitch_wheel_mapping_(nullptr),
44 note_percentage_(nullptr) {
46 note_from_reference_ =
new cr::Add();
59 createFilters(note_from_reference_->
output());
74 std::string number = std::to_string(i + 1);
75 std::string amount_name =
"modulation_" + number +
"_amount";
90 setupPolyModulationReadouts();
94 std::string name =
"macro_control_" + std::to_string(i + 1);
95 data_->mod_sources[name] = macros[i];
101 std::string name =
"random_" + std::to_string(i + 1);
102 data_->mod_sources[name] = random_lfos_[i]->
output();
114 std::string modulation_source_prefix =
"modulation_source_";
115 std::string modulation_amount_prefix =
"modulation_amount_";
119 std::string number = std::to_string(i + 1);
140 void EffectsModulationHandler::createModulators() {
142 for (
int i = 0; i <
kNumLfos; ++i) {
143 lfo_sources_[i].
setLoop(
false);
145 std::string prefix =
"lfo_" + std::to_string(i + 1);
163 std::string prefix =
"env_" + std::to_string(i + 1);
164 EnvelopeModule* envelope =
new EnvelopeModule(prefix);
168 envelopes_[i] = envelope;
176 random_ =
new TriggerRandom();
182 std::string name =
"random_" + std::to_string(i + 1);
183 random_lfos_[i] =
new RandomLfoModule(name, beats_per_second_);
195 data_->mod_sources[
"note"] = note_percentage_->
output();
220 void EffectsModulationHandler::createFilters(Output* keytrack) {
221 filters_module_ =
new FiltersModule();
233 void EffectsModulationHandler::createArticulation() {
236 cr::Interpolate* velocity_track_mult =
new cr::Interpolate();
248 current_midi_note_ =
new PortamentoSlope();
263 cr::Multiply* pitch_bend =
new cr::Multiply();
265 pitch_bend->plug(pitch_bend_range, 1);
267 bent_midi_ =
new cr::VariableAdd();
268 bent_midi_->
plugNext(current_midi_note_);
273 static const cr::Value max_midi_invert(1.0f / (
kMidiSize - 1));
274 note_percentage_ =
new cr::Multiply();
275 note_percentage_->
plug(&max_midi_invert, 0);
276 note_percentage_->
plug(bent_midi_, 1);
280 note_from_reference_->
plug(&reference_adjust, 0);
281 note_from_reference_->
plug(bent_midi_, 1);
303 for (
auto& status_source :
data_->status_outputs)
304 status_source.second->clear();
313 poly_float masked_value = buffer[0] & voice_mask;
317 for (
auto& status_source :
data_->status_outputs)
318 status_source.second->update(voice_mask);
375 envelopes_[i]->
enable(
false);
386 if (source !=
"env_1")
393 void EffectsModulationHandler::setupPolyModulationReadouts() {
395 for (
auto& mod : poly_mods)
405 return poly_readouts_;
void setLoop(bool loop)
Sets whether the line should loop at the end.
Definition line_generator.h:72
void initTriangle()
Initializes the line as a triangle shape.
Definition line_generator.cpp:23
void correctToTime(double seconds) override
Synchronizes internal modulator phases to a given absolute time.
Definition effects_modulation_handler.cpp:362
void disableUnnecessaryModSources()
Disables all modulation sources that are not strictly necessary.
Definition effects_modulation_handler.cpp:370
void prepareDestroy()
Prepares the object for destruction by removing all modulation processors.
Definition effects_modulation_handler.cpp:130
output_map & getPolyModulations() override
Returns a reference to the polyphonic modulation output map.
Definition effects_modulation_handler.cpp:404
void disableModSource(const std::string &source)
Disables a specific modulation source by name.
Definition effects_modulation_handler.cpp:385
void init() override
Initializes internal processors and modulation sources.
Definition effects_modulation_handler.cpp:56
EffectsModulationHandler(Output *beats_per_second)
Constructs an EffectsModulationHandler given a beats-per-second output reference.
Definition effects_modulation_handler.cpp:23
void noteOff(int note, mono_float lift, int sample, int channel) override
Handles note-off events, ending envelopes and other modulation if needed.
Definition effects_modulation_handler.cpp:350
void noteOn(int note, mono_float velocity, int sample, int channel) override
Handles note-on events, triggering envelopes and other modulation if needed.
Definition effects_modulation_handler.cpp:333
void process(int num_samples) override
Processes audio/midi data for a block of samples.
Definition effects_modulation_handler.cpp:293
@ kTrigger
Definition envelope_module.h:25
@ kValue
Definition envelope_module.h:36
@ kPhase
Definition envelope_module.h:37
@ kReset
Definition filters_module.h:32
@ kMidi
Definition filters_module.h:31
@ kKeytrack
Definition filters_module.h:30
@ kTo
Definition operators.h:423
@ kFrom
Definition operators.h:422
@ kFractional
Definition operators.h:424
A module that generates a Low-Frequency Oscillation (LFO) signal from a LineGenerator source.
Definition lfo_module.h:18
@ kMidi
Definition lfo_module.h:30
@ kNoteCount
Definition lfo_module.h:29
@ kNoteTrigger
Definition lfo_module.h:28
@ kOscPhase
Definition lfo_module.h:43
@ kValue
Definition lfo_module.h:42
@ kOscFrequency
Definition lfo_module.h:44
ModulationConnection * atIndex(int index)
Retrieves a ModulationConnection by index.
Definition synth_types.h:114
A processor that applies a modulation signal to a parameter, performing mapping, scaling,...
Definition modulation_connection_processor.h:18
@ kModulationPreScale
Definition modulation_connection_processor.h:45
@ kModulationSource
Definition modulation_connection_processor.h:46
void initializeBaseValue(Value *base_value)
Initializes a base value for this modulation connection, used as a starting point.
Definition modulation_connection_processor.h:121
@ kReset
Definition modulation_connection_processor.h:32
@ kModulationAmount
Definition modulation_connection_processor.h:30
@ kModulationPower
Definition modulation_connection_processor.h:31
@ kRunSeconds
Duration of portamento in seconds input index.
Definition portamento_slope.h:47
@ kPortamentoScale
Scale portamento by interval input index.
Definition portamento_slope.h:46
@ kNumNotesPressed
Number of notes currently pressed input index.
Definition portamento_slope.h:50
@ kSlopePower
Power/curve of the slope input index.
Definition portamento_slope.h:48
@ kSource
Source value input index.
Definition portamento_slope.h:44
@ kReset
Reset trigger input index.
Definition portamento_slope.h:49
@ kTarget
Target value input index.
Definition portamento_slope.h:43
@ kPortamentoForce
Force portamento on/off input index.
Definition portamento_slope.h:45
void plugNext(const Output *source)
Connects an external Output to the first available (unplugged) input.
Definition processor.cpp:104
force_inline bool enabled() const
Checks if this Processor is enabled.
Definition processor.h:310
void plug(const Output *source)
Connects an external Output to this Processor's first input.
Definition processor.cpp:79
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
@ kNoteTrigger
Definition random_lfo_module.h:23
@ kMidi
Definition random_lfo_module.h:24
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
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
std::shared_ptr< ModuleData > data_
Shared data storage for this SynthModule.
Definition synth_module.h:354
virtual output_map & getPolyModulations()
Returns a reference to the map of poly modulation readouts.
Definition synth_module.cpp:490
Output * getModulationSource(std::string name)
Retrieves a modulation source output by name.
Definition synth_module.cpp:350
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
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
A Processor that maintains and outputs a constant poly_float value.
Definition value.h:24
A SynthModule and NoteHandler that manages a pool of polyphonic voices, handles note-on/off logic,...
Definition voice_handler.h:380
force_inline Output * velocity()
Returns a pointer to velocity, the note-on velocity.
Definition voice_handler.h:634
force_inline Output * retrigger()
Returns a pointer to the retrigger Output, used for controlling certain envelope triggers.
Definition voice_handler.h:610
force_inline Output * note()
Returns a pointer to the note Output, giving the current tuned note frequency or pitch.
Definition voice_handler.h:616
force_inline Output * pitch_wheel()
Returns a pointer to pitch_wheel, storing the pitch-bend range for each channel.
Definition voice_handler.h:649
force_inline int getNumPressedNotes()
Returns how many notes are pressed (including partial states).
Definition voice_handler.h:476
force_inline Output * local_pitch_bend()
Returns a pointer to local_pitch_bend, the per-voice pitch bend output.
Definition voice_handler.h:655
virtual void noteOn(int note, mono_float velocity, int sample, int channel) override
Handles a MIDI note-on event, starting a note with a specified velocity and timing.
Definition voice_handler.cpp:721
void resetFeedbacks(poly_mask reset_mask) override
Resets any feedback paths in the poly router, applying the given mask.
Definition voice_handler.cpp:892
force_inline Output * note_pressed()
Returns a pointer to the note_pressed Output, a count of how many times a note was pressed.
Definition voice_handler.h:622
force_inline Output * channel()
Returns a pointer to channel, indicating the MIDI channel of the voice.
Definition voice_handler.h:631
virtual void init() override
Initializes the voice and global routers, then calls SynthModule::init().
Definition voice_handler.cpp:409
force_inline Output * slide()
Returns a pointer to slide, the MPE "slide" expression value.
Definition voice_handler.h:643
int getNumActiveVoices()
Returns the number of currently active voices (not dead).
Definition voice_handler.cpp:425
force_inline int polyphony()
Returns the current maximum polyphony (number of active voices allowed).
Definition voice_handler.h:670
bool isNotePlaying(int note)
Checks if a given MIDI note is playing.
Definition voice_handler.cpp:429
force_inline Output * voice_event()
Returns a pointer to the voice_event Output, used to track voice On/Off/Kill events.
Definition voice_handler.h:607
void removeProcessor(Processor *processor) override
Removes a Processor from this router.
Definition voice_handler.cpp:880
virtual void process(int num_samples) override
Processes audio for a block of samples. For each active voice, triggers events, updates parameters,...
Definition voice_handler.cpp:321
force_inline Output * mod_wheel()
Returns a pointer to mod_wheel, storing the mod wheel value for each channel.
Definition voice_handler.h:658
virtual void noteOff(int note, mono_float velocity, int sample, int channel) override
Handles a MIDI note-off event, releasing a currently active note.
Definition voice_handler.cpp:752
force_inline Output * note_count()
Returns a pointer to note_count, a global note counter.
Definition voice_handler.h:625
force_inline Output * aftertouch()
Returns a pointer to aftertouch, storing per-voice or channel-based aftertouch.
Definition voice_handler.h:640
force_inline bool legato()
Returns true if legato mode is enabled.
Definition voice_handler.h:764
force_inline Output * pitch_wheel_percent()
Returns a pointer to pitch_wheel_percent, a normalized [0..1] version of pitch_wheel.
Definition voice_handler.h:652
force_inline Output * reset()
Returns a pointer to the reset Output, indicating a full voice reset (On from Dead).
Definition voice_handler.h:613
void addProcessor(Processor *processor) override
Adds a Processor to be managed by this router.
Definition voice_handler.cpp:870
void addIdleProcessor(Processor *processor) override
Adds a Processor that should remain idle (not processed) in the router.
Definition voice_handler.cpp:875
Output * registerOutput(Output *output) override
Registers an Output with this VoiceHandler, returning a pointer to a new accumulated or single-lane O...
Definition voice_handler.cpp:896
force_inline Output * lift()
Returns a pointer to lift, the note-off velocity or release velocity.
Definition voice_handler.h:637
force_inline Output * last_note()
Returns a pointer to the last_note Output, giving the previous note (for legato transitions).
Definition voice_handler.h:619
force_inline void setVoiceMidi(const Output *midi)
Sets the Output that provides the current MIDI note for the voice.
Definition voice_handler.h:751
force_inline Output * note_in_octave()
Returns a pointer to note_in_octave, a fractional note position in [0..1).
Definition voice_handler.h:628
poly_mask getCurrentVoiceMask()
Returns a mask for the last active voice, used for writing to output buffers.
Definition voice_handler.cpp:556
Control-rate addition of two values.
Definition operators.h:700
const poly_mask kFullMask
A mask covering all lanes of a poly_float vector.
Definition synth_constants.h:257
const poly_float kLeftOne(1.0f, 0.0f)
A poly_float representing a vector [1.0f, 0.0f] used for channel manipulations.
const cr::Value kValueOne(1.0f)
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
constexpr int kNumRandomLfos
Number of random LFO sources (random modulation generators).
Definition synth_constants.h:25
constexpr int kMidiSize
MIDI note count (0-127).
Definition common.h:44
constexpr int kMidiTrackCenter
MIDI note considered as center (Middle C).
Definition common.h:45
constexpr int kNumEnvelopes
Number of envelope generators in Vital.
Definition synth_constants.h:22
constexpr int kNumLfos
Number of LFO sources available in the Vital synthesizer.
Definition synth_constants.h:13
constexpr int kMaxModulationConnections
Maximum number of modulation connections allowed.
Definition synth_constants.h:49
constexpr int kNumMacros
Number of macro controls available.
Definition synth_constants.h:28
float mono_float
Definition common.h:33
Declares the PortamentoSlope class, which applies a portamento transition between a source and target...
std::unique_ptr< ModulationConnectionProcessor > modulation_processor
Processor applying scaling/mapping.
Definition synth_types.h:75
Holds and manages a buffer of samples (poly_float) for a Processor's output.
Definition processor.h:35
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
Processor * owner
Owning processor.
Definition processor.h:112
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
Represents a vector of floating-point values using SIMD instructions.
Definition poly_values.h:600
Represents a vector of integer values using SIMD instructions.
Definition poly_values.h:56
static force_inline uint32_t vector_call anyMask(simd_type value)
Returns a bitmask that indicates which bytes/elements in the register are non-zero.
Definition poly_values.h:352
Declares the ValueSwitch class, which allows switching the output buffer based on a control value.