Script option other than looping for performance improvement?

Greetings,
I’m running into a performance issue with one of my scripts. I have each key sampled separately for an instrument leading to a lot of zones. It works fine until I get into Halion Sonic 3 and load up 4 layers with my instrument and then tweak the knobs that are running code similar to below. I get crackles until I increase the buffer size when changing parameters in my macro designer with the knobs that have code similar to the below. Is there a more efficient way to set a parameter across all zones in a script other than doing a loop?


-- remap the LFO1 cutoff depth from -100 to 100 to 0 to 100
function onParamCutoffDepthChanged()
    elements = this.program:findChildren(true)
    for i, element in ipairs(elements) do
        if type(element) == "Zone" then
 		--print(element.name)
		--print(element:getModulationMatrixRow(2).rowNumber)
	     if element:getModulationMatrixRow(2):hasParameter("Destination.Depth") then
              element:getModulationMatrixRow(2):setParameter("Destination.Depth",paramCutoffDepth)
	     end
        end
    end
end

-- remap the LFO2 pitch depth from -100 to 100 to 0 to 100
function onParamPitchDepthChanged()
    elements = this.program:findChildren(true)
    for i, element in ipairs(elements) do
        if type(element) == "Zone" then
	     if element:getModulationMatrixRow(1):hasParameter("Destination.Depth") then
              element:getModulationMatrixRow(1):setParameter("Destination.Depth",paramPitchDepth)
	     end
        end
    end
end

I hope there is a better way of doing this so I can keep the instrument running at low buffer sizes. Appreciate the advice/thoughts.

Hi DodgingRain,

Does each of the layers in Halion Sonic has its own macro page and the same script?

I’m just wondering if using “this.program” is necessary. Maybe it is if you want to control all the layers from a single script module.

But I would try “findZones(true)” instead of “findChildren”. This way you don’t need to loop through all objects including layers, busses, effects, midi modules… You only loop through zones. It would also save you a few “ifs”. You don’t need to check if it is zone.

Also I don’t think the line with “hasParameter” is necessary. Every zone has modulation matrix row parameter “Destination.Depth”.

You can simplify the function to “findZones”, “getModulationMatrixRow”, “setParameter”.
Depending on how many zones you have it might still not be as efficient as you’d like but worth a try.

\


Another option could be using a ui script. Create parameters with the range you want.

defineParameter("destDepth1",nil,0,0,100)
defineParameter("destDepth2",nil,0,0,100)

Connect the ui script parameters to Destination.Depth parameters of the first and second modulation matrix row.

@type:Zone/@id:100a0002
@type:Zone/@id:104a0002


You won’t be able to automate them though.