annotate testApp.mm @ 49:178642d134a7 tip

xtra files
author Robert Tubb <rt300@eecs.qmul.ac.uk>
date Wed, 01 May 2013 17:34:33 +0100
parents 0d3a993405e4
children
rev   line source
rt300@0 1 #include "testApp.h"
rt300@2 2
rt300@39 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@35 8 extern Hilbert hilbert;
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@46 15 // really GUI and all that stuff should be somewhere else
rt300@46 16
rt300@43 17 //--------------------------------------------------------------
rt300@43 18 void testApp::setup(){
rt300@43 19
rt300@43 20 // initilaise
rt300@43 21
rt300@43 22 initialiseVariables();
rt300@43 23 initialiseGUIs();
rt300@43 24
rt300@43 25 // initialise PD
rt300@43 26
rt300@43 27 int ticksPerBuffer = 8; // 8 * 64 = buffer len of 512
rt300@43 28 core.setup(2, 1, 44100, ticksPerBuffer);
rt300@46 29 // send to PD
rt300@46 30 List toPD;
rt300@46 31 toPD.addSymbol("smoothing");
rt300@46 32 toPD.addFloat(70); // rounding here??
rt300@46 33 core.pd.sendList("fromOF", toPD);
rt300@46 34 //cout << ctrlName[i] << "sending" << ctrlout[i] << "\n";
rt300@43 35
rt300@43 36 // setup OF sound stream
rt300@43 37 ofSoundStreamSetup(2, 1, this, 44100, ofxPd::blockSize()*ticksPerBuffer, 3);
rt300@43 38
rt300@43 39 tsc = [[TimedSessionController alloc] init];
rt300@43 40 [tsc setAppRef:(id)this];
rt300@43 41
rt300@43 42 //--------------------------------------
rt300@43 43 // load stuff
rt300@43 44 loadSequences();
rt300@43 45
rt300@43 46 // load presets
rt300@43 47 presetManager.startLoadAll();
rt300@43 48
rt300@43 49 eventLogger.startLoadAll();
rt300@43 50 //--------------------------------------
rt300@43 51
rt300@43 52 // now do things that will affect the start up state of the app
rt300@43 53
rt300@46 54 //if(true){
rt300@46 55 if(eventLogger.questionnaireCompleted){ // then we go into do-what-you-like mode
rt300@43 56
rt300@43 57 freeUseMode();
rt300@46 58 randomise();
rt300@43 59 }else{
rt300@43 60 // then we're in timed session mode
rt300@43 61 showIntro();
rt300@43 62 }
rt300@44 63
rt300@44 64 //freeUseMode();
rt300@43 65 // GO
rt300@43 66 paused = false;
rt300@43 67 eventLogger.logEvent(APP_STARTED);
rt300@43 68 }
rt300@24 69
rt300@43 70 //-----------------------------------------------------------------------------
rt300@35 71
rt300@7 72 //DeviceID3523537000
rt300@42 73 void testApp::initialiseVariables(){
rt300@46 74 animatingGrid = false;
rt300@16 75 paused = true;
rt300@39 76 sendMIDIAndOSC = false;
rt300@46 77 allowAnimation = false;
rt300@16 78 ofBackground( 0, 0, 0 );
rt300@0 79 ofEnableAlphaBlending();
rt300@36 80 currentSequence = 0;
rt300@40 81 //ofEnableSmoothing();
rt300@37 82
rt300@29 83 // open an outgoing connection to HOST:PORT for OSC
rt300@29 84
rt300@29 85 sender.setup( OSC_HOST, OSC_PORT );
rt300@28 86 ofSetFrameRate(50);
rt300@43 87
rt300@6 88 lastMoveTime = ofGetSystemTimeMicros();
rt300@0 89 prevTouchX = 0;
rt300@0 90 prevTouchY = 0;
rt300@0 91
rt300@0 92 xLocked = false;
rt300@0 93 yLocked = false;
rt300@0 94
rt300@0 95 numActiveTouches = 0;
rt300@3 96 touch0.setCoord(17./7., 2./3.);
rt300@0 97 touch1.setCoord(10,20);
rt300@3 98
rt300@0 99 prevTouch0.setCoord(1,2);
rt300@0 100 prevTouch1.setCoord(10,20);
rt300@0 101 prevDist = 10;
rt300@16 102 slowFactor = 0.98;
rt300@27 103 preventingMovePostScroll = false;
rt300@16 104
rt300@16 105 // the 5 harmonics for the frequencer
rt300@16 106 freqIndexes.push_back(0);
rt300@16 107 freqIndexes.push_back(4);
rt300@16 108 freqIndexes.push_back(6);
rt300@16 109 freqIndexes.push_back(7);
rt300@16 110 freqIndexes.push_back(8);
rt300@16 111
rt300@16 112
rt300@42 113 ofxiPhoneSetOrientation( OFXIPHONE_ORIENTATION_PORTRAIT );
rt300@42 114 ofxiPhoneExternalDisplay::mirrorOn();
rt300@42 115 }
rt300@43 116 //---------------------------------------------------------
rt300@42 117 void testApp::initialiseGUIs(){
rt300@0 118 theGridView.init();
rt300@0 119
rt300@43 120
rt300@43 121 //SLIDER
rt300@44 122 //setupSliderGui();
rt300@44 123 //sliderGUI->setVisible(false);
rt300@0 124
rt300@0 125 // initial slider vals
rt300@0 126 for(int i=0; i<10;i++){
rt300@0 127 sliderVals.push_back(64);
rt300@0 128 }
rt300@37 129
rt300@37 130
rt300@24 131 // set up iOS gui stuff
rt300@24 132 bottomTabViewController = [[BottomTabViewController alloc] initWithNibName:@"BottomTabViewController" bundle:nil];
rt300@24 133 [ofxiPhoneGetGLParentView() addSubview:bottomTabViewController.view];
rt300@24 134
rt300@24 135 [bottomTabViewController setAppRef:(id)this];
rt300@24 136 bottomTabViewController.view.frame = CGRectMake(0,getHeight()-44,getWidth(),44);
rt300@29 137 bottomTabViewController.view.hidden = YES;
rt300@37 138
rt300@24 139 /////
rt300@24 140
rt300@24 141 topButtonViewController = [[TopButtonViewController alloc] initWithNibName:@"TopButtonViewController" bundle:nil];
rt300@24 142 [ofxiPhoneGetGLParentView() addSubview:topButtonViewController.view];
rt300@24 143 [topButtonViewController setAppRef:(id)this];
rt300@24 144 [topButtonViewController show:(id)this];
rt300@24 145 topButtonViewController.view.frame = CGRectMake(0,0,getWidth(),44);
rt300@24 146
rt300@44 147
rt300@44 148
rt300@44 149 //SLIDER
rt300@44 150
rt300@44 151 sliderViewController = [[SliderViewController alloc] initWithNibName:@"SliderViewController" bundle:nil];
rt300@44 152 [ofxiPhoneGetGLParentView() addSubview:sliderViewController.view];
rt300@44 153 [sliderViewController setAppRef:(id)this];
rt300@44 154 sliderViewController.view.frame = CGRectMake(0,getHeight()-43 - 278,getWidth(),278);
rt300@44 155 [sliderViewController show:(id)this];
rt300@26 156
rt300@27 157 helpViewController = [[HelpViewController alloc] initWithNibName:@"HelpViewController" bundle:nil];
rt300@27 158 [ofxiPhoneGetGLParentView() addSubview:helpViewController.view];
rt300@27 159 [helpViewController setAppRef:(id)this];
rt300@27 160 helpViewController.view.hidden = YES;
rt300@27 161
rt300@44 162
rt300@44 163 usernameAlertViewController = [[UsernameAlertViewController alloc] init];
rt300@44 164 [usernameAlertViewController setAppRef:(id)this];
rt300@36 165
rt300@47 166
rt300@47 167 //////
rt300@47 168
rt300@47 169
rt300@47 170 /////////
rt300@47 171
rt300@42 172 setAllGUISliders(theGridView.getParams());
rt300@25 173
rt300@42 174 }
rt300@43 175 //--------------------------------------------------------------------------
rt300@42 176 void testApp::initialiseMIDI(){
rt300@36 177
rt300@39 178 /////////////////////////
rt300@39 179 // MIDI
rt300@39 180
rt300@39 181 midiChannel = 7;
rt300@47 182 midiOffset = 12;
rt300@39 183
rt300@39 184 // enables the network midi session between iOS and Mac OSX on a
rt300@39 185 // local wifi network
rt300@39 186 //
rt300@39 187 // in ofxMidi: open the input/outport network ports named "Session 1"
rt300@39 188 //
rt300@39 189 // on OSX: use the Audio MIDI Setup Utility to connect to the iOS device
rt300@39 190 //
rt300@39 191 ofxMidi::enableNetworking();
rt300@39 192
rt300@39 193 // list the number of available input & output ports
rt300@39 194 ofxMidiIn::listPorts();
rt300@39 195 ofxMidiOut::listPorts();
rt300@39 196
rt300@39 197 // create and open input ports
rt300@39 198 for(int i = 0; i < ofxMidiIn::getNumPorts(); ++i) {
rt300@39 199
rt300@39 200 // new object
rt300@39 201 inputs.push_back(new ofxMidiIn);
rt300@39 202
rt300@39 203 // set this class to receive incoming midi events
rt300@39 204 inputs[i]->addListener(this);
rt300@39 205
rt300@39 206 // open input port via port number
rt300@39 207 inputs[i]->openPort(i);
rt300@39 208 }
rt300@39 209
rt300@39 210 // create and open output ports
rt300@39 211 for(int i = 0; i < ofxMidiOut::getNumPorts(); ++i) {
rt300@39 212
rt300@39 213 // new object
rt300@39 214 outputs.push_back(new ofxMidiOut);
rt300@39 215
rt300@39 216 // open input port via port number
rt300@39 217 outputs[i]->openPort(i);
rt300@39 218 }
rt300@39 219
rt300@39 220 // set this class to receieve midi device (dis)connection events
rt300@39 221 ofxMidi::setConnectionListener(this);
rt300@39 222
rt300@39 223 // END MIDI
rt300@42 224
rt300@42 225 }
rt300@24 226
rt300@24 227
rt300@24 228 //--------------------------------------------------------------
rt300@24 229 void testApp::exit(){
rt300@37 230
rt300@25 231 presetManager.exitAndSaveAll();
rt300@25 232 eventLogger.exitAndSave();
rt300@37 233
rt300@24 234 core.exit();
rt300@24 235
rt300@25 236 // are these handled automatically?
rt300@25 237 //[introViewController release];
rt300@25 238 //[topButtonViewController release];
rt300@25 239 //[bottomTabViewController release];
rt300@24 240
rt300@39 241 // clean up MIDI
rt300@39 242 for(int i = 0; i < inputs.size(); ++i) {
rt300@39 243 inputs[i]->closePort();
rt300@39 244 inputs[i]->removeListener(this);
rt300@39 245 delete inputs[i];
rt300@39 246 }
rt300@39 247
rt300@39 248 for(int i = 0; i < outputs.size(); ++i) {
rt300@39 249 outputs[i]->closePort();
rt300@39 250 delete outputs[i];
rt300@39 251 }
rt300@39 252
rt300@43 253 //SLIDER
rt300@44 254 //delete sliderGUI;
rt300@37 255
rt300@24 256 cout << "exit done \n";
rt300@0 257 }
rt300@24 258
rt300@24 259 //--------------------------------------------------------------
rt300@3 260 #pragma mark GUI
rt300@16 261 //--
rt300@16 262 float testApp::getWidth(){
rt300@16 263 // depends on orientation
rt300@16 264 return ofGetWidth();
rt300@16 265
rt300@16 266 }
rt300@16 267 float testApp::getHeight(){
rt300@16 268 // depends on orientation
rt300@16 269 return ofGetHeight();
rt300@16 270
rt300@16 271 }
rt300@24 272 #pragma mark GUI
rt300@24 273 ////////////////////////////
rt300@24 274 // These functions called from iOS toolbars
rt300@24 275 //--------------------------------------------------------------
rt300@24 276 void testApp::lockSequencerPressed(bool locked){
rt300@24 277 theGridView.shiftCentreToSnapped();
rt300@24 278 xLocked = locked;
rt300@39 279 eventLogger.logEvent(SEQ_LOCKED); // TODO whatabout unlock?
rt300@25 280
rt300@24 281
rt300@24 282 }
rt300@24 283 //--------------------------------------------------------------
rt300@24 284 void testApp::lockSynthPressed(bool locked){
rt300@24 285 theGridView.shiftCentreToSnapped();
rt300@24 286 yLocked = locked;
rt300@25 287 eventLogger.logEvent(SYNTH_LOCKED);
rt300@24 288
rt300@24 289 }
rt300@24 290 //--------------------------------------------------------------
rt300@24 291 void testApp::seqStartStop(bool go){
rt300@24 292 if(!go){ //stop
rt300@24 293 core.pd.startMessage();
rt300@24 294 core.pd.addFloat(0);
rt300@24 295 core.pd.finishMessage("fromOF", "seqStartStop");
rt300@25 296 eventLogger.logEvent(PAUSE_PRESSED);
rt300@24 297 }else { // play
rt300@24 298 //stopSequencer();
rt300@24 299 core.pd.startMessage();
rt300@24 300 core.pd.addFloat(1);
rt300@24 301 core.pd.finishMessage("fromOF", "seqStartStop");
rt300@25 302 eventLogger.logEvent(PLAY_PRESSED);
rt300@24 303 }
rt300@24 304 }
rt300@24 305 //--------------------------------------------------------------
rt300@24 306 void testApp::showQuestionnaire(){
rt300@24 307 // stop updating / drawing
rt300@37 308
rt300@24 309 // if(eventLogger.questionnaireCompleted) return;
rt300@37 310
rt300@27 311 [topButtonViewController pausePressed:(id)this];
rt300@24 312
rt300@24 313 //stopSequencer
rt300@27 314 seqStartStop(false);
rt300@24 315
rt300@24 316 questionnaireViewController = [[QuestionnaireViewController alloc] initWithNibName:@"QuestionnaireViewController" bundle:nil];
rt300@24 317 [ofxiPhoneGetGLParentView() addSubview:questionnaireViewController.view];
rt300@24 318
rt300@24 319 [questionnaireViewController setAppRef:(id)this];
rt300@24 320 [questionnaireViewController show:(id)this];
rt300@24 321
rt300@24 322 whichInterfaceShowing = QUESTIONNAIRE;
rt300@24 323
rt300@37 324
rt300@24 325 }
rt300@24 326 //--------------------------------------------------------------
rt300@28 327 void testApp::questionnaireHidden(vector<int> answers, const char* userComments){
rt300@24 328 // send answers to server as json
rt300@28 329 eventLogger.questionnaireAnswersObtained(answers, userComments);
rt300@39 330
rt300@39 331 freeUseMode();
rt300@37 332
rt300@39 333 }
rt300@39 334 //--------------------------------------------------------------
rt300@39 335 // shortcut function for testing
rt300@39 336 void testApp::justStart(){
rt300@39 337 freeUseMode();
rt300@39 338 }
rt300@39 339 //--------------------------------------------------------------
rt300@39 340 void testApp::freeUseMode(){
rt300@38 341 interfaceSelected(1);
rt300@32 342 [bottomTabViewController show:(id)this withSelection:1];
rt300@24 343
rt300@38 344 [topButtonViewController enableSmoothSwitch:(id)this];
rt300@37 345
rt300@39 346 sendMIDIAndOSC = true;
rt300@46 347 allowAnimation = true;
rt300@38 348 }
rt300@38 349 //--------------------------------------------------------------
rt300@38 350 void testApp::setInterp(int state){
rt300@38 351 if(state == 0){
rt300@38 352 theGridView.setInterpolation(Grid::NO_INTERPOLATION);
rt300@39 353 eventLogger.logEvent(SMOOTHING_OFF);
rt300@38 354 }else if(state == 1){
rt300@38 355 theGridView.setInterpolation(Grid::INTERPOLATE_GRID);
rt300@39 356 eventLogger.logEvent(SMOOTHING_ON);
rt300@38 357 }
rt300@38 358 // tell sliders and PD
rt300@38 359 setAllGUISliders(theGridView.getParams());
rt300@39 360
rt300@33 361 }
rt300@33 362 //--------------------------------------------------------------
rt300@24 363 void testApp::showIntro(){
rt300@37 364
rt300@24 365 cout << "SHOW INTRO\n";
rt300@37 366
rt300@29 367 [tsc cancelTimers];
rt300@29 368 bottomTabViewController.view.hidden = YES;
rt300@24 369 introViewController = [[IntroViewController alloc] initWithNibName:@"IntroViewController" bundle:nil];
rt300@24 370 [ofxiPhoneGetGLParentView() addSubview:introViewController.view];
rt300@24 371
rt300@24 372 [introViewController setAppRef:(id)this];
rt300@24 373 [introViewController show:(id)this];
rt300@24 374
rt300@24 375
rt300@24 376 whichInterfaceShowing = INTRO;
rt300@24 377
rt300@24 378 }
rt300@24 379 //--------------------------------------------------------------
rt300@24 380 void testApp::introHidden(bool OK){
rt300@24 381 if(OK){
rt300@25 382 eventLogger.consentGiven = true;
rt300@29 383 //
rt300@29 384 // clear presets?
rt300@46 385 //presetManager.clearAll();
rt300@25 386 // show username prompt
rt300@25 387 [usernameAlertViewController showUserNamePrompt];
rt300@32 388 // reset top buttons
rt300@32 389 [topButtonViewController unlockAll];
rt300@32 390 randomise();
rt300@24 391 }
rt300@24 392 // no unOK
rt300@24 393 }
rt300@24 394 //--------------------------------------------------------------
rt300@42 395 void testApp::startTimedSession(){
rt300@42 396 [tsc startTimer];
rt300@42 397 // timer will show alert and set interface
rt300@42 398 }
rt300@42 399 //--------------------------------------------------------------
rt300@39 400 // called from BottomTabViewController iOS segmented thing, also timed session controller
rt300@24 401 void testApp::interfaceSelected(int which){
rt300@47 402 if(whichInterfaceShowing == HELP){
rt300@47 403 // hide the help
rt300@47 404 [helpViewController hide:(id) this];
rt300@47 405 }
rt300@24 406 switch (which){
rt300@39 407 case 0: // slider
rt300@43 408 //SLIDER
rt300@24 409 whichInterfaceShowing = SLIDERS;
rt300@43 410
rt300@43 411 [sliderViewController show:(id)this];
rt300@24 412 // set the slider values to stuff got from zoomer
rt300@24 413 sliderVals = theGridView.getParams();
rt300@24 414 setAllGUISliders(sliderVals);
rt300@25 415
rt300@24 416 break;
rt300@39 417 case 1: // both
rt300@43 418 //SLIDER
rt300@24 419 whichInterfaceShowing = BOTH;
rt300@43 420
rt300@43 421 [sliderViewController show:(id)this];
rt300@24 422 // set the slider values to stuff got from zoomer
rt300@24 423 sliderVals = theGridView.getParams();
rt300@24 424 setAllGUISliders(sliderVals);
rt300@39 425
rt300@24 426 break;
rt300@39 427 case 2: // zoomer
rt300@43 428 //SLIDER
rt300@43 429
rt300@43 430 [sliderViewController hide:(id)this];
rt300@24 431 whichInterfaceShowing = ZOOMER;
rt300@24 432 break;
rt300@24 433 }
rt300@39 434 eventLogger.logEvent(SWAP_VIEW,theGridView.getCoord(),theGridView.getScale(), which);
rt300@24 435 }
rt300@24 436 //--------------------------------------------------------------
rt300@39 437
rt300@43 438
rt300@0 439 //--------------------------------------------------------------
rt300@3 440 void testApp::sliderMoved(int which, float value){
rt300@43 441
rt300@3 442 // an update caused by slider view being touched
rt300@0 443 sliderVals[which] = (int)value;
rt300@0 444 theGridView.setParams(sliderVals);
rt300@37 445
rt300@3 446 sendParametersToPD();
rt300@39 447 if(sendMIDIAndOSC){
rt300@39 448
rt300@39 449 sendMidiParam(which);
rt300@39 450 sendOSCParams();
rt300@39 451 }
rt300@5 452
rt300@44 453 eventLogger.logEvent(CHANGE_SLIDER, theGridView.getCoord(),0.0,which , value);
rt300@44 454
rt300@0 455 }
rt300@0 456 //--------------------------------------------------------------
rt300@3 457 void testApp::setAllGUISliders(vector<int> vals){
rt300@44 458
rt300@3 459 // an update caused by zoomer view being moved
rt300@46 460 // can be called by theGridView or testApp
rt300@46 461 // casues PD and midi to be sent
rt300@46 462
rt300@25 463 for(int i = 0; i<NUM_PARAMS;i++){
rt300@44 464 //sliders[i]->setValue(vals[i]);
rt300@1 465 sliderVals[i] = vals[i];
rt300@43 466
rt300@43 467 [sliderViewController setSlider:i to:vals[i]];
rt300@0 468 }
rt300@3 469
rt300@39 470 sendParametersToPD();
rt300@39 471 if(sendMIDIAndOSC){
rt300@39 472
rt300@39 473 sendMidiParams();
rt300@39 474 sendOSCParams();
rt300@39 475 }
rt300@39 476
rt300@0 477 }
rt300@0 478 //--------------------------------------------------------------
rt300@25 479 void testApp::randomise(){
rt300@25 480 // pick random settings for all params
rt300@39 481
rt300@39 482 // random zoom? no.
rt300@25 483 for(int i=0; i < NUM_PARAMS ; i++){
rt300@25 484 sliderVals[i] = ofRandom(0, 127);
rt300@25 485
rt300@25 486 }
rt300@37 487 currentSequence = ofRandom(0, sequences.size()-1);
rt300@25 488 // send to grid, sliders and PD
rt300@25 489 theGridView.setParams(sliderVals);
rt300@25 490 setAllGUISliders(sliderVals);
rt300@39 491
rt300@39 492
rt300@44 493 eventLogger.logEvent(RANDOMISE, theGridView.getCoord() ,theGridView.getScale());
rt300@25 494
rt300@25 495 }
rt300@39 496 //--------------------------------------------------------------
rt300@27 497 void testApp::showHelp(){
rt300@46 498 previousInterface = whichInterfaceShowing;
rt300@29 499 whichInterfaceShowing = HELP;
rt300@27 500 seqStartStop(false);
rt300@27 501 [topButtonViewController pausePressed:(id)this];
rt300@27 502 helpViewController.view.hidden = NO;
rt300@27 503 eventLogger.logEvent(HELP_PRESSED);
rt300@46 504
rt300@27 505 }
rt300@27 506 void testApp::helpHidden(){
rt300@46 507 whichInterfaceShowing = previousInterface;
rt300@27 508 // start seq?
rt300@27 509
rt300@27 510 }
rt300@25 511 //--------------------------------------------------------------
rt300@46 512 int testApp::nextSequence(){
rt300@36 513 currentSequence++;
rt300@36 514 if(currentSequence >= sequences.size()){
rt300@36 515 currentSequence = 0;
rt300@36 516 }
rt300@36 517 sendParametersToPD();
rt300@46 518 return currentSequence;
rt300@36 519 }
rt300@36 520 //--------------------------------------------------------------
rt300@39 521 //--------------------------------------------------------------
rt300@39 522 #pragma mark sending to pd and midi
rt300@3 523 void testApp::sendParametersToPD(){
rt300@37 524 static int previousSequence;
rt300@36 525
rt300@45 526 if(core.patchName == "synth5paramMM.pd"){
rt300@45 527 // frequencer stuff to get 16 steps
rt300@45 528
rt300@45 529 vector<double> vals;
rt300@45 530
rt300@45 531
rt300@45 532 vals.push_back((sliderVals[0]+32)*8.); // DC offset
rt300@45 533 for(int i=1; i<5;i++){
rt300@45 534 vals.push_back((sliderVals[i] - 64)*2.);
rt300@45 535 }
rt300@45 536
rt300@45 537 vector<double> steps = frequencer.freqMagEdit(freqIndexes, vals);
rt300@45 538 List seqSteps;
rt300@45 539 seqSteps.addSymbol("seqSteps");
rt300@45 540 for(int i=0; i < 16; i++){
rt300@45 541 seqSteps.addFloat(round(steps[i]));
rt300@45 542 }
rt300@45 543 core.pd.sendList("fromOF", seqSteps);
rt300@45 544
rt300@45 545
rt300@45 546 // send synth params
rt300@45 547 sendOscShape(sliderVals[5]);
rt300@45 548 sendFiltType(sliderVals[6]);
rt300@45 549 sendFiltFreq(sliderVals[7]);
rt300@45 550 sendEnvShape(sliderVals[8]);
rt300@45 551 sendModFreq(sliderVals[9]);
rt300@45 552
rt300@45 553 }else if (core.patchName == "synth10param.pd"){
rt300@45 554 // for 10 param synth we get sequence from saved presets
rt300@45 555 // and send 5 extra synth params
rt300@45 556 if(currentSequence != previousSequence){
rt300@45 557 List seqSteps;
rt300@45 558
rt300@45 559 seqSteps.addSymbol("seqSteps");
rt300@45 560 if(currentSequence >= sequences.size() || currentSequence < 0){
rt300@45 561 cout << "ERROR: not a valid sequence index\n";
rt300@45 562 for(int i=0; i < 16; i++){
rt300@45 563 seqSteps.addFloat(50);
rt300@45 564 }
rt300@45 565 }else{
rt300@45 566 for(int i=0; i < 16; i++){
rt300@45 567 seqSteps.addFloat(round(sequences[currentSequence][i]));
rt300@45 568 }
rt300@45 569 }
rt300@45 570
rt300@45 571 core.pd.sendList("fromOF", seqSteps);
rt300@45 572 previousSequence = currentSequence;
rt300@45 573 }
rt300@45 574 /*
rt300@45 575 @"Amp Env",@"Waveform",@"FM amount",@"FM frequency",@"Reverb",
rt300@45 576 @"Filter Type",@"Filter Cut off",@"Filter Resonance",@"Filter Envelope",@"SOMETHING",
rt300@45 577 */
rt300@45 578 // send synth params
rt300@45 579 sendAmpEnvShape(sliderVals[0]);
rt300@45 580 sendOscShape(sliderVals[1]);
rt300@45 581 sendFMAmt(sliderVals[2]);
rt300@45 582 sendModFreq(sliderVals[3]);
rt300@45 583 sendRevAmt(sliderVals[4]);
rt300@45 584
rt300@45 585 sendFiltType(sliderVals[5]);
rt300@45 586 sendFiltFreq(sliderVals[6]);
rt300@45 587 sendResonance(sliderVals[7]);
rt300@45 588 sendFiltEnvShape(sliderVals[8]);
rt300@45 589 sendFiltEnvModAmt(sliderVals[9]);
rt300@45 590 //sendUmame(sliderVals[8]);
rt300@45 591 //sendX(sliderVals[2]);
rt300@45 592 //sendX(sliderVals[3]);
rt300@45 593
rt300@45 594
rt300@45 595
rt300@45 596
rt300@45 597
rt300@45 598
rt300@37 599 }
rt300@45 600
rt300@37 601
rt300@36 602 /*
rt300@45 603 cout << "SLIDERVALS: ";
rt300@45 604 for(int i=0;i<10;i++){
rt300@45 605 cout << sliderVals[i] << ",";
rt300@3 606 }
rt300@45 607 cout << '\n';
rt300@45 608 */
rt300@3 609
rt300@3 610 }
rt300@39 611 //--------------------------------------------------------------
rt300@39 612 void testApp::sendMidiParam(int which){
rt300@39 613 int midiChannel = 7;
rt300@39 614 int offset = 0;
rt300@39 615
rt300@39 616 for(int i = 0; i < outputs.size(); ++i) {
rt300@39 617 outputs[i]->sendControlChange(midiChannel, offset+which, sliderVals[which]);
rt300@39 618 }
rt300@39 619
rt300@39 620
rt300@39 621 }
rt300@39 622 //--------------------------------------------------------------
rt300@39 623 void testApp::sendMidiParams(){
rt300@39 624
rt300@39 625 for(int i = 0; i< sliderVals.size(); i++){
rt300@39 626 for(int j = 0; j < outputs.size(); ++j) {
rt300@39 627 outputs[j]->sendControlChange(midiChannel, midiOffset+i, sliderVals[i]);
rt300@39 628 }
rt300@39 629 }
rt300@39 630
rt300@39 631 }
rt300@39 632 //--------------------------------------------------------------
rt300@39 633 void testApp::sendOSCParams(){
rt300@39 634
rt300@39 635 ofxOscMessage m;
rt300@39 636 m.setAddress( "sonicZoom" );
rt300@39 637
rt300@39 638 for(int i = 0; i< sliderVals.size(); i++){
rt300@39 639
rt300@39 640 m.addFloatArg(sliderVals[i]);
rt300@39 641
rt300@39 642 }
rt300@39 643 sender.sendMessage( m );
rt300@39 644 }
rt300@39 645 //--------------------------------------------------------------
rt300@39 646
rt300@27 647 void testApp::setupNewUser(){
rt300@27 648 // this function is for supervised trials with my ipad
rt300@27 649 eventLogger.newUser();
rt300@27 650 }
rt300@8 651 //--------------------------------------------------------------
rt300@3 652 #pragma mark STANDARD OF FUNCTIONS
rt300@3 653 //--------------------------------------------------------------
rt300@0 654 void testApp::update(){
rt300@37 655
rt300@16 656 if(paused) return;
rt300@16 657
rt300@46 658 if(theGridView.automatedMovementInProgress){
rt300@46 659 theGridView.update();
rt300@46 660 return;
rt300@46 661 }
rt300@46 662
rt300@32 663 if(ofxiPhoneExternalDisplay::isExternalScreenConnected()){
rt300@32 664 if(!ofxiPhoneExternalDisplay::isMirroring()){
rt300@32 665 ofxiPhoneExternalDisplay::mirrorOn();
rt300@32 666 printf("turned on Mirroring!\n");
rt300@32 667 }
rt300@32 668 }
rt300@32 669
rt300@46 670 if(animatingGrid){
rt300@46 671 // theGrid
rt300@46 672
rt300@46 673 }
rt300@27 674 // continiue to move or zoom at velocity, unless snapped
rt300@3 675
rt300@3 676 if (numActiveTouches == 0){ // no touches, use momentum
rt300@32 677 // ZOOM MOMENTUM
rt300@32 678 // continiue to zoom at velocity
rt300@32 679 if (numActiveTouches < 2 && abs(zoomVel)>0.001){
rt300@32 680 theGridView.zoom(zoomVel + 1.0); // +1 because zoomVel factor is + or - , wheras zoom is a multiplier near 1
rt300@32 681 zoomVel = zoomVel*slowFactor;
rt300@32 682 moveVel.setCoord(0.0,0.0);; // don't move if zooming! Too many events!
rt300@35 683
rt300@37 684 setAllGUISliders(theGridView.getParams());
rt300@39 685
rt300@32 686 }
rt300@44 687 // MOVE MOMENTUM
rt300@22 688 if(moveVel.norm() > 0.3){
rt300@22 689 if(theGridView.snapped){
rt300@28 690 // stop it (snap check sends snap event)
rt300@22 691 moveVel.setCoord(0.0,0.0);
rt300@22 692 }else{
rt300@22 693 theGridView.move(moveVel);
rt300@22 694 moveVel = moveVel*slowFactor;
rt300@22 695 }
rt300@37 696 // and get new parameter values
rt300@5 697 setAllGUISliders(theGridView.getParams());
rt300@39 698
rt300@22 699 }else if(moveVel.norm() > 0.01){ // and less than 0.3
rt300@3 700 // stop it
rt300@3 701 moveVel.setCoord(0.0,0.0);
rt300@5 702 setAllGUISliders(theGridView.getParams());
rt300@39 703
rt300@5 704 eventLogger.logEvent(SCROLL_STOPPED, theGridView.getCoord() );
rt300@22 705
rt300@3 706 }else{
rt300@3 707 // stopped - do nothing
rt300@3 708 }
rt300@37 709
rt300@0 710 }
rt300@37 711
rt300@0 712 }
rt300@0 713 //--------------------------------------------------------------
rt300@39 714
rt300@0 715 void testApp::draw(){
rt300@37 716
rt300@24 717 switch (whichInterfaceShowing){
rt300@24 718 case SLIDERS:
rt300@24 719 break;
rt300@24 720 case ZOOMER:
rt300@24 721 theGridView.draw();
rt300@37 722
rt300@24 723 break;
rt300@24 724 case BOTH:
rt300@33 725
rt300@33 726 theGridView.draw();
rt300@37 727
rt300@24 728 break;
rt300@24 729 case INTRO:
rt300@24 730 break;
rt300@24 731
rt300@24 732 case QUESTIONNAIRE:
rt300@24 733 break;
rt300@24 734
rt300@0 735 }
rt300@4 736
rt300@0 737 }
rt300@0 738
rt300@0 739 //--------------------------------------------------------------
rt300@0 740 void testApp::touchDown(ofTouchEventArgs &touch){
rt300@46 741 if(theGridView.automatedMovementInProgress) return;
rt300@46 742 if(whichInterfaceShowing == SLIDERS){
rt300@46 743 return;
rt300@46 744 }
rt300@0 745 numActiveTouches++;
rt300@27 746 preventingMovePostScroll = false;
rt300@44 747 tapFlag = false; // unless touch 0
rt300@0 748 if(touch.id == 0){
rt300@0 749 touch0.setCoord(touch.x,touch.y);
rt300@0 750 prevTouch0 = touch0;
rt300@32 751 // stop zoom
rt300@32 752 zoomVel = 0.0;
rt300@44 753 tapFlag = true;
rt300@0 754 }else if(touch.id == 1){
rt300@0 755
rt300@0 756 touch1.setCoord(touch.x,touch.y);
rt300@0 757 prevTouch1 = touch1;
rt300@0 758
rt300@0 759 }
rt300@0 760 if(numActiveTouches == 1){
rt300@0 761 moveVel.setCoord(0.0, 0.0);
rt300@0 762 prevMove.setCoord(0.0, 0.0);
rt300@0 763 prevMove2.setCoord(0.0, 0.0);
rt300@27 764
rt300@0 765 }else if(numActiveTouches == 2){
rt300@0 766 zoomVel = 0.0;
rt300@0 767 prevZoom = 0.0;
rt300@0 768 prevZoom2 = 0.0;
rt300@0 769 double dist = touch1.distanceTo(touch0);
rt300@0 770 prevDist = dist;
rt300@0 771 }
rt300@37 772
rt300@0 773 }
rt300@0 774
rt300@0 775 //--------------------------------------------------------------
rt300@0 776 void testApp::touchMoved(ofTouchEventArgs &touch){
rt300@46 777 if(theGridView.automatedMovementInProgress) return;
rt300@46 778 if(whichInterfaceShowing == SLIDERS){
rt300@46 779 return;
rt300@46 780 }
rt300@46 781
rt300@44 782 tapFlag = false;
rt300@1 783 // which one? keep track of each touch point
rt300@0 784 if(touch.id == 0){
rt300@0 785 touch0.setCoord(touch.x,touch.y);
rt300@0 786
rt300@0 787 }else if(touch.id == 1){
rt300@0 788
rt300@0 789 touch1.setCoord(touch.x,touch.y);
rt300@0 790 }
rt300@37 791
rt300@1 792 if(numActiveTouches == 1){
rt300@27 793 if(preventingMovePostScroll) return;
rt300@1 794 handleScroll();
rt300@0 795 }else if(numActiveTouches == 2){
rt300@1 796 handleZoom();
rt300@0 797
rt300@0 798 }
rt300@0 799 prevTouch0 = touch0;
rt300@37 800
rt300@0 801
rt300@0 802 }
rt300@5 803
rt300@1 804 //--------------------------------------------------------------
rt300@44 805 void testApp::touchUp(ofTouchEventArgs &touch){
rt300@46 806 if(theGridView.automatedMovementInProgress) return;
rt300@46 807 if(whichInterfaceShowing == SLIDERS){
rt300@46 808 return;
rt300@46 809 }
rt300@44 810 if(numActiveTouches > 0) numActiveTouches--; // dirty
rt300@44 811 preventingMovePostScroll = false;
rt300@44 812 // TODO check if in gui area!!!
rt300@44 813 //SLIDER
rt300@44 814 if(whichInterfaceShowing == SLIDERS){
rt300@44 815 return;
rt300@44 816 }
rt300@44 817
rt300@44 818 if(tapFlag){
rt300@44 819 cout << "TAP!!\n";
rt300@44 820 // look for close preset
rt300@46 821
rt300@44 822 theGridView.tap(TwoVector(touch.x,touch.y));
rt300@44 823 }
rt300@44 824 tapFlag = false;
rt300@44 825 // which one?
rt300@44 826 if(touch.id == 0){
rt300@44 827 // tricky situation - we tried to zoom but may have left non-move finger on
rt300@44 828 prevTouch0.setCoord(touch.x,touch.y);
rt300@44 829
rt300@44 830 }else if(touch.id == 1){
rt300@44 831
rt300@44 832
rt300@44 833 prevTouch1.setCoord(0,0);
rt300@44 834
rt300@44 835 }
rt300@44 836 if(numActiveTouches == 0){
rt300@44 837 // check time since last move
rt300@44 838 // check time since last move - if
rt300@44 839 unsigned int moveTime = ofGetSystemTimeMicros();
rt300@44 840 if(moveTime - lastMoveTime > 100000){
rt300@44 841 moveVel = TwoVector(); // zero
rt300@44 842 }else{
rt300@44 843 moveVel = (move*0.3 + prevMove*0.34 + prevMove2*0.38); // use the time
rt300@44 844
rt300@44 845 }
rt300@44 846 lastMoveTime = moveTime;
rt300@44 847 }else if (numActiveTouches == 1){
rt300@44 848 // just zoomed , but now lifted one of the fingers
rt300@44 849 // can be bad if moved so create special mode to stop scroll (special modes bad!)
rt300@44 850 preventingMovePostScroll = true;
rt300@44 851 }
rt300@44 852
rt300@44 853 }
rt300@44 854
rt300@44 855
rt300@44 856 //--------------------------------------------------------------
rt300@27 857 // handle a finger being dragged
rt300@1 858 void testApp::handleScroll(){
rt300@37 859
rt300@1 860 TwoVector move = touch0 - prevTouch0;
rt300@5 861 if(yLocked){
rt300@5 862 move.y = 0.0;
rt300@5 863 }
rt300@5 864 if(xLocked){
rt300@5 865 move.x = 0.0;
rt300@5 866 }
rt300@37 867
rt300@6 868 // check time since last move - if
rt300@6 869 unsigned int moveTime = ofGetSystemTimeMicros();
rt300@6 870 if(moveTime - lastMoveTime > 100000){
rt300@6 871 moveVel = TwoVector(); // zero
rt300@6 872 }else{
rt300@6 873 moveVel = (move*0.3 + prevMove*0.34 + prevMove2*0.38); // use the time
rt300@6 874
rt300@6 875 }
rt300@6 876 lastMoveTime = moveTime;
rt300@6 877
rt300@37 878
rt300@1 879 prevMove2 = prevMove;
rt300@1 880 prevMove = move;
rt300@1 881
rt300@37 882
rt300@3 883 theGridView.move(move);
rt300@3 884
rt300@3 885 // and get new parameter values
rt300@3 886 setAllGUISliders(theGridView.getParams());
rt300@39 887
rt300@1 888 }
rt300@1 889 //--------------------------------------------------------------
rt300@27 890 // handle pinch movememnt
rt300@1 891 void testApp::handleZoom(){
rt300@1 892 // work out change in difference
rt300@1 893 double dist = touch1.distanceTo(touch0);
rt300@1 894 double zoomFactor = prevDist/dist;
rt300@1 895
rt300@1 896 //TODO check for sensible maximums, e.g. spurious touch data
rt300@1 897 if(zoomFactor > 2.0 || zoomFactor < 0.5){
rt300@1 898 cout << "Zoom too much!!!!" << zoomFactor;
rt300@1 899 zoomFactor = 1.0;
rt300@1 900 }
rt300@1 901
rt300@1 902 zoomVel = (zoomFactor-1)*0.3 + prevZoom*0.34 + prevZoom2*0.38;
rt300@1 903 prevZoom2 = prevZoom;
rt300@1 904 prevZoom = (zoomFactor-1);
rt300@1 905
rt300@1 906 theGridView.zoom(zoomFactor);
rt300@1 907
rt300@1 908 prevDist = dist;
rt300@35 909
rt300@3 910
rt300@37 911 setAllGUISliders(theGridView.getParams());
rt300@39 912
rt300@37 913
rt300@37 914
rt300@1 915 }
rt300@0 916 //--------------------------------------------------------------
rt300@0 917 void testApp::touchDoubleTap(ofTouchEventArgs &touch){
rt300@0 918 // preset?
rt300@25 919
rt300@25 920 /* ballses everything for some reason
rt300@37 921 TwoVector centre = TwoVector(getWidth()*0.5,getHeight()*0.5);
rt300@37 922 // if near centre
rt300@37 923 if((touch.x < centre.x+10) && (touch.x > centre.x-10) && (touch.y < centre.y+10) && (touch.y > centre.y-10)){
rt300@37 924 numActiveTouches = 0; // dirty
rt300@37 925 presetManager.showNameDialog();
rt300@37 926
rt300@37 927 }
rt300@25 928 */
rt300@25 929
rt300@0 930 }
rt300@0 931
rt300@0 932 //--------------------------------------------------------------
rt300@0 933 void testApp::lostFocus(){
rt300@37 934
rt300@0 935 }
rt300@0 936
rt300@0 937 //--------------------------------------------------------------
rt300@0 938 void testApp::gotFocus(){
rt300@37 939
rt300@0 940 }
rt300@0 941
rt300@0 942 //--------------------------------------------------------------
rt300@0 943 void testApp::gotMemoryWarning(){
rt300@37 944
rt300@0 945 }
rt300@0 946
rt300@0 947 //--------------------------------------------------------------
rt300@0 948 void testApp::deviceOrientationChanged(int newOrientation){
rt300@37 949 /*
rt300@37 950 cout << "orientation: " << newOrientation;
rt300@37 951
rt300@37 952 if(newOrientation == 4){
rt300@37 953 ofxiPhoneSetOrientation( OF_ORIENTATION_DEFAULT );
rt300@37 954
rt300@37 955 }else if(newOrientation == 3){
rt300@37 956 ofxiPhoneSetOrientation( OF_ORIENTATION_90_LEFT );
rt300@37 957 }else if(newOrientation == 3){
rt300@37 958 ofxiPhoneSetOrientation( OF_ORIENTATION_90_LEFT );
rt300@37 959 }
rt300@37 960
rt300@37 961
rt300@37 962 [ofxiPhoneGetGLView() updateDimensions];
rt300@37 963 */
rt300@0 964 }
rt300@0 965
rt300@0 966
rt300@0 967 //--------------------------------------------------------------
rt300@0 968 void testApp::touchCancelled(ofTouchEventArgs& args){
rt300@37 969
rt300@0 970 }
rt300@3 971 //---------------------------------------------------------------
rt300@3 972 // AUDIO STUFF
rt300@3 973 //---------------------------------------------------------------
rt300@3 974
rt300@3 975 #pragma mark AUDIO STREAMS
rt300@3 976 //--------------------------------------------------------------
rt300@3 977 void testApp::audioReceived(float * input, int bufferSize, int nChannels) {
rt300@3 978 core.audioReceived(input, bufferSize, nChannels);
rt300@3 979 }
rt300@3 980
rt300@3 981 void testApp::audioRequested(float * output, int bufferSize, int nChannels) {
rt300@3 982 core.audioRequested(output, bufferSize, nChannels);
rt300@3 983 }
rt300@3 984 //---------------------------------------------------------------
rt300@3 985 #pragma mark UTILITIES
rt300@0 986
rt300@0 987 // 5hz cut off
rt300@0 988 const double fB[3] = {0.049489956268677, 0.098979912537354, 0.049489956268677};
rt300@0 989
rt300@0 990 const double fA[3] = {1.000000000000000, -1.279632424997809, 0.477592250072517};
rt300@0 991
rt300@0 992 // 1hz cut off
rt300@0 993 //const double fB[3] = {0.002550535158536, 0.005101070317073, 0.002550535158536};
rt300@0 994
rt300@0 995 //const double fA[3] = {1.000000000000000, -1.852146485395936, 0.862348626030081};
rt300@0 996
rt300@0 997
rt300@0 998 //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 999 //---------------------------------------------------------------
rt300@0 1000 vector<float> testApp::vectorFilter(vector<float> newVec){
rt300@0 1001 static vector<float> x0(10,0);
rt300@0 1002 static vector<float> x1(10,0);
rt300@0 1003 static vector<float> x2(10,0);
rt300@0 1004 static vector<float> y0(10,0);
rt300@0 1005 static vector<float> y1(10,0);
rt300@0 1006 static vector<float> y2(10,0);
rt300@0 1007
rt300@0 1008 x0 = newVec;
rt300@0 1009
rt300@0 1010 // this low passes a bunch of params values all at once
rt300@0 1011 int sz = newVec.size();
rt300@0 1012 for(int i=0; i<sz; i++){
rt300@0 1013 y0[i] = fB[0]*x0[i] + fB[1]*x1[i] + fB[2]*x2[i] - fA[1]*y1[i] - fA[2]*y2[i];
rt300@0 1014 }
rt300@0 1015 // shift
rt300@0 1016 x2 = x1;
rt300@0 1017 x1 = x0;
rt300@0 1018 y2 = y1;
rt300@0 1019 y1 = y0;
rt300@0 1020
rt300@0 1021 return y0;
rt300@2 1022 }
rt300@35 1023 //---------------------------------------------------------------
rt300@24 1024 float ctrlSmoother(float newsamp){
rt300@24 1025 static float x1,x2,y1,y2;
rt300@24 1026 float x0, y0;
rt300@37 1027
rt300@24 1028 x0 = newsamp;
rt300@37 1029
rt300@24 1030 y0 = fB[0]*x0 + fB[1]*x1 + fB[2]*x2 - fA[1]*y1 - fA[2]*y2;
rt300@37 1031
rt300@24 1032 // shift
rt300@24 1033 x2 = x1;
rt300@24 1034 x1 = x0;
rt300@24 1035 y2 = y1;
rt300@24 1036 y1 = y0;
rt300@24 1037
rt300@24 1038 return y0;
rt300@24 1039 }
rt300@8 1040 //---------------------------------------------------------------
rt300@45 1041 //---------------------------------------------------------------
rt300@45 1042 //---------------------------------------------------------------
rt300@45 1043 #pragma mark SYNTH PARAM SENDING TO PD CURVES
rt300@3 1044 void testApp::sendOscShape(int ctrlin){
rt300@35 1045 if(ctrlin < 0 || ctrlin > 127){
rt300@35 1046 cout << "ERROR: bad slider value!";
rt300@35 1047 return;
rt300@35 1048 }
rt300@3 1049
rt300@3 1050 static int numpoints = 5;
rt300@3 1051 static int numcontrols = 5;
rt300@3 1052 //float values[points][controls] =
rt300@3 1053 float ctrlout[numcontrols];
rt300@45 1054 string ctrlName[4] = {"pWidth" , "sqVol", "sawVol", "sineVol"};
rt300@45 1055 float values[5][4] =
rt300@45 1056 {{0.5, 0., 0., 1.}, // 0
rt300@45 1057 {0.5, 0., 0., 1.}, // 32
rt300@45 1058 {0.5, 0., 1., 0.}, // 64
rt300@45 1059 {0.5, 1., 1., 0.}, // 96
rt300@45 1060 {0.01,1., 1., 0.}}; // 127
rt300@37 1061
rt300@3 1062 float fidx = (numpoints-1)*ctrlin/128.;
rt300@3 1063 int idx = floor(fidx);
rt300@3 1064 float frac = fidx - idx;
rt300@3 1065 for(int i=0; i < numcontrols; i++){
rt300@3 1066 ctrlout[i] = (1 - frac)*values[idx][i] + (frac)*values[idx+1][i];
rt300@3 1067 // send to PD
rt300@3 1068 List toPD;
rt300@3 1069
rt300@3 1070 toPD.addSymbol(ctrlName[i]);
rt300@3 1071 toPD.addFloat(ctrlout[i]); // rounding here??
rt300@37 1072
rt300@3 1073 core.pd.sendList("fromOF", toPD);
rt300@3 1074 //cout << ctrlName[i] << "sending" << ctrlout[i] << "\n";
rt300@3 1075 }
rt300@3 1076
rt300@2 1077 }
rt300@8 1078 //---------------------------------------------------------------
rt300@3 1079 void testApp::sendFiltType(int ctrlin){
rt300@35 1080 if(ctrlin < 0 || ctrlin > 127){
rt300@35 1081 cout << "ERROR: bad slider value!";
rt300@35 1082 return;
rt300@35 1083 }
rt300@45 1084 /*
rt300@45 1085 static int numpoints = 3;
rt300@45 1086 static int numcontrols = 2;
rt300@45 1087 //float values[points][controls] =
rt300@45 1088 float ctrlout[numcontrols];
rt300@45 1089 string ctrlName[2] = {"fType","reson"};
rt300@45 1090 float values[3][2] =
rt300@45 1091 {{0., 45}, // 0
rt300@45 1092 {0.5, 120}, // 64
rt300@45 1093 {1., 55}}; // 127
rt300@45 1094 */
rt300@45 1095
rt300@45 1096 static int numpoints = 2;
rt300@45 1097 static int numcontrols = 1;
rt300@45 1098 //float values[points][controls] =
rt300@45 1099 float ctrlout[numcontrols];
rt300@45 1100 string ctrlName[2] = {"fType"};
rt300@45 1101 float values[2][1] =
rt300@45 1102 {{0.}, // 0
rt300@45 1103 {1.},}; // 127
rt300@45 1104
rt300@45 1105 float fidx = (numpoints-1)*ctrlin/128.;
rt300@45 1106 int idx = floor(fidx);
rt300@45 1107 float frac = fidx - idx;
rt300@45 1108
rt300@45 1109 for(int i=0; i < numcontrols; i++){
rt300@45 1110 ctrlout[i] = (1 - frac)*values[idx][i] + (frac)*values[idx+1][i];
rt300@45 1111 // send to PD
rt300@45 1112 List toPD;
rt300@45 1113
rt300@45 1114 toPD.addSymbol(ctrlName[i]);
rt300@45 1115 toPD.addFloat(ctrlout[i]); // rounding here??
rt300@45 1116
rt300@45 1117 core.pd.sendList("fromOF", toPD);
rt300@45 1118 //cout << ctrlName[i] << "sending" << ctrlout[i] << "\n";
rt300@45 1119 }
rt300@45 1120 }
rt300@45 1121 //---------------------------------------------------------------
rt300@45 1122 void testApp::sendFiltTypeOld(int ctrlin){
rt300@45 1123 if(ctrlin < 0 || ctrlin > 127){
rt300@45 1124 cout << "ERROR: bad slider value!";
rt300@45 1125 return;
rt300@45 1126 }
rt300@3 1127 static int numpoints = 3;
rt300@3 1128 static int numcontrols = 4;
rt300@3 1129 //float values[points][controls] =
rt300@3 1130 float ctrlout[numcontrols];
rt300@3 1131 string ctrlName[4] = {"lpLev" , "bpLev", "hpLev", "reson"};
rt300@3 1132 float values[3][4] =
rt300@37 1133 {{2., 0., 0., 1.}, // 0
rt300@24 1134 {0., 10., 0., 10.}, // 64
rt300@24 1135 {0., 0., 1., 1.}}; // 127
rt300@3 1136
rt300@3 1137 float fidx = (numpoints-1)*ctrlin/128.;
rt300@3 1138 int idx = floor(fidx);
rt300@3 1139 float frac = fidx - idx;
rt300@3 1140 for(int i=0; i < numcontrols; i++){
rt300@3 1141 ctrlout[i] = (1 - frac)*values[idx][i] + (frac)*values[idx+1][i];
rt300@3 1142 // send to PD
rt300@3 1143 List toPD;
rt300@3 1144
rt300@3 1145 toPD.addSymbol(ctrlName[i]);
rt300@3 1146 toPD.addFloat(ctrlout[i]); // rounding here??
rt300@3 1147
rt300@3 1148 core.pd.sendList("fromOF", toPD);
rt300@3 1149 //cout << ctrlName[i] << "sending" << ctrlout[i] << "\n";
rt300@3 1150 }
rt300@2 1151 }
rt300@8 1152 //---------------------------------------------------------------
rt300@3 1153 void testApp::sendFiltFreq(int ctrlin){
rt300@35 1154 if(ctrlin < 0 || ctrlin > 127){
rt300@35 1155 cout << "ERROR: bad slider value!";
rt300@35 1156 return;
rt300@35 1157 }
rt300@24 1158 // smooth this
rt300@24 1159 float fin = ctrlin;
rt300@24 1160 float fout;
rt300@24 1161 fout = (int)ctrlSmoother(fin);
rt300@3 1162 List toPD;
rt300@3 1163
rt300@3 1164 toPD.addSymbol("filtFreq");
rt300@37 1165 toPD.addFloat(fout);
rt300@3 1166
rt300@3 1167 core.pd.sendList("fromOF", toPD);
rt300@3 1168 }
rt300@8 1169 //---------------------------------------------------------------
rt300@3 1170 void testApp::sendEnvShape(int ctrlin){
rt300@35 1171 if(ctrlin < 0 || ctrlin > 127){
rt300@35 1172 cout << "ERROR: bad slider value!";
rt300@35 1173 return;
rt300@35 1174 }
rt300@3 1175 static int numpoints = 5;
rt300@3 1176 static int numcontrols = 3;
rt300@3 1177 //float values[points][controls] =
rt300@3 1178 float ctrlout[numcontrols];
rt300@3 1179 string ctrlName[3] = {"attack" , "decay", "sustain"};
rt300@3 1180 float values[5][3] =
rt300@37 1181 {{0., 0., 0.}, // 0
rt300@3 1182 {0., 0.5, 0.}, // 32
rt300@3 1183 {0.0, 1., 0.8}, // 64
rt300@3 1184 {0.99, 0.3, 0.}, // 96
rt300@3 1185 {0.3, 0.1, 0.}}; // 127
rt300@3 1186
rt300@3 1187 float fidx = (numpoints-1)*ctrlin/128.;
rt300@3 1188 int idx = floor(fidx);
rt300@3 1189 float frac = fidx - idx;
rt300@3 1190 for(int i=0; i < numcontrols; i++){
rt300@3 1191 ctrlout[i] = (1 - frac)*values[idx][i] + (frac)*values[idx+1][i];
rt300@3 1192 // send to PD
rt300@3 1193 List toPD;
rt300@3 1194
rt300@3 1195 toPD.addSymbol(ctrlName[i]);
rt300@3 1196 toPD.addFloat(ctrlout[i]); // rounding here??
rt300@3 1197
rt300@3 1198 core.pd.sendList("fromOF", toPD);
rt300@3 1199 //cout << ctrlName[i] << "sending" << ctrlout[i] << "\n";
rt300@3 1200 }
rt300@3 1201 }
rt300@8 1202 //---------------------------------------------------------------
rt300@43 1203 // alternative envelopes: seperate for amp and filt
rt300@43 1204 void testApp::sendAmpEnvShape(int ctrlin){
rt300@43 1205 if(ctrlin < 0 || ctrlin > 127){
rt300@43 1206 cout << "ERROR: bad slider value!";
rt300@43 1207 return;
rt300@43 1208 }
rt300@43 1209 static int numpoints = 5;
rt300@43 1210 static int numcontrols = 3;
rt300@43 1211 //float values[points][controls] =
rt300@43 1212 float ctrlout[numcontrols];
rt300@43 1213 string ctrlName[3] = {"attack" , "decay", "sustain"};
rt300@43 1214 float values[5][3] =
rt300@43 1215 {{0., 0., 0.}, // 0
rt300@43 1216 {0., 0.5, 0.}, // 32
rt300@43 1217 {0.0, 1., 0.8}, // 64
rt300@43 1218 {0.99, 0.3, 0.}, // 96
rt300@43 1219 {0.3, 0.1, 0.}}; // 127
rt300@43 1220
rt300@43 1221 float fidx = (numpoints-1)*ctrlin/128.;
rt300@43 1222 int idx = floor(fidx);
rt300@43 1223 float frac = fidx - idx;
rt300@43 1224 for(int i=0; i < numcontrols; i++){
rt300@43 1225 ctrlout[i] = (1 - frac)*values[idx][i] + (frac)*values[idx+1][i];
rt300@43 1226 // send to PD
rt300@43 1227 List toPD;
rt300@43 1228 toPD.addSymbol("aenv");
rt300@43 1229 toPD.addSymbol(ctrlName[i]);
rt300@43 1230 toPD.addFloat(ctrlout[i]); // rounding here??
rt300@43 1231
rt300@43 1232 core.pd.sendList("fromOF", toPD);
rt300@43 1233 //cout << ctrlName[i] << "sending" << ctrlout[i] << "\n";
rt300@43 1234 }
rt300@43 1235 }
rt300@43 1236 //---------------------------------------------------------------
rt300@43 1237 void testApp::sendFiltEnvShape(int ctrlin){
rt300@43 1238 if(ctrlin < 0 || ctrlin > 127){
rt300@43 1239 cout << "ERROR: bad slider value!";
rt300@43 1240 return;
rt300@43 1241 }
rt300@43 1242 static int numpoints = 5;
rt300@43 1243 static int numcontrols = 3;
rt300@43 1244 //float values[points][controls] =
rt300@43 1245 float ctrlout[numcontrols];
rt300@43 1246 string ctrlName[3] = {"attack" , "decay", "sustain"};
rt300@43 1247 float values[5][3] =
rt300@43 1248 {{0., 0., 0.}, // 0
rt300@43 1249 {0., 0.5, 0.}, // 32
rt300@43 1250 {0.0, 1., 0.8}, // 64
rt300@43 1251 {0.99, 0.3, 0.}, // 96
rt300@43 1252 {0.3, 0.1, 0.}}; // 127
rt300@43 1253
rt300@43 1254 float fidx = (numpoints-1)*ctrlin/128.;
rt300@43 1255 int idx = floor(fidx);
rt300@43 1256 float frac = fidx - idx;
rt300@43 1257 for(int i=0; i < numcontrols; i++){
rt300@43 1258 ctrlout[i] = (1 - frac)*values[idx][i] + (frac)*values[idx+1][i];
rt300@43 1259 // send to PD
rt300@43 1260 List toPD;
rt300@43 1261 toPD.addSymbol("fenv");
rt300@43 1262 toPD.addSymbol(ctrlName[i]);
rt300@43 1263 toPD.addFloat(ctrlout[i]); // rounding here??
rt300@43 1264
rt300@43 1265 core.pd.sendList("fromOF", toPD);
rt300@43 1266 //cout << ctrlName[i] << "sending" << ctrlout[i] << "\n";
rt300@43 1267 }
rt300@43 1268 }
rt300@43 1269 //---------------------------------------------------------------
rt300@45 1270 void testApp::sendFiltEnvModAmt(int ctrlin){
rt300@45 1271 if(ctrlin < 0 || ctrlin > 127){
rt300@45 1272 cout << "ERROR: bad slider value!";
rt300@45 1273 return;
rt300@45 1274 }
rt300@45 1275 float amt = ctrlin/127.0;
rt300@45 1276 List toPD;
rt300@45 1277
rt300@45 1278 toPD.addSymbol("fenv");
rt300@45 1279 toPD.addSymbol("amount");
rt300@45 1280 toPD.addFloat(amt); // rounding here??
rt300@45 1281
rt300@45 1282 core.pd.sendList("fromOF", toPD);
rt300@45 1283 }
rt300@45 1284 //---------------------------------------------------------------
rt300@3 1285 void testApp::sendModFreq(int ctrlin){
rt300@35 1286 if(ctrlin < 0 || ctrlin > 127){
rt300@35 1287 cout << "ERROR: bad slider value!";
rt300@35 1288 return;
rt300@35 1289 }
rt300@3 1290 float fm = ctrlin/127.;
rt300@3 1291 List toPD;
rt300@3 1292
rt300@3 1293 toPD.addSymbol("FMFreq");
rt300@3 1294 toPD.addFloat(fm); // rounding here??
rt300@3 1295
rt300@3 1296 core.pd.sendList("fromOF", toPD);
rt300@8 1297 }
rt300@35 1298 //---------------------------------------------------------------
rt300@45 1299 //---------------------------------------------------------------
rt300@45 1300 void testApp::sendRevAmt(int ctrlin){
rt300@45 1301 if(ctrlin < 0 || ctrlin > 127){
rt300@45 1302 cout << "ERROR: bad slider value!";
rt300@45 1303 return;
rt300@45 1304 }
rt300@45 1305 static int numpoints = 5;
rt300@45 1306 static int numcontrols = 2;
rt300@45 1307 //float values[points][controls] =
rt300@45 1308 float ctrlout[numcontrols];
rt300@45 1309 string ctrlName[3] = {"revDryWet" , "revLength"};
rt300@45 1310 float values[5][3] =
rt300@45 1311 {{0., 0.1}, // 0
rt300@45 1312 {0., 0.1}, // 32
rt300@45 1313 {0.3, 30.}, // 64
rt300@45 1314 {0.6, 60.}, // 96
rt300@45 1315 {1., 95.}}; // 127
rt300@45 1316
rt300@45 1317 float fidx = (numpoints-1)*ctrlin/128.;
rt300@45 1318 int idx = floor(fidx);
rt300@45 1319 float frac = fidx - idx;
rt300@45 1320 for(int i=0; i < numcontrols; i++){
rt300@45 1321 ctrlout[i] = (1 - frac)*values[idx][i] + (frac)*values[idx+1][i];
rt300@45 1322 // send to PD
rt300@45 1323 List toPD;
rt300@45 1324 toPD.addSymbol(ctrlName[i]);
rt300@45 1325 toPD.addFloat(ctrlout[i]); // rounding here??
rt300@45 1326
rt300@45 1327 core.pd.sendList("fromOF", toPD);
rt300@45 1328 //cout << ctrlName[i] << "sending" << ctrlout[i] << "\n";
rt300@45 1329 }
rt300@35 1330
rt300@45 1331 }
rt300@45 1332 //---------------------------------------------------------------
rt300@45 1333 void testApp::sendResonance(int ctrlin){
rt300@45 1334 if(ctrlin < 0 || ctrlin > 127){
rt300@45 1335 cout << "ERROR: bad slider value!";
rt300@45 1336 return;
rt300@45 1337 }
rt300@45 1338 float res = ctrlin;
rt300@45 1339 List toPD;
rt300@45 1340
rt300@45 1341 toPD.addSymbol("reson");
rt300@45 1342 toPD.addFloat(res); // rounding here??
rt300@45 1343
rt300@45 1344 core.pd.sendList("fromOF", toPD);
rt300@45 1345 }
rt300@45 1346 //---------------------------------------------------------------------------
rt300@45 1347 void testApp::sendFMAmt(int ctrlin){
rt300@45 1348 static int numpoints = 4;
rt300@45 1349 static int numcontrols = 1;
rt300@45 1350 //float values[points][controls] =
rt300@45 1351 float ctrlout[numcontrols];
rt300@45 1352 string ctrlName[1] = {"FMAmt"};
rt300@45 1353 float values[4][1] =
rt300@45 1354 {{0.}, // 0
rt300@45 1355 {0.}, //
rt300@45 1356 {0.3}, //
rt300@45 1357 {1.}}; // 127
rt300@45 1358
rt300@45 1359 float fidx = (numpoints-1)*ctrlin/128.;
rt300@45 1360 int idx = floor(fidx);
rt300@45 1361 float frac = fidx - idx;
rt300@45 1362 for(int i=0; i < numcontrols; i++){
rt300@45 1363 ctrlout[i] = (1 - frac)*values[idx][i] + (frac)*values[idx+1][i];
rt300@45 1364 // send to PD
rt300@45 1365 List toPD;
rt300@45 1366 toPD.addSymbol(ctrlName[i]);
rt300@45 1367 toPD.addFloat(ctrlout[i]); // rounding here??
rt300@45 1368
rt300@45 1369 core.pd.sendList("fromOF", toPD);
rt300@45 1370 //cout << ctrlName[i] << "sending" << ctrlout[i] << "\n";
rt300@45 1371 }
rt300@45 1372 }
rt300@45 1373 //---------------------------------------------------------------------------
rt300@45 1374 void testApp::sendDistortion(int ctrlin){
rt300@45 1375 static int numpoints = 5;
rt300@45 1376 static int numcontrols = 2;
rt300@45 1377 //float values[points][controls] =
rt300@45 1378 float ctrlout[numcontrols];
rt300@45 1379 string ctrlName[2] = {"sigGain", "sineGain"};
rt300@45 1380 float values[5][2] =
rt300@45 1381 {{0., 0.}, // 0
rt300@45 1382 {0., 0.}, //
rt300@45 1383 {20, 0.}, //
rt300@45 1384 {45 , 0.}, //
rt300@45 1385 {0, 18}}; // 127
rt300@45 1386
rt300@45 1387 float fidx = (numpoints-1)*ctrlin/128.;
rt300@45 1388 int idx = floor(fidx);
rt300@45 1389 float frac = fidx - idx;
rt300@45 1390 for(int i=0; i < numcontrols; i++){
rt300@45 1391 ctrlout[i] = (1 - frac)*values[idx][i] + (frac)*values[idx+1][i];
rt300@45 1392 // send to PD
rt300@45 1393 List toPD;
rt300@45 1394 toPD.addSymbol(ctrlName[i]);
rt300@45 1395 toPD.addFloat(ctrlout[i]); // rounding here??
rt300@45 1396
rt300@45 1397 core.pd.sendList("fromOF", toPD);
rt300@45 1398 //cout << ctrlName[i] << "sending" << ctrlout[i] << "\n";
rt300@45 1399 }
rt300@45 1400 }
rt300@45 1401 //---------------------------------------------------------------------------
rt300@45 1402 //===========================================================================
rt300@35 1403 //---------------------------------------------------------------------------
rt300@35 1404 void saveSequences(){
rt300@35 1405 ofFile sequenceFile(ofxiPhoneGetDocumentsDirectory() + "pilot_sequences.json" ,ofFile::WriteOnly);
rt300@35 1406
rt300@35 1407 // the 5 harmonics for the frequencer
rt300@35 1408 vector<int> freqIndexes;
rt300@35 1409 freqIndexes.push_back(0);
rt300@35 1410 freqIndexes.push_back(4);
rt300@35 1411 freqIndexes.push_back(6);
rt300@35 1412 freqIndexes.push_back(7);
rt300@35 1413 freqIndexes.push_back(8);
rt300@35 1414
rt300@35 1415 // loop thru all presets
rt300@35 1416 int N = presetManager.thePresets.size();
rt300@35 1417
rt300@35 1418 vector<int> sliderVals;
rt300@35 1419
rt300@35 1420 Json::Value root;
rt300@35 1421
rt300@35 1422 vector<double> vals;
rt300@35 1423
rt300@35 1424 for(int i = 0; i< N ; i++){
rt300@44 1425 sliderVals = theGridView.calculateParamsFromCoord(presetManager.thePresets[i].coordinates);
rt300@35 1426
rt300@35 1427 vals.push_back((sliderVals[0]+32)*8.); // DC offset
rt300@35 1428 for(int i=1; i<5;i++){
rt300@35 1429 vals.push_back((sliderVals[i] - 64)*2.);
rt300@35 1430 }
rt300@35 1431
rt300@35 1432
rt300@35 1433 vector<double> steps = frequencer.freqMagEdit(freqIndexes, vals);
rt300@35 1434
rt300@35 1435 for(int j = 0; j<16;j++){
rt300@35 1436 root["sequences"][i][j] = int(steps[j]);
rt300@35 1437 }
rt300@35 1438 vals.clear();
rt300@35 1439 }
rt300@35 1440
rt300@35 1441 //cout << root;
rt300@35 1442 sequenceFile << root;
rt300@35 1443 }
rt300@35 1444 //=--------------------------------------------------------------------
rt300@36 1445 void testApp::loadSequences(){
rt300@36 1446
rt300@36 1447 // read in sequence preset file
rt300@45 1448 string jsonFile = ofFilePath::getAbsolutePath(ofToDataPath("pilot_sequences.json"));
rt300@45 1449
rt300@45 1450 cout << "SQUENCES FILE: " << jsonFile << "\n";
rt300@45 1451 //string jsonFile = ofxiPhoneGetDocumentsDirectory() + "pilot_sequences.json";
rt300@37 1452
rt300@36 1453 Json::Value root;
rt300@36 1454 Json::Reader reader;
rt300@37 1455
rt300@36 1456 ifstream theFile(jsonFile.c_str());
rt300@36 1457 stringstream fileText;
rt300@36 1458 string line;
rt300@36 1459 if(!theFile){
rt300@36 1460 cout<<"can't find sequence file: " << jsonFile.c_str() << "\n";
rt300@36 1461 return;
rt300@36 1462 }else{
rt300@36 1463
rt300@36 1464 while(theFile){
rt300@36 1465 theFile >> line;
rt300@36 1466 // cout << line << "\n"; // lots?
rt300@37 1467 fileText << line;
rt300@36 1468 }
rt300@36 1469
rt300@36 1470 theFile.close();
rt300@36 1471 }
rt300@36 1472
rt300@36 1473 bool parsingSuccessful = reader.parse( fileText.str(), root );
rt300@36 1474
rt300@36 1475 if ( !parsingSuccessful )
rt300@36 1476 {
rt300@36 1477 // report to the user the failure and their locations in the document.
rt300@36 1478 std::cout << "Failed to parse sequence JSON: \n"
rt300@36 1479 << reader.getFormattedErrorMessages();
rt300@36 1480 return;
rt300@36 1481 }
rt300@36 1482
rt300@36 1483 // now put into variables
rt300@36 1484 const Json::Value jseqs = root["sequences"];
rt300@36 1485 int N = jseqs.size();
rt300@36 1486 for(int i=0; i<N; i++){
rt300@36 1487 sequences.push_back(vector<int>());
rt300@36 1488 for(int j=0; j<jseqs[i].size(); j++){
rt300@36 1489 sequences.back().push_back(jseqs[i][j].asInt());
rt300@36 1490 }
rt300@36 1491 }
rt300@36 1492 // currentSequence
rt300@37 1493
rt300@37 1494 currentSequence = ofRandom(0,N-1);
rt300@36 1495
rt300@36 1496 }
rt300@39 1497 //-------------------------------------------------------------------------
rt300@39 1498 //--------------------------------------------------------------
rt300@39 1499
rt300@39 1500 #pragma mark MIDI
rt300@39 1501 void testApp::addMessage(string msg) {
rt300@39 1502 cout << msg << endl;
rt300@39 1503 messages.push_back(msg);
rt300@39 1504 while(messages.size() > maxMessages)
rt300@39 1505 messages.pop_front();
rt300@39 1506 }
rt300@39 1507
rt300@39 1508 //--------------------------------------------------------------
rt300@39 1509 void testApp::newMidiMessage(ofxMidiMessage& msg) {
rt300@39 1510 //addMessage(msg.toString());
rt300@39 1511
rt300@39 1512 // look at what it is
rt300@39 1513
rt300@39 1514 if(msg.channel == midiChannel && msg.status == MIDI_CONTROL_CHANGE){
rt300@39 1515 int ctl_num = msg.control;
rt300@39 1516 int ctl_val = msg.value;
rt300@39 1517 if(ctl_num - midiOffset >= 0 && ctl_num - midiOffset < sliderVals.size()){
rt300@39 1518 sliderVals[ctl_num] = (int)ctl_val;
rt300@39 1519 theGridView.setParams(sliderVals);
rt300@39 1520 }
rt300@39 1521 }
rt300@39 1522
rt300@39 1523 }
rt300@39 1524
rt300@39 1525 //--------------------------------------------------------------
rt300@39 1526 void testApp::midiInputAdded(string name, bool isNetwork) {
rt300@39 1527 stringstream msg;
rt300@39 1528 msg << "ofxMidi: input added: " << name << " network: " << isNetwork;
rt300@39 1529 cout << msg.str();
rt300@39 1530 addMessage(msg.str());
rt300@39 1531
rt300@39 1532 // create and open a new input port
rt300@39 1533 ofxMidiIn * newInput = new ofxMidiIn;
rt300@39 1534 newInput->openPort(name);
rt300@39 1535 newInput->addListener(this);
rt300@39 1536 inputs.push_back(newInput);
rt300@39 1537 }
rt300@39 1538
rt300@39 1539 //--------------------------------------------------------------
rt300@39 1540 void testApp::midiInputRemoved(string name, bool isNetwork) {
rt300@39 1541 stringstream msg;
rt300@39 1542 msg << "ofxMidi: input removed: " << name << " network: " << isNetwork << endl;
rt300@39 1543 cout << msg.str();
rt300@39 1544 addMessage(msg.str());
rt300@39 1545
rt300@39 1546 // close and remove input port
rt300@39 1547 vector<ofxMidiIn*>::iterator iter;
rt300@39 1548 for(iter = inputs.begin(); iter != inputs.end(); ++iter) {
rt300@39 1549 ofxMidiIn * input = (*iter);
rt300@39 1550 if(input->getName() == name) {
rt300@39 1551 input->closePort();
rt300@39 1552 input->removeListener(this);
rt300@39 1553 delete input;
rt300@39 1554 inputs.erase(iter);
rt300@39 1555 break;
rt300@39 1556 }
rt300@39 1557 }
rt300@39 1558 }
rt300@39 1559
rt300@39 1560 //--------------------------------------------------------------
rt300@39 1561 void testApp::midiOutputAdded(string name, bool isNetwork) {
rt300@39 1562 stringstream msg;
rt300@39 1563 msg << "ofxMidi: output added: " << name << " network: " << isNetwork << endl;
rt300@39 1564 cout << msg.str();
rt300@39 1565 addMessage(msg.str());
rt300@39 1566
rt300@39 1567 // create and open new output port
rt300@39 1568 ofxMidiOut * newOutput = new ofxMidiOut;
rt300@39 1569 newOutput->openPort(name);
rt300@39 1570 outputs.push_back(newOutput);
rt300@39 1571 }
rt300@39 1572
rt300@39 1573 //--------------------------------------------------------------
rt300@39 1574 void testApp::midiOutputRemoved(string name, bool isNetwork) {
rt300@39 1575 stringstream msg;
rt300@39 1576 msg << "ofxMidi: output removed: " << name << " network: " << isNetwork << endl;
rt300@39 1577 cout << msg.str();
rt300@39 1578 addMessage(msg.str());
rt300@39 1579
rt300@39 1580 // close and remove output port
rt300@39 1581 vector<ofxMidiOut*>::iterator iter;
rt300@39 1582 for(iter = outputs.begin(); iter != outputs.end(); ++iter) {
rt300@39 1583 ofxMidiOut * output = (*iter);
rt300@39 1584 if(output->getName() == name) {
rt300@39 1585 output->closePort();
rt300@39 1586 delete output;
rt300@39 1587 outputs.erase(iter);
rt300@39 1588 break;
rt300@39 1589 }
rt300@39 1590 }
rt300@39 1591 }
rt300@39 1592 //--------------------------------------------------------------