User Script Examples - II

Key Switch

Midi module preset with a simple macropage.
Key Switch Midi Module.zip (2.22 KB)

layers = this.parent:findLayers()

defineParameter("DefaultSwitch", nil, this.parent:getParameterDefinition("LowKey"), function() getLayerNames() end)

function getLayerNames()
  layerNames = {}
  keySwitches = {}
  keyColor = getKeySwitches()
  for i, layer in ipairs(layers) do
    layerNames[i] = layer.name
    keySwitches[DefaultSwitch + i - 1] = i
    keyColor[i] = {name = layer.name, keyMin = DefaultSwitch + i - 1}
  end
end

getLayerNames()

defineParameter("LayerSelect", nil, 1, layerNames)


function isKeyswitch(event)
  if keySwitches[event.note] then
    LayerSelect = keySwitches[event.note]
    return true
  else
    return false
  end
end


function onNote(event)
  if not isKeyswitch(event) then
    playNote(event.note, event.velocity, -1, layers[LayerSelect])
  end
end

1 Like