Here's the code I used in processBlock to timestamp midi events (note ons in my case) even when the audioplayhead isn't playing:
void GmetAudioProcessor::processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages)
{
// This is the place where you'd normally do the guts of your plugin's
// audio processing...
for (int channel = 0; channel < getNumInputChannels(); ++channel)
{
float* channelData = buffer.getSampleData (channel);
// ..do something to the data...
}
// In case we have more outputs than inputs, we'll clear any output
// channels that didn't contain input data, (because these aren't
// guaranteed to be empty - they may contain garbage).
for (int i = getNumInputChannels(); i < getNumOutputChannels(); ++i)
{
buffer.clear (i, 0, buffer.getNumSamples());
}
// ask the host for the current time so we can display it...
AudioPlayHead::CurrentPositionInfo newTime;
if (getPlayHead() != nullptr && getPlayHead()->getCurrentPosition (newTime))
{
// Successfully got the current time from the host..
lastPosInfo = newTime;
}
else
{
// If the host fails to fill-in the current time, we'll just clear it to a default..
lastPosInfo.resetToDefault();
}
double msPerSample = 1000 / getSampleRate();
if (!midiMessages.isEmpty()) {
int i;
MidiMessage m;
MidiBuffer::Iterator it(midiMessages);
while(it.getNextEvent(m, i)) {
if (m.isNoteOn()) {
m.setTimeStamp(currentTime + i * msPerSample);
midiMessageSequence.addEvent(m, 0);
gotMidi = true;
}
}
}
// keep track of time even whe the host isn't playing (set currentTime = 0 in prepareToPlay)
currentTime += msPerSample * buffer.getNumSamples();
}
cheers,
Gord