Problem with saving data


#1

Hello!
I am new to juce. I am trying to create my first plugin. I am making a distortion. I follow some step-by-step tutorials and everything works fine, but now i am fighting with saving plugin state (values of sliders etc.). It only works for my volume knob and wet slider, but for dry slider and drive knob doesn’t.

void DistortionAudioProcessor::getStateInformation (MemoryBlock& destData)
{
// You should use this method to store your parameters in the memory block.
// You could do that either as raw data, or use the XML or ValueTree classes
// as intermediaries to make it easy to save and load complex data.

ScopedPointer<XmlElement> xml (new XmlElement ("DistortionParameters"));

xml-> setAttribute("gain", (double) *gain);
xml-> setAttribute("alpha", (double) *alpha);
xml-> setAttribute("dry", (double) *dry);
xml-> setAttribute("wet", (double) *wet);

copyXmlToBinary(*xml, destData);

}

void DistortionAudioProcessor::setStateInformation (const void* data, int sizeInBytes)
{
// You should use this method to restore your parameters from this memory block,
// whose contents will have been created by the getStateInformation() call.

ScopedPointer<XmlElement> xmlState (getXmlFromBinary(data, sizeInBytes));

if (xmlState != nullptr)
{

    if(xmlState->hasTagName("DistortionParameters"))
    {


        *gain = xmlState->getDoubleAttribute("gain",0.0);
        *alpha = xmlState->getDoubleAttribute("alpha",5.0);
        *dry = xmlState->getDoubleAttribute("dry",-120.0);
        *wet = xmlState->getDoubleAttribute("wet",0.0);


    }

}

}


#2

Did you use slider attachments and attach them to your value tree?


#3

I did it without it. I know that i can do it with Value Tree, but I would have re-build my whole project., so first i want to try solving the problem, why it is working only for 2 parameters. Thanks for suggestion, i will do it with Value Tree if i couldn’t find the answer!


#4

Sorry if I didn’t ask this more clearly, but what I was trying to see was if you were updating all your sliders after loading the plugin state. Are you using a timer? Listeners? Can you show how you’re updating the UI?


#5

Ok, i understand i will start at the begining.
I got slider listeners

Than i got my variables:

AudioParameterFloat* gain;

AudioParameterFloat* alpha;

AudioParameterFloat* dry;

AudioParameterFloat* wet;

private:
//==============================================================================
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (DistortionAudioProcessor)
};

This is how i change value of variables:

void DistortionAudioProcessorEditor::sliderValueChanged(Slider* slider)
{

if (slider == &volumeKnob) {
   // *processor.gain = pow(10.0,(slider -> getValue()) / 20.0);
    *processor.gain = slider -> getValue();
}

else if (slider == &driveKnob){
    
    *processor.alpha = slider -> getValue();
}

else if (slider == &drySlider){
    
    *processor.dry = slider -> getValue();
}
else if (slider == &wetSlider){
    
    *processor.wet = slider -> getValue();
    
}

}

Timer:

class DistortionAudioProcessorEditor : public AudioProcessorEditor,
public Slider::Listener,
public Button::Listener,
public Timer

private:
// This reference is provided as a quick way for your editor to
// access the processor object that created it.
DistortionAudioProcessor& processor;

void timerCallback() override;

Timer callback:

void DistortionAudioProcessorEditor::timerCallback()
{
volumeKnob.setValue(*processor.gain,dontSendNotification);
driveKnob.setValue(*processor.alpha,dontSendNotification);
drySlider.setValue(*processor.dry,dontSendNotification);
wetSlider.setValue(*processor.wet,dontSendNotification);

}

And than i start my timer at AudioProcessorEditor with: startTimer(50);


#6

surround your code with three backticks: `
to format it correctly:

like this