Mercurial > hg > soniczoomios
diff testApp.mm @ 24:a4908ad8c78e
Top and bottom toolbars. Intro page.
author | Robert Tubb <rt300@eecs.qmul.ac.uk> |
---|---|
date | Fri, 01 Feb 2013 11:16:56 +0000 |
parents | 8c0783739337 |
children | f42a00e3f22d |
line wrap: on
line diff
--- a/testApp.mm Fri Jan 25 17:42:47 2013 +0000 +++ b/testApp.mm Fri Feb 01 11:16:56 2013 +0000 @@ -1,16 +1,23 @@ #include "testApp.h" - +#define SLIDER_GUI_WIDTH 256 extern Grid theGridView; extern PresetManager presetManager; extern EventLogger eventLogger; extern Frequencer frequencer; +const vector<string> parameterNames; + +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]); + + //DeviceID3523537000 //-------------------------------------------------------------- void testApp::setup(){ paused = true; + ofBackground( 0, 0, 0 ); ofEnableAlphaBlending(); //ofEnableSmoothing(); @@ -46,20 +53,19 @@ ofxiPhoneSetOrientation( OFXIPHONE_ORIENTATION_PORTRAIT ); // do this before setting up all the other objects + // initialise the interfaces theGridView.init(); - setupStandardGui(); - standardGUIShowing = false; - standardGUI->setVisible(standardGUIShowing); - - setupZoomGui(); - zoomGUI->setVisible(!standardGUIShowing); + setupSliderGui(); + sliderGUI->setVisible(true); // initial slider vals for(int i=0; i<10;i++){ sliderVals.push_back(64); } + // initialise PD + int ticksPerBuffer = 8; // 8 * 64 = buffer len of 512 // setup the app core @@ -68,13 +74,58 @@ // setup OF sound stream ofSoundStreamSetup(2, 1, this, 44100, ofxPd::blockSize()*ticksPerBuffer, 3); + + + // set up iOS gui stuff + bottomTabViewController = [[BottomTabViewController alloc] initWithNibName:@"BottomTabViewController" bundle:nil]; + [ofxiPhoneGetGLParentView() addSubview:bottomTabViewController.view]; + + [bottomTabViewController setAppRef:(id)this]; + [bottomTabViewController show:(id)this]; + + bottomTabViewController.view.frame = CGRectMake(0,getHeight()-44,getWidth(),44); + + ///// + + topButtonViewController = [[TopButtonViewController alloc] initWithNibName:@"TopButtonViewController" bundle:nil]; + [ofxiPhoneGetGLParentView() addSubview:topButtonViewController.view]; + + [topButtonViewController setAppRef:(id)this]; + [topButtonViewController show:(id)this]; + + topButtonViewController.view.frame = CGRectMake(0,0,getWidth(),44); + + // initialise user logging stuff presetManager.startupLoadAll(); eventLogger.init(); - + + + // GO paused = false; +} + + +//-------------------------------------------------------------- +void testApp::exit(){ + if(consentGiven){ + presetManager.exitAndSaveAll(); + eventLogger.exitAndSave(); + } + // else - don't save anything and app will boot up into consent/intro screen + core.exit(); + + [introViewController release]; + [topButtonViewController release]; + [bottomTabViewController release]; + + delete sliderGUI; + + cout << "exit done \n"; } + +//-------------------------------------------------------------- #pragma mark GUI //-- float testApp::getWidth(){ @@ -87,41 +138,39 @@ return ofGetHeight(); } +#pragma mark GUI + //-------------------------------------------------------------- +/* void testApp::setupZoomGui(){ // width = height - zoomGUI = new ofxUICanvas(getWidth()-200,0,190,300); - zoomGUI->setTheme(OFX_UI_THEME_HACKER ); + int buttonHeight = 45; + zoomGUI = new ofxUICanvas(getWidth()-200,0,190,buttonHeight*7); + zoomGUI->setTheme(OFX_UI_THEME_METALGEAR ); - zoomGUI->addLabelToggle("SWITCH VIEW", false); - - zoomGUI->addLabelButton("SAVE PRESET", false); - - + zoomGUI->addLabelToggle("START/STOP", false); + zoomGUI->addLabelButton("SAVE PRESET", false); zoomGUI->addLabelButton("ZOOM MIN", false); zoomGUI->addLabelButton("ZOOM MAX", false); zoomGUI->addLabelButton("QUESTIONS", false); + + ofxUILabelToggle * butt = zoomGUI->addLabelToggle("LOCK SEQUENCE (X)", false); + butt->setColorFill(ofColor(0,0,255)); + butt->setColorFillHighlight(ofColor(0,0,255)); + + ofxUILabelToggle * butt2 = zoomGUI->addLabelToggle("LOCK SYNTH (Y)", false); + butt2->setColorFill(ofColor(255,0,0)); + butt2->setColorFillHighlight(ofColor(255,0,0)); + + ofAddListener(zoomGUI->newGUIEvent, this, &testApp::zoomGUIEvent); } + //-------------------------------------------------------------- void testApp::zoomGUIEvent(ofxUIEventArgs &e){ - if(e.widget->getName() == "SWITCH VIEW") - { - // is toggle - cout << "change VIEW\n"; - cout << "of width " << ofGetWidth() <<'\n'; - cout << "of height " << ofGetHeight() <<'\n'; - standardGUI->setVisible(!standardGUIShowing); - standardGUIShowing = !standardGUIShowing; - if(standardGUIShowing){ - // set the slider values to stuff got from zoomer - sliderVals = theGridView.getParams(); - setAllGUISliders(sliderVals); - } - - }else if(e.widget->getName() == "SAVE PRESET") + if(e.widget->getName() == "SAVE PRESET") { if(((ofxUIButton *)e.widget)->getValue()==0){ // touchup @@ -150,89 +199,7 @@ if(((ofxUIButton *)e.widget)->getValue()==0){ // touchup showQuestionnaire(); } - }else{ - cout << "GUI error : unknown event recieved\n"; - } - -} -//-------------------------------------------------------------- -void testApp::showQuestionnaire(){ - // stop updating / drawing - - // if(eventLogger.questionnaireCompleted) return; - - paused = true; - - questionnaireViewController = [[QuestionnaireViewController alloc] initWithNibName:@"QuestionnaireViewController" bundle:nil]; - [ofxiPhoneGetGLParentView() addSubview:questionnaireViewController.view]; - - [questionnaireViewController setAppRef:(id)this]; - [questionnaireViewController show:(id)this]; - - //IF THE VIEW IS HIDDEN LETS BRING IT BACK! - //if( questionnaireViewController.view.hidden ){ - // questionnaireViewController.view.hidden = NO; - //} - -} -//-------------------------------------------------------------- -void testApp::questionnaireHidden(vector<int> answers){ - // send answers to server as json - eventLogger.questionnaireAnswersObtained(answers); - - // set "we've done questionnaire" to true in event logger - paused = false; -} -//-------------------------------------------------------------- -void testApp::setupStandardGui(){ - float xInit = OFX_UI_GLOBAL_WIDGET_SPACING; - float length = 256-xInit*2; - - - float dim = 42; - - // LEFT GUI - standardGUI = new ofxUICanvas(0,0,length+90,getHeight()); - - - ofxUILabelToggle * butt = standardGUI->addLabelToggle("LOCK SEQUENCE (X)", false); - butt->setColorFill(ofColor(0,0,255)); - butt->setColorFillHighlight(ofColor(0,0,255)); - - // Uh.. loop this - for(int i = 1; i<=10;i++){ - stringstream ss; - ss << "P" << i; - ofxUISlider *slider; - slider = (ofxUISlider *)standardGUI->addWidgetDown(new ofxUISlider(length,dim,0.0,127,64,ss.str())); - slider->setDrawPadding(true); - if(i <= 5){ - slider->setColorFill(ofColor(0,0,255)); - slider->setColorFillHighlight(ofColor(0,0,255)); - }else{ - slider->setColorFill(ofColor(255,0,0)); - slider->setColorFillHighlight(ofColor(255,0,0)); - } - - sliders.push_back(slider); - } - - ofxUILabelToggle * butt2 = standardGUI->addLabelToggle("LOCK SYNTH (Y)", false); - butt2->setColorFill(ofColor(255,0,0)); - butt2->setColorFillHighlight(ofColor(255,0,0)); - - ofAddListener(standardGUI->newGUIEvent, this, &testApp::standardGUIEvent); - standardGUI->loadSettings(ofxiPhoneGetDocumentsDirectory() + "guiSettings.xml"); - -} -//-------------------------------------------------------------- -void testApp::standardGUIEvent(ofxUIEventArgs &e){ - if(!standardGUIShowing){ - cout << "GUI ERROR"; - return; - } - - if(e.widget->getName() == "LOCK SEQUENCE (X)") + }else if(e.widget->getName() == "LOCK SEQUENCE (X)") { cout << "LOCK SEQUENCE (X)\n"; @@ -252,36 +219,205 @@ yLocked = false; } + + }else if(e.widget->getName() == "START/STOP") + { + + + //pd.startMessage(); + /// pd.addSymbol("hello"); + /// pd.addFloat(1.23); + /// pd.finishList("test"); + }else{ + cout << "GUI error : unknown event recieved\n"; } +} + */ + + +//////////////////////////// +// These functions called from iOS toolbars +//-------------------------------------------------------------- +void testApp::lockSequencerPressed(bool locked){ + theGridView.shiftCentreToSnapped(); + xLocked = locked; + +} +//-------------------------------------------------------------- +void testApp::lockSynthPressed(bool locked){ + theGridView.shiftCentreToSnapped(); + yLocked = locked; + +} +//-------------------------------------------------------------- +void testApp::seqStartStop(bool go){ + if(!go){ //stop + core.pd.startMessage(); + core.pd.addFloat(0); + core.pd.finishMessage("fromOF", "seqStartStop"); + }else { // play + //stopSequencer(); + core.pd.startMessage(); + core.pd.addFloat(1); + core.pd.finishMessage("fromOF", "seqStartStop"); + } +} +//-------------------------------------------------------------- +void testApp::showQuestionnaire(){ + // stop updating / drawing + + // if(eventLogger.questionnaireCompleted) return; + + paused = true; + + //stopSequencer + core.pd.startMessage(); + core.pd.addFloat(0); + core.pd.finishMessage("fromOF", "seqStartStop"); + + questionnaireViewController = [[QuestionnaireViewController alloc] initWithNibName:@"QuestionnaireViewController" bundle:nil]; + [ofxiPhoneGetGLParentView() addSubview:questionnaireViewController.view]; + + [questionnaireViewController setAppRef:(id)this]; + [questionnaireViewController show:(id)this]; + + whichInterfaceShowing = QUESTIONNAIRE; + + +} +//-------------------------------------------------------------- +void testApp::questionnaireHidden(vector<int> answers){ + // send answers to server as json + eventLogger.questionnaireAnswersObtained(answers); + + // set "we've done questionnaire" to true in event logger + paused = false; + + //startSequencer (TODO what about the toggle ? ?) + core.pd.startMessage(); + core.pd.addFloat(1); + core.pd.finishMessage("fromOF", "seqStartStop"); + whichInterfaceShowing = BOTH; + // tell bottomtabviewcontroller + +} +//-------------------------------------------------------------- +void testApp::showIntro(){ + paused = true; + consentGiven = false; + cout << "SHOW INTRO\n"; + + introViewController = [[IntroViewController alloc] initWithNibName:@"IntroViewController" bundle:nil]; + [ofxiPhoneGetGLParentView() addSubview:introViewController.view]; + + [introViewController setAppRef:(id)this]; + [introViewController show:(id)this]; + + + whichInterfaceShowing = INTRO; + +} +//-------------------------------------------------------------- +void testApp::introHidden(bool OK){ + if(OK){ + paused = false; + consentGiven = true; + whichInterfaceShowing = BOTH; + } + // no unOK +} +//-------------------------------------------------------------- +// called from BottomTabViewController iOS segmented thing +void testApp::interfaceSelected(int which){ + switch (which){ + case 0: + + whichInterfaceShowing = SLIDERS; + sliderGUI->setVisible(true); + // set the slider values to stuff got from zoomer + sliderVals = theGridView.getParams(); + setAllGUISliders(sliderVals); + break; + case 1: + + whichInterfaceShowing = BOTH; + sliderGUI->setVisible(true); + // set the slider values to stuff got from zoomer + sliderVals = theGridView.getParams(); + setAllGUISliders(sliderVals); + break; + case 2: + + sliderGUI->setVisible(false); + whichInterfaceShowing = ZOOMER; + break; + } + +} +//-------------------------------------------------------------- +//-------------------------------------------------------------- +void testApp::setupSliderGui(){ + float xInit = OFX_UI_GLOBAL_WIDGET_SPACING; + float length = SLIDER_GUI_WIDTH - (OFX_UI_GLOBAL_WIDGET_SPACING*2); + + + //float dim = 42; + + // make this iphone size...? + int height = 480; + int width = 320; + float dim = (height-10.0*OFX_UI_GLOBAL_WIDGET_SPACING)/10.0; + // LEFT GUI + sliderGUI = new ofxUICanvas(0,100,SLIDER_GUI_WIDTH,getHeight()); + + // Uh.. loop this + for(int i = 1; i<=10;i++){ + + ofxUISlider *slider; + slider = (ofxUISlider *)sliderGUI->addWidgetDown(new ofxUISlider(width,dim,0.0,127,64,sliderParamNames[i-1])); + slider->setDrawPadding(true); + if(i <= 5){ + slider->setColorFill(ofColor(0,0,255)); + slider->setColorFillHighlight(ofColor(0,0,255)); + }else{ + slider->setColorFill(ofColor(255,0,0)); + slider->setColorFillHighlight(ofColor(255,0,0)); + } + + sliders.push_back(slider); + } + + + + ofAddListener(sliderGUI->newGUIEvent, this, &testApp::sliderGUIEvent); + +} +//-------------------------------------------------------------- +void testApp::sliderGUIEvent(ofxUIEventArgs &e){ + if(whichInterfaceShowing == ZOOMER){ + cout << "GUI ERROR"; + return; + } + // "normal" parameter changes for(int i = 1; i<=10;i++){ - stringstream ss; - ss << "P" << i; - string p = ss.str(); - if(e.widget->getName() == p) + if(e.widget->getName() == sliderParamNames[i-1]) { //cout << "param change: " << p; ofxUISlider *slider = (ofxUISlider *) e.widget; sliderMoved(i-1,slider->getScaledValue()); // internal array 0 indexed - - - } } - - // TODO reflect these changes in zoomer view? Or only when switching? - + } //-------------------------------------------------------------- void testApp::sliderMoved(int which, float value){ // an update caused by slider view being touched sliderVals[which] = (int)value; theGridView.setParams(sliderVals); - - // TODO if <5 do frequencer stuff and send list to PD - // if > 5 send control value to PD + sendParametersToPD(); eventLogger.logEvent(CHANGE_SLIDER, TwoVector(),0.0,which , value); @@ -343,7 +479,6 @@ // continiue to move at velocity, unless snapped if (numActiveTouches == 0){ // no touches, use momentum - // TODO set velocity to 0 when hits walls if(moveVel.norm() > 0.3){ if(theGridView.snapped){ @@ -394,32 +529,38 @@ //-------------------------------------------------------------- void testApp::draw(){ if(paused) return; - if (standardGUIShowing){// ? - ofSetColor(57, 57, 57,200); - ofRect(0,0,getWidth(),getHeight()); + + switch (whichInterfaceShowing){ + case SLIDERS: + break; + case ZOOMER: + theGridView.draw(); + break; + case BOTH: + + theGridView.draw(); + break; + case INTRO: + break; + + case QUESTIONNAIRE: + break; + } - theGridView.draw(); -} - -//-------------------------------------------------------------- -void testApp::exit(){ - presetManager.exitAndSaveAll(); - eventLogger.exitAndSave(); - core.exit(); - - delete standardGUI; - delete zoomGUI; - cout << "exit done \n"; } //-------------------------------------------------------------- void testApp::touchDown(ofTouchEventArgs &touch){ - if(standardGUIShowing){ - // check if in GUI area - if(touch.x < 256) return; - } + + // TODO check if in gui area!!! + if(whichInterfaceShowing == SLIDERS){ + return; + }else if (whichInterfaceShowing == BOTH && touch.x < (SLIDER_GUI_WIDTH+10)){ + return; + + }// otherwise we're good to let the zoomer handle touch numActiveTouches++; // absolute position doesn't matter @@ -450,14 +591,15 @@ //-------------------------------------------------------------- void testApp::touchMoved(ofTouchEventArgs &touch){ - //cout << "touch id " << touch.id << "\n"; - //cout << "active touches " << numActiveTouches << "\n"; + // TODO check if in gui area!!! + if(whichInterfaceShowing == SLIDERS){ + return; + }else if (whichInterfaceShowing == BOTH && touch.x < (SLIDER_GUI_WIDTH+10)){ + return; + + }// otherwise we're good to let the zoomer handle touch + - - if(standardGUIShowing){ - // TODO check if in GUI area - if(touch.x < 256) return; - } // check if in other gui area if(touch.x > getWidth()-200 && touch.y < 300){ return; @@ -541,13 +683,14 @@ void testApp::touchUp(ofTouchEventArgs &touch){ if(numActiveTouches > 0) numActiveTouches--; // dirty - if(standardGUIShowing){ - // check if in GUI area - if(touch.x < 256) + // TODO check if in gui area!!! + if(whichInterfaceShowing == SLIDERS){ + return; + }else if (whichInterfaceShowing == BOTH && touch.x < 256){ + return; - return; - } - // check if in + }// otherwise we're good to let the zoomer handle touch + // which one? if(touch.id == 0){ @@ -672,6 +815,22 @@ return y0; } +float ctrlSmoother(float newsamp){ + static float x1,x2,y1,y2; + float x0, y0; + + x0 = newsamp; + + y0 = fB[0]*x0 + fB[1]*x1 + fB[2]*x2 - fA[1]*y1 - fA[2]*y2; + + // shift + x2 = x1; + x1 = x0; + y2 = y1; + y1 = y0; + + return y0; +} //--------------------------------------------------------------- void testApp::sendOscShape(int ctrlin){ @@ -711,9 +870,9 @@ float ctrlout[numcontrols]; string ctrlName[4] = {"lpLev" , "bpLev", "hpLev", "reson"}; float values[3][4] = - {{1., 0., 0., 1}, // 0 - {0., 10., 0., 10}, // 64 - {0., 0., 1., 1}}; // 127 + {{2., 0., 0., 1.}, // 0 + {0., 10., 0., 10.}, // 64 + {0., 0., 1., 1.}}; // 127 float fidx = (numpoints-1)*ctrlin/128.; int idx = floor(fidx); @@ -732,10 +891,14 @@ } //--------------------------------------------------------------- void testApp::sendFiltFreq(int ctrlin){ + // smooth this + float fin = ctrlin; + float fout; + fout = (int)ctrlSmoother(fin); List toPD; toPD.addSymbol("filtFreq"); - toPD.addFloat(ctrlin); + toPD.addFloat(fout); core.pd.sendList("fromOF", toPD); }