Getting values and structure from MIDI keyboard

I'd like to use Tidal like a software synthesizer for a MIDI controller as far as possible, so I would ideally not only have notes and velocities taken from the MIDI input, but also the pattern structure, in real time.

The farthest I got is like this:

d1 $ (stack $ map (\ pitch
                     (gain $ (2 * (cF 0.0 $ show pitch)))
                       |> (n $ fromInteger (pitch - 48)))
            $ [36..84])
   # s "superpiano"

(the range [36..84] and the pitch adjustment - 48 might vary depending on the MIDI controller)

I can play single notes and chords and also have the velocities reflected, but the events are always significantly delayed from when they were triggered from the controller, and I don't seem to have full control over when the notes are played.

I also tried this approach (also capable of reflecting chords in Tidal), but it seems to have the same problems regarding structure.

Is there are better way to get the structure from what is played on the MIDI controller?

And/or maybe some settings that can reduce the delay between MIDI signal and notes played from Tidal?

not easy what you're trying to do! it's been discussed many times

are you trying to do something like Using Tidal as a MIDI Instrument ?

or is it more like an MPC loop thing where you'd play a rhythm and then tidal would play that back as structure ?

the idea that comes to mind is you'll need to use some haskell midi library and program something such that when you press a key it sends a once type message to SuperDirt