portamento.lua
--------------------------------------------------------------------------------
--! @example portamento.lua
--------------------------------------------------------------------------------
local numNotes = 0
local lastid = -1
local lastnote = 0
Fade = Knob("fade", 100, 1, 500)
function glide(id, from, to, duration, period)
duration = duration or 100 -- 100 ms
period = period or 10 -- 5 ms
local doglide = function()
local value = from
local increment = (to - from) * period / duration
local t = 0
local immediate = true
while t < duration do
changeTune(id, value, false, immediate)
immediate = false
wait(period)
value = value + increment
t = t + period
end
changeTune(id, to)
end
_spawn(doglide)
end
function onNote(e)
if numNotes > 0 then
local fadetime = Fade.value
fadeout(lastid, fadetime, true)
glide(lastid, 0, (e.note-lastnote), fadetime)
lastid = playNote(e.note, e.velocity)
--setSampleOffset(lastid, 0.1)
fadein(lastid, fadetime, true)
glide(lastid, (lastnote-e.note), 0, fadetime)
lastnote = e.note
else
lastid = playNote(e.note, e.velocity)
lastnote = e.note
end
numNotes = numNotes + 1
end
function onRelease(e)
numNotes = math.max(0, numNotes - 1)
end