In my implementation of the AudioProcessor::processBlock function, I’m trying to get the accurate sample position of the processed block (relatively to the timeline of the host).
I observe that such information is obtained in the VST, RTAS, AudioUnit wrappers, however these are only transitory info, and are not made available to the final AudioProcessor which is available to the juce library user (plug-in developer).
In VST, this is available through the getTimeInfo call (see juce’s VST wrapper).
In RTAS, this is available through the GetCurrentRTASSampleLocation call (or GetCurrentTDMSampleLocation if not playing) (see juce’s RTAS wrapper).
In AudioUnit, this is available through the CallHostTransportState call (see juce’s AudioUnit wrapper).
In AAX, this should be available through a GetCurrentNativeSampleLocation call (not double checked yet).
Is it possible to add such a “current sample location” field into the AudioPlayHead::CurrentPositionInfo structure so that the getCurrentPosition() calls of the various wrappers can deliver this info to the AudioProcessor class?
Good request… Haven’t time right now to code it myself, but if you’re in a hurry and want to suggest some changes, I’d be happy to sanity-check and merge them in!
Well, I did not understand where I could add an equivalent bool getCurrentPosition (AudioPlayHead::CurrentPositionInfo& info) method in the AAX wrapper, so I only added that to the VST, RTAS and AU wrappers.
[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).
// Moved for scope...
// Cmn_Int64 sampleLocation;
if (isPlaying)
midiTransport->GetCurrentRTASSampleLocation (&sampleLocation);
else
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 true;
}[/code]
In Pro Tools this now displays the accurate sample location of the insertion point.
One other change I made to the plugin demo was to fix the rounding error in the Bars/Beats display in ppqToBarsBeatsString()
The bars/beats display in the demo then matches the Pro Tools timeline with a fixed meter.
Did you see that I’d already made the changes we discussed in this thread? What you’re posting here just looks like a different version of the stuff I’ve already added…