rt300@0
|
1 #include "testApp.h"
|
rt300@2
|
2
|
rt300@0
|
3
|
rt300@0
|
4 extern Grid theGridView;
|
rt300@0
|
5 extern PresetManager presetManager;
|
rt300@1
|
6 extern EventLogger eventLogger;
|
rt300@3
|
7 extern Frequencer frequencer;
|
rt300@3
|
8
|
rt300@0
|
9 //--------------------------------------------------------------
|
rt300@0
|
10 void testApp::setup(){
|
rt300@0
|
11 ofSetOrientation(OF_ORIENTATION_90_LEFT);
|
rt300@0
|
12
|
rt300@0
|
13 ofBackground( 0, 0, 0 );
|
rt300@0
|
14 ofEnableAlphaBlending();
|
rt300@0
|
15
|
rt300@0
|
16 // open an outgoing connection to HOST:PORT
|
rt300@0
|
17 sender.setup( HOST, PORT );
|
rt300@3
|
18 ofSetFrameRate(30);
|
rt300@0
|
19 // reciever
|
rt300@6
|
20 lastMoveTime = ofGetSystemTimeMicros();
|
rt300@0
|
21 prevTouchX = 0;
|
rt300@0
|
22 prevTouchY = 0;
|
rt300@0
|
23
|
rt300@0
|
24 xLocked = false;
|
rt300@0
|
25 yLocked = false;
|
rt300@0
|
26
|
rt300@0
|
27 numActiveTouches = 0;
|
rt300@3
|
28 touch0.setCoord(17./7., 2./3.);
|
rt300@0
|
29 touch1.setCoord(10,20);
|
rt300@3
|
30
|
rt300@3
|
31 TwoVector ttest;
|
rt300@3
|
32 string str = "(4.5,7.8)";
|
rt300@3
|
33 stringstream sstr;
|
rt300@3
|
34 sstr << str;
|
rt300@3
|
35 sstr >> ttest;
|
rt300@4
|
36 cout << "ttest: " << ttest << "\n";
|
rt300@3
|
37
|
rt300@3
|
38
|
rt300@0
|
39 prevTouch0.setCoord(1,2);
|
rt300@0
|
40 prevTouch1.setCoord(10,20);
|
rt300@0
|
41 prevDist = 10;
|
rt300@0
|
42
|
rt300@0
|
43 theGridView.init();
|
rt300@0
|
44
|
rt300@3
|
45 slowFactor = 0.98;
|
rt300@3
|
46
|
rt300@0
|
47
|
rt300@0
|
48 setupStandardGui();
|
rt300@0
|
49 standardGUIShowing = false;
|
rt300@0
|
50 standardGUI->setVisible(standardGUIShowing);
|
rt300@0
|
51
|
rt300@0
|
52 setupZoomGui();
|
rt300@0
|
53 zoomGUI->setVisible(!standardGUIShowing);
|
rt300@0
|
54
|
rt300@0
|
55 // initial slider vals
|
rt300@0
|
56 for(int i=0; i<10;i++){
|
rt300@0
|
57 sliderVals.push_back(64);
|
rt300@0
|
58 }
|
rt300@0
|
59
|
rt300@3
|
60 // the 5 harmonics for the frequencer
|
rt300@3
|
61 freqIndexes.push_back(0);
|
rt300@3
|
62 freqIndexes.push_back(4);
|
rt300@3
|
63 freqIndexes.push_back(6);
|
rt300@3
|
64 freqIndexes.push_back(7);
|
rt300@3
|
65 freqIndexes.push_back(8);
|
rt300@3
|
66
|
rt300@0
|
67 keyboard = new ofxiPhoneKeyboard(500,380,320,32);
|
rt300@0
|
68 keyboard->setVisible(false);
|
rt300@0
|
69 keyboard->setBgColor(255, 255, 255, 255);
|
rt300@0
|
70 keyboard->setFontColor(0,0,0, 255);
|
rt300@0
|
71 keyboard->setFontSize(26);
|
rt300@0
|
72
|
rt300@0
|
73 ofxiPhoneSetOrientation( OF_ORIENTATION_90_RIGHT );
|
rt300@0
|
74
|
rt300@2
|
75 //-----------------
|
rt300@2
|
76 // the number if libpd ticks per buffer,
|
rt300@2
|
77 // used to compute the audio buffer len: tpb * blocksize (always 64)
|
rt300@2
|
78 int ticksPerBuffer = 8; // 8 * 64 = buffer len of 512
|
rt300@2
|
79
|
rt300@2
|
80 // setup the app core
|
rt300@2
|
81 core.setup(2, 1, 44100, ticksPerBuffer);
|
rt300@2
|
82
|
rt300@2
|
83 // setup OF sound stream
|
rt300@2
|
84 ofSoundStreamSetup(2, 1, this, 44100, ofxPd::blockSize()*ticksPerBuffer, 3);
|
rt300@1
|
85
|
rt300@5
|
86 presetManager.startupLoadAll();
|
rt300@5
|
87
|
rt300@0
|
88 }
|
rt300@3
|
89 #pragma mark GUI
|
rt300@0
|
90 //--------------------------------------------------------------
|
rt300@0
|
91 void testApp::setupZoomGui(){
|
rt300@3
|
92 zoomGUI = new ofxUICanvas(ofGetWidth()-200,0,190,300);
|
rt300@1
|
93 zoomGUI->setTheme(OFX_UI_THEME_HACKER );
|
rt300@0
|
94
|
rt300@3
|
95 zoomGUI->addLabelToggle("SWITCH VIEW", false);
|
rt300@0
|
96
|
rt300@0
|
97 zoomGUI->addLabelButton("SAVE PRESET", false);
|
rt300@0
|
98
|
rt300@0
|
99 zoomGUI->addLabelToggle("LOCK SEQUENCE (X)", false);
|
rt300@0
|
100 zoomGUI->addLabelToggle("LOCK SYNTH (Y)", false);
|
rt300@0
|
101
|
rt300@3
|
102 zoomGUI->addLabelButton("ZOOM MIN", false);
|
rt300@3
|
103 zoomGUI->addLabelButton("ZOOM MAX", false);
|
rt300@3
|
104
|
rt300@0
|
105 ofAddListener(zoomGUI->newGUIEvent, this, &testApp::zoomGUIEvent);
|
rt300@0
|
106 }
|
rt300@0
|
107 //--------------------------------------------------------------
|
rt300@0
|
108 void testApp::zoomGUIEvent(ofxUIEventArgs &e){
|
rt300@0
|
109
|
rt300@0
|
110 if(e.widget->getName() == "SWITCH VIEW")
|
rt300@0
|
111 {
|
rt300@0
|
112 cout << "change VIEW\n";
|
rt300@0
|
113
|
rt300@0
|
114 standardGUI->setVisible(!standardGUIShowing);
|
rt300@0
|
115 standardGUIShowing = !standardGUIShowing;
|
rt300@0
|
116 if(standardGUIShowing){
|
rt300@0
|
117 // set the slider values to stuff got from zoomer
|
rt300@0
|
118 sliderVals = theGridView.getParams();
|
rt300@3
|
119 setAllGUISliders(sliderVals);
|
rt300@0
|
120 }
|
rt300@0
|
121
|
rt300@0
|
122 }else if(e.widget->getName() == "SAVE PRESET")
|
rt300@0
|
123 {
|
rt300@0
|
124
|
rt300@3
|
125 if(((ofxUIButton *)e.widget)->getValue()){
|
rt300@3
|
126 cout << "SAVE PRESET\n";
|
rt300@3
|
127 stringstream n;
|
rt300@3
|
128 double timemsd = [NSDate timeIntervalSinceReferenceDate];
|
rt300@3
|
129 long long timems = (long long)(timemsd*1000);
|
rt300@3
|
130 n << "P" << timems;
|
rt300@3
|
131 string name = n.str();
|
rt300@3
|
132
|
rt300@3
|
133 presetManager.addPreset(theGridView.getCoord(),name);
|
rt300@5
|
134 eventLogger.logEvent(SAVE_PRESET, theGridView.getCoord());
|
rt300@3
|
135 }
|
rt300@3
|
136 /*
|
rt300@0
|
137 if(!keyboard->isKeyboardShowing()){
|
rt300@0
|
138 keyboard->openKeyboard();
|
rt300@0
|
139 keyboard->setVisible(true);
|
rt300@0
|
140 } else{
|
rt300@0
|
141 keyboard->setVisible(false);
|
rt300@0
|
142 }
|
rt300@3
|
143 */
|
rt300@0
|
144 // set some kind of modal dialog thing to stop other stuff going on...
|
rt300@0
|
145 // this wont work
|
rt300@3
|
146 // HACK just name it after time
|
rt300@3
|
147
|
rt300@0
|
148 }else if(e.widget->getName() == "LOCK SEQUENCE (X)")
|
rt300@0
|
149 {
|
rt300@3
|
150
|
rt300@3
|
151 cout << "LOCK SEQUENCE (X)\n";
|
rt300@3
|
152 // lock
|
rt300@3
|
153 xLocked = !xLocked;
|
rt300@5
|
154 presetManager.clearAll();
|
rt300@3
|
155
|
rt300@0
|
156 }else if(e.widget->getName() == "LOCK SYNTH (Y)")
|
rt300@0
|
157 {
|
rt300@3
|
158
|
rt300@0
|
159 cout << "LOCK SYNTH (Y)\n";
|
rt300@0
|
160 // lock
|
rt300@5
|
161 if(((ofxUIButton *)e.widget)->getValue()){
|
rt300@5
|
162 yLocked = true;
|
rt300@5
|
163 }else{
|
rt300@5
|
164 yLocked = false;
|
rt300@5
|
165
|
rt300@5
|
166 }
|
rt300@3
|
167 }else if(e.widget->getName() == "ZOOM MIN")
|
rt300@3
|
168 {
|
rt300@3
|
169 if(((ofxUIButton *)e.widget)->getValue()){
|
rt300@3
|
170 cout << "ZOOM MIN\n";
|
rt300@5
|
171 theGridView.setMinZoom();
|
rt300@5
|
172 eventLogger.logEvent(SET_MIN_ZOOM);
|
rt300@3
|
173 }
|
rt300@3
|
174 }else if(e.widget->getName() == "ZOOM MAX")
|
rt300@3
|
175 {
|
rt300@3
|
176 if(((ofxUIButton *)e.widget)->getValue()){
|
rt300@3
|
177 cout << "ZOOM MAX\n";
|
rt300@5
|
178 theGridView.setMaxZoom();
|
rt300@5
|
179 eventLogger.logEvent(SET_MAX_ZOOM);
|
rt300@5
|
180 //eventLogger.printAll();
|
rt300@3
|
181 }
|
rt300@0
|
182 }else{
|
rt300@0
|
183 cout << "GUI error : unknown event recieved\n";
|
rt300@0
|
184 }
|
rt300@0
|
185
|
rt300@0
|
186 }
|
rt300@0
|
187 //--------------------------------------------------------------
|
rt300@0
|
188 void testApp::setupStandardGui(){
|
rt300@0
|
189 float xInit = OFX_UI_GLOBAL_WIDGET_SPACING;
|
rt300@0
|
190 float length = 256-xInit*2;
|
rt300@0
|
191
|
rt300@0
|
192
|
rt300@0
|
193 float dim = 42;
|
rt300@0
|
194
|
rt300@0
|
195 // LEFT GUI
|
rt300@0
|
196 standardGUI = new ofxUICanvas(0,0,length+90,ofGetHeight()-90);
|
rt300@0
|
197
|
rt300@0
|
198
|
rt300@0
|
199
|
rt300@0
|
200 // Uh.. loop this
|
rt300@0
|
201 for(int i = 1; i<=10;i++){
|
rt300@0
|
202 stringstream ss;
|
rt300@0
|
203 ss << "P" << i;
|
rt300@0
|
204 ofxUISlider *slider;
|
rt300@0
|
205 slider = (ofxUISlider *)standardGUI->addWidgetDown(new ofxUISlider(length,dim,0.0,127,64,ss.str()));
|
rt300@0
|
206 slider->setDrawPadding(true);
|
rt300@1
|
207 if(i <= 5){
|
rt300@1
|
208 slider->setColorFill(ofColor(0,0,255));
|
rt300@1
|
209 slider->setColorFillHighlight(ofColor(0,0,255));
|
rt300@1
|
210 }else{
|
rt300@1
|
211 slider->setColorFill(ofColor(255,0,0));
|
rt300@1
|
212 slider->setColorFillHighlight(ofColor(255,0,0));
|
rt300@1
|
213 }
|
rt300@1
|
214
|
rt300@0
|
215 sliders.push_back(slider);
|
rt300@0
|
216 }
|
rt300@0
|
217
|
rt300@0
|
218 ofAddListener(standardGUI->newGUIEvent, this, &testApp::standardGUIEvent);
|
rt300@0
|
219 standardGUI->loadSettings(ofxiPhoneGetDocumentsDirectory() + "guiSettings.xml");
|
rt300@0
|
220
|
rt300@0
|
221 }
|
rt300@0
|
222 //--------------------------------------------------------------
|
rt300@0
|
223 void testApp::standardGUIEvent(ofxUIEventArgs &e){
|
rt300@0
|
224 if(!standardGUIShowing){
|
rt300@0
|
225 cout << "GUI ERROR";
|
rt300@0
|
226 return;
|
rt300@0
|
227 }
|
rt300@0
|
228 // "normal" parameter changes
|
rt300@0
|
229 for(int i = 1; i<=10;i++){
|
rt300@0
|
230 stringstream ss;
|
rt300@0
|
231 ss << "P" << i;
|
rt300@0
|
232 string p = ss.str();
|
rt300@0
|
233
|
rt300@0
|
234 if(e.widget->getName() == p)
|
rt300@0
|
235 {
|
rt300@0
|
236 //cout << "param change: " << p;
|
rt300@0
|
237 ofxUISlider *slider = (ofxUISlider *) e.widget;
|
rt300@3
|
238 sliderMoved(i-1,slider->getScaledValue()); // internal array 0 indexed
|
rt300@0
|
239
|
rt300@5
|
240
|
rt300@5
|
241
|
rt300@0
|
242 }
|
rt300@0
|
243 }
|
rt300@0
|
244
|
rt300@0
|
245 // TODO reflect these changes in zoomer view? Or only when switching?
|
rt300@0
|
246
|
rt300@0
|
247 }
|
rt300@0
|
248 //--------------------------------------------------------------
|
rt300@3
|
249 void testApp::sliderMoved(int which, float value){
|
rt300@3
|
250 // an update caused by slider view being touched
|
rt300@0
|
251 sliderVals[which] = (int)value;
|
rt300@0
|
252 theGridView.setParams(sliderVals);
|
rt300@3
|
253
|
rt300@3
|
254 // TODO if <5 do frequencer stuff and send list to PD
|
rt300@3
|
255 // if > 5 send control value to PD
|
rt300@3
|
256 sendParametersToPD();
|
rt300@5
|
257
|
rt300@5
|
258 eventLogger.logEvent(CHANGE_SLIDER, which , value);
|
rt300@5
|
259
|
rt300@0
|
260 }
|
rt300@0
|
261 //--------------------------------------------------------------
|
rt300@3
|
262 void testApp::setAllGUISliders(vector<int> vals){
|
rt300@3
|
263 // an update caused by zoomer view being moved
|
rt300@0
|
264 for(int i = 0; i<10;i++){
|
rt300@0
|
265 sliders[i]->setValue(vals[i]);
|
rt300@1
|
266 sliderVals[i] = vals[i];
|
rt300@0
|
267 }
|
rt300@3
|
268
|
rt300@0
|
269 }
|
rt300@0
|
270 //--------------------------------------------------------------
|
rt300@3
|
271 void testApp::sendParametersToPD(){
|
rt300@3
|
272 // frequencer stuff to get 16 steps
|
rt300@3
|
273 vector<double> vals;
|
rt300@3
|
274
|
rt300@3
|
275
|
rt300@3
|
276 vals.push_back((sliderVals[0]+32)*8.); // DC offset
|
rt300@3
|
277 for(int i=1; i<5;i++){
|
rt300@3
|
278 vals.push_back((sliderVals[i] - 64)*2.);
|
rt300@3
|
279 }
|
rt300@3
|
280
|
rt300@3
|
281 vector<double> steps = frequencer.freqMagEdit(freqIndexes, vals);
|
rt300@3
|
282 // send a list using the List object
|
rt300@3
|
283 List seqSteps;
|
rt300@3
|
284
|
rt300@3
|
285 seqSteps.addSymbol("seqSteps");
|
rt300@3
|
286 for(int i=0; i < 16; i++){
|
rt300@3
|
287 seqSteps.addFloat(round(steps[i])); // rounding here??
|
rt300@3
|
288 }
|
rt300@3
|
289
|
rt300@3
|
290 core.pd.sendList("fromOF", seqSteps);
|
rt300@3
|
291 //core.pd.sendMessage("fromOF", "msg", seqSteps);
|
rt300@3
|
292
|
rt300@3
|
293 // implement synth param calculations here?
|
rt300@3
|
294 // oscshape, filt type , cut off, envelope, mod freq (fm for sine, ? for pulse, sync for saw)
|
rt300@3
|
295 // oscillators:
|
rt300@3
|
296 sendOscShape(sliderVals[5]);
|
rt300@3
|
297 sendFiltType(sliderVals[6]);
|
rt300@3
|
298 sendFiltFreq(sliderVals[7]);
|
rt300@3
|
299 sendEnvShape(sliderVals[8]);
|
rt300@3
|
300 sendModFreq(sliderVals[9]);
|
rt300@3
|
301
|
rt300@3
|
302 }
|
rt300@3
|
303 #pragma mark STANDARD OF FUNCTIONS
|
rt300@3
|
304 //--------------------------------------------------------------
|
rt300@0
|
305 void testApp::update(){
|
rt300@0
|
306 //we do a heartbeat on iOS as the phone will shut down the network connection to save power
|
rt300@0
|
307 //this keeps the network alive as it thinks it is being used.
|
rt300@0
|
308 if( ofGetFrameNum() % 120 == 0 ){
|
rt300@0
|
309 ofxOscMessage m;
|
rt300@0
|
310 m.setAddress( "/misc/heartbeat" );
|
rt300@0
|
311 m.addIntArg( ofGetFrameNum() );
|
rt300@0
|
312 sender.sendMessage( m );
|
rt300@0
|
313 }
|
rt300@0
|
314
|
rt300@5
|
315 // continiue to move at velocity, unless snapped
|
rt300@3
|
316
|
rt300@3
|
317 if (numActiveTouches == 0){ // no touches, use momentum
|
rt300@3
|
318 // TODO set velocity to 0 when hits walls
|
rt300@3
|
319
|
rt300@5
|
320 if(moveVel.norm() > 0.3 && !theGridView.snapped){
|
rt300@3
|
321 theGridView.move(moveVel);
|
rt300@3
|
322 moveVel = moveVel*slowFactor;
|
rt300@3
|
323
|
rt300@3
|
324 // and get new parameter values
|
rt300@5
|
325 setAllGUISliders(theGridView.getParams());
|
rt300@3
|
326 sendParametersToPD();
|
rt300@5
|
327 }else if(moveVel.norm() > 0.01 || theGridView.snapped){
|
rt300@3
|
328 // stop it
|
rt300@3
|
329 moveVel.setCoord(0.0,0.0);
|
rt300@5
|
330 setAllGUISliders(theGridView.getParams());
|
rt300@3
|
331 sendParametersToPD();
|
rt300@5
|
332 eventLogger.logEvent(SCROLL_STOPPED, theGridView.getCoord() );
|
rt300@3
|
333 }else{
|
rt300@3
|
334 // stopped - do nothing
|
rt300@3
|
335 }
|
rt300@3
|
336
|
rt300@0
|
337 }
|
rt300@0
|
338 // continiue to zoom at velocity
|
rt300@0
|
339 if (numActiveTouches < 2 && abs(zoomVel)>0.001){
|
rt300@0
|
340 theGridView.zoom(zoomVel + 1.0); // +1 because zoomVel factor is + or - , wheras zoom is a multiplier near 1
|
rt300@0
|
341 zoomVel = zoomVel*slowFactor;
|
rt300@0
|
342 }
|
rt300@6
|
343
|
rt300@0
|
344 }
|
rt300@0
|
345 //--------------------------------------------------------------
|
rt300@0
|
346 void testApp::sendOSCParams(){
|
rt300@0
|
347
|
rt300@0
|
348 vector<int> params = theGridView.getParams(); // FILTER HERE? NEED FLOATS...
|
rt300@0
|
349 vector<int>::iterator iter = params.begin();
|
rt300@0
|
350
|
rt300@0
|
351 ofxOscMessage m;
|
rt300@0
|
352 m.setAddress( "p" );
|
rt300@0
|
353
|
rt300@0
|
354 for(;iter < params.end();iter++){
|
rt300@0
|
355
|
rt300@0
|
356 m.addFloatArg( *iter );
|
rt300@0
|
357
|
rt300@0
|
358 }
|
rt300@0
|
359 sender.sendMessage( m );
|
rt300@0
|
360 }
|
rt300@0
|
361 //--------------------------------------------------------------
|
rt300@0
|
362 void testApp::draw(){
|
rt300@0
|
363
|
rt300@0
|
364 if (standardGUIShowing){
|
rt300@0
|
365 ofSetColor(57, 57, 57,200);
|
rt300@0
|
366 ofRect(0,0,ofGetWidth(),ofGetHeight());
|
rt300@0
|
367 }
|
rt300@0
|
368 theGridView.draw();
|
rt300@0
|
369
|
rt300@1
|
370 //ofSetColor(20, 160, 240, 255);
|
rt300@1
|
371 //ofDrawBitmapString("text entered = "+ keyboard->getText() , 2, 70);
|
rt300@0
|
372 }
|
rt300@0
|
373
|
rt300@0
|
374 //--------------------------------------------------------------
|
rt300@0
|
375 void testApp::exit(){
|
rt300@4
|
376
|
rt300@4
|
377 presetManager.exitAndSaveAll();
|
rt300@2
|
378 core.exit();
|
rt300@4
|
379
|
rt300@0
|
380 delete standardGUI;
|
rt300@0
|
381 delete zoomGUI;
|
rt300@4
|
382 cout << "exit done \n";
|
rt300@0
|
383 }
|
rt300@0
|
384
|
rt300@0
|
385 //--------------------------------------------------------------
|
rt300@0
|
386 void testApp::touchDown(ofTouchEventArgs &touch){
|
rt300@0
|
387 if(standardGUIShowing){
|
rt300@0
|
388 // check if in GUI area
|
rt300@0
|
389 if(touch.x < 256) return;
|
rt300@0
|
390 }
|
rt300@0
|
391
|
rt300@0
|
392 numActiveTouches++;
|
rt300@0
|
393 // absolute position doesn't matter
|
rt300@0
|
394 // which one?
|
rt300@0
|
395 if(touch.id == 0){
|
rt300@0
|
396 touch0.setCoord(touch.x,touch.y);
|
rt300@0
|
397 prevTouch0 = touch0;
|
rt300@0
|
398 }else if(touch.id == 1){
|
rt300@0
|
399
|
rt300@0
|
400 touch1.setCoord(touch.x,touch.y);
|
rt300@0
|
401 prevTouch1 = touch1;
|
rt300@0
|
402
|
rt300@0
|
403 }
|
rt300@0
|
404 if(numActiveTouches == 1){
|
rt300@0
|
405 moveVel.setCoord(0.0, 0.0);
|
rt300@0
|
406 prevMove.setCoord(0.0, 0.0);
|
rt300@0
|
407 prevMove2.setCoord(0.0, 0.0);
|
rt300@0
|
408 }else if(numActiveTouches == 2){
|
rt300@0
|
409 zoomVel = 0.0;
|
rt300@0
|
410 prevZoom = 0.0;
|
rt300@0
|
411 prevZoom2 = 0.0;
|
rt300@0
|
412 double dist = touch1.distanceTo(touch0);
|
rt300@0
|
413 prevDist = dist;
|
rt300@0
|
414 }
|
rt300@0
|
415
|
rt300@0
|
416 }
|
rt300@0
|
417
|
rt300@0
|
418 //--------------------------------------------------------------
|
rt300@0
|
419 void testApp::touchMoved(ofTouchEventArgs &touch){
|
rt300@1
|
420
|
rt300@1
|
421 //cout << "touch id " << touch.id << "\n";
|
rt300@1
|
422 //cout << "active touches " << numActiveTouches << "\n";
|
rt300@1
|
423
|
rt300@1
|
424
|
rt300@0
|
425 if(standardGUIShowing){
|
rt300@3
|
426 // TODO check if in GUI area
|
rt300@0
|
427 if(touch.x < 256) return;
|
rt300@0
|
428 }
|
rt300@0
|
429
|
rt300@1
|
430 // which one? keep track of each touch point
|
rt300@0
|
431 if(touch.id == 0){
|
rt300@0
|
432 touch0.setCoord(touch.x,touch.y);
|
rt300@0
|
433
|
rt300@0
|
434 }else if(touch.id == 1){
|
rt300@0
|
435
|
rt300@0
|
436 touch1.setCoord(touch.x,touch.y);
|
rt300@0
|
437 }
|
rt300@0
|
438
|
rt300@1
|
439 if(numActiveTouches == 1){
|
rt300@0
|
440
|
rt300@1
|
441 handleScroll();
|
rt300@0
|
442 }else if(numActiveTouches == 2){
|
rt300@1
|
443 handleZoom();
|
rt300@0
|
444
|
rt300@0
|
445 }
|
rt300@0
|
446 prevTouch0 = touch0;
|
rt300@0
|
447
|
rt300@0
|
448
|
rt300@0
|
449 }
|
rt300@5
|
450
|
rt300@1
|
451 //--------------------------------------------------------------
|
rt300@1
|
452 void testApp::handleScroll(){
|
rt300@6
|
453
|
rt300@1
|
454 TwoVector move = touch0 - prevTouch0;
|
rt300@5
|
455 if(yLocked){
|
rt300@5
|
456 move.y = 0.0;
|
rt300@5
|
457 }
|
rt300@5
|
458 if(xLocked){
|
rt300@5
|
459 move.x = 0.0;
|
rt300@5
|
460 }
|
rt300@5
|
461
|
rt300@6
|
462 // check time since last move - if
|
rt300@6
|
463 unsigned int moveTime = ofGetSystemTimeMicros();
|
rt300@6
|
464 if(moveTime - lastMoveTime > 100000){
|
rt300@6
|
465 moveVel = TwoVector(); // zero
|
rt300@6
|
466 }else{
|
rt300@6
|
467 moveVel = (move*0.3 + prevMove*0.34 + prevMove2*0.38); // use the time
|
rt300@6
|
468
|
rt300@6
|
469 }
|
rt300@6
|
470 lastMoveTime = moveTime;
|
rt300@6
|
471
|
rt300@5
|
472
|
rt300@1
|
473 prevMove2 = prevMove;
|
rt300@1
|
474 prevMove = move;
|
rt300@1
|
475
|
rt300@5
|
476
|
rt300@3
|
477 theGridView.move(move);
|
rt300@3
|
478
|
rt300@3
|
479 // and get new parameter values
|
rt300@3
|
480 setAllGUISliders(theGridView.getParams());
|
rt300@3
|
481 sendParametersToPD();
|
rt300@1
|
482 }
|
rt300@1
|
483 //--------------------------------------------------------------
|
rt300@1
|
484 void testApp::handleZoom(){
|
rt300@1
|
485 // work out change in difference
|
rt300@1
|
486 double dist = touch1.distanceTo(touch0);
|
rt300@1
|
487 double zoomFactor = prevDist/dist;
|
rt300@1
|
488
|
rt300@1
|
489 //TODO check for sensible maximums, e.g. spurious touch data
|
rt300@1
|
490 if(zoomFactor > 2.0 || zoomFactor < 0.5){
|
rt300@1
|
491 cout << "Zoom too much!!!!" << zoomFactor;
|
rt300@1
|
492 zoomFactor = 1.0;
|
rt300@1
|
493 }
|
rt300@1
|
494
|
rt300@1
|
495 zoomVel = (zoomFactor-1)*0.3 + prevZoom*0.34 + prevZoom2*0.38;
|
rt300@1
|
496 prevZoom2 = prevZoom;
|
rt300@1
|
497 prevZoom = (zoomFactor-1);
|
rt300@1
|
498
|
rt300@1
|
499 theGridView.zoom(zoomFactor);
|
rt300@1
|
500
|
rt300@1
|
501 prevDist = dist;
|
rt300@3
|
502
|
rt300@1
|
503 }
|
rt300@0
|
504 //--------------------------------------------------------------
|
rt300@0
|
505 void testApp::touchUp(ofTouchEventArgs &touch){
|
rt300@1
|
506 if(numActiveTouches > 0) numActiveTouches--; // dirty
|
rt300@1
|
507
|
rt300@0
|
508 if(standardGUIShowing){
|
rt300@0
|
509 // check if in GUI area
|
rt300@0
|
510 if(touch.x < 256)
|
rt300@1
|
511
|
rt300@0
|
512 return;
|
rt300@0
|
513 }
|
rt300@1
|
514
|
rt300@0
|
515 // which one?
|
rt300@0
|
516 if(touch.id == 0){
|
rt300@0
|
517 // tricky situation - we tried to zoom but may have left non-move finger on
|
rt300@0
|
518 prevTouch0.setCoord(touch.x,touch.y);
|
rt300@0
|
519
|
rt300@0
|
520 }else if(touch.id == 1){
|
rt300@0
|
521
|
rt300@0
|
522
|
rt300@0
|
523 prevTouch1.setCoord(0,0);
|
rt300@6
|
524
|
rt300@6
|
525 }
|
rt300@6
|
526 if(numActiveTouches == 0){
|
rt300@6
|
527 // check time since last move
|
rt300@6
|
528 // check time since last move - if
|
rt300@6
|
529 unsigned int moveTime = ofGetSystemTimeMicros();
|
rt300@6
|
530 if(moveTime - lastMoveTime > 100000){
|
rt300@6
|
531 moveVel = TwoVector(); // zero
|
rt300@6
|
532 }else{
|
rt300@6
|
533 moveVel = (move*0.3 + prevMove*0.34 + prevMove2*0.38); // use the time
|
rt300@6
|
534
|
rt300@6
|
535 }
|
rt300@6
|
536 lastMoveTime = moveTime;
|
rt300@0
|
537 }
|
rt300@0
|
538
|
rt300@0
|
539 }
|
rt300@0
|
540
|
rt300@0
|
541 //--------------------------------------------------------------
|
rt300@0
|
542 void testApp::touchDoubleTap(ofTouchEventArgs &touch){
|
rt300@0
|
543 // preset?
|
rt300@0
|
544
|
rt300@0
|
545 }
|
rt300@0
|
546
|
rt300@0
|
547 //--------------------------------------------------------------
|
rt300@0
|
548 void testApp::lostFocus(){
|
rt300@0
|
549
|
rt300@0
|
550 }
|
rt300@0
|
551
|
rt300@0
|
552 //--------------------------------------------------------------
|
rt300@0
|
553 void testApp::gotFocus(){
|
rt300@0
|
554
|
rt300@0
|
555 }
|
rt300@0
|
556
|
rt300@0
|
557 //--------------------------------------------------------------
|
rt300@0
|
558 void testApp::gotMemoryWarning(){
|
rt300@0
|
559
|
rt300@0
|
560 }
|
rt300@0
|
561
|
rt300@0
|
562 //--------------------------------------------------------------
|
rt300@0
|
563 void testApp::deviceOrientationChanged(int newOrientation){
|
rt300@0
|
564 cout << "orientation: " << newOrientation;
|
rt300@0
|
565 keyboard->updateOrientation(); // takes ages , only applies to text box
|
rt300@0
|
566 if(newOrientation == 4){
|
rt300@0
|
567 ofxiPhoneSetOrientation( OF_ORIENTATION_90_RIGHT );
|
rt300@0
|
568 }else if(newOrientation == 3){
|
rt300@0
|
569 ofxiPhoneSetOrientation( OF_ORIENTATION_90_LEFT );
|
rt300@0
|
570 }
|
rt300@0
|
571
|
rt300@0
|
572 }
|
rt300@0
|
573
|
rt300@0
|
574
|
rt300@0
|
575 //--------------------------------------------------------------
|
rt300@0
|
576 void testApp::touchCancelled(ofTouchEventArgs& args){
|
rt300@0
|
577
|
rt300@0
|
578 }
|
rt300@3
|
579 //---------------------------------------------------------------
|
rt300@3
|
580 // AUDIO STUFF
|
rt300@3
|
581 //---------------------------------------------------------------
|
rt300@3
|
582
|
rt300@3
|
583 #pragma mark AUDIO STREAMS
|
rt300@3
|
584 //--------------------------------------------------------------
|
rt300@3
|
585 void testApp::audioReceived(float * input, int bufferSize, int nChannels) {
|
rt300@3
|
586 core.audioReceived(input, bufferSize, nChannels);
|
rt300@3
|
587 }
|
rt300@3
|
588
|
rt300@3
|
589 void testApp::audioRequested(float * output, int bufferSize, int nChannels) {
|
rt300@3
|
590 core.audioRequested(output, bufferSize, nChannels);
|
rt300@3
|
591 }
|
rt300@3
|
592 //---------------------------------------------------------------
|
rt300@3
|
593 #pragma mark UTILITIES
|
rt300@0
|
594
|
rt300@0
|
595 // 5hz cut off
|
rt300@0
|
596 const double fB[3] = {0.049489956268677, 0.098979912537354, 0.049489956268677};
|
rt300@0
|
597
|
rt300@0
|
598 const double fA[3] = {1.000000000000000, -1.279632424997809, 0.477592250072517};
|
rt300@0
|
599
|
rt300@0
|
600 // 1hz cut off
|
rt300@0
|
601 //const double fB[3] = {0.002550535158536, 0.005101070317073, 0.002550535158536};
|
rt300@0
|
602
|
rt300@0
|
603 //const double fA[3] = {1.000000000000000, -1.852146485395936, 0.862348626030081};
|
rt300@0
|
604
|
rt300@0
|
605
|
rt300@0
|
606 //a(1)*y(n) = b(1)*x(n) + b(2)*x(n-1) + ... + b(nb+1)*x(n-nb)- a(2)*y(n-1) - ... - a(na+1)*y(n-na)
|
rt300@0
|
607 //---------------------------------------------------------------
|
rt300@0
|
608 vector<float> testApp::vectorFilter(vector<float> newVec){
|
rt300@0
|
609 static vector<float> x0(10,0);
|
rt300@0
|
610 static vector<float> x1(10,0);
|
rt300@0
|
611 static vector<float> x2(10,0);
|
rt300@0
|
612 static vector<float> y0(10,0);
|
rt300@0
|
613 static vector<float> y1(10,0);
|
rt300@0
|
614 static vector<float> y2(10,0);
|
rt300@0
|
615
|
rt300@0
|
616 x0 = newVec;
|
rt300@0
|
617
|
rt300@0
|
618 // this low passes a bunch of params values all at once
|
rt300@0
|
619 int sz = newVec.size();
|
rt300@0
|
620 for(int i=0; i<sz; i++){
|
rt300@0
|
621 y0[i] = fB[0]*x0[i] + fB[1]*x1[i] + fB[2]*x2[i] - fA[1]*y1[i] - fA[2]*y2[i];
|
rt300@0
|
622 }
|
rt300@0
|
623 // shift
|
rt300@0
|
624 x2 = x1;
|
rt300@0
|
625 x1 = x0;
|
rt300@0
|
626 y2 = y1;
|
rt300@0
|
627 y1 = y0;
|
rt300@0
|
628
|
rt300@0
|
629 return y0;
|
rt300@2
|
630 }
|
rt300@2
|
631
|
rt300@3
|
632 void testApp::sendOscShape(int ctrlin){
|
rt300@3
|
633
|
rt300@3
|
634 static int numpoints = 5;
|
rt300@3
|
635 static int numcontrols = 5;
|
rt300@3
|
636 //float values[points][controls] =
|
rt300@3
|
637 float ctrlout[numcontrols];
|
rt300@3
|
638 string ctrlName[5] = {"pWidth" , "sqVol", "sawVol", "sineVol", "FMAmt"};
|
rt300@3
|
639 float values[5][5] =
|
rt300@3
|
640 {{0.5, 0., 0., 1., 1.}, // 0
|
rt300@3
|
641 {0.5, 0., 0., 1., 0.}, // 32
|
rt300@3
|
642 {0.5, 0., 1., 0., 0.}, // 64
|
rt300@3
|
643 {0.5, 1., 1., 0., 0.}, // 96
|
rt300@3
|
644 {0.01,1., 1., 0., 0.}}; // 127
|
rt300@3
|
645
|
rt300@3
|
646 float fidx = (numpoints-1)*ctrlin/128.;
|
rt300@3
|
647 int idx = floor(fidx);
|
rt300@3
|
648 float frac = fidx - idx;
|
rt300@3
|
649 for(int i=0; i < numcontrols; i++){
|
rt300@3
|
650 ctrlout[i] = (1 - frac)*values[idx][i] + (frac)*values[idx+1][i];
|
rt300@3
|
651 // send to PD
|
rt300@3
|
652 List toPD;
|
rt300@3
|
653
|
rt300@3
|
654 toPD.addSymbol(ctrlName[i]);
|
rt300@3
|
655 toPD.addFloat(ctrlout[i]); // rounding here??
|
rt300@3
|
656
|
rt300@3
|
657 core.pd.sendList("fromOF", toPD);
|
rt300@3
|
658 //cout << ctrlName[i] << "sending" << ctrlout[i] << "\n";
|
rt300@3
|
659 }
|
rt300@3
|
660
|
rt300@2
|
661 }
|
rt300@3
|
662 void testApp::sendFiltType(int ctrlin){
|
rt300@3
|
663 static int numpoints = 3;
|
rt300@3
|
664 static int numcontrols = 4;
|
rt300@3
|
665 //float values[points][controls] =
|
rt300@3
|
666 float ctrlout[numcontrols];
|
rt300@3
|
667 string ctrlName[4] = {"lpLev" , "bpLev", "hpLev", "reson"};
|
rt300@3
|
668 float values[3][4] =
|
rt300@3
|
669 {{1., 0., 0., 1}, // 0
|
rt300@3
|
670 {0., 10., 0., 10}, // 64
|
rt300@3
|
671 {0., 0., 1., 1}}; // 127
|
rt300@3
|
672
|
rt300@3
|
673 float fidx = (numpoints-1)*ctrlin/128.;
|
rt300@3
|
674 int idx = floor(fidx);
|
rt300@3
|
675 float frac = fidx - idx;
|
rt300@3
|
676 for(int i=0; i < numcontrols; i++){
|
rt300@3
|
677 ctrlout[i] = (1 - frac)*values[idx][i] + (frac)*values[idx+1][i];
|
rt300@3
|
678 // send to PD
|
rt300@3
|
679 List toPD;
|
rt300@3
|
680
|
rt300@3
|
681 toPD.addSymbol(ctrlName[i]);
|
rt300@3
|
682 toPD.addFloat(ctrlout[i]); // rounding here??
|
rt300@3
|
683
|
rt300@3
|
684 core.pd.sendList("fromOF", toPD);
|
rt300@3
|
685 //cout << ctrlName[i] << "sending" << ctrlout[i] << "\n";
|
rt300@3
|
686 }
|
rt300@2
|
687 }
|
rt300@3
|
688 void testApp::sendFiltFreq(int ctrlin){
|
rt300@3
|
689 List toPD;
|
rt300@3
|
690
|
rt300@3
|
691 toPD.addSymbol("filtFreq");
|
rt300@3
|
692 toPD.addFloat(ctrlin);
|
rt300@3
|
693
|
rt300@3
|
694 core.pd.sendList("fromOF", toPD);
|
rt300@3
|
695 }
|
rt300@3
|
696 void testApp::sendEnvShape(int ctrlin){
|
rt300@3
|
697 static int numpoints = 5;
|
rt300@3
|
698 static int numcontrols = 3;
|
rt300@3
|
699 //float values[points][controls] =
|
rt300@3
|
700 float ctrlout[numcontrols];
|
rt300@3
|
701 string ctrlName[3] = {"attack" , "decay", "sustain"};
|
rt300@3
|
702 float values[5][3] =
|
rt300@3
|
703 {{0., 0., 0.}, // 0
|
rt300@3
|
704 {0., 0.5, 0.}, // 32
|
rt300@3
|
705 {0.0, 1., 0.8}, // 64
|
rt300@3
|
706 {0.99, 0.3, 0.}, // 96
|
rt300@3
|
707 {0.3, 0.1, 0.}}; // 127
|
rt300@3
|
708
|
rt300@3
|
709 float fidx = (numpoints-1)*ctrlin/128.;
|
rt300@3
|
710 int idx = floor(fidx);
|
rt300@3
|
711 float frac = fidx - idx;
|
rt300@3
|
712 for(int i=0; i < numcontrols; i++){
|
rt300@3
|
713 ctrlout[i] = (1 - frac)*values[idx][i] + (frac)*values[idx+1][i];
|
rt300@3
|
714 // send to PD
|
rt300@3
|
715 List toPD;
|
rt300@3
|
716
|
rt300@3
|
717 toPD.addSymbol(ctrlName[i]);
|
rt300@3
|
718 toPD.addFloat(ctrlout[i]); // rounding here??
|
rt300@3
|
719
|
rt300@3
|
720 core.pd.sendList("fromOF", toPD);
|
rt300@3
|
721 //cout << ctrlName[i] << "sending" << ctrlout[i] << "\n";
|
rt300@3
|
722 }
|
rt300@3
|
723 }
|
rt300@3
|
724 void testApp::sendModFreq(int ctrlin){
|
rt300@3
|
725 float fm = ctrlin/127.;
|
rt300@3
|
726 List toPD;
|
rt300@3
|
727
|
rt300@3
|
728 toPD.addSymbol("FMFreq");
|
rt300@3
|
729 toPD.addFloat(fm); // rounding here??
|
rt300@3
|
730
|
rt300@3
|
731 core.pd.sendList("fromOF", toPD);
|
rt300@3
|
732 } |