NOTE: I mistakenly wrote “patch” in the title and in the text below. I meant “preset.” Sorry for confusing things.
I’m facing a challenge as I add some new params to an existing module.
If a user loads an old patch, Rack sets the values of the params saved in the patch, but leaves new params unchanged.
I would like my module to have an opportunity to set the new params to values that make sense for the old patch. For different params, the appropriate value might be:
- A default value.
- A value based on the values of old params in the patch.
None of the old versions of my module saved any “data” at all in the JSON. If they had, this would be easy for me to handle. Rack would call my module’s
dataFromJson(), which could detect the old version and do the right thing.
Alas, no. There’s no “data” in the JSON. And so Rack never calls my module’s
dataFromJson(). And so my new params remain at values that have nothing to do with the loaded patch.
My only solution at the moment is to rely on deprecated behavior: Override
ModuleWidget::fromJson(), and add a “data” object to the JSON (if there isn’t one already) before calling the base class.
There’s an open issue that would help: In
onBeforeFromJson() I could set a field in the module to indicate patch version 0. In
onAfterFromJson(), I could detect the old style patch by checking that field.
Another possibility is for Rack to call
dataFromJson() even if there’s no data (passing either nullptr or an empty JSON object). But for all I know, that might cause lots of other folks’ modules to explode.
Is there something better I can do? I would like my module to be able to supplement old patches with new smarts.