Skip to content

Instantly share code, notes, and snippets.

@ryrun
Last active April 17, 2021 16:49
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/0649eb5fbcef9cc21053ea5e2a1cf994 to your computer and use it in GitHub Desktop.
Save ryrun/0649eb5fbcef9cc21053ea5e2a1cf994 to your computer and use it in GitHub Desktop.
Midi script for VST protoplug for "drone" notes
require "include/protoplug"
noteOn = 0
function plugin.processBlock(samples, smax, midiBuf)
blockEvents = {}
-- drone note, 72 = C
local rootNote = 69
for ev in midiBuf:eachEvent() do
if ev:isNoteOn() and ev:getNote() ~= rootNote then
if noteOn > 0 then
local newEv = midi.Event.noteOff(
ev:getChannel(),
rootNote,
ev:getVel())
table.insert(blockEvents, newEv)
end
local newEv = midi.Event.noteOn(
ev:getChannel(),
rootNote,
ev:getVel())
table.insert(blockEvents, newEv)
noteOn = noteOn + 1
elseif ev:isNoteOff() and ev:getNote() ~= rootNote then
local newEv = midi.Event.noteOff(
ev:getChannel(),
rootNote,
ev:getVel())
if noteOn==1 then
table.insert(blockEvents, newEv)
end
noteOn = noteOn - 1
end
end
--midiBuf:clear() --uncomment for just drone note
if #blockEvents>0 then
for _,e in ipairs(blockEvents) do
midiBuf:addEvent(e)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment