annotate core.js @ 816:9c579fc05a09

Updating test create using questions
author Nicholas Jillings <n.g.r.jillings@se14.qmul.ac.uk>
date Wed, 23 Sep 2015 11:42:11 +0100
parents
children 2ac1cb304fdc
rev   line source
n@816 1 /**
n@816 2 * core.js
n@816 3 *
n@816 4 * Main script to run, calls all other core functions and manages loading/store to backend.
n@816 5 * Also contains all global variables.
n@816 6 */
n@816 7
n@816 8 /* create the web audio API context and store in audioContext*/
n@816 9 var audioContext; // Hold the browser web audio API
n@816 10 var projectXML; // Hold the parsed setup XML
n@816 11 var specification;
n@816 12 var interfaceContext;
n@816 13 var popup; // Hold the interfacePopup object
n@816 14 var testState;
n@816 15 var currentTrackOrder = []; // Hold the current XML tracks in their (randomised) order
n@816 16 var audioEngineContext; // The custome AudioEngine object
n@816 17 var projectReturn; // Hold the URL for the return
n@816 18
n@816 19
n@816 20 // Add a prototype to the bufferSourceNode to reference to the audioObject holding it
n@816 21 AudioBufferSourceNode.prototype.owner = undefined;
n@816 22
n@816 23 window.onload = function() {
n@816 24 // Function called once the browser has loaded all files.
n@816 25 // This should perform any initial commands such as structure / loading documents
n@816 26
n@816 27 // Create a web audio API context
n@816 28 // Fixed for cross-browser support
n@816 29 var AudioContext = window.AudioContext || window.webkitAudioContext;
n@816 30 audioContext = new AudioContext;
n@816 31
n@816 32 // Create test state
n@816 33 testState = new stateMachine();
n@816 34
n@816 35 // Create the audio engine object
n@816 36 audioEngineContext = new AudioEngine();
n@816 37
n@816 38 // Create the popup interface object
n@816 39 popup = new interfacePopup();
n@816 40
n@816 41 // Create the specification object
n@816 42 specification = new Specification();
n@816 43
n@816 44 // Create the interface object
n@816 45 interfaceContext = new Interface(specification);
n@816 46 };
n@816 47
n@816 48 function interfacePopup() {
n@816 49 // Creates an object to manage the popup
n@816 50 this.popup = null;
n@816 51 this.popupContent = null;
n@816 52 this.popupTitle = null;
n@816 53 this.popupResponse = null;
n@816 54 this.buttonProceed = null;
n@816 55 this.buttonPrevious = null;
n@816 56 this.popupOptions = null;
n@816 57 this.currentIndex = null;
n@816 58 this.responses = null;
n@816 59
n@816 60 this.createPopup = function(){
n@816 61 // Create popup window interface
n@816 62 var insertPoint = document.getElementById("topLevelBody");
n@816 63 var blank = document.createElement('div');
n@816 64 blank.className = 'testHalt';
n@816 65
n@816 66 this.popup = document.createElement('div');
n@816 67 this.popup.id = 'popupHolder';
n@816 68 this.popup.className = 'popupHolder';
n@816 69 this.popup.style.position = 'absolute';
n@816 70 this.popup.style.left = (window.innerWidth/2)-250 + 'px';
n@816 71 this.popup.style.top = (window.innerHeight/2)-125 + 'px';
n@816 72
n@816 73 this.popupContent = document.createElement('div');
n@816 74 this.popupContent.id = 'popupContent';
n@816 75 this.popupContent.style.marginTop = '20px';
n@816 76 this.popupContent.align = 'center';
n@816 77 this.popup.appendChild(this.popupContent);
n@816 78
n@816 79 var titleHolder = document.createElement('div');
n@816 80 titleHolder.id = 'popupTitleHolder';
n@816 81 titleHolder.style.width = 'inherit';
n@816 82 titleHolder.style.height = '25px';
n@816 83 titleHolder.style.marginBottom = '5px';
n@816 84
n@816 85 this.popupTitle = document.createElement('span');
n@816 86 this.popupTitle.id = 'popupTitle';
n@816 87 titleHolder.appendChild(this.popupTitle);
n@816 88 this.popupContent.appendChild(titleHolder);
n@816 89
n@816 90 this.popupResponse = document.createElement('div');
n@816 91 this.popupResponse.id = 'popupResponse';
n@816 92 this.popupResponse.style.width = 'inherit';
n@816 93 this.popupResponse.style.minHeight = '170px';
n@816 94 this.popupResponse.style.maxHeight = '320px';
n@816 95 this.popupResponse.style.overflow = 'auto';
n@816 96 this.popupContent.appendChild(this.popupResponse);
n@816 97
n@816 98 var buttonHolder = document.createElement('div');
n@816 99 buttonHolder.id='buttonHolder';
n@816 100 buttonHolder.width = 'inherit';
n@816 101 buttonHolder.style.height= '30px';
n@816 102 buttonHolder.align = 'left';
n@816 103 this.popupContent.appendChild(buttonHolder);
n@816 104
n@816 105 this.buttonProceed = document.createElement('button');
n@816 106 this.buttonProceed.className = 'popupButton';
n@816 107 this.buttonProceed.style.left = '390px';
n@816 108 this.buttonProceed.style.top = '2px';
n@816 109 this.buttonProceed.innerHTML = 'Next';
n@816 110 this.buttonProceed.onclick = function(){popup.proceedClicked();};
n@816 111
n@816 112 this.buttonPrevious = document.createElement('button');
n@816 113 this.buttonPrevious.className = 'popupButton';
n@816 114 this.buttonPrevious.style.left = '10px';
n@816 115 this.buttonPrevious.style.top = '2px';
n@816 116 this.buttonPrevious.innerHTML = 'Back';
n@816 117 this.buttonPrevious.onclick = function(){popup.previousClick();};
n@816 118
n@816 119 buttonHolder.appendChild(this.buttonPrevious);
n@816 120 buttonHolder.appendChild(this.buttonProceed);
n@816 121
n@816 122 this.popup.style.zIndex = -1;
n@816 123 this.popup.style.visibility = 'hidden';
n@816 124 blank.style.zIndex = -2;
n@816 125 blank.style.visibility = 'hidden';
n@816 126 insertPoint.appendChild(this.popup);
n@816 127 insertPoint.appendChild(blank);
n@816 128 };
n@816 129
n@816 130 this.showPopup = function(){
n@816 131 if (this.popup == null) {
n@816 132 this.createPopup();
n@816 133 }
n@816 134 this.popup.style.zIndex = 3;
n@816 135 this.popup.style.visibility = 'visible';
n@816 136 var blank = document.getElementsByClassName('testHalt')[0];
n@816 137 blank.style.zIndex = 2;
n@816 138 blank.style.visibility = 'visible';
n@816 139 $(window).keypress(function(e){
n@816 140 if (e.keyCode == 13 && popup.popup.style.visibility == 'visible')
n@816 141 {
n@816 142 // Enter key pressed
n@816 143 var textarea = $(popup.popupContent).find('textarea');
n@816 144 if (textarea.length != 0)
n@816 145 {
n@816 146 if (textarea[0] == document.activeElement)
n@816 147 {return;}
n@816 148 }
n@816 149 popup.buttonProceed.onclick();
n@816 150 }
n@816 151 });
n@816 152 };
n@816 153
n@816 154 this.hidePopup = function(){
n@816 155 this.popup.style.zIndex = -1;
n@816 156 this.popup.style.visibility = 'hidden';
n@816 157 var blank = document.getElementsByClassName('testHalt')[0];
n@816 158 blank.style.zIndex = -2;
n@816 159 blank.style.visibility = 'hidden';
n@816 160 this.buttonPrevious.style.visibility = 'inherit';
n@816 161 };
n@816 162
n@816 163 this.postNode = function() {
n@816 164 // This will take the node from the popupOptions and display it
n@816 165 var node = this.popupOptions[this.currentIndex];
n@816 166 this.popupResponse.innerHTML = null;
n@816 167 if (node.type == 'statement') {
n@816 168 this.popupTitle.textContent = null;
n@816 169 var statement = document.createElement('span');
n@816 170 statement.textContent = node.statement;
n@816 171 this.popupResponse.appendChild(statement);
n@816 172 } else if (node.type == 'question') {
n@816 173 this.popupTitle.textContent = node.question;
n@816 174 var textArea = document.createElement('textarea');
n@816 175 switch (node.boxsize) {
n@816 176 case 'small':
n@816 177 textArea.cols = "20";
n@816 178 textArea.rows = "1";
n@816 179 break;
n@816 180 case 'normal':
n@816 181 textArea.cols = "30";
n@816 182 textArea.rows = "2";
n@816 183 break;
n@816 184 case 'large':
n@816 185 textArea.cols = "40";
n@816 186 textArea.rows = "5";
n@816 187 break;
n@816 188 case 'huge':
n@816 189 textArea.cols = "50";
n@816 190 textArea.rows = "10";
n@816 191 break;
n@816 192 }
n@816 193 this.popupResponse.appendChild(textArea);
n@816 194 textArea.focus();
n@816 195 } else if (node.type == 'checkbox') {
n@816 196 this.popupTitle.textContent = node.statement;
n@816 197 var optHold = this.popupResponse;
n@816 198 for (var i=0; i<node.options.length; i++) {
n@816 199 var option = node.options[i];
n@816 200 var input = document.createElement('input');
n@816 201 input.id = option.id;
n@816 202 input.type = 'checkbox';
n@816 203 var span = document.createElement('span');
n@816 204 span.textContent = option.text;
n@816 205 var hold = document.createElement('div');
n@816 206 hold.setAttribute('name','option');
n@816 207 hold.style.padding = '4px';
n@816 208 hold.appendChild(input);
n@816 209 hold.appendChild(span);
n@816 210 optHold.appendChild(hold);
n@816 211 }
n@816 212 } else if (node.type == 'radio') {
n@816 213 this.popupTitle.textContent = node.statement;
n@816 214 var optHold = this.popupResponse;
n@816 215 for (var i=0; i<node.options.length; i++) {
n@816 216 var option = node.options[i];
n@816 217 var input = document.createElement('input');
n@816 218 input.id = option.name;
n@816 219 input.type = 'radio';
n@816 220 input.name = node.id;
n@816 221 var span = document.createElement('span');
n@816 222 span.textContent = option.text;
n@816 223 var hold = document.createElement('div');
n@816 224 hold.setAttribute('name','option');
n@816 225 hold.style.padding = '4px';
n@816 226 hold.appendChild(input);
n@816 227 hold.appendChild(span);
n@816 228 optHold.appendChild(hold);
n@816 229 }
n@816 230 } else if (node.type == 'number') {
n@816 231 this.popupTitle.textContent = node.statement;
n@816 232 var input = document.createElement('input');
n@816 233 input.type = 'textarea';
n@816 234 if (node.min != null) {input.min = node.min;}
n@816 235 if (node.max != null) {input.max = node.max;}
n@816 236 if (node.step != null) {input.step = node.step;}
n@816 237 this.popupResponse.appendChild(input);
n@816 238 }
n@816 239 if(this.currentIndex+1 == this.popupOptions.length) {
n@816 240 if (this.responses.nodeName == "PRETEST") {
n@816 241 this.buttonProceed.textContent = 'Start';
n@816 242 } else {
n@816 243 this.buttonProceed.textContent = 'Submit';
n@816 244 }
n@816 245 } else {
n@816 246 this.buttonProceed.textContent = 'Next';
n@816 247 }
n@816 248 if(this.currentIndex > 0)
n@816 249 this.buttonPrevious.style.visibility = 'visible';
n@816 250 else
n@816 251 this.buttonPrevious.style.visibility = 'hidden';
n@816 252 };
n@816 253
n@816 254 this.initState = function(node) {
n@816 255 //Call this with your preTest and postTest nodes when needed to
n@816 256 // initialise the popup procedure.
n@816 257 this.popupOptions = node.options;
n@816 258 if (this.popupOptions.length > 0) {
n@816 259 if (node.type == 'pretest') {
n@816 260 this.responses = document.createElement('PreTest');
n@816 261 } else if (node.type == 'posttest') {
n@816 262 this.responses = document.createElement('PostTest');
n@816 263 } else {
n@816 264 console.log ('WARNING - popup node neither pre or post!');
n@816 265 this.responses = document.createElement('responses');
n@816 266 }
n@816 267 this.currentIndex = 0;
n@816 268 this.showPopup();
n@816 269 this.postNode();
n@816 270 } else {
n@816 271 advanceState();
n@816 272 }
n@816 273 };
n@816 274
n@816 275 this.proceedClicked = function() {
n@816 276 // Each time the popup button is clicked!
n@816 277 var node = this.popupOptions[this.currentIndex];
n@816 278 if (node.type == 'question') {
n@816 279 // Must extract the question data
n@816 280 var textArea = $(popup.popupContent).find('textarea')[0];
n@816 281 if (node.mandatory == true && textArea.value.length == 0) {
n@816 282 alert('This question is mandatory');
n@816 283 return;
n@816 284 } else {
n@816 285 // Save the text content
n@816 286 var hold = document.createElement('comment');
n@816 287 hold.id = node.id;
n@816 288 hold.innerHTML = textArea.value;
n@816 289 console.log("Question: "+ node.question);
n@816 290 console.log("Question Response: "+ textArea.value);
n@816 291 this.responses.appendChild(hold);
n@816 292 }
n@816 293 } else if (node.type == 'checkbox') {
n@816 294 // Must extract checkbox data
n@816 295 var optHold = this.popupResponse;
n@816 296 var hold = document.createElement('checkbox');
n@816 297 console.log("Checkbox: "+ node.statement);
n@816 298 hold.id = node.id;
n@816 299 for (var i=0; i<optHold.childElementCount; i++) {
n@816 300 var input = optHold.childNodes[i].getElementsByTagName('input')[0];
n@816 301 var statement = optHold.childNodes[i].getElementsByTagName('span')[0];
n@816 302 var response = document.createElement('option');
n@816 303 response.setAttribute('name',input.id);
n@816 304 response.textContent = input.checked;
n@816 305 hold.appendChild(response);
n@816 306 console.log(input.id +': '+ input.checked);
n@816 307 }
n@816 308 this.responses.appendChild(hold);
n@816 309 } else if (node.type == "radio") {
n@816 310 var optHold = this.popupResponse;
n@816 311 var hold = document.createElement('radio');
n@816 312 var responseID = null;
n@816 313 var i=0;
n@816 314 while(responseID == null) {
n@816 315 var input = optHold.childNodes[i].getElementsByTagName('input')[0];
n@816 316 if (input.checked == true) {
n@816 317 responseID = i;
n@816 318 }
n@816 319 i++;
n@816 320 }
n@816 321 hold.id = node.id;
n@816 322 hold.setAttribute('name',node.options[responseID].name);
n@816 323 hold.textContent = node.options[responseID].text;
n@816 324 this.responses.appendChild(hold);
n@816 325 } else if (node.type == "number") {
n@816 326 var input = this.popupContent.getElementsByTagName('input')[0];
n@816 327 if (node.mandatory == true && input.value.length == 0) {
n@816 328 alert('This question is mandatory. Please enter a number');
n@816 329 return;
n@816 330 }
n@816 331 var enteredNumber = Number(input.value);
n@816 332 if (isNaN(enteredNumber)) {
n@816 333 alert('Please enter a valid number');
n@816 334 return;
n@816 335 }
n@816 336 if (enteredNumber < node.min && node.min != null) {
n@816 337 alert('Number is below the minimum value of '+node.min);
n@816 338 return;
n@816 339 }
n@816 340 if (enteredNumber > node.max && node.max != null) {
n@816 341 alert('Number is above the maximum value of '+node.max);
n@816 342 return;
n@816 343 }
n@816 344 var hold = document.createElement('number');
n@816 345 hold.id = node.id;
n@816 346 hold.textContent = input.value;
n@816 347 this.responses.appendChild(hold);
n@816 348 }
n@816 349 this.currentIndex++;
n@816 350 if (this.currentIndex < this.popupOptions.length) {
n@816 351 this.postNode();
n@816 352 } else {
n@816 353 // Reached the end of the popupOptions
n@816 354 this.hidePopup();
n@816 355 if (this.responses.nodeName == testState.stateResults[testState.stateIndex].nodeName) {
n@816 356 testState.stateResults[testState.stateIndex] = this.responses;
n@816 357 } else {
n@816 358 testState.stateResults[testState.stateIndex].appendChild(this.responses);
n@816 359 }
n@816 360 advanceState();
n@816 361 }
n@816 362 };
n@816 363
n@816 364 this.previousClick = function() {
n@816 365 // Triggered when the 'Back' button is clicked in the survey
n@816 366 if (this.currentIndex > 0) {
n@816 367 this.currentIndex--;
n@816 368 var node = this.popupOptions[this.currentIndex];
n@816 369 if (node.type != 'statement') {
n@816 370 var prevResp = this.responses.childNodes[this.responses.childElementCount-1];
n@816 371 this.responses.removeChild(prevResp);
n@816 372 }
n@816 373 this.postNode();
n@816 374 if (node.type == 'question') {
n@816 375 this.popupContent.getElementsByTagName('textarea')[0].value = prevResp.textContent;
n@816 376 } else if (node.type == 'checkbox') {
n@816 377 var options = this.popupContent.getElementsByTagName('input');
n@816 378 var savedOptions = prevResp.getElementsByTagName('option');
n@816 379 for (var i=0; i<options.length; i++) {
n@816 380 var id = options[i].id;
n@816 381 for (var j=0; j<savedOptions.length; j++) {
n@816 382 if (savedOptions[j].getAttribute('name') == id) {
n@816 383 if (savedOptions[j].textContent == 'true') {options[i].checked = true;}
n@816 384 else {options[i].checked = false;}
n@816 385 break;
n@816 386 }
n@816 387 }
n@816 388 }
n@816 389 } else if (node.type == 'number') {
n@816 390 this.popupContent.getElementsByTagName('input')[0].value = prevResp.textContent;
n@816 391 } else if (node.type == 'radio') {
n@816 392 var options = this.popupContent.getElementsByTagName('input');
n@816 393 var name = prevResp.getAttribute('name');
n@816 394 for (var i=0; i<options.length; i++) {
n@816 395 if (options[i].id == name) {
n@816 396 options[i].checked = true;
n@816 397 break;
n@816 398 }
n@816 399 }
n@816 400 }
n@816 401 }
n@816 402 };
n@816 403 }
n@816 404
n@816 405 function advanceState()
n@816 406 {
n@816 407 // Just for complete clarity
n@816 408 testState.advanceState();
n@816 409 }
n@816 410
n@816 411 function stateMachine()
n@816 412 {
n@816 413 // Object prototype for tracking and managing the test state
n@816 414 this.stateMap = [];
n@816 415 this.stateIndex = null;
n@816 416 this.currentStateMap = [];
n@816 417 this.currentIndex = null;
n@816 418 this.currentTestId = 0;
n@816 419 this.stateResults = [];
n@816 420 this.timerCallBackHolders = null;
n@816 421 this.initialise = function(){
n@816 422 if (this.stateMap.length > 0) {
n@816 423 if(this.stateIndex != null) {
n@816 424 console.log('NOTE - State already initialise');
n@816 425 }
n@816 426 this.stateIndex = -1;
n@816 427 var that = this;
n@816 428 var aH_pId = 0;
n@816 429 for (var id=0; id<this.stateMap.length; id++){
n@816 430 var name = this.stateMap[id].type;
n@816 431 var obj = document.createElement(name);
n@816 432 if (name == 'audioHolder') {
n@816 433 obj.id = this.stateMap[id].id;
n@816 434 obj.setAttribute('presentedid',aH_pId);
n@816 435 aH_pId+=1;
n@816 436 }
n@816 437 this.stateResults.push(obj);
n@816 438 }
n@816 439 } else {
n@816 440 console.log('FATAL - StateMap not correctly constructed. EMPTY_STATE_MAP');
n@816 441 }
n@816 442 };
n@816 443 this.advanceState = function(){
n@816 444 if (this.stateIndex == null) {
n@816 445 this.initialise();
n@816 446 }
n@816 447 if (this.stateIndex == -1) {
n@816 448 console.log('Starting test...');
n@816 449 }
n@816 450 if (this.currentIndex == null){
n@816 451 if (this.currentStateMap.type == "audioHolder") {
n@816 452 // Save current page
n@816 453 this.testPageCompleted(this.stateResults[this.stateIndex],this.currentStateMap,this.currentTestId);
n@816 454 this.currentTestId++;
n@816 455 }
n@816 456 this.stateIndex++;
n@816 457 if (this.stateIndex >= this.stateMap.length) {
n@816 458 console.log('Test Completed');
n@816 459 createProjectSave(specification.projectReturn);
n@816 460 } else {
n@816 461 this.currentStateMap = this.stateMap[this.stateIndex];
n@816 462 if (this.currentStateMap.type == "audioHolder") {
n@816 463 console.log('Loading test page');
n@816 464 loadTest(this.currentStateMap);
n@816 465 this.initialiseInnerState(this.currentStateMap);
n@816 466 } else if (this.currentStateMap.type == "pretest" || this.currentStateMap.type == "posttest") {
n@816 467 if (this.currentStateMap.options.length >= 1) {
n@816 468 popup.initState(this.currentStateMap);
n@816 469 } else {
n@816 470 this.advanceState();
n@816 471 }
n@816 472 } else {
n@816 473 this.advanceState();
n@816 474 }
n@816 475 }
n@816 476 } else {
n@816 477 this.advanceInnerState();
n@816 478 }
n@816 479 };
n@816 480
n@816 481 this.testPageCompleted = function(store, testXML, testId) {
n@816 482 // Function called each time a test page has been completed
n@816 483 // Can be used to over-rule default behaviour
n@816 484
n@816 485 pageXMLSave(store, testXML);
n@816 486 };
n@816 487
n@816 488 this.initialiseInnerState = function(node) {
n@816 489 // Parses the received testXML for pre and post test options
n@816 490 this.currentStateMap = [];
n@816 491 var preTest = node.preTest;
n@816 492 var postTest = node.postTest;
n@816 493 if (preTest == undefined) {preTest = document.createElement("preTest");}
n@816 494 if (postTest == undefined){postTest= document.createElement("postTest");}
n@816 495 this.currentStateMap.push(preTest);
n@816 496 this.currentStateMap.push(node);
n@816 497 this.currentStateMap.push(postTest);
n@816 498 this.currentIndex = -1;
n@816 499 this.advanceInnerState();
n@816 500 };
n@816 501
n@816 502 this.advanceInnerState = function() {
n@816 503 this.currentIndex++;
n@816 504 if (this.currentIndex >= this.currentStateMap.length) {
n@816 505 this.currentIndex = null;
n@816 506 this.currentStateMap = this.stateMap[this.stateIndex];
n@816 507 this.advanceState();
n@816 508 } else {
n@816 509 if (this.currentStateMap[this.currentIndex].type == "audioHolder") {
n@816 510 console.log("Loading test page"+this.currentTestId);
n@816 511 } else if (this.currentStateMap[this.currentIndex].type == "pretest") {
n@816 512 popup.initState(this.currentStateMap[this.currentIndex]);
n@816 513 } else if (this.currentStateMap[this.currentIndex].type == "posttest") {
n@816 514 popup.initState(this.currentStateMap[this.currentIndex]);
n@816 515 } else {
n@816 516 this.advanceInnerState();
n@816 517 }
n@816 518 }
n@816 519 };
n@816 520
n@816 521 this.previousState = function(){};
n@816 522 }
n@816 523
n@816 524 function testEnded(testId)
n@816 525 {
n@816 526 pageXMLSave(testId);
n@816 527 if (testXMLSetups.length-1 > testId)
n@816 528 {
n@816 529 // Yes we have another test to perform
n@816 530 testId = (Number(testId)+1);
n@816 531 currentState = 'testRun-'+testId;
n@816 532 loadTest(testId);
n@816 533 } else {
n@816 534 console.log('Testing Completed!');
n@816 535 currentState = 'postTest';
n@816 536 // Check for any post tests
n@816 537 var xmlSetup = projectXML.find('setup');
n@816 538 var postTest = xmlSetup.find('PostTest')[0];
n@816 539 popup.initState(postTest);
n@816 540 }
n@816 541 }
n@816 542
n@816 543 function loadProjectSpec(url) {
n@816 544 // Load the project document from the given URL, decode the XML and instruct audioEngine to get audio data
n@816 545 // If url is null, request client to upload project XML document
n@816 546 var r = new XMLHttpRequest();
n@816 547 r.open('GET',url,true);
n@816 548 r.onload = function() {
n@816 549 loadProjectSpecCallback(r.response);
n@816 550 };
n@816 551 r.send();
n@816 552 };
n@816 553
n@816 554 function loadProjectSpecCallback(response) {
n@816 555 // Function called after asynchronous download of XML project specification
n@816 556 //var decode = $.parseXML(response);
n@816 557 //projectXML = $(decode);
n@816 558
n@816 559 var parse = new DOMParser();
n@816 560 projectXML = parse.parseFromString(response,'text/xml');
n@816 561
n@816 562 // Build the specification
n@816 563 specification.decode();
n@816 564
n@816 565 testState.stateMap.push(specification.preTest);
n@816 566
n@816 567 $(specification.audioHolders).each(function(index,elem){
n@816 568 testState.stateMap.push(elem);
n@816 569 });
n@816 570
n@816 571 testState.stateMap.push(specification.postTest);
n@816 572
n@816 573 // Obtain the metrics enabled
n@816 574 $(specification.metrics).each(function(index,node){
n@816 575 var enabled = node.textContent;
n@816 576 switch(node.enabled)
n@816 577 {
n@816 578 case 'testTimer':
n@816 579 sessionMetrics.prototype.enableTestTimer = true;
n@816 580 break;
n@816 581 case 'elementTimer':
n@816 582 sessionMetrics.prototype.enableElementTimer = true;
n@816 583 break;
n@816 584 case 'elementTracker':
n@816 585 sessionMetrics.prototype.enableElementTracker = true;
n@816 586 break;
n@816 587 case 'elementListenTracker':
n@816 588 sessionMetrics.prototype.enableElementListenTracker = true;
n@816 589 break;
n@816 590 case 'elementInitialPosition':
n@816 591 sessionMetrics.prototype.enableElementInitialPosition = true;
n@816 592 break;
n@816 593 case 'elementFlagListenedTo':
n@816 594 sessionMetrics.prototype.enableFlagListenedTo = true;
n@816 595 break;
n@816 596 case 'elementFlagMoved':
n@816 597 sessionMetrics.prototype.enableFlagMoved = true;
n@816 598 break;
n@816 599 case 'elementFlagComments':
n@816 600 sessionMetrics.prototype.enableFlagComments = true;
n@816 601 break;
n@816 602 }
n@816 603 });
n@816 604
n@816 605
n@816 606
n@816 607 // Detect the interface to use and load the relevant javascripts.
n@816 608 var interfaceJS = document.createElement('script');
n@816 609 interfaceJS.setAttribute("type","text/javascript");
n@816 610 if (specification.interfaceType == 'APE') {
n@816 611 interfaceJS.setAttribute("src","ape.js");
n@816 612
n@816 613 // APE comes with a css file
n@816 614 var css = document.createElement('link');
n@816 615 css.rel = 'stylesheet';
n@816 616 css.type = 'text/css';
n@816 617 css.href = 'ape.css';
n@816 618
n@816 619 document.getElementsByTagName("head")[0].appendChild(css);
n@816 620 } else if (specification.interfaceType == "MUSHRA")
n@816 621 {
n@816 622 interfaceJS.setAttribute("src","mushra.js");
n@816 623
n@816 624 // MUSHRA comes with a css file
n@816 625 var css = document.createElement('link');
n@816 626 css.rel = 'stylesheet';
n@816 627 css.type = 'text/css';
n@816 628 css.href = 'mushra.css';
n@816 629
n@816 630 document.getElementsByTagName("head")[0].appendChild(css);
n@816 631 }
n@816 632 document.getElementsByTagName("head")[0].appendChild(interfaceJS);
n@816 633
n@816 634 // Define window callbacks for interface
n@816 635 window.onresize = function(event){interfaceContext.resizeWindow(event);};
n@816 636 }
n@816 637
n@816 638 function createProjectSave(destURL) {
n@816 639 // Save the data from interface into XML and send to destURL
n@816 640 // If destURL is null then download XML in client
n@816 641 // Now time to render file locally
n@816 642 var xmlDoc = interfaceXMLSave();
n@816 643 var parent = document.createElement("div");
n@816 644 parent.appendChild(xmlDoc);
n@816 645 var file = [parent.innerHTML];
n@816 646 if (destURL == "null" || destURL == undefined) {
n@816 647 var bb = new Blob(file,{type : 'application/xml'});
n@816 648 var dnlk = window.URL.createObjectURL(bb);
n@816 649 var a = document.createElement("a");
n@816 650 a.hidden = '';
n@816 651 a.href = dnlk;
n@816 652 a.download = "save.xml";
n@816 653 a.textContent = "Save File";
n@816 654
n@816 655 popup.showPopup();
n@816 656 popup.popupContent.innerHTML = null;
n@816 657 popup.popupContent.appendChild(a);
n@816 658 } else {
n@816 659 var xmlhttp = new XMLHttpRequest;
n@816 660 xmlhttp.open("POST",destURL,true);
n@816 661 xmlhttp.setRequestHeader('Content-Type', 'text/xml');
n@816 662 xmlhttp.onerror = function(){
n@816 663 console.log('Error saving file to server! Presenting download locally');
n@816 664 createProjectSave(null);
n@816 665 };
n@816 666 xmlhttp.onreadystatechange = function() {
n@816 667 console.log(xmlhttp.status);
n@816 668 if (xmlhttp.status != 200 && xmlhttp.readyState == 4) {
n@816 669 createProjectSave(null);
n@816 670 } else {
n@816 671 popup.showPopup();
n@816 672 popup.popupContent.innerHTML = null;
n@816 673 popup.popupContent.textContent = "Thank you for performing this listening test";
n@816 674 }
n@816 675 };
n@816 676 xmlhttp.send(file);
n@816 677 }
n@816 678 }
n@816 679
n@816 680 function errorSessionDump(msg){
n@816 681 // Create the partial interface XML save
n@816 682 // Include error node with message on why the dump occured
n@816 683 var xmlDoc = interfaceXMLSave();
n@816 684 var err = document.createElement('error');
n@816 685 err.textContent = msg;
n@816 686 xmlDoc.appendChild(err);
n@816 687 var parent = document.createElement("div");
n@816 688 parent.appendChild(xmlDoc);
n@816 689 var file = [parent.innerHTML];
n@816 690 var bb = new Blob(file,{type : 'application/xml'});
n@816 691 var dnlk = window.URL.createObjectURL(bb);
n@816 692 var a = document.createElement("a");
n@816 693 a.hidden = '';
n@816 694 a.href = dnlk;
n@816 695 a.download = "save.xml";
n@816 696 a.textContent = "Save File";
n@816 697
n@816 698 popup.showPopup();
n@816 699 popup.popupContent.innerHTML = "ERROR : "+msg;
n@816 700 popup.popupContent.appendChild(a);
n@816 701 }
n@816 702
n@816 703 // Only other global function which must be defined in the interface class. Determines how to create the XML document.
n@816 704 function interfaceXMLSave(){
n@816 705 // Create the XML string to be exported with results
n@816 706 var xmlDoc = document.createElement("BrowserEvaluationResult");
n@816 707 var projectDocument = specification.projectXML;
n@816 708 projectDocument.setAttribute('file-name',url);
n@816 709 xmlDoc.appendChild(projectDocument);
n@816 710 xmlDoc.appendChild(returnDateNode());
n@816 711 for (var i=0; i<testState.stateResults.length; i++)
n@816 712 {
n@816 713 xmlDoc.appendChild(testState.stateResults[i]);
n@816 714 }
n@816 715
n@816 716 return xmlDoc;
n@816 717 }
n@816 718
n@816 719 function AudioEngine() {
n@816 720
n@816 721 // Create two output paths, the main outputGain and fooGain.
n@816 722 // Output gain is default to 1 and any items for playback route here
n@816 723 // Foo gain is used for analysis to ensure paths get processed, but are not heard
n@816 724 // because web audio will optimise and any route which does not go to the destination gets ignored.
n@816 725 this.outputGain = audioContext.createGain();
n@816 726 this.fooGain = audioContext.createGain();
n@816 727 this.fooGain.gain = 0;
n@816 728
n@816 729 // Use this to detect playback state: 0 - stopped, 1 - playing
n@816 730 this.status = 0;
n@816 731
n@816 732 // Connect both gains to output
n@816 733 this.outputGain.connect(audioContext.destination);
n@816 734 this.fooGain.connect(audioContext.destination);
n@816 735
n@816 736 // Create the timer Object
n@816 737 this.timer = new timer();
n@816 738 // Create session metrics
n@816 739 this.metric = new sessionMetrics(this);
n@816 740
n@816 741 this.loopPlayback = false;
n@816 742
n@816 743 // Create store for new audioObjects
n@816 744 this.audioObjects = [];
n@816 745
n@816 746 this.play = function(id) {
n@816 747 // Start the timer and set the audioEngine state to playing (1)
n@816 748 if (this.status == 0 && this.loopPlayback) {
n@816 749 // Check if all audioObjects are ready
n@816 750 if(this.checkAllReady())
n@816 751 {
n@816 752 this.status = 1;
n@816 753 this.setSynchronousLoop();
n@816 754 }
n@816 755 }
n@816 756 else
n@816 757 {
n@816 758 this.status = 1;
n@816 759 }
n@816 760 if (this.status== 1) {
n@816 761 this.timer.startTest();
n@816 762 if (id == undefined) {
n@816 763 id = -1;
n@816 764 console.log('FATAL - Passed id was undefined - AudioEngineContext.play(id)');
n@816 765 return;
n@816 766 } else {
n@816 767 interfaceContext.playhead.setTimePerPixel(this.audioObjects[id]);
n@816 768 }
n@816 769 if (this.loopPlayback) {
n@816 770 for (var i=0; i<this.audioObjects.length; i++)
n@816 771 {
n@816 772 this.audioObjects[i].play(this.timer.getTestTime()+1);
n@816 773 if (id == i) {
n@816 774 this.audioObjects[i].loopStart();
n@816 775 } else {
n@816 776 this.audioObjects[i].loopStop();
n@816 777 }
n@816 778 }
n@816 779 } else {
n@816 780 for (var i=0; i<this.audioObjects.length; i++)
n@816 781 {
n@816 782 if (i != id) {
n@816 783 this.audioObjects[i].outputGain.gain.value = 0.0;
n@816 784 this.audioObjects[i].stop();
n@816 785 } else if (i == id) {
n@816 786 this.audioObjects[id].outputGain.gain.value = 1.0;
n@816 787 this.audioObjects[id].play(audioContext.currentTime+0.01);
n@816 788 }
n@816 789 }
n@816 790 }
n@816 791 interfaceContext.playhead.start();
n@816 792 }
n@816 793 };
n@816 794
n@816 795 this.stop = function() {
n@816 796 // Send stop and reset command to all playback buffers and set audioEngine state to stopped (1)
n@816 797 if (this.status == 1) {
n@816 798 for (var i=0; i<this.audioObjects.length; i++)
n@816 799 {
n@816 800 this.audioObjects[i].stop();
n@816 801 }
n@816 802 interfaceContext.playhead.stop();
n@816 803 this.status = 0;
n@816 804 }
n@816 805 };
n@816 806
n@816 807 this.newTrack = function(element) {
n@816 808 // Pull data from given URL into new audio buffer
n@816 809 // URLs must either be from the same source OR be setup to 'Access-Control-Allow-Origin'
n@816 810
n@816 811 // Create the audioObject with ID of the new track length;
n@816 812 audioObjectId = this.audioObjects.length;
n@816 813 this.audioObjects[audioObjectId] = new audioObject(audioObjectId);
n@816 814
n@816 815 // AudioObject will get track itself.
n@816 816 this.audioObjects[audioObjectId].specification = element;
n@816 817 this.audioObjects[audioObjectId].constructTrack(element.parent.hostURL + element.url);
n@816 818 return this.audioObjects[audioObjectId];
n@816 819 };
n@816 820
n@816 821 this.newTestPage = function() {
n@816 822 this.state = 0;
n@816 823 this.audioObjectsReady = false;
n@816 824 this.metric.reset();
n@816 825 this.audioObjects = [];
n@816 826 };
n@816 827
n@816 828 this.checkAllPlayed = function() {
n@816 829 arr = [];
n@816 830 for (var id=0; id<this.audioObjects.length; id++) {
n@816 831 if (this.audioObjects[id].metric.wasListenedTo == false) {
n@816 832 arr.push(this.audioObjects[id].id);
n@816 833 }
n@816 834 }
n@816 835 return arr;
n@816 836 };
n@816 837
n@816 838 this.checkAllReady = function() {
n@816 839 var ready = true;
n@816 840 for (var i=0; i<this.audioObjects.length; i++) {
n@816 841 if (this.audioObjects[i].state == 0) {
n@816 842 // Track not ready
n@816 843 console.log('WAIT -- audioObject '+i+' not ready yet!');
n@816 844 ready = false;
n@816 845 };
n@816 846 }
n@816 847 return ready;
n@816 848 };
n@816 849
n@816 850 this.setSynchronousLoop = function() {
n@816 851 // Pads the signals so they are all exactly the same length
n@816 852 var length = 0;
n@816 853 var lens = [];
n@816 854 var maxId;
n@816 855 for (var i=0; i<this.audioObjects.length; i++)
n@816 856 {
n@816 857 lens.push(this.audioObjects[i].buffer.length);
n@816 858 if (length < this.audioObjects[i].buffer.length)
n@816 859 {
n@816 860 length = this.audioObjects[i].buffer.length;
n@816 861 maxId = i;
n@816 862 }
n@816 863 }
n@816 864 // Perform difference
n@816 865 for (var i=0; i<lens.length; i++)
n@816 866 {
n@816 867 lens[i] = length - lens[i];
n@816 868 }
n@816 869 // Extract the audio and zero-pad
n@816 870 for (var i=0; i<lens.length; i++)
n@816 871 {
n@816 872 var orig = this.audioObjects[i].buffer;
n@816 873 var hold = audioContext.createBuffer(orig.numberOfChannels,length,orig.sampleRate);
n@816 874 for (var c=0; c<orig.numberOfChannels; c++)
n@816 875 {
n@816 876 var inData = hold.getChannelData(c);
n@816 877 var outData = orig.getChannelData(c);
n@816 878 for (var n=0; n<orig.length; n++)
n@816 879 {inData[n] = outData[n];}
n@816 880 }
n@816 881 this.audioObjects[i].buffer = hold;
n@816 882 delete orig;
n@816 883 }
n@816 884 };
n@816 885
n@816 886 }
n@816 887
n@816 888 function audioObject(id) {
n@816 889 // The main buffer object with common control nodes to the AudioEngine
n@816 890
n@816 891 this.specification;
n@816 892 this.id = id;
n@816 893 this.state = 0; // 0 - no data, 1 - ready
n@816 894 this.url = null; // Hold the URL given for the output back to the results.
n@816 895 this.metric = new metricTracker(this);
n@816 896
n@816 897 // Bindings for GUI
n@816 898 this.interfaceDOM = null;
n@816 899 this.commentDOM = null;
n@816 900
n@816 901 // Create a buffer and external gain control to allow internal patching of effects and volume leveling.
n@816 902 this.bufferNode = undefined;
n@816 903 this.outputGain = audioContext.createGain();
n@816 904
n@816 905 // Default output gain to be zero
n@816 906 this.outputGain.gain.value = 0.0;
n@816 907
n@816 908 // Connect buffer to the audio graph
n@816 909 this.outputGain.connect(audioEngineContext.outputGain);
n@816 910
n@816 911 // the audiobuffer is not designed for multi-start playback
n@816 912 // When stopeed, the buffer node is deleted and recreated with the stored buffer.
n@816 913 this.buffer;
n@816 914
n@816 915 this.loopStart = function() {
n@816 916 this.outputGain.gain.value = 1.0;
n@816 917 this.metric.startListening(audioEngineContext.timer.getTestTime());
n@816 918 };
n@816 919
n@816 920 this.loopStop = function() {
n@816 921 if (this.outputGain.gain.value != 0.0) {
n@816 922 this.outputGain.gain.value = 0.0;
n@816 923 this.metric.stopListening(audioEngineContext.timer.getTestTime());
n@816 924 }
n@816 925 };
n@816 926
n@816 927 this.play = function(startTime) {
n@816 928 if (this.bufferNode == undefined) {
n@816 929 this.bufferNode = audioContext.createBufferSource();
n@816 930 this.bufferNode.owner = this;
n@816 931 this.bufferNode.connect(this.outputGain);
n@816 932 this.bufferNode.buffer = this.buffer;
n@816 933 this.bufferNode.loop = audioEngineContext.loopPlayback;
n@816 934 this.bufferNode.onended = function(event) {
n@816 935 // Safari does not like using 'this' to reference the calling object!
n@816 936 event.currentTarget.owner.metric.stopListening(audioEngineContext.timer.getTestTime(),event.currentTarget.owner.getCurrentPosition());
n@816 937 };
n@816 938 if (this.bufferNode.loop == false) {
n@816 939 this.metric.startListening(audioEngineContext.timer.getTestTime());
n@816 940 }
n@816 941 this.bufferNode.start(startTime);
n@816 942 }
n@816 943 };
n@816 944
n@816 945 this.stop = function() {
n@816 946 if (this.bufferNode != undefined)
n@816 947 {
n@816 948 this.metric.stopListening(audioEngineContext.timer.getTestTime(),this.getCurrentPosition());
n@816 949 this.bufferNode.stop(0);
n@816 950 this.bufferNode = undefined;
n@816 951 }
n@816 952 };
n@816 953
n@816 954 this.getCurrentPosition = function() {
n@816 955 var time = audioEngineContext.timer.getTestTime();
n@816 956 if (this.bufferNode != undefined) {
n@816 957 if (this.bufferNode.loop == true) {
n@816 958 if (audioEngineContext.status == 1) {
n@816 959 return time%this.buffer.duration;
n@816 960 } else {
n@816 961 return 0;
n@816 962 }
n@816 963 } else {
n@816 964 if (this.metric.listenHold) {
n@816 965 return time - this.metric.listenStart;
n@816 966 } else {
n@816 967 return 0;
n@816 968 }
n@816 969 }
n@816 970 } else {
n@816 971 return 0;
n@816 972 }
n@816 973 };
n@816 974
n@816 975 this.constructTrack = function(url) {
n@816 976 var request = new XMLHttpRequest();
n@816 977 this.url = url;
n@816 978 request.open('GET',url,true);
n@816 979 request.responseType = 'arraybuffer';
n@816 980
n@816 981 var audioObj = this;
n@816 982
n@816 983 // Create callback to decode the data asynchronously
n@816 984 request.onloadend = function() {
n@816 985 audioContext.decodeAudioData(request.response, function(decodedData) {
n@816 986 audioObj.buffer = decodedData;
n@816 987 audioObj.state = 1;
n@816 988 if (audioObj.specification.type != 'outsidereference')
n@816 989 {audioObj.interfaceDOM.enable();}
n@816 990 }, function(){
n@816 991 // Should only be called if there was an error, but sometimes gets called continuously
n@816 992 // Check here if the error is genuine
n@816 993 if (audioObj.state == 0 || audioObj.buffer == undefined) {
n@816 994 // Genuine error
n@816 995 console.log('FATAL - Error loading buffer on '+audioObj.id);
n@816 996 if (request.status == 404)
n@816 997 {
n@816 998 console.log('FATAL - Fragment '+audioObj.id+' 404 error');
n@816 999 console.log('URL: '+audioObj.url);
n@816 1000 errorSessionDump('Fragment '+audioObj.id+' 404 error');
n@816 1001 }
n@816 1002 }
n@816 1003 });
n@816 1004 };
n@816 1005 request.send();
n@816 1006 };
n@816 1007
n@816 1008 this.exportXMLDOM = function() {
n@816 1009 var root = document.createElement('audioElement');
n@816 1010 root.id = this.specification.id;
n@816 1011 root.setAttribute('url',this.url);
n@816 1012 var file = document.createElement('file');
n@816 1013 file.setAttribute('sampleRate',this.buffer.sampleRate);
n@816 1014 file.setAttribute('channels',this.buffer.numberOfChannels);
n@816 1015 file.setAttribute('sampleCount',this.buffer.length);
n@816 1016 file.setAttribute('duration',this.buffer.duration);
n@816 1017 root.appendChild(file);
n@816 1018 if (this.specification.type != 'outsidereference') {
n@816 1019 root.appendChild(this.interfaceDOM.exportXMLDOM(this));
n@816 1020 root.appendChild(this.commentDOM.exportXMLDOM(this));
n@816 1021 if(this.specification.type == 'anchor') {
n@816 1022 root.setAttribute('anchor',true);
n@816 1023 } else if(this.specification.type == 'reference') {
n@816 1024 root.setAttribute('reference',true);
n@816 1025 }
n@816 1026 }
n@816 1027 root.appendChild(this.metric.exportXMLDOM());
n@816 1028 return root;
n@816 1029 };
n@816 1030 }
n@816 1031
n@816 1032 function timer()
n@816 1033 {
n@816 1034 /* Timer object used in audioEngine to keep track of session timings
n@816 1035 * Uses the timer of the web audio API, so sample resolution
n@816 1036 */
n@816 1037 this.testStarted = false;
n@816 1038 this.testStartTime = 0;
n@816 1039 this.testDuration = 0;
n@816 1040 this.minimumTestTime = 0; // No minimum test time
n@816 1041 this.startTest = function()
n@816 1042 {
n@816 1043 if (this.testStarted == false)
n@816 1044 {
n@816 1045 this.testStartTime = audioContext.currentTime;
n@816 1046 this.testStarted = true;
n@816 1047 this.updateTestTime();
n@816 1048 audioEngineContext.metric.initialiseTest();
n@816 1049 }
n@816 1050 };
n@816 1051 this.stopTest = function()
n@816 1052 {
n@816 1053 if (this.testStarted)
n@816 1054 {
n@816 1055 this.testDuration = this.getTestTime();
n@816 1056 this.testStarted = false;
n@816 1057 } else {
n@816 1058 console.log('ERR: Test tried to end before beginning');
n@816 1059 }
n@816 1060 };
n@816 1061 this.updateTestTime = function()
n@816 1062 {
n@816 1063 if (this.testStarted)
n@816 1064 {
n@816 1065 this.testDuration = audioContext.currentTime - this.testStartTime;
n@816 1066 }
n@816 1067 };
n@816 1068 this.getTestTime = function()
n@816 1069 {
n@816 1070 this.updateTestTime();
n@816 1071 return this.testDuration;
n@816 1072 };
n@816 1073 }
n@816 1074
n@816 1075 function sessionMetrics(engine)
n@816 1076 {
n@816 1077 /* Used by audioEngine to link to audioObjects to minimise the timer call timers;
n@816 1078 */
n@816 1079 this.engine = engine;
n@816 1080 this.lastClicked = -1;
n@816 1081 this.data = -1;
n@816 1082 this.reset = function() {
n@816 1083 this.lastClicked = -1;
n@816 1084 this.data = -1;
n@816 1085 };
n@816 1086 this.initialiseTest = function(){};
n@816 1087 }
n@816 1088
n@816 1089 function metricTracker(caller)
n@816 1090 {
n@816 1091 /* Custom object to track and collect metric data
n@816 1092 * Used only inside the audioObjects object.
n@816 1093 */
n@816 1094
n@816 1095 this.listenedTimer = 0;
n@816 1096 this.listenStart = 0;
n@816 1097 this.listenHold = false;
n@816 1098 this.initialPosition = -1;
n@816 1099 this.movementTracker = [];
n@816 1100 this.listenTracker =[];
n@816 1101 this.wasListenedTo = false;
n@816 1102 this.wasMoved = false;
n@816 1103 this.hasComments = false;
n@816 1104 this.parent = caller;
n@816 1105
n@816 1106 this.initialised = function(position)
n@816 1107 {
n@816 1108 if (this.initialPosition == -1) {
n@816 1109 this.initialPosition = position;
n@816 1110 }
n@816 1111 };
n@816 1112
n@816 1113 this.moved = function(time,position)
n@816 1114 {
n@816 1115 this.wasMoved = true;
n@816 1116 this.movementTracker[this.movementTracker.length] = [time, position];
n@816 1117 };
n@816 1118
n@816 1119 this.startListening = function(time)
n@816 1120 {
n@816 1121 if (this.listenHold == false)
n@816 1122 {
n@816 1123 this.wasListenedTo = true;
n@816 1124 this.listenStart = time;
n@816 1125 this.listenHold = true;
n@816 1126
n@816 1127 var evnt = document.createElement('event');
n@816 1128 var testTime = document.createElement('testTime');
n@816 1129 testTime.setAttribute('start',time);
n@816 1130 var bufferTime = document.createElement('bufferTime');
n@816 1131 bufferTime.setAttribute('start',this.parent.getCurrentPosition());
n@816 1132 evnt.appendChild(testTime);
n@816 1133 evnt.appendChild(bufferTime);
n@816 1134 this.listenTracker.push(evnt);
n@816 1135
n@816 1136 console.log('slider ' + this.parent.id + ' played (' + time + ')'); // DEBUG/SAFETY: show played slider id
n@816 1137 }
n@816 1138 };
n@816 1139
n@816 1140 this.stopListening = function(time,bufferStopTime)
n@816 1141 {
n@816 1142 if (this.listenHold == true)
n@816 1143 {
n@816 1144 var diff = time - this.listenStart;
n@816 1145 this.listenedTimer += (diff);
n@816 1146 this.listenStart = 0;
n@816 1147 this.listenHold = false;
n@816 1148
n@816 1149 var evnt = this.listenTracker[this.listenTracker.length-1];
n@816 1150 var testTime = evnt.getElementsByTagName('testTime')[0];
n@816 1151 var bufferTime = evnt.getElementsByTagName('bufferTime')[0];
n@816 1152 testTime.setAttribute('stop',time);
n@816 1153 if (bufferStopTime == undefined) {
n@816 1154 bufferTime.setAttribute('stop',this.parent.getCurrentPosition());
n@816 1155 } else {
n@816 1156 bufferTime.setAttribute('stop',bufferStopTime);
n@816 1157 }
n@816 1158 console.log('slider ' + this.parent.id + ' played for (' + diff + ')'); // DEBUG/SAFETY: show played slider id
n@816 1159 }
n@816 1160 };
n@816 1161
n@816 1162 this.exportXMLDOM = function() {
n@816 1163 var root = document.createElement('metric');
n@816 1164 if (audioEngineContext.metric.enableElementTimer) {
n@816 1165 var mElementTimer = document.createElement('metricresult');
n@816 1166 mElementTimer.setAttribute('name','enableElementTimer');
n@816 1167 mElementTimer.textContent = this.listenedTimer;
n@816 1168 root.appendChild(mElementTimer);
n@816 1169 }
n@816 1170 if (audioEngineContext.metric.enableElementTracker) {
n@816 1171 var elementTrackerFull = document.createElement('metricResult');
n@816 1172 elementTrackerFull.setAttribute('name','elementTrackerFull');
n@816 1173 for (var k=0; k<this.movementTracker.length; k++)
n@816 1174 {
n@816 1175 var timePos = document.createElement('timePos');
n@816 1176 timePos.id = k;
n@816 1177 var time = document.createElement('time');
n@816 1178 time.textContent = this.movementTracker[k][0];
n@816 1179 var position = document.createElement('position');
n@816 1180 position.textContent = this.movementTracker[k][1];
n@816 1181 timePos.appendChild(time);
n@816 1182 timePos.appendChild(position);
n@816 1183 elementTrackerFull.appendChild(timePos);
n@816 1184 }
n@816 1185 root.appendChild(elementTrackerFull);
n@816 1186 }
n@816 1187 if (audioEngineContext.metric.enableElementListenTracker) {
n@816 1188 var elementListenTracker = document.createElement('metricResult');
n@816 1189 elementListenTracker.setAttribute('name','elementListenTracker');
n@816 1190 for (var k=0; k<this.listenTracker.length; k++) {
n@816 1191 elementListenTracker.appendChild(this.listenTracker[k]);
n@816 1192 }
n@816 1193 root.appendChild(elementListenTracker);
n@816 1194 }
n@816 1195 if (audioEngineContext.metric.enableElementInitialPosition) {
n@816 1196 var elementInitial = document.createElement('metricResult');
n@816 1197 elementInitial.setAttribute('name','elementInitialPosition');
n@816 1198 elementInitial.textContent = this.initialPosition;
n@816 1199 root.appendChild(elementInitial);
n@816 1200 }
n@816 1201 if (audioEngineContext.metric.enableFlagListenedTo) {
n@816 1202 var flagListenedTo = document.createElement('metricResult');
n@816 1203 flagListenedTo.setAttribute('name','elementFlagListenedTo');
n@816 1204 flagListenedTo.textContent = this.wasListenedTo;
n@816 1205 root.appendChild(flagListenedTo);
n@816 1206 }
n@816 1207 if (audioEngineContext.metric.enableFlagMoved) {
n@816 1208 var flagMoved = document.createElement('metricResult');
n@816 1209 flagMoved.setAttribute('name','elementFlagMoved');
n@816 1210 flagMoved.textContent = this.wasMoved;
n@816 1211 root.appendChild(flagMoved);
n@816 1212 }
n@816 1213 if (audioEngineContext.metric.enableFlagComments) {
n@816 1214 var flagComments = document.createElement('metricResult');
n@816 1215 flagComments.setAttribute('name','elementFlagComments');
n@816 1216 if (this.parent.commentDOM == null)
n@816 1217 {flag.textContent = 'false';}
n@816 1218 else if (this.parent.commentDOM.textContent.length == 0)
n@816 1219 {flag.textContent = 'false';}
n@816 1220 else
n@816 1221 {flag.textContet = 'true';}
n@816 1222 root.appendChild(flagComments);
n@816 1223 }
n@816 1224
n@816 1225 return root;
n@816 1226 };
n@816 1227 }
n@816 1228
n@816 1229 function randomiseOrder(input)
n@816 1230 {
n@816 1231 // This takes an array of information and randomises the order
n@816 1232 var N = input.length;
n@816 1233
n@816 1234 var inputSequence = []; // For safety purposes: keep track of randomisation
n@816 1235 for (var counter = 0; counter < N; ++counter)
n@816 1236 inputSequence.push(counter) // Fill array
n@816 1237 var inputSequenceClone = inputSequence.slice(0);
n@816 1238
n@816 1239 var holdArr = [];
n@816 1240 var outputSequence = [];
n@816 1241 for (var n=0; n<N; n++)
n@816 1242 {
n@816 1243 // First pick a random number
n@816 1244 var r = Math.random();
n@816 1245 // Multiply and floor by the number of elements left
n@816 1246 r = Math.floor(r*input.length);
n@816 1247 // Pick out that element and delete from the array
n@816 1248 holdArr.push(input.splice(r,1)[0]);
n@816 1249 // Do the same with sequence
n@816 1250 outputSequence.push(inputSequence.splice(r,1)[0]);
n@816 1251 }
n@816 1252 console.log(inputSequenceClone.toString()); // print original array to console
n@816 1253 console.log(outputSequence.toString()); // print randomised array to console
n@816 1254 return holdArr;
n@816 1255 }
n@816 1256
n@816 1257 function returnDateNode()
n@816 1258 {
n@816 1259 // Create an XML Node for the Date and Time a test was conducted
n@816 1260 // Structure is
n@816 1261 // <datetime>
n@816 1262 // <date year="##" month="##" day="##">DD/MM/YY</date>
n@816 1263 // <time hour="##" minute="##" sec="##">HH:MM:SS</time>
n@816 1264 // </datetime>
n@816 1265 var dateTime = new Date();
n@816 1266 var year = document.createAttribute('year');
n@816 1267 var month = document.createAttribute('month');
n@816 1268 var day = document.createAttribute('day');
n@816 1269 var hour = document.createAttribute('hour');
n@816 1270 var minute = document.createAttribute('minute');
n@816 1271 var secs = document.createAttribute('secs');
n@816 1272
n@816 1273 year.nodeValue = dateTime.getFullYear();
n@816 1274 month.nodeValue = dateTime.getMonth()+1;
n@816 1275 day.nodeValue = dateTime.getDate();
n@816 1276 hour.nodeValue = dateTime.getHours();
n@816 1277 minute.nodeValue = dateTime.getMinutes();
n@816 1278 secs.nodeValue = dateTime.getSeconds();
n@816 1279
n@816 1280 var hold = document.createElement("datetime");
n@816 1281 var date = document.createElement("date");
n@816 1282 date.textContent = year.nodeValue+'/'+month.nodeValue+'/'+day.nodeValue;
n@816 1283 var time = document.createElement("time");
n@816 1284 time.textContent = hour.nodeValue+':'+minute.nodeValue+':'+secs.nodeValue;
n@816 1285
n@816 1286 date.setAttributeNode(year);
n@816 1287 date.setAttributeNode(month);
n@816 1288 date.setAttributeNode(day);
n@816 1289 time.setAttributeNode(hour);
n@816 1290 time.setAttributeNode(minute);
n@816 1291 time.setAttributeNode(secs);
n@816 1292
n@816 1293 hold.appendChild(date);
n@816 1294 hold.appendChild(time);
n@816 1295 return hold
n@816 1296
n@816 1297 }
n@816 1298
n@816 1299 function Specification() {
n@816 1300 // Handles the decoding of the project specification XML into a simple JavaScript Object.
n@816 1301
n@816 1302 this.interfaceType = null;
n@816 1303 this.commonInterface = null;
n@816 1304 this.projectReturn = null;
n@816 1305 this.randomiseOrder = null;
n@816 1306 this.collectMetrics = null;
n@816 1307 this.testPages = null;
n@816 1308 this.preTest = null;
n@816 1309 this.postTest = null;
n@816 1310 this.metrics =[];
n@816 1311
n@816 1312 this.audioHolders = [];
n@816 1313
n@816 1314 this.decode = function() {
n@816 1315 // projectXML - DOM Parsed document
n@816 1316 this.projectXML = projectXML.childNodes[0];
n@816 1317 var setupNode = projectXML.getElementsByTagName('setup')[0];
n@816 1318 this.interfaceType = setupNode.getAttribute('interface');
n@816 1319 this.projectReturn = setupNode.getAttribute('projectReturn');
n@816 1320 this.testPages = setupNode.getAttribute('testPages');
n@816 1321 if (setupNode.getAttribute('randomiseOrder') == "true") {
n@816 1322 this.randomiseOrder = true;
n@816 1323 } else {this.randomiseOrder = false;}
n@816 1324 if (setupNode.getAttribute('collectMetrics') == "true") {
n@816 1325 this.collectMetrics = true;
n@816 1326 } else {this.collectMetrics = false;}
n@816 1327 if (isNaN(Number(this.testPages)) || this.testPages == undefined)
n@816 1328 {
n@816 1329 this.testPages = null;
n@816 1330 } else {
n@816 1331 this.testPages = Number(this.testPages);
n@816 1332 if (this.testPages == 0) {this.testPages = null;}
n@816 1333 }
n@816 1334 var metricCollection = setupNode.getElementsByTagName('Metric');
n@816 1335
n@816 1336 this.preTest = new this.prepostNode('pretest',setupNode.getElementsByTagName('PreTest'));
n@816 1337 this.postTest = new this.prepostNode('posttest',setupNode.getElementsByTagName('PostTest'));
n@816 1338
n@816 1339 if (metricCollection.length > 0) {
n@816 1340 metricCollection = metricCollection[0].getElementsByTagName('metricEnable');
n@816 1341 for (var i=0; i<metricCollection.length; i++) {
n@816 1342 this.metrics.push(new this.metricNode(metricCollection[i].textContent));
n@816 1343 }
n@816 1344 }
n@816 1345
n@816 1346 var commonInterfaceNode = setupNode.getElementsByTagName('interface');
n@816 1347 if (commonInterfaceNode.length > 0) {
n@816 1348 commonInterfaceNode = commonInterfaceNode[0];
n@816 1349 } else {
n@816 1350 commonInterfaceNode = undefined;
n@816 1351 }
n@816 1352
n@816 1353 this.commonInterface = new function() {
n@816 1354 this.OptionNode = function(child) {
n@816 1355 this.type = child.nodeName;
n@816 1356 if (this.type == 'option')
n@816 1357 {
n@816 1358 this.name = child.getAttribute('name');
n@816 1359 }
n@816 1360 else if (this.type == 'check') {
n@816 1361 this.check = child.getAttribute('name');
n@816 1362 if (this.check == 'scalerange') {
n@816 1363 this.min = child.getAttribute('min');
n@816 1364 this.max = child.getAttribute('max');
n@816 1365 if (this.min == null) {this.min = 1;}
n@816 1366 else if (Number(this.min) > 1 && this.min != null) {
n@816 1367 this.min = Number(this.min)/100;
n@816 1368 } else {
n@816 1369 this.min = Number(this.min);
n@816 1370 }
n@816 1371 if (this.max == null) {this.max = 0;}
n@816 1372 else if (Number(this.max) > 1 && this.max != null) {
n@816 1373 this.max = Number(this.max)/100;
n@816 1374 } else {
n@816 1375 this.max = Number(this.max);
n@816 1376 }
n@816 1377 }
n@816 1378 } else if (this.type == 'anchor' || this.type == 'reference') {
n@816 1379 this.value = Number(child.textContent);
n@816 1380 this.enforce = child.getAttribute('enforce');
n@816 1381 if (this.enforce == 'true') {this.enforce = true;}
n@816 1382 else {this.enforce = false;}
n@816 1383 }
n@816 1384 };
n@816 1385 this.options = [];
n@816 1386 if (commonInterfaceNode != undefined) {
n@816 1387 var child = commonInterfaceNode.firstElementChild;
n@816 1388 while (child != undefined) {
n@816 1389 this.options.push(new this.OptionNode(child));
n@816 1390 child = child.nextElementSibling;
n@816 1391 }
n@816 1392 }
n@816 1393 };
n@816 1394
n@816 1395 var audioHolders = projectXML.getElementsByTagName('audioHolder');
n@816 1396 for (var i=0; i<audioHolders.length; i++) {
n@816 1397 this.audioHolders.push(new this.audioHolderNode(this,audioHolders[i]));
n@816 1398 }
n@816 1399
n@816 1400 // New check if we need to randomise the test order
n@816 1401 if (this.randomiseOrder)
n@816 1402 {
n@816 1403 this.audioHolders = randomiseOrder(this.audioHolders);
n@816 1404 for (var i=0; i<this.audioHolders.length; i++)
n@816 1405 {
n@816 1406 this.audioHolders[i].presentedId = i;
n@816 1407 }
n@816 1408 }
n@816 1409
n@816 1410 if (this.testPages != null || this.testPages != undefined)
n@816 1411 {
n@816 1412 if (this.testPages > audioHolders.length)
n@816 1413 {
n@816 1414 console.log('Warning: You have specified '+audioHolders.length+' tests but requested '+this.testPages+' be completed!');
n@816 1415 this.testPages = audioHolders.length;
n@816 1416 }
n@816 1417 var aH = this.audioHolders;
n@816 1418 this.audioHolders = [];
n@816 1419 for (var i=0; i<this.testPages; i++)
n@816 1420 {
n@816 1421 this.audioHolders.push(aH[i]);
n@816 1422 }
n@816 1423 }
n@816 1424 };
n@816 1425
n@816 1426 this.prepostNode = function(type,Collection) {
n@816 1427 this.type = type;
n@816 1428 this.options = [];
n@816 1429
n@816 1430 this.OptionNode = function(child) {
n@816 1431
n@816 1432 this.childOption = function(element) {
n@816 1433 this.type = 'option';
n@816 1434 this.id = element.id;
n@816 1435 this.name = element.getAttribute('name');
n@816 1436 this.text = element.textContent;
n@816 1437 };
n@816 1438
n@816 1439 this.type = child.nodeName;
n@816 1440 if (child.nodeName == "question") {
n@816 1441 this.id = child.id;
n@816 1442 this.mandatory;
n@816 1443 if (child.getAttribute('mandatory') == "true") {this.mandatory = true;}
n@816 1444 else {this.mandatory = false;}
n@816 1445 this.question = child.textContent;
n@816 1446 if (child.getAttribute('boxsize') == null) {
n@816 1447 this.boxsize = 'normal';
n@816 1448 } else {
n@816 1449 this.boxsize = child.getAttribute('boxsize');
n@816 1450 }
n@816 1451 } else if (child.nodeName == "statement") {
n@816 1452 this.statement = child.textContent;
n@816 1453 } else if (child.nodeName == "checkbox" || child.nodeName == "radio") {
n@816 1454 var element = child.firstElementChild;
n@816 1455 this.id = child.id;
n@816 1456 if (element == null) {
n@816 1457 console.log('Malformed' +child.nodeName+ 'entry');
n@816 1458 this.statement = 'Malformed' +child.nodeName+ 'entry';
n@816 1459 this.type = 'statement';
n@816 1460 } else {
n@816 1461 this.options = [];
n@816 1462 while (element != null) {
n@816 1463 if (element.nodeName == 'statement' && this.statement == undefined){
n@816 1464 this.statement = element.textContent;
n@816 1465 } else if (element.nodeName == 'option') {
n@816 1466 this.options.push(new this.childOption(element));
n@816 1467 }
n@816 1468 element = element.nextElementSibling;
n@816 1469 }
n@816 1470 }
n@816 1471 } else if (child.nodeName == "number") {
n@816 1472 this.statement = child.textContent;
n@816 1473 this.id = child.id;
n@816 1474 this.min = child.getAttribute('min');
n@816 1475 this.max = child.getAttribute('max');
n@816 1476 this.step = child.getAttribute('step');
n@816 1477 }
n@816 1478 };
n@816 1479
n@816 1480 // On construction:
n@816 1481 if (Collection.length != 0) {
n@816 1482 Collection = Collection[0];
n@816 1483 if (Collection.childElementCount != 0) {
n@816 1484 var child = Collection.firstElementChild;
n@816 1485 this.options.push(new this.OptionNode(child));
n@816 1486 while (child.nextElementSibling != null) {
n@816 1487 child = child.nextElementSibling;
n@816 1488 this.options.push(new this.OptionNode(child));
n@816 1489 }
n@816 1490 }
n@816 1491 }
n@816 1492 };
n@816 1493
n@816 1494 this.metricNode = function(name) {
n@816 1495 this.enabled = name;
n@816 1496 };
n@816 1497
n@816 1498 this.audioHolderNode = function(parent,xml) {
n@816 1499 this.type = 'audioHolder';
n@816 1500 this.presentedId = parent.audioHolders.length;
n@816 1501 this.interfaceNode = function(DOM) {
n@816 1502 var title = DOM.getElementsByTagName('title');
n@816 1503 if (title.length == 0) {this.title = null;}
n@816 1504 else {this.title = title[0].textContent;}
n@816 1505 this.options = parent.commonInterface.options;
n@816 1506 var scale = DOM.getElementsByTagName('scale');
n@816 1507 this.scale = [];
n@816 1508 for (var i=0; i<scale.length; i++) {
n@816 1509 var arr = [null, null];
n@816 1510 arr[0] = scale[i].getAttribute('position');
n@816 1511 arr[1] = scale[i].textContent;
n@816 1512 this.scale.push(arr);
n@816 1513 }
n@816 1514 };
n@816 1515
n@816 1516 this.audioElementNode = function(parent,xml) {
n@816 1517 this.url = xml.getAttribute('url');
n@816 1518 this.id = xml.id;
n@816 1519 this.parent = parent;
n@816 1520 this.type = xml.getAttribute('type');
n@816 1521 if (this.type == null) {this.type = "normal";}
n@816 1522 if (this.type == 'anchor') {this.anchor = true;}
n@816 1523 else {this.anchor = false;}
n@816 1524 if (this.type == 'reference') {this.reference = true;}
n@816 1525 else {this.reference = false;}
n@816 1526
n@816 1527 this.marker = xml.getAttribute('marker');
n@816 1528 if (this.marker == null) {this.marker = undefined;}
n@816 1529
n@816 1530 if (this.anchor == true) {
n@816 1531 if (this.marker != undefined) {this.enforce = true;}
n@816 1532 else {this.enforce = enforceAnchor;}
n@816 1533 this.marker = anchor;
n@816 1534 }
n@816 1535 else if (this.reference == true) {
n@816 1536 if (this.marker != undefined) {this.enforce = true;}
n@816 1537 else {this.enforce = enforceReference;}
n@816 1538 this.marker = reference;
n@816 1539 }
n@816 1540
n@816 1541 if (this.marker != undefined) {
n@816 1542 this.marker = Number(this.marker);
n@816 1543 if (this.marker > 1) {this.marker /= 100;}
n@816 1544 }
n@816 1545 };
n@816 1546
n@816 1547 this.commentQuestionNode = function(xml) {
n@816 1548 this.childOption = function(element) {
n@816 1549 this.type = 'option';
n@816 1550 this.name = element.getAttribute('name');
n@816 1551 this.text = element.textContent;
n@816 1552 };
n@816 1553 this.id = xml.id;
n@816 1554 if (xml.getAttribute('mandatory') == 'true') {this.mandatory = true;}
n@816 1555 else {this.mandatory = false;}
n@816 1556 this.type = xml.getAttribute('type');
n@816 1557 if (this.type == undefined) {this.type = 'text';}
n@816 1558 switch (this.type) {
n@816 1559 case 'text':
n@816 1560 this.question = xml.textContent;
n@816 1561 break;
n@816 1562 case 'radio':
n@816 1563 var child = xml.firstElementChild;
n@816 1564 this.options = [];
n@816 1565 while (child != undefined) {
n@816 1566 if (child.nodeName == 'statement' && this.statement == undefined) {
n@816 1567 this.statement = child.textContent;
n@816 1568 } else if (child.nodeName == 'option') {
n@816 1569 this.options.push(new this.childOption(child));
n@816 1570 }
n@816 1571 child = child.nextElementSibling;
n@816 1572 }
n@816 1573 break;
n@816 1574 case 'checkbox':
n@816 1575 var child = xml.firstElementChild;
n@816 1576 this.options = [];
n@816 1577 while (child != undefined) {
n@816 1578 if (child.nodeName == 'statement' && this.statement == undefined) {
n@816 1579 this.statement = child.textContent;
n@816 1580 } else if (child.nodeName == 'option') {
n@816 1581 this.options.push(new this.childOption(child));
n@816 1582 }
n@816 1583 child = child.nextElementSibling;
n@816 1584 }
n@816 1585 break;
n@816 1586 }
n@816 1587 };
n@816 1588
n@816 1589 this.id = xml.id;
n@816 1590 this.hostURL = xml.getAttribute('hostURL');
n@816 1591 this.sampleRate = xml.getAttribute('sampleRate');
n@816 1592 if (xml.getAttribute('randomiseOrder') == "true") {this.randomiseOrder = true;}
n@816 1593 else {this.randomiseOrder = false;}
n@816 1594 this.repeatCount = xml.getAttribute('repeatCount');
n@816 1595 if (xml.getAttribute('loop') == 'true') {this.loop = true;}
n@816 1596 else {this.loop == false;}
n@816 1597 if (xml.getAttribute('elementComments') == "true") {this.elementComments = true;}
n@816 1598 else {this.elementComments = false;}
n@816 1599
n@816 1600 var anchor = xml.getElementsByTagName('anchor');
n@816 1601 var enforceAnchor = false;
n@816 1602 if (anchor.length == 0) {
n@816 1603 // Find anchor in commonInterface;
n@816 1604 for (var i=0; i<parent.commonInterface.options.length; i++) {
n@816 1605 if(parent.commonInterface.options[i].type == 'anchor') {
n@816 1606 anchor = parent.commonInterface.options[i].value;
n@816 1607 enforceAnchor = parent.commonInterface.options[i].enforce;
n@816 1608 break;
n@816 1609 }
n@816 1610 }
n@816 1611 if (typeof(anchor) == "object") {
n@816 1612 anchor = null;
n@816 1613 }
n@816 1614 } else {
n@816 1615 anchor = anchor[0].textContent;
n@816 1616 }
n@816 1617
n@816 1618 var reference = xml.getElementsByTagName('anchor');
n@816 1619 var enforceReference = false;
n@816 1620 if (reference.length == 0) {
n@816 1621 // Find anchor in commonInterface;
n@816 1622 for (var i=0; i<parent.commonInterface.options.length; i++) {
n@816 1623 if(parent.commonInterface.options[i].type == 'reference') {
n@816 1624 reference = parent.commonInterface.options[i].value;
n@816 1625 enforceReference = parent.commonInterface.options[i].enforce;
n@816 1626 break;
n@816 1627 }
n@816 1628 }
n@816 1629 if (typeof(reference) == "object") {
n@816 1630 reference = null;
n@816 1631 }
n@816 1632 } else {
n@816 1633 reference = reference[0].textContent;
n@816 1634 }
n@816 1635
n@816 1636 if (typeof(anchor) == 'number') {
n@816 1637 if (anchor > 1 && anchor < 100) {anchor /= 100.0;}
n@816 1638 }
n@816 1639
n@816 1640 if (typeof(reference) == 'number') {
n@816 1641 if (reference > 1 && reference < 100) {reference /= 100.0;}
n@816 1642 }
n@816 1643
n@816 1644 this.preTest = new parent.prepostNode('pretest',xml.getElementsByTagName('PreTest'));
n@816 1645 this.postTest = new parent.prepostNode('posttest',xml.getElementsByTagName('PostTest'));
n@816 1646
n@816 1647 this.interfaces = [];
n@816 1648 var interfaceDOM = xml.getElementsByTagName('interface');
n@816 1649 for (var i=0; i<interfaceDOM.length; i++) {
n@816 1650 this.interfaces.push(new this.interfaceNode(interfaceDOM[i]));
n@816 1651 }
n@816 1652
n@816 1653 this.commentBoxPrefix = xml.getElementsByTagName('commentBoxPrefix');
n@816 1654 if (this.commentBoxPrefix.length != 0) {
n@816 1655 this.commentBoxPrefix = this.commentBoxPrefix[0].textContent;
n@816 1656 } else {
n@816 1657 this.commentBoxPrefix = "Comment on track";
n@816 1658 }
n@816 1659
n@816 1660 this.audioElements =[];
n@816 1661 var audioElementsDOM = xml.getElementsByTagName('audioElements');
n@816 1662 this.outsideReference = null;
n@816 1663 for (var i=0; i<audioElementsDOM.length; i++) {
n@816 1664 if (audioElementsDOM[i].getAttribute('type') == 'outsidereference') {
n@816 1665 if (this.outsideReference == null) {
n@816 1666 this.outsideReference = new this.audioElementNode(this,audioElementsDOM[i]);
n@816 1667 } else {
n@816 1668 console.log('Error only one audioelement can be of type outsidereference per audioholder');
n@816 1669 this.audioElements.push(new this.audioElementNode(this,audioElementsDOM[i]));
n@816 1670 console.log('Element id '+audioElementsDOM[i].id+' made into normal node');
n@816 1671 }
n@816 1672 } else {
n@816 1673 this.audioElements.push(new this.audioElementNode(this,audioElementsDOM[i]));
n@816 1674 }
n@816 1675 }
n@816 1676
n@816 1677 if (this.randomiseOrder) {
n@816 1678 this.audioElements = randomiseOrder(this.audioElements);
n@816 1679 }
n@816 1680
n@816 1681 // Check only one anchor and one reference per audioNode
n@816 1682 var anchor = [];
n@816 1683 var reference = [];
n@816 1684 this.anchorId = null;
n@816 1685 this.referenceId = null;
n@816 1686 for (var i=0; i<this.audioElements.length; i++)
n@816 1687 {
n@816 1688 if (this.audioElements[i].anchor == true) {anchor.push(i);}
n@816 1689 if (this.audioElements[i].reference == true) {reference.push(i);}
n@816 1690 }
n@816 1691
n@816 1692 if (anchor.length > 1) {
n@816 1693 console.log('Error - cannot have more than one anchor!');
n@816 1694 console.log('Each anchor node will be a normal mode to continue the test');
n@816 1695 for (var i=0; i<anchor.length; i++)
n@816 1696 {
n@816 1697 this.audioElements[anchor[i]].anchor = false;
n@816 1698 this.audioElements[anchor[i]].value = undefined;
n@816 1699 }
n@816 1700 } else {this.anchorId = anchor[0];}
n@816 1701 if (reference.length > 1) {
n@816 1702 console.log('Error - cannot have more than one anchor!');
n@816 1703 console.log('Each anchor node will be a normal mode to continue the test');
n@816 1704 for (var i=0; i<reference.length; i++)
n@816 1705 {
n@816 1706 this.audioElements[reference[i]].reference = false;
n@816 1707 this.audioElements[reference[i]].value = undefined;
n@816 1708 }
n@816 1709 } else {this.referenceId = reference[0];}
n@816 1710
n@816 1711 this.commentQuestions = [];
n@816 1712 var commentQuestionsDOM = xml.getElementsByTagName('CommentQuestion');
n@816 1713 for (var i=0; i<commentQuestionsDOM.length; i++) {
n@816 1714 this.commentQuestions.push(new this.commentQuestionNode(commentQuestionsDOM[i]));
n@816 1715 }
n@816 1716 };
n@816 1717 }
n@816 1718
n@816 1719 function Interface(specificationObject) {
n@816 1720 // This handles the bindings between the interface and the audioEngineContext;
n@816 1721 this.specification = specificationObject;
n@816 1722 this.insertPoint = document.getElementById("topLevelBody");
n@816 1723
n@816 1724 // Bounded by interface!!
n@816 1725 // Interface object MUST have an exportXMLDOM method which returns the various DOM levels
n@816 1726 // For example, APE returns the slider position normalised in a <value> tag.
n@816 1727 this.interfaceObjects = [];
n@816 1728 this.interfaceObject = function(){};
n@816 1729
n@816 1730 this.resizeWindow = function(event)
n@816 1731 {
n@816 1732 for(var i=0; i<this.commentBoxes.length; i++)
n@816 1733 {this.commentBoxes[i].resize();}
n@816 1734 for(var i=0; i<this.commentQuestions.length; i++)
n@816 1735 {this.commentQuestions[i].resize();}
n@816 1736 try
n@816 1737 {
n@816 1738 resizeWindow(event);
n@816 1739 }
n@816 1740 catch(err)
n@816 1741 {
n@816 1742 console.log("Warning - Interface does not have Resize option");
n@816 1743 console.log(err);
n@816 1744 }
n@816 1745 };
n@816 1746
n@816 1747 this.commentBoxes = [];
n@816 1748 this.elementCommentBox = function(audioObject) {
n@816 1749 var element = audioObject.specification;
n@816 1750 this.audioObject = audioObject;
n@816 1751 this.id = audioObject.id;
n@816 1752 var audioHolderObject = audioObject.specification.parent;
n@816 1753 // Create document objects to hold the comment boxes
n@816 1754 this.trackComment = document.createElement('div');
n@816 1755 this.trackComment.className = 'comment-div';
n@816 1756 this.trackComment.id = 'comment-div-'+audioObject.id;
n@816 1757 // Create a string next to each comment asking for a comment
n@816 1758 this.trackString = document.createElement('span');
n@816 1759 this.trackString.innerHTML = audioHolderObject.commentBoxPrefix+' '+audioObject.id;
n@816 1760 // Create the HTML5 comment box 'textarea'
n@816 1761 this.trackCommentBox = document.createElement('textarea');
n@816 1762 this.trackCommentBox.rows = '4';
n@816 1763 this.trackCommentBox.cols = '100';
n@816 1764 this.trackCommentBox.name = 'trackComment'+audioObject.id;
n@816 1765 this.trackCommentBox.className = 'trackComment';
n@816 1766 var br = document.createElement('br');
n@816 1767 // Add to the holder.
n@816 1768 this.trackComment.appendChild(this.trackString);
n@816 1769 this.trackComment.appendChild(br);
n@816 1770 this.trackComment.appendChild(this.trackCommentBox);
n@816 1771
n@816 1772 this.exportXMLDOM = function() {
n@816 1773 var root = document.createElement('comment');
n@816 1774 if (this.audioObject.specification.parent.elementComments) {
n@816 1775 var question = document.createElement('question');
n@816 1776 question.textContent = this.trackString.textContent;
n@816 1777 var response = document.createElement('response');
n@816 1778 response.textContent = this.trackCommentBox.value;
n@816 1779 console.log("Comment frag-"+this.id+": "+response.textContent);
n@816 1780 root.appendChild(question);
n@816 1781 root.appendChild(response);
n@816 1782 }
n@816 1783 return root;
n@816 1784 };
n@816 1785 this.resize = function()
n@816 1786 {
n@816 1787 var boxwidth = (window.innerWidth-100)/2;
n@816 1788 if (boxwidth >= 600)
n@816 1789 {
n@816 1790 boxwidth = 600;
n@816 1791 }
n@816 1792 else if (boxwidth < 400)
n@816 1793 {
n@816 1794 boxwidth = 400;
n@816 1795 }
n@816 1796 this.trackComment.style.width = boxwidth+"px";
n@816 1797 this.trackCommentBox.style.width = boxwidth-6+"px";
n@816 1798 };
n@816 1799 this.resize();
n@816 1800 };
n@816 1801
n@816 1802 this.commentQuestions = [];
n@816 1803
n@816 1804 this.commentBox = function(commentQuestion) {
n@816 1805 this.specification = commentQuestion;
n@816 1806 // Create document objects to hold the comment boxes
n@816 1807 this.holder = document.createElement('div');
n@816 1808 this.holder.className = 'comment-div';
n@816 1809 // Create a string next to each comment asking for a comment
n@816 1810 this.string = document.createElement('span');
n@816 1811 this.string.innerHTML = commentQuestion.question;
n@816 1812 // Create the HTML5 comment box 'textarea'
n@816 1813 this.textArea = document.createElement('textarea');
n@816 1814 this.textArea.rows = '4';
n@816 1815 this.textArea.cols = '100';
n@816 1816 this.textArea.className = 'trackComment';
n@816 1817 var br = document.createElement('br');
n@816 1818 // Add to the holder.
n@816 1819 this.holder.appendChild(this.string);
n@816 1820 this.holder.appendChild(br);
n@816 1821 this.holder.appendChild(this.textArea);
n@816 1822
n@816 1823 this.exportXMLDOM = function() {
n@816 1824 var root = document.createElement('comment');
n@816 1825 root.id = this.specification.id;
n@816 1826 root.setAttribute('type',this.specification.type);
n@816 1827 root.textContent = this.textArea.value;
n@816 1828 console.log("Question: "+this.string.textContent);
n@816 1829 console.log("Response: "+root.textContent);
n@816 1830 return root;
n@816 1831 };
n@816 1832 this.resize = function()
n@816 1833 {
n@816 1834 var boxwidth = (window.innerWidth-100)/2;
n@816 1835 if (boxwidth >= 600)
n@816 1836 {
n@816 1837 boxwidth = 600;
n@816 1838 }
n@816 1839 else if (boxwidth < 400)
n@816 1840 {
n@816 1841 boxwidth = 400;
n@816 1842 }
n@816 1843 this.holder.style.width = boxwidth+"px";
n@816 1844 this.textArea.style.width = boxwidth-6+"px";
n@816 1845 };
n@816 1846 this.resize();
n@816 1847 };
n@816 1848
n@816 1849 this.radioBox = function(commentQuestion) {
n@816 1850 this.specification = commentQuestion;
n@816 1851 // Create document objects to hold the comment boxes
n@816 1852 this.holder = document.createElement('div');
n@816 1853 this.holder.className = 'comment-div';
n@816 1854 // Create a string next to each comment asking for a comment
n@816 1855 this.string = document.createElement('span');
n@816 1856 this.string.innerHTML = commentQuestion.statement;
n@816 1857 var br = document.createElement('br');
n@816 1858 // Add to the holder.
n@816 1859 this.holder.appendChild(this.string);
n@816 1860 this.holder.appendChild(br);
n@816 1861 this.options = [];
n@816 1862 this.inputs = document.createElement('div');
n@816 1863 this.span = document.createElement('div');
n@816 1864 this.inputs.align = 'center';
n@816 1865 this.inputs.style.marginLeft = '12px';
n@816 1866 this.span.style.marginLeft = '12px';
n@816 1867 this.span.align = 'center';
n@816 1868 this.span.style.marginTop = '15px';
n@816 1869
n@816 1870 var optCount = commentQuestion.options.length;
n@816 1871 for (var i=0; i<optCount; i++)
n@816 1872 {
n@816 1873 var div = document.createElement('div');
n@816 1874 div.style.width = '80px';
n@816 1875 div.style.float = 'left';
n@816 1876 var input = document.createElement('input');
n@816 1877 input.type = 'radio';
n@816 1878 input.name = commentQuestion.id;
n@816 1879 input.setAttribute('setvalue',commentQuestion.options[i].name);
n@816 1880 input.className = 'comment-radio';
n@816 1881 div.appendChild(input);
n@816 1882 this.inputs.appendChild(div);
n@816 1883
n@816 1884
n@816 1885 div = document.createElement('div');
n@816 1886 div.style.width = '80px';
n@816 1887 div.style.float = 'left';
n@816 1888 div.align = 'center';
n@816 1889 var span = document.createElement('span');
n@816 1890 span.textContent = commentQuestion.options[i].text;
n@816 1891 span.className = 'comment-radio-span';
n@816 1892 div.appendChild(span);
n@816 1893 this.span.appendChild(div);
n@816 1894 this.options.push(input);
n@816 1895 }
n@816 1896 this.holder.appendChild(this.span);
n@816 1897 this.holder.appendChild(this.inputs);
n@816 1898
n@816 1899 this.exportXMLDOM = function() {
n@816 1900 var root = document.createElement('comment');
n@816 1901 root.id = this.specification.id;
n@816 1902 root.setAttribute('type',this.specification.type);
n@816 1903 var question = document.createElement('question');
n@816 1904 question.textContent = this.string.textContent;
n@816 1905 var response = document.createElement('response');
n@816 1906 var i=0;
n@816 1907 while(this.options[i].checked == false) {
n@816 1908 i++;
n@816 1909 if (i >= this.options.length) {
n@816 1910 break;
n@816 1911 }
n@816 1912 }
n@816 1913 if (i >= this.options.length) {
n@816 1914 response.textContent = 'null';
n@816 1915 } else {
n@816 1916 response.textContent = this.options[i].getAttribute('setvalue');
n@816 1917 response.setAttribute('number',i);
n@816 1918 }
n@816 1919 console.log('Comment: '+question.textContent);
n@816 1920 console.log('Response: '+response.textContent);
n@816 1921 root.appendChild(question);
n@816 1922 root.appendChild(response);
n@816 1923 return root;
n@816 1924 };
n@816 1925 this.resize = function()
n@816 1926 {
n@816 1927 var boxwidth = (window.innerWidth-100)/2;
n@816 1928 if (boxwidth >= 600)
n@816 1929 {
n@816 1930 boxwidth = 600;
n@816 1931 }
n@816 1932 else if (boxwidth < 400)
n@816 1933 {
n@816 1934 boxwidth = 400;
n@816 1935 }
n@816 1936 this.holder.style.width = boxwidth+"px";
n@816 1937 var text = this.holder.children[2];
n@816 1938 var options = this.holder.children[3];
n@816 1939 var optCount = options.children.length;
n@816 1940 var spanMargin = Math.floor(((boxwidth-20-(optCount*80))/(optCount))/2)+'px';
n@816 1941 var options = options.firstChild;
n@816 1942 var text = text.firstChild;
n@816 1943 options.style.marginRight = spanMargin;
n@816 1944 options.style.marginLeft = spanMargin;
n@816 1945 text.style.marginRight = spanMargin;
n@816 1946 text.style.marginLeft = spanMargin;
n@816 1947 while(options.nextSibling != undefined)
n@816 1948 {
n@816 1949 options = options.nextSibling;
n@816 1950 text = text.nextSibling;
n@816 1951 options.style.marginRight = spanMargin;
n@816 1952 options.style.marginLeft = spanMargin;
n@816 1953 text.style.marginRight = spanMargin;
n@816 1954 text.style.marginLeft = spanMargin;
n@816 1955 }
n@816 1956 };
n@816 1957 this.resize();
n@816 1958 };
n@816 1959
n@816 1960 this.checkboxBox = function(commentQuestion) {
n@816 1961 this.specification = commentQuestion;
n@816 1962 // Create document objects to hold the comment boxes
n@816 1963 this.holder = document.createElement('div');
n@816 1964 this.holder.className = 'comment-div';
n@816 1965 // Create a string next to each comment asking for a comment
n@816 1966 this.string = document.createElement('span');
n@816 1967 this.string.innerHTML = commentQuestion.statement;
n@816 1968 var br = document.createElement('br');
n@816 1969 // Add to the holder.
n@816 1970 this.holder.appendChild(this.string);
n@816 1971 this.holder.appendChild(br);
n@816 1972 this.options = [];
n@816 1973 this.inputs = document.createElement('div');
n@816 1974 this.span = document.createElement('div');
n@816 1975 this.inputs.align = 'center';
n@816 1976 this.inputs.style.marginLeft = '12px';
n@816 1977 this.span.style.marginLeft = '12px';
n@816 1978 this.span.align = 'center';
n@816 1979 this.span.style.marginTop = '15px';
n@816 1980
n@816 1981 var optCount = commentQuestion.options.length;
n@816 1982 for (var i=0; i<optCount; i++)
n@816 1983 {
n@816 1984 var div = document.createElement('div');
n@816 1985 div.style.width = '80px';
n@816 1986 div.style.float = 'left';
n@816 1987 var input = document.createElement('input');
n@816 1988 input.type = 'checkbox';
n@816 1989 input.name = commentQuestion.id;
n@816 1990 input.setAttribute('setvalue',commentQuestion.options[i].name);
n@816 1991 input.className = 'comment-radio';
n@816 1992 div.appendChild(input);
n@816 1993 this.inputs.appendChild(div);
n@816 1994
n@816 1995
n@816 1996 div = document.createElement('div');
n@816 1997 div.style.width = '80px';
n@816 1998 div.style.float = 'left';
n@816 1999 div.align = 'center';
n@816 2000 var span = document.createElement('span');
n@816 2001 span.textContent = commentQuestion.options[i].text;
n@816 2002 span.className = 'comment-radio-span';
n@816 2003 div.appendChild(span);
n@816 2004 this.span.appendChild(div);
n@816 2005 this.options.push(input);
n@816 2006 }
n@816 2007 this.holder.appendChild(this.span);
n@816 2008 this.holder.appendChild(this.inputs);
n@816 2009
n@816 2010 this.exportXMLDOM = function() {
n@816 2011 var root = document.createElement('comment');
n@816 2012 root.id = this.specification.id;
n@816 2013 root.setAttribute('type',this.specification.type);
n@816 2014 var question = document.createElement('question');
n@816 2015 question.textContent = this.string.textContent;
n@816 2016 root.appendChild(question);
n@816 2017 console.log('Comment: '+question.textContent);
n@816 2018 for (var i=0; i<this.options.length; i++) {
n@816 2019 var response = document.createElement('response');
n@816 2020 response.textContent = this.options[i].checked;
n@816 2021 response.setAttribute('name',this.options[i].getAttribute('setvalue'));
n@816 2022 root.appendChild(response);
n@816 2023 console.log('Response '+response.getAttribute('name') +': '+response.textContent);
n@816 2024 }
n@816 2025 return root;
n@816 2026 };
n@816 2027 this.resize = function()
n@816 2028 {
n@816 2029 var boxwidth = (window.innerWidth-100)/2;
n@816 2030 if (boxwidth >= 600)
n@816 2031 {
n@816 2032 boxwidth = 600;
n@816 2033 }
n@816 2034 else if (boxwidth < 400)
n@816 2035 {
n@816 2036 boxwidth = 400;
n@816 2037 }
n@816 2038 this.holder.style.width = boxwidth+"px";
n@816 2039 var text = this.holder.children[2];
n@816 2040 var options = this.holder.children[3];
n@816 2041 var optCount = options.children.length;
n@816 2042 var spanMargin = Math.floor(((boxwidth-20-(optCount*80))/(optCount))/2)+'px';
n@816 2043 var options = options.firstChild;
n@816 2044 var text = text.firstChild;
n@816 2045 options.style.marginRight = spanMargin;
n@816 2046 options.style.marginLeft = spanMargin;
n@816 2047 text.style.marginRight = spanMargin;
n@816 2048 text.style.marginLeft = spanMargin;
n@816 2049 while(options.nextSibling != undefined)
n@816 2050 {
n@816 2051 options = options.nextSibling;
n@816 2052 text = text.nextSibling;
n@816 2053 options.style.marginRight = spanMargin;
n@816 2054 options.style.marginLeft = spanMargin;
n@816 2055 text.style.marginRight = spanMargin;
n@816 2056 text.style.marginLeft = spanMargin;
n@816 2057 }
n@816 2058 };
n@816 2059 this.resize();
n@816 2060 };
n@816 2061
n@816 2062 this.createCommentBox = function(audioObject) {
n@816 2063 var node = new this.elementCommentBox(audioObject);
n@816 2064 this.commentBoxes.push(node);
n@816 2065 audioObject.commentDOM = node;
n@816 2066 return node;
n@816 2067 };
n@816 2068
n@816 2069 this.sortCommentBoxes = function() {
n@816 2070 var holder = [];
n@816 2071 while (this.commentBoxes.length > 0) {
n@816 2072 var node = this.commentBoxes.pop(0);
n@816 2073 holder[node.id] = node;
n@816 2074 }
n@816 2075 this.commentBoxes = holder;
n@816 2076 };
n@816 2077
n@816 2078 this.showCommentBoxes = function(inject, sort) {
n@816 2079 if (sort) {interfaceContext.sortCommentBoxes();}
n@816 2080 for (var i=0; i<interfaceContext.commentBoxes.length; i++) {
n@816 2081 inject.appendChild(this.commentBoxes[i].trackComment);
n@816 2082 }
n@816 2083 };
n@816 2084
n@816 2085 this.deleteCommentBoxes = function() {
n@816 2086 this.commentBoxes = [];
n@816 2087 };
n@816 2088
n@816 2089 this.createCommentQuestion = function(element) {
n@816 2090 var node;
n@816 2091 if (element.type == 'text') {
n@816 2092 node = new this.commentBox(element);
n@816 2093 } else if (element.type == 'radio') {
n@816 2094 node = new this.radioBox(element);
n@816 2095 } else if (element.type == 'checkbox') {
n@816 2096 node = new this.checkboxBox(element);
n@816 2097 }
n@816 2098 this.commentQuestions.push(node);
n@816 2099 return node;
n@816 2100 };
n@816 2101
n@816 2102 this.deleteCommentQuestions = function()
n@816 2103 {
n@816 2104 this.commentQuestions = [];
n@816 2105 };
n@816 2106
n@816 2107 this.playhead = new function()
n@816 2108 {
n@816 2109 this.object = document.createElement('div');
n@816 2110 this.object.className = 'playhead';
n@816 2111 this.object.align = 'left';
n@816 2112 var curTime = document.createElement('div');
n@816 2113 curTime.style.width = '50px';
n@816 2114 this.curTimeSpan = document.createElement('span');
n@816 2115 this.curTimeSpan.textContent = '00:00';
n@816 2116 curTime.appendChild(this.curTimeSpan);
n@816 2117 this.object.appendChild(curTime);
n@816 2118 this.scrubberTrack = document.createElement('div');
n@816 2119 this.scrubberTrack.className = 'playhead-scrub-track';
n@816 2120
n@816 2121 this.scrubberHead = document.createElement('div');
n@816 2122 this.scrubberHead.id = 'playhead-scrubber';
n@816 2123 this.scrubberTrack.appendChild(this.scrubberHead);
n@816 2124 this.object.appendChild(this.scrubberTrack);
n@816 2125
n@816 2126 this.timePerPixel = 0;
n@816 2127 this.maxTime = 0;
n@816 2128
n@816 2129 this.playbackObject;
n@816 2130
n@816 2131 this.setTimePerPixel = function(audioObject) {
n@816 2132 //maxTime must be in seconds
n@816 2133 this.playbackObject = audioObject;
n@816 2134 this.maxTime = audioObject.buffer.duration;
n@816 2135 var width = 490; //500 - 10, 5 each side of the tracker head
n@816 2136 this.timePerPixel = this.maxTime/490;
n@816 2137 if (this.maxTime < 60) {
n@816 2138 this.curTimeSpan.textContent = '0.00';
n@816 2139 } else {
n@816 2140 this.curTimeSpan.textContent = '00:00';
n@816 2141 }
n@816 2142 };
n@816 2143
n@816 2144 this.update = function() {
n@816 2145 // Update the playhead position, startPlay must be called
n@816 2146 if (this.timePerPixel > 0) {
n@816 2147 var time = this.playbackObject.getCurrentPosition();
n@816 2148 if (time > 0) {
n@816 2149 var width = 490;
n@816 2150 var pix = Math.floor(time/this.timePerPixel);
n@816 2151 this.scrubberHead.style.left = pix+'px';
n@816 2152 if (this.maxTime > 60.0) {
n@816 2153 var secs = time%60;
n@816 2154 var mins = Math.floor((time-secs)/60);
n@816 2155 secs = secs.toString();
n@816 2156 secs = secs.substr(0,2);
n@816 2157 mins = mins.toString();
n@816 2158 this.curTimeSpan.textContent = mins+':'+secs;
n@816 2159 } else {
n@816 2160 time = time.toString();
n@816 2161 this.curTimeSpan.textContent = time.substr(0,4);
n@816 2162 }
n@816 2163 } else {
n@816 2164 this.scrubberHead.style.left = '0px';
n@816 2165 if (this.maxTime < 60) {
n@816 2166 this.curTimeSpan.textContent = '0.00';
n@816 2167 } else {
n@816 2168 this.curTimeSpan.textContent = '00:00';
n@816 2169 }
n@816 2170 }
n@816 2171 }
n@816 2172 };
n@816 2173
n@816 2174 this.interval = undefined;
n@816 2175
n@816 2176 this.start = function() {
n@816 2177 if (this.playbackObject != undefined && this.interval == undefined) {
n@816 2178 if (this.maxTime < 60) {
n@816 2179 this.interval = setInterval(function(){interfaceContext.playhead.update();},10);
n@816 2180 } else {
n@816 2181 this.interval = setInterval(function(){interfaceContext.playhead.update();},100);
n@816 2182 }
n@816 2183 }
n@816 2184 };
n@816 2185 this.stop = function() {
n@816 2186 clearInterval(this.interval);
n@816 2187 this.interval = undefined;
n@816 2188 if (this.maxTime < 60) {
n@816 2189 this.curTimeSpan.textContent = '0.00';
n@816 2190 } else {
n@816 2191 this.curTimeSpan.textContent = '00:00';
n@816 2192 }
n@816 2193 };
n@816 2194 };
n@816 2195
n@816 2196 // Global Checkers
n@816 2197 // These functions will help enforce the checkers
n@816 2198 this.checkHiddenAnchor = function()
n@816 2199 {
n@816 2200 var audioHolder = testState.currentStateMap[testState.currentIndex];
n@816 2201 if (audioHolder.anchorId != null)
n@816 2202 {
n@816 2203 var audioObject = audioEngineContext.audioObjects[audioHolder.anchorId];
n@816 2204 if (audioObject.interfaceDOM.getValue() > audioObject.specification.marker && audioObject.interfaceDOM.enforce == true)
n@816 2205 {
n@816 2206 // Anchor is not set below
n@816 2207 console.log('Anchor node not below marker value');
n@816 2208 alert('Please keep listening');
n@816 2209 return false;
n@816 2210 }
n@816 2211 }
n@816 2212 return true;
n@816 2213 };
n@816 2214
n@816 2215 this.checkHiddenReference = function()
n@816 2216 {
n@816 2217 var audioHolder = testState.currentStateMap[testState.currentIndex];
n@816 2218 if (audioHolder.referenceId != null)
n@816 2219 {
n@816 2220 var audioObject = audioEngineContext.audioObjects[audioHolder.referenceId];
n@816 2221 if (audioObject.interfaceDOM.getValue() < audioObject.specification.marker && audioObject.interfaceDOM.enforce == true)
n@816 2222 {
n@816 2223 // Anchor is not set below
n@816 2224 console.log('Reference node not above marker value');
n@816 2225 alert('Please keep listening');
n@816 2226 return false;
n@816 2227 }
n@816 2228 }
n@816 2229 return true;
n@816 2230 };
n@816 2231 }