Only show user-presets in favorite sidebar
[ardour.git] / scripts / _midifilter.lua
1 ardour {
2         ["type"]    = "dsp",
3         name        = "Midi Filter",
4         category    = "Example", -- "Utility"
5         license     = "MIT",
6         author      = "Ardour Lua Task Force",
7         description = [[An Example Midi Filter for prototyping.]]
8 }
9
10 function dsp_ioconfig ()
11         return { { midi_in = 1, midi_out = 1, audio_in = 0, audio_out = 0}, }
12 end
13
14 function dsp_run (_, _, n_samples)
15         assert (type(midiin) == "table")
16         assert (type(midiout) == "table")
17         local cnt = 1;
18
19         function tx_midi (time, data)
20                 midiout[cnt] = {}
21                 midiout[cnt]["time"] = time;
22                 midiout[cnt]["data"] = data;
23                 cnt = cnt + 1;
24         end
25
26         -- for each incoming midi event
27         for _,b in pairs (midiin) do
28                 local t = b["time"] -- t = [ 1 .. n_samples ]
29                 local d = b["data"] -- get midi-event
30                 local event_type
31                 if #d == 0 then event_type = -1 else event_type = d[1] >> 4 end
32
33                 if (#d == 3 and event_type == 9) then -- note on
34                         tx_midi (t, d)
35                 elseif (#d == 3 and event_type == 8) then -- note off
36                         tx_midi (t, d)
37                 end
38         end
39 end