comparison core.js @ 842:1e8bdac90b78

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