# Storing string AudioParameter in plugin state

**URL:** <https://forum.juce.com/t/storing-string-audioparameter-in-plugin-state/39620>\
**Category:** Development\
**Created:** [May 22, 2020, 6:29pm UTC](https://forum.juce.com/t/storing-string-audioparameter-in-plugin-state/39620 "2020-05-22T18:29:33Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![lubenskiy](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/lubenskiy/32/8439_2.png) [@lubenskiy](https://forum.juce.com/u/lubenskiy)\
**Post date:** [May 22, 2020, 6:29pm UTC](https://forum.juce.com/t/storing-string-audioparameter-in-plugin-state/39620/1 "2020-05-22T18:29:33Z")

</div>

Hi.  
I need to store _IPAdress_ or a _host\_name_ in plugin state.  
I don’t understand WHY there is no AudioParameter **String** class?..

You even can drop AudioParameter **Int** class, and use just AudioParameter **Float** , but… How to store a **string**?

Can you help please?

---

<div class="post-metadata">

**Author:** ![daniel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daniel/32/790_2.png) [@daniel](https://forum.juce.com/u/daniel)\
**Post date:** [May 22, 2020, 7:01pm UTC](https://forum.juce.com/t/storing-string-audioparameter-in-plugin-state/39620/2 "2020-05-22T19:01:37Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![xenakios](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/xenakios/32/4047_2.png) [@xenakios](https://forum.juce.com/u/xenakios)\
**Post date:** [May 22, 2020, 7:02pm UTC](https://forum.juce.com/t/storing-string-audioparameter-in-plugin-state/39620/3 "2020-05-22T19:02:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![lubenskiy](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/lubenskiy/32/8439_2.png) [@lubenskiy](https://forum.juce.com/u/lubenskiy)\
**Post date:** [May 22, 2020, 8:11pm UTC](https://forum.juce.com/t/storing-string-audioparameter-in-plugin-state/39620/4 "2020-05-22T20:11:52Z")

</div>

I cannot find any example how to store a string…

---

<div class="post-metadata">

**Author:** ![lubenskiy](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/lubenskiy/32/8439_2.png) [@lubenskiy](https://forum.juce.com/u/lubenskiy)\
**Post date:** [May 22, 2020, 8:20pm UTC](https://forum.juce.com/t/storing-string-audioparameter-in-plugin-state/39620/5 "2020-05-22T20:20:58Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![daniel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daniel/32/790_2.png) [@daniel](https://forum.juce.com/u/daniel)\
**Post date:** [May 22, 2020, 8:32pm UTC](https://forum.juce.com/t/storing-string-audioparameter-in-plugin-state/39620/6 "2020-05-22T20:32:52Z")

</div>

Storing the states works by implementing the callbacks:

[audioProcessor.getStateInformtaion (MemoryBlock&)](https://docs.juce.com/develop/classAudioProcessor.html#a5d79591b367a7c0516e4ef4d1d6c32b2) to save and  
[audioProcessor.setStateInformation (const void\*, int)](https://docs.juce.com/develop/classAudioProcessor.html#a6154837fea67c594a9b35c487894df27) to restore.

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

---

<div class="post-metadata">

**Author:** ![lubenskiy](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/lubenskiy/32/8439_2.png) [@lubenskiy](https://forum.juce.com/u/lubenskiy)\
**Post date:** [May 22, 2020, 8:40pm UTC](https://forum.juce.com/t/storing-string-audioparameter-in-plugin-state/39620/7 "2020-05-22T20:40:04Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![daniel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daniel/32/790_2.png) [@daniel](https://forum.juce.com/u/daniel)\
**Post date:** [May 22, 2020, 8:42pm UTC](https://forum.juce.com/t/storing-string-audioparameter-in-plugin-state/39620/8 "2020-05-22T20:42:13Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![lubenskiy](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/lubenskiy/32/8439_2.png) [@lubenskiy](https://forum.juce.com/u/lubenskiy)\
**Post date:** [May 22, 2020, 8:47pm UTC](https://forum.juce.com/t/storing-string-audioparameter-in-plugin-state/39620/9 "2020-05-22T20:47:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![daniel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daniel/32/790_2.png) [@daniel](https://forum.juce.com/u/daniel)\
**Post date:** [May 22, 2020, 8:54pm UTC](https://forum.juce.com/t/storing-string-audioparameter-in-plugin-state/39620/10 "2020-05-22T20:54:24Z")

</div>

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:

```auto
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.

---

<div class="post-metadata">

**Author:** ![lubenskiy](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/lubenskiy/32/8439_2.png) [@lubenskiy](https://forum.juce.com/u/lubenskiy)\
**Post date:** [May 23, 2020, 5:13pm UTC](https://forum.juce.com/t/storing-string-audioparameter-in-plugin-state/39620/11 "2020-05-23T17:13:14Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![daniel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daniel/32/790_2.png) [@daniel](https://forum.juce.com/u/daniel)\
**Post date:** [May 23, 2020, 5:14pm UTC](https://forum.juce.com/t/storing-string-audioparameter-in-plugin-state/39620/12 "2020-05-23T17:14:24Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![lubenskiy](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/lubenskiy/32/8439_2.png) [@lubenskiy](https://forum.juce.com/u/lubenskiy)\
**Post date:** [May 23, 2020, 5:39pm UTC](https://forum.juce.com/t/storing-string-audioparameter-in-plugin-state/39620/13 "2020-05-23T17:39:26Z")

</div>

Good point. Thank you.

---

<div class="post-metadata">

**Author:** ![ogsus](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/ogsus/32/9411_2.png) [@ogsus](https://forum.juce.com/u/ogsus)\
**Post date:** [December 16, 2020, 9:04pm UTC](https://forum.juce.com/t/storing-string-audioparameter-in-plugin-state/39620/14 "2020-12-16T21:04:28Z")

</div>

Hi, I want to do exactly the same.  
Can you give a small code example how to do that? Do you manually add a string to the xml or create a “pseudo” Parameter that stores the string?
