annotate testApp.mm @ 15:e45c3e631d20

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