Disable or hide an element if more parameters are set to a specific value

Hello everyone.
Using the “Disable” element (or template), I am trying to hide a section of knobs on my macro page.
However, I need to group more parameters…
I am confident to get values ​​using “getParameter” function, but I have no idea how to develop the script to set the IF variable and get a unique feedback value to link it to the “Disable” template. The values ​​I would like to obtain could be for example the source 1 of matrix rows 1 + the source 1 of matrix row 2 and obtain a final value 0 (or another defined number) only if both parameter are set to 0.
Thank you very much for your help!

You need a parameter that will be connected to the disable control.

Then it depends whether it’s script parameters or Halion engine parameters you want to group. The script doesn’t keep checking the parameters all the time. So you need something to tell it when to check those parameters. With script parameters it’s easier. Just add a few more lines in their callback. If one of them changes, check the others and set the disable parameter accordingly.

If it’s not script parameters you want to group in this way then it’s probably easier in ui script. Create parameters of the same type in ui script. Connect them to Halion engine parameters. Now you will know when the engine parameters change. The rest is same as above. Check the values of other parameters and set the disable parameter.

Thanks as usual Misohoza!
I think I have not understood very well… :frowning:
I try to explain easily exactly what I would like to do in practice:

I want to disable or hide a knob if source 1 of matrix rows 1 and 2 (both) are set to 0 (or none value). If instead for example source 1 of row 1 is set on 0 and source 1 of row 2 is set on 1 (LFO 1) the disabling must not take place.

Ok, I’ll attach some examples of what I meant.

Both scripts do the same thing. You need to load them as ui script. Connect the created mod source parameters to zone parameters. If you want to check a lot of rows then the first one using the loop is probably better. Just adjust the numberORows variable. If it’s really just 2 rows then you can use either of them.

local zone = getElement():findZones(true)[1]
local source1def = zone:getModulationMatrixRow(1):getParameterDefinition("Source1.Source")

defineParameter("disable", nil, 0, 0, 1, 1)

local numberOfRows = 2

function modSourceChanged()
  local value = 0
  for i = 1, numberOfRows do
    if _G["ModSource"..i] > 0 then
      value = 1
      break
    end
  end
  disable = value
end

for i = 1, numberOfRows do
  defineParameter("ModSource"..i, nil, source1def, modSourceChanged)
end

modSourceChanged()



local zone = getElement():findZones(true)[1]
local source1def = zone:getModulationMatrixRow(1):getParameterDefinition("Source1.Source")

defineParameter("disable", nil, 0, 0, 1, 1)

local numberOfRows = 2

function modSourceChanged()
  if ModSource1 == 0 and ModSource2 == 0 then
    disable = 0
  else
    disable = 1
  end
end

for i = 1, numberOfRows do
  defineParameter("ModSource"..i, nil, source1def, modSourceChanged)
end

modSourceChanged()

Disable.zip (6.46 KB)

1 Like

Whoow, Yes!
Thanks again, first code works perfectly… and thanks for the examples attached!

I really admire your knowledge.

Hello Misohoza,
I found a problem using those scripts… When I save a program and I reload it, the macro page load always the 1st value, changing the program proprieties.

Do you think could be a solution for that?

Many thanks

I just tried the Disable example from my previous post and it seems to load exactly as saved last time. Can you check that? Or maybe I misunderstand the problem.

It’s strange. Talking about the 2nd code. Probably after the update it’s change somethings. Before it worked but with the problem I explain: it changed the saved sound parameter. Now, it work on parameter list, but it doesn’t work in macro and doesn’t change the effective parameter (sound tab). I load the sample program… The same in gui and Lua scriptMultiple Disable.vstpreset (13.4 KB)

Try this one, it seems to work here:
Multiple Disable.vstpreset (9.4 KB)

You definitely want this script as ui script. I removed the program tree script and reconnected the menus to zone parameters.

Hello Misohoza, thanks a lot. It works now :slight_smile:
Sorry for my previous bad explanation…
I gave a little modify to the code (below), because in my macro project I have 3 OSC and if one of this is connected to one of 3 LFO, macro section need to be activated (using the disable template)…
So this script is the part 1 of 3 scripts (one per OSC).

The problem of losing the saved parameter born when I connect the connection of UI to a string script menu parameter (not direct to the parameter). So, when I load the program, the disable template automatically set the parameter on the reference value. If I disconnect the disable value of disable template, program is loaded correctly.
Do you think could be the possible connect the variable script of UI to a string list?

local zone = getElement():findZones(true)[1]
local source1def = zone:getModulationMatrixRow(1):getParameterDefinition("Source1.Source")

defineParameter("disable", nil, 0, 0, 1, 1)

local numberOfRows = 2

function modSourceChanged()
  if ModSource1 == 1 or ModSource2 == 1 then
    disable = 0
  else
    disable = 1
  end
end

for i = 1, numberOfRows do
  defineParameter("ModSource"..i, nil, source1def, modSourceChanged)
end

modSourceChanged()

Yes, that was the problem.

But I still don’t quite understand what you are trying to do. Maybe a cut down version of your preset might help.

Hi misohoza, I attach the cut down version.
If you save program assigning LFO2 source, when you load again the program, it will auto set to LFO1 source…
TEST Multiple Disable Mini Macro.vstpreset.zip (10.5 KB)

Forum no longer allows me to load directly .vstpreset from now on…:man_shrugging:

Thanks you

I couldn’t reproduce that. Seems to load ok. But now that I see what you want to do I would change the ui script a little bit.

local sourceDef = getElement():findMidiModules(true, "Lua Script")[1]:getParameterDefinition("ModSourceOSCZone1")

for i = 1, 3 do
    defineParameter("disable"..i, nil, 0, 0, 1, 1)
end

for i = 1, 4 do
    defineParameter("ModSourceOSCZone"..i, nil, sourceDef, function() checkDisable() end)
end

function checkDisable()
    local disable = {0, 0, 0}
    for i = 1, 4 do
        local source = _G["ModSourceOSCZone"..i]
        if source > 1 and source < 5 then
            disable[source - 1] = 1
        end
    end
    for i = 1, 3 do
        _G["disable"..i] = disable[i]
    end
end

But because you use script parameters to change the modulation sources you might not need ui script at all. I’ll attach 2 versions. One with ui script and one without. Try if it works for you.
TEST Multiple Disable Mini Macro 3.zip (21.4 KB)

1 Like

Thanks you very much!
Code without UI works perfectly, saving works fine too.

Instead with UI codes give me randomly load anomaly, for example, if you save SOURCE 1 with LFO2, then change value to LFO1 without save, then you load again the program it will set a wrong source.

That’s great.

Does it happen with those examples or with your real project?
I couldn’t reproduce this.

I’ve tried again many times and the problem doesn’t appear again :slight_smile:
Sorry for my further wrong report. Probably it happend because I pasted the new code to my old program… (I did this to try to understand the code better). So I discovered only yesterday that when you save a program it save both the standard parameter + script parameter (I thought only the standard), then if you connect a new script parameter it return a wrong setup of the program…
Thanks a lot misohoza!

In particular, program works perfectly when you use it, but if you reload it does not reflect the previous saved configuration. In easy words the exact problem was the “new macro page” doesn’t match with old programs— and it’s understandably normal