void SamplePlayerNodeTestApp::update() { // light up rects if an xrun was detected const float xrunFadeTime = 1.3f; auto filePlayer = dynamic_pointer_cast<audio::FilePlayerNode>( mSamplePlayerNode ); if( filePlayer ) { if( filePlayer->getLastUnderrun() ) timeline().apply( &mUnderrunFade, 1.0f, 0.0f, xrunFadeTime ); if( filePlayer->getLastOverrun() ) timeline().apply( &mOverrunFade, 1.0f, 0.0f, xrunFadeTime ); } // print SamplePlayerNode start / stop times if( mSamplePlayerNodeEnabledState != mSamplePlayerNode->isEnabled() ) { mSamplePlayerNodeEnabledState = mSamplePlayerNode->isEnabled(); string stateStr = mSamplePlayerNodeEnabledState ? "started" : "stopped"; CI_LOG_V( "mSamplePlayerNode " << stateStr << " at " << to_string( getElapsedSeconds() ) << ", isEof: " << boolalpha << mSamplePlayerNode->isEof() << dec ); } bool testIsRecorder = ( mTestSelector.currentSection() == "recorder" ); mRecordButton.mHidden = mWriteButton.mHidden = mAutoResizeButton.mHidden = ! testIsRecorder; // test auto resizing the Recorder's buffer depending on how full it is if( testIsRecorder && mAutoResizeButton.mEnabled ) { CI_ASSERT( mRecorder ); size_t writePos = mRecorder->getWritePosition(); size_t numFrames = mRecorder->getNumFrames(); if( writePos + mRecorder->getSampleRate() / 2 > numFrames ) { size_t resizeFrames = numFrames + mRecorder->getSampleRate(); CI_LOG_V( "writePos: " << writePos << ", numFrames: " << numFrames << ", resizing frames to: " << resizeFrames ); mRecorder->setNumFrames( resizeFrames ); } if( mRecorder->getLastOverrun() ) timeline().apply( &mRecorderOverrunFade, 1.0f, 0.0f, xrunFadeTime ); } }
void SamplePlayerNodeTestApp::processTap( ivec2 pos ) { if( mEnableSamplePlayerNodeButton.hitTest( pos ) ) mSamplePlayerNode->setEnabled( ! mSamplePlayerNode->isEnabled() ); else if( mStartPlaybackButton.hitTest( pos ) ) triggerStartStop( true ); else if( mStopPlaybackButton.hitTest( pos ) ) triggerStartStop( false ); else if( mLoopButton.hitTest( pos ) ) mSamplePlayerNode->setLoopEnabled( ! mSamplePlayerNode->isLoopEnabled() ); else if( mRecordButton.hitTest( pos ) ) { if( mRecordButton.mEnabled ) mRecorder->start(); else mRecorder->disable(); } else if( mWriteButton.hitTest( pos ) ) writeRecordedToFile(); else if( mAutoResizeButton.hitTest( pos ) ) ; else if( mAsyncButton.hitTest( pos ) ) ; else if( pos.y > getWindowCenter().y ) seek( pos.x ); size_t currentIndex = mTestSelector.mCurrentSectionIndex; if( mTestSelector.hitTest( pos ) && currentIndex != mTestSelector.mCurrentSectionIndex ) { string currentTest = mTestSelector.currentSection(); CI_LOG_V( "selected: " << currentTest ); if( currentTest == "BufferPlayerNode" ) setupBufferPlayerNode(); if( currentTest == "FilePlayerNode" ) setupFilePlayerNode(); if( currentTest == "recorder" ) setupBufferRecorderNode(); } }