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