f@0
|
1 #pragma once
|
f@0
|
2
|
f@0
|
3
|
f@0
|
4 #include "cinder/app/App.h"
|
f@0
|
5 #include "cinder/gl/gl.h"
|
f@0
|
6 #include "cinder/gl/Batch.h"
|
f@0
|
7
|
f@0
|
8
|
f@0
|
9 #include "Chunk.h"
|
f@0
|
10 #include "DrawInfo.h"
|
f@0
|
11
|
f@0
|
12 #ifdef USE_PARTICLES
|
f@0
|
13 #include "ParticleController.h"
|
f@0
|
14 #endif
|
f@0
|
15
|
f@0
|
16 #include "cinder/Color.h"
|
f@0
|
17 #include "cinder/PolyLine.h"
|
f@0
|
18 #include "cinder/Rand.h"
|
f@0
|
19
|
f@0
|
20 #include <vector>
|
f@0
|
21 #include <map>
|
f@0
|
22
|
f@0
|
23
|
f@0
|
24 class DrawInfo;
|
f@0
|
25 typedef int SynthID;
|
f@0
|
26
|
f@0
|
27
|
f@0
|
28 using ci::ivec2;
|
f@0
|
29 using ci::vec2;
|
f@0
|
30 using ci::Color;
|
f@0
|
31 using ci::ColorA;
|
f@0
|
32
|
f@0
|
33 struct Cursor {
|
f@0
|
34 static const int kNoPosition = -100;
|
f@0
|
35 int pos;
|
f@0
|
36 double lastUpdate;
|
f@0
|
37 };
|
f@0
|
38
|
f@0
|
39
|
f@0
|
40 class Wave
|
f@0
|
41 {
|
f@0
|
42 friend class ParticleController;
|
f@0
|
43
|
f@0
|
44 public:
|
f@0
|
45
|
f@0
|
46 class Selection {
|
f@0
|
47
|
f@0
|
48 public:
|
f@0
|
49
|
f@0
|
50 Selection( Wave * w, Color color );
|
f@0
|
51
|
f@0
|
52 void setStart( size_t start );
|
f@0
|
53
|
f@0
|
54 void setSize( size_t size );
|
f@0
|
55
|
f@0
|
56 void inline setParticleSpread( float spread ){
|
f@0
|
57 mParticleSpread = spread;
|
f@0
|
58 }
|
f@0
|
59
|
f@0
|
60 size_t getStart(void) const { return mSelectionStart; }
|
f@0
|
61
|
f@0
|
62 size_t getEnd(void) const { return mSelectionEnd; }
|
f@0
|
63
|
f@0
|
64 size_t inline getSize(void) const {
|
f@0
|
65 if (mNull)
|
f@0
|
66 return 0;
|
f@0
|
67 else
|
f@0
|
68 return 1 + mSelectionEnd - mSelectionStart;
|
f@0
|
69 }
|
f@0
|
70
|
f@0
|
71 float inline getParticleSpread() const { return mParticleSpread; }
|
f@0
|
72
|
f@0
|
73 inline void setToNull(){
|
f@0
|
74 mParticleSpread = 1.0f;
|
f@0
|
75 mNull = true;
|
f@0
|
76 }
|
f@0
|
77
|
f@0
|
78 inline bool isNull() const{
|
f@0
|
79 return mNull;
|
f@0
|
80 }
|
f@0
|
81
|
f@0
|
82 inline const Color & getColor() const{
|
f@0
|
83 return mColor;
|
f@0
|
84 }
|
f@0
|
85
|
f@0
|
86 private:
|
f@0
|
87
|
f@0
|
88 size_t mSelectionStart;
|
f@0
|
89
|
f@0
|
90 size_t mSelectionEnd;
|
f@0
|
91
|
f@0
|
92 float mParticleSpread;
|
f@0
|
93
|
f@0
|
94 bool mNull = true;
|
f@0
|
95
|
f@0
|
96 Color mColor;
|
f@0
|
97
|
f@0
|
98 Wave * mWave;
|
f@0
|
99
|
f@0
|
100 }; // class Selection
|
f@0
|
101
|
f@0
|
102
|
f@0
|
103
|
f@0
|
104 #ifdef USE_PARTICLES
|
f@0
|
105 ParticleController mParticleController;
|
f@0
|
106 #endif
|
f@0
|
107
|
f@0
|
108
|
f@0
|
109
|
f@0
|
110 /* there is one cursor for each Synth being played */
|
f@0
|
111 std::map < SynthID, Cursor > mCursors;
|
f@0
|
112 std::vector<int> mCursorsPos;
|
f@0
|
113
|
f@0
|
114 public:
|
f@0
|
115
|
f@0
|
116 // note used to identify the loop for cursor position
|
f@0
|
117 static const int kLoopNote = -1;
|
f@0
|
118 static const cinder::Color CURSOR_CLR;
|
f@0
|
119 /* must be in sync with supercollider durationFactor ControlSpec max */
|
f@0
|
120 static const int MAX_DURATION = 8;
|
f@0
|
121 #ifdef USE_PARTICLES
|
f@0
|
122 static const int PARTICLESIZE_COEFF = 40;
|
f@0
|
123 #endif
|
f@0
|
124
|
f@0
|
125 void reset(bool onlyChunks);
|
f@0
|
126
|
f@0
|
127 void setChunk(size_t index, float bottom, float top);
|
f@0
|
128
|
f@0
|
129 const Chunk & getChunk(size_t index);
|
f@0
|
130
|
f@0
|
131 inline void setCursorPos( SynthID id, int pos, const DrawInfo& di ){
|
f@0
|
132
|
f@0
|
133 Cursor & cursor = mCursors[id];
|
f@0
|
134 cursor.pos = pos;
|
f@0
|
135 cursor.lastUpdate = ci::app::getElapsedSeconds();
|
f@0
|
136
|
f@0
|
137 #ifdef USE_PARTICLES
|
f@0
|
138 /* if the duration is greater than 1.0 carry on the cursor as a particle
|
f@0
|
139 the smaller the selection the more particles
|
f@0
|
140 the bigger the duration the more particles */
|
f@0
|
141 if (mSelection.getParticleSpread() > 1.0f){
|
f@0
|
142 /* amountCoeff ranges from 1/8 to 1 */
|
f@0
|
143 const float amountCoeff = (mSelection.getParticleSpread() / MAX_DURATION);
|
f@0
|
144
|
f@0
|
145 /* get radom point within seleciton as center of the particle */
|
f@0
|
146 vec2 centrePoint; // was former getRandomPoint
|
f@0
|
147 const int randomChunkIndex = ci::Rand::randInt(mSelection.getStart(), mSelection.getEnd() );
|
f@0
|
148
|
f@0
|
149 centrePoint.x = di.flipX( 1 + (randomChunkIndex * (2 + Chunk::kWidth)) + Chunk::kWidth / 2 );
|
f@0
|
150 centrePoint.y = di.flipY( di.audioToHeigt(0.0) );
|
f@0
|
151
|
f@0
|
152 const float wavePixelLen = mNumChunks * ( 2 + Chunk::kWidth);
|
f@0
|
153 centrePoint.x *= float(di.getWindowWidth()) / wavePixelLen;
|
f@0
|
154
|
f@0
|
155 mParticleController.addParticles(
|
f@0
|
156 std::max( 1, (int)(amountCoeff * ParticleController::kMaxParticleAdd * mFilterCoeff) ), // amount of particles to add
|
f@0
|
157 centrePoint,
|
f@0
|
158 mSelection.getParticleSpread() * PARTICLESIZE_COEFF // size of the cloud
|
f@0
|
159 );
|
f@0
|
160 }
|
f@0
|
161 #endif
|
f@0
|
162
|
f@0
|
163
|
f@0
|
164 }
|
f@0
|
165
|
f@0
|
166 void update( double secondsPerChunk, const DrawInfo& di );
|
f@0
|
167
|
f@0
|
168 void removeCursor( SynthID id ) { mCursors.erase( id ); }
|
f@0
|
169
|
f@0
|
170 // parameter ranges from 0 to 1
|
f@0
|
171 inline void setselectionAlpha(float alpha){ mFilterCoeff = alpha;}
|
f@0
|
172
|
f@0
|
173 void draw( const DrawInfo& di );
|
f@0
|
174
|
f@0
|
175 Selection& getSelection() { return mSelection; };
|
f@0
|
176
|
f@0
|
177 size_t getSize() const{ return mChunks.size(); }
|
f@0
|
178
|
f@0
|
179 void setScopePoint(int index, float audioVal);
|
f@0
|
180
|
f@0
|
181 Wave( size_t numChunks, Color selectionColor );
|
f@0
|
182
|
f@0
|
183 // no copies
|
f@0
|
184 Wave( const Wave © ) = delete;
|
f@0
|
185 Wave & operator=(const Wave ©) = delete;
|
f@0
|
186
|
f@0
|
187
|
f@0
|
188 private:
|
f@0
|
189
|
f@0
|
190 const size_t mNumChunks;
|
f@0
|
191
|
f@0
|
192 std::vector<Chunk> mChunks;
|
f@0
|
193
|
f@0
|
194 Selection mSelection;
|
f@0
|
195
|
f@0
|
196 cinder::Color mColor;
|
f@0
|
197
|
f@0
|
198 float mFilterCoeff;
|
f@0
|
199
|
f@0
|
200 ci::gl::BatchRef mChunkBatch;
|
f@0
|
201
|
f@0
|
202 };
|
f@0
|
203
|