RTAS getCurrentPosition and mHWBufferSizeInSamples


This is my first time using Juce and the RTAS SDK so bear with me…

Using Juce 2.0 and the RTAS wrapper getCurrentPosition() I find that the returned info.timeInSeconds is off by twice the HW Buffer Size.

By adding a member variable to the CurrentPositionInfo struct:

and by modifying getCurrentPosition() to:

[code]bool getCurrentPosition (AudioPlayHead::CurrentPositionInfo& info)
// this method can only be called while the plugin is running
jassert (prepared);

    Cmn_Float64 bpm = 120.0;
    Cmn_Int32 num = 4, denom = 4;
    Cmn_Int64 ticks = 0;
    Cmn_Bool isPlaying = false;
    // Moved sampleLocation for scope & check the value for mRTGlobals->mHWBufferSizeInSamples :

    Cmn_Int64 sampleLocation;
    const Cmn_UInt32 bufferSize = mRTGlobals->mHWBufferSizeInSamples;

    if (midiTransport != 0)
        midiTransport->GetCurrentTempo (&bpm);
        midiTransport->IsTransportPlaying (&isPlaying);
        midiTransport->GetCurrentMeter (&num, &denom);

        // (The following is a work-around because GetCurrentTickPosition() doesn't work correctly).

        if (isPlaying)
            midiTransport->GetCurrentRTASSampleLocation (&sampleLocation);
            midiTransport->GetCurrentTDMSampleLocation (&sampleLocation);

        // Adjust the sampleLocation value by twice the HW buffer size
        sampleLocation = sampleLocation + (bufferSize * 2);

        midiTransport->GetCustomTickPosition (&ticks, sampleLocation);

    info.bpm = bpm;
    info.timeSigNumerator = num;
    info.timeSigDenominator = denom;
    info.isPlaying = isPlaying;
    info.isRecording = false;
    info.ppqPosition = ticks / 960000.0;
    info.ppqPositionOfLastBarStart = 0; //xxx no idea how to get this correctly..
    info.isLooping = false;
    info.ppqLoopStart = 0;
    info.ppqLoopEnd = 0;
    info.currentSampleLocation = sampleLocation;  // return this to check sample location in plugin


    return true;

The returned value now is correct in Pro Tools 10.x (native)

Is this correct or am I missing something ?? Will this be different using TDM or HDX hardware?




“Off” compared to what? How are you measuring it?


Compared to the timeline display in Pro Tools 10.x

I’m using the demo code to display the location in the plugin and added the currentSampleLocation

If I move the insertion point the values displayed in the plugin differ from the Pro Tools counter by exactly two times the HW Buffer size. By modifying the code the values are now exactly the same.




Well you can’t really expect that to be the same…! The plugin gets given its data in blocks, and you’re only reporting the start position of the last block that it processed. There’s no reason to assume that the start of the last block would be exactly the same as the host’s cursor position.


I guess I was expecting the demo time display to account for the buffer size so that the displayed time would match the host’s

As I said I’m just starting to experiment and read through the source code.