annotate testApp.mm @ 45:c2fffc8ea84d

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