annotate core.js @ 1527:74485fc481e1

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