Now that I am debugging my synth in the Reaper DAW, I am having a very confusing issue.
I put a breakpoint in getStateInformation which as a test now only has;
void MutineerAudioProcessor::getStateInformation (MemoryBlock & destData)
{
juce::MemoryOutputStream (destData, true).writeFloat (*mainLevelParameter);
}
I also put a breakpoint in setStateInformation, which for now only have this;
void MutineerAudioProcessor::setStateInformation (const void* data, int sizeInBytes)
{
*mainLevelParameter = juce::MemoryInputStream (data, static_cast<size_t>
(sizeInBytes), false).readFloat ();
}
When I start my Visual Studio project in debug mode, my Reaper project, with only one track with my synth is loaded, getStateInformation is invoked twice. Here I would have assumed setStateInformation would be called. This causes my stored parameter to be overwritten.
Anyways after getStateInformatin has been called twice, setStateInformation is finally called, but now off course the data is incorrect!
Next in Reaper, on the track I open the “FX” which is my synth Plugin (PluginEditor). And now each and every time I via the parameter attached slider, change the parameter, getStateInformation is invoked! That does not seem right, as eventually when my 200+ parameters is added in this method, whenever I via a slider change any of these 200+ values, getStateInformation will be invoked storing all 200+ again!?!
getStateInformation is also invoked when I close my PluginEditor.
getStateInformation is invoked when I save my Reaper project.
This is how declare my parameter layout and single test parameter;
juce::AudioProcessorValueTreeState::ParameterLayout createParameterLayout ();
std::atomic<float>* mainLevelParameter = nullptr;
This is my PluginProcessor.cpp’s constructor;
MutineerAudioProcessor::MutineerAudioProcessor ()
#ifndef JucePlugin_PreferredChannelConfigurations
: AudioProcessor (BusesProperties ()
#if ! JucePlugin_IsMidiEffect
#if ! JucePlugin_IsSynth
.withInput ("Input", AudioChannelSet::stereo (), true)
#endif
.withOutput ("Output", AudioChannelSet::stereo (), true)
#endif
),
parameters (*this, nullptr, "Parameters", createParameterLayout ())
#endif
{
...
My createParameterLayout;
juce::AudioProcessorValueTreeState::ParameterLayout
MutineerAudioProcessor::createParameterLayout ()
{
juce::AudioProcessorValueTreeState::ParameterLayout params;
params.add (std::make_unique<AudioParameterFloat> ("MainLevelID", "Main Level",
0.0f, 1.0f, 0.5f));
return params;
}
I declare the parameter slider attachment in PluginEditor.h;
typedef juce::AudioProcessorValueTreeState::SliderAttachment SliderAttachment;
std::unique_ptr<SliderAttachment> mainLevelAttachment;
Finally in my PluginEditor’s constructor I attach the parameter to a slider;
mainLevelAttachment = std::make_unique<SliderAttachment> (processor.parameters,
"MainLevelID", mainLevelSlider);
So obviously I messed up somewhere, but where?