Cache Modulator/Component Object #482
dnaldoog
started this conversation in
Show and tell
Replies: 2 comments 3 replies
-
It's like you said, another way of doing things, but the fact that you don't have to close Ctrlr each time you add a modulator to the init file is very convenient. Nice method :) |
Beta Was this translation helpful? Give feedback.
2 replies
-
What I found in practice is that it is good to have two caching tables, one for
So now you could call a uiSlider named _c.cutoff:getProperty("uiButtonColourOn", "ffffffff", true) _m.cutoff:getProperty("modulatorCustomIndex") |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
If you have a uiSlider for example named "cutoff" and you want to change the value in lua, we can write code like:
panel:getModulatorByName("cutoff"):setModulatorValue(newValue,false,true,false)
panel:getModulatorByName("cutoff"):getComponent():setValue(newValue,true)
panel:getComponent("cutoff"):setValue(newValue,true)
When this call is made, the whole list of panel objects is traversed looking for the component "cutoff".
This is inefficient, so in order to speed up this process we can assign a variable name in lua that references the object "cutoff". This variable reference is usually declared in a function within the Ctrlr program interface area Called when the panel has finished loading. Let's call it init().
Instead of calling
panel:getModulatorByName("cutoff"):setModulatorValue(20,false,true,false)
, as above, you initialise it by:cutoff = panel:getModulatorByName("cutoff")
in init(). Now in your code you can do:cutoff:setModulatorValue(20,false,true,false)
in your callback functions. This should be faster.There is another way of doing this using Memoizing, a kind of run-time optimisation, which uses lua metatables to do the same thing.
_mod.cutoff:setModulatorValue(20,false,true,false)
is called instead.Or if the component name has spaces or funny characters:
_mod("cutoff value"):setModulatorValue(20,false,true,false)
or_mod["cutoff value"]:setModulatorValue(20,false,true,false)
in a loop you can do things like:
so
_mod.mylabelL:setText()
actually calls and is a reference for:panel:getLabelComponent("myLabelL"):setText()
One advantage when compared to the
init()
script way is that while in development any variable can be created on the fly and will subsequently be cached as a variable without having to close and reload the program/Ctrlr after adding a new variable to init() in the old way. But, really the end result is the same as the init() method.Note that the first time a call is made to the cached version the underlying
panel:getModulatorByName()
is called. All subsequent calls will access the lua variable in the table _mod. (memoizing)Here is the code for this. Comment out certain groups of modulators if you want to use Ctrlr properties like
modulatorCustomIndex
etc; otherwise we access the JUCE component directly. Add the following code as you would add a global table in a separatevirtual
file in Ctrlr i.e. Add Method.In this example panel , first open the console window. On first run, or after recompiling, you will notice various messages print to console, but only once. All subsequent calls to panel components are now cached or memoized.
Beta Was this translation helpful? Give feedback.
All reactions