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

The main editor component for the SynthPlugin audio processor. More...

#include <synth_editor.h>

Inheritance diagram for SynthEditor:
SynthGuiInterface SynthBase SynthGuiInterface MidiManager::Listener

Public Member Functions

 SynthEditor (SynthPlugin &synth)
 Constructs the SynthEditor.
 
void paint (Graphics &) override
 Paints the editor background.
 
void resized () override
 Called when the editor is resized.
 
void setScaleFactor (float newScale) override
 Sets a new scale factor for the GUI.
 
void updateFullGui () override
 Forces a full GUI update.
 
 SynthEditor (bool use_gui=true)
 Constructs a SynthEditor.
 
 ~SynthEditor ()
 Destructor. Cleans up resources, shutting down audio and dismissing menus.
 
void prepareToPlay (int buffer_size, double sample_rate) override
 Prepares the audio engine to begin playing.
 
void getNextAudioBlock (const AudioSourceChannelInfo &buffer) override
 Callback for the audio device. Processes incoming audio and MIDI.
 
void releaseResources () override
 Releases resources allocated for audio playback.
 
void paint (Graphics &g) override
 Called to repaint any custom graphics, which are not currently used here.
 
void resized () override
 Called when the component is resized. Resizes internal GUI components if present.
 
const CriticalSection & getCriticalSection () override
 Returns the critical section used for thread-safe operations.
 
void pauseProcessing (bool pause) override
 Pauses or resumes audio processing by locking or unlocking the critical section.
 
SynthGuiInterfacegetGuiInterface () override
 Returns a pointer to the GUI interface of this synth.
 
AudioDeviceManager * getAudioDeviceManager () override
 Returns a pointer to the AudioDeviceManager for this standalone app.
 
void timerCallback () override
 Timer callback used to periodically scan for new MIDI devices.
 
void animate (bool animate)
 Enables or disables animation in the GUI (e.g., for meters or visualizations).
 
- Public Member Functions inherited from SynthGuiInterface
 SynthGuiInterface (SynthBase *synth, bool use_gui=true)
 Constructs the SynthGuiInterface, optionally creating a FullInterface GUI.
 
virtual ~SynthGuiInterface ()
 Destroys the SynthGuiInterface, cleaning up any associated GUI resources.
 
SynthBasegetSynth ()
 Returns the SynthBase instance this interface is managing.
 
virtual void updateGuiControl (const std::string &name, vital::mono_float value)
 Updates a single GUI control to reflect a new parameter value.
 
vital::mono_float getControlValue (const std::string &name)
 Retrieves the current value of a named control from the synth.
 
void notifyModulationsChanged ()
 Notifies the GUI that modulation connections or states have changed.
 
void notifyModulationValueChanged (int index)
 Notifies the GUI that a specific modulation's value changed.
 
void connectModulation (std::string source, std::string destination)
 Connects a modulation source to a destination parameter through the GUI.
 
void connectModulation (vital::ModulationConnection *connection)
 Connects a modulation using a pre-existing ModulationConnection object.
 
void setModulationValues (const std::string &source, const std::string &destination, vital::mono_float amount, bool bipolar, bool stereo, bool bypass)
 Sets various modulation parameters (amount, bipolar, stereo, bypass) for a given connection.
 
void initModulationValues (const std::string &source, const std::string &destination)
 Initializes modulation values for a newly created modulation connection.
 
void disconnectModulation (std::string source, std::string destination)
 Disconnects a modulation from the GUI layer.
 
void disconnectModulation (vital::ModulationConnection *connection)
 Disconnects a modulation using a ModulationConnection object.
 
void setFocus ()
 Brings the GUI window or main component into focus.
 
void notifyChange ()
 Notifies the GUI that a parameter or modulation changed, prompting GUI updates.
 
void notifyFresh ()
 Notifies the GUI that a fresh state (like a new preset load) has occurred, prompting a full refresh.
 
void openSaveDialog ()
 Opens a save dialog (e.g., to save a preset) through the GUI.
 
void externalPresetLoaded (File preset)
 Notifies the GUI that a preset was loaded externally (outside the GUI controls).
 
void setGuiSize (float scale)
 Sets the GUI window or component size based on a scale factor.
 
FullInterfacegetGui ()
 Gets the FullInterface GUI component if it exists.
 
- 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.
 
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 &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 ()
 

Additional Inherited Members

- 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
 
- 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 SynthGuiInterface
SynthBasesynth_
 The backend SynthBase this GUI interface controls.
 
std::unique_ptr< FullInterfacegui_
 The primary GUI component (if applicable).
 
- 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

The main editor component for the SynthPlugin audio processor.

A standalone JUCE AudioAppComponent for hosting the Synth interface and audio engine.

SynthEditor is an AudioProcessorEditor that integrates a SynthGuiInterface, providing the user interface for the plugin. It handles resizing, aspect ratio constraints, scaling, and updates to the GUI as the underlying synthesizer changes.

SynthEditor combines the GUI (if enabled) with real-time audio handling, MIDI management, and the Vital synthesizer engine. It inherits from various classes to integrate JUCE’s audio processing, the Vital engine, and the GUI interface.

Constructor & Destructor Documentation

◆ SynthEditor() [1/2]

SynthEditor::SynthEditor ( SynthPlugin & synth)

Constructs the SynthEditor.

Parameters
synthReference to the SynthPlugin instance associated with this editor.

Initializes the look and feel, sets up the main GUI (FullInterface), applies animation settings, and configures resizing constraints and scaling.

◆ SynthEditor() [2/2]

SynthEditor::SynthEditor ( bool use_gui = true)

Constructs a SynthEditor.

Constructs a SynthEditor object.

Parameters
use_guiDetermines whether to create and display the full GUI interface.

Initializes the audio device manager, sets the default sample rate, creates the optional GUI, and starts a timer to poll for MIDI devices.

Parameters
use_guiDetermines whether the GUI is created and displayed.

◆ ~SynthEditor()

SynthEditor::~SynthEditor ( )

Destructor. Cleans up resources, shutting down audio and dismissing menus.

Destructor for SynthEditor.

Cleans up the audio system and dismisses any active popup menus.

Member Function Documentation

◆ animate()

void SynthEditor::animate ( bool animate)

Enables or disables animation in the GUI (e.g., for meters or visualizations).

Toggles GUI animation such as oscilloscopes or VU meters.

Parameters
animateWhether to animate the GUI elements.
animateIf true, animations are turned on; otherwise, off.

◆ getAudioDeviceManager()

AudioDeviceManager * SynthEditor::getAudioDeviceManager ( )
inlineoverridevirtual

Returns a pointer to the AudioDeviceManager for this standalone app.

Returns
Pointer to the AudioDeviceManager.

Reimplemented from SynthGuiInterface.

◆ getCriticalSection()

const CriticalSection & SynthEditor::getCriticalSection ( )
inlineoverridevirtual

Returns the critical section used for thread-safe operations.

Returns
Reference to the CriticalSection.

Implements SynthBase.

◆ getGuiInterface()

SynthGuiInterface * SynthEditor::getGuiInterface ( )
inlineoverridevirtual

Returns a pointer to the GUI interface of this synth.

Returns
This SynthEditor as a SynthGuiInterface.

Implements SynthBase.

◆ getNextAudioBlock()

void SynthEditor::getNextAudioBlock ( const AudioSourceChannelInfo & buffer)
override

Callback for the audio device. Processes incoming audio and MIDI.

Called by the audio device to provide next audio block.

Parameters
bufferThe channel info containing buffer data.

Processes pending MIDI events, updates the synthesizer engine, and renders audio data into the provided buffer.

Parameters
bufferReference to the AudioSourceChannelInfo containing the buffer.

◆ paint() [1/2]

void SynthEditor::paint ( Graphics & )
inlineoverride

Paints the editor background.

Parameters
gThe graphics context used for rendering.

◆ paint() [2/2]

void SynthEditor::paint ( Graphics & g)
inlineoverride

Called to repaint any custom graphics, which are not currently used here.

Parameters
gThe JUCE Graphics context.

◆ pauseProcessing()

void SynthEditor::pauseProcessing ( bool pause)
inlineoverridevirtual

Pauses or resumes audio processing by locking or unlocking the critical section.

Parameters
pauseIf true, locks the section; otherwise, unlocks it.

Implements SynthBase.

◆ prepareToPlay()

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

Prepares the audio engine to begin playing.

Prepares the audio engine for playback.

Called by the audio subsystem. Sets up sample rate and other parameters in the engine.

Parameters
buffer_sizeThe size of the audio buffer in samples.
sample_rateThe sampling rate.

Sets the sample rate for the sound engine and the MIDI manager, and updates any modulation switches in the engine.

Parameters
buffer_sizeThe size of the audio buffer (in samples).
sample_rateThe sampling rate (in Hz).

◆ releaseResources()

void SynthEditor::releaseResources ( )
override

Releases resources allocated for audio playback.

Releases any resources allocated for audio playback.

Currently empty, but can be used to cleanup resources if needed.

◆ resized() [1/2]

void SynthEditor::resized ( )
override

Called when the editor is resized.

Called when the component is resized.

Adjusts the GUI bounds to match the new editor size.

Ensures the GUI interface is resized to fill the entire window.

◆ resized() [2/2]

void SynthEditor::resized ( )
override

Called when the component is resized. Resizes internal GUI components if present.

◆ setScaleFactor()

void SynthEditor::setScaleFactor ( float newScale)
override

Sets a new scale factor for the GUI.

Parameters
newScaleThe new scaling factor to apply.

Adjusts the interface scaling and triggers a background re-render.

◆ timerCallback()

void SynthEditor::timerCallback ( )
override

Timer callback used to periodically scan for new MIDI devices.

Periodically checks for new MIDI devices and enables them.

This callback runs at intervals set by startTimer().

◆ updateFullGui()

void SynthEditor::updateFullGui ( )
overridevirtual

Forces a full GUI update.

Updates all GUI elements and notifies the host that the display might have changed.

Reimplemented from SynthGuiInterface.


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