Timing MIDI events generated in middle of buffer

If I have an event sent sometime after the most recent processBlock has begun, and I wanted to play a MIDI event at the right time on the next processBlock, is there a good way to do this?

For example, say the processBlock begun 100 samples ago and I play an event at that time. I would like to put it on sample 100 of the next processBlock, so it would be on time, with regard to the buffer length. The issue I’m facing is getting a timestamp in samples of the event.

Currently I only see a way to play the note immediately (which skips the processBlock, which isn’t helpful as I want to do some processing), or I can just play it arbitrarily on the next buffer, which won’t be as nicely timed (particularly for large buffers). Ideally, I would like it to be perfectly timed.

Of course, I can’t use second-based timers as that won’t allow the app to export audio.

After thinking about use cases for this, I realized there may not be any. I was first thinking of an async process that ran parallel, but if that itself is not strictly bound to the processBlock’s timing, then it could still have errors.

It may be just that everything needs to be synced to the processBlock.