f@0: #include "Chunk.h" f@0: #include "DrawInfo.h" f@0: f@0: f@0: #include "cinder/gl/gl.h" f@0: f@0: f@0: Chunk::Chunk( size_t index ) : f@0: mIndex( index ), f@0: mAudioTop(0.0f), f@0: mAudioBottom(0.0f) f@0: {} f@0: f@0: f@0: void update( const DrawInfo& di ) f@0: { f@0: f@0: } f@0: f@0: void Chunk::update( const DrawInfo &di ) f@0: { f@0: using namespace ci; f@0: /* if resetting animate the chunks to shrink to 0 size */ f@0: if ( mResetting ){ f@0: if ( mAnimate > 0.0f ){ f@0: mAnimate -= 0.1f; f@0: if ( mAnimate <= 0.0f ){ f@0: mAnimate = 0.0f; f@0: mResetting = false; f@0: mAudioTop = 0.0f; f@0: mAudioBottom = 0.0f; f@0: } f@0: } f@0: } f@0: /* animate makes the chunks pop nicely when they are created */ f@0: else if ( mAnimate < 1.0f ){ f@0: mAnimate += 0.3333f; // in three (namely 1/0.333) steps f@0: if ( mAnimate > 1.0f ){ // clip to one f@0: mAnimate = 1.0f; f@0: } f@0: } f@0: f@0: mX = di.flipX( 1 + (mIndex * (2 + kWidth)) ); // FIXME this should happen only once when resized f@0: } f@0: f@0: void Chunk::draw( const DrawInfo& di, ci::gl::BatchRef &batch ){ f@0: using namespace ci; f@0: f@0: gl::pushModelMatrix(); f@0: f@0: const float chunkHeight = mAnimate * mAudioTop * di.getMaxChunkHeight(); f@0: f@0: // place the chunk in the right position brigns back the y of chunkHeight/2 so f@0: // so that after scaling the wave is still centered at the wave center f@0: gl::translate( mX, di.getWaveCenterY() - ( chunkHeight / 2 ) - 1 ); f@0: f@0: // FIXME todo use max between top and bottom f@0: // scale according to audio amplitude f@0: gl::scale( 1.0f, chunkHeight ); f@0: batch->draw(); f@0: f@0: f@0: gl::popModelMatrix(); f@0: } f@0: f@0: f@0: void Chunk::drawBar( const DrawInfo& di, ci::gl::BatchRef &batch ){ f@0: using namespace ci; f@0: f@0: gl::pushModelMatrix(); f@0: f@0: const float barHeight = di.getSelectionBarHeight(); f@0: f@0: gl::translate( mX, di.getWaveCenterY() - ( barHeight / 2 ) - 1 ); f@0: gl::scale( 1.0f, barHeight ); f@0: f@0: batch->draw(); f@0: f@0: gl::popModelMatrix(); f@0: } f@0: f@0: f@0: const float Chunk::kWidth = 7.0f; f@0: const float Chunk::kHalfWidth = 3.5f;