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