I wrote a CAL script to do this a few years ago. It isn't bomb-proofed against things like multiple notes starting at the same time (i.e. chords), and it's hard-coded to truncate overlapping notes to end 1 tick before the next note. I can't guarantee some unexpected input won't hang it, but I just did a quick test on something I would typically use it for, and it worked as expected.
I was going to paste the plain text here, but the forum software trashed the indents. It would still work, but it looks ugly. P.M. me an e-mail address, and I'll send you a copy.