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