A Question About External Midi Input And Timing

I’m trying to figure out why the midi data that I record from my MPD24 always seems to be out of sync, and after some testing and searching this forum, I’ve reached the following conclusions (please correct me if I’m wrong):

(1) there seems to be be a constant delay of about 17 ms on each recorded note. This probably depends on the hardware setup.
(2) this delay changes when using plugins that use PDC.
(3) the delay is also influenced by using track delays. This is especially problematic because the more you use track delays to compensate for input latency, the worse the problem becomes (and the delay is limited to 100ms).

So I thought I could maybe write a script that calculates what the total delay is and adjusts the timing of notes accordingly, but I’m not sure how to calculate it, or whether this is even possible.

From my (limited) testing, I suspect that I could add the total FX latency value form the PDC info window to the constant hardware-dependent delay. But this doesn’t take into account the track delays.

So, does anyone know if there is a reliable way of calculating midi input latency (apart from the hardware-dependent latency of course)? Particularly, how do track delays factor in?

I’m also interested if there are any workarounds to input latency problems, apart from using track delays.