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