Safely querying tempo/signature/position from the audio thread(s)

Hi,

One of my custom plugin requires to be fed with tempo/signature/position, but it seems I can’t just use the TempoSequence (from the Edit) since this code could trigger an async update :

tempo::BarsAndBeats TempoSequence::toBarsAndBeats (TimePosition t) const
{
    updateTempoDataIfNeeded();
    return internalSequence.toBarsAndBeats (t);
}

and :

void TempoSequence::updateTempoDataIfNeeded() const
{
    // The check on isUpdatePending is to avoid triggering a message thread assert
    // if this is called on a background thread when no update is needed
    if (tempos->isUpdatePending())
        tempos->handleUpdateNowIfNeeded();

    if (timeSigs->isUpdatePending())
        timeSigs->handleUpdateNowIfNeeded();
}

I can’t call the isUpdatePending() methods myself since tempos and timeSigs aren’t public.

So… How I can retrieve tempo/signature/positions safely from the audio context ?

Thank you !

E.

You can use create a tempo::Sequence::Position and then use that from the audio thread.
It directly uses the internal tempo data so doesn’t do the updating and is thread safe.

1 Like

Perfect, thank you @dave96 !