Getting the right global position of a MIDI note

Hi there!

My current VST plugin project needs an internal representation of notes on its MIDI track.

So I am basically “recording” the notes as they come into processBlock together with their time information … and there is my problem: Using the play head and the note’s timestamp to get the global sample position works well enough unless I am at the end of a loop (tested in Cubase): the play head is at the end of the loop when the plugin gets the next midi buffer, which already contains notes from the start of the loop. So globalPos = playHeadPos + timeStamp fails here.

Any ideas how I could solve this? Or is there a more elegant solution to my initial problem of storing notes on a MIDI track - I actually don’t need all of them, but the last one BEFORE and the first one AFTER the current playhead position (for syncing purposes).

Many Thanks,