nickjillings@1318: /** nickjillings@1318: * core.js nickjillings@1318: * nickjillings@1318: * Main script to run, calls all other core functions and manages loading/store to backend. nickjillings@1318: * Also contains all global variables. nickjillings@1318: */ nickjillings@1318: nickjillings@1318: /* create the web audio API context and store in audioContext*/ nickjillings@1318: var audioContext; // Hold the browser web audio API nickjillings@1318: var projectXML; // Hold the parsed setup XML nickjillings@1324: var schemaXSD; // Hold the parsed schema XSD nickjillings@1318: var specification; nickjillings@1318: var interfaceContext; nickjillings@1324: var storage; nickjillings@1318: var popup; // Hold the interfacePopup object nickjillings@1318: var testState; nickjillings@1318: var currentTrackOrder = []; // Hold the current XML tracks in their (randomised) order nickjillings@1318: var audioEngineContext; // The custome AudioEngine object nickjillings@1318: var projectReturn; // Hold the URL for the return nickjillings@1318: nickjillings@1318: nickjillings@1318: // Add a prototype to the bufferSourceNode to reference to the audioObject holding it nickjillings@1318: AudioBufferSourceNode.prototype.owner = 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@1318: window.onload = function() { nickjillings@1318: // Function called once the browser has loaded all files. nickjillings@1318: // This should perform any initial commands such as structure / loading documents nickjillings@1318: nickjillings@1318: // Create a web audio API context nickjillings@1318: // Fixed for cross-browser support nickjillings@1318: var AudioContext = window.AudioContext || window.webkitAudioContext; nickjillings@1318: audioContext = new AudioContext; nickjillings@1318: nickjillings@1318: // Create test state nickjillings@1318: testState = new stateMachine(); nickjillings@1318: nickjillings@1318: // Create the popup interface object nickjillings@1318: popup = new interfacePopup(); nickjillings@1318: nickjillings@1318: // Create the specification object nickjillings@1318: specification = new Specification(); nickjillings@1318: nickjillings@1318: // Create the interface object nickjillings@1318: interfaceContext = new Interface(specification); nickjillings@1324: nickjillings@1324: // Create the storage object nickjillings@1324: storage = new Storage(); nickjillings@1318: // Define window callbacks for interface nickjillings@1318: window.onresize = function(event){interfaceContext.resizeWindow(event);}; nickjillings@1318: }; nickjillings@1318: nickjillings@1318: function loadProjectSpec(url) { nickjillings@1318: // Load the project document from the given URL, decode the XML and instruct audioEngine to get audio data nickjillings@1318: // 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@1324: r.send(); nickjillings@1318: }; nickjillings@1324: xmlhttp.send(); nickjillings@1318: }; nickjillings@1318: nickjillings@1318: function loadProjectSpecCallback(response) { nickjillings@1318: // Function called after asynchronous download of XML project specification nickjillings@1318: //var decode = $.parseXML(response); nickjillings@1318: //projectXML = $(decode); nickjillings@1318: 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@1318: var parse = new DOMParser(); nickjillings@1318: projectXML = parse.parseFromString(response,'text/xml'); nickjillings@1318: var errorNode = projectXML.getElementsByTagName('parsererror'); nickjillings@1318: if (errorNode.length >= 1) nickjillings@1318: { nickjillings@1318: var msg = document.createElement("h3"); nickjillings@1318: msg.textContent = "FATAL ERROR"; nickjillings@1318: var span = document.createElement("span"); nickjillings@1318: span.textContent = "The XML parser returned the following errors when decoding your XML file"; nickjillings@1318: document.getElementsByTagName('body')[0].innerHTML = null; nickjillings@1318: document.getElementsByTagName('body')[0].appendChild(msg); nickjillings@1318: document.getElementsByTagName('body')[0].appendChild(span); nickjillings@1318: document.getElementsByTagName('body')[0].appendChild(errorNode[0]); nickjillings@1318: return; nickjillings@1318: } nickjillings@1318: nickjillings@1318: // Build the specification nickjillings@1318: 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@1318: nickjillings@1318: // Detect the interface to use and load the relevant javascripts. nickjillings@1318: var interfaceJS = document.createElement('script'); nickjillings@1318: 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@1318: nickjillings@1318: // APE comes with a css file nickjillings@1318: var css = document.createElement('link'); nickjillings@1318: css.rel = 'stylesheet'; nickjillings@1318: css.type = 'text/css'; nickjillings@1341: css.href = 'interfaces/ape.css'; nickjillings@1318: nickjillings@1318: document.getElementsByTagName("head")[0].appendChild(css); nickjillings@1329: break; nickjillings@1329: nickjillings@1329: case "MUSHRA": nickjillings@1341: interfaceJS.setAttribute("src","interfaces/mushra.js"); nickjillings@1318: nickjillings@1318: // MUSHRA comes with a css file nickjillings@1318: var css = document.createElement('link'); nickjillings@1318: css.rel = 'stylesheet'; nickjillings@1318: css.type = 'text/css'; nickjillings@1341: css.href = 'interfaces/mushra.css'; nickjillings@1318: nickjillings@1318: 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@1318: } nickjillings@1318: document.getElementsByTagName("head")[0].appendChild(interfaceJS); nickjillings@1318: nickjillings@1318: // Create the audio engine object nickjillings@1318: audioEngineContext = new AudioEngine(specification); nickjillings@1318: nickjillings@1324: $(specification.pages).each(function(index,elem){ nickjillings@1318: $(elem.audioElements).each(function(i,audioElem){ nickjillings@1324: var URL = elem.hostURL + audioElem.url; nickjillings@1318: var buffer = null; nickjillings@1318: for (var i=0; i 0) nickjillings@1318: this.buttonPrevious.style.visibility = 'visible'; nickjillings@1318: else nickjillings@1318: this.buttonPrevious.style.visibility = 'hidden'; nickjillings@1318: }; nickjillings@1318: nickjillings@1324: this.initState = function(node,store) { nickjillings@1318: //Call this with your preTest and postTest nodes when needed to nickjillings@1318: // 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@1318: this.currentIndex = 0; nickjillings@1318: this.showPopup(); nickjillings@1318: this.postNode(); nickjillings@1318: } else { nickjillings@1318: advanceState(); nickjillings@1318: } nickjillings@1318: }; nickjillings@1318: nickjillings@1318: this.proceedClicked = function() { nickjillings@1318: // Each time the popup button is clicked! nickjillings@1318: var node = this.popupOptions[this.currentIndex]; nickjillings@1324: if (node.specification.type == 'question') { nickjillings@1318: // Must extract the question data nickjillings@1318: var textArea = $(popup.popupContent).find('textarea')[0]; nickjillings@1324: if (node.specification.mandatory == true && textArea.value.length == 0) { nickjillings@1318: alert('This question is mandatory'); nickjillings@1318: return; nickjillings@1318: } else { nickjillings@1318: // Save the text content nickjillings@1324: console.log("Question: "+ node.specification.statement); nickjillings@1318: console.log("Question Response: "+ textArea.value); nickjillings@1324: node.response = textArea.value; nickjillings@1318: } nickjillings@1324: } else if (node.specification.type == 'checkbox') { nickjillings@1318: // 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@1318: alert('Number is above the maximum value of '+node.max); nickjillings@1318: return; nickjillings@1318: } nickjillings@1324: node.response = input.value; nickjillings@1318: } nickjillings@1318: this.currentIndex++; nickjillings@1318: if (this.currentIndex < this.popupOptions.length) { nickjillings@1318: this.postNode(); nickjillings@1318: } else { nickjillings@1318: // Reached the end of the popupOptions nickjillings@1318: this.hidePopup(); nickjillings@1324: for (var node of this.popupOptions) nickjillings@1324: { nickjillings@1324: this.store.postResult(node); nickjillings@1318: } nickjillings@1318: advanceState(); nickjillings@1318: } nickjillings@1318: }; nickjillings@1318: nickjillings@1318: this.previousClick = function() { nickjillings@1318: // Triggered when the 'Back' button is clicked in the survey nickjillings@1318: if (this.currentIndex > 0) { nickjillings@1318: this.currentIndex--; nickjillings@1318: var node = this.popupOptions[this.currentIndex]; nickjillings@1318: if (node.type != 'statement') { nickjillings@1318: var prevResp = this.responses.childNodes[this.responses.childElementCount-1]; nickjillings@1318: this.responses.removeChild(prevResp); nickjillings@1318: } nickjillings@1318: this.postNode(); nickjillings@1318: if (node.type == 'question') { nickjillings@1318: this.popupContent.getElementsByTagName('textarea')[0].value = prevResp.textContent; nickjillings@1318: } else if (node.type == 'checkbox') { nickjillings@1318: var options = this.popupContent.getElementsByTagName('input'); nickjillings@1318: var savedOptions = prevResp.getElementsByTagName('option'); nickjillings@1318: for (var i=0; i 0) { nickjillings@1318: if(this.stateIndex != null) { nickjillings@1318: console.log('NOTE - State already initialise'); nickjillings@1318: } nickjillings@1318: this.stateIndex = -1; nickjillings@1318: var that = this; nickjillings@1318: var aH_pId = 0; nickjillings@1318: for (var id=0; id this.stateMap.length) nickjillings@1324: { nickjillings@1324: createProjectSave(specification.projectReturn); nickjillings@1324: } 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@1324: 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@1324: } 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@1324: } else { nickjillings@1324: popup.initState(this.currentStateMap.postTest,storage.testPages[this.stateIndex].postTest); nickjillings@1318: } 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@1318: } nickjillings@1318: }; nickjillings@1318: nickjillings@1324: this.testPageCompleted = function() { nickjillings@1318: // 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@1318: if (audioEngineContext.metric.enableTestTimer) nickjillings@1318: { nickjillings@1324: var testTime = storePoint.parent.document.createElement('metricresult'); nickjillings@1318: testTime.id = 'testTime'; nickjillings@1318: testTime.textContent = audioEngineContext.timer.testDuration; nickjillings@1318: metric.appendChild(testTime); nickjillings@1318: } nickjillings@1324: nickjillings@1318: var audioObjects = audioEngineContext.audioObjects; nickjillings@1324: for (var ao of audioEngineContext.audioObjects) nickjillings@1318: { nickjillings@1324: ao.exportXMLDOM(); nickjillings@1318: } 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@1318: }; nickjillings@1318: } nickjillings@1318: nickjillings@1318: function AudioEngine(specification) { nickjillings@1318: nickjillings@1318: // Create two output paths, the main outputGain and fooGain. nickjillings@1318: // Output gain is default to 1 and any items for playback route here nickjillings@1318: // Foo gain is used for analysis to ensure paths get processed, but are not heard nickjillings@1318: // because web audio will optimise and any route which does not go to the destination gets ignored. nickjillings@1318: this.outputGain = audioContext.createGain(); nickjillings@1318: this.fooGain = audioContext.createGain(); nickjillings@1318: this.fooGain.gain = 0; nickjillings@1318: nickjillings@1318: // Use this to detect playback state: 0 - stopped, 1 - playing nickjillings@1318: this.status = 0; nickjillings@1318: nickjillings@1318: // Connect both gains to output nickjillings@1318: this.outputGain.connect(audioContext.destination); nickjillings@1318: this.fooGain.connect(audioContext.destination); nickjillings@1318: nickjillings@1318: // Create the timer Object nickjillings@1318: this.timer = new timer(); nickjillings@1318: // Create session metrics nickjillings@1318: this.metric = new sessionMetrics(this,specification); nickjillings@1318: nickjillings@1318: this.loopPlayback = false; nickjillings@1318: nickjillings@1324: this.pageStore = null; nickjillings@1324: nickjillings@1318: // Create store for new audioObjects nickjillings@1318: this.audioObjects = []; nickjillings@1318: nickjillings@1318: this.buffers = []; nickjillings@1318: this.bufferObj = function() nickjillings@1318: { nickjillings@1318: this.url = null; nickjillings@1318: this.buffer = null; nickjillings@1318: this.xmlRequest = new XMLHttpRequest(); nickjillings@1318: this.xmlRequest.parent = this; nickjillings@1318: this.users = []; nickjillings@1342: this.ready = function() nickjillings@1342: { nickjillings@1342: for (var i=0; i 0) {this.wasMoved = true;} nickjillings@1318: this.movementTracker[this.movementTracker.length] = [time, position]; nickjillings@1318: }; nickjillings@1318: nickjillings@1318: this.startListening = function(time) nickjillings@1318: { nickjillings@1318: if (this.listenHold == false) nickjillings@1318: { nickjillings@1318: this.wasListenedTo = true; nickjillings@1318: this.listenStart = time; nickjillings@1318: this.listenHold = true; nickjillings@1318: nickjillings@1318: var evnt = document.createElement('event'); nickjillings@1318: var testTime = document.createElement('testTime'); nickjillings@1318: testTime.setAttribute('start',time); nickjillings@1318: var bufferTime = document.createElement('bufferTime'); nickjillings@1318: bufferTime.setAttribute('start',this.parent.getCurrentPosition()); nickjillings@1318: evnt.appendChild(testTime); nickjillings@1318: evnt.appendChild(bufferTime); nickjillings@1318: this.listenTracker.push(evnt); nickjillings@1318: nickjillings@1318: console.log('slider ' + this.parent.id + ' played (' + time + ')'); // DEBUG/SAFETY: show played slider id nickjillings@1318: } nickjillings@1318: }; nickjillings@1318: nickjillings@1318: this.stopListening = function(time,bufferStopTime) nickjillings@1318: { nickjillings@1318: if (this.listenHold == true) nickjillings@1318: { nickjillings@1318: var diff = time - this.listenStart; nickjillings@1318: this.listenedTimer += (diff); nickjillings@1318: this.listenStart = 0; nickjillings@1318: this.listenHold = false; nickjillings@1318: nickjillings@1318: var evnt = this.listenTracker[this.listenTracker.length-1]; nickjillings@1318: var testTime = evnt.getElementsByTagName('testTime')[0]; nickjillings@1318: var bufferTime = evnt.getElementsByTagName('bufferTime')[0]; nickjillings@1318: testTime.setAttribute('stop',time); nickjillings@1318: if (bufferStopTime == undefined) { nickjillings@1318: bufferTime.setAttribute('stop',this.parent.getCurrentPosition()); nickjillings@1318: } else { nickjillings@1318: bufferTime.setAttribute('stop',bufferStopTime); nickjillings@1318: } nickjillings@1318: console.log('slider ' + this.parent.id + ' played for (' + diff + ')'); // DEBUG/SAFETY: show played slider id nickjillings@1318: } nickjillings@1318: }; nickjillings@1318: nickjillings@1318: this.exportXMLDOM = function() { nickjillings@1324: var storeDOM = []; nickjillings@1318: if (audioEngineContext.metric.enableElementTimer) { nickjillings@1324: var mElementTimer = storage.document.createElement('metricresult'); nickjillings@1318: mElementTimer.setAttribute('name','enableElementTimer'); nickjillings@1318: mElementTimer.textContent = this.listenedTimer; nickjillings@1324: storeDOM.push(mElementTimer); nickjillings@1318: } nickjillings@1318: if (audioEngineContext.metric.enableElementTracker) { nickjillings@1324: var elementTrackerFull = storage.document.createElement('metricResult'); nickjillings@1318: elementTrackerFull.setAttribute('name','elementTrackerFull'); nickjillings@1318: for (var k=0; k nickjillings@1318: // DD/MM/YY nickjillings@1318: // nickjillings@1318: // nickjillings@1318: var dateTime = new Date(); nickjillings@1318: var year = document.createAttribute('year'); nickjillings@1318: var month = document.createAttribute('month'); nickjillings@1318: var day = document.createAttribute('day'); nickjillings@1318: var hour = document.createAttribute('hour'); nickjillings@1318: var minute = document.createAttribute('minute'); nickjillings@1318: var secs = document.createAttribute('secs'); nickjillings@1318: nickjillings@1318: year.nodeValue = dateTime.getFullYear(); nickjillings@1318: month.nodeValue = dateTime.getMonth()+1; nickjillings@1318: day.nodeValue = dateTime.getDate(); nickjillings@1318: hour.nodeValue = dateTime.getHours(); nickjillings@1318: minute.nodeValue = dateTime.getMinutes(); nickjillings@1318: secs.nodeValue = dateTime.getSeconds(); nickjillings@1318: nickjillings@1318: var hold = document.createElement("datetime"); nickjillings@1318: var date = document.createElement("date"); nickjillings@1318: date.textContent = year.nodeValue+'/'+month.nodeValue+'/'+day.nodeValue; nickjillings@1318: var time = document.createElement("time"); nickjillings@1318: time.textContent = hour.nodeValue+':'+minute.nodeValue+':'+secs.nodeValue; nickjillings@1318: nickjillings@1318: date.setAttributeNode(year); nickjillings@1318: date.setAttributeNode(month); nickjillings@1318: date.setAttributeNode(day); nickjillings@1318: time.setAttributeNode(hour); nickjillings@1318: time.setAttributeNode(minute); nickjillings@1318: time.setAttributeNode(secs); nickjillings@1318: nickjillings@1318: hold.appendChild(date); nickjillings@1318: hold.appendChild(time); nickjillings@1318: return hold; nickjillings@1318: nickjillings@1318: } nickjillings@1318: nickjillings@1318: function Specification() { nickjillings@1318: // Handles the decoding of the project specification XML into a simple JavaScript Object. nickjillings@1318: nickjillings@1324: this.interface = null; nickjillings@1324: 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@1318: this.randomiseOrder = function(input) nickjillings@1318: { nickjillings@1318: // This takes an array of information and randomises the order nickjillings@1318: var N = input.length; nickjillings@1318: nickjillings@1318: var inputSequence = []; // For safety purposes: keep track of randomisation nickjillings@1318: for (var counter = 0; counter < N; ++counter) nickjillings@1318: inputSequence.push(counter) // Fill array nickjillings@1318: var inputSequenceClone = inputSequence.slice(0); nickjillings@1318: nickjillings@1318: var holdArr = []; nickjillings@1318: var outputSequence = []; nickjillings@1318: for (var n=0; n node nickjillings@1324: if (schema.getAttribute('name') == undefined && schema.getAttribute('ref') != undefined) nickjillings@1324: { nickjillings@1324: schema = this.schema.getElementsByName(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@1324: }; nickjillings@1318: nickjillings@1318: this.decode = function(projectXML) { nickjillings@1324: this.errors = []; nickjillings@1318: // projectXML - DOM Parsed document nickjillings@1318: this.projectXML = projectXML.childNodes[0]; nickjillings@1318: var setupNode = projectXML.getElementsByTagName('setup')[0]; nickjillings@1324: var schemaSetup = this.schema.getElementsByName('setup')[0]; nickjillings@1324: // First decode the attributes nickjillings@1324: var attributes = schemaSetup.getElementsByTagName('attribute'); nickjillings@1324: for (var i in attributes) nickjillings@1318: { 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@1318: { 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@1318: } nickjillings@1324: nickjillings@1318: } nickjillings@1318: nickjillings@1324: this.metrics = { nickjillings@1324: enabled: [], nickjillings@1324: decode: function(parent, xml) { nickjillings@1324: var children = xml.getElementsByTagName('metricenable'); nickjillings@1324: for (var i in children) { nickjillings@1324: if (isNaN(Number(i)) == true){break;} nickjillings@1324: this.enabled.push(children[i].textContent); nickjillings@1324: } nickjillings@1324: }, nickjillings@1324: encode: function(root) { nickjillings@1324: var node = root.createElement('metric'); nickjillings@1324: for (var i in this.enabled) nickjillings@1324: { nickjillings@1324: if (isNaN(Number(i)) == true){break;} nickjillings@1324: var child = root.createElement('metricenable'); nickjillings@1324: child.textContent = this.enabled[i]; nickjillings@1324: node.appendChild(child); nickjillings@1324: } nickjillings@1324: return node; nickjillings@1324: } nickjillings@1324: }; nickjillings@1318: 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: var surveySchema = specification.schema.getElementsByName('survey')[0]; 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@1324: this.preTest.decode(this,survey[i],surveySchema); 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@1324: this.postTest.decode(this,survey[i],surveySchema); nickjillings@1324: } nickjillings@1318: } nickjillings@1318: } nickjillings@1318: 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@1324: this.interfaces.decode(this,interfaceNode,this.schema.getElementsByName('interface')[1]); nickjillings@1318: } nickjillings@1318: nickjillings@1324: // Page tags nickjillings@1324: var pageTags = projectXML.getElementsByTagName('page'); nickjillings@1324: var pageSchema = this.schema.getElementsByName('page')[0]; nickjillings@1324: for (var i=0; i nickjillings@1318: for (var i=0; i nickjillings@1318: var AHPreTest = root.createElement("PreTest"); nickjillings@1318: for (var i=0; i tag. nickjillings@1318: this.interfaceObjects = []; nickjillings@1318: this.interfaceObject = function(){}; nickjillings@1318: nickjillings@1318: this.resizeWindow = function(event) nickjillings@1318: { nickjillings@1318: popup.resize(event); nickjillings@1318: for(var i=0; i= 600) nickjillings@1318: { nickjillings@1318: boxwidth = 600; nickjillings@1318: } nickjillings@1318: else if (boxwidth < 400) nickjillings@1318: { nickjillings@1318: boxwidth = 400; nickjillings@1318: } nickjillings@1318: this.trackComment.style.width = boxwidth+"px"; nickjillings@1318: this.trackCommentBox.style.width = boxwidth-6+"px"; nickjillings@1318: }; nickjillings@1318: this.resize(); nickjillings@1318: }; nickjillings@1318: nickjillings@1318: this.commentQuestions = []; nickjillings@1318: nickjillings@1318: this.commentBox = function(commentQuestion) { nickjillings@1318: this.specification = commentQuestion; nickjillings@1318: // Create document objects to hold the comment boxes nickjillings@1318: this.holder = document.createElement('div'); nickjillings@1318: this.holder.className = 'comment-div'; nickjillings@1318: // Create a string next to each comment asking for a comment nickjillings@1318: this.string = document.createElement('span'); nickjillings@1324: this.string.innerHTML = commentQuestion.statement; nickjillings@1318: // Create the HTML5 comment box 'textarea' nickjillings@1318: this.textArea = document.createElement('textarea'); nickjillings@1318: this.textArea.rows = '4'; nickjillings@1318: this.textArea.cols = '100'; nickjillings@1318: this.textArea.className = 'trackComment'; nickjillings@1318: var br = document.createElement('br'); nickjillings@1318: // Add to the holder. nickjillings@1318: this.holder.appendChild(this.string); nickjillings@1318: this.holder.appendChild(br); nickjillings@1318: this.holder.appendChild(this.textArea); nickjillings@1318: nickjillings@1318: this.exportXMLDOM = function() { nickjillings@1318: var root = document.createElement('comment'); nickjillings@1318: root.id = this.specification.id; nickjillings@1318: root.setAttribute('type',this.specification.type); nickjillings@1318: root.textContent = this.textArea.value; nickjillings@1318: console.log("Question: "+this.string.textContent); nickjillings@1318: console.log("Response: "+root.textContent); nickjillings@1318: return root; nickjillings@1318: }; nickjillings@1318: this.resize = function() nickjillings@1318: { nickjillings@1318: var boxwidth = (window.innerWidth-100)/2; nickjillings@1318: if (boxwidth >= 600) nickjillings@1318: { nickjillings@1318: boxwidth = 600; nickjillings@1318: } nickjillings@1318: else if (boxwidth < 400) nickjillings@1318: { nickjillings@1318: boxwidth = 400; nickjillings@1318: } nickjillings@1318: this.holder.style.width = boxwidth+"px"; nickjillings@1318: this.textArea.style.width = boxwidth-6+"px"; nickjillings@1318: }; nickjillings@1318: this.resize(); nickjillings@1318: }; nickjillings@1318: nickjillings@1318: this.radioBox = function(commentQuestion) { nickjillings@1318: this.specification = commentQuestion; nickjillings@1318: // Create document objects to hold the comment boxes nickjillings@1318: this.holder = document.createElement('div'); nickjillings@1318: this.holder.className = 'comment-div'; nickjillings@1318: // Create a string next to each comment asking for a comment nickjillings@1318: this.string = document.createElement('span'); nickjillings@1318: this.string.innerHTML = commentQuestion.statement; nickjillings@1318: var br = document.createElement('br'); nickjillings@1318: // Add to the holder. nickjillings@1318: this.holder.appendChild(this.string); nickjillings@1318: this.holder.appendChild(br); nickjillings@1318: this.options = []; nickjillings@1318: this.inputs = document.createElement('div'); nickjillings@1318: this.span = document.createElement('div'); nickjillings@1318: this.inputs.align = 'center'; nickjillings@1318: this.inputs.style.marginLeft = '12px'; nickjillings@1318: this.span.style.marginLeft = '12px'; nickjillings@1318: this.span.align = 'center'; nickjillings@1318: this.span.style.marginTop = '15px'; nickjillings@1318: nickjillings@1318: var optCount = commentQuestion.options.length; nickjillings@1324: for (var optNode of commentQuestion.options) nickjillings@1318: { nickjillings@1318: var div = document.createElement('div'); nickjillings@1318: div.style.width = '80px'; nickjillings@1318: div.style.float = 'left'; nickjillings@1318: var input = document.createElement('input'); nickjillings@1318: input.type = 'radio'; nickjillings@1318: input.name = commentQuestion.id; nickjillings@1324: input.setAttribute('setvalue',optNode.name); nickjillings@1318: input.className = 'comment-radio'; nickjillings@1318: div.appendChild(input); nickjillings@1318: this.inputs.appendChild(div); nickjillings@1318: nickjillings@1318: nickjillings@1318: div = document.createElement('div'); nickjillings@1318: div.style.width = '80px'; nickjillings@1318: div.style.float = 'left'; nickjillings@1318: div.align = 'center'; nickjillings@1318: var span = document.createElement('span'); nickjillings@1324: span.textContent = optNode.text; nickjillings@1318: span.className = 'comment-radio-span'; nickjillings@1318: div.appendChild(span); nickjillings@1318: this.span.appendChild(div); nickjillings@1318: this.options.push(input); nickjillings@1318: } nickjillings@1318: this.holder.appendChild(this.span); nickjillings@1318: this.holder.appendChild(this.inputs); nickjillings@1318: nickjillings@1318: this.exportXMLDOM = function() { nickjillings@1318: var root = document.createElement('comment'); nickjillings@1318: root.id = this.specification.id; nickjillings@1318: root.setAttribute('type',this.specification.type); nickjillings@1318: var question = document.createElement('question'); nickjillings@1318: question.textContent = this.string.textContent; nickjillings@1318: var response = document.createElement('response'); nickjillings@1318: var i=0; nickjillings@1318: while(this.options[i].checked == false) { nickjillings@1318: i++; nickjillings@1318: if (i >= this.options.length) { nickjillings@1318: break; nickjillings@1318: } nickjillings@1318: } nickjillings@1318: if (i >= this.options.length) { nickjillings@1318: response.textContent = 'null'; nickjillings@1318: } else { nickjillings@1318: response.textContent = this.options[i].getAttribute('setvalue'); nickjillings@1318: response.setAttribute('number',i); nickjillings@1318: } nickjillings@1318: console.log('Comment: '+question.textContent); nickjillings@1318: console.log('Response: '+response.textContent); nickjillings@1318: root.appendChild(question); nickjillings@1318: root.appendChild(response); nickjillings@1318: return root; nickjillings@1318: }; nickjillings@1318: this.resize = function() nickjillings@1318: { nickjillings@1318: var boxwidth = (window.innerWidth-100)/2; nickjillings@1318: if (boxwidth >= 600) nickjillings@1318: { nickjillings@1318: boxwidth = 600; nickjillings@1318: } nickjillings@1318: else if (boxwidth < 400) nickjillings@1318: { nickjillings@1318: boxwidth = 400; nickjillings@1318: } nickjillings@1318: this.holder.style.width = boxwidth+"px"; nickjillings@1318: var text = this.holder.children[2]; nickjillings@1318: var options = this.holder.children[3]; nickjillings@1318: var optCount = options.children.length; nickjillings@1318: var spanMargin = Math.floor(((boxwidth-20-(optCount*80))/(optCount))/2)+'px'; nickjillings@1318: var options = options.firstChild; nickjillings@1318: var text = text.firstChild; nickjillings@1318: options.style.marginRight = spanMargin; nickjillings@1318: options.style.marginLeft = spanMargin; nickjillings@1318: text.style.marginRight = spanMargin; nickjillings@1318: text.style.marginLeft = spanMargin; nickjillings@1318: while(options.nextSibling != undefined) nickjillings@1318: { nickjillings@1318: options = options.nextSibling; nickjillings@1318: text = text.nextSibling; nickjillings@1318: options.style.marginRight = spanMargin; nickjillings@1318: options.style.marginLeft = spanMargin; nickjillings@1318: text.style.marginRight = spanMargin; nickjillings@1318: text.style.marginLeft = spanMargin; nickjillings@1318: } nickjillings@1318: }; nickjillings@1318: this.resize(); nickjillings@1318: }; nickjillings@1318: nickjillings@1318: this.checkboxBox = function(commentQuestion) { nickjillings@1318: this.specification = commentQuestion; nickjillings@1318: // Create document objects to hold the comment boxes nickjillings@1318: this.holder = document.createElement('div'); nickjillings@1318: this.holder.className = 'comment-div'; nickjillings@1318: // Create a string next to each comment asking for a comment nickjillings@1318: this.string = document.createElement('span'); nickjillings@1318: this.string.innerHTML = commentQuestion.statement; nickjillings@1318: var br = document.createElement('br'); nickjillings@1318: // Add to the holder. nickjillings@1318: this.holder.appendChild(this.string); nickjillings@1318: this.holder.appendChild(br); nickjillings@1318: this.options = []; nickjillings@1318: this.inputs = document.createElement('div'); nickjillings@1318: this.span = document.createElement('div'); nickjillings@1318: this.inputs.align = 'center'; nickjillings@1318: this.inputs.style.marginLeft = '12px'; nickjillings@1318: this.span.style.marginLeft = '12px'; nickjillings@1318: this.span.align = 'center'; nickjillings@1318: this.span.style.marginTop = '15px'; nickjillings@1318: nickjillings@1318: var optCount = commentQuestion.options.length; nickjillings@1318: for (var i=0; i= 600) nickjillings@1318: { nickjillings@1318: boxwidth = 600; nickjillings@1318: } nickjillings@1318: else if (boxwidth < 400) nickjillings@1318: { nickjillings@1318: boxwidth = 400; nickjillings@1318: } nickjillings@1318: this.holder.style.width = boxwidth+"px"; nickjillings@1318: var text = this.holder.children[2]; nickjillings@1318: var options = this.holder.children[3]; nickjillings@1318: var optCount = options.children.length; nickjillings@1318: var spanMargin = Math.floor(((boxwidth-20-(optCount*80))/(optCount))/2)+'px'; nickjillings@1318: var options = options.firstChild; nickjillings@1318: var text = text.firstChild; nickjillings@1318: options.style.marginRight = spanMargin; nickjillings@1318: options.style.marginLeft = spanMargin; nickjillings@1318: text.style.marginRight = spanMargin; nickjillings@1318: text.style.marginLeft = spanMargin; nickjillings@1318: while(options.nextSibling != undefined) nickjillings@1318: { nickjillings@1318: options = options.nextSibling; nickjillings@1318: text = text.nextSibling; nickjillings@1318: options.style.marginRight = spanMargin; nickjillings@1318: options.style.marginLeft = spanMargin; nickjillings@1318: text.style.marginRight = spanMargin; nickjillings@1318: text.style.marginLeft = spanMargin; nickjillings@1318: } nickjillings@1318: }; nickjillings@1318: this.resize(); nickjillings@1318: }; nickjillings@1318: nickjillings@1318: this.createCommentBox = function(audioObject) { nickjillings@1318: var node = new this.elementCommentBox(audioObject); nickjillings@1318: this.commentBoxes.push(node); nickjillings@1318: audioObject.commentDOM = node; nickjillings@1318: return node; nickjillings@1318: }; nickjillings@1318: nickjillings@1318: this.sortCommentBoxes = function() { nickjillings@1338: this.commentBoxes.sort(function(a,b){return a.id - b.id;}); nickjillings@1318: }; nickjillings@1318: nickjillings@1318: this.showCommentBoxes = function(inject, sort) { nickjillings@1318: if (sort) {interfaceContext.sortCommentBoxes();} nickjillings@1338: for (var box of interfaceContext.commentBoxes) { nickjillings@1338: inject.appendChild(box.trackComment); nickjillings@1318: } nickjillings@1318: }; nickjillings@1318: nickjillings@1318: this.deleteCommentBoxes = function() { nickjillings@1318: this.commentBoxes = []; nickjillings@1318: }; nickjillings@1318: nickjillings@1318: this.createCommentQuestion = function(element) { nickjillings@1318: var node; nickjillings@1324: if (element.type == 'question') { nickjillings@1318: node = new this.commentBox(element); nickjillings@1318: } else if (element.type == 'radio') { nickjillings@1318: node = new this.radioBox(element); nickjillings@1318: } else if (element.type == 'checkbox') { nickjillings@1318: node = new this.checkboxBox(element); nickjillings@1318: } nickjillings@1318: this.commentQuestions.push(node); nickjillings@1318: return node; nickjillings@1318: }; nickjillings@1318: nickjillings@1318: this.deleteCommentQuestions = function() nickjillings@1318: { nickjillings@1318: this.commentQuestions = []; nickjillings@1318: }; nickjillings@1318: nickjillings@1318: this.playhead = new function() nickjillings@1318: { nickjillings@1318: this.object = document.createElement('div'); nickjillings@1318: this.object.className = 'playhead'; nickjillings@1318: this.object.align = 'left'; nickjillings@1318: var curTime = document.createElement('div'); nickjillings@1318: curTime.style.width = '50px'; nickjillings@1318: this.curTimeSpan = document.createElement('span'); nickjillings@1318: this.curTimeSpan.textContent = '00:00'; nickjillings@1318: curTime.appendChild(this.curTimeSpan); nickjillings@1318: this.object.appendChild(curTime); nickjillings@1318: this.scrubberTrack = document.createElement('div'); nickjillings@1318: this.scrubberTrack.className = 'playhead-scrub-track'; nickjillings@1318: nickjillings@1318: this.scrubberHead = document.createElement('div'); nickjillings@1318: this.scrubberHead.id = 'playhead-scrubber'; nickjillings@1318: this.scrubberTrack.appendChild(this.scrubberHead); nickjillings@1318: this.object.appendChild(this.scrubberTrack); nickjillings@1318: nickjillings@1318: this.timePerPixel = 0; nickjillings@1318: this.maxTime = 0; nickjillings@1318: nickjillings@1318: this.playbackObject; nickjillings@1318: nickjillings@1318: this.setTimePerPixel = function(audioObject) { nickjillings@1318: //maxTime must be in seconds nickjillings@1318: this.playbackObject = audioObject; nickjillings@1318: this.maxTime = audioObject.buffer.buffer.duration; nickjillings@1318: var width = 490; //500 - 10, 5 each side of the tracker head nickjillings@1318: this.timePerPixel = this.maxTime/490; nickjillings@1318: if (this.maxTime < 60) { nickjillings@1318: this.curTimeSpan.textContent = '0.00'; nickjillings@1318: } else { nickjillings@1318: this.curTimeSpan.textContent = '00:00'; nickjillings@1318: } nickjillings@1318: }; nickjillings@1318: nickjillings@1318: this.update = function() { nickjillings@1318: // Update the playhead position, startPlay must be called nickjillings@1318: if (this.timePerPixel > 0) { nickjillings@1318: var time = this.playbackObject.getCurrentPosition(); nickjillings@1318: if (time > 0) { nickjillings@1318: var width = 490; nickjillings@1318: var pix = Math.floor(time/this.timePerPixel); nickjillings@1318: this.scrubberHead.style.left = pix+'px'; nickjillings@1318: if (this.maxTime > 60.0) { nickjillings@1318: var secs = time%60; nickjillings@1318: var mins = Math.floor((time-secs)/60); nickjillings@1318: secs = secs.toString(); nickjillings@1318: secs = secs.substr(0,2); nickjillings@1318: mins = mins.toString(); nickjillings@1318: this.curTimeSpan.textContent = mins+':'+secs; nickjillings@1318: } else { nickjillings@1318: time = time.toString(); nickjillings@1318: this.curTimeSpan.textContent = time.substr(0,4); nickjillings@1318: } nickjillings@1318: } else { nickjillings@1318: this.scrubberHead.style.left = '0px'; nickjillings@1318: if (this.maxTime < 60) { nickjillings@1318: this.curTimeSpan.textContent = '0.00'; nickjillings@1318: } else { nickjillings@1318: this.curTimeSpan.textContent = '00:00'; nickjillings@1318: } nickjillings@1318: } nickjillings@1318: } nickjillings@1318: }; nickjillings@1318: nickjillings@1318: this.interval = undefined; nickjillings@1318: nickjillings@1318: this.start = function() { nickjillings@1318: if (this.playbackObject != undefined && this.interval == undefined) { nickjillings@1318: if (this.maxTime < 60) { nickjillings@1318: this.interval = setInterval(function(){interfaceContext.playhead.update();},10); nickjillings@1318: } else { nickjillings@1318: this.interval = setInterval(function(){interfaceContext.playhead.update();},100); nickjillings@1318: } nickjillings@1318: } nickjillings@1318: }; nickjillings@1318: this.stop = function() { nickjillings@1318: clearInterval(this.interval); nickjillings@1318: this.interval = undefined; nickjillings@1318: if (this.maxTime < 60) { nickjillings@1318: this.curTimeSpan.textContent = '0.00'; nickjillings@1318: } else { nickjillings@1318: this.curTimeSpan.textContent = '00:00'; nickjillings@1318: } nickjillings@1318: }; nickjillings@1318: }; nickjillings@1318: nickjillings@1318: // Global Checkers nickjillings@1318: // These functions will help enforce the checkers nickjillings@1318: this.checkHiddenAnchor = function() nickjillings@1318: { nickjillings@1324: for (var ao of audioEngineContext.audioObjects) nickjillings@1318: { nickjillings@1324: if (ao.specification.type == "anchor") nickjillings@1318: { 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@1324: return false; nickjillings@1324: } nickjillings@1318: } nickjillings@1318: } nickjillings@1318: return true; nickjillings@1318: }; nickjillings@1318: nickjillings@1318: this.checkHiddenReference = function() nickjillings@1318: { nickjillings@1324: for (var ao of audioEngineContext.audioObjects) nickjillings@1318: { nickjillings@1324: if (ao.specification.type == "reference") nickjillings@1318: { 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('Reference node not below marker value'); nickjillings@1324: alert('Please keep listening'); nickjillings@1324: return false; nickjillings@1324: } nickjillings@1318: } nickjillings@1318: } nickjillings@1318: return true; nickjillings@1318: }; nickjillings@1318: nickjillings@1318: this.checkFragmentsFullyPlayed = function () nickjillings@1318: { nickjillings@1318: // Checks the entire file has been played back nickjillings@1318: // NOTE ! This will return true IF playback is Looped!!! nickjillings@1318: if (audioEngineContext.loopPlayback) nickjillings@1318: { nickjillings@1318: console.log("WARNING - Looped source: Cannot check fragments are fully played"); nickjillings@1318: return true; nickjillings@1318: } nickjillings@1318: var check_pass = true; nickjillings@1318: var error_obj = []; nickjillings@1318: for (var i = 0; i= time) nickjillings@1318: { nickjillings@1318: passed = true; nickjillings@1318: break; nickjillings@1318: } nickjillings@1318: } nickjillings@1318: if (passed == false) nickjillings@1318: { nickjillings@1318: 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@1318: } nickjillings@1318: } nickjillings@1318: if (check_pass == false) nickjillings@1318: { nickjillings@1318: var str_start = "You have not completely listened to fragments "; nickjillings@1318: 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: // Add any commentQuestions nickjillings@1324: for (var element of this.specification.commentQuestions) nickjillings@1324: { nickjillings@1324: var cqNode = this.parent.document.createElement('commentquestion'); nickjillings@1324: cqNode.id = element.id; nickjillings@1324: cqNode.setAttribute('type',element.type); nickjillings@1324: var statement = this.parent.document.createElement('statement'); nickjillings@1324: statement.textContent = cqNode.statement; nickjillings@1324: cqNode.appendChild(statement); nickjillings@1324: var response = this.parent.document.createElement('response'); nickjillings@1324: cqNode.appendChild(response); nickjillings@1324: this.XMLDOM.appendChild(cqNode); 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: }