Example #1
0
EventTime TimeNow() {
  struct timeval tvNow;

  gettimeofday(&tvNow, NULL);

  return EventTime(tvNow.tv_sec, tvNow.tv_usec);
}
status_t AmEventTimeView::ConstructSignatureFromTime()
{
	if (!mEvent) return B_ERROR;
	status_t		err = B_ERROR;
	// READ TRACK BLOCK
	#ifdef AM_TRACE_LOCKS
	printf("AmEventTimeView::ConstructSignatureFromTime() read lock\n");
	#endif
	const AmSong*	song = ReadLock();
	const AmTrack*	track = song ? song->Track( mTrackRef ) : 0;
	if (track) {
		AmSignature		sig;
		if ( (err = track->GetSignature(EventTime(), sig)) == B_OK ) {
			mSignature->Set(sig);
		}
	}
	ReadUnlock( song );
	// END READ TRACK BLOCK
	return err;
}
status_t AmEventTimeView::SetControls()
{
	if (ConstructSignatureFromTime() != B_OK) return B_ERROR;
	// Set the measure value
	if (mMeasureCtrl) mMeasureCtrl->SetValue( mSignature->Measure() );
	// Calculate and set the beat value
	AmTime	time = EventTime() - mSignature->StartTime();
	AmTime	start = 0;
	AmTime	ticks = mSignature->TicksPerBeat();
	int32	beat = 1;
	while ( (start + ticks) <= time) {
		start += ticks;
		beat++;
	}
	// Also need to set the range of values for the beat control here.
	if (mBeatCtrl) {
		mBeatCtrl->SetLimits(1, mSignature->Beats() );
		mBeatCtrl->SetValue(beat);
	}
	// Calculate and set the clock value
	if (mClockCtrl) mClockCtrl->SetValue(time - start);
	
	return B_OK;
}