diff testApp.mm @ 42:3d627dce8bf0

Tidied up startup logic.
author Robert Tubb <rt300@eecs.qmul.ac.uk>
date Wed, 17 Apr 2013 13:44:05 +0100
parents af06bb942d58
children b91a1859829a
line wrap: on
line diff
--- a/testApp.mm	Fri Apr 12 17:50:25 2013 +0100
+++ b/testApp.mm	Wed Apr 17 13:44:05 2013 +0100
@@ -15,8 +15,7 @@
 
 
 //DeviceID3523537000
-//--------------------------------------------------------------
-void testApp::setup(){
+void testApp::initialiseVariables(){
     paused = true;
     sendMIDIAndOSC = false;
     
@@ -55,14 +54,10 @@
     freqIndexes.push_back(8);
     
     
-    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
+    ofxiPhoneSetOrientation( OFXIPHONE_ORIENTATION_PORTRAIT );
+    ofxiPhoneExternalDisplay::mirrorOn();
+}
+void testApp::initialiseGUIs(){
     theGridView.init();
     
     setupSliderGui();
@@ -73,17 +68,6 @@
         sliderVals.push_back(64);
     }
     
-    // initialise PD
-    
-	int ticksPerBuffer = 8;	// 8 * 64 = buffer len of 512
-	
-	// setup the app core
-	core.setup(2, 1, 44100, ticksPerBuffer);
-    
-	// 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];
@@ -102,39 +86,26 @@
     topButtonViewController.view.frame = CGRectMake(0,0,getWidth(),44);
     
     usernameAlertViewController = [[UsernameAlertViewController alloc] init];
+    [usernameAlertViewController setAppRef:(id)this];
     
     helpViewController	= [[HelpViewController alloc] initWithNibName:@"HelpViewController" bundle:nil];
     [ofxiPhoneGetGLParentView() addSubview:helpViewController.view];
     [helpViewController setAppRef:(id)this];
     helpViewController.view.hidden = YES;
     
+    /*
+     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];
+     */
     
+    setAllGUISliders(theGridView.getParams());
     
-    // load preset sequences
-    loadSequences();
-    
-    // initialise user logging stuff
-    presetManager.startLoadAll();
-    tsc = [[TimedSessionController alloc] init];
-    [tsc setAppRef:(id)this];
-    eventLogger.init();
-    
-    // timer.init();
-	whichInterfaceShowing = BOTH; // but timer will change this
-    
-    
-    if(eventLogger.questionnaireCompleted){
-        [bottomTabViewController show:(id)this withSelection:1];
-    }
-    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::initialiseMIDI(){
     
     /////////////////////////
     // MIDI
@@ -182,7 +153,50 @@
 	ofxMidi::setConnectionListener(this);
     
     // 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);
 }
 
 
@@ -351,6 +365,11 @@
     // no unOK
 }
 //--------------------------------------------------------------
+void testApp::startTimedSession(){
+    [tsc startTimer];
+    // timer will show alert and set interface
+}
+//--------------------------------------------------------------
 // called from BottomTabViewController iOS segmented thing, also timed session controller
 void testApp::interfaceSelected(int which){
     switch (which){
@@ -394,7 +413,7 @@
 
     float dim = (height-10.0*OFX_UI_GLOBAL_WIDGET_SPACING)/10.0;
     // LEFT GUI
-    sliderGUI = new ofxUICanvas(0,160,SLIDER_GUI_WIDTH,getHeight());
+    sliderGUI = new ofxUICanvas(10,160,SLIDER_GUI_WIDTH,getHeight());
     
     // Uh.. loop this
     for(int i = 1; i<=10;i++){