The only thing that seems pertinent to the discussion is perhaps the "pianotec" which I'm not familiar with. Is that improving on stock Ubuntu somehow?
Lowering latency consists of balancing two opposing "forces".
To lower it, you "simply" need to tell the software that you're using to use a small buffer size. This reduces the time between the MIDI event arriving in the software and the software producing some sound corresponding to that event.
However, there are limits on how low you can go, some caused by hardware and some caused by software. The kernel configuration itself can play a role, along with a variety of different devices and device drivers. This document tries to help you understand the sorts of system (hardware-ish) issues that can prevent you from reducing the buffer size:
https://manual.ardour.org/setting-up-your-system/the-right-c...
Ensuring that your software runs with realtime scheduling (SCHED_FIFO) is where it can be necessary to adjust stock Ubuntu systems to give you permission to do this (you are not allowed to do so by default). In addition, the software you're using (Timidity) will not necessarily do this by itself.
If you want to know more, I'd suggest visiting linuxmusicians.com and using their forums.