comparison CollidoscopeApp/include/Wave.h @ 5:75b744078d66

added license
author Fiore Martin <f.martin@qmul.ac.uk>
date Wed, 13 Jul 2016 16:06:46 +0200
parents 7fb593d53361
children a4a336624f5a
comparison
equal deleted inserted replaced
4:ab6db404403a 5:75b744078d66
1 /*
2
3 Copyright (C) 2015 Fiore Martin
4 Copyright (C) 2016 Queen Mary University of London
5 Author: Fiore Martin
6
7 This file is part of Collidoscope.
8
9 Collidoscope is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
21
22 */
1 #pragma once 23 #pragma once
2 24
3 25
4 #include "cinder/app/App.h" 26 #include "cinder/app/App.h"
5 #include "cinder/gl/gl.h" 27 #include "cinder/gl/gl.h"
43 * Collidoscope's graphical wave 65 * Collidoscope's graphical wave
44 * 66 *
45 */ 67 */
46 class Wave 68 class Wave
47 { 69 {
48 friend class ParticleController; 70 friend class ParticleController;
49 71
50 public: 72 public:
51 73
52 /** 74 /**
53 * The selection of the wave that is controlled by the big horizontal knob 75 * The selection of the wave that is controlled by the big horizontal knob
54 * 76 *
55 */ 77 */
56 class Selection { 78 class Selection {
57 79
58 public: 80 public:
59 81
60 Selection( Wave * w, Color color ); 82 Selection( Wave * w, Color color );
61 83
62 /** Sets the start of selection. start is the index of the first chunk of the selection */ 84 /** Sets the start of selection. start is the index of the first chunk of the selection */
63 void setStart( size_t start ); 85 void setStart( size_t start );
64 86
65 /** Sets the size of selection. size is the number of chunks the selection is made of */ 87 /** Sets the size of selection. size is the number of chunks the selection is made of */
66 void setSize( size_t size ); 88 void setSize( size_t size );
67 89
68 /** Particle spread is used to calculate the size of the cloud of particles */ 90 /** Particle spread is used to calculate the size of the cloud of particles */
69 void inline setParticleSpread( float spread ){ 91 void inline setParticleSpread( float spread ){
70 mParticleSpread = spread; 92 mParticleSpread = spread;
71 } 93 }
72 94
73 size_t getStart(void) const { return mSelectionStart; } 95 size_t getStart(void) const { return mSelectionStart; }
74 96
75 size_t getEnd(void) const { return mSelectionEnd; } 97 size_t getEnd(void) const { return mSelectionEnd; }
76 98
77 size_t inline getSize(void) const { 99 size_t inline getSize(void) const {
78 if (mNull) 100 if (mNull)
79 return 0; 101 return 0;
80 else 102 else
81 return 1 + mSelectionEnd - mSelectionStart; 103 return 1 + mSelectionEnd - mSelectionStart;
82 } 104 }
83 105
84 float inline getParticleSpread() const { return mParticleSpread; } 106 float inline getParticleSpread() const { return mParticleSpread; }
85 107
86 /** When selection is null no selection is showed on the wave */ 108 /** When selection is null no selection is showed on the wave */
87 inline void setToNull(){ 109 inline void setToNull(){
88 mParticleSpread = 1.0f; 110 mParticleSpread = 1.0f;
89 mNull = true; 111 mNull = true;
90 } 112 }
91 113
92 inline bool isNull() const{ 114 inline bool isNull() const{
93 return mNull; 115 return mNull;
94 } 116 }
95 117
96 inline const Color & getColor() const{ 118 inline const Color & getColor() const{
97 return mColor; 119 return mColor;
98 } 120 }
99 121
100 private: 122 private:
101 123
102 size_t mSelectionStart; 124 size_t mSelectionStart;
103 125
109 131
110 Color mColor; 132 Color mColor;
111 133
112 Wave * mWave; 134 Wave * mWave;
113 135
114 }; // class Selection 136 }; // class Selection
115 137
116 138
117 139
118 #ifdef USE_PARTICLES 140 #ifdef USE_PARTICLES
119 ParticleController mParticleController; 141 ParticleController mParticleController;
120 #endif 142 #endif
121 143
122 144
123 145
124 /* Maps id of the synth to cursor. There is one cursor for each Synth being played */ 146 /* Maps id of the synth to cursor. There is one cursor for each Synth being played */
125 std::map < SynthID, Cursor > mCursors; 147 std::map < SynthID, Cursor > mCursors;
126 /** Holds the positions of the cursor, namely on which chunk the cursor is currently */ 148 /** Holds the positions of the cursor, namely on which chunk the cursor is currently */
127 std::vector<int> mCursorsPos; 149 std::vector<int> mCursorsPos;
128 150
129 public: 151 public:
130 152
131 // value used to identify the loop for cursor position 153 // value used to identify the loop for cursor position
132 static const int kLoopNote = -1; 154 static const int kLoopNote = -1;
133 static const cinder::Color CURSOR_CLR; 155 static const cinder::Color CURSOR_CLR;
134 /* must be in sync with supercollider durationFactor ControlSpec max */ 156 /* must be in sync with supercollider durationFactor ControlSpec max */
135 static const int MAX_DURATION = 8; 157 static const int MAX_DURATION = 8;
136 #ifdef USE_PARTICLES 158 #ifdef USE_PARTICLES
137 static const int PARTICLESIZE_COEFF = 40; 159 static const int PARTICLESIZE_COEFF = 40;
138 #endif 160 #endif
139 161
140 /** Resetting a wave makes it shrink until it disappears. Each time a new sample is recorder the wave is reset 162 /** Resetting a wave makes it shrink until it disappears. Each time a new sample is recorder the wave is reset
141 * \param onlyChunks if false the selection is also set to null, if true only the chunks are reset 163 * \param onlyChunks if false the selection is also set to null, if true only the chunks are reset
142 */ 164 */
143 void reset(bool onlyChunks); 165 void reset(bool onlyChunks);
144 166
145 /** sets top and bottom values for the chunk. 167 /** sets top and bottom values for the chunk.
146 * \a bottom and \a top are in audio coordinates [-1.0, 1.0] 168 * \a bottom and \a top are in audio coordinates [-1.0, 1.0]
147 */ 169 */
148 void setChunk(size_t index, float bottom, float top); 170 void setChunk(size_t index, float bottom, float top);
149 171
150 const Chunk & getChunk(size_t index); 172 const Chunk & getChunk(size_t index);
151 173
152 /** places the cursor on the wave. Every cursor is associated to a synth voice of the audio engine. 174 /** places the cursor on the wave. Every cursor is associated to a synth voice of the audio engine.
153 * The synth id identifies uniquely the cursor in the internal map of the wave. 175 * The synth id identifies uniquely the cursor in the internal map of the wave.
154 * If the cursor doesn't exist it is created */ 176 * If the cursor doesn't exist it is created */
155 inline void setCursorPos( SynthID id, int pos, const DrawInfo& di ){ 177 inline void setCursorPos( SynthID id, int pos, const DrawInfo& di ){
156 178
157 Cursor & cursor = mCursors[id]; 179 Cursor & cursor = mCursors[id];
158 cursor.pos = pos; 180 cursor.pos = pos;
159 cursor.lastUpdate = ci::app::getElapsedSeconds(); 181 cursor.lastUpdate = ci::app::getElapsedSeconds();
160 182
161 #ifdef USE_PARTICLES 183 #ifdef USE_PARTICLES
162 // The idea is that, if the duration is greater than 1.0, the cursor continues in form of particles 184 // The idea is that, if the duration is greater than 1.0, the cursor continues in form of particles
163 // The smaller the selection the more particles; the bigger the duration the more particles 185 // The smaller the selection the more particles; the bigger the duration the more particles
164 if (mSelection.getParticleSpread() > 1.0f){ 186 if (mSelection.getParticleSpread() > 1.0f){
165 /* amountCoeff ranges from 1/8 to 1 */ 187 /* amountCoeff ranges from 1/8 to 1 */
166 const float amountCoeff = (mSelection.getParticleSpread() / MAX_DURATION); 188 const float amountCoeff = (mSelection.getParticleSpread() / MAX_DURATION);
167 189
168 /* get radom point within seleciton as center of the particle */ 190 /* get radom point within seleciton as center of the particle */
169 vec2 centrePoint; // was former getRandomPoint 191 vec2 centrePoint; // was former getRandomPoint
170 const int randomChunkIndex = ci::Rand::randInt(mSelection.getStart(), mSelection.getEnd() ); 192 const int randomChunkIndex = ci::Rand::randInt(mSelection.getStart(), mSelection.getEnd() );
171 193
172 centrePoint.x = di.flipX( 1 + (randomChunkIndex * (2 + Chunk::kWidth)) + Chunk::kWidth / 2 ); 194 centrePoint.x = di.flipX( 1 + (randomChunkIndex * (2 + Chunk::kWidth)) + Chunk::kWidth / 2 );
173 centrePoint.y = di.flipY( di.audioToHeigt(0.0) ); 195 centrePoint.y = di.flipY( di.audioToHeigt(0.0) );
174 196
175 const float wavePixelLen = mNumChunks * ( 2 + Chunk::kWidth); 197 const float wavePixelLen = mNumChunks * ( 2 + Chunk::kWidth);
176 centrePoint.x *= float(di.getWindowWidth()) / wavePixelLen; 198 centrePoint.x *= float(di.getWindowWidth()) / wavePixelLen;
177 199
178 mParticleController.addParticles( 200 mParticleController.addParticles(
179 std::max( 1, (int)(amountCoeff * ParticleController::kMaxParticleAdd * mFilterCoeff) ), // amount of particles to add 201 std::max( 1, (int)(amountCoeff * ParticleController::kMaxParticleAdd * mFilterCoeff) ), // amount of particles to add
180 centrePoint, 202 centrePoint,
181 mSelection.getParticleSpread() * PARTICLESIZE_COEFF // size of the cloud 203 mSelection.getParticleSpread() * PARTICLESIZE_COEFF // size of the cloud
182 ); 204 );
183 } 205 }
184 #endif 206 #endif
185 207
186 208
187 } 209 }
188 210
189 void update( double secondsPerChunk, const DrawInfo& di ); 211 void update( double secondsPerChunk, const DrawInfo& di );
190 212
191 void removeCursor( SynthID id ) { mCursors.erase( id ); } 213 void removeCursor( SynthID id ) { mCursors.erase( id ); }
192 214
193 /** Sets the transparency of this wave. \a alpha ranges from 0 to 1 */ 215 /** Sets the transparency of this wave. \a alpha ranges from 0 to 1 */
194 inline void setselectionAlpha(float alpha){ mFilterCoeff = alpha;} 216 inline void setselectionAlpha(float alpha){ mFilterCoeff = alpha;}
195 217
196 void draw( const DrawInfo& di ); 218 void draw( const DrawInfo& di );
197 219
198 Selection& getSelection() { return mSelection; }; 220 Selection& getSelection() { return mSelection; };
199 221
200 size_t getSize() const{ return mChunks.size(); } 222 size_t getSize() const{ return mChunks.size(); }
201 223
202 void setScopePoint(int index, float audioVal); 224 void setScopePoint(int index, float audioVal);
203 225
204 Wave( size_t numChunks, Color selectionColor ); 226 Wave( size_t numChunks, Color selectionColor );
205 227
206 /** no copies */ 228 /** no copies */
207 Wave( const Wave &copy ) = delete; 229 Wave( const Wave &copy ) = delete;