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