The purpose would be that it recalls the last UI size as set by the user just as it recalls all other control settings last touched by the user.
Yes, that would be good - in hindsight. Unfortunately once a plugin is released and users have created projects and presets with it you can’t change anything in the chunk format or it will break backward compatibility.
All that said, I have found a way to save the UI size as a plugin parameter and I will share it here for anyone who’s interested. The advantage of this approach is that it can be added to any existing plugin without breaking backwards compatibility - just as adding any other new control parameter to the end of the parameter list.
I started by declaring a global variable to store the resize value as float PluginUISize (initialized to 1.0) along with a new plugin parameter kPluginUISize that I added to the bottom of the parameter list.
I establish the new parameter and hide it from automation like this (0.67 to 1.5 is my resize range):
GetParam(kPlugUIScale)->InitDouble(“UI Scale”, PlugUIScale, 0.67, 1.5, 0.01, “”, IParam::kFlagCannotAutomate);
and then added the associated call to OnParamChange() that retrieves the value saved in the parameter chunk:
case kPlugUIScale:
{PlugUIScale = GetParam(kPlugUIScale)->Value();}
break;
I then added this line to the very bottom of mLayoutFunc that redraws the UI to the saved parameter size each time the UI is opened:
pGraphics->Resize(PLUG_WIDTH, PLUG_HEIGHT, PlugUIScale, true);
Finally, the current UI rescale size is retrieved and saved to the kPluginUIScale parameter by calling this in OnIdle():
if (GetUI() && PlugScale != GetUI()->GetDrawScale()) PlugUIScale = GetUI()->GetDrawScale(), GetParam(kPlugUIScale)->Set(PlugUIScale);
I tried adding the above “Get & Save Current Size” code to OnUIClose() but I found out that if the plugin UI is open when the DAW is closed OnUIClose doesn’t get called - so that didn’t always work. Repeatedly checking the plugin size in OnIdle() is inefficient but I found no other way to capture the current resize value.
Anyhow, this is unusual but it works. It saves the plugin UI size in the DAW project as well as when copies of the plugin are moved to other tracks, etc. It basically does the same thing saving the Editor State does in this regard but adding it does not mess up any existing chunk data - so it’s backwards compatibile.