changeset 25:f42a00e3f22d

Logs condensed slightly. Questionnaire button enable. double precision location!!!
author Robert Tubb <rt300@eecs.qmul.ac.uk>
date Fri, 01 Feb 2013 17:39:19 +0000
parents a4908ad8c78e
children 2e1fdac115af
files BottomTabViewController.h BottomTabViewController.mm BottomTabViewController.xib TopButtonViewController.h TopButtonViewController.mm TopButtonViewController.xib UsernameAlertViewController.mm eventLogger.h eventLogger.mm presetManager.mm testApp.h testApp.mm
diffstat 12 files changed, 257 insertions(+), 336 deletions(-) [+]
line wrap: on
line diff
--- a/BottomTabViewController.h	Fri Feb 01 11:16:56 2013 +0000
+++ b/BottomTabViewController.h	Fri Feb 01 17:39:19 2013 +0000
@@ -11,6 +11,7 @@
 @interface BottomTabViewController : UIViewController
 
 @property (nonatomic, assign)       id theOFAppRef;
+@property (retain, nonatomic) IBOutlet UISegmentedControl *interfaceSelector;
 
 
 -(IBAction)show:(id)sender;
--- a/BottomTabViewController.mm	Fri Feb 01 11:16:56 2013 +0000
+++ b/BottomTabViewController.mm	Fri Feb 01 17:39:19 2013 +0000
@@ -27,6 +27,8 @@
 {
     [super viewDidLoad];
     // Do any additional setup after loading the view from its nib.
+    self.interfaceSelector.selectedSegmentIndex = 1;
+    
 }
 
 - (void)didReceiveMemoryWarning
@@ -53,4 +55,12 @@
     self.view.hidden = NO;
 }
 
+- (void)dealloc {
+    [_interfaceSelector release];
+    [super dealloc];
+}
+- (void)viewDidUnload {
+    [self setInterfaceSelector:nil];
+    [super viewDidUnload];
+}
 @end
--- a/BottomTabViewController.xib	Fri Feb 01 11:16:56 2013 +0000
+++ b/BottomTabViewController.xib	Fri Feb 01 17:39:19 2013 +0000
@@ -40,7 +40,6 @@
 						<int key="NSvFlags">292</int>
 						<string key="NSFrameSize">{768, 44}</string>
 						<reference key="NSSuperview" ref="766721923"/>
-						<reference key="NSWindow"/>
 						<string key="NSReuseIdentifierKey">_NS:9</string>
 						<bool key="IBUIOpaque">NO</bool>
 						<string key="targetRuntimeIdentifier">IBIPadFramework</string>
@@ -75,7 +74,6 @@
 				</array>
 				<string key="NSFrameSize">{768, 43}</string>
 				<reference key="NSSuperview"/>
-				<reference key="NSWindow"/>
 				<reference key="NSNextKeyView" ref="416841628"/>
 				<bool key="IBUIOpaque">NO</bool>
 				<bool key="IBUIClearsContextBeforeDrawing">NO</bool>
@@ -98,6 +96,14 @@
 					<int key="connectionID">3</int>
 				</object>
 				<object class="IBConnectionRecord">
+					<object class="IBCocoaTouchOutletConnection" key="connection">
+						<string key="label">interfaceSelector</string>
+						<reference key="source" ref="841351856"/>
+						<reference key="destination" ref="416841628"/>
+					</object>
+					<int key="connectionID">6</int>
+				</object>
+				<object class="IBConnectionRecord">
 					<object class="IBCocoaTouchEventConnection" key="connection">
 						<string key="label">interfaceSelected:</string>
 						<reference key="source" ref="416841628"/>
@@ -154,34 +160,9 @@
 			<nil key="activeLocalization"/>
 			<dictionary class="NSMutableDictionary" key="localizations"/>
 			<nil key="sourceID"/>
-			<int key="maxID">5</int>
+			<int key="maxID">6</int>
 		</object>
-		<object class="IBClassDescriber" key="IBDocument.Classes">
-			<array class="NSMutableArray" key="referencedPartialClassDescriptions">
-				<object class="IBPartialClassDescription">
-					<string key="className">BottomTabViewController</string>
-					<string key="superclassName">UIViewController</string>
-					<dictionary class="NSMutableDictionary" key="actions">
-						<string key="interfaceSelected:">id</string>
-						<string key="show:">id</string>
-					</dictionary>
-					<dictionary class="NSMutableDictionary" key="actionInfosByName">
-						<object class="IBActionInfo" key="interfaceSelected:">
-							<string key="name">interfaceSelected:</string>
-							<string key="candidateClassName">id</string>
-						</object>
-						<object class="IBActionInfo" key="show:">
-							<string key="name">show:</string>
-							<string key="candidateClassName">id</string>
-						</object>
-					</dictionary>
-					<object class="IBClassDescriptionSource" key="sourceIdentifier">
-						<string key="majorKey">IBProjectSource</string>
-						<string key="minorKey">./Classes/BottomTabViewController.h</string>
-					</object>
-				</object>
-			</array>
-		</object>
+		<object class="IBClassDescriber" key="IBDocument.Classes"/>
 		<int key="IBDocument.localizationMode">0</int>
 		<string key="IBDocument.TargetRuntimeIdentifier">IBIPadFramework</string>
 		<bool key="IBDocument.PluginDeclaredDependenciesTrackSystemTargetVersion">YES</bool>
--- a/TopButtonViewController.h	Fri Feb 01 11:16:56 2013 +0000
+++ b/TopButtonViewController.h	Fri Feb 01 17:39:19 2013 +0000
@@ -14,14 +14,17 @@
 
 @property (retain, nonatomic) IBOutlet UIBarButtonItem *playButton;
 @property (retain, nonatomic) IBOutlet UIBarButtonItem *pauseButton;
+@property (retain, nonatomic) IBOutlet UIBarButtonItem *qButton;
 
 -(IBAction)show:(id)sender;
 -(void)setAppRef:(id)theOFApp;
+-(void)enableQuestionButton;
 - (IBAction)playPressed:(id)sender;
 - (IBAction)pausePressed:(id)sender;
 - (IBAction)savePressed:(id)sender;
 - (IBAction)lockSequencePressed:(id)sender;
 - (IBAction)lockSynthPressed:(id)sender;
 - (IBAction)qPressed:(id)sender;
+- (IBAction)randomise:(id)sender;
 
 @end
--- a/TopButtonViewController.mm	Fri Feb 01 11:16:56 2013 +0000
+++ b/TopButtonViewController.mm	Fri Feb 01 17:39:19 2013 +0000
@@ -34,8 +34,13 @@
     // Do any additional setup after loading the view from its nib.
     self.playButton.enabled = true;
     self.pauseButton.enabled = false;
+    self.qButton.enabled = false;
+
 }
 
+- (void)enableQuestionButton{
+    self.qButton.enabled = true;
+}
 - (void)didReceiveMemoryWarning
 {
     [super didReceiveMemoryWarning];
@@ -94,6 +99,10 @@
     ((testApp *)self.theOFAppRef)->showQuestionnaire();
 }
 
+- (IBAction)randomise:(id)sender {
+    ((testApp *)self.theOFAppRef)->randomise();
+}
+
 - (IBAction)show:(id)sender
 {
     self.theOFAppRef = sender;
@@ -103,11 +112,13 @@
 - (void)dealloc {
     [_playButton release];
     [_pauseButton release];
+    [_qButton release];
     [super dealloc];
 }
 - (void)viewDidUnload {
     [self setPlayButton:nil];
     [self setPauseButton:nil];
+    [self setQButton:nil];
     [super viewDidUnload];
 }
 @end
--- a/TopButtonViewController.xib	Fri Feb 01 11:16:56 2013 +0000
+++ b/TopButtonViewController.xib	Fri Feb 01 17:39:19 2013 +0000
@@ -11,7 +11,6 @@
 			<string key="NS.object.0">1930</string>
 		</object>
 		<array key="IBDocument.IntegratedClassDependencies">
-			<string>IBNSLayoutConstraint</string>
 			<string>IBProxyObject</string>
 			<string>IBUIBarButtonItem</string>
 			<string>IBUIToolbar</string>
@@ -48,6 +47,23 @@
 						<bool key="IBUIClearsContextBeforeDrawing">NO</bool>
 						<string key="targetRuntimeIdentifier">IBIPadFramework</string>
 						<array class="NSMutableArray" key="IBUIItems">
+							<object class="IBUIBarButtonItem" id="996249183">
+								<string key="IBUITitle">Save Preset</string>
+								<string key="targetRuntimeIdentifier">IBIPadFramework</string>
+								<int key="IBUIStyle">1</int>
+								<reference key="IBUIToolbar" ref="358683122"/>
+							</object>
+							<object class="IBUIBarButtonItem" id="702923516">
+								<string key="IBUITitle">Take Questionnaire</string>
+								<string key="targetRuntimeIdentifier">IBIPadFramework</string>
+								<int key="IBUIStyle">1</int>
+								<reference key="IBUIToolbar" ref="358683122"/>
+							</object>
+							<object class="IBUIBarButtonItem" id="528026433">
+								<string key="targetRuntimeIdentifier">IBIPadFramework</string>
+								<reference key="IBUIToolbar" ref="358683122"/>
+								<int key="IBUISystemItemIdentifier">5</int>
+							</object>
 							<object class="IBUIBarButtonItem" id="379344923">
 								<string key="targetRuntimeIdentifier">IBIPadFramework</string>
 								<int key="IBUIStyle">1</int>
@@ -60,39 +76,17 @@
 								<reference key="IBUIToolbar" ref="358683122"/>
 								<int key="IBUISystemItemIdentifier">18</int>
 							</object>
-							<object class="IBUIBarButtonItem" id="220646609">
-								<string key="targetRuntimeIdentifier">IBIPadFramework</string>
-								<float key="IBUIWidth">52</float>
-								<reference key="IBUIToolbar" ref="358683122"/>
-								<int key="IBUISystemItemIdentifier">6</int>
-							</object>
-							<object class="IBUIBarButtonItem" id="996249183">
-								<string key="IBUITitle">Save Preset</string>
-								<string key="targetRuntimeIdentifier">IBIPadFramework</string>
-								<int key="IBUIStyle">1</int>
-								<reference key="IBUIToolbar" ref="358683122"/>
-								<object class="NSColor" key="IBUITintColor">
-									<int key="NSColorSpace">1</int>
-									<bytes key="NSRGB">MC4zNjc1OTI2Njc5IDAuNTkyNTIwODk2NyAxAA</bytes>
-								</object>
-							</object>
-							<object class="IBUIBarButtonItem" id="318310914">
-								<string key="targetRuntimeIdentifier">IBIPadFramework</string>
-								<float key="IBUIWidth">62</float>
-								<reference key="IBUIToolbar" ref="358683122"/>
-								<int key="IBUISystemItemIdentifier">6</int>
-							</object>
-							<object class="IBUIBarButtonItem" id="702923516">
-								<string key="IBUITitle">Take Questionnaire</string>
-								<string key="targetRuntimeIdentifier">IBIPadFramework</string>
-								<int key="IBUIStyle">1</int>
-								<reference key="IBUIToolbar" ref="358683122"/>
-							</object>
 							<object class="IBUIBarButtonItem" id="680653375">
 								<string key="targetRuntimeIdentifier">IBIPadFramework</string>
 								<reference key="IBUIToolbar" ref="358683122"/>
 								<int key="IBUISystemItemIdentifier">5</int>
 							</object>
+							<object class="IBUIBarButtonItem" id="180077124">
+								<string key="IBUITitle">Random</string>
+								<string key="targetRuntimeIdentifier">IBIPadFramework</string>
+								<int key="IBUIStyle">1</int>
+								<reference key="IBUIToolbar" ref="358683122"/>
+							</object>
 							<object class="IBUIBarButtonItem" id="189059998">
 								<string key="IBUITitle">Lock Sequence (X)</string>
 								<string key="targetRuntimeIdentifier">IBIPadFramework</string>
@@ -150,6 +144,14 @@
 					<int key="connectionID">27</int>
 				</object>
 				<object class="IBConnectionRecord">
+					<object class="IBCocoaTouchOutletConnection" key="connection">
+						<string key="label">qButton</string>
+						<reference key="source" ref="841351856"/>
+						<reference key="destination" ref="702923516"/>
+					</object>
+					<int key="connectionID">32</int>
+				</object>
+				<object class="IBConnectionRecord">
 					<object class="IBCocoaTouchEventConnection" key="connection">
 						<string key="label">savePressed:</string>
 						<reference key="source" ref="996249183"/>
@@ -197,6 +199,14 @@
 					</object>
 					<int key="connectionID">21</int>
 				</object>
+				<object class="IBConnectionRecord">
+					<object class="IBCocoaTouchEventConnection" key="connection">
+						<string key="label">randomise:</string>
+						<reference key="source" ref="180077124"/>
+						<reference key="destination" ref="841351856"/>
+					</object>
+					<int key="connectionID">31</int>
+				</object>
 			</array>
 			<object class="IBMutableOrderedSet" key="objectRecords">
 				<array key="orderedObjects">
@@ -222,54 +232,6 @@
 						<reference key="object" ref="766721923"/>
 						<array class="NSMutableArray" key="children">
 							<reference ref="358683122"/>
-							<object class="IBNSLayoutConstraint" id="901616674">
-								<reference key="firstItem" ref="358683122"/>
-								<int key="firstAttribute">3</int>
-								<int key="relation">0</int>
-								<reference key="secondItem" ref="766721923"/>
-								<int key="secondAttribute">3</int>
-								<float key="multiplier">1</float>
-								<object class="IBLayoutConstant" key="constant">
-									<double key="value">0.0</double>
-								</object>
-								<float key="priority">1000</float>
-								<reference key="containingView" ref="766721923"/>
-								<int key="scoringType">8</int>
-								<float key="scoringTypeFloat">29</float>
-								<int key="contentType">3</int>
-							</object>
-							<object class="IBNSLayoutConstraint" id="227999361">
-								<reference key="firstItem" ref="358683122"/>
-								<int key="firstAttribute">5</int>
-								<int key="relation">0</int>
-								<reference key="secondItem" ref="766721923"/>
-								<int key="secondAttribute">5</int>
-								<float key="multiplier">1</float>
-								<object class="IBLayoutConstant" key="constant">
-									<double key="value">0.0</double>
-								</object>
-								<float key="priority">1000</float>
-								<reference key="containingView" ref="766721923"/>
-								<int key="scoringType">8</int>
-								<float key="scoringTypeFloat">29</float>
-								<int key="contentType">3</int>
-							</object>
-							<object class="IBNSLayoutConstraint" id="1035495854">
-								<reference key="firstItem" ref="358683122"/>
-								<int key="firstAttribute">6</int>
-								<int key="relation">0</int>
-								<reference key="secondItem" ref="766721923"/>
-								<int key="secondAttribute">6</int>
-								<float key="multiplier">1</float>
-								<object class="IBLayoutConstant" key="constant">
-									<double key="value">0.0</double>
-								</object>
-								<float key="priority">1000</float>
-								<reference key="containingView" ref="766721923"/>
-								<int key="scoringType">8</int>
-								<float key="scoringTypeFloat">29</float>
-								<int key="contentType">3</int>
-							</object>
 						</array>
 						<reference key="parent" ref="0"/>
 					</object>
@@ -277,15 +239,15 @@
 						<int key="objectID">4</int>
 						<reference key="object" ref="358683122"/>
 						<array class="NSMutableArray" key="children">
-							<reference ref="220646609"/>
-							<reference ref="702923516"/>
 							<reference ref="189059998"/>
 							<reference ref="597523981"/>
-							<reference ref="318310914"/>
+							<reference ref="996249183"/>
+							<reference ref="680653375"/>
+							<reference ref="702923516"/>
+							<reference ref="528026433"/>
 							<reference ref="379344923"/>
-							<reference ref="996249183"/>
 							<reference ref="898331149"/>
-							<reference ref="680653375"/>
+							<reference ref="180077124"/>
 						</array>
 						<reference key="parent" ref="766721923"/>
 					</object>
@@ -295,31 +257,11 @@
 						<reference key="parent" ref="358683122"/>
 					</object>
 					<object class="IBObjectRecord">
-						<int key="objectID">6</int>
-						<reference key="object" ref="1035495854"/>
-						<reference key="parent" ref="766721923"/>
-					</object>
-					<object class="IBObjectRecord">
-						<int key="objectID">7</int>
-						<reference key="object" ref="227999361"/>
-						<reference key="parent" ref="766721923"/>
-					</object>
-					<object class="IBObjectRecord">
-						<int key="objectID">8</int>
-						<reference key="object" ref="901616674"/>
-						<reference key="parent" ref="766721923"/>
-					</object>
-					<object class="IBObjectRecord">
 						<int key="objectID">9</int>
 						<reference key="object" ref="379344923"/>
 						<reference key="parent" ref="358683122"/>
 					</object>
 					<object class="IBObjectRecord">
-						<int key="objectID">10</int>
-						<reference key="object" ref="220646609"/>
-						<reference key="parent" ref="358683122"/>
-					</object>
-					<object class="IBObjectRecord">
 						<int key="objectID">11</int>
 						<reference key="object" ref="702923516"/>
 						<reference key="parent" ref="358683122"/>
@@ -335,11 +277,6 @@
 						<reference key="parent" ref="358683122"/>
 					</object>
 					<object class="IBObjectRecord">
-						<int key="objectID">14</int>
-						<reference key="object" ref="318310914"/>
-						<reference key="parent" ref="358683122"/>
-					</object>
-					<object class="IBObjectRecord">
 						<int key="objectID">16</int>
 						<reference key="object" ref="898331149"/>
 						<reference key="parent" ref="358683122"/>
@@ -349,6 +286,16 @@
 						<reference key="object" ref="680653375"/>
 						<reference key="parent" ref="358683122"/>
 					</object>
+					<object class="IBObjectRecord">
+						<int key="objectID">29</int>
+						<reference key="object" ref="528026433"/>
+						<reference key="parent" ref="358683122"/>
+					</object>
+					<object class="IBObjectRecord">
+						<int key="objectID">30</int>
+						<reference key="object" ref="180077124"/>
+						<reference key="parent" ref="358683122"/>
+					</object>
 				</array>
 			</object>
 			<dictionary class="NSMutableDictionary" key="flattenedProperties">
@@ -356,44 +303,27 @@
 				<string key="-1.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
 				<string key="-2.CustomClassName">UIResponder</string>
 				<string key="-2.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
-				<string key="10.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
 				<string key="11.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
 				<string key="12.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
 				<string key="13.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
-				<string key="14.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
 				<string key="16.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
 				<string key="2.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
-				<array class="NSMutableArray" key="2.IBViewMetadataConstraints">
-					<reference ref="1035495854"/>
-					<reference ref="227999361"/>
-					<reference ref="901616674"/>
-				</array>
 				<string key="28.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+				<string key="29.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+				<string key="30.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
 				<string key="4.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
-				<boolean value="NO" key="4.IBViewMetadataTranslatesAutoresizingMaskIntoConstraints"/>
 				<string key="5.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
-				<string key="6.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
-				<string key="7.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
-				<string key="8.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
 				<string key="9.IBPluginDependency">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
 			</dictionary>
 			<dictionary class="NSMutableDictionary" key="unlocalizedProperties"/>
 			<nil key="activeLocalization"/>
 			<dictionary class="NSMutableDictionary" key="localizations"/>
 			<nil key="sourceID"/>
-			<int key="maxID">28</int>
+			<int key="maxID">32</int>
 		</object>
 		<object class="IBClassDescriber" key="IBDocument.Classes">
 			<array class="NSMutableArray" key="referencedPartialClassDescriptions">
 				<object class="IBPartialClassDescription">
-					<string key="className">NSLayoutConstraint</string>
-					<string key="superclassName">NSObject</string>
-					<object class="IBClassDescriptionSource" key="sourceIdentifier">
-						<string key="majorKey">IBProjectSource</string>
-						<string key="minorKey">./Classes/NSLayoutConstraint.h</string>
-					</object>
-				</object>
-				<object class="IBPartialClassDescription">
 					<string key="className">TopButtonViewController</string>
 					<string key="superclassName">UIViewController</string>
 					<dictionary class="NSMutableDictionary" key="actions">
@@ -402,6 +332,7 @@
 						<string key="pausePressed:">id</string>
 						<string key="playPressed:">id</string>
 						<string key="qPressed:">id</string>
+						<string key="randomise:">id</string>
 						<string key="savePressed:">id</string>
 						<string key="show:">id</string>
 					</dictionary>
@@ -426,6 +357,10 @@
 							<string key="name">qPressed:</string>
 							<string key="candidateClassName">id</string>
 						</object>
+						<object class="IBActionInfo" key="randomise:">
+							<string key="name">randomise:</string>
+							<string key="candidateClassName">id</string>
+						</object>
 						<object class="IBActionInfo" key="savePressed:">
 							<string key="name">savePressed:</string>
 							<string key="candidateClassName">id</string>
@@ -438,6 +373,7 @@
 					<dictionary class="NSMutableDictionary" key="outlets">
 						<string key="pauseButton">UIBarButtonItem</string>
 						<string key="playButton">UIBarButtonItem</string>
+						<string key="qButton">UIBarButtonItem</string>
 					</dictionary>
 					<dictionary class="NSMutableDictionary" key="toOneOutletInfosByName">
 						<object class="IBToOneOutletInfo" key="pauseButton">
@@ -448,6 +384,10 @@
 							<string key="name">playButton</string>
 							<string key="candidateClassName">UIBarButtonItem</string>
 						</object>
+						<object class="IBToOneOutletInfo" key="qButton">
+							<string key="name">qButton</string>
+							<string key="candidateClassName">UIBarButtonItem</string>
+						</object>
 					</dictionary>
 					<object class="IBClassDescriptionSource" key="sourceIdentifier">
 						<string key="majorKey">IBProjectSource</string>
@@ -460,7 +400,6 @@
 		<string key="IBDocument.TargetRuntimeIdentifier">IBIPadFramework</string>
 		<bool key="IBDocument.PluginDeclaredDependenciesTrackSystemTargetVersion">YES</bool>
 		<int key="IBDocument.defaultPropertyAccessControl">3</int>
-		<bool key="IBDocument.UseAutolayout">YES</bool>
 		<string key="IBCocoaTouchPluginVersion">1930</string>
 	</data>
 </archive>
--- a/UsernameAlertViewController.mm	Fri Feb 01 11:16:56 2013 +0000
+++ b/UsernameAlertViewController.mm	Fri Feb 01 17:39:19 2013 +0000
@@ -62,4 +62,4 @@
 
 
 // global. again.
-UsernameAlertViewController *usernameAlertViewController = [[UsernameAlertViewController alloc] init];
+
--- a/eventLogger.h	Fri Feb 01 11:16:56 2013 +0000
+++ b/eventLogger.h	Fri Feb 01 17:39:19 2013 +0000
@@ -11,8 +11,6 @@
 #ifndef __oscSenderExample__eventLogger__
 #define __oscSenderExample__eventLogger__
 
-#define EVENT_LOG_FILENAME "log.json"
-#define SERVER_URL "http://127.0.0.1:8080/testservice/"
 
 #include "ofMain.h"
 #include "ofxiPhone.h"
@@ -27,22 +25,38 @@
 #include "json.h"
 #include "testApp.h"
 
-#import "usernameAlertViewController.h"
 
 
+
+
+#define EVENT_LOG_FILENAME "log.json"
+#define SERVER_URL "http://127.0.0.1:8080/testservice/"
+#define UPLOAD_CHUNK_SIZE 500
+#define QUESTIONNAIRE_ENABLE_TIME 100000 // milliseconds
+#define APP_CREATION_TIME 381429000000   // milliseconds to the time i wrote this wee blighter 
+
+#define PROGRAM_VERSION 1.0 // IMPORTANT TOCHNAGE!
+
 // can add but don't change ordering - this will invalidate logs
-#define PROGRAM_VERSION 1.0
-enum leventType {SAVE_PRESET,
-    SAVE_DESET,
-    SCROLL,
-    ZOOM,
-    SCROLL_STOPPED,
-    ZOOM_STOPPED,
-    SNAPPED_TO_PRESET,
-    CHANGE_SLIDER,
-    SWAP_VIEW,
-    SET_MIN_ZOOM,
-    SET_MAX_ZOOM};
+enum leventType {SAVE_PRESET,  // 0
+    SAVE_DESET,           // 1
+    SCROLL,               // 2
+    ZOOM,                 // 3
+    SCROLL_STOPPED,        // 4
+    ZOOM_STOPPED,           // 5
+    SNAPPED_TO_PRESET,      // 6
+    CHANGE_SLIDER,          // 7
+    SWAP_VIEW,              // 8
+    SET_MIN_ZOOM,           // 9
+    SET_MAX_ZOOM,           // 10
+    RANDOMISE,             // 11
+    APP_STARTED,            // 12
+    APP_EXITED,             // 13
+    CONSENT_DENIED,         // 14
+    SEQ_LOCKED,             // 15
+    SYNTH_LOCKED,           // 16
+    PLAY_PRESSED,           // 17
+    PAUSE_PRESSED};         // 18
 
 //---------------------------------------------------------------------------
 
@@ -52,7 +66,7 @@
     leventType eventType;
     double val1; // x coord, scale if zoom
     double val2; // y coord, 0 if zoom
-    int sliderID;
+    int sliderID; // xtra int 
     long long eventTime;
     lEvent(leventType eType, double v1 = 0.0, double v2 = 0.0,int sID = 0){
         eventType = eType;
@@ -61,27 +75,29 @@
         sliderID = sID;
         
         double timemsd = [NSDate timeIntervalSinceReferenceDate];
-        eventTime = (unsigned long long)(timemsd*1000);
+        eventTime = (unsigned long long)(timemsd*1000) - APP_CREATION_TIME;
         
     }
+
     lEvent(const Json::Value &jevt){
     // constructor takes "jsonToEvent" readfile function role
-        eventType = (leventType)jevt["eventType"].asInt();
-        val1 = jevt["val1"].asFloat();
-        val2 = jevt["val2"].asFloat();
-        sliderID = jevt["sliderID"].asInt();
-        eventTime = jevt["eventTime"].asLargestInt();
+        eventType = (leventType)jevt["eType"].asInt();
+        val1 = jevt["v1"].asDouble();
+        val2 = jevt["v2"].asDouble();
+        sliderID = jevt["sID"].asInt();
+        eventTime = jevt["eTime"].asLargestInt();
         
         // TODO what happens if we try to read one that isn't there?
         
     }
     Json::Value eventToJson(){
         Json::Value jevt;
-        jevt["eventType"] = eventType;
-        jevt["val1"] = val1;
-        jevt["val2"] = val2;
-        jevt["sliderID"] = sliderID;
-        jevt["eventTime"] = eventTime;
+        jevt["eType"] = eventType;
+        // here: should give a certain number of sig figs? 
+        jevt["v1"] = val1;
+        jevt["v2"] = val2;
+        jevt["sID"] = sliderID;
+        jevt["eTime"] = eventTime;
         return jevt;
     }
 };
@@ -114,10 +130,12 @@
 
 class EventLogger{
 public:
+    int nextUploadNumber;
     bool loggingEnabled;
     bool serverConnectionOK;
+    bool consentGiven;
     unsigned int deviceID; // unique get something from hardware??
-    unsigned int totalInteractionTime, sessionTime, sessionStartTime;
+    unsigned int totalInteractionTime, savedInteractionTime, sessionTime, sessionStartTime;
     string userName; // not unique
     
     EventLogger();
--- a/eventLogger.mm	Fri Feb 01 11:16:56 2013 +0000
+++ b/eventLogger.mm	Fri Feb 01 17:39:19 2013 +0000
@@ -9,15 +9,13 @@
 //---------------------------------------------------------------------------
 #include "eventLogger.h"
 
-
 EventLogger eventLogger;
-extern UsernameAlertViewController *usernameAlertViewController;
 
 //---------------------------------------------------------------------------
 EventLogger::EventLogger(){
     //QuestionnaireViewController * questionnaireViewController;
 
-    
+    consentGiven = true; // unless told otherwise by introView
     loggingEnabled = true;
     serverConnectionOK = false;
     questionnaireCompleted = false;
@@ -27,7 +25,7 @@
     ofxiPhoneDeviceType iOSdeviceType = ofxiPhoneGetDeviceType();
     cout << "Device: " << iOSdeviceType << '\n';
     
-    nextUploadQty = 5000; // amount of data uploaded is always more than 5000 events
+    nextUploadQty = UPLOAD_CHUNK_SIZE; // amount of data uploaded is always more than UPLOAD_CHUNK_SIZE events
 }
 //---------------------------------------------------------------------------
 // draw() - show path of last N scroll events  - can be scrubbed along?
@@ -40,7 +38,7 @@
     
     testConnection();
 
-
+    logEvent(APP_STARTED);
 }
 //---------------------------------------------------------------------------
 void EventLogger::questionnaireAnswersObtained(vector<int> answers){
@@ -130,7 +128,6 @@
     stringstream fileText;
     string line;
     if(!theFile){
-        cout<<"no event log file - first APP open\n";
         
         firstEverAppOpen();
         
@@ -159,7 +156,8 @@
     // now put user deets into variables
     userName = root["userName"].asString();
     deviceID = root["deviceID"].asLargestInt();
-    totalInteractionTime = root["totalInteractionTime"].asLargestInt();
+    nextUploadNumber = root["uploadNumber"].asInt();
+    savedInteractionTime = root["savedInteractionTime"].asLargestInt();
     questionnaireCompleted = root["questionnaireCompleted"].asBool();
     questionnaireUploaded = root["questionnaireUploaded"].asBool();
     
@@ -186,14 +184,7 @@
         uploadEventLog();
     }
     // TODO if the total interaction time is greater than a certain amount && no questions answered - questionnaire time!
-    cout << "Total interaction time: " << totalInteractionTime << '\n';
-    
-    if(totalInteractionTime > 123){
-        //testApp->showQuestionnaire();
-        
-    }
-    // is there logged stuff that hasn't been uploaded yet? - handled automatically
-
+    cout << "Total interaction time: " << savedInteractionTime << '\n';
 
     
 }
@@ -203,16 +194,19 @@
 
 bool EventLogger::uploadEventLog(){
     // show indicator
-    cout << "^^^^^^^^  UPLOADING: " << theEvents.size() << " EVENTS ^^^^^^^^ .\n";
+    
+    cout << "^^^^^^^^  ATTEMPTING TO UPLOAD " << theEvents.size() << " EVENTS ^^^^^^^^ .\n";
     
     bool logUploaded = sendToServer("eventlog", logsToJson());
     if(!logUploaded){
         // try later
-        nextUploadQty += 5000;
+        nextUploadQty += UPLOAD_CHUNK_SIZE;
     }else{
         
         // if success - clear memory
         theEvents.clear();
+        cout << "UPLOAD SUCCESS\n";
+        nextUploadNumber++;
     }
     return logUploaded;
     
@@ -223,16 +217,15 @@
 //---------------------------------------------------------------------------
 
 void EventLogger::firstEverAppOpen(){
+    cout<<"no event log file - first APP open\n";
+    nextUploadNumber = 0;
     deviceID = ofGetSystemTimeMicros();
-    totalInteractionTime = 0;
+    savedInteractionTime = 0;
     questionnaireCompleted = false;
     questionnaireUploaded = false;
     
     ((testApp *)ofGetAppPtr())->showIntro();
-    
-    
-    //[usernameAlertViewController showUserNamePrompt];
-    // then we get userName via setUsername, called from button delegate
+    consentGiven = false;
     
 }
 //---------------------------------------------------------------------------
@@ -282,8 +275,12 @@
         case CHANGE_SLIDER:
             theEvents.push_back(lEvent(evtType,sliderVal , 0.0 , sliderID));
             break;
+        case SWAP_VIEW:
+            theEvents.push_back(lEvent(evtType,0.0 , 0.0 , sliderID)); // slider ID is which view
+            break;
         default:
-            // Code
+            // default is just an event type with no values
+            theEvents.push_back(lEvent(evtType));
             break;
     }
     if(theEvents.size() > nextUploadQty){
@@ -291,23 +288,35 @@
         uploadEventLog();
     }
     //sessionTime = (ofGetSystemTime() - sessionStartTime);
-    
-    
+    totalInteractionTime = savedInteractionTime + (ofGetSystemTime() - sessionStartTime);
+    if(totalInteractionTime > QUESTIONNAIRE_ENABLE_TIME){
+        TopButtonViewController *tbvc = ((testApp *)ofGetAppPtr())->topButtonViewController;
+        [tbvc enableQuestionButton];
+    }
 }
 
 //---------------------------------------------------------------------------
 
 void EventLogger::exitAndSave(){
-    totalInteractionTime = totalInteractionTime + (ofGetSystemTime() - sessionStartTime);
+    
+    if(!consentGiven){
+        logEvent(CONSENT_DENIED);
+        Json::Value jlogs = logsToJson();
+        // try to upload TODO (no - might hang and prevent exit???)
+        uploadEventLog();
+        return;
+    }
+    logEvent(APP_EXITED);
+    savedInteractionTime = savedInteractionTime + (ofGetSystemTime() - sessionStartTime);
     // save user details
     string fname = ofxiPhoneGetDocumentsDirectory() + EVENT_LOG_FILENAME;
 
-    Json::Value jlogs = logsToJson();
-    // try to upload
+    // try to upload TODO (no - might hang and prevent exit???)
     uploadEventLog();
     
     // write to file
-    
+    // json without the logs that were uploaded!
+    Json::Value jlogs = logsToJson();
     ofFile logFile(fname,ofFile::WriteOnly);
     logFile << jlogs;
     
@@ -323,8 +332,9 @@
     root["programVersion"] = PROGRAM_VERSION;
     root["userName"] = userName;
     root["deviceID"] = deviceID;
+    root["uploadNumber"] = nextUploadNumber;
     root["iOSdeviceType"] = iOSdeviceType;
-    root["totalInteractionTime"] = totalInteractionTime;
+    root["savedInteractionTime"] = savedInteractionTime;
     root["questionnaireCompleted"] = questionnaireCompleted;
     root["questionnaireUploaded"] = questionnaireUploaded;
     if(questionnaireCompleted && !questionnaireUploaded){
@@ -336,7 +346,7 @@
         root["events"][i] = (*eventIter).eventToJson();
         i++;
     }
-    
+    root["numEventsHere"] = i;
     return root;
 }
 
--- a/presetManager.mm	Fri Feb 01 11:16:56 2013 +0000
+++ b/presetManager.mm	Fri Feb 01 17:39:19 2013 +0000
@@ -104,8 +104,6 @@
  
     // use jsoncpp
     vector<Preset *>::iterator presetIter;
-
-    root["something"] = 23;
     
     int i = 0;
     for(presetIter = thePresets.begin(); presetIter < thePresets.end(); presetIter++){
@@ -166,6 +164,7 @@
         
     }
 }
+//---------------------------------------------------------------------------
 void PresetManager::showNameDialog(){
     if(!presetAlertShowing){ // this is to stop wierd infinite loop in ios5 (simulator)
         presetAlertShowing = true;
--- a/testApp.h	Fri Feb 01 11:16:56 2013 +0000
+++ b/testApp.h	Fri Feb 01 17:39:19 2013 +0000
@@ -22,6 +22,8 @@
 #import "BottomTabViewController.h"
 #import "IntroViewController.h"
 #import "TopButtonViewController.h"
+#import "SliderViewController.h"
+#import "usernameAlertViewController.h"
 
 #define HOST "169.254.1.1"
 #define PORT 12345
@@ -34,8 +36,8 @@
 public:
     
     interfaceType whichInterfaceShowing;
-    bool consentGiven;
     BottomTabViewController *bottomTabViewController;
+    UsernameAlertViewController *usernameAlertViewController;
     int prevTouchX;
     int prevTouchY;
     double prevDist;
@@ -66,7 +68,7 @@
     QuestionnaireViewController * questionnaireViewController;
     IntroViewController * introViewController;
     TopButtonViewController * topButtonViewController;
-    
+    SliderViewController * sliderViewController;
     //
     
     void setup();
@@ -118,6 +120,7 @@
     
     void sliderMoved(int which, float value);
     void setAllGUISliders(vector<int> vals);
+    void randomise();
     
     // zoom gui - the swap view button and save preset button
     void zoomGUIEvent(ofxUIEventArgs &e);
--- a/testApp.mm	Fri Feb 01 11:16:56 2013 +0000
+++ b/testApp.mm	Fri Feb 01 17:39:19 2013 +0000
@@ -1,6 +1,7 @@
 #include "testApp.h"
 
 #define SLIDER_GUI_WIDTH 256
+#define NUM_PARAMS 10
 extern Grid theGridView;
 extern PresetManager presetManager;
 extern EventLogger eventLogger;
@@ -89,17 +90,26 @@
     
     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);
     
+    usernameAlertViewController = [[UsernameAlertViewController alloc] init];
+    /*
+    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);
+    */
+
     // initialise user logging stuff
     presetManager.startupLoadAll();
     eventLogger.init();
     
-    
+    whichInterfaceShowing = BOTH;
     // GO
     paused = false;
     
@@ -108,17 +118,16 @@
 
 //--------------------------------------------------------------
 void testApp::exit(){
-    if(consentGiven){
-        presetManager.exitAndSaveAll();
-        eventLogger.exitAndSave();
-    }
-    
-    // else - don't save anything and app will boot up into consent/intro screen
+
+    presetManager.exitAndSaveAll();
+    eventLogger.exitAndSave();
+
     core.exit();
     
-    [introViewController release];
-    [topButtonViewController release];
-    [bottomTabViewController release];
+    // are these handled automatically?
+    //[introViewController release];
+    //[topButtonViewController release];
+    //[bottomTabViewController release];
     
     delete sliderGUI;
 
@@ -139,115 +148,21 @@
     
 }
 #pragma mark GUI
-
-//--------------------------------------------------------------
-/*
-void testApp::setupZoomGui(){
-    // width = height
-    int buttonHeight = 45;
-    zoomGUI = new ofxUICanvas(getWidth()-200,0,190,buttonHeight*7);
-    zoomGUI->setTheme(OFX_UI_THEME_METALGEAR );
-    
-    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() == "SAVE PRESET")
-    {
-        
-        if(((ofxUIButton *)e.widget)->getValue()==0){ // touchup
-            cout << "SAVE PRESET\n";
-            presetManager.showNameDialog();
-
-        }
-
-    }else if(e.widget->getName() == "ZOOM MIN")
-    {
-        if(((ofxUIButton *)e.widget)->getValue()==0){ // touchup
-        cout << "ZOOM MIN\n";
-            theGridView.setMinZoom();
-            eventLogger.logEvent(SET_MIN_ZOOM);
-        }
-    }else if(e.widget->getName() == "ZOOM MAX")
-    {
-        if(((ofxUIButton *)e.widget)->getValue()==0){ // touchup
-            cout << "ZOOM MAX\n";
-            theGridView.setMaxZoom();
-            eventLogger.logEvent(SET_MAX_ZOOM);
-
-        }
-    }else if(e.widget->getName() == "QUESTIONS")
-    {
-        if(((ofxUIButton *)e.widget)->getValue()==0){ // touchup
-            showQuestionnaire();
-        }
-    }else if(e.widget->getName() == "LOCK SEQUENCE (X)")
-    {
-        
-        cout << "LOCK SEQUENCE (X)\n";
-        // lock
-        theGridView.shiftCentreToSnapped();
-        xLocked = !xLocked;
-        
-    }else if(e.widget->getName() == "LOCK SYNTH (Y)")
-    {
-        
-        cout << "LOCK SYNTH (Y)\n";
-        // lock
-        theGridView.shiftCentreToSnapped();
-        if(((ofxUIButton *)e.widget)->getValue()){
-            yLocked = true;
-        }else{
-            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;
+    eventLogger.logEvent(SEQ_LOCKED);
+    
     
 }
 //--------------------------------------------------------------
 void testApp::lockSynthPressed(bool locked){
     theGridView.shiftCentreToSnapped();
     yLocked = locked;
+    eventLogger.logEvent(SYNTH_LOCKED);
     
 }
 //--------------------------------------------------------------
@@ -256,11 +171,13 @@
         core.pd.startMessage();
         core.pd.addFloat(0);
         core.pd.finishMessage("fromOF", "seqStartStop");
+        eventLogger.logEvent(PAUSE_PRESSED);
     }else { // play
         //stopSequencer();
         core.pd.startMessage();
         core.pd.addFloat(1);
         core.pd.finishMessage("fromOF", "seqStartStop");
+        eventLogger.logEvent(PLAY_PRESSED);
     }
 }
 //--------------------------------------------------------------
@@ -305,7 +222,7 @@
 //--------------------------------------------------------------
 void testApp::showIntro(){
     paused = true;
-    consentGiven = false;
+
     cout << "SHOW INTRO\n";
 
     introViewController	= [[IntroViewController alloc] initWithNibName:@"IntroViewController" bundle:nil];
@@ -322,8 +239,10 @@
 void testApp::introHidden(bool OK){
     if(OK){
         paused = false;
-        consentGiven = true;
+        eventLogger.consentGiven = true;
         whichInterfaceShowing = BOTH;
+        // show username prompt
+        [usernameAlertViewController showUserNamePrompt];
     }
     // no unOK
 }
@@ -338,6 +257,7 @@
             // set the slider values to stuff got from zoomer
             sliderVals = theGridView.getParams();
             setAllGUISliders(sliderVals);
+            
             break;
         case 1:
 
@@ -353,7 +273,7 @@
             whichInterfaceShowing = ZOOMER;
             break;
     }
-    
+    eventLogger.logEvent(SWAP_VIEW,TwoVector(),0.0, which);
 }
 //--------------------------------------------------------------
 //--------------------------------------------------------------
@@ -375,7 +295,7 @@
     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 = (ofxUISlider *)sliderGUI->addWidgetDown(new ofxUISlider(length,dim,0.0,127,64,sliderParamNames[i-1]));
         slider->setDrawPadding(true);
         if(i <= 5){
             slider->setColorFill(ofColor(0,0,255));
@@ -426,13 +346,29 @@
 //--------------------------------------------------------------
 void testApp::setAllGUISliders(vector<int> vals){
     // an update caused by zoomer view being moved
-    for(int i = 0; i<10;i++){
+    for(int i = 0; i<NUM_PARAMS;i++){
         sliders[i]->setValue(vals[i]);
         sliderVals[i] = vals[i];
     }
     
 }
 //--------------------------------------------------------------
+void testApp::randomise(){
+    // pick random settings for all params
+    for(int i=0; i < NUM_PARAMS ; i++){
+        sliderVals[i] = ofRandom(0, 127);
+        
+    }
+    
+    // send to grid, sliders and PD
+    theGridView.setParams(sliderVals);
+    setAllGUISliders(sliderVals);
+    sendParametersToPD();
+    
+    eventLogger.logEvent(RANDOMISE, theGridView.getCoord() ,0.0);
+    
+}
+//--------------------------------------------------------------
 void testApp::sendParametersToPD(){
     // frequencer stuff to get 16 steps
     vector<double> vals;
@@ -721,7 +657,17 @@
 //--------------------------------------------------------------
 void testApp::touchDoubleTap(ofTouchEventArgs &touch){
     // 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();
+        
+    }
+     */
+    
 }
 
 //--------------------------------------------------------------