-------------------------------------------------
-- Arpegiator
-------------------------------------------------
resolutions = {0.5, 0.25, 0.125}
resolutionNames = {"8th","16th","32th"}
heldNotes = {};
velocity = 0;
res = Menu{"resolution", resolutionNames, selected=2}
duty = Knob("duty", 1, 0, 1)
numOctaves = Knob("numOctaves", 1, 1, 4, true)
-- repeat each held note at a fixed rate
function arpeg()
local i=1;
local octave=0
while #heldNotes > 0 do
if i > #heldNotes then
i = 1 + (i-1) % (#heldNotes);
octave = (octave+1) % numOctaves.value;
end
local note = (heldNotes[i])
note = note + (octave)*12
local p = resolutions[res.value]
playNote(note, velocity, beat2ms(duty.value*p));
waitBeat(p);
i = i+1;
end
end
function onNote(e)
velocity = e.velocity;
local first = nil
if #heldNotes == 0 then first = true end
table.insert(heldNotes, e.note);
if first then
arpeg()
end
end
function onRelease(e)
for i,v in ipairs(heldNotes) do
if v == e.note then
table.remove(heldNotes, i)
break
end
end
end