|
Vital
|
A base class providing foundational functionality for the Vital synthesizer’s engine, UI integration, modulation system, MIDI mapping, and preset management. More...
#include <synth_base.h>
Classes | |
| struct | ValueChangedCallback |
| A callback message used when values change, allowing asynchronous updates to GUI or host. More... | |
Public Member Functions | |
| SynthBase () | |
| Constructs a SynthBase, initializing the sound engine, MIDI manager, wavetables, and settings. | |
| virtual | ~SynthBase () |
| Destroys the SynthBase, cleaning up resources such as sound engine and memory buffers. | |
| void | valueChanged (const std::string &name, vital::mono_float value) |
| Updates the value of a control parameter. | |
| void | valueChangedThroughMidi (const std::string &name, vital::mono_float value) override |
| Handles parameter changes triggered through MIDI mappings. | |
| void | pitchWheelMidiChanged (vital::mono_float value) override |
| Called when the pitch wheel value changes via MIDI. | |
| void | modWheelMidiChanged (vital::mono_float value) override |
| Called when the mod wheel value changes via MIDI. | |
| void | pitchWheelGuiChanged (vital::mono_float value) |
| Called when the pitch wheel changes via the GUI or another external source. | |
| void | modWheelGuiChanged (vital::mono_float value) |
| Called when the mod wheel changes via the GUI or another external source. | |
| void | presetChangedThroughMidi (File preset) override |
| Called when a preset is changed through MIDI (e.g., program change messages). | |
| void | valueChangedExternal (const std::string &name, vital::mono_float value) |
| Handles external (non-GUI, non-MIDI) value changes to parameters. | |
| void | valueChangedInternal (const std::string &name, vital::mono_float value) |
| Handles internal value changes, updating the parameter and optionally notifying the host. | |
| bool | connectModulation (const std::string &source, const std::string &destination) |
| Connects a modulation source to a destination parameter. | |
| void | connectModulation (vital::ModulationConnection *connection) |
| Connects a modulation using a pre-existing ModulationConnection object. | |
| void | disconnectModulation (const std::string &source, const std::string &destination) |
| Disconnects a modulation source from a destination parameter. | |
| void | disconnectModulation (vital::ModulationConnection *connection) |
| Disconnects a modulation given a ModulationConnection object. | |
| void | clearModulations () |
| Clears all modulation connections. | |
| void | forceShowModulation (const std::string &source, bool force) |
| Forces a modulation source to remain active even if not currently connected. | |
| bool | isModSourceEnabled (const std::string &source) |
| Checks if a modulation source is currently enabled. | |
| int | getNumModulations (const std::string &destination) |
| Counts how many modulations target a given parameter. | |
| int | getConnectionIndex (const std::string &source, const std::string &destination) |
| Gets the index of a modulation connection given its source and destination. | |
| vital::CircularQueue< vital::ModulationConnection * > | getModulationConnections () |
| Gets all current modulation connections as a CircularQueue. | |
| std::vector< vital::ModulationConnection * > | getSourceConnections (const std::string &source) |
| Returns all modulation connections from a particular source. | |
| bool | isSourceConnected (const std::string &source) |
| Checks if a given modulation source has any active connections. | |
| std::vector< vital::ModulationConnection * > | getDestinationConnections (const std::string &destination) |
| Returns all modulation connections targeting a given destination parameter. | |
| const vital::StatusOutput * | getStatusOutput (const std::string &name) |
| Retrieves a status output by name. | |
| vital::Wavetable * | getWavetable (int index) |
| Gets a wavetable object from the engine. | |
| WavetableCreator * | getWavetableCreator (int index) |
| Gets a WavetableCreator for a given oscillator index. | |
| vital::Sample * | getSample () |
| Gets the Sample object used by the engine. | |
| LineGenerator * | getLfoSource (int index) |
| Retrieves an LFO source by index. | |
| int | getSampleRate () |
| Retrieves the current audio sample rate used by the engine. | |
| void | initEngine () |
| Initializes the engine to a default state, clearing modulations and resetting parameters. | |
| void | loadTuningFile (const File &file) |
| Loads a tuning file into the synthesizer’s tuning system. | |
| void | loadInitPreset () |
| Loads an "init" preset, resetting Vital to its default initial state. | |
| bool | loadFromFile (File preset, std::string &error) |
| Attempts to load a preset from a file. | |
| void | renderAudioToFile (File file, float seconds, float bpm, std::vector< int > notes, bool render_images) |
| Renders audio to a WAV file for a given duration and note sequence. | |
| void | renderAudioForResynthesis (float *data, int samples, int note) |
| Renders audio for the purpose of resynthesis into a provided buffer. | |
| bool | saveToFile (File preset) |
| Saves the current preset state to the specified file. | |
| bool | saveToActiveFile () |
| Saves the current preset state to the active file (if any). | |
| void | clearActiveFile () |
| Clears the currently active preset file, meaning changes are not saved to a previously loaded file. | |
| File | getActiveFile () |
| Gets the currently active preset file. | |
| void | setMpeEnabled (bool enabled) |
| Enables or disables MPE (MIDI Polyphonic Expression) mode. | |
| virtual void | beginChangeGesture (const std::string &name) |
| Called when a parameter change gesture begins. Typically not implemented in this base class. | |
| virtual void | endChangeGesture (const std::string &name) |
| Called when a parameter change gesture ends. Typically not implemented in this base class. | |
| virtual void | setValueNotifyHost (const std::string &name, vital::mono_float value) |
| Called when a parameter changes to notify a potential host environment. Typically not implemented here. | |
| void | armMidiLearn (const std::string &name) |
| Arms the given parameter name for MIDI learn, associating the next received MIDI control with it. | |
| void | cancelMidiLearn () |
| Cancels a previously armed MIDI learn operation. | |
| void | clearMidiLearn (const std::string &name) |
| Clears the MIDI mapping for a given parameter name. | |
| bool | isMidiMapped (const std::string &name) |
| Checks if a given parameter name is MIDI mapped. | |
| void | setAuthor (const String &author) |
| Sets the author metadata of the current preset. | |
| void | setComments (const String &comments) |
| Sets the comments or description metadata of the current preset. | |
| void | setStyle (const String &style) |
| Sets the style metadata of the current preset (e.g., bass, lead, etc.). | |
| void | setPresetName (const String &preset_name) |
| Sets the preset name. | |
| void | setMacroName (int index, const String ¯o_name) |
| Sets the name of a macro control by index. | |
| String | getAuthor () |
| Gets the author of the current preset. | |
| String | getComments () |
| Gets the comments for the current preset. | |
| String | getStyle () |
| Gets the style of the current preset. | |
| String | getPresetName () |
| Gets the current preset’s name. | |
| String | getMacroName (int index) |
| Gets the name of a macro control by index. | |
| vital::control_map & | getControls () |
| Provides access to the controls map (parameter name to Parameter pointer). | |
| vital::SoundEngine * | getEngine () |
| Returns a pointer to the SoundEngine used for audio and modulation processing. | |
| MidiKeyboardState * | getKeyboardState () |
| Retrieves the keyboard state (for processing MIDI note events from a virtual keyboard). | |
| const vital::poly_float * | getOscilloscopeMemory () |
| Retrieves the oscilloscope memory for visualization of audio output waveforms. | |
| const vital::StereoMemory * | getAudioMemory () |
| Retrieves stereo memory holding recent audio output samples for visualization. | |
| const vital::StereoMemory * | getEqualizerMemory () |
| Retrieves memory used for equalizer visualization, if available. | |
| vital::ModulationConnectionBank & | getModulationBank () |
| Retrieves the ModulationConnectionBank managing all modulation connections. | |
| void | notifyOversamplingChanged () |
| Notifies that oversampling settings have changed, reinitializing the engine if needed. | |
| void | checkOversampling () |
| Checks and updates oversampling settings. May be called if parameters affecting oversampling change. | |
| virtual const CriticalSection & | getCriticalSection ()=0 |
| Provides access to the synth’s internal CriticalSection for thread safety. | |
| virtual void | pauseProcessing (bool pause)=0 |
| Pauses or resumes audio processing. | |
| Tuning * | getTuning () |
| Returns a pointer to the synth's Tuning object. | |
Public Member Functions inherited from MidiManager::Listener | |
| virtual | ~Listener () |
Static Public Attributes | |
| static constexpr float | kOutputWindowMinNote = 16.0f |
| Minimum and maximum note values considered for output window display or related processing. | |
| static constexpr float | kOutputWindowMaxNote = 128.0f |
Protected Member Functions | |
| vital::modulation_change | createModulationChange (vital::ModulationConnection *connection) |
| Creates a modulation_change structure for a given connection, preparing it for engine operations. | |
| bool | isInvalidConnection (const vital::modulation_change &change) |
| Checks if a modulation_change is invalid (e.g., creates a loop). | |
| virtual SynthGuiInterface * | getGuiInterface ()=0 |
| Retrieves the GUI interface if available, for updating controls or notifications. | |
| json | saveToJson () |
| Serializes the current synth state into a JSON object. | |
| bool | loadFromJson (const json &state) |
| Deserializes and applies the synth state from a JSON object. | |
| vital::ModulationConnection * | getConnection (const std::string &source, const std::string &destination) |
| Finds a ModulationConnection by source and destination names. | |
| bool | getNextModulationChange (vital::modulation_change &change) |
| Attempts to dequeue a modulation_change for processing. | |
| void | clearModulationQueue () |
| Clears the modulation change queue, removing all pending changes. | |
| void | processAudio (AudioSampleBuffer *buffer, int channels, int samples, int offset) |
| Processes audio into the given buffer. May be overridden or extended by subclasses. | |
| void | processAudioWithInput (AudioSampleBuffer *buffer, const vital::poly_float *input_buffer, int channels, int samples, int offset) |
| Processes audio with an input buffer, often used for sidechain or feedback loops. | |
| void | writeAudio (AudioSampleBuffer *buffer, int channels, int samples, int offset) |
| Writes audio data from the engine to the output buffer. | |
| void | processMidi (MidiBuffer &buffer, int start_sample=0, int end_sample=0) |
| Processes MIDI messages from a MidiBuffer, applying them to the engine’s sound generation. | |
| void | processKeyboardEvents (MidiBuffer &buffer, int num_samples) |
| Processes keyboard events from a MidiBuffer, integrating them with the MidiKeyboardState. | |
| void | processModulationChanges () |
| Processes pending modulation changes and updates the engine accordingly. | |
| void | updateMemoryOutput (int samples, const vital::poly_float *audio) |
| Updates the oscilloscope memory with the latest audio samples. | |
A base class providing foundational functionality for the Vital synthesizer’s engine, UI integration, modulation system, MIDI mapping, and preset management.
The SynthBase class:
The class can be integrated with a GUI through a SynthGuiInterface or used headlessly (see HeadlessSynth). Subclasses must implement certain virtual methods to integrate with an audio processing environment.
| SynthBase::SynthBase | ( | ) |
Constructs a SynthBase, initializing the sound engine, MIDI manager, wavetables, and settings.
|
virtual |
Destroys the SynthBase, cleaning up resources such as sound engine and memory buffers.
| void SynthBase::armMidiLearn | ( | const std::string & | name | ) |
Arms the given parameter name for MIDI learn, associating the next received MIDI control with it.
| name | The parameter name. |
|
inlinevirtual |
Called when a parameter change gesture begins. Typically not implemented in this base class.
| name | The parameter name. |
Reimplemented in SynthPlugin.
| void SynthBase::cancelMidiLearn | ( | ) |
Cancels a previously armed MIDI learn operation.
| void SynthBase::checkOversampling | ( | ) |
Checks and updates oversampling settings. May be called if parameters affecting oversampling change.
|
inline |
Clears the currently active preset file, meaning changes are not saved to a previously loaded file.
| void SynthBase::clearMidiLearn | ( | const std::string & | name | ) |
Clears the MIDI mapping for a given parameter name.
| name | The parameter to clear from MIDI mappings. |
|
inlineprotected |
Clears the modulation change queue, removing all pending changes.
| void SynthBase::clearModulations | ( | ) |
Clears all modulation connections.
| bool SynthBase::connectModulation | ( | const std::string & | source, |
| const std::string & | destination ) |
Connects a modulation source to a destination parameter.
| source | The modulation source name. |
| destination | The parameter name to modulate. |
| void SynthBase::connectModulation | ( | vital::ModulationConnection * | connection | ) |
Connects a modulation using a pre-existing ModulationConnection object.
| connection | A pointer to the ModulationConnection object to be connected. |
|
protected |
Creates a modulation_change structure for a given connection, preparing it for engine operations.
| connection | A pointer to a ModulationConnection. |
| void SynthBase::disconnectModulation | ( | const std::string & | source, |
| const std::string & | destination ) |
Disconnects a modulation source from a destination parameter.
| source | The modulation source name. |
| destination | The parameter name. |
| void SynthBase::disconnectModulation | ( | vital::ModulationConnection * | connection | ) |
Disconnects a modulation given a ModulationConnection object.
| connection | The ModulationConnection to disconnect. |
|
inlinevirtual |
Called when a parameter change gesture ends. Typically not implemented in this base class.
| name | The parameter name. |
Reimplemented in SynthPlugin.
| void SynthBase::forceShowModulation | ( | const std::string & | source, |
| bool | force ) |
Forces a modulation source to remain active even if not currently connected.
| source | The modulation source. |
| force | True to keep it active, false to allow disabling. |
|
inline |
Gets the currently active preset file.
|
inline |
Retrieves stereo memory holding recent audio output samples for visualization.
| String SynthBase::getAuthor | ( | ) |
Gets the author of the current preset.
| String SynthBase::getComments | ( | ) |
Gets the comments for the current preset.
|
protected |
Finds a ModulationConnection by source and destination names.
| source | The modulation source name. |
| destination | The parameter destination name. |
| int SynthBase::getConnectionIndex | ( | const std::string & | source, |
| const std::string & | destination ) |
Gets the index of a modulation connection given its source and destination.
| source | The modulation source. |
| destination | The parameter destination. |
|
inline |
Provides access to the controls map (parameter name to Parameter pointer).
|
pure virtual |
Provides access to the synth’s internal CriticalSection for thread safety.
Must be implemented by subclasses.
Implemented in HeadlessSynth, SynthEditor, and SynthPlugin.
| std::vector< vital::ModulationConnection * > SynthBase::getDestinationConnections | ( | const std::string & | destination | ) |
Returns all modulation connections targeting a given destination parameter.
| destination | The parameter name. |
|
inline |
Returns a pointer to the SoundEngine used for audio and modulation processing.
| const vital::StereoMemory * SynthBase::getEqualizerMemory | ( | ) |
Retrieves memory used for equalizer visualization, if available.
|
protectedpure virtual |
Retrieves the GUI interface if available, for updating controls or notifications.
Implemented in HeadlessSynth, SynthEditor, and SynthPlugin.
|
inline |
Retrieves the keyboard state (for processing MIDI note events from a virtual keyboard).
| LineGenerator * SynthBase::getLfoSource | ( | int | index | ) |
Retrieves an LFO source by index.
| index | The LFO index. |
| String SynthBase::getMacroName | ( | int | index | ) |
Gets the name of a macro control by index.
| index | The macro index (0-based). |
| vital::ModulationConnectionBank & SynthBase::getModulationBank | ( | ) |
Retrieves the ModulationConnectionBank managing all modulation connections.
|
inline |
Gets all current modulation connections as a CircularQueue.
|
inlineprotected |
Attempts to dequeue a modulation_change for processing.
| change | A reference to store the dequeued change. |
| int SynthBase::getNumModulations | ( | const std::string & | destination | ) |
Counts how many modulations target a given parameter.
| destination | The parameter name. |
|
inline |
Retrieves the oscilloscope memory for visualization of audio output waveforms.
| String SynthBase::getPresetName | ( | ) |
Gets the current preset’s name.
| vital::Sample * SynthBase::getSample | ( | ) |
Gets the Sample object used by the engine.
| int SynthBase::getSampleRate | ( | ) |
Retrieves the current audio sample rate used by the engine.
| std::vector< vital::ModulationConnection * > SynthBase::getSourceConnections | ( | const std::string & | source | ) |
Returns all modulation connections from a particular source.
| source | The modulation source. |
| const vital::StatusOutput * SynthBase::getStatusOutput | ( | const std::string & | name | ) |
Retrieves a status output by name.
| name | The status output name. |
| String SynthBase::getStyle | ( | ) |
Gets the style of the current preset.
|
inline |
| vital::Wavetable * SynthBase::getWavetable | ( | int | index | ) |
Gets a wavetable object from the engine.
| index | The oscillator index. |
| WavetableCreator * SynthBase::getWavetableCreator | ( | int | index | ) |
Gets a WavetableCreator for a given oscillator index.
| index | The oscillator index. |
| void SynthBase::initEngine | ( | ) |
Initializes the engine to a default state, clearing modulations and resetting parameters.
|
protected |
Checks if a modulation_change is invalid (e.g., creates a loop).
| change | The modulation_change object to check. |
| bool SynthBase::isMidiMapped | ( | const std::string & | name | ) |
Checks if a given parameter name is MIDI mapped.
| name | The parameter name. |
| bool SynthBase::isModSourceEnabled | ( | const std::string & | source | ) |
Checks if a modulation source is currently enabled.
| source | The modulation source name. |
| bool SynthBase::isSourceConnected | ( | const std::string & | source | ) |
Checks if a given modulation source has any active connections.
| source | The modulation source. |
| bool SynthBase::loadFromFile | ( | File | preset, |
| std::string & | error ) |
Attempts to load a preset from a file.
| preset | The preset file. |
| error | A string to store error messages if loading fails. |
|
protected |
Deserializes and applies the synth state from a JSON object.
| state | The JSON object to load. |
| void SynthBase::loadInitPreset | ( | ) |
Loads an "init" preset, resetting Vital to its default initial state.
| void SynthBase::loadTuningFile | ( | const File & | file | ) |
Loads a tuning file into the synthesizer’s tuning system.
| file | The File representing the tuning. |
| void SynthBase::modWheelGuiChanged | ( | vital::mono_float | value | ) |
Called when the mod wheel changes via the GUI or another external source.
| value | The new mod wheel value. |
|
overridevirtual |
Called when the mod wheel value changes via MIDI.
| value | The new mod wheel value. |
Implements MidiManager::Listener.
| void SynthBase::notifyOversamplingChanged | ( | ) |
Notifies that oversampling settings have changed, reinitializing the engine if needed.
|
pure virtual |
Pauses or resumes audio processing.
When paused, processing locks the critical section to avoid concurrency issues.
| pause | True to pause, false to resume. |
Implemented in HeadlessSynth, SynthEditor, and SynthPlugin.
| void SynthBase::pitchWheelGuiChanged | ( | vital::mono_float | value | ) |
Called when the pitch wheel changes via the GUI or another external source.
| value | The new pitch wheel value. |
|
overridevirtual |
Called when the pitch wheel value changes via MIDI.
| value | The new pitch wheel value. |
Implements MidiManager::Listener.
|
overridevirtual |
Called when a preset is changed through MIDI (e.g., program change messages).
| preset | The new preset file. |
Implements MidiManager::Listener.
|
protected |
Processes audio into the given buffer. May be overridden or extended by subclasses.
| buffer | Pointer to the output AudioSampleBuffer. |
| channels | Number of output channels. |
| samples | Number of samples to process. |
| offset | Sample offset in the output buffer. |
|
protected |
Processes audio with an input buffer, often used for sidechain or feedback loops.
| buffer | The output buffer. |
| input_buffer | A pointer to the input poly_float buffer. |
| channels | Number of output channels. |
| samples | Number of samples to process. |
| offset | Sample offset in the output buffer. |
|
protected |
Processes keyboard events from a MidiBuffer, integrating them with the MidiKeyboardState.
| buffer | The MidiBuffer with keyboard messages. |
| num_samples | The number of samples to process. |
|
protected |
Processes MIDI messages from a MidiBuffer, applying them to the engine’s sound generation.
| buffer | The MidiBuffer containing MIDI messages. |
| start_sample | The starting sample to process MIDI for. |
| end_sample | The ending sample (0 means process all). |
|
protected |
Processes pending modulation changes and updates the engine accordingly.
| void SynthBase::renderAudioForResynthesis | ( | float * | data, |
| int | samples, | ||
| int | note ) |
Renders audio for the purpose of resynthesis into a provided buffer.
| data | Pointer to a float array to store samples. |
| samples | The number of samples to render. |
| note | The MIDI note to play for resynthesis. |
| void SynthBase::renderAudioToFile | ( | File | file, |
| float | seconds, | ||
| float | bpm, | ||
| std::vector< int > | notes, | ||
| bool | render_images ) |
Renders audio to a WAV file for a given duration and note sequence.
| file | The output WAV file. |
| seconds | The duration in seconds. |
| bpm | The tempo in beats per minute. |
| notes | A vector of MIDI notes to play. |
| render_images | Whether to render oscilloscope images alongside. |
| bool SynthBase::saveToActiveFile | ( | ) |
Saves the current preset state to the active file (if any).
| bool SynthBase::saveToFile | ( | File | preset | ) |
Saves the current preset state to the specified file.
| preset | The file to save to (the extension is enforced). |
|
protected |
Serializes the current synth state into a JSON object.
| void SynthBase::setAuthor | ( | const String & | author | ) |
Sets the author metadata of the current preset.
| author | The author's name. |
| void SynthBase::setComments | ( | const String & | comments | ) |
Sets the comments or description metadata of the current preset.
| comments | The comments string. |
| void SynthBase::setMacroName | ( | int | index, |
| const String & | macro_name ) |
Sets the name of a macro control by index.
| index | The macro index (0-based). |
| macro_name | The macro name as a String. |
| void SynthBase::setMpeEnabled | ( | bool | enabled | ) |
Enables or disables MPE (MIDI Polyphonic Expression) mode.
| enabled | True to enable MPE, false to disable. |
| void SynthBase::setPresetName | ( | const String & | preset_name | ) |
Sets the preset name.
| preset_name | The preset name as a String. |
| void SynthBase::setStyle | ( | const String & | style | ) |
Sets the style metadata of the current preset (e.g., bass, lead, etc.).
| style | The style description string. |
|
inlinevirtual |
Called when a parameter changes to notify a potential host environment. Typically not implemented here.
| name | The parameter name. |
| value | The new parameter value. |
Reimplemented in SynthPlugin.
|
protected |
Updates the oscilloscope memory with the latest audio samples.
| samples | Number of samples processed. |
| audio | Pointer to the audio sample data. |
| void SynthBase::valueChanged | ( | const std::string & | name, |
| vital::mono_float | value ) |
Updates the value of a control parameter.
| name | The name of the parameter. |
| value | The new value. |
| void SynthBase::valueChangedExternal | ( | const std::string & | name, |
| vital::mono_float | value ) |
Handles external (non-GUI, non-MIDI) value changes to parameters.
| name | The parameter name. |
| value | The new value. |
| void SynthBase::valueChangedInternal | ( | const std::string & | name, |
| vital::mono_float | value ) |
Handles internal value changes, updating the parameter and optionally notifying the host.
| name | The parameter name. |
| value | The new parameter value. |
|
overridevirtual |
Handles parameter changes triggered through MIDI mappings.
| name | The name of the parameter. |
| value | The new parameter value. |
Implements MidiManager::Listener.
|
protected |
Writes audio data from the engine to the output buffer.
| buffer | The output AudioSampleBuffer. |
| channels | Number of output channels. |
| samples | Number of samples to write. |
| offset | The sample offset in the output buffer. |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
staticconstexpr |
|
staticconstexpr |
Minimum and maximum note values considered for output window display or related processing.
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |