annotate core.js @ 278:8020152a36af

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