Mercurial > hg > webaudioevaluationtool
view js/min/core.min.js @ 3141:335bc77627e0 tip
fixing discrete interface to allow labels to display
author | Dave Moffat <me@davemoffat.com> |
---|---|
date | Mon, 26 Jul 2021 12:15:24 +0100 |
parents | 90c7b42264d4 |
children |
line wrap: on
line source
function escapeHTML(e){return e.split("&").join("&").split("<").join("<").split('"').join(""")}function qualifyURL(e){var t=document.createElement("div");return t.innerHTML='<a href="'+escapeHTML(e)+'">x</a>',t.firstChild.href}function loadProjectSpec(e){var t=new XMLHttpRequest;t.open("GET","xml/test-schema.xsd",!0),t.onload=function(){specification.processSchema(t.response);var i=new XMLHttpRequest;i.open("GET",e,!0),i.onload=function(){loadProjectSpecCallback(i.response)},i.onerror=function(){document.getElementsByTagName("body")[0].innerHTML=null;var e=document.createElement("h3");e.textContent="FATAL ERROR";var t=document.createElement("p");t.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.",document.getElementsByTagName("body")[0].appendChild(e),document.getElementsByTagName("body")[0].appendChild(t)},i.send()},t.send()}function loadProjectSpecCallback(e){var t,i,n=(new DOMParser).parseFromString(e,"text/xml"),o=n.getElementsByTagName("parsererror");if(o.length>=1)return t=document.createElement("h3"),t.textContent="FATAL ERROR",i=document.createElement("span"),i.textContent="The XML parser returned the following errors when decoding your XML file",document.getElementsByTagName("body")[0].innerHTML=null,document.getElementsByTagName("body")[0].appendChild(t),document.getElementsByTagName("body")[0].appendChild(i),void document.getElementsByTagName("body")[0].appendChild(o[0]);if(void 0===n||void 0===n.firstChild)return t=document.createElement("h3"),t.textContent="FATAL ERROR",i=document.createElement("span"),i.textContent="The project XML was not decoded properly, try refreshing your browser and clearing caches. If the problem persists, contact the test creator.",document.getElementsByTagName("body")[0].innerHTML=null,document.getElementsByTagName("body")[0].appendChild(t),void document.getElementsByTagName("body")[0].appendChild(i);if("waet"==n.firstChild.nodeName){var s={xml:e,schema:specification.getSchemaString(),arguments:["--noout","--schema","test-schema.xsd","document.xml"]};projectXML=n;var r=validateXML(s);if(console.log(r),"document.xml validates\n"!=r){document.getElementsByTagName("body")[0].innerHTML=null,(t=document.createElement("h3")).textContent="FATAL ERROR",(i=document.createElement("h4")).textContent="The XML validator returned the following errors when decoding your XML file",document.getElementsByTagName("body")[0].appendChild(t),document.getElementsByTagName("body")[0].appendChild(i),r=r.split("\n");for(var a in r)document.getElementsByTagName("body")[0].appendChild(document.createElement("br")),(i=document.createElement("span")).textContent=r[a],document.getElementsByTagName("body")[0].appendChild(i);return}specification.decode(projectXML),storage.initialise()}else if("waetresult"==n.firstChild.nodeName){(projectXML=document.implementation.createDocument(null,"waet")).firstChild.appendChild(n.getElementsByTagName("waet")[0].getElementsByTagName("setup")[0].cloneNode(!0));for(var c,l=n.firstChild.firstChild;null!==l;){if("survey"==l.nodeName)if("complete"==l.getAttribute("state"))for(var u=l.getAttribute("location"),h=projectXML.getElementsByTagName("setup")[0].getElementsByTagName("survey")[0];null!==h;){if("pre"==u||"before"==u){if("pre"==h.getAttribute("location")||"before"==h.getAttribute("location")){projectXML.getElementsByTagName("setup")[0].removeChild(h);break}}else if("post"==h.getAttribute("location")||"after"==h.getAttribute("location")){projectXML.getElementsByTagName("setup")[0].removeChild(h);break}h=h.nextElementSibling}else c=l,l=l.previousElementSibling,n.firstChild.removeChild(c);else"page"==l.nodeName&&"empty"==l.getAttribute("state")&&(projectXML.firstChild.appendChild(n.getElementById(l.getAttribute("ref")).cloneNode(!0)),c=l,l=l.previousElementSibling,n.firstChild.removeChild(c));l=l.nextElementSibling}specification.decode(projectXML),storage.initialise(n)}if(isFinite(specification.sampleRate)&&Number(specification.sampleRate)!=audioContext.sampleRate){var p="Sample rates do not match! Requested "+Number(specification.sampleRate)+", got "+audioContext.sampleRate+". Please set the sample rate to match before completing this test.";interfaceContext.lightbox.post("Error",p)}else{var d=new XMLHttpRequest;d.open("GET","interfaces/interfaces.json"),d.onerror=function(e){throw e},d.onload=function(){if(200!==d.status)throw new Error(d.status);var e=specification.interface,t=document.getElementsByTagName("head")[0],i=JSON.parse(d.responseText).interfaces.find(function(t){return t.name==e});if(!i)throw"Cannot load desired interface";i.scripts.forEach(function(e){var i=document.createElement("script");i.setAttribute("type","text/javascript"),i.setAttribute("src",e),t.appendChild(i)}),i.css.forEach(function(e){var i=document.createElement("link");i.setAttribute("rel","stylesheet"),i.setAttribute("type","text/css"),i.setAttribute("href",e),t.appendChild(i)})},d.send(),void 0!==gReturnURL&&(console.log("returnURL Overide from "+specification.returnURL+" to "+gReturnURL),specification.returnURL=gReturnURL),void 0!==gSaveFilenamePrefix&&(specification.saveFilenamePrefix=gSaveFilenamePrefix),audioEngineContext=new AudioEngine(specification)}}function createProjectSave(e){window.onbeforeunload=null;var t=storage.finish(),i=document.createElement("div");i.appendChild(t);var n=[i.innerHTML];if("local"==e){var o=new Blob(n,{type:"application/xml"}),s=window.URL.createObjectURL(o),r=document.createElement("a");r.hidden="",r.href=s,r.download="save.xml",r.textContent="Save File",popup.showPopup(),popup.popupContent.innerHTML="<span>Please save the file below to give to your test supervisor</span><br>",popup.popupContent.appendChild(r)}else{"string"==typeof specification.projectReturn&&"http"==specification.projectReturn.substr(0,4)&&specification.projectReturn,storage.SessionKey.finish().then(function(e){"string"==typeof specification.returnURL&&specification.returnURL.length>0?window.location=specification.returnURL:popup.popupContent.textContent=specification.exitText},function(e){console.log("Save: Error! "+e.textContent),createProjectSave("local")}),popup.showPopup(),popup.popupContent.innerHTML=null,popup.popupContent.textContent="Submitting. Please Wait","function"==typeof popup.hideNextButton&&popup.hideNextButton(),"function"==typeof popup.hidePreviousButton&&popup.hidePreviousButton()}}function errorSessionDump(e){popup.showPopup(),popup.popupContent.innerHTML=null;var t=document.createElement("error"),i=document.createElement("div");"object"==typeof e?(t.appendChild(e),popup.popupContent.appendChild(e)):(t.textContent=e,popup.popupContent.innerHTML="ERROR : "+e);var n=interfaceXMLSave();n.appendChild(t),i.appendChild(n);var o=[i.innerHTML],s=new Blob(o,{type:"application/xml"}),r=window.URL.createObjectURL(s),a=document.createElement("a");a.hidden="",a.href=r,a.download="save.xml",a.textContent="Save File",popup.popupContent.appendChild(a)}function interfaceXMLSave(){return storage.finish()}function linearToDecibel(e){return 20*Math.log10(e)}function decibelToLinear(e){return Math.pow(10,e/20)}function secondsToSamples(e,t){return Math.round(e*t)}function samplesToSeconds(e,t){return e/t}function randomString(e){for(var t="",i=0;i<e;i+=2){t+=Math.floor(1295*Math.random()).toString(36)}return t}function randomiseOrder(e){for(var t=e.length,i=[],n=0;n<t;++n)i.push(n);for(var o=i.slice(0),s=[],r=[],a=0;a<t;a++){var c=Math.random();c=Math.floor(c*e.length),s.push(e.splice(c,1)[0]),r.push(i.splice(c,1)[0])}return console.log(o.toString()),console.log(r.toString()),s}function randomSubArray(e,t){t>e.length&&(t=e.length);for(var i=[];t>0;){var n=Math.floor(Math.random()*e.length);i.push(e.splice(n,1)[0]),t--}return i}function interfacePopup(){function e(e,r){function a(e){var t=this.popupOptions.findIndex(function(t,i,n){return t.specification.id==e},this);this.currentIndex=t-1}var c;if("question"===e.specification.type)c=t;else if("checkbox"===e.specification.type)c=i;else if("radio"===e.specification.type)c=n;else if("number"===e.specification.type)c=o;else{if("slider"!==e.specification.type)return;c=s}for(var l=0;l<e.specification.conditions.length;l++){var u,h=e.specification.conditions[l];if(null!==(u=c(h,r)?h.jumpToOnPass:h.jumpToOnFail)){a.call(this,u);break}}}function t(e,t){switch(e.check){case"equals":if(t==e.value)return!0;break;case"greaterThan":case"lessThan":console.log("Survey Element of type 'question' cannot interpret greaterThan/lessThan conditions. IGNORING");break;case"contains":if(t.includes(e.value))return!0}return!1}function i(e,t){switch(e.check){case"contains":for(var i=0;i<t.length;i++){var n=t[i];if(n.name===e.value&&n.checked)return!0}break;case"equals":case"greaterThan":case"lessThan":console.log("Survey Element of type 'checkbox' cannot interpret equals/greaterThan/lessThan conditions. IGNORING");break;default:console.log("Unknown condition. IGNORING")}return!1}function n(e,t){switch(e.check){case"equals":if(t===e.value)return!0;break;case"contains":case"greaterThan":case"lessThan":console.log("Survey Element of type 'radio' cannot interpret contains/greaterThan/lessThan conditions. IGNORING");break;default:console.log("Unknown condition. IGNORING")}return!1}function o(e,t){var i=i;switch(i.check){case"greaterThan":if(t>Number(i.value))return!0;break;case"lessThan":if(t<Number(i.value))return!0;break;case"equals":if(t==i.value)return!0;break;case"contains":console.log("Survey Element of type 'number' cannot interpret \"contains\" conditions. IGNORING");break;default:console.log("Unknown condition. IGNORING")}return!1}function s(e,t){switch(e.check){case"contains":console.log("Survey Element of type 'number' cannot interpret contains conditions. IGNORING");break;case"greaterThan":if(t>Number(e.value))return!0;break;case"lessThan":if(t<Number(e.value))return!0;break;case"equals":if(t==e.value)return!0;break;default:console.log("Unknown condition. IGNORING")}return!1}this.popup=null,this.popupContent=null,this.popupTitle=null,this.popupResponse=null,this.buttonProceed=null,this.buttonPrevious=null,this.popupOptions=null,this.currentIndex=null,this.node=null,this.store=null;var r;$(window).keypress(function(e){13==e.keyCode&&"visible"==popup.popup.style.visibility&&!1===interfaceContext.lightbox.isVisible()&&(console.log(e),popup.buttonProceed.onclick(),e.preventDefault())}),this.createPopup=function(){document.getElementById("topLevelBody");this.popup=document.getElementById("popupHolder"),this.popup.style.left=window.innerWidth/2-250+"px",this.popup.style.top=window.innerHeight/2-125+"px",this.popupContent=document.getElementById("popupContent"),this.popupTitle=document.getElementById("popupTitleHolder"),this.popupResponse=document.getElementById("popupResponse"),this.buttonProceed=document.getElementById("popup-proceed"),this.buttonProceed.onclick=function(){popup.proceedClicked()},this.buttonPrevious=document.getElementById("popup-previous"),this.buttonPrevious.onclick=function(){popup.previousClick()},this.hidePopup(),this.popup.style.visibility="hidden"},this.showPopup=function(){null===this.popup&&this.createPopup(),this.popup.style.visibility="visible";document.getElementsByClassName("testHalt")[0].style.visibility="visible",this.popupResponse.style.left="0%"},this.hidePopup=function(){if(this.popup){this.popup.style.visibility="hidden";document.getElementsByClassName("testHalt")[0].style.visibility="hidden",this.buttonPrevious.style.visibility="inherit"}},this.postNode=function(){var e=this.popupOptions[this.currentIndex],t=new showdown.Converter,i=new DOMParser;r=new Date,this.popupResponse.innerHTML="",this.popupTitle.innerHTML="";var n=e.specification.statement.split("\n");n.forEach(function(e,t,i){i[t]=e.trim()}),e.specification.statement=n.join("\n");for(var o=i.parseFromString(t.makeHtml(e.specification.statement),"text/html").querySelector("body").children;o.length>0;)this.popupTitle.appendChild(o[0]);"question"==e.specification.type?function(e){var t=document.createElement("textarea");switch(e.specification.boxsize){case"small":t.cols="20",t.rows="1";break;case"normal":t.cols="30",t.rows="2";break;case"large":t.cols="40",t.rows="5";break;case"huge":t.cols="50",t.rows="10"}void 0===e.response?e.response="":t.value=e.response,this.popupResponse.appendChild(t),t.focus(),this.popupResponse.style.textAlign="center",this.popupResponse.style.left="0%"}.call(this,e):"checkbox"==e.specification.type?function(e){null===e.response&&(e.response=[]);var t=document.createElement("table");t.className="popup-option-list",t.border="0";var i=[];e.specification.options.forEach(function(t,n){var o=document.createElement("tr");i.push(o);var s=document.createElement("td");o.appendChild(s);var r=document.createElement("input");r.id=t.name,r.type="checkbox",s.appendChild(r),s=document.createElement("td"),o.appendChild(s);var a=document.createElement("span");a.textContent=t.text,s.appendChild(a),(o=document.createElement("div")).setAttribute("name","option"),o.className="popup-option-checbox";var c;e.response.length>0&&(c=e.response.find(function(e){return e.name==t.name})),void 0!==c?!0===c.checked&&(r.checked="true"):e.response.push({name:t.name,text:t.text,checked:!1})}),e.specification.randomise&&(i=randomiseOrder(i)),i.forEach(function(e){t.appendChild(e)}),this.popupResponse.appendChild(t)}.call(this,e):"radio"==e.specification.type?function(e){null===e.response&&(e.response={name:"",text:""});var t=document.createElement("table");t.className="popup-option-list",t.border="0";var i=[];e.specification.options.forEach(function(t,n){var o=document.createElement("tr");i.push(o);var s=document.createElement("td");o.appendChild(s);var r=document.createElement("input");r.id=t.name,r.type="radio",r.name=e.specification.id,s.appendChild(r),s=document.createElement("td"),o.appendChild(s);var a=document.createElement("span");a.textContent=t.text,s.appendChild(a),(o=document.createElement("div")).setAttribute("name","option"),o.className="popup-option-checkbox",e.response.name===t.name&&(r.checked=!0)}),e.specification.randomise&&(i=randomiseOrder(i)),i.forEach(function(e){t.appendChild(e)}),this.popupResponse.appendChild(t)}.call(this,e):"number"==e.specification.type?function(e){var t=document.createElement("input");t.type="textarea",null!==e.specification.min&&(t.min=e.specification.min),null!==e.specification.max&&(t.max=e.specification.max),null!==e.specification.step&&(t.step=e.specification.step),void 0!==e.response&&(t.value=e.response),this.popupResponse.appendChild(t),this.popupResponse.style.textAlign="center",this.popupResponse.style.left="0%"}.call(this,e):"video"==e.specification.type?function(e){var t=document.createElement("video");t.src=e.specification.url,this.popupResponse.appendChild(t)}.call(this,e):"youtube"==e.specification.type?function(e){var t=document.createElement("iframe");t.className="youtube",t.src=e.specification.url,this.popupResponse.appendChild(t)}.call(this,e):"slider"==e.specification.type&&function(e){var t=document.createElement("div"),i=document.createElement("input");i.type="range",i.style.width="90%",null!==e.specification.min&&(i.min=e.specification.min),null!==e.specification.max&&(i.max=e.specification.max),void 0!==e.response&&(i.value=e.response),t.className="survey-slider-text-holder";var n=document.createElement("span"),o=document.createElement("span");n.textContent=e.specification.leftText,o.textContent=e.specification.rightText,t.appendChild(n),t.appendChild(o),this.popupResponse.appendChild(i),this.popupResponse.appendChild(t),this.popupResponse.style.textAlign="center"}.call(this,e),this.currentIndex+1==this.popupOptions.length?"pre"==this.node.location?this.buttonProceed.textContent="Start":this.buttonProceed.textContent="Submit":this.buttonProceed.textContent="Next",this.currentIndex>0?this.buttonPrevious.style.visibility="visible":this.buttonPrevious.style.visibility="hidden"},this.initState=function(e,t){e.options.length>0?(this.popupOptions=[],this.node=e,this.store=t,e.options.forEach(function(e){this.popupOptions.push({specification:e,response:null})},this),this.currentIndex=0,this.showPopup(),this.postNode()):advanceState()},this.proceedClicked=function(){if(0===testState.stateIndex&&specification.calibration)return interfaceContext.calibrationModuleObject.collect(),void advanceState();var t=this.popupOptions[this.currentIndex],i=!0,n=(new Date-r)/1e3;n<t.specification.minWait?interfaceContext.lightbox.post("Error","Not enough time has elapsed, please wait "+(t.specification.minWait-n).toFixed(0)+" seconds"):(t.elapsedTime=n,"question"==t.specification.type?i=function(t){var i=this.popupResponse.getElementsByTagName("textarea")[0];return!0===t.specification.mandatory&&0===i.value.length?(interfaceContext.lightbox.post("Error","This question is mandatory"),!1):(console.log("Question: "+t.specification.statement),console.log("Question Response: "+i.value),t.response=i.value,e.call(this,t,i.value),!0)}.call(this,t):"checkbox"==t.specification.type?i=function(t){console.log("Checkbox: "+t.specification.statement);var i,n=this.popupResponse.getElementsByTagName("input"),o=0;for(i=0;i<t.specification.options.length;i++)n[i].checked&&o++;if(void 0!==t.specification.min)if(void 0===t.specification.max){if(o<t.specification.min){var s="You must select at least "+t.specification.min+" option";return t.specification.min>1&&(s+="s"),void interfaceContext.lightbox.post("Error",s)}}else if(o<t.specification.min||o>t.specification.max)return t.specification.min==t.specification.max?interfaceContext.lightbox.post("Error","You must only select "+t.specification.min):interfaceContext.lightbox.post("Error","You must select between "+t.specification.min+" and "+t.specification.max),!1;for(i=0;i<t.specification.options.length;i++)t.response.forEach(function(e){var t=this.popupResponse.querySelector("#"+e.name);e.checked=t.checked}),console.log(t.specification.options[i].name+": "+n[i].checked);return e.call(this,t,t.response),!0}.call(this,t):"radio"==t.specification.type?i=function(t){var i=this.popupResponse;console.log("Radio: "+t.specification.statement),t.response=null;for(var n,o=0,s=i.getElementsByTagName("input");void 0===n;){if(o==s.length){if(!0===t.specification.mandatory)return interfaceContext.lightbox.post("Error","Please select one option"),!1;break}!0===s[o].checked&&(n=s[o]),o++}var r=t.specification.options.find(function(e){return n.id==e.name});if(void 0===r)throw interfaceContext.lightbox.post("Error","A configuration error has occured, the test cannot be continued"),"ERROR - Cannot find option";return t.response=r,e.call(this,t,t.response.name),!0}.call(this,t):"number"==t.specification.type?i=function(t){var i=this.popupContent.getElementsByTagName("input")[0];if(!0===t.specification.mandatory&&0===i.value.length)return interfaceContext.lightbox.post("Error","This question is mandatory. Please enter a number"),!1;var n=Number(i.value);return isNaN(n)?(interfaceContext.lightbox.post("Error","Please enter a valid number"),!1):n<t.specification.min&&null!==t.specification.min?(interfaceContext.lightbox.post("Error","Number is below the minimum value of "+t.specification.min),!1):n>t.specification.max&&null!==t.specification.max?(interfaceContext.lightbox.post("Error","Number is above the maximum value of "+t.specification.max),!1):(t.response=i.value,e.call(this,t,t.response),!0)}.call(this,t):"slider"==t.specification.type&&(i=function(t){var i=this.popupContent.getElementsByTagName("input")[0];return t.response=i.value,e.call(this,t,t.response),!0}.call(this,t)),!1!==i&&(this.currentIndex++,this.currentIndex<this.popupOptions.length?this.postNode():(this.popupTitle.innerHTML="",this.popupResponse.innerHTML="",this.hidePopup(),this.popupOptions.forEach(function(e){this.store.postResult(e)},this),this.store.complete(),advanceState())))},this.previousClick=function(){this.currentIndex>0&&(this.currentIndex--,this.postNode())},this.resize=function(e){if(null!==this.popup){this.popup.style.left=window.innerWidth/2-250+"px",this.popup.style.top=window.innerHeight/2-125+"px";var t=document.getElementsByClassName("testHalt")[0];t.style.width=window.innerWidth,t.style.height=window.innerHeight}},this.hideNextButton=function(){this.buttonProceed.style.visibility="hidden"},this.hidePreviousButton=function(){this.buttonPrevious.style.visibility="hidden"},this.showNextButton=function(){this.buttonProceed.style.visibility="visible"},this.showPreviousButton=function(){this.buttonPrevious.style.visibility="visible"}}function advanceState(){testState.advanceState()}function stateMachine(){function e(e,t){var i=[];return e.forEach(function(t,n){t.alwaysInclude&&i.push(e.splice(n,1)[0])}),i.concat(randomSubArray(e,t-i.length))}this.stateMap=[],this.preTestSurvey=null,this.postTestSurvey=null,this.stateIndex=null,this.currentStateMap=null,this.currentStatePosition=null,this.currentStore=null,this.initialise=function(){var t=[];specification.pages.forEach(function(e){(null!==e.position||e.alwaysInclude)&&(e.alwaysInclude=!0),t.push(e)}),specification.numPages>0&&(specification.randomiseOrder=!0,t=e(t,specification.numPages));var i=[];t.forEach(function(e){if(void 0!==e.position){i.push(e);var n=t.indexOf(e);t.splice(n,1)}}),specification.randomiseOrder&&(t=randomiseOrder(t)),i.forEach(function(e){t.splice(e.position,0,e)}),t.forEach(function(t,i){t.presentedId=i,this.stateMap.push(t);t.audioElements;!function(t){var i=[],n=[],o=[];t.audioElements.forEach(function(e){e.label.length>0||void 0!==e.postion?i.push(e):"outside-reference"===e.type?n.push(e):o.push(e)}),(t.poolSize>0||t.randomiseOrder)&&(t.randomiseOrder=!0,0===t.poolSize&&(t.poolSize=t.audioElements.length),t.poolSize-=i.length,o=e(o,t.poolSize)),t.randomiseOrder&&(o=randomiseOrder(o)),i=i.concat(o),t.audioElements=i.concat(n),t.audioElements.forEach(function(e,t){e.position=t})}(t),storage.createTestPageStore(t),audioEngineContext.loadPageData(t)},this),null!==specification.preTest&&(this.preTestSurvey=specification.preTest),null!==specification.postTest&&(this.postTestSurvey=specification.postTest),this.stateMap.length>0?(null!==this.stateIndex&&console.log("NOTE - State already initialise"),this.stateIndex=-2,console.log("Starting test...")):console.log("FATAL - StateMap not correctly constructed. EMPTY_STATE_MAP")},this.advanceState=function(){if(null===this.stateIndex&&this.initialise(),this.stateIndex>-2&&storage.update(),-2==this.stateIndex)this.stateIndex++,void 0!==this.preTestSurvey?popup.initState(this.preTestSurvey,storage.globalPreTest):this.advanceState();else if(-1==this.stateIndex)this.stateIndex++,specification.calibration?(popup.showPopup(),popup.popupTitle.textContent="Calibration. Set the levels so all tones are of equal amplitude. Move your mouse over the sliders to hear the tones. The red slider is the reference tone",interfaceContext.calibrationModuleObject=new interfaceContext.calibrationModule,interfaceContext.calibrationModuleObject.build(popup.popupResponse),popup.hidePreviousButton()):this.advanceState();else if(this.stateIndex==this.stateMap.length)console.log("Ending test ..."),this.stateIndex++,void 0===this.postTestSurvey?this.advanceState():popup.initState(this.postTestSurvey,storage.globalPostTest);else if(this.stateIndex>this.stateMap.length)createProjectSave(specification.projectReturn);else{if(popup.hidePopup(),null===this.currentStateMap)return this.currentStateMap=this.stateMap[this.stateIndex],this.currentStore=storage.testPages[this.stateIndex],void 0!==this.currentStateMap.preTest?(this.currentStatePosition="pre",popup.initState(this.currentStateMap.preTest,storage.testPages[this.stateIndex].preTest)):this.currentStatePosition="test",void interfaceContext.newPage(this.currentStateMap,storage.testPages[this.stateIndex]);switch(this.currentStatePosition){case"pre":this.currentStatePosition="test";break;case"test":if(this.currentStatePosition="post",this.testPageCompleted(),void 0===this.currentStateMap.postTest)return void this.advanceState();popup.initState(this.currentStateMap.postTest,storage.testPages[this.stateIndex].postTest);break;case"post":this.stateIndex++,this.currentStateMap=null,this.advanceState()}}},this.testPageCompleted=function(){var e=storage.testPages[this.stateIndex],t=e.XMLDOM.getElementsByTagName("metric")[0];if(audioEngineContext.metric.enableTestTimer){var i=e.parent.document.createElement("metricresult");i.id="testTime",i.textContent=audioEngineContext.timer.testDuration,t.appendChild(i)}audioEngineContext.audioObjects;audioEngineContext.audioObjects.forEach(function(e){e.exportXMLDOM()}),interfaceContext.commentQuestions.forEach(function(t){t.exportXMLDOM(e)}),pageXMLSave(e.XMLDOM,this.currentStateMap),e.complete()},this.getCurrentTestPage=function(){return this.stateIndex>=0&&this.stateIndex<this.stateMap.length?this.currentStateMap:null},this.getCurrentTestPageStore=function(){return this.stateIndex>=0&&this.stateIndex<this.stateMap.length?this.currentStore:null}}function AudioEngine(e){this.outputGain=audioContext.createGain(),this.fooGain=audioContext.createGain(),this.fooGain.gain.value=0,this.status=0,this.outputGain.connect(audioContext.destination),this.fooGain.connect(audioContext.destination),this.timer=new timer,this.metric=new sessionMetrics(this,e),this.loopPlayback=!1,this.synchPlayback=!1,this.pageSpecification=null,this.pageStore=null;var t=audioContext.createBuffer(1,audioContext.sampleRate,audioContext.sampleRate);this.nullBufferSource=audioContext.createBufferSource(),this.nullBufferSource.buffer=t,this.nullBufferSource.loop=!0,this.nullBufferSource.start(0),this.audioObjects=[],this.buffers=[],this.bufferObj=function(){var e=[];this.buffer=null,this.users=[],this.progress=0,this.status=0,this.ready=function(){this.status>=2&&(this.status=3);for(var e=0;e<this.users.length;e++)this.users[e].state=1,null!==this.users[e].interfaceDOM&&this.users[e].bufferLoaded(this)},this.setUrls=function(t){var i,n=audioContext.sampleRate,o=[];for(i=0;i<t.length;i++)t[i].sampleRate==n&&o.push(t.splice(i,1)[0]);o=o.concat(t),e=o},this.hasUrl=function(t){var i,n=e.length;for(i=0;i<n;i++)if(e[i].url==t)return!0;return!1},this.getMedia=function(){function t(e){return new Promise(function(t,i){var n=new XMLHttpRequest;n.open("GET",e,!0),n.responseType="arraybuffer",n.onload=function(){200==n.status&&t(n.response)},n.onerror=function(){i(new Error(n.statusText))},n.addEventListener("progress",function(e){if(e.lengthComputable){this.progress=e.loaded/e.total;for(var t=0;t<this.users.length;t++)null!==this.users[t].interfaceDOM&&"function"==typeof this.users[t].interfaceDOM.updateLoading&&this.users[t].interfaceDOM.updateLoading(100*this.progress)}}.bind(o)),n.send()})}function i(){if(!(++s>=e.length))return t(e[s].url).then(n.bind(this)).catch(i.bind(this));!function(){this.status=-1;for(var t=0;t<this.users.length;t++)this.users[t].state=-1,null!==this.users[t].interfaceDOM&&this.users[t].bufferLoaded(this);interfaceContext.lightbox.post("Error","Could not load resource "+e[s].url)}()}function n(e){var t=this;return audioContext.decodeAudioData(e,function(e){return t.buffer=e,t.status=2,calculateLoudness(t,"I"),!0},function(i){var n=new WAVE;if(0===n.open(e)){t.buffer=audioContext.createBuffer(n.num_channels,n.num_samples,n.sample_rate);for(var o=0;o<n.num_channels;o++)for(var s=t.buffer.getChannelData(o),r=0;r<n.num_samples;r++)s[r]=n.decoded_data[o][r]}return void 0!==t.buffer?(t.status=2,calculateLoudness(t,"I"),!0):(n=void 0,!1)})}var o=this,s=0;this.progress=0,this.status=1,s=0,t(e[0].url).then(n.bind(o)).catch(i.bind(o))},this.registerAudioObject=function(e){this.users.forEach(function(t){if(e.id==t.id)return 0}),this.users.push(e),3!=this.status&&-1!=this.status||e.bufferLoaded(this)},this.copyBuffer=function(e,t){void 0===e&&(e=0),void 0===t&&(t=0);var i,n=secondsToSamples(e,this.buffer.sampleRate),o=secondsToSamples(t,this.buffer.sampleRate),s=this.buffer.length+n+o,r=audioContext.createBuffer(this.buffer.numberOfChannels,s,this.buffer.sampleRate);if(0===n&&"function"==typeof r.copyToChannel)for(i=0;i<this.buffer.numberOfChannels;i++)r.copyToChannel(this.buffer.getChannelData(i),i);else for(i=0;i<this.buffer.numberOfChannels;i++)for(var a=this.buffer.getChannelData(i),c=r.getChannelData(i),l=0;l<a.length;l++)c[l+n]=a[l];return r.lufs=this.buffer.lufs,r.playbackGain=this.buffer.playbackGain,r},this.cropBuffer=function(e,t){for(var i=Math.floor(e*this.buffer.sampleRate),n=Math.floor(t*this.buffer.sampleRate),o=n-i,s=audioContext.createBuffer(this.buffer.numberOfChannels,o,this.buffer.sampleRate),r=0;r<this.buffer.numberOfChannels;r++){var a=this.buffer.getChannelData(r),c=a.subarray(i,n);if("function"==typeof s.copyToChannel)s.copyToChannel(c,r);else for(var l=s.getChannelData(r),u=0;u<o;u++)l[u]=a[u+i]}return s}},this.loadPageData=function(e){e.audioElements.forEach(function(t){var i=e.hostURL+t.url,n=this.buffers.find(function(e){return e.hasUrl(i)});if(void 0===n){n=new this.bufferObj;var o=[{url:i,sampleRate:t.sampleRate}];t.alternatives.forEach(function(e){o.push({url:e.url,sampleRate:e.sampleRate})}),n.setUrls(o),n.getMedia(),this.buffers.push(n)}},this)},this.play=function(t){if("number"!=typeof t||t<0||t>this.audioObjects.length)throw"FATAL - Passed id was undefined - AudioEngineContext.play(id)";var i=this.audioObjects[t].specification.maxNumberPlays||this.audioObjects[t].specification.parent.maxNumberPlays||e.maxNumberPlays;if(void 0!==i&&this.audioObjects[t].numberOfPlays>=i)interfaceContext.lightbox.post("Error","Cannot play this fragment more than "+i+" times");else if(1===this.status){if(this.timer.startTest(),interfaceContext.playhead.setTimePerPixel(this.audioObjects[t]),this.synchPlayback)(function(t){var i=audioContext.currentTime+.1;e.crossFade,this.audioObjects.forEach(function(e){e.setupPlayback(),e.bufferStart(i),e.id===t?e.listenStart(i):e.listenStop(i)})}).call(this,t);else{if(!1===this.bufferReady(t))return void console.log("Cannot play. Buffer not ready");(function(t){var i=audioContext.currentTime+.1,n=i+e.crossFade;this.audioObjects.forEach(function(e){e.id===t?(e.setupPlayback(),e.bufferStart(i),e.listenStart(i)):(e.listenStop(i),e.bufferStop(n))})}).call(this,t)}interfaceContext.playhead.start()}},this.stop=function(){if(1==this.status){var e=audioContext.currentTime+.1;this.audioObjects.forEach(function(t){t.listenStop(e),t.bufferStop(e)}),interfaceContext.playhead.stop()}},this.newTrack=function(e){var t=this.audioObjects.length;this.audioObjects[t]=new audioObject(t);var i=testState.currentStateMap.hostURL+e.url,n=this.buffers.find(function(e){return e.hasUrl(i)});void 0===n&&(console.log("[WARN]: Buffer was not loaded in pre-test! "+i),n=new this.bufferObj,this.buffers.push(n),n.getMedia(i)),this.audioObjects[t].specification=e,this.audioObjects[t].url=i;for(var o=this.pageStore.XMLDOM.getElementsByTagName("audioelement"),s=0;s<o.length;s++)if(o[s].getAttribute("ref")==e.id){this.audioObjects[t].storeDOM=o[s];break}return n.registerAudioObject(this.audioObjects[t]),this.audioObjects[t]},this.newTestPage=function(e,t){this.pageStore=t,this.pageSpecification=e,this.status=0,this.audioObjectsReady=!1,this.metric.reset(),this.buffers.forEach(function(e){e.users=[]}),this.audioObjects=[],this.timer=new timer,this.loopPlayback=e.loop,this.synchPlayback=e.synchronous,interfaceContext.keyboardInterface.resetKeyBindings()},this.checkAllPlayed=function(){for(var e=[],t=0;t<this.audioObjects.length;t++)!1===this.audioObjects[t].metric.wasListenedTo&&e.push(this.audioObjects[t].id);return e},this.checkAllReady=function(){for(var e=!0,t=0;t<this.audioObjects.length;t++)0===this.audioObjects[t].state&&(console.log("WAIT -- audioObject "+t+" not ready yet!"),e=!1);return e},this.setSynchronousLoop=function(){for(var e=0,t=0;t<this.audioObjects.length;t++)e<this.audioObjects[t].buffer.buffer.duration&&(e=this.audioObjects[t].buffer.buffer.duration,t);this.audioObjects.forEach(function(t){t.buffer.buffer.duration!==e&&(t.buffer.buffer=t.buffer.copyBuffer(0,e-t.buffer.buffer.duration))})},this.bufferReady=function(e){return!!this.checkAllReady()&&(this.synchPlayback&&this.setSynchronousLoop(),this.status=1,!0)}}function audioObject(e){var t=0;this.specification=void 0,this.id=e,this.state=0,this.url=null,this.metric=new metricTracker(this),this.storeDOM=null,this.playing=!1,this.interfaceDOM=null,this.commentDOM=null,this.bufferNode=void 0,this.outputGain=audioContext.createGain(),this.outputGain.gain.value=0,this.onplayGain=1,this.outputGain.connect(audioEngineContext.outputGain),audioEngineContext.nullBufferSource.connect(this.outputGain),this.buffer=void 0,this.bufferLoaded=function(t){if(-1==t.status)return this.state=-1,null!==this.interfaceDOM&&this.interfaceDOM.error(),void(this.buffer=t);this.buffer=t;var i=this.specification.preSilence||this.specification.parent.preSilence||specification.preSilence||0,n=this.specification.postSilence||this.specification.parent.postSilence||specification.postSilence||0,o=this.specification.startTime,s=this.specification.stopTime,r=new t.constructor;r.buffer=t.cropBuffer(o||0,s||t.buffer.duration),0===i&&0===n||(r.buffer=r.copyBuffer(i,n)),r.buffer.lufs=t.buffer.lufs,this.buffer=r;var a=this.specification.loudness||this.specification.parent.loudness||specification.loudness;"number"==typeof a&&isFinite(a)?this.buffer.buffer.playbackGain=decibelToLinear(a-this.buffer.buffer.lufs):this.buffer.buffer.playbackGain=1,null!==this.interfaceDOM&&this.interfaceDOM.enable(),this.onplayGain=decibelToLinear(this.specification.gain)*(this.buffer.buffer.playbackGain||1),this.storeDOM.setAttribute("playGain",linearToDecibel(this.onplayGain)),this.state=1,audioEngineContext.bufferReady(e)},this.bindInterface=function(e){if(this.interfaceDOM=e,this.metric.initialise(e.getValue()),1==this.state)this.interfaceDOM.enable();else if(-1==this.state)return void this.interfaceDOM.error();var t=e.getPresentedId();this.storeDOM.setAttribute("presentedId",t),1==t.length&&interfaceContext.keyboardInterface.registerKeyBinding(t,this)},this.listenStart=function(e){!1===this.playing&&(t++,this.outputGain.gain.linearRampToValueAtTime(this.onplayGain,e),this.metric.startListening(audioEngineContext.timer.getTestTime()),this.bufferNode.playbackStartTime=audioEngineContext.timer.getTestTime(),this.interfaceDOM.startPlayback(),this.playing=!0)},this.listenStop=function(e){!0===this.playing&&(this.outputGain.gain.linearRampToValueAtTime(0,e),this.metric.stopListening(audioEngineContext.timer.getTestTime(),this.getCurrentPosition())),this.interfaceDOM.stopPlayback(),this.playing=!1},this.setupPlayback=function(){void 0===this.bufferNode&&void 0!==this.buffer.buffer&&(this.bufferNode=audioContext.createBufferSource(),this.bufferNode.owner=this,this.bufferNode.connect(this.outputGain),this.bufferNode.buffer=this.buffer.buffer,audioEngineContext.loopPlayback&&(this.bufferNode.loopStart=this.specification.startTime||0,this.bufferNode.loopEnd=this.specification.stopTime-this.specification.startTime||this.buffer.buffer.duration,this.bufferNode.loop=!0),this.bufferNode.onended=function(e){null!==e.currentTarget&&(e.currentTarget.owner.bufferStop(audioContext.currentTime+.1),e.currentTarget.owner.listenStop(audioContext.currentTime+.1))},this.bufferNode.state=0)},this.bufferStart=function(e){this.outputGain.gain.cancelScheduledValues(audioContext.currentTime),this.bufferNode&&0===this.bufferNode.state&&(this.bufferNode.state=1,!0===this.bufferNode.loop?this.bufferNode.start(e):this.bufferNode.start(e,this.specification.startTime||0,this.specification.stopTime-this.specification.startTime||this.buffer.buffer.duration))},this.bufferStop=function(e){this.outputGain.gain.cancelScheduledValues(audioContext.currentTime),void 0!==this.bufferNode&&this.bufferNode.state>0&&(this.bufferNode.stop(e),this.bufferNode=void 0),this.outputGain.gain.linearRampToValueAtTime(0,e),this.interfaceDOM.stopPlayback()},this.getCurrentPosition=function(){var e=audioEngineContext.timer.getTestTime();if(void 0!==this.bufferNode){var t=(e-this.bufferNode.playbackStartTime)%this.buffer.buffer.duration;return isNaN(t)?0:t}return 0},this.exportXMLDOM=function(){var e=storage.document.createElement("file");if(e.setAttribute("sampleRate",this.buffer.buffer.sampleRate),e.setAttribute("channels",this.buffer.buffer.numberOfChannels),e.setAttribute("sampleCount",this.buffer.buffer.length),e.setAttribute("duration",this.buffer.buffer.duration),this.storeDOM.appendChild(e),"outside-reference"!=this.specification.type){var t=this.interfaceDOM.exportXMLDOM(this);if(null!==t)if(void 0===t.length)this.storeDOM.appendChild(t);else for(var i=0;i<t.length;i++)this.storeDOM.appendChild(t[i]);null!==this.commentDOM&&this.storeDOM.appendChild(this.commentDOM.exportXMLDOM(this))}this.metric.exportXMLDOM(this.storeDOM.getElementsByTagName("metric")[0])},Object.defineProperties(this,{numberOfPlays:{get:function(){return t},set:function(){return t}}})}function timer(){this.testStarted=!1,this.testStartTime=0,this.testDuration=0,this.minimumTestTime=0,this.startTest=function(){!1===this.testStarted&&(this.testStartTime=audioContext.currentTime,this.testStarted=!0,this.updateTestTime(),audioEngineContext.metric.initialiseTest())},this.stopTest=function(){this.testStarted?(this.testDuration=this.getTestTime(),this.testStarted=!1):console.log("ERR: Test tried to end before beginning")},this.updateTestTime=function(){this.testStarted&&(this.testDuration=audioContext.currentTime-this.testStartTime)},this.getTestTime=function(){return this.updateTestTime(),this.testDuration}}function sessionMetrics(e,t){this.engine=e,this.lastClicked=-1,this.data=-1,this.reset=function(){this.lastClicked=-1,this.data=-1},this.enableElementInitialPosition=!1,this.enableElementListenTracker=!1,this.enableElementTimer=!1,this.enableElementTracker=!1,this.enableFlagListenedTo=!1,this.enableFlagMoved=!1,this.enableTestTimer=!1;for(var i=0;i<t.metrics.enabled.length;i++){switch(t.metrics.enabled[i]){case"testTimer":this.enableTestTimer=!0;break;case"elementTimer":this.enableElementTimer=!0;break;case"elementTracker":this.enableElementTracker=!0;break;case"elementListenTracker":this.enableElementListenTracker=!0;break;case"elementInitialPosition":this.enableElementInitialPosition=!0;break;case"elementFlagListenedTo":this.enableFlagListenedTo=!0;break;case"elementFlagMoved":this.enableFlagMoved=!0;break;case"elementFlagComments":this.enableFlagComments=!0}}this.initialiseTest=function(){}}function metricTracker(e){this.listenedTimer=0,this.listenStart=0,this.listenHold=!1,this.initialPosition=-1,this.movementTracker=[],this.listenTracker=[],this.wasListenedTo=!1,this.wasMoved=!1,this.hasComments=!1,this.parent=e,this.initialise=function(e){-1==this.initialPosition&&(this.initialPosition=e,this.moved(0,e))},this.moved=function(e,t){e>0&&(this.wasMoved=!0),t!=(this.movementTracker.length>0?this.movementTracker[this.movementTracker.length-1]:-1)[1]&&(this.movementTracker[this.movementTracker.length]=[e,t])},this.startListening=function(e){if(!1===this.listenHold){this.wasListenedTo=!0,this.listenStart=e,this.listenHold=!0;var t=document.createElement("event"),i=document.createElement("testTime");i.setAttribute("start",e);var n=document.createElement("bufferTime");n.setAttribute("start",this.parent.getCurrentPosition()),t.appendChild(i),t.appendChild(n),this.listenTracker.push(t),console.log("slider "+this.parent.id+" played ("+e+")")}},this.stopListening=function(e,t){if(!0===this.listenHold){var i=e-this.listenStart;this.listenedTimer+=i,this.listenStart=0,this.listenHold=!1;var n=this.listenTracker[this.listenTracker.length-1],o=n.getElementsByTagName("testTime")[0],s=n.getElementsByTagName("bufferTime")[0];o.setAttribute("stop",e),void 0===t?s.setAttribute("stop",this.parent.getCurrentPosition()):s.setAttribute("stop",t),console.log("slider "+this.parent.id+" played for ("+i+")")}},this.exportXMLDOM=function(e){var t=[];return audioEngineContext.metric.enableElementTimer&&t.push(function(e){var t=storage.document.createElement("metricresult");return t.setAttribute("name","enableElementTimer"),t.textContent=this.listenedTimer,e.appendChild(t),t}.call(this,e)),audioEngineContext.metric.enableElementTracker&&t.push(function(e){var t=storage.document.createElement("metricresult");t.setAttribute("name","elementTrackerFull");for(var i=0;i<this.movementTracker.length;i++){var n=storage.document.createElement("movement");n.setAttribute("time",this.movementTracker[i][0]),n.setAttribute("value",this.movementTracker[i][1]),t.appendChild(n)}return e.appendChild(t),t}.call(this,e)),audioEngineContext.metric.enableElementListenTracker&&t.push(function(e){var t=storage.document.createElement("metricresult");t.setAttribute("name","elementListenTracker");for(var i=0;i<this.listenTracker.length;i++)t.appendChild(this.listenTracker[i]);return e.appendChild(t),t}.call(this,e)),audioEngineContext.metric.enableElementInitialPosition&&t.push(function(e){var t=storage.document.createElement("metricresult");return t.setAttribute("name","elementInitialPosition"),t.textContent=this.initialPosition,e.appendChild(t),t}.call(this,e)),audioEngineContext.metric.enableFlagListenedTo&&t.push(function(e){var t=storage.document.createElement("metricresult");return t.setAttribute("name","elementFlagListenedTo"),t.textContent=this.wasListenedTo,e.appendChild(t),t}.call(this,e)),audioEngineContext.metric.enableFlagMoved&&t.push(function(e){var t=storage.document.createElement("metricresult");return t.setAttribute("name","elementFlagMoved"),t.textContent=this.wasMoved,e.appendChild(t),t}.call(this,e)),audioEngineContext.metric.enableFlagComments&&t.push(function(e){var t=storage.document.createElement("metricresult");return t.setAttribute("name","elementFlagComments"),null===this.parent.commentDOM?t.textContent="false":0===this.parent.commentDOM.textContent.length?t.textContent="false":t.textContet="true",e.appendChild(t),t}.call(this,e)),t}}function Interface(e){this.specification=e,this.insertPoint=document.getElementById("topLevelBody"),this.newPage=function(e,t){audioEngineContext.newTestPage(e,t),interfaceContext.commentBoxes.deleteCommentBoxes(),interfaceContext.deleteCommentQuestions(),loadTest(e,t)},this.keyboardInterface=function(){var e={keys:[],registerKeyBinding:function(e,t){if("string"!=typeof e||1!=e.length)throw"Key must be a singular character";if(this.keys.findIndex(function(t){return t.key==e})>=0)throw"Key "+e+" already bounded!";return this.keys.push({key:e,audioObject:t}),!0},deregisterKeyBinding:function(e){var t=this.keys.findIndex(function(t){return t.key==e});if(-1==t)throw"Key "+e+" not bounded!";return this.keys.splice(t,1),!0},resetKeyBindings:function(){this.keys=[]},handleEvent:function(e){" "===e.key?audioEngineContext.audioObjects.some(function(e){return e.playing})&&document.activeElement.className.indexOf("trackComment")>=0==!1&&(e.preventDefault(),audioEngineContext.stop()):function(e){var t=this.keys.findIndex(function(t){return t.key==e});t>=0&&audioEngineContext.play(this.keys[t].audioObject.id)}.call(this,e.key),console.log(e)}};return document.addEventListener("keydown",e,!1),e}(),this.interfaceObjects=[],this.interfaceObject=function(){},this.resizeWindow=function(e){popup.resize(e),this.volume.resize(),this.lightbox.resize(),this.commentBoxes.boxes.forEach(function(e){e.resize()}),this.commentQuestions.forEach(function(e){e.resize()});try{resizeWindow(e)}catch(e){console.log("Warning - Interface does not have Resize option"),console.log(e)}},this.returnNavigator=function(){var e=storage.document.createElement("navigator"),t=storage.document.createElement("platform");t.textContent=navigator.platform;var i=storage.document.createElement("vendor");i.textContent=navigator.vendor;var n=storage.document.createElement("uagent");n.textContent=navigator.userAgent;var o=storage.document.createElement("window");return o.setAttribute("innerWidth",window.innerWidth),o.setAttribute("innerHeight",window.innerHeight),e.appendChild(t),e.appendChild(i),e.appendChild(n),e.appendChild(o),e},this.returnDateNode=function(){var e=new Date,t=storage.document.createElement("datetime"),i=storage.document.createElement("date"),n=storage.document.createElement("time");return i.setAttribute("year",e.getFullYear()),i.setAttribute("month",e.getMonth()+1),i.setAttribute("day",e.getDate()),n.setAttribute("hour",e.getHours()),n.setAttribute("minute",e.getMinutes()),n.setAttribute("secs",e.getSeconds()),t.appendChild(i),t.appendChild(n),t},this.lightbox={parent:this,root:document.createElement("div"),content:document.createElement("div"),accept:document.createElement("button"),blanker:document.createElement("div"),post:function(e,t){switch(e){case"Error":this.content.className="lightbox-error";break;case"Warning":this.content.className="lightbox-warning";break;default:this.content.className="lightbox-message"}var i=document.createElement("p");i.textContent=t,this.content.appendChild(i),this.show()},show:function(){this.root.style.visibility="visible",this.blanker.style.visibility="visible",this.accept.focus()},clear:function(){this.root.style.visibility="",this.blanker.style.visibility="",this.content.textContent=""},handleEvent:function(e){e.currentTarget==this.accept&&this.clear()},resize:function(e){this.root.style.left=window.innerWidth/2-250+"px"},isVisible:function(){return"visible"==this.root.style.visibility}},this.lightbox.root.appendChild(this.lightbox.content),this.lightbox.root.appendChild(this.lightbox.accept),this.lightbox.root.className="popupHolder",this.lightbox.root.id="lightbox-root",this.lightbox.accept.className="popupButton",this.lightbox.accept.style.bottom="10px",this.lightbox.accept.textContent="OK",this.lightbox.accept.style.left="237.5px",this.lightbox.accept.addEventListener("click",this.lightbox),this.lightbox.blanker.className="testHalt",this.lightbox.blanker.id="lightbox-blanker",document.getElementsByTagName("body")[0].appendChild(this.lightbox.root),document.getElementsByTagName("body")[0].appendChild(this.lightbox.blanker),this.commentBoxes=function(){var e={};return e.boxes=[],e.injectPoint=null,e.elementCommentBox=function(e){e.specification;this.audioObject=e,this.id=e.id;var t=e.specification.parent;this.trackComment=document.createElement("div"),this.trackComment.className="comment-div",this.trackComment.id="comment-div-"+e.id,this.trackString=document.createElement("span"),this.trackString.innerHTML=t.commentBoxPrefix+" "+e.interfaceDOM.getPresentedId(),this.trackCommentBox=document.createElement("textarea"),this.trackCommentBox.rows="4",this.trackCommentBox.cols="100",this.trackCommentBox.name="trackComment"+e.id,this.trackCommentBox.className="trackComment";var i=document.createElement("br");this.trackComment.appendChild(this.trackString),this.trackComment.appendChild(i),this.trackComment.appendChild(this.trackCommentBox),this.exportXMLDOM=function(){var e=document.createElement("comment"),t=document.createElement("question");t.textContent=this.trackString.textContent;var i=document.createElement("response");return i.textContent=this.trackCommentBox.value,console.log("Comment frag-"+this.id+": "+i.textContent),e.appendChild(t),e.appendChild(i),e},this.resize=function(){var e=(window.innerWidth-100)/2;e>=600?e=600:e<400&&(e=400),this.trackComment.style.width=e+"px",this.trackCommentBox.style.width=e-6+"px"},this.resize(),this.highlight=function(e){!0===e?$(this.trackComment).addClass("comment-box-playing"):$(this.trackComment).removeClass("comment-box-playing")}},e.createCommentBox=function(e){var t=new this.elementCommentBox(e);return this.boxes.push(t),e.commentDOM=t,t},e.sortCommentBoxes=function(){this.boxes.sort(function(e,t){return e.id-t.id})},e.showCommentBoxes=function(e,t){this.injectPoint=e,t&&this.sortCommentBoxes(),this.boxes.forEach(function(t){e.appendChild(t.trackComment)})},e.deleteCommentBoxes=function(){null!==this.injectPoint&&(this.boxes.forEach(function(e){this.injectPoint.removeChild(e.trackComment)},this),this.injectPoint=null),this.boxes=[]},e.highlightById=function(e){(void 0===e||"number"!=typeof e||e>=this.boxes.length)&&(console.log("Error - Invalid id"),e=-1),this.boxes.forEach(function(t){t.id===e?t.highlight(!0):t.highlight(!1)})},e}(),this.commentQuestions=[],this.commentBox=function(e){this.specification=e,this.holder=document.createElement("div"),this.holder.className="comment-div",this.string=document.createElement("span"),this.string.innerHTML=e.statement,this.textArea=document.createElement("textarea"),this.textArea.rows="4",this.textArea.cols="100",this.textArea.className="trackComment";var t=document.createElement("br");this.holder.appendChild(this.string),this.holder.appendChild(t),this.holder.appendChild(this.textArea),this.exportXMLDOM=function(e){var t=e.parent.document.createElement("comment");t.id=this.specification.id,t.setAttribute("type",this.specification.type),console.log("Question: "+this.string.textContent),console.log("Response: "+t.textContent);var i=e.parent.document.createElement("question");i.textContent=this.string.textContent;var n=e.parent.document.createElement("response");return n.textContent=this.textArea.value,t.appendChild(i),t.appendChild(n),e.XMLDOM.appendChild(t),t},this.resize=function(){var e=(window.innerWidth-100)/2;e>=600?e=600:e<400&&(e=400),this.holder.style.width=e+"px",this.textArea.style.width=e-6+"px"},this.resize(),this.check=function(){return!this.specification.mandatory||0!==this.textArea.value.length}},this.radioBox=function(e){this.specification=e,this.holder=document.createElement("div"),this.holder.className="comment-div",this.string=document.createElement("span"),this.string.innerHTML=e.statement,this.holder.appendChild(this.string),this.options=[],this.inputs=document.createElement("div"),this.inputs.className="comment-checkbox-inputs-holder";for(var t=e.options.length,i=0;i<t;i++){var n=document.createElement("div");n.className="comment-checkbox-inputs-flex";var o=document.createElement("span");o.textContent=e.options[i].text,o.className="comment-radio-span",n.appendChild(o);var s=document.createElement("input");s.type="radio",s.name=e.id,s.setAttribute("setvalue",e.options[i].name),s.className="comment-radio",n.appendChild(s),this.inputs.appendChild(n),this.options.push(s)}this.holder.appendChild(this.inputs),this.exportXMLDOM=function(e){var t=e.parent.document.createElement("comment");t.id=this.specification.id,t.setAttribute("type",this.specification.type);var i=document.createElement("question");i.textContent=this.string.textContent;for(var n=document.createElement("response"),o=0;!1===this.options[o].checked&&!(++o>=this.options.length););return o>=this.options.length?n.textContent="null":(n.textContent=this.options[o].getAttribute("setvalue"),n.setAttribute("number",o)),console.log("Comment: "+i.textContent),console.log("Response: "+n.textContent),t.appendChild(i),t.appendChild(n),e.XMLDOM.appendChild(t),t},this.resize=function(){var e=(window.innerWidth-100)/2;e>=600?e=600:e<400&&(e=400),this.holder.style.width=e+"px"},this.check=function(){var e=this.options.some(function(e){return e.checked});return!this.specification.mandatory||!1!==e},this.resize()},this.checkboxBox=function(e){this.specification=e,this.holder=document.createElement("div"),this.holder.className="comment-div",this.string=document.createElement("span"),this.string.innerHTML=e.statement,this.holder.appendChild(this.string),this.options=[],this.inputs=document.createElement("div"),this.inputs.className="comment-checkbox-inputs-holder";for(var t=e.options.length,i=0;i<t;i++){var n=document.createElement("div");n.className="comment-checkbox-inputs-flex";var o=document.createElement("span");o.textContent=e.options[i].text,o.className="comment-radio-span",n.appendChild(o);var s=document.createElement("input");s.type="checkbox",s.name=e.id,s.setAttribute("setvalue",e.options[i].name),s.className="comment-radio",n.appendChild(s),this.inputs.appendChild(n),this.options.push(s)}this.holder.appendChild(this.inputs),this.exportXMLDOM=function(e){var t=e.parent.document.createElement("comment");t.id=this.specification.id,t.setAttribute("type",this.specification.type);var i=document.createElement("question");i.textContent=this.string.textContent,t.appendChild(i),console.log("Comment: "+i.textContent);for(var n=0;n<this.options.length;n++){var o=document.createElement("response");o.textContent=this.options[n].checked,o.setAttribute("name",this.options[n].getAttribute("setvalue")),t.appendChild(o),console.log("Response "+o.getAttribute("name")+": "+o.textContent)}return e.XMLDOM.appendChild(t),t},this.resize=function(){var e=(window.innerWidth-100)/2;e>=600?e=600:e<400&&(e=400),this.holder.style.width=e+"px"},this.check=function(){var e=this.options.some(function(e){return e.checked});return!this.specification.mandatory||!1!==e},this.resize()},this.sliderBox=function(e){this.specification=e,this.holder=document.createElement("div"),this.holder.className="comment-div",this.string=document.createElement("span"),this.string.innerHTML=e.statement,this.slider=document.createElement("input"),this.slider.type="range",this.slider.min=e.min,this.slider.max=e.max,this.slider.step=e.step,this.slider.value=e.value;var t=document.createElement("br"),i=document.createElement("div");i.className="comment-slider-text-holder",this.leftText=document.createElement("span"),this.leftText.textContent=e.leftText,this.rightText=document.createElement("span"),this.rightText.textContent=e.rightText,i.appendChild(this.leftText),i.appendChild(this.rightText),this.holder.appendChild(this.string),this.holder.appendChild(t),this.holder.appendChild(this.slider),this.holder.appendChild(i),this.exportXMLDOM=function(e){var t=e.parent.document.createElement("comment");t.id=this.specification.id,t.setAttribute("type",this.specification.type),console.log("Question: "+this.string.textContent),console.log("Response: "+this.slider.value);var i=e.parent.document.createElement("question");i.textContent=this.string.textContent;var n=e.parent.document.createElement("response");return n.textContent=this.slider.value,t.appendChild(i),t.appendChild(n),e.XMLDOM.appendChild(t),t},this.resize=function(){var e=(window.innerWidth-100)/2;e>=600?e=600:e<400&&(e=400),this.holder.style.width=e+"px",this.slider.style.width=e-24+"px"},this.check=function(){return!0},this.resize()},this.createCommentQuestion=function(e){var t;return"question"==e.type?t=new this.commentBox(e):"radio"==e.type?t=new this.radioBox(e):"checkbox"==e.type?t=new this.checkboxBox(e):"slider"==e.type&&(t=new this.sliderBox(e)),this.commentQuestions.push(t),t},this.deleteCommentQuestions=function(){this.commentQuestions=[]},this.checkCommentQuestions=function(){if(0===this.commentQuestions.reduce(function(e,t){return!1===t.check()&&e.push(t),e},[]).length)return!0;interfaceContext.lightbox.post("Message","Not all the mandatory comment boxes below have been filled.")},this.outsideReferenceDOM=function(e,t,i){this.parent=e,this.outsideReferenceHolder=document.createElement("button"),this.outsideReferenceHolder.className="outside-reference",this.outsideReferenceHolder.setAttribute("track-id",t),this.outsideReferenceHolder.textContent=this.parent.specification.label||"Reference",this.outsideReferenceHolder.disabled=!0,this.handleEvent=function(e){audioEngineContext.play(this.parent.id)},this.outsideReferenceHolder.addEventListener("click",this),i.appendChild(this.outsideReferenceHolder),this.enable=function(){1==this.parent.state&&(this.outsideReferenceHolder.disabled=!1)},this.updateLoading=function(e){100!=e?(e=(e=String(e)).split(".")[0],this.outsideReferenceHolder.textContent=e+"%"):this.outsideReferenceHolder.textContent=this.parent.specification.label||"Reference"},this.startPlayback=function(){$(".track-slider").removeClass("track-slider-playing"),$(".comment-div").removeClass("comment-box-playing"),this.outsideReferenceHolder.style.backgroundColor="#FDD"},this.stopPlayback=function(){this.outsideReferenceHolder.style.backgroundColor=""},this.exportXMLDOM=function(e){return null},this.getValue=function(){return 0},this.getPresentedId=function(){return this.parent.specification.label||"Reference"},this.canMove=function(){return!1},this.error=function(){this.outsideReferenceHolder.textContent="Error",this.outsideReferenceHolder.style.backgroundColor="#F00"}},this.playhead=function(){var e={};e.object=document.createElement("div"),e.object.className="playhead",e.object.align="left";var t=document.createElement("div");return t.style.width="50px",e.curTimeSpan=document.createElement("span"),e.curTimeSpan.textContent="00:00",t.appendChild(e.curTimeSpan),e.object.appendChild(t),e.scrubberTrack=document.createElement("div"),e.scrubberTrack.className="playhead-scrub-track",e.scrubberHead=document.createElement("div"),e.scrubberHead.id="playhead-scrubber",e.scrubberTrack.appendChild(e.scrubberHead),e.object.appendChild(e.scrubberTrack),e.timePerPixel=0,e.maxTime=0,e.playbackObject=void 0,e.setTimePerPixel=function(e){this.playbackObject=e,this.maxTime=e.buffer.buffer.duration;this.timePerPixel=this.maxTime/490,this.maxTime<60?this.curTimeSpan.textContent="0.00":this.curTimeSpan.textContent="00:00"},e.update=function(){if(this.timePerPixel>0){var e=this.playbackObject.getCurrentPosition();if(e>0&&e<this.maxTime){var t=Math.floor(e/this.timePerPixel);if(this.scrubberHead.style.left=t+"px",this.maxTime>60){var i=e%60,n=Math.floor((e-i)/60);i=(i=i.toString()).substr(0,2),n=n.toString(),this.curTimeSpan.textContent=n+":"+i}else e=e.toString(),this.curTimeSpan.textContent=e.substr(0,4)}else this.scrubberHead.style.left="0px",this.maxTime<60?this.curTimeSpan.textContent="0.00":this.curTimeSpan.textContent="00:00"}void 0!==this.playbackObject&&void 0===this.interval&&window.requestAnimationFrame(this.update.bind(this))},e.interval=void 0,e.start=function(){void 0!==this.playbackObject&&void 0===this.interval&&window.requestAnimationFrame(this.update.bind(this))},e.stop=function(){this.timePerPixel=0},e}(),this.volume=function(){var e={};e.valueLin=1,e.valueDB=0,e.root=document.createElement("div"),e.root.id="master-volume-root",e.object=document.createElement("div"),e.object.className="master-volume-holder-float",e.object.appendChild(e.root),e.slider=document.createElement("input"),e.slider.id="master-volume-control",e.slider.type="range",e.valueText=document.createElement("span"),e.valueText.id="master-volume-feedback",e.valueText.textContent="0dB",e.slider.min=-60,e.slider.max=12,e.slider.value=0,e.slider.step=1,e.handleEvent=function(e){"mousemove"!=e.type&&"mouseup"!=e.type||(this.valueDB=Number(this.slider.value),this.valueLin=decibelToLinear(this.valueDB),this.valueText.textContent=this.valueDB+"dB",audioEngineContext.outputGain.gain.value=this.valueLin),"mouseup"==e.type&&this.onmouseup(),this.slider.value=this.valueDB,e.stopPropagation&&e.stopPropagation()},e.onmouseup=function(){var e=testState.currentStore.XMLDOM.getElementsByTagName("metric")[0].getAllElementsByName("volumeTracker");0===e.length?((e=storage.document.createElement("metricresult")).setAttribute("name","volumeTracker"),testState.currentStore.XMLDOM.getElementsByTagName("metric")[0].appendChild(e)):e=e[0];var t=storage.document.createElement("movement");t.setAttribute("test-time",audioEngineContext.timer.getTestTime()),t.setAttribute("volume",this.valueDB),t.setAttribute("format","dBFS"),e.appendChild(t)},e.slider.addEventListener("mousemove",e),e.root.addEventListener("mouseup",e);var t=document.createElement("div");return t.innerHTML="<span>Master Volume Control</span>",t.style.fontSize="0.75em",t.style.width="100%",t.align="center",e.root.appendChild(t),e.root.appendChild(e.slider),e.root.appendChild(e.valueText),e.resize=function(e){window.innerWidth<1e3?this.object.className="master-volume-holder-inline":this.object.className="master-volume-holder-float"},e}(),this.imageHolder=function(){var e={};return e.root=document.createElement("div"),e.root.id="imageController",e.img=document.createElement("img"),e.root.appendChild(e.img),e.setImage=function(t){e.img.src="","string"==typeof t&&void 0!==t.length&&(e.img.src=t)},e}(),this.calibrationModuleObject=null,this.calibrationModule=function(){this.storeDOM=storage.document.createElement("calibration"),storage.root.appendChild(this.storeDOM),this.calibrationNodes=[],this.holder=null,this.build=function(e){var t=62.5;for(this.holder=document.createElement("div"),this.holder.className="calibration-holder",this.calibrationNodes=[];t<2e4;){var i={root:document.createElement("div"),input:document.createElement("input"),oscillator:audioContext.createOscillator(),gain:audioContext.createGain(),f:t,parent:this,handleEvent:function(e){switch(e.type){case"mouseenter":this.oscillator.start(0);break;case"mouseleave":this.oscillator.stop(0),this.oscillator=audioContext.createOscillator(),this.oscillator.connect(this.gain),this.oscillator.frequency.value=this.f;break;case"mousemove":var t=Math.pow(10,this.input.value/20);1e3==this.f?(audioEngineContext.outputGain.gain.value=t,interfaceContext.volume.slider.value=this.input.value):this.gain.gain.value=t}},disconnect:function(){this.gain.disconnect()}};i.root.className="calibration-slider",i.root.appendChild(i.input),i.oscillator.connect(i.gain),i.gain.connect(audioEngineContext.outputGain),i.gain.gain.value=2*Math.random(),i.input.value=i.gain.gain.value,i.input.setAttribute("orient","vertical"),i.input.type="range",i.input.min=-12,i.input.max=0,i.input.step=.25,1e3!=t?i.input.value=12*Math.random()-6:(i.input.value=0,i.root.style.backgroundColor="rgb(255,125,125)"),i.input.addEventListener("mousemove",i),i.input.addEventListener("mouseenter",i),i.input.addEventListener("mouseleave",i),i.gain.gain.value=Math.pow(10,i.input.value/20),i.oscillator.frequency.value=t,this.calibrationNodes.push(i),this.holder.appendChild(i.root),t*=2}e.appendChild(this.holder)},this.collect=function(){this.calibrationNodes.forEach(function(e){var t=storage.document.createElement("calibrationresult");t.setAttribute("frequency",e.f),t.setAttribute("range-min",e.input.min),t.setAttribute("range-max",e.input.max),t.setAttribute("gain-lin",e.gain.gain.value),this.storeDOM.appendChild(t)},this)}},this.checkHiddenAnchor=function(e){return!audioEngineContext.audioObjects.filter(function(e){return"anchor"===e.specification.type}).some(function(e){return e.interfaceDOM.getValue()>e.specification.marker/100&&e.specification.marker>0})||(console.log("Anchor node not below marker value"),e?interfaceContext.lightbox.post("Message",e):interfaceContext.lightbox.post("Message","Please keep listening"),this.storeErrorNode("Anchor node not below marker value"),!1)},this.checkHiddenReference=function(e){return!audioEngineContext.audioObjects.filter(function(e){return"reference"===e.specification.type}).some(function(e){return e.interfaceDOM.getValue()<e.specification.marker/100&&e.specification.marker>0})||(console.log("Reference node not below marker value"),e?interfaceContext.lightbox.post("Message",e):interfaceContext.lightbox.post("Message","Please keep listening"),this.storeErrorNode("Reference node not below marker value"),!1)},this.checkFragmentsFullyPlayed=function(e){if(audioEngineContext.loopPlayback)return console.log("WARNING - Looped source: Cannot check fragments are fully played"),!0;var t,i=!0,n=[];for(t=0;t<audioEngineContext.audioObjects.length;t++){for(var o=audioEngineContext.audioObjects[t],s=o.buffer.buffer.duration,r=o.metric,a=!1,c=0;c<r.listenTracker.length;c++){var l=r.listenTracker[c].getElementsByTagName("testtime"),u=Number(l[0].getAttribute("start"));if(Number(l[0].getAttribute("stop"))-u>=s){a=!0;break}}!1===a&&(i=!1,console.log("Continue listening to track-"+o.interfaceDOM.getPresentedId()),n.push(o.interfaceDOM.getPresentedId()))}if(!1===i){var h="You have not completely listened to fragments ";for(t=0;t<n.length;t++)h+=n[t],t!=n.length-1&&(h+=", ");return h+=". Please keep listening",console.log(h),this.storeErrorNode(h),e&&(h=e),interfaceContext.lightbox.post("Error",h),!1}return!0},this.checkAllMoved=function(e){var t="You have not moved ",i=[];if(audioEngineContext.audioObjects.forEach(function(e){!1===e.metric.wasMoved&&!0===e.interfaceDOM.canMove()&&i.push(e.interfaceDOM.getPresentedId())},this),0===i.length)return!0;if(1==i.length)t+="track "+i[0];else{t+="tracks ";for(var n=0;n<i.length-1;n++)t+=i[n]+", ";t+="and "+i[n]}return t+=".",console.log(t),this.storeErrorNode(t),e&&(t=e),interfaceContext.lightbox.post("Error",t),!1},this.checkAllPlayed=function(e){var t="You have not played ",i=[];if(audioEngineContext.audioObjects.forEach(function(e){!1===e.metric.wasListenedTo&&i.push(e.interfaceDOM.getPresentedId())},this),0===i.length)return!0;if(1==i.length)t+="track "+i[0];else{t+="tracks ";for(var n=0;n<i.length-1;n++)t+=i[n]+", ";t+="and "+i[n]}return t+=".",console.log(t),this.storeErrorNode(t),e&&(t=e),interfaceContext.lightbox.post("Error",t),!1},this.checkAllCommented=function(e){var t,i="You have not commented on all the fragments.",n=this.commentBoxes.boxes,o=n.length;for(t=0;t<o;t++)if(""===n[t].trackCommentBox.value)return console.log(i),this.storeErrorNode(i),e&&(i=e),interfaceContext.lightbox.post("Error",i),!1;return!0},this.checkScaleRange=function(e){var t=testState.getCurrentTestPage().interfaces,i=!0,n="Please keep listening. ";if(void 0===t)return!0;t=t[0];var o=function(){var e=t.options.find(function(e){return"scalerange"==e.name});return{min:e.min,max:e.max}}(),s=audioEngineContext.audioObjects.reduce(function(e,t){var i=100*t.interfaceDOM.getValue();return{min:Math.min(e.min,i),max:Math.max(e.max,i)}},{min:100,max:0});return s.min>o.min?(n+="At least one fragment must be below the "+o.min+" mark.",i=!1):s.max<o.max&&(n+="At least one fragment must be above the "+o.max+" mark.",i=!1),!1===i&&(console.log(n),this.storeErrorNode(n),e&&(n=e),interfaceContext.lightbox.post("Error",n)),i},this.checkFragmentMinPlays=function(){var e=audioEngineContext.audioObjects.filter(function(e){var t=e.specification.minNumberPlays||e.specification.parent.minNumberPlays||specification.minNumberPlays;return!(void 0===t||e.numberOfPlays>=t)});if(0===e.length)return!0;var t=[];e.forEach(function(e){t.push(e.interfaceDOM.getPresentedId())});var i="You have not played fragments "+t.join(", ")+" enough. Please keep listening";return interfaceContext.lightbox.post("Message",i),this.storeErrorNode(i),!1},this.sortFragmentsByScore=function(){for(var e=audioEngineContext.audioObjects.filter(function(e){return"outside-reference"!==e.specification.type}),t=[],i=0;t.push(i++)<e.length;);return t.sort(function(t,i){var n=e[t].interfaceDOM.getValue(),o=e[i].interfaceDOM.getValue();return n>o?1:n<o?-1:0},e[0].interfaceDOM.getValue())},this.storeErrorNode=function(e){var t=audioEngineContext.timer.getTestTime(),i=storage.document.createElement("error");i.setAttribute("time",t),i.textContent=e,testState.currentStore.XMLDOM.appendChild(i)},this.getLabel=function(e,t,i){function n(e,t,i){if("none"==e)return"";switch(e){case"letter":return String.fromCharCode((t+i)%26+97);case"capital":return String.fromCharCode((t+i)%26+65);case"samediff":return 0===t?"Same":1==t?"Difference":"";case"number":return String(t+i);default:return""}}switch("string"==typeof i&&0!==i.length||(i=String.fromCharCode(0)),e){case"letter":((i=i.charCodeAt(0))<97||i>122)&&(i=97),i-=97;break;case"capital":((i=i.charCodeAt(0))<65||i>90)&&(i=65),i-=65;break;case"number":i=Number(i),isFinite(i)||(i=1);break;default:i=0}if("number"==typeof t)return n(e,t,i);if(t.length&&t.length>0){var o,s=[],r=t.length;for(o=0;o<r;o++)s[o]=n(e,t[o],i);return s}throw"Invalid arguments"},this.getCombinedInterfaces=function(e){var t=specification.interfaces,i=e.interfaces;return i.forEach(function(e){var i=[];t.options.forEach(function(t){e.options.find(function(e){return e.name==t.name&&e.type==t.type})||i.push(t)}),e.options=e.options.concat(i),!e.scales&&t.scales&&(e.scales=t.scales)}),i}}function Storage(){this.globalPreTest=null,this.globalPostTest=null,this.testPages=[],this.document=null,this.root=null,this.state=0;var e="save";this.initialise=function(e){if(void 0===e){this.SessionKey.requestKey(),this.document=document.implementation.createDocument(null,"waetresult",null),this.root=this.document.childNodes[0];var t=specification.projectXML;t.setAttribute("file-name",specification.url),t.setAttribute("url",qualifyURL(specification.url)),this.root.appendChild(t),this.root.appendChild(interfaceContext.returnDateNode()),this.root.appendChild(interfaceContext.returnNavigator())}else this.document=e,this.root=e.firstChild,this.SessionKey.key=this.root.getAttribute("key");void 0!==specification.preTest&&(this.globalPreTest=new this.surveyNode(this,this.root,specification.preTest)),void 0!==specification.postTest&&(this.globalPostTest=new this.surveyNode(this,this.root,specification.postTest))},this.SessionKey=function(e){function t(){var t=document.createElement("div"),n=e.root.cloneNode(!0);return t.appendChild(n),new Promise(function(n,s){console.log("Requested save...");var r=new XMLHttpRequest;r.open("POST",i+"php/save.php?key="+o+"&saveFilenamePrefix="+e.filenamePrefix),r.setRequestHeader("Content-Type","text/xml"),r.onload=function(){if(this.status>=300)console.log("WARNING - Could not update at this time");else{var e=(new DOMParser).parseFromString(r.responseText,"application/xml").getElementsByTagName("response")[0];if("OK"==e.getAttribute("state")){var t=e.getElementsByTagName("file")[0];console.log("Intermediate save: OK, written "+t.getAttribute("bytes")+"B"),n(!0)}else{var i=e.getElementsByTagName("message");console.log("Intermediate save: Error! "+i.textContent),s("Intermediate save: Error! "+i.textContent)}}},r.onerror=function(){s(Error("Network Error"))},r.send([t.innerHTML])})}var i="";void 0!==window.returnURL&&(i=String(window.returnURL));var n=null,o=null,s={};return Object.defineProperties(s,{key:{get:function(){return o},set:function(e){throw"Cannot set read-only property"}},request:{value:new XMLHttpRequest},parent:{value:e},requestKey:{value:function(){n=new Promise(function(t,n){var o=new XMLHttpRequest;o.open("GET",i+"php/requestKey.php?saveFilenamePrefix="+e.filenamePrefix,!0),o.onload=function(){200==o.status?t(o.response):n(Error(o.statusText))},o.onerror=function(){n(Error("Network Error"))},o.send()}).then(function(t){function i(){throw o=null,"An unspecified error occured, no server key could be generated"}var n=(new DOMParser).parseFromString(t,"text/xml");if(0===t.length&&i(),n.getElementsByTagName("state").length>0){if("OK"==n.getElementsByTagName("state")[0].textContent)return o=n.getAllElementsByTagName("key")[0].textContent,e.root.setAttribute("key",o),e.root.setAttribute("state","empty"),!0;if("ERROR"==n.getElementsByTagName("state")[0].textContent)return o=null,console.error('Could not generate server key. Server responded with error message: "'+n.getElementsByTagName("message")[0].textContent+'"'),!1}else i();return!0})}},update:{value:function(){if(null===this.key||void 0===n)throw"Cannot save as key == null";this.parent.root.setAttribute("state","update"),n=n.then(t)}},finish:{value:function(){if(null===this.key||void 0===n)throw"Cannot save as key == null";return this.parent.finish(),n.then(t()).then(function(){console.log("OK")},function(){createProjectSave("local")})}}}),s}(this),this.createTestPageStore=function(e){var t=new this.pageNode(this,e);return this.testPages.push(t),this.testPages[this.testPages.length-1]},this.surveyNode=function(e,t,i){this.specification=i,this.parent=e,this.state="empty",this.XMLDOM=this.parent.document.createElement("survey"),this.XMLDOM.setAttribute("location",this.specification.location),this.XMLDOM.setAttribute("state",this.state),this.specification.options.forEach(function(e){if("statement"!=e.type){var t=this.parent.document.createElement("surveyresult");t.setAttribute("ref",e.id),t.setAttribute("type",e.type),this.XMLDOM.appendChild(t)}},this),t.appendChild(this.XMLDOM),this.postResult=function(e){function t(e,t){var i=e.createElement("response");return i.setAttribute("name",t.name),i.setAttribute("checked",t.checked),i}if("statement"!=e.specification.type){for(var i=this.XMLDOM.firstChild;null!==i&&i.getAttribute("ref")!=e.specification.id;)i=i.nextElementSibling;switch(i.setAttribute("duration",e.elapsedTime),e.specification.type){case"number":case"question":case"slider":i.appendChild(function(e,t){var i=e.createElement("response");return i.textContent=t,i}(this.parent.document,e.response));break;case"radio":i.appendChild(function(e,t){var i=e.createElement("response");return null!==t.response&&(i.setAttribute("name",t.response.name),i.textContent=t.response.text),i}(this.parent.document,e));break;case"checkbox":if(void 0===e.response){i.appendChild(this.parent.document.createElement("response"));break}for(var n=0;n<e.response.length;n++)i.appendChild(t(this.parent.document,e.response[n]))}}},this.complete=function(){this.state="complete",this.XMLDOM.setAttribute("state",this.state)}},this.pageNode=function(e,t){this.specification=t,this.parent=e,this.state="empty",this.XMLDOM=this.parent.document.createElement("page"),this.XMLDOM.setAttribute("ref",t.id),this.XMLDOM.setAttribute("presentedId",t.presentedId),this.XMLDOM.setAttribute("state",this.state),void 0!==t.preTest&&(this.preTest=new this.parent.surveyNode(this.parent,this.XMLDOM,this.specification.preTest)),void 0!==t.postTest&&(this.postTest=new this.parent.surveyNode(this.parent,this.XMLDOM,this.specification.postTest));var i=this.parent.document.createElement("metric");this.XMLDOM.appendChild(i),this.specification.audioElements.forEach(function(e){var t=this.parent.document.createElement("audioelement");t.setAttribute("ref",e.id),void 0!==e.name&&t.setAttribute("name",e.name),t.setAttribute("type",e.type),t.setAttribute("url",e.url),t.setAttribute("fqurl",qualifyURL(e.url)),t.setAttribute("gain",e.gain),"anchor"!=e.type&&"reference"!=e.type||e.marker>0&&t.setAttribute("marker",e.marker);var i=this.parent.document.createElement("metric");t.appendChild(i),this.XMLDOM.appendChild(t)},this),this.parent.root.appendChild(this.XMLDOM),this.complete=function(){this.state="complete",this.XMLDOM.setAttribute("state","complete")}},this.update=function(){this.SessionKey.update()},this.finish=function(){return this.state=1,this.root.setAttribute("state","complete"),this.root},Object.defineProperties(this,{filenamePrefix:{get:function(){return e},set:function(t){return"string"!=typeof t&&(t=String(t)),e=t,t}}})}var audioContext,projectXML,schemaXSD,specification,interfaceContext,storage,popup,testState,audioEngineContext,gReturnURL,gSaveFilenamePrefix,currentTrackOrder=[];AudioBufferSourceNode.prototype.owner=void 0,AudioBufferSourceNode.prototype.playbackStartTime=void 0,AudioBuffer.prototype.playbackGain=void 0,AudioBuffer.prototype.lufs=void 0,XMLDocument.prototype.getAllElementsByName=function(e){e=String(e);return this.documentElement.getAllElementsByName(e)},Element.prototype.getAllElementsByName=function(e){e=String(e);for(var t=[],i=this.firstElementChild;null!==i;)i.getAttribute("name")==e&&t.push(i),i.childElementCount>0&&(t=t.concat(i.getAllElementsByName(e))),i=i.nextElementSibling;return t},XMLDocument.prototype.getAllElementsByTagName=function(e){e=String(e);return this.documentElement.getAllElementsByTagName(e)},Element.prototype.getAllElementsByTagName=function(e){e=String(e);for(var t=[],i=this.firstElementChild;null!==i;)i.nodeName==e&&t.push(i),i.childElementCount>0&&(t=t.concat(i.getAllElementsByTagName(e))),i=i.nextElementSibling;return t},"function"!=typeof XMLDocument.prototype.getElementsByName&&(XMLDocument.prototype.getElementsByName=function(e){e=String(e);for(var t=this.documentElement.firstElementChild,i=[];null!==t;)t.getAttribute("name")==e&&i.push(t),t=t.nextElementSibling;return i});var window_depedancy_callback,check_dependancies=function(){return"function"==typeof jQuery&&("function"==typeof Specification&&("function"==typeof calculateLoudness&&("function"==typeof WAVE&&"function"==typeof validateXML)))},onload=function(){var e=window.AudioContext||window.webkitAudioContext;if(audioContext=new e,testState=new stateMachine,popup=new interfacePopup,specification=new Specification,interfaceContext=new Interface(specification),storage=new Storage,window.onresize=function(e){interfaceContext.resizeWindow(e)},0!==window.location.search.length){var t,i=window.location.search.split("?")[1].split("&");for(var n in i){i[n]=i[n].split("=");var o=i[n][0],s=decodeURIComponent(i[n][1]);switch(o){case"url":t=s,specification.url=t;break;case"returnURL":gReturnURL=s;break;case"saveFilenamePrefix":storage.filenamePrefix=s}}loadProjectSpec(t),window.onbeforeunload=function(){return"Please only leave this page once you have completed the tests. Are you sure you have completed all testing?"}}interfaceContext.lightbox.resize()};window_depedancy_callback=window.setInterval(function(){check_dependancies()?(window.clearInterval(window_depedancy_callback),onload()):document.getElementById("topLevelBody").innerHTML="<h1>Loading Resources</h1>"},100);