Skip to content
This repository was archived by the owner on Jun 27, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion include/cinder/app/AppBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,25 @@ class AppBase {
virtual void setFullScreen( bool fullScreen, const FullScreenOptions &options = FullScreenOptions() ) { getWindow()->setFullScreen( fullScreen, options ); }

//! Returns the number of seconds which have elapsed since application launch
double getElapsedSeconds() const { return mTimer.getSeconds(); }
//double getElapsedSeconds() const { return mTimer.getSeconds(); }
double getTrueElapsedSeconds() const { return mTimer.getSeconds(); }
double getElapsedSeconds() const {
return mDoPlaybackForCapture ? mFrameCount / mCaptureFrameRate : mTimer.getSeconds();
}
//! Returns the number of animation frames which have elapsed since application launch
uint32_t getElapsedFrames() const { return mFrameCount; }

void setPlaybackForCapture ( bool doPlaybackForCapture ) {
mDoPlaybackForCapture = doPlaybackForCapture;
mFpsLastSampleTime = getElapsedSeconds();
mFpsLastSampleFrame = mFrameCount;
}
float getCaptureFrameRate() const { return mCaptureFrameRate; }
void setCaptureFrameRate( float frameRate ) { mCaptureFrameRate = frameRate; }

float getPlaybackFrameRate() const {
return mDoPlaybackForCapture ? mCaptureFrameRate : getFrameRate();
}

//! Returns whether the app is registered to receive multiTouch events from the operating system, configurable via Settings at startup. Disabled by default on desktop platforms, enabled on mobile.
bool isMultiTouchEnabled() const { return mMultiTouchEnabled; }
Expand Down Expand Up @@ -438,6 +454,9 @@ class AppBase {
double mFpsSampleInterval;
bool mMultiTouchEnabled, mHighDensityDisplayEnabled;
RendererRef mDefaultRenderer;

bool mDoPlaybackForCapture;
float mCaptureFrameRate;

std::vector<std::string> mCommandLineArgs;
std::shared_ptr<Timeline> mTimeline;
Expand Down Expand Up @@ -495,6 +514,8 @@ inline Area getWindowBounds() { return AppBase::get()->getWindowBounds(); }
inline float getWindowContentScale() { return AppBase::get()->getWindowContentScale(); }
//! Returns the maximum frame-rate the active App will attempt to maintain.
inline float getFrameRate() { return AppBase::get()->getFrameRate(); }
//! Returns the current frame rate setting - either real-time or capture mode
inline float getPlaybackFrameRate() { return AppBase::get()->getPlaybackFrameRate(); }
//! Sets the maximum frame-rate the active App will attempt to maintain.
inline void setFrameRate( float frameRate ) { AppBase::get()->setFrameRate( frameRate ); }
//! Returns whether the active App is in full-screen mode or not.
Expand Down
4 changes: 2 additions & 2 deletions include/cinder/qtime/QuickTimeImplAvf.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ class MovieBase {
//! Sets whether the movie is set to loop during playback. If \a palindrome is true, the movie will "ping-pong" back and forth
void setLoop( bool loop = true, bool palindrome = false );
//! Advances the movie by one frame (a single video sample). Ignores looping settings.
bool stepForward();
bool stepForward( int frms = 1 );
//! Steps backward by one frame (a single video sample). Ignores looping settings.
bool stepBackward();
bool stepBackward( int frms = 1 );
/** Sets the playback rate, which begins playback immediately for nonzero values.
* 1.0 represents normal speed. Negative values indicate reverse playback and \c 0 stops.
*
Expand Down
4 changes: 3 additions & 1 deletion src/cinder/TimelineItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ void TimelineItem::stepTo( float newTime, bool reverse )
complete( true );
}
}
else if( ( ! mLoop ) && ( ! mInfinite ) ) { // newTime >= endTime
// CB - I've fixed this bug before
//else if( ( ! mLoop ) && ( ! mInfinite ) ) { // newTime >= endTime
else if( ( ! mLoop ) && ( ! mInfinite ) && ( ! mPingPong ) ) { // newTime >= endTime
if( ( ! mComplete ) && ( ! reverse ) ) {
mComplete = true;
mReverseComplete = false;
Expand Down
18 changes: 13 additions & 5 deletions src/cinder/app/AppBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ void AppBase::Settings::setShouldQuit( bool shouldQuit )

AppBase::AppBase()
: mFrameCount( 0 ), mAverageFps( 0 ), mFpsSampleInterval( 1 ), mTimer( true ), mTimeline( Timeline::create() ),
mFpsLastSampleFrame( 0 ), mFpsLastSampleTime( 0 )
mFpsLastSampleFrame( 0 ), mFpsLastSampleTime( 0 ),
mDoPlaybackForCapture( false ), mCaptureFrameRate( 30 )
{
sInstance = this;

Expand Down Expand Up @@ -155,6 +156,7 @@ void AppBase::privateSetup__()
setup();
}

// this is the central update() call in the application
void AppBase::privateUpdate__()
{
mFrameCount++;
Expand All @@ -170,16 +172,22 @@ void AppBase::privateUpdate__()

mSignalUpdate.emit();

update();
update(); // call <ourApp>::update()

// mTimer is used only here and in getElapsedSeconds()
// mFrameRate defaults to 60.0f, used in startAnimationTimer() to create a timer which fires at the frame rate
// mCaptureFrameRate defaults to 30.0f since that's what works best for quicktime videos
double now = getElapsedSeconds();

mTimeline->stepTo( static_cast<float>( getElapsedSeconds() ) );
// update master timeline - not sure why this is done after update()
mTimeline->stepTo( static_cast<float>( now ) );

double now = mTimer.getSeconds();
// update FPS statistics
// mFpsSampleInterval == 1.0 secs by default
if( now > mFpsLastSampleTime + mFpsSampleInterval ) {
//calculate average Fps over sample interval
uint32_t framesPassed = mFrameCount - mFpsLastSampleFrame;
mAverageFps = (float)(framesPassed / (now - mFpsLastSampleTime));

mFpsLastSampleTime = now;
mFpsLastSampleFrame = mFrameCount;
}
Expand Down
10 changes: 6 additions & 4 deletions src/cinder/qtime/QuickTimeImplAvf.mm
Original file line number Diff line number Diff line change
Expand Up @@ -367,28 +367,30 @@ - (void)outputSequenceWasFlushed:(AVPlayerItemOutput *)output
mPalindrome = (loop? palindrome: false);
}

bool MovieBase::stepForward()
bool MovieBase::stepForward( int frms /* = 1 */ )
{
if( ! mPlayerItem )
return false;

bool can_step_forwards = [mPlayerItem canStepForward];
if( can_step_forwards ) {
[mPlayerItem stepByCount:1];
//[mPlayerItem stepByCount:1];
[mPlayerItem stepByCount:frms];
}

return can_step_forwards;
}

bool MovieBase::stepBackward()
bool MovieBase::stepBackward( int frms /* = 1 */ )
{
if( ! mPlayerItem)
return false;

bool can_step_backwards = [mPlayerItem canStepBackward];

if (can_step_backwards) {
[mPlayerItem stepByCount:-1];
//[mPlayerItem stepByCount:-1];
[mPlayerItem stepByCount:-frms];
}

return can_step_backwards;
Expand Down