changeset 235:a9a86478a038 Dev_main

Updated #1272 and #1271 preparing for #1270
author Nicholas Jillings <nicholas.jillings@eecs.qmul.ac.uk>
date Sat, 20 Jun 2015 14:57:14 +0100
parents c48ad18bbda3
children f42e3d4a565f
files ape.js core.js example_eval/project.xml
diffstat 3 files changed, 63 insertions(+), 85 deletions(-) [+]
line wrap: on
line diff
--- a/ape.js	Sat Jun 20 11:16:30 2015 +0100
+++ b/ape.js	Sat Jun 20 14:57:14 2015 +0100
@@ -355,14 +355,6 @@
 	currentTestHolder.id = audioHolderObject.id;
 	currentTestHolder.repeatCount = audioHolderObject.repeatCount;
 	
-	var randomise = audioHolderObject.randomiseOrder;
-	
-	var audioElements = audioHolderObject.audioElements;
-	currentTrackOrder = [];
-	if (randomise) {
-		audioHolderObject.audioElements = randomiseOrder(audioHolderObject.audioElements);
-	}
-	
 	// Delete any previous audioObjects associated with the audioEngine
 	audioEngineContext.audioObjects = [];
 	interfaceContext.deleteCommentBoxes();
@@ -480,62 +472,8 @@
 	var canContinue = true;
 	
 	// Check that the anchor and reference objects are correctly placed
-	var audioObjs = audioEngineContext.audioObjects;
-	var audioHolder = testState.stateMap[testState.stateIndex];
-	var anchorId = null;
-	var referenceId = null;
-	for (var i=0; i<audioObjs.length; i++) {
-		if (audioObjs[i].specification.anchor == true && anchorId == null) {anchorId = i;}
-		if (audioObjs[i].specification.reference == true && referenceId == null) {referenceId = i;}
-	}
-	if (anchorId != null) {
-		if (audioObjs[anchorId].specification.marker != null) {
-			if (audioObjs[anchorId].interfaceDOM.getValue() > audioObjs[anchorId].specification.marker)
-			{
-				// Anchor is not set below
-				console.log('Anchor node not below marker value');
-				alert('Please keep listening');
-				return;
-			}
-		} else {
-			// No marker value given, ensure it is the minimum value
-			var anchorVal = audioObjs[anchorId].interfaceDOM.getValue();
-			for (var i=0; i<audioObjs.length; i++) {
-				if (i != anchorId) {
-					if (anchorVal > audioObjs[i].interfaceDOM.getValue()) {
-						// Anchor not the minimum
-						console.log('No marker set, anchor node not the minimum');
-						alert('Please keep listening');
-						return;
-					}
-				}
-			}
-		}
-	}
-	if (referenceId != null) {
-		if (audioObjs[referenceId].specification.marker != null) {
-			if (audioObjs[referenceId].interfaceDOM.getValue() < audioObjs[referenceId].specification.marker)
-			{
-				// Anchor is not set below
-				console.log('Reference node not above marker value');
-				alert('Please keep listening');
-				return;
-			}
-		} else {
-			// No marker value given, ensure it is the minimum value
-			var referenceVal = audioObjs[referenceId].interfaceDOM.getValue();
-			for (var i=0; i<audioObjs.length; i++) {
-				if (i != referenceId) {
-					if (referenceVal > audioObjs[i].interfaceDOM.getValue()) {
-						// Anchor not the minimum
-						console.log('No marker set, reference node not the maximum');
-						alert('Please keep listening');
-						return;
-					}
-				}
-			}
-		}
-	}
+	if (interfaceContext.checkHiddenAnchor() == false) {return;}
+	if (interfaceContext.checkHiddenReference() == false) {return;}
 	
 	for (var i=0; i<checks.length; i++) {
 		if (checks[i].type == 'check')
--- a/core.js	Sat Jun 20 11:16:30 2015 +0100
+++ b/core.js	Sat Jun 20 14:57:14 2015 +0100
@@ -1382,27 +1382,27 @@
 			this.url = xml.getAttribute('url');
 			this.id = xml.id;
 			this.parent = parent;
-			this.anchor = xml.getAttribute('anchor');
-			if (this.anchor == 'true') {this.anchor = true;}
+			this.type = xml.getAttribute('type');
+			if (this.type == null) {this.type = "normal";}
+			if (this.type == 'anchor') {this.anchor = true;}
 			else {this.anchor = false;}
-			
-			this.reference = xml.getAttribute('reference');
-			if (this.reference == 'true') {this.reference = true;}
+			if (this.type == 'reference') {this.reference = true;}
 			else {this.reference = false;}
 			
-			if (this.anchor == true && this.reference == true) {
-				console.log('ERROR - Cannot have one audioElement be both the reference and anchor!');
-				console.log(this);
-				console.log('Neither reference nor anchor will be enabled on this fragment');
-				this.anchor = false;
-				this.reference = false;
-			}
-			if (this.anchor == true) {
+			this.marker = xml.getAttribute('marker');
+			if (this.marker == null) {this.marker = undefined;}
+			
+			if (this.anchor == true && this.marker == undefined) {
 				this.marker = anchor;
 			}
-			if (this.reference == true) {
+			else if (this.reference == true && this.marker == undefined) {
 				this.marker = reference;
 			}
+			
+			if (this.marker != undefined) {
+				this.marker = Number(this.marker);
+				if (this.marker > 1) {this.marker /= 100;}
+			}
 		};
 		
 		this.commentQuestionNode = function(xml) {
@@ -1520,9 +1520,15 @@
 			this.audioElements.push(new this.audioElementNode(this,audioElementsDOM[i]));
 		}
 		
+		if (this.randomiseOrder) {
+			this.audioElements = randomiseOrder(this.audioElements);
+		}
+		
 		// Check only one anchor and one reference per audioNode
 		var anchor = [];
 		var reference = [];
+		this.anchorId = null;
+		this.referenceId = null;
 		for (var i=0; i<this.audioElements.length; i++)
 		{
 			if (this.audioElements[i].anchor == true) {anchor.push(i);}
@@ -1537,7 +1543,7 @@
 				this.audioElements[anchor[i]].anchor = false;
 				this.audioElements[anchor[i]].value = undefined;
 			}
-		}
+		} else {this.anchorId = anchor[0];}
 		if (reference.length > 1) {
 			console.log('Error - cannot have more than one anchor!');
 			console.log('Each anchor node will be a normal mode to continue the test');
@@ -1546,7 +1552,7 @@
 				this.audioElements[reference[i]].reference = false;
 				this.audioElements[reference[i]].value = undefined;
 			}
-		}
+		} else {this.referenceId = reference[0];}
 		
 		this.commentQuestions = [];
 		var commentQuestionsDOM = xml.getElementsByTagName('CommentQuestion');
@@ -1905,5 +1911,41 @@
 			this.interval = undefined;
 		};
 	};
+	
+	// Global Checkers
+	// These functions will help enforce the checkers
+	this.checkHiddenAnchor = function()
+	{
+		var audioHolder = testState.currentStateMap[testState.currentIndex];
+		if (audioHolder.anchorId != null)
+		{
+			var audioObject = audioEngineContext.audioObjects[audioHolder.anchorId];
+			if (audioObject.interfaceDOM.getValue() > audioObject.specification.marker)
+			{
+				// Anchor is not set below
+				console.log('Anchor node not below marker value');
+				alert('Please keep listening');
+				return false;
+			}
+		}
+		return true;
+	};
+	
+	this.checkHiddenReference = function()
+	{
+		var audioHolder = testState.currentStateMap[testState.currentIndex];
+		if (audioHolder.referenceId != null)
+		{
+			var audioObject = audioEngineContext.audioObjects[audioHolder.referenceId];
+			if (audioObject.interfaceDOM.getValue() < audioObject.specification.marker)
+			{
+				// Anchor is not set below
+				console.log('Reference node not above marker value');
+				alert('Please keep listening');
+				return false;
+			}
+		}
+		return true;
+	};
 }
 
--- a/example_eval/project.xml	Sat Jun 20 11:16:30 2015 +0100
+++ b/example_eval/project.xml	Sat Jun 20 14:57:14 2015 +0100
@@ -40,8 +40,6 @@
 			<check name="fragmentMoved"/>
 			<check name="fragmentComments"/>-->
 			<check name="scalerange" min="25" max="75"/>
-			<anchor>20</anchor>
-			<reference>80</reference>
 		</interface>
 	</setup>
 	<audioHolder id='test-0' hostURL="example_eval/" sampleRate="44100" randomiseOrder='true' repeatCount='0' loop='true' elementComments='true'>
@@ -53,7 +51,7 @@
 			<scale position="20">20</scale>
 			<commentBoxPrefix>Comment on fragment</commentBoxPrefix>
 		</interface>
-		<audioElements url="0.wav" id="0" anchor='true'/>
+		<audioElements url="0.wav" id="0" type="anchor" marker="20"/>
 		<audioElements url="1.wav" id="1"/>
 		<audioElements url="2.wav" id="2"/>
 		<audioElements url="3.wav" id="3"/>
@@ -96,8 +94,8 @@
             <scalerange min="25" max="75"/>
             <commentBoxPrefix>Comment on fragment</commentBoxPrefix>
         </interface>
-        <audioElements url="0.wav" id="0" reference="true"/>
-        <audioElements url="1.wav" id="1" anchor="true"/>
+        <audioElements url="0.wav" id="0" type="reference" marker="80"/>
+        <audioElements url="1.wav" id="1" type="anchor" marker="20"/>
         <audioElements url="2.wav" id="2"/>
         <audioElements url="3.wav" id="3"/>
         <audioElements url="4.wav" id="4"/>