A learn when using the Engine.Builder functionality
-
So.... I did know that compiled plugins don't have access to the builder... but I didn't really absorb it.
I wrote a function that would create some containers, then store the index for the container in a global array.
It worked inside Hise when developing, but it didn't work inside the compiled plugin. Why? Because the builder.create call I was using doesn't run, so I don't get an index, so the global array is empty.
So, if you use the builder at all... make sure to separate out your concerns. Only use the builder for constructing the module tree, and don't expect to store the index variable from a builder.create() call, and use it elsewhere across your plugin.
Instead, write an additional function that performs whatever Synth.get call you need, to get a reference to the created module, once you've created everything.
I spent a chunk of today refactoring my code into two namespaces - TreeBuilder, and TreeConfigurator. The first just creates the modules I need according to a JSON object created earlier. The TreeConfigurator does all the hard work by getting references to modules, objects, and parameters, and storing them for future access.
The More You Know.
-
@Orvillain the script gets executed when you initialize the plugin export, so you still get your tree built, no? Because it's done on HISE level?
So when it's exported, the tree is built and there's no need to run the builder on plugin start? Did I get that right?
I see how treacherous relying on the builder returns for anything other than other builder functionality can be, though.
-
@aaronventure Yeah the builder builds the module tree, and you get that in the plugin once it is exported. But any data you derive from the builder won't get initialised correctly, which is to be expected. I'd just overlooked it.
For example let's say I do:
const builder = Synth.createBuilder() const moduleReferences = {}; inline function buildTree() { local index = builder.create(builder.Modulators.AHDSR, // the module type "GainAHDSR", // the ID sampler, // the parent module builder.ChainIndexes.Gain); // the slot type moduleReferences[index] = Synth.getEffect("GainAHDSR"); }
A fairly contrived example... but the code above should work and inside HISE when developing, it will make the AHDSR, return the module tree index for it, and then store an object reference for it in the top level moduleReferences dictionary.
But in the plugin, since the create() method cannot run, we don't get an index, which means the moduleReferences insertion doesn't resolve, which means anything relying on that data further downstream, will not work properly.
In my scenario, it was all my broadcasters that broke. The samplers worked and played back, but the broadcasters I had setup to control module parameters from UI controls, were completely broken. Because the reference dictionary I had setup for their targets, were completely empty. They were completely empty because I was initialising them within my builder calls.
-
@Orvillain good PSA, thanks!