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