Skip to content

Instantly share code, notes, and snippets.

@ryrun
Created October 17, 2020 17:22
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/3d86d66cb9bba329822addff52f5f173 to your computer and use it in GitHub Desktop.
Save ryrun/3d86d66cb9bba329822addff52f5f173 to your computer and use it in GitHub Desktop.
protplug midi script: "note tie", delay note offs till next note on event
require "include/protoplug"
lastoff = 0
function plugin.processBlock(samples, smax, midiBuf)
playEvents = {}
for ev in midiBuf:eachEvent() do
if ev:isNoteOn() and ev:getNote() ~= lastoff and lastoff>0 then
table.insert(playEvents, midi.Event(ev))
table.insert(playEvents, midi.Event.noteOff(
1,
lastoff))
if ev:getVel() == 1 then
lastoff = tonumber(ev:getNote())
else
lastoff = 0
end
elseif ev:isNoteOn() and ev:getVel() == 1 then
lastoff = tonumber(ev:getNote())
table.insert(playEvents, midi.Event(ev))
elseif ev:isNoteOff() and ev:getNote() == lastoff then
else
table.insert(playEvents, midi.Event(ev))
end
end
midiBuf:clear()
for _,ev in ipairs(playEvents) do
if ev:isNoteOn() then
ev:setVel(127)
end
midiBuf:addEvent(ev)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment