Video-Frame (not sample)
[ardour.git] / scripts / _midi_rewrite.lua
1 ardour {
2         ["type"]    = "session",
3         name        = "Rewrite Midi",
4         license     = "MIT",
5         author      = "Ardour Lua Task Force",
6         description = [[An example session script preprocesses midi buffers.]]
7 }
8
9 function factory ()
10         -- this function is called in every process cycle, before processing
11         return function (n_samples)
12                 _, t = Session:engine ():get_ports (ARDOUR.DataType.midi (), ARDOUR.PortList ())
13                 for p in t[2]:iter () do
14                         if not p:receives_input () then goto next end
15
16                         if not p:name () == "MIDI/midi_in 1" then goto next end
17
18                         midiport = p:to_midiport ()
19                         assert (not midiport:isnil ())
20                         mb = midiport:get_midi_buffer (n_samples);
21
22                         events = mb:table() -- copy event list into lua table
23                         mb:silence (n_samples, 0); -- clear existing buffer
24
25                         for _,e in pairs (events) do
26                                 -- e is-a http://manual.ardour.org/lua-scripting/class_reference/#Evoral:MidiEvent
27                                 e:set_channel (2)
28                                 mb:push_event (e)
29                         end
30
31                         ::next::
32                 end
33         end
34 end