Synchronise timing of plugin MIDI events to host output

Hi Everyone,

I am trying to work out a MIDI timing problem. My plugin accepts MIDI notes and automation values converting them to OSC messages sent over the network.

Normally a plugin would fill audio and MIDI buffers which are then synchronised by the host. In this case MIDI events and audio arrive at the output at the correct time. However, my plugin’s output is not being synchronised by the host as OSC messages are sent over the network.

The audio callbacks don’t always occur at regular intervals with a regular sample count so it is hard to get a solid time reference for MIDI events. I am currently storing the arrival time (ticks) and sample count of each buffer so that I can calculate the average/expected time for any given sample number. Averaging based on the arrival time and sample count of each buffer provides a kind of virtual playhead with some smoothing. It works quite well but it still drifts around a bit.

I accept that I may need to manually compensate for latency by a few ms but I would really like to ensure that the timing of events is linear. I am trying to think of another way of synchronising incoming MIDI notes to the host output but I am a bit stumped.

Others have posted similar questions with the aim of synchronising the GUI with the actual playhead position for a metronome or audio visualiser but I couldn’t find a solution. Has anyone found another way to obtain a linear realtime playhead position from the host?

Cheers,

Chris

1 Like