Last active
April 10, 2023 21:40
-
-
Save ryrun/42e755650de907a33acb6784141b5955 to your computer and use it in GitHub Desktop.
Protoplug LUA midi plugin - play midi channel 2 exclusive, note off other notes during playing (perfect arp melody maker)
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" | |
local buffer = {} | |
local channelOneActive = false | |
function mydebug(ev, skipped) | |
local onoff = "On" | |
local skip = "skipped" | |
if not skipped then | |
skip = "" | |
end | |
if ev:isNoteOff() then | |
onoff = "Off" | |
end | |
if ev:getChannel()==1 then | |
--print("Note " .. onoff .. " " .. ev:getNote() .. ";" .. ev.time .. ";" .. skip) | |
elseif ev:getChannel()==2 then | |
--print(" ;Note " .. onoff .. " " .. ev:getNote() .. ";" .. ev.time .. ";" .. skip) | |
end | |
end | |
function plugin.processBlock(samples, smax, midiBuf) | |
for ev in midiBuf:eachEvent() do | |
if ev:isNoteOn() or ev:isNoteOff() then | |
table.insert(buffer, ev) | |
end | |
end | |
midiBuf:clear() | |
for k,n in ipairs(buffer) do | |
if buffer[k]:getChannel()==1 then | |
if buffer[k]:isNoteOn() then | |
channelOneActive = true | |
elseif buffer[k]:isNoteOff() then | |
channelOneActive = false | |
end | |
end | |
local skipped = true | |
if not channelOneActive or buffer[k]:getChannel()==1 then | |
skipped = false | |
mydebug(buffer[k],skipped) | |
if buffer[k]:isNoteOn() then | |
midiBuf:addEvent(midi.Event.noteOn(1,buffer[k]:getNote(),buffer[k]:getVel())) | |
end | |
if buffer[k]:isNoteOff() then | |
midiBuf:addEvent(midi.Event.noteOff(1,buffer[k]:getNote())) | |
end | |
else | |
mydebug(buffer[k],skipped) | |
end | |
end | |
buffer = {} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment