Help with switch that contro 2 parameters

Hello,
I’m trying to figure out if it’s possible to have a switch to turn ON/OFF two different parameters at the same time, do I need a script?
These are the two parameters:
StretchEnable
FormantShiftEnable

Thanks in advance for any help.

You need to create a boolean parameter and put whatever you want it to do inside its callback function.

function switchChanged()
    if Switch then  -- Switch == true
        -- do something 
    else  -- Switch == false
        -- do something else
    end
end

defineParameter("Switch", nil, false, switchChanged)

Thanks,
I’m a little bit lost as you know I’m zero in scripting, trying to understand…

I have tried this but I’m sure is completely wrong!
Also, where do I have to put this code, inside the Switch?



local zones = layer:findZones()

function switchChanged()
    if Switch then  -- Switch == true
       local zones StretchEnable = 1
      local zones FormantShiftEnable =1
    else  -- Switch == false
       local zones StretchEnable = 0
       local zones FormantShiftEnable =0
    end
end

defineParameter("Switch", nil, false, switchChanged)
defineParameter("Switch", nil, false, switchChanged)```

I would suggest to check the scripting documentation. It might give you some clues.

You cannot set parameters like this.
You need something like

for i, zone in ipairs (zones) do
    zone:setParameter("Name", value)
end

The parameter name needs to be exactly as it appears in parameter list. You cannot just make it up. If you find the parameter in subfolder (in parameter list) then write it as subfolder.parameter (Filter.Cutoff)…

Because you want to set 2 different parameters just duplicate the line
zone:setParameter("Name", value) with different parameter name and value.

Hello, thanks.

Is this correct?

function switchChanged()
    if Switch then  -- Switch == true
        for i, zone in ipairs (zones) do
    zone:setParameter("StretchEnable", 1)
    zone:setParameter("FormantShiftEnable", 1)
end 
    else  -- Switch == false
       for i, zone in ipairs (zones) do
     zone:setParameter("StretchEnable", 0)
    zone:setParameter("FormantShiftEnable", 0)
end
    end
end

defineParameter("Switch", nil, false, switchChanged)

Also where I have to put this code?
I tried both in the program and in the GUI but is not working…

Almost there…
Those 2 parameters are grouped under SampleOsc folder so you need to adjust the names.
Also check what type of values you need to set them. In this case it’s boolean, not a number.
(You can check this in parameter list)

Because the script parameter and those 2 parameters are of the same type you can skip the “if else” bit and do it like this:

local zones = this.parent:findZones()

function stretchFormantChanged()
	for i, zone in ipairs(zones) do
		zone:setParameter("SampleOsc.StretchEnable", StretchFormant)
		zone:setParameter("SampleOsc.FormantShiftEnable", StretchFormant)
	end
end

defineParameter("StretchFormant", nil, true, stretchFormantChanged)
1 Like

Thanks again.
unfortunately, I tried also with your new script but is still not working for me.
I tried also in a new initialized program.

This was meant for the program tree script.

Add lua script module inside your Init layer.

1 Like