Vital
Loading...
Searching...
No Matches
lfo_module.cpp
Go to the documentation of this file.
1#include "lfo_module.h"
2
3#include "line_generator.h"
4#include "synth_lfo.h"
5
6namespace vital {
7
8 LfoModule::LfoModule(const std::string& prefix, LineGenerator* line_generator, const Output* beats_per_second) :
9 SynthModule(kNumInputs, kNumOutputs),
10 prefix_(prefix),
11 beats_per_second_(beats_per_second) {
12 // Create a SynthLfo processor and add it to this module's processing chain.
13 lfo_ = new SynthLfo(line_generator);
15
16 // Default to control-rate processing.
17 setControlRate(true);
18 }
19
27 Output* free_frequency = createPolyModControl(prefix_ + "_frequency");
28 Output* phase = createPolyModControl(prefix_ + "_phase");
29 Output* fade = createPolyModControl(prefix_ + "_fade_time");
30 Output* delay = createPolyModControl(prefix_ + "_delay_time");
31 Output* stereo_phase = createPolyModControl(prefix_ + "_stereo");
32 Value* sync_type = createBaseControl(prefix_ + "_sync_type");
33 Value* smooth_mode = createBaseControl(prefix_ + "_smooth_mode");
34 Output* smooth_time = createPolyModControl(prefix_ + "_smooth_time");
35
36 // Create a tempo-sync switch for frequency if needed.
37 // The 'true' at the end indicates this frequency depends on MIDI input.
38 Output* frequency = createTempoSyncSwitch(prefix_, free_frequency->owner, beats_per_second_, true, input(kMidi));
39
40 // Use the note trigger and note count inputs:
43
44 // Link LFO outputs to this module's outputs:
48
49 // Plug parameters into the SynthLfo:
50 lfo_->plug(frequency, SynthLfo::kFrequency);
51 lfo_->plug(phase, SynthLfo::kPhase);
52 lfo_->plug(stereo_phase, SynthLfo::kStereoPhase);
53 lfo_->plug(sync_type, SynthLfo::kSyncType);
54 lfo_->plug(smooth_mode, SynthLfo::kSmoothMode);
56 lfo_->plug(smooth_time, SynthLfo::kSmoothTime);
57 lfo_->plug(delay, SynthLfo::kDelay);
58 }
59
60 void LfoModule::correctToTime(double seconds) {
64 lfo_->correctToTime(seconds);
65 }
66
67 void LfoModule::setControlRate(bool control_rate) {
71 Processor::setControlRate(control_rate);
72 lfo_->setControlRate(control_rate);
73 }
74} // namespace vital
A class for generating and storing a line shape, defined by a series of points and associated powers.
Definition line_generator.h:20
const Output * beats_per_second_
Reference for tempo synchronization.
Definition lfo_module.h:86
SynthLfo * lfo_
The internal SynthLfo processor generating the LFO signal.
Definition lfo_module.h:85
std::string prefix_
Prefix for parameter naming.
Definition lfo_module.h:84
void correctToTime(double seconds) override
Aligns the LFO's phase to a specific time, useful for syncing to a host timeline.
Definition lfo_module.cpp:60
@ 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
void setControlRate(bool control_rate) override
Sets whether the LFO should run at control-rate or audio-rate.
Definition lfo_module.cpp:67
LfoModule(const std::string &prefix, LineGenerator *line_generator, const Output *beats_per_second)
Constructs an LfoModule.
Definition lfo_module.cpp:8
void init() override
Initializes the LfoModule, creating parameters and linking them to the SynthLfo processor.
Definition lfo_module.cpp:20
virtual void setControlRate(bool control_rate)
Sets whether this Processor runs at control rate.
Definition processor.h:350
void useOutput(Output *output)
Uses an existing Output object as this Processor's first output.
Definition processor.cpp:138
force_inline Input * input(unsigned int index=0) const
Retrieves the Input pointer at a given index.
Definition processor.h:587
void useInput(Input *input)
Uses an existing Input object as this Processor's first input.
Definition processor.cpp:126
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 addProcessor(Processor *processor)
Adds a Processor to be managed by this router.
Definition processor_router.cpp:121
A versatile Low-Frequency Oscillator (LFO) for audio synthesis, supporting multiple sync modes and sm...
Definition synth_lfo.h:16
void correctToTime(double seconds)
Updates the LFO to align with a given time in seconds, enabling synchronization with an external cloc...
Definition synth_lfo.cpp:460
@ kValue
Definition synth_lfo.h:56
@ kOscFrequency
Definition synth_lfo.h:58
@ kPhase
Definition synth_lfo.h:35
@ kFade
Definition synth_lfo.h:40
@ kSmoothMode
Definition synth_lfo.h:39
@ kSmoothTime
Definition synth_lfo.h:41
@ kDelay
Definition synth_lfo.h:43
@ kFrequency
Definition synth_lfo.h:34
@ kSyncType
Definition synth_lfo.h:38
@ kStereoPhase
Definition synth_lfo.h:42
@ kNoteCount
Definition synth_lfo.h:44
@ kNoteTrigger
Definition synth_lfo.h:37
A ProcessorRouter that encapsulates a cohesive unit of functionality in the synthesizer.
Definition synth_module.h:129
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
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
A Processor that maintains and outputs a constant poly_float value.
Definition value.h:24
Contains classes and functions used within the Vital synthesizer framework.
Holds and manages a buffer of samples (poly_float) for a Processor's output.
Definition processor.h:35
Processor * owner
Owning processor.
Definition processor.h:112