Sources Matrix Menus With Modulation Module (LFO)

Hello,
I am trying to have a very easy and limited menus with only matrix source destinations.
I have some problem only to callback the Modulation Module (LFO), other sources are ok.

I attach the preset.
I hope in your help…
Thanks

-- MATRIX SOURCES


function assignLFO3(row, source, polarity, smoothing)
  local LFO3 = this.parent:getMidiModule("LFO3")

  if LFO3 then
    setSource(row, source, polarity, smoothing, ModulationSource.modulationModule, LFO3)
  else
    setSource(row, source, polarity, smoothing, ModulationSource.unassigned)
  end
end


matrixSources={
  {name="Off",   index=0},
  {name="LFO 1",   index=1},
  {name="LFO 2",   index=2},
  {name="LFO 3",   assignLFO3},
  {name="Env 3",   index=6},
}

function getMatrixSourceNames()
  matrixSourceNames={}
  for i=1,#matrixSources do
    matrixSourceNames[i]=matrixSources[i].name
  end
end

getMatrixSourceNames()

last = {}


function matrixSourceChanged()
  this:setParameter("M2OSCSource", MatrixSource)
  this:setParameter("M2OSCSource", MatrixSource)
  this:setParameter("M3OSCSource", MatrixSource)
  this:setParameter("M4OSCSource", MatrixSource)
  this:setParameter("M1WaveSource", MatrixSource)
  this:setParameter("M2WaveSource", MatrixSource)
  this:setParameter("M3WaveSource", MatrixSource)
  this:setParameter("M4WaveSource", MatrixSource)
end

defineParameter("MatrixSource",nil,1,matrixSourceNames,matrixSourceChanged)


function M1OSCSourceChanged()
  this.parent:getLayer("Generators"):getZone("OSC Zone"):getModulationMatrixRow(1):setParameter("Source1.Source",matrixSources[M1OSCSource].index)
end

defineParameter("M1OSCSource",nil,1,matrixSourceNames,M1OSCSourceChanged)


function M2OSCSourceChanged()
  this.parent:getLayer("Generators"):getZone("OSC Zone"):getModulationMatrixRow(2):setParameter("Source1.Source",matrixSources[M2OSCSource].index)
end

defineParameter("M2OSCSource",nil,1,matrixSourceNames,M3OSCSourceChanged)

function M3OSCSourceChanged()
  this.parent:getLayer("Generators"):getZone("OSC Zone"):getModulationMatrixRow(3):setParameter("Source1.Source",matrixSources[M3OSCSource].index)
end

defineParameter("M3OSCSource",nil,1,matrixSourceNames,M3OSCSourceChanged)

function M4OSCSourceChanged()
  this.parent:getLayer("Generators"):getZone("OSC Zone"):getModulationMatrixRow(4):setParameter("Source1.Source",matrixSources[M4OSCSource].index)
end

defineParameter("M4OSCSource",nil,1,matrixSourceNames,M4OSCSourceChanged)

function M1WaveSourceChanged()
  this.parent:getLayer("Generators"):getZone("OSC Zone"):getModulationMatrixRow(5):setParameter("Source1.Source",matrixSources[M1WaveSource].index)
end

defineParameter("M1WaveSource",nil,1,matrixSourceNames,M1WaveSourceChanged)

function M2WaveSourceChanged()
  this.parent:getLayer("Generators"):getZone("OSC Zone"):getModulationMatrixRow(6):setParameter("Source1.Source",matrixSources[M2WaveSource].index)
end

defineParameter("M2WaveSource",nil,1,matrixSourceNames,M2WaveSourceChanged)

function M3WaveSourceChanged()
  this.parent:getLayer("Generators"):getZone("OSC Zone"):getModulationMatrixRow(7):setParameter("Source1.Source",matrixSources[M3WaveSource].index)
end

defineParameter("M3WaveSource",nil,1,matrixSourceNames,M3WaveSourceChanged)

function M4WaveSourceChanged()
  this.parent:getLayer("Generators"):getZone("OSC Zone"):getModulationMatrixRow(8):setParameter("Source1.Source",matrixSources[M4WaveSource].index)
end

defineParameter("M4WaveSource",nil,1,matrixSourceNames,M4WaveSourceChanged)

Test Matrix Source.vstpreset.zip (11.8 KB)

AUTO SOLUTION :smiley:

After a day, I managed to come up with this script that works well.
It allows to have a customized sources menu, with a modulation module LFO and 2 different Synth and wavetable zone sources.

Hope it can be helpful for someone :slight_smile:

-- functions for assigning the modulation sources

function setSource(row, source, sourceIndex, sourceExtra1, sourceExtra2)

		row:setSource1(sourceIndex, sourceExtra1, sourceExtra2)

end

function assignStandardSource(row, source, sourceIndex)
	setSource(row, source, sourceIndex)
end

function assignLfo3(row, source)
	local lfo3 = this.parent:getMidiModule("LFO3")
	if lfo3 then
		setSource(row, source, ModulationSource.modulationModule, lfo3)
	else
		setSource(row, source, ModulationSource.unassigned)
	end
end


-- define modulation sources
defineSlotLocal("modSources")
modSources = {
				{ name = "-", 					assignFunc = assignStandardSource, index = ModulationSource.unassigned},
				{ name = "LFO 1", 		        assignFunc = assignStandardSource, index = ModulationSource.lfo1},
				{ name = "LFO 2", 	            assignFunc = assignStandardSource, index = ModulationSource.lfo2},
				{ name = "LFO 3", 				assignFunc = assignLfo3},
			    { name = "Env3", 				assignFunc = assignStandardSource, index = ModulationSource.userEnv},
			 }


-- create table with mod source names

function getModSrcNames()
	modSrcNames = {}
	for i=1, #modSources do
		modSrcNames[i] = modSources[i].name
	end
end

getModSrcNames()

-- parameter change callback to set the modulation source OSC

function onModSourceOSCChanged(row, source, modSourceParam)

	local modRow = this.parent:getLayer("Generators"):getZone("OSC Zone"):getModulationMatrixRow(row)
	local modSource = modSources[modSourceParam]

	modSource.assignFunc(modRow, source, modSource.index)

end

-- parameter change callback to set the modulation source Wave

function onModSourceWaveChanged(row, source, modSourceParam)

	local modRow = this.parent:getLayer("Generators"):getZone("Wavetable Zone"):getModulationMatrixRow(row)
	local modSource = modSources[modSourceParam]

	modSource.assignFunc(modRow, source, modSource.index)

end


defineSlotLocal("mmParameterInfo")
mmParameterInfo =
{
	default = 1,
	automatable = false,
	strings = modSrcNames
}

-- define parameters for modulation matrix rows MOD SOURCE OSC
for i = 1, 4 do
	mmParameterInfo.name = "ModSourceOSC"..i
	mmParameterInfo.longName = "Modulation Source "..i
	mmParameterInfo.onChanged = function() onModSourceOSCChanged(i, 1, _G["ModSourceOSC"..i]) end
	defineParameter(mmParameterInfo)

end

-- define parameters for modulation matrix rows MOD SOURCE Wave
for i = 1, 4 do
	mmParameterInfo.name = "ModSourceWave"..i
	mmParameterInfo.longName = "Modulation Source "..i
	mmParameterInfo.onChanged = function() onModSourceWaveChanged(i, 1, _G["ModSourceWave"..i]) end
	defineParameter(mmParameterInfo)

end