Ensemble.lua

Ensemble script trigger multiple voices

--------------------------------------------------------------------------------
--! @example Ensemble.lua
--! Ensemble script
--! trigger multiple voices
--------------------------------------------------------------------------------
PanSpread = Knob("PanSpread", 1.0, 0, 1)
TimeSpread = Knob("TimeSpread", 0.5, 0, 1)
shifts = {0, 1, -1, 2, -2}
--shifts = {0, 1, -1, 2, -2, 3, -3}
--shifts = {0, 1, -1, 2, -2, 3, -3, 4, -4}
function onNote(e)
local panSpread = PanSpread.value
local timeSpread = TimeSpread.value
local numShifts = #shifts
for i=1,numShifts do
local shift = shifts[i]
local note = e.note + shift
local id = playNote(note, e.velocity)
local tune = -shift
changeTune(id, tune) -- repitch the note
changeVolume(id, 1/math.sqrt(numShifts))
changePan(id, panSpread * shifts[i] / 2)
wait(timeSpread*10) -- 10 ms jitter
end
end
function onRelease()
-- eat event release is automatic in playNote
end