f@5
|
1 /*
|
f@5
|
2
|
f@5
|
3 Copyright (C) 2015 Fiore Martin
|
f@5
|
4 Copyright (C) 2016 Queen Mary University of London
|
f@5
|
5 Author: Fiore Martin
|
f@5
|
6
|
f@5
|
7 This file is part of Collidoscope.
|
f@5
|
8
|
f@5
|
9 Collidoscope is free software: you can redistribute it and/or modify
|
f@5
|
10 it under the terms of the GNU General Public License as published by
|
f@5
|
11 the Free Software Foundation, either version 3 of the License, or
|
f@5
|
12 (at your option) any later version.
|
f@5
|
13
|
f@5
|
14 This program is distributed in the hope that it will be useful,
|
f@5
|
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
f@5
|
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
f@5
|
17 GNU General Public License for more details.
|
f@5
|
18
|
f@5
|
19 You should have received a copy of the GNU General Public License
|
f@5
|
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
|
f@5
|
21
|
f@5
|
22 */
|
f@5
|
23
|
f@5
|
24
|
f@0
|
25 #include "Chunk.h"
|
f@0
|
26 #include "DrawInfo.h"
|
f@0
|
27
|
f@0
|
28
|
f@0
|
29 #include "cinder/gl/gl.h"
|
f@0
|
30
|
f@0
|
31
|
f@0
|
32 Chunk::Chunk( size_t index ) :
|
f@0
|
33 mIndex( index ),
|
f@0
|
34 mAudioTop(0.0f),
|
f@0
|
35 mAudioBottom(0.0f)
|
f@0
|
36 {}
|
f@0
|
37
|
f@0
|
38
|
f@0
|
39 void update( const DrawInfo& di )
|
f@0
|
40 {
|
f@0
|
41
|
f@0
|
42 }
|
f@0
|
43
|
f@0
|
44 void Chunk::update( const DrawInfo &di )
|
f@0
|
45 {
|
f@0
|
46 using namespace ci;
|
f@16
|
47 /* if resetting animate the chunks to nicely shrink to 0 size */
|
f@0
|
48 if ( mResetting ){
|
f@0
|
49 if ( mAnimate > 0.0f ){
|
f@0
|
50 mAnimate -= 0.1f;
|
f@0
|
51 if ( mAnimate <= 0.0f ){
|
f@0
|
52 mAnimate = 0.0f;
|
f@0
|
53 mResetting = false;
|
f@0
|
54 mAudioTop = 0.0f;
|
f@0
|
55 mAudioBottom = 0.0f;
|
f@0
|
56 }
|
f@0
|
57 }
|
f@0
|
58 }
|
f@0
|
59 /* animate makes the chunks pop nicely when they are created */
|
f@0
|
60 else if ( mAnimate < 1.0f ){
|
f@0
|
61 mAnimate += 0.3333f; // in three (namely 1/0.333) steps
|
f@0
|
62 if ( mAnimate > 1.0f ){ // clip to one
|
f@0
|
63 mAnimate = 1.0f;
|
f@0
|
64 }
|
f@0
|
65 }
|
f@0
|
66
|
f@16
|
67 mX = di.flipX( 1 + (mIndex * (2 + kWidth)) ); // FIXME more efficient if it happens only once when resized
|
f@0
|
68 }
|
f@0
|
69
|
f@0
|
70 void Chunk::draw( const DrawInfo& di, ci::gl::BatchRef &batch ){
|
f@0
|
71 using namespace ci;
|
f@5
|
72
|
f@0
|
73 gl::pushModelMatrix();
|
f@0
|
74
|
f@0
|
75 const float chunkHeight = mAnimate * mAudioTop * di.getMaxChunkHeight();
|
f@0
|
76
|
f@16
|
77 // place the chunk in the right position brings back the y of chunkHeight/2 so
|
f@0
|
78 // so that after scaling the wave is still centered at the wave center
|
f@0
|
79 gl::translate( mX, di.getWaveCenterY() - ( chunkHeight / 2 ) - 1 );
|
f@0
|
80
|
f@0
|
81 // scale according to audio amplitude
|
f@0
|
82 gl::scale( 1.0f, chunkHeight );
|
f@0
|
83 batch->draw();
|
f@0
|
84
|
f@0
|
85
|
f@0
|
86 gl::popModelMatrix();
|
f@0
|
87 }
|
f@0
|
88
|
f@0
|
89
|
f@0
|
90 void Chunk::drawBar( const DrawInfo& di, ci::gl::BatchRef &batch ){
|
f@5
|
91 using namespace ci;
|
f@0
|
92
|
f@0
|
93 gl::pushModelMatrix();
|
f@0
|
94
|
f@0
|
95 const float barHeight = di.getSelectionBarHeight();
|
f@0
|
96
|
f@0
|
97 gl::translate( mX, di.getWaveCenterY() - ( barHeight / 2 ) - 1 );
|
f@0
|
98 gl::scale( 1.0f, barHeight );
|
f@0
|
99
|
f@0
|
100 batch->draw();
|
f@0
|
101
|
f@0
|
102 gl::popModelMatrix();
|
f@0
|
103 }
|
f@0
|
104
|
f@0
|
105
|
f@0
|
106 const float Chunk::kWidth = 7.0f;
|
f@5
|
107 const float Chunk::kHalfWidth = 3.5f;
|