Adding multiple zones via getZone command without mutual exclusivity

Much to my dismay I’m discovering just now that when layering samples via velocity (ie, 1-10 sample A, 11-20 sample B, etc) each one creates a seperate zone. This means that the LuaScript I was using to define the LFO destination is only being applied to Zone1.

To resolve this I have modified the first line of the script (full version below) from:

local zone = this.parent:getZone()

to

local zone = this.parent:getZone(“Zone 001”)
local zone = this.parent:getZone(“Zone 002”)
local zone = this.parent:getZone(“Zone 003”)

I confirm the names of the zones match:
image

However, this only works on the last zone mentioned. For example, if I remove the Zone003 row then Zone002 is being affected and if I remove that, Zone001 is being affected. Essentially instead of this being read as an OR statement I need it as an AND statement

The full LuaScript is below.

local zone = this.parent:getZone(“Zone 001”)
local zone = this.parent:getZone(“Zone 002”)
local zone = this.parent:getZone(“Zone 003”)

local Destination = {
{name = “Off”, index = 0},
{name = “Pitch”, index = 1},
{name = “Cutoff”, index = 2},
{name = “Resonance”, index = 3},
{name = “Distortion”, index = 4},
{name = “Pan”, index = 12},
{name = “Formant”, index = 15},

}

function getDestinationNames()
DestinationNames = {}
for i = 1, #Destination do
DestinationNames[i] = Destination[i].name
end
end

getDestinationNames()

function DestinationChanged()
zone:getModulationMatrixRow(3):setParameter(“Destination.Destination”, Destination[ModDestination].index)
end

defineParameter(“ModDestination”, nil, 4, DestinationNames, DestinationChanged)

Sure it does. Because you keep “overwriting” the same variable (zone). Think of it as reading the script from top to bottom. First the variable refers to zone 1. After second line it refers to zone 2…

But there is a solution to this. Either use different variable for each zone or use findZones which returns array of multiple zone objects and then use loop inside the parameter callback function.

zones = this.parent:findZones()

function parameterChanged()
    for i, zone in ipairs(zones) do
        zone:setParameter(parameter, value)
    end
end
1 Like

Perfect. This has worked.

Now starts the laborious task of modifying all my existing scripts to incorporate the change.
Fun fun :sweat_smile: