I’m wondering if it is possible to use Lua to trigger MIDI and/or UI events programmatically with the grid? For example, I could press a button which causes an LED to light in a different location and playback a series of midi messages that are stored in a Lua variable?
I’m guessing this is outside of the scope of the Lua environment, but it would be pretty cool and would open up a lot of possibilities if so.
@narayb did you ever create a demo for this? I’m really interested in the idea of recording various controller changes which I make and then playing them back in a loop and i’d love to see a simple example of this to get started with.
I’ve been working with your example (thank you again!) and I think I mostly understand it, but there’s one place I’d really appreciate a little bit of extra explanation.
In the system block you have a function
self.midirx_cb = function(self, midi_ev, grid_headers)
table.insert(midirx_list, midi_ev)
limit(midirx_list, 4)
end
then in the timer you are copying the last element from the midirx_list into the buffer, so that we can later read from that buffer for playback.
What I don’t really understand is when midirx_cb is called, and what midi_ev contains, I don’t see any place where this function is called or any reference to it, or the values it takes in the wiki.
Also what does the limit function do? it seems like it keeps the midi input recording list at 4 elements max. But when we are inserting that data into the buffer are we not just taking the most recent value? table.insert(buffer, midirx_list[#midirx_list]), so couldn’t we just keep the single most recent value in memory? or am I getting confused about what the # operator does in lua? (sorry my lua is a bit rusty!)
and could you give me some hints about how to rewrite this to target only recording a specific control rather than everything?
What essentially happens is that there is a not documented micro-instrumentation hook for grabbing all MIDI events that happen across your Grid setup.
The limit() function makes the buffer of midirx_list{} a FIFO one by setting the limit of the buffer with the second parameter. You can make a different buffer if you’d like.
If you want to limit the buffer to only look for specific CCs and similar, just insert an if branch around the table.insert function.