How to detect the beats in AudioAppComponent class

I try to inherit the audio player from the tutorialhttps://docs.juce.com/master/tutorial_looping_audio_sample_buffer.html
, and adding the extra rhythm detection methods to output the audio beats. Is it possible to implement the “AudioPlayHead::CurrentPositionInfo” in this AudioAppComponent?

According to the restriction in the function of “getplayhead()”, it must be involved in the “processBlock()”.
so I have built the AudioProcessor class, then try to evoke the “processBlock()” method in the function of “getNextAudioBlock()” in the AudioAppComponent class.

though, the result of “getplayhead()” eventually got the nullptr.

Is this due to no initialize method in the processor? or should I use the original audiodevecieManger to bond the new AudioProcessorPlayer?

    
**Eg_AudioAppComponent code:**
Eg_AudioProcessor m_processor;
void getNextAudioBlock (const juce::AudioSourceChannelInfo& bufferToFill) override
   {
            m_processor.processBlock(*currentAudioSampleBuffer, m_midi_buffer);
        }

**Eg_AudioProcessor code:**

void Eg_AudioProcessor ::processBlock(AudioBuffer<float>& buffer, MidiBuffer& midiMessages)
{
	buffer.clear();
	AudioPlayHead* playHead = getPlayHead();
	AudioPlayHead::CurrentPositionInfo currentPositionInfo;

	if (playHead != nullptr)
	{
		playHead->getCurrentPosition(currentPositionInfo);
	}
	auto bpm = currentPositionInfo.bpm;
	juce::Logger::getCurrentLogger()->writeToLog("bpm:\t" + (String)bpm);
}

The AudioAppComponent or the AudioProcessor don’t provide you with the playhead object by default. You would need to implement your own playhead/audio position tracking.

Thanks for replying to me. could you give me some further details about
why the playhead is not in my AudioProcessor.

I notice the comment parts of the getPlayHead() function, the nullptr related to time info.
Is this the case? if so is there any guide to supplement this parameter?

When you implement an AudioProcessor for a plugin, Juce provides that with the playhead object, but if you use AudioProcessor in a non-plugin context, there will be no playhead by default. To implement the playhead, you need to subclass AudioPlayHead, instantiate that and set it for your AudioProcessor with the setPlayhead method.

You could also skip dealing with the playhead and just track the audio position directly in your code. The AudioPlayHead is an abstract class and you will have to implement the position tracking yourself anyway, so you don’t necessarily get any particular benefit from using it in a stand alone application context.

Also note that the playhead has nothing to do with beat detection, it just provides information about the play position of the audio. Audio beat detection is a completely separate topic and much more complicated to deal with.

It makes sense to me. thank again.