Skip to content

Instantly share code, notes, and snippets.

@ryrun
Created September 10, 2022 18:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryrun/a1a32484b02c90b777baf47c1105584c to your computer and use it in GitHub Desktop.
Save ryrun/a1a32484b02c90b777baf47c1105584c to your computer and use it in GitHub Desktop.
VST Protoplug midi plugin - Simple Arp with CH2 note exclusive
require "include/protoplug"
speed = 0.25
notelength = 0.2
notes = {0,7,12}
buffer = {}
buffer2 = {}
time = 0
lasttime = 0
lastnote = -1
blockarp = false
function plugin.processBlock(samples, smax, midiBuf)
pos = plugin.getCurrentPosition ()
rate = plugin.getSampleRate()
noteduration = (( rate * 1 * 60 ) / pos.bpm) * speed
for ev in midiBuf:eachEvent() do
if ev:isNoteOn() and ev:getChannel()==1 then
if lastnote ~= -1 then
table.insert(buffer2,{lastnote,0})
lastnote = -1
end
time = 0
lasttime = -1
offset = 0
buffer = {}
for i=1, #notes do
table.insert(buffer,{0+offset,ev:getNote()+notes[i],127})
table.insert(buffer,{(noteduration*notelength)+offset,ev:getNote()+notes[i],0})
offset = offset + noteduration
end
elseif ev:isNoteOff() and ev:getChannel()==1 then
if lastnote ~= -1 then
table.insert(buffer2,{lastnote,0})
lastnote = -1
end
buffer = {}
elseif ev:isNoteOn() and ev:getChannel()==2 then
table.insert(buffer2,{ev:getNote(),127})
if lastnote ~= -1 then
table.insert(buffer2,{lastnote,0})
lastnote = -1
end
blockarp = true
elseif ev:isNoteOff() and ev:getChannel()==2 then
table.insert(buffer2,{ev:getNote(),0})
blockarp = false
end
end
midiBuf:clear()
if #buffer2 then
for k,n in ipairs(buffer2) do
ev = midi.Event.noteOn(1, n[1], n[2])
midiBuf:addEvent(ev)
table.remove(buffer2,k)
end
end
if #buffer and not blockarp then
for k,n in ipairs(buffer) do
if n[1]<time + smax and n[1]>=lasttime then
offset = math.ceil(math.max (0, math.min ((noteduration - time), smax - 1)))
ev = midi.Event.noteOn(1, n[2], n[3])
ev.time = offset --not sure if this will fix timing issues
if n[3]>0 then
lastnote = n[2]
else
lastnote = -1
end
midiBuf:addEvent(ev)
end
end
end
time = (time + smax) % (#notes * noteduration)
if lasttime>time then
lasttime = -1
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment