annotate core.js @ 1773:33b2dc939edd

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