annotate core.js @ 1404:3b9f0bc523d6

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