Strange midi sync issue for multiple tracks in host

I’ve noticed a strange midi behavior on my plugin and was wondering if anyone else has encountered this issue.

If I play my plugin solo on a single track in an empty project, midi timing works as expected. Notes are playing on time and if I bounce the audio, I get a good result.

Adding another instrument track will mess everything up. Midi notes are no longer on time and bouncing audio will produce an un-synced audio clip. Not just for my plugin but for other VSTs as well, whether if they are multiple instances of my plugin or not.

My plugin only takes midi in, and during processBlock I clear the midi buffer just to be sure nothing is being sent out. What could possibly go wrong with my rendering that could cause other VSTs in other tracks to go off sync?

This sounds very unusual, but it’s difficult to say what might be going wrong without seeing your code. If your own plugin is getting out of sync, the most likely culprit is that MIDI processing in the plugin is broken somehow. Perhaps you are processing all incoming MIDI events in one go at the beginning of each audio block, rather than respecting the event’s sample offset in the block.

If other plugins are going of of sync with the DAW’s clock, then I’m not sure what to suggest. I don’t think this should even be possible…

Can you bounce/record the audio with a metronome playing simultaneously? It’d be useful to know whether all tracks become desynchronised, or whether it’s just your plugin (or just other plugins!). It would also be interesting to know whether all tracks are desynchronised by the same amount.

Thanks, you are right. I had a round-off error for midi offsets so they all went to the begining of the buffer instead of their real timestamp.

What is interesting here, is that the errror was only noticed when I had over one instance, or when a single channel was armed for recording.

It seems that if you work with only one channel without recording, Logic will be kind enough to trim your buffers in a way that if you have for example a noteOn at sample #100 you want to ouput, you will first send an empty buffer of 100 samples length, and the next buffer will have the noteOn at sample 0. So the round-off error can’t be detected if there is nothing to round off.

If you have more then 1 instance or if you’re armed for recording, Logic will not bother trying to do so.

So the error was not related to multiple tracks, but to some calculation bug that was magically auto-corrected by Logic as long as I kept my project with only 1 instnace.