Use of Drop Down menues

Hi guys,
I’m really scratching my head over here, trying to use drop down menues from LUA, but somehow they never seem to display the information I want them to. I’ve seen them work fine when directly connected to MacroPage parameters like filter types etc, but what about access from a script?

So as an example, let’s say I want to create a drop down box that allows the user to select which audio-output they want to use.
So I got a list of outputs via this.program.instance:findBusses() - great!
I also have defined a parameter gOutputs. But I don’t seem to be able to figure out how to make that list of outputs stored in gOutputs become selectable options in a menue-template on my UI.
The only thing I seem to be able to do is to drag gOutputs onto the “Value” field of my menue, which results in a long list of integers when clicking on the menue. Obviously what I’d like to see are the individual strings with the names of the outpus neatly listed as options.
I’ve tried defining gOutputs as different types - tables, string lists, you name it. None of it gives me the desired result. Maybe somebody could give me a clue, the documentation most certainly doesn’t, but I can’t imagine that I’m the only one trying to do this…

Hi guys,
I’m really scratching my head over here, trying to use drop down menues from LUA, but somehow they never seem to display the information I want them to. I’ve seen them work fine when directly connected to MacroPage parameters like filter types etc, but what about access from a script?

For the drop down menu you need to create an indexed string array. While the parameter value is displayed as string the actual value used to set the parameter is integer number (index of currently selected element of the string array).

With your output bus example something like this could work:

busses = this.program.instance:findBusses()

function getBusNames()
  busNames = {}
  busNames[0] = "--"  --this will be nil: use default routing
  for i, bus in ipairs(busses) do
    busNames[i] = bus.name
  end
end

getBusNames()

defineParameter("Output", nil, 0, busNames, function() outputChange() end)

function outputChange()
  local zones = this.parent:findZones(true)
  for i, zone in ipairs(zones) do
    zone:setOutputBus(busses[Output])
  end
end

Or if you want to change the output for busses instead of zones:

outputBusses = this.program.instance:findBusses()
busses = this.parent:findBusses(true)

table.remove(busses, 1) --remove Program Bus object from 'busses' assuming the script module is at program level and Program Bus is the first object returned by findBusses()

function getOutputBusNames()
  outputBusNames = {}
  outputBusNames[0] = "--"
  for i, bus in ipairs(outputBusses) do
    outputBusNames[i] = bus.name
  end
end

getOutputBusNames()

for i, bus in ipairs(busses) do
  print("Parameter Output"..i.." created for bus: "..bus.name)
  defineParameter("Output"..i, nil, 0, outputBusNames, function() outputChange(i) end)
end

function outputChange(i)
  local bus = busses[i]
  local par = _G["Output"..i]
  bus:setOutputBus(outputBusses[par])
end

Thank you very much, this helped quite a bit! I had done something similar, but clearly it didn’t work, so now it’s a matter to compare and figure out what’s the difference.

It’s strange though - when I first ran the code and connected one of the “Output” parameters it creates to the menue template that I had sitting there it was still showing me the numbers. I then deleted the menue and brought in a new one - then it worked. Are there different types of menue items that respond in different ways? From the namings it seems like the differences should be purely visual (flat, embedded etc) but I’m not so sure now…