ok, so midi only has gate, no concept of how long the note is.
but you could do what you want ;
if you want to shorten the note: (or rather set a maximum length)
you could do this, by from note on, starting a timer (/delay) and using that to do the noteoff (/gate) after the specified 'timeout' if the note has not already finished.
if you want to extend the note: (or set a minimum length)
basically you do something similar, but this time the note_off, is ignored if its before the timer, , and you use the timer to turn the noteoff.
if you just want to always have the same length note, you can simply use a timer and ignore the note_off.