developer -> VstTimeInfo worries...

UHE is now closed. For Technical Support from Ableton, please go here: http://www.ableton.com/support
Locked
bram
Posts: 5
Joined: Mon Jun 02, 2003 7:56 pm

developer -> VstTimeInfo worries...

Post by bram » Mon Jun 02, 2003 8:03 pm

Hi,


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;
	}
}

But Andreas (who's a regular here) told me samplesToNextBarIsValid is FALSE in Live.... Auch.

Can anyone @ Ableton comment on this and propose a possible fix in my plugin or Live itself ;)


kindest regards,


- bram

bram
Posts: 5
Joined: Mon Jun 02, 2003 7:56 pm

Post by bram » Mon Jun 02, 2003 8:06 pm

oh, it's not necessary, but here's the structure of FFXTimeInfo

Code: Select all

class FFXTimeInfo
{
public:
	FFXTimeInfo() {};
	~FFXTimeInfo() {};

	// false if the VstTimeInfo pointer returned is null
	// i.e. the host doesn't support VstTimeInfo
	bool	isValid;

	// always valid
	double	samplePos;			// current location in samples
	double	sampleRate;
	
	bool	tempoIsValid;		// kVstTempoValid
	double	tempo;				// in beats/minute
	double	tempoBPS;			// in beats/second
	double	numSamplesInBeat;	// number of samples in 1 beat

	bool	ppqPosIsValid;		// kVstPpqPosValid
	double	ppqPos;				// 1 ppq = 1 MIDI beat (primary note division value)

	bool	barsIsValid;		// kVstBarsValid
	double	barStartPos;		// last bar start position, in ppq, relative to ppqPos

	bool	timeSigIsValid;		// kVstTimeSigValid
	long	timeSigNumerator;	// time signature
	long	timeSigDenominator;

	bool	samplesToNextBarIsValid;
	double	numSamplesToNextBar;

	bool	cyclePosIsValid;	// kVstCyclePosValid
	double	cycleStartPos;		// in terms of ppq
	double	cycleEndPos;		// in terms of ppq

	bool	playbackChanged;	// kVstTransportChanged
	bool	playbackIsOccuring;	// kVstTransportPlaying
	bool	cycleIsActive;		// kVstTransportCycleActive
};

Frank Hoffmann
Posts: 771
Joined: Tue Jan 28, 2003 6:01 pm
Location: Ableton Headquarter

Post by Frank Hoffmann » Thu Jun 05, 2003 4:24 pm

That is true. Live does set the info triggered with kVstPpqPosValid, kVstTempoValid and kVstTimeSigValid. But it does _not_ support kVstBarsValid.

In addition the kVstTransportPlaying flag is set or not.
sampleRate and samplePos are valid as well.

But beware that ffxtime->numSamplesInBeat is only valid for the one buffer you calculate. The tempo might be automated and therefore change over time. To spy ahead over the calculation buffer in this way is not possible.

frank
Frank Hoffmann
hoffmann@ableton.com

bram
Posts: 5
Joined: Mon Jun 02, 2003 7:56 pm

Post by bram » Wed Jun 11, 2003 9:57 pm

Hiya, thx for the reply...


But, can someone @ ableton then tell me how I should do this in Live?
I need the curent position INSIDE the measure...

I.e.
ppqpos - barstartpos = position in the current bar where I am in ppq
(this is easily transformed in samples)

With this info I can easily sync to measures.

I'm not sure how to do this w/out the barstartpos !

the only way to do it without barstartpos is to take for granted that the timesig stayed constant since ppq=0, and that's not something I would want to do as it will break a lot of other hosts that DO change the time-sig...


- bram

Frank Hoffmann
Posts: 771
Joined: Tue Jan 28, 2003 6:01 pm
Location: Ableton Headquarter

Post by Frank Hoffmann » Thu Jun 12, 2003 11:37 am

You have to understand that a all informations TimeInfo provides are only valid for the current buffer in calculation. You can't look ahead or back the buffer boundaries, because tempo is not a fixed value. To look back, you can track the values you need from previous buffer calculations. There is no way to look ahead. This is also true for all other hosts, except they don't have tempo automation.

Your assuption is right, but if you don't get a valid bar, then you can only assume that the signature doesn't change, right? You can also check in this case if the host is Live.

I try to implement the barStartPos in Live 3. No promise.

Frank
Frank Hoffmann
hoffmann@ableton.com

bram
Posts: 5
Joined: Mon Jun 02, 2003 7:56 pm

Post by bram » Thu Jun 12, 2003 2:41 pm

frh wrote:You have to understand that a all informations TimeInfo provides are only valid for the current buffer in calculation. You can't look ahead or back the buffer boundaries, because tempo is not a fixed value. To look back, you can track the values you need from previous buffer calculations. There is no way to look ahead. This is also true for all other hosts, except they don't have tempo automation.
That is true, but one can 'estimate', right?
Ableton doesn't let me estimate....
frh wrote:Your assuption is right, but if you don't get a valid bar, then you can only assume that the signature doesn't change, right?
You can also check in this case if the host is Live.
Afaic that's a hack ;) but you're right.
frh wrote:I try to implement the barStartPos in Live 3. No promise.
That would RULE. I've made this plugin with micha and chris from funkstörung in mind and now they can't use it :(

BTW, could you perhaps give me an example on how I should calculate (estimate...) the right 'current-sample-in-measure' in Live?

greetings,


- bram

Frank Hoffmann
Posts: 771
Joined: Tue Jan 28, 2003 6:01 pm
Location: Ableton Headquarter

Post by Frank Hoffmann » Fri Jun 13, 2003 1:03 pm

Live provides the ppq position. This is the quarter note position (double) the buffer starts with. With the signature given, you can easily calculate where the last bar started. With signature of 4/4 a bar starts every 4 quarter notes or (or every 4.0 ppq). with 3/4 a bar starts every 3 quarter notes, etc. When you ignore tempo automation, then you can use the sample code provided by you above.

Frank
Frank Hoffmann
hoffmann@ableton.com

Frank Hoffmann
Posts: 771
Joined: Tue Jan 28, 2003 6:01 pm
Location: Ableton Headquarter

Post by Frank Hoffmann » Mon Jul 07, 2003 9:37 am

Live 2.1 features now barStartPos as well as Cycle settings in VstTimeInfo. Please test if everything works as expected.

Frank
Frank Hoffmann
hoffmann@ableton.com

bram
Posts: 5
Joined: Mon Jun 02, 2003 7:56 pm

Post by bram » Mon Jul 07, 2003 9:42 am

wow! that's greatnews!!! I'm still running 1.0 or something, so I'll have to update.... Lot's of people will love being able to use my plugin in Ableton Live now!


greetings,

- bram

jinek
Posts: 67
Joined: Wed May 30, 2007 7:51 am
Location: RUSSIA

Post by jinek » Tue Feb 17, 2009 10:05 am

Frank Hoffmann wrote:Live 2.1 features now barStartPos as well as Cycle settings in VstTimeInfo. Please test if everything works as expected.

Frank
SO... we have ableton 7 and 8 is comming, i'm trying GetTimeInfo(ALL) and cycle start and Cycle End are 0.
I want to calculate the number of sample frames of quarter (and 1/2,1/4 and so on) notes, and i need to know where is the start of the current cycle,because deltaFrame of generated events must be related to the start of the cycle.

how could i do that, does ableton still provide the plugins with cycle bounds information?

jinek
Posts: 67
Joined: Wed May 30, 2007 7:51 am
Location: RUSSIA

Post by jinek » Wed Feb 18, 2009 9:08 am

i've got it. GetTimeInfo give us information about start position of the current buffer, so we can calculate the end and so on. Great.

Locked