annotate testApp.mm @ 30:c0a6f7c66719

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