If you wan’t to sync the plugin time with the daw time you could do it at the first process call something like this:
void YourAudioSourceProcessor::suspendProcessing (bool shouldBeSuspended)
{
if (!shouldBeSuspended)
samplesSinceStart = -1; // Flag it to be set at first processBlock call
juce::suspendProcessing (shouldBeSuspended);
}
void processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiBuffer)
{
if (samplesSinceStart < 0)
samplesSinceStart = playHead->timeInSamples; //or what ever it's called
else
/*should stay in sync here if host is updating playHead acc to spec
could possibly differ by one bufferful
*/
jassert (samplesSinceStart == playHead->timeInSamples)
// your code
samplesSinceStart += buffer.getNumSamples();
}
Hopefully, if the host is doing it’s job, the assert will never trigger, and if it does, it will hopefully be a constant offset, which you could subtract from samplesSinceStart, and if not even that’s the case, your user won’t possible notice the midi events is a few samples off anyway.
No, your plugin will not wander away from the host’s timing (under normal conditions), just as no other (well behaving) plugin will - otherwise they would lose audiosamples every now and then, and they don’t.
The only thing that might happen is there might be a constant offset between the the host and the plugin if the host fail to report it’s timeInSamples at the beginning, but that will hopefully be unnoticeable.
