@okyeron
midi is fairly straightforward…
midi.add = function (dev) … blah
is defining a function you wish to be called when a midi devices is added (or reconnected to a script)
in this particular case, all that is happening is its setting the ‘event callback function’ on the midi device (dev.event = )
so dev.event is a function that is called for each midi event.
(if you look in norns/lua/midi , you can see this happening)
so in playfair what is happening is…
when we get a new midi device (added/reconnected) it is telling it to call used beatclocks.process_midi as the event callback , which in turn will process the midi (which might be a midi clock tick)
i read this as , how do you get your script to be able to process midi
simple… define your own event callback handler
so to give you the idea you want (untested/compiled
) its something like
my_midi_hander = function(data)
-- do your midi handling here
-- then call the beat clock to update the beat clock
clk.process_midi(data)
end
midi.add = function(dev)
dev.event = my_midi_hander
end
so what this does it… you define midi.add, so you can add your own handler
then in your handler you then call the process_miidi of clk as well
again, this is a bit like the last study, it comes down to being able to define function pointers/callbacks. (sorry dont know what lua calls them
)
Ive not had a close look, but given tick() is being called by both the midi handler and the internal metro,
Id assume the internal metro is being set at 24ppqn (just like [midi clock]) (https://en.wikipedia.org/wiki/MIDI_beat_clock) , so this is why the ‘ticks per steps’ is defaulted to 6, (6*4 = 24)
anyway, hopefully this will give you a few pointers till is all explained better 
(fwiw , I suspect many are going to struggle with extensive use of callback functions… they are not the easiest of things to trace through if your not familiar with them)