I’m trying to combine two parameters that were defined in my script but I’m having issues with the execution and wondering if anyone may know what I’m missing. It is probably a really simple solution but I’m struggling with the precise syntax.
I have code that allows the me to drag and drop my own samples onto my interface to use. I also have code that allows for the switching of subpresets. The problem I’m running into is that when I drop my own samples onto the user interface the name doesn’t change in the text field to reflect the filename. It still reflects the last chosen subpreset’s name. This is because the text template on the macro page is assigned to the “selectedPreset” parameter of the script that deals with the switching of subpresets. But for it to show the filename of the user sample it needs to be assigned to the “NameInfo” parameter. How can I merge these to accomplish the same function?
Here’s the portion of the script that deals with the drag n drop (this all works):
zone=this.parent:getZone()
function onSampleChange()
local sample=AudioFile.open(SampleInfo)
intZone=this.parent:getLayer():getZone()
if sample.valid then
local name=string.sub(string.match(sample.fileName,"[^\\/]+$"),1,-5)
this:setParameter("NameInfo",name)
intZone:setParameter("SampleOsc.Filename",sample.fileName)
intZone:setParameter("SampleOsc.SampleEnd",sample.length)
local rootKey=sample.rootKey
if rootKey then
intZone:setParameter("SampleOsc.Rootkey",rootKey)
else
intZone:setParameter("SampleOsc.Rootkey",60)
end
local loops=sample.loops
if loops[1] then
intZone:setParameter("SampleOsc.SustainLoopStartA",loops[1].loopStart)
intZone:setParameter("SampleOsc.SustainLoopEndA",loops[1].loopEnd)
this:setParameter("Loop",true)
else
intZone:setParameter("SampleOsc.SustainLoopStartA",0)
intZone:setParameter("SampleOsc.SustainLoopEndA",sample.length)
this:setParameter("Loop",false)
end
end
end
defineParameter("SampleInfo",nil,"",onSampleChange)
defineParameter("NameInfo",nil,"")
This is part of the portion of the script that deals with switching sub presets (I’ve condensed this a lot to only show the sections that have the “selectedPreset” parameter):
defineParameter{name = "selectedPreset", default = "", persistent = false, automatable = false}
function onSave()
return { selectedPath = selectedPath, selectedPreset = selectedPreset }
end
function onLoad(data)
if type(data) == "table" then
-- beware of old tables still filled with other entries
if data.selectedPath then
selectedPath = data.selectedPath
end
if data.selectedPreset then
selectedPreset = data.selectedPreset
end
end
function onUndo()
-- print("onUndo: redo = ", undoInfo.redo, "update = ", undoInfo.updateDisplay)
if undoInfo.updateDisplay then
updateSampleDisplay(36)
local layer = this.parent:getLayer()
if layer then
selectedPreset = layer.name
end
end
end
I’ve tried a few different things but still haven’t gotten it to work just right. So I thought I’d present it to the forum.
Thanks for any help and suggestions!