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@1124: var schemaXSD; // Hold the parsed schema XSD n@911: var specification; n@912: var interfaceContext; n@1124: var storage; 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: n@1118: n@1118: // Add a prototype to the bufferSourceNode to reference to the audioObject holding it n@1118: AudioBufferSourceNode.prototype.owner = undefined; n@1193: // Add a prototype to the bufferSourceNode to hold when the object was given a play command n@1193: AudioBufferSourceNode.prototype.playbackStartTime = undefined; n@1118: // Add a prototype to the bufferNode to hold the desired LINEAR gain n@1120: AudioBuffer.prototype.playbackGain = undefined; n@1118: // Add a prototype to the bufferNode to hold the computed LUFS loudness n@1118: AudioBuffer.prototype.lufs = undefined; n@1118: n@1148: // Firefox does not have an XMLDocument.prototype.getElementsByName n@1148: // and there is no searchAll style command, this custom function will n@1148: // search all children recusrively for the name. Used for XSD where all n@1148: // element nodes must have a name and therefore can pull the schema node n@1148: XMLDocument.prototype.getAllElementsByName = function(name) n@1148: { n@1148: name = String(name); n@1148: var selected = this.documentElement.getAllElementsByName(name); n@1148: return selected; n@1148: } n@1148: n@1148: Element.prototype.getAllElementsByName = function(name) n@1148: { n@1148: name = String(name); n@1148: var selected = []; n@1148: var node = this.firstElementChild; n@1148: while(node != null) n@1148: { n@1148: if (node.getAttribute('name') == name) n@1148: { n@1148: selected.push(node); n@1148: } n@1148: if (node.childElementCount > 0) n@1148: { n@1148: selected = selected.concat(node.getAllElementsByName(name)); n@1148: } n@1148: node = node.nextElementSibling; n@1148: } n@1148: return selected; n@1148: } n@1148: n@1148: XMLDocument.prototype.getAllElementsByTagName = function(name) n@1148: { n@1148: name = String(name); n@1148: var selected = this.documentElement.getAllElementsByTagName(name); n@1148: return selected; n@1148: } n@1148: n@1148: Element.prototype.getAllElementsByTagName = function(name) n@1148: { n@1148: name = String(name); n@1148: var selected = []; n@1148: var node = this.firstElementChild; n@1148: while(node != null) n@1148: { n@1148: if (node.nodeName == name) n@1148: { n@1148: selected.push(node); n@1148: } n@1148: if (node.childElementCount > 0) n@1148: { n@1148: selected = selected.concat(node.getAllElementsByTagName(name)); n@1148: } n@1148: node = node.nextElementSibling; n@1148: } n@1148: return selected; n@1148: } n@1148: n@1148: // Firefox does not have an XMLDocument.prototype.getElementsByName n@1148: if (typeof XMLDocument.prototype.getElementsByName != "function") { n@1148: XMLDocument.prototype.getElementsByName = function(name) n@1148: { n@1148: name = String(name); n@1148: var node = this.documentElement.firstElementChild; n@1148: var selected = []; n@1148: while(node != null) n@1148: { n@1148: if (node.getAttribute('name') == name) n@1148: { n@1148: selected.push(node); n@1148: } n@1148: node = node.nextElementSibling; n@1148: } n@1148: return selected; n@1148: } n@1148: } n@1148: 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@1170: n@1170: // Create the specification object n@911: specification = new Specification(); n@912: n@912: // Create the interface object n@912: interfaceContext = new Interface(specification); n@1124: n@1124: // Create the storage object n@1124: storage = new Storage(); n@773: // Define window callbacks for interface n@773: window.onresize = function(event){interfaceContext.resizeWindow(event);}; 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@1124: var xmlhttp = new XMLHttpRequest(); n@1124: xmlhttp.open("GET",'test-schema.xsd',true); n@1124: xmlhttp.onload = function() n@1124: { n@1124: schemaXSD = xmlhttp.response; n@1124: var parse = new DOMParser(); n@1124: specification.schema = parse.parseFromString(xmlhttp.response,'text/xml'); n@1124: var r = new XMLHttpRequest(); n@1124: r.open('GET',url,true); n@1124: r.onload = function() { n@1124: loadProjectSpecCallback(r.response); n@1124: }; n@1202: r.onerror = function() { n@1202: document.getElementsByTagName('body')[0].innerHTML = null; n@1202: var msg = document.createElement("h3"); n@1202: msg.textContent = "FATAL ERROR"; n@1202: var span = document.createElement("p"); n@1202: span.textContent = "There was an error when loading your XML file. Please check your path in the URL. After the path to this page, there should be '?url=path/to/your/file.xml'. Check the spelling of your filename as well. If you are still having issues, check the log of the python server or your webserver distribution for 404 codes for your file."; n@1202: document.getElementsByTagName('body')[0].appendChild(msg); n@1202: document.getElementsByTagName('body')[0].appendChild(span); n@1202: } n@1124: r.send(); n@771: }; n@1124: xmlhttp.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@1124: // First perform XML schema validation n@1124: var Module = { n@1124: xml: response, n@1124: schema: schemaXSD, n@1124: arguments:["--noout", "--schema", 'test-schema.xsd','document.xml'] n@1124: }; n@1124: n@1124: var xmllint = validateXML(Module); n@1124: console.log(xmllint); n@1124: if(xmllint != 'document.xml validates\n') n@1124: { n@1124: document.getElementsByTagName('body')[0].innerHTML = null; n@1124: var msg = document.createElement("h3"); n@1124: msg.textContent = "FATAL ERROR"; n@1124: var span = document.createElement("h4"); n@1124: span.textContent = "The XML validator returned the following errors when decoding your XML file"; n@1124: document.getElementsByTagName('body')[0].appendChild(msg); n@1124: document.getElementsByTagName('body')[0].appendChild(span); n@1124: xmllint = xmllint.split('\n'); n@1124: for (var i in xmllint) n@1124: { n@1124: document.getElementsByTagName('body')[0].appendChild(document.createElement('br')); n@1124: var span = document.createElement("span"); n@1124: span.textContent = xmllint[i]; n@1124: document.getElementsByTagName('body')[0].appendChild(span); n@1124: } n@1124: return; n@1124: } n@1124: 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@1124: storage.initialise(); n@1139: /// CHECK FOR SAMPLE RATE COMPATIBILITY n@1139: if (specification.sampleRate != undefined) { n@1139: if (Number(specification.sampleRate) != audioContext.sampleRate) { n@1139: 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@1139: alert(errStr); n@1139: return; n@1139: } n@1139: } 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@1129: switch(specification.interface) n@1129: { n@1129: case "APE": n@1141: interfaceJS.setAttribute("src","interfaces/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@1141: css.href = 'interfaces/ape.css'; n@771: n@771: document.getElementsByTagName("head")[0].appendChild(css); n@1129: break; n@1129: n@1129: case "MUSHRA": n@1141: interfaceJS.setAttribute("src","interfaces/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@1141: css.href = 'interfaces/mushra.css'; n@771: n@771: document.getElementsByTagName("head")[0].appendChild(css); n@1129: break; n@1129: n@1129: case "AB": n@1141: interfaceJS.setAttribute("src","interfaces/AB.js"); n@1129: n@1129: // AB comes with a css file n@1129: var css = document.createElement('link'); n@1129: css.rel = 'stylesheet'; n@1129: css.type = 'text/css'; n@1141: css.href = 'interfaces/AB.css'; n@1129: n@1129: document.getElementsByTagName("head")[0].appendChild(css); n@1145: break; n@1145: case "Bipolar": n@1145: case "ACR": n@1145: case "DCR": n@1145: case "CCR": n@1143: case "ABC": n@1143: // Above enumerate to horizontal sliders n@1143: interfaceJS.setAttribute("src","interfaces/horizontal-sliders.js"); n@1143: n@1143: // horizontal-sliders comes with a css file n@1143: var css = document.createElement('link'); n@1143: css.rel = 'stylesheet'; n@1143: css.type = 'text/css'; n@1143: css.href = 'interfaces/horizontal-sliders.css'; n@1143: n@1143: document.getElementsByTagName("head")[0].appendChild(css); n@1145: break; n@1145: case "discrete": n@1145: case "likert": n@1145: // Above enumerate to horizontal discrete radios n@1145: interfaceJS.setAttribute("src","interfaces/discrete.js"); n@1145: n@1145: // horizontal-sliders comes with a css file n@1145: var css = document.createElement('link'); n@1145: css.rel = 'stylesheet'; n@1145: css.type = 'text/css'; n@1145: css.href = 'interfaces/discrete.css'; n@1145: n@1145: document.getElementsByTagName("head")[0].appendChild(css); n@1145: break; 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@1124: $(specification.pages).each(function(index,elem){ n@773: $(elem.audioElements).each(function(i,audioElem){ n@1124: var URL = elem.hostURL + audioElem.url; n@773: var buffer = null; n@773: for (var i=0; i max_w) n@1182: max_w = w; n@1161: index++; nicholas@918: } n@1182: max_w += 12; n@1182: this.popupResponse.style.textAlign=""; n@1182: var leftP = ((max_w/500)/2)*100; n@1182: this.popupResponse.style.left=leftP+"%"; n@1124: } else if (node.specification.type == 'radio') { n@1161: if (node.response == undefined) { n@1161: node.response = {name: "", text: ""}; n@1161: } n@1161: var index = 0; n@1182: var max_w = 0; n@1124: for (var option of node.specification.options) { nicholas@919: var input = document.createElement('input'); nicholas@919: input.id = option.name; nicholas@919: input.type = 'radio'; n@1124: input.name = node.specification.id; nicholas@919: var span = document.createElement('span'); nicholas@919: span.textContent = option.text; nicholas@919: var hold = document.createElement('div'); nicholas@919: hold.setAttribute('name','option'); nicholas@919: hold.style.padding = '4px'; nicholas@919: hold.appendChild(input); nicholas@919: hold.appendChild(span); n@1124: this.popupResponse.appendChild(hold); n@1161: if (input.id == node.response.name) { n@1161: input.checked = "true"; n@1161: } n@1182: var w = $(span).width(); n@1182: if (w > max_w) n@1182: max_w = w; nicholas@919: } n@1182: max_w += 12; n@1182: this.popupResponse.style.textAlign=""; n@1182: var leftP = ((max_w/500)/2)*100; n@1182: this.popupResponse.style.left=leftP+"%"; n@1124: } else if (node.specification.type == 'number') { n@903: var input = document.createElement('input'); nicholas@1038: input.type = 'textarea'; n@1124: if (node.min != null) {input.min = node.specification.min;} n@1124: if (node.max != null) {input.max = node.specification.max;} n@1124: if (node.step != null) {input.step = node.specification.step;} n@1161: if (node.response != undefined) { n@1161: input.value = node.response; n@1161: } n@856: this.popupResponse.appendChild(input); n@1182: this.popupResponse.style.textAlign="center"; n@1182: this.popupResponse.style.left="0%"; nicholas@952: } n@1028: if(this.currentIndex+1 == this.popupOptions.length) { n@1124: if (this.node.location == "pre") { nicholas@861: this.buttonProceed.textContent = 'Start'; nicholas@861: } else { nicholas@861: this.buttonProceed.textContent = 'Submit'; nicholas@861: } n@1028: } else { n@1028: this.buttonProceed.textContent = 'Next'; n@1028: } n@1028: if(this.currentIndex > 0) n@856: this.buttonPrevious.style.visibility = 'visible'; n@856: else n@856: this.buttonPrevious.style.visibility = 'hidden'; n@1009: }; nicholas@952: n@1124: this.initState = function(node,store) { nicholas@952: //Call this with your preTest and postTest nodes when needed to nicholas@952: // initialise the popup procedure. n@1124: if (node.options.length > 0) { n@1124: this.popupOptions = []; n@1124: this.node = node; n@1124: this.store = store; n@1124: for (var opt of node.options) n@1124: { n@1124: this.popupOptions.push({ n@1124: specification: opt, n@1124: response: null n@1124: }); n@1124: } 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@1124: if (node.specification.type == 'question') { nicholas@952: // Must extract the question data nicholas@952: var textArea = $(popup.popupContent).find('textarea')[0]; n@1124: if (node.specification.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 n@1124: console.log("Question: "+ node.specification.statement); nicholas@953: console.log("Question Response: "+ textArea.value); n@1124: node.response = textArea.value; nicholas@952: } n@1124: } else if (node.specification.type == 'checkbox') { nicholas@918: // Must extract checkbox data n@1126: console.log("Checkbox: "+ node.specification.statement); n@1124: var inputs = this.popupResponse.getElementsByTagName('input'); n@1124: node.response = []; n@1124: 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@1124: node.response = input.value; 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(); n@1124: for (var node of this.popupOptions) n@1124: { n@1124: this.store.postResult(node); 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: this.postNode(); n@1028: } n@1028: }; n@784: n@784: this.resize = function(event) n@784: { n@784: // Called on window resize; n@1144: if (this.popup != null) { n@1144: this.popup.style.left = (window.innerWidth/2)-250 + 'px'; n@1144: this.popup.style.top = (window.innerHeight/2)-125 + 'px'; n@1144: var blank = document.getElementsByClassName('testHalt')[0]; n@1144: blank.style.width = window.innerWidth; n@1144: blank.style.height = window.innerHeight; n@1144: } n@784: }; n@1198: this.hideNextButton = function() { n@1198: this.buttonProceed.style.visibility = "hidden"; n@1198: } n@1198: this.hidePreviousButton = function() { n@1198: this.buttonPrevious.style.visibility = "hidden"; n@1198: } n@1198: this.showNextButton = function() { n@1198: this.buttonProceed.style.visibility = "visible"; n@1198: } n@1198: this.showPreviousButton = function() { n@1198: this.buttonPrevious.style.visibility = "visible"; n@1198: } nicholas@951: } nicholas@951: nicholas@952: function advanceState() nicholas@951: { nicholas@964: // Just for complete clarity nicholas@964: testState.advanceState(); nicholas@964: } nicholas@964: nicholas@964: function stateMachine() nicholas@964: { nicholas@964: // Object prototype for tracking and managing the test state nicholas@964: this.stateMap = []; n@1124: this.preTestSurvey = null; n@1124: this.postTestSurvey = null; nicholas@964: this.stateIndex = null; n@1124: this.currentStateMap = null; n@1124: this.currentStatePosition = null; n@1154: this.currentStore = null; nicholas@964: this.initialise = function(){ n@1124: n@1124: // Get the data from Specification n@1124: var pageHolder = []; n@1124: for (var page of specification.pages) n@1124: { n@1180: var repeat = page.repeatCount; n@1180: while(repeat >= 0) n@1180: { n@1180: pageHolder.push(page); n@1180: repeat--; n@1180: } n@1124: } n@1124: if (specification.randomiseOrder) n@1124: { n@1124: pageHolder = randomiseOrder(pageHolder); n@1124: } n@1124: 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: } else { BrechtDeMan@1053: console.log('FATAL - StateMap not correctly constructed. EMPTY_STATE_MAP'); nicholas@952: } nicholas@964: }; nicholas@964: this.advanceState = function(){ nicholas@964: if (this.stateIndex == null) { nicholas@964: this.initialise(); nicholas@964: } nicholas@964: if (this.stateIndex == -1) { n@1142: this.stateIndex++; nicholas@964: console.log('Starting test...'); n@1124: if (this.preTestSurvey != null) n@1124: { n@1124: popup.initState(this.preTestSurvey,storage.globalPreTest); n@1142: } else { n@1142: this.advanceState(); n@1118: } n@1124: } else if (this.stateIndex == this.stateMap.length) n@1124: { n@1124: // All test pages complete, post test n@1124: console.log('Ending test ...'); n@1124: this.stateIndex++; n@1124: if (this.postTestSurvey == null) { n@1124: this.advanceState(); n@1118: } else { n@1124: popup.initState(this.postTestSurvey,storage.globalPostTest); n@1124: } n@1124: } else if (this.stateIndex > this.stateMap.length) n@1124: { n@1124: createProjectSave(specification.projectReturn); nicholas@964: } n@1124: else n@1124: { n@1124: if (this.currentStateMap == null) n@1124: { n@1118: this.currentStateMap = this.stateMap[this.stateIndex]; n@1134: if (this.currentStateMap.randomiseOrder) n@1134: { n@1134: this.currentStateMap.audioElements = randomiseOrder(this.currentStateMap.audioElements); n@1134: } n@1154: this.currentStore = storage.createTestPageStore(this.currentStateMap); n@1124: if (this.currentStateMap.preTest != null) n@1124: { n@1124: this.currentStatePosition = 'pre'; n@1124: popup.initState(this.currentStateMap.preTest,storage.testPages[this.stateIndex].preTest); n@1118: } else { n@1124: this.currentStatePosition = 'test'; n@1124: } n@1124: interfaceContext.newPage(this.currentStateMap,storage.testPages[this.stateIndex]); n@1124: return; nicholas@964: } n@1124: switch(this.currentStatePosition) n@1124: { n@1124: case 'pre': n@1124: this.currentStatePosition = 'test'; n@1124: break; n@1124: case 'test': n@1124: this.currentStatePosition = 'post'; n@1124: // Save the data n@1124: this.testPageCompleted(); n@1124: if (this.currentStateMap.postTest == null) n@1124: { n@1118: this.advanceState(); n@1124: return; nicholas@964: } else { n@1124: popup.initState(this.currentStateMap.postTest,storage.testPages[this.stateIndex].postTest); nicholas@964: } n@1124: break; n@1124: case 'post': n@1124: this.stateIndex++; n@1124: this.currentStateMap = null; n@1124: this.advanceState(); n@1124: break; n@1124: }; nicholas@964: } nicholas@964: }; nicholas@964: n@1124: this.testPageCompleted = function() { nicholas@964: // Function called each time a test page has been completed n@1124: var storePoint = storage.testPages[this.stateIndex]; n@1124: // First get the test metric n@1124: n@1124: var metric = storePoint.XMLDOM.getElementsByTagName('metric')[0]; n@775: if (audioEngineContext.metric.enableTestTimer) n@775: { n@1124: var testTime = storePoint.parent.document.createElement('metricresult'); n@775: testTime.id = 'testTime'; n@775: testTime.textContent = audioEngineContext.timer.testDuration; n@775: metric.appendChild(testTime); n@775: } n@1124: n@775: var audioObjects = audioEngineContext.audioObjects; n@1124: for (var ao of audioEngineContext.audioObjects) n@775: { n@1124: ao.exportXMLDOM(); n@775: } n@1124: for (var element of interfaceContext.commentQuestions) n@1124: { n@1124: element.exportXMLDOM(storePoint); n@1124: } n@1124: pageXMLSave(storePoint.XMLDOM, this.currentStateMap); n@906: }; 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: n@1124: this.pageStore = null; n@1124: 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@1116: this.progress = 0; n@1116: this.status = 0; n@1142: this.ready = function() n@1142: { n@1116: if (this.status >= 2) n@1116: { n@1116: this.status = 3; n@1116: } n@1142: for (var i=0; i 0) {this.wasMoved = true;} n@673: this.movementTracker[this.movementTracker.length] = [time, position]; n@673: }; n@673: nicholas@967: this.startListening = function(time) n@673: { nicholas@947: if (this.listenHold == false) n@673: { n@673: this.wasListenedTo = true; n@673: this.listenStart = time; nicholas@947: this.listenHold = true; n@1013: n@1013: var evnt = document.createElement('event'); n@1013: var testTime = document.createElement('testTime'); n@1013: testTime.setAttribute('start',time); n@1013: var bufferTime = document.createElement('bufferTime'); n@1013: bufferTime.setAttribute('start',this.parent.getCurrentPosition()); n@1013: evnt.appendChild(testTime); n@1013: evnt.appendChild(bufferTime); n@1013: this.listenTracker.push(evnt); n@1013: n@932: console.log('slider ' + this.parent.id + ' played (' + time + ')'); // DEBUG/SAFETY: show played slider id n@932: } n@932: }; nicholas@967: n@896: this.stopListening = function(time,bufferStopTime) nicholas@967: { nicholas@967: if (this.listenHold == true) nicholas@967: { n@1013: var diff = time - this.listenStart; n@1013: this.listenedTimer += (diff); n@673: this.listenStart = 0; nicholas@947: this.listenHold = false; n@1013: n@1013: var evnt = this.listenTracker[this.listenTracker.length-1]; n@1013: var testTime = evnt.getElementsByTagName('testTime')[0]; n@1013: var bufferTime = evnt.getElementsByTagName('bufferTime')[0]; n@1013: testTime.setAttribute('stop',time); n@896: if (bufferStopTime == undefined) { n@896: bufferTime.setAttribute('stop',this.parent.getCurrentPosition()); n@896: } else { n@896: bufferTime.setAttribute('stop',bufferStopTime); n@896: } n@1013: console.log('slider ' + this.parent.id + ' played for (' + diff + ')'); // DEBUG/SAFETY: show played slider id n@673: } n@673: }; n@907: n@907: this.exportXMLDOM = function() { n@1124: var storeDOM = []; n@907: if (audioEngineContext.metric.enableElementTimer) { n@1124: var mElementTimer = storage.document.createElement('metricresult'); n@907: mElementTimer.setAttribute('name','enableElementTimer'); n@907: mElementTimer.textContent = this.listenedTimer; n@1124: storeDOM.push(mElementTimer); n@907: } n@907: if (audioEngineContext.metric.enableElementTracker) { n@1124: var elementTrackerFull = storage.document.createElement('metricResult'); n@907: elementTrackerFull.setAttribute('name','elementTrackerFull'); n@907: for (var k=0; k 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@1124: this.interface = null; n@1173: this.projectReturn = "null"; n@1124: this.randomiseOrder = null; n@1124: this.testPages = null; n@1124: this.pages = []; n@1124: this.metrics = null; n@1124: this.interfaces = null; n@1124: this.loudness = null; n@1124: this.errors = []; n@1124: this.schema = null; n@1118: n@1124: this.processAttribute = function(attribute,schema) n@769: { n@1124: // attribute is the string returned from getAttribute on the XML n@1124: // schema is the node n@1124: if (schema.getAttribute('name') == undefined && schema.getAttribute('ref') != undefined) n@769: { n@1148: schema = this.schema.getAllElementsByName(schema.getAttribute('ref'))[0]; n@1124: } n@1124: var defaultOpt = schema.getAttribute('default'); n@1124: if (attribute == null) { n@1124: attribute = defaultOpt; n@1124: } n@1124: var dataType = schema.getAttribute('type'); n@1124: if (typeof dataType == "string") { dataType = dataType.substr(3);} n@1124: else {dataType = "string";} n@1124: if (attribute == null) n@1124: { n@1124: return attribute; n@1124: } n@1124: switch(dataType) n@1124: { n@1124: case "boolean": n@1124: if (attribute == 'true'){attribute = true;}else{attribute=false;} n@1124: break; n@1124: case "negativeInteger": n@1124: case "positiveInteger": n@1124: case "nonNegativeInteger": n@1124: case "nonPositiveInteger": n@1124: case "integer": n@1124: case "decimal": n@1124: case "short": n@1124: attribute = Number(attribute); n@1124: break; n@1124: case "string": n@1124: default: n@1124: attribute = String(attribute); n@1124: break; n@1124: } n@1124: return attribute; n@769: }; n@774: n@769: this.decode = function(projectXML) { n@1124: this.errors = []; n@910: // projectXML - DOM Parsed document nicholas@1046: this.projectXML = projectXML.childNodes[0]; n@910: var setupNode = projectXML.getElementsByTagName('setup')[0]; n@1148: var schemaSetup = this.schema.getAllElementsByName('setup')[0]; n@1124: // First decode the attributes n@1148: var attributes = schemaSetup.getAllElementsByTagName('xs:attribute'); n@1124: for (var i in attributes) n@850: { n@1124: if (isNaN(Number(i)) == true){break;} n@1124: var attributeName = attributes[i].getAttribute('name'); n@1124: var projectAttr = setupNode.getAttribute(attributeName); n@1124: projectAttr = this.processAttribute(projectAttr,attributes[i]); n@1124: switch(typeof projectAttr) n@795: { n@1124: case "number": n@1124: case "boolean": n@1124: eval('this.'+attributeName+' = '+projectAttr); n@1124: break; n@1124: case "string": n@1124: eval('this.'+attributeName+' = "'+projectAttr+'"'); n@1124: break; n@795: } n@1124: n@769: } n@769: n@1170: this.metrics = new this.metricNode(); n@910: n@1124: this.metrics.decode(this,setupNode.getElementsByTagName('metric')[0]); n@1124: n@1124: // Now process the survey node options n@1124: var survey = setupNode.getElementsByTagName('survey'); n@1124: for (var i in survey) { n@1124: if (isNaN(Number(i)) == true){break;} n@1124: var location = survey[i].getAttribute('location'); n@1124: if (location == 'pre' || location == 'before') n@1124: { n@1124: if (this.preTest != null){this.errors.push("Already a pre/before test survey defined! Ignoring second!!");} n@1124: else { n@1124: this.preTest = new this.surveyNode(); n@1170: this.preTest.decode(this,survey[i]); n@1124: } n@1124: } else if (location == 'post' || location == 'after') { n@1124: if (this.postTest != null){this.errors.push("Already a post/after test survey defined! Ignoring second!!");} n@1124: else { n@1124: this.postTest = new this.surveyNode(); n@1170: this.postTest.decode(this,survey[i]); n@1124: } n@910: } n@910: } n@910: n@1124: var interfaceNode = setupNode.getElementsByTagName('interface'); n@1124: if (interfaceNode.length > 1) n@1124: { n@1124: this.errors.push("Only one node in the node allowed! Others except first ingnored!"); n@1124: } n@1124: this.interfaces = new this.interfaceNode(); n@1124: if (interfaceNode.length != 0) n@1124: { n@1124: interfaceNode = interfaceNode[0]; n@1148: this.interfaces.decode(this,interfaceNode,this.schema.getAllElementsByName('interface')[1]); nicholas@886: } nicholas@886: n@1124: // Page tags n@1124: var pageTags = projectXML.getElementsByTagName('page'); n@1148: var pageSchema = this.schema.getAllElementsByName('page')[0]; n@1124: for (var i=0; i n@1172: var commentboxprefix = root.createElement("commentboxprefix"); n@1172: commentboxprefix.textContent = this.commentBoxPrefix; n@1172: AHNode.appendChild(commentboxprefix); n@1172: n@769: for (var i=0; i 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@1209: { n@1209: boxwidth = 600; n@1209: } n@1209: else if (boxwidth < 400) n@1209: { n@1209: boxwidth = 400; n@1209: } n@1209: this.trackComment.style.width = boxwidth+"px"; n@1209: this.trackCommentBox.style.width = boxwidth-6+"px"; n@1209: }; n@1209: this.resize(); n@1209: }; n@1209: this.createCommentBox = function(audioObject) { n@1209: var node = new this.elementCommentBox(audioObject); n@1209: this.boxes.push(node); n@1209: audioObject.commentDOM = node; n@1209: return node; n@1209: }; n@1209: this.sortCommentBoxes = function() { n@1209: this.boxes.sort(function(a,b){return a.id - b.id;}); n@1209: }; n@1209: n@1209: this.showCommentBoxes = function(inject, sort) { n@1209: this.injectPoint = inject; n@1209: if (sort) {this.sortCommentBoxes();} n@1209: for (var box of this.boxes) { n@1209: inject.appendChild(box.trackComment); n@1209: } n@1209: }; n@1209: n@1209: this.deleteCommentBoxes = function() { n@1209: if (this.injectPoint != null) { n@1209: for (var box of this.boxes) { n@1209: this.injectPoint.removeChild(box.trackComment); n@1209: } n@1209: this.injectPoint = null; n@1209: } n@1209: this.boxes = []; n@1209: }; n@1209: } 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@1124: this.string.innerHTML = commentQuestion.statement; 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@1189: this.exportXMLDOM = function(storePoint) { n@1189: var root = storePoint.parent.document.createElement('comment'); n@1026: root.id = this.specification.id; n@1026: root.setAttribute('type',this.specification.type); BrechtDeMan@1053: console.log("Question: "+this.string.textContent); BrechtDeMan@1053: console.log("Response: "+root.textContent); n@1189: var question = storePoint.parent.document.createElement('question'); n@1189: question.textContent = this.string.textContent; n@1189: var response = storePoint.parent.document.createElement('response'); n@1189: response.textContent = this.textArea.value; n@1189: root.appendChild(question); n@1189: root.appendChild(response); n@1189: storePoint.XMLDOM.appendChild(root); 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@1124: for (var optNode of commentQuestion.options) n@1026: { n@1026: var div = document.createElement('div'); n@854: div.style.width = '80px'; n@1026: div.style.float = 'left'; n@1026: var input = document.createElement('input'); n@1026: input.type = 'radio'; n@1026: input.name = commentQuestion.id; n@1124: input.setAttribute('setvalue',optNode.name); n@1026: input.className = 'comment-radio'; n@1026: div.appendChild(input); n@1026: this.inputs.appendChild(div); n@1026: n@1026: n@1026: div = document.createElement('div'); n@854: div.style.width = '80px'; n@1026: div.style.float = 'left'; n@1026: div.align = 'center'; n@1026: var span = document.createElement('span'); n@1124: span.textContent = optNode.text; n@1026: span.className = 'comment-radio-span'; n@1026: div.appendChild(span); n@1026: this.span.appendChild(div); n@1026: this.options.push(input); n@1026: } n@1026: this.holder.appendChild(this.span); n@1026: this.holder.appendChild(this.inputs); n@1026: n@1189: this.exportXMLDOM = function(storePoint) { n@1189: var root = storePoint.parent.document.createElement('comment'); n@1026: root.id = this.specification.id; n@1026: root.setAttribute('type',this.specification.type); n@1026: var question = document.createElement('question'); n@1026: question.textContent = this.string.textContent; n@1026: var response = document.createElement('response'); n@1026: var i=0; n@1026: while(this.options[i].checked == false) { n@1026: i++; n@1026: if (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@1189: storePoint.XMLDOM.appendChild(root); 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: }; nicholas@900: n@1026: this.createCommentQuestion = function(element) { n@1026: var node; n@1124: if (element.type == 'question') { n@1026: node = new this.commentBox(element); n@1026: } else if (element.type == 'radio') { n@1026: node = new this.radioBox(element); n@902: } else if (element.type == 'checkbox') { n@902: node = new this.checkboxBox(element); n@1026: } n@1026: this.commentQuestions.push(node); n@1026: return node; n@1026: }; n@894: nicholas@1045: this.deleteCommentQuestions = function() nicholas@1045: { nicholas@1045: this.commentQuestions = []; nicholas@1045: }; nicholas@1045: n@894: this.playhead = new function() n@894: { n@894: this.object = document.createElement('div'); n@894: this.object.className = 'playhead'; n@894: this.object.align = 'left'; n@894: var curTime = document.createElement('div'); n@894: curTime.style.width = '50px'; n@894: this.curTimeSpan = document.createElement('span'); n@894: this.curTimeSpan.textContent = '00:00'; n@894: curTime.appendChild(this.curTimeSpan); n@894: this.object.appendChild(curTime); n@894: this.scrubberTrack = document.createElement('div'); n@894: this.scrubberTrack.className = 'playhead-scrub-track'; n@894: n@894: this.scrubberHead = document.createElement('div'); n@894: this.scrubberHead.id = 'playhead-scrubber'; n@894: this.scrubberTrack.appendChild(this.scrubberHead); n@894: this.object.appendChild(this.scrubberTrack); n@894: n@894: this.timePerPixel = 0; n@894: this.maxTime = 0; n@894: n@897: this.playbackObject; n@897: n@897: this.setTimePerPixel = function(audioObject) { n@894: //maxTime must be in seconds n@897: this.playbackObject = audioObject; n@773: this.maxTime = audioObject.buffer.buffer.duration; n@894: var width = 490; //500 - 10, 5 each side of the tracker head n@897: this.timePerPixel = this.maxTime/490; n@897: if (this.maxTime < 60) { n@894: this.curTimeSpan.textContent = '0.00'; n@894: } else { n@894: this.curTimeSpan.textContent = '00:00'; n@894: } n@894: }; n@894: n@897: this.update = function() { n@894: // Update the playhead position, startPlay must be called n@894: if (this.timePerPixel > 0) { n@897: var time = this.playbackObject.getCurrentPosition(); n@1167: if (time > 0 && time < this.maxTime) { 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; n@1193: 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@897: }; n@894: }; n@1154: n@1154: this.volume = new function() n@1154: { n@1154: // An in-built volume module which can be viewed on page n@1154: // Includes trackers on page-by-page data n@1154: // Volume does NOT reset to 0dB on each page load n@1154: this.valueLin = 1.0; n@1154: this.valueDB = 0.0; n@1154: this.object = document.createElement('div'); n@1154: this.object.id = 'master-volume-holder'; n@1154: this.slider = document.createElement('input'); n@1154: this.slider.id = 'master-volume-control'; n@1154: this.slider.type = 'range'; n@1154: this.valueText = document.createElement('span'); n@1154: this.valueText.id = 'master-volume-feedback'; n@1154: this.valueText.textContent = '0dB'; n@1154: n@1154: this.slider.min = -60; n@1154: this.slider.max = 12; n@1154: this.slider.value = 0; n@1154: this.slider.step = 1; n@1154: this.slider.onmousemove = function(event) n@1154: { n@1154: interfaceContext.volume.valueDB = event.currentTarget.value; n@1154: interfaceContext.volume.valueLin = decibelToLinear(interfaceContext.volume.valueDB); n@1154: interfaceContext.volume.valueText.textContent = interfaceContext.volume.valueDB+'dB'; n@1154: audioEngineContext.outputGain.gain.value = interfaceContext.volume.valueLin; n@1154: } n@1154: this.slider.onmouseup = function(event) n@1154: { n@1192: var storePoint = testState.currentStore.XMLDOM.getElementsByTagName('metric')[0].getAllElementsByName('volumeTracker'); n@1154: if (storePoint.length == 0) n@1154: { n@1154: storePoint = storage.document.createElement('metricresult'); n@1154: storePoint.setAttribute('name','volumeTracker'); n@1192: testState.currentStore.XMLDOM.getElementsByTagName('metric')[0].appendChild(storePoint); n@1154: } n@1154: else { n@1154: storePoint = storePoint[0]; n@1154: } n@1154: var node = storage.document.createElement('movement'); n@1154: node.setAttribute('test-time',audioEngineContext.timer.getTestTime()); n@1154: node.setAttribute('volume',interfaceContext.volume.valueDB); n@1154: node.setAttribute('format','dBFS'); n@1154: storePoint.appendChild(node); n@1154: } n@1154: n@1155: var title = document.createElement('div'); n@1155: title.innerHTML = 'Master Volume Control'; n@1155: title.style.fontSize = '0.75em'; n@1155: title.style.width = "100%"; n@1155: title.align = 'center'; n@1155: this.object.appendChild(title); n@1155: n@1154: this.object.appendChild(this.slider); n@1154: this.object.appendChild(this.valueText); n@1154: } nicholas@1043: // Global Checkers nicholas@1043: // These functions will help enforce the checkers nicholas@1043: this.checkHiddenAnchor = function() nicholas@1043: { n@1124: for (var ao of audioEngineContext.audioObjects) nicholas@1043: { n@1124: if (ao.specification.type == "anchor") nicholas@1043: { n@1125: if (ao.interfaceDOM.getValue() > (ao.specification.marker/100) && ao.specification.marker > 0) { n@1124: // Anchor is not set below n@1124: console.log('Anchor node not below marker value'); n@1124: alert('Please keep listening'); n@1167: this.storeErrorNode('Anchor node not below marker value'); n@1124: return false; n@1124: } nicholas@1043: } nicholas@1043: } nicholas@1043: return true; nicholas@1043: }; nicholas@1043: nicholas@1043: this.checkHiddenReference = function() nicholas@1043: { n@1124: for (var ao of audioEngineContext.audioObjects) nicholas@1043: { n@1124: if (ao.specification.type == "reference") nicholas@1043: { n@1125: if (ao.interfaceDOM.getValue() < (ao.specification.marker/100) && ao.specification.marker > 0) { n@1124: // Anchor is not set below n@1167: console.log('Reference node not above marker value'); n@1167: this.storeErrorNode('Reference node not above marker value'); n@1124: alert('Please keep listening'); n@1124: return false; n@1124: } 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@1140: console.log("Continue listening to track-"+audioEngineContext.audioObjects.interfaceDOM.getPresentedId()); n@1140: error_obj.push(audioEngineContext.audioObjects.interfaceDOM.getPresentedId()); 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 0) n@1124: { n@1124: aeNode.setAttribute('marker',element.marker); n@1124: } n@1124: } n@1124: var ae_metric = this.parent.document.createElement('metric'); n@1124: aeNode.appendChild(ae_metric); n@1124: this.XMLDOM.appendChild(aeNode); n@1124: } n@1124: n@1124: this.parent.root.appendChild(this.XMLDOM); n@1124: }; n@1124: this.finish = function() n@1124: { n@1124: if (this.state == 0) n@1124: { n@1124: var projectDocument = specification.projectXML; n@1124: projectDocument.setAttribute('file-name',url); n@1124: this.root.appendChild(projectDocument); n@1124: this.root.appendChild(returnDateNode()); n@1124: this.root.appendChild(interfaceContext.returnNavigator()); n@1124: } n@1124: this.state = 1; n@1124: return this.root; n@1124: }; n@1124: }