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