n@1106: /** n@1106: * core.js n@1106: * n@1106: * Main script to run, calls all other core functions and manages loading/store to backend. n@1106: * Also contains all global variables. n@1106: */ n@1106: n@1106: /* create the web audio API context and store in audioContext*/ n@1106: var audioContext; // Hold the browser web audio API n@1106: var projectXML; // Hold the parsed setup XML n@1106: var schemaXSD; // Hold the parsed schema XSD n@1106: var specification; n@1106: var interfaceContext; n@1106: var storage; n@1106: var popup; // Hold the interfacePopup object n@1106: var testState; n@1106: var currentTrackOrder = []; // Hold the current XML tracks in their (randomised) order n@1106: var audioEngineContext; // The custome AudioEngine object n@1106: var projectReturn; // Hold the URL for the return n@1106: n@1106: n@1106: // Add a prototype to the bufferSourceNode to reference to the audioObject holding it n@1106: AudioBufferSourceNode.prototype.owner = undefined; n@1106: // Add a prototype to the bufferNode to hold the desired LINEAR gain n@1106: AudioBuffer.prototype.playbackGain = undefined; n@1106: // Add a prototype to the bufferNode to hold the computed LUFS loudness n@1106: AudioBuffer.prototype.lufs = undefined; n@1106: n@1106: // Firefox does not have an XMLDocument.prototype.getElementsByName n@1106: // and there is no searchAll style command, this custom function will n@1106: // search all children recusrively for the name. Used for XSD where all n@1106: // element nodes must have a name and therefore can pull the schema node n@1106: XMLDocument.prototype.getAllElementsByName = function(name) n@1106: { n@1106: name = String(name); n@1106: var selected = this.documentElement.getAllElementsByName(name); n@1106: return selected; n@1106: } n@1106: n@1106: Element.prototype.getAllElementsByName = function(name) n@1106: { n@1106: name = String(name); n@1106: var selected = []; n@1106: var node = this.firstElementChild; n@1106: while(node != null) n@1106: { n@1106: if (node.getAttribute('name') == name) n@1106: { n@1106: selected.push(node); n@1106: } n@1106: if (node.childElementCount > 0) n@1106: { n@1106: selected = selected.concat(node.getAllElementsByName(name)); n@1106: } n@1106: node = node.nextElementSibling; n@1106: } n@1106: return selected; n@1106: } n@1106: n@1106: XMLDocument.prototype.getAllElementsByTagName = function(name) n@1106: { n@1106: name = String(name); n@1106: var selected = this.documentElement.getAllElementsByTagName(name); n@1106: return selected; n@1106: } n@1106: n@1106: Element.prototype.getAllElementsByTagName = function(name) n@1106: { n@1106: name = String(name); n@1106: var selected = []; n@1106: var node = this.firstElementChild; n@1106: while(node != null) n@1106: { n@1106: if (node.nodeName == name) n@1106: { n@1106: selected.push(node); n@1106: } n@1106: if (node.childElementCount > 0) n@1106: { n@1106: selected = selected.concat(node.getAllElementsByTagName(name)); n@1106: } n@1106: node = node.nextElementSibling; n@1106: } n@1106: return selected; n@1106: } n@1106: n@1106: // Firefox does not have an XMLDocument.prototype.getElementsByName n@1106: if (typeof XMLDocument.prototype.getElementsByName != "function") { n@1106: XMLDocument.prototype.getElementsByName = function(name) n@1106: { n@1106: name = String(name); n@1106: var node = this.documentElement.firstElementChild; n@1106: var selected = []; n@1106: while(node != null) n@1106: { n@1106: if (node.getAttribute('name') == name) n@1106: { n@1106: selected.push(node); n@1106: } n@1106: node = node.nextElementSibling; n@1106: } n@1106: return selected; n@1106: } n@1106: } n@1106: n@1106: window.onload = function() { n@1106: // Function called once the browser has loaded all files. n@1106: // This should perform any initial commands such as structure / loading documents n@1106: n@1106: // Create a web audio API context n@1106: // Fixed for cross-browser support n@1106: var AudioContext = window.AudioContext || window.webkitAudioContext; n@1106: audioContext = new AudioContext; n@1106: n@1106: // Create test state n@1106: testState = new stateMachine(); n@1106: n@1106: // Create the popup interface object n@1106: popup = new interfacePopup(); n@1106: n@1106: // Create the specification object n@1106: specification = new Specification(); n@1106: n@1106: // Create the interface object n@1106: interfaceContext = new Interface(specification); n@1106: n@1106: // Create the storage object n@1106: storage = new Storage(); n@1106: // Define window callbacks for interface n@1106: window.onresize = function(event){interfaceContext.resizeWindow(event);}; n@1106: }; n@1106: n@1106: function loadProjectSpec(url) { n@1106: // Load the project document from the given URL, decode the XML and instruct audioEngine to get audio data n@1106: // If url is null, request client to upload project XML document n@1106: var xmlhttp = new XMLHttpRequest(); n@1106: xmlhttp.open("GET",'test-schema.xsd',true); n@1106: xmlhttp.onload = function() n@1106: { n@1106: schemaXSD = xmlhttp.response; n@1106: var parse = new DOMParser(); n@1106: specification.schema = parse.parseFromString(xmlhttp.response,'text/xml'); n@1106: var r = new XMLHttpRequest(); n@1106: r.open('GET',url,true); n@1106: r.onload = function() { n@1106: loadProjectSpecCallback(r.response); n@1106: }; n@1106: r.send(); n@1106: }; n@1106: xmlhttp.send(); n@1106: }; n@1106: n@1106: function loadProjectSpecCallback(response) { n@1106: // Function called after asynchronous download of XML project specification n@1106: //var decode = $.parseXML(response); n@1106: //projectXML = $(decode); n@1106: n@1106: // First perform XML schema validation n@1106: var Module = { n@1106: xml: response, n@1106: schema: schemaXSD, n@1106: arguments:["--noout", "--schema", 'test-schema.xsd','document.xml'] n@1106: }; n@1106: n@1106: var xmllint = validateXML(Module); n@1106: console.log(xmllint); n@1106: if(xmllint != 'document.xml validates\n') n@1106: { n@1106: document.getElementsByTagName('body')[0].innerHTML = null; n@1106: var msg = document.createElement("h3"); n@1106: msg.textContent = "FATAL ERROR"; n@1106: var span = document.createElement("h4"); n@1106: span.textContent = "The XML validator returned the following errors when decoding your XML file"; n@1106: document.getElementsByTagName('body')[0].appendChild(msg); n@1106: document.getElementsByTagName('body')[0].appendChild(span); n@1106: xmllint = xmllint.split('\n'); n@1106: for (var i in xmllint) n@1106: { n@1106: document.getElementsByTagName('body')[0].appendChild(document.createElement('br')); n@1106: var span = document.createElement("span"); n@1106: span.textContent = xmllint[i]; n@1106: document.getElementsByTagName('body')[0].appendChild(span); n@1106: } n@1106: return; n@1106: } n@1106: n@1106: var parse = new DOMParser(); n@1106: projectXML = parse.parseFromString(response,'text/xml'); n@1106: var errorNode = projectXML.getElementsByTagName('parsererror'); n@1106: if (errorNode.length >= 1) n@1106: { n@1106: var msg = document.createElement("h3"); n@1106: msg.textContent = "FATAL ERROR"; n@1106: var span = document.createElement("span"); n@1106: span.textContent = "The XML parser returned the following errors when decoding your XML file"; n@1106: document.getElementsByTagName('body')[0].innerHTML = null; n@1106: document.getElementsByTagName('body')[0].appendChild(msg); n@1106: document.getElementsByTagName('body')[0].appendChild(span); n@1106: document.getElementsByTagName('body')[0].appendChild(errorNode[0]); n@1106: return; n@1106: } n@1106: n@1106: // Build the specification n@1106: specification.decode(projectXML); n@1106: storage.initialise(); n@1106: /// CHECK FOR SAMPLE RATE COMPATIBILITY n@1106: if (specification.sampleRate != undefined) { n@1106: if (Number(specification.sampleRate) != audioContext.sampleRate) { n@1106: var errStr = 'Sample rates do not match! Requested '+Number(specification.sampleRate)+', got '+audioContext.sampleRate+'. Please set the sample rate to match before completing this test.'; n@1106: alert(errStr); n@1106: return; n@1106: } n@1106: } n@1106: n@1106: // Detect the interface to use and load the relevant javascripts. n@1106: var interfaceJS = document.createElement('script'); n@1106: interfaceJS.setAttribute("type","text/javascript"); n@1106: switch(specification.interface) n@1106: { n@1106: case "APE": n@1106: interfaceJS.setAttribute("src","interfaces/ape.js"); n@1106: n@1106: // APE comes with a css file n@1106: var css = document.createElement('link'); n@1106: css.rel = 'stylesheet'; n@1106: css.type = 'text/css'; n@1106: css.href = 'interfaces/ape.css'; n@1106: n@1106: document.getElementsByTagName("head")[0].appendChild(css); n@1106: break; n@1106: n@1106: case "MUSHRA": n@1106: interfaceJS.setAttribute("src","interfaces/mushra.js"); n@1106: n@1106: // MUSHRA comes with a css file n@1106: var css = document.createElement('link'); n@1106: css.rel = 'stylesheet'; n@1106: css.type = 'text/css'; n@1106: css.href = 'interfaces/mushra.css'; n@1106: n@1106: document.getElementsByTagName("head")[0].appendChild(css); n@1106: break; n@1106: n@1106: case "AB": n@1106: interfaceJS.setAttribute("src","interfaces/AB.js"); n@1106: n@1106: // AB comes with a css file n@1106: var css = document.createElement('link'); n@1106: css.rel = 'stylesheet'; n@1106: css.type = 'text/css'; n@1106: css.href = 'interfaces/AB.css'; n@1106: n@1106: document.getElementsByTagName("head")[0].appendChild(css); n@1106: break; n@1106: case "Bipolar": n@1106: case "ACR": n@1106: case "DCR": n@1106: case "CCR": n@1106: case "ABC": n@1106: // Above enumerate to horizontal sliders n@1106: interfaceJS.setAttribute("src","interfaces/horizontal-sliders.js"); n@1106: n@1106: // horizontal-sliders comes with a css file n@1106: var css = document.createElement('link'); n@1106: css.rel = 'stylesheet'; n@1106: css.type = 'text/css'; n@1106: css.href = 'interfaces/horizontal-sliders.css'; n@1106: n@1106: document.getElementsByTagName("head")[0].appendChild(css); n@1106: break; n@1106: case "discrete": n@1106: case "likert": n@1106: // Above enumerate to horizontal discrete radios n@1106: interfaceJS.setAttribute("src","interfaces/discrete.js"); n@1106: n@1106: // horizontal-sliders comes with a css file n@1106: var css = document.createElement('link'); n@1106: css.rel = 'stylesheet'; n@1106: css.type = 'text/css'; n@1106: css.href = 'interfaces/discrete.css'; n@1106: n@1106: document.getElementsByTagName("head")[0].appendChild(css); n@1106: break; n@1106: } n@1106: document.getElementsByTagName("head")[0].appendChild(interfaceJS); n@1106: n@1106: // Create the audio engine object n@1106: audioEngineContext = new AudioEngine(specification); n@1106: n@1106: $(specification.pages).each(function(index,elem){ n@1106: $(elem.audioElements).each(function(i,audioElem){ n@1106: var URL = elem.hostURL + audioElem.url; n@1106: var buffer = null; n@1106: for (var i=0; i max_w) n@1106: max_w = w; n@1106: index++; n@1106: } n@1106: max_w += 12; n@1106: this.popupResponse.style.textAlign=""; n@1106: var leftP = ((max_w/500)/2)*100; n@1106: this.popupResponse.style.left=leftP+"%"; n@1106: } else if (node.specification.type == 'radio') { n@1106: if (node.response == undefined) { n@1106: node.response = {name: "", text: ""}; n@1106: } n@1106: var index = 0; n@1106: var max_w = 0; n@1106: for (var option of node.specification.options) { n@1106: var input = document.createElement('input'); n@1106: input.id = option.name; n@1106: input.type = 'radio'; n@1106: input.name = node.specification.id; n@1106: var span = document.createElement('span'); n@1106: span.textContent = option.text; n@1106: var hold = document.createElement('div'); n@1106: hold.setAttribute('name','option'); n@1106: hold.style.padding = '4px'; n@1106: hold.appendChild(input); n@1106: hold.appendChild(span); n@1106: this.popupResponse.appendChild(hold); n@1106: if (input.id == node.response.name) { n@1106: input.checked = "true"; n@1106: } n@1106: var w = $(span).width(); n@1106: if (w > max_w) n@1106: max_w = w; n@1106: } n@1106: max_w += 12; n@1106: this.popupResponse.style.textAlign=""; n@1106: var leftP = ((max_w/500)/2)*100; n@1106: this.popupResponse.style.left=leftP+"%"; n@1106: } else if (node.specification.type == 'number') { n@1106: var input = document.createElement('input'); n@1106: input.type = 'textarea'; n@1106: if (node.min != null) {input.min = node.specification.min;} n@1106: if (node.max != null) {input.max = node.specification.max;} n@1106: if (node.step != null) {input.step = node.specification.step;} n@1106: if (node.response != undefined) { n@1106: input.value = node.response; n@1106: } n@1106: this.popupResponse.appendChild(input); n@1106: this.popupResponse.style.textAlign="center"; n@1106: this.popupResponse.style.left="0%"; n@1106: } n@1106: if(this.currentIndex+1 == this.popupOptions.length) { n@1106: if (this.node.location == "pre") { n@1106: this.buttonProceed.textContent = 'Start'; n@1106: } else { n@1106: this.buttonProceed.textContent = 'Submit'; n@1106: } n@1106: } else { n@1106: this.buttonProceed.textContent = 'Next'; n@1106: } n@1106: if(this.currentIndex > 0) n@1106: this.buttonPrevious.style.visibility = 'visible'; n@1106: else n@1106: this.buttonPrevious.style.visibility = 'hidden'; n@1106: }; n@1106: n@1106: this.initState = function(node,store) { n@1106: //Call this with your preTest and postTest nodes when needed to n@1106: // initialise the popup procedure. n@1106: if (node.options.length > 0) { n@1106: this.popupOptions = []; n@1106: this.node = node; n@1106: this.store = store; n@1106: for (var opt of node.options) n@1106: { n@1106: this.popupOptions.push({ n@1106: specification: opt, n@1106: response: null n@1106: }); n@1106: } n@1106: this.currentIndex = 0; n@1106: this.showPopup(); n@1106: this.postNode(); n@1106: } else { n@1106: advanceState(); n@1106: } n@1106: }; n@1106: n@1106: this.proceedClicked = function() { n@1106: // Each time the popup button is clicked! n@1106: var node = this.popupOptions[this.currentIndex]; n@1106: if (node.specification.type == 'question') { n@1106: // Must extract the question data n@1106: var textArea = $(popup.popupContent).find('textarea')[0]; n@1106: if (node.specification.mandatory == true && textArea.value.length == 0) { n@1106: alert('This question is mandatory'); n@1106: return; n@1106: } else { n@1106: // Save the text content n@1106: console.log("Question: "+ node.specification.statement); n@1106: console.log("Question Response: "+ textArea.value); n@1106: node.response = textArea.value; n@1106: } n@1106: } else if (node.specification.type == 'checkbox') { n@1106: // Must extract checkbox data n@1106: console.log("Checkbox: "+ node.specification.statement); n@1106: var inputs = this.popupResponse.getElementsByTagName('input'); n@1106: node.response = []; n@1106: for (var i=0; i node.max && node.max != null) { n@1106: alert('Number is above the maximum value of '+node.max); n@1106: return; n@1106: } n@1106: node.response = input.value; n@1106: } n@1106: this.currentIndex++; n@1106: if (this.currentIndex < this.popupOptions.length) { n@1106: this.postNode(); n@1106: } else { n@1106: // Reached the end of the popupOptions n@1106: this.hidePopup(); n@1106: for (var node of this.popupOptions) n@1106: { n@1106: this.store.postResult(node); n@1106: } n@1106: advanceState(); n@1106: } n@1106: }; n@1106: n@1106: this.previousClick = function() { n@1106: // Triggered when the 'Back' button is clicked in the survey n@1106: if (this.currentIndex > 0) { n@1106: this.currentIndex--; n@1106: this.postNode(); n@1106: } n@1106: }; n@1106: n@1106: this.resize = function(event) n@1106: { n@1106: // Called on window resize; n@1106: if (this.popup != null) { n@1106: this.popup.style.left = (window.innerWidth/2)-250 + 'px'; n@1106: this.popup.style.top = (window.innerHeight/2)-125 + 'px'; n@1106: var blank = document.getElementsByClassName('testHalt')[0]; n@1106: blank.style.width = window.innerWidth; n@1106: blank.style.height = window.innerHeight; n@1106: } n@1106: }; n@1106: } n@1106: n@1106: function advanceState() n@1106: { n@1106: // Just for complete clarity n@1106: testState.advanceState(); n@1106: } n@1106: n@1106: function stateMachine() n@1106: { n@1106: // Object prototype for tracking and managing the test state n@1106: this.stateMap = []; n@1106: this.preTestSurvey = null; n@1106: this.postTestSurvey = null; n@1106: this.stateIndex = null; n@1106: this.currentStateMap = null; n@1106: this.currentStatePosition = null; n@1106: this.currentStore = null; n@1106: this.initialise = function(){ n@1106: n@1106: // Get the data from Specification n@1106: var pageHolder = []; n@1106: for (var page of specification.pages) n@1106: { n@1106: var repeat = page.repeatCount; n@1106: while(repeat >= 0) n@1106: { n@1106: pageHolder.push(page); n@1106: repeat--; n@1106: } n@1106: } n@1106: if (specification.randomiseOrder) n@1106: { n@1106: pageHolder = randomiseOrder(pageHolder); n@1106: } n@1106: for (var i=0; i 0) { n@1106: if(this.stateIndex != null) { n@1106: console.log('NOTE - State already initialise'); n@1106: } n@1106: this.stateIndex = -1; n@1106: } else { n@1106: console.log('FATAL - StateMap not correctly constructed. EMPTY_STATE_MAP'); n@1106: } n@1106: }; n@1106: this.advanceState = function(){ n@1106: if (this.stateIndex == null) { n@1106: this.initialise(); n@1106: } n@1106: if (this.stateIndex == -1) { n@1106: this.stateIndex++; n@1106: console.log('Starting test...'); n@1106: if (this.preTestSurvey != null) n@1106: { n@1106: popup.initState(this.preTestSurvey,storage.globalPreTest); n@1106: } else { n@1106: this.advanceState(); n@1106: } n@1106: } else if (this.stateIndex == this.stateMap.length) n@1106: { n@1106: // All test pages complete, post test n@1106: console.log('Ending test ...'); n@1106: this.stateIndex++; n@1106: if (this.postTestSurvey == null) { n@1106: this.advanceState(); n@1106: } else { n@1106: popup.initState(this.postTestSurvey,storage.globalPostTest); n@1106: } n@1106: } else if (this.stateIndex > this.stateMap.length) n@1106: { n@1106: createProjectSave(specification.projectReturn); n@1106: } n@1106: else n@1106: { n@1106: if (this.currentStateMap == null) n@1106: { n@1106: this.currentStateMap = this.stateMap[this.stateIndex]; n@1106: if (this.currentStateMap.randomiseOrder) n@1106: { n@1106: this.currentStateMap.audioElements = randomiseOrder(this.currentStateMap.audioElements); n@1106: } n@1106: this.currentStore = storage.createTestPageStore(this.currentStateMap); n@1106: if (this.currentStateMap.preTest != null) n@1106: { n@1106: this.currentStatePosition = 'pre'; n@1106: popup.initState(this.currentStateMap.preTest,storage.testPages[this.stateIndex].preTest); n@1106: } else { n@1106: this.currentStatePosition = 'test'; n@1106: } n@1106: interfaceContext.newPage(this.currentStateMap,storage.testPages[this.stateIndex]); n@1106: return; n@1106: } n@1106: switch(this.currentStatePosition) n@1106: { n@1106: case 'pre': n@1106: this.currentStatePosition = 'test'; n@1106: break; n@1106: case 'test': n@1106: this.currentStatePosition = 'post'; n@1106: // Save the data n@1106: this.testPageCompleted(); n@1106: if (this.currentStateMap.postTest == null) n@1106: { n@1106: this.advanceState(); n@1106: return; n@1106: } else { n@1106: popup.initState(this.currentStateMap.postTest,storage.testPages[this.stateIndex].postTest); n@1106: } n@1106: break; n@1106: case 'post': n@1106: this.stateIndex++; n@1106: this.currentStateMap = null; n@1106: this.advanceState(); n@1106: break; n@1106: }; n@1106: } n@1106: }; n@1106: n@1106: this.testPageCompleted = function() { n@1106: // Function called each time a test page has been completed n@1106: var storePoint = storage.testPages[this.stateIndex]; n@1106: // First get the test metric n@1106: n@1106: var metric = storePoint.XMLDOM.getElementsByTagName('metric')[0]; n@1106: if (audioEngineContext.metric.enableTestTimer) n@1106: { n@1106: var testTime = storePoint.parent.document.createElement('metricresult'); n@1106: testTime.id = 'testTime'; n@1106: testTime.textContent = audioEngineContext.timer.testDuration; n@1106: metric.appendChild(testTime); n@1106: } n@1106: n@1106: var audioObjects = audioEngineContext.audioObjects; n@1106: for (var ao of audioEngineContext.audioObjects) n@1106: { n@1106: ao.exportXMLDOM(); n@1106: } n@1106: for (var element of interfaceContext.commentQuestions) n@1106: { n@1106: element.exportXMLDOM(storePoint); n@1106: } n@1106: pageXMLSave(storePoint.XMLDOM, this.currentStateMap); n@1106: }; n@1106: } n@1106: n@1106: function AudioEngine(specification) { n@1106: n@1106: // Create two output paths, the main outputGain and fooGain. n@1106: // Output gain is default to 1 and any items for playback route here n@1106: // Foo gain is used for analysis to ensure paths get processed, but are not heard n@1106: // because web audio will optimise and any route which does not go to the destination gets ignored. n@1106: this.outputGain = audioContext.createGain(); n@1106: this.fooGain = audioContext.createGain(); n@1106: this.fooGain.gain = 0; n@1106: n@1106: // Use this to detect playback state: 0 - stopped, 1 - playing n@1106: this.status = 0; n@1106: n@1106: // Connect both gains to output n@1106: this.outputGain.connect(audioContext.destination); n@1106: this.fooGain.connect(audioContext.destination); n@1106: n@1106: // Create the timer Object n@1106: this.timer = new timer(); n@1106: // Create session metrics n@1106: this.metric = new sessionMetrics(this,specification); n@1106: n@1106: this.loopPlayback = false; n@1106: n@1106: this.pageStore = null; n@1106: n@1106: // Create store for new audioObjects n@1106: this.audioObjects = []; n@1106: n@1106: this.buffers = []; n@1106: this.bufferObj = function() n@1106: { n@1106: this.url = null; n@1106: this.buffer = null; n@1106: this.xmlRequest = new XMLHttpRequest(); n@1106: this.xmlRequest.parent = this; n@1106: this.users = []; n@1106: this.progress = 0; n@1106: this.status = 0; n@1106: this.ready = function() n@1106: { n@1106: if (this.status >= 2) n@1106: { n@1106: this.status = 3; n@1106: } n@1106: for (var i=0; i 0) {this.wasMoved = true;} n@1106: this.movementTracker[this.movementTracker.length] = [time, position]; n@1106: }; n@1106: n@1106: this.startListening = function(time) n@1106: { n@1106: if (this.listenHold == false) n@1106: { n@1106: this.wasListenedTo = true; n@1106: this.listenStart = time; n@1106: this.listenHold = true; n@1106: n@1106: var evnt = document.createElement('event'); n@1106: var testTime = document.createElement('testTime'); n@1106: testTime.setAttribute('start',time); n@1106: var bufferTime = document.createElement('bufferTime'); n@1106: bufferTime.setAttribute('start',this.parent.getCurrentPosition()); n@1106: evnt.appendChild(testTime); n@1106: evnt.appendChild(bufferTime); n@1106: this.listenTracker.push(evnt); n@1106: n@1106: console.log('slider ' + this.parent.id + ' played (' + time + ')'); // DEBUG/SAFETY: show played slider id n@1106: } n@1106: }; n@1106: n@1106: this.stopListening = function(time,bufferStopTime) n@1106: { n@1106: if (this.listenHold == true) n@1106: { n@1106: var diff = time - this.listenStart; n@1106: this.listenedTimer += (diff); n@1106: this.listenStart = 0; n@1106: this.listenHold = false; n@1106: n@1106: var evnt = this.listenTracker[this.listenTracker.length-1]; n@1106: var testTime = evnt.getElementsByTagName('testTime')[0]; n@1106: var bufferTime = evnt.getElementsByTagName('bufferTime')[0]; n@1106: testTime.setAttribute('stop',time); n@1106: if (bufferStopTime == undefined) { n@1106: bufferTime.setAttribute('stop',this.parent.getCurrentPosition()); n@1106: } else { n@1106: bufferTime.setAttribute('stop',bufferStopTime); n@1106: } n@1106: console.log('slider ' + this.parent.id + ' played for (' + diff + ')'); // DEBUG/SAFETY: show played slider id n@1106: } n@1106: }; n@1106: n@1106: this.exportXMLDOM = function() { n@1106: var storeDOM = []; n@1106: if (audioEngineContext.metric.enableElementTimer) { n@1106: var mElementTimer = storage.document.createElement('metricresult'); n@1106: mElementTimer.setAttribute('name','enableElementTimer'); n@1106: mElementTimer.textContent = this.listenedTimer; n@1106: storeDOM.push(mElementTimer); n@1106: } n@1106: if (audioEngineContext.metric.enableElementTracker) { n@1106: var elementTrackerFull = storage.document.createElement('metricResult'); n@1106: elementTrackerFull.setAttribute('name','elementTrackerFull'); n@1106: for (var k=0; k n@1106: // DD/MM/YY n@1106: // n@1106: // n@1106: var dateTime = new Date(); n@1106: var year = document.createAttribute('year'); n@1106: var month = document.createAttribute('month'); n@1106: var day = document.createAttribute('day'); n@1106: var hour = document.createAttribute('hour'); n@1106: var minute = document.createAttribute('minute'); n@1106: var secs = document.createAttribute('secs'); n@1106: n@1106: year.nodeValue = dateTime.getFullYear(); n@1106: month.nodeValue = dateTime.getMonth()+1; n@1106: day.nodeValue = dateTime.getDate(); n@1106: hour.nodeValue = dateTime.getHours(); n@1106: minute.nodeValue = dateTime.getMinutes(); n@1106: secs.nodeValue = dateTime.getSeconds(); n@1106: n@1106: var hold = document.createElement("datetime"); n@1106: var date = document.createElement("date"); n@1106: date.textContent = year.nodeValue+'/'+month.nodeValue+'/'+day.nodeValue; n@1106: var time = document.createElement("time"); n@1106: time.textContent = hour.nodeValue+':'+minute.nodeValue+':'+secs.nodeValue; n@1106: n@1106: date.setAttributeNode(year); n@1106: date.setAttributeNode(month); n@1106: date.setAttributeNode(day); n@1106: time.setAttributeNode(hour); n@1106: time.setAttributeNode(minute); n@1106: time.setAttributeNode(secs); n@1106: n@1106: hold.appendChild(date); n@1106: hold.appendChild(time); n@1106: return hold; n@1106: n@1106: } n@1106: n@1106: function Specification() { n@1106: // Handles the decoding of the project specification XML into a simple JavaScript Object. n@1106: n@1106: this.interface = null; n@1106: this.projectReturn = "null"; n@1106: this.randomiseOrder = null; n@1106: this.testPages = null; n@1106: this.pages = []; n@1106: this.metrics = null; n@1106: this.interfaces = null; n@1106: this.loudness = null; n@1106: this.errors = []; n@1106: this.schema = null; n@1106: n@1106: this.processAttribute = function(attribute,schema) n@1106: { n@1106: // attribute is the string returned from getAttribute on the XML n@1106: // schema is the node n@1106: if (schema.getAttribute('name') == undefined && schema.getAttribute('ref') != undefined) n@1106: { n@1106: schema = this.schema.getAllElementsByName(schema.getAttribute('ref'))[0]; n@1106: } n@1106: var defaultOpt = schema.getAttribute('default'); n@1106: if (attribute == null) { n@1106: attribute = defaultOpt; n@1106: } n@1106: var dataType = schema.getAttribute('type'); n@1106: if (typeof dataType == "string") { dataType = dataType.substr(3);} n@1106: else {dataType = "string";} n@1106: if (attribute == null) n@1106: { n@1106: return attribute; n@1106: } n@1106: switch(dataType) n@1106: { n@1106: case "boolean": n@1106: if (attribute == 'true'){attribute = true;}else{attribute=false;} n@1106: break; n@1106: case "negativeInteger": n@1106: case "positiveInteger": n@1106: case "nonNegativeInteger": n@1106: case "nonPositiveInteger": n@1106: case "integer": n@1106: case "decimal": n@1106: case "short": n@1106: attribute = Number(attribute); n@1106: break; n@1106: case "string": n@1106: default: n@1106: attribute = String(attribute); n@1106: break; n@1106: } n@1106: return attribute; n@1106: }; n@1106: n@1106: this.decode = function(projectXML) { n@1106: this.errors = []; n@1106: // projectXML - DOM Parsed document n@1106: this.projectXML = projectXML.childNodes[0]; n@1106: var setupNode = projectXML.getElementsByTagName('setup')[0]; n@1106: var schemaSetup = this.schema.getAllElementsByName('setup')[0]; n@1106: // First decode the attributes n@1106: var attributes = schemaSetup.getAllElementsByTagName('xs:attribute'); n@1106: for (var i in attributes) n@1106: { n@1106: if (isNaN(Number(i)) == true){break;} n@1106: var attributeName = attributes[i].getAttribute('name'); n@1106: var projectAttr = setupNode.getAttribute(attributeName); n@1106: projectAttr = this.processAttribute(projectAttr,attributes[i]); n@1106: switch(typeof projectAttr) n@1106: { n@1106: case "number": n@1106: case "boolean": n@1106: eval('this.'+attributeName+' = '+projectAttr); n@1106: break; n@1106: case "string": n@1106: eval('this.'+attributeName+' = "'+projectAttr+'"'); n@1106: break; n@1106: } n@1106: n@1106: } n@1106: n@1106: this.metrics = new this.metricNode(); n@1106: n@1106: this.metrics.decode(this,setupNode.getElementsByTagName('metric')[0]); n@1106: n@1106: // Now process the survey node options n@1106: var survey = setupNode.getElementsByTagName('survey'); n@1106: for (var i in survey) { n@1106: if (isNaN(Number(i)) == true){break;} n@1106: var location = survey[i].getAttribute('location'); n@1106: if (location == 'pre' || location == 'before') n@1106: { n@1106: if (this.preTest != null){this.errors.push("Already a pre/before test survey defined! Ignoring second!!");} n@1106: else { n@1106: this.preTest = new this.surveyNode(); n@1106: this.preTest.decode(this,survey[i]); n@1106: } n@1106: } else if (location == 'post' || location == 'after') { n@1106: if (this.postTest != null){this.errors.push("Already a post/after test survey defined! Ignoring second!!");} n@1106: else { n@1106: this.postTest = new this.surveyNode(); n@1106: this.postTest.decode(this,survey[i]); n@1106: } n@1106: } n@1106: } n@1106: n@1106: var interfaceNode = setupNode.getElementsByTagName('interface'); n@1106: if (interfaceNode.length > 1) n@1106: { n@1106: this.errors.push("Only one node in the node allowed! Others except first ingnored!"); n@1106: } n@1106: this.interfaces = new this.interfaceNode(); n@1106: if (interfaceNode.length != 0) n@1106: { n@1106: interfaceNode = interfaceNode[0]; n@1106: this.interfaces.decode(this,interfaceNode,this.schema.getAllElementsByName('interface')[1]); n@1106: } n@1106: n@1106: // Page tags n@1106: var pageTags = projectXML.getElementsByTagName('page'); n@1106: var pageSchema = this.schema.getAllElementsByName('page')[0]; n@1106: for (var i=0; i n@1106: var commentboxprefix = root.createElement("commentboxprefix"); n@1106: commentboxprefix.textContent = this.commentBoxPrefix; n@1106: AHNode.appendChild(commentboxprefix); n@1106: n@1106: for (var i=0; i n@1106: for (var i=0; i tag. n@1106: this.interfaceObjects = []; n@1106: this.interfaceObject = function(){}; n@1106: n@1106: this.resizeWindow = function(event) n@1106: { n@1106: popup.resize(event); n@1106: for(var i=0; i= 600) n@1106: { n@1106: boxwidth = 600; n@1106: } n@1106: else if (boxwidth < 400) n@1106: { n@1106: boxwidth = 400; n@1106: } n@1106: this.trackComment.style.width = boxwidth+"px"; n@1106: this.trackCommentBox.style.width = boxwidth-6+"px"; n@1106: }; n@1106: this.resize(); n@1106: }; n@1106: n@1106: this.commentQuestions = []; n@1106: n@1106: this.commentBox = function(commentQuestion) { n@1106: this.specification = commentQuestion; n@1106: // Create document objects to hold the comment boxes n@1106: this.holder = document.createElement('div'); n@1106: this.holder.className = 'comment-div'; n@1106: // Create a string next to each comment asking for a comment n@1106: this.string = document.createElement('span'); n@1106: this.string.innerHTML = commentQuestion.statement; n@1106: // Create the HTML5 comment box 'textarea' n@1106: this.textArea = document.createElement('textarea'); n@1106: this.textArea.rows = '4'; n@1106: this.textArea.cols = '100'; n@1106: this.textArea.className = 'trackComment'; n@1106: var br = document.createElement('br'); n@1106: // Add to the holder. n@1106: this.holder.appendChild(this.string); n@1106: this.holder.appendChild(br); n@1106: this.holder.appendChild(this.textArea); n@1106: n@1106: this.exportXMLDOM = function() { n@1106: var root = document.createElement('comment'); n@1106: root.id = this.specification.id; n@1106: root.setAttribute('type',this.specification.type); n@1106: root.textContent = this.textArea.value; n@1106: console.log("Question: "+this.string.textContent); n@1106: console.log("Response: "+root.textContent); n@1106: return root; n@1106: }; n@1106: this.resize = function() n@1106: { n@1106: var boxwidth = (window.innerWidth-100)/2; n@1106: if (boxwidth >= 600) n@1106: { n@1106: boxwidth = 600; n@1106: } n@1106: else if (boxwidth < 400) n@1106: { n@1106: boxwidth = 400; n@1106: } n@1106: this.holder.style.width = boxwidth+"px"; n@1106: this.textArea.style.width = boxwidth-6+"px"; n@1106: }; n@1106: this.resize(); n@1106: }; n@1106: n@1106: this.radioBox = function(commentQuestion) { n@1106: this.specification = commentQuestion; n@1106: // Create document objects to hold the comment boxes n@1106: this.holder = document.createElement('div'); n@1106: this.holder.className = 'comment-div'; n@1106: // Create a string next to each comment asking for a comment n@1106: this.string = document.createElement('span'); n@1106: this.string.innerHTML = commentQuestion.statement; n@1106: var br = document.createElement('br'); n@1106: // Add to the holder. n@1106: this.holder.appendChild(this.string); n@1106: this.holder.appendChild(br); n@1106: this.options = []; n@1106: this.inputs = document.createElement('div'); n@1106: this.span = document.createElement('div'); n@1106: this.inputs.align = 'center'; n@1106: this.inputs.style.marginLeft = '12px'; n@1106: this.span.style.marginLeft = '12px'; n@1106: this.span.align = 'center'; n@1106: this.span.style.marginTop = '15px'; n@1106: n@1106: var optCount = commentQuestion.options.length; n@1106: for (var optNode of commentQuestion.options) n@1106: { n@1106: var div = document.createElement('div'); n@1106: div.style.width = '80px'; n@1106: div.style.float = 'left'; n@1106: var input = document.createElement('input'); n@1106: input.type = 'radio'; n@1106: input.name = commentQuestion.id; n@1106: input.setAttribute('setvalue',optNode.name); n@1106: input.className = 'comment-radio'; n@1106: div.appendChild(input); n@1106: this.inputs.appendChild(div); n@1106: n@1106: n@1106: div = document.createElement('div'); n@1106: div.style.width = '80px'; n@1106: div.style.float = 'left'; n@1106: div.align = 'center'; n@1106: var span = document.createElement('span'); n@1106: span.textContent = optNode.text; n@1106: span.className = 'comment-radio-span'; n@1106: div.appendChild(span); n@1106: this.span.appendChild(div); n@1106: this.options.push(input); n@1106: } n@1106: this.holder.appendChild(this.span); n@1106: this.holder.appendChild(this.inputs); n@1106: n@1106: this.exportXMLDOM = function() { n@1106: var root = document.createElement('comment'); n@1106: root.id = this.specification.id; n@1106: root.setAttribute('type',this.specification.type); n@1106: var question = document.createElement('question'); n@1106: question.textContent = this.string.textContent; n@1106: var response = document.createElement('response'); n@1106: var i=0; n@1106: while(this.options[i].checked == false) { n@1106: i++; n@1106: if (i >= this.options.length) { n@1106: break; n@1106: } n@1106: } n@1106: if (i >= this.options.length) { n@1106: response.textContent = 'null'; n@1106: } else { n@1106: response.textContent = this.options[i].getAttribute('setvalue'); n@1106: response.setAttribute('number',i); n@1106: } n@1106: console.log('Comment: '+question.textContent); n@1106: console.log('Response: '+response.textContent); n@1106: root.appendChild(question); n@1106: root.appendChild(response); n@1106: return root; n@1106: }; n@1106: this.resize = function() n@1106: { n@1106: var boxwidth = (window.innerWidth-100)/2; n@1106: if (boxwidth >= 600) n@1106: { n@1106: boxwidth = 600; n@1106: } n@1106: else if (boxwidth < 400) n@1106: { n@1106: boxwidth = 400; n@1106: } n@1106: this.holder.style.width = boxwidth+"px"; n@1106: var text = this.holder.children[2]; n@1106: var options = this.holder.children[3]; n@1106: var optCount = options.children.length; n@1106: var spanMargin = Math.floor(((boxwidth-20-(optCount*80))/(optCount))/2)+'px'; n@1106: var options = options.firstChild; n@1106: var text = text.firstChild; n@1106: options.style.marginRight = spanMargin; n@1106: options.style.marginLeft = spanMargin; n@1106: text.style.marginRight = spanMargin; n@1106: text.style.marginLeft = spanMargin; n@1106: while(options.nextSibling != undefined) n@1106: { n@1106: options = options.nextSibling; n@1106: text = text.nextSibling; n@1106: options.style.marginRight = spanMargin; n@1106: options.style.marginLeft = spanMargin; n@1106: text.style.marginRight = spanMargin; n@1106: text.style.marginLeft = spanMargin; n@1106: } n@1106: }; n@1106: this.resize(); n@1106: }; n@1106: n@1106: this.checkboxBox = function(commentQuestion) { n@1106: this.specification = commentQuestion; n@1106: // Create document objects to hold the comment boxes n@1106: this.holder = document.createElement('div'); n@1106: this.holder.className = 'comment-div'; n@1106: // Create a string next to each comment asking for a comment n@1106: this.string = document.createElement('span'); n@1106: this.string.innerHTML = commentQuestion.statement; n@1106: var br = document.createElement('br'); n@1106: // Add to the holder. n@1106: this.holder.appendChild(this.string); n@1106: this.holder.appendChild(br); n@1106: this.options = []; n@1106: this.inputs = document.createElement('div'); n@1106: this.span = document.createElement('div'); n@1106: this.inputs.align = 'center'; n@1106: this.inputs.style.marginLeft = '12px'; n@1106: this.span.style.marginLeft = '12px'; n@1106: this.span.align = 'center'; n@1106: this.span.style.marginTop = '15px'; n@1106: n@1106: var optCount = commentQuestion.options.length; n@1106: for (var i=0; i= 600) n@1106: { n@1106: boxwidth = 600; n@1106: } n@1106: else if (boxwidth < 400) n@1106: { n@1106: boxwidth = 400; n@1106: } n@1106: this.holder.style.width = boxwidth+"px"; n@1106: var text = this.holder.children[2]; n@1106: var options = this.holder.children[3]; n@1106: var optCount = options.children.length; n@1106: var spanMargin = Math.floor(((boxwidth-20-(optCount*80))/(optCount))/2)+'px'; n@1106: var options = options.firstChild; n@1106: var text = text.firstChild; n@1106: options.style.marginRight = spanMargin; n@1106: options.style.marginLeft = spanMargin; n@1106: text.style.marginRight = spanMargin; n@1106: text.style.marginLeft = spanMargin; n@1106: while(options.nextSibling != undefined) n@1106: { n@1106: options = options.nextSibling; n@1106: text = text.nextSibling; n@1106: options.style.marginRight = spanMargin; n@1106: options.style.marginLeft = spanMargin; n@1106: text.style.marginRight = spanMargin; n@1106: text.style.marginLeft = spanMargin; n@1106: } n@1106: }; n@1106: this.resize(); n@1106: }; n@1106: n@1106: this.createCommentBox = function(audioObject) { n@1106: var node = new this.elementCommentBox(audioObject); n@1106: this.commentBoxes.push(node); n@1106: audioObject.commentDOM = node; n@1106: return node; n@1106: }; n@1106: n@1106: this.sortCommentBoxes = function() { n@1106: this.commentBoxes.sort(function(a,b){return a.id - b.id;}); n@1106: }; n@1106: n@1106: this.showCommentBoxes = function(inject, sort) { n@1106: if (sort) {interfaceContext.sortCommentBoxes();} n@1106: for (var box of interfaceContext.commentBoxes) { n@1106: inject.appendChild(box.trackComment); n@1106: } n@1106: }; n@1106: n@1106: this.deleteCommentBoxes = function() { n@1106: this.commentBoxes = []; n@1106: }; n@1106: n@1106: this.createCommentQuestion = function(element) { n@1106: var node; n@1106: if (element.type == 'question') { n@1106: node = new this.commentBox(element); n@1106: } else if (element.type == 'radio') { n@1106: node = new this.radioBox(element); n@1106: } else if (element.type == 'checkbox') { n@1106: node = new this.checkboxBox(element); n@1106: } n@1106: this.commentQuestions.push(node); n@1106: return node; n@1106: }; n@1106: n@1106: this.deleteCommentQuestions = function() n@1106: { n@1106: this.commentQuestions = []; n@1106: }; n@1106: n@1106: this.playhead = new function() n@1106: { n@1106: this.object = document.createElement('div'); n@1106: this.object.className = 'playhead'; n@1106: this.object.align = 'left'; n@1106: var curTime = document.createElement('div'); n@1106: curTime.style.width = '50px'; n@1106: this.curTimeSpan = document.createElement('span'); n@1106: this.curTimeSpan.textContent = '00:00'; n@1106: curTime.appendChild(this.curTimeSpan); n@1106: this.object.appendChild(curTime); n@1106: this.scrubberTrack = document.createElement('div'); n@1106: this.scrubberTrack.className = 'playhead-scrub-track'; n@1106: n@1106: this.scrubberHead = document.createElement('div'); n@1106: this.scrubberHead.id = 'playhead-scrubber'; n@1106: this.scrubberTrack.appendChild(this.scrubberHead); n@1106: this.object.appendChild(this.scrubberTrack); n@1106: n@1106: this.timePerPixel = 0; n@1106: this.maxTime = 0; n@1106: n@1106: this.playbackObject; n@1106: n@1106: this.setTimePerPixel = function(audioObject) { n@1106: //maxTime must be in seconds n@1106: this.playbackObject = audioObject; n@1106: this.maxTime = audioObject.buffer.buffer.duration; n@1106: var width = 490; //500 - 10, 5 each side of the tracker head n@1106: this.timePerPixel = this.maxTime/490; n@1106: if (this.maxTime < 60) { n@1106: this.curTimeSpan.textContent = '0.00'; n@1106: } else { n@1106: this.curTimeSpan.textContent = '00:00'; n@1106: } n@1106: }; n@1106: n@1106: this.update = function() { n@1106: // Update the playhead position, startPlay must be called n@1106: if (this.timePerPixel > 0) { n@1106: var time = this.playbackObject.getCurrentPosition(); n@1106: if (time > 0 && time < this.maxTime) { n@1106: var width = 490; n@1106: var pix = Math.floor(time/this.timePerPixel); n@1106: this.scrubberHead.style.left = pix+'px'; n@1106: if (this.maxTime > 60.0) { n@1106: var secs = time%60; n@1106: var mins = Math.floor((time-secs)/60); n@1106: secs = secs.toString(); n@1106: secs = secs.substr(0,2); n@1106: mins = mins.toString(); n@1106: this.curTimeSpan.textContent = mins+':'+secs; n@1106: } else { n@1106: time = time.toString(); n@1106: this.curTimeSpan.textContent = time.substr(0,4); n@1106: } n@1106: } else { n@1106: this.scrubberHead.style.left = '0px'; n@1106: if (this.maxTime < 60) { n@1106: this.curTimeSpan.textContent = '0.00'; n@1106: } else { n@1106: this.curTimeSpan.textContent = '00:00'; n@1106: } n@1106: } n@1106: } n@1106: }; n@1106: n@1106: this.interval = undefined; n@1106: n@1106: this.start = function() { n@1106: if (this.playbackObject != undefined && this.interval == undefined) { n@1106: if (this.maxTime < 60) { n@1106: this.interval = setInterval(function(){interfaceContext.playhead.update();},10); n@1106: } else { n@1106: this.interval = setInterval(function(){interfaceContext.playhead.update();},100); n@1106: } n@1106: } n@1106: }; n@1106: this.stop = function() { n@1106: clearInterval(this.interval); n@1106: this.interval = undefined; n@1106: if (this.maxTime < 60) { n@1106: this.curTimeSpan.textContent = '0.00'; n@1106: } else { n@1106: this.curTimeSpan.textContent = '00:00'; n@1106: } n@1106: }; n@1106: }; n@1106: n@1106: this.volume = new function() n@1106: { n@1106: // An in-built volume module which can be viewed on page n@1106: // Includes trackers on page-by-page data n@1106: // Volume does NOT reset to 0dB on each page load n@1106: this.valueLin = 1.0; n@1106: this.valueDB = 0.0; n@1106: this.object = document.createElement('div'); n@1106: this.object.id = 'master-volume-holder'; n@1106: this.slider = document.createElement('input'); n@1106: this.slider.id = 'master-volume-control'; n@1106: this.slider.type = 'range'; n@1106: this.valueText = document.createElement('span'); n@1106: this.valueText.id = 'master-volume-feedback'; n@1106: this.valueText.textContent = '0dB'; n@1106: n@1106: this.slider.min = -60; n@1106: this.slider.max = 12; n@1106: this.slider.value = 0; n@1106: this.slider.step = 1; n@1106: this.slider.onmousemove = function(event) n@1106: { n@1106: interfaceContext.volume.valueDB = event.currentTarget.value; n@1106: interfaceContext.volume.valueLin = decibelToLinear(interfaceContext.volume.valueDB); n@1106: interfaceContext.volume.valueText.textContent = interfaceContext.volume.valueDB+'dB'; n@1106: audioEngineContext.outputGain.gain.value = interfaceContext.volume.valueLin; n@1106: } n@1106: this.slider.onmouseup = function(event) n@1106: { n@1106: var storePoint = testState.currentStore.XMLDOM.children[0].getAllElementsByName('volumeTracker'); n@1106: if (storePoint.length == 0) n@1106: { n@1106: storePoint = storage.document.createElement('metricresult'); n@1106: storePoint.setAttribute('name','volumeTracker'); n@1106: testState.currentStore.XMLDOM.children[0].appendChild(storePoint); n@1106: } n@1106: else { n@1106: storePoint = storePoint[0]; n@1106: } n@1106: var node = storage.document.createElement('movement'); n@1106: node.setAttribute('test-time',audioEngineContext.timer.getTestTime()); n@1106: node.setAttribute('volume',interfaceContext.volume.valueDB); n@1106: node.setAttribute('format','dBFS'); n@1106: storePoint.appendChild(node); n@1106: } n@1106: n@1106: var title = document.createElement('div'); n@1106: title.innerHTML = 'Master Volume Control'; n@1106: title.style.fontSize = '0.75em'; n@1106: title.style.width = "100%"; n@1106: title.align = 'center'; n@1106: this.object.appendChild(title); n@1106: n@1106: this.object.appendChild(this.slider); n@1106: this.object.appendChild(this.valueText); n@1106: } n@1106: // Global Checkers n@1106: // These functions will help enforce the checkers n@1106: this.checkHiddenAnchor = function() n@1106: { n@1106: for (var ao of audioEngineContext.audioObjects) n@1106: { n@1106: if (ao.specification.type == "anchor") n@1106: { n@1106: if (ao.interfaceDOM.getValue() > (ao.specification.marker/100) && ao.specification.marker > 0) { n@1106: // Anchor is not set below n@1106: console.log('Anchor node not below marker value'); n@1106: alert('Please keep listening'); n@1106: this.storeErrorNode('Anchor node not below marker value'); n@1106: return false; n@1106: } n@1106: } n@1106: } n@1106: return true; n@1106: }; n@1106: n@1106: this.checkHiddenReference = function() n@1106: { n@1106: for (var ao of audioEngineContext.audioObjects) n@1106: { n@1106: if (ao.specification.type == "reference") n@1106: { n@1106: if (ao.interfaceDOM.getValue() < (ao.specification.marker/100) && ao.specification.marker > 0) { n@1106: // Anchor is not set below n@1106: console.log('Reference node not above marker value'); n@1106: this.storeErrorNode('Reference node not above marker value'); n@1106: alert('Please keep listening'); n@1106: return false; n@1106: } n@1106: } n@1106: } n@1106: return true; n@1106: }; n@1106: n@1106: this.checkFragmentsFullyPlayed = function () n@1106: { n@1106: // Checks the entire file has been played back n@1106: // NOTE ! This will return true IF playback is Looped!!! n@1106: if (audioEngineContext.loopPlayback) n@1106: { n@1106: console.log("WARNING - Looped source: Cannot check fragments are fully played"); n@1106: return true; n@1106: } n@1106: var check_pass = true; n@1106: var error_obj = []; n@1106: for (var i = 0; i= time) n@1106: { n@1106: passed = true; n@1106: break; n@1106: } n@1106: } n@1106: if (passed == false) n@1106: { n@1106: check_pass = false; n@1106: console.log("Continue listening to track-"+audioEngineContext.audioObjects.interfaceDOM.getPresentedId()); n@1106: error_obj.push(audioEngineContext.audioObjects.interfaceDOM.getPresentedId()); n@1106: } n@1106: } n@1106: if (check_pass == false) n@1106: { n@1106: var str_start = "You have not completely listened to fragments "; n@1106: for (var i=0; i 0) n@1106: { n@1106: aeNode.setAttribute('marker',element.marker); n@1106: } n@1106: } n@1106: var ae_metric = this.parent.document.createElement('metric'); n@1106: aeNode.appendChild(ae_metric); n@1106: this.XMLDOM.appendChild(aeNode); n@1106: } n@1106: n@1106: // Add any commentQuestions n@1106: for (var element of this.specification.commentQuestions) n@1106: { n@1106: var cqNode = this.parent.document.createElement('commentquestion'); n@1106: cqNode.id = element.id; n@1106: cqNode.setAttribute('type',element.type); n@1106: var statement = this.parent.document.createElement('statement'); n@1106: statement.textContent = cqNode.statement; n@1106: cqNode.appendChild(statement); n@1106: var response = this.parent.document.createElement('response'); n@1106: cqNode.appendChild(response); n@1106: this.XMLDOM.appendChild(cqNode); n@1106: } n@1106: n@1106: this.parent.root.appendChild(this.XMLDOM); n@1106: }; n@1106: this.finish = function() n@1106: { n@1106: if (this.state == 0) n@1106: { n@1106: var projectDocument = specification.projectXML; n@1106: projectDocument.setAttribute('file-name',url); n@1106: this.root.appendChild(projectDocument); n@1106: this.root.appendChild(returnDateNode()); n@1106: this.root.appendChild(interfaceContext.returnNavigator()); n@1106: } n@1106: this.state = 1; n@1106: return this.root; n@1106: }; n@1106: }