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