Combining two user defined parameters with different functions

Post topics about HALion scripting.
Post Reply
rmjmusic
Junior Member
Posts: 51
Joined: Thu Jan 04, 2018 3:22 am
Contact:

Combining two user defined parameters with different functions

Post by rmjmusic »

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):

Code: Select all

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):

Code: Select all

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!
Cubase Pro 10.5
Cubase Pro 10
HALioin 6
Windows 10 Pro 64bit
Mac OS 10.13.6

misohoza
Member
Posts: 955
Joined: Sun Oct 05, 2014 12:18 am
Contact:

Re: Combining two user defined parameters with different functions

Post by misohoza »

You need to change the selectedPreset parameter when loading sample.

You could also use undo block if you want to rename the entry in edit history.

Code: Select all

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)
    startUndoBlock("Load Sample "..name)
    selectedPreset = name
    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,"")
Win 10 Home, 64 bit, 8 gb ram,
Cubase Pro 10.5, Wavelab Pro 9.5, Halion 6, Dorico 3,
NI Komplete 10 Ultimate, Ozone 7,
UR 44

rmjmusic
Junior Member
Posts: 51
Joined: Thu Jan 04, 2018 3:22 am
Contact:

Re: Combining two user defined parameters with different functions

Post by rmjmusic »

I knew it had to be something pretty simple. You're a genius! It works perfectly. This is exactly what I was looking for.

Thanks!
Cubase Pro 10.5
Cubase Pro 10
HALioin 6
Windows 10 Pro 64bit
Mac OS 10.13.6

Post Reply

Return to “Halion Scripting”

Who is online

Users browsing this forum: No registered users and 1 guest