[JUCE API] Getting BPM From DAW

SangHoon You·2025년 4월 6일
0

JUCE API

목록 보기
6/17
post-thumbnail

To implement tempo delay, you need to know the BPM.

Since the DAW already contains BPM information, you should use the JUCE API to retrieve it.

void EulerDelayAudioProcessor::updateBpm(double& outBpm) noexcept
{
    juce::AudioPlayHead* playhead = getPlayHead();
    if(playhead==nullptr)
    {
        return;
    }
    
    auto positioninfo =  playhead->getPosition();
    
    if(!positioninfo)
    {
        return;
    }
    
    auto bpmFromDAW = positioninfo->getBpm();
    if(bpmFromDAW)
    {
       outBpm = *bpmFromDAW;
    }
    
}

getPlayHead()

  • This method, which belongs to the AudioProcessor class
  • Serves as an entry point to obtain playback state and position information from the DAW.
  • It returns an AudioPlayHead*, through which you can access timing details including the BPM.

AudioPlayHead::PositionInfo

  • When you call playHead->getPosition(), you can obtain the current playback position and tempo (BPM) information through this structure.

getBpm()

  • This function retrieves the BPM from the PositionInfo object.
  • It returns a std::optional, meaning it only holds a valid value if BPM information is available.

std::optional ?

std::optional is a type that may or may not contain a value, and can be checked similarly to a pointer.
Since it holds an actual value inside, you can access it using *optional.
Because the return type can be complex, using auto makes the code simpler and more readable.


profile
Audio Plugin Developer

0개의 댓글