# Plugin not loading state in Reaper (noob questions part 2), but stand-alone

**URL:** <https://forum.juce.com/t/plugin-not-loading-state-in-reaper-noob-questions-part-2-but-stand-alone/55529>\
**Category:** General JUCE discussion\
**Created:** [March 27, 2023, 8:02am UTC](https://forum.juce.com/t/plugin-not-loading-state-in-reaper-noob-questions-part-2-but-stand-alone/55529 "2023-03-27T08:02:17Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![maximpiz](https://avatars.discourse-cdn.com/v4/letter/m/8c91f0/32.png) [@maximpiz](https://forum.juce.com/u/maximpiz)\
**Post date:** [March 27, 2023, 8:02am UTC](https://forum.juce.com/t/plugin-not-loading-state-in-reaper-noob-questions-part-2-but-stand-alone/55529/1 "2023-03-27T08:02:17Z")

</div>

As a beginner, I am currently running into some serious problem when loading stored parameters:

One test plugin here uses the **generic editor** only and correctly loads its state using method _setStateInformation_. So far so good.

![5](https://us1.discourse-cdn.com/flex026/uploads/juce/original/2X/c/c9bf24ab60f827f88a686ef7103ab5d37ff83bbf.png)

Now I made a second test plugin to see what kind of method is called in what situation using a **normal (custom) editor**. It looks like the state is not loaded, because **setStateInformation** is not called when reopening a Reaper session where the plugin is instantiated. I have no idea what prevents it to load. In the stand-alone version of this code, the state is correctly stored and loaded, but not in plugin mode.

[PluginEditor.cpp](https://forum.juce.com/uploads/short-url/1U6bt9klSFEyl2O5YKhb24Xja7Z.cpp) (3.0 KB)  
[PluginEditor.h](https://forum.juce.com/uploads/short-url/3KiEj9yqmNhCI1Wz46gpFdP490S.h) (956 Bytes)  
[PluginProcessor.cpp](https://forum.juce.com/uploads/short-url/lwzDkvY5m9hJ9LaTWgX3NT8raYf.cpp) (2.5 KB)  
[PluginProcessor.h](https://forum.juce.com/uploads/short-url/zZyEErDWpM9CawL3JxlRfPawBOB.h) (2.6 KB)

The plugin has a counter as a state to be incremented each time the plugin is loaded (or started).  
Also, I instantiate a parameterfloat and store it although it’s not used, just to avoid the case that no “official” parameter exists.

img1 is the plugin freshly opened, img2 is the plugin reopened in the same session. Destructor and Constructor are called. img3 is the Reaper session reopened: no call of setStateInformation. img4 is the stand-alone version which behaves correctly.

Does anyone have an idea what prevents the function to be called? Is it only called when there is some parameter linked to a slider? (attachment object actually exists). Those parameterfloats are only automatically shown when there is a generic editor. I dunno yet any way to make them visible in a custom editor, but that’s a different story.

Thanks

 ![1](https://us1.discourse-cdn.com/flex026/uploads/juce/original/2X/5/5b104d6e3ca709f0c7c122f6c4cdc85eb3259eb4.png)  
 ![2](https://us1.discourse-cdn.com/flex026/uploads/juce/original/2X/f/f5c143d36db520f9cba95282a9fa04308e361310.png)  
 ![3](https://us1.discourse-cdn.com/flex026/uploads/juce/original/2X/b/bfbb8f5f3066197dbff24346d0f8879551027098.png)  
 ![4](https://us1.discourse-cdn.com/flex026/uploads/juce/original/2X/5/54df17ef3d1e0f13208423778a69807e0de4d421.png)

---

<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:** [March 27, 2023, 12:15pm UTC](https://forum.juce.com/t/plugin-not-loading-state-in-reaper-noob-questions-part-2-but-stand-alone/55529/2 "2023-03-27T12:15:07Z")

</div>

It looks like Reaper doesn’t bother calling get/setStateInformation if the parameter values haven’t actually changed. You are not changing the “dummy” parameter’s value anywhere in your code after you have constructed it. But if I change your prepareToPlay to the following, the setStateInformation call will happen

```auto
void JUCE_TESTAudioProcessor::prepareToPlay (double sampleRate, int samplesPerBlock)
{
    n_prepare++;
    *dummy = 0.4;
}
```

Note that if you are attempting to do some kind of non-parameter state in your plugin, you may end up having to do this kind of thing anyway. There doesn’t seem to be a universally working solution to notify the host that non-parameter state has changed in the plugin.(\*) You would have set the “dummy” parameter’s value to something else each time the non-parameter state has changed.

(\*) The “official” solution that should work is to call the following in the audio processor when the non-parameter state has changed, but it doesn’t really always work

```auto
updateHostDisplay(juce::AudioProcessorListener::ChangeDetails().withNonParameterStateChanged(true));
```

---

<div class="post-metadata">

**Author:** ![maximpiz](https://avatars.discourse-cdn.com/v4/letter/m/8c91f0/32.png) [@maximpiz](https://forum.juce.com/u/maximpiz)\
**Post date:** [March 28, 2023, 8:42am UTC](https://forum.juce.com/t/plugin-not-loading-state-in-reaper-noob-questions-part-2-but-stand-alone/55529/3 "2023-03-28T08:42:34Z")

</div>

Hi @xenakios ,

thanks a lot for your input!

Actually, the _getstateinformation_ is called as shown before, only _set…_ is not called. I checked your change (the explicit assignment of the _dummy_ parameter to force a change) and for some reason, it doesn’t make a difference here. Maybe we have different Reaper versions. I will investigate further.

I made some example plugin. Also interesting that if I use _new_ and _delete_, code will not pass Reaper plugin check, so I went with static storage for now.

EDIT:

I have to correct myself: I put it in _prepareToPlay_ and now it’s working!!  
100 thanks. I guess I had put it in the release function before.

---

<div class="post-metadata">

**Author:** ![splintersilk](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/splintersilk/32/14724_2.png) [@splintersilk](https://forum.juce.com/u/splintersilk)\
**Post date:** [January 15, 2024, 9:38am UTC](https://forum.juce.com/t/plugin-not-loading-state-in-reaper-noob-questions-part-2-but-stand-alone/55529/4 "2024-01-15T09:38:54Z")

</div>

> [@xenakios](#):
>
> ```auto
> updateHostDisplay(juce::AudioProcessorListener::ChangeDetails().withNonParameterStateChanged(true));
> 
> ```

Hey there, thank you both for sharing your experience on this. I’ve been wrestling with this for a couple of days, purely with Reaper per the OP (Ableton Live 11 is completely fine).

In my experience just now, yes doing a dance in prepareToPlay just to dirty a parameter does seem to work - setStateInformation() _does_ get called. Yay.

However I did also find that this updateHostDisplay _also_ worked. @xenakios could share your thoughts behind saying “it doesn’t really always work” please? I’m trying to figure out what the gotchas might be.

Cheers!

---

<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:** [January 15, 2024, 4:38pm UTC](https://forum.juce.com/t/plugin-not-loading-state-in-reaper-noob-questions-part-2-but-stand-alone/55529/5 "2024-01-15T16:38:39Z")

</div>

> [@splintersilk](#):
>
> could share your thoughts behind saying “it doesn’t really always work” please? I’m trying to figure out what the gotchas might be

You’d need to check it with every plugin format and host combination you want to support to be sure it really works in all those. The hosts are not really obligated to do anything in response to that updateHostDisplay call.

---

<div class="post-metadata">

**Author:** ![maximpiz](https://avatars.discourse-cdn.com/v4/letter/m/8c91f0/32.png) [@maximpiz](https://forum.juce.com/u/maximpiz)\
**Post date:** [January 15, 2024, 5:16pm UTC](https://forum.juce.com/t/plugin-not-loading-state-in-reaper-noob-questions-part-2-but-stand-alone/55529/6 "2024-01-15T17:16:31Z")

</div>

I solved this issue back then, somehow.

Always use

xml-\>setAttribute

in getStateInformation

and stuff like

```
std::unique_ptr<juce::XmlElement> xmlState (getXmlFromBinary (data, sizeInBytes));

if ((xmlState.get() != nullptr) && (xmlState->hasTagName("PluginName")))
{
    for (int i = 0; i < NUM_PAR; i++)
        **par_vec[i] = (float)xmlState->getDoubleAttribute(par_tag_vec[i], par_def_vec[i]);
}
*bla = xmlState->getBoolAttribute("bla", false);

```

in setStateInformation

So basically, the xml-related functions, the others didn’t work.  
Now it always works.
