free-audio / clap

Audio Plugin API
https://cleveraudio.org/
MIT License
1.73k stars 98 forks source link

Clarification on how to notify host of change in number of parameters #341

Closed frabert closed 11 months ago

frabert commented 11 months ago

The comments state:

It can only be used while the plugin is deactivated. If the plugin is activated use clap_host->restart() and delay any change until the host calls clap_plugin->deactivate().

I'm not completely sure on what this means. Would this be correct?

...
params_changed = 1;
host->restart();
...

void deactivate() {
  if (params_changed) {
    params_changed = 0;
    apply_changes();
    params->rescan(CLAP_PARAM_RESCAN_ALL);
  }
}
robbert-vdh commented 11 months ago

I think that clap_host->restart() part is a leftover of an older version of the API. You call clap_host_params->rescan(CLAP_PARAM_RESCAN_ALL) from the main thread when you want to change the number of parameters, or when changing parameter options that cannot be changed at runtime. But as noted in the flag's description, you should only actually report a different parameter count after the host has deactivated your plugin (as that could otherwise result in race conditions).

frabert commented 11 months ago

Thanks for the clarification! I guess the behavior I am observing in my plugin is a bug in the host itself then.