changeset 891:8c44e2d0d6c4

Feature #1271 and #1272 implemented.
author Nicholas Jillings <nicholas.jillings@eecs.qmul.ac.uk>
date Wed, 17 Jun 2015 16:37:32 +0100
parents 716cd1efe64c
children 6922eac3b945
files ape.js core.js example_eval/project.xml
diffstat 3 files changed, 130 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/ape.js	Wed Jun 17 15:53:57 2015 +0100
+++ b/ape.js	Wed Jun 17 16:37:32 2015 +0100
@@ -82,7 +82,7 @@
 	        return false;
 	    }
 	    return true;
-	}
+	};
 	
 	Interface.prototype.checkAllMoved = function() {
 		var audioObjs = audioEngineContext.audioObjects;
@@ -112,7 +112,7 @@
 	       }
 		}
 		return state;
-	}
+	};
 	
 	Interface.prototype.checkAllCommented = function() {
 		var audioObjs = audioEngineContext.audioObjects;
@@ -145,7 +145,7 @@
 			}
 		}
 		return state;
-	}
+	};
 	
 	// Bindings for audioObjects
 	
@@ -410,12 +410,15 @@
 		}
 	};
 	
-	this.exportXMLDOM = function() {
+	this.exportXMLDOM = function(audioObject) {
 		// Called by the audioObject holding this element. Must be present
 		var node = document.createElement('value');
 		node.textContent = convSliderPosToRate(this.trackSliderObj);
 		return node;
 	};
+	this.getValue = function() {
+		return convSliderPosToRate(this.trackSliderObj);
+	}
 }
 
 function dragEnd(ev) {
@@ -443,6 +446,65 @@
 {
 	var checks = specification.commonInterface.options;
 	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;
+					}
+				}
+			}
+		}
+	}
+	
 	for (var i=0; i<checks.length; i++) {
 		if (checks[i].type == 'check')
 		{
--- a/core.js	Wed Jun 17 15:53:57 2015 +0100
+++ b/core.js	Wed Jun 17 16:37:32 2015 +0100
@@ -892,8 +892,8 @@
 		var root = document.createElement('audioElement');
 		root.id = this.specification.id;
 		root.setAttribute('url',this.url);
-		root.appendChild(this.interfaceDOM.exportXMLDOM());
-		root.appendChild(this.commentDOM.exportXMLDOM());
+		root.appendChild(this.interfaceDOM.exportXMLDOM(this));
+		root.appendChild(this.commentDOM.exportXMLDOM(this));
 		root.appendChild(this.metric.exportXMLDOM());
 		return root;
 	};
@@ -1365,16 +1365,22 @@
 			else {this.anchor = false;}
 			
 			this.reference = xml.getAttribute('reference');
-			if (this.reference == 'true') {this.anchor = true;}
+			if (this.reference == 'true') {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('ERROR - Cannot have one audioElement be both the reference and anchor!');
 				console.log(this);
-				console.log('Neither will be enabled');
+				console.log('Neither reference nor anchor will be enabled on this fragment');
 				this.anchor = false;
 				this.reference = false;
 			}
+			if (this.anchor == true) {
+				this.marker = anchor;
+			}
+			if (this.reference == true) {
+				this.marker = reference;
+			}
 		};
 		
 		this.commentQuestionNode = function(xml) {
@@ -1430,36 +1436,44 @@
 		if (xml.getAttribute('elementComments') == "true") {this.elementComments = true;}
 		else {this.elementComments = false;}
 		
-		this.anchor = xml.getElementsByTagName('anchor');
-		if (this.anchor.length == 0) {
+		var anchor = xml.getElementsByTagName('anchor');
+		if (anchor.length == 0) {
 			// Find anchor in commonInterface;
 			for (var i=0; i<parent.commonInterface.options.length; i++) {
 				if(parent.commonInterface.options[i].type == 'anchor') {
-					this.anchor = parent.commonInterface.options[i].value;
+					anchor = parent.commonInterface.options[i].value;
 					break;
 				}
 			}
-			if (typeof(this.anchor) == "object") {
-				this.reference = null;
+			if (typeof(anchor) == "object") {
+				anchor = null;
 			}
 		} else {
-			this.anchor = this.anchor[0].textContent;
+			anchor = anchor[0].textContent;
 		}
 		
-		this.reference = xml.getElementsByTagName('reference');
-		if (this.reference.length == 0) {
+		var reference = xml.getElementsByTagName('anchor');
+		if (reference.length == 0) {
 			// Find anchor in commonInterface;
 			for (var i=0; i<parent.commonInterface.options.length; i++) {
 				if(parent.commonInterface.options[i].type == 'reference') {
-					this.reference = parent.commonInterface.options[i].value;
+					reference = parent.commonInterface.options[i].value;
 					break;
 				}
 			}
-			if (typeof(this.reference) == "object") {
-				this.reference = null;
+			if (typeof(reference) == "object") {
+				reference = null;
 			}
 		} else {
-			this.reference = this.reference[0].textContent;
+			reference = reference[0].textContent;
+		}
+		
+		if (typeof(anchor) == 'number') {
+			if (anchor > 1 && anchor < 100) {anchor /= 100.0;}
+		}
+		
+		if (typeof(reference) == 'number') {
+			if (reference > 1 && reference < 100) {reference /= 100.0;}
 		}
 		
 		this.preTest = new parent.prepostNode('pretest',xml.getElementsByTagName('PreTest'));
@@ -1484,6 +1498,34 @@
 			this.audioElements.push(new this.audioElementNode(this,audioElementsDOM[i]));
 		}
 		
+		// Check only one anchor and one reference per audioNode
+		var anchor = [];
+		var reference = [];
+		for (var i=0; i<this.audioElements.length; i++)
+		{
+			if (this.audioElements[i].anchor == true) {anchor.push(i);}
+			if (this.audioElements[i].reference == true) {reference.push(i);}
+		}
+		
+		if (anchor.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');
+			for (var i=0; i<anchor.length; i++)
+			{
+				this.audioElements[anchor[i]].anchor = false;
+				this.audioElements[anchor[i]].value = undefined;
+			}
+		}
+		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');
+			for (var i=0; i<reference.length; i++)
+			{
+				this.audioElements[reference[i]].reference = false;
+				this.audioElements[reference[i]].value = undefined;
+			}
+		}
+		
 		this.commentQuestions = [];
 		var commentQuestionsDOM = xml.getElementsByTagName('CommentQuestion');
 		for (var i=0; i<commentQuestionsDOM.length; i++) {
--- a/example_eval/project.xml	Wed Jun 17 15:53:57 2015 +0100
+++ b/example_eval/project.xml	Wed Jun 17 16:37:32 2015 +0100
@@ -35,11 +35,12 @@
 			<metricEnable>elementListenTracker</metricEnable>
 		</Metric>
 		<interface>
-			<check name="fragmentPlayed"/>
+			<!--<check name="fragmentPlayed"/>
 			<check name="fragmentFullPlayback"/>
 			<check name="fragmentMoved"/>
-			<check name="fragmentComments"/>
+			<check name="fragmentComments"/>-->
 			<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'>
@@ -93,8 +94,8 @@
             <scale position="75">75</scale>
             <commentBoxPrefix>Comment on fragment</commentBoxPrefix>
         </interface>
-        <audioElements url="0.wav" id="0"/>
-        <audioElements url="1.wav" id="1"/>
+        <audioElements url="0.wav" id="0" reference="true"/>
+        <audioElements url="1.wav" id="1" anchor="true"/>
         <audioElements url="2.wav" id="2"/>
         <audioElements url="3.wav" id="3"/>
         <audioElements url="4.wav" id="4"/>