Use generic sorter.
[ardour.git] / scripts / midifilter.lua
1 ardour {
2         ["type"]    = "dsp",
3         name        = "Midi Filter",
4         category    = "Utility",
5         license     = "MIT",
6         author      = "Robin Gareus",
7         email       = "robin@gareus.org",
8         site        = "http://gareus.org",
9         description = [[An Example Midi Filter for prototyping.]]
10 }
11
12 function dsp_ioconfig ()
13         return { { audio_in = 0, audio_out = 0}, }
14 end
15
16 function dsp_has_midi_input () return true end
17 function dsp_has_midi_output () return true end
18
19 function dsp_run (_, _, n_samples)
20         assert (type(midiin) == "table")
21         assert (type(midiout) == "table")
22         local cnt = 1;
23
24         function tx_midi (time, data)
25                 midiout[cnt] = {}
26                 midiout[cnt]["time"] = time;
27                 midiout[cnt]["data"] = data;
28                 cnt = cnt + 1;
29         end
30
31         -- for each incoming midi event
32         for _,b in pairs (midiin) do
33                 local t = b["time"] -- t = [ 1 .. n_samples ]
34                 local d = b["data"] -- get midi-event
35
36                 if (#d == 3 and bit32.band (d[1], 240) == 144) then -- note on
37                         tx_midi (t, d)
38                 end
39                 if (#d == 3 and bit32.band (d[1], 240) == 128) then -- note off
40                         tx_midi (t, d)
41                 end
42         end
43 end