Combine Mod Matrix Depth of multiple rows

I’m trying to create a knob that when it is moved it changes the depth of 2 rows in the mod matrix however one row’s depth is positive and the other is negative.
For instance, if the knob is moved to value 85, one row’s depth is 85 and the other is -85. Likewise, you move the knob to 45, the other is -45.
I know this is simple but for whatever reason no matter what way I write it its not working.

zone = this.parent:getZone("Zone 1")
amountA = zone:getModulationMatrixRow(11):getParameter("Destination.Depth")

function onAmountChanged()
  depth = amountA-(amountA*2)
  return zone:getModulationMatrixRow(12):setParameter("Destination.Depth", depth)
end
defineParameter ('Amount', "Amounts", 100, -100, 100, 0.1, onAmountChanged)

You can do it like this:

zone = this.parent:getZone("Zone 1")

function onAmountChanged()
    zone:getModulationMatrixRow(11):setParameter("Destination.Depth", Amount)
    zone:getModulationMatrixRow(12):setParameter("Destination.Depth", -Amount)
end

defineParameter ('Amount', "Amounts", 0, -100, 100, 0.1, onAmountChanged)

If you want to control several pairs of parameters you can make the function accept arguments and use anonymous callback.

zone = this.parent:getZone("Zone 1")

function onAmountChanged(row, invRow, value)
    zone:getModulationMatrixRow(row):setParameter("Destination.Depth", value)
    zone:getModulationMatrixRow(invRow):setParameter("Destination.Depth", -value)
end

defineParameter ('Amount1', "Amounts1", 0, -100, 100, 0.1, function() onAmountChanged(11, 12, Amount1) end)
defineParameter ('Amount2', "Amounts2", 0, -100, 100, 0.1, function() onAmountChanged(13, 14, Amount2) end)
1 Like

Thanks for the quick response. Feel a bit dumb, I knew I was overthinking the arithmetic on that ha.

If I can add on to this…

Any idea why the connection to the knob and the function of the script breaks if I change a subpreset?

My instrument has a structure similar to this:

  • Main Layer
    • Main Layer Script
    • Layer 1
      • Layer 1 Script
      • Zone Layer
        • Zone
    • Layer 2
      • Layer 2 Script
      • Zone Layer
        • Zone

I placed the function in the script of the Main Layer Script. When doing so the knob I attach the “Amount” parameter of the function to works as desired. However, when I change a subpreset of either Layer 1 or Layer 2. with the Sample Selector template, the knob breaks.

I have a script within each of the Layer 1 and Layer 2 scripts that copy’s parameters of the zones before changing the subpreset and then restores those parameters. So the whole mod matrix remains the same even when changing subpresets…

My guess is it’s the zone variable assuming you use the script above.

You create the zone variable when the script loads. After loading new preset you have new zone but the script variable still refers to the original zone.

You probably need to update the zone variable after loading new preset. Or put the variable inside the function and possibly make it local.

Or just do this.parent:getZone():getModulationMatrixRow()... inside the function.

Ah, you’re right. That seems to have fixed it for the most part. However, if I change to a multi sample subpreset, it only affects one of the zones.
I tried changing getZone() to findZones(), but that didn’t seem to resolve the issue. I know adding “true” as an argument to the findZones() has it look in further sublayers but that doesn’t really change the outcome.

Use a loop and change the parameters for all zones.

function onAmountChanged()
	local zones = this.parent:findZones(true)
	for i, zone in ipairs(zones) do
		zone:getModulationMatrixRow(11):setParameter("Destination.Depth", Amount)
		zone:getModulationMatrixRow(12):setParameter("Destination.Depth", -Amount)
	end
end

defineParameter ('Amount', "Amounts", 0, -100, 100, 0.1, onAmountChanged)

Ah, I see. I had actually tried the loop but I failed to mention I modified it so that I’m using the same row instead of two mod rows. But its no harm to use two rows. I’ll give this a try. THANKS!