in a new plugin I'm working on I've got some trouble with VstTimeInfo...
I need the number of samples per measure and the current "sample-in-measure".
For this I'm using this piece of code I stole from DestroyFX, our dear fellows @ smartelectronix
Code: Select all
void CRetriggaHappyNigga::convertVstTimeInfo(FFXTimeInfo *ffxtime)
{
if (ffxtime == NULL) // bogus
return;
if (this == NULL) // totally bogus
{
ffxtime->isValid = false;
return;
}
// get some VstTimeInfo with flags requesting all of the info that we want
VstTimeInfo *vstTimeInfo = this->getTimeInfo(kVstTempoValid
| kVstTransportChanged
| kVstBarsValid
| kVstPpqPosValid
| kVstTimeSigValid
| kVstCyclePosValid
| kVstTransportPlaying
| kVstTransportCycleActive);
if (vstTimeInfo == NULL)
{
ffxtime->isValid = false;
return;
}
ffxtime->isValid = true;
// set all validity bools according to the flags returned by our VstTimeInfo request
ffxtime->tempoIsValid = (vstTimeInfo->flags & kVstTempoValid) != 0;
ffxtime->ppqPosIsValid = (vstTimeInfo->flags & kVstPpqPosValid) != 0;
ffxtime->barsIsValid = (vstTimeInfo->flags & kVstBarsValid) != 0;
ffxtime->timeSigIsValid = (vstTimeInfo->flags & kVstTimeSigValid) != 0;
ffxtime->samplesToNextBarIsValid = (ffxtime->tempoIsValid && ffxtime->ppqPosIsValid) && (ffxtime->barsIsValid && ffxtime->timeSigIsValid);
ffxtime->cyclePosIsValid = (vstTimeInfo->flags & kVstCyclePosValid) != 0;
ffxtime->playbackChanged = (vstTimeInfo->flags & kVstTransportChanged) != 0;
ffxtime->playbackIsOccuring = (vstTimeInfo->flags & kVstTransportPlaying) != 0;
ffxtime->cycleIsActive = (vstTimeInfo->flags & kVstTransportCycleActive) != 0;
// these can always be counted on, unless the VstTimeInfo pointer was null
ffxtime->samplePos = vstTimeInfo->samplePos;
ffxtime->sampleRate = vstTimeInfo->sampleRate;
if (ffxtime->tempoIsValid)
{
ffxtime->tempo = vstTimeInfo->tempo;
ffxtime->tempoBPS = vstTimeInfo->tempo / 60.0;
ffxtime->numSamplesInBeat = vstTimeInfo->sampleRate / ffxtime->tempoBPS;
}
// get the song beat position of our precise current location
if (ffxtime->ppqPosIsValid)
ffxtime->ppqPos = vstTimeInfo->ppqPos;
// get the song beat position of the beginning of the previous measure
if (ffxtime->barsIsValid)
ffxtime->barStartPos = vstTimeInfo->barStartPos;
// get the numerator of the time signature - this is the number of beats per measure
if (ffxtime->timeSigIsValid)
{
ffxtime->timeSigNumerator = vstTimeInfo->timeSigNumerator;
ffxtime->timeSigDenominator = vstTimeInfo->timeSigDenominator;
// it will screw up the while loop below bigtime if timeSigNumerator isn't a positive number
if (ffxtime->timeSigNumerator <= 0)
ffxtime->timeSigNumerator = 4;
}
// do some calculations for this one
if (ffxtime->samplesToNextBarIsValid)
{
double distanceToNextBarPPQ;
// calculate the distance in beats to the upcoming measure beginning point
if (ffxtime->barStartPos == ffxtime->ppqPos)
distanceToNextBarPPQ = 0.0;
else
distanceToNextBarPPQ = ffxtime->barStartPos + (double)(ffxtime->timeSigNumerator) - ffxtime->ppqPos;
// do this stuff because some hosts (Cubase) give kind of wacky barStartPos sometimes
while (distanceToNextBarPPQ < 0.0)
distanceToNextBarPPQ += (double)(ffxtime->timeSigNumerator);
while (distanceToNextBarPPQ > (double)(ffxtime->timeSigNumerator))
distanceToNextBarPPQ -= (double)(ffxtime->timeSigNumerator);
// convert the value for the distance to the next measure from beats to samples
//ffxtime->numSamplesToNextBar = (long) (distanceToNextBarPPQ * ffxtime->numSamplesInBeat);
ffxtime->numSamplesToNextBar =(distanceToNextBarPPQ * vstTimeInfo->sampleRate * 60.0) / vstTimeInfo->tempo;
if (ffxtime->numSamplesToNextBar < 0) // just protecting again against wacky values
ffxtime->numSamplesToNextBar = 0;
}
if (ffxtime->cyclePosIsValid)
{
ffxtime->cycleStartPos = vstTimeInfo->cycleStartPos;
ffxtime->cycleEndPos = vstTimeInfo->cycleEndPos;
}
}
Can anyone @ Ableton comment on this and propose a possible fix in my plugin or Live itself
kindest regards,
- bram