diff ape.js @ 1561:bd06a7dc0418

Feature #1271 and #1272 implemented.
author Nicholas Jillings <nickjillings@users.noreply.github.com>
date Wed, 17 Jun 2015 16:37:32 +0100
parents c7c95761323d
children 6922eac3b945
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')
 		{