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