void MyPluginAudioProcessor::processBlock (juce::AudioBuffer<float>& buffer, juce::MidiBuffer& midiMessages)
{
double bpm { 120 }; // default fallback when host does not provide info
if (auto bpmFromHost = *getPlayHead()->getPosition()->getBpm())
bpm = bpmFromHost;
}
EDIT:
yes, it was actually way simpler than i thought it would be.
You can omit inheriting AudioPlayHead, it does nothing in the code example.
Also, since the PositionInfo is an Optional, the code in processBlock() should check if there is a value, and act accordingly.
For example, I think in a Standalone build, you don’t get a positionInfo. In AudioPluginHost on the other hand, you get a positionInfo, but the BPM is 0, which is also a failure mode you might want to address. In these cases, going with a default like 120 BPM or switching off any tempo syncing would make sense.