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