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