# Timing MIDI events generated in middle of buffer

**URL:** <https://forum.juce.com/t/timing-midi-events-generated-in-middle-of-buffer/46333>\
**Category:** General JUCE discussion\
**Created:** [June 4, 2021, 3:55pm UTC](https://forum.juce.com/t/timing-midi-events-generated-in-middle-of-buffer/46333 "2021-06-04T15:55:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![psyzza](https://avatars.discourse-cdn.com/v4/letter/p/8edcca/32.png) [@psyzza](https://forum.juce.com/u/psyzza)\
**Post date:** [June 4, 2021, 3:55pm UTC](https://forum.juce.com/t/timing-midi-events-generated-in-middle-of-buffer/46333/1 "2021-06-04T15:55:29Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![psyzza](https://avatars.discourse-cdn.com/v4/letter/p/8edcca/32.png) [@psyzza](https://forum.juce.com/u/psyzza)\
**Post date:** [June 4, 2021, 5:19pm UTC](https://forum.juce.com/t/timing-midi-events-generated-in-middle-of-buffer/46333/2 "2021-06-04T17:19:43Z")

</div>

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.
