/******************************************************************************
* Timer callback used during animation playback.
******************************************************************************/
void AnimationSettings::onPlaybackTimer()
{
	// Check if the animation playback has been deactivated in the meantime.
	if(!_isPlaybackActive)
		return;

	// Add one frame to current time
	int newFrame = timeToFrame(time()) + 1;
	TimePoint newTime = frameToTime(newFrame);

	// Loop back to first frame if end has been reached.
	if(newTime > animationInterval().end())
		newTime = animationInterval().start();

	// Set new time.
	setTime(newTime);

	// Wait until the scene is ready. Then jump to the next frame.
	dataset()->runWhenSceneIsReady([this]() {
		if(_isPlaybackActive) {
			_isPlaybackActive = false;
			startAnimationPlayback();
		}
	});
}
示例#2
0
void readGroundTruth(std::vector<double>& storage, std::string file, int FPS){
    
    File* f=new File(file);
    Scanner* s=new Scanner(f);
    
    
    while(s->hasNext()){
        
        std::string temp=s->nextLine();
        if(temp.empty()){
            return;
        }
        StringTokenizer* st=new StringTokenizer(temp, ",");
        double tstamp, value;
       // println("Getting Paired Value");
        st->GetPairedValue(&tstamp, &value, temp, ",");
        
        //println("Converting to Frame number");
        int frameNum=timeToFrame(tstamp, FPS);
        
        //println("Seeing where to put it in the array");
        //print("("); print(frameNum); print(","); print(value); println(")");
        if((int)storage.size()>=frameNum+1){
            //We already have an entry for this frame, average it out
            storage[frameNum]=(storage[frameNum]+value)/2;
        }else{
            storage.push_back(value);
        }
        
         
    }
    
    
}
/******************************************************************************
* Jumps to the previous animation frame.
******************************************************************************/
void AnimationSettings::jumpToNextFrame()
{
	// Subtract one frame from current time.
	TimePoint newTime = frameToTime(timeToFrame(time()) + 1);
	// Clamp new time
	newTime = std::min(newTime, animationInterval().end());
	// Set new time.
	setTime(newTime);
}
/******************************************************************************
* Jumps to the previous animation frame.
******************************************************************************/
void AnimationSettings::jumpToPreviousFrame()
{
	// Subtract one frame from current time.
	TimePoint newTime = frameToTime(timeToFrame(time()) - 1);
	// Clamp new time
	newTime = std::max(newTime, animationInterval().start());
	// Set new time.
	setTime(newTime);
}
示例#5
0
void Context::schedule( double when, const NodeRef &node, bool enable, const std::function<void ()> &func )
{
	const uint64_t framesPerBlock = (uint64_t)getFramesPerBlock();
	uint64_t eventFrameThreshold = timeToFrame( when, getSampleRate() );

	// Place the threshold back one block so we can process the block first, guarding against wrap around
	if( eventFrameThreshold >= framesPerBlock )
		eventFrameThreshold -= framesPerBlock;

	lock_guard<mutex> lock( mMutex );
	mScheduledEvents.push_back( ScheduledEvent( eventFrameThreshold, node, enable, func ) );
}
示例#6
0
void Context::scheduleEvent( double when, const NodeRef &node, bool callFuncBeforeProcess, const std::function<void ()> &func )
{
	const uint64_t framesPerBlock = (uint64_t)getFramesPerBlock();
	uint64_t eventFrameThreshold = std::max( mNumProcessedFrames.load(), timeToFrame( when, static_cast<double>( getSampleRate() ) ) );

	// Place the threshold back one block so we can process the block first, guarding against wrap around
	if( eventFrameThreshold >= framesPerBlock )
		eventFrameThreshold -= framesPerBlock;

	// TODO: support multiple events, at the moment only supporting one per node.
	if( node->mEventScheduled ) {
		cancelScheduledEvents( node );
	}

	lock_guard<mutex> lock( mMutex );
	node->mEventScheduled = true;
	mScheduledEvents.push_back( ScheduledEvent( eventFrameThreshold, node, callFuncBeforeProcess, func ) );
}
/******************************************************************************
* Converts a time value to its string representation.
******************************************************************************/
QString AnimationSettings::timeToString(TimePoint time)
{
	return QString::number(timeToFrame(time));
}