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