Created
May 11, 2021 07:30
-
-
Save paulfd/74a5e223e23d1fa2ee61172195a9597e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
ardour { | |
["type"] = "Session", | |
name = "Midi Keyswitch", | |
category = "MIDI Controls", | |
license = "MIT", | |
author = "Mostly Ardour devs", | |
description = [[Switch preset on key]] | |
} | |
function factory () | |
return function (n_samples) | |
-- iterate over all MIDI ports | |
_, t = Session:engine():get_ports(ARDOUR.DataType.midi (), ARDOUR.PortList()) | |
local routes = Session:get_routes():table() | |
local proc = routes[1]:nth_plugin (0) | |
if proc:isnil () then | |
print("Proc is nil") | |
return | |
else | |
-- print(proc:display_name()) | |
end | |
local plug = proc:to_insert():plugin(0) | |
for p in t[2]:iter () do | |
-- skip output ports | |
if not p:receives_input () then goto next end | |
local midiport = p:to_midiport () | |
-- and skip async event ports | |
if midiport:isnil () then goto next end | |
local mb = midiport:get_midi_buffer(n_samples) -- get the midi-data buffers | |
local events = mb:table() -- copy event list into lua table | |
for _,e in pairs (events) do -- iterate over all events in the midi-buffer | |
if (e:buffer():array()[1] & 0xf0) == 0x90 then -- note on | |
print("Note on") | |
local record = plug:preset_by_label("Test 2") | |
if plug:load_preset(record) then | |
print("Loaded") | |
else | |
print("Error") | |
end | |
end | |
end | |
::next:: | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment