Page 1 of 1
setState() stateChanged() and getSate()
Posted: Sun Aug 18, 2019 3:05 pm
by marbangens
I have this
on both Plugin and UI. They should share this "wave information"
I have
Code: Select all
void DistoTVUI::stateChanged(const char* key, const char* value)
{
printf("Im here at StateChanged\n");
if (strcmp(key, "waveform") == 0) {
char* tmp;
int i = 0;
char tmpbuf[4*AREAHEIGHT+1] = {0};
snprintf(tmpbuf, 4*AREAHEIGHT, "%s", value);
tmp = strtok(tmpbuf, " ");
while ((tmp != NULL) && (i < AREAHEIGHT)) {
wave_y[i] = AREAHEIGHT-((float)atoi(tmp));
i++;
printf("reload dsp wave_y[%d]=%.2f ", i, wave_y[i]);
tmp = strtok(NULL, " ");
}
}
repaint();
}
on the UI but it never gets called.
So if I close the UI window, the wave never gets re-painted and overwritten by the UI when I open the window from host.
I think I should change stateChanged() to setState(), because the UI is the only input and the state never gets changed on the plugin side, it only has the information there. But there is no documentation or examples I have found on UI::setState()
https://github.com/martinbangens/DistoTV
Re: setState() stateChanged() and getSate()
Posted: Sun Aug 18, 2019 4:31 pm
by marbangens
It works with Carla and Ardour but not Renoise. Something weird is going on

Re: setState() stateChanged() and getSate()
Posted: Sun Aug 18, 2019 4:44 pm
by Michael Willis
You should not override setState() in your UI class. Here's the general flow of how states work in DPF:
When something happens in the UI that changes the state, the UI class should call setState() to notify the Plugin class about the update. The should result in the plugin host eventually saving that state.
When the plugin hosts loads the UI, it should call the stateChanged() method to restore the previously saved state.
I noticed that your Plugin class has the following:
Plugin(paramCount, 0, 0) // 1 program, 0 states
The comment is already inconsistent with the code, but what you want is this:
Plugin(paramCount, 0, 1) // 0 programs, 1 state
Otherwise I don't think it will save and load your state.
Re: setState() stateChanged() and getSate()
Posted: Sun Aug 18, 2019 5:04 pm
by marbangens
ops, Thank you I forgot that

I have to enable 1 state there

and It work for Renoise now

Re: setState() stateChanged() and getSate()
Posted: Sun Aug 18, 2019 5:14 pm
by Michael Willis
marbangens wrote:ops, Thank you I forgot that

I have to enable 1 state there

and It work for Renoise now

Virtual long distance high-five. I look forward to trying your distortion effect.
Off topic, why is distortion always associated with guitar? Why not ukulele or piano or saxophone or something?
Re: setState() stateChanged() and getSate()
Posted: Sun Aug 18, 2019 6:31 pm
by SpotlightKid
Michael Willis wrote:[...] what you want is this:
Plugin(paramCount, 0, 1) // 0 programs, 1 state
Otherwise I don't think it will save and load your state.
I think if you have state it is a good idea to have at least one factory program. The state can be be saved in LV2 preset files, but if the plugin has no factory preset, Carla, for example, won't enable the GUI controls to load LV2 presets.
Re: setState() stateChanged() and getSate()
Posted: Sun Aug 18, 2019 7:11 pm
by Michael Willis
SpotlightKid wrote:
I think if you have state it is a good idea to have at least one factory program.
Oh right, in DPF set that up by overriding the Plugin::initState method.
Re: setState() stateChanged() and getSate()
Posted: Sun Aug 18, 2019 8:26 pm
by marbangens
SpotlightKid wrote:
I think if you have state it is a good idea to have at least one factory program. The state can be be saved in LV2 preset files, but if the plugin has no factory preset, Carla, for example, won't enable the GUI controls to load LV2 presets.
Now I need to implement full state API in order for that to work. Cus when you enable both of those DPF wants me
to override getState() now. And Renoise wont save the wave aging. I think now it depends on this function getState().
Re: setState() stateChanged() and getSate()
Posted: Sun Aug 18, 2019 8:36 pm
by SpotlightKid
You probably know that, but you can look at this DPF example:
https://github.com/DISTRHO/DPF/blob/mas ... States.cpp
I also just implemented state in one of my plugins (no UI):
https://github.com/SpotlightKid/midioma ... r.cpp#L203
One interesting thing I did there is to save binary data (a uint8_t array) as a base64 encode string. In LV2, if you set the correct state type, the host would do that for you. But since DPF also must support VST2, you have to do it yourself.
Re: setState() stateChanged() and getSate()
Posted: Sun Aug 18, 2019 9:49 pm
by SpotlightKid
if the plugin has no factory preset, Carla, for example, won't enable the GUI controls to load LV2 presets.
Correction: Carla doesn't enable the "Load State" button, unless there's at least one factory
or user preset. So apparently no need to include a factory preset, if not needed.
Sorry the misinformation.
Re: setState() stateChanged() and getSate()
Posted: Mon Aug 19, 2019 7:01 am
by marbangens
No I need it, I want presets later
