Page 1 of 1

Creating Multiple Parameters

Posted: Wed Mar 01, 2017 10:20 am
by AposMus
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.

Code: Select all

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

Re: Creating Multiple Parameters

Posted: Thu Mar 02, 2017 5:34 pm
by Matthias Klag
Hi AposMus,

since the loop for defineParameter is only called during the initalization of your script, I see no reason why you shouldn't do so.

Please notice that all the things you do with the quick controls, could also be done with the script. But, that's up to you, of course.

Cheers,

Matthias

Re: Creating Multiple Parameters

Posted: Mon Mar 06, 2017 11:10 pm
by AposMus
Thanks.

The quick controls are used because I started making this as a sound in Halion 5 so they where my only option at the time.

When I heard Halion 6 is coming, I stopped working on the program to see what new features could be used to improve it. I didn't want to undo all my QC connections, but for some of the functions I think it might be beneficial to do so.

I'm putting a lot of work into a very, very simple instrument, but it has become more important to me to learn how to do things correctly, rather than push something out for the sake of having it.