annotate core.js @ 2085:11328fe5d16d

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