Query regarding the timing accuracy of midi messages from Cubase to Kontakt

I am writing a Kontakt multiscript in which I want to detect if a note-on arrives within a gap of 1/16 of a beat (quarter-note) after the previous note-off. (If it does, the next note is considered to be a slurred (legato) note.) To measure the tolerance that I need to allow to check if this new note arrives in time, I have created a chain of bars with a note lasting the full length of the bar except for a 1/64 gap at the end; the data is sent to an instance of Kontakt containing the following multiscript:


if ($MIDI_COMMAND = $MIDI_COMMAND_NOTE_OFF)	
    reset_ksp_timer
end if
if ($MIDI_COMMAND = $MIDI_COMMAND_NOTE_ON)	
    if ($KSP_TIMER > $max)
        $max := $KSP_TIMER
    end if
    if ($KSP_TIMER < $min)
        $min := $KSP_TIMER
    end if
    message ("min = " & $min & ("  max = " & $max)
end if

For example, the results I get for 120 BPM (should be $DURATION_QUARTER/16 = 31.25ms) are 30.2ms min and 40.9ms max.

I have suspected for a while that Cubases’s midi timing is loose.

Can somebody please explain these results?