Storing string AudioParameter in plugin state

Hi.
I need to store IPAdress or a host_name in plugin state.
I don’t understand WHY there is no AudioParameterString class?..

You even can drop AudioParameterInt class, and use just AudioParameterFloat, but… How to store a string?

Can you help please?

You can store whatever you want in the state. The reason why there is no AudioParameterString is, because those classes are the interface to host automation. But there is nothing useful to automate with a string, at least that’s what the SDK designers thought.

You need to handle that as custom plugin state. The plugin parameters are just numbers. (Usually handled as floats by the host application.)

I cannot find any example how to store a string…

And I don’t know how to store state for particular project. I can use the same plugin many times in one DAW project, and I want each of them to save their individual state for a given DAW project.
Where I can see the examples?

Storing the states works by implementing the callbacks:

audioProcessor.getStateInformtaion (MemoryBlock&) to save and
audioProcessor.setStateInformation (const void*, int) to restore.

It is a private chunk, so it is up to you how you serialise the data there.

Thank you.
Does it mean that I have to create a directory somewhere Library/MyCompany/PluginName/, and store individual state for each DAW project?

Not at all. When the host wants to store the project, it will ask your plugin to return it’s current state by calling getStateInformation(). Same when it loads a project, it will call your setStateInformation() providing the same chunk of memory allowing your plugin to restore what ever it needs to restore.

This chunk will be included by your hosts project file as binary blob.

Thank you Daniel! Very helpful.
I managed to store string values, and saving and restoring states.

Glad it works.

N.B. if you use the AudioProcessorValueTreeState, then there is an easy way to save and restore all parameters with one call:

void FooProcessor::getStateInformation (juce::MemoryBlock& destData)
{
    juce::MemoryOutputStream stream(destData, false);
    state.state.writeToStream (stream);
}

void FooProcessor::setStateInformation (const void* data, int sizeInBytes, juce::AudioProcessorEditor* editor)
{
    auto tree = juce::ValueTree::readFromData (data, size_t (sizeInBytes));
    if (tree.isValid() == false)
        return;

    state.replaceState (tree);
}

The AudioValueTreeState already contains all parameter values. And it has a public ValueTree member, also called state. If you store your string as property there, it will automatically be included in the persistent state.

Just as a shortcut. But you are free in the choice how to save and restore and which format to use.

Thank you. I do exactly how you described.
Do you know how I can save state only when DAW project is saved?
When I just delete plugin from a track, then getStateInformation is called, too.

In other words, I want to be able to distinguish:

  • when my plugin is just deleted from a track.
  • when getStateInformation is triggered by DAW save call.

I just don’t want to save plugin state when it just deleted from a track.

I don’t think you can. My assumption is, the host saves the state to allow undo.

Good point. Thank you.