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