コード例 #1
0
ファイル: Context.cpp プロジェクト: ChristophPacher/Cinder
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 ) );
}
コード例 #2
0
ファイル: Context.cpp プロジェクト: martinfm/Cinder
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 ) );
}