Newb - This is supposed to be getting the current BPM - what am I doing wrong? (AudioPlayHead)

I’m using the AudioPlayHead struct to try and get BPM.
I’m aware I have to use this in the processBlock().

This is my code. It doesn’t appear to be working. BPM end up containing 0.000, and time signature ends up with something random like 9.5453422.
What I am doing wrong?

You might want to try something more like this…

In your header, make a private member

juce::AudioPlayHead *playHead;
juce::AudioPlayHead::CurrentPositionInfo cpi;

In your cpp file, do this in the processBlock function

playHead = this->getPlayHead();
if (playHead != nullptr)
auto bpm = cpi.bpm;

I am guessing (can’t remember) that there is a juce tutorial that walks you through this or the documentation shows it.

1 Like

yes… that worked for me, you’re a star !.
I had a look at the tutorials, an AudioPlayHead one didn’t seem like it was there.
The docs are scant for me, would like to see some examples in the docs.(JUCE: AudioPlayHead::CurrentPositionInfo Struct Reference)

Sure. Happy to help.

Yeah, sorry. It could be in the demo projects too, though its been so long since I looked at any of those.

I don’t recall if this was one of them but there have been a few things that it felt like i spent 1000 hours just trying to get working. This forum has been a great help in avoiding that for me in the past.

Good luck!

1 Like