setState() stateChanged() and getSate()

Programming applications for making music on Linux.

Moderators: MattKingUSA, khz

Post Reply
User avatar
marbangens
Established Member
Posts: 56
Joined: Fri Nov 16, 2018 8:39 pm
Been thanked: 6 times

setState() stateChanged() and getSate()

Post by marbangens »

I have this

Code: Select all

float wave_y[AREAHEIGHT]
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
User avatar
marbangens
Established Member
Posts: 56
Joined: Fri Nov 16, 2018 8:39 pm
Been thanked: 6 times

Re: setState() stateChanged() and getSate()

Post by marbangens »

It works with Carla and Ardour but not Renoise. Something weird is going on :|
User avatar
Michael Willis
Established Member
Posts: 1458
Joined: Mon Oct 03, 2016 3:27 pm
Location: Rocky Mountains, North America
Has thanked: 70 times
Been thanked: 166 times
Contact:

Re: setState() stateChanged() and getSate()

Post 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.
User avatar
marbangens
Established Member
Posts: 56
Joined: Fri Nov 16, 2018 8:39 pm
Been thanked: 6 times

Re: setState() stateChanged() and getSate()

Post by marbangens »

ops, Thank you I forgot that :wink: I have to enable 1 state there :lol:
and It work for Renoise now :D
User avatar
Michael Willis
Established Member
Posts: 1458
Joined: Mon Oct 03, 2016 3:27 pm
Location: Rocky Mountains, North America
Has thanked: 70 times
Been thanked: 166 times
Contact:

Re: setState() stateChanged() and getSate()

Post by Michael Willis »

marbangens wrote:ops, Thank you I forgot that :wink: I have to enable 1 state there :lol:
and It work for Renoise now :D
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?
User avatar
SpotlightKid
Established Member
Posts: 260
Joined: Sun Jul 02, 2017 1:24 pm
Has thanked: 57 times
Been thanked: 61 times

Re: setState() stateChanged() and getSate()

Post 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.
User avatar
Michael Willis
Established Member
Posts: 1458
Joined: Mon Oct 03, 2016 3:27 pm
Location: Rocky Mountains, North America
Has thanked: 70 times
Been thanked: 166 times
Contact:

Re: setState() stateChanged() and getSate()

Post 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.
User avatar
marbangens
Established Member
Posts: 56
Joined: Fri Nov 16, 2018 8:39 pm
Been thanked: 6 times

Re: setState() stateChanged() and getSate()

Post 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().
User avatar
SpotlightKid
Established Member
Posts: 260
Joined: Sun Jul 02, 2017 1:24 pm
Has thanked: 57 times
Been thanked: 61 times

Re: setState() stateChanged() and getSate()

Post 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.
User avatar
SpotlightKid
Established Member
Posts: 260
Joined: Sun Jul 02, 2017 1:24 pm
Has thanked: 57 times
Been thanked: 61 times

Re: setState() stateChanged() and getSate()

Post 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.
User avatar
marbangens
Established Member
Posts: 56
Joined: Fri Nov 16, 2018 8:39 pm
Been thanked: 6 times

Re: setState() stateChanged() and getSate()

Post by marbangens »

No I need it, I want presets later :wink:
Post Reply