Bypass Layers Using Keys

Hi all,

I’ve got an instrument that contains multiple layers. I was trying to script something where I can toggle each layer’s bypass state with a key on the keyboard. The key would work like a switch. You hit press and release once and the corresponding layer goes into bypass. You do it again and the layer is enabled. Unfortunately, I’m not very experienced with the scripting side so I’m having quite a bit of difficulty. I’ve seen some posts on here trying to do something fairly similar but the code for it and my novice don’t transfer well into what I’m trying to implement.

Thanks for any help you can extend.

Hi rmjmusic,

You could try something like this:

layers = this.parent:findLayers()

defaultSwitch = 36
keys = getKeyProperties()
for i = 1, #layers do
  keys[defaultSwitch + i - 1] = {color = 10, tooltip = layers[i].name}
end

function onNote(event)
  if event.note >= defaultSwitch and event.note < #layers + defaultSwitch then
    local layer = layers[event.note - defaultSwitch + 1]
    local layerMidiMute = layer:getParameter("LayerMidiMute")
    layer:setParameter("LayerMidiMute", not layerMidiMute)
  else
    postEvent(event)
  end
end
1 Like

As per usual, you rock! This works perfectly and exactly what I needed.

Thanks, Again!