Mercurial > hg > soniczoomios
diff testApp.mm @ 43:b91a1859829a
used UIkit sliders
author | Robert Tubb <rt300@eecs.qmul.ac.uk> |
---|---|
date | Fri, 19 Apr 2013 18:50:04 +0100 |
parents | 3d627dce8bf0 |
children | a1e75b94c505 |
line wrap: on
line diff
--- a/testApp.mm Wed Apr 17 13:44:05 2013 +0100 +++ b/testApp.mm Fri Apr 19 18:50:04 2013 +0100 @@ -12,7 +12,53 @@ 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"}; //const vector<const string> v(ra[0],ra[1]); +//-------------------------------------------------------------- +void testApp::setup(){ + + // initilaise + + initialiseVariables(); + initialiseGUIs(); + + // initialise PD + + int ticksPerBuffer = 8; // 8 * 64 = buffer len of 512 + core.setup(2, 1, 44100, ticksPerBuffer); + + // setup OF sound stream + ofSoundStreamSetup(2, 1, this, 44100, ofxPd::blockSize()*ticksPerBuffer, 3); + + tsc = [[TimedSessionController alloc] init]; + [tsc setAppRef:(id)this]; + + //-------------------------------------- + // load stuff + loadSequences(); + + // load presets + presetManager.startLoadAll(); + + eventLogger.startLoadAll(); + //-------------------------------------- + + // now do things that will affect the start up state of the app + + /* + if(eventLogger.questionnaireCompleted){ // then we go into do-what-you-like mode + + freeUseMode(); + }else{ + // then we're in timed session mode + showIntro(); + } + */ + freeUseMode(); + // GO + paused = false; + eventLogger.logEvent(APP_STARTED); +} +//----------------------------------------------------------------------------- //DeviceID3523537000 void testApp::initialiseVariables(){ @@ -28,7 +74,7 @@ sender.setup( OSC_HOST, OSC_PORT ); ofSetFrameRate(50); - // reciever + lastMoveTime = ofGetSystemTimeMicros(); prevTouchX = 0; prevTouchY = 0; @@ -57,11 +103,14 @@ ofxiPhoneSetOrientation( OFXIPHONE_ORIENTATION_PORTRAIT ); ofxiPhoneExternalDisplay::mirrorOn(); } +//--------------------------------------------------------- void testApp::initialiseGUIs(){ theGridView.init(); + + //SLIDER setupSliderGui(); - sliderGUI->setVisible(true); + sliderGUI->setVisible(false); // initial slider vals for(int i=0; i<10;i++){ @@ -93,18 +142,19 @@ [helpViewController setAppRef:(id)this]; helpViewController.view.hidden = YES; - /* + //SLIDER + sliderViewController = [[SliderViewController alloc] initWithNibName:@"SliderViewController" bundle:nil]; [ofxiPhoneGetGLParentView() addSubview:sliderViewController.view]; [sliderViewController setAppRef:(id)this]; - sliderViewController.view.frame = CGRectMake(0,getHeight()-43 - 363,getWidth(),363); - //[sliderViewController show:(id)this]; - */ + sliderViewController.view.frame = CGRectMake(0,getHeight()-43 - 325,getWidth(),325); + [sliderViewController show:(id)this]; + setAllGUISliders(theGridView.getParams()); } - +//-------------------------------------------------------------------------- void testApp::initialiseMIDI(){ ///////////////////////// @@ -155,49 +205,6 @@ // END MIDI } -//-------------------------------------------------------------- -void testApp::setup(){ - - // initilaise - - initialiseVariables(); - initialiseGUIs(); - - // initialise PD - - int ticksPerBuffer = 8; // 8 * 64 = buffer len of 512 - core.setup(2, 1, 44100, ticksPerBuffer); - - // setup OF sound stream - ofSoundStreamSetup(2, 1, this, 44100, ofxPd::blockSize()*ticksPerBuffer, 3); - - tsc = [[TimedSessionController alloc] init]; - [tsc setAppRef:(id)this]; - - //-------------------------------------- - // load stuff - loadSequences(); - - // load presets - presetManager.startLoadAll(); - - eventLogger.startLoadAll(); - //-------------------------------------- - - // now do things that will affect the start up state of the app - - if(eventLogger.questionnaireCompleted){ // then we go into do-what-you-like mode - - freeUseMode(); - }else{ - // then we're in timed session mode - showIntro(); - } - - // GO - paused = false; - eventLogger.logEvent(APP_STARTED); -} //-------------------------------------------------------------- @@ -225,6 +232,7 @@ delete outputs[i]; } + //SLIDER delete sliderGUI; cout << "exit done \n"; @@ -374,26 +382,29 @@ void testApp::interfaceSelected(int which){ switch (which){ case 0: // slider - + //SLIDER whichInterfaceShowing = SLIDERS; - sliderGUI->setVisible(true); + + [sliderViewController show:(id)this]; // set the slider values to stuff got from zoomer sliderVals = theGridView.getParams(); setAllGUISliders(sliderVals); break; case 1: // both - + //SLIDER whichInterfaceShowing = BOTH; - sliderGUI->setVisible(true); + + [sliderViewController show:(id)this]; // set the slider values to stuff got from zoomer sliderVals = theGridView.getParams(); setAllGUISliders(sliderVals); break; case 2: // zoomer - - sliderGUI->setVisible(false); + //SLIDER + + [sliderViewController hide:(id)this]; whichInterfaceShowing = ZOOMER; break; } @@ -402,7 +413,7 @@ //-------------------------------------------------------------- //-------------------------------------------------------------- void testApp::setupSliderGui(){ - +//SLIDER not used float length = SLIDER_GUI_WIDTH - (OFX_UI_GLOBAL_WIDGET_SPACING*2); @@ -440,6 +451,7 @@ } //-------------------------------------------------------------- void testApp::sliderGUIEvent(ofxUIEventArgs &e){ + //SLIDER not used if(whichInterfaceShowing == ZOOMER){ cout << "GUI ERROR"; return; @@ -457,8 +469,10 @@ } } + //-------------------------------------------------------------- void testApp::sliderMoved(int which, float value){ + // an update caused by slider view being touched sliderVals[which] = (int)value; theGridView.setParams(sliderVals); @@ -475,10 +489,13 @@ } //-------------------------------------------------------------- void testApp::setAllGUISliders(vector<int> vals){ + //SLIDER // an update caused by zoomer view being moved for(int i = 0; i<NUM_PARAMS;i++){ sliders[i]->setValue(vals[i]); sliderVals[i] = vals[i]; + + [sliderViewController setSlider:i to:vals[i]]; } sendParametersToPD(); @@ -704,6 +721,7 @@ //-------------------------------------------------------------- void testApp::touchDown(ofTouchEventArgs &touch){ // in slider gui area? + //SLIDER if(whichInterfaceShowing == SLIDERS){ return; }else if (whichInterfaceShowing == BOTH && touch.x < (SLIDER_GUI_WIDTH+10)){ @@ -744,6 +762,7 @@ void testApp::touchMoved(ofTouchEventArgs &touch){ // TODO check if in gui area!!! + //SLIDER if(whichInterfaceShowing == SLIDERS){ return; }else if (whichInterfaceShowing == BOTH && touch.x < (SLIDER_GUI_WIDTH+10)){ @@ -839,6 +858,7 @@ if(numActiveTouches > 0) numActiveTouches--; // dirty preventingMovePostScroll = false; // TODO check if in gui area!!! + //SLIDER if(whichInterfaceShowing == SLIDERS){ return; }else if (whichInterfaceShowing == BOTH && touch.x < 256){ @@ -1118,6 +1138,73 @@ } } //--------------------------------------------------------------- +// alternative envelopes: seperate for amp and filt +void testApp::sendAmpEnvShape(int ctrlin){ + if(ctrlin < 0 || ctrlin > 127){ + cout << "ERROR: bad slider value!"; + return; + } + static int numpoints = 5; + static int numcontrols = 3; + //float values[points][controls] = + float ctrlout[numcontrols]; + string ctrlName[3] = {"attack" , "decay", "sustain"}; + float values[5][3] = + {{0., 0., 0.}, // 0 + {0., 0.5, 0.}, // 32 + {0.0, 1., 0.8}, // 64 + {0.99, 0.3, 0.}, // 96 + {0.3, 0.1, 0.}}; // 127 + + float fidx = (numpoints-1)*ctrlin/128.; + int idx = floor(fidx); + float frac = fidx - idx; + for(int i=0; i < numcontrols; i++){ + ctrlout[i] = (1 - frac)*values[idx][i] + (frac)*values[idx+1][i]; + // send to PD + List toPD; + toPD.addSymbol("aenv"); + toPD.addSymbol(ctrlName[i]); + toPD.addFloat(ctrlout[i]); // rounding here?? + + core.pd.sendList("fromOF", toPD); + //cout << ctrlName[i] << "sending" << ctrlout[i] << "\n"; + } +} +//--------------------------------------------------------------- +void testApp::sendFiltEnvShape(int ctrlin){ + if(ctrlin < 0 || ctrlin > 127){ + cout << "ERROR: bad slider value!"; + return; + } + static int numpoints = 5; + static int numcontrols = 3; + //float values[points][controls] = + float ctrlout[numcontrols]; + string ctrlName[3] = {"attack" , "decay", "sustain"}; + float values[5][3] = + {{0., 0., 0.}, // 0 + {0., 0.5, 0.}, // 32 + {0.0, 1., 0.8}, // 64 + {0.99, 0.3, 0.}, // 96 + {0.3, 0.1, 0.}}; // 127 + + float fidx = (numpoints-1)*ctrlin/128.; + int idx = floor(fidx); + float frac = fidx - idx; + for(int i=0; i < numcontrols; i++){ + ctrlout[i] = (1 - frac)*values[idx][i] + (frac)*values[idx+1][i]; + // send to PD + List toPD; + toPD.addSymbol("fenv"); + toPD.addSymbol(ctrlName[i]); + toPD.addFloat(ctrlout[i]); // rounding here?? + + core.pd.sendList("fromOF", toPD); + //cout << ctrlName[i] << "sending" << ctrlout[i] << "\n"; + } +} +//--------------------------------------------------------------- void testApp::sendModFreq(int ctrlin){ if(ctrlin < 0 || ctrlin > 127){ cout << "ERROR: bad slider value!";