annotate testApp.mm @ 32:ab7c86d0f3d8

V0.3 SZBeta sent out. bristol tests.
author Robert Tubb <rt300@eecs.qmul.ac.uk>
date Fri, 08 Mar 2013 14:54:55 +0000
parents c0a6f7c66719
children 92dba082d957
rev   line source
rt300@0 1 #include "testApp.h"
rt300@2 2
rt300@24 3 #define SLIDER_GUI_WIDTH 256
rt300@25 4 #define NUM_PARAMS 10
rt300@0 5 extern Grid theGridView;
rt300@0 6 extern PresetManager presetManager;
rt300@1 7 extern EventLogger eventLogger;
rt300@3 8 extern Frequencer frequencer;
rt300@9 9
rt300@24 10 const vector<string> parameterNames;
rt300@24 11
rt300@24 12 const string sliderParamNames[10] = {"Transpose", "1/4 note","1/6 note","1/7 note","1/8 note","Waveform", "Filter Type","Filter Freq", "Envelope","FM amt"};
rt300@24 13 //const vector<const string> v(ra[0],ra[1]);
rt300@24 14
rt300@24 15
rt300@7 16 //DeviceID3523537000
rt300@0 17 //--------------------------------------------------------------
rt300@0 18 void testApp::setup(){
rt300@16 19 paused = true;
rt300@29 20
rt300@24 21
rt300@16 22 ofBackground( 0, 0, 0 );
rt300@0 23 ofEnableAlphaBlending();
rt300@21 24 //ofEnableSmoothing();
rt300@0 25
rt300@29 26 // open an outgoing connection to HOST:PORT for OSC
rt300@29 27
rt300@29 28 sender.setup( OSC_HOST, OSC_PORT );
rt300@28 29 ofSetFrameRate(50);
rt300@0 30 // reciever
rt300@6 31 lastMoveTime = ofGetSystemTimeMicros();
rt300@0 32 prevTouchX = 0;
rt300@0 33 prevTouchY = 0;
rt300@0 34
rt300@0 35 xLocked = false;
rt300@0 36 yLocked = false;
rt300@0 37
rt300@0 38 numActiveTouches = 0;
rt300@3 39 touch0.setCoord(17./7., 2./3.);
rt300@0 40 touch1.setCoord(10,20);
rt300@3 41
rt300@0 42 prevTouch0.setCoord(1,2);
rt300@0 43 prevTouch1.setCoord(10,20);
rt300@0 44 prevDist = 10;
rt300@16 45 slowFactor = 0.98;
rt300@27 46 preventingMovePostScroll = false;
rt300@16 47
rt300@16 48 // the 5 harmonics for the frequencer
rt300@16 49 freqIndexes.push_back(0);
rt300@16 50 freqIndexes.push_back(4);
rt300@16 51 freqIndexes.push_back(6);
rt300@16 52 freqIndexes.push_back(7);
rt300@16 53 freqIndexes.push_back(8);
rt300@16 54
rt300@16 55
rt300@16 56 ofxiPhoneSetOrientation( OFXIPHONE_ORIENTATION_PORTRAIT ); // do this before setting up all the other objects
rt300@0 57
rt300@24 58 // initialise the interfaces
rt300@0 59 theGridView.init();
rt300@0 60
rt300@24 61 setupSliderGui();
rt300@24 62 sliderGUI->setVisible(true);
rt300@0 63
rt300@0 64 // initial slider vals
rt300@0 65 for(int i=0; i<10;i++){
rt300@0 66 sliderVals.push_back(64);
rt300@0 67 }
rt300@8 68
rt300@24 69 // initialise PD
rt300@24 70
rt300@2 71 int ticksPerBuffer = 8; // 8 * 64 = buffer len of 512
rt300@2 72
rt300@2 73 // setup the app core
rt300@2 74 core.setup(2, 1, 44100, ticksPerBuffer);
rt300@2 75
rt300@2 76 // setup OF sound stream
rt300@2 77 ofSoundStreamSetup(2, 1, this, 44100, ofxPd::blockSize()*ticksPerBuffer, 3);
rt300@1 78
rt300@24 79
rt300@24 80
rt300@24 81 // set up iOS gui stuff
rt300@24 82 bottomTabViewController = [[BottomTabViewController alloc] initWithNibName:@"BottomTabViewController" bundle:nil];
rt300@24 83 [ofxiPhoneGetGLParentView() addSubview:bottomTabViewController.view];
rt300@24 84
rt300@24 85 [bottomTabViewController setAppRef:(id)this];
rt300@24 86 bottomTabViewController.view.frame = CGRectMake(0,getHeight()-44,getWidth(),44);
rt300@29 87 bottomTabViewController.view.hidden = YES;
rt300@28 88
rt300@24 89 /////
rt300@24 90
rt300@24 91 topButtonViewController = [[TopButtonViewController alloc] initWithNibName:@"TopButtonViewController" bundle:nil];
rt300@24 92 [ofxiPhoneGetGLParentView() addSubview:topButtonViewController.view];
rt300@24 93 [topButtonViewController setAppRef:(id)this];
rt300@24 94 [topButtonViewController show:(id)this];
rt300@24 95 topButtonViewController.view.frame = CGRectMake(0,0,getWidth(),44);
rt300@24 96
rt300@25 97 usernameAlertViewController = [[UsernameAlertViewController alloc] init];
rt300@26 98
rt300@27 99 helpViewController = [[HelpViewController alloc] initWithNibName:@"HelpViewController" bundle:nil];
rt300@27 100 [ofxiPhoneGetGLParentView() addSubview:helpViewController.view];
rt300@27 101 [helpViewController setAppRef:(id)this];
rt300@27 102 helpViewController.view.hidden = YES;
rt300@27 103
rt300@25 104 /*
rt300@25 105 sliderViewController = [[SliderViewController alloc] initWithNibName:@"SLiderViewController" bundle:nil];
rt300@25 106 [ofxiPhoneGetGLParentView() addSubview:sliderViewController.view];
rt300@25 107
rt300@25 108 [sliderViewController setAppRef:(id)this];
rt300@25 109 [sliderViewController show:(id)this];
rt300@25 110
rt300@25 111 sliderViewController.view.frame = CGRectMake(0,getHeight()-43 - 363,getWidth(),44);
rt300@25 112 */
rt300@25 113
rt300@24 114 // initialise user logging stuff
rt300@30 115 presetManager.startLoadAll();
rt300@29 116 tsc = [[TimedSessionController alloc] init];
rt300@29 117 [tsc setAppRef:(id)this];
rt300@7 118 eventLogger.init();
rt300@24 119
rt300@28 120 // timer.init();
rt300@29 121 whichInterfaceShowing = BOTH; // but timer will change this
rt300@29 122
rt300@28 123
rt300@29 124 if(eventLogger.questionnaireCompleted){
rt300@29 125 [bottomTabViewController show:(id)this withSelection:1];
rt300@29 126 }
rt300@27 127 setAllGUISliders(theGridView.getParams());
rt300@24 128 // GO
rt300@16 129 paused = false;
rt300@29 130
rt300@32 131 randomise(); // everyone starts from random position
rt300@32 132
rt300@32 133 ofxiPhoneExternalDisplay::mirrorOn();
rt300@32 134
rt300@32 135 double timemsd = [NSDate timeIntervalSinceReferenceDate];
rt300@32 136 cout << "TIME: " << timemsd << '\n';
rt300@16 137
rt300@24 138 }
rt300@24 139
rt300@24 140
rt300@24 141 //--------------------------------------------------------------
rt300@24 142 void testApp::exit(){
rt300@25 143
rt300@25 144 presetManager.exitAndSaveAll();
rt300@25 145 eventLogger.exitAndSave();
rt300@25 146
rt300@24 147 core.exit();
rt300@24 148
rt300@25 149 // are these handled automatically?
rt300@25 150 //[introViewController release];
rt300@25 151 //[topButtonViewController release];
rt300@25 152 //[bottomTabViewController release];
rt300@24 153
rt300@24 154 delete sliderGUI;
rt300@24 155
rt300@24 156 cout << "exit done \n";
rt300@0 157 }
rt300@24 158
rt300@24 159 //--------------------------------------------------------------
rt300@3 160 #pragma mark GUI
rt300@16 161 //--
rt300@16 162 float testApp::getWidth(){
rt300@16 163 // depends on orientation
rt300@16 164 return ofGetWidth();
rt300@16 165
rt300@16 166 }
rt300@16 167 float testApp::getHeight(){
rt300@16 168 // depends on orientation
rt300@16 169 return ofGetHeight();
rt300@16 170
rt300@16 171 }
rt300@24 172 #pragma mark GUI
rt300@24 173 ////////////////////////////
rt300@24 174 // These functions called from iOS toolbars
rt300@24 175 //--------------------------------------------------------------
rt300@24 176 void testApp::lockSequencerPressed(bool locked){
rt300@24 177 theGridView.shiftCentreToSnapped();
rt300@24 178 xLocked = locked;
rt300@25 179 eventLogger.logEvent(SEQ_LOCKED);
rt300@25 180
rt300@24 181
rt300@24 182 }
rt300@24 183 //--------------------------------------------------------------
rt300@24 184 void testApp::lockSynthPressed(bool locked){
rt300@24 185 theGridView.shiftCentreToSnapped();
rt300@24 186 yLocked = locked;
rt300@25 187 eventLogger.logEvent(SYNTH_LOCKED);
rt300@24 188
rt300@24 189 }
rt300@24 190 //--------------------------------------------------------------
rt300@24 191 void testApp::seqStartStop(bool go){
rt300@24 192 if(!go){ //stop
rt300@24 193 core.pd.startMessage();
rt300@24 194 core.pd.addFloat(0);
rt300@24 195 core.pd.finishMessage("fromOF", "seqStartStop");
rt300@25 196 eventLogger.logEvent(PAUSE_PRESSED);
rt300@24 197 }else { // play
rt300@24 198 //stopSequencer();
rt300@24 199 core.pd.startMessage();
rt300@24 200 core.pd.addFloat(1);
rt300@24 201 core.pd.finishMessage("fromOF", "seqStartStop");
rt300@25 202 eventLogger.logEvent(PLAY_PRESSED);
rt300@24 203 }
rt300@24 204 }
rt300@24 205 //--------------------------------------------------------------
rt300@24 206 void testApp::showQuestionnaire(){
rt300@24 207 // stop updating / drawing
rt300@24 208
rt300@24 209 // if(eventLogger.questionnaireCompleted) return;
rt300@29 210
rt300@27 211 [topButtonViewController pausePressed:(id)this];
rt300@24 212
rt300@24 213 //stopSequencer
rt300@27 214 seqStartStop(false);
rt300@24 215
rt300@24 216 questionnaireViewController = [[QuestionnaireViewController alloc] initWithNibName:@"QuestionnaireViewController" bundle:nil];
rt300@24 217 [ofxiPhoneGetGLParentView() addSubview:questionnaireViewController.view];
rt300@24 218
rt300@24 219 [questionnaireViewController setAppRef:(id)this];
rt300@24 220 [questionnaireViewController show:(id)this];
rt300@24 221
rt300@24 222 whichInterfaceShowing = QUESTIONNAIRE;
rt300@24 223
rt300@24 224
rt300@24 225 }
rt300@24 226 //--------------------------------------------------------------
rt300@28 227 void testApp::questionnaireHidden(vector<int> answers, const char* userComments){
rt300@24 228 // send answers to server as json
rt300@28 229 eventLogger.questionnaireAnswersObtained(answers, userComments);
rt300@32 230
rt300@32 231 // tell bottomtabviewcontroller to show and select both interface
rt300@32 232 interfaceSelected(BOTH);
rt300@32 233 [bottomTabViewController show:(id)this withSelection:1];
rt300@24 234
rt300@29 235
rt300@24 236 }
rt300@24 237 //--------------------------------------------------------------
rt300@24 238 void testApp::showIntro(){
rt300@25 239
rt300@24 240 cout << "SHOW INTRO\n";
rt300@24 241
rt300@29 242 [tsc cancelTimers];
rt300@29 243 bottomTabViewController.view.hidden = YES;
rt300@24 244 introViewController = [[IntroViewController alloc] initWithNibName:@"IntroViewController" bundle:nil];
rt300@24 245 [ofxiPhoneGetGLParentView() addSubview:introViewController.view];
rt300@24 246
rt300@24 247 [introViewController setAppRef:(id)this];
rt300@24 248 [introViewController show:(id)this];
rt300@24 249
rt300@24 250
rt300@24 251 whichInterfaceShowing = INTRO;
rt300@24 252
rt300@24 253 }
rt300@24 254 //--------------------------------------------------------------
rt300@24 255 void testApp::introHidden(bool OK){
rt300@24 256 if(OK){
rt300@25 257 eventLogger.consentGiven = true;
rt300@29 258 //
rt300@29 259 // clear presets?
rt300@29 260 presetManager.clearAll();
rt300@25 261 // show username prompt
rt300@25 262 [usernameAlertViewController showUserNamePrompt];
rt300@32 263 // reset top buttons
rt300@32 264 [topButtonViewController unlockAll];
rt300@32 265 randomise();
rt300@24 266 }
rt300@24 267 // no unOK
rt300@24 268 }
rt300@24 269 //--------------------------------------------------------------
rt300@24 270 // called from BottomTabViewController iOS segmented thing
rt300@24 271 void testApp::interfaceSelected(int which){
rt300@24 272 switch (which){
rt300@24 273 case 0:
rt300@24 274
rt300@24 275 whichInterfaceShowing = SLIDERS;
rt300@24 276 sliderGUI->setVisible(true);
rt300@24 277 // set the slider values to stuff got from zoomer
rt300@24 278 sliderVals = theGridView.getParams();
rt300@24 279 setAllGUISliders(sliderVals);
rt300@25 280
rt300@24 281 break;
rt300@24 282 case 1:
rt300@24 283
rt300@24 284 whichInterfaceShowing = BOTH;
rt300@24 285 sliderGUI->setVisible(true);
rt300@24 286 // set the slider values to stuff got from zoomer
rt300@24 287 sliderVals = theGridView.getParams();
rt300@24 288 setAllGUISliders(sliderVals);
rt300@24 289 break;
rt300@24 290 case 2:
rt300@24 291
rt300@24 292 sliderGUI->setVisible(false);
rt300@24 293 whichInterfaceShowing = ZOOMER;
rt300@24 294 break;
rt300@24 295 }
rt300@25 296 eventLogger.logEvent(SWAP_VIEW,TwoVector(),0.0, which);
rt300@24 297 }
rt300@24 298 //--------------------------------------------------------------
rt300@24 299 //--------------------------------------------------------------
rt300@24 300 void testApp::setupSliderGui(){
rt300@24 301 float xInit = OFX_UI_GLOBAL_WIDGET_SPACING;
rt300@24 302 float length = SLIDER_GUI_WIDTH - (OFX_UI_GLOBAL_WIDGET_SPACING*2);
rt300@24 303
rt300@24 304
rt300@24 305 //float dim = 42;
rt300@24 306
rt300@24 307 // make this iphone size...?
rt300@24 308 int height = 480;
rt300@24 309 int width = 320;
rt300@24 310 float dim = (height-10.0*OFX_UI_GLOBAL_WIDGET_SPACING)/10.0;
rt300@24 311 // LEFT GUI
rt300@30 312 sliderGUI = new ofxUICanvas(0,160,SLIDER_GUI_WIDTH,getHeight());
rt300@30 313
rt300@24 314 // Uh.. loop this
rt300@24 315 for(int i = 1; i<=10;i++){
rt300@29 316
rt300@24 317 ofxUISlider *slider;
rt300@25 318 slider = (ofxUISlider *)sliderGUI->addWidgetDown(new ofxUISlider(length,dim,0.0,127,64,sliderParamNames[i-1]));
rt300@24 319 slider->setDrawPadding(true);
rt300@28 320 slider->setDrawPaddingOutline(true);
rt300@24 321 if(i <= 5){
rt300@24 322 slider->setColorFill(ofColor(0,0,255));
rt300@24 323 slider->setColorFillHighlight(ofColor(0,0,255));
rt300@24 324 }else{
rt300@24 325 slider->setColorFill(ofColor(255,0,0));
rt300@24 326 slider->setColorFillHighlight(ofColor(255,0,0));
rt300@24 327 }
rt300@24 328
rt300@24 329 sliders.push_back(slider);
rt300@24 330 }
rt300@24 331
rt300@24 332
rt300@24 333
rt300@24 334 ofAddListener(sliderGUI->newGUIEvent, this, &testApp::sliderGUIEvent);
rt300@24 335
rt300@24 336 }
rt300@24 337 //--------------------------------------------------------------
rt300@24 338 void testApp::sliderGUIEvent(ofxUIEventArgs &e){
rt300@24 339 if(whichInterfaceShowing == ZOOMER){
rt300@24 340 cout << "GUI ERROR";
rt300@24 341 return;
rt300@24 342 }
rt300@24 343
rt300@0 344 // "normal" parameter changes
rt300@0 345 for(int i = 1; i<=10;i++){
rt300@0 346
rt300@24 347 if(e.widget->getName() == sliderParamNames[i-1])
rt300@0 348 {
rt300@0 349 //cout << "param change: " << p;
rt300@0 350 ofxUISlider *slider = (ofxUISlider *) e.widget;
rt300@3 351 sliderMoved(i-1,slider->getScaledValue()); // internal array 0 indexed
rt300@0 352 }
rt300@0 353 }
rt300@24 354
rt300@0 355 }
rt300@0 356 //--------------------------------------------------------------
rt300@3 357 void testApp::sliderMoved(int which, float value){
rt300@3 358 // an update caused by slider view being touched
rt300@0 359 sliderVals[which] = (int)value;
rt300@0 360 theGridView.setParams(sliderVals);
rt300@24 361
rt300@3 362 sendParametersToPD();
rt300@5 363
rt300@9 364 eventLogger.logEvent(CHANGE_SLIDER, TwoVector(),0.0,which , value);
rt300@5 365
rt300@0 366 }
rt300@0 367 //--------------------------------------------------------------
rt300@3 368 void testApp::setAllGUISliders(vector<int> vals){
rt300@3 369 // an update caused by zoomer view being moved
rt300@25 370 for(int i = 0; i<NUM_PARAMS;i++){
rt300@0 371 sliders[i]->setValue(vals[i]);
rt300@1 372 sliderVals[i] = vals[i];
rt300@0 373 }
rt300@3 374
rt300@0 375 }
rt300@0 376 //--------------------------------------------------------------
rt300@25 377 void testApp::randomise(){
rt300@25 378 // pick random settings for all params
rt300@25 379 for(int i=0; i < NUM_PARAMS ; i++){
rt300@25 380 sliderVals[i] = ofRandom(0, 127);
rt300@25 381
rt300@25 382 }
rt300@25 383
rt300@25 384 // send to grid, sliders and PD
rt300@25 385 theGridView.setParams(sliderVals);
rt300@25 386 setAllGUISliders(sliderVals);
rt300@25 387 sendParametersToPD();
rt300@25 388
rt300@25 389 eventLogger.logEvent(RANDOMISE, theGridView.getCoord() ,0.0);
rt300@25 390
rt300@25 391 }
rt300@27 392 //-
rt300@27 393 void testApp::showHelp(){
rt300@29 394 whichInterfaceShowing = HELP;
rt300@27 395 seqStartStop(false);
rt300@27 396 [topButtonViewController pausePressed:(id)this];
rt300@27 397 helpViewController.view.hidden = NO;
rt300@27 398 eventLogger.logEvent(HELP_PRESSED);
rt300@27 399 }
rt300@27 400 void testApp::helpHidden(){
rt300@29 401 whichInterfaceShowing = BOTH;
rt300@27 402 // start seq?
rt300@27 403
rt300@27 404 }
rt300@25 405 //--------------------------------------------------------------
rt300@3 406 void testApp::sendParametersToPD(){
rt300@3 407 // frequencer stuff to get 16 steps
rt300@3 408 vector<double> vals;
rt300@3 409
rt300@3 410
rt300@3 411 vals.push_back((sliderVals[0]+32)*8.); // DC offset
rt300@3 412 for(int i=1; i<5;i++){
rt300@3 413 vals.push_back((sliderVals[i] - 64)*2.);
rt300@3 414 }
rt300@3 415
rt300@3 416 vector<double> steps = frequencer.freqMagEdit(freqIndexes, vals);
rt300@3 417 // send a list using the List object
rt300@3 418 List seqSteps;
rt300@3 419
rt300@3 420 seqSteps.addSymbol("seqSteps");
rt300@3 421 for(int i=0; i < 16; i++){
rt300@3 422 seqSteps.addFloat(round(steps[i])); // rounding here??
rt300@3 423 }
rt300@3 424
rt300@3 425 core.pd.sendList("fromOF", seqSteps);
rt300@8 426
rt300@3 427 sendOscShape(sliderVals[5]);
rt300@3 428 sendFiltType(sliderVals[6]);
rt300@3 429 sendFiltFreq(sliderVals[7]);
rt300@3 430 sendEnvShape(sliderVals[8]);
rt300@3 431 sendModFreq(sliderVals[9]);
rt300@3 432
rt300@3 433 }
rt300@27 434 void testApp::setupNewUser(){
rt300@27 435 // this function is for supervised trials with my ipad
rt300@27 436 eventLogger.newUser();
rt300@27 437 }
rt300@8 438 //--------------------------------------------------------------
rt300@3 439 #pragma mark STANDARD OF FUNCTIONS
rt300@3 440 //--------------------------------------------------------------
rt300@0 441 void testApp::update(){
rt300@27 442
rt300@16 443 if(paused) return;
rt300@16 444
rt300@32 445 if(ofxiPhoneExternalDisplay::isExternalScreenConnected()){
rt300@32 446 if(!ofxiPhoneExternalDisplay::isMirroring()){
rt300@32 447 ofxiPhoneExternalDisplay::mirrorOn();
rt300@32 448 printf("turned on Mirroring!\n");
rt300@32 449 }
rt300@32 450 }
rt300@32 451
rt300@27 452 // continiue to move or zoom at velocity, unless snapped
rt300@3 453
rt300@3 454 if (numActiveTouches == 0){ // no touches, use momentum
rt300@32 455 // ZOOM MOMENTUM
rt300@32 456 // continiue to zoom at velocity
rt300@32 457 if (numActiveTouches < 2 && abs(zoomVel)>0.001){
rt300@32 458 theGridView.zoom(zoomVel + 1.0); // +1 because zoomVel factor is + or - , wheras zoom is a multiplier near 1
rt300@32 459 zoomVel = zoomVel*slowFactor;
rt300@32 460 moveVel.setCoord(0.0,0.0);; // don't move if zooming! Too many events!
rt300@32 461 }
rt300@32 462
rt300@22 463 if(moveVel.norm() > 0.3){
rt300@22 464 if(theGridView.snapped){
rt300@28 465 // stop it (snap check sends snap event)
rt300@22 466 moveVel.setCoord(0.0,0.0);
rt300@22 467 }else{
rt300@22 468 theGridView.move(moveVel);
rt300@22 469 moveVel = moveVel*slowFactor;
rt300@22 470 }
rt300@3 471 // and get new parameter values
rt300@5 472 setAllGUISliders(theGridView.getParams());
rt300@3 473 sendParametersToPD();
rt300@22 474 }else if(moveVel.norm() > 0.01){ // and less than 0.3
rt300@3 475 // stop it
rt300@3 476 moveVel.setCoord(0.0,0.0);
rt300@5 477 setAllGUISliders(theGridView.getParams());
rt300@3 478 sendParametersToPD();
rt300@5 479 eventLogger.logEvent(SCROLL_STOPPED, theGridView.getCoord() );
rt300@22 480
rt300@3 481 }else{
rt300@3 482 // stopped - do nothing
rt300@3 483 }
rt300@32 484
rt300@32 485
rt300@3 486
rt300@0 487 }
rt300@32 488
rt300@6 489
rt300@0 490 }
rt300@0 491 //--------------------------------------------------------------
rt300@0 492 void testApp::sendOSCParams(){
rt300@0 493
rt300@0 494 vector<int> params = theGridView.getParams(); // FILTER HERE? NEED FLOATS...
rt300@0 495 vector<int>::iterator iter = params.begin();
rt300@0 496
rt300@0 497 ofxOscMessage m;
rt300@0 498 m.setAddress( "p" );
rt300@0 499
rt300@0 500 for(;iter < params.end();iter++){
rt300@0 501
rt300@0 502 m.addFloatArg( *iter );
rt300@0 503
rt300@0 504 }
rt300@0 505 sender.sendMessage( m );
rt300@0 506 }
rt300@0 507 //--------------------------------------------------------------
rt300@0 508 void testApp::draw(){
rt300@24 509
rt300@24 510 switch (whichInterfaceShowing){
rt300@24 511 case SLIDERS:
rt300@24 512 break;
rt300@24 513 case ZOOMER:
rt300@24 514 theGridView.draw();
rt300@24 515 break;
rt300@24 516 case BOTH:
rt300@24 517
rt300@24 518 theGridView.draw();
rt300@24 519 break;
rt300@24 520 case INTRO:
rt300@24 521 break;
rt300@24 522
rt300@24 523 case QUESTIONNAIRE:
rt300@24 524 break;
rt300@24 525
rt300@0 526 }
rt300@4 527
rt300@0 528 }
rt300@0 529
rt300@0 530 //--------------------------------------------------------------
rt300@0 531 void testApp::touchDown(ofTouchEventArgs &touch){
rt300@27 532 // in slider gui area?
rt300@24 533 if(whichInterfaceShowing == SLIDERS){
rt300@24 534 return;
rt300@24 535 }else if (whichInterfaceShowing == BOTH && touch.x < (SLIDER_GUI_WIDTH+10)){
rt300@24 536 return;
rt300@24 537
rt300@24 538 }// otherwise we're good to let the zoomer handle touch
rt300@0 539
rt300@0 540 numActiveTouches++;
rt300@27 541 preventingMovePostScroll = false;
rt300@27 542
rt300@0 543 if(touch.id == 0){
rt300@0 544 touch0.setCoord(touch.x,touch.y);
rt300@0 545 prevTouch0 = touch0;
rt300@32 546 // stop zoom
rt300@32 547 zoomVel = 0.0;
rt300@0 548 }else if(touch.id == 1){
rt300@0 549
rt300@0 550 touch1.setCoord(touch.x,touch.y);
rt300@0 551 prevTouch1 = touch1;
rt300@0 552
rt300@0 553 }
rt300@0 554 if(numActiveTouches == 1){
rt300@0 555 moveVel.setCoord(0.0, 0.0);
rt300@0 556 prevMove.setCoord(0.0, 0.0);
rt300@0 557 prevMove2.setCoord(0.0, 0.0);
rt300@27 558
rt300@0 559 }else if(numActiveTouches == 2){
rt300@0 560 zoomVel = 0.0;
rt300@0 561 prevZoom = 0.0;
rt300@0 562 prevZoom2 = 0.0;
rt300@0 563 double dist = touch1.distanceTo(touch0);
rt300@0 564 prevDist = dist;
rt300@0 565 }
rt300@0 566
rt300@0 567 }
rt300@0 568
rt300@0 569 //--------------------------------------------------------------
rt300@0 570 void testApp::touchMoved(ofTouchEventArgs &touch){
rt300@1 571
rt300@24 572 // TODO check if in gui area!!!
rt300@24 573 if(whichInterfaceShowing == SLIDERS){
rt300@24 574 return;
rt300@24 575 }else if (whichInterfaceShowing == BOTH && touch.x < (SLIDER_GUI_WIDTH+10)){
rt300@24 576 return;
rt300@24 577
rt300@27 578 }
rt300@24 579
rt300@27 580 // otherwise we're good to let the zoomer handle touch
rt300@0 581
rt300@1 582 // which one? keep track of each touch point
rt300@0 583 if(touch.id == 0){
rt300@0 584 touch0.setCoord(touch.x,touch.y);
rt300@0 585
rt300@0 586 }else if(touch.id == 1){
rt300@0 587
rt300@0 588 touch1.setCoord(touch.x,touch.y);
rt300@0 589 }
rt300@0 590
rt300@1 591 if(numActiveTouches == 1){
rt300@27 592 if(preventingMovePostScroll) return;
rt300@1 593 handleScroll();
rt300@0 594 }else if(numActiveTouches == 2){
rt300@1 595 handleZoom();
rt300@0 596
rt300@0 597 }
rt300@0 598 prevTouch0 = touch0;
rt300@0 599
rt300@0 600
rt300@0 601 }
rt300@5 602
rt300@1 603 //--------------------------------------------------------------
rt300@27 604 // handle a finger being dragged
rt300@1 605 void testApp::handleScroll(){
rt300@6 606
rt300@1 607 TwoVector move = touch0 - prevTouch0;
rt300@5 608 if(yLocked){
rt300@5 609 move.y = 0.0;
rt300@5 610 }
rt300@5 611 if(xLocked){
rt300@5 612 move.x = 0.0;
rt300@5 613 }
rt300@5 614
rt300@6 615 // check time since last move - if
rt300@6 616 unsigned int moveTime = ofGetSystemTimeMicros();
rt300@6 617 if(moveTime - lastMoveTime > 100000){
rt300@6 618 moveVel = TwoVector(); // zero
rt300@6 619 }else{
rt300@6 620 moveVel = (move*0.3 + prevMove*0.34 + prevMove2*0.38); // use the time
rt300@6 621
rt300@6 622 }
rt300@6 623 lastMoveTime = moveTime;
rt300@6 624
rt300@5 625
rt300@1 626 prevMove2 = prevMove;
rt300@1 627 prevMove = move;
rt300@1 628
rt300@5 629
rt300@3 630 theGridView.move(move);
rt300@3 631
rt300@3 632 // and get new parameter values
rt300@3 633 setAllGUISliders(theGridView.getParams());
rt300@3 634 sendParametersToPD();
rt300@1 635 }
rt300@1 636 //--------------------------------------------------------------
rt300@27 637 // handle pinch movememnt
rt300@1 638 void testApp::handleZoom(){
rt300@1 639 // work out change in difference
rt300@1 640 double dist = touch1.distanceTo(touch0);
rt300@1 641 double zoomFactor = prevDist/dist;
rt300@1 642
rt300@1 643 //TODO check for sensible maximums, e.g. spurious touch data
rt300@1 644 if(zoomFactor > 2.0 || zoomFactor < 0.5){
rt300@1 645 cout << "Zoom too much!!!!" << zoomFactor;
rt300@1 646 zoomFactor = 1.0;
rt300@1 647 }
rt300@1 648
rt300@1 649 zoomVel = (zoomFactor-1)*0.3 + prevZoom*0.34 + prevZoom2*0.38;
rt300@1 650 prevZoom2 = prevZoom;
rt300@1 651 prevZoom = (zoomFactor-1);
rt300@1 652
rt300@1 653 theGridView.zoom(zoomFactor);
rt300@1 654
rt300@1 655 prevDist = dist;
rt300@3 656
rt300@1 657 }
rt300@0 658 //--------------------------------------------------------------
rt300@0 659 void testApp::touchUp(ofTouchEventArgs &touch){
rt300@1 660 if(numActiveTouches > 0) numActiveTouches--; // dirty
rt300@27 661 preventingMovePostScroll = false;
rt300@24 662 // TODO check if in gui area!!!
rt300@24 663 if(whichInterfaceShowing == SLIDERS){
rt300@24 664 return;
rt300@24 665 }else if (whichInterfaceShowing == BOTH && touch.x < 256){
rt300@24 666 return;
rt300@1 667
rt300@24 668 }// otherwise we're good to let the zoomer handle touch
rt300@24 669
rt300@1 670
rt300@0 671 // which one?
rt300@0 672 if(touch.id == 0){
rt300@0 673 // tricky situation - we tried to zoom but may have left non-move finger on
rt300@0 674 prevTouch0.setCoord(touch.x,touch.y);
rt300@0 675
rt300@0 676 }else if(touch.id == 1){
rt300@0 677
rt300@0 678
rt300@0 679 prevTouch1.setCoord(0,0);
rt300@6 680
rt300@6 681 }
rt300@6 682 if(numActiveTouches == 0){
rt300@6 683 // check time since last move
rt300@6 684 // check time since last move - if
rt300@6 685 unsigned int moveTime = ofGetSystemTimeMicros();
rt300@6 686 if(moveTime - lastMoveTime > 100000){
rt300@6 687 moveVel = TwoVector(); // zero
rt300@6 688 }else{
rt300@6 689 moveVel = (move*0.3 + prevMove*0.34 + prevMove2*0.38); // use the time
rt300@6 690
rt300@6 691 }
rt300@6 692 lastMoveTime = moveTime;
rt300@27 693 }else if (numActiveTouches == 1){
rt300@27 694 // just zoomed , but now lifted one of the fingers
rt300@27 695 // can be bad if moved so create special mode to stop scroll (special modes bad!)
rt300@27 696 preventingMovePostScroll = true;
rt300@0 697 }
rt300@0 698
rt300@0 699 }
rt300@0 700
rt300@0 701 //--------------------------------------------------------------
rt300@0 702 void testApp::touchDoubleTap(ofTouchEventArgs &touch){
rt300@0 703 // preset?
rt300@25 704
rt300@25 705 /* ballses everything for some reason
rt300@25 706 TwoVector centre = TwoVector(getWidth()*0.5,getHeight()*0.5);
rt300@25 707 // if near centre
rt300@25 708 if((touch.x < centre.x+10) && (touch.x > centre.x-10) && (touch.y < centre.y+10) && (touch.y > centre.y-10)){
rt300@25 709 numActiveTouches = 0; // dirty
rt300@25 710 presetManager.showNameDialog();
rt300@25 711
rt300@25 712 }
rt300@25 713 */
rt300@25 714
rt300@0 715 }
rt300@0 716
rt300@0 717 //--------------------------------------------------------------
rt300@0 718 void testApp::lostFocus(){
rt300@0 719
rt300@0 720 }
rt300@0 721
rt300@0 722 //--------------------------------------------------------------
rt300@0 723 void testApp::gotFocus(){
rt300@0 724
rt300@0 725 }
rt300@0 726
rt300@0 727 //--------------------------------------------------------------
rt300@0 728 void testApp::gotMemoryWarning(){
rt300@0 729
rt300@0 730 }
rt300@0 731
rt300@0 732 //--------------------------------------------------------------
rt300@0 733 void testApp::deviceOrientationChanged(int newOrientation){
rt300@16 734 /*
rt300@0 735 cout << "orientation: " << newOrientation;
rt300@15 736
rt300@0 737 if(newOrientation == 4){
rt300@16 738 ofxiPhoneSetOrientation( OF_ORIENTATION_DEFAULT );
rt300@16 739
rt300@0 740 }else if(newOrientation == 3){
rt300@0 741 ofxiPhoneSetOrientation( OF_ORIENTATION_90_LEFT );
rt300@16 742 }else if(newOrientation == 3){
rt300@16 743 ofxiPhoneSetOrientation( OF_ORIENTATION_90_LEFT );
rt300@16 744 }
rt300@16 745
rt300@16 746
rt300@16 747 [ofxiPhoneGetGLView() updateDimensions];
rt300@16 748 */
rt300@0 749 }
rt300@0 750
rt300@0 751
rt300@0 752 //--------------------------------------------------------------
rt300@0 753 void testApp::touchCancelled(ofTouchEventArgs& args){
rt300@0 754
rt300@0 755 }
rt300@3 756 //---------------------------------------------------------------
rt300@3 757 // AUDIO STUFF
rt300@3 758 //---------------------------------------------------------------
rt300@3 759
rt300@3 760 #pragma mark AUDIO STREAMS
rt300@3 761 //--------------------------------------------------------------
rt300@3 762 void testApp::audioReceived(float * input, int bufferSize, int nChannels) {
rt300@3 763 core.audioReceived(input, bufferSize, nChannels);
rt300@3 764 }
rt300@3 765
rt300@3 766 void testApp::audioRequested(float * output, int bufferSize, int nChannels) {
rt300@3 767 core.audioRequested(output, bufferSize, nChannels);
rt300@3 768 }
rt300@3 769 //---------------------------------------------------------------
rt300@3 770 #pragma mark UTILITIES
rt300@0 771
rt300@0 772 // 5hz cut off
rt300@0 773 const double fB[3] = {0.049489956268677, 0.098979912537354, 0.049489956268677};
rt300@0 774
rt300@0 775 const double fA[3] = {1.000000000000000, -1.279632424997809, 0.477592250072517};
rt300@0 776
rt300@0 777 // 1hz cut off
rt300@0 778 //const double fB[3] = {0.002550535158536, 0.005101070317073, 0.002550535158536};
rt300@0 779
rt300@0 780 //const double fA[3] = {1.000000000000000, -1.852146485395936, 0.862348626030081};
rt300@0 781
rt300@0 782
rt300@0 783 //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 784 //---------------------------------------------------------------
rt300@0 785 vector<float> testApp::vectorFilter(vector<float> newVec){
rt300@0 786 static vector<float> x0(10,0);
rt300@0 787 static vector<float> x1(10,0);
rt300@0 788 static vector<float> x2(10,0);
rt300@0 789 static vector<float> y0(10,0);
rt300@0 790 static vector<float> y1(10,0);
rt300@0 791 static vector<float> y2(10,0);
rt300@0 792
rt300@0 793 x0 = newVec;
rt300@0 794
rt300@0 795 // this low passes a bunch of params values all at once
rt300@0 796 int sz = newVec.size();
rt300@0 797 for(int i=0; i<sz; i++){
rt300@0 798 y0[i] = fB[0]*x0[i] + fB[1]*x1[i] + fB[2]*x2[i] - fA[1]*y1[i] - fA[2]*y2[i];
rt300@0 799 }
rt300@0 800 // shift
rt300@0 801 x2 = x1;
rt300@0 802 x1 = x0;
rt300@0 803 y2 = y1;
rt300@0 804 y1 = y0;
rt300@0 805
rt300@0 806 return y0;
rt300@2 807 }
rt300@24 808 float ctrlSmoother(float newsamp){
rt300@24 809 static float x1,x2,y1,y2;
rt300@24 810 float x0, y0;
rt300@24 811
rt300@24 812 x0 = newsamp;
rt300@24 813
rt300@24 814 y0 = fB[0]*x0 + fB[1]*x1 + fB[2]*x2 - fA[1]*y1 - fA[2]*y2;
rt300@24 815
rt300@24 816 // shift
rt300@24 817 x2 = x1;
rt300@24 818 x1 = x0;
rt300@24 819 y2 = y1;
rt300@24 820 y1 = y0;
rt300@24 821
rt300@24 822 return y0;
rt300@24 823 }
rt300@8 824 //---------------------------------------------------------------
rt300@3 825 void testApp::sendOscShape(int ctrlin){
rt300@3 826
rt300@3 827 static int numpoints = 5;
rt300@3 828 static int numcontrols = 5;
rt300@3 829 //float values[points][controls] =
rt300@3 830 float ctrlout[numcontrols];
rt300@3 831 string ctrlName[5] = {"pWidth" , "sqVol", "sawVol", "sineVol", "FMAmt"};
rt300@3 832 float values[5][5] =
rt300@3 833 {{0.5, 0., 0., 1., 1.}, // 0
rt300@3 834 {0.5, 0., 0., 1., 0.}, // 32
rt300@3 835 {0.5, 0., 1., 0., 0.}, // 64
rt300@3 836 {0.5, 1., 1., 0., 0.}, // 96
rt300@3 837 {0.01,1., 1., 0., 0.}}; // 127
rt300@3 838
rt300@3 839 float fidx = (numpoints-1)*ctrlin/128.;
rt300@3 840 int idx = floor(fidx);
rt300@3 841 float frac = fidx - idx;
rt300@3 842 for(int i=0; i < numcontrols; i++){
rt300@3 843 ctrlout[i] = (1 - frac)*values[idx][i] + (frac)*values[idx+1][i];
rt300@3 844 // send to PD
rt300@3 845 List toPD;
rt300@3 846
rt300@3 847 toPD.addSymbol(ctrlName[i]);
rt300@3 848 toPD.addFloat(ctrlout[i]); // rounding here??
rt300@3 849
rt300@3 850 core.pd.sendList("fromOF", toPD);
rt300@3 851 //cout << ctrlName[i] << "sending" << ctrlout[i] << "\n";
rt300@3 852 }
rt300@3 853
rt300@2 854 }
rt300@8 855 //---------------------------------------------------------------
rt300@3 856 void testApp::sendFiltType(int ctrlin){
rt300@3 857 static int numpoints = 3;
rt300@3 858 static int numcontrols = 4;
rt300@3 859 //float values[points][controls] =
rt300@3 860 float ctrlout[numcontrols];
rt300@3 861 string ctrlName[4] = {"lpLev" , "bpLev", "hpLev", "reson"};
rt300@3 862 float values[3][4] =
rt300@24 863 {{2., 0., 0., 1.}, // 0
rt300@24 864 {0., 10., 0., 10.}, // 64
rt300@24 865 {0., 0., 1., 1.}}; // 127
rt300@3 866
rt300@3 867 float fidx = (numpoints-1)*ctrlin/128.;
rt300@3 868 int idx = floor(fidx);
rt300@3 869 float frac = fidx - idx;
rt300@3 870 for(int i=0; i < numcontrols; i++){
rt300@3 871 ctrlout[i] = (1 - frac)*values[idx][i] + (frac)*values[idx+1][i];
rt300@3 872 // send to PD
rt300@3 873 List toPD;
rt300@3 874
rt300@3 875 toPD.addSymbol(ctrlName[i]);
rt300@3 876 toPD.addFloat(ctrlout[i]); // rounding here??
rt300@3 877
rt300@3 878 core.pd.sendList("fromOF", toPD);
rt300@3 879 //cout << ctrlName[i] << "sending" << ctrlout[i] << "\n";
rt300@3 880 }
rt300@2 881 }
rt300@8 882 //---------------------------------------------------------------
rt300@3 883 void testApp::sendFiltFreq(int ctrlin){
rt300@24 884 // smooth this
rt300@24 885 float fin = ctrlin;
rt300@24 886 float fout;
rt300@24 887 fout = (int)ctrlSmoother(fin);
rt300@3 888 List toPD;
rt300@3 889
rt300@3 890 toPD.addSymbol("filtFreq");
rt300@24 891 toPD.addFloat(fout);
rt300@3 892
rt300@3 893 core.pd.sendList("fromOF", toPD);
rt300@3 894 }
rt300@8 895 //---------------------------------------------------------------
rt300@3 896 void testApp::sendEnvShape(int ctrlin){
rt300@3 897 static int numpoints = 5;
rt300@3 898 static int numcontrols = 3;
rt300@3 899 //float values[points][controls] =
rt300@3 900 float ctrlout[numcontrols];
rt300@3 901 string ctrlName[3] = {"attack" , "decay", "sustain"};
rt300@3 902 float values[5][3] =
rt300@3 903 {{0., 0., 0.}, // 0
rt300@3 904 {0., 0.5, 0.}, // 32
rt300@3 905 {0.0, 1., 0.8}, // 64
rt300@3 906 {0.99, 0.3, 0.}, // 96
rt300@3 907 {0.3, 0.1, 0.}}; // 127
rt300@3 908
rt300@3 909 float fidx = (numpoints-1)*ctrlin/128.;
rt300@3 910 int idx = floor(fidx);
rt300@3 911 float frac = fidx - idx;
rt300@3 912 for(int i=0; i < numcontrols; i++){
rt300@3 913 ctrlout[i] = (1 - frac)*values[idx][i] + (frac)*values[idx+1][i];
rt300@3 914 // send to PD
rt300@3 915 List toPD;
rt300@3 916
rt300@3 917 toPD.addSymbol(ctrlName[i]);
rt300@3 918 toPD.addFloat(ctrlout[i]); // rounding here??
rt300@3 919
rt300@3 920 core.pd.sendList("fromOF", toPD);
rt300@3 921 //cout << ctrlName[i] << "sending" << ctrlout[i] << "\n";
rt300@3 922 }
rt300@3 923 }
rt300@8 924 //---------------------------------------------------------------
rt300@3 925 void testApp::sendModFreq(int ctrlin){
rt300@3 926 float fm = ctrlin/127.;
rt300@3 927 List toPD;
rt300@3 928
rt300@3 929 toPD.addSymbol("FMFreq");
rt300@3 930 toPD.addFloat(fm); // rounding here??
rt300@3 931
rt300@3 932 core.pd.sendList("fromOF", toPD);
rt300@8 933 }
rt300@8 934 //---------------------------------------------------------------