I'm working with [midifile] to create algorithmic scores from analog-style synthesis models. Really I'm at the beginning stages of doing so.

My flow is to generate data, write it into a MIDI file, and then open it in Finale to see the results. Unfortunately, I'm seeing an accumulation of previous notes that appears at the start of each measure.

Here's a picture of the patch and the output:
https://i.imgur.com/t4naCah.png

Any idea what I'm doing wrong? I'm assuming there might be some kind of problem with how I'm creating noteoff commands. 

What I remember from study is that the MIDI spec has both noteon and noteoff messages, but most instruments just use noteon messages with zero velocity. Do sequencers translate those zero velocity messages into noteoff messages before saving them into a file?

Thanks,
Sam