annotate core.js @ 1942:4988c805ff9e

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