Created
October 17, 2020 17:22
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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