annotate core.js @ 1174:dd7ba3054bf9

Test create drag and drop active. Auto-builds on page HTML from specification.
author Nicholas Jillings <n.g.r.jillings@se14.qmul.ac.uk>
date Thu, 11 Feb 2016 12:06:54 +0000
parents d4348ae0bc02
children 9131490d80a3
rev   line source
n@1118 1 /**
n@1118 2 * core.js
n@1118 3 *
n@1118 4 * Main script to run, calls all other core functions and manages loading/store to backend.
n@1118 5 * Also contains all global variables.
n@1118 6 */
n@1118 7
n@1118 8 /* create the web audio API context and store in audioContext*/
n@1118 9 var audioContext; // Hold the browser web audio API
n@1118 10 var projectXML; // Hold the parsed setup XML
n@1124 11 var schemaXSD; // Hold the parsed schema XSD
n@1118 12 var specification;
n@1118 13 var interfaceContext;
n@1124 14 var storage;
n@1118 15 var popup; // Hold the interfacePopup object
n@1118 16 var testState;
n@1118 17 var currentTrackOrder = []; // Hold the current XML tracks in their (randomised) order
n@1118 18 var audioEngineContext; // The custome AudioEngine object
n@1118 19 var projectReturn; // Hold the URL for the return
n@1118 20
n@1118 21
n@1118 22 // Add a prototype to the bufferSourceNode to reference to the audioObject holding it
n@1118 23 AudioBufferSourceNode.prototype.owner = undefined;
n@1118 24 // Add a prototype to the bufferNode to hold the desired LINEAR gain
n@1120 25 AudioBuffer.prototype.playbackGain = undefined;
n@1118 26 // Add a prototype to the bufferNode to hold the computed LUFS loudness
n@1118 27 AudioBuffer.prototype.lufs = undefined;
n@1118 28
n@1148 29 // Firefox does not have an XMLDocument.prototype.getElementsByName
n@1148 30 // and there is no searchAll style command, this custom function will
n@1148 31 // search all children recusrively for the name. Used for XSD where all
n@1148 32 // element nodes must have a name and therefore can pull the schema node
n@1148 33 XMLDocument.prototype.getAllElementsByName = function(name)
n@1148 34 {
n@1148 35 name = String(name);
n@1148 36 var selected = this.documentElement.getAllElementsByName(name);
n@1148 37 return selected;
n@1148 38 }
n@1148 39
n@1148 40 Element.prototype.getAllElementsByName = function(name)
n@1148 41 {
n@1148 42 name = String(name);
n@1148 43 var selected = [];
n@1148 44 var node = this.firstElementChild;
n@1148 45 while(node != null)
n@1148 46 {
n@1148 47 if (node.getAttribute('name') == name)
n@1148 48 {
n@1148 49 selected.push(node);
n@1148 50 }
n@1148 51 if (node.childElementCount > 0)
n@1148 52 {
n@1148 53 selected = selected.concat(node.getAllElementsByName(name));
n@1148 54 }
n@1148 55 node = node.nextElementSibling;
n@1148 56 }
n@1148 57 return selected;
n@1148 58 }
n@1148 59
n@1148 60 XMLDocument.prototype.getAllElementsByTagName = function(name)
n@1148 61 {
n@1148 62 name = String(name);
n@1148 63 var selected = this.documentElement.getAllElementsByTagName(name);
n@1148 64 return selected;
n@1148 65 }
n@1148 66
n@1148 67 Element.prototype.getAllElementsByTagName = function(name)
n@1148 68 {
n@1148 69 name = String(name);
n@1148 70 var selected = [];
n@1148 71 var node = this.firstElementChild;
n@1148 72 while(node != null)
n@1148 73 {
n@1148 74 if (node.nodeName == name)
n@1148 75 {
n@1148 76 selected.push(node);
n@1148 77 }
n@1148 78 if (node.childElementCount > 0)
n@1148 79 {
n@1148 80 selected = selected.concat(node.getAllElementsByTagName(name));
n@1148 81 }
n@1148 82 node = node.nextElementSibling;
n@1148 83 }
n@1148 84 return selected;
n@1148 85 }
n@1148 86
n@1148 87 // Firefox does not have an XMLDocument.prototype.getElementsByName
n@1148 88 if (typeof XMLDocument.prototype.getElementsByName != "function") {
n@1148 89 XMLDocument.prototype.getElementsByName = function(name)
n@1148 90 {
n@1148 91 name = String(name);
n@1148 92 var node = this.documentElement.firstElementChild;
n@1148 93 var selected = [];
n@1148 94 while(node != null)
n@1148 95 {
n@1148 96 if (node.getAttribute('name') == name)
n@1148 97 {
n@1148 98 selected.push(node);
n@1148 99 }
n@1148 100 node = node.nextElementSibling;
n@1148 101 }
n@1148 102 return selected;
n@1148 103 }
n@1148 104 }
n@1148 105
n@1118 106 window.onload = function() {
n@1118 107 // Function called once the browser has loaded all files.
n@1118 108 // This should perform any initial commands such as structure / loading documents
n@1118 109
n@1118 110 // Create a web audio API context
n@1118 111 // Fixed for cross-browser support
n@1118 112 var AudioContext = window.AudioContext || window.webkitAudioContext;
n@1118 113 audioContext = new AudioContext;
n@1118 114
n@1118 115 // Create test state
n@1118 116 testState = new stateMachine();
n@1118 117
n@1118 118 // Create the popup interface object
n@1118 119 popup = new interfacePopup();
n@1170 120
n@1170 121 // Create the specification object
n@1118 122 specification = new Specification();
n@1118 123
n@1118 124 // Create the interface object
n@1118 125 interfaceContext = new Interface(specification);
n@1124 126
n@1124 127 // Create the storage object
n@1124 128 storage = new Storage();
n@1118 129 // Define window callbacks for interface
n@1118 130 window.onresize = function(event){interfaceContext.resizeWindow(event);};
n@1118 131 };
n@1118 132
n@1118 133 function loadProjectSpec(url) {
n@1118 134 // Load the project document from the given URL, decode the XML and instruct audioEngine to get audio data
n@1118 135 // If url is null, request client to upload project XML document
n@1124 136 var xmlhttp = new XMLHttpRequest();
n@1124 137 xmlhttp.open("GET",'test-schema.xsd',true);
n@1124 138 xmlhttp.onload = function()
n@1124 139 {
n@1124 140 schemaXSD = xmlhttp.response;
n@1124 141 var parse = new DOMParser();
n@1124 142 specification.schema = parse.parseFromString(xmlhttp.response,'text/xml');
n@1124 143 var r = new XMLHttpRequest();
n@1124 144 r.open('GET',url,true);
n@1124 145 r.onload = function() {
n@1124 146 loadProjectSpecCallback(r.response);
n@1124 147 };
n@1124 148 r.send();
n@1118 149 };
n@1124 150 xmlhttp.send();
n@1118 151 };
n@1118 152
n@1118 153 function loadProjectSpecCallback(response) {
n@1118 154 // Function called after asynchronous download of XML project specification
n@1118 155 //var decode = $.parseXML(response);
n@1118 156 //projectXML = $(decode);
n@1118 157
n@1124 158 // First perform XML schema validation
n@1124 159 var Module = {
n@1124 160 xml: response,
n@1124 161 schema: schemaXSD,
n@1124 162 arguments:["--noout", "--schema", 'test-schema.xsd','document.xml']
n@1124 163 };
n@1124 164
n@1124 165 var xmllint = validateXML(Module);
n@1124 166 console.log(xmllint);
n@1124 167 if(xmllint != 'document.xml validates\n')
n@1124 168 {
n@1124 169 document.getElementsByTagName('body')[0].innerHTML = null;
n@1124 170 var msg = document.createElement("h3");
n@1124 171 msg.textContent = "FATAL ERROR";
n@1124 172 var span = document.createElement("h4");
n@1124 173 span.textContent = "The XML validator returned the following errors when decoding your XML file";
n@1124 174 document.getElementsByTagName('body')[0].appendChild(msg);
n@1124 175 document.getElementsByTagName('body')[0].appendChild(span);
n@1124 176 xmllint = xmllint.split('\n');
n@1124 177 for (var i in xmllint)
n@1124 178 {
n@1124 179 document.getElementsByTagName('body')[0].appendChild(document.createElement('br'));
n@1124 180 var span = document.createElement("span");
n@1124 181 span.textContent = xmllint[i];
n@1124 182 document.getElementsByTagName('body')[0].appendChild(span);
n@1124 183 }
n@1124 184 return;
n@1124 185 }
n@1124 186
n@1118 187 var parse = new DOMParser();
n@1118 188 projectXML = parse.parseFromString(response,'text/xml');
n@1118 189 var errorNode = projectXML.getElementsByTagName('parsererror');
n@1118 190 if (errorNode.length >= 1)
n@1118 191 {
n@1118 192 var msg = document.createElement("h3");
n@1118 193 msg.textContent = "FATAL ERROR";
n@1118 194 var span = document.createElement("span");
n@1118 195 span.textContent = "The XML parser returned the following errors when decoding your XML file";
n@1118 196 document.getElementsByTagName('body')[0].innerHTML = null;
n@1118 197 document.getElementsByTagName('body')[0].appendChild(msg);
n@1118 198 document.getElementsByTagName('body')[0].appendChild(span);
n@1118 199 document.getElementsByTagName('body')[0].appendChild(errorNode[0]);
n@1118 200 return;
n@1118 201 }
n@1118 202
n@1118 203 // Build the specification
n@1118 204 specification.decode(projectXML);
n@1124 205 storage.initialise();
n@1139 206 /// CHECK FOR SAMPLE RATE COMPATIBILITY
n@1139 207 if (specification.sampleRate != undefined) {
n@1139 208 if (Number(specification.sampleRate) != audioContext.sampleRate) {
n@1139 209 var errStr = 'Sample rates do not match! Requested '+Number(specification.sampleRate)+', got '+audioContext.sampleRate+'. Please set the sample rate to match before completing this test.';
n@1139 210 alert(errStr);
n@1139 211 return;
n@1139 212 }
n@1139 213 }
n@1118 214
n@1118 215 // Detect the interface to use and load the relevant javascripts.
n@1118 216 var interfaceJS = document.createElement('script');
n@1118 217 interfaceJS.setAttribute("type","text/javascript");
n@1129 218 switch(specification.interface)
n@1129 219 {
n@1129 220 case "APE":
n@1141 221 interfaceJS.setAttribute("src","interfaces/ape.js");
n@1118 222
n@1118 223 // APE comes with a css file
n@1118 224 var css = document.createElement('link');
n@1118 225 css.rel = 'stylesheet';
n@1118 226 css.type = 'text/css';
n@1141 227 css.href = 'interfaces/ape.css';
n@1118 228
n@1118 229 document.getElementsByTagName("head")[0].appendChild(css);
n@1129 230 break;
n@1129 231
n@1129 232 case "MUSHRA":
n@1141 233 interfaceJS.setAttribute("src","interfaces/mushra.js");
n@1118 234
n@1118 235 // MUSHRA comes with a css file
n@1118 236 var css = document.createElement('link');
n@1118 237 css.rel = 'stylesheet';
n@1118 238 css.type = 'text/css';
n@1141 239 css.href = 'interfaces/mushra.css';
n@1118 240
n@1118 241 document.getElementsByTagName("head")[0].appendChild(css);
n@1129 242 break;
n@1129 243
n@1129 244 case "AB":
n@1141 245 interfaceJS.setAttribute("src","interfaces/AB.js");
n@1129 246
n@1129 247 // AB comes with a css file
n@1129 248 var css = document.createElement('link');
n@1129 249 css.rel = 'stylesheet';
n@1129 250 css.type = 'text/css';
n@1141 251 css.href = 'interfaces/AB.css';
n@1129 252
n@1129 253 document.getElementsByTagName("head")[0].appendChild(css);
n@1145 254 break;
n@1145 255 case "Bipolar":
n@1145 256 case "ACR":
n@1145 257 case "DCR":
n@1145 258 case "CCR":
n@1143 259 case "ABC":
n@1143 260 // Above enumerate to horizontal sliders
n@1143 261 interfaceJS.setAttribute("src","interfaces/horizontal-sliders.js");
n@1143 262
n@1143 263 // horizontal-sliders comes with a css file
n@1143 264 var css = document.createElement('link');
n@1143 265 css.rel = 'stylesheet';
n@1143 266 css.type = 'text/css';
n@1143 267 css.href = 'interfaces/horizontal-sliders.css';
n@1143 268
n@1143 269 document.getElementsByTagName("head")[0].appendChild(css);
n@1145 270 break;
n@1145 271 case "discrete":
n@1145 272 case "likert":
n@1145 273 // Above enumerate to horizontal discrete radios
n@1145 274 interfaceJS.setAttribute("src","interfaces/discrete.js");
n@1145 275
n@1145 276 // horizontal-sliders comes with a css file
n@1145 277 var css = document.createElement('link');
n@1145 278 css.rel = 'stylesheet';
n@1145 279 css.type = 'text/css';
n@1145 280 css.href = 'interfaces/discrete.css';
n@1145 281
n@1145 282 document.getElementsByTagName("head")[0].appendChild(css);
n@1145 283 break;
n@1118 284 }
n@1118 285 document.getElementsByTagName("head")[0].appendChild(interfaceJS);
n@1118 286
n@1118 287 // Create the audio engine object
n@1118 288 audioEngineContext = new AudioEngine(specification);
n@1118 289
n@1124 290 $(specification.pages).each(function(index,elem){
n@1118 291 $(elem.audioElements).each(function(i,audioElem){
n@1124 292 var URL = elem.hostURL + audioElem.url;
n@1118 293 var buffer = null;
n@1118 294 for (var i=0; i<audioEngineContext.buffers.length; i++)
n@1118 295 {
n@1118 296 if (URL == audioEngineContext.buffers[i].url)
n@1118 297 {
n@1118 298 buffer = audioEngineContext.buffers[i];
n@1118 299 break;
n@1118 300 }
n@1118 301 }
n@1118 302 if (buffer == null)
n@1118 303 {
n@1118 304 buffer = new audioEngineContext.bufferObj();
n@1118 305 buffer.getMedia(URL);
n@1118 306 audioEngineContext.buffers.push(buffer);
n@1118 307 }
n@1118 308 });
n@1118 309 });
n@1118 310 }
n@1118 311
n@1118 312 function createProjectSave(destURL) {
n@1118 313 // Save the data from interface into XML and send to destURL
n@1118 314 // If destURL is null then download XML in client
n@1118 315 // Now time to render file locally
n@1118 316 var xmlDoc = interfaceXMLSave();
n@1118 317 var parent = document.createElement("div");
n@1118 318 parent.appendChild(xmlDoc);
n@1118 319 var file = [parent.innerHTML];
n@1118 320 if (destURL == "null" || destURL == undefined) {
n@1118 321 var bb = new Blob(file,{type : 'application/xml'});
n@1118 322 var dnlk = window.URL.createObjectURL(bb);
n@1118 323 var a = document.createElement("a");
n@1118 324 a.hidden = '';
n@1118 325 a.href = dnlk;
n@1118 326 a.download = "save.xml";
n@1118 327 a.textContent = "Save File";
n@1118 328
n@1118 329 popup.showPopup();
n@1132 330 popup.popupContent.innerHTML = "</span>Please save the file below to give to your test supervisor</span><br>";
n@1118 331 popup.popupContent.appendChild(a);
n@1118 332 } else {
n@1118 333 var xmlhttp = new XMLHttpRequest;
n@1118 334 xmlhttp.open("POST",destURL,true);
n@1118 335 xmlhttp.setRequestHeader('Content-Type', 'text/xml');
n@1118 336 xmlhttp.onerror = function(){
n@1118 337 console.log('Error saving file to server! Presenting download locally');
n@1118 338 createProjectSave(null);
n@1118 339 };
n@1118 340 xmlhttp.onreadystatechange = function() {
n@1118 341 console.log(xmlhttp.status);
n@1118 342 if (xmlhttp.status != 200 && xmlhttp.readyState == 4) {
n@1118 343 createProjectSave(null);
n@1118 344 } else {
n@1118 345 if (xmlhttp.responseXML == null)
n@1118 346 {
n@1124 347 createProjectSave('null');
n@1118 348 }
n@1118 349 var response = xmlhttp.responseXML.childNodes[0];
n@1118 350 if (response.getAttribute('state') == "OK")
n@1118 351 {
n@1118 352 var file = response.getElementsByTagName('file')[0];
n@1118 353 console.log('Save OK: Filename '+file.textContent+','+file.getAttribute('bytes')+'B');
n@1118 354 popup.showPopup();
n@1118 355 popup.popupContent.innerHTML = null;
n@1118 356 popup.popupContent.textContent = "Thank you!";
n@1118 357 } else {
n@1118 358 var message = response.getElementsByTagName('message')[0];
n@1118 359 errorSessionDump(message.textContent);
n@1118 360 }
n@1118 361 }
n@1118 362 };
n@1118 363 xmlhttp.send(file);
n@1132 364 popup.showPopup();
n@1132 365 popup.popupContent.innerHTML = null;
n@1132 366 popup.popupContent.textContent = "Submitting. Please Wait";
n@1118 367 }
n@1118 368 }
n@1118 369
n@1118 370 function errorSessionDump(msg){
n@1118 371 // Create the partial interface XML save
n@1118 372 // Include error node with message on why the dump occured
n@1118 373 popup.showPopup();
n@1118 374 popup.popupContent.innerHTML = null;
n@1118 375 var err = document.createElement('error');
n@1118 376 var parent = document.createElement("div");
n@1118 377 if (typeof msg === "object")
n@1118 378 {
n@1118 379 err.appendChild(msg);
n@1118 380 popup.popupContent.appendChild(msg);
n@1118 381
n@1118 382 } else {
n@1118 383 err.textContent = msg;
n@1118 384 popup.popupContent.innerHTML = "ERROR : "+msg;
n@1118 385 }
n@1118 386 var xmlDoc = interfaceXMLSave();
n@1118 387 xmlDoc.appendChild(err);
n@1118 388 parent.appendChild(xmlDoc);
n@1118 389 var file = [parent.innerHTML];
n@1118 390 var bb = new Blob(file,{type : 'application/xml'});
n@1118 391 var dnlk = window.URL.createObjectURL(bb);
n@1118 392 var a = document.createElement("a");
n@1118 393 a.hidden = '';
n@1118 394 a.href = dnlk;
n@1118 395 a.download = "save.xml";
n@1118 396 a.textContent = "Save File";
n@1118 397
n@1118 398
n@1118 399
n@1118 400 popup.popupContent.appendChild(a);
n@1118 401 }
n@1118 402
n@1118 403 // Only other global function which must be defined in the interface class. Determines how to create the XML document.
n@1118 404 function interfaceXMLSave(){
n@1118 405 // Create the XML string to be exported with results
n@1124 406 return storage.finish();
n@1118 407 }
n@1118 408
n@1118 409 function linearToDecibel(gain)
n@1118 410 {
n@1118 411 return 20.0*Math.log10(gain);
n@1118 412 }
n@1118 413
n@1118 414 function decibelToLinear(gain)
n@1118 415 {
n@1118 416 return Math.pow(10,gain/20.0);
n@1118 417 }
n@1118 418
n@1118 419 function interfacePopup() {
n@1118 420 // Creates an object to manage the popup
n@1118 421 this.popup = null;
n@1118 422 this.popupContent = null;
n@1118 423 this.popupTitle = null;
n@1118 424 this.popupResponse = null;
n@1118 425 this.buttonProceed = null;
n@1118 426 this.buttonPrevious = null;
n@1118 427 this.popupOptions = null;
n@1118 428 this.currentIndex = null;
n@1124 429 this.node = null;
n@1124 430 this.store = null;
n@1118 431 $(window).keypress(function(e){
n@1118 432 if (e.keyCode == 13 && popup.popup.style.visibility == 'visible')
n@1118 433 {
n@1118 434 console.log(e);
n@1118 435 popup.buttonProceed.onclick();
n@1118 436 e.preventDefault();
n@1118 437 }
n@1118 438 });
n@1118 439
n@1118 440 this.createPopup = function(){
n@1118 441 // Create popup window interface
n@1118 442 var insertPoint = document.getElementById("topLevelBody");
n@1118 443 var blank = document.createElement('div');
n@1118 444 blank.className = 'testHalt';
n@1118 445
n@1118 446 this.popup = document.createElement('div');
n@1118 447 this.popup.id = 'popupHolder';
n@1118 448 this.popup.className = 'popupHolder';
n@1118 449 this.popup.style.position = 'absolute';
n@1118 450 this.popup.style.left = (window.innerWidth/2)-250 + 'px';
n@1118 451 this.popup.style.top = (window.innerHeight/2)-125 + 'px';
n@1118 452
n@1118 453 this.popupContent = document.createElement('div');
n@1118 454 this.popupContent.id = 'popupContent';
n@1118 455 this.popupContent.style.marginTop = '20px';
n@1118 456 this.popupContent.style.marginBottom = '5px';
n@1118 457 this.popup.appendChild(this.popupContent);
n@1118 458
n@1118 459 var titleHolder = document.createElement('div');
n@1118 460 titleHolder.id = 'popupTitleHolder';
n@1118 461 titleHolder.align = 'center';
n@1118 462 titleHolder.style.width = 'inherit';
n@1118 463 titleHolder.style.minHeight = '25px';
n@1118 464 titleHolder.style.maxHeight = '250px';
n@1118 465 titleHolder.style.overflow = 'auto';
n@1118 466 titleHolder.style.marginBottom = '5px';
n@1118 467
n@1118 468 this.popupTitle = document.createElement('span');
n@1118 469 this.popupTitle.id = 'popupTitle';
n@1118 470 titleHolder.appendChild(this.popupTitle);
n@1118 471 this.popupContent.appendChild(titleHolder);
n@1118 472
n@1118 473 this.popupResponse = document.createElement('div');
n@1118 474 this.popupResponse.id = 'popupResponse';
n@1118 475 this.popupResponse.align = 'center';
n@1118 476 this.popupResponse.style.width = 'inherit';
n@1118 477 this.popupResponse.style.minHeight = '50px';
n@1118 478 this.popupResponse.style.maxHeight = '320px';
n@1118 479 this.popupResponse.style.overflow = 'auto';
n@1118 480 this.popupContent.appendChild(this.popupResponse);
n@1118 481
n@1118 482 this.buttonProceed = document.createElement('button');
n@1171 483 this.buttonProceed.id = "popup-proceed";
n@1118 484 this.buttonProceed.className = 'popupButton';
n@1118 485 this.buttonProceed.innerHTML = 'Next';
n@1118 486 this.buttonProceed.onclick = function(){popup.proceedClicked();};
n@1118 487
n@1118 488 this.buttonPrevious = document.createElement('button');
n@1171 489 this.buttonPrevious.id = "popup-previous";
n@1118 490 this.buttonPrevious.className = 'popupButton';
n@1118 491 this.buttonPrevious.innerHTML = 'Back';
n@1118 492 this.buttonPrevious.onclick = function(){popup.previousClick();};
n@1118 493
n@1171 494 this.popup.appendChild(this.buttonPrevious);
n@1171 495 this.popup.appendChild(this.buttonProceed);
n@1118 496
n@1118 497 this.popup.style.zIndex = -1;
n@1118 498 this.popup.style.visibility = 'hidden';
n@1118 499 blank.style.zIndex = -2;
n@1118 500 blank.style.visibility = 'hidden';
n@1118 501 insertPoint.appendChild(this.popup);
n@1118 502 insertPoint.appendChild(blank);
n@1118 503 };
n@1118 504
n@1118 505 this.showPopup = function(){
n@1118 506 if (this.popup == null) {
n@1118 507 this.createPopup();
n@1118 508 }
n@1118 509 this.popup.style.zIndex = 3;
n@1118 510 this.popup.style.visibility = 'visible';
n@1118 511 var blank = document.getElementsByClassName('testHalt')[0];
n@1118 512 blank.style.zIndex = 2;
n@1118 513 blank.style.visibility = 'visible';
n@1118 514 };
n@1118 515
n@1118 516 this.hidePopup = function(){
n@1118 517 this.popup.style.zIndex = -1;
n@1118 518 this.popup.style.visibility = 'hidden';
n@1118 519 var blank = document.getElementsByClassName('testHalt')[0];
n@1118 520 blank.style.zIndex = -2;
n@1118 521 blank.style.visibility = 'hidden';
n@1118 522 this.buttonPrevious.style.visibility = 'inherit';
n@1118 523 };
n@1118 524
n@1118 525 this.postNode = function() {
n@1118 526 // This will take the node from the popupOptions and display it
n@1118 527 var node = this.popupOptions[this.currentIndex];
n@1118 528 this.popupResponse.innerHTML = null;
n@1124 529 this.popupTitle.textContent = node.specification.statement;
n@1124 530 if (node.specification.type == 'question') {
n@1118 531 var textArea = document.createElement('textarea');
n@1124 532 switch (node.specification.boxsize) {
n@1118 533 case 'small':
n@1118 534 textArea.cols = "20";
n@1118 535 textArea.rows = "1";
n@1118 536 break;
n@1118 537 case 'normal':
n@1118 538 textArea.cols = "30";
n@1118 539 textArea.rows = "2";
n@1118 540 break;
n@1118 541 case 'large':
n@1118 542 textArea.cols = "40";
n@1118 543 textArea.rows = "5";
n@1118 544 break;
n@1118 545 case 'huge':
n@1118 546 textArea.cols = "50";
n@1118 547 textArea.rows = "10";
n@1118 548 break;
n@1118 549 }
n@1161 550 if (node.response == undefined) {
n@1161 551 node.response = "";
n@1161 552 } else {
n@1161 553 textArea.value = node.response;
n@1161 554 }
n@1118 555 this.popupResponse.appendChild(textArea);
n@1118 556 textArea.focus();
n@1124 557 } else if (node.specification.type == 'checkbox') {
n@1161 558 if (node.response == undefined) {
n@1161 559 node.response = Array(node.specification.options.length);
n@1161 560 }
n@1161 561 var index = 0;
n@1124 562 for (var option of node.specification.options) {
n@1118 563 var input = document.createElement('input');
n@1120 564 input.id = option.name;
n@1118 565 input.type = 'checkbox';
n@1118 566 var span = document.createElement('span');
n@1118 567 span.textContent = option.text;
n@1118 568 var hold = document.createElement('div');
n@1118 569 hold.setAttribute('name','option');
n@1118 570 hold.style.padding = '4px';
n@1118 571 hold.appendChild(input);
n@1118 572 hold.appendChild(span);
n@1124 573 this.popupResponse.appendChild(hold);
n@1161 574 if (node.response[index] != undefined){
n@1161 575 if (node.response[index].checked == true) {
n@1161 576 input.checked = "true";
n@1161 577 }
n@1161 578 }
n@1161 579 index++;
n@1118 580 }
n@1124 581 } else if (node.specification.type == 'radio') {
n@1161 582 if (node.response == undefined) {
n@1161 583 node.response = {name: "", text: ""};
n@1161 584 }
n@1161 585 var index = 0;
n@1124 586 for (var option of node.specification.options) {
n@1118 587 var input = document.createElement('input');
n@1118 588 input.id = option.name;
n@1118 589 input.type = 'radio';
n@1124 590 input.name = node.specification.id;
n@1118 591 var span = document.createElement('span');
n@1118 592 span.textContent = option.text;
n@1118 593 var hold = document.createElement('div');
n@1118 594 hold.setAttribute('name','option');
n@1118 595 hold.style.padding = '4px';
n@1118 596 hold.appendChild(input);
n@1118 597 hold.appendChild(span);
n@1124 598 this.popupResponse.appendChild(hold);
n@1161 599 if (input.id == node.response.name) {
n@1161 600 input.checked = "true";
n@1161 601 }
n@1118 602 }
n@1124 603 } else if (node.specification.type == 'number') {
n@1118 604 var input = document.createElement('input');
n@1118 605 input.type = 'textarea';
n@1124 606 if (node.min != null) {input.min = node.specification.min;}
n@1124 607 if (node.max != null) {input.max = node.specification.max;}
n@1124 608 if (node.step != null) {input.step = node.specification.step;}
n@1161 609 if (node.response != undefined) {
n@1161 610 input.value = node.response;
n@1161 611 }
n@1118 612 this.popupResponse.appendChild(input);
n@1118 613 }
n@1118 614 if(this.currentIndex+1 == this.popupOptions.length) {
n@1124 615 if (this.node.location == "pre") {
n@1118 616 this.buttonProceed.textContent = 'Start';
n@1118 617 } else {
n@1118 618 this.buttonProceed.textContent = 'Submit';
n@1118 619 }
n@1118 620 } else {
n@1118 621 this.buttonProceed.textContent = 'Next';
n@1118 622 }
n@1118 623 if(this.currentIndex > 0)
n@1118 624 this.buttonPrevious.style.visibility = 'visible';
n@1118 625 else
n@1118 626 this.buttonPrevious.style.visibility = 'hidden';
n@1118 627 };
n@1118 628
n@1124 629 this.initState = function(node,store) {
n@1118 630 //Call this with your preTest and postTest nodes when needed to
n@1118 631 // initialise the popup procedure.
n@1124 632 if (node.options.length > 0) {
n@1124 633 this.popupOptions = [];
n@1124 634 this.node = node;
n@1124 635 this.store = store;
n@1124 636 for (var opt of node.options)
n@1124 637 {
n@1124 638 this.popupOptions.push({
n@1124 639 specification: opt,
n@1124 640 response: null
n@1124 641 });
n@1124 642 }
n@1118 643 this.currentIndex = 0;
n@1118 644 this.showPopup();
n@1118 645 this.postNode();
n@1118 646 } else {
n@1118 647 advanceState();
n@1118 648 }
n@1118 649 };
n@1118 650
n@1118 651 this.proceedClicked = function() {
n@1118 652 // Each time the popup button is clicked!
n@1118 653 var node = this.popupOptions[this.currentIndex];
n@1124 654 if (node.specification.type == 'question') {
n@1118 655 // Must extract the question data
n@1118 656 var textArea = $(popup.popupContent).find('textarea')[0];
n@1124 657 if (node.specification.mandatory == true && textArea.value.length == 0) {
n@1118 658 alert('This question is mandatory');
n@1118 659 return;
n@1118 660 } else {
n@1118 661 // Save the text content
n@1124 662 console.log("Question: "+ node.specification.statement);
n@1118 663 console.log("Question Response: "+ textArea.value);
n@1124 664 node.response = textArea.value;
n@1118 665 }
n@1124 666 } else if (node.specification.type == 'checkbox') {
n@1118 667 // Must extract checkbox data
n@1126 668 console.log("Checkbox: "+ node.specification.statement);
n@1124 669 var inputs = this.popupResponse.getElementsByTagName('input');
n@1124 670 node.response = [];
n@1124 671 for (var i=0; i<node.specification.options.length; i++) {
n@1124 672 node.response.push({
n@1124 673 name: node.specification.options[i].name,
n@1124 674 text: node.specification.options[i].text,
n@1124 675 checked: inputs[i].checked
n@1124 676 });
n@1126 677 console.log(node.specification.options[i].name+": "+ inputs[i].checked);
n@1124 678 }
n@1124 679 } else if (node.specification.type == "radio") {
n@1118 680 var optHold = this.popupResponse;
n@1124 681 console.log("Radio: "+ node.specification.statement);
n@1124 682 node.response = null;
n@1118 683 var i=0;
n@1124 684 var inputs = optHold.getElementsByTagName('input');
n@1124 685 while(node.response == null) {
n@1124 686 if (i == inputs.length)
n@1124 687 {
n@1124 688 if (node.specification.mandatory == true)
n@1124 689 {
n@1124 690 alert("This radio is mandatory");
n@1124 691 } else {
n@1124 692 node.response = -1;
n@1124 693 }
n@1124 694 return;
n@1124 695 }
n@1124 696 if (inputs[i].checked == true) {
n@1124 697 node.response = node.specification.options[i];
n@1124 698 console.log("Selected: "+ node.specification.options[i].name);
n@1118 699 }
n@1118 700 i++;
n@1118 701 }
n@1124 702 } else if (node.specification.type == "number") {
n@1118 703 var input = this.popupContent.getElementsByTagName('input')[0];
n@1118 704 if (node.mandatory == true && input.value.length == 0) {
n@1118 705 alert('This question is mandatory. Please enter a number');
n@1118 706 return;
n@1118 707 }
n@1118 708 var enteredNumber = Number(input.value);
n@1118 709 if (isNaN(enteredNumber)) {
n@1118 710 alert('Please enter a valid number');
n@1118 711 return;
n@1118 712 }
n@1118 713 if (enteredNumber < node.min && node.min != null) {
n@1118 714 alert('Number is below the minimum value of '+node.min);
n@1118 715 return;
n@1118 716 }
n@1118 717 if (enteredNumber > node.max && node.max != null) {
n@1118 718 alert('Number is above the maximum value of '+node.max);
n@1118 719 return;
n@1118 720 }
n@1124 721 node.response = input.value;
n@1118 722 }
n@1118 723 this.currentIndex++;
n@1118 724 if (this.currentIndex < this.popupOptions.length) {
n@1118 725 this.postNode();
n@1118 726 } else {
n@1118 727 // Reached the end of the popupOptions
n@1118 728 this.hidePopup();
n@1124 729 for (var node of this.popupOptions)
n@1124 730 {
n@1124 731 this.store.postResult(node);
n@1118 732 }
n@1118 733 advanceState();
n@1118 734 }
n@1118 735 };
n@1118 736
n@1118 737 this.previousClick = function() {
n@1118 738 // Triggered when the 'Back' button is clicked in the survey
n@1118 739 if (this.currentIndex > 0) {
n@1118 740 this.currentIndex--;
n@1118 741 this.postNode();
n@1118 742 }
n@1118 743 };
n@1118 744
n@1118 745 this.resize = function(event)
n@1118 746 {
n@1118 747 // Called on window resize;
n@1144 748 if (this.popup != null) {
n@1144 749 this.popup.style.left = (window.innerWidth/2)-250 + 'px';
n@1144 750 this.popup.style.top = (window.innerHeight/2)-125 + 'px';
n@1144 751 var blank = document.getElementsByClassName('testHalt')[0];
n@1144 752 blank.style.width = window.innerWidth;
n@1144 753 blank.style.height = window.innerHeight;
n@1144 754 }
n@1118 755 };
n@1118 756 }
n@1118 757
n@1118 758 function advanceState()
n@1118 759 {
n@1118 760 // Just for complete clarity
n@1118 761 testState.advanceState();
n@1118 762 }
n@1118 763
n@1118 764 function stateMachine()
n@1118 765 {
n@1118 766 // Object prototype for tracking and managing the test state
n@1118 767 this.stateMap = [];
n@1124 768 this.preTestSurvey = null;
n@1124 769 this.postTestSurvey = null;
n@1118 770 this.stateIndex = null;
n@1124 771 this.currentStateMap = null;
n@1124 772 this.currentStatePosition = null;
n@1154 773 this.currentStore = null;
n@1118 774 this.initialise = function(){
n@1124 775
n@1124 776 // Get the data from Specification
n@1124 777 var pageHolder = [];
n@1124 778 for (var page of specification.pages)
n@1124 779 {
n@1124 780 pageHolder.push(page);
n@1124 781 }
n@1124 782 if (specification.randomiseOrder)
n@1124 783 {
n@1124 784 pageHolder = randomiseOrder(pageHolder);
n@1124 785 }
n@1124 786 for (var i=0; i<pageHolder.length; i++)
n@1124 787 {
n@1124 788 pageHolder[i].presentedId = i;
n@1124 789 }
n@1124 790 for (var i=0; i<specification.pages.length; i++)
n@1124 791 {
n@1124 792 if (specification.testPages < i && specification.testPages != 0) {break;}
n@1124 793 this.stateMap.push(pageHolder[i]);
n@1124 794
n@1124 795 }
n@1124 796 if (specification.preTest != null) {this.preTestSurvey = specification.preTest;}
n@1124 797 if (specification.postTest != null) {this.postTestSurvey = specification.postTest;}
n@1124 798
n@1118 799 if (this.stateMap.length > 0) {
n@1118 800 if(this.stateIndex != null) {
n@1118 801 console.log('NOTE - State already initialise');
n@1118 802 }
n@1118 803 this.stateIndex = -1;
n@1118 804 } else {
n@1118 805 console.log('FATAL - StateMap not correctly constructed. EMPTY_STATE_MAP');
n@1118 806 }
n@1118 807 };
n@1118 808 this.advanceState = function(){
n@1118 809 if (this.stateIndex == null) {
n@1118 810 this.initialise();
n@1118 811 }
n@1118 812 if (this.stateIndex == -1) {
n@1142 813 this.stateIndex++;
n@1118 814 console.log('Starting test...');
n@1124 815 if (this.preTestSurvey != null)
n@1124 816 {
n@1124 817 popup.initState(this.preTestSurvey,storage.globalPreTest);
n@1142 818 } else {
n@1142 819 this.advanceState();
n@1118 820 }
n@1124 821 } else if (this.stateIndex == this.stateMap.length)
n@1124 822 {
n@1124 823 // All test pages complete, post test
n@1124 824 console.log('Ending test ...');
n@1124 825 this.stateIndex++;
n@1124 826 if (this.postTestSurvey == null) {
n@1124 827 this.advanceState();
n@1118 828 } else {
n@1124 829 popup.initState(this.postTestSurvey,storage.globalPostTest);
n@1124 830 }
n@1124 831 } else if (this.stateIndex > this.stateMap.length)
n@1124 832 {
n@1124 833 createProjectSave(specification.projectReturn);
n@1124 834 }
n@1124 835 else
n@1124 836 {
n@1124 837 if (this.currentStateMap == null)
n@1124 838 {
n@1118 839 this.currentStateMap = this.stateMap[this.stateIndex];
n@1134 840 if (this.currentStateMap.randomiseOrder)
n@1134 841 {
n@1134 842 this.currentStateMap.audioElements = randomiseOrder(this.currentStateMap.audioElements);
n@1134 843 }
n@1154 844 this.currentStore = storage.createTestPageStore(this.currentStateMap);
n@1124 845 if (this.currentStateMap.preTest != null)
n@1124 846 {
n@1124 847 this.currentStatePosition = 'pre';
n@1124 848 popup.initState(this.currentStateMap.preTest,storage.testPages[this.stateIndex].preTest);
n@1118 849 } else {
n@1124 850 this.currentStatePosition = 'test';
n@1124 851 }
n@1124 852 interfaceContext.newPage(this.currentStateMap,storage.testPages[this.stateIndex]);
n@1124 853 return;
n@1124 854 }
n@1124 855 switch(this.currentStatePosition)
n@1124 856 {
n@1124 857 case 'pre':
n@1124 858 this.currentStatePosition = 'test';
n@1124 859 break;
n@1124 860 case 'test':
n@1124 861 this.currentStatePosition = 'post';
n@1124 862 // Save the data
n@1124 863 this.testPageCompleted();
n@1124 864 if (this.currentStateMap.postTest == null)
n@1124 865 {
n@1118 866 this.advanceState();
n@1124 867 return;
n@1124 868 } else {
n@1124 869 popup.initState(this.currentStateMap.postTest,storage.testPages[this.stateIndex].postTest);
n@1118 870 }
n@1124 871 break;
n@1124 872 case 'post':
n@1124 873 this.stateIndex++;
n@1124 874 this.currentStateMap = null;
n@1124 875 this.advanceState();
n@1124 876 break;
n@1124 877 };
n@1118 878 }
n@1118 879 };
n@1118 880
n@1124 881 this.testPageCompleted = function() {
n@1118 882 // Function called each time a test page has been completed
n@1124 883 var storePoint = storage.testPages[this.stateIndex];
n@1124 884 // First get the test metric
n@1124 885
n@1124 886 var metric = storePoint.XMLDOM.getElementsByTagName('metric')[0];
n@1118 887 if (audioEngineContext.metric.enableTestTimer)
n@1118 888 {
n@1124 889 var testTime = storePoint.parent.document.createElement('metricresult');
n@1118 890 testTime.id = 'testTime';
n@1118 891 testTime.textContent = audioEngineContext.timer.testDuration;
n@1118 892 metric.appendChild(testTime);
n@1118 893 }
n@1124 894
n@1118 895 var audioObjects = audioEngineContext.audioObjects;
n@1124 896 for (var ao of audioEngineContext.audioObjects)
n@1118 897 {
n@1124 898 ao.exportXMLDOM();
n@1118 899 }
n@1124 900 for (var element of interfaceContext.commentQuestions)
n@1124 901 {
n@1124 902 element.exportXMLDOM(storePoint);
n@1124 903 }
n@1124 904 pageXMLSave(storePoint.XMLDOM, this.currentStateMap);
n@1118 905 };
n@1118 906 }
n@1118 907
n@1118 908 function AudioEngine(specification) {
n@1118 909
n@1118 910 // Create two output paths, the main outputGain and fooGain.
n@1118 911 // Output gain is default to 1 and any items for playback route here
n@1118 912 // Foo gain is used for analysis to ensure paths get processed, but are not heard
n@1118 913 // because web audio will optimise and any route which does not go to the destination gets ignored.
n@1118 914 this.outputGain = audioContext.createGain();
n@1118 915 this.fooGain = audioContext.createGain();
n@1118 916 this.fooGain.gain = 0;
n@1118 917
n@1118 918 // Use this to detect playback state: 0 - stopped, 1 - playing
n@1118 919 this.status = 0;
n@1118 920
n@1118 921 // Connect both gains to output
n@1118 922 this.outputGain.connect(audioContext.destination);
n@1118 923 this.fooGain.connect(audioContext.destination);
n@1118 924
n@1118 925 // Create the timer Object
n@1118 926 this.timer = new timer();
n@1118 927 // Create session metrics
n@1118 928 this.metric = new sessionMetrics(this,specification);
n@1118 929
n@1118 930 this.loopPlayback = false;
n@1118 931
n@1124 932 this.pageStore = null;
n@1124 933
n@1118 934 // Create store for new audioObjects
n@1118 935 this.audioObjects = [];
n@1118 936
n@1118 937 this.buffers = [];
n@1118 938 this.bufferObj = function()
n@1118 939 {
n@1118 940 this.url = null;
n@1118 941 this.buffer = null;
n@1118 942 this.xmlRequest = new XMLHttpRequest();
n@1118 943 this.xmlRequest.parent = this;
n@1118 944 this.users = [];
n@1116 945 this.progress = 0;
n@1116 946 this.status = 0;
n@1142 947 this.ready = function()
n@1142 948 {
n@1116 949 if (this.status >= 2)
n@1116 950 {
n@1116 951 this.status = 3;
n@1116 952 }
n@1142 953 for (var i=0; i<this.users.length; i++)
n@1142 954 {
n@1142 955 this.users[i].state = 1;
n@1142 956 if (this.users[i].interfaceDOM != null)
n@1142 957 {
n@1142 958 this.users[i].bufferLoaded(this);
n@1142 959 }
n@1142 960 }
n@1142 961 };
n@1118 962 this.getMedia = function(url) {
n@1118 963 this.url = url;
n@1118 964 this.xmlRequest.open('GET',this.url,true);
n@1118 965 this.xmlRequest.responseType = 'arraybuffer';
n@1118 966
n@1118 967 var bufferObj = this;
n@1118 968
n@1118 969 // Create callback to decode the data asynchronously
n@1118 970 this.xmlRequest.onloadend = function() {
n@1153 971 // Use inbuilt WAVE decoder first
n@1153 972 var waveObj = new WAVE();
n@1153 973 if (waveObj.open(bufferObj.xmlRequest.response) == 0)
n@1153 974 {
n@1153 975 bufferObj.buffer = audioContext.createBuffer(waveObj.num_channels,waveObj.num_samples,waveObj.sample_rate);
n@1153 976 for (var c=0; c<waveObj.num_channels; c++)
n@1153 977 {
n@1153 978 var buffer_ptr = bufferObj.buffer.getChannelData(c);
n@1153 979 for (var n=0; n<waveObj.num_samples; n++)
n@1153 980 {
n@1153 981 buffer_ptr[n] = waveObj.decoded_data[c][n];
n@1153 982 }
n@1153 983 }
n@1116 984
n@1153 985 delete waveObj;
n@1153 986 } else {
n@1153 987 audioContext.decodeAudioData(bufferObj.xmlRequest.response, function(decodedData) {
n@1153 988 bufferObj.buffer = decodedData;
n@1153 989 }, function(e){
n@1153 990 // Should only be called if there was an error, but sometimes gets called continuously
n@1153 991 // Check here if the error is genuine
n@1153 992 if (bufferObj.xmlRequest.response == undefined) {
n@1153 993 // Genuine error
n@1153 994 console.log('FATAL - Error loading buffer on '+audioObj.id);
n@1153 995 if (request.status == 404)
n@1153 996 {
n@1153 997 console.log('FATAL - Fragment '+audioObj.id+' 404 error');
n@1153 998 console.log('URL: '+audioObj.url);
n@1153 999 errorSessionDump('Fragment '+audioObj.id+' 404 error');
n@1153 1000 }
n@1116 1001 this.status = -1;
n@1153 1002 }
n@1153 1003 });
n@1153 1004 }
n@1153 1005 if (bufferObj.buffer != undefined)
n@1153 1006 {
n@1116 1007 bufferObj.status = 2;
n@1153 1008 calculateLoudness(bufferObj,"I");
n@1153 1009 }
n@1118 1010 };
n@1118 1011 this.progress = 0;
n@1118 1012 this.progressCallback = function(event){
n@1118 1013 if (event.lengthComputable)
n@1118 1014 {
n@1118 1015 this.parent.progress = event.loaded / event.total;
n@1118 1016 for (var i=0; i<this.parent.users.length; i++)
n@1118 1017 {
n@1118 1018 if(this.parent.users[i].interfaceDOM != null)
n@1118 1019 {
n@1118 1020 if (typeof this.parent.users[i].interfaceDOM.updateLoading === "function")
n@1118 1021 {
n@1118 1022 this.parent.users[i].interfaceDOM.updateLoading(this.parent.progress*100);
n@1118 1023 }
n@1118 1024 }
n@1118 1025 }
n@1118 1026 }
n@1118 1027 };
n@1118 1028 this.xmlRequest.addEventListener("progress", this.progressCallback);
n@1116 1029 this.status = 1;
n@1118 1030 this.xmlRequest.send();
n@1118 1031 };
n@1116 1032
n@1116 1033 this.registerAudioObject = function(audioObject)
n@1116 1034 {
n@1116 1035 // Called by an audioObject to register to the buffer for use
n@1116 1036 // First check if already in the register pool
n@1116 1037 for (var objects of this.users)
n@1116 1038 {
n@1116 1039 if (audioObject.id == objects.id){return 0;}
n@1116 1040 }
n@1116 1041 this.users.push(audioObject);
n@1116 1042 if (this.status == 3)
n@1116 1043 {
n@1116 1044 // The buffer is already ready, trigger bufferLoaded
n@1116 1045 audioObject.bufferLoaded(this);
n@1116 1046 }
n@1116 1047 }
n@1118 1048 };
n@1118 1049
n@1118 1050 this.play = function(id) {
n@1118 1051 // Start the timer and set the audioEngine state to playing (1)
n@1118 1052 if (this.status == 0 && this.loopPlayback) {
n@1118 1053 // Check if all audioObjects are ready
n@1118 1054 if(this.checkAllReady())
n@1118 1055 {
n@1118 1056 this.status = 1;
n@1118 1057 this.setSynchronousLoop();
n@1118 1058 }
n@1118 1059 }
n@1118 1060 else
n@1118 1061 {
n@1118 1062 this.status = 1;
n@1118 1063 }
n@1118 1064 if (this.status== 1) {
n@1118 1065 this.timer.startTest();
n@1118 1066 if (id == undefined) {
n@1118 1067 id = -1;
n@1118 1068 console.log('FATAL - Passed id was undefined - AudioEngineContext.play(id)');
n@1118 1069 return;
n@1118 1070 } else {
n@1118 1071 interfaceContext.playhead.setTimePerPixel(this.audioObjects[id]);
n@1118 1072 }
n@1118 1073 if (this.loopPlayback) {
n@1160 1074 var setTime = audioContext.currentTime+2;
n@1118 1075 for (var i=0; i<this.audioObjects.length; i++)
n@1118 1076 {
n@1160 1077 this.audioObjects[i].play(setTime-2);
n@1118 1078 if (id == i) {
n@1160 1079 this.audioObjects[i].loopStart(setTime);
n@1118 1080 } else {
n@1160 1081 this.audioObjects[i].loopStop(setTime);
n@1118 1082 }
n@1118 1083 }
n@1118 1084 } else {
n@1160 1085 var setTime = audioContext.currentTime+0.1;
n@1118 1086 for (var i=0; i<this.audioObjects.length; i++)
n@1118 1087 {
n@1118 1088 if (i != id) {
n@1160 1089 this.audioObjects[i].stop(setTime);
n@1118 1090 } else if (i == id) {
n@1160 1091 this.audioObjects[id].play(setTime);
n@1118 1092 }
n@1118 1093 }
n@1118 1094 }
n@1118 1095 interfaceContext.playhead.start();
n@1118 1096 }
n@1118 1097 };
n@1118 1098
n@1118 1099 this.stop = function() {
n@1118 1100 // Send stop and reset command to all playback buffers and set audioEngine state to stopped (1)
n@1118 1101 if (this.status == 1) {
n@1160 1102 var setTime = audioContext.currentTime+0.1;
n@1118 1103 for (var i=0; i<this.audioObjects.length; i++)
n@1118 1104 {
n@1160 1105 this.audioObjects[i].stop(setTime);
n@1118 1106 }
n@1118 1107 interfaceContext.playhead.stop();
n@1118 1108 this.status = 0;
n@1118 1109 }
n@1118 1110 };
n@1118 1111
n@1118 1112 this.newTrack = function(element) {
n@1118 1113 // Pull data from given URL into new audio buffer
n@1118 1114 // URLs must either be from the same source OR be setup to 'Access-Control-Allow-Origin'
n@1118 1115
n@1118 1116 // Create the audioObject with ID of the new track length;
n@1118 1117 audioObjectId = this.audioObjects.length;
n@1118 1118 this.audioObjects[audioObjectId] = new audioObject(audioObjectId);
n@1118 1119
n@1118 1120 // Check if audioObject buffer is currently stored by full URL
n@1124 1121 var URL = testState.currentStateMap.hostURL + element.url;
n@1118 1122 var buffer = null;
n@1118 1123 for (var i=0; i<this.buffers.length; i++)
n@1118 1124 {
n@1118 1125 if (URL == this.buffers[i].url)
n@1118 1126 {
n@1118 1127 buffer = this.buffers[i];
n@1118 1128 break;
n@1118 1129 }
n@1118 1130 }
n@1118 1131 if (buffer == null)
n@1118 1132 {
n@1118 1133 console.log("[WARN]: Buffer was not loaded in pre-test! "+URL);
n@1118 1134 buffer = new this.bufferObj();
n@1116 1135 this.buffers.push(buffer);
n@1118 1136 buffer.getMedia(URL);
n@1118 1137 }
n@1118 1138 this.audioObjects[audioObjectId].specification = element;
n@1118 1139 this.audioObjects[audioObjectId].url = URL;
n@1124 1140 // Obtain store node
n@1124 1141 var aeNodes = this.pageStore.XMLDOM.getElementsByTagName('audioelement');
n@1124 1142 for (var i=0; i<aeNodes.length; i++)
n@1124 1143 {
n@1124 1144 if(aeNodes[i].id == element.id)
n@1124 1145 {
n@1124 1146 this.audioObjects[audioObjectId].storeDOM = aeNodes[i];
n@1124 1147 break;
n@1124 1148 }
n@1124 1149 }
n@1116 1150 buffer.registerAudioObject(this.audioObjects[audioObjectId]);
n@1118 1151 return this.audioObjects[audioObjectId];
n@1118 1152 };
n@1118 1153
n@1169 1154 this.newTestPage = function(audioHolderObject,store) {
n@1124 1155 this.pageStore = store;
n@1118 1156 this.state = 0;
n@1118 1157 this.audioObjectsReady = false;
n@1118 1158 this.metric.reset();
n@1118 1159 for (var i=0; i < this.buffers.length; i++)
n@1118 1160 {
n@1118 1161 this.buffers[i].users = [];
n@1118 1162 }
n@1118 1163 this.audioObjects = [];
n@1169 1164 this.timer = new timer();
n@1169 1165 this.loopPlayback = audioHolderObject.loop;
n@1118 1166 };
n@1118 1167
n@1118 1168 this.checkAllPlayed = function() {
n@1118 1169 arr = [];
n@1118 1170 for (var id=0; id<this.audioObjects.length; id++) {
n@1118 1171 if (this.audioObjects[id].metric.wasListenedTo == false) {
n@1118 1172 arr.push(this.audioObjects[id].id);
n@1118 1173 }
n@1118 1174 }
n@1118 1175 return arr;
n@1118 1176 };
n@1118 1177
n@1118 1178 this.checkAllReady = function() {
n@1118 1179 var ready = true;
n@1118 1180 for (var i=0; i<this.audioObjects.length; i++) {
n@1118 1181 if (this.audioObjects[i].state == 0) {
n@1118 1182 // Track not ready
n@1118 1183 console.log('WAIT -- audioObject '+i+' not ready yet!');
n@1118 1184 ready = false;
n@1118 1185 };
n@1118 1186 }
n@1118 1187 return ready;
n@1118 1188 };
n@1118 1189
n@1118 1190 this.setSynchronousLoop = function() {
n@1118 1191 // Pads the signals so they are all exactly the same length
n@1118 1192 var length = 0;
n@1118 1193 var maxId;
n@1118 1194 for (var i=0; i<this.audioObjects.length; i++)
n@1118 1195 {
n@1118 1196 if (length < this.audioObjects[i].buffer.buffer.length)
n@1118 1197 {
n@1118 1198 length = this.audioObjects[i].buffer.buffer.length;
n@1118 1199 maxId = i;
n@1118 1200 }
n@1118 1201 }
n@1118 1202 // Extract the audio and zero-pad
n@1118 1203 for (var i=0; i<this.audioObjects.length; i++)
n@1118 1204 {
n@1118 1205 var orig = this.audioObjects[i].buffer.buffer;
n@1118 1206 var hold = audioContext.createBuffer(orig.numberOfChannels,length,orig.sampleRate);
n@1118 1207 for (var c=0; c<orig.numberOfChannels; c++)
n@1118 1208 {
n@1118 1209 var inData = hold.getChannelData(c);
n@1118 1210 var outData = orig.getChannelData(c);
n@1118 1211 for (var n=0; n<orig.length; n++)
n@1118 1212 {inData[n] = outData[n];}
n@1118 1213 }
n@1120 1214 hold.playbackGain = orig.playbackGain;
n@1118 1215 hold.lufs = orig.lufs;
n@1118 1216 this.audioObjects[i].buffer.buffer = hold;
n@1118 1217 }
n@1118 1218 };
n@1170 1219
n@1170 1220 this.exportXML = function()
n@1170 1221 {
n@1170 1222
n@1170 1223 };
n@1118 1224
n@1118 1225 }
n@1118 1226
n@1118 1227 function audioObject(id) {
n@1118 1228 // The main buffer object with common control nodes to the AudioEngine
n@1118 1229
n@1118 1230 this.specification;
n@1118 1231 this.id = id;
n@1118 1232 this.state = 0; // 0 - no data, 1 - ready
n@1118 1233 this.url = null; // Hold the URL given for the output back to the results.
n@1118 1234 this.metric = new metricTracker(this);
n@1124 1235 this.storeDOM = null;
n@1118 1236
n@1118 1237 // Bindings for GUI
n@1118 1238 this.interfaceDOM = null;
n@1118 1239 this.commentDOM = null;
n@1118 1240
n@1118 1241 // Create a buffer and external gain control to allow internal patching of effects and volume leveling.
n@1118 1242 this.bufferNode = undefined;
n@1118 1243 this.outputGain = audioContext.createGain();
n@1118 1244
n@1124 1245 this.onplayGain = 1.0;
n@1118 1246
n@1118 1247 // Connect buffer to the audio graph
n@1118 1248 this.outputGain.connect(audioEngineContext.outputGain);
n@1118 1249
n@1118 1250 // the audiobuffer is not designed for multi-start playback
n@1118 1251 // When stopeed, the buffer node is deleted and recreated with the stored buffer.
n@1118 1252 this.buffer;
n@1118 1253
n@1118 1254 this.bufferLoaded = function(callee)
n@1118 1255 {
n@1118 1256 // Called by the associated buffer when it has finished loading, will then 'bind' the buffer to the
n@1118 1257 // audioObject and trigger the interfaceDOM.enable() function for user feedback
n@1118 1258 if (audioEngineContext.loopPlayback){
n@1118 1259 // First copy the buffer into this.buffer
n@1118 1260 this.buffer = new audioEngineContext.bufferObj();
n@1118 1261 this.buffer.url = callee.url;
n@1118 1262 this.buffer.buffer = audioContext.createBuffer(callee.buffer.numberOfChannels, callee.buffer.length, callee.buffer.sampleRate);
n@1118 1263 for (var c=0; c<callee.buffer.numberOfChannels; c++)
n@1118 1264 {
n@1118 1265 var src = callee.buffer.getChannelData(c);
n@1118 1266 var dst = this.buffer.buffer.getChannelData(c);
n@1118 1267 for (var n=0; n<src.length; n++)
n@1118 1268 {
n@1118 1269 dst[n] = src[n];
n@1118 1270 }
n@1118 1271 }
n@1118 1272 } else {
n@1118 1273 this.buffer = callee;
n@1118 1274 }
n@1118 1275 this.state = 1;
n@1120 1276 this.buffer.buffer.playbackGain = callee.buffer.playbackGain;
n@1118 1277 this.buffer.buffer.lufs = callee.buffer.lufs;
n@1148 1278 var targetLUFS = this.specification.parent.loudness || specification.loudness;
n@1118 1279 if (typeof targetLUFS === "number")
n@1118 1280 {
n@1120 1281 this.buffer.buffer.playbackGain = decibelToLinear(targetLUFS - this.buffer.buffer.lufs);
n@1118 1282 } else {
n@1120 1283 this.buffer.buffer.playbackGain = 1.0;
n@1118 1284 }
n@1118 1285 if (this.interfaceDOM != null) {
n@1118 1286 this.interfaceDOM.enable();
n@1118 1287 }
n@1124 1288 this.onplayGain = decibelToLinear(this.specification.gain)*this.buffer.buffer.playbackGain;
n@1124 1289 this.storeDOM.setAttribute('playGain',linearToDecibel(this.onplayGain));
n@1118 1290 };
n@1125 1291
n@1125 1292 this.bindInterface = function(interfaceObject)
n@1125 1293 {
n@1125 1294 this.interfaceDOM = interfaceObject;
n@1125 1295 this.metric.initialise(interfaceObject.getValue());
n@1125 1296 if (this.state == 1)
n@1125 1297 {
n@1125 1298 this.interfaceDOM.enable();
n@1125 1299 }
n@1138 1300 this.storeDOM.setAttribute('presentedId',interfaceObject.getPresentedId());
n@1125 1301 };
n@1118 1302
n@1160 1303 this.loopStart = function(setTime) {
n@1160 1304 this.outputGain.gain.linearRampToValueAtTime(this.onplayGain,setTime);
n@1118 1305 this.metric.startListening(audioEngineContext.timer.getTestTime());
n@1160 1306 this.interfaceDOM.startPlayback();
n@1118 1307 };
n@1118 1308
n@1160 1309 this.loopStop = function(setTime) {
n@1118 1310 if (this.outputGain.gain.value != 0.0) {
n@1160 1311 this.outputGain.gain.linearRampToValueAtTime(0.0,setTime);
n@1118 1312 this.metric.stopListening(audioEngineContext.timer.getTestTime());
n@1118 1313 }
n@1160 1314 this.interfaceDOM.stopPlayback();
n@1118 1315 };
n@1118 1316
n@1118 1317 this.play = function(startTime) {
n@1118 1318 if (this.bufferNode == undefined && this.buffer.buffer != undefined) {
n@1118 1319 this.bufferNode = audioContext.createBufferSource();
n@1118 1320 this.bufferNode.owner = this;
n@1118 1321 this.bufferNode.connect(this.outputGain);
n@1118 1322 this.bufferNode.buffer = this.buffer.buffer;
n@1118 1323 this.bufferNode.loop = audioEngineContext.loopPlayback;
n@1118 1324 this.bufferNode.onended = function(event) {
n@1118 1325 // Safari does not like using 'this' to reference the calling object!
n@1118 1326 //event.currentTarget.owner.metric.stopListening(audioEngineContext.timer.getTestTime(),event.currentTarget.owner.getCurrentPosition());
n@1160 1327 event.currentTarget.owner.stop(audioContext.currentTime+1);
n@1118 1328 };
n@1118 1329 if (this.bufferNode.loop == false) {
n@1118 1330 this.metric.startListening(audioEngineContext.timer.getTestTime());
n@1160 1331 this.outputGain.gain.setValueAtTime(this.onplayGain,startTime);
n@1160 1332 this.interfaceDOM.startPlayback();
n@1160 1333 } else {
n@1160 1334 this.outputGain.gain.setValueAtTime(0.0,startTime);
n@1160 1335 }
n@1118 1336 this.bufferNode.start(startTime);
n@1118 1337 }
n@1118 1338 };
n@1118 1339
n@1160 1340 this.stop = function(stopTime) {
n@1160 1341 this.outputGain.gain.cancelScheduledValues(audioContext.currentTime);
n@1118 1342 if (this.bufferNode != undefined)
n@1118 1343 {
n@1118 1344 this.metric.stopListening(audioEngineContext.timer.getTestTime(),this.getCurrentPosition());
n@1160 1345 this.bufferNode.stop(stopTime);
n@1118 1346 this.bufferNode = undefined;
n@1118 1347 }
n@1160 1348 this.outputGain.gain.value = 0.0;
n@1160 1349 this.interfaceDOM.stopPlayback();
n@1118 1350 };
n@1118 1351
n@1118 1352 this.getCurrentPosition = function() {
n@1118 1353 var time = audioEngineContext.timer.getTestTime();
n@1118 1354 if (this.bufferNode != undefined) {
n@1118 1355 if (this.bufferNode.loop == true) {
n@1118 1356 if (audioEngineContext.status == 1) {
n@1118 1357 return (time-this.metric.listenStart)%this.buffer.buffer.duration;
n@1118 1358 } else {
n@1118 1359 return 0;
n@1118 1360 }
n@1118 1361 } else {
n@1118 1362 if (this.metric.listenHold) {
n@1118 1363 return time - this.metric.listenStart;
n@1118 1364 } else {
n@1118 1365 return 0;
n@1118 1366 }
n@1118 1367 }
n@1118 1368 } else {
n@1118 1369 return 0;
n@1118 1370 }
n@1118 1371 };
n@1118 1372
n@1118 1373 this.exportXMLDOM = function() {
n@1124 1374 var file = storage.document.createElement('file');
n@1118 1375 file.setAttribute('sampleRate',this.buffer.buffer.sampleRate);
n@1118 1376 file.setAttribute('channels',this.buffer.buffer.numberOfChannels);
n@1118 1377 file.setAttribute('sampleCount',this.buffer.buffer.length);
n@1118 1378 file.setAttribute('duration',this.buffer.buffer.duration);
n@1124 1379 this.storeDOM.appendChild(file);
n@1124 1380 if (this.specification.type != 'outside-reference') {
n@1118 1381 var interfaceXML = this.interfaceDOM.exportXMLDOM(this);
n@1140 1382 if (interfaceXML != null)
n@1140 1383 {
n@1140 1384 if (interfaceXML.length == undefined) {
n@1140 1385 this.storeDOM.appendChild(interfaceXML);
n@1140 1386 } else {
n@1140 1387 for (var i=0; i<interfaceXML.length; i++)
n@1140 1388 {
n@1140 1389 this.storeDOM.appendChild(interfaceXML[i]);
n@1140 1390 }
n@1118 1391 }
n@1118 1392 }
n@1130 1393 if (this.commentDOM != null) {
n@1130 1394 this.storeDOM.appendChild(this.commentDOM.exportXMLDOM(this));
n@1130 1395 }
n@1118 1396 }
n@1124 1397 var nodes = this.metric.exportXMLDOM();
n@1124 1398 var mroot = this.storeDOM.getElementsByTagName('metric')[0];
n@1124 1399 for (var i=0; i<nodes.length; i++)
n@1124 1400 {
n@1124 1401 mroot.appendChild(nodes[i]);
n@1124 1402 }
n@1118 1403 };
n@1118 1404 }
n@1118 1405
n@1118 1406 function timer()
n@1118 1407 {
n@1118 1408 /* Timer object used in audioEngine to keep track of session timings
n@1118 1409 * Uses the timer of the web audio API, so sample resolution
n@1118 1410 */
n@1118 1411 this.testStarted = false;
n@1118 1412 this.testStartTime = 0;
n@1118 1413 this.testDuration = 0;
n@1118 1414 this.minimumTestTime = 0; // No minimum test time
n@1118 1415 this.startTest = function()
n@1118 1416 {
n@1118 1417 if (this.testStarted == false)
n@1118 1418 {
n@1118 1419 this.testStartTime = audioContext.currentTime;
n@1118 1420 this.testStarted = true;
n@1118 1421 this.updateTestTime();
n@1118 1422 audioEngineContext.metric.initialiseTest();
n@1118 1423 }
n@1118 1424 };
n@1118 1425 this.stopTest = function()
n@1118 1426 {
n@1118 1427 if (this.testStarted)
n@1118 1428 {
n@1118 1429 this.testDuration = this.getTestTime();
n@1118 1430 this.testStarted = false;
n@1118 1431 } else {
n@1118 1432 console.log('ERR: Test tried to end before beginning');
n@1118 1433 }
n@1118 1434 };
n@1118 1435 this.updateTestTime = function()
n@1118 1436 {
n@1118 1437 if (this.testStarted)
n@1118 1438 {
n@1118 1439 this.testDuration = audioContext.currentTime - this.testStartTime;
n@1118 1440 }
n@1118 1441 };
n@1118 1442 this.getTestTime = function()
n@1118 1443 {
n@1118 1444 this.updateTestTime();
n@1118 1445 return this.testDuration;
n@1118 1446 };
n@1118 1447 }
n@1118 1448
n@1118 1449 function sessionMetrics(engine,specification)
n@1118 1450 {
n@1118 1451 /* Used by audioEngine to link to audioObjects to minimise the timer call timers;
n@1118 1452 */
n@1118 1453 this.engine = engine;
n@1118 1454 this.lastClicked = -1;
n@1118 1455 this.data = -1;
n@1118 1456 this.reset = function() {
n@1118 1457 this.lastClicked = -1;
n@1118 1458 this.data = -1;
n@1118 1459 };
n@1118 1460
n@1118 1461 this.enableElementInitialPosition = false;
n@1118 1462 this.enableElementListenTracker = false;
n@1118 1463 this.enableElementTimer = false;
n@1118 1464 this.enableElementTracker = false;
n@1118 1465 this.enableFlagListenedTo = false;
n@1118 1466 this.enableFlagMoved = false;
n@1118 1467 this.enableTestTimer = false;
n@1118 1468 // Obtain the metrics enabled
n@1124 1469 for (var i=0; i<specification.metrics.enabled.length; i++)
n@1118 1470 {
n@1124 1471 var node = specification.metrics.enabled[i];
n@1124 1472 switch(node)
n@1118 1473 {
n@1118 1474 case 'testTimer':
n@1118 1475 this.enableTestTimer = true;
n@1118 1476 break;
n@1118 1477 case 'elementTimer':
n@1118 1478 this.enableElementTimer = true;
n@1118 1479 break;
n@1118 1480 case 'elementTracker':
n@1118 1481 this.enableElementTracker = true;
n@1118 1482 break;
n@1118 1483 case 'elementListenTracker':
n@1118 1484 this.enableElementListenTracker = true;
n@1118 1485 break;
n@1118 1486 case 'elementInitialPosition':
n@1118 1487 this.enableElementInitialPosition = true;
n@1118 1488 break;
n@1118 1489 case 'elementFlagListenedTo':
n@1118 1490 this.enableFlagListenedTo = true;
n@1118 1491 break;
n@1118 1492 case 'elementFlagMoved':
n@1118 1493 this.enableFlagMoved = true;
n@1118 1494 break;
n@1118 1495 case 'elementFlagComments':
n@1118 1496 this.enableFlagComments = true;
n@1118 1497 break;
n@1118 1498 }
n@1118 1499 }
n@1118 1500 this.initialiseTest = function(){};
n@1118 1501 }
n@1118 1502
n@1118 1503 function metricTracker(caller)
n@1118 1504 {
n@1118 1505 /* Custom object to track and collect metric data
n@1118 1506 * Used only inside the audioObjects object.
n@1118 1507 */
n@1118 1508
n@1118 1509 this.listenedTimer = 0;
n@1118 1510 this.listenStart = 0;
n@1118 1511 this.listenHold = false;
n@1118 1512 this.initialPosition = -1;
n@1118 1513 this.movementTracker = [];
n@1118 1514 this.listenTracker =[];
n@1118 1515 this.wasListenedTo = false;
n@1118 1516 this.wasMoved = false;
n@1118 1517 this.hasComments = false;
n@1118 1518 this.parent = caller;
n@1118 1519
n@1124 1520 this.initialise = function(position)
n@1118 1521 {
n@1118 1522 if (this.initialPosition == -1) {
n@1118 1523 this.initialPosition = position;
n@1125 1524 this.moved(0,position);
n@1118 1525 }
n@1118 1526 };
n@1118 1527
n@1118 1528 this.moved = function(time,position)
n@1118 1529 {
n@1125 1530 if (time > 0) {this.wasMoved = true;}
n@1118 1531 this.movementTracker[this.movementTracker.length] = [time, position];
n@1118 1532 };
n@1118 1533
n@1118 1534 this.startListening = function(time)
n@1118 1535 {
n@1118 1536 if (this.listenHold == false)
n@1118 1537 {
n@1118 1538 this.wasListenedTo = true;
n@1118 1539 this.listenStart = time;
n@1118 1540 this.listenHold = true;
n@1118 1541
n@1118 1542 var evnt = document.createElement('event');
n@1118 1543 var testTime = document.createElement('testTime');
n@1118 1544 testTime.setAttribute('start',time);
n@1118 1545 var bufferTime = document.createElement('bufferTime');
n@1118 1546 bufferTime.setAttribute('start',this.parent.getCurrentPosition());
n@1118 1547 evnt.appendChild(testTime);
n@1118 1548 evnt.appendChild(bufferTime);
n@1118 1549 this.listenTracker.push(evnt);
n@1118 1550
n@1118 1551 console.log('slider ' + this.parent.id + ' played (' + time + ')'); // DEBUG/SAFETY: show played slider id
n@1118 1552 }
n@1118 1553 };
n@1118 1554
n@1118 1555 this.stopListening = function(time,bufferStopTime)
n@1118 1556 {
n@1118 1557 if (this.listenHold == true)
n@1118 1558 {
n@1118 1559 var diff = time - this.listenStart;
n@1118 1560 this.listenedTimer += (diff);
n@1118 1561 this.listenStart = 0;
n@1118 1562 this.listenHold = false;
n@1118 1563
n@1118 1564 var evnt = this.listenTracker[this.listenTracker.length-1];
n@1118 1565 var testTime = evnt.getElementsByTagName('testTime')[0];
n@1118 1566 var bufferTime = evnt.getElementsByTagName('bufferTime')[0];
n@1118 1567 testTime.setAttribute('stop',time);
n@1118 1568 if (bufferStopTime == undefined) {
n@1118 1569 bufferTime.setAttribute('stop',this.parent.getCurrentPosition());
n@1118 1570 } else {
n@1118 1571 bufferTime.setAttribute('stop',bufferStopTime);
n@1118 1572 }
n@1118 1573 console.log('slider ' + this.parent.id + ' played for (' + diff + ')'); // DEBUG/SAFETY: show played slider id
n@1118 1574 }
n@1118 1575 };
n@1118 1576
n@1118 1577 this.exportXMLDOM = function() {
n@1124 1578 var storeDOM = [];
n@1118 1579 if (audioEngineContext.metric.enableElementTimer) {
n@1124 1580 var mElementTimer = storage.document.createElement('metricresult');
n@1118 1581 mElementTimer.setAttribute('name','enableElementTimer');
n@1118 1582 mElementTimer.textContent = this.listenedTimer;
n@1124 1583 storeDOM.push(mElementTimer);
n@1118 1584 }
n@1118 1585 if (audioEngineContext.metric.enableElementTracker) {
n@1124 1586 var elementTrackerFull = storage.document.createElement('metricResult');
n@1118 1587 elementTrackerFull.setAttribute('name','elementTrackerFull');
n@1118 1588 for (var k=0; k<this.movementTracker.length; k++)
n@1118 1589 {
n@1124 1590 var timePos = storage.document.createElement('timePos');
n@1118 1591 timePos.id = k;
n@1124 1592 var time = storage.document.createElement('time');
n@1118 1593 time.textContent = this.movementTracker[k][0];
n@1118 1594 var position = document.createElement('position');
n@1118 1595 position.textContent = this.movementTracker[k][1];
n@1118 1596 timePos.appendChild(time);
n@1118 1597 timePos.appendChild(position);
n@1118 1598 elementTrackerFull.appendChild(timePos);
n@1118 1599 }
n@1124 1600 storeDOM.push(elementTrackerFull);
n@1118 1601 }
n@1118 1602 if (audioEngineContext.metric.enableElementListenTracker) {
n@1124 1603 var elementListenTracker = storage.document.createElement('metricResult');
n@1118 1604 elementListenTracker.setAttribute('name','elementListenTracker');
n@1118 1605 for (var k=0; k<this.listenTracker.length; k++) {
n@1118 1606 elementListenTracker.appendChild(this.listenTracker[k]);
n@1118 1607 }
n@1124 1608 storeDOM.push(elementListenTracker);
n@1118 1609 }
n@1118 1610 if (audioEngineContext.metric.enableElementInitialPosition) {
n@1124 1611 var elementInitial = storage.document.createElement('metricResult');
n@1118 1612 elementInitial.setAttribute('name','elementInitialPosition');
n@1118 1613 elementInitial.textContent = this.initialPosition;
n@1124 1614 storeDOM.push(elementInitial);
n@1118 1615 }
n@1118 1616 if (audioEngineContext.metric.enableFlagListenedTo) {
n@1124 1617 var flagListenedTo = storage.document.createElement('metricResult');
n@1118 1618 flagListenedTo.setAttribute('name','elementFlagListenedTo');
n@1118 1619 flagListenedTo.textContent = this.wasListenedTo;
n@1124 1620 storeDOM.push(flagListenedTo);
n@1118 1621 }
n@1118 1622 if (audioEngineContext.metric.enableFlagMoved) {
n@1124 1623 var flagMoved = storage.document.createElement('metricResult');
n@1118 1624 flagMoved.setAttribute('name','elementFlagMoved');
n@1118 1625 flagMoved.textContent = this.wasMoved;
n@1124 1626 storeDOM.push(flagMoved);
n@1118 1627 }
n@1118 1628 if (audioEngineContext.metric.enableFlagComments) {
n@1124 1629 var flagComments = storage.document.createElement('metricResult');
n@1118 1630 flagComments.setAttribute('name','elementFlagComments');
n@1118 1631 if (this.parent.commentDOM == null)
n@1118 1632 {flag.textContent = 'false';}
n@1118 1633 else if (this.parent.commentDOM.textContent.length == 0)
n@1118 1634 {flag.textContent = 'false';}
n@1118 1635 else
n@1118 1636 {flag.textContet = 'true';}
n@1124 1637 storeDOM.push(flagComments);
n@1118 1638 }
n@1124 1639 return storeDOM;
n@1118 1640 };
n@1118 1641 }
n@1118 1642
n@1118 1643 function randomiseOrder(input)
n@1118 1644 {
n@1118 1645 // This takes an array of information and randomises the order
n@1118 1646 var N = input.length;
n@1118 1647
n@1118 1648 var inputSequence = []; // For safety purposes: keep track of randomisation
n@1118 1649 for (var counter = 0; counter < N; ++counter)
n@1118 1650 inputSequence.push(counter) // Fill array
n@1118 1651 var inputSequenceClone = inputSequence.slice(0);
n@1118 1652
n@1118 1653 var holdArr = [];
n@1118 1654 var outputSequence = [];
n@1118 1655 for (var n=0; n<N; n++)
n@1118 1656 {
n@1118 1657 // First pick a random number
n@1118 1658 var r = Math.random();
n@1118 1659 // Multiply and floor by the number of elements left
n@1118 1660 r = Math.floor(r*input.length);
n@1118 1661 // Pick out that element and delete from the array
n@1118 1662 holdArr.push(input.splice(r,1)[0]);
n@1118 1663 // Do the same with sequence
n@1118 1664 outputSequence.push(inputSequence.splice(r,1)[0]);
n@1118 1665 }
n@1118 1666 console.log(inputSequenceClone.toString()); // print original array to console
n@1118 1667 console.log(outputSequence.toString()); // print randomised array to console
n@1118 1668 return holdArr;
n@1118 1669 }
n@1118 1670
n@1118 1671 function returnDateNode()
n@1118 1672 {
n@1118 1673 // Create an XML Node for the Date and Time a test was conducted
n@1118 1674 // Structure is
n@1118 1675 // <datetime>
n@1118 1676 // <date year="##" month="##" day="##">DD/MM/YY</date>
n@1118 1677 // <time hour="##" minute="##" sec="##">HH:MM:SS</time>
n@1118 1678 // </datetime>
n@1118 1679 var dateTime = new Date();
n@1118 1680 var year = document.createAttribute('year');
n@1118 1681 var month = document.createAttribute('month');
n@1118 1682 var day = document.createAttribute('day');
n@1118 1683 var hour = document.createAttribute('hour');
n@1118 1684 var minute = document.createAttribute('minute');
n@1118 1685 var secs = document.createAttribute('secs');
n@1118 1686
n@1118 1687 year.nodeValue = dateTime.getFullYear();
n@1118 1688 month.nodeValue = dateTime.getMonth()+1;
n@1118 1689 day.nodeValue = dateTime.getDate();
n@1118 1690 hour.nodeValue = dateTime.getHours();
n@1118 1691 minute.nodeValue = dateTime.getMinutes();
n@1118 1692 secs.nodeValue = dateTime.getSeconds();
n@1118 1693
n@1118 1694 var hold = document.createElement("datetime");
n@1118 1695 var date = document.createElement("date");
n@1118 1696 date.textContent = year.nodeValue+'/'+month.nodeValue+'/'+day.nodeValue;
n@1118 1697 var time = document.createElement("time");
n@1118 1698 time.textContent = hour.nodeValue+':'+minute.nodeValue+':'+secs.nodeValue;
n@1118 1699
n@1118 1700 date.setAttributeNode(year);
n@1118 1701 date.setAttributeNode(month);
n@1118 1702 date.setAttributeNode(day);
n@1118 1703 time.setAttributeNode(hour);
n@1118 1704 time.setAttributeNode(minute);
n@1118 1705 time.setAttributeNode(secs);
n@1118 1706
n@1118 1707 hold.appendChild(date);
n@1118 1708 hold.appendChild(time);
n@1118 1709 return hold;
n@1118 1710
n@1118 1711 }
n@1118 1712
n@1118 1713 function Specification() {
n@1118 1714 // Handles the decoding of the project specification XML into a simple JavaScript Object.
n@1118 1715
n@1124 1716 this.interface = null;
n@1173 1717 this.projectReturn = "null";
n@1124 1718 this.randomiseOrder = null;
n@1124 1719 this.testPages = null;
n@1124 1720 this.pages = [];
n@1124 1721 this.metrics = null;
n@1124 1722 this.interfaces = null;
n@1124 1723 this.loudness = null;
n@1124 1724 this.errors = [];
n@1124 1725 this.schema = null;
n@1118 1726
n@1124 1727 this.processAttribute = function(attribute,schema)
n@1124 1728 {
n@1124 1729 // attribute is the string returned from getAttribute on the XML
n@1124 1730 // schema is the <xs:attribute> node
n@1124 1731 if (schema.getAttribute('name') == undefined && schema.getAttribute('ref') != undefined)
n@1124 1732 {
n@1148 1733 schema = this.schema.getAllElementsByName(schema.getAttribute('ref'))[0];
n@1124 1734 }
n@1124 1735 var defaultOpt = schema.getAttribute('default');
n@1124 1736 if (attribute == null) {
n@1124 1737 attribute = defaultOpt;
n@1124 1738 }
n@1124 1739 var dataType = schema.getAttribute('type');
n@1124 1740 if (typeof dataType == "string") { dataType = dataType.substr(3);}
n@1124 1741 else {dataType = "string";}
n@1124 1742 if (attribute == null)
n@1124 1743 {
n@1124 1744 return attribute;
n@1124 1745 }
n@1124 1746 switch(dataType)
n@1124 1747 {
n@1124 1748 case "boolean":
n@1124 1749 if (attribute == 'true'){attribute = true;}else{attribute=false;}
n@1124 1750 break;
n@1124 1751 case "negativeInteger":
n@1124 1752 case "positiveInteger":
n@1124 1753 case "nonNegativeInteger":
n@1124 1754 case "nonPositiveInteger":
n@1124 1755 case "integer":
n@1124 1756 case "decimal":
n@1124 1757 case "short":
n@1124 1758 attribute = Number(attribute);
n@1124 1759 break;
n@1124 1760 case "string":
n@1124 1761 default:
n@1124 1762 attribute = String(attribute);
n@1124 1763 break;
n@1124 1764 }
n@1124 1765 return attribute;
n@1124 1766 };
n@1118 1767
n@1118 1768 this.decode = function(projectXML) {
n@1124 1769 this.errors = [];
n@1118 1770 // projectXML - DOM Parsed document
n@1118 1771 this.projectXML = projectXML.childNodes[0];
n@1118 1772 var setupNode = projectXML.getElementsByTagName('setup')[0];
n@1148 1773 var schemaSetup = this.schema.getAllElementsByName('setup')[0];
n@1124 1774 // First decode the attributes
n@1148 1775 var attributes = schemaSetup.getAllElementsByTagName('xs:attribute');
n@1124 1776 for (var i in attributes)
n@1118 1777 {
n@1124 1778 if (isNaN(Number(i)) == true){break;}
n@1124 1779 var attributeName = attributes[i].getAttribute('name');
n@1124 1780 var projectAttr = setupNode.getAttribute(attributeName);
n@1124 1781 projectAttr = this.processAttribute(projectAttr,attributes[i]);
n@1124 1782 switch(typeof projectAttr)
n@1118 1783 {
n@1124 1784 case "number":
n@1124 1785 case "boolean":
n@1124 1786 eval('this.'+attributeName+' = '+projectAttr);
n@1124 1787 break;
n@1124 1788 case "string":
n@1124 1789 eval('this.'+attributeName+' = "'+projectAttr+'"');
n@1124 1790 break;
n@1118 1791 }
n@1124 1792
n@1118 1793 }
n@1118 1794
n@1170 1795 this.metrics = new this.metricNode();
n@1118 1796
n@1124 1797 this.metrics.decode(this,setupNode.getElementsByTagName('metric')[0]);
n@1124 1798
n@1124 1799 // Now process the survey node options
n@1124 1800 var survey = setupNode.getElementsByTagName('survey');
n@1124 1801 for (var i in survey) {
n@1124 1802 if (isNaN(Number(i)) == true){break;}
n@1124 1803 var location = survey[i].getAttribute('location');
n@1124 1804 if (location == 'pre' || location == 'before')
n@1124 1805 {
n@1124 1806 if (this.preTest != null){this.errors.push("Already a pre/before test survey defined! Ignoring second!!");}
n@1124 1807 else {
n@1124 1808 this.preTest = new this.surveyNode();
n@1170 1809 this.preTest.decode(this,survey[i]);
n@1124 1810 }
n@1124 1811 } else if (location == 'post' || location == 'after') {
n@1124 1812 if (this.postTest != null){this.errors.push("Already a post/after test survey defined! Ignoring second!!");}
n@1124 1813 else {
n@1124 1814 this.postTest = new this.surveyNode();
n@1170 1815 this.postTest.decode(this,survey[i]);
n@1124 1816 }
n@1118 1817 }
n@1118 1818 }
n@1118 1819
n@1124 1820 var interfaceNode = setupNode.getElementsByTagName('interface');
n@1124 1821 if (interfaceNode.length > 1)
n@1124 1822 {
n@1124 1823 this.errors.push("Only one <interface> node in the <setup> node allowed! Others except first ingnored!");
n@1124 1824 }
n@1124 1825 this.interfaces = new this.interfaceNode();
n@1124 1826 if (interfaceNode.length != 0)
n@1124 1827 {
n@1124 1828 interfaceNode = interfaceNode[0];
n@1148 1829 this.interfaces.decode(this,interfaceNode,this.schema.getAllElementsByName('interface')[1]);
n@1118 1830 }
n@1118 1831
n@1124 1832 // Page tags
n@1124 1833 var pageTags = projectXML.getElementsByTagName('page');
n@1148 1834 var pageSchema = this.schema.getAllElementsByName('page')[0];
n@1124 1835 for (var i=0; i<pageTags.length; i++)
n@1118 1836 {
n@1124 1837 var node = new this.page();
n@1124 1838 node.decode(this,pageTags[i],pageSchema);
n@1124 1839 this.pages.push(node);
n@1118 1840 }
n@1118 1841 };
n@1118 1842
n@1118 1843 this.encode = function()
n@1118 1844 {
n@1172 1845 var RootDocument = document.implementation.createDocument(null,"waet");
n@1172 1846 var root = RootDocument.children[0];
n@1172 1847 root.setAttribute("xmlns:xsi","http://www.w3.org/2001/XMLSchema-instance");
n@1172 1848 root.setAttribute("xsi:noNamespaceSchemaLocation","test-schema.xsd");
n@1124 1849 // Build setup node
n@1172 1850 var setup = RootDocument.createElement("setup");
n@1172 1851 var schemaSetup = this.schema.getAllElementsByName('setup')[0];
n@1172 1852 // First decode the attributes
n@1172 1853 var attributes = schemaSetup.getAllElementsByTagName('xs:attribute');
n@1172 1854 for (var i=0; i<attributes.length; i++)
n@1172 1855 {
n@1172 1856 var name = attributes[i].getAttribute("name");
n@1172 1857 if (name == undefined) {
n@1172 1858 name = attributes[i].getAttribute("ref");
n@1172 1859 }
n@1172 1860 if(eval("this."+name+" != undefined") || attributes[i].getAttribute("use") == "required")
n@1172 1861 {
n@1172 1862 eval("setup.setAttribute('"+name+"',this."+name+")");
n@1172 1863 }
n@1172 1864 }
n@1172 1865 root.appendChild(setup);
n@1172 1866 // Survey node
n@1172 1867 setup.appendChild(this.preTest.encode(RootDocument));
n@1172 1868 setup.appendChild(this.postTest.encode(RootDocument));
n@1172 1869 setup.appendChild(this.metrics.encode(RootDocument));
n@1172 1870 setup.appendChild(this.interfaces.encode(RootDocument));
n@1172 1871 for (var page of this.pages)
n@1172 1872 {
n@1172 1873 root.appendChild(page.encode(RootDocument));
n@1172 1874 }
n@1172 1875 return RootDocument;
n@1118 1876 };
n@1118 1877
n@1124 1878 this.surveyNode = function() {
n@1124 1879 this.location = null;
n@1118 1880 this.options = [];
n@1170 1881 this.schema = specification.schema.getAllElementsByName('survey')[0];
n@1118 1882
n@1118 1883 this.OptionNode = function() {
n@1118 1884 this.type = undefined;
n@1170 1885 this.schema = specification.schema.getAllElementsByName('surveyentry')[0];
n@1118 1886 this.id = undefined;
n@1118 1887 this.mandatory = undefined;
n@1118 1888 this.statement = undefined;
n@1118 1889 this.boxsize = undefined;
n@1118 1890 this.options = [];
n@1118 1891 this.min = undefined;
n@1118 1892 this.max = undefined;
n@1118 1893 this.step = undefined;
n@1118 1894
n@1170 1895 this.decode = function(parent,child)
n@1118 1896 {
n@1170 1897 var attributeMap = this.schema.getAllElementsByTagName('xs:attribute');
n@1124 1898 for (var i in attributeMap){
n@1124 1899 if(isNaN(Number(i)) == true){break;}
n@1124 1900 var attributeName = attributeMap[i].getAttribute('name') || attributeMap[i].getAttribute('ref');
n@1124 1901 var projectAttr = child.getAttribute(attributeName);
n@1124 1902 projectAttr = parent.processAttribute(projectAttr,attributeMap[i]);
n@1124 1903 switch(typeof projectAttr)
n@1124 1904 {
n@1124 1905 case "number":
n@1124 1906 case "boolean":
n@1124 1907 eval('this.'+attributeName+' = '+projectAttr);
n@1124 1908 break;
n@1124 1909 case "string":
n@1124 1910 eval('this.'+attributeName+' = "'+projectAttr+'"');
n@1124 1911 break;
n@1118 1912 }
n@1124 1913 }
n@1124 1914 this.statement = child.getElementsByTagName('statement')[0].textContent;
n@1124 1915 if (this.type == "checkbox" || this.type == "radio") {
n@1124 1916 var children = child.getElementsByTagName('option');
n@1124 1917 if (children.length == null) {
n@1118 1918 console.log('Malformed' +child.nodeName+ 'entry');
n@1118 1919 this.statement = 'Malformed' +child.nodeName+ 'entry';
n@1118 1920 this.type = 'statement';
n@1118 1921 } else {
n@1118 1922 this.options = [];
n@1124 1923 for (var i in children)
n@1124 1924 {
n@1124 1925 if (isNaN(Number(i))==true){break;}
n@1124 1926 this.options.push({
n@1124 1927 name: children[i].getAttribute('name'),
n@1124 1928 text: children[i].textContent
n@1124 1929 });
n@1118 1930 }
n@1118 1931 }
n@1118 1932 }
n@1118 1933 };
n@1118 1934
n@1172 1935 this.exportXML = function(doc)
n@1118 1936 {
n@1172 1937 var node = doc.createElement('surveyelement');
n@1124 1938 node.setAttribute('type',this.type);
n@1172 1939 var statement = doc.createElement('statement');
n@1124 1940 statement.textContent = this.statement;
n@1124 1941 node.appendChild(statement);
n@1118 1942 switch(this.type)
n@1118 1943 {
n@1118 1944 case "statement":
n@1118 1945 break;
n@1118 1946 case "question":
n@1118 1947 node.id = this.id;
n@1118 1948 node.setAttribute("mandatory",this.mandatory);
n@1118 1949 node.setAttribute("boxsize",this.boxsize);
n@1118 1950 break;
n@1118 1951 case "number":
n@1118 1952 node.id = this.id;
n@1118 1953 node.setAttribute("mandatory",this.mandatory);
n@1118 1954 node.setAttribute("min", this.min);
n@1118 1955 node.setAttribute("max", this.max);
n@1118 1956 node.setAttribute("step", this.step);
n@1118 1957 break;
n@1118 1958 case "checkbox":
n@1118 1959 case "radio":
n@1118 1960 node.id = this.id;
n@1118 1961 for (var i=0; i<this.options.length; i++)
n@1118 1962 {
n@1118 1963 var option = this.options[i];
n@1172 1964 var optionNode = doc.createElement("option");
n@1118 1965 optionNode.setAttribute("name",option.name);
n@1118 1966 optionNode.textContent = option.text;
n@1118 1967 node.appendChild(optionNode);
n@1118 1968 }
n@1118 1969 break;
n@1118 1970 }
n@1118 1971 return node;
n@1118 1972 };
n@1118 1973 };
n@1170 1974 this.decode = function(parent,xml) {
n@1124 1975 this.location = xml.getAttribute('location');
n@1124 1976 if (this.location == 'before'){this.location = 'pre';}
n@1124 1977 else if (this.location == 'after'){this.location = 'post';}
n@1124 1978 for (var i in xml.children)
n@1124 1979 {
n@1124 1980 if(isNaN(Number(i))==true){break;}
n@1118 1981 var node = new this.OptionNode();
n@1170 1982 node.decode(parent,xml.children[i]);
n@1118 1983 this.options.push(node);
n@1124 1984 }
n@1124 1985 };
n@1172 1986 this.encode = function(doc) {
n@1172 1987 var node = doc.createElement('survey');
n@1124 1988 node.setAttribute('location',this.location);
n@1124 1989 for (var i=0; i<this.options.length; i++)
n@1124 1990 {
n@1172 1991 node.appendChild(this.options[i].exportXML(doc));
n@1124 1992 }
n@1124 1993 return node;
n@1124 1994 };
n@1124 1995 };
n@1124 1996
n@1124 1997 this.interfaceNode = function()
n@1124 1998 {
n@1124 1999 this.title = null;
n@1124 2000 this.name = null;
n@1124 2001 this.options = [];
n@1124 2002 this.scales = [];
n@1170 2003 this.schema = specification.schema.getAllElementsByName('interface')[1];
n@1124 2004
n@1170 2005 this.decode = function(parent,xml) {
n@1124 2006 this.name = xml.getAttribute('name');
n@1124 2007 var titleNode = xml.getElementsByTagName('title');
n@1124 2008 if (titleNode.length == 1)
n@1124 2009 {
n@1124 2010 this.title = titleNode[0].textContent;
n@1124 2011 }
n@1124 2012 var interfaceOptionNodes = xml.getElementsByTagName('interfaceoption');
n@1124 2013 // Extract interfaceoption node schema
n@1170 2014 var interfaceOptionNodeSchema = this.schema.getAllElementsByName('interfaceoption')[0];
n@1148 2015 var attributeMap = interfaceOptionNodeSchema.getAllElementsByTagName('xs:attribute');
n@1124 2016 for (var i=0; i<interfaceOptionNodes.length; i++)
n@1124 2017 {
n@1124 2018 var ioNode = interfaceOptionNodes[i];
n@1124 2019 var option = {};
n@1124 2020 for (var j=0; j<attributeMap.length; j++)
n@1124 2021 {
n@1124 2022 var attributeName = attributeMap[j].getAttribute('name') || attributeMap[j].getAttribute('ref');
n@1124 2023 var projectAttr = ioNode.getAttribute(attributeName);
n@1124 2024 projectAttr = parent.processAttribute(projectAttr,attributeMap[j]);
n@1124 2025 switch(typeof projectAttr)
n@1124 2026 {
n@1124 2027 case "number":
n@1124 2028 case "boolean":
n@1124 2029 eval('option.'+attributeName+' = '+projectAttr);
n@1124 2030 break;
n@1124 2031 case "string":
n@1124 2032 eval('option.'+attributeName+' = "'+projectAttr+'"');
n@1124 2033 break;
n@1124 2034 }
n@1124 2035 }
n@1124 2036 this.options.push(option);
n@1124 2037 }
n@1124 2038
n@1124 2039 // Now the scales nodes
n@1124 2040 var scaleParent = xml.getElementsByTagName('scales');
n@1124 2041 if (scaleParent.length == 1) {
n@1124 2042 scaleParent = scaleParent[0];
n@1124 2043 for (var i=0; i<scaleParent.children.length; i++) {
n@1124 2044 var child = scaleParent.children[i];
n@1124 2045 this.scales.push({
n@1124 2046 text: child.textContent,
n@1124 2047 position: Number(child.getAttribute('position'))
n@1124 2048 });
n@1118 2049 }
n@1118 2050 }
n@1118 2051 };
n@1124 2052
n@1172 2053 this.encode = function(doc) {
n@1172 2054 var node = doc.createElement("interface");
n@1172 2055 if (typeof name == "string")
n@1172 2056 node.setAttribute("name",this.name);
n@1172 2057 for (var option of this.options)
n@1172 2058 {
n@1172 2059 var child = doc.createElement("interfaceoption");
n@1172 2060 child.setAttribute("type",option.type);
n@1172 2061 child.setAttribute("name",option.name);
n@1172 2062 node.appendChild(child);
n@1172 2063 }
n@1172 2064 if (this.scales.length != 0) {
n@1172 2065 var scales = doc.createElement("scales");
n@1172 2066 for (var scale of this.scales)
n@1172 2067 {
n@1172 2068 var child = doc.createElement("scalelabel");
n@1172 2069 child.setAttribute("position",scale.position);
n@1172 2070 child.textContent = scale.text;
n@1172 2071 scales.appendChild(child);
n@1172 2072 }
n@1172 2073 node.appendChild(scales);
n@1172 2074 }
n@1172 2075 return node;
n@1124 2076 };
n@1118 2077 };
n@1118 2078
n@1170 2079 this.metricNode = function() {
n@1170 2080 this.enabled = [];
n@1170 2081 this.decode = function(parent, xml) {
n@1170 2082 var children = xml.getElementsByTagName('metricenable');
n@1170 2083 for (var i in children) {
n@1170 2084 if (isNaN(Number(i)) == true){break;}
n@1170 2085 this.enabled.push(children[i].textContent);
n@1170 2086 }
n@1170 2087 }
n@1172 2088 this.encode = function(doc) {
n@1172 2089 var node = doc.createElement('metric');
n@1170 2090 for (var i in this.enabled)
n@1170 2091 {
n@1170 2092 if (isNaN(Number(i)) == true){break;}
n@1172 2093 var child = doc.createElement('metricenable');
n@1170 2094 child.textContent = this.enabled[i];
n@1170 2095 node.appendChild(child);
n@1170 2096 }
n@1170 2097 return node;
n@1170 2098 }
n@1170 2099 }
n@1170 2100
n@1124 2101 this.page = function() {
n@1118 2102 this.presentedId = undefined;
n@1118 2103 this.id = undefined;
n@1118 2104 this.hostURL = undefined;
n@1118 2105 this.randomiseOrder = undefined;
n@1118 2106 this.loop = undefined;
n@1124 2107 this.showElementComments = undefined;
n@1118 2108 this.outsideReference = null;
n@1118 2109 this.loudness = null;
n@1124 2110 this.preTest = null;
n@1124 2111 this.postTest = null;
n@1118 2112 this.interfaces = [];
n@1118 2113 this.commentBoxPrefix = "Comment on track";
n@1118 2114 this.audioElements = [];
n@1118 2115 this.commentQuestions = [];
n@1170 2116 this.schema = specification.schema.getAllElementsByName("page")[0];
n@1118 2117
n@1170 2118 this.decode = function(parent,xml)
n@1118 2119 {
n@1148 2120 var attributeMap = this.schema.getAllElementsByTagName('xs:attribute');
n@1124 2121 for (var i=0; i<attributeMap.length; i++)
n@1118 2122 {
n@1124 2123 var attributeName = attributeMap[i].getAttribute('name') || attributeMap[i].getAttribute('ref');
n@1124 2124 var projectAttr = xml.getAttribute(attributeName);
n@1124 2125 projectAttr = parent.processAttribute(projectAttr,attributeMap[i]);
n@1124 2126 switch(typeof projectAttr)
n@1118 2127 {
n@1124 2128 case "number":
n@1124 2129 case "boolean":
n@1124 2130 eval('this.'+attributeName+' = '+projectAttr);
n@1124 2131 break;
n@1124 2132 case "string":
n@1124 2133 eval('this.'+attributeName+' = "'+projectAttr+'"');
n@1124 2134 break;
n@1118 2135 }
n@1118 2136 }
n@1118 2137
n@1124 2138 // Get the Comment Box Prefix
n@1124 2139 var CBP = xml.getElementsByTagName('commentboxprefix');
n@1124 2140 if (CBP.length != 0) {
n@1124 2141 this.commentBoxPrefix = CBP[0].textContent;
n@1118 2142 }
n@1118 2143
n@1124 2144 // Now decode the interfaces
n@1124 2145 var interfaceNode = xml.getElementsByTagName('interface');
n@1124 2146 for (var i=0; i<interfaceNode.length; i++)
n@1124 2147 {
n@1124 2148 var node = new parent.interfaceNode();
n@1148 2149 node.decode(this,interfaceNode[i],parent.schema.getAllElementsByName('interface')[1]);
n@1124 2150 this.interfaces.push(node);
n@1124 2151 }
n@1118 2152
n@1124 2153 // Now process the survey node options
n@1124 2154 var survey = xml.getElementsByTagName('survey');
n@1148 2155 var surveySchema = parent.schema.getAllElementsByName('survey')[0];
n@1124 2156 for (var i in survey) {
n@1124 2157 if (isNaN(Number(i)) == true){break;}
n@1124 2158 var location = survey[i].getAttribute('location');
n@1124 2159 if (location == 'pre' || location == 'before')
n@1124 2160 {
n@1124 2161 if (this.preTest != null){this.errors.push("Already a pre/before test survey defined! Ignoring second!!");}
n@1124 2162 else {
n@1124 2163 this.preTest = new parent.surveyNode();
n@1124 2164 this.preTest.decode(parent,survey[i],surveySchema);
n@1124 2165 }
n@1124 2166 } else if (location == 'post' || location == 'after') {
n@1124 2167 if (this.postTest != null){this.errors.push("Already a post/after test survey defined! Ignoring second!!");}
n@1124 2168 else {
n@1124 2169 this.postTest = new parent.surveyNode();
n@1124 2170 this.postTest.decode(parent,survey[i],surveySchema);
n@1124 2171 }
n@1124 2172 }
n@1124 2173 }
n@1124 2174
n@1124 2175 // Now process the audioelement tags
n@1124 2176 var audioElements = xml.getElementsByTagName('audioelement');
n@1124 2177 for (var i=0; i<audioElements.length; i++)
n@1124 2178 {
n@1124 2179 var node = new this.audioElementNode();
n@1170 2180 node.decode(this,audioElements[i]);
n@1124 2181 this.audioElements.push(node);
n@1124 2182 }
n@1124 2183
n@1124 2184 // Now decode the commentquestions
n@1124 2185 var commentQuestions = xml.getElementsByTagName('commentquestion');
n@1124 2186 for (var i=0; i<commentQuestions.length; i++)
n@1124 2187 {
n@1118 2188 var node = new this.commentQuestionNode();
n@1170 2189 node.decode(parent,commentQuestions[i]);
n@1118 2190 this.commentQuestions.push(node);
n@1118 2191 }
n@1118 2192 };
n@1118 2193
n@1118 2194 this.encode = function(root)
n@1118 2195 {
n@1172 2196 var AHNode = root.createElement("page");
n@1172 2197 // First decode the attributes
n@1172 2198 var attributes = this.schema.getAllElementsByTagName('xs:attribute');
n@1172 2199 for (var i=0; i<attributes.length; i++)
n@1172 2200 {
n@1172 2201 var name = attributes[i].getAttribute("name");
n@1172 2202 if (name == undefined) {
n@1172 2203 name = attributes[i].getAttribute("ref");
n@1172 2204 }
n@1172 2205 if(eval("this."+name+" != undefined") || attributes[i].getAttribute("use") == "required")
n@1172 2206 {
n@1172 2207 eval("AHNode.setAttribute('"+name+"',this."+name+")");
n@1172 2208 }
n@1172 2209 }
n@1118 2210 if(this.loudness != null) {AHNode.setAttribute("loudness",this.loudness);}
n@1172 2211 // <commentboxprefix>
n@1172 2212 var commentboxprefix = root.createElement("commentboxprefix");
n@1172 2213 commentboxprefix.textContent = this.commentBoxPrefix;
n@1172 2214 AHNode.appendChild(commentboxprefix);
n@1172 2215
n@1118 2216 for (var i=0; i<this.interfaces.length; i++)
n@1118 2217 {
n@1118 2218 AHNode.appendChild(this.interfaces[i].encode(root));
n@1118 2219 }
n@1118 2220
n@1118 2221 for (var i=0; i<this.audioElements.length; i++) {
n@1118 2222 AHNode.appendChild(this.audioElements[i].encode(root));
n@1118 2223 }
n@1118 2224 // Create <CommentQuestion>
n@1118 2225 for (var i=0; i<this.commentQuestions.length; i++)
n@1118 2226 {
n@1172 2227 AHNode.appendChild(this.commentQuestions[i].encode(root));
n@1118 2228 }
n@1118 2229
n@1172 2230 AHNode.appendChild(this.preTest.encode(root));
n@1172 2231 AHNode.appendChild(this.postTest.encode(root));
n@1118 2232 return AHNode;
n@1118 2233 };
n@1118 2234
n@1124 2235 this.commentQuestionNode = function() {
n@1124 2236 this.id = null;
n@1124 2237 this.type = undefined;
n@1118 2238 this.options = [];
n@1124 2239 this.statement = undefined;
n@1170 2240 this.schema = specification.schema.getAllElementsByName('commentquestion')[0];
n@1170 2241 this.decode = function(parent,xml)
n@1118 2242 {
n@1124 2243 this.id = xml.id;
n@1124 2244 this.type = xml.getAttribute('type');
n@1124 2245 this.statement = xml.getElementsByTagName('statement')[0].textContent;
n@1124 2246 var optNodes = xml.getElementsByTagName('option');
n@1124 2247 for (var i=0; i<optNodes.length; i++)
n@1124 2248 {
n@1124 2249 var optNode = optNodes[i];
n@1124 2250 this.options.push({
n@1124 2251 name: optNode.getAttribute('name'),
n@1124 2252 text: optNode.textContent
n@1124 2253 });
n@1118 2254 }
n@1118 2255 };
n@1124 2256
n@1118 2257 this.encode = function(root)
n@1118 2258 {
n@1172 2259 var node = root.createElement("commentquestion");
n@1172 2260 node.id = this.id;
n@1172 2261 node.setAttribute("type",this.type);
n@1172 2262 var statement = root.createElement("statement");
n@1172 2263 statement.textContent = this.statement;
n@1172 2264 node.appendChild(statement);
n@1172 2265 for (var option of this.options)
n@1172 2266 {
n@1172 2267 var child = root.createElement("option");
n@1172 2268 child.setAttribute("name",option.name);
n@1172 2269 child.textContent = option.text;
n@1172 2270 node.appendChild(child);
n@1172 2271 }
n@1172 2272 return node;
n@1118 2273 };
n@1118 2274 };
n@1118 2275
n@1118 2276 this.audioElementNode = function() {
n@1118 2277 this.url = null;
n@1118 2278 this.id = null;
n@1118 2279 this.parent = null;
n@1124 2280 this.type = null;
n@1118 2281 this.marker = false;
n@1118 2282 this.enforce = false;
n@1118 2283 this.gain = 1.0;
n@1170 2284 this.schema = specification.schema.getAllElementsByName('audioelement')[0];;
n@1124 2285 this.parent = null;
n@1170 2286 this.decode = function(parent,xml)
n@1118 2287 {
n@1118 2288 this.parent = parent;
n@1148 2289 var attributeMap = this.schema.getAllElementsByTagName('xs:attribute');
n@1124 2290 for (var i=0; i<attributeMap.length; i++)
n@1118 2291 {
n@1124 2292 var attributeName = attributeMap[i].getAttribute('name') || attributeMap[i].getAttribute('ref');
n@1124 2293 var projectAttr = xml.getAttribute(attributeName);
n@1124 2294 projectAttr = specification.processAttribute(projectAttr,attributeMap[i]);
n@1124 2295 switch(typeof projectAttr)
n@1118 2296 {
n@1124 2297 case "number":
n@1124 2298 case "boolean":
n@1124 2299 eval('this.'+attributeName+' = '+projectAttr);
n@1124 2300 break;
n@1124 2301 case "string":
n@1124 2302 eval('this.'+attributeName+' = "'+projectAttr+'"');
n@1124 2303 break;
n@1118 2304 }
n@1118 2305 }
n@1124 2306
n@1118 2307 };
n@1118 2308 this.encode = function(root)
n@1118 2309 {
n@1172 2310 var AENode = root.createElement("audioelement");
n@1172 2311 var attributes = this.schema.getAllElementsByTagName('xs:attribute');
n@1172 2312 for (var i=0; i<attributes.length; i++)
n@1172 2313 {
n@1172 2314 var name = attributes[i].getAttribute("name");
n@1172 2315 if (name == undefined) {
n@1172 2316 name = attributes[i].getAttribute("ref");
n@1172 2317 }
n@1172 2318 if(eval("this."+name+" != undefined") || attributes[i].getAttribute("use") == "required")
n@1172 2319 {
n@1172 2320 eval("AENode.setAttribute('"+name+"',this."+name+")");
n@1172 2321 }
n@1172 2322 }
n@1118 2323 return AENode;
n@1118 2324 };
n@1118 2325 };
n@1118 2326 };
n@1118 2327 }
n@1118 2328
n@1118 2329 function Interface(specificationObject) {
n@1118 2330 // This handles the bindings between the interface and the audioEngineContext;
n@1118 2331 this.specification = specificationObject;
n@1118 2332 this.insertPoint = document.getElementById("topLevelBody");
n@1118 2333
n@1124 2334 this.newPage = function(audioHolderObject,store)
n@1118 2335 {
n@1169 2336 audioEngineContext.newTestPage(audioHolderObject,store);
n@1118 2337 interfaceContext.deleteCommentBoxes();
n@1118 2338 interfaceContext.deleteCommentQuestions();
n@1124 2339 loadTest(audioHolderObject,store);
n@1118 2340 };
n@1118 2341
n@1118 2342 // Bounded by interface!!
n@1118 2343 // Interface object MUST have an exportXMLDOM method which returns the various DOM levels
n@1118 2344 // For example, APE returns the slider position normalised in a <value> tag.
n@1118 2345 this.interfaceObjects = [];
n@1118 2346 this.interfaceObject = function(){};
n@1118 2347
n@1118 2348 this.resizeWindow = function(event)
n@1118 2349 {
n@1118 2350 popup.resize(event);
n@1118 2351 for(var i=0; i<this.commentBoxes.length; i++)
n@1118 2352 {this.commentBoxes[i].resize();}
n@1118 2353 for(var i=0; i<this.commentQuestions.length; i++)
n@1118 2354 {this.commentQuestions[i].resize();}
n@1118 2355 try
n@1118 2356 {
n@1118 2357 resizeWindow(event);
n@1118 2358 }
n@1118 2359 catch(err)
n@1118 2360 {
n@1118 2361 console.log("Warning - Interface does not have Resize option");
n@1118 2362 console.log(err);
n@1118 2363 }
n@1118 2364 };
n@1118 2365
n@1118 2366 this.returnNavigator = function()
n@1118 2367 {
n@1162 2368 var node = storage.document.createElement("navigator");
n@1162 2369 var platform = storage.document.createElement("platform");
n@1118 2370 platform.textContent = navigator.platform;
n@1162 2371 var vendor = storage.document.createElement("vendor");
n@1118 2372 vendor.textContent = navigator.vendor;
n@1162 2373 var userAgent = storage.document.createElement("uagent");
n@1118 2374 userAgent.textContent = navigator.userAgent;
n@1162 2375 var screen = storage.document.createElement("window");
n@1162 2376 screen.setAttribute('innerWidth',window.innerWidth);
n@1162 2377 screen.setAttribute('innerHeight',window.innerHeight);
n@1118 2378 node.appendChild(platform);
n@1118 2379 node.appendChild(vendor);
n@1118 2380 node.appendChild(userAgent);
n@1162 2381 node.appendChild(screen);
n@1118 2382 return node;
n@1118 2383 };
n@1118 2384
n@1118 2385 this.commentBoxes = [];
n@1118 2386 this.elementCommentBox = function(audioObject) {
n@1118 2387 var element = audioObject.specification;
n@1118 2388 this.audioObject = audioObject;
n@1118 2389 this.id = audioObject.id;
n@1118 2390 var audioHolderObject = audioObject.specification.parent;
n@1118 2391 // Create document objects to hold the comment boxes
n@1118 2392 this.trackComment = document.createElement('div');
n@1118 2393 this.trackComment.className = 'comment-div';
n@1118 2394 this.trackComment.id = 'comment-div-'+audioObject.id;
n@1118 2395 // Create a string next to each comment asking for a comment
n@1118 2396 this.trackString = document.createElement('span');
n@1116 2397 this.trackString.innerHTML = audioHolderObject.commentBoxPrefix+' '+audioObject.interfaceDOM.getPresentedId();
n@1118 2398 // Create the HTML5 comment box 'textarea'
n@1118 2399 this.trackCommentBox = document.createElement('textarea');
n@1118 2400 this.trackCommentBox.rows = '4';
n@1118 2401 this.trackCommentBox.cols = '100';
n@1118 2402 this.trackCommentBox.name = 'trackComment'+audioObject.id;
n@1118 2403 this.trackCommentBox.className = 'trackComment';
n@1118 2404 var br = document.createElement('br');
n@1118 2405 // Add to the holder.
n@1118 2406 this.trackComment.appendChild(this.trackString);
n@1118 2407 this.trackComment.appendChild(br);
n@1118 2408 this.trackComment.appendChild(this.trackCommentBox);
n@1118 2409
n@1118 2410 this.exportXMLDOM = function() {
n@1118 2411 var root = document.createElement('comment');
n@1118 2412 if (this.audioObject.specification.parent.elementComments) {
n@1118 2413 var question = document.createElement('question');
n@1118 2414 question.textContent = this.trackString.textContent;
n@1118 2415 var response = document.createElement('response');
n@1118 2416 response.textContent = this.trackCommentBox.value;
n@1118 2417 console.log("Comment frag-"+this.id+": "+response.textContent);
n@1118 2418 root.appendChild(question);
n@1118 2419 root.appendChild(response);
n@1118 2420 }
n@1118 2421 return root;
n@1118 2422 };
n@1118 2423 this.resize = function()
n@1118 2424 {
n@1118 2425 var boxwidth = (window.innerWidth-100)/2;
n@1118 2426 if (boxwidth >= 600)
n@1118 2427 {
n@1118 2428 boxwidth = 600;
n@1118 2429 }
n@1118 2430 else if (boxwidth < 400)
n@1118 2431 {
n@1118 2432 boxwidth = 400;
n@1118 2433 }
n@1118 2434 this.trackComment.style.width = boxwidth+"px";
n@1118 2435 this.trackCommentBox.style.width = boxwidth-6+"px";
n@1118 2436 };
n@1118 2437 this.resize();
n@1118 2438 };
n@1118 2439
n@1118 2440 this.commentQuestions = [];
n@1118 2441
n@1118 2442 this.commentBox = function(commentQuestion) {
n@1118 2443 this.specification = commentQuestion;
n@1118 2444 // Create document objects to hold the comment boxes
n@1118 2445 this.holder = document.createElement('div');
n@1118 2446 this.holder.className = 'comment-div';
n@1118 2447 // Create a string next to each comment asking for a comment
n@1118 2448 this.string = document.createElement('span');
n@1124 2449 this.string.innerHTML = commentQuestion.statement;
n@1118 2450 // Create the HTML5 comment box 'textarea'
n@1118 2451 this.textArea = document.createElement('textarea');
n@1118 2452 this.textArea.rows = '4';
n@1118 2453 this.textArea.cols = '100';
n@1118 2454 this.textArea.className = 'trackComment';
n@1118 2455 var br = document.createElement('br');
n@1118 2456 // Add to the holder.
n@1118 2457 this.holder.appendChild(this.string);
n@1118 2458 this.holder.appendChild(br);
n@1118 2459 this.holder.appendChild(this.textArea);
n@1118 2460
n@1118 2461 this.exportXMLDOM = function() {
n@1118 2462 var root = document.createElement('comment');
n@1118 2463 root.id = this.specification.id;
n@1118 2464 root.setAttribute('type',this.specification.type);
n@1118 2465 root.textContent = this.textArea.value;
n@1118 2466 console.log("Question: "+this.string.textContent);
n@1118 2467 console.log("Response: "+root.textContent);
n@1118 2468 return root;
n@1118 2469 };
n@1118 2470 this.resize = function()
n@1118 2471 {
n@1118 2472 var boxwidth = (window.innerWidth-100)/2;
n@1118 2473 if (boxwidth >= 600)
n@1118 2474 {
n@1118 2475 boxwidth = 600;
n@1118 2476 }
n@1118 2477 else if (boxwidth < 400)
n@1118 2478 {
n@1118 2479 boxwidth = 400;
n@1118 2480 }
n@1118 2481 this.holder.style.width = boxwidth+"px";
n@1118 2482 this.textArea.style.width = boxwidth-6+"px";
n@1118 2483 };
n@1118 2484 this.resize();
n@1118 2485 };
n@1118 2486
n@1118 2487 this.radioBox = function(commentQuestion) {
n@1118 2488 this.specification = commentQuestion;
n@1118 2489 // Create document objects to hold the comment boxes
n@1118 2490 this.holder = document.createElement('div');
n@1118 2491 this.holder.className = 'comment-div';
n@1118 2492 // Create a string next to each comment asking for a comment
n@1118 2493 this.string = document.createElement('span');
n@1118 2494 this.string.innerHTML = commentQuestion.statement;
n@1118 2495 var br = document.createElement('br');
n@1118 2496 // Add to the holder.
n@1118 2497 this.holder.appendChild(this.string);
n@1118 2498 this.holder.appendChild(br);
n@1118 2499 this.options = [];
n@1118 2500 this.inputs = document.createElement('div');
n@1118 2501 this.span = document.createElement('div');
n@1118 2502 this.inputs.align = 'center';
n@1118 2503 this.inputs.style.marginLeft = '12px';
n@1118 2504 this.span.style.marginLeft = '12px';
n@1118 2505 this.span.align = 'center';
n@1118 2506 this.span.style.marginTop = '15px';
n@1118 2507
n@1118 2508 var optCount = commentQuestion.options.length;
n@1124 2509 for (var optNode of commentQuestion.options)
n@1118 2510 {
n@1118 2511 var div = document.createElement('div');
n@1118 2512 div.style.width = '80px';
n@1118 2513 div.style.float = 'left';
n@1118 2514 var input = document.createElement('input');
n@1118 2515 input.type = 'radio';
n@1118 2516 input.name = commentQuestion.id;
n@1124 2517 input.setAttribute('setvalue',optNode.name);
n@1118 2518 input.className = 'comment-radio';
n@1118 2519 div.appendChild(input);
n@1118 2520 this.inputs.appendChild(div);
n@1118 2521
n@1118 2522
n@1118 2523 div = document.createElement('div');
n@1118 2524 div.style.width = '80px';
n@1118 2525 div.style.float = 'left';
n@1118 2526 div.align = 'center';
n@1118 2527 var span = document.createElement('span');
n@1124 2528 span.textContent = optNode.text;
n@1118 2529 span.className = 'comment-radio-span';
n@1118 2530 div.appendChild(span);
n@1118 2531 this.span.appendChild(div);
n@1118 2532 this.options.push(input);
n@1118 2533 }
n@1118 2534 this.holder.appendChild(this.span);
n@1118 2535 this.holder.appendChild(this.inputs);
n@1118 2536
n@1118 2537 this.exportXMLDOM = function() {
n@1118 2538 var root = document.createElement('comment');
n@1118 2539 root.id = this.specification.id;
n@1118 2540 root.setAttribute('type',this.specification.type);
n@1118 2541 var question = document.createElement('question');
n@1118 2542 question.textContent = this.string.textContent;
n@1118 2543 var response = document.createElement('response');
n@1118 2544 var i=0;
n@1118 2545 while(this.options[i].checked == false) {
n@1118 2546 i++;
n@1118 2547 if (i >= this.options.length) {
n@1118 2548 break;
n@1118 2549 }
n@1118 2550 }
n@1118 2551 if (i >= this.options.length) {
n@1118 2552 response.textContent = 'null';
n@1118 2553 } else {
n@1118 2554 response.textContent = this.options[i].getAttribute('setvalue');
n@1118 2555 response.setAttribute('number',i);
n@1118 2556 }
n@1118 2557 console.log('Comment: '+question.textContent);
n@1118 2558 console.log('Response: '+response.textContent);
n@1118 2559 root.appendChild(question);
n@1118 2560 root.appendChild(response);
n@1118 2561 return root;
n@1118 2562 };
n@1118 2563 this.resize = function()
n@1118 2564 {
n@1118 2565 var boxwidth = (window.innerWidth-100)/2;
n@1118 2566 if (boxwidth >= 600)
n@1118 2567 {
n@1118 2568 boxwidth = 600;
n@1118 2569 }
n@1118 2570 else if (boxwidth < 400)
n@1118 2571 {
n@1118 2572 boxwidth = 400;
n@1118 2573 }
n@1118 2574 this.holder.style.width = boxwidth+"px";
n@1118 2575 var text = this.holder.children[2];
n@1118 2576 var options = this.holder.children[3];
n@1118 2577 var optCount = options.children.length;
n@1118 2578 var spanMargin = Math.floor(((boxwidth-20-(optCount*80))/(optCount))/2)+'px';
n@1118 2579 var options = options.firstChild;
n@1118 2580 var text = text.firstChild;
n@1118 2581 options.style.marginRight = spanMargin;
n@1118 2582 options.style.marginLeft = spanMargin;
n@1118 2583 text.style.marginRight = spanMargin;
n@1118 2584 text.style.marginLeft = spanMargin;
n@1118 2585 while(options.nextSibling != undefined)
n@1118 2586 {
n@1118 2587 options = options.nextSibling;
n@1118 2588 text = text.nextSibling;
n@1118 2589 options.style.marginRight = spanMargin;
n@1118 2590 options.style.marginLeft = spanMargin;
n@1118 2591 text.style.marginRight = spanMargin;
n@1118 2592 text.style.marginLeft = spanMargin;
n@1118 2593 }
n@1118 2594 };
n@1118 2595 this.resize();
n@1118 2596 };
n@1118 2597
n@1118 2598 this.checkboxBox = function(commentQuestion) {
n@1118 2599 this.specification = commentQuestion;
n@1118 2600 // Create document objects to hold the comment boxes
n@1118 2601 this.holder = document.createElement('div');
n@1118 2602 this.holder.className = 'comment-div';
n@1118 2603 // Create a string next to each comment asking for a comment
n@1118 2604 this.string = document.createElement('span');
n@1118 2605 this.string.innerHTML = commentQuestion.statement;
n@1118 2606 var br = document.createElement('br');
n@1118 2607 // Add to the holder.
n@1118 2608 this.holder.appendChild(this.string);
n@1118 2609 this.holder.appendChild(br);
n@1118 2610 this.options = [];
n@1118 2611 this.inputs = document.createElement('div');
n@1118 2612 this.span = document.createElement('div');
n@1118 2613 this.inputs.align = 'center';
n@1118 2614 this.inputs.style.marginLeft = '12px';
n@1118 2615 this.span.style.marginLeft = '12px';
n@1118 2616 this.span.align = 'center';
n@1118 2617 this.span.style.marginTop = '15px';
n@1118 2618
n@1118 2619 var optCount = commentQuestion.options.length;
n@1118 2620 for (var i=0; i<optCount; i++)
n@1118 2621 {
n@1118 2622 var div = document.createElement('div');
n@1118 2623 div.style.width = '80px';
n@1118 2624 div.style.float = 'left';
n@1118 2625 var input = document.createElement('input');
n@1118 2626 input.type = 'checkbox';
n@1118 2627 input.name = commentQuestion.id;
n@1118 2628 input.setAttribute('setvalue',commentQuestion.options[i].name);
n@1118 2629 input.className = 'comment-radio';
n@1118 2630 div.appendChild(input);
n@1118 2631 this.inputs.appendChild(div);
n@1118 2632
n@1118 2633
n@1118 2634 div = document.createElement('div');
n@1118 2635 div.style.width = '80px';
n@1118 2636 div.style.float = 'left';
n@1118 2637 div.align = 'center';
n@1118 2638 var span = document.createElement('span');
n@1118 2639 span.textContent = commentQuestion.options[i].text;
n@1118 2640 span.className = 'comment-radio-span';
n@1118 2641 div.appendChild(span);
n@1118 2642 this.span.appendChild(div);
n@1118 2643 this.options.push(input);
n@1118 2644 }
n@1118 2645 this.holder.appendChild(this.span);
n@1118 2646 this.holder.appendChild(this.inputs);
n@1118 2647
n@1118 2648 this.exportXMLDOM = function() {
n@1118 2649 var root = document.createElement('comment');
n@1118 2650 root.id = this.specification.id;
n@1118 2651 root.setAttribute('type',this.specification.type);
n@1118 2652 var question = document.createElement('question');
n@1118 2653 question.textContent = this.string.textContent;
n@1118 2654 root.appendChild(question);
n@1118 2655 console.log('Comment: '+question.textContent);
n@1118 2656 for (var i=0; i<this.options.length; i++) {
n@1118 2657 var response = document.createElement('response');
n@1118 2658 response.textContent = this.options[i].checked;
n@1118 2659 response.setAttribute('name',this.options[i].getAttribute('setvalue'));
n@1118 2660 root.appendChild(response);
n@1118 2661 console.log('Response '+response.getAttribute('name') +': '+response.textContent);
n@1118 2662 }
n@1118 2663 return root;
n@1118 2664 };
n@1118 2665 this.resize = function()
n@1118 2666 {
n@1118 2667 var boxwidth = (window.innerWidth-100)/2;
n@1118 2668 if (boxwidth >= 600)
n@1118 2669 {
n@1118 2670 boxwidth = 600;
n@1118 2671 }
n@1118 2672 else if (boxwidth < 400)
n@1118 2673 {
n@1118 2674 boxwidth = 400;
n@1118 2675 }
n@1118 2676 this.holder.style.width = boxwidth+"px";
n@1118 2677 var text = this.holder.children[2];
n@1118 2678 var options = this.holder.children[3];
n@1118 2679 var optCount = options.children.length;
n@1118 2680 var spanMargin = Math.floor(((boxwidth-20-(optCount*80))/(optCount))/2)+'px';
n@1118 2681 var options = options.firstChild;
n@1118 2682 var text = text.firstChild;
n@1118 2683 options.style.marginRight = spanMargin;
n@1118 2684 options.style.marginLeft = spanMargin;
n@1118 2685 text.style.marginRight = spanMargin;
n@1118 2686 text.style.marginLeft = spanMargin;
n@1118 2687 while(options.nextSibling != undefined)
n@1118 2688 {
n@1118 2689 options = options.nextSibling;
n@1118 2690 text = text.nextSibling;
n@1118 2691 options.style.marginRight = spanMargin;
n@1118 2692 options.style.marginLeft = spanMargin;
n@1118 2693 text.style.marginRight = spanMargin;
n@1118 2694 text.style.marginLeft = spanMargin;
n@1118 2695 }
n@1118 2696 };
n@1118 2697 this.resize();
n@1118 2698 };
n@1118 2699
n@1118 2700 this.createCommentBox = function(audioObject) {
n@1118 2701 var node = new this.elementCommentBox(audioObject);
n@1118 2702 this.commentBoxes.push(node);
n@1118 2703 audioObject.commentDOM = node;
n@1118 2704 return node;
n@1118 2705 };
n@1118 2706
n@1118 2707 this.sortCommentBoxes = function() {
n@1138 2708 this.commentBoxes.sort(function(a,b){return a.id - b.id;});
n@1118 2709 };
n@1118 2710
n@1118 2711 this.showCommentBoxes = function(inject, sort) {
n@1118 2712 if (sort) {interfaceContext.sortCommentBoxes();}
n@1138 2713 for (var box of interfaceContext.commentBoxes) {
n@1138 2714 inject.appendChild(box.trackComment);
n@1118 2715 }
n@1118 2716 };
n@1118 2717
n@1118 2718 this.deleteCommentBoxes = function() {
n@1118 2719 this.commentBoxes = [];
n@1118 2720 };
n@1118 2721
n@1118 2722 this.createCommentQuestion = function(element) {
n@1118 2723 var node;
n@1124 2724 if (element.type == 'question') {
n@1118 2725 node = new this.commentBox(element);
n@1118 2726 } else if (element.type == 'radio') {
n@1118 2727 node = new this.radioBox(element);
n@1118 2728 } else if (element.type == 'checkbox') {
n@1118 2729 node = new this.checkboxBox(element);
n@1118 2730 }
n@1118 2731 this.commentQuestions.push(node);
n@1118 2732 return node;
n@1118 2733 };
n@1118 2734
n@1118 2735 this.deleteCommentQuestions = function()
n@1118 2736 {
n@1118 2737 this.commentQuestions = [];
n@1118 2738 };
n@1118 2739
n@1118 2740 this.playhead = new function()
n@1118 2741 {
n@1118 2742 this.object = document.createElement('div');
n@1118 2743 this.object.className = 'playhead';
n@1118 2744 this.object.align = 'left';
n@1118 2745 var curTime = document.createElement('div');
n@1118 2746 curTime.style.width = '50px';
n@1118 2747 this.curTimeSpan = document.createElement('span');
n@1118 2748 this.curTimeSpan.textContent = '00:00';
n@1118 2749 curTime.appendChild(this.curTimeSpan);
n@1118 2750 this.object.appendChild(curTime);
n@1118 2751 this.scrubberTrack = document.createElement('div');
n@1118 2752 this.scrubberTrack.className = 'playhead-scrub-track';
n@1118 2753
n@1118 2754 this.scrubberHead = document.createElement('div');
n@1118 2755 this.scrubberHead.id = 'playhead-scrubber';
n@1118 2756 this.scrubberTrack.appendChild(this.scrubberHead);
n@1118 2757 this.object.appendChild(this.scrubberTrack);
n@1118 2758
n@1118 2759 this.timePerPixel = 0;
n@1118 2760 this.maxTime = 0;
n@1118 2761
n@1118 2762 this.playbackObject;
n@1118 2763
n@1118 2764 this.setTimePerPixel = function(audioObject) {
n@1118 2765 //maxTime must be in seconds
n@1118 2766 this.playbackObject = audioObject;
n@1118 2767 this.maxTime = audioObject.buffer.buffer.duration;
n@1118 2768 var width = 490; //500 - 10, 5 each side of the tracker head
n@1118 2769 this.timePerPixel = this.maxTime/490;
n@1118 2770 if (this.maxTime < 60) {
n@1118 2771 this.curTimeSpan.textContent = '0.00';
n@1118 2772 } else {
n@1118 2773 this.curTimeSpan.textContent = '00:00';
n@1118 2774 }
n@1118 2775 };
n@1118 2776
n@1118 2777 this.update = function() {
n@1118 2778 // Update the playhead position, startPlay must be called
n@1118 2779 if (this.timePerPixel > 0) {
n@1118 2780 var time = this.playbackObject.getCurrentPosition();
n@1167 2781 if (time > 0 && time < this.maxTime) {
n@1118 2782 var width = 490;
n@1118 2783 var pix = Math.floor(time/this.timePerPixel);
n@1118 2784 this.scrubberHead.style.left = pix+'px';
n@1118 2785 if (this.maxTime > 60.0) {
n@1118 2786 var secs = time%60;
n@1118 2787 var mins = Math.floor((time-secs)/60);
n@1118 2788 secs = secs.toString();
n@1118 2789 secs = secs.substr(0,2);
n@1118 2790 mins = mins.toString();
n@1118 2791 this.curTimeSpan.textContent = mins+':'+secs;
n@1118 2792 } else {
n@1118 2793 time = time.toString();
n@1118 2794 this.curTimeSpan.textContent = time.substr(0,4);
n@1118 2795 }
n@1118 2796 } else {
n@1118 2797 this.scrubberHead.style.left = '0px';
n@1118 2798 if (this.maxTime < 60) {
n@1118 2799 this.curTimeSpan.textContent = '0.00';
n@1118 2800 } else {
n@1118 2801 this.curTimeSpan.textContent = '00:00';
n@1118 2802 }
n@1118 2803 }
n@1118 2804 }
n@1118 2805 };
n@1118 2806
n@1118 2807 this.interval = undefined;
n@1118 2808
n@1118 2809 this.start = function() {
n@1118 2810 if (this.playbackObject != undefined && this.interval == undefined) {
n@1118 2811 if (this.maxTime < 60) {
n@1118 2812 this.interval = setInterval(function(){interfaceContext.playhead.update();},10);
n@1118 2813 } else {
n@1118 2814 this.interval = setInterval(function(){interfaceContext.playhead.update();},100);
n@1118 2815 }
n@1118 2816 }
n@1118 2817 };
n@1118 2818 this.stop = function() {
n@1118 2819 clearInterval(this.interval);
n@1118 2820 this.interval = undefined;
n@1118 2821 if (this.maxTime < 60) {
n@1118 2822 this.curTimeSpan.textContent = '0.00';
n@1118 2823 } else {
n@1118 2824 this.curTimeSpan.textContent = '00:00';
n@1118 2825 }
n@1118 2826 };
n@1118 2827 };
n@1154 2828
n@1154 2829 this.volume = new function()
n@1154 2830 {
n@1154 2831 // An in-built volume module which can be viewed on page
n@1154 2832 // Includes trackers on page-by-page data
n@1154 2833 // Volume does NOT reset to 0dB on each page load
n@1154 2834 this.valueLin = 1.0;
n@1154 2835 this.valueDB = 0.0;
n@1154 2836 this.object = document.createElement('div');
n@1154 2837 this.object.id = 'master-volume-holder';
n@1154 2838 this.slider = document.createElement('input');
n@1154 2839 this.slider.id = 'master-volume-control';
n@1154 2840 this.slider.type = 'range';
n@1154 2841 this.valueText = document.createElement('span');
n@1154 2842 this.valueText.id = 'master-volume-feedback';
n@1154 2843 this.valueText.textContent = '0dB';
n@1154 2844
n@1154 2845 this.slider.min = -60;
n@1154 2846 this.slider.max = 12;
n@1154 2847 this.slider.value = 0;
n@1154 2848 this.slider.step = 1;
n@1154 2849 this.slider.onmousemove = function(event)
n@1154 2850 {
n@1154 2851 interfaceContext.volume.valueDB = event.currentTarget.value;
n@1154 2852 interfaceContext.volume.valueLin = decibelToLinear(interfaceContext.volume.valueDB);
n@1154 2853 interfaceContext.volume.valueText.textContent = interfaceContext.volume.valueDB+'dB';
n@1154 2854 audioEngineContext.outputGain.gain.value = interfaceContext.volume.valueLin;
n@1154 2855 }
n@1154 2856 this.slider.onmouseup = function(event)
n@1154 2857 {
n@1154 2858 var storePoint = testState.currentStore.XMLDOM.children[0].getAllElementsByName('volumeTracker');
n@1154 2859 if (storePoint.length == 0)
n@1154 2860 {
n@1154 2861 storePoint = storage.document.createElement('metricresult');
n@1154 2862 storePoint.setAttribute('name','volumeTracker');
n@1154 2863 testState.currentStore.XMLDOM.children[0].appendChild(storePoint);
n@1154 2864 }
n@1154 2865 else {
n@1154 2866 storePoint = storePoint[0];
n@1154 2867 }
n@1154 2868 var node = storage.document.createElement('movement');
n@1154 2869 node.setAttribute('test-time',audioEngineContext.timer.getTestTime());
n@1154 2870 node.setAttribute('volume',interfaceContext.volume.valueDB);
n@1154 2871 node.setAttribute('format','dBFS');
n@1154 2872 storePoint.appendChild(node);
n@1154 2873 }
n@1154 2874
n@1155 2875 var title = document.createElement('div');
n@1155 2876 title.innerHTML = '<span>Master Volume Control</span>';
n@1155 2877 title.style.fontSize = '0.75em';
n@1155 2878 title.style.width = "100%";
n@1155 2879 title.align = 'center';
n@1155 2880 this.object.appendChild(title);
n@1155 2881
n@1154 2882 this.object.appendChild(this.slider);
n@1154 2883 this.object.appendChild(this.valueText);
n@1154 2884 }
n@1118 2885 // Global Checkers
n@1118 2886 // These functions will help enforce the checkers
n@1118 2887 this.checkHiddenAnchor = function()
n@1118 2888 {
n@1124 2889 for (var ao of audioEngineContext.audioObjects)
n@1118 2890 {
n@1124 2891 if (ao.specification.type == "anchor")
n@1118 2892 {
n@1125 2893 if (ao.interfaceDOM.getValue() > (ao.specification.marker/100) && ao.specification.marker > 0) {
n@1124 2894 // Anchor is not set below
n@1124 2895 console.log('Anchor node not below marker value');
n@1124 2896 alert('Please keep listening');
n@1167 2897 this.storeErrorNode('Anchor node not below marker value');
n@1124 2898 return false;
n@1124 2899 }
n@1118 2900 }
n@1118 2901 }
n@1118 2902 return true;
n@1118 2903 };
n@1118 2904
n@1118 2905 this.checkHiddenReference = function()
n@1118 2906 {
n@1124 2907 for (var ao of audioEngineContext.audioObjects)
n@1118 2908 {
n@1124 2909 if (ao.specification.type == "reference")
n@1118 2910 {
n@1125 2911 if (ao.interfaceDOM.getValue() < (ao.specification.marker/100) && ao.specification.marker > 0) {
n@1124 2912 // Anchor is not set below
n@1167 2913 console.log('Reference node not above marker value');
n@1167 2914 this.storeErrorNode('Reference node not above marker value');
n@1124 2915 alert('Please keep listening');
n@1124 2916 return false;
n@1124 2917 }
n@1118 2918 }
n@1118 2919 }
n@1118 2920 return true;
n@1118 2921 };
n@1118 2922
n@1118 2923 this.checkFragmentsFullyPlayed = function ()
n@1118 2924 {
n@1118 2925 // Checks the entire file has been played back
n@1118 2926 // NOTE ! This will return true IF playback is Looped!!!
n@1118 2927 if (audioEngineContext.loopPlayback)
n@1118 2928 {
n@1118 2929 console.log("WARNING - Looped source: Cannot check fragments are fully played");
n@1118 2930 return true;
n@1118 2931 }
n@1118 2932 var check_pass = true;
n@1118 2933 var error_obj = [];
n@1118 2934 for (var i = 0; i<audioEngineContext.audioObjects.length; i++)
n@1118 2935 {
n@1118 2936 var object = audioEngineContext.audioObjects[i];
n@1118 2937 var time = object.buffer.buffer.duration;
n@1118 2938 var metric = object.metric;
n@1118 2939 var passed = false;
n@1118 2940 for (var j=0; j<metric.listenTracker.length; j++)
n@1118 2941 {
n@1118 2942 var bt = metric.listenTracker[j].getElementsByTagName('buffertime');
n@1118 2943 var start_time = Number(bt[0].getAttribute('start'));
n@1118 2944 var stop_time = Number(bt[0].getAttribute('stop'));
n@1118 2945 var delta = stop_time - start_time;
n@1118 2946 if (delta >= time)
n@1118 2947 {
n@1118 2948 passed = true;
n@1118 2949 break;
n@1118 2950 }
n@1118 2951 }
n@1118 2952 if (passed == false)
n@1118 2953 {
n@1118 2954 check_pass = false;
n@1140 2955 console.log("Continue listening to track-"+audioEngineContext.audioObjects.interfaceDOM.getPresentedId());
n@1140 2956 error_obj.push(audioEngineContext.audioObjects.interfaceDOM.getPresentedId());
n@1118 2957 }
n@1118 2958 }
n@1118 2959 if (check_pass == false)
n@1118 2960 {
n@1118 2961 var str_start = "You have not completely listened to fragments ";
n@1118 2962 for (var i=0; i<error_obj.length; i++)
n@1118 2963 {
n@1118 2964 str_start += error_obj[i];
n@1118 2965 if (i != error_obj.length-1)
n@1118 2966 {
n@1118 2967 str_start += ', ';
n@1118 2968 }
n@1118 2969 }
n@1118 2970 str_start += ". Please keep listening";
n@1118 2971 console.log("[ALERT]: "+str_start);
n@1167 2972 this.storeErrorNode("[ALERT]: "+str_start);
n@1118 2973 alert(str_start);
n@1118 2974 }
n@1118 2975 };
n@1118 2976 this.checkAllMoved = function()
n@1118 2977 {
n@1118 2978 var str = "You have not moved ";
n@1118 2979 var failed = [];
n@1140 2980 for (var ao of audioEngineContext.audioObjects)
n@1118 2981 {
n@1140 2982 if(ao.metric.wasMoved == false && ao.interfaceDOM.canMove() == true)
n@1118 2983 {
n@1140 2984 failed.push(ao.interfaceDOM.getPresentedId());
n@1118 2985 }
n@1118 2986 }
n@1118 2987 if (failed.length == 0)
n@1118 2988 {
n@1118 2989 return true;
n@1118 2990 } else if (failed.length == 1)
n@1118 2991 {
n@1118 2992 str += 'track '+failed[0];
n@1118 2993 } else {
n@1118 2994 str += 'tracks ';
n@1118 2995 for (var i=0; i<failed.length-1; i++)
n@1118 2996 {
n@1118 2997 str += failed[i]+', ';
n@1118 2998 }
n@1118 2999 str += 'and '+failed[i];
n@1118 3000 }
n@1118 3001 str +='.';
n@1118 3002 alert(str);
n@1118 3003 console.log(str);
n@1167 3004 this.storeErrorNode(str);
n@1118 3005 return false;
n@1118 3006 };
n@1118 3007 this.checkAllPlayed = function()
n@1118 3008 {
n@1118 3009 var str = "You have not played ";
n@1118 3010 var failed = [];
n@1140 3011 for (var ao of audioEngineContext.audioObjects)
n@1118 3012 {
n@1140 3013 if(ao.metric.wasListenedTo == false)
n@1118 3014 {
n@1140 3015 failed.push(ao.interfaceDOM.getPresentedId());
n@1118 3016 }
n@1118 3017 }
n@1118 3018 if (failed.length == 0)
n@1118 3019 {
n@1118 3020 return true;
n@1118 3021 } else if (failed.length == 1)
n@1118 3022 {
n@1118 3023 str += 'track '+failed[0];
n@1118 3024 } else {
n@1118 3025 str += 'tracks ';
n@1118 3026 for (var i=0; i<failed.length-1; i++)
n@1118 3027 {
n@1118 3028 str += failed[i]+', ';
n@1118 3029 }
n@1118 3030 str += 'and '+failed[i];
n@1118 3031 }
n@1118 3032 str +='.';
n@1118 3033 alert(str);
n@1118 3034 console.log(str);
n@1167 3035 this.storeErrorNode(str);
n@1118 3036 return false;
n@1118 3037 };
n@1167 3038
n@1167 3039 this.storeErrorNode = function(errorMessage)
n@1167 3040 {
n@1167 3041 var time = audioEngineContext.timer.getTestTime();
n@1167 3042 var node = storage.document.createElement('error');
n@1167 3043 node.setAttribute('time',time);
n@1167 3044 node.textContent = errorMessage;
n@1167 3045 testState.currentStore.XMLDOM.appendChild(node);
n@1167 3046 };
n@1124 3047 }
n@1124 3048
n@1124 3049 function Storage()
n@1124 3050 {
n@1124 3051 // Holds results in XML format until ready for collection
n@1124 3052 this.globalPreTest = null;
n@1124 3053 this.globalPostTest = null;
n@1124 3054 this.testPages = [];
n@1124 3055 this.document = document.implementation.createDocument(null,"waetresult");
n@1124 3056 this.root = this.document.children[0];
n@1124 3057 this.state = 0;
n@1124 3058
n@1124 3059 this.initialise = function()
n@1124 3060 {
n@1142 3061 if (specification.preTest != undefined){this.globalPreTest = new this.surveyNode(this,this.root,specification.preTest);}
n@1142 3062 if (specification.postTest != undefined){this.globalPostTest = new this.surveyNode(this,this.root,specification.postTest);}
n@1124 3063 };
n@1124 3064
n@1124 3065 this.createTestPageStore = function(specification)
n@1124 3066 {
n@1124 3067 var store = new this.pageNode(this,specification);
n@1124 3068 this.testPages.push(store);
n@1124 3069 return this.testPages[this.testPages.length-1];
n@1124 3070 };
n@1124 3071
n@1124 3072 this.surveyNode = function(parent,root,specification)
n@1124 3073 {
n@1124 3074 this.specification = specification;
n@1124 3075 this.parent = parent;
n@1124 3076 this.XMLDOM = this.parent.document.createElement('survey');
n@1124 3077 this.XMLDOM.setAttribute('location',this.specification.location);
n@1124 3078 for (var optNode of this.specification.options)
n@1124 3079 {
n@1124 3080 if (optNode.type != 'statement')
n@1124 3081 {
n@1124 3082 var node = this.parent.document.createElement('surveyresult');
n@1124 3083 node.id = optNode.id;
n@1124 3084 node.setAttribute('type',optNode.type);
n@1124 3085 this.XMLDOM.appendChild(node);
n@1124 3086 }
n@1124 3087 }
n@1124 3088 root.appendChild(this.XMLDOM);
n@1124 3089
n@1124 3090 this.postResult = function(node)
n@1124 3091 {
n@1124 3092 // From popup: node is the popupOption node containing both spec. and results
n@1124 3093 // ID is the position
n@1124 3094 if (node.specification.type == 'statement'){return;}
n@1124 3095 var surveyresult = this.parent.document.getElementById(node.specification.id);
n@1124 3096 switch(node.specification.type)
n@1124 3097 {
n@1124 3098 case "number":
n@1124 3099 case "question":
n@1124 3100 var child = this.parent.document.createElement('response');
n@1124 3101 child.textContent = node.response;
n@1124 3102 surveyresult.appendChild(child);
n@1124 3103 break;
n@1124 3104 case "radio":
n@1124 3105 var child = this.parent.document.createElement('response');
n@1124 3106 child.setAttribute('name',node.response.name);
n@1124 3107 child.textContent = node.response.text;
n@1124 3108 surveyresult.appendChild(child);
n@1124 3109 break;
n@1124 3110 case "checkbox":
n@1124 3111 for (var i=0; i<node.response.length; i++)
n@1124 3112 {
n@1124 3113 var checkNode = this.parent.document.createElement('response');
n@1147 3114 checkNode.setAttribute('name',node.response[i].name);
n@1147 3115 checkNode.setAttribute('checked',node.response[i].checked);
n@1126 3116 surveyresult.appendChild(checkNode);
n@1124 3117 }
n@1124 3118 break;
n@1124 3119 }
n@1124 3120 };
n@1124 3121 };
n@1124 3122
n@1124 3123 this.pageNode = function(parent,specification)
n@1124 3124 {
n@1124 3125 // Create one store per test page
n@1124 3126 this.specification = specification;
n@1124 3127 this.parent = parent;
n@1124 3128 this.XMLDOM = this.parent.document.createElement('page');
n@1124 3129 this.XMLDOM.setAttribute('id',specification.id);
n@1124 3130 this.XMLDOM.setAttribute('presentedId',specification.presentedId);
n@1145 3131 if (specification.preTest != undefined){this.preTest = new this.parent.surveyNode(this.parent,this.XMLDOM,this.specification.preTest);}
n@1145 3132 if (specification.postTest != undefined){this.postTest = new this.parent.surveyNode(this.parent,this.XMLDOM,this.specification.postTest);}
n@1124 3133
n@1124 3134 // Add any page metrics
n@1124 3135 var page_metric = this.parent.document.createElement('metric');
n@1124 3136 this.XMLDOM.appendChild(page_metric);
n@1124 3137
n@1124 3138 // Add the audioelement
n@1124 3139 for (var element of this.specification.audioElements)
n@1124 3140 {
n@1124 3141 var aeNode = this.parent.document.createElement('audioelement');
n@1124 3142 aeNode.id = element.id;
n@1124 3143 aeNode.setAttribute('type',element.type);
n@1124 3144 aeNode.setAttribute('url', element.url);
n@1124 3145 aeNode.setAttribute('gain', element.gain);
n@1124 3146 if (element.type == 'anchor' || element.type == 'reference')
n@1124 3147 {
n@1124 3148 if (element.marker > 0)
n@1124 3149 {
n@1124 3150 aeNode.setAttribute('marker',element.marker);
n@1124 3151 }
n@1124 3152 }
n@1124 3153 var ae_metric = this.parent.document.createElement('metric');
n@1124 3154 aeNode.appendChild(ae_metric);
n@1124 3155 this.XMLDOM.appendChild(aeNode);
n@1124 3156 }
n@1124 3157
n@1124 3158 // Add any commentQuestions
n@1124 3159 for (var element of this.specification.commentQuestions)
n@1124 3160 {
n@1124 3161 var cqNode = this.parent.document.createElement('commentquestion');
n@1124 3162 cqNode.id = element.id;
n@1124 3163 cqNode.setAttribute('type',element.type);
n@1124 3164 var statement = this.parent.document.createElement('statement');
n@1124 3165 statement.textContent = cqNode.statement;
n@1124 3166 cqNode.appendChild(statement);
n@1124 3167 var response = this.parent.document.createElement('response');
n@1124 3168 cqNode.appendChild(response);
n@1124 3169 this.XMLDOM.appendChild(cqNode);
n@1124 3170 }
n@1124 3171
n@1124 3172 this.parent.root.appendChild(this.XMLDOM);
n@1124 3173 };
n@1124 3174 this.finish = function()
n@1124 3175 {
n@1124 3176 if (this.state == 0)
n@1124 3177 {
n@1124 3178 var projectDocument = specification.projectXML;
n@1124 3179 projectDocument.setAttribute('file-name',url);
n@1124 3180 this.root.appendChild(projectDocument);
n@1124 3181 this.root.appendChild(returnDateNode());
n@1124 3182 this.root.appendChild(interfaceContext.returnNavigator());
n@1124 3183 }
n@1124 3184 this.state = 1;
n@1124 3185 return this.root;
n@1124 3186 };
n@1124 3187 }