diff testApp.mm @ 44:a1e75b94c505

Snap to eval points. Double tap to go to preset (doesn't quite work yet). Coloured locks. Changed Question 2. Fixed some leaks.
author Robert Tubb <rt300@eecs.qmul.ac.uk>
date Mon, 22 Apr 2013 18:32:34 +0100
parents b91a1859829a
children c2fffc8ea84d
line wrap: on
line diff
--- a/testApp.mm	Fri Apr 19 18:50:04 2013 +0100
+++ b/testApp.mm	Mon Apr 22 18:32:34 2013 +0100
@@ -43,16 +43,16 @@
     
     // 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
+    if(true){
+    // if(eventLogger.questionnaireCompleted){ // then we go into do-what-you-like mode
         
         freeUseMode();
     }else{
         // then we're in timed session mode
         showIntro();
     }
-    */
-    freeUseMode();
+
+    //freeUseMode();
     // GO
     paused = false;
     eventLogger.logEvent(APP_STARTED);
@@ -109,8 +109,8 @@
     
     
     //SLIDER
-    setupSliderGui();
-    sliderGUI->setVisible(false);
+    //setupSliderGui();
+    //sliderGUI->setVisible(false);
     
     // initial slider vals
     for(int i=0; i<10;i++){
@@ -134,22 +134,24 @@
     [topButtonViewController show:(id)this];
     topButtonViewController.view.frame = CGRectMake(0,0,getWidth(),44);
     
-    usernameAlertViewController = [[UsernameAlertViewController alloc] init];
-    [usernameAlertViewController setAppRef:(id)this];
+
+    
+    //SLIDER
+    
+    sliderViewController	= [[SliderViewController alloc] initWithNibName:@"SliderViewController" bundle:nil];
+    [ofxiPhoneGetGLParentView() addSubview:sliderViewController.view];
+    [sliderViewController setAppRef:(id)this];
+    sliderViewController.view.frame = CGRectMake(0,getHeight()-43 - 278,getWidth(),278);
+    [sliderViewController show:(id)this];
     
     helpViewController	= [[HelpViewController alloc] initWithNibName:@"HelpViewController" bundle:nil];
     [ofxiPhoneGetGLParentView() addSubview:helpViewController.view];
     [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 - 325,getWidth(),325);
-     [sliderViewController show:(id)this];
-     
+
+    usernameAlertViewController = [[UsernameAlertViewController alloc] init];
+    [usernameAlertViewController setAppRef:(id)this];
     
     setAllGUISliders(theGridView.getParams());
     
@@ -233,7 +235,7 @@
 	}
     
     //SLIDER
-    delete sliderGUI;
+    //delete sliderGUI;
     
     cout << "exit done \n";
 }
@@ -484,15 +486,15 @@
         sendOSCParams();
     }
     
-    eventLogger.logEvent(CHANGE_SLIDER, TwoVector(),0.0,which , value);
-    
+    eventLogger.logEvent(CHANGE_SLIDER, theGridView.getCoord(),0.0,which , value);
+
 }
 //--------------------------------------------------------------
 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]);
+        //sliders[i]->setValue(vals[i]);
         sliderVals[i] = vals[i];
         
         [sliderViewController setSlider:i to:vals[i]];
@@ -521,7 +523,7 @@
     setAllGUISliders(sliderVals);
 
 
-    eventLogger.logEvent(RANDOMISE, theGridView.getCoord() ,0.0);
+    eventLogger.logEvent(RANDOMISE, theGridView.getCoord() ,theGridView.getScale());
     
 }
 //--------------------------------------------------------------
@@ -665,7 +667,7 @@
             setAllGUISliders(theGridView.getParams());
 
         }
-        
+        // MOVE MOMENTUM
         if(moveVel.norm() > 0.3){
             if(theGridView.snapped){
                 // stop it (snap check sends snap event)
@@ -720,23 +722,16 @@
 
 //--------------------------------------------------------------
 void testApp::touchDown(ofTouchEventArgs &touch){
-    // in slider gui area?
-    //SLIDER
-    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++;
     preventingMovePostScroll = false;
-    
+    tapFlag = false; // unless touch 0
     if(touch.id == 0){
         touch0.setCoord(touch.x,touch.y);
         prevTouch0 = touch0;
         // stop zoom
         zoomVel = 0.0;
+        tapFlag = true;
     }else if(touch.id == 1){
         
         touch1.setCoord(touch.x,touch.y);
@@ -760,18 +755,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)){
-        return;
-        
-    }
-    
-    // otherwise we're good to let the zoomer handle touch
-    
+    tapFlag = false;
     // which one? keep track of each touch point
     if(touch.id == 0){
         touch0.setCoord(touch.x,touch.y);
@@ -794,6 +778,53 @@
 }
 
 //--------------------------------------------------------------
+void testApp::touchUp(ofTouchEventArgs &touch){
+    if(numActiveTouches > 0) numActiveTouches--; // dirty
+    preventingMovePostScroll = false;
+    // TODO check if in gui area!!!
+    //SLIDER
+    if(whichInterfaceShowing == SLIDERS){
+        return;
+    }
+    
+    if(tapFlag){
+        cout << "TAP!!\n";
+        // look for close preset
+        theGridView.tap(TwoVector(touch.x,touch.y));
+    }
+    tapFlag = false;
+    // which one?
+    if(touch.id == 0){
+        // tricky situation - we tried to zoom but may have left non-move finger on
+        prevTouch0.setCoord(touch.x,touch.y);
+        
+    }else if(touch.id == 1){
+        
+        
+        prevTouch1.setCoord(0,0);
+        
+    }
+    if(numActiveTouches == 0){
+        // check time since last move
+        // check time since last move - if
+        unsigned int moveTime = ofGetSystemTimeMicros();
+        if(moveTime - lastMoveTime > 100000){
+            moveVel = TwoVector(); // zero
+        }else{
+            moveVel = (move*0.3 + prevMove*0.34 + prevMove2*0.38); // use the time
+            
+        }
+        lastMoveTime = moveTime;
+    }else if (numActiveTouches == 1){
+        // just zoomed , but now lifted one of the fingers
+        // can be bad if moved so create special mode to stop scroll  (special modes bad!)
+        preventingMovePostScroll = true;
+    }
+    
+}
+
+
+//--------------------------------------------------------------
 // handle a finger being dragged
 void testApp::handleScroll(){
     
@@ -854,50 +885,6 @@
     
 }
 //--------------------------------------------------------------
-void testApp::touchUp(ofTouchEventArgs &touch){
-    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){
-        return;
-        
-    }// otherwise we're good to let the zoomer handle touch
-    
-    
-    // which one?
-    if(touch.id == 0){
-        // tricky situation - we tried to zoom but may have left non-move finger on
-        prevTouch0.setCoord(touch.x,touch.y);
-        
-    }else if(touch.id == 1){
-        
-        
-        prevTouch1.setCoord(0,0);
-        
-    }
-    if(numActiveTouches == 0){
-        // check time since last move
-        // check time since last move - if
-        unsigned int moveTime = ofGetSystemTimeMicros();
-        if(moveTime - lastMoveTime > 100000){
-            moveVel = TwoVector(); // zero
-        }else{
-            moveVel = (move*0.3 + prevMove*0.34 + prevMove2*0.38); // use the time
-            
-        }
-        lastMoveTime = moveTime;
-    }else if (numActiveTouches == 1){
-        // just zoomed , but now lifted one of the fingers
-        // can be bad if moved so create special mode to stop scroll  (special modes bad!)
-        preventingMovePostScroll = true;
-    }
-    
-}
-
-//--------------------------------------------------------------
 void testApp::touchDoubleTap(ofTouchEventArgs &touch){
     // preset?
     
@@ -1244,7 +1231,7 @@
     vector<double> vals;
     
     for(int i = 0; i< N ; i++){
-        sliderVals = theGridView.calculateParamsFromCoord(presetManager.thePresets[i]->coordinates);
+        sliderVals = theGridView.calculateParamsFromCoord(presetManager.thePresets[i].coordinates);
         
         vals.push_back((sliderVals[0]+32)*8.); // DC offset
         for(int i=1; i<5;i++){