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