Last active
March 2, 2020 14:17
-
-
Save normen/959d09cdd0e1d6586ad8aff9a21ce8af to your computer and use it in GitHub Desktop.
Separate Notes to Channels MIDI Machine
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
channels = {} -- save pitch per channel# | |
channelNo = {} -- save channel# per pitch | |
function GetFreeChannel() | |
for i = 1, 16 do if channels[i] == nil then return i end end | |
Print("Error: ran out of channels") | |
return 1 | |
end | |
function OnNote(channel, pitch, velocity) | |
if velocity > 0 then | |
if channelNo[pitch] == nil then -- note-on with new note, assign channel | |
channelNo[pitch] = GetFreeChannel() | |
channels[channelNo[pitch]] = pitch | |
Note(channelNo[pitch], pitch, velocity) | |
else | |
Note(channelNo[pitch], pitch, velocity) | |
end | |
else -- note-off, remove note from channels | |
Note(channelNo[pitch], pitch, velocity) | |
channels[channelNo[pitch]] = nil | |
channelNo[pitch] = nil | |
end | |
end | |
function OnBend(channel, pitch, velocity) | |
if channelNo[pitch] == nil then | |
Print("Error: bend for nonexisting note") | |
Bend(channel, pitch, velocity) | |
else | |
Bend(channelNo[pitch], pitch, velocity) | |
end | |
end | |
function OnAfterTouch(channel, pitch, velocity) | |
if channelNo[pitch] == nil then | |
Print("Error: bend for nonexisting note") | |
AfterTouch(channel, pitch, velocity) | |
else | |
AfterTouch(channelNo[pitch], pitch, velocity) | |
end | |
end | |
function OnStart(info) | |
info.description = | |
"Route simultaneous notes to multiple MIDI channels to preserve pitch bend info." | |
info.link = "http://jamorigin.com/midi-machine" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment