2016-05-29 14:36:16 -04:00
|
|
|
ardour {
|
|
|
|
["type"] = "dsp",
|
|
|
|
name = "Midi Filter",
|
2016-07-12 09:21:23 -04:00
|
|
|
category = "Example", -- "Utility"
|
2016-05-29 14:36:16 -04:00
|
|
|
license = "MIT",
|
2016-07-12 09:21:23 -04:00
|
|
|
author = "Ardour Lua Task Force",
|
2016-05-29 14:36:16 -04:00
|
|
|
description = [[An Example Midi Filter for prototyping.]]
|
|
|
|
}
|
|
|
|
|
|
|
|
function dsp_ioconfig ()
|
2016-08-04 11:47:38 -04:00
|
|
|
return { { midi_in = 1, midi_out = 1, audio_in = 0, audio_out = 0}, }
|
2016-05-29 14:36:16 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
function dsp_run (_, _, n_samples)
|
|
|
|
assert (type(midiin) == "table")
|
|
|
|
assert (type(midiout) == "table")
|
|
|
|
local cnt = 1;
|
|
|
|
|
|
|
|
function tx_midi (time, data)
|
|
|
|
midiout[cnt] = {}
|
|
|
|
midiout[cnt]["time"] = time;
|
|
|
|
midiout[cnt]["data"] = data;
|
|
|
|
cnt = cnt + 1;
|
|
|
|
end
|
|
|
|
|
|
|
|
-- for each incoming midi event
|
|
|
|
for _,b in pairs (midiin) do
|
|
|
|
local t = b["time"] -- t = [ 1 .. n_samples ]
|
|
|
|
local d = b["data"] -- get midi-event
|
2017-07-14 09:16:33 -04:00
|
|
|
local event_type
|
|
|
|
if #d == 0 then event_type = -1 else event_type = d[1] >> 4 end
|
2016-05-29 14:36:16 -04:00
|
|
|
|
2017-07-14 09:16:33 -04:00
|
|
|
if (#d == 3 and event_type == 9) then -- note on
|
2016-05-29 14:36:16 -04:00
|
|
|
tx_midi (t, d)
|
2017-07-14 09:16:33 -04:00
|
|
|
elseif (#d == 3 and event_type = 8) then -- note off
|
2016-05-29 14:36:16 -04:00
|
|
|
tx_midi (t, d)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|