changeset 1407:303b9d9889d7

Moved common test options into core.JS
author Nicholas Jillings <nickjillings@users.noreply.github.com>
date Mon, 07 Dec 2015 11:18:11 +0000
parents a2a0a3a6f36d
children 8e19255b85b3
files ape.js core.js mushra.js
diffstat 3 files changed, 22 insertions(+), 42 deletions(-) [+]
line wrap: on
line diff
--- a/ape.js	Mon Dec 07 09:47:26 2015 +0000
+++ b/ape.js	Mon Dec 07 11:18:11 2015 +0000
@@ -315,10 +315,7 @@
 
 function loadTest(audioHolderObject)
 {
-	
-	// Reset audioEngineContext.Metric globals for new test
-	audioEngineContext.newTestPage();
-	
+
 	var id = audioHolderObject.id;
 	
 	var feedbackHolder = document.getElementById('feedbackHolder');
@@ -385,32 +382,15 @@
 			commentBoxPrefix = interfaceObj.commentBoxPrefix;
 		}
 	}
-
-	/// CHECK FOR SAMPLE RATE COMPATIBILITY
-	if (audioHolderObject.sampleRate != undefined) {
-		if (Number(audioHolderObject.sampleRate) != audioContext.sampleRate) {
-			var errStr = 'Sample rates do not match! Requested '+Number(audioHolderObject.sampleRate)+', got '+audioContext.sampleRate+'. Please set the sample rate to match before completing this test.';
-			alert(errStr);
-			return;
-		}
-	}
 	
 	var commentShow = audioHolderObject.elementComments;
 	
 	var loopPlayback = audioHolderObject.loop;
 
-	audioEngineContext.loopPlayback = loopPlayback;
-	// Create AudioEngine bindings for playback
-	
 	currentTestHolder = document.createElement('audioHolder');
 	currentTestHolder.id = audioHolderObject.id;
 	currentTestHolder.repeatCount = audioHolderObject.repeatCount;
 	
-	// Delete any previous audioObjects associated with the audioEngine
-	audioEngineContext.audioObjects = [];
-	interfaceContext.deleteCommentBoxes();
-	interfaceContext.deleteCommentQuestions();
-	
 	// Find all the audioElements from the audioHolder
 	$(audioHolderObject.audioElements).each(function(index,element){
 		// Find URL of track
--- a/core.js	Mon Dec 07 09:47:26 2015 +0000
+++ b/core.js	Mon Dec 07 11:18:11 2015 +0000
@@ -458,7 +458,7 @@
 				this.currentStateMap = this.stateMap[this.stateIndex];
 				if (this.currentStateMap.type == "audioHolder") {
 					console.log('Loading test page');
-					loadTest(this.currentStateMap);
+					interfaceContext.newPage(this.currentStateMap);
 					this.initialiseInnerState(this.currentStateMap);
 				} else if (this.currentStateMap.type == "pretest" || this.currentStateMap.type == "posttest") {
 					if (this.currentStateMap.options.length >= 1) {
@@ -2000,6 +2000,26 @@
 	this.specification = specificationObject;
 	this.insertPoint = document.getElementById("topLevelBody");
 	
+	this.newPage = function(audioHolderObject)
+	{
+		audioEngineContext.newTestPage();
+		/// CHECK FOR SAMPLE RATE COMPATIBILITY
+		if (audioHolderObject.sampleRate != undefined) {
+			if (Number(audioHolderObject.sampleRate) != audioContext.sampleRate) {
+				var errStr = 'Sample rates do not match! Requested '+Number(audioHolderObject.sampleRate)+', got '+audioContext.sampleRate+'. Please set the sample rate to match before completing this test.';
+				alert(errStr);
+				return;
+			}
+		}
+		
+		audioEngineContext.loopPlayback = audioHolderObject.loop;
+		// Delete any previous audioObjects associated with the audioEngine
+		audioEngineContext.audioObjects = [];
+		interfaceContext.deleteCommentBoxes();
+		interfaceContext.deleteCommentQuestions();
+		loadTest(audioHolderObject);
+	};
+	
 	// Bounded by interface!!
 	// Interface object MUST have an exportXMLDOM method which returns the various DOM levels
 	// For example, APE returns  the slider position normalised in a <value> tag.
--- a/mushra.js	Mon Dec 07 09:47:26 2015 +0000
+++ b/mushra.js	Mon Dec 07 11:18:11 2015 +0000
@@ -95,14 +95,6 @@
 
 function loadTest(audioHolderObject)
 {
-	// Reset audioEngineContext.Metric globals for new test
-	audioEngineContext.newTestPage();
-	
-	// Delete any previous audioObjects associated with the audioEngine
-	audioEngineContext.audioObjects = [];
-	interfaceContext.deleteCommentBoxes();
-	interfaceContext.deleteCommentQuestions();
-	
 	var id = audioHolderObject.id;
 	
 	var feedbackHolder = document.getElementById('feedbackHolder');
@@ -116,20 +108,8 @@
 	if (interfaceObj.commentBoxPrefix != undefined) {
 		commentBoxPrefix = interfaceObj.commentBoxPrefix;
 	}
-	
-	/// CHECK FOR SAMPLE RATE COMPATIBILITY
-	if (audioHolderObject.sampleRate != undefined) {
-		if (Number(audioHolderObject.sampleRate) != audioContext.sampleRate) {
-			var errStr = 'Sample rates do not match! Requested '+Number(audioHolderObject.sampleRate)+', got '+audioContext.sampleRate+'. Please set the sample rate to match before completing this test.';
-			alert(errStr);
-			return;
-		}
-	}
-	
 	var loopPlayback = audioHolderObject.loop;
 	
-	audioEngineContext.loopPlayback = loopPlayback;
-	
 	currentTestHolder = document.createElement('audioHolder');
 	currentTestHolder.id = audioHolderObject.id;
 	currentTestHolder.repeatCount = audioHolderObject.repeatCount;