In most sequencers, there is a quantize function. This will take all of the note data on a track and aligns all of the notes to the nearest division. So if you play sloppily or you just have bad latency on your midi keyboard, quantize is your friend. Select the division most appropriate to what you’ve just played. 1/8th and 1/16th divisions are most common. Another cool thing about quantization is that it will sometimes snap a note to a division that you didn’t intend. But it sounds good anyway, minus a few odd parts. Then this quantized melody may inspire you to come up with a new melody altogether. Of course, not all music sounds good with quantization. If you’re going for an organic, human sound, then you probably won’t want to quantize 100%. There are options in most sequencers to quantize to a certain percentage. This is useful if you want to correct your timing, but not to the point of computerized perfection.