diff testApp.mm @ 37:8ed7522deaaa

Interpolation.
author Robert Tubb <rt300@eecs.qmul.ac.uk>
date Tue, 09 Apr 2013 17:14:31 +0100
parents a42903c61558
children 0dfe9e0c01aa
line wrap: on
line diff
--- a/testApp.mm	Tue Apr 09 13:22:28 2013 +0100
+++ b/testApp.mm	Tue Apr 09 17:14:31 2013 +0100
@@ -19,13 +19,13 @@
 //--------------------------------------------------------------
 void testApp::setup(){
     paused = true;
-
-   
+    
+    
     ofBackground( 0, 0, 0 );
     ofEnableAlphaBlending();
     currentSequence = 0;
     //ofEnableSmoothing();
-
+    
 	// open an outgoing connection to HOST:PORT for OSC
     
 	sender.setup( OSC_HOST, OSC_PORT );
@@ -57,7 +57,12 @@
     
     
     ofxiPhoneSetOrientation( OFXIPHONE_ORIENTATION_PORTRAIT ); // do this before setting up all the other objects
-    
+    /*
+    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);
+    */
     // initialise the interfaces
     theGridView.init();
     
@@ -68,7 +73,7 @@
     for(int i=0; i<10;i++){
         sliderVals.push_back(64);
     }
-
+    
     // initialise PD
     
 	int ticksPerBuffer = 8;	// 8 * 64 = buffer len of 512
@@ -79,8 +84,8 @@
 	// 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];
@@ -88,7 +93,7 @@
     [bottomTabViewController setAppRef:(id)this];
     bottomTabViewController.view.frame = CGRectMake(0,getHeight()-44,getWidth(),44);
     bottomTabViewController.view.hidden = YES;
-
+    
     /////
     
     topButtonViewController	= [[TopButtonViewController alloc] initWithNibName:@"TopButtonViewController" bundle:nil];
@@ -105,15 +110,7 @@
     helpViewController.view.hidden = YES;
     
     
-    sliderViewController	= [[SliderViewController alloc] initWithNibName:@"SLiderViewController" bundle:nil];
-    [ofxiPhoneGetGLParentView() addSubview:sliderViewController.view];
-	
-    [sliderViewController setAppRef:(id)this];
-    [sliderViewController show:(id)this];
     
-    sliderViewController.view.frame = CGRectMake(0,getHeight()-43 - 363,getWidth(),44);
-    
-
     // load preset sequences
     loadSequences();
     
@@ -125,7 +122,7 @@
     
     // timer.init();
 	whichInterfaceShowing = BOTH; // but timer will change this
-
+    
     
     if(eventLogger.questionnaireCompleted){
         [bottomTabViewController show:(id)this withSelection:1];
@@ -133,21 +130,22 @@
     setAllGUISliders(theGridView.getParams());
     // GO
     paused = false;
-
+    
     randomise(); // everyone starts from random position (or where they left off??)
     
     ofxiPhoneExternalDisplay::mirrorOn();
-
+    
+    //[sliderViewController show:(id)this];
     
 }
 
 
 //--------------------------------------------------------------
 void testApp::exit(){
-
+    
     presetManager.exitAndSaveAll();
     eventLogger.exitAndSave();
-
+    
     core.exit();
     
     // are these handled automatically?
@@ -156,7 +154,7 @@
     //[bottomTabViewController release];
     
     delete sliderGUI;
-
+    
     cout << "exit done \n";
 }
 
@@ -209,9 +207,9 @@
 //--------------------------------------------------------------
 void testApp::showQuestionnaire(){
     // stop updating / drawing
-
+    
     // if(eventLogger.questionnaireCompleted) return;
-
+    
     [topButtonViewController pausePressed:(id)this];
     
     //stopSequencer
@@ -225,18 +223,18 @@
     
     whichInterfaceShowing = QUESTIONNAIRE;
     
-
+    
 }
 //--------------------------------------------------------------
 void testApp::questionnaireHidden(vector<int> answers, const char* userComments){
     // send answers to server as json
     eventLogger.questionnaireAnswersObtained(answers, userComments);
-
+    
     // tell bottomtabviewcontroller to show and select both interface
     interfaceSelected(BOTH);
     [bottomTabViewController show:(id)this withSelection:1];
     
-
+    
 }
 //--------------------------------------------------------------
 // shortcut function for testing
@@ -247,9 +245,9 @@
 }
 //--------------------------------------------------------------
 void testApp::showIntro(){
-
+    
     cout << "SHOW INTRO\n";
-
+    
     [tsc cancelTimers];
     bottomTabViewController.view.hidden = YES;
     introViewController	= [[IntroViewController alloc] initWithNibName:@"IntroViewController" bundle:nil];
@@ -282,7 +280,7 @@
 void testApp::interfaceSelected(int which){
     switch (which){
         case 0:
-
+            
             whichInterfaceShowing = SLIDERS;
             sliderGUI->setVisible(true);
             // set the slider values to stuff got from zoomer
@@ -291,7 +289,7 @@
             
             break;
         case 1:
-
+            
             whichInterfaceShowing = BOTH;
             sliderGUI->setVisible(true);
             // set the slider values to stuff got from zoomer
@@ -299,7 +297,7 @@
             setAllGUISliders(sliderVals);
             break;
         case 2:
-
+            
             sliderGUI->setVisible(false);
             whichInterfaceShowing = ZOOMER;
             break;
@@ -321,10 +319,10 @@
     float dim = (height-10.0*OFX_UI_GLOBAL_WIDGET_SPACING)/10.0;
     // LEFT GUI
     sliderGUI = new ofxUICanvas(0,160,SLIDER_GUI_WIDTH,getHeight());
-  
+    
     // Uh.. loop this
     for(int i = 1; i<=10;i++){
-    
+        
         ofxUISlider *slider;
         slider = (ofxUISlider *)sliderGUI->addWidgetDown(new ofxUISlider(length,dim,0.0,127,64,sliderParamNames[i-1]));
         slider->setDrawPadding(true);
@@ -340,10 +338,10 @@
         sliders.push_back(slider);
     }
     
-
+    
     
     ofAddListener(sliderGUI->newGUIEvent, this, &testApp::sliderGUIEvent);
-   
+    
 }
 //--------------------------------------------------------------
 void testApp::sliderGUIEvent(ofxUIEventArgs &e){
@@ -351,7 +349,7 @@
         cout << "GUI ERROR";
         return;
     }
-
+    
     // "normal" parameter changes
     for(int i = 1; i<=10;i++){
         
@@ -362,14 +360,14 @@
             sliderMoved(i-1,slider->getScaledValue()); // internal array 0 indexed
         }
     }
-
+    
 }
 //--------------------------------------------------------------
 void testApp::sliderMoved(int which, float value){
     // an update caused by slider view being touched
     sliderVals[which] = (int)value;
     theGridView.setParams(sliderVals);
-
+    
     sendParametersToPD();
     
     eventLogger.logEvent(CHANGE_SLIDER, TwoVector(),0.0,which , value);
@@ -391,7 +389,7 @@
         sliderVals[i] = ofRandom(0, 127);
         
     }
-    
+    currentSequence = ofRandom(0, sequences.size()-1);
     // send to grid, sliders and PD
     theGridView.setParams(sliderVals);
     setAllGUISliders(sliderVals);
@@ -423,35 +421,47 @@
 }
 //--------------------------------------------------------------
 void testApp::sendParametersToPD(){
+    static int previousSequence;
+    // frequencer stuff to get 16 steps
     
-    // frequencer stuff to get 16 steps
+     vector<double> vals;
+     
+     
+     vals.push_back((sliderVals[0]+32)*8.); // DC offset
+     for(int i=1; i<5;i++){
+     vals.push_back((sliderVals[i] - 64)*2.);
+     }
+    
+    vector<double> steps = frequencer.freqMagEdit(freqIndexes, vals);
+    List seqSteps;
+    seqSteps.addSymbol("seqSteps");
+    for(int i=0; i < 16; i++){
+        seqSteps.addFloat(round(steps[i]));
+    }
+    core.pd.sendList("fromOF", seqSteps);
+
     /*
-    vector<double> vals;
-    
-    
-    vals.push_back((sliderVals[0]+32)*8.); // DC offset
-    for(int i=1; i<5;i++){
-        vals.push_back((sliderVals[i] - 64)*2.);
+    if(currentSequence != previousSequence){
+        List seqSteps;
+        
+        seqSteps.addSymbol("seqSteps");
+        if(currentSequence >= sequences.size() || currentSequence < 0){
+            cout << "ERROR: not a valid sequence index\n";
+            for(int i=0; i < 16; i++){
+                seqSteps.addFloat(50);
+            }
+        }else{
+            for(int i=0; i < 16; i++){
+                seqSteps.addFloat(round(sequences[currentSequence][i]));
+            }
+        }
+        
+        core.pd.sendList("fromOF", seqSteps);
+        previousSequence = currentSequence;
     }
-
-    vector<double> steps = frequencer.freqMagEdit(freqIndexes, vals);
-     
      */
     
-    // send a list using the List object
-    List seqSteps;
-    
-    seqSteps.addSymbol("seqSteps");
-    if(currentSequence > sequences.size() || currentSequence < 0){
-        cout << "ERROR: not a valid sequence index\n";
-    }
-    for(int i=0; i < 16; i++){
-        seqSteps.addFloat(round(sequences[currentSequence][i])); // rounding here??
-    }
-    
-    
-    core.pd.sendList("fromOF", seqSteps);
-
+    // send synth params
     sendOscShape(sliderVals[5]);
     sendFiltType(sliderVals[6]);
     sendFiltFreq(sliderVals[7]);
@@ -467,7 +477,7 @@
 #pragma mark STANDARD OF FUNCTIONS
 //--------------------------------------------------------------
 void testApp::update(){
-
+    
     if(paused) return;
     
     if(ofxiPhoneExternalDisplay::isExternalScreenConnected()){
@@ -487,11 +497,8 @@
             zoomVel = zoomVel*slowFactor;
             moveVel.setCoord(0.0,0.0);; // don't move if zooming! Too many events!
             
-            // need to do this if zoom goes to snap
-            if(theGridView.snapped){
-                setAllGUISliders(theGridView.getParams());
-                sendParametersToPD();
-            }
+            setAllGUISliders(theGridView.getParams());
+            sendParametersToPD();
         }
         
         if(moveVel.norm() > 0.3){
@@ -502,7 +509,7 @@
                 theGridView.move(moveVel);
                 moveVel = moveVel*slowFactor;
             }
-         // and get new parameter values
+            // and get new parameter values
             setAllGUISliders(theGridView.getParams());
             sendParametersToPD();
         }else if(moveVel.norm() > 0.01){ // and less than 0.3
@@ -515,9 +522,9 @@
         }else{
             // stopped - do nothing
         }
-
+        
     }
-
+    
 }
 //--------------------------------------------------------------
 void testApp::sendOSCParams(){
@@ -537,18 +544,18 @@
 }
 //--------------------------------------------------------------
 void testApp::draw(){
-
+    
     switch (whichInterfaceShowing){
         case SLIDERS:
             break;
         case ZOOMER:
             theGridView.draw();
-
+            
             break;
         case BOTH:
             
             theGridView.draw();
-
+            
             break;
         case INTRO:
             break;
@@ -572,7 +579,7 @@
     
     numActiveTouches++;
     preventingMovePostScroll = false;
-
+    
     if(touch.id == 0){
         touch0.setCoord(touch.x,touch.y);
         prevTouch0 = touch0;
@@ -596,7 +603,7 @@
         double dist = touch1.distanceTo(touch0);
         prevDist = dist;
     }
-
+    
 }
 
 //--------------------------------------------------------------
@@ -611,7 +618,7 @@
     }
     
     // otherwise we're good to let the zoomer handle touch
-
+    
     // which one? keep track of each touch point
     if(touch.id == 0){
         touch0.setCoord(touch.x,touch.y);
@@ -620,7 +627,7 @@
         
         touch1.setCoord(touch.x,touch.y);
     }
-
+    
     if(numActiveTouches == 1){
         if(preventingMovePostScroll) return;
         handleScroll();
@@ -629,14 +636,14 @@
         
     }
     prevTouch0 = touch0;
-   
+    
     
 }
 
 //--------------------------------------------------------------
 // handle a finger being dragged
 void testApp::handleScroll(){
-
+    
     TwoVector move = touch0 - prevTouch0;
     if(yLocked){
         move.y = 0.0;
@@ -644,7 +651,7 @@
     if(xLocked){
         move.x = 0.0;
     }
-
+    
     // check time since last move - if
     unsigned int moveTime = ofGetSystemTimeMicros();
     if(moveTime - lastMoveTime > 100000){
@@ -655,11 +662,11 @@
     }
     lastMoveTime = moveTime;
     
-
+    
     prevMove2 = prevMove;
     prevMove = move;
     
-
+    
     theGridView.move(move);
     
     // and get new parameter values
@@ -687,12 +694,11 @@
     
     prevDist = dist;
     
-    // need to do this if zoom goes to snap
-    if(theGridView.snapped){
-        setAllGUISliders(theGridView.getParams());
-        sendParametersToPD();
-    }
 
+    setAllGUISliders(theGridView.getParams());
+    sendParametersToPD();
+
+    
 }
 //--------------------------------------------------------------
 void testApp::touchUp(ofTouchEventArgs &touch){
@@ -706,7 +712,7 @@
         
     }// 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
@@ -714,7 +720,7 @@
         
     }else if(touch.id == 1){
         
-
+        
         prevTouch1.setCoord(0,0);
         
     }
@@ -734,7 +740,7 @@
         // can be bad if moved so create special mode to stop scroll  (special modes bad!)
         preventingMovePostScroll = true;
     }
-
+    
 }
 
 //--------------------------------------------------------------
@@ -742,55 +748,55 @@
     // preset?
     
     /* ballses everything for some reason
-    TwoVector centre = TwoVector(getWidth()*0.5,getHeight()*0.5);
-    // if near centre
-    if((touch.x < centre.x+10) && (touch.x > centre.x-10) && (touch.y < centre.y+10) && (touch.y > centre.y-10)){
-        numActiveTouches = 0; // dirty
-        presetManager.showNameDialog();
-        
-    }
+     TwoVector centre = TwoVector(getWidth()*0.5,getHeight()*0.5);
+     // if near centre
+     if((touch.x < centre.x+10) && (touch.x > centre.x-10) && (touch.y < centre.y+10) && (touch.y > centre.y-10)){
+     numActiveTouches = 0; // dirty
+     presetManager.showNameDialog();
+     
+     }
      */
     
 }
 
 //--------------------------------------------------------------
 void testApp::lostFocus(){
-
+    
 }
 
 //--------------------------------------------------------------
 void testApp::gotFocus(){
-
+    
 }
 
 //--------------------------------------------------------------
 void testApp::gotMemoryWarning(){
-
+    
 }
 
 //--------------------------------------------------------------
 void testApp::deviceOrientationChanged(int newOrientation){
-/*
-    cout << "orientation: " << newOrientation;
-
-    if(newOrientation == 4){
-        ofxiPhoneSetOrientation( OF_ORIENTATION_DEFAULT );
-        
-    }else if(newOrientation == 3){
-        ofxiPhoneSetOrientation( OF_ORIENTATION_90_LEFT );
-    }else if(newOrientation == 3){
-            ofxiPhoneSetOrientation( OF_ORIENTATION_90_LEFT );
-        }
-
-
-    [ofxiPhoneGetGLView() updateDimensions];
-*/
+    /*
+     cout << "orientation: " << newOrientation;
+     
+     if(newOrientation == 4){
+     ofxiPhoneSetOrientation( OF_ORIENTATION_DEFAULT );
+     
+     }else if(newOrientation == 3){
+     ofxiPhoneSetOrientation( OF_ORIENTATION_90_LEFT );
+     }else if(newOrientation == 3){
+     ofxiPhoneSetOrientation( OF_ORIENTATION_90_LEFT );
+     }
+     
+     
+     [ofxiPhoneGetGLView() updateDimensions];
+     */
 }
 
 
 //--------------------------------------------------------------
 void testApp::touchCancelled(ofTouchEventArgs& args){
-
+    
 }
 //---------------------------------------------------------------
 // AUDIO STUFF
@@ -848,11 +854,11 @@
 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;
@@ -874,12 +880,12 @@
     float ctrlout[numcontrols];
     string ctrlName[5] = {"pWidth" , "sqVol", "sawVol", "sineVol", "FMAmt"};
     float values[5][5] =
-        {{0.5, 0., 0., 1., 1.}, // 0
-        {0.5, 0., 0., 1., 0.},  // 32 
+    {{0.5, 0., 0., 1., 1.}, // 0
+        {0.5, 0., 0., 1., 0.},  // 32
         {0.5, 0., 1., 0., 0.},  // 64
         {0.5, 1., 1., 0., 0.},  // 96
         {0.01,1., 1., 0., 0.}}; // 127
-
+    
     float fidx = (numpoints-1)*ctrlin/128.;
     int idx = floor(fidx);
     float frac = fidx - idx;
@@ -890,7 +896,7 @@
         
         toPD.addSymbol(ctrlName[i]);
         toPD.addFloat(ctrlout[i]); // rounding here??
-
+        
         core.pd.sendList("fromOF", toPD);
         //cout << ctrlName[i] << "sending" << ctrlout[i] << "\n";
     }
@@ -908,7 +914,7 @@
     float ctrlout[numcontrols];
     string ctrlName[4] = {"lpLev" , "bpLev", "hpLev", "reson"};
     float values[3][4] =
-       {{2., 0., 0., 1.}, // 0
+    {{2., 0., 0., 1.}, // 0
         {0., 10., 0., 10.},  // 64
         {0., 0., 1., 1.}}; // 127
     
@@ -940,7 +946,7 @@
     List toPD;
     
     toPD.addSymbol("filtFreq");
-    toPD.addFloat(fout); 
+    toPD.addFloat(fout);
     
     core.pd.sendList("fromOF", toPD);
 }
@@ -956,7 +962,7 @@
     float ctrlout[numcontrols];
     string ctrlName[3] = {"attack" , "decay", "sustain"};
     float values[5][3] =
-        {{0., 0., 0.}, // 0
+    {{0., 0., 0.}, // 0
         {0., 0.5, 0.},  // 32
         {0.0, 1., 0.8},  // 64
         {0.99, 0.3, 0.},  // 96
@@ -1041,10 +1047,10 @@
     
     // read in sequence preset file
     string jsonFile = ofxiPhoneGetDocumentsDirectory() + "pilot_sequences.json";
-
+    
     Json::Value root;
     Json::Reader reader;
-
+    
     ifstream theFile(jsonFile.c_str());
     stringstream fileText;
     string line;
@@ -1056,7 +1062,7 @@
         while(theFile){
             theFile >> line;
             // cout << line << "\n"; // lots?
-            fileText << line;   
+            fileText << line;
         }
         
         theFile.close();
@@ -1082,6 +1088,7 @@
         }
     }
     // currentSequence
-    currentSequence = ofRandom(0,N);
+    
+    currentSequence = ofRandom(0,N-1);
     
 }