i want to pass incomming Midi messages from the audio callback to
a Midi output device using sendBlockOfMessages. The only issue I have
is that the Midi output send the outgoing events to early.
To test this I use an internal Midi cable from my plugin’s Midi output connected to an
input of a Midi track in Ableton. I can only get a precise timing if I use
Time::getMillisecondCounter() + 93 as millisecondCounterToStartAt value
but I think that this is not the right way to go.
Is there a logical way to get the exact number to use for millisecondCounterToStartAt
or is it bounded to latency or such?
Well, it’s up to you to figure out what’s best for your app, really. You can find out the audio device’s latency from the AudioIODevice object, and can specify a real-world start time when you call sendBlockOfMessages(), so I think there’s enough information available to make it do whatever you need.
thank you for your answer.
I have no AudioIODevice object as it is a plugin unless I can pull the host
it’s latency from somewhere else. Even not if I compile my app as standalone,
I just open Midi devs.
What I really need to know/understand is:
- sendBlockOfMessages -> samplesPerSecondForBuffer = I assume that using the filter its sample rate here is fine???
- CurrentPositionInfo::ppqPosition returns a double like 12.0123456789; can I assume that 12 stands for the quarter notes and
the numbers after the separator stands for samples?
- Assuming that number 2 is right, to calculate the real-world time out of ppqPosition I need to know the resolution (ppq) of the host, how can I get this?
Am I completely wrong?
I’m sure you’ve got a good answer for this, but why aren’t you just returning your midi messages to the host? There’s no guarantee that a plugin will give you any kind of predictable latency at all (and may not even be running in realtime…), and it may already have opened the midi output that you’re trying to use. Some hosts probably won’t even give you a ppq position to work with. There are all sorts of gotchas in trying to go directly to the device like that inside a host…
That is what I am already do but some hosts i.e. Ableton are just ignoring Midi events from plugins to output.
And if they do, then only short Midi messages but NO sysex.
So I have to provide an alterative way by using real Midi devs (I wish somebody will write a generic multi client Midi driver
to get arround this “Sorry, device is in use” nightmare.
Anyway, assuming the host provides the right ppqPosition number, can I work with my assumtion number 1 and 2?
Yes, your assumptions sound ok to me.