How do I set state information?

How do I set state information?

void AnalogueOverdriveAudioProcessor::setStateInformation (const void* data, int sizeInBytes)
{
    // this doesn't work
    inputLevel = 1.0f;
}

You can implement getStateInformation and setStateInformation in whatever way you like. Those only provide and receive blocks of memory to/from the host. (So how you implement setStateInformation has to somehow closely mirror what getStateInformation does.)

How is the inputLevel = 1.0f; not working? (Besides it being a bit nonsensical inside the setStateInformation implementation…)

Yes, to always set a variable to the same value for this is nonsensical, I’m only doing this to help me figure out a starting point. From a trivial perspective though, shouldn’t this work?

Maybe I’m doing something wrong somewhere else…

Work to do what exactly? Is inputLevel at least a member variable of your AudioProcessor subclass?

edit : It would be helpful to know how exactly the code is not working. It does not compile? The setStateInformation method is never called by the host/JUCE? Some other issue?

Yes “inputLevel” is a member variable of my AudioProcessor subclass.

When I load the plugin into a DAW and it begins processing, “inputLevel” is not set to 1.0, even though I explicitly set it to 1.0 in setStateInformation().

setStateInformation is called when the host has some state to set into your plugin. (Like when the host is loading its project file or doing undo/redo.) To handle the case when the host doesn’t have that state to give to your plugin, your plugin should initialize its variables in the AudioProcessor subclass constructor. (Or if you are using C++11, you can initialize your member variables directly in your class declaration.)

I see.

So I need to implement getStateInformation(), if I want setStateInformation() to work?

Yes. But you will still also need to explicitly initialize your class members. (In the constructor or in the directly in the class members.)

The call order is something like :

  1. Host creates the plugin. The plugin must initialize itself explicitly into a default state.
  2. Host saves its project file. The plugin’s getStateInformation is called and the plugin should serialize its state into the memory block provided.
  3. Host loads its project file. The plugin is created and setStateInformation is called and the plugin should recreate its state from the memory block provided.

Great. Thanks very much for your help.

Sidenote, what I just found out: you don’t have to load the parameters in setStateInformation, because the host will set them anyway by calling AudioParameter::setValue()… Because the values are depending on the position on the timeline anyway. A constant value for the parameter is the exception, not the rule.

And in case of FinalCut it is actually creating problems to do so.

So setStateInformation is actually useful for host-not-aware information…

I could swear that has not worked for me with Reaper and the JUCE demo host, it was necessary to implement getStateInformation and setInformation to get the parameters to recall…But maybe I didn’t test well enough or there was some other issue at the time in my plugin’s code… edit : It of course makes sense it should work without get/setStateInformation for simple numeric parameters.

At the same time it makes sense, that it doesn’t work for the JUCE demo host, as that doesn’t implement automations…
But for Reaper I don’t find an excuse…

Seems not yet perfect… but I heard rumors, that the parameter stuff is scheduled for revision…