Linking two Mod Destinations

I’ve gotten pretty comfortable linking multiple parameters to one control on the macro page via scripting. However, I’m having a lot of trouble getting this to work with the mod matrix destinations.

I have two rows in the mod matrix that I’d like to be able to control the destinations of using one menu template on the macro page. I’ve customized the list of options for the destinations as well. I’ve inserted most of the mod matrix code I have dealing with destinations below. I’ve commented out just a few of the codes I’ve tried but unfortunately known have yielded any results.

-- define modulation destinations
defineSlotLocal("modDestinations")
modDestinations = {
					{ name = "-", 					index = ModulationDestination.unassigned    },
          { name = "Level", 				index = ModulationDestination.level    },
          { name = "Pan", 				index = ModulationDestination.pan   }
					{ name = "Cutoff", 				index = ModulationDestination.cutoff    },
					{ name = "Resonance", 			index = ModulationDestination.resonance    },
					{ name = "Distortion", 			index = ModulationDestination.distortion    },
					{ name = "Cutoff Offset", 				index = ModulationDestination.cutoffOffset    },
					{ name = "Resonance Offset", 			index = ModulationDestination.resonanceOffset    },
					{ name = "Pan", 				index = ModulationDestination.pan   }
				  }

-- create table with the names of the modulation destinations
function getModDestNames()
	modDestNames = {}
	for i=1, #modDestinations do
		modDestNames[i] = modDestinations[i].name
	end
end

getModDestNames()

-- parameter change callback to set the modulation destination
function onModDestChanged(row, modDestinationParam)
	local modDestination = modDestinations[modDestinationParam]
	local zones = this.parent:getLayer():findZones()
	for i, zone in pairs(zones) do
		zone:getModulationMatrixRow(row):setParameter("Destination.Destination", modDestination.index)
	end
end

mmParameterInfo.strings = modDestNames

-- define parameters for modulation matrix rows
for i = 1, 32 do
	mmParameterInfo.name = "ModDestination"..i
	mmParameterInfo.longName = "Modulation Destination "..i
	mmParameterInfo.onChanged = function() onModDestChanged(i, _G["ModDestination"..i]) end
	defineParameter(mmParameterInfo)
end

-- define parameters for arpeggiator controller lane destinations
for i = 1, 3 do
	mmParameterInfo.name = "CtrlLane"..i.."Dest"
	mmParameterInfo.longName = "Ctrl Lane "..i.." Destination"
	mmParameterInfo.onChanged = function() onModDestChanged(16 + i, _G["CtrlLane"..i.."Dest"]) end
	defineParameter(mmParameterInfo)
end

function verifyParam(name, callback)
	if last[name] ~= _G[name] then
		callback()
	end
end


--**ATTEMPT TO LINK TWO DESTINATIONS #1**

--[[
function onLinkModDestChanged(row, modDestinationParam)
  local modDestination = modDestinations[modDestinationParam]
  local zone1Synth=this.parent:getLayer():getZone()
	zone1Synth:getModulationMatrixRow(11):getParameter("Destination.Destination", modDestination.index)
  zone1Synth:getModulationMatrixRow(25):getParameter("Destination.Destination", modDestination.index)
end

defineParameter("LinkModDestination", "LinkModDestination", onLinkModDestChanged)
]]--

--**ATTEMPT TO LINK TWO DESTINATIONS #2**

--[[
function onLinkModDestChanged(row, modDestinationParam)
	local modDestination = modDestinations[modDestinationParam]
	local zones = this.parent:getLayer():findZones()
	for i, zone in pairs(zones) do
		zone:getModulationMatrixRow(11):setParameter("Destination.Destination", modDestination.index)
    zone:getModulationMatrixRow(25):setParameter("Destination.Destination", modDestination.index)
	end
end

defineParameter("LinkModDestination", "LinkModDestination", onLinkModDestChanged)
]]--

--**ATEMPT TO LINK TWO DESTINATIONS #3**

--[[
function onLinkModDestChanged()
  getModDestNames()
  function onModDestChanged(11)
  function onModDestChanged(25)
  mmParameterInfo.strings = modDestNames
end 

defineParameter("LinkModDestination", "LinkModDestination", onLinkModDestChanged)
]]--

Any ideas?

Thanks in advance!

A few errors to take care of first :

Your ‘Pan’ entry in the modDestinations table is missing a comma at the end.
The mmParameterInfo table needs to be declared before the strings can be added.

mmParameterInfo = {}
mmParameterInfo.strings = modDestNames

Working on attempt #1 :

The function doesn’t need the parameters, seeing as it is called by only one parameter and the modRows are hard coded. The defined parameter’s callback also doesn’t make use of the parameters anyway.
While setting the destinations, getParameter needs to be setParameter.

The parameter was defined incorrectly. It had a long and short name and callback function, but no properties. Menus make use of string lists, so an default index number is needed and also an array containing the menu entry names.

Old Version

function onLinkModDestChanged(row, modDestinationParam)
  local modDestination = modDestinations[modDestinationParam]
  local zone1Synth=this.parent:getLayer():getZone()
	zone1Synth:getModulationMatrixRow(11):getParameter("Destination.Destination", modDestination.index)
  zone1Synth:getModulationMatrixRow(25):getParameter("Destination.Destination", modDestination.index)
end

defineParameter("LinkModDestination", "LinkModDestination", onLinkModDestChanged)

New version

function onLinkModDestChanged()
  local modDestination = modDestinations[LinkModDestination]
  local zone1Synth = this.parent:getLayer():getZone()
	zone1Synth:getModulationMatrixRow(11):setParameter("Destination.Destination", modDestination.index)
  	zone1Synth:getModulationMatrixRow(25):setParameter("Destination.Destination", modDestination.index)
end

defineParameter("LinkModDestination", "LinkModDestination", 1, modDestNames, onLinkModDestChanged)

This works perfectly! Thanks so much for the help and the detailed explanation of what to fix. All the trial and error and help from this forum really helps my progress in understanding this stuff.

Thanks again!