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