9#include "sound_engine.h"
13 last_seconds_time_ = 0.0;
17 for (
int i = 0; i < num_params; ++i) {
25 bridge_lookup_[details->
name] = bridge;
29 bypass_parameter_ = bridge_lookup_[
"bypass"];
39 AudioProcessorEditor* editor = getActiveEditor();
47 if (bridge_lookup_.count(name))
48 bridge_lookup_[name]->beginChangeGesture();
53 if (bridge_lookup_.count(name))
54 bridge_lookup_[name]->endChangeGesture();
59 if (bridge_lookup_.count(name)) {
60 vital::mono_float plugin_value = bridge_lookup_[name]->convertToPluginValue(value);
61 bridge_lookup_[name]->setValueNotifyHost(plugin_value);
67 return getCallbackLock();
72 suspendProcessing(pause);
76 return JucePlugin_Name;
80 return String(channel_index + 1);
84 return String(channel_index + 1);
96#if JucePlugin_WantsMidiInput
104#if JucePlugin_ProducesMidiOutput
122 if (editor ==
nullptr || editor->
getSynth() ==
nullptr)
130 engine_->setSampleRate(sample_rate);
131 engine_->updateAllModulationSwitches();
140 static constexpr double kSecondsPerMinute = 60.0f;
143 if (bypass_parameter_->
getValue()) {
144 processBlockBypassed(buffer, midi_messages);
148 int total_samples = buffer.getNumSamples();
149 int num_channels = getTotalNumOutputChannels();
150 AudioPlayHead* play_head = getPlayHead();
152 play_head->getCurrentPosition(position_info_);
153 if (position_info_.bpm)
154 engine_->setBpm(position_info_.bpm);
156 if (position_info_.isPlaying) {
157 double bps = position_info_.bpm / kSecondsPerMinute;
158 last_seconds_time_ = position_info_.ppqPosition / bps;
166 double sample_time = 1.0 / AudioProcessor::getSampleRate();
167 for (
int sample_offset = 0; sample_offset < total_samples;) {
170 engine_->correctToTime(last_seconds_time_);
171 processMidi(midi_messages, sample_offset, sample_offset + num_samples);
172 processAudio(&buffer, num_channels, num_samples, sample_offset);
174 last_seconds_time_ += num_samples * sample_time;
175 sample_offset += num_samples;
198 String data_string = data.dump();
199 MemoryOutputStream stream;
200 stream.writeString(data_string);
201 dest_data.append(stream.getData(), stream.getDataSize());
206 MemoryInputStream stream(data, size_in_bytes,
false);
207 String data_string = stream.readEntireStreamAsString();
211 json json_data = json::parse(data_string.toStdString());
214 if (json_data.count(
"tuning"))
217 catch (
const json::exception& e) {
218 std::string error =
"There was an error open the preset. Preset file is corrupted.";
219 AlertWindow::showNativeDialogBox(
"Error opening preset", error,
false);
static json stateToJson(SynthBase *synth, const CriticalSection &critical_section)
Converts the state of a given SynthBase to JSON.
Definition load_save.cpp:78
static bool jsonToState(SynthBase *synth, std::map< std::string, String > &save_info, json state)
Loads a JSON state into the given SynthBase, applying older version updates if necessary.
Definition load_save.cpp:1011
void processKeyboardEvents(MidiBuffer &buffer, int num_samples)
Processes keyboard events from a MidiBuffer, integrating them with the MidiKeyboardState.
Definition synth_base.cpp:604
void valueChangedExternal(const std::string &name, vital::mono_float value)
Handles external (non-GUI, non-MIDI) value changes to parameters.
Definition synth_base.cpp:92
Tuning * getTuning()
Returns a pointer to the synth's Tuning object.
Definition synth_base.h:554
std::unique_ptr< MidiManager > midi_manager_
Definition synth_base.h:700
std::unique_ptr< MidiKeyboardState > keyboard_state_
Definition synth_base.h:701
vital::control_map controls_
Definition synth_base.h:718
void processAudio(AudioSampleBuffer *buffer, int channels, int samples, int offset)
Processes audio into the given buffer. May be overridden or extended by subclasses.
Definition synth_base.cpp:564
std::map< std::string, String > save_info_
Definition synth_base.h:717
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.
Definition synth_base.cpp:595
String getPresetName()
Gets the current preset’s name.
Definition synth_base.cpp:713
std::unique_ptr< vital::SoundEngine > engine_
Definition synth_base.h:699
void processModulationChanges()
Processes pending modulation changes and updates the engine accordingly.
Definition synth_base.cpp:608
The main editor component for the SynthPlugin audio processor.
Definition synth_editor.h:24
An interface class linking the Vital synthesizer backend (SynthBase) with a GUI.
Definition synth_gui_interface.h:56
SynthBase * getSynth()
Returns the SynthBase instance this interface is managing.
Definition synth_gui_interface.h:85
virtual void updateFullGui()
Updates the entire GUI to reflect the current synth state.
Definition synth_gui_interface.cpp:62
An AudioProcessor implementation for a synthesizer plugin.
Definition synth_plugin.h:26
void parameterChanged(std::string name, vital::mono_float value) override
Called when a parameter changes externally via a ValueBridge.
Definition synth_plugin.cpp:188
void processBlock(AudioSampleBuffer &, MidiBuffer &) override
Process audio and MIDI data each block.
Definition synth_plugin.cpp:139
void endChangeGesture(const std::string &name) override
Ends a parameter change gesture for the specified parameter.
Definition synth_plugin.cpp:51
void setStateInformation(const void *data, int size_in_bytes) override
Restores the plugin state from a memory block.
Definition synth_plugin.cpp:204
void prepareToPlay(double sample_rate, int buffer_size) override
Prepare the plugin to play with the given sample rate and buffer size.
Definition synth_plugin.cpp:128
bool acceptsMidi() const override
Checks if the plugin accepts MIDI input.
Definition synth_plugin.cpp:95
void releaseResources() override
Release any resources allocated for playback.
Definition synth_plugin.cpp:135
bool silenceInProducesSilenceOut() const override
Checks if silence in leads to silence out.
Definition synth_plugin.cpp:111
const String getOutputChannelName(int channel_index) const override
Returns the output channel name.
Definition synth_plugin.cpp:83
AudioProcessorEditor * createEditor() override
Creates and returns the AudioProcessorEditor for this plugin.
Definition synth_plugin.cpp:183
bool producesMidi() const override
Checks if the plugin produces MIDI output.
Definition synth_plugin.cpp:103
void beginChangeGesture(const std::string &name) override
Begins a parameter change gesture for the specified parameter.
Definition synth_plugin.cpp:45
void getStateInformation(MemoryBlock &destData) override
Saves the plugin state to a memory block.
Definition synth_plugin.cpp:193
void setValueNotifyHost(const std::string &name, vital::mono_float value) override
Sets a parameter value and notifies the host.
Definition synth_plugin.cpp:57
const String getInputChannelName(int channel_index) const override
Returns the input channel name.
Definition synth_plugin.cpp:79
const String getProgramName(int index) override
Gets the name of a program.
Definition synth_plugin.cpp:119
bool isInputChannelStereoPair(int index) const override
Checks if the given input channel forms a stereo pair.
Definition synth_plugin.cpp:87
bool hasEditor() const override
Checks if the plugin has an editor.
Definition synth_plugin.cpp:179
SynthGuiInterface * getGuiInterface() override
Returns the GUI interface for this plugin.
Definition synth_plugin.cpp:37
const CriticalSection & getCriticalSection() override
Returns the CriticalSection for thread synchronization.
Definition synth_plugin.cpp:65
virtual ~SynthPlugin()
Destructor, cleans up allocated resources.
Definition synth_plugin.cpp:32
bool isOutputChannelStereoPair(int index) const override
Checks if the given output channel forms a stereo pair.
Definition synth_plugin.cpp:91
void pauseProcessing(bool pause) override
Pauses or resumes audio processing.
Definition synth_plugin.cpp:70
const String getName() const override
Returns the name of the plugin.
Definition synth_plugin.cpp:75
SynthPlugin()
Constructs the SynthPlugin.
Definition synth_plugin.cpp:12
double getTailLengthSeconds() const override
Gets the plugin's tail length in seconds.
Definition synth_plugin.cpp:115
json stateToJson() const
Saves the current tuning state into a JSON object.
Definition tuning.cpp:387
void jsonToState(const json &data)
Restores the tuning state from a JSON object.
Definition tuning.cpp:410
A parameter bridge that connects a vital::Value to an AudioProcessorParameter, allowing the host to m...
Definition value_bridge.h:17
float getValue() const override
Gets the current normalized (0.0 to 1.0) value of the parameter.
Definition value_bridge.h:68
void setListener(Listener *listener)
Sets a listener to receive parameter change callbacks.
Definition value_bridge.h:94
static int getNumParameters()
Definition synth_parameters.h:204
static const ValueDetails & getDetails(const std::string &name)
Definition synth_parameters.h:200
nlohmann::json json
Definition line_generator.h:7
constexpr int kMaxBufferSize
Maximum buffer size for processing.
Definition common.h:39
float mono_float
Definition common.h:33
Holds metadata about a single parameter (control) in the Vital synthesizer.
Definition synth_parameters.h:23
std::string name
Unique parameter name/identifier.
Definition synth_parameters.h:38
AudioProcessor *JUCE_CALLTYPE createPluginFilter()
Definition synth_plugin.cpp:228