How are you making your midi file? Is it generated by your digital piano/keyboard?
OK, here's a good solution actually: if you go to www.midieditor.org you can download the midi editor there so you can actually see all the midi events in your midi file, change the tempo, delete things, move things etc. Really useful.
Also, I've figured out that you can actually import Midi files into Audacity, which is ridiculously useful because it enables you to have it playing at the same time as the audio track and you can then easily move the audio track around so that it lines up perfectly with the Midi track.
You could therefore load up your Midi track into the Midi Editor, make whatever adjustments you need to make, save it, then open the newly-saved Midi track into Audacity, add a stereo audio track alongside it, import your audio track, move the audio track around a bit so it all lines up perfectly, remove the Midi track, export the audio track and you would then end up with an audio track that matches the Midi track perfectly in time.
There was an issue with MIDI Recording that should have been fixed in a recent update. Please make sure you're using the latest version of the app from this website or your App Store?
If you're still having issues recording MIDI after the update, please let me know...