setState() stateChanged() and getSate()

Programming applications for making music on Linux.

Moderators: khz, MattKingUSA

User avatar
marbangens
Established Member
Posts: 21
Joined: Fri Nov 16, 2018 8:39 pm

setState() stateChanged() and getSate()

Postby marbangens » Sun Aug 18, 2019 3:05 pm

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: 21
Joined: Fri Nov 16, 2018 8:39 pm

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

Postby marbangens » Sun Aug 18, 2019 4:31 pm

It works with Carla and Ardour but not Renoise. Something weird is going on :|

User avatar
Michael Willis
Established Member
Posts: 840
Joined: Mon Oct 03, 2016 3:27 pm
Location: Rocky Mountains, North America
Contact:

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

Postby Michael Willis » Sun Aug 18, 2019 4:44 pm

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: 21
Joined: Fri Nov 16, 2018 8:39 pm

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

Postby marbangens » Sun Aug 18, 2019 5:04 pm

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: 840
Joined: Mon Oct 03, 2016 3:27 pm
Location: Rocky Mountains, North America
Contact:

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

Postby Michael Willis » Sun Aug 18, 2019 5:14 pm

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: 105
Joined: Sun Jul 02, 2017 1:24 pm

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

Postby SpotlightKid » Sun Aug 18, 2019 6:31 pm

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: 840
Joined: Mon Oct 03, 2016 3:27 pm
Location: Rocky Mountains, North America
Contact:

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

Postby Michael Willis » Sun Aug 18, 2019 7:11 pm

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: 21
Joined: Fri Nov 16, 2018 8:39 pm

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

Postby marbangens » Sun Aug 18, 2019 8:26 pm

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: 105
Joined: Sun Jul 02, 2017 1:24 pm

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

Postby SpotlightKid » Sun Aug 18, 2019 8:36 pm

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: 105
Joined: Sun Jul 02, 2017 1:24 pm

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

Postby SpotlightKid » Sun Aug 18, 2019 9:49 pm

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: 21
Joined: Fri Nov 16, 2018 8:39 pm

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

Postby marbangens » Mon Aug 19, 2019 7:01 am

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


Return to “Developer's Section”

Who is online

Users browsing this forum: No registered users and 1 guest