f@5: /* f@5: f@5: Copyright (C) 2015 Fiore Martin f@5: Copyright (C) 2016 Queen Mary University of London f@5: Author: Fiore Martin f@5: f@5: This file is part of Collidoscope. f@5: f@5: Collidoscope is free software: you can redistribute it and/or modify f@5: it under the terms of the GNU General Public License as published by f@5: the Free Software Foundation, either version 3 of the License, or f@5: (at your option) any later version. f@5: f@5: This program is distributed in the hope that it will be useful, f@5: but WITHOUT ANY WARRANTY; without even the implied warranty of f@5: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the f@5: GNU General Public License for more details. f@5: f@5: You should have received a copy of the GNU General Public License f@5: along with this program. If not, see . f@5: f@5: */ f@5: f@5: 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@16: /* if resetting animate the chunks to nicely 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@16: mX = di.flipX( 1 + (mIndex * (2 + kWidth)) ); // FIXME more efficient if it happens 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@5: f@0: gl::pushModelMatrix(); f@0: f@0: const float chunkHeight = mAnimate * mAudioTop * di.getMaxChunkHeight(); f@0: f@16: // place the chunk in the right position brings 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: // 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@5: 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@5: const float Chunk::kHalfWidth = 3.5f;