I have 4 controllers in 3 rows I wanted linked to the relevant layer QCs. The 4 controllers do exactly the same thing on each layer, so I thought this is a good time to use loops to create the parameters and change call.
This script does work:
My question is, is this a good way of doing it. I’m worried that the nested for loops and using a single change function for all 12 parameters is bad practice / bad for CPU usage.
One “end)” is moved to the next line in the code display, so it looks a bit funny.
masterLayer = this.parent:getLayer()
noiseLayers = masterLayer:findLayers()
-- Modulation parameter names and controllers
modSetup = {
{name = "pitch", control = "QuickControl.QC3"},
{name = "toPitchEnv", control = "QuickControl.QC4"},
{name = "pitchLfoDepth", control = "QuickControl.QC6"},
{name = "filtLfoDepth", control = "QuickControl.QC7"},
{name = "volLfoDepth", control = "QuickControl.QC8"}
}
-- Create modulation parameters
modSetupNames = {}
for i = 1, #modSetup do
modSetupNames[i] = modSetup[i].name
end
for i, noiseLayer in ipairs(noiseLayers) do
for j, modSetupName in ipairs(modSetupNames) do
local paramName = noiseLayer.name.." "..modSetupName
defineParameter(paramName, nil, 0, -50, 50, 0.1, function() modChange(i, j, _G[paramName]) end)
end
end
-- Modulation change call
modSetupControls = {}
for i = 1, #modSetup do
modSetupControls[i] = modSetup[i].control
end
function modChange(layer, param, modVal)
local modLayer = noiseLayers[layer].name
local modParam = modSetupControls[param]
masterLayer:getLayer(modLayer):setParameter(modParam, modVal + 50)
end