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