Vital
Loading...
Searching...
No Matches
SynthPlugin Class Reference

An AudioProcessor implementation for a synthesizer plugin. More...

#include <synth_plugin.h>

Inheritance diagram for SynthPlugin:
SynthBase ValueBridge::Listener MidiManager::Listener

Public Member Functions

 SynthPlugin ()
 Constructs the SynthPlugin.
 
virtual ~SynthPlugin ()
 Destructor, cleans up allocated resources.
 
SynthGuiInterfacegetGuiInterface () override
 Returns the GUI interface for this plugin.
 
void beginChangeGesture (const std::string &name) override
 Begins a parameter change gesture for the specified parameter.
 
void endChangeGesture (const std::string &name) override
 Ends a parameter change gesture for the specified parameter.
 
void setValueNotifyHost (const std::string &name, vital::mono_float value) override
 Sets a parameter value and notifies the host.
 
const CriticalSection & getCriticalSection () override
 Returns the CriticalSection for thread synchronization.
 
void pauseProcessing (bool pause) override
 Pauses or resumes audio processing.
 
void prepareToPlay (double sample_rate, int buffer_size) override
 Prepare the plugin to play with the given sample rate and buffer size.
 
void releaseResources () override
 Release any resources allocated for playback.
 
void processBlock (AudioSampleBuffer &, MidiBuffer &) override
 Process audio and MIDI data each block.
 
AudioProcessorEditor * createEditor () override
 Creates and returns the AudioProcessorEditor for this plugin.
 
bool hasEditor () const override
 Checks if the plugin has an editor.
 
const String getName () const override
 Returns the name of the plugin.
 
bool supportsMPE () const override
 Returns whether the plugin supports MPE (MIDI Polyphonic Expression).
 
const String getInputChannelName (int channel_index) const override
 Returns the input channel name.
 
const String getOutputChannelName (int channel_index) const override
 Returns the output channel name.
 
bool isInputChannelStereoPair (int index) const override
 Checks if the given input channel forms a stereo pair.
 
bool isOutputChannelStereoPair (int index) const override
 Checks if the given output channel forms a stereo pair.
 
bool acceptsMidi () const override
 Checks if the plugin accepts MIDI input.
 
bool producesMidi () const override
 Checks if the plugin produces MIDI output.
 
bool silenceInProducesSilenceOut () const override
 Checks if silence in leads to silence out.
 
double getTailLengthSeconds () const override
 Gets the plugin's tail length in seconds.
 
int getNumPrograms () override
 Returns the number of programs (only one here).
 
int getCurrentProgram () override
 Returns the current program index (always 0 here).
 
void setCurrentProgram (int index) override
 Sets the current program (does nothing here).
 
const String getProgramName (int index) override
 Gets the name of a program.
 
void changeProgramName (int index, const String &new_name) override
 Changes the name of a program (not implemented).
 
void getStateInformation (MemoryBlock &destData) override
 Saves the plugin state to a memory block.
 
void setStateInformation (const void *data, int size_in_bytes) override
 Restores the plugin state from a memory block.
 
AudioProcessorParameter * getBypassParameter () const override
 Returns the bypass parameter for hosts that support bypass.
 
void parameterChanged (std::string name, vital::mono_float value) override
 Called when a parameter changes externally via a ValueBridge.
 
- Public Member Functions inherited from SynthBase
 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::StatusOutputgetStatusOutput (const std::string &name)
 Retrieves a status output by name.
 
vital::WavetablegetWavetable (int index)
 Gets a wavetable object from the engine.
 
WavetableCreatorgetWavetableCreator (int index)
 Gets a WavetableCreator for a given oscillator index.
 
vital::SamplegetSample ()
 Gets the Sample object used by the engine.
 
LineGeneratorgetLfoSource (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.
 
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 &macro_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_mapgetControls ()
 Provides access to the controls map (parameter name to Parameter pointer).
 
vital::SoundEnginegetEngine ()
 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_floatgetOscilloscopeMemory ()
 Retrieves the oscilloscope memory for visualization of audio output waveforms.
 
const vital::StereoMemorygetAudioMemory ()
 Retrieves stereo memory holding recent audio output samples for visualization.
 
const vital::StereoMemorygetEqualizerMemory ()
 Retrieves memory used for equalizer visualization, if available.
 
vital::ModulationConnectionBankgetModulationBank ()
 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.
 
TuninggetTuning ()
 Returns a pointer to the synth's Tuning object.
 
- Public Member Functions inherited from MidiManager::Listener
virtual ~Listener ()
 
- Public Member Functions inherited from ValueBridge::Listener
virtual ~Listener ()
 Virtual destructor.
 

Static Public Attributes

static constexpr int kSetProgramWaitMilliseconds = 500
 Wait time after setting a program.
 
- Static Public Attributes inherited from SynthBase
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
 

Additional Inherited Members

- Protected Member Functions inherited from SynthBase
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).
 
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::ModulationConnectiongetConnection (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.
 
- Protected Attributes inherited from SynthBase
std::unique_ptr< vital::SoundEngineengine_
 
std::unique_ptr< MidiManagermidi_manager_
 
std::unique_ptr< MidiKeyboardState > keyboard_state_
 
std::unique_ptr< WavetableCreatorwavetable_creators_ [vital::kNumOscillators]
 
std::shared_ptr< SynthBase * > self_reference_
 
File active_file_
 
vital::poly_float oscilloscope_memory_ [2 *vital::kOscilloscopeMemoryResolution]
 
vital::poly_float oscilloscope_memory_write_ [2 *vital::kOscilloscopeMemoryResolution]
 
std::unique_ptr< vital::StereoMemoryaudio_memory_
 
vital::mono_float last_played_note_
 
int last_num_pressed_
 
vital::mono_float memory_reset_period_
 
vital::mono_float memory_input_offset_
 
int memory_index_
 
bool expired_
 
std::map< std::string, String > save_info_
 
vital::control_map controls_
 
vital::CircularQueue< vital::ModulationConnection * > mod_connections_
 
moodycamel::ConcurrentQueue< vital::control_changevalue_change_queue_
 
moodycamel::ConcurrentQueue< vital::modulation_changemodulation_change_queue_
 
Tuning tuning_
 

Detailed Description

An AudioProcessor implementation for a synthesizer plugin.

SynthPlugin integrates a SynthBase for synthesis engine management and JUCE's AudioProcessor for plugin-host communication. It manages parameters, state loading/saving, and interaction with the GUI. SynthPlugin also interacts with ValueBridge objects to synchronize parameter changes between the synth engine and the host.

Constructor & Destructor Documentation

◆ SynthPlugin()

SynthPlugin::SynthPlugin ( )

Constructs the SynthPlugin.

Registers parameters, sets up ValueBridges, and initializes the bypass parameter.

◆ ~SynthPlugin()

SynthPlugin::~SynthPlugin ( )
virtual

Destructor, cleans up allocated resources.

Member Function Documentation

◆ acceptsMidi()

bool SynthPlugin::acceptsMidi ( ) const
override

Checks if the plugin accepts MIDI input.

Returns
True if it accepts MIDI input.

◆ beginChangeGesture()

void SynthPlugin::beginChangeGesture ( const std::string & name)
overridevirtual

Begins a parameter change gesture for the specified parameter.

Parameters
nameThe parameter's name.

Reimplemented from SynthBase.

◆ changeProgramName()

void SynthPlugin::changeProgramName ( int index,
const String & new_name )
inlineoverride

Changes the name of a program (not implemented).

Parameters
indexThe program index.
new_nameThe new program name.

◆ createEditor()

AudioProcessorEditor * SynthPlugin::createEditor ( )
override

Creates and returns the AudioProcessorEditor for this plugin.

Returns
A pointer to the newly created editor component.

◆ endChangeGesture()

void SynthPlugin::endChangeGesture ( const std::string & name)
overridevirtual

Ends a parameter change gesture for the specified parameter.

Parameters
nameThe parameter's name.

Reimplemented from SynthBase.

◆ getBypassParameter()

AudioProcessorParameter * SynthPlugin::getBypassParameter ( ) const
inlineoverride

Returns the bypass parameter for hosts that support bypass.

Returns
A pointer to the bypass parameter.

◆ getCriticalSection()

const CriticalSection & SynthPlugin::getCriticalSection ( )
overridevirtual

Returns the CriticalSection for thread synchronization.

Returns
A reference to the callback lock CriticalSection.

Implements SynthBase.

◆ getCurrentProgram()

int SynthPlugin::getCurrentProgram ( )
inlineoverride

Returns the current program index (always 0 here).

◆ getGuiInterface()

SynthGuiInterface * SynthPlugin::getGuiInterface ( )
overridevirtual

Returns the GUI interface for this plugin.

Returns
Pointer to SynthGuiInterface if the editor is active, otherwise nullptr.

Implements SynthBase.

◆ getInputChannelName()

const String SynthPlugin::getInputChannelName ( int channel_index) const
override

Returns the input channel name.

Parameters
channel_indexThe zero-based index of the input channel.

◆ getName()

const String SynthPlugin::getName ( ) const
override

Returns the name of the plugin.

Returns
The plugin's name as a JUCE String.

◆ getNumPrograms()

int SynthPlugin::getNumPrograms ( )
inlineoverride

Returns the number of programs (only one here).

◆ getOutputChannelName()

const String SynthPlugin::getOutputChannelName ( int channel_index) const
override

Returns the output channel name.

Parameters
channel_indexThe zero-based index of the output channel.

◆ getProgramName()

const String SynthPlugin::getProgramName ( int index)
override

Gets the name of a program.

Parameters
indexThe program index.
Returns
The program name.

◆ getStateInformation()

void SynthPlugin::getStateInformation ( MemoryBlock & destData)
override

Saves the plugin state to a memory block.

Parameters
destDataThe memory block to write state data.

◆ getTailLengthSeconds()

double SynthPlugin::getTailLengthSeconds ( ) const
override

Gets the plugin's tail length in seconds.

Returns
Tail length in seconds.

◆ hasEditor()

bool SynthPlugin::hasEditor ( ) const
override

Checks if the plugin has an editor.

Returns
True, since this plugin provides a custom editor.

◆ isInputChannelStereoPair()

bool SynthPlugin::isInputChannelStereoPair ( int index) const
override

Checks if the given input channel forms a stereo pair.

Parameters
indexThe input channel index.
Returns
True if it forms a stereo pair.

◆ isOutputChannelStereoPair()

bool SynthPlugin::isOutputChannelStereoPair ( int index) const
override

Checks if the given output channel forms a stereo pair.

Parameters
indexThe output channel index.
Returns
True if it forms a stereo pair.

◆ parameterChanged()

void SynthPlugin::parameterChanged ( std::string name,
vital::mono_float value )
overridevirtual

Called when a parameter changes externally via a ValueBridge.

Parameters
nameThe name of the changed parameter.
valueThe new parameter value.

Implements ValueBridge::Listener.

◆ pauseProcessing()

void SynthPlugin::pauseProcessing ( bool pause)
overridevirtual

Pauses or resumes audio processing.

Parameters
pauseTrue to suspend processing, false to resume.

Implements SynthBase.

◆ prepareToPlay()

void SynthPlugin::prepareToPlay ( double sample_rate,
int buffer_size )
override

Prepare the plugin to play with the given sample rate and buffer size.

Parameters
sample_rateThe audio sample rate.
buffer_sizeThe buffer size in samples.

◆ processBlock()

void SynthPlugin::processBlock ( AudioSampleBuffer & buffer,
MidiBuffer & midi_messages )
override

Process audio and MIDI data each block.

Parameters
bufferThe audio buffer to process.
midi_messagesThe MIDI events to process.

◆ producesMidi()

bool SynthPlugin::producesMidi ( ) const
override

Checks if the plugin produces MIDI output.

Returns
True if it produces MIDI output.

◆ releaseResources()

void SynthPlugin::releaseResources ( )
override

Release any resources allocated for playback.

◆ setCurrentProgram()

void SynthPlugin::setCurrentProgram ( int index)
inlineoverride

Sets the current program (does nothing here).

Parameters
indexThe program index to set.

◆ setStateInformation()

void SynthPlugin::setStateInformation ( const void * data,
int size_in_bytes )
override

Restores the plugin state from a memory block.

Parameters
dataPointer to the state data.
size_in_bytesSize of the state data in bytes.

◆ setValueNotifyHost()

void SynthPlugin::setValueNotifyHost ( const std::string & name,
vital::mono_float value )
overridevirtual

Sets a parameter value and notifies the host.

Parameters
nameThe parameter's name.
valueThe new parameter value to set.

Reimplemented from SynthBase.

◆ silenceInProducesSilenceOut()

bool SynthPlugin::silenceInProducesSilenceOut ( ) const
override

Checks if silence in leads to silence out.

Returns
False for this plugin.

◆ supportsMPE()

bool SynthPlugin::supportsMPE ( ) const
inlineoverride

Returns whether the plugin supports MPE (MIDI Polyphonic Expression).

Returns
True if MPE is supported.

Member Data Documentation

◆ kSetProgramWaitMilliseconds

int SynthPlugin::kSetProgramWaitMilliseconds = 500
staticconstexpr

Wait time after setting a program.


The documentation for this class was generated from the following files: