Did a quick bit of hacking on your question today.
I think the thing to keep in mind is that midi clock just happens all the time (when it’s being sent). It’s a constant stream of messages. Start/Stop/Continue messages are separate and need to be sent independently of clock messages.
So I think what would really be needed is some key assigned to the midi start/stop messages.
As an example I tried this:
at line 56 add
local midi_start_state = false
then at line 666 add
elseif x==16 and y==8 then
if midi_start_state == false then
midi_device:start()
midi_start_state = true
else
midi_device:stop()
midi_start_state = false
end
This will define grid key 16/8 as midi start/stop.
This starts/stops my TR-9 drum machine as expected. If sync is turned on in params, then it also tracks tempo.
(next step would be to make that key light up, but I’ll leave that for another time)