nicholas@755: /** nicholas@755: * core.js nicholas@755: * nicholas@755: * Main script to run, calls all other core functions and manages loading/store to backend. nicholas@755: * Also contains all global variables. nicholas@755: */ nicholas@755: nicholas@755: /* create the web audio API context and store in audioContext*/ nicholas@755: var audioContext; // Hold the browser web audio API nicholas@755: var projectXML; // Hold the parsed setup XML nicholas@755: var specification; nicholas@755: var interfaceContext; nicholas@755: var popup; // Hold the interfacePopup object nicholas@755: var testState; nicholas@755: var currentTrackOrder = []; // Hold the current XML tracks in their (randomised) order nicholas@755: var audioEngineContext; // The custome AudioEngine object nicholas@755: var projectReturn; // Hold the URL for the return nicholas@755: nicholas@755: nicholas@755: // Add a prototype to the bufferSourceNode to reference to the audioObject holding it nicholas@755: AudioBufferSourceNode.prototype.owner = undefined; nicholas@755: // Add a prototype to the bufferNode to hold the desired LINEAR gain nicholas@755: AudioBuffer.prototype.gain = undefined; nicholas@755: // Add a prototype to the bufferNode to hold the computed LUFS loudness nicholas@755: AudioBuffer.prototype.lufs = undefined; nicholas@755: nicholas@755: window.onload = function() { nicholas@755: // Function called once the browser has loaded all files. nicholas@755: // This should perform any initial commands such as structure / loading documents nicholas@755: nicholas@755: // Create a web audio API context nicholas@755: // Fixed for cross-browser support nicholas@755: var AudioContext = window.AudioContext || window.webkitAudioContext; nicholas@755: audioContext = new AudioContext; nicholas@755: nicholas@755: // Create test state nicholas@755: testState = new stateMachine(); nicholas@755: nicholas@755: // Create the popup interface object nicholas@755: popup = new interfacePopup(); nicholas@755: nicholas@755: // Create the specification object nicholas@755: specification = new Specification(); nicholas@755: nicholas@755: // Create the interface object nicholas@755: interfaceContext = new Interface(specification); nicholas@755: // Define window callbacks for interface nicholas@755: window.onresize = function(event){interfaceContext.resizeWindow(event);}; nicholas@755: }; nicholas@755: nicholas@755: function loadProjectSpec(url) { nicholas@755: // Load the project document from the given URL, decode the XML and instruct audioEngine to get audio data nicholas@755: // If url is null, request client to upload project XML document nicholas@755: var r = new XMLHttpRequest(); nicholas@755: r.open('GET',url,true); nicholas@755: r.onload = function() { nicholas@755: loadProjectSpecCallback(r.response); nicholas@755: }; nicholas@755: r.send(); nicholas@755: }; nicholas@755: nicholas@755: function loadProjectSpecCallback(response) { nicholas@755: // Function called after asynchronous download of XML project specification nicholas@755: //var decode = $.parseXML(response); nicholas@755: //projectXML = $(decode); nicholas@755: nicholas@755: var parse = new DOMParser(); nicholas@755: projectXML = parse.parseFromString(response,'text/xml'); nicholas@755: nicholas@755: // Build the specification nicholas@755: specification.decode(projectXML); nicholas@755: nicholas@755: // Detect the interface to use and load the relevant javascripts. nicholas@755: var interfaceJS = document.createElement('script'); nicholas@755: interfaceJS.setAttribute("type","text/javascript"); nicholas@755: if (specification.interfaceType == 'APE') { nicholas@755: interfaceJS.setAttribute("src","ape.js"); nicholas@755: nicholas@755: // APE comes with a css file nicholas@755: var css = document.createElement('link'); nicholas@755: css.rel = 'stylesheet'; nicholas@755: css.type = 'text/css'; nicholas@755: css.href = 'ape.css'; nicholas@755: nicholas@755: document.getElementsByTagName("head")[0].appendChild(css); nicholas@755: } else if (specification.interfaceType == "MUSHRA") nicholas@755: { nicholas@755: interfaceJS.setAttribute("src","mushra.js"); nicholas@755: nicholas@755: // MUSHRA comes with a css file nicholas@755: var css = document.createElement('link'); nicholas@755: css.rel = 'stylesheet'; nicholas@755: css.type = 'text/css'; nicholas@755: css.href = 'mushra.css'; nicholas@755: nicholas@755: document.getElementsByTagName("head")[0].appendChild(css); nicholas@755: } nicholas@755: document.getElementsByTagName("head")[0].appendChild(interfaceJS); nicholas@755: nicholas@755: // Create the audio engine object nicholas@755: audioEngineContext = new AudioEngine(specification); nicholas@755: nicholas@755: testState.stateMap.push(specification.preTest); nicholas@755: nicholas@755: $(specification.audioHolders).each(function(index,elem){ nicholas@755: testState.stateMap.push(elem); nicholas@755: $(elem.audioElements).each(function(i,audioElem){ nicholas@755: var URL = audioElem.parent.hostURL + audioElem.url; nicholas@755: var buffer = null; nicholas@755: for (var i=0; i 0) nicholas@755: this.buttonPrevious.style.visibility = 'visible'; nicholas@755: else nicholas@755: this.buttonPrevious.style.visibility = 'hidden'; nicholas@755: }; nicholas@755: nicholas@755: this.initState = function(node) { nicholas@755: //Call this with your preTest and postTest nodes when needed to nicholas@755: // initialise the popup procedure. nicholas@755: this.popupOptions = node.options; nicholas@755: if (this.popupOptions.length > 0) { nicholas@755: if (node.type == 'pretest') { nicholas@755: this.responses = document.createElement('PreTest'); nicholas@755: } else if (node.type == 'posttest') { nicholas@755: this.responses = document.createElement('PostTest'); nicholas@755: } else { nicholas@755: console.log ('WARNING - popup node neither pre or post!'); nicholas@755: this.responses = document.createElement('responses'); nicholas@755: } nicholas@755: this.currentIndex = 0; nicholas@755: this.showPopup(); nicholas@755: this.postNode(); nicholas@755: } else { nicholas@755: advanceState(); nicholas@755: } nicholas@755: }; nicholas@755: nicholas@755: this.proceedClicked = function() { nicholas@755: // Each time the popup button is clicked! nicholas@755: var node = this.popupOptions[this.currentIndex]; nicholas@755: if (node.type == 'question') { nicholas@755: // Must extract the question data nicholas@755: var textArea = $(popup.popupContent).find('textarea')[0]; nicholas@755: if (node.mandatory == true && textArea.value.length == 0) { nicholas@755: alert('This question is mandatory'); nicholas@755: return; nicholas@755: } else { nicholas@755: // Save the text content nicholas@755: var hold = document.createElement('comment'); nicholas@755: hold.id = node.id; nicholas@755: hold.innerHTML = textArea.value; nicholas@755: console.log("Question: "+ node.question); nicholas@755: console.log("Question Response: "+ textArea.value); nicholas@755: this.responses.appendChild(hold); nicholas@755: } nicholas@755: } else if (node.type == 'checkbox') { nicholas@755: // Must extract checkbox data nicholas@755: var optHold = this.popupResponse; nicholas@755: var hold = document.createElement('checkbox'); nicholas@755: console.log("Checkbox: "+ node.statement); nicholas@755: hold.id = node.id; nicholas@755: for (var i=0; i node.max && node.max != null) { nicholas@755: alert('Number is above the maximum value of '+node.max); nicholas@755: return; nicholas@755: } nicholas@755: var hold = document.createElement('number'); nicholas@755: hold.id = node.id; nicholas@755: hold.textContent = input.value; nicholas@755: this.responses.appendChild(hold); nicholas@755: } nicholas@755: this.currentIndex++; nicholas@755: if (this.currentIndex < this.popupOptions.length) { nicholas@755: this.postNode(); nicholas@755: } else { nicholas@755: // Reached the end of the popupOptions nicholas@755: this.hidePopup(); nicholas@755: if (this.responses.nodeName == testState.stateResults[testState.stateIndex].nodeName) { nicholas@755: testState.stateResults[testState.stateIndex] = this.responses; nicholas@755: } else { nicholas@755: testState.stateResults[testState.stateIndex].appendChild(this.responses); nicholas@755: } nicholas@755: advanceState(); nicholas@755: } nicholas@755: }; nicholas@755: nicholas@755: this.previousClick = function() { nicholas@755: // Triggered when the 'Back' button is clicked in the survey nicholas@755: if (this.currentIndex > 0) { nicholas@755: this.currentIndex--; nicholas@755: var node = this.popupOptions[this.currentIndex]; nicholas@755: if (node.type != 'statement') { nicholas@755: var prevResp = this.responses.childNodes[this.responses.childElementCount-1]; nicholas@755: this.responses.removeChild(prevResp); nicholas@755: } nicholas@755: this.postNode(); nicholas@755: if (node.type == 'question') { nicholas@755: this.popupContent.getElementsByTagName('textarea')[0].value = prevResp.textContent; nicholas@755: } else if (node.type == 'checkbox') { nicholas@755: var options = this.popupContent.getElementsByTagName('input'); nicholas@755: var savedOptions = prevResp.getElementsByTagName('option'); nicholas@755: for (var i=0; i 0) { nicholas@755: if(this.stateIndex != null) { nicholas@755: console.log('NOTE - State already initialise'); nicholas@755: } nicholas@755: this.stateIndex = -1; nicholas@755: var that = this; nicholas@755: var aH_pId = 0; nicholas@755: for (var id=0; id= this.stateMap.length) { nicholas@755: console.log('Test Completed'); nicholas@755: createProjectSave(specification.projectReturn); nicholas@755: } else { nicholas@755: this.currentStateMap = this.stateMap[this.stateIndex]; nicholas@755: if (this.currentStateMap.type == "audioHolder") { nicholas@755: console.log('Loading test page'); nicholas@755: interfaceContext.newPage(this.currentStateMap); nicholas@755: this.initialiseInnerState(this.currentStateMap); nicholas@755: } else if (this.currentStateMap.type == "pretest" || this.currentStateMap.type == "posttest") { nicholas@755: if (this.currentStateMap.options.length >= 1) { nicholas@755: popup.initState(this.currentStateMap); nicholas@755: } else { nicholas@755: this.advanceState(); nicholas@755: } nicholas@755: } else { nicholas@755: this.advanceState(); nicholas@755: } nicholas@755: } nicholas@755: } else { nicholas@755: this.advanceInnerState(); nicholas@755: } nicholas@755: }; nicholas@755: nicholas@755: this.testPageCompleted = function(store, testXML, testId) { nicholas@755: // Function called each time a test page has been completed nicholas@755: var metric = document.createElement('metric'); nicholas@755: if (audioEngineContext.metric.enableTestTimer) nicholas@755: { nicholas@755: var testTime = document.createElement('metricResult'); nicholas@755: testTime.id = 'testTime'; nicholas@755: testTime.textContent = audioEngineContext.timer.testDuration; nicholas@755: metric.appendChild(testTime); nicholas@755: } nicholas@755: store.appendChild(metric); nicholas@755: var audioObjects = audioEngineContext.audioObjects; nicholas@755: for (var i=0; i= this.currentStateMap.length) { nicholas@755: this.currentIndex = null; nicholas@755: this.currentStateMap = this.stateMap[this.stateIndex]; nicholas@755: this.advanceState(); nicholas@755: } else { nicholas@755: if (this.currentStateMap[this.currentIndex].type == "audioHolder") { nicholas@755: console.log("Loading test page"+this.currentTestId); nicholas@755: } else if (this.currentStateMap[this.currentIndex].type == "pretest") { nicholas@755: popup.initState(this.currentStateMap[this.currentIndex]); nicholas@755: } else if (this.currentStateMap[this.currentIndex].type == "posttest") { nicholas@755: popup.initState(this.currentStateMap[this.currentIndex]); nicholas@755: } else { nicholas@755: this.advanceInnerState(); nicholas@755: } nicholas@755: } nicholas@755: }; nicholas@755: nicholas@755: this.previousState = function(){}; nicholas@755: } nicholas@755: nicholas@755: function AudioEngine(specification) { nicholas@755: nicholas@755: // Create two output paths, the main outputGain and fooGain. nicholas@755: // Output gain is default to 1 and any items for playback route here nicholas@755: // Foo gain is used for analysis to ensure paths get processed, but are not heard nicholas@755: // because web audio will optimise and any route which does not go to the destination gets ignored. nicholas@755: this.outputGain = audioContext.createGain(); nicholas@755: this.fooGain = audioContext.createGain(); nicholas@755: this.fooGain.gain = 0; nicholas@755: nicholas@755: // Use this to detect playback state: 0 - stopped, 1 - playing nicholas@755: this.status = 0; nicholas@755: nicholas@755: // Connect both gains to output nicholas@755: this.outputGain.connect(audioContext.destination); nicholas@755: this.fooGain.connect(audioContext.destination); nicholas@755: nicholas@755: // Create the timer Object nicholas@755: this.timer = new timer(); nicholas@755: // Create session metrics nicholas@755: this.metric = new sessionMetrics(this,specification); nicholas@755: nicholas@755: this.loopPlayback = false; nicholas@755: nicholas@755: // Create store for new audioObjects nicholas@755: this.audioObjects = []; nicholas@755: nicholas@755: this.buffers = []; nicholas@755: this.bufferObj = function() nicholas@755: { nicholas@755: this.url = null; nicholas@755: this.buffer = null; nicholas@755: this.xmlRequest = new XMLHttpRequest(); nicholas@759: this.xmlRequest.parent = this; nicholas@755: this.users = []; nicholas@755: this.getMedia = function(url) { nicholas@755: this.url = url; nicholas@755: this.xmlRequest.open('GET',this.url,true); nicholas@755: this.xmlRequest.responseType = 'arraybuffer'; nicholas@755: nicholas@755: var bufferObj = this; nicholas@755: nicholas@755: // Create callback to decode the data asynchronously nicholas@755: this.xmlRequest.onloadend = function() { nicholas@755: audioContext.decodeAudioData(bufferObj.xmlRequest.response, function(decodedData) { nicholas@755: bufferObj.buffer = decodedData; nicholas@755: for (var i=0; i nicholas@755: // DD/MM/YY nicholas@755: // nicholas@755: // nicholas@755: var dateTime = new Date(); nicholas@755: var year = document.createAttribute('year'); nicholas@755: var month = document.createAttribute('month'); nicholas@755: var day = document.createAttribute('day'); nicholas@755: var hour = document.createAttribute('hour'); nicholas@755: var minute = document.createAttribute('minute'); nicholas@755: var secs = document.createAttribute('secs'); nicholas@755: nicholas@755: year.nodeValue = dateTime.getFullYear(); nicholas@755: month.nodeValue = dateTime.getMonth()+1; nicholas@755: day.nodeValue = dateTime.getDate(); nicholas@755: hour.nodeValue = dateTime.getHours(); nicholas@755: minute.nodeValue = dateTime.getMinutes(); nicholas@755: secs.nodeValue = dateTime.getSeconds(); nicholas@755: nicholas@755: var hold = document.createElement("datetime"); nicholas@755: var date = document.createElement("date"); nicholas@755: date.textContent = year.nodeValue+'/'+month.nodeValue+'/'+day.nodeValue; nicholas@755: var time = document.createElement("time"); nicholas@755: time.textContent = hour.nodeValue+':'+minute.nodeValue+':'+secs.nodeValue; nicholas@755: nicholas@755: date.setAttributeNode(year); nicholas@755: date.setAttributeNode(month); nicholas@755: date.setAttributeNode(day); nicholas@755: time.setAttributeNode(hour); nicholas@755: time.setAttributeNode(minute); nicholas@755: time.setAttributeNode(secs); nicholas@755: nicholas@755: hold.appendChild(date); nicholas@755: hold.appendChild(time); nicholas@755: return hold; nicholas@755: nicholas@755: } nicholas@755: nicholas@755: function Specification() { nicholas@755: // Handles the decoding of the project specification XML into a simple JavaScript Object. nicholas@755: nicholas@755: this.interfaceType = null; nicholas@755: this.commonInterface = new function() nicholas@755: { nicholas@755: this.options = []; nicholas@755: this.optionNode = function(input) nicholas@755: { nicholas@755: var name = input.getAttribute('name'); nicholas@755: this.type = name; nicholas@755: if(this.type == "option") nicholas@755: { nicholas@755: this.name = input.id; nicholas@755: } else if (this.type == "check") nicholas@755: { nicholas@755: this.check = input.id; nicholas@755: } nicholas@755: }; nicholas@755: }; nicholas@755: nicholas@755: this.randomiseOrder = function(input) nicholas@755: { nicholas@755: // This takes an array of information and randomises the order nicholas@755: var N = input.length; nicholas@755: nicholas@755: var inputSequence = []; // For safety purposes: keep track of randomisation nicholas@755: for (var counter = 0; counter < N; ++counter) nicholas@755: inputSequence.push(counter) // Fill array nicholas@755: var inputSequenceClone = inputSequence.slice(0); nicholas@755: nicholas@755: var holdArr = []; nicholas@755: var outputSequence = []; nicholas@755: for (var n=0; n 0) { nicholas@755: metricCollection = metricCollection[0].getElementsByTagName('metricEnable'); nicholas@755: for (var i=0; i 0) { nicholas@755: commonInterfaceNode = commonInterfaceNode[0]; nicholas@755: } else { nicholas@755: commonInterfaceNode = undefined; nicholas@755: } nicholas@755: nicholas@755: this.commonInterface = new function() { nicholas@755: this.OptionNode = function(child) { nicholas@755: this.type = child.nodeName; nicholas@755: if (this.type == 'option') nicholas@755: { nicholas@755: this.name = child.getAttribute('name'); nicholas@755: } nicholas@755: else if (this.type == 'check') { nicholas@755: this.check = child.getAttribute('name'); nicholas@755: if (this.check == 'scalerange') { nicholas@755: this.min = child.getAttribute('min'); nicholas@755: this.max = child.getAttribute('max'); nicholas@755: if (this.min == null) {this.min = 1;} nicholas@755: else if (Number(this.min) > 1 && this.min != null) { nicholas@755: this.min = Number(this.min)/100; nicholas@755: } else { nicholas@755: this.min = Number(this.min); nicholas@755: } nicholas@755: if (this.max == null) {this.max = 0;} nicholas@755: else if (Number(this.max) > 1 && this.max != null) { nicholas@755: this.max = Number(this.max)/100; nicholas@755: } else { nicholas@755: this.max = Number(this.max); nicholas@755: } nicholas@755: } nicholas@755: } else if (this.type == 'anchor' || this.type == 'reference') { nicholas@755: this.value = Number(child.textContent); nicholas@755: this.enforce = child.getAttribute('enforce'); nicholas@755: if (this.enforce == 'true') {this.enforce = true;} nicholas@755: else {this.enforce = false;} nicholas@755: } nicholas@755: }; nicholas@755: this.options = []; nicholas@755: if (commonInterfaceNode != undefined) { nicholas@755: var child = commonInterfaceNode.firstElementChild; nicholas@755: while (child != undefined) { nicholas@755: this.options.push(new this.OptionNode(child)); nicholas@755: child = child.nextElementSibling; nicholas@755: } nicholas@755: } nicholas@755: }; nicholas@755: nicholas@755: var audioHolders = projectXML.getElementsByTagName('audioHolder'); nicholas@755: for (var i=0; i audioHolders.length) nicholas@755: { nicholas@755: console.log('Warning: You have specified '+audioHolders.length+' tests but requested '+this.testPages+' be completed!'); nicholas@755: this.testPages = audioHolders.length; nicholas@755: } nicholas@755: var aH = this.audioHolders; nicholas@755: this.audioHolders = []; nicholas@755: for (var i=0; i tag compiled nicholas@755: var setupNode = root.createElement("setup"); nicholas@755: setupNode.setAttribute('interface',this.interfaceType); nicholas@755: setupNode.setAttribute('projectReturn',this.projectReturn); nicholas@755: setupNode.setAttribute('randomiseOrder',this.randomiseOrder); nicholas@755: setupNode.setAttribute('collectMetrics',this.collectMetrics); nicholas@755: setupNode.setAttribute('testPages',this.testPages); nicholas@755: if(this.loudness != null) {AHNode.setAttribute("loudness",this.loudness);} nicholas@755: nicholas@755: var setupPreTest = root.createElement("PreTest"); nicholas@755: for (var i=0; i tag nicholas@755: var Metric = root.createElement("Metric"); nicholas@755: for (var i=0; i tag nicholas@755: var CommonInterface = root.createElement("interface"); nicholas@755: for (var i=0; i tags nicholas@755: for (var ahIndex = 0; ahIndex < this.audioHolders.length; ahIndex++) nicholas@755: { nicholas@755: var node = this.audioHolders[ahIndex].encode(root); nicholas@755: root.getElementsByTagName("BrowserEvalProjectDocument")[0].appendChild(node); nicholas@755: } nicholas@755: return root; nicholas@755: }; nicholas@755: nicholas@755: this.prepostNode = function(type) { nicholas@755: this.type = type; nicholas@755: this.options = []; nicholas@755: nicholas@755: this.OptionNode = function() { nicholas@755: nicholas@755: this.childOption = function() { nicholas@755: this.type = 'option'; nicholas@755: this.id = null; nicholas@755: this.name = undefined; nicholas@755: this.text = null; nicholas@755: }; nicholas@755: nicholas@755: this.type = undefined; nicholas@755: this.id = undefined; nicholas@755: this.mandatory = undefined; nicholas@755: this.question = undefined; nicholas@755: this.statement = undefined; nicholas@755: this.boxsize = undefined; nicholas@755: this.options = []; nicholas@755: this.min = undefined; nicholas@755: this.max = undefined; nicholas@755: this.step = undefined; nicholas@755: nicholas@755: this.decode = function(child) nicholas@755: { nicholas@755: this.type = child.nodeName; nicholas@755: if (child.nodeName == "question") { nicholas@755: this.id = child.id; nicholas@755: this.mandatory; nicholas@755: if (child.getAttribute('mandatory') == "true") {this.mandatory = true;} nicholas@755: else {this.mandatory = false;} nicholas@755: this.question = child.textContent; nicholas@755: if (child.getAttribute('boxsize') == null) { nicholas@755: this.boxsize = 'normal'; nicholas@755: } else { nicholas@755: this.boxsize = child.getAttribute('boxsize'); nicholas@755: } nicholas@755: } else if (child.nodeName == "statement") { nicholas@755: this.statement = child.textContent; nicholas@755: } else if (child.nodeName == "checkbox" || child.nodeName == "radio") { nicholas@755: var element = child.firstElementChild; nicholas@755: this.id = child.id; nicholas@755: if (element == null) { nicholas@755: console.log('Malformed' +child.nodeName+ 'entry'); nicholas@755: this.statement = 'Malformed' +child.nodeName+ 'entry'; nicholas@755: this.type = 'statement'; nicholas@755: } else { nicholas@755: this.options = []; nicholas@755: while (element != null) { nicholas@755: if (element.nodeName == 'statement' && this.statement == undefined){ nicholas@755: this.statement = element.textContent; nicholas@755: } else if (element.nodeName == 'option') { nicholas@755: var node = new this.childOption(); nicholas@755: node.id = element.id; nicholas@755: node.name = element.getAttribute('name'); nicholas@755: node.text = element.textContent; nicholas@755: this.options.push(node); nicholas@755: } nicholas@755: element = element.nextElementSibling; nicholas@755: } nicholas@755: } nicholas@755: } else if (child.nodeName == "number") { nicholas@755: this.statement = child.textContent; nicholas@755: this.id = child.id; nicholas@755: this.min = child.getAttribute('min'); nicholas@755: this.max = child.getAttribute('max'); nicholas@755: this.step = child.getAttribute('step'); nicholas@755: } nicholas@755: }; nicholas@755: nicholas@755: this.exportXML = function(root) nicholas@755: { nicholas@755: var node = root.createElement(this.type); nicholas@755: switch(this.type) nicholas@755: { nicholas@755: case "statement": nicholas@755: node.textContent = this.statement; nicholas@755: break; nicholas@755: case "question": nicholas@755: node.id = this.id; nicholas@755: node.setAttribute("mandatory",this.mandatory); nicholas@755: node.setAttribute("boxsize",this.boxsize); nicholas@755: node.textContent = this.question; nicholas@755: break; nicholas@755: case "number": nicholas@755: node.id = this.id; nicholas@755: node.setAttribute("mandatory",this.mandatory); nicholas@755: node.setAttribute("min", this.min); nicholas@755: node.setAttribute("max", this.max); nicholas@755: node.setAttribute("step", this.step); nicholas@755: node.textContent = this.statement; nicholas@755: break; nicholas@755: case "checkbox": nicholas@755: node.id = this.id; nicholas@755: var statement = root.createElement("statement"); nicholas@755: statement.textContent = this.statement; nicholas@755: node.appendChild(statement); nicholas@755: for (var i=0; i 1) nicholas@758: { nicholas@758: xmlInitialPosition /= 100; nicholas@758: } nicholas@758: this.initialPosition = xmlInitialPosition; nicholas@758: } nicholas@758: } nicholas@755: if (xml.getAttribute('loudness') != null) nicholas@755: { nicholas@755: var XMLloudness = xml.getAttribute('loudness'); nicholas@755: if (isNaN(Number(XMLloudness)) == false) nicholas@755: { nicholas@755: this.loudness = Number(XMLloudness); nicholas@755: } nicholas@755: } nicholas@755: var setupPreTestNode = xml.getElementsByTagName('PreTest'); nicholas@755: if (setupPreTestNode.length != 0) nicholas@755: { nicholas@755: setupPreTestNode = setupPreTestNode[0]; nicholas@755: this.preTest.construct(setupPreTestNode); nicholas@755: } nicholas@755: nicholas@755: var setupPostTestNode = xml.getElementsByTagName('PostTest'); nicholas@755: if (setupPostTestNode.length != 0) nicholas@755: { nicholas@755: setupPostTestNode = setupPostTestNode[0]; nicholas@755: this.postTest.construct(setupPostTestNode); nicholas@755: } nicholas@755: nicholas@755: var interfaceDOM = xml.getElementsByTagName('interface'); nicholas@755: for (var i=0; i nicholas@755: for (var i=0; i nicholas@755: var AHPreTest = root.createElement("PreTest"); nicholas@755: for (var i=0; i 1) nicholas@755: { this.marker /= 100.0;} nicholas@755: if (this.marker >= 0 && this.marker <= 1) nicholas@755: { nicholas@755: this.enforce = true; nicholas@755: return; nicholas@755: } else { nicholas@755: console.log("ERROR - Marker of audioElement "+this.id+" is not between 0 and 1 (float) or 0 and 100 (integer)!"); nicholas@755: console.log("ERROR - Marker not enforced!"); nicholas@755: } nicholas@755: } else { nicholas@755: console.log("ERROR - Marker of audioElement "+this.id+" is not a number!"); nicholas@755: console.log("ERROR - Marker not enforced!"); nicholas@755: } nicholas@755: } nicholas@755: } nicholas@755: }; nicholas@755: this.encode = function(root) nicholas@755: { nicholas@755: var AENode = root.createElement("audioElements"); nicholas@755: AENode.id = this.id; nicholas@755: AENode.setAttribute("url",this.url); nicholas@755: AENode.setAttribute("type",this.type); nicholas@755: AENode.setAttribute("gain",linearToDecibel(this.gain)); nicholas@755: if (this.marker != false) nicholas@755: { nicholas@755: AENode.setAttribute("marker",this.marker*100); nicholas@755: } nicholas@755: return AENode; nicholas@755: }; nicholas@755: }; nicholas@755: nicholas@755: this.commentQuestionNode = function(xml) { nicholas@755: this.id = null; nicholas@755: this.type = undefined; nicholas@755: this.question = undefined; nicholas@755: this.options = []; nicholas@755: this.statement = undefined; nicholas@755: nicholas@755: this.childOption = function() { nicholas@755: this.type = 'option'; nicholas@755: this.name = null; nicholas@755: this.text = null; nicholas@755: }; nicholas@755: this.exportXML = function(root) nicholas@755: { nicholas@755: var CQNode = root.createElement("CommentQuestion"); nicholas@755: CQNode.id = this.id; nicholas@755: CQNode.setAttribute("type",this.type); nicholas@755: switch(this.type) nicholas@755: { nicholas@755: case "text": nicholas@755: CQNode.textContent = this.question; nicholas@755: break; nicholas@755: case "radio": nicholas@755: var statement = root.createElement("statement"); nicholas@755: statement.textContent = this.statement; nicholas@755: CQNode.appendChild(statement); nicholas@755: for (var i=0; i tag. nicholas@755: this.interfaceObjects = []; nicholas@755: this.interfaceObject = function(){}; nicholas@755: nicholas@755: this.resizeWindow = function(event) nicholas@755: { nicholas@755: popup.resize(event); nicholas@755: for(var i=0; i= 600) nicholas@755: { nicholas@755: boxwidth = 600; nicholas@755: } nicholas@755: else if (boxwidth < 400) nicholas@755: { nicholas@755: boxwidth = 400; nicholas@755: } nicholas@755: this.trackComment.style.width = boxwidth+"px"; nicholas@755: this.trackCommentBox.style.width = boxwidth-6+"px"; nicholas@755: }; nicholas@755: this.resize(); nicholas@755: }; nicholas@755: nicholas@755: this.commentQuestions = []; nicholas@755: nicholas@755: this.commentBox = function(commentQuestion) { nicholas@755: this.specification = commentQuestion; nicholas@755: // Create document objects to hold the comment boxes nicholas@755: this.holder = document.createElement('div'); nicholas@755: this.holder.className = 'comment-div'; nicholas@755: // Create a string next to each comment asking for a comment nicholas@755: this.string = document.createElement('span'); nicholas@755: this.string.innerHTML = commentQuestion.question; nicholas@755: // Create the HTML5 comment box 'textarea' nicholas@755: this.textArea = document.createElement('textarea'); nicholas@755: this.textArea.rows = '4'; nicholas@755: this.textArea.cols = '100'; nicholas@755: this.textArea.className = 'trackComment'; nicholas@755: var br = document.createElement('br'); nicholas@755: // Add to the holder. nicholas@755: this.holder.appendChild(this.string); nicholas@755: this.holder.appendChild(br); nicholas@755: this.holder.appendChild(this.textArea); nicholas@755: nicholas@755: this.exportXMLDOM = function() { nicholas@755: var root = document.createElement('comment'); nicholas@755: root.id = this.specification.id; nicholas@755: root.setAttribute('type',this.specification.type); nicholas@755: root.textContent = this.textArea.value; nicholas@755: console.log("Question: "+this.string.textContent); nicholas@755: console.log("Response: "+root.textContent); nicholas@755: return root; nicholas@755: }; nicholas@755: this.resize = function() nicholas@755: { nicholas@755: var boxwidth = (window.innerWidth-100)/2; nicholas@755: if (boxwidth >= 600) nicholas@755: { nicholas@755: boxwidth = 600; nicholas@755: } nicholas@755: else if (boxwidth < 400) nicholas@755: { nicholas@755: boxwidth = 400; nicholas@755: } nicholas@755: this.holder.style.width = boxwidth+"px"; nicholas@755: this.textArea.style.width = boxwidth-6+"px"; nicholas@755: }; nicholas@755: this.resize(); nicholas@755: }; nicholas@755: nicholas@755: this.radioBox = function(commentQuestion) { nicholas@755: this.specification = commentQuestion; nicholas@755: // Create document objects to hold the comment boxes nicholas@755: this.holder = document.createElement('div'); nicholas@755: this.holder.className = 'comment-div'; nicholas@755: // Create a string next to each comment asking for a comment nicholas@755: this.string = document.createElement('span'); nicholas@755: this.string.innerHTML = commentQuestion.statement; nicholas@755: var br = document.createElement('br'); nicholas@755: // Add to the holder. nicholas@755: this.holder.appendChild(this.string); nicholas@755: this.holder.appendChild(br); nicholas@755: this.options = []; nicholas@755: this.inputs = document.createElement('div'); nicholas@755: this.span = document.createElement('div'); nicholas@755: this.inputs.align = 'center'; nicholas@755: this.inputs.style.marginLeft = '12px'; nicholas@755: this.span.style.marginLeft = '12px'; nicholas@755: this.span.align = 'center'; nicholas@755: this.span.style.marginTop = '15px'; nicholas@755: nicholas@755: var optCount = commentQuestion.options.length; nicholas@755: for (var i=0; i= this.options.length) { nicholas@755: break; nicholas@755: } nicholas@755: } nicholas@755: if (i >= this.options.length) { nicholas@755: response.textContent = 'null'; nicholas@755: } else { nicholas@755: response.textContent = this.options[i].getAttribute('setvalue'); nicholas@755: response.setAttribute('number',i); nicholas@755: } nicholas@755: console.log('Comment: '+question.textContent); nicholas@755: console.log('Response: '+response.textContent); nicholas@755: root.appendChild(question); nicholas@755: root.appendChild(response); nicholas@755: return root; nicholas@755: }; nicholas@755: this.resize = function() nicholas@755: { nicholas@755: var boxwidth = (window.innerWidth-100)/2; nicholas@755: if (boxwidth >= 600) nicholas@755: { nicholas@755: boxwidth = 600; nicholas@755: } nicholas@755: else if (boxwidth < 400) nicholas@755: { nicholas@755: boxwidth = 400; nicholas@755: } nicholas@755: this.holder.style.width = boxwidth+"px"; nicholas@755: var text = this.holder.children[2]; nicholas@755: var options = this.holder.children[3]; nicholas@755: var optCount = options.children.length; nicholas@755: var spanMargin = Math.floor(((boxwidth-20-(optCount*80))/(optCount))/2)+'px'; nicholas@755: var options = options.firstChild; nicholas@755: var text = text.firstChild; nicholas@755: options.style.marginRight = spanMargin; nicholas@755: options.style.marginLeft = spanMargin; nicholas@755: text.style.marginRight = spanMargin; nicholas@755: text.style.marginLeft = spanMargin; nicholas@755: while(options.nextSibling != undefined) nicholas@755: { nicholas@755: options = options.nextSibling; nicholas@755: text = text.nextSibling; nicholas@755: options.style.marginRight = spanMargin; nicholas@755: options.style.marginLeft = spanMargin; nicholas@755: text.style.marginRight = spanMargin; nicholas@755: text.style.marginLeft = spanMargin; nicholas@755: } nicholas@755: }; nicholas@755: this.resize(); nicholas@755: }; nicholas@755: nicholas@755: this.checkboxBox = function(commentQuestion) { nicholas@755: this.specification = commentQuestion; nicholas@755: // Create document objects to hold the comment boxes nicholas@755: this.holder = document.createElement('div'); nicholas@755: this.holder.className = 'comment-div'; nicholas@755: // Create a string next to each comment asking for a comment nicholas@755: this.string = document.createElement('span'); nicholas@755: this.string.innerHTML = commentQuestion.statement; nicholas@755: var br = document.createElement('br'); nicholas@755: // Add to the holder. nicholas@755: this.holder.appendChild(this.string); nicholas@755: this.holder.appendChild(br); nicholas@755: this.options = []; nicholas@755: this.inputs = document.createElement('div'); nicholas@755: this.span = document.createElement('div'); nicholas@755: this.inputs.align = 'center'; nicholas@755: this.inputs.style.marginLeft = '12px'; nicholas@755: this.span.style.marginLeft = '12px'; nicholas@755: this.span.align = 'center'; nicholas@755: this.span.style.marginTop = '15px'; nicholas@755: nicholas@755: var optCount = commentQuestion.options.length; nicholas@755: for (var i=0; i= 600) nicholas@755: { nicholas@755: boxwidth = 600; nicholas@755: } nicholas@755: else if (boxwidth < 400) nicholas@755: { nicholas@755: boxwidth = 400; nicholas@755: } nicholas@755: this.holder.style.width = boxwidth+"px"; nicholas@755: var text = this.holder.children[2]; nicholas@755: var options = this.holder.children[3]; nicholas@755: var optCount = options.children.length; nicholas@755: var spanMargin = Math.floor(((boxwidth-20-(optCount*80))/(optCount))/2)+'px'; nicholas@755: var options = options.firstChild; nicholas@755: var text = text.firstChild; nicholas@755: options.style.marginRight = spanMargin; nicholas@755: options.style.marginLeft = spanMargin; nicholas@755: text.style.marginRight = spanMargin; nicholas@755: text.style.marginLeft = spanMargin; nicholas@755: while(options.nextSibling != undefined) nicholas@755: { nicholas@755: options = options.nextSibling; nicholas@755: text = text.nextSibling; nicholas@755: options.style.marginRight = spanMargin; nicholas@755: options.style.marginLeft = spanMargin; nicholas@755: text.style.marginRight = spanMargin; nicholas@755: text.style.marginLeft = spanMargin; nicholas@755: } nicholas@755: }; nicholas@755: this.resize(); nicholas@755: }; nicholas@755: nicholas@755: this.createCommentBox = function(audioObject) { nicholas@755: var node = new this.elementCommentBox(audioObject); nicholas@755: this.commentBoxes.push(node); nicholas@755: audioObject.commentDOM = node; nicholas@755: return node; nicholas@755: }; nicholas@755: nicholas@755: this.sortCommentBoxes = function() { nicholas@755: var holder = []; nicholas@755: while (this.commentBoxes.length > 0) { nicholas@755: var node = this.commentBoxes.pop(0); nicholas@755: holder[node.id] = node; nicholas@755: } nicholas@755: this.commentBoxes = holder; nicholas@755: }; nicholas@755: nicholas@755: this.showCommentBoxes = function(inject, sort) { nicholas@755: if (sort) {interfaceContext.sortCommentBoxes();} nicholas@755: for (var i=0; i 0) { nicholas@755: var time = this.playbackObject.getCurrentPosition(); nicholas@755: if (time > 0) { nicholas@755: var width = 490; nicholas@755: var pix = Math.floor(time/this.timePerPixel); nicholas@755: this.scrubberHead.style.left = pix+'px'; nicholas@755: if (this.maxTime > 60.0) { nicholas@755: var secs = time%60; nicholas@755: var mins = Math.floor((time-secs)/60); nicholas@755: secs = secs.toString(); nicholas@755: secs = secs.substr(0,2); nicholas@755: mins = mins.toString(); nicholas@755: this.curTimeSpan.textContent = mins+':'+secs; nicholas@755: } else { nicholas@755: time = time.toString(); nicholas@755: this.curTimeSpan.textContent = time.substr(0,4); nicholas@755: } nicholas@755: } else { nicholas@755: this.scrubberHead.style.left = '0px'; nicholas@755: if (this.maxTime < 60) { nicholas@755: this.curTimeSpan.textContent = '0.00'; nicholas@755: } else { nicholas@755: this.curTimeSpan.textContent = '00:00'; nicholas@755: } nicholas@755: } nicholas@755: } nicholas@755: }; nicholas@755: nicholas@755: this.interval = undefined; nicholas@755: nicholas@755: this.start = function() { nicholas@755: if (this.playbackObject != undefined && this.interval == undefined) { nicholas@755: if (this.maxTime < 60) { nicholas@755: this.interval = setInterval(function(){interfaceContext.playhead.update();},10); nicholas@755: } else { nicholas@755: this.interval = setInterval(function(){interfaceContext.playhead.update();},100); nicholas@755: } nicholas@755: } nicholas@755: }; nicholas@755: this.stop = function() { nicholas@755: clearInterval(this.interval); nicholas@755: this.interval = undefined; nicholas@755: if (this.maxTime < 60) { nicholas@755: this.curTimeSpan.textContent = '0.00'; nicholas@755: } else { nicholas@755: this.curTimeSpan.textContent = '00:00'; nicholas@755: } nicholas@755: }; nicholas@755: }; nicholas@755: nicholas@755: // Global Checkers nicholas@755: // These functions will help enforce the checkers nicholas@755: this.checkHiddenAnchor = function() nicholas@755: { nicholas@755: var audioHolder = testState.currentStateMap[testState.currentIndex]; nicholas@755: if (audioHolder.anchorId != null) nicholas@755: { nicholas@755: var audioObject = audioEngineContext.audioObjects[audioHolder.anchorId]; nicholas@755: if (audioObject.interfaceDOM.getValue() > audioObject.specification.marker && audioObject.interfaceDOM.enforce == true) nicholas@755: { nicholas@755: // Anchor is not set below nicholas@755: console.log('Anchor node not below marker value'); nicholas@755: alert('Please keep listening'); nicholas@755: return false; nicholas@755: } nicholas@755: } nicholas@755: return true; nicholas@755: }; nicholas@755: nicholas@755: this.checkHiddenReference = function() nicholas@755: { nicholas@755: var audioHolder = testState.currentStateMap[testState.currentIndex]; nicholas@755: if (audioHolder.referenceId != null) nicholas@755: { nicholas@755: var audioObject = audioEngineContext.audioObjects[audioHolder.referenceId]; nicholas@755: if (audioObject.interfaceDOM.getValue() < audioObject.specification.marker && audioObject.interfaceDOM.enforce == true) nicholas@755: { nicholas@755: // Anchor is not set below nicholas@755: console.log('Reference node not above marker value'); nicholas@755: alert('Please keep listening'); nicholas@755: return false; nicholas@755: } nicholas@755: } nicholas@755: return true; nicholas@755: }; nicholas@755: nicholas@755: this.checkFragmentsFullyPlayed = function () nicholas@755: { nicholas@755: // Checks the entire file has been played back nicholas@755: // NOTE ! This will return true IF playback is Looped!!! nicholas@755: if (audioEngineContext.loopPlayback) nicholas@755: { nicholas@755: console.log("WARNING - Looped source: Cannot check fragments are fully played"); nicholas@755: return true; nicholas@755: } nicholas@755: var check_pass = true; nicholas@755: var error_obj = []; nicholas@755: for (var i = 0; i= time) nicholas@755: { nicholas@755: passed = true; nicholas@755: break; nicholas@755: } nicholas@755: } nicholas@755: if (passed == false) nicholas@755: { nicholas@755: check_pass = false; nicholas@755: console.log("Continue listening to track-"+i); nicholas@755: error_obj.push(i); nicholas@755: } nicholas@755: } nicholas@755: if (check_pass == false) nicholas@755: { nicholas@756: var str_start = "You have not completely listened to fragments "; nicholas@755: for (var i=0; i