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