nickjillings@1318
|
1 /**
|
nickjillings@1318
|
2 * core.js
|
nickjillings@1318
|
3 *
|
nickjillings@1318
|
4 * Main script to run, calls all other core functions and manages loading/store to backend.
|
nickjillings@1318
|
5 * Also contains all global variables.
|
nickjillings@1318
|
6 */
|
nickjillings@1318
|
7
|
nickjillings@1318
|
8 /* create the web audio API context and store in audioContext*/
|
nickjillings@1318
|
9 var audioContext; // Hold the browser web audio API
|
nickjillings@1318
|
10 var projectXML; // Hold the parsed setup XML
|
nickjillings@1324
|
11 var schemaXSD; // Hold the parsed schema XSD
|
nickjillings@1318
|
12 var specification;
|
nickjillings@1318
|
13 var interfaceContext;
|
nickjillings@1324
|
14 var storage;
|
nickjillings@1318
|
15 var popup; // Hold the interfacePopup object
|
nickjillings@1318
|
16 var testState;
|
nickjillings@1318
|
17 var currentTrackOrder = []; // Hold the current XML tracks in their (randomised) order
|
nickjillings@1318
|
18 var audioEngineContext; // The custome AudioEngine object
|
nickjillings@1318
|
19 var projectReturn; // Hold the URL for the return
|
nickjillings@1318
|
20
|
nickjillings@1318
|
21
|
nickjillings@1318
|
22 // Add a prototype to the bufferSourceNode to reference to the audioObject holding it
|
nickjillings@1318
|
23 AudioBufferSourceNode.prototype.owner = undefined;
|
nickjillings@1318
|
24 // Add a prototype to the bufferNode to hold the desired LINEAR gain
|
nickjillings@1320
|
25 AudioBuffer.prototype.playbackGain = undefined;
|
nickjillings@1318
|
26 // Add a prototype to the bufferNode to hold the computed LUFS loudness
|
nickjillings@1318
|
27 AudioBuffer.prototype.lufs = undefined;
|
nickjillings@1318
|
28
|
nickjillings@1348
|
29 // Firefox does not have an XMLDocument.prototype.getElementsByName
|
nickjillings@1348
|
30 // and there is no searchAll style command, this custom function will
|
nickjillings@1348
|
31 // search all children recusrively for the name. Used for XSD where all
|
nickjillings@1348
|
32 // element nodes must have a name and therefore can pull the schema node
|
nickjillings@1348
|
33 XMLDocument.prototype.getAllElementsByName = function(name)
|
nickjillings@1348
|
34 {
|
nickjillings@1348
|
35 name = String(name);
|
nickjillings@1348
|
36 var selected = this.documentElement.getAllElementsByName(name);
|
nickjillings@1348
|
37 return selected;
|
nickjillings@1348
|
38 }
|
nickjillings@1348
|
39
|
nickjillings@1348
|
40 Element.prototype.getAllElementsByName = function(name)
|
nickjillings@1348
|
41 {
|
nickjillings@1348
|
42 name = String(name);
|
nickjillings@1348
|
43 var selected = [];
|
nickjillings@1348
|
44 var node = this.firstElementChild;
|
nickjillings@1348
|
45 while(node != null)
|
nickjillings@1348
|
46 {
|
nickjillings@1348
|
47 if (node.getAttribute('name') == name)
|
nickjillings@1348
|
48 {
|
nickjillings@1348
|
49 selected.push(node);
|
nickjillings@1348
|
50 }
|
nickjillings@1348
|
51 if (node.childElementCount > 0)
|
nickjillings@1348
|
52 {
|
nickjillings@1348
|
53 selected = selected.concat(node.getAllElementsByName(name));
|
nickjillings@1348
|
54 }
|
nickjillings@1348
|
55 node = node.nextElementSibling;
|
nickjillings@1348
|
56 }
|
nickjillings@1348
|
57 return selected;
|
nickjillings@1348
|
58 }
|
nickjillings@1348
|
59
|
nickjillings@1348
|
60 XMLDocument.prototype.getAllElementsByTagName = function(name)
|
nickjillings@1348
|
61 {
|
nickjillings@1348
|
62 name = String(name);
|
nickjillings@1348
|
63 var selected = this.documentElement.getAllElementsByTagName(name);
|
nickjillings@1348
|
64 return selected;
|
nickjillings@1348
|
65 }
|
nickjillings@1348
|
66
|
nickjillings@1348
|
67 Element.prototype.getAllElementsByTagName = function(name)
|
nickjillings@1348
|
68 {
|
nickjillings@1348
|
69 name = String(name);
|
nickjillings@1348
|
70 var selected = [];
|
nickjillings@1348
|
71 var node = this.firstElementChild;
|
nickjillings@1348
|
72 while(node != null)
|
nickjillings@1348
|
73 {
|
nickjillings@1348
|
74 if (node.nodeName == name)
|
nickjillings@1348
|
75 {
|
nickjillings@1348
|
76 selected.push(node);
|
nickjillings@1348
|
77 }
|
nickjillings@1348
|
78 if (node.childElementCount > 0)
|
nickjillings@1348
|
79 {
|
nickjillings@1348
|
80 selected = selected.concat(node.getAllElementsByTagName(name));
|
nickjillings@1348
|
81 }
|
nickjillings@1348
|
82 node = node.nextElementSibling;
|
nickjillings@1348
|
83 }
|
nickjillings@1348
|
84 return selected;
|
nickjillings@1348
|
85 }
|
nickjillings@1348
|
86
|
nickjillings@1348
|
87 // Firefox does not have an XMLDocument.prototype.getElementsByName
|
nickjillings@1348
|
88 if (typeof XMLDocument.prototype.getElementsByName != "function") {
|
nickjillings@1348
|
89 XMLDocument.prototype.getElementsByName = function(name)
|
nickjillings@1348
|
90 {
|
nickjillings@1348
|
91 name = String(name);
|
nickjillings@1348
|
92 var node = this.documentElement.firstElementChild;
|
nickjillings@1348
|
93 var selected = [];
|
nickjillings@1348
|
94 while(node != null)
|
nickjillings@1348
|
95 {
|
nickjillings@1348
|
96 if (node.getAttribute('name') == name)
|
nickjillings@1348
|
97 {
|
nickjillings@1348
|
98 selected.push(node);
|
nickjillings@1348
|
99 }
|
nickjillings@1348
|
100 node = node.nextElementSibling;
|
nickjillings@1348
|
101 }
|
nickjillings@1348
|
102 return selected;
|
nickjillings@1348
|
103 }
|
nickjillings@1348
|
104 }
|
nickjillings@1348
|
105
|
nickjillings@1318
|
106 window.onload = function() {
|
nickjillings@1318
|
107 // Function called once the browser has loaded all files.
|
nickjillings@1318
|
108 // This should perform any initial commands such as structure / loading documents
|
nickjillings@1318
|
109
|
nickjillings@1318
|
110 // Create a web audio API context
|
nickjillings@1318
|
111 // Fixed for cross-browser support
|
nickjillings@1318
|
112 var AudioContext = window.AudioContext || window.webkitAudioContext;
|
nickjillings@1318
|
113 audioContext = new AudioContext;
|
nickjillings@1318
|
114
|
nickjillings@1318
|
115 // Create test state
|
nickjillings@1318
|
116 testState = new stateMachine();
|
nickjillings@1318
|
117
|
nickjillings@1318
|
118 // Create the popup interface object
|
nickjillings@1318
|
119 popup = new interfacePopup();
|
nickjillings@1370
|
120
|
nickjillings@1370
|
121 // Create the specification object
|
nickjillings@1318
|
122 specification = new Specification();
|
nickjillings@1318
|
123
|
nickjillings@1318
|
124 // Create the interface object
|
nickjillings@1318
|
125 interfaceContext = new Interface(specification);
|
nickjillings@1324
|
126
|
nickjillings@1324
|
127 // Create the storage object
|
nickjillings@1324
|
128 storage = new Storage();
|
nickjillings@1318
|
129 // Define window callbacks for interface
|
nickjillings@1318
|
130 window.onresize = function(event){interfaceContext.resizeWindow(event);};
|
nickjillings@1318
|
131 };
|
nickjillings@1318
|
132
|
nickjillings@1318
|
133 function loadProjectSpec(url) {
|
nickjillings@1318
|
134 // Load the project document from the given URL, decode the XML and instruct audioEngine to get audio data
|
nickjillings@1318
|
135 // If url is null, request client to upload project XML document
|
nickjillings@1324
|
136 var xmlhttp = new XMLHttpRequest();
|
nickjillings@1324
|
137 xmlhttp.open("GET",'test-schema.xsd',true);
|
nickjillings@1324
|
138 xmlhttp.onload = function()
|
nickjillings@1324
|
139 {
|
nickjillings@1324
|
140 schemaXSD = xmlhttp.response;
|
nickjillings@1324
|
141 var parse = new DOMParser();
|
nickjillings@1324
|
142 specification.schema = parse.parseFromString(xmlhttp.response,'text/xml');
|
nickjillings@1324
|
143 var r = new XMLHttpRequest();
|
nickjillings@1324
|
144 r.open('GET',url,true);
|
nickjillings@1324
|
145 r.onload = function() {
|
nickjillings@1324
|
146 loadProjectSpecCallback(r.response);
|
nickjillings@1324
|
147 };
|
nickjillings@1324
|
148 r.send();
|
nickjillings@1318
|
149 };
|
nickjillings@1324
|
150 xmlhttp.send();
|
nickjillings@1318
|
151 };
|
nickjillings@1318
|
152
|
nickjillings@1318
|
153 function loadProjectSpecCallback(response) {
|
nickjillings@1318
|
154 // Function called after asynchronous download of XML project specification
|
nickjillings@1318
|
155 //var decode = $.parseXML(response);
|
nickjillings@1318
|
156 //projectXML = $(decode);
|
nickjillings@1318
|
157
|
nickjillings@1324
|
158 // First perform XML schema validation
|
nickjillings@1324
|
159 var Module = {
|
nickjillings@1324
|
160 xml: response,
|
nickjillings@1324
|
161 schema: schemaXSD,
|
nickjillings@1324
|
162 arguments:["--noout", "--schema", 'test-schema.xsd','document.xml']
|
nickjillings@1324
|
163 };
|
nickjillings@1324
|
164
|
nickjillings@1324
|
165 var xmllint = validateXML(Module);
|
nickjillings@1324
|
166 console.log(xmllint);
|
nickjillings@1324
|
167 if(xmllint != 'document.xml validates\n')
|
nickjillings@1324
|
168 {
|
nickjillings@1324
|
169 document.getElementsByTagName('body')[0].innerHTML = null;
|
nickjillings@1324
|
170 var msg = document.createElement("h3");
|
nickjillings@1324
|
171 msg.textContent = "FATAL ERROR";
|
nickjillings@1324
|
172 var span = document.createElement("h4");
|
nickjillings@1324
|
173 span.textContent = "The XML validator returned the following errors when decoding your XML file";
|
nickjillings@1324
|
174 document.getElementsByTagName('body')[0].appendChild(msg);
|
nickjillings@1324
|
175 document.getElementsByTagName('body')[0].appendChild(span);
|
nickjillings@1324
|
176 xmllint = xmllint.split('\n');
|
nickjillings@1324
|
177 for (var i in xmllint)
|
nickjillings@1324
|
178 {
|
nickjillings@1324
|
179 document.getElementsByTagName('body')[0].appendChild(document.createElement('br'));
|
nickjillings@1324
|
180 var span = document.createElement("span");
|
nickjillings@1324
|
181 span.textContent = xmllint[i];
|
nickjillings@1324
|
182 document.getElementsByTagName('body')[0].appendChild(span);
|
nickjillings@1324
|
183 }
|
nickjillings@1324
|
184 return;
|
nickjillings@1324
|
185 }
|
nickjillings@1324
|
186
|
nickjillings@1318
|
187 var parse = new DOMParser();
|
nickjillings@1318
|
188 projectXML = parse.parseFromString(response,'text/xml');
|
nickjillings@1318
|
189 var errorNode = projectXML.getElementsByTagName('parsererror');
|
nickjillings@1318
|
190 if (errorNode.length >= 1)
|
nickjillings@1318
|
191 {
|
nickjillings@1318
|
192 var msg = document.createElement("h3");
|
nickjillings@1318
|
193 msg.textContent = "FATAL ERROR";
|
nickjillings@1318
|
194 var span = document.createElement("span");
|
nickjillings@1318
|
195 span.textContent = "The XML parser returned the following errors when decoding your XML file";
|
nickjillings@1318
|
196 document.getElementsByTagName('body')[0].innerHTML = null;
|
nickjillings@1318
|
197 document.getElementsByTagName('body')[0].appendChild(msg);
|
nickjillings@1318
|
198 document.getElementsByTagName('body')[0].appendChild(span);
|
nickjillings@1318
|
199 document.getElementsByTagName('body')[0].appendChild(errorNode[0]);
|
nickjillings@1318
|
200 return;
|
nickjillings@1318
|
201 }
|
nickjillings@1318
|
202
|
nickjillings@1318
|
203 // Build the specification
|
nickjillings@1318
|
204 specification.decode(projectXML);
|
nickjillings@1324
|
205 storage.initialise();
|
nickjillings@1339
|
206 /// CHECK FOR SAMPLE RATE COMPATIBILITY
|
nickjillings@1339
|
207 if (specification.sampleRate != undefined) {
|
nickjillings@1339
|
208 if (Number(specification.sampleRate) != audioContext.sampleRate) {
|
nickjillings@1339
|
209 var errStr = 'Sample rates do not match! Requested '+Number(specification.sampleRate)+', got '+audioContext.sampleRate+'. Please set the sample rate to match before completing this test.';
|
nickjillings@1339
|
210 alert(errStr);
|
nickjillings@1339
|
211 return;
|
nickjillings@1339
|
212 }
|
nickjillings@1339
|
213 }
|
nickjillings@1318
|
214
|
nickjillings@1318
|
215 // Detect the interface to use and load the relevant javascripts.
|
nickjillings@1318
|
216 var interfaceJS = document.createElement('script');
|
nickjillings@1318
|
217 interfaceJS.setAttribute("type","text/javascript");
|
nickjillings@1329
|
218 switch(specification.interface)
|
nickjillings@1329
|
219 {
|
nickjillings@1329
|
220 case "APE":
|
nickjillings@1341
|
221 interfaceJS.setAttribute("src","interfaces/ape.js");
|
nickjillings@1318
|
222
|
nickjillings@1318
|
223 // APE comes with a css file
|
nickjillings@1318
|
224 var css = document.createElement('link');
|
nickjillings@1318
|
225 css.rel = 'stylesheet';
|
nickjillings@1318
|
226 css.type = 'text/css';
|
nickjillings@1341
|
227 css.href = 'interfaces/ape.css';
|
nickjillings@1318
|
228
|
nickjillings@1318
|
229 document.getElementsByTagName("head")[0].appendChild(css);
|
nickjillings@1329
|
230 break;
|
nickjillings@1329
|
231
|
nickjillings@1329
|
232 case "MUSHRA":
|
nickjillings@1341
|
233 interfaceJS.setAttribute("src","interfaces/mushra.js");
|
nickjillings@1318
|
234
|
nickjillings@1318
|
235 // MUSHRA comes with a css file
|
nickjillings@1318
|
236 var css = document.createElement('link');
|
nickjillings@1318
|
237 css.rel = 'stylesheet';
|
nickjillings@1318
|
238 css.type = 'text/css';
|
nickjillings@1341
|
239 css.href = 'interfaces/mushra.css';
|
nickjillings@1318
|
240
|
nickjillings@1318
|
241 document.getElementsByTagName("head")[0].appendChild(css);
|
nickjillings@1329
|
242 break;
|
nickjillings@1329
|
243
|
nickjillings@1329
|
244 case "AB":
|
nickjillings@1341
|
245 interfaceJS.setAttribute("src","interfaces/AB.js");
|
nickjillings@1329
|
246
|
nickjillings@1329
|
247 // AB comes with a css file
|
nickjillings@1329
|
248 var css = document.createElement('link');
|
nickjillings@1329
|
249 css.rel = 'stylesheet';
|
nickjillings@1329
|
250 css.type = 'text/css';
|
nickjillings@1341
|
251 css.href = 'interfaces/AB.css';
|
nickjillings@1329
|
252
|
nickjillings@1329
|
253 document.getElementsByTagName("head")[0].appendChild(css);
|
nickjillings@1345
|
254 break;
|
nickjillings@1345
|
255 case "Bipolar":
|
nickjillings@1345
|
256 case "ACR":
|
nickjillings@1345
|
257 case "DCR":
|
nickjillings@1345
|
258 case "CCR":
|
nickjillings@1343
|
259 case "ABC":
|
nickjillings@1343
|
260 // Above enumerate to horizontal sliders
|
nickjillings@1343
|
261 interfaceJS.setAttribute("src","interfaces/horizontal-sliders.js");
|
nickjillings@1343
|
262
|
nickjillings@1343
|
263 // horizontal-sliders comes with a css file
|
nickjillings@1343
|
264 var css = document.createElement('link');
|
nickjillings@1343
|
265 css.rel = 'stylesheet';
|
nickjillings@1343
|
266 css.type = 'text/css';
|
nickjillings@1343
|
267 css.href = 'interfaces/horizontal-sliders.css';
|
nickjillings@1343
|
268
|
nickjillings@1343
|
269 document.getElementsByTagName("head")[0].appendChild(css);
|
nickjillings@1345
|
270 break;
|
nickjillings@1345
|
271 case "discrete":
|
nickjillings@1345
|
272 case "likert":
|
nickjillings@1345
|
273 // Above enumerate to horizontal discrete radios
|
nickjillings@1345
|
274 interfaceJS.setAttribute("src","interfaces/discrete.js");
|
nickjillings@1345
|
275
|
nickjillings@1345
|
276 // horizontal-sliders comes with a css file
|
nickjillings@1345
|
277 var css = document.createElement('link');
|
nickjillings@1345
|
278 css.rel = 'stylesheet';
|
nickjillings@1345
|
279 css.type = 'text/css';
|
nickjillings@1345
|
280 css.href = 'interfaces/discrete.css';
|
nickjillings@1345
|
281
|
nickjillings@1345
|
282 document.getElementsByTagName("head")[0].appendChild(css);
|
nickjillings@1345
|
283 break;
|
nickjillings@1318
|
284 }
|
nickjillings@1318
|
285 document.getElementsByTagName("head")[0].appendChild(interfaceJS);
|
nickjillings@1318
|
286
|
nickjillings@1318
|
287 // Create the audio engine object
|
nickjillings@1318
|
288 audioEngineContext = new AudioEngine(specification);
|
nickjillings@1318
|
289
|
nickjillings@1324
|
290 $(specification.pages).each(function(index,elem){
|
nickjillings@1318
|
291 $(elem.audioElements).each(function(i,audioElem){
|
nickjillings@1324
|
292 var URL = elem.hostURL + audioElem.url;
|
nickjillings@1318
|
293 var buffer = null;
|
nickjillings@1318
|
294 for (var i=0; i<audioEngineContext.buffers.length; i++)
|
nickjillings@1318
|
295 {
|
nickjillings@1318
|
296 if (URL == audioEngineContext.buffers[i].url)
|
nickjillings@1318
|
297 {
|
nickjillings@1318
|
298 buffer = audioEngineContext.buffers[i];
|
nickjillings@1318
|
299 break;
|
nickjillings@1318
|
300 }
|
nickjillings@1318
|
301 }
|
nickjillings@1318
|
302 if (buffer == null)
|
nickjillings@1318
|
303 {
|
nickjillings@1318
|
304 buffer = new audioEngineContext.bufferObj();
|
nickjillings@1318
|
305 buffer.getMedia(URL);
|
nickjillings@1318
|
306 audioEngineContext.buffers.push(buffer);
|
nickjillings@1318
|
307 }
|
nickjillings@1318
|
308 });
|
nickjillings@1318
|
309 });
|
nickjillings@1318
|
310 }
|
nickjillings@1318
|
311
|
nickjillings@1318
|
312 function createProjectSave(destURL) {
|
nickjillings@1318
|
313 // Save the data from interface into XML and send to destURL
|
nickjillings@1318
|
314 // If destURL is null then download XML in client
|
nickjillings@1318
|
315 // Now time to render file locally
|
nickjillings@1318
|
316 var xmlDoc = interfaceXMLSave();
|
nickjillings@1318
|
317 var parent = document.createElement("div");
|
nickjillings@1318
|
318 parent.appendChild(xmlDoc);
|
nickjillings@1318
|
319 var file = [parent.innerHTML];
|
nickjillings@1318
|
320 if (destURL == "null" || destURL == undefined) {
|
nickjillings@1318
|
321 var bb = new Blob(file,{type : 'application/xml'});
|
nickjillings@1318
|
322 var dnlk = window.URL.createObjectURL(bb);
|
nickjillings@1318
|
323 var a = document.createElement("a");
|
nickjillings@1318
|
324 a.hidden = '';
|
nickjillings@1318
|
325 a.href = dnlk;
|
nickjillings@1318
|
326 a.download = "save.xml";
|
nickjillings@1318
|
327 a.textContent = "Save File";
|
nickjillings@1318
|
328
|
nickjillings@1318
|
329 popup.showPopup();
|
nickjillings@1332
|
330 popup.popupContent.innerHTML = "</span>Please save the file below to give to your test supervisor</span><br>";
|
nickjillings@1318
|
331 popup.popupContent.appendChild(a);
|
nickjillings@1318
|
332 } else {
|
nickjillings@1318
|
333 var xmlhttp = new XMLHttpRequest;
|
nickjillings@1318
|
334 xmlhttp.open("POST",destURL,true);
|
nickjillings@1318
|
335 xmlhttp.setRequestHeader('Content-Type', 'text/xml');
|
nickjillings@1318
|
336 xmlhttp.onerror = function(){
|
nickjillings@1318
|
337 console.log('Error saving file to server! Presenting download locally');
|
nickjillings@1318
|
338 createProjectSave(null);
|
nickjillings@1318
|
339 };
|
nickjillings@1318
|
340 xmlhttp.onreadystatechange = function() {
|
nickjillings@1318
|
341 console.log(xmlhttp.status);
|
nickjillings@1318
|
342 if (xmlhttp.status != 200 && xmlhttp.readyState == 4) {
|
nickjillings@1318
|
343 createProjectSave(null);
|
nickjillings@1318
|
344 } else {
|
nickjillings@1318
|
345 if (xmlhttp.responseXML == null)
|
nickjillings@1318
|
346 {
|
nickjillings@1324
|
347 createProjectSave('null');
|
nickjillings@1318
|
348 }
|
nickjillings@1318
|
349 var response = xmlhttp.responseXML.childNodes[0];
|
nickjillings@1318
|
350 if (response.getAttribute('state') == "OK")
|
nickjillings@1318
|
351 {
|
nickjillings@1318
|
352 var file = response.getElementsByTagName('file')[0];
|
nickjillings@1318
|
353 console.log('Save OK: Filename '+file.textContent+','+file.getAttribute('bytes')+'B');
|
nickjillings@1318
|
354 popup.showPopup();
|
nickjillings@1318
|
355 popup.popupContent.innerHTML = null;
|
nickjillings@1318
|
356 popup.popupContent.textContent = "Thank you!";
|
nickjillings@1318
|
357 } else {
|
nickjillings@1318
|
358 var message = response.getElementsByTagName('message')[0];
|
nickjillings@1318
|
359 errorSessionDump(message.textContent);
|
nickjillings@1318
|
360 }
|
nickjillings@1318
|
361 }
|
nickjillings@1318
|
362 };
|
nickjillings@1318
|
363 xmlhttp.send(file);
|
nickjillings@1332
|
364 popup.showPopup();
|
nickjillings@1332
|
365 popup.popupContent.innerHTML = null;
|
nickjillings@1332
|
366 popup.popupContent.textContent = "Submitting. Please Wait";
|
nickjillings@1318
|
367 }
|
nickjillings@1318
|
368 }
|
nickjillings@1318
|
369
|
nickjillings@1318
|
370 function errorSessionDump(msg){
|
nickjillings@1318
|
371 // Create the partial interface XML save
|
nickjillings@1318
|
372 // Include error node with message on why the dump occured
|
nickjillings@1318
|
373 popup.showPopup();
|
nickjillings@1318
|
374 popup.popupContent.innerHTML = null;
|
nickjillings@1318
|
375 var err = document.createElement('error');
|
nickjillings@1318
|
376 var parent = document.createElement("div");
|
nickjillings@1318
|
377 if (typeof msg === "object")
|
nickjillings@1318
|
378 {
|
nickjillings@1318
|
379 err.appendChild(msg);
|
nickjillings@1318
|
380 popup.popupContent.appendChild(msg);
|
nickjillings@1318
|
381
|
nickjillings@1318
|
382 } else {
|
nickjillings@1318
|
383 err.textContent = msg;
|
nickjillings@1318
|
384 popup.popupContent.innerHTML = "ERROR : "+msg;
|
nickjillings@1318
|
385 }
|
nickjillings@1318
|
386 var xmlDoc = interfaceXMLSave();
|
nickjillings@1318
|
387 xmlDoc.appendChild(err);
|
nickjillings@1318
|
388 parent.appendChild(xmlDoc);
|
nickjillings@1318
|
389 var file = [parent.innerHTML];
|
nickjillings@1318
|
390 var bb = new Blob(file,{type : 'application/xml'});
|
nickjillings@1318
|
391 var dnlk = window.URL.createObjectURL(bb);
|
nickjillings@1318
|
392 var a = document.createElement("a");
|
nickjillings@1318
|
393 a.hidden = '';
|
nickjillings@1318
|
394 a.href = dnlk;
|
nickjillings@1318
|
395 a.download = "save.xml";
|
nickjillings@1318
|
396 a.textContent = "Save File";
|
nickjillings@1318
|
397
|
nickjillings@1318
|
398
|
nickjillings@1318
|
399
|
nickjillings@1318
|
400 popup.popupContent.appendChild(a);
|
nickjillings@1318
|
401 }
|
nickjillings@1318
|
402
|
nickjillings@1318
|
403 // Only other global function which must be defined in the interface class. Determines how to create the XML document.
|
nickjillings@1318
|
404 function interfaceXMLSave(){
|
nickjillings@1318
|
405 // Create the XML string to be exported with results
|
nickjillings@1324
|
406 return storage.finish();
|
nickjillings@1318
|
407 }
|
nickjillings@1318
|
408
|
nickjillings@1318
|
409 function linearToDecibel(gain)
|
nickjillings@1318
|
410 {
|
nickjillings@1318
|
411 return 20.0*Math.log10(gain);
|
nickjillings@1318
|
412 }
|
nickjillings@1318
|
413
|
nickjillings@1318
|
414 function decibelToLinear(gain)
|
nickjillings@1318
|
415 {
|
nickjillings@1318
|
416 return Math.pow(10,gain/20.0);
|
nickjillings@1318
|
417 }
|
nickjillings@1318
|
418
|
nickjillings@1318
|
419 function interfacePopup() {
|
nickjillings@1318
|
420 // Creates an object to manage the popup
|
nickjillings@1318
|
421 this.popup = null;
|
nickjillings@1318
|
422 this.popupContent = null;
|
nickjillings@1318
|
423 this.popupTitle = null;
|
nickjillings@1318
|
424 this.popupResponse = null;
|
nickjillings@1318
|
425 this.buttonProceed = null;
|
nickjillings@1318
|
426 this.buttonPrevious = null;
|
nickjillings@1318
|
427 this.popupOptions = null;
|
nickjillings@1318
|
428 this.currentIndex = null;
|
nickjillings@1324
|
429 this.node = null;
|
nickjillings@1324
|
430 this.store = null;
|
nickjillings@1318
|
431 $(window).keypress(function(e){
|
nickjillings@1318
|
432 if (e.keyCode == 13 && popup.popup.style.visibility == 'visible')
|
nickjillings@1318
|
433 {
|
nickjillings@1318
|
434 console.log(e);
|
nickjillings@1318
|
435 popup.buttonProceed.onclick();
|
nickjillings@1318
|
436 e.preventDefault();
|
nickjillings@1318
|
437 }
|
nickjillings@1318
|
438 });
|
nickjillings@1318
|
439
|
nickjillings@1318
|
440 this.createPopup = function(){
|
nickjillings@1318
|
441 // Create popup window interface
|
nickjillings@1318
|
442 var insertPoint = document.getElementById("topLevelBody");
|
nickjillings@1318
|
443
|
nickjillings@1379
|
444 this.popup = document.getElementById('popupHolder');
|
nickjillings@1318
|
445 this.popup.style.left = (window.innerWidth/2)-250 + 'px';
|
nickjillings@1318
|
446 this.popup.style.top = (window.innerHeight/2)-125 + 'px';
|
nickjillings@1318
|
447
|
nickjillings@1379
|
448 this.popupContent = document.getElementById('popupContent');
|
nickjillings@1318
|
449
|
nickjillings@1379
|
450 this.popupTitle = document.getElementById('popupTitle');
|
nickjillings@1318
|
451
|
nickjillings@1379
|
452 this.popupResponse = document.getElementById('popupResponse');
|
nickjillings@1318
|
453
|
nickjillings@1379
|
454 this.buttonProceed = document.getElementById('popup-proceed');
|
nickjillings@1318
|
455 this.buttonProceed.onclick = function(){popup.proceedClicked();};
|
nickjillings@1318
|
456
|
nickjillings@1379
|
457 this.buttonPrevious = document.getElementById('popup-previous');
|
nickjillings@1318
|
458 this.buttonPrevious.onclick = function(){popup.previousClick();};
|
nickjillings@1318
|
459
|
nickjillings@1379
|
460 this.hidePopup();
|
nickjillings@1379
|
461
|
nickjillings@1318
|
462 this.popup.style.zIndex = -1;
|
nickjillings@1318
|
463 this.popup.style.visibility = 'hidden';
|
nickjillings@1318
|
464 };
|
nickjillings@1318
|
465
|
nickjillings@1318
|
466 this.showPopup = function(){
|
nickjillings@1318
|
467 if (this.popup == null) {
|
nickjillings@1318
|
468 this.createPopup();
|
nickjillings@1318
|
469 }
|
nickjillings@1318
|
470 this.popup.style.zIndex = 3;
|
nickjillings@1318
|
471 this.popup.style.visibility = 'visible';
|
nickjillings@1318
|
472 var blank = document.getElementsByClassName('testHalt')[0];
|
nickjillings@1318
|
473 blank.style.zIndex = 2;
|
nickjillings@1318
|
474 blank.style.visibility = 'visible';
|
nickjillings@1318
|
475 };
|
nickjillings@1318
|
476
|
nickjillings@1318
|
477 this.hidePopup = function(){
|
nickjillings@1318
|
478 this.popup.style.zIndex = -1;
|
nickjillings@1318
|
479 this.popup.style.visibility = 'hidden';
|
nickjillings@1318
|
480 var blank = document.getElementsByClassName('testHalt')[0];
|
nickjillings@1318
|
481 blank.style.zIndex = -2;
|
nickjillings@1318
|
482 blank.style.visibility = 'hidden';
|
nickjillings@1318
|
483 this.buttonPrevious.style.visibility = 'inherit';
|
nickjillings@1318
|
484 };
|
nickjillings@1318
|
485
|
nickjillings@1318
|
486 this.postNode = function() {
|
nickjillings@1318
|
487 // This will take the node from the popupOptions and display it
|
nickjillings@1318
|
488 var node = this.popupOptions[this.currentIndex];
|
nickjillings@1318
|
489 this.popupResponse.innerHTML = null;
|
nickjillings@1324
|
490 this.popupTitle.textContent = node.specification.statement;
|
nickjillings@1324
|
491 if (node.specification.type == 'question') {
|
nickjillings@1318
|
492 var textArea = document.createElement('textarea');
|
nickjillings@1324
|
493 switch (node.specification.boxsize) {
|
nickjillings@1318
|
494 case 'small':
|
nickjillings@1318
|
495 textArea.cols = "20";
|
nickjillings@1318
|
496 textArea.rows = "1";
|
nickjillings@1318
|
497 break;
|
nickjillings@1318
|
498 case 'normal':
|
nickjillings@1318
|
499 textArea.cols = "30";
|
nickjillings@1318
|
500 textArea.rows = "2";
|
nickjillings@1318
|
501 break;
|
nickjillings@1318
|
502 case 'large':
|
nickjillings@1318
|
503 textArea.cols = "40";
|
nickjillings@1318
|
504 textArea.rows = "5";
|
nickjillings@1318
|
505 break;
|
nickjillings@1318
|
506 case 'huge':
|
nickjillings@1318
|
507 textArea.cols = "50";
|
nickjillings@1318
|
508 textArea.rows = "10";
|
nickjillings@1318
|
509 break;
|
nickjillings@1318
|
510 }
|
nickjillings@1361
|
511 if (node.response == undefined) {
|
nickjillings@1361
|
512 node.response = "";
|
nickjillings@1361
|
513 } else {
|
nickjillings@1361
|
514 textArea.value = node.response;
|
nickjillings@1361
|
515 }
|
nickjillings@1318
|
516 this.popupResponse.appendChild(textArea);
|
nickjillings@1318
|
517 textArea.focus();
|
nickjillings@1324
|
518 } else if (node.specification.type == 'checkbox') {
|
nickjillings@1361
|
519 if (node.response == undefined) {
|
nickjillings@1361
|
520 node.response = Array(node.specification.options.length);
|
nickjillings@1361
|
521 }
|
nickjillings@1361
|
522 var index = 0;
|
nickjillings@1324
|
523 for (var option of node.specification.options) {
|
nickjillings@1318
|
524 var input = document.createElement('input');
|
nickjillings@1320
|
525 input.id = option.name;
|
nickjillings@1318
|
526 input.type = 'checkbox';
|
nickjillings@1318
|
527 var span = document.createElement('span');
|
nickjillings@1318
|
528 span.textContent = option.text;
|
nickjillings@1318
|
529 var hold = document.createElement('div');
|
nickjillings@1318
|
530 hold.setAttribute('name','option');
|
nickjillings@1318
|
531 hold.style.padding = '4px';
|
nickjillings@1318
|
532 hold.appendChild(input);
|
nickjillings@1318
|
533 hold.appendChild(span);
|
nickjillings@1324
|
534 this.popupResponse.appendChild(hold);
|
nickjillings@1361
|
535 if (node.response[index] != undefined){
|
nickjillings@1361
|
536 if (node.response[index].checked == true) {
|
nickjillings@1361
|
537 input.checked = "true";
|
nickjillings@1361
|
538 }
|
nickjillings@1361
|
539 }
|
nickjillings@1361
|
540 index++;
|
nickjillings@1318
|
541 }
|
nickjillings@1324
|
542 } else if (node.specification.type == 'radio') {
|
nickjillings@1361
|
543 if (node.response == undefined) {
|
nickjillings@1361
|
544 node.response = {name: "", text: ""};
|
nickjillings@1361
|
545 }
|
nickjillings@1361
|
546 var index = 0;
|
nickjillings@1324
|
547 for (var option of node.specification.options) {
|
nickjillings@1318
|
548 var input = document.createElement('input');
|
nickjillings@1318
|
549 input.id = option.name;
|
nickjillings@1318
|
550 input.type = 'radio';
|
nickjillings@1324
|
551 input.name = node.specification.id;
|
nickjillings@1318
|
552 var span = document.createElement('span');
|
nickjillings@1318
|
553 span.textContent = option.text;
|
nickjillings@1318
|
554 var hold = document.createElement('div');
|
nickjillings@1318
|
555 hold.setAttribute('name','option');
|
nickjillings@1318
|
556 hold.style.padding = '4px';
|
nickjillings@1318
|
557 hold.appendChild(input);
|
nickjillings@1318
|
558 hold.appendChild(span);
|
nickjillings@1324
|
559 this.popupResponse.appendChild(hold);
|
nickjillings@1361
|
560 if (input.id == node.response.name) {
|
nickjillings@1361
|
561 input.checked = "true";
|
nickjillings@1361
|
562 }
|
nickjillings@1318
|
563 }
|
nickjillings@1324
|
564 } else if (node.specification.type == 'number') {
|
nickjillings@1318
|
565 var input = document.createElement('input');
|
nickjillings@1318
|
566 input.type = 'textarea';
|
nickjillings@1324
|
567 if (node.min != null) {input.min = node.specification.min;}
|
nickjillings@1324
|
568 if (node.max != null) {input.max = node.specification.max;}
|
nickjillings@1324
|
569 if (node.step != null) {input.step = node.specification.step;}
|
nickjillings@1361
|
570 if (node.response != undefined) {
|
nickjillings@1361
|
571 input.value = node.response;
|
nickjillings@1361
|
572 }
|
nickjillings@1318
|
573 this.popupResponse.appendChild(input);
|
nickjillings@1318
|
574 }
|
nickjillings@1318
|
575 if(this.currentIndex+1 == this.popupOptions.length) {
|
nickjillings@1324
|
576 if (this.node.location == "pre") {
|
nickjillings@1318
|
577 this.buttonProceed.textContent = 'Start';
|
nickjillings@1318
|
578 } else {
|
nickjillings@1318
|
579 this.buttonProceed.textContent = 'Submit';
|
nickjillings@1318
|
580 }
|
nickjillings@1318
|
581 } else {
|
nickjillings@1318
|
582 this.buttonProceed.textContent = 'Next';
|
nickjillings@1318
|
583 }
|
nickjillings@1318
|
584 if(this.currentIndex > 0)
|
nickjillings@1318
|
585 this.buttonPrevious.style.visibility = 'visible';
|
nickjillings@1318
|
586 else
|
nickjillings@1318
|
587 this.buttonPrevious.style.visibility = 'hidden';
|
nickjillings@1318
|
588 };
|
nickjillings@1318
|
589
|
nickjillings@1324
|
590 this.initState = function(node,store) {
|
nickjillings@1318
|
591 //Call this with your preTest and postTest nodes when needed to
|
nickjillings@1318
|
592 // initialise the popup procedure.
|
nickjillings@1324
|
593 if (node.options.length > 0) {
|
nickjillings@1324
|
594 this.popupOptions = [];
|
nickjillings@1324
|
595 this.node = node;
|
nickjillings@1324
|
596 this.store = store;
|
nickjillings@1324
|
597 for (var opt of node.options)
|
nickjillings@1324
|
598 {
|
nickjillings@1324
|
599 this.popupOptions.push({
|
nickjillings@1324
|
600 specification: opt,
|
nickjillings@1324
|
601 response: null
|
nickjillings@1324
|
602 });
|
nickjillings@1324
|
603 }
|
nickjillings@1318
|
604 this.currentIndex = 0;
|
nickjillings@1318
|
605 this.showPopup();
|
nickjillings@1318
|
606 this.postNode();
|
nickjillings@1318
|
607 } else {
|
nickjillings@1318
|
608 advanceState();
|
nickjillings@1318
|
609 }
|
nickjillings@1318
|
610 };
|
nickjillings@1318
|
611
|
nickjillings@1318
|
612 this.proceedClicked = function() {
|
nickjillings@1318
|
613 // Each time the popup button is clicked!
|
nickjillings@1318
|
614 var node = this.popupOptions[this.currentIndex];
|
nickjillings@1324
|
615 if (node.specification.type == 'question') {
|
nickjillings@1318
|
616 // Must extract the question data
|
nickjillings@1318
|
617 var textArea = $(popup.popupContent).find('textarea')[0];
|
nickjillings@1324
|
618 if (node.specification.mandatory == true && textArea.value.length == 0) {
|
nickjillings@1318
|
619 alert('This question is mandatory');
|
nickjillings@1318
|
620 return;
|
nickjillings@1318
|
621 } else {
|
nickjillings@1318
|
622 // Save the text content
|
nickjillings@1324
|
623 console.log("Question: "+ node.specification.statement);
|
nickjillings@1318
|
624 console.log("Question Response: "+ textArea.value);
|
nickjillings@1324
|
625 node.response = textArea.value;
|
nickjillings@1318
|
626 }
|
nickjillings@1324
|
627 } else if (node.specification.type == 'checkbox') {
|
nickjillings@1318
|
628 // Must extract checkbox data
|
nickjillings@1326
|
629 console.log("Checkbox: "+ node.specification.statement);
|
nickjillings@1324
|
630 var inputs = this.popupResponse.getElementsByTagName('input');
|
nickjillings@1324
|
631 node.response = [];
|
nickjillings@1324
|
632 for (var i=0; i<node.specification.options.length; i++) {
|
nickjillings@1324
|
633 node.response.push({
|
nickjillings@1324
|
634 name: node.specification.options[i].name,
|
nickjillings@1324
|
635 text: node.specification.options[i].text,
|
nickjillings@1324
|
636 checked: inputs[i].checked
|
nickjillings@1324
|
637 });
|
nickjillings@1326
|
638 console.log(node.specification.options[i].name+": "+ inputs[i].checked);
|
nickjillings@1324
|
639 }
|
nickjillings@1324
|
640 } else if (node.specification.type == "radio") {
|
nickjillings@1318
|
641 var optHold = this.popupResponse;
|
nickjillings@1324
|
642 console.log("Radio: "+ node.specification.statement);
|
nickjillings@1324
|
643 node.response = null;
|
nickjillings@1318
|
644 var i=0;
|
nickjillings@1324
|
645 var inputs = optHold.getElementsByTagName('input');
|
nickjillings@1324
|
646 while(node.response == null) {
|
nickjillings@1324
|
647 if (i == inputs.length)
|
nickjillings@1324
|
648 {
|
nickjillings@1324
|
649 if (node.specification.mandatory == true)
|
nickjillings@1324
|
650 {
|
nickjillings@1324
|
651 alert("This radio is mandatory");
|
nickjillings@1324
|
652 } else {
|
nickjillings@1324
|
653 node.response = -1;
|
nickjillings@1324
|
654 }
|
nickjillings@1324
|
655 return;
|
nickjillings@1324
|
656 }
|
nickjillings@1324
|
657 if (inputs[i].checked == true) {
|
nickjillings@1324
|
658 node.response = node.specification.options[i];
|
nickjillings@1324
|
659 console.log("Selected: "+ node.specification.options[i].name);
|
nickjillings@1318
|
660 }
|
nickjillings@1318
|
661 i++;
|
nickjillings@1318
|
662 }
|
nickjillings@1324
|
663 } else if (node.specification.type == "number") {
|
nickjillings@1318
|
664 var input = this.popupContent.getElementsByTagName('input')[0];
|
nickjillings@1318
|
665 if (node.mandatory == true && input.value.length == 0) {
|
nickjillings@1318
|
666 alert('This question is mandatory. Please enter a number');
|
nickjillings@1318
|
667 return;
|
nickjillings@1318
|
668 }
|
nickjillings@1318
|
669 var enteredNumber = Number(input.value);
|
nickjillings@1318
|
670 if (isNaN(enteredNumber)) {
|
nickjillings@1318
|
671 alert('Please enter a valid number');
|
nickjillings@1318
|
672 return;
|
nickjillings@1318
|
673 }
|
nickjillings@1318
|
674 if (enteredNumber < node.min && node.min != null) {
|
nickjillings@1318
|
675 alert('Number is below the minimum value of '+node.min);
|
nickjillings@1318
|
676 return;
|
nickjillings@1318
|
677 }
|
nickjillings@1318
|
678 if (enteredNumber > node.max && node.max != null) {
|
nickjillings@1318
|
679 alert('Number is above the maximum value of '+node.max);
|
nickjillings@1318
|
680 return;
|
nickjillings@1318
|
681 }
|
nickjillings@1324
|
682 node.response = input.value;
|
nickjillings@1318
|
683 }
|
nickjillings@1318
|
684 this.currentIndex++;
|
nickjillings@1318
|
685 if (this.currentIndex < this.popupOptions.length) {
|
nickjillings@1318
|
686 this.postNode();
|
nickjillings@1318
|
687 } else {
|
nickjillings@1318
|
688 // Reached the end of the popupOptions
|
nickjillings@1318
|
689 this.hidePopup();
|
nickjillings@1324
|
690 for (var node of this.popupOptions)
|
nickjillings@1324
|
691 {
|
nickjillings@1324
|
692 this.store.postResult(node);
|
nickjillings@1318
|
693 }
|
nickjillings@1318
|
694 advanceState();
|
nickjillings@1318
|
695 }
|
nickjillings@1318
|
696 };
|
nickjillings@1318
|
697
|
nickjillings@1318
|
698 this.previousClick = function() {
|
nickjillings@1318
|
699 // Triggered when the 'Back' button is clicked in the survey
|
nickjillings@1318
|
700 if (this.currentIndex > 0) {
|
nickjillings@1318
|
701 this.currentIndex--;
|
nickjillings@1318
|
702 this.postNode();
|
nickjillings@1318
|
703 }
|
nickjillings@1318
|
704 };
|
nickjillings@1318
|
705
|
nickjillings@1318
|
706 this.resize = function(event)
|
nickjillings@1318
|
707 {
|
nickjillings@1318
|
708 // Called on window resize;
|
nickjillings@1344
|
709 if (this.popup != null) {
|
nickjillings@1344
|
710 this.popup.style.left = (window.innerWidth/2)-250 + 'px';
|
nickjillings@1344
|
711 this.popup.style.top = (window.innerHeight/2)-125 + 'px';
|
nickjillings@1344
|
712 var blank = document.getElementsByClassName('testHalt')[0];
|
nickjillings@1344
|
713 blank.style.width = window.innerWidth;
|
nickjillings@1344
|
714 blank.style.height = window.innerHeight;
|
nickjillings@1344
|
715 }
|
nickjillings@1318
|
716 };
|
nickjillings@1318
|
717 }
|
nickjillings@1318
|
718
|
nickjillings@1318
|
719 function advanceState()
|
nickjillings@1318
|
720 {
|
nickjillings@1318
|
721 // Just for complete clarity
|
nickjillings@1318
|
722 testState.advanceState();
|
nickjillings@1318
|
723 }
|
nickjillings@1318
|
724
|
nickjillings@1318
|
725 function stateMachine()
|
nickjillings@1318
|
726 {
|
nickjillings@1318
|
727 // Object prototype for tracking and managing the test state
|
nickjillings@1318
|
728 this.stateMap = [];
|
nickjillings@1324
|
729 this.preTestSurvey = null;
|
nickjillings@1324
|
730 this.postTestSurvey = null;
|
nickjillings@1318
|
731 this.stateIndex = null;
|
nickjillings@1324
|
732 this.currentStateMap = null;
|
nickjillings@1324
|
733 this.currentStatePosition = null;
|
nickjillings@1354
|
734 this.currentStore = null;
|
nickjillings@1318
|
735 this.initialise = function(){
|
nickjillings@1324
|
736
|
nickjillings@1324
|
737 // Get the data from Specification
|
nickjillings@1324
|
738 var pageHolder = [];
|
nickjillings@1324
|
739 for (var page of specification.pages)
|
nickjillings@1324
|
740 {
|
nickjillings@1380
|
741 var repeat = page.repeatCount;
|
nickjillings@1380
|
742 while(repeat >= 0)
|
nickjillings@1380
|
743 {
|
nickjillings@1380
|
744 pageHolder.push(page);
|
nickjillings@1380
|
745 repeat--;
|
nickjillings@1380
|
746 }
|
nickjillings@1324
|
747 }
|
nickjillings@1324
|
748 if (specification.randomiseOrder)
|
nickjillings@1324
|
749 {
|
nickjillings@1324
|
750 pageHolder = randomiseOrder(pageHolder);
|
nickjillings@1324
|
751 }
|
nickjillings@1324
|
752 for (var i=0; i<pageHolder.length; i++)
|
nickjillings@1324
|
753 {
|
nickjillings@1324
|
754 pageHolder[i].presentedId = i;
|
nickjillings@1324
|
755 }
|
nickjillings@1324
|
756 for (var i=0; i<specification.pages.length; i++)
|
nickjillings@1324
|
757 {
|
nickjillings@1324
|
758 if (specification.testPages < i && specification.testPages != 0) {break;}
|
nickjillings@1324
|
759 this.stateMap.push(pageHolder[i]);
|
nickjillings@1324
|
760
|
nickjillings@1324
|
761 }
|
nickjillings@1324
|
762 if (specification.preTest != null) {this.preTestSurvey = specification.preTest;}
|
nickjillings@1324
|
763 if (specification.postTest != null) {this.postTestSurvey = specification.postTest;}
|
nickjillings@1324
|
764
|
nickjillings@1318
|
765 if (this.stateMap.length > 0) {
|
nickjillings@1318
|
766 if(this.stateIndex != null) {
|
nickjillings@1318
|
767 console.log('NOTE - State already initialise');
|
nickjillings@1318
|
768 }
|
nickjillings@1318
|
769 this.stateIndex = -1;
|
nickjillings@1318
|
770 } else {
|
nickjillings@1318
|
771 console.log('FATAL - StateMap not correctly constructed. EMPTY_STATE_MAP');
|
nickjillings@1318
|
772 }
|
nickjillings@1318
|
773 };
|
nickjillings@1318
|
774 this.advanceState = function(){
|
nickjillings@1318
|
775 if (this.stateIndex == null) {
|
nickjillings@1318
|
776 this.initialise();
|
nickjillings@1318
|
777 }
|
nickjillings@1318
|
778 if (this.stateIndex == -1) {
|
nickjillings@1342
|
779 this.stateIndex++;
|
nickjillings@1318
|
780 console.log('Starting test...');
|
nickjillings@1324
|
781 if (this.preTestSurvey != null)
|
nickjillings@1324
|
782 {
|
nickjillings@1324
|
783 popup.initState(this.preTestSurvey,storage.globalPreTest);
|
nickjillings@1342
|
784 } else {
|
nickjillings@1342
|
785 this.advanceState();
|
nickjillings@1318
|
786 }
|
nickjillings@1324
|
787 } else if (this.stateIndex == this.stateMap.length)
|
nickjillings@1324
|
788 {
|
nickjillings@1324
|
789 // All test pages complete, post test
|
nickjillings@1324
|
790 console.log('Ending test ...');
|
nickjillings@1324
|
791 this.stateIndex++;
|
nickjillings@1324
|
792 if (this.postTestSurvey == null) {
|
nickjillings@1324
|
793 this.advanceState();
|
nickjillings@1318
|
794 } else {
|
nickjillings@1324
|
795 popup.initState(this.postTestSurvey,storage.globalPostTest);
|
nickjillings@1324
|
796 }
|
nickjillings@1324
|
797 } else if (this.stateIndex > this.stateMap.length)
|
nickjillings@1324
|
798 {
|
nickjillings@1324
|
799 createProjectSave(specification.projectReturn);
|
nickjillings@1324
|
800 }
|
nickjillings@1324
|
801 else
|
nickjillings@1324
|
802 {
|
nickjillings@1324
|
803 if (this.currentStateMap == null)
|
nickjillings@1324
|
804 {
|
nickjillings@1318
|
805 this.currentStateMap = this.stateMap[this.stateIndex];
|
nickjillings@1334
|
806 if (this.currentStateMap.randomiseOrder)
|
nickjillings@1334
|
807 {
|
nickjillings@1334
|
808 this.currentStateMap.audioElements = randomiseOrder(this.currentStateMap.audioElements);
|
nickjillings@1334
|
809 }
|
nickjillings@1354
|
810 this.currentStore = storage.createTestPageStore(this.currentStateMap);
|
nickjillings@1324
|
811 if (this.currentStateMap.preTest != null)
|
nickjillings@1324
|
812 {
|
nickjillings@1324
|
813 this.currentStatePosition = 'pre';
|
nickjillings@1324
|
814 popup.initState(this.currentStateMap.preTest,storage.testPages[this.stateIndex].preTest);
|
nickjillings@1318
|
815 } else {
|
nickjillings@1324
|
816 this.currentStatePosition = 'test';
|
nickjillings@1324
|
817 }
|
nickjillings@1324
|
818 interfaceContext.newPage(this.currentStateMap,storage.testPages[this.stateIndex]);
|
nickjillings@1324
|
819 return;
|
nickjillings@1324
|
820 }
|
nickjillings@1324
|
821 switch(this.currentStatePosition)
|
nickjillings@1324
|
822 {
|
nickjillings@1324
|
823 case 'pre':
|
nickjillings@1324
|
824 this.currentStatePosition = 'test';
|
nickjillings@1324
|
825 break;
|
nickjillings@1324
|
826 case 'test':
|
nickjillings@1324
|
827 this.currentStatePosition = 'post';
|
nickjillings@1324
|
828 // Save the data
|
nickjillings@1324
|
829 this.testPageCompleted();
|
nickjillings@1324
|
830 if (this.currentStateMap.postTest == null)
|
nickjillings@1324
|
831 {
|
nickjillings@1318
|
832 this.advanceState();
|
nickjillings@1324
|
833 return;
|
nickjillings@1324
|
834 } else {
|
nickjillings@1324
|
835 popup.initState(this.currentStateMap.postTest,storage.testPages[this.stateIndex].postTest);
|
nickjillings@1318
|
836 }
|
nickjillings@1324
|
837 break;
|
nickjillings@1324
|
838 case 'post':
|
nickjillings@1324
|
839 this.stateIndex++;
|
nickjillings@1324
|
840 this.currentStateMap = null;
|
nickjillings@1324
|
841 this.advanceState();
|
nickjillings@1324
|
842 break;
|
nickjillings@1324
|
843 };
|
nickjillings@1318
|
844 }
|
nickjillings@1318
|
845 };
|
nickjillings@1318
|
846
|
nickjillings@1324
|
847 this.testPageCompleted = function() {
|
nickjillings@1318
|
848 // Function called each time a test page has been completed
|
nickjillings@1324
|
849 var storePoint = storage.testPages[this.stateIndex];
|
nickjillings@1324
|
850 // First get the test metric
|
nickjillings@1324
|
851
|
nickjillings@1324
|
852 var metric = storePoint.XMLDOM.getElementsByTagName('metric')[0];
|
nickjillings@1318
|
853 if (audioEngineContext.metric.enableTestTimer)
|
nickjillings@1318
|
854 {
|
nickjillings@1324
|
855 var testTime = storePoint.parent.document.createElement('metricresult');
|
nickjillings@1318
|
856 testTime.id = 'testTime';
|
nickjillings@1318
|
857 testTime.textContent = audioEngineContext.timer.testDuration;
|
nickjillings@1318
|
858 metric.appendChild(testTime);
|
nickjillings@1318
|
859 }
|
nickjillings@1324
|
860
|
nickjillings@1318
|
861 var audioObjects = audioEngineContext.audioObjects;
|
nickjillings@1324
|
862 for (var ao of audioEngineContext.audioObjects)
|
nickjillings@1318
|
863 {
|
nickjillings@1324
|
864 ao.exportXMLDOM();
|
nickjillings@1318
|
865 }
|
nickjillings@1324
|
866 for (var element of interfaceContext.commentQuestions)
|
nickjillings@1324
|
867 {
|
nickjillings@1324
|
868 element.exportXMLDOM(storePoint);
|
nickjillings@1324
|
869 }
|
nickjillings@1324
|
870 pageXMLSave(storePoint.XMLDOM, this.currentStateMap);
|
nickjillings@1318
|
871 };
|
nickjillings@1318
|
872 }
|
nickjillings@1318
|
873
|
nickjillings@1318
|
874 function AudioEngine(specification) {
|
nickjillings@1318
|
875
|
nickjillings@1318
|
876 // Create two output paths, the main outputGain and fooGain.
|
nickjillings@1318
|
877 // Output gain is default to 1 and any items for playback route here
|
nickjillings@1318
|
878 // Foo gain is used for analysis to ensure paths get processed, but are not heard
|
nickjillings@1318
|
879 // because web audio will optimise and any route which does not go to the destination gets ignored.
|
nickjillings@1318
|
880 this.outputGain = audioContext.createGain();
|
nickjillings@1318
|
881 this.fooGain = audioContext.createGain();
|
nickjillings@1318
|
882 this.fooGain.gain = 0;
|
nickjillings@1318
|
883
|
nickjillings@1318
|
884 // Use this to detect playback state: 0 - stopped, 1 - playing
|
nickjillings@1318
|
885 this.status = 0;
|
nickjillings@1318
|
886
|
nickjillings@1318
|
887 // Connect both gains to output
|
nickjillings@1318
|
888 this.outputGain.connect(audioContext.destination);
|
nickjillings@1318
|
889 this.fooGain.connect(audioContext.destination);
|
nickjillings@1318
|
890
|
nickjillings@1318
|
891 // Create the timer Object
|
nickjillings@1318
|
892 this.timer = new timer();
|
nickjillings@1318
|
893 // Create session metrics
|
nickjillings@1318
|
894 this.metric = new sessionMetrics(this,specification);
|
nickjillings@1318
|
895
|
nickjillings@1318
|
896 this.loopPlayback = false;
|
nickjillings@1318
|
897
|
nickjillings@1324
|
898 this.pageStore = null;
|
nickjillings@1324
|
899
|
nickjillings@1318
|
900 // Create store for new audioObjects
|
nickjillings@1318
|
901 this.audioObjects = [];
|
nickjillings@1318
|
902
|
nickjillings@1318
|
903 this.buffers = [];
|
nickjillings@1318
|
904 this.bufferObj = function()
|
nickjillings@1318
|
905 {
|
nickjillings@1318
|
906 this.url = null;
|
nickjillings@1318
|
907 this.buffer = null;
|
nickjillings@1318
|
908 this.xmlRequest = new XMLHttpRequest();
|
nickjillings@1318
|
909 this.xmlRequest.parent = this;
|
nickjillings@1318
|
910 this.users = [];
|
nickjillings@1316
|
911 this.progress = 0;
|
nickjillings@1316
|
912 this.status = 0;
|
nickjillings@1342
|
913 this.ready = function()
|
nickjillings@1342
|
914 {
|
nickjillings@1316
|
915 if (this.status >= 2)
|
nickjillings@1316
|
916 {
|
nickjillings@1316
|
917 this.status = 3;
|
nickjillings@1316
|
918 }
|
nickjillings@1342
|
919 for (var i=0; i<this.users.length; i++)
|
nickjillings@1342
|
920 {
|
nickjillings@1342
|
921 this.users[i].state = 1;
|
nickjillings@1342
|
922 if (this.users[i].interfaceDOM != null)
|
nickjillings@1342
|
923 {
|
nickjillings@1342
|
924 this.users[i].bufferLoaded(this);
|
nickjillings@1342
|
925 }
|
nickjillings@1342
|
926 }
|
nickjillings@1342
|
927 };
|
nickjillings@1318
|
928 this.getMedia = function(url) {
|
nickjillings@1318
|
929 this.url = url;
|
nickjillings@1318
|
930 this.xmlRequest.open('GET',this.url,true);
|
nickjillings@1318
|
931 this.xmlRequest.responseType = 'arraybuffer';
|
nickjillings@1318
|
932
|
nickjillings@1318
|
933 var bufferObj = this;
|
nickjillings@1318
|
934
|
nickjillings@1318
|
935 // Create callback to decode the data asynchronously
|
nickjillings@1318
|
936 this.xmlRequest.onloadend = function() {
|
nickjillings@1353
|
937 // Use inbuilt WAVE decoder first
|
nickjillings@1353
|
938 var waveObj = new WAVE();
|
nickjillings@1353
|
939 if (waveObj.open(bufferObj.xmlRequest.response) == 0)
|
nickjillings@1353
|
940 {
|
nickjillings@1353
|
941 bufferObj.buffer = audioContext.createBuffer(waveObj.num_channels,waveObj.num_samples,waveObj.sample_rate);
|
nickjillings@1353
|
942 for (var c=0; c<waveObj.num_channels; c++)
|
nickjillings@1353
|
943 {
|
nickjillings@1353
|
944 var buffer_ptr = bufferObj.buffer.getChannelData(c);
|
nickjillings@1353
|
945 for (var n=0; n<waveObj.num_samples; n++)
|
nickjillings@1353
|
946 {
|
nickjillings@1353
|
947 buffer_ptr[n] = waveObj.decoded_data[c][n];
|
nickjillings@1353
|
948 }
|
nickjillings@1353
|
949 }
|
nickjillings@1316
|
950
|
nickjillings@1353
|
951 delete waveObj;
|
nickjillings@1353
|
952 } else {
|
nickjillings@1353
|
953 audioContext.decodeAudioData(bufferObj.xmlRequest.response, function(decodedData) {
|
nickjillings@1353
|
954 bufferObj.buffer = decodedData;
|
nickjillings@1353
|
955 }, function(e){
|
nickjillings@1353
|
956 // Should only be called if there was an error, but sometimes gets called continuously
|
nickjillings@1353
|
957 // Check here if the error is genuine
|
nickjillings@1353
|
958 if (bufferObj.xmlRequest.response == undefined) {
|
nickjillings@1353
|
959 // Genuine error
|
nickjillings@1353
|
960 console.log('FATAL - Error loading buffer on '+audioObj.id);
|
nickjillings@1353
|
961 if (request.status == 404)
|
nickjillings@1353
|
962 {
|
nickjillings@1353
|
963 console.log('FATAL - Fragment '+audioObj.id+' 404 error');
|
nickjillings@1353
|
964 console.log('URL: '+audioObj.url);
|
nickjillings@1353
|
965 errorSessionDump('Fragment '+audioObj.id+' 404 error');
|
nickjillings@1353
|
966 }
|
nickjillings@1316
|
967 this.status = -1;
|
nickjillings@1353
|
968 }
|
nickjillings@1353
|
969 });
|
nickjillings@1353
|
970 }
|
nickjillings@1353
|
971 if (bufferObj.buffer != undefined)
|
nickjillings@1353
|
972 {
|
nickjillings@1316
|
973 bufferObj.status = 2;
|
nickjillings@1353
|
974 calculateLoudness(bufferObj,"I");
|
nickjillings@1353
|
975 }
|
nickjillings@1318
|
976 };
|
nickjillings@1318
|
977 this.progress = 0;
|
nickjillings@1318
|
978 this.progressCallback = function(event){
|
nickjillings@1318
|
979 if (event.lengthComputable)
|
nickjillings@1318
|
980 {
|
nickjillings@1318
|
981 this.parent.progress = event.loaded / event.total;
|
nickjillings@1318
|
982 for (var i=0; i<this.parent.users.length; i++)
|
nickjillings@1318
|
983 {
|
nickjillings@1318
|
984 if(this.parent.users[i].interfaceDOM != null)
|
nickjillings@1318
|
985 {
|
nickjillings@1318
|
986 if (typeof this.parent.users[i].interfaceDOM.updateLoading === "function")
|
nickjillings@1318
|
987 {
|
nickjillings@1318
|
988 this.parent.users[i].interfaceDOM.updateLoading(this.parent.progress*100);
|
nickjillings@1318
|
989 }
|
nickjillings@1318
|
990 }
|
nickjillings@1318
|
991 }
|
nickjillings@1318
|
992 }
|
nickjillings@1318
|
993 };
|
nickjillings@1318
|
994 this.xmlRequest.addEventListener("progress", this.progressCallback);
|
nickjillings@1316
|
995 this.status = 1;
|
nickjillings@1318
|
996 this.xmlRequest.send();
|
nickjillings@1318
|
997 };
|
nickjillings@1316
|
998
|
nickjillings@1316
|
999 this.registerAudioObject = function(audioObject)
|
nickjillings@1316
|
1000 {
|
nickjillings@1316
|
1001 // Called by an audioObject to register to the buffer for use
|
nickjillings@1316
|
1002 // First check if already in the register pool
|
nickjillings@1316
|
1003 for (var objects of this.users)
|
nickjillings@1316
|
1004 {
|
nickjillings@1316
|
1005 if (audioObject.id == objects.id){return 0;}
|
nickjillings@1316
|
1006 }
|
nickjillings@1316
|
1007 this.users.push(audioObject);
|
nickjillings@1316
|
1008 if (this.status == 3)
|
nickjillings@1316
|
1009 {
|
nickjillings@1316
|
1010 // The buffer is already ready, trigger bufferLoaded
|
nickjillings@1316
|
1011 audioObject.bufferLoaded(this);
|
nickjillings@1316
|
1012 }
|
nickjillings@1316
|
1013 }
|
nickjillings@1318
|
1014 };
|
nickjillings@1318
|
1015
|
nickjillings@1318
|
1016 this.play = function(id) {
|
nickjillings@1318
|
1017 // Start the timer and set the audioEngine state to playing (1)
|
nickjillings@1318
|
1018 if (this.status == 0 && this.loopPlayback) {
|
nickjillings@1318
|
1019 // Check if all audioObjects are ready
|
nickjillings@1318
|
1020 if(this.checkAllReady())
|
nickjillings@1318
|
1021 {
|
nickjillings@1318
|
1022 this.status = 1;
|
nickjillings@1318
|
1023 this.setSynchronousLoop();
|
nickjillings@1318
|
1024 }
|
nickjillings@1318
|
1025 }
|
nickjillings@1318
|
1026 else
|
nickjillings@1318
|
1027 {
|
nickjillings@1318
|
1028 this.status = 1;
|
nickjillings@1318
|
1029 }
|
nickjillings@1318
|
1030 if (this.status== 1) {
|
nickjillings@1318
|
1031 this.timer.startTest();
|
nickjillings@1318
|
1032 if (id == undefined) {
|
nickjillings@1318
|
1033 id = -1;
|
nickjillings@1318
|
1034 console.log('FATAL - Passed id was undefined - AudioEngineContext.play(id)');
|
nickjillings@1318
|
1035 return;
|
nickjillings@1318
|
1036 } else {
|
nickjillings@1318
|
1037 interfaceContext.playhead.setTimePerPixel(this.audioObjects[id]);
|
nickjillings@1318
|
1038 }
|
nickjillings@1318
|
1039 if (this.loopPlayback) {
|
nickjillings@1360
|
1040 var setTime = audioContext.currentTime+2;
|
nickjillings@1318
|
1041 for (var i=0; i<this.audioObjects.length; i++)
|
nickjillings@1318
|
1042 {
|
nickjillings@1360
|
1043 this.audioObjects[i].play(setTime-2);
|
nickjillings@1318
|
1044 if (id == i) {
|
nickjillings@1360
|
1045 this.audioObjects[i].loopStart(setTime);
|
nickjillings@1318
|
1046 } else {
|
nickjillings@1360
|
1047 this.audioObjects[i].loopStop(setTime);
|
nickjillings@1318
|
1048 }
|
nickjillings@1318
|
1049 }
|
nickjillings@1318
|
1050 } else {
|
nickjillings@1360
|
1051 var setTime = audioContext.currentTime+0.1;
|
nickjillings@1318
|
1052 for (var i=0; i<this.audioObjects.length; i++)
|
nickjillings@1318
|
1053 {
|
nickjillings@1318
|
1054 if (i != id) {
|
nickjillings@1360
|
1055 this.audioObjects[i].stop(setTime);
|
nickjillings@1318
|
1056 } else if (i == id) {
|
nickjillings@1360
|
1057 this.audioObjects[id].play(setTime);
|
nickjillings@1318
|
1058 }
|
nickjillings@1318
|
1059 }
|
nickjillings@1318
|
1060 }
|
nickjillings@1318
|
1061 interfaceContext.playhead.start();
|
nickjillings@1318
|
1062 }
|
nickjillings@1318
|
1063 };
|
nickjillings@1318
|
1064
|
nickjillings@1318
|
1065 this.stop = function() {
|
nickjillings@1378
|
1066 // Send stop and reset command to all playback buffers
|
nickjillings@1318
|
1067 if (this.status == 1) {
|
nickjillings@1360
|
1068 var setTime = audioContext.currentTime+0.1;
|
nickjillings@1318
|
1069 for (var i=0; i<this.audioObjects.length; i++)
|
nickjillings@1318
|
1070 {
|
nickjillings@1360
|
1071 this.audioObjects[i].stop(setTime);
|
nickjillings@1318
|
1072 }
|
nickjillings@1318
|
1073 interfaceContext.playhead.stop();
|
nickjillings@1318
|
1074 }
|
nickjillings@1318
|
1075 };
|
nickjillings@1318
|
1076
|
nickjillings@1318
|
1077 this.newTrack = function(element) {
|
nickjillings@1318
|
1078 // Pull data from given URL into new audio buffer
|
nickjillings@1318
|
1079 // URLs must either be from the same source OR be setup to 'Access-Control-Allow-Origin'
|
nickjillings@1318
|
1080
|
nickjillings@1318
|
1081 // Create the audioObject with ID of the new track length;
|
nickjillings@1318
|
1082 audioObjectId = this.audioObjects.length;
|
nickjillings@1318
|
1083 this.audioObjects[audioObjectId] = new audioObject(audioObjectId);
|
nickjillings@1318
|
1084
|
nickjillings@1318
|
1085 // Check if audioObject buffer is currently stored by full URL
|
nickjillings@1324
|
1086 var URL = testState.currentStateMap.hostURL + element.url;
|
nickjillings@1318
|
1087 var buffer = null;
|
nickjillings@1318
|
1088 for (var i=0; i<this.buffers.length; i++)
|
nickjillings@1318
|
1089 {
|
nickjillings@1318
|
1090 if (URL == this.buffers[i].url)
|
nickjillings@1318
|
1091 {
|
nickjillings@1318
|
1092 buffer = this.buffers[i];
|
nickjillings@1318
|
1093 break;
|
nickjillings@1318
|
1094 }
|
nickjillings@1318
|
1095 }
|
nickjillings@1318
|
1096 if (buffer == null)
|
nickjillings@1318
|
1097 {
|
nickjillings@1318
|
1098 console.log("[WARN]: Buffer was not loaded in pre-test! "+URL);
|
nickjillings@1318
|
1099 buffer = new this.bufferObj();
|
nickjillings@1316
|
1100 this.buffers.push(buffer);
|
nickjillings@1318
|
1101 buffer.getMedia(URL);
|
nickjillings@1318
|
1102 }
|
nickjillings@1318
|
1103 this.audioObjects[audioObjectId].specification = element;
|
nickjillings@1318
|
1104 this.audioObjects[audioObjectId].url = URL;
|
nickjillings@1324
|
1105 // Obtain store node
|
nickjillings@1324
|
1106 var aeNodes = this.pageStore.XMLDOM.getElementsByTagName('audioelement');
|
nickjillings@1324
|
1107 for (var i=0; i<aeNodes.length; i++)
|
nickjillings@1324
|
1108 {
|
nickjillings@1324
|
1109 if(aeNodes[i].id == element.id)
|
nickjillings@1324
|
1110 {
|
nickjillings@1324
|
1111 this.audioObjects[audioObjectId].storeDOM = aeNodes[i];
|
nickjillings@1324
|
1112 break;
|
nickjillings@1324
|
1113 }
|
nickjillings@1324
|
1114 }
|
nickjillings@1316
|
1115 buffer.registerAudioObject(this.audioObjects[audioObjectId]);
|
nickjillings@1318
|
1116 return this.audioObjects[audioObjectId];
|
nickjillings@1318
|
1117 };
|
nickjillings@1318
|
1118
|
nickjillings@1369
|
1119 this.newTestPage = function(audioHolderObject,store) {
|
nickjillings@1324
|
1120 this.pageStore = store;
|
nickjillings@1318
|
1121 this.state = 0;
|
nickjillings@1318
|
1122 this.audioObjectsReady = false;
|
nickjillings@1318
|
1123 this.metric.reset();
|
nickjillings@1318
|
1124 for (var i=0; i < this.buffers.length; i++)
|
nickjillings@1318
|
1125 {
|
nickjillings@1318
|
1126 this.buffers[i].users = [];
|
nickjillings@1318
|
1127 }
|
nickjillings@1318
|
1128 this.audioObjects = [];
|
nickjillings@1369
|
1129 this.timer = new timer();
|
nickjillings@1369
|
1130 this.loopPlayback = audioHolderObject.loop;
|
nickjillings@1318
|
1131 };
|
nickjillings@1318
|
1132
|
nickjillings@1318
|
1133 this.checkAllPlayed = function() {
|
nickjillings@1318
|
1134 arr = [];
|
nickjillings@1318
|
1135 for (var id=0; id<this.audioObjects.length; id++) {
|
nickjillings@1318
|
1136 if (this.audioObjects[id].metric.wasListenedTo == false) {
|
nickjillings@1318
|
1137 arr.push(this.audioObjects[id].id);
|
nickjillings@1318
|
1138 }
|
nickjillings@1318
|
1139 }
|
nickjillings@1318
|
1140 return arr;
|
nickjillings@1318
|
1141 };
|
nickjillings@1318
|
1142
|
nickjillings@1318
|
1143 this.checkAllReady = function() {
|
nickjillings@1318
|
1144 var ready = true;
|
nickjillings@1318
|
1145 for (var i=0; i<this.audioObjects.length; i++) {
|
nickjillings@1318
|
1146 if (this.audioObjects[i].state == 0) {
|
nickjillings@1318
|
1147 // Track not ready
|
nickjillings@1318
|
1148 console.log('WAIT -- audioObject '+i+' not ready yet!');
|
nickjillings@1318
|
1149 ready = false;
|
nickjillings@1318
|
1150 };
|
nickjillings@1318
|
1151 }
|
nickjillings@1318
|
1152 return ready;
|
nickjillings@1318
|
1153 };
|
nickjillings@1318
|
1154
|
nickjillings@1318
|
1155 this.setSynchronousLoop = function() {
|
nickjillings@1318
|
1156 // Pads the signals so they are all exactly the same length
|
nickjillings@1318
|
1157 var length = 0;
|
nickjillings@1318
|
1158 var maxId;
|
nickjillings@1318
|
1159 for (var i=0; i<this.audioObjects.length; i++)
|
nickjillings@1318
|
1160 {
|
nickjillings@1318
|
1161 if (length < this.audioObjects[i].buffer.buffer.length)
|
nickjillings@1318
|
1162 {
|
nickjillings@1318
|
1163 length = this.audioObjects[i].buffer.buffer.length;
|
nickjillings@1318
|
1164 maxId = i;
|
nickjillings@1318
|
1165 }
|
nickjillings@1318
|
1166 }
|
nickjillings@1318
|
1167 // Extract the audio and zero-pad
|
nickjillings@1318
|
1168 for (var i=0; i<this.audioObjects.length; i++)
|
nickjillings@1318
|
1169 {
|
nickjillings@1318
|
1170 var orig = this.audioObjects[i].buffer.buffer;
|
nickjillings@1318
|
1171 var hold = audioContext.createBuffer(orig.numberOfChannels,length,orig.sampleRate);
|
nickjillings@1318
|
1172 for (var c=0; c<orig.numberOfChannels; c++)
|
nickjillings@1318
|
1173 {
|
nickjillings@1318
|
1174 var inData = hold.getChannelData(c);
|
nickjillings@1318
|
1175 var outData = orig.getChannelData(c);
|
nickjillings@1318
|
1176 for (var n=0; n<orig.length; n++)
|
nickjillings@1318
|
1177 {inData[n] = outData[n];}
|
nickjillings@1318
|
1178 }
|
nickjillings@1320
|
1179 hold.playbackGain = orig.playbackGain;
|
nickjillings@1318
|
1180 hold.lufs = orig.lufs;
|
nickjillings@1318
|
1181 this.audioObjects[i].buffer.buffer = hold;
|
nickjillings@1318
|
1182 }
|
nickjillings@1318
|
1183 };
|
nickjillings@1370
|
1184
|
nickjillings@1370
|
1185 this.exportXML = function()
|
nickjillings@1370
|
1186 {
|
nickjillings@1370
|
1187
|
nickjillings@1370
|
1188 };
|
nickjillings@1318
|
1189
|
nickjillings@1318
|
1190 }
|
nickjillings@1318
|
1191
|
nickjillings@1318
|
1192 function audioObject(id) {
|
nickjillings@1318
|
1193 // The main buffer object with common control nodes to the AudioEngine
|
nickjillings@1318
|
1194
|
nickjillings@1318
|
1195 this.specification;
|
nickjillings@1318
|
1196 this.id = id;
|
nickjillings@1318
|
1197 this.state = 0; // 0 - no data, 1 - ready
|
nickjillings@1318
|
1198 this.url = null; // Hold the URL given for the output back to the results.
|
nickjillings@1318
|
1199 this.metric = new metricTracker(this);
|
nickjillings@1324
|
1200 this.storeDOM = null;
|
nickjillings@1318
|
1201
|
nickjillings@1318
|
1202 // Bindings for GUI
|
nickjillings@1318
|
1203 this.interfaceDOM = null;
|
nickjillings@1318
|
1204 this.commentDOM = null;
|
nickjillings@1318
|
1205
|
nickjillings@1318
|
1206 // Create a buffer and external gain control to allow internal patching of effects and volume leveling.
|
nickjillings@1318
|
1207 this.bufferNode = undefined;
|
nickjillings@1318
|
1208 this.outputGain = audioContext.createGain();
|
nickjillings@1318
|
1209
|
nickjillings@1324
|
1210 this.onplayGain = 1.0;
|
nickjillings@1318
|
1211
|
nickjillings@1318
|
1212 // Connect buffer to the audio graph
|
nickjillings@1318
|
1213 this.outputGain.connect(audioEngineContext.outputGain);
|
nickjillings@1318
|
1214
|
nickjillings@1318
|
1215 // the audiobuffer is not designed for multi-start playback
|
nickjillings@1318
|
1216 // When stopeed, the buffer node is deleted and recreated with the stored buffer.
|
nickjillings@1318
|
1217 this.buffer;
|
nickjillings@1318
|
1218
|
nickjillings@1318
|
1219 this.bufferLoaded = function(callee)
|
nickjillings@1318
|
1220 {
|
nickjillings@1318
|
1221 // Called by the associated buffer when it has finished loading, will then 'bind' the buffer to the
|
nickjillings@1318
|
1222 // audioObject and trigger the interfaceDOM.enable() function for user feedback
|
nickjillings@1318
|
1223 if (audioEngineContext.loopPlayback){
|
nickjillings@1318
|
1224 // First copy the buffer into this.buffer
|
nickjillings@1318
|
1225 this.buffer = new audioEngineContext.bufferObj();
|
nickjillings@1318
|
1226 this.buffer.url = callee.url;
|
nickjillings@1318
|
1227 this.buffer.buffer = audioContext.createBuffer(callee.buffer.numberOfChannels, callee.buffer.length, callee.buffer.sampleRate);
|
nickjillings@1318
|
1228 for (var c=0; c<callee.buffer.numberOfChannels; c++)
|
nickjillings@1318
|
1229 {
|
nickjillings@1318
|
1230 var src = callee.buffer.getChannelData(c);
|
nickjillings@1318
|
1231 var dst = this.buffer.buffer.getChannelData(c);
|
nickjillings@1318
|
1232 for (var n=0; n<src.length; n++)
|
nickjillings@1318
|
1233 {
|
nickjillings@1318
|
1234 dst[n] = src[n];
|
nickjillings@1318
|
1235 }
|
nickjillings@1318
|
1236 }
|
nickjillings@1318
|
1237 } else {
|
nickjillings@1318
|
1238 this.buffer = callee;
|
nickjillings@1318
|
1239 }
|
nickjillings@1318
|
1240 this.state = 1;
|
nickjillings@1320
|
1241 this.buffer.buffer.playbackGain = callee.buffer.playbackGain;
|
nickjillings@1318
|
1242 this.buffer.buffer.lufs = callee.buffer.lufs;
|
nickjillings@1348
|
1243 var targetLUFS = this.specification.parent.loudness || specification.loudness;
|
nickjillings@1318
|
1244 if (typeof targetLUFS === "number")
|
nickjillings@1318
|
1245 {
|
nickjillings@1320
|
1246 this.buffer.buffer.playbackGain = decibelToLinear(targetLUFS - this.buffer.buffer.lufs);
|
nickjillings@1318
|
1247 } else {
|
nickjillings@1320
|
1248 this.buffer.buffer.playbackGain = 1.0;
|
nickjillings@1318
|
1249 }
|
nickjillings@1318
|
1250 if (this.interfaceDOM != null) {
|
nickjillings@1318
|
1251 this.interfaceDOM.enable();
|
nickjillings@1318
|
1252 }
|
nickjillings@1324
|
1253 this.onplayGain = decibelToLinear(this.specification.gain)*this.buffer.buffer.playbackGain;
|
nickjillings@1324
|
1254 this.storeDOM.setAttribute('playGain',linearToDecibel(this.onplayGain));
|
nickjillings@1318
|
1255 };
|
nickjillings@1325
|
1256
|
nickjillings@1325
|
1257 this.bindInterface = function(interfaceObject)
|
nickjillings@1325
|
1258 {
|
nickjillings@1325
|
1259 this.interfaceDOM = interfaceObject;
|
nickjillings@1325
|
1260 this.metric.initialise(interfaceObject.getValue());
|
nickjillings@1325
|
1261 if (this.state == 1)
|
nickjillings@1325
|
1262 {
|
nickjillings@1325
|
1263 this.interfaceDOM.enable();
|
nickjillings@1325
|
1264 }
|
nickjillings@1338
|
1265 this.storeDOM.setAttribute('presentedId',interfaceObject.getPresentedId());
|
nickjillings@1325
|
1266 };
|
nickjillings@1318
|
1267
|
nickjillings@1360
|
1268 this.loopStart = function(setTime) {
|
nickjillings@1360
|
1269 this.outputGain.gain.linearRampToValueAtTime(this.onplayGain,setTime);
|
nickjillings@1318
|
1270 this.metric.startListening(audioEngineContext.timer.getTestTime());
|
nickjillings@1360
|
1271 this.interfaceDOM.startPlayback();
|
nickjillings@1318
|
1272 };
|
nickjillings@1318
|
1273
|
nickjillings@1360
|
1274 this.loopStop = function(setTime) {
|
nickjillings@1318
|
1275 if (this.outputGain.gain.value != 0.0) {
|
nickjillings@1360
|
1276 this.outputGain.gain.linearRampToValueAtTime(0.0,setTime);
|
nickjillings@1318
|
1277 this.metric.stopListening(audioEngineContext.timer.getTestTime());
|
nickjillings@1318
|
1278 }
|
nickjillings@1360
|
1279 this.interfaceDOM.stopPlayback();
|
nickjillings@1318
|
1280 };
|
nickjillings@1318
|
1281
|
nickjillings@1318
|
1282 this.play = function(startTime) {
|
nickjillings@1318
|
1283 if (this.bufferNode == undefined && this.buffer.buffer != undefined) {
|
nickjillings@1318
|
1284 this.bufferNode = audioContext.createBufferSource();
|
nickjillings@1318
|
1285 this.bufferNode.owner = this;
|
nickjillings@1318
|
1286 this.bufferNode.connect(this.outputGain);
|
nickjillings@1318
|
1287 this.bufferNode.buffer = this.buffer.buffer;
|
nickjillings@1318
|
1288 this.bufferNode.loop = audioEngineContext.loopPlayback;
|
nickjillings@1318
|
1289 this.bufferNode.onended = function(event) {
|
nickjillings@1318
|
1290 // Safari does not like using 'this' to reference the calling object!
|
nickjillings@1318
|
1291 //event.currentTarget.owner.metric.stopListening(audioEngineContext.timer.getTestTime(),event.currentTarget.owner.getCurrentPosition());
|
nickjillings@1360
|
1292 event.currentTarget.owner.stop(audioContext.currentTime+1);
|
nickjillings@1318
|
1293 };
|
nickjillings@1318
|
1294 if (this.bufferNode.loop == false) {
|
nickjillings@1318
|
1295 this.metric.startListening(audioEngineContext.timer.getTestTime());
|
nickjillings@1360
|
1296 this.outputGain.gain.setValueAtTime(this.onplayGain,startTime);
|
nickjillings@1360
|
1297 this.interfaceDOM.startPlayback();
|
nickjillings@1360
|
1298 } else {
|
nickjillings@1360
|
1299 this.outputGain.gain.setValueAtTime(0.0,startTime);
|
nickjillings@1360
|
1300 }
|
nickjillings@1318
|
1301 this.bufferNode.start(startTime);
|
nickjillings@1318
|
1302 }
|
nickjillings@1318
|
1303 };
|
nickjillings@1318
|
1304
|
nickjillings@1360
|
1305 this.stop = function(stopTime) {
|
nickjillings@1360
|
1306 this.outputGain.gain.cancelScheduledValues(audioContext.currentTime);
|
nickjillings@1318
|
1307 if (this.bufferNode != undefined)
|
nickjillings@1318
|
1308 {
|
nickjillings@1318
|
1309 this.metric.stopListening(audioEngineContext.timer.getTestTime(),this.getCurrentPosition());
|
nickjillings@1360
|
1310 this.bufferNode.stop(stopTime);
|
nickjillings@1318
|
1311 this.bufferNode = undefined;
|
nickjillings@1318
|
1312 }
|
nickjillings@1360
|
1313 this.outputGain.gain.value = 0.0;
|
nickjillings@1360
|
1314 this.interfaceDOM.stopPlayback();
|
nickjillings@1318
|
1315 };
|
nickjillings@1318
|
1316
|
nickjillings@1318
|
1317 this.getCurrentPosition = function() {
|
nickjillings@1318
|
1318 var time = audioEngineContext.timer.getTestTime();
|
nickjillings@1318
|
1319 if (this.bufferNode != undefined) {
|
nickjillings@1318
|
1320 if (this.bufferNode.loop == true) {
|
nickjillings@1318
|
1321 if (audioEngineContext.status == 1) {
|
nickjillings@1318
|
1322 return (time-this.metric.listenStart)%this.buffer.buffer.duration;
|
nickjillings@1318
|
1323 } else {
|
nickjillings@1318
|
1324 return 0;
|
nickjillings@1318
|
1325 }
|
nickjillings@1318
|
1326 } else {
|
nickjillings@1318
|
1327 if (this.metric.listenHold) {
|
nickjillings@1318
|
1328 return time - this.metric.listenStart;
|
nickjillings@1318
|
1329 } else {
|
nickjillings@1318
|
1330 return 0;
|
nickjillings@1318
|
1331 }
|
nickjillings@1318
|
1332 }
|
nickjillings@1318
|
1333 } else {
|
nickjillings@1318
|
1334 return 0;
|
nickjillings@1318
|
1335 }
|
nickjillings@1318
|
1336 };
|
nickjillings@1318
|
1337
|
nickjillings@1318
|
1338 this.exportXMLDOM = function() {
|
nickjillings@1324
|
1339 var file = storage.document.createElement('file');
|
nickjillings@1318
|
1340 file.setAttribute('sampleRate',this.buffer.buffer.sampleRate);
|
nickjillings@1318
|
1341 file.setAttribute('channels',this.buffer.buffer.numberOfChannels);
|
nickjillings@1318
|
1342 file.setAttribute('sampleCount',this.buffer.buffer.length);
|
nickjillings@1318
|
1343 file.setAttribute('duration',this.buffer.buffer.duration);
|
nickjillings@1324
|
1344 this.storeDOM.appendChild(file);
|
nickjillings@1324
|
1345 if (this.specification.type != 'outside-reference') {
|
nickjillings@1318
|
1346 var interfaceXML = this.interfaceDOM.exportXMLDOM(this);
|
nickjillings@1340
|
1347 if (interfaceXML != null)
|
nickjillings@1340
|
1348 {
|
nickjillings@1340
|
1349 if (interfaceXML.length == undefined) {
|
nickjillings@1340
|
1350 this.storeDOM.appendChild(interfaceXML);
|
nickjillings@1340
|
1351 } else {
|
nickjillings@1340
|
1352 for (var i=0; i<interfaceXML.length; i++)
|
nickjillings@1340
|
1353 {
|
nickjillings@1340
|
1354 this.storeDOM.appendChild(interfaceXML[i]);
|
nickjillings@1340
|
1355 }
|
nickjillings@1318
|
1356 }
|
nickjillings@1318
|
1357 }
|
nickjillings@1330
|
1358 if (this.commentDOM != null) {
|
nickjillings@1330
|
1359 this.storeDOM.appendChild(this.commentDOM.exportXMLDOM(this));
|
nickjillings@1330
|
1360 }
|
nickjillings@1318
|
1361 }
|
nickjillings@1324
|
1362 var nodes = this.metric.exportXMLDOM();
|
nickjillings@1324
|
1363 var mroot = this.storeDOM.getElementsByTagName('metric')[0];
|
nickjillings@1324
|
1364 for (var i=0; i<nodes.length; i++)
|
nickjillings@1324
|
1365 {
|
nickjillings@1324
|
1366 mroot.appendChild(nodes[i]);
|
nickjillings@1324
|
1367 }
|
nickjillings@1318
|
1368 };
|
nickjillings@1318
|
1369 }
|
nickjillings@1318
|
1370
|
nickjillings@1318
|
1371 function timer()
|
nickjillings@1318
|
1372 {
|
nickjillings@1318
|
1373 /* Timer object used in audioEngine to keep track of session timings
|
nickjillings@1318
|
1374 * Uses the timer of the web audio API, so sample resolution
|
nickjillings@1318
|
1375 */
|
nickjillings@1318
|
1376 this.testStarted = false;
|
nickjillings@1318
|
1377 this.testStartTime = 0;
|
nickjillings@1318
|
1378 this.testDuration = 0;
|
nickjillings@1318
|
1379 this.minimumTestTime = 0; // No minimum test time
|
nickjillings@1318
|
1380 this.startTest = function()
|
nickjillings@1318
|
1381 {
|
nickjillings@1318
|
1382 if (this.testStarted == false)
|
nickjillings@1318
|
1383 {
|
nickjillings@1318
|
1384 this.testStartTime = audioContext.currentTime;
|
nickjillings@1318
|
1385 this.testStarted = true;
|
nickjillings@1318
|
1386 this.updateTestTime();
|
nickjillings@1318
|
1387 audioEngineContext.metric.initialiseTest();
|
nickjillings@1318
|
1388 }
|
nickjillings@1318
|
1389 };
|
nickjillings@1318
|
1390 this.stopTest = function()
|
nickjillings@1318
|
1391 {
|
nickjillings@1318
|
1392 if (this.testStarted)
|
nickjillings@1318
|
1393 {
|
nickjillings@1318
|
1394 this.testDuration = this.getTestTime();
|
nickjillings@1318
|
1395 this.testStarted = false;
|
nickjillings@1318
|
1396 } else {
|
nickjillings@1318
|
1397 console.log('ERR: Test tried to end before beginning');
|
nickjillings@1318
|
1398 }
|
nickjillings@1318
|
1399 };
|
nickjillings@1318
|
1400 this.updateTestTime = function()
|
nickjillings@1318
|
1401 {
|
nickjillings@1318
|
1402 if (this.testStarted)
|
nickjillings@1318
|
1403 {
|
nickjillings@1318
|
1404 this.testDuration = audioContext.currentTime - this.testStartTime;
|
nickjillings@1318
|
1405 }
|
nickjillings@1318
|
1406 };
|
nickjillings@1318
|
1407 this.getTestTime = function()
|
nickjillings@1318
|
1408 {
|
nickjillings@1318
|
1409 this.updateTestTime();
|
nickjillings@1318
|
1410 return this.testDuration;
|
nickjillings@1318
|
1411 };
|
nickjillings@1318
|
1412 }
|
nickjillings@1318
|
1413
|
nickjillings@1318
|
1414 function sessionMetrics(engine,specification)
|
nickjillings@1318
|
1415 {
|
nickjillings@1318
|
1416 /* Used by audioEngine to link to audioObjects to minimise the timer call timers;
|
nickjillings@1318
|
1417 */
|
nickjillings@1318
|
1418 this.engine = engine;
|
nickjillings@1318
|
1419 this.lastClicked = -1;
|
nickjillings@1318
|
1420 this.data = -1;
|
nickjillings@1318
|
1421 this.reset = function() {
|
nickjillings@1318
|
1422 this.lastClicked = -1;
|
nickjillings@1318
|
1423 this.data = -1;
|
nickjillings@1318
|
1424 };
|
nickjillings@1318
|
1425
|
nickjillings@1318
|
1426 this.enableElementInitialPosition = false;
|
nickjillings@1318
|
1427 this.enableElementListenTracker = false;
|
nickjillings@1318
|
1428 this.enableElementTimer = false;
|
nickjillings@1318
|
1429 this.enableElementTracker = false;
|
nickjillings@1318
|
1430 this.enableFlagListenedTo = false;
|
nickjillings@1318
|
1431 this.enableFlagMoved = false;
|
nickjillings@1318
|
1432 this.enableTestTimer = false;
|
nickjillings@1318
|
1433 // Obtain the metrics enabled
|
nickjillings@1324
|
1434 for (var i=0; i<specification.metrics.enabled.length; i++)
|
nickjillings@1318
|
1435 {
|
nickjillings@1324
|
1436 var node = specification.metrics.enabled[i];
|
nickjillings@1324
|
1437 switch(node)
|
nickjillings@1318
|
1438 {
|
nickjillings@1318
|
1439 case 'testTimer':
|
nickjillings@1318
|
1440 this.enableTestTimer = true;
|
nickjillings@1318
|
1441 break;
|
nickjillings@1318
|
1442 case 'elementTimer':
|
nickjillings@1318
|
1443 this.enableElementTimer = true;
|
nickjillings@1318
|
1444 break;
|
nickjillings@1318
|
1445 case 'elementTracker':
|
nickjillings@1318
|
1446 this.enableElementTracker = true;
|
nickjillings@1318
|
1447 break;
|
nickjillings@1318
|
1448 case 'elementListenTracker':
|
nickjillings@1318
|
1449 this.enableElementListenTracker = true;
|
nickjillings@1318
|
1450 break;
|
nickjillings@1318
|
1451 case 'elementInitialPosition':
|
nickjillings@1318
|
1452 this.enableElementInitialPosition = true;
|
nickjillings@1318
|
1453 break;
|
nickjillings@1318
|
1454 case 'elementFlagListenedTo':
|
nickjillings@1318
|
1455 this.enableFlagListenedTo = true;
|
nickjillings@1318
|
1456 break;
|
nickjillings@1318
|
1457 case 'elementFlagMoved':
|
nickjillings@1318
|
1458 this.enableFlagMoved = true;
|
nickjillings@1318
|
1459 break;
|
nickjillings@1318
|
1460 case 'elementFlagComments':
|
nickjillings@1318
|
1461 this.enableFlagComments = true;
|
nickjillings@1318
|
1462 break;
|
nickjillings@1318
|
1463 }
|
nickjillings@1318
|
1464 }
|
nickjillings@1318
|
1465 this.initialiseTest = function(){};
|
nickjillings@1318
|
1466 }
|
nickjillings@1318
|
1467
|
nickjillings@1318
|
1468 function metricTracker(caller)
|
nickjillings@1318
|
1469 {
|
nickjillings@1318
|
1470 /* Custom object to track and collect metric data
|
nickjillings@1318
|
1471 * Used only inside the audioObjects object.
|
nickjillings@1318
|
1472 */
|
nickjillings@1318
|
1473
|
nickjillings@1318
|
1474 this.listenedTimer = 0;
|
nickjillings@1318
|
1475 this.listenStart = 0;
|
nickjillings@1318
|
1476 this.listenHold = false;
|
nickjillings@1318
|
1477 this.initialPosition = -1;
|
nickjillings@1318
|
1478 this.movementTracker = [];
|
nickjillings@1318
|
1479 this.listenTracker =[];
|
nickjillings@1318
|
1480 this.wasListenedTo = false;
|
nickjillings@1318
|
1481 this.wasMoved = false;
|
nickjillings@1318
|
1482 this.hasComments = false;
|
nickjillings@1318
|
1483 this.parent = caller;
|
nickjillings@1318
|
1484
|
nickjillings@1324
|
1485 this.initialise = function(position)
|
nickjillings@1318
|
1486 {
|
nickjillings@1318
|
1487 if (this.initialPosition == -1) {
|
nickjillings@1318
|
1488 this.initialPosition = position;
|
nickjillings@1325
|
1489 this.moved(0,position);
|
nickjillings@1318
|
1490 }
|
nickjillings@1318
|
1491 };
|
nickjillings@1318
|
1492
|
nickjillings@1318
|
1493 this.moved = function(time,position)
|
nickjillings@1318
|
1494 {
|
nickjillings@1325
|
1495 if (time > 0) {this.wasMoved = true;}
|
nickjillings@1318
|
1496 this.movementTracker[this.movementTracker.length] = [time, position];
|
nickjillings@1318
|
1497 };
|
nickjillings@1318
|
1498
|
nickjillings@1318
|
1499 this.startListening = function(time)
|
nickjillings@1318
|
1500 {
|
nickjillings@1318
|
1501 if (this.listenHold == false)
|
nickjillings@1318
|
1502 {
|
nickjillings@1318
|
1503 this.wasListenedTo = true;
|
nickjillings@1318
|
1504 this.listenStart = time;
|
nickjillings@1318
|
1505 this.listenHold = true;
|
nickjillings@1318
|
1506
|
nickjillings@1318
|
1507 var evnt = document.createElement('event');
|
nickjillings@1318
|
1508 var testTime = document.createElement('testTime');
|
nickjillings@1318
|
1509 testTime.setAttribute('start',time);
|
nickjillings@1318
|
1510 var bufferTime = document.createElement('bufferTime');
|
nickjillings@1318
|
1511 bufferTime.setAttribute('start',this.parent.getCurrentPosition());
|
nickjillings@1318
|
1512 evnt.appendChild(testTime);
|
nickjillings@1318
|
1513 evnt.appendChild(bufferTime);
|
nickjillings@1318
|
1514 this.listenTracker.push(evnt);
|
nickjillings@1318
|
1515
|
nickjillings@1318
|
1516 console.log('slider ' + this.parent.id + ' played (' + time + ')'); // DEBUG/SAFETY: show played slider id
|
nickjillings@1318
|
1517 }
|
nickjillings@1318
|
1518 };
|
nickjillings@1318
|
1519
|
nickjillings@1318
|
1520 this.stopListening = function(time,bufferStopTime)
|
nickjillings@1318
|
1521 {
|
nickjillings@1318
|
1522 if (this.listenHold == true)
|
nickjillings@1318
|
1523 {
|
nickjillings@1318
|
1524 var diff = time - this.listenStart;
|
nickjillings@1318
|
1525 this.listenedTimer += (diff);
|
nickjillings@1318
|
1526 this.listenStart = 0;
|
nickjillings@1318
|
1527 this.listenHold = false;
|
nickjillings@1318
|
1528
|
nickjillings@1318
|
1529 var evnt = this.listenTracker[this.listenTracker.length-1];
|
nickjillings@1318
|
1530 var testTime = evnt.getElementsByTagName('testTime')[0];
|
nickjillings@1318
|
1531 var bufferTime = evnt.getElementsByTagName('bufferTime')[0];
|
nickjillings@1318
|
1532 testTime.setAttribute('stop',time);
|
nickjillings@1318
|
1533 if (bufferStopTime == undefined) {
|
nickjillings@1318
|
1534 bufferTime.setAttribute('stop',this.parent.getCurrentPosition());
|
nickjillings@1318
|
1535 } else {
|
nickjillings@1318
|
1536 bufferTime.setAttribute('stop',bufferStopTime);
|
nickjillings@1318
|
1537 }
|
nickjillings@1318
|
1538 console.log('slider ' + this.parent.id + ' played for (' + diff + ')'); // DEBUG/SAFETY: show played slider id
|
nickjillings@1318
|
1539 }
|
nickjillings@1318
|
1540 };
|
nickjillings@1318
|
1541
|
nickjillings@1318
|
1542 this.exportXMLDOM = function() {
|
nickjillings@1324
|
1543 var storeDOM = [];
|
nickjillings@1318
|
1544 if (audioEngineContext.metric.enableElementTimer) {
|
nickjillings@1324
|
1545 var mElementTimer = storage.document.createElement('metricresult');
|
nickjillings@1318
|
1546 mElementTimer.setAttribute('name','enableElementTimer');
|
nickjillings@1318
|
1547 mElementTimer.textContent = this.listenedTimer;
|
nickjillings@1324
|
1548 storeDOM.push(mElementTimer);
|
nickjillings@1318
|
1549 }
|
nickjillings@1318
|
1550 if (audioEngineContext.metric.enableElementTracker) {
|
nickjillings@1324
|
1551 var elementTrackerFull = storage.document.createElement('metricResult');
|
nickjillings@1318
|
1552 elementTrackerFull.setAttribute('name','elementTrackerFull');
|
nickjillings@1318
|
1553 for (var k=0; k<this.movementTracker.length; k++)
|
nickjillings@1318
|
1554 {
|
nickjillings@1324
|
1555 var timePos = storage.document.createElement('timePos');
|
nickjillings@1318
|
1556 timePos.id = k;
|
nickjillings@1324
|
1557 var time = storage.document.createElement('time');
|
nickjillings@1318
|
1558 time.textContent = this.movementTracker[k][0];
|
nickjillings@1318
|
1559 var position = document.createElement('position');
|
nickjillings@1318
|
1560 position.textContent = this.movementTracker[k][1];
|
nickjillings@1318
|
1561 timePos.appendChild(time);
|
nickjillings@1318
|
1562 timePos.appendChild(position);
|
nickjillings@1318
|
1563 elementTrackerFull.appendChild(timePos);
|
nickjillings@1318
|
1564 }
|
nickjillings@1324
|
1565 storeDOM.push(elementTrackerFull);
|
nickjillings@1318
|
1566 }
|
nickjillings@1318
|
1567 if (audioEngineContext.metric.enableElementListenTracker) {
|
nickjillings@1324
|
1568 var elementListenTracker = storage.document.createElement('metricResult');
|
nickjillings@1318
|
1569 elementListenTracker.setAttribute('name','elementListenTracker');
|
nickjillings@1318
|
1570 for (var k=0; k<this.listenTracker.length; k++) {
|
nickjillings@1318
|
1571 elementListenTracker.appendChild(this.listenTracker[k]);
|
nickjillings@1318
|
1572 }
|
nickjillings@1324
|
1573 storeDOM.push(elementListenTracker);
|
nickjillings@1318
|
1574 }
|
nickjillings@1318
|
1575 if (audioEngineContext.metric.enableElementInitialPosition) {
|
nickjillings@1324
|
1576 var elementInitial = storage.document.createElement('metricResult');
|
nickjillings@1318
|
1577 elementInitial.setAttribute('name','elementInitialPosition');
|
nickjillings@1318
|
1578 elementInitial.textContent = this.initialPosition;
|
nickjillings@1324
|
1579 storeDOM.push(elementInitial);
|
nickjillings@1318
|
1580 }
|
nickjillings@1318
|
1581 if (audioEngineContext.metric.enableFlagListenedTo) {
|
nickjillings@1324
|
1582 var flagListenedTo = storage.document.createElement('metricResult');
|
nickjillings@1318
|
1583 flagListenedTo.setAttribute('name','elementFlagListenedTo');
|
nickjillings@1318
|
1584 flagListenedTo.textContent = this.wasListenedTo;
|
nickjillings@1324
|
1585 storeDOM.push(flagListenedTo);
|
nickjillings@1318
|
1586 }
|
nickjillings@1318
|
1587 if (audioEngineContext.metric.enableFlagMoved) {
|
nickjillings@1324
|
1588 var flagMoved = storage.document.createElement('metricResult');
|
nickjillings@1318
|
1589 flagMoved.setAttribute('name','elementFlagMoved');
|
nickjillings@1318
|
1590 flagMoved.textContent = this.wasMoved;
|
nickjillings@1324
|
1591 storeDOM.push(flagMoved);
|
nickjillings@1318
|
1592 }
|
nickjillings@1318
|
1593 if (audioEngineContext.metric.enableFlagComments) {
|
nickjillings@1324
|
1594 var flagComments = storage.document.createElement('metricResult');
|
nickjillings@1318
|
1595 flagComments.setAttribute('name','elementFlagComments');
|
nickjillings@1318
|
1596 if (this.parent.commentDOM == null)
|
nickjillings@1318
|
1597 {flag.textContent = 'false';}
|
nickjillings@1318
|
1598 else if (this.parent.commentDOM.textContent.length == 0)
|
nickjillings@1318
|
1599 {flag.textContent = 'false';}
|
nickjillings@1318
|
1600 else
|
nickjillings@1318
|
1601 {flag.textContet = 'true';}
|
nickjillings@1324
|
1602 storeDOM.push(flagComments);
|
nickjillings@1318
|
1603 }
|
nickjillings@1324
|
1604 return storeDOM;
|
nickjillings@1318
|
1605 };
|
nickjillings@1318
|
1606 }
|
nickjillings@1318
|
1607
|
nickjillings@1318
|
1608 function randomiseOrder(input)
|
nickjillings@1318
|
1609 {
|
nickjillings@1318
|
1610 // This takes an array of information and randomises the order
|
nickjillings@1318
|
1611 var N = input.length;
|
nickjillings@1318
|
1612
|
nickjillings@1318
|
1613 var inputSequence = []; // For safety purposes: keep track of randomisation
|
nickjillings@1318
|
1614 for (var counter = 0; counter < N; ++counter)
|
nickjillings@1318
|
1615 inputSequence.push(counter) // Fill array
|
nickjillings@1318
|
1616 var inputSequenceClone = inputSequence.slice(0);
|
nickjillings@1318
|
1617
|
nickjillings@1318
|
1618 var holdArr = [];
|
nickjillings@1318
|
1619 var outputSequence = [];
|
nickjillings@1318
|
1620 for (var n=0; n<N; n++)
|
nickjillings@1318
|
1621 {
|
nickjillings@1318
|
1622 // First pick a random number
|
nickjillings@1318
|
1623 var r = Math.random();
|
nickjillings@1318
|
1624 // Multiply and floor by the number of elements left
|
nickjillings@1318
|
1625 r = Math.floor(r*input.length);
|
nickjillings@1318
|
1626 // Pick out that element and delete from the array
|
nickjillings@1318
|
1627 holdArr.push(input.splice(r,1)[0]);
|
nickjillings@1318
|
1628 // Do the same with sequence
|
nickjillings@1318
|
1629 outputSequence.push(inputSequence.splice(r,1)[0]);
|
nickjillings@1318
|
1630 }
|
nickjillings@1318
|
1631 console.log(inputSequenceClone.toString()); // print original array to console
|
nickjillings@1318
|
1632 console.log(outputSequence.toString()); // print randomised array to console
|
nickjillings@1318
|
1633 return holdArr;
|
nickjillings@1318
|
1634 }
|
nickjillings@1318
|
1635
|
nickjillings@1318
|
1636 function returnDateNode()
|
nickjillings@1318
|
1637 {
|
nickjillings@1318
|
1638 // Create an XML Node for the Date and Time a test was conducted
|
nickjillings@1318
|
1639 // Structure is
|
nickjillings@1318
|
1640 // <datetime>
|
nickjillings@1318
|
1641 // <date year="##" month="##" day="##">DD/MM/YY</date>
|
nickjillings@1318
|
1642 // <time hour="##" minute="##" sec="##">HH:MM:SS</time>
|
nickjillings@1318
|
1643 // </datetime>
|
nickjillings@1318
|
1644 var dateTime = new Date();
|
nickjillings@1318
|
1645 var year = document.createAttribute('year');
|
nickjillings@1318
|
1646 var month = document.createAttribute('month');
|
nickjillings@1318
|
1647 var day = document.createAttribute('day');
|
nickjillings@1318
|
1648 var hour = document.createAttribute('hour');
|
nickjillings@1318
|
1649 var minute = document.createAttribute('minute');
|
nickjillings@1318
|
1650 var secs = document.createAttribute('secs');
|
nickjillings@1318
|
1651
|
nickjillings@1318
|
1652 year.nodeValue = dateTime.getFullYear();
|
nickjillings@1318
|
1653 month.nodeValue = dateTime.getMonth()+1;
|
nickjillings@1318
|
1654 day.nodeValue = dateTime.getDate();
|
nickjillings@1318
|
1655 hour.nodeValue = dateTime.getHours();
|
nickjillings@1318
|
1656 minute.nodeValue = dateTime.getMinutes();
|
nickjillings@1318
|
1657 secs.nodeValue = dateTime.getSeconds();
|
nickjillings@1318
|
1658
|
nickjillings@1318
|
1659 var hold = document.createElement("datetime");
|
nickjillings@1318
|
1660 var date = document.createElement("date");
|
nickjillings@1318
|
1661 date.textContent = year.nodeValue+'/'+month.nodeValue+'/'+day.nodeValue;
|
nickjillings@1318
|
1662 var time = document.createElement("time");
|
nickjillings@1318
|
1663 time.textContent = hour.nodeValue+':'+minute.nodeValue+':'+secs.nodeValue;
|
nickjillings@1318
|
1664
|
nickjillings@1318
|
1665 date.setAttributeNode(year);
|
nickjillings@1318
|
1666 date.setAttributeNode(month);
|
nickjillings@1318
|
1667 date.setAttributeNode(day);
|
nickjillings@1318
|
1668 time.setAttributeNode(hour);
|
nickjillings@1318
|
1669 time.setAttributeNode(minute);
|
nickjillings@1318
|
1670 time.setAttributeNode(secs);
|
nickjillings@1318
|
1671
|
nickjillings@1318
|
1672 hold.appendChild(date);
|
nickjillings@1318
|
1673 hold.appendChild(time);
|
nickjillings@1318
|
1674 return hold;
|
nickjillings@1318
|
1675
|
nickjillings@1318
|
1676 }
|
nickjillings@1318
|
1677
|
nickjillings@1318
|
1678 function Specification() {
|
nickjillings@1318
|
1679 // Handles the decoding of the project specification XML into a simple JavaScript Object.
|
nickjillings@1318
|
1680
|
nickjillings@1324
|
1681 this.interface = null;
|
nickjillings@1373
|
1682 this.projectReturn = "null";
|
nickjillings@1324
|
1683 this.randomiseOrder = null;
|
nickjillings@1324
|
1684 this.testPages = null;
|
nickjillings@1324
|
1685 this.pages = [];
|
nickjillings@1324
|
1686 this.metrics = null;
|
nickjillings@1324
|
1687 this.interfaces = null;
|
nickjillings@1324
|
1688 this.loudness = null;
|
nickjillings@1324
|
1689 this.errors = [];
|
nickjillings@1324
|
1690 this.schema = null;
|
nickjillings@1318
|
1691
|
nickjillings@1324
|
1692 this.processAttribute = function(attribute,schema)
|
nickjillings@1324
|
1693 {
|
nickjillings@1324
|
1694 // attribute is the string returned from getAttribute on the XML
|
nickjillings@1324
|
1695 // schema is the <xs:attribute> node
|
nickjillings@1324
|
1696 if (schema.getAttribute('name') == undefined && schema.getAttribute('ref') != undefined)
|
nickjillings@1324
|
1697 {
|
nickjillings@1348
|
1698 schema = this.schema.getAllElementsByName(schema.getAttribute('ref'))[0];
|
nickjillings@1324
|
1699 }
|
nickjillings@1324
|
1700 var defaultOpt = schema.getAttribute('default');
|
nickjillings@1324
|
1701 if (attribute == null) {
|
nickjillings@1324
|
1702 attribute = defaultOpt;
|
nickjillings@1324
|
1703 }
|
nickjillings@1324
|
1704 var dataType = schema.getAttribute('type');
|
nickjillings@1324
|
1705 if (typeof dataType == "string") { dataType = dataType.substr(3);}
|
nickjillings@1324
|
1706 else {dataType = "string";}
|
nickjillings@1324
|
1707 if (attribute == null)
|
nickjillings@1324
|
1708 {
|
nickjillings@1324
|
1709 return attribute;
|
nickjillings@1324
|
1710 }
|
nickjillings@1324
|
1711 switch(dataType)
|
nickjillings@1324
|
1712 {
|
nickjillings@1324
|
1713 case "boolean":
|
nickjillings@1324
|
1714 if (attribute == 'true'){attribute = true;}else{attribute=false;}
|
nickjillings@1324
|
1715 break;
|
nickjillings@1324
|
1716 case "negativeInteger":
|
nickjillings@1324
|
1717 case "positiveInteger":
|
nickjillings@1324
|
1718 case "nonNegativeInteger":
|
nickjillings@1324
|
1719 case "nonPositiveInteger":
|
nickjillings@1324
|
1720 case "integer":
|
nickjillings@1324
|
1721 case "decimal":
|
nickjillings@1324
|
1722 case "short":
|
nickjillings@1324
|
1723 attribute = Number(attribute);
|
nickjillings@1324
|
1724 break;
|
nickjillings@1324
|
1725 case "string":
|
nickjillings@1324
|
1726 default:
|
nickjillings@1324
|
1727 attribute = String(attribute);
|
nickjillings@1324
|
1728 break;
|
nickjillings@1324
|
1729 }
|
nickjillings@1324
|
1730 return attribute;
|
nickjillings@1324
|
1731 };
|
nickjillings@1318
|
1732
|
nickjillings@1318
|
1733 this.decode = function(projectXML) {
|
nickjillings@1324
|
1734 this.errors = [];
|
nickjillings@1318
|
1735 // projectXML - DOM Parsed document
|
nickjillings@1318
|
1736 this.projectXML = projectXML.childNodes[0];
|
nickjillings@1318
|
1737 var setupNode = projectXML.getElementsByTagName('setup')[0];
|
nickjillings@1348
|
1738 var schemaSetup = this.schema.getAllElementsByName('setup')[0];
|
nickjillings@1324
|
1739 // First decode the attributes
|
nickjillings@1348
|
1740 var attributes = schemaSetup.getAllElementsByTagName('xs:attribute');
|
nickjillings@1324
|
1741 for (var i in attributes)
|
nickjillings@1318
|
1742 {
|
nickjillings@1324
|
1743 if (isNaN(Number(i)) == true){break;}
|
nickjillings@1324
|
1744 var attributeName = attributes[i].getAttribute('name');
|
nickjillings@1324
|
1745 var projectAttr = setupNode.getAttribute(attributeName);
|
nickjillings@1324
|
1746 projectAttr = this.processAttribute(projectAttr,attributes[i]);
|
nickjillings@1324
|
1747 switch(typeof projectAttr)
|
nickjillings@1318
|
1748 {
|
nickjillings@1324
|
1749 case "number":
|
nickjillings@1324
|
1750 case "boolean":
|
nickjillings@1324
|
1751 eval('this.'+attributeName+' = '+projectAttr);
|
nickjillings@1324
|
1752 break;
|
nickjillings@1324
|
1753 case "string":
|
nickjillings@1324
|
1754 eval('this.'+attributeName+' = "'+projectAttr+'"');
|
nickjillings@1324
|
1755 break;
|
nickjillings@1318
|
1756 }
|
nickjillings@1324
|
1757
|
nickjillings@1318
|
1758 }
|
nickjillings@1318
|
1759
|
nickjillings@1370
|
1760 this.metrics = new this.metricNode();
|
nickjillings@1318
|
1761
|
nickjillings@1324
|
1762 this.metrics.decode(this,setupNode.getElementsByTagName('metric')[0]);
|
nickjillings@1324
|
1763
|
nickjillings@1324
|
1764 // Now process the survey node options
|
nickjillings@1324
|
1765 var survey = setupNode.getElementsByTagName('survey');
|
nickjillings@1324
|
1766 for (var i in survey) {
|
nickjillings@1324
|
1767 if (isNaN(Number(i)) == true){break;}
|
nickjillings@1324
|
1768 var location = survey[i].getAttribute('location');
|
nickjillings@1324
|
1769 if (location == 'pre' || location == 'before')
|
nickjillings@1324
|
1770 {
|
nickjillings@1324
|
1771 if (this.preTest != null){this.errors.push("Already a pre/before test survey defined! Ignoring second!!");}
|
nickjillings@1324
|
1772 else {
|
nickjillings@1324
|
1773 this.preTest = new this.surveyNode();
|
nickjillings@1370
|
1774 this.preTest.decode(this,survey[i]);
|
nickjillings@1324
|
1775 }
|
nickjillings@1324
|
1776 } else if (location == 'post' || location == 'after') {
|
nickjillings@1324
|
1777 if (this.postTest != null){this.errors.push("Already a post/after test survey defined! Ignoring second!!");}
|
nickjillings@1324
|
1778 else {
|
nickjillings@1324
|
1779 this.postTest = new this.surveyNode();
|
nickjillings@1370
|
1780 this.postTest.decode(this,survey[i]);
|
nickjillings@1324
|
1781 }
|
nickjillings@1318
|
1782 }
|
nickjillings@1318
|
1783 }
|
nickjillings@1318
|
1784
|
nickjillings@1324
|
1785 var interfaceNode = setupNode.getElementsByTagName('interface');
|
nickjillings@1324
|
1786 if (interfaceNode.length > 1)
|
nickjillings@1324
|
1787 {
|
nickjillings@1324
|
1788 this.errors.push("Only one <interface> node in the <setup> node allowed! Others except first ingnored!");
|
nickjillings@1324
|
1789 }
|
nickjillings@1324
|
1790 this.interfaces = new this.interfaceNode();
|
nickjillings@1324
|
1791 if (interfaceNode.length != 0)
|
nickjillings@1324
|
1792 {
|
nickjillings@1324
|
1793 interfaceNode = interfaceNode[0];
|
nickjillings@1348
|
1794 this.interfaces.decode(this,interfaceNode,this.schema.getAllElementsByName('interface')[1]);
|
nickjillings@1318
|
1795 }
|
nickjillings@1318
|
1796
|
nickjillings@1324
|
1797 // Page tags
|
nickjillings@1324
|
1798 var pageTags = projectXML.getElementsByTagName('page');
|
nickjillings@1348
|
1799 var pageSchema = this.schema.getAllElementsByName('page')[0];
|
nickjillings@1324
|
1800 for (var i=0; i<pageTags.length; i++)
|
nickjillings@1318
|
1801 {
|
nickjillings@1324
|
1802 var node = new this.page();
|
nickjillings@1324
|
1803 node.decode(this,pageTags[i],pageSchema);
|
nickjillings@1324
|
1804 this.pages.push(node);
|
nickjillings@1318
|
1805 }
|
nickjillings@1318
|
1806 };
|
nickjillings@1318
|
1807
|
nickjillings@1318
|
1808 this.encode = function()
|
nickjillings@1318
|
1809 {
|
nickjillings@1372
|
1810 var RootDocument = document.implementation.createDocument(null,"waet");
|
nickjillings@1372
|
1811 var root = RootDocument.children[0];
|
nickjillings@1372
|
1812 root.setAttribute("xmlns:xsi","http://www.w3.org/2001/XMLSchema-instance");
|
nickjillings@1372
|
1813 root.setAttribute("xsi:noNamespaceSchemaLocation","test-schema.xsd");
|
nickjillings@1324
|
1814 // Build setup node
|
nickjillings@1372
|
1815 var setup = RootDocument.createElement("setup");
|
nickjillings@1372
|
1816 var schemaSetup = this.schema.getAllElementsByName('setup')[0];
|
nickjillings@1372
|
1817 // First decode the attributes
|
nickjillings@1372
|
1818 var attributes = schemaSetup.getAllElementsByTagName('xs:attribute');
|
nickjillings@1372
|
1819 for (var i=0; i<attributes.length; i++)
|
nickjillings@1372
|
1820 {
|
nickjillings@1372
|
1821 var name = attributes[i].getAttribute("name");
|
nickjillings@1372
|
1822 if (name == undefined) {
|
nickjillings@1372
|
1823 name = attributes[i].getAttribute("ref");
|
nickjillings@1372
|
1824 }
|
nickjillings@1372
|
1825 if(eval("this."+name+" != undefined") || attributes[i].getAttribute("use") == "required")
|
nickjillings@1372
|
1826 {
|
nickjillings@1372
|
1827 eval("setup.setAttribute('"+name+"',this."+name+")");
|
nickjillings@1372
|
1828 }
|
nickjillings@1372
|
1829 }
|
nickjillings@1372
|
1830 root.appendChild(setup);
|
nickjillings@1372
|
1831 // Survey node
|
nickjillings@1372
|
1832 setup.appendChild(this.preTest.encode(RootDocument));
|
nickjillings@1372
|
1833 setup.appendChild(this.postTest.encode(RootDocument));
|
nickjillings@1372
|
1834 setup.appendChild(this.metrics.encode(RootDocument));
|
nickjillings@1372
|
1835 setup.appendChild(this.interfaces.encode(RootDocument));
|
nickjillings@1372
|
1836 for (var page of this.pages)
|
nickjillings@1372
|
1837 {
|
nickjillings@1372
|
1838 root.appendChild(page.encode(RootDocument));
|
nickjillings@1372
|
1839 }
|
nickjillings@1372
|
1840 return RootDocument;
|
nickjillings@1318
|
1841 };
|
nickjillings@1318
|
1842
|
nickjillings@1324
|
1843 this.surveyNode = function() {
|
nickjillings@1324
|
1844 this.location = null;
|
nickjillings@1318
|
1845 this.options = [];
|
nickjillings@1370
|
1846 this.schema = specification.schema.getAllElementsByName('survey')[0];
|
nickjillings@1318
|
1847
|
nickjillings@1318
|
1848 this.OptionNode = function() {
|
nickjillings@1318
|
1849 this.type = undefined;
|
nickjillings@1370
|
1850 this.schema = specification.schema.getAllElementsByName('surveyentry')[0];
|
nickjillings@1318
|
1851 this.id = undefined;
|
nickjillings@1318
|
1852 this.mandatory = undefined;
|
nickjillings@1318
|
1853 this.statement = undefined;
|
nickjillings@1318
|
1854 this.boxsize = undefined;
|
nickjillings@1318
|
1855 this.options = [];
|
nickjillings@1318
|
1856 this.min = undefined;
|
nickjillings@1318
|
1857 this.max = undefined;
|
nickjillings@1318
|
1858 this.step = undefined;
|
nickjillings@1318
|
1859
|
nickjillings@1370
|
1860 this.decode = function(parent,child)
|
nickjillings@1318
|
1861 {
|
nickjillings@1370
|
1862 var attributeMap = this.schema.getAllElementsByTagName('xs:attribute');
|
nickjillings@1324
|
1863 for (var i in attributeMap){
|
nickjillings@1324
|
1864 if(isNaN(Number(i)) == true){break;}
|
nickjillings@1324
|
1865 var attributeName = attributeMap[i].getAttribute('name') || attributeMap[i].getAttribute('ref');
|
nickjillings@1324
|
1866 var projectAttr = child.getAttribute(attributeName);
|
nickjillings@1324
|
1867 projectAttr = parent.processAttribute(projectAttr,attributeMap[i]);
|
nickjillings@1324
|
1868 switch(typeof projectAttr)
|
nickjillings@1324
|
1869 {
|
nickjillings@1324
|
1870 case "number":
|
nickjillings@1324
|
1871 case "boolean":
|
nickjillings@1324
|
1872 eval('this.'+attributeName+' = '+projectAttr);
|
nickjillings@1324
|
1873 break;
|
nickjillings@1324
|
1874 case "string":
|
nickjillings@1324
|
1875 eval('this.'+attributeName+' = "'+projectAttr+'"');
|
nickjillings@1324
|
1876 break;
|
nickjillings@1318
|
1877 }
|
nickjillings@1324
|
1878 }
|
nickjillings@1324
|
1879 this.statement = child.getElementsByTagName('statement')[0].textContent;
|
nickjillings@1324
|
1880 if (this.type == "checkbox" || this.type == "radio") {
|
nickjillings@1324
|
1881 var children = child.getElementsByTagName('option');
|
nickjillings@1324
|
1882 if (children.length == null) {
|
nickjillings@1318
|
1883 console.log('Malformed' +child.nodeName+ 'entry');
|
nickjillings@1318
|
1884 this.statement = 'Malformed' +child.nodeName+ 'entry';
|
nickjillings@1318
|
1885 this.type = 'statement';
|
nickjillings@1318
|
1886 } else {
|
nickjillings@1318
|
1887 this.options = [];
|
nickjillings@1324
|
1888 for (var i in children)
|
nickjillings@1324
|
1889 {
|
nickjillings@1324
|
1890 if (isNaN(Number(i))==true){break;}
|
nickjillings@1324
|
1891 this.options.push({
|
nickjillings@1324
|
1892 name: children[i].getAttribute('name'),
|
nickjillings@1324
|
1893 text: children[i].textContent
|
nickjillings@1324
|
1894 });
|
nickjillings@1318
|
1895 }
|
nickjillings@1318
|
1896 }
|
nickjillings@1318
|
1897 }
|
nickjillings@1318
|
1898 };
|
nickjillings@1318
|
1899
|
nickjillings@1372
|
1900 this.exportXML = function(doc)
|
nickjillings@1318
|
1901 {
|
nickjillings@1372
|
1902 var node = doc.createElement('surveyelement');
|
nickjillings@1324
|
1903 node.setAttribute('type',this.type);
|
nickjillings@1372
|
1904 var statement = doc.createElement('statement');
|
nickjillings@1324
|
1905 statement.textContent = this.statement;
|
nickjillings@1324
|
1906 node.appendChild(statement);
|
nickjillings@1318
|
1907 switch(this.type)
|
nickjillings@1318
|
1908 {
|
nickjillings@1318
|
1909 case "statement":
|
nickjillings@1318
|
1910 break;
|
nickjillings@1318
|
1911 case "question":
|
nickjillings@1318
|
1912 node.id = this.id;
|
nickjillings@1318
|
1913 node.setAttribute("mandatory",this.mandatory);
|
nickjillings@1318
|
1914 node.setAttribute("boxsize",this.boxsize);
|
nickjillings@1318
|
1915 break;
|
nickjillings@1318
|
1916 case "number":
|
nickjillings@1318
|
1917 node.id = this.id;
|
nickjillings@1318
|
1918 node.setAttribute("mandatory",this.mandatory);
|
nickjillings@1318
|
1919 node.setAttribute("min", this.min);
|
nickjillings@1318
|
1920 node.setAttribute("max", this.max);
|
nickjillings@1318
|
1921 node.setAttribute("step", this.step);
|
nickjillings@1318
|
1922 break;
|
nickjillings@1318
|
1923 case "checkbox":
|
nickjillings@1318
|
1924 case "radio":
|
nickjillings@1318
|
1925 node.id = this.id;
|
nickjillings@1318
|
1926 for (var i=0; i<this.options.length; i++)
|
nickjillings@1318
|
1927 {
|
nickjillings@1318
|
1928 var option = this.options[i];
|
nickjillings@1372
|
1929 var optionNode = doc.createElement("option");
|
nickjillings@1318
|
1930 optionNode.setAttribute("name",option.name);
|
nickjillings@1318
|
1931 optionNode.textContent = option.text;
|
nickjillings@1318
|
1932 node.appendChild(optionNode);
|
nickjillings@1318
|
1933 }
|
nickjillings@1318
|
1934 break;
|
nickjillings@1318
|
1935 }
|
nickjillings@1318
|
1936 return node;
|
nickjillings@1318
|
1937 };
|
nickjillings@1318
|
1938 };
|
nickjillings@1370
|
1939 this.decode = function(parent,xml) {
|
nickjillings@1324
|
1940 this.location = xml.getAttribute('location');
|
nickjillings@1324
|
1941 if (this.location == 'before'){this.location = 'pre';}
|
nickjillings@1324
|
1942 else if (this.location == 'after'){this.location = 'post';}
|
nickjillings@1324
|
1943 for (var i in xml.children)
|
nickjillings@1324
|
1944 {
|
nickjillings@1324
|
1945 if(isNaN(Number(i))==true){break;}
|
nickjillings@1318
|
1946 var node = new this.OptionNode();
|
nickjillings@1370
|
1947 node.decode(parent,xml.children[i]);
|
nickjillings@1318
|
1948 this.options.push(node);
|
nickjillings@1324
|
1949 }
|
nickjillings@1324
|
1950 };
|
nickjillings@1372
|
1951 this.encode = function(doc) {
|
nickjillings@1372
|
1952 var node = doc.createElement('survey');
|
nickjillings@1324
|
1953 node.setAttribute('location',this.location);
|
nickjillings@1324
|
1954 for (var i=0; i<this.options.length; i++)
|
nickjillings@1324
|
1955 {
|
nickjillings@1372
|
1956 node.appendChild(this.options[i].exportXML(doc));
|
nickjillings@1324
|
1957 }
|
nickjillings@1324
|
1958 return node;
|
nickjillings@1324
|
1959 };
|
nickjillings@1324
|
1960 };
|
nickjillings@1324
|
1961
|
nickjillings@1324
|
1962 this.interfaceNode = function()
|
nickjillings@1324
|
1963 {
|
nickjillings@1324
|
1964 this.title = null;
|
nickjillings@1324
|
1965 this.name = null;
|
nickjillings@1324
|
1966 this.options = [];
|
nickjillings@1324
|
1967 this.scales = [];
|
nickjillings@1370
|
1968 this.schema = specification.schema.getAllElementsByName('interface')[1];
|
nickjillings@1324
|
1969
|
nickjillings@1370
|
1970 this.decode = function(parent,xml) {
|
nickjillings@1324
|
1971 this.name = xml.getAttribute('name');
|
nickjillings@1324
|
1972 var titleNode = xml.getElementsByTagName('title');
|
nickjillings@1324
|
1973 if (titleNode.length == 1)
|
nickjillings@1324
|
1974 {
|
nickjillings@1324
|
1975 this.title = titleNode[0].textContent;
|
nickjillings@1324
|
1976 }
|
nickjillings@1324
|
1977 var interfaceOptionNodes = xml.getElementsByTagName('interfaceoption');
|
nickjillings@1324
|
1978 // Extract interfaceoption node schema
|
nickjillings@1370
|
1979 var interfaceOptionNodeSchema = this.schema.getAllElementsByName('interfaceoption')[0];
|
nickjillings@1348
|
1980 var attributeMap = interfaceOptionNodeSchema.getAllElementsByTagName('xs:attribute');
|
nickjillings@1324
|
1981 for (var i=0; i<interfaceOptionNodes.length; i++)
|
nickjillings@1324
|
1982 {
|
nickjillings@1324
|
1983 var ioNode = interfaceOptionNodes[i];
|
nickjillings@1324
|
1984 var option = {};
|
nickjillings@1324
|
1985 for (var j=0; j<attributeMap.length; j++)
|
nickjillings@1324
|
1986 {
|
nickjillings@1324
|
1987 var attributeName = attributeMap[j].getAttribute('name') || attributeMap[j].getAttribute('ref');
|
nickjillings@1324
|
1988 var projectAttr = ioNode.getAttribute(attributeName);
|
nickjillings@1324
|
1989 projectAttr = parent.processAttribute(projectAttr,attributeMap[j]);
|
nickjillings@1324
|
1990 switch(typeof projectAttr)
|
nickjillings@1324
|
1991 {
|
nickjillings@1324
|
1992 case "number":
|
nickjillings@1324
|
1993 case "boolean":
|
nickjillings@1324
|
1994 eval('option.'+attributeName+' = '+projectAttr);
|
nickjillings@1324
|
1995 break;
|
nickjillings@1324
|
1996 case "string":
|
nickjillings@1324
|
1997 eval('option.'+attributeName+' = "'+projectAttr+'"');
|
nickjillings@1324
|
1998 break;
|
nickjillings@1324
|
1999 }
|
nickjillings@1324
|
2000 }
|
nickjillings@1324
|
2001 this.options.push(option);
|
nickjillings@1324
|
2002 }
|
nickjillings@1324
|
2003
|
nickjillings@1324
|
2004 // Now the scales nodes
|
nickjillings@1324
|
2005 var scaleParent = xml.getElementsByTagName('scales');
|
nickjillings@1324
|
2006 if (scaleParent.length == 1) {
|
nickjillings@1324
|
2007 scaleParent = scaleParent[0];
|
nickjillings@1324
|
2008 for (var i=0; i<scaleParent.children.length; i++) {
|
nickjillings@1324
|
2009 var child = scaleParent.children[i];
|
nickjillings@1324
|
2010 this.scales.push({
|
nickjillings@1324
|
2011 text: child.textContent,
|
nickjillings@1324
|
2012 position: Number(child.getAttribute('position'))
|
nickjillings@1324
|
2013 });
|
nickjillings@1318
|
2014 }
|
nickjillings@1318
|
2015 }
|
nickjillings@1318
|
2016 };
|
nickjillings@1324
|
2017
|
nickjillings@1372
|
2018 this.encode = function(doc) {
|
nickjillings@1372
|
2019 var node = doc.createElement("interface");
|
nickjillings@1372
|
2020 if (typeof name == "string")
|
nickjillings@1372
|
2021 node.setAttribute("name",this.name);
|
nickjillings@1372
|
2022 for (var option of this.options)
|
nickjillings@1372
|
2023 {
|
nickjillings@1372
|
2024 var child = doc.createElement("interfaceoption");
|
nickjillings@1372
|
2025 child.setAttribute("type",option.type);
|
nickjillings@1372
|
2026 child.setAttribute("name",option.name);
|
nickjillings@1372
|
2027 node.appendChild(child);
|
nickjillings@1372
|
2028 }
|
nickjillings@1372
|
2029 if (this.scales.length != 0) {
|
nickjillings@1372
|
2030 var scales = doc.createElement("scales");
|
nickjillings@1372
|
2031 for (var scale of this.scales)
|
nickjillings@1372
|
2032 {
|
nickjillings@1372
|
2033 var child = doc.createElement("scalelabel");
|
nickjillings@1372
|
2034 child.setAttribute("position",scale.position);
|
nickjillings@1372
|
2035 child.textContent = scale.text;
|
nickjillings@1372
|
2036 scales.appendChild(child);
|
nickjillings@1372
|
2037 }
|
nickjillings@1372
|
2038 node.appendChild(scales);
|
nickjillings@1372
|
2039 }
|
nickjillings@1372
|
2040 return node;
|
nickjillings@1324
|
2041 };
|
nickjillings@1318
|
2042 };
|
nickjillings@1318
|
2043
|
nickjillings@1370
|
2044 this.metricNode = function() {
|
nickjillings@1370
|
2045 this.enabled = [];
|
nickjillings@1370
|
2046 this.decode = function(parent, xml) {
|
nickjillings@1370
|
2047 var children = xml.getElementsByTagName('metricenable');
|
nickjillings@1370
|
2048 for (var i in children) {
|
nickjillings@1370
|
2049 if (isNaN(Number(i)) == true){break;}
|
nickjillings@1370
|
2050 this.enabled.push(children[i].textContent);
|
nickjillings@1370
|
2051 }
|
nickjillings@1370
|
2052 }
|
nickjillings@1372
|
2053 this.encode = function(doc) {
|
nickjillings@1372
|
2054 var node = doc.createElement('metric');
|
nickjillings@1370
|
2055 for (var i in this.enabled)
|
nickjillings@1370
|
2056 {
|
nickjillings@1370
|
2057 if (isNaN(Number(i)) == true){break;}
|
nickjillings@1372
|
2058 var child = doc.createElement('metricenable');
|
nickjillings@1370
|
2059 child.textContent = this.enabled[i];
|
nickjillings@1370
|
2060 node.appendChild(child);
|
nickjillings@1370
|
2061 }
|
nickjillings@1370
|
2062 return node;
|
nickjillings@1370
|
2063 }
|
nickjillings@1370
|
2064 }
|
nickjillings@1370
|
2065
|
nickjillings@1324
|
2066 this.page = function() {
|
nickjillings@1318
|
2067 this.presentedId = undefined;
|
nickjillings@1318
|
2068 this.id = undefined;
|
nickjillings@1318
|
2069 this.hostURL = undefined;
|
nickjillings@1318
|
2070 this.randomiseOrder = undefined;
|
nickjillings@1318
|
2071 this.loop = undefined;
|
nickjillings@1324
|
2072 this.showElementComments = undefined;
|
nickjillings@1318
|
2073 this.outsideReference = null;
|
nickjillings@1318
|
2074 this.loudness = null;
|
nickjillings@1324
|
2075 this.preTest = null;
|
nickjillings@1324
|
2076 this.postTest = null;
|
nickjillings@1318
|
2077 this.interfaces = [];
|
nickjillings@1318
|
2078 this.commentBoxPrefix = "Comment on track";
|
nickjillings@1318
|
2079 this.audioElements = [];
|
nickjillings@1318
|
2080 this.commentQuestions = [];
|
nickjillings@1370
|
2081 this.schema = specification.schema.getAllElementsByName("page")[0];
|
nickjillings@1318
|
2082
|
nickjillings@1370
|
2083 this.decode = function(parent,xml)
|
nickjillings@1318
|
2084 {
|
nickjillings@1348
|
2085 var attributeMap = this.schema.getAllElementsByTagName('xs:attribute');
|
nickjillings@1324
|
2086 for (var i=0; i<attributeMap.length; i++)
|
nickjillings@1318
|
2087 {
|
nickjillings@1324
|
2088 var attributeName = attributeMap[i].getAttribute('name') || attributeMap[i].getAttribute('ref');
|
nickjillings@1324
|
2089 var projectAttr = xml.getAttribute(attributeName);
|
nickjillings@1324
|
2090 projectAttr = parent.processAttribute(projectAttr,attributeMap[i]);
|
nickjillings@1324
|
2091 switch(typeof projectAttr)
|
nickjillings@1318
|
2092 {
|
nickjillings@1324
|
2093 case "number":
|
nickjillings@1324
|
2094 case "boolean":
|
nickjillings@1324
|
2095 eval('this.'+attributeName+' = '+projectAttr);
|
nickjillings@1324
|
2096 break;
|
nickjillings@1324
|
2097 case "string":
|
nickjillings@1324
|
2098 eval('this.'+attributeName+' = "'+projectAttr+'"');
|
nickjillings@1324
|
2099 break;
|
nickjillings@1318
|
2100 }
|
nickjillings@1318
|
2101 }
|
nickjillings@1318
|
2102
|
nickjillings@1324
|
2103 // Get the Comment Box Prefix
|
nickjillings@1324
|
2104 var CBP = xml.getElementsByTagName('commentboxprefix');
|
nickjillings@1324
|
2105 if (CBP.length != 0) {
|
nickjillings@1324
|
2106 this.commentBoxPrefix = CBP[0].textContent;
|
nickjillings@1318
|
2107 }
|
nickjillings@1318
|
2108
|
nickjillings@1324
|
2109 // Now decode the interfaces
|
nickjillings@1324
|
2110 var interfaceNode = xml.getElementsByTagName('interface');
|
nickjillings@1324
|
2111 for (var i=0; i<interfaceNode.length; i++)
|
nickjillings@1324
|
2112 {
|
nickjillings@1324
|
2113 var node = new parent.interfaceNode();
|
nickjillings@1348
|
2114 node.decode(this,interfaceNode[i],parent.schema.getAllElementsByName('interface')[1]);
|
nickjillings@1324
|
2115 this.interfaces.push(node);
|
nickjillings@1324
|
2116 }
|
nickjillings@1318
|
2117
|
nickjillings@1324
|
2118 // Now process the survey node options
|
nickjillings@1324
|
2119 var survey = xml.getElementsByTagName('survey');
|
nickjillings@1348
|
2120 var surveySchema = parent.schema.getAllElementsByName('survey')[0];
|
nickjillings@1324
|
2121 for (var i in survey) {
|
nickjillings@1324
|
2122 if (isNaN(Number(i)) == true){break;}
|
nickjillings@1324
|
2123 var location = survey[i].getAttribute('location');
|
nickjillings@1324
|
2124 if (location == 'pre' || location == 'before')
|
nickjillings@1324
|
2125 {
|
nickjillings@1324
|
2126 if (this.preTest != null){this.errors.push("Already a pre/before test survey defined! Ignoring second!!");}
|
nickjillings@1324
|
2127 else {
|
nickjillings@1324
|
2128 this.preTest = new parent.surveyNode();
|
nickjillings@1324
|
2129 this.preTest.decode(parent,survey[i],surveySchema);
|
nickjillings@1324
|
2130 }
|
nickjillings@1324
|
2131 } else if (location == 'post' || location == 'after') {
|
nickjillings@1324
|
2132 if (this.postTest != null){this.errors.push("Already a post/after test survey defined! Ignoring second!!");}
|
nickjillings@1324
|
2133 else {
|
nickjillings@1324
|
2134 this.postTest = new parent.surveyNode();
|
nickjillings@1324
|
2135 this.postTest.decode(parent,survey[i],surveySchema);
|
nickjillings@1324
|
2136 }
|
nickjillings@1324
|
2137 }
|
nickjillings@1324
|
2138 }
|
nickjillings@1324
|
2139
|
nickjillings@1324
|
2140 // Now process the audioelement tags
|
nickjillings@1324
|
2141 var audioElements = xml.getElementsByTagName('audioelement');
|
nickjillings@1324
|
2142 for (var i=0; i<audioElements.length; i++)
|
nickjillings@1324
|
2143 {
|
nickjillings@1324
|
2144 var node = new this.audioElementNode();
|
nickjillings@1370
|
2145 node.decode(this,audioElements[i]);
|
nickjillings@1324
|
2146 this.audioElements.push(node);
|
nickjillings@1324
|
2147 }
|
nickjillings@1324
|
2148
|
nickjillings@1324
|
2149 // Now decode the commentquestions
|
nickjillings@1324
|
2150 var commentQuestions = xml.getElementsByTagName('commentquestion');
|
nickjillings@1324
|
2151 for (var i=0; i<commentQuestions.length; i++)
|
nickjillings@1324
|
2152 {
|
nickjillings@1318
|
2153 var node = new this.commentQuestionNode();
|
nickjillings@1370
|
2154 node.decode(parent,commentQuestions[i]);
|
nickjillings@1318
|
2155 this.commentQuestions.push(node);
|
nickjillings@1318
|
2156 }
|
nickjillings@1318
|
2157 };
|
nickjillings@1318
|
2158
|
nickjillings@1318
|
2159 this.encode = function(root)
|
nickjillings@1318
|
2160 {
|
nickjillings@1372
|
2161 var AHNode = root.createElement("page");
|
nickjillings@1372
|
2162 // First decode the attributes
|
nickjillings@1372
|
2163 var attributes = this.schema.getAllElementsByTagName('xs:attribute');
|
nickjillings@1372
|
2164 for (var i=0; i<attributes.length; i++)
|
nickjillings@1372
|
2165 {
|
nickjillings@1372
|
2166 var name = attributes[i].getAttribute("name");
|
nickjillings@1372
|
2167 if (name == undefined) {
|
nickjillings@1372
|
2168 name = attributes[i].getAttribute("ref");
|
nickjillings@1372
|
2169 }
|
nickjillings@1372
|
2170 if(eval("this."+name+" != undefined") || attributes[i].getAttribute("use") == "required")
|
nickjillings@1372
|
2171 {
|
nickjillings@1372
|
2172 eval("AHNode.setAttribute('"+name+"',this."+name+")");
|
nickjillings@1372
|
2173 }
|
nickjillings@1372
|
2174 }
|
nickjillings@1318
|
2175 if(this.loudness != null) {AHNode.setAttribute("loudness",this.loudness);}
|
nickjillings@1372
|
2176 // <commentboxprefix>
|
nickjillings@1372
|
2177 var commentboxprefix = root.createElement("commentboxprefix");
|
nickjillings@1372
|
2178 commentboxprefix.textContent = this.commentBoxPrefix;
|
nickjillings@1372
|
2179 AHNode.appendChild(commentboxprefix);
|
nickjillings@1372
|
2180
|
nickjillings@1318
|
2181 for (var i=0; i<this.interfaces.length; i++)
|
nickjillings@1318
|
2182 {
|
nickjillings@1318
|
2183 AHNode.appendChild(this.interfaces[i].encode(root));
|
nickjillings@1318
|
2184 }
|
nickjillings@1318
|
2185
|
nickjillings@1318
|
2186 for (var i=0; i<this.audioElements.length; i++) {
|
nickjillings@1318
|
2187 AHNode.appendChild(this.audioElements[i].encode(root));
|
nickjillings@1318
|
2188 }
|
nickjillings@1318
|
2189 // Create <CommentQuestion>
|
nickjillings@1318
|
2190 for (var i=0; i<this.commentQuestions.length; i++)
|
nickjillings@1318
|
2191 {
|
nickjillings@1372
|
2192 AHNode.appendChild(this.commentQuestions[i].encode(root));
|
nickjillings@1318
|
2193 }
|
nickjillings@1318
|
2194
|
nickjillings@1372
|
2195 AHNode.appendChild(this.preTest.encode(root));
|
nickjillings@1372
|
2196 AHNode.appendChild(this.postTest.encode(root));
|
nickjillings@1318
|
2197 return AHNode;
|
nickjillings@1318
|
2198 };
|
nickjillings@1318
|
2199
|
nickjillings@1324
|
2200 this.commentQuestionNode = function() {
|
nickjillings@1324
|
2201 this.id = null;
|
nickjillings@1324
|
2202 this.type = undefined;
|
nickjillings@1318
|
2203 this.options = [];
|
nickjillings@1324
|
2204 this.statement = undefined;
|
nickjillings@1370
|
2205 this.schema = specification.schema.getAllElementsByName('commentquestion')[0];
|
nickjillings@1370
|
2206 this.decode = function(parent,xml)
|
nickjillings@1318
|
2207 {
|
nickjillings@1324
|
2208 this.id = xml.id;
|
nickjillings@1324
|
2209 this.type = xml.getAttribute('type');
|
nickjillings@1324
|
2210 this.statement = xml.getElementsByTagName('statement')[0].textContent;
|
nickjillings@1324
|
2211 var optNodes = xml.getElementsByTagName('option');
|
nickjillings@1324
|
2212 for (var i=0; i<optNodes.length; i++)
|
nickjillings@1324
|
2213 {
|
nickjillings@1324
|
2214 var optNode = optNodes[i];
|
nickjillings@1324
|
2215 this.options.push({
|
nickjillings@1324
|
2216 name: optNode.getAttribute('name'),
|
nickjillings@1324
|
2217 text: optNode.textContent
|
nickjillings@1324
|
2218 });
|
nickjillings@1318
|
2219 }
|
nickjillings@1318
|
2220 };
|
nickjillings@1324
|
2221
|
nickjillings@1318
|
2222 this.encode = function(root)
|
nickjillings@1318
|
2223 {
|
nickjillings@1372
|
2224 var node = root.createElement("commentquestion");
|
nickjillings@1372
|
2225 node.id = this.id;
|
nickjillings@1372
|
2226 node.setAttribute("type",this.type);
|
nickjillings@1372
|
2227 var statement = root.createElement("statement");
|
nickjillings@1372
|
2228 statement.textContent = this.statement;
|
nickjillings@1372
|
2229 node.appendChild(statement);
|
nickjillings@1372
|
2230 for (var option of this.options)
|
nickjillings@1372
|
2231 {
|
nickjillings@1372
|
2232 var child = root.createElement("option");
|
nickjillings@1372
|
2233 child.setAttribute("name",option.name);
|
nickjillings@1372
|
2234 child.textContent = option.text;
|
nickjillings@1372
|
2235 node.appendChild(child);
|
nickjillings@1372
|
2236 }
|
nickjillings@1372
|
2237 return node;
|
nickjillings@1318
|
2238 };
|
nickjillings@1318
|
2239 };
|
nickjillings@1318
|
2240
|
nickjillings@1318
|
2241 this.audioElementNode = function() {
|
nickjillings@1318
|
2242 this.url = null;
|
nickjillings@1318
|
2243 this.id = null;
|
nickjillings@1318
|
2244 this.parent = null;
|
nickjillings@1324
|
2245 this.type = null;
|
nickjillings@1318
|
2246 this.marker = false;
|
nickjillings@1318
|
2247 this.enforce = false;
|
nickjillings@1318
|
2248 this.gain = 1.0;
|
nickjillings@1370
|
2249 this.schema = specification.schema.getAllElementsByName('audioelement')[0];;
|
nickjillings@1324
|
2250 this.parent = null;
|
nickjillings@1370
|
2251 this.decode = function(parent,xml)
|
nickjillings@1318
|
2252 {
|
nickjillings@1318
|
2253 this.parent = parent;
|
nickjillings@1348
|
2254 var attributeMap = this.schema.getAllElementsByTagName('xs:attribute');
|
nickjillings@1324
|
2255 for (var i=0; i<attributeMap.length; i++)
|
nickjillings@1318
|
2256 {
|
nickjillings@1324
|
2257 var attributeName = attributeMap[i].getAttribute('name') || attributeMap[i].getAttribute('ref');
|
nickjillings@1324
|
2258 var projectAttr = xml.getAttribute(attributeName);
|
nickjillings@1324
|
2259 projectAttr = specification.processAttribute(projectAttr,attributeMap[i]);
|
nickjillings@1324
|
2260 switch(typeof projectAttr)
|
nickjillings@1318
|
2261 {
|
nickjillings@1324
|
2262 case "number":
|
nickjillings@1324
|
2263 case "boolean":
|
nickjillings@1324
|
2264 eval('this.'+attributeName+' = '+projectAttr);
|
nickjillings@1324
|
2265 break;
|
nickjillings@1324
|
2266 case "string":
|
nickjillings@1324
|
2267 eval('this.'+attributeName+' = "'+projectAttr+'"');
|
nickjillings@1324
|
2268 break;
|
nickjillings@1318
|
2269 }
|
nickjillings@1318
|
2270 }
|
nickjillings@1324
|
2271
|
nickjillings@1318
|
2272 };
|
nickjillings@1318
|
2273 this.encode = function(root)
|
nickjillings@1318
|
2274 {
|
nickjillings@1372
|
2275 var AENode = root.createElement("audioelement");
|
nickjillings@1372
|
2276 var attributes = this.schema.getAllElementsByTagName('xs:attribute');
|
nickjillings@1372
|
2277 for (var i=0; i<attributes.length; i++)
|
nickjillings@1372
|
2278 {
|
nickjillings@1372
|
2279 var name = attributes[i].getAttribute("name");
|
nickjillings@1372
|
2280 if (name == undefined) {
|
nickjillings@1372
|
2281 name = attributes[i].getAttribute("ref");
|
nickjillings@1372
|
2282 }
|
nickjillings@1372
|
2283 if(eval("this."+name+" != undefined") || attributes[i].getAttribute("use") == "required")
|
nickjillings@1372
|
2284 {
|
nickjillings@1372
|
2285 eval("AENode.setAttribute('"+name+"',this."+name+")");
|
nickjillings@1372
|
2286 }
|
nickjillings@1372
|
2287 }
|
nickjillings@1318
|
2288 return AENode;
|
nickjillings@1318
|
2289 };
|
nickjillings@1318
|
2290 };
|
nickjillings@1318
|
2291 };
|
nickjillings@1318
|
2292 }
|
nickjillings@1318
|
2293
|
nickjillings@1318
|
2294 function Interface(specificationObject) {
|
nickjillings@1318
|
2295 // This handles the bindings between the interface and the audioEngineContext;
|
nickjillings@1318
|
2296 this.specification = specificationObject;
|
nickjillings@1318
|
2297 this.insertPoint = document.getElementById("topLevelBody");
|
nickjillings@1318
|
2298
|
nickjillings@1324
|
2299 this.newPage = function(audioHolderObject,store)
|
nickjillings@1318
|
2300 {
|
nickjillings@1369
|
2301 audioEngineContext.newTestPage(audioHolderObject,store);
|
nickjillings@1318
|
2302 interfaceContext.deleteCommentBoxes();
|
nickjillings@1318
|
2303 interfaceContext.deleteCommentQuestions();
|
nickjillings@1324
|
2304 loadTest(audioHolderObject,store);
|
nickjillings@1318
|
2305 };
|
nickjillings@1318
|
2306
|
nickjillings@1318
|
2307 // Bounded by interface!!
|
nickjillings@1318
|
2308 // Interface object MUST have an exportXMLDOM method which returns the various DOM levels
|
nickjillings@1318
|
2309 // For example, APE returns the slider position normalised in a <value> tag.
|
nickjillings@1318
|
2310 this.interfaceObjects = [];
|
nickjillings@1318
|
2311 this.interfaceObject = function(){};
|
nickjillings@1318
|
2312
|
nickjillings@1318
|
2313 this.resizeWindow = function(event)
|
nickjillings@1318
|
2314 {
|
nickjillings@1318
|
2315 popup.resize(event);
|
nickjillings@1318
|
2316 for(var i=0; i<this.commentBoxes.length; i++)
|
nickjillings@1318
|
2317 {this.commentBoxes[i].resize();}
|
nickjillings@1318
|
2318 for(var i=0; i<this.commentQuestions.length; i++)
|
nickjillings@1318
|
2319 {this.commentQuestions[i].resize();}
|
nickjillings@1318
|
2320 try
|
nickjillings@1318
|
2321 {
|
nickjillings@1318
|
2322 resizeWindow(event);
|
nickjillings@1318
|
2323 }
|
nickjillings@1318
|
2324 catch(err)
|
nickjillings@1318
|
2325 {
|
nickjillings@1318
|
2326 console.log("Warning - Interface does not have Resize option");
|
nickjillings@1318
|
2327 console.log(err);
|
nickjillings@1318
|
2328 }
|
nickjillings@1318
|
2329 };
|
nickjillings@1318
|
2330
|
nickjillings@1318
|
2331 this.returnNavigator = function()
|
nickjillings@1318
|
2332 {
|
nickjillings@1362
|
2333 var node = storage.document.createElement("navigator");
|
nickjillings@1362
|
2334 var platform = storage.document.createElement("platform");
|
nickjillings@1318
|
2335 platform.textContent = navigator.platform;
|
nickjillings@1362
|
2336 var vendor = storage.document.createElement("vendor");
|
nickjillings@1318
|
2337 vendor.textContent = navigator.vendor;
|
nickjillings@1362
|
2338 var userAgent = storage.document.createElement("uagent");
|
nickjillings@1318
|
2339 userAgent.textContent = navigator.userAgent;
|
nickjillings@1362
|
2340 var screen = storage.document.createElement("window");
|
nickjillings@1362
|
2341 screen.setAttribute('innerWidth',window.innerWidth);
|
nickjillings@1362
|
2342 screen.setAttribute('innerHeight',window.innerHeight);
|
nickjillings@1318
|
2343 node.appendChild(platform);
|
nickjillings@1318
|
2344 node.appendChild(vendor);
|
nickjillings@1318
|
2345 node.appendChild(userAgent);
|
nickjillings@1362
|
2346 node.appendChild(screen);
|
nickjillings@1318
|
2347 return node;
|
nickjillings@1318
|
2348 };
|
nickjillings@1318
|
2349
|
nickjillings@1318
|
2350 this.commentBoxes = [];
|
nickjillings@1318
|
2351 this.elementCommentBox = function(audioObject) {
|
nickjillings@1318
|
2352 var element = audioObject.specification;
|
nickjillings@1318
|
2353 this.audioObject = audioObject;
|
nickjillings@1318
|
2354 this.id = audioObject.id;
|
nickjillings@1318
|
2355 var audioHolderObject = audioObject.specification.parent;
|
nickjillings@1318
|
2356 // Create document objects to hold the comment boxes
|
nickjillings@1318
|
2357 this.trackComment = document.createElement('div');
|
nickjillings@1318
|
2358 this.trackComment.className = 'comment-div';
|
nickjillings@1318
|
2359 this.trackComment.id = 'comment-div-'+audioObject.id;
|
nickjillings@1318
|
2360 // Create a string next to each comment asking for a comment
|
nickjillings@1318
|
2361 this.trackString = document.createElement('span');
|
nickjillings@1316
|
2362 this.trackString.innerHTML = audioHolderObject.commentBoxPrefix+' '+audioObject.interfaceDOM.getPresentedId();
|
nickjillings@1318
|
2363 // Create the HTML5 comment box 'textarea'
|
nickjillings@1318
|
2364 this.trackCommentBox = document.createElement('textarea');
|
nickjillings@1318
|
2365 this.trackCommentBox.rows = '4';
|
nickjillings@1318
|
2366 this.trackCommentBox.cols = '100';
|
nickjillings@1318
|
2367 this.trackCommentBox.name = 'trackComment'+audioObject.id;
|
nickjillings@1318
|
2368 this.trackCommentBox.className = 'trackComment';
|
nickjillings@1318
|
2369 var br = document.createElement('br');
|
nickjillings@1318
|
2370 // Add to the holder.
|
nickjillings@1318
|
2371 this.trackComment.appendChild(this.trackString);
|
nickjillings@1318
|
2372 this.trackComment.appendChild(br);
|
nickjillings@1318
|
2373 this.trackComment.appendChild(this.trackCommentBox);
|
nickjillings@1318
|
2374
|
nickjillings@1318
|
2375 this.exportXMLDOM = function() {
|
nickjillings@1318
|
2376 var root = document.createElement('comment');
|
nickjillings@1318
|
2377 if (this.audioObject.specification.parent.elementComments) {
|
nickjillings@1318
|
2378 var question = document.createElement('question');
|
nickjillings@1318
|
2379 question.textContent = this.trackString.textContent;
|
nickjillings@1318
|
2380 var response = document.createElement('response');
|
nickjillings@1318
|
2381 response.textContent = this.trackCommentBox.value;
|
nickjillings@1318
|
2382 console.log("Comment frag-"+this.id+": "+response.textContent);
|
nickjillings@1318
|
2383 root.appendChild(question);
|
nickjillings@1318
|
2384 root.appendChild(response);
|
nickjillings@1318
|
2385 }
|
nickjillings@1318
|
2386 return root;
|
nickjillings@1318
|
2387 };
|
nickjillings@1318
|
2388 this.resize = function()
|
nickjillings@1318
|
2389 {
|
nickjillings@1318
|
2390 var boxwidth = (window.innerWidth-100)/2;
|
nickjillings@1318
|
2391 if (boxwidth >= 600)
|
nickjillings@1318
|
2392 {
|
nickjillings@1318
|
2393 boxwidth = 600;
|
nickjillings@1318
|
2394 }
|
nickjillings@1318
|
2395 else if (boxwidth < 400)
|
nickjillings@1318
|
2396 {
|
nickjillings@1318
|
2397 boxwidth = 400;
|
nickjillings@1318
|
2398 }
|
nickjillings@1318
|
2399 this.trackComment.style.width = boxwidth+"px";
|
nickjillings@1318
|
2400 this.trackCommentBox.style.width = boxwidth-6+"px";
|
nickjillings@1318
|
2401 };
|
nickjillings@1318
|
2402 this.resize();
|
nickjillings@1318
|
2403 };
|
nickjillings@1318
|
2404
|
nickjillings@1318
|
2405 this.commentQuestions = [];
|
nickjillings@1318
|
2406
|
nickjillings@1318
|
2407 this.commentBox = function(commentQuestion) {
|
nickjillings@1318
|
2408 this.specification = commentQuestion;
|
nickjillings@1318
|
2409 // Create document objects to hold the comment boxes
|
nickjillings@1318
|
2410 this.holder = document.createElement('div');
|
nickjillings@1318
|
2411 this.holder.className = 'comment-div';
|
nickjillings@1318
|
2412 // Create a string next to each comment asking for a comment
|
nickjillings@1318
|
2413 this.string = document.createElement('span');
|
nickjillings@1324
|
2414 this.string.innerHTML = commentQuestion.statement;
|
nickjillings@1318
|
2415 // Create the HTML5 comment box 'textarea'
|
nickjillings@1318
|
2416 this.textArea = document.createElement('textarea');
|
nickjillings@1318
|
2417 this.textArea.rows = '4';
|
nickjillings@1318
|
2418 this.textArea.cols = '100';
|
nickjillings@1318
|
2419 this.textArea.className = 'trackComment';
|
nickjillings@1318
|
2420 var br = document.createElement('br');
|
nickjillings@1318
|
2421 // Add to the holder.
|
nickjillings@1318
|
2422 this.holder.appendChild(this.string);
|
nickjillings@1318
|
2423 this.holder.appendChild(br);
|
nickjillings@1318
|
2424 this.holder.appendChild(this.textArea);
|
nickjillings@1318
|
2425
|
nickjillings@1318
|
2426 this.exportXMLDOM = function() {
|
nickjillings@1318
|
2427 var root = document.createElement('comment');
|
nickjillings@1318
|
2428 root.id = this.specification.id;
|
nickjillings@1318
|
2429 root.setAttribute('type',this.specification.type);
|
nickjillings@1318
|
2430 root.textContent = this.textArea.value;
|
nickjillings@1318
|
2431 console.log("Question: "+this.string.textContent);
|
nickjillings@1318
|
2432 console.log("Response: "+root.textContent);
|
nickjillings@1318
|
2433 return root;
|
nickjillings@1318
|
2434 };
|
nickjillings@1318
|
2435 this.resize = function()
|
nickjillings@1318
|
2436 {
|
nickjillings@1318
|
2437 var boxwidth = (window.innerWidth-100)/2;
|
nickjillings@1318
|
2438 if (boxwidth >= 600)
|
nickjillings@1318
|
2439 {
|
nickjillings@1318
|
2440 boxwidth = 600;
|
nickjillings@1318
|
2441 }
|
nickjillings@1318
|
2442 else if (boxwidth < 400)
|
nickjillings@1318
|
2443 {
|
nickjillings@1318
|
2444 boxwidth = 400;
|
nickjillings@1318
|
2445 }
|
nickjillings@1318
|
2446 this.holder.style.width = boxwidth+"px";
|
nickjillings@1318
|
2447 this.textArea.style.width = boxwidth-6+"px";
|
nickjillings@1318
|
2448 };
|
nickjillings@1318
|
2449 this.resize();
|
nickjillings@1318
|
2450 };
|
nickjillings@1318
|
2451
|
nickjillings@1318
|
2452 this.radioBox = function(commentQuestion) {
|
nickjillings@1318
|
2453 this.specification = commentQuestion;
|
nickjillings@1318
|
2454 // Create document objects to hold the comment boxes
|
nickjillings@1318
|
2455 this.holder = document.createElement('div');
|
nickjillings@1318
|
2456 this.holder.className = 'comment-div';
|
nickjillings@1318
|
2457 // Create a string next to each comment asking for a comment
|
nickjillings@1318
|
2458 this.string = document.createElement('span');
|
nickjillings@1318
|
2459 this.string.innerHTML = commentQuestion.statement;
|
nickjillings@1318
|
2460 var br = document.createElement('br');
|
nickjillings@1318
|
2461 // Add to the holder.
|
nickjillings@1318
|
2462 this.holder.appendChild(this.string);
|
nickjillings@1318
|
2463 this.holder.appendChild(br);
|
nickjillings@1318
|
2464 this.options = [];
|
nickjillings@1318
|
2465 this.inputs = document.createElement('div');
|
nickjillings@1318
|
2466 this.span = document.createElement('div');
|
nickjillings@1318
|
2467 this.inputs.align = 'center';
|
nickjillings@1318
|
2468 this.inputs.style.marginLeft = '12px';
|
nickjillings@1318
|
2469 this.span.style.marginLeft = '12px';
|
nickjillings@1318
|
2470 this.span.align = 'center';
|
nickjillings@1318
|
2471 this.span.style.marginTop = '15px';
|
nickjillings@1318
|
2472
|
nickjillings@1318
|
2473 var optCount = commentQuestion.options.length;
|
nickjillings@1324
|
2474 for (var optNode of commentQuestion.options)
|
nickjillings@1318
|
2475 {
|
nickjillings@1318
|
2476 var div = document.createElement('div');
|
nickjillings@1318
|
2477 div.style.width = '80px';
|
nickjillings@1318
|
2478 div.style.float = 'left';
|
nickjillings@1318
|
2479 var input = document.createElement('input');
|
nickjillings@1318
|
2480 input.type = 'radio';
|
nickjillings@1318
|
2481 input.name = commentQuestion.id;
|
nickjillings@1324
|
2482 input.setAttribute('setvalue',optNode.name);
|
nickjillings@1318
|
2483 input.className = 'comment-radio';
|
nickjillings@1318
|
2484 div.appendChild(input);
|
nickjillings@1318
|
2485 this.inputs.appendChild(div);
|
nickjillings@1318
|
2486
|
nickjillings@1318
|
2487
|
nickjillings@1318
|
2488 div = document.createElement('div');
|
nickjillings@1318
|
2489 div.style.width = '80px';
|
nickjillings@1318
|
2490 div.style.float = 'left';
|
nickjillings@1318
|
2491 div.align = 'center';
|
nickjillings@1318
|
2492 var span = document.createElement('span');
|
nickjillings@1324
|
2493 span.textContent = optNode.text;
|
nickjillings@1318
|
2494 span.className = 'comment-radio-span';
|
nickjillings@1318
|
2495 div.appendChild(span);
|
nickjillings@1318
|
2496 this.span.appendChild(div);
|
nickjillings@1318
|
2497 this.options.push(input);
|
nickjillings@1318
|
2498 }
|
nickjillings@1318
|
2499 this.holder.appendChild(this.span);
|
nickjillings@1318
|
2500 this.holder.appendChild(this.inputs);
|
nickjillings@1318
|
2501
|
nickjillings@1318
|
2502 this.exportXMLDOM = function() {
|
nickjillings@1318
|
2503 var root = document.createElement('comment');
|
nickjillings@1318
|
2504 root.id = this.specification.id;
|
nickjillings@1318
|
2505 root.setAttribute('type',this.specification.type);
|
nickjillings@1318
|
2506 var question = document.createElement('question');
|
nickjillings@1318
|
2507 question.textContent = this.string.textContent;
|
nickjillings@1318
|
2508 var response = document.createElement('response');
|
nickjillings@1318
|
2509 var i=0;
|
nickjillings@1318
|
2510 while(this.options[i].checked == false) {
|
nickjillings@1318
|
2511 i++;
|
nickjillings@1318
|
2512 if (i >= this.options.length) {
|
nickjillings@1318
|
2513 break;
|
nickjillings@1318
|
2514 }
|
nickjillings@1318
|
2515 }
|
nickjillings@1318
|
2516 if (i >= this.options.length) {
|
nickjillings@1318
|
2517 response.textContent = 'null';
|
nickjillings@1318
|
2518 } else {
|
nickjillings@1318
|
2519 response.textContent = this.options[i].getAttribute('setvalue');
|
nickjillings@1318
|
2520 response.setAttribute('number',i);
|
nickjillings@1318
|
2521 }
|
nickjillings@1318
|
2522 console.log('Comment: '+question.textContent);
|
nickjillings@1318
|
2523 console.log('Response: '+response.textContent);
|
nickjillings@1318
|
2524 root.appendChild(question);
|
nickjillings@1318
|
2525 root.appendChild(response);
|
nickjillings@1318
|
2526 return root;
|
nickjillings@1318
|
2527 };
|
nickjillings@1318
|
2528 this.resize = function()
|
nickjillings@1318
|
2529 {
|
nickjillings@1318
|
2530 var boxwidth = (window.innerWidth-100)/2;
|
nickjillings@1318
|
2531 if (boxwidth >= 600)
|
nickjillings@1318
|
2532 {
|
nickjillings@1318
|
2533 boxwidth = 600;
|
nickjillings@1318
|
2534 }
|
nickjillings@1318
|
2535 else if (boxwidth < 400)
|
nickjillings@1318
|
2536 {
|
nickjillings@1318
|
2537 boxwidth = 400;
|
nickjillings@1318
|
2538 }
|
nickjillings@1318
|
2539 this.holder.style.width = boxwidth+"px";
|
nickjillings@1318
|
2540 var text = this.holder.children[2];
|
nickjillings@1318
|
2541 var options = this.holder.children[3];
|
nickjillings@1318
|
2542 var optCount = options.children.length;
|
nickjillings@1318
|
2543 var spanMargin = Math.floor(((boxwidth-20-(optCount*80))/(optCount))/2)+'px';
|
nickjillings@1318
|
2544 var options = options.firstChild;
|
nickjillings@1318
|
2545 var text = text.firstChild;
|
nickjillings@1318
|
2546 options.style.marginRight = spanMargin;
|
nickjillings@1318
|
2547 options.style.marginLeft = spanMargin;
|
nickjillings@1318
|
2548 text.style.marginRight = spanMargin;
|
nickjillings@1318
|
2549 text.style.marginLeft = spanMargin;
|
nickjillings@1318
|
2550 while(options.nextSibling != undefined)
|
nickjillings@1318
|
2551 {
|
nickjillings@1318
|
2552 options = options.nextSibling;
|
nickjillings@1318
|
2553 text = text.nextSibling;
|
nickjillings@1318
|
2554 options.style.marginRight = spanMargin;
|
nickjillings@1318
|
2555 options.style.marginLeft = spanMargin;
|
nickjillings@1318
|
2556 text.style.marginRight = spanMargin;
|
nickjillings@1318
|
2557 text.style.marginLeft = spanMargin;
|
nickjillings@1318
|
2558 }
|
nickjillings@1318
|
2559 };
|
nickjillings@1318
|
2560 this.resize();
|
nickjillings@1318
|
2561 };
|
nickjillings@1318
|
2562
|
nickjillings@1318
|
2563 this.checkboxBox = function(commentQuestion) {
|
nickjillings@1318
|
2564 this.specification = commentQuestion;
|
nickjillings@1318
|
2565 // Create document objects to hold the comment boxes
|
nickjillings@1318
|
2566 this.holder = document.createElement('div');
|
nickjillings@1318
|
2567 this.holder.className = 'comment-div';
|
nickjillings@1318
|
2568 // Create a string next to each comment asking for a comment
|
nickjillings@1318
|
2569 this.string = document.createElement('span');
|
nickjillings@1318
|
2570 this.string.innerHTML = commentQuestion.statement;
|
nickjillings@1318
|
2571 var br = document.createElement('br');
|
nickjillings@1318
|
2572 // Add to the holder.
|
nickjillings@1318
|
2573 this.holder.appendChild(this.string);
|
nickjillings@1318
|
2574 this.holder.appendChild(br);
|
nickjillings@1318
|
2575 this.options = [];
|
nickjillings@1318
|
2576 this.inputs = document.createElement('div');
|
nickjillings@1318
|
2577 this.span = document.createElement('div');
|
nickjillings@1318
|
2578 this.inputs.align = 'center';
|
nickjillings@1318
|
2579 this.inputs.style.marginLeft = '12px';
|
nickjillings@1318
|
2580 this.span.style.marginLeft = '12px';
|
nickjillings@1318
|
2581 this.span.align = 'center';
|
nickjillings@1318
|
2582 this.span.style.marginTop = '15px';
|
nickjillings@1318
|
2583
|
nickjillings@1318
|
2584 var optCount = commentQuestion.options.length;
|
nickjillings@1318
|
2585 for (var i=0; i<optCount; i++)
|
nickjillings@1318
|
2586 {
|
nickjillings@1318
|
2587 var div = document.createElement('div');
|
nickjillings@1318
|
2588 div.style.width = '80px';
|
nickjillings@1318
|
2589 div.style.float = 'left';
|
nickjillings@1318
|
2590 var input = document.createElement('input');
|
nickjillings@1318
|
2591 input.type = 'checkbox';
|
nickjillings@1318
|
2592 input.name = commentQuestion.id;
|
nickjillings@1318
|
2593 input.setAttribute('setvalue',commentQuestion.options[i].name);
|
nickjillings@1318
|
2594 input.className = 'comment-radio';
|
nickjillings@1318
|
2595 div.appendChild(input);
|
nickjillings@1318
|
2596 this.inputs.appendChild(div);
|
nickjillings@1318
|
2597
|
nickjillings@1318
|
2598
|
nickjillings@1318
|
2599 div = document.createElement('div');
|
nickjillings@1318
|
2600 div.style.width = '80px';
|
nickjillings@1318
|
2601 div.style.float = 'left';
|
nickjillings@1318
|
2602 div.align = 'center';
|
nickjillings@1318
|
2603 var span = document.createElement('span');
|
nickjillings@1318
|
2604 span.textContent = commentQuestion.options[i].text;
|
nickjillings@1318
|
2605 span.className = 'comment-radio-span';
|
nickjillings@1318
|
2606 div.appendChild(span);
|
nickjillings@1318
|
2607 this.span.appendChild(div);
|
nickjillings@1318
|
2608 this.options.push(input);
|
nickjillings@1318
|
2609 }
|
nickjillings@1318
|
2610 this.holder.appendChild(this.span);
|
nickjillings@1318
|
2611 this.holder.appendChild(this.inputs);
|
nickjillings@1318
|
2612
|
nickjillings@1318
|
2613 this.exportXMLDOM = function() {
|
nickjillings@1318
|
2614 var root = document.createElement('comment');
|
nickjillings@1318
|
2615 root.id = this.specification.id;
|
nickjillings@1318
|
2616 root.setAttribute('type',this.specification.type);
|
nickjillings@1318
|
2617 var question = document.createElement('question');
|
nickjillings@1318
|
2618 question.textContent = this.string.textContent;
|
nickjillings@1318
|
2619 root.appendChild(question);
|
nickjillings@1318
|
2620 console.log('Comment: '+question.textContent);
|
nickjillings@1318
|
2621 for (var i=0; i<this.options.length; i++) {
|
nickjillings@1318
|
2622 var response = document.createElement('response');
|
nickjillings@1318
|
2623 response.textContent = this.options[i].checked;
|
nickjillings@1318
|
2624 response.setAttribute('name',this.options[i].getAttribute('setvalue'));
|
nickjillings@1318
|
2625 root.appendChild(response);
|
nickjillings@1318
|
2626 console.log('Response '+response.getAttribute('name') +': '+response.textContent);
|
nickjillings@1318
|
2627 }
|
nickjillings@1318
|
2628 return root;
|
nickjillings@1318
|
2629 };
|
nickjillings@1318
|
2630 this.resize = function()
|
nickjillings@1318
|
2631 {
|
nickjillings@1318
|
2632 var boxwidth = (window.innerWidth-100)/2;
|
nickjillings@1318
|
2633 if (boxwidth >= 600)
|
nickjillings@1318
|
2634 {
|
nickjillings@1318
|
2635 boxwidth = 600;
|
nickjillings@1318
|
2636 }
|
nickjillings@1318
|
2637 else if (boxwidth < 400)
|
nickjillings@1318
|
2638 {
|
nickjillings@1318
|
2639 boxwidth = 400;
|
nickjillings@1318
|
2640 }
|
nickjillings@1318
|
2641 this.holder.style.width = boxwidth+"px";
|
nickjillings@1318
|
2642 var text = this.holder.children[2];
|
nickjillings@1318
|
2643 var options = this.holder.children[3];
|
nickjillings@1318
|
2644 var optCount = options.children.length;
|
nickjillings@1318
|
2645 var spanMargin = Math.floor(((boxwidth-20-(optCount*80))/(optCount))/2)+'px';
|
nickjillings@1318
|
2646 var options = options.firstChild;
|
nickjillings@1318
|
2647 var text = text.firstChild;
|
nickjillings@1318
|
2648 options.style.marginRight = spanMargin;
|
nickjillings@1318
|
2649 options.style.marginLeft = spanMargin;
|
nickjillings@1318
|
2650 text.style.marginRight = spanMargin;
|
nickjillings@1318
|
2651 text.style.marginLeft = spanMargin;
|
nickjillings@1318
|
2652 while(options.nextSibling != undefined)
|
nickjillings@1318
|
2653 {
|
nickjillings@1318
|
2654 options = options.nextSibling;
|
nickjillings@1318
|
2655 text = text.nextSibling;
|
nickjillings@1318
|
2656 options.style.marginRight = spanMargin;
|
nickjillings@1318
|
2657 options.style.marginLeft = spanMargin;
|
nickjillings@1318
|
2658 text.style.marginRight = spanMargin;
|
nickjillings@1318
|
2659 text.style.marginLeft = spanMargin;
|
nickjillings@1318
|
2660 }
|
nickjillings@1318
|
2661 };
|
nickjillings@1318
|
2662 this.resize();
|
nickjillings@1318
|
2663 };
|
nickjillings@1318
|
2664
|
nickjillings@1318
|
2665 this.createCommentBox = function(audioObject) {
|
nickjillings@1318
|
2666 var node = new this.elementCommentBox(audioObject);
|
nickjillings@1318
|
2667 this.commentBoxes.push(node);
|
nickjillings@1318
|
2668 audioObject.commentDOM = node;
|
nickjillings@1318
|
2669 return node;
|
nickjillings@1318
|
2670 };
|
nickjillings@1318
|
2671
|
nickjillings@1318
|
2672 this.sortCommentBoxes = function() {
|
nickjillings@1338
|
2673 this.commentBoxes.sort(function(a,b){return a.id - b.id;});
|
nickjillings@1318
|
2674 };
|
nickjillings@1318
|
2675
|
nickjillings@1318
|
2676 this.showCommentBoxes = function(inject, sort) {
|
nickjillings@1318
|
2677 if (sort) {interfaceContext.sortCommentBoxes();}
|
nickjillings@1338
|
2678 for (var box of interfaceContext.commentBoxes) {
|
nickjillings@1338
|
2679 inject.appendChild(box.trackComment);
|
nickjillings@1318
|
2680 }
|
nickjillings@1318
|
2681 };
|
nickjillings@1318
|
2682
|
nickjillings@1318
|
2683 this.deleteCommentBoxes = function() {
|
nickjillings@1318
|
2684 this.commentBoxes = [];
|
nickjillings@1318
|
2685 };
|
nickjillings@1318
|
2686
|
nickjillings@1318
|
2687 this.createCommentQuestion = function(element) {
|
nickjillings@1318
|
2688 var node;
|
nickjillings@1324
|
2689 if (element.type == 'question') {
|
nickjillings@1318
|
2690 node = new this.commentBox(element);
|
nickjillings@1318
|
2691 } else if (element.type == 'radio') {
|
nickjillings@1318
|
2692 node = new this.radioBox(element);
|
nickjillings@1318
|
2693 } else if (element.type == 'checkbox') {
|
nickjillings@1318
|
2694 node = new this.checkboxBox(element);
|
nickjillings@1318
|
2695 }
|
nickjillings@1318
|
2696 this.commentQuestions.push(node);
|
nickjillings@1318
|
2697 return node;
|
nickjillings@1318
|
2698 };
|
nickjillings@1318
|
2699
|
nickjillings@1318
|
2700 this.deleteCommentQuestions = function()
|
nickjillings@1318
|
2701 {
|
nickjillings@1318
|
2702 this.commentQuestions = [];
|
nickjillings@1318
|
2703 };
|
nickjillings@1318
|
2704
|
nickjillings@1318
|
2705 this.playhead = new function()
|
nickjillings@1318
|
2706 {
|
nickjillings@1318
|
2707 this.object = document.createElement('div');
|
nickjillings@1318
|
2708 this.object.className = 'playhead';
|
nickjillings@1318
|
2709 this.object.align = 'left';
|
nickjillings@1318
|
2710 var curTime = document.createElement('div');
|
nickjillings@1318
|
2711 curTime.style.width = '50px';
|
nickjillings@1318
|
2712 this.curTimeSpan = document.createElement('span');
|
nickjillings@1318
|
2713 this.curTimeSpan.textContent = '00:00';
|
nickjillings@1318
|
2714 curTime.appendChild(this.curTimeSpan);
|
nickjillings@1318
|
2715 this.object.appendChild(curTime);
|
nickjillings@1318
|
2716 this.scrubberTrack = document.createElement('div');
|
nickjillings@1318
|
2717 this.scrubberTrack.className = 'playhead-scrub-track';
|
nickjillings@1318
|
2718
|
nickjillings@1318
|
2719 this.scrubberHead = document.createElement('div');
|
nickjillings@1318
|
2720 this.scrubberHead.id = 'playhead-scrubber';
|
nickjillings@1318
|
2721 this.scrubberTrack.appendChild(this.scrubberHead);
|
nickjillings@1318
|
2722 this.object.appendChild(this.scrubberTrack);
|
nickjillings@1318
|
2723
|
nickjillings@1318
|
2724 this.timePerPixel = 0;
|
nickjillings@1318
|
2725 this.maxTime = 0;
|
nickjillings@1318
|
2726
|
nickjillings@1318
|
2727 this.playbackObject;
|
nickjillings@1318
|
2728
|
nickjillings@1318
|
2729 this.setTimePerPixel = function(audioObject) {
|
nickjillings@1318
|
2730 //maxTime must be in seconds
|
nickjillings@1318
|
2731 this.playbackObject = audioObject;
|
nickjillings@1318
|
2732 this.maxTime = audioObject.buffer.buffer.duration;
|
nickjillings@1318
|
2733 var width = 490; //500 - 10, 5 each side of the tracker head
|
nickjillings@1318
|
2734 this.timePerPixel = this.maxTime/490;
|
nickjillings@1318
|
2735 if (this.maxTime < 60) {
|
nickjillings@1318
|
2736 this.curTimeSpan.textContent = '0.00';
|
nickjillings@1318
|
2737 } else {
|
nickjillings@1318
|
2738 this.curTimeSpan.textContent = '00:00';
|
nickjillings@1318
|
2739 }
|
nickjillings@1318
|
2740 };
|
nickjillings@1318
|
2741
|
nickjillings@1318
|
2742 this.update = function() {
|
nickjillings@1318
|
2743 // Update the playhead position, startPlay must be called
|
nickjillings@1318
|
2744 if (this.timePerPixel > 0) {
|
nickjillings@1318
|
2745 var time = this.playbackObject.getCurrentPosition();
|
nickjillings@1367
|
2746 if (time > 0 && time < this.maxTime) {
|
nickjillings@1318
|
2747 var width = 490;
|
nickjillings@1318
|
2748 var pix = Math.floor(time/this.timePerPixel);
|
nickjillings@1318
|
2749 this.scrubberHead.style.left = pix+'px';
|
nickjillings@1318
|
2750 if (this.maxTime > 60.0) {
|
nickjillings@1318
|
2751 var secs = time%60;
|
nickjillings@1318
|
2752 var mins = Math.floor((time-secs)/60);
|
nickjillings@1318
|
2753 secs = secs.toString();
|
nickjillings@1318
|
2754 secs = secs.substr(0,2);
|
nickjillings@1318
|
2755 mins = mins.toString();
|
nickjillings@1318
|
2756 this.curTimeSpan.textContent = mins+':'+secs;
|
nickjillings@1318
|
2757 } else {
|
nickjillings@1318
|
2758 time = time.toString();
|
nickjillings@1318
|
2759 this.curTimeSpan.textContent = time.substr(0,4);
|
nickjillings@1318
|
2760 }
|
nickjillings@1318
|
2761 } else {
|
nickjillings@1318
|
2762 this.scrubberHead.style.left = '0px';
|
nickjillings@1318
|
2763 if (this.maxTime < 60) {
|
nickjillings@1318
|
2764 this.curTimeSpan.textContent = '0.00';
|
nickjillings@1318
|
2765 } else {
|
nickjillings@1318
|
2766 this.curTimeSpan.textContent = '00:00';
|
nickjillings@1318
|
2767 }
|
nickjillings@1318
|
2768 }
|
nickjillings@1318
|
2769 }
|
nickjillings@1318
|
2770 };
|
nickjillings@1318
|
2771
|
nickjillings@1318
|
2772 this.interval = undefined;
|
nickjillings@1318
|
2773
|
nickjillings@1318
|
2774 this.start = function() {
|
nickjillings@1318
|
2775 if (this.playbackObject != undefined && this.interval == undefined) {
|
nickjillings@1318
|
2776 if (this.maxTime < 60) {
|
nickjillings@1318
|
2777 this.interval = setInterval(function(){interfaceContext.playhead.update();},10);
|
nickjillings@1318
|
2778 } else {
|
nickjillings@1318
|
2779 this.interval = setInterval(function(){interfaceContext.playhead.update();},100);
|
nickjillings@1318
|
2780 }
|
nickjillings@1318
|
2781 }
|
nickjillings@1318
|
2782 };
|
nickjillings@1318
|
2783 this.stop = function() {
|
nickjillings@1318
|
2784 clearInterval(this.interval);
|
nickjillings@1318
|
2785 this.interval = undefined;
|
nickjillings@1318
|
2786 if (this.maxTime < 60) {
|
nickjillings@1318
|
2787 this.curTimeSpan.textContent = '0.00';
|
nickjillings@1318
|
2788 } else {
|
nickjillings@1318
|
2789 this.curTimeSpan.textContent = '00:00';
|
nickjillings@1318
|
2790 }
|
nickjillings@1318
|
2791 };
|
nickjillings@1318
|
2792 };
|
nickjillings@1354
|
2793
|
nickjillings@1354
|
2794 this.volume = new function()
|
nickjillings@1354
|
2795 {
|
nickjillings@1354
|
2796 // An in-built volume module which can be viewed on page
|
nickjillings@1354
|
2797 // Includes trackers on page-by-page data
|
nickjillings@1354
|
2798 // Volume does NOT reset to 0dB on each page load
|
nickjillings@1354
|
2799 this.valueLin = 1.0;
|
nickjillings@1354
|
2800 this.valueDB = 0.0;
|
nickjillings@1354
|
2801 this.object = document.createElement('div');
|
nickjillings@1354
|
2802 this.object.id = 'master-volume-holder';
|
nickjillings@1354
|
2803 this.slider = document.createElement('input');
|
nickjillings@1354
|
2804 this.slider.id = 'master-volume-control';
|
nickjillings@1354
|
2805 this.slider.type = 'range';
|
nickjillings@1354
|
2806 this.valueText = document.createElement('span');
|
nickjillings@1354
|
2807 this.valueText.id = 'master-volume-feedback';
|
nickjillings@1354
|
2808 this.valueText.textContent = '0dB';
|
nickjillings@1354
|
2809
|
nickjillings@1354
|
2810 this.slider.min = -60;
|
nickjillings@1354
|
2811 this.slider.max = 12;
|
nickjillings@1354
|
2812 this.slider.value = 0;
|
nickjillings@1354
|
2813 this.slider.step = 1;
|
nickjillings@1354
|
2814 this.slider.onmousemove = function(event)
|
nickjillings@1354
|
2815 {
|
nickjillings@1354
|
2816 interfaceContext.volume.valueDB = event.currentTarget.value;
|
nickjillings@1354
|
2817 interfaceContext.volume.valueLin = decibelToLinear(interfaceContext.volume.valueDB);
|
nickjillings@1354
|
2818 interfaceContext.volume.valueText.textContent = interfaceContext.volume.valueDB+'dB';
|
nickjillings@1354
|
2819 audioEngineContext.outputGain.gain.value = interfaceContext.volume.valueLin;
|
nickjillings@1354
|
2820 }
|
nickjillings@1354
|
2821 this.slider.onmouseup = function(event)
|
nickjillings@1354
|
2822 {
|
nickjillings@1354
|
2823 var storePoint = testState.currentStore.XMLDOM.children[0].getAllElementsByName('volumeTracker');
|
nickjillings@1354
|
2824 if (storePoint.length == 0)
|
nickjillings@1354
|
2825 {
|
nickjillings@1354
|
2826 storePoint = storage.document.createElement('metricresult');
|
nickjillings@1354
|
2827 storePoint.setAttribute('name','volumeTracker');
|
nickjillings@1354
|
2828 testState.currentStore.XMLDOM.children[0].appendChild(storePoint);
|
nickjillings@1354
|
2829 }
|
nickjillings@1354
|
2830 else {
|
nickjillings@1354
|
2831 storePoint = storePoint[0];
|
nickjillings@1354
|
2832 }
|
nickjillings@1354
|
2833 var node = storage.document.createElement('movement');
|
nickjillings@1354
|
2834 node.setAttribute('test-time',audioEngineContext.timer.getTestTime());
|
nickjillings@1354
|
2835 node.setAttribute('volume',interfaceContext.volume.valueDB);
|
nickjillings@1354
|
2836 node.setAttribute('format','dBFS');
|
nickjillings@1354
|
2837 storePoint.appendChild(node);
|
nickjillings@1354
|
2838 }
|
nickjillings@1354
|
2839
|
nickjillings@1355
|
2840 var title = document.createElement('div');
|
nickjillings@1355
|
2841 title.innerHTML = '<span>Master Volume Control</span>';
|
nickjillings@1355
|
2842 title.style.fontSize = '0.75em';
|
nickjillings@1355
|
2843 title.style.width = "100%";
|
nickjillings@1355
|
2844 title.align = 'center';
|
nickjillings@1355
|
2845 this.object.appendChild(title);
|
nickjillings@1355
|
2846
|
nickjillings@1354
|
2847 this.object.appendChild(this.slider);
|
nickjillings@1354
|
2848 this.object.appendChild(this.valueText);
|
nickjillings@1354
|
2849 }
|
nickjillings@1318
|
2850 // Global Checkers
|
nickjillings@1318
|
2851 // These functions will help enforce the checkers
|
nickjillings@1318
|
2852 this.checkHiddenAnchor = function()
|
nickjillings@1318
|
2853 {
|
nickjillings@1324
|
2854 for (var ao of audioEngineContext.audioObjects)
|
nickjillings@1318
|
2855 {
|
nickjillings@1324
|
2856 if (ao.specification.type == "anchor")
|
nickjillings@1318
|
2857 {
|
nickjillings@1325
|
2858 if (ao.interfaceDOM.getValue() > (ao.specification.marker/100) && ao.specification.marker > 0) {
|
nickjillings@1324
|
2859 // Anchor is not set below
|
nickjillings@1324
|
2860 console.log('Anchor node not below marker value');
|
nickjillings@1324
|
2861 alert('Please keep listening');
|
nickjillings@1367
|
2862 this.storeErrorNode('Anchor node not below marker value');
|
nickjillings@1324
|
2863 return false;
|
nickjillings@1324
|
2864 }
|
nickjillings@1318
|
2865 }
|
nickjillings@1318
|
2866 }
|
nickjillings@1318
|
2867 return true;
|
nickjillings@1318
|
2868 };
|
nickjillings@1318
|
2869
|
nickjillings@1318
|
2870 this.checkHiddenReference = function()
|
nickjillings@1318
|
2871 {
|
nickjillings@1324
|
2872 for (var ao of audioEngineContext.audioObjects)
|
nickjillings@1318
|
2873 {
|
nickjillings@1324
|
2874 if (ao.specification.type == "reference")
|
nickjillings@1318
|
2875 {
|
nickjillings@1325
|
2876 if (ao.interfaceDOM.getValue() < (ao.specification.marker/100) && ao.specification.marker > 0) {
|
nickjillings@1324
|
2877 // Anchor is not set below
|
nickjillings@1367
|
2878 console.log('Reference node not above marker value');
|
nickjillings@1367
|
2879 this.storeErrorNode('Reference node not above marker value');
|
nickjillings@1324
|
2880 alert('Please keep listening');
|
nickjillings@1324
|
2881 return false;
|
nickjillings@1324
|
2882 }
|
nickjillings@1318
|
2883 }
|
nickjillings@1318
|
2884 }
|
nickjillings@1318
|
2885 return true;
|
nickjillings@1318
|
2886 };
|
nickjillings@1318
|
2887
|
nickjillings@1318
|
2888 this.checkFragmentsFullyPlayed = function ()
|
nickjillings@1318
|
2889 {
|
nickjillings@1318
|
2890 // Checks the entire file has been played back
|
nickjillings@1318
|
2891 // NOTE ! This will return true IF playback is Looped!!!
|
nickjillings@1318
|
2892 if (audioEngineContext.loopPlayback)
|
nickjillings@1318
|
2893 {
|
nickjillings@1318
|
2894 console.log("WARNING - Looped source: Cannot check fragments are fully played");
|
nickjillings@1318
|
2895 return true;
|
nickjillings@1318
|
2896 }
|
nickjillings@1318
|
2897 var check_pass = true;
|
nickjillings@1318
|
2898 var error_obj = [];
|
nickjillings@1318
|
2899 for (var i = 0; i<audioEngineContext.audioObjects.length; i++)
|
nickjillings@1318
|
2900 {
|
nickjillings@1318
|
2901 var object = audioEngineContext.audioObjects[i];
|
nickjillings@1318
|
2902 var time = object.buffer.buffer.duration;
|
nickjillings@1318
|
2903 var metric = object.metric;
|
nickjillings@1318
|
2904 var passed = false;
|
nickjillings@1318
|
2905 for (var j=0; j<metric.listenTracker.length; j++)
|
nickjillings@1318
|
2906 {
|
nickjillings@1318
|
2907 var bt = metric.listenTracker[j].getElementsByTagName('buffertime');
|
nickjillings@1318
|
2908 var start_time = Number(bt[0].getAttribute('start'));
|
nickjillings@1318
|
2909 var stop_time = Number(bt[0].getAttribute('stop'));
|
nickjillings@1318
|
2910 var delta = stop_time - start_time;
|
nickjillings@1318
|
2911 if (delta >= time)
|
nickjillings@1318
|
2912 {
|
nickjillings@1318
|
2913 passed = true;
|
nickjillings@1318
|
2914 break;
|
nickjillings@1318
|
2915 }
|
nickjillings@1318
|
2916 }
|
nickjillings@1318
|
2917 if (passed == false)
|
nickjillings@1318
|
2918 {
|
nickjillings@1318
|
2919 check_pass = false;
|
nickjillings@1340
|
2920 console.log("Continue listening to track-"+audioEngineContext.audioObjects.interfaceDOM.getPresentedId());
|
nickjillings@1340
|
2921 error_obj.push(audioEngineContext.audioObjects.interfaceDOM.getPresentedId());
|
nickjillings@1318
|
2922 }
|
nickjillings@1318
|
2923 }
|
nickjillings@1318
|
2924 if (check_pass == false)
|
nickjillings@1318
|
2925 {
|
nickjillings@1318
|
2926 var str_start = "You have not completely listened to fragments ";
|
nickjillings@1318
|
2927 for (var i=0; i<error_obj.length; i++)
|
nickjillings@1318
|
2928 {
|
nickjillings@1318
|
2929 str_start += error_obj[i];
|
nickjillings@1318
|
2930 if (i != error_obj.length-1)
|
nickjillings@1318
|
2931 {
|
nickjillings@1318
|
2932 str_start += ', ';
|
nickjillings@1318
|
2933 }
|
nickjillings@1318
|
2934 }
|
nickjillings@1318
|
2935 str_start += ". Please keep listening";
|
nickjillings@1318
|
2936 console.log("[ALERT]: "+str_start);
|
nickjillings@1367
|
2937 this.storeErrorNode("[ALERT]: "+str_start);
|
nickjillings@1318
|
2938 alert(str_start);
|
nickjillings@1318
|
2939 }
|
nickjillings@1318
|
2940 };
|
nickjillings@1318
|
2941 this.checkAllMoved = function()
|
nickjillings@1318
|
2942 {
|
nickjillings@1318
|
2943 var str = "You have not moved ";
|
nickjillings@1318
|
2944 var failed = [];
|
nickjillings@1340
|
2945 for (var ao of audioEngineContext.audioObjects)
|
nickjillings@1318
|
2946 {
|
nickjillings@1340
|
2947 if(ao.metric.wasMoved == false && ao.interfaceDOM.canMove() == true)
|
nickjillings@1318
|
2948 {
|
nickjillings@1340
|
2949 failed.push(ao.interfaceDOM.getPresentedId());
|
nickjillings@1318
|
2950 }
|
nickjillings@1318
|
2951 }
|
nickjillings@1318
|
2952 if (failed.length == 0)
|
nickjillings@1318
|
2953 {
|
nickjillings@1318
|
2954 return true;
|
nickjillings@1318
|
2955 } else if (failed.length == 1)
|
nickjillings@1318
|
2956 {
|
nickjillings@1318
|
2957 str += 'track '+failed[0];
|
nickjillings@1318
|
2958 } else {
|
nickjillings@1318
|
2959 str += 'tracks ';
|
nickjillings@1318
|
2960 for (var i=0; i<failed.length-1; i++)
|
nickjillings@1318
|
2961 {
|
nickjillings@1318
|
2962 str += failed[i]+', ';
|
nickjillings@1318
|
2963 }
|
nickjillings@1318
|
2964 str += 'and '+failed[i];
|
nickjillings@1318
|
2965 }
|
nickjillings@1318
|
2966 str +='.';
|
nickjillings@1318
|
2967 alert(str);
|
nickjillings@1318
|
2968 console.log(str);
|
nickjillings@1367
|
2969 this.storeErrorNode(str);
|
nickjillings@1318
|
2970 return false;
|
nickjillings@1318
|
2971 };
|
nickjillings@1318
|
2972 this.checkAllPlayed = function()
|
nickjillings@1318
|
2973 {
|
nickjillings@1318
|
2974 var str = "You have not played ";
|
nickjillings@1318
|
2975 var failed = [];
|
nickjillings@1340
|
2976 for (var ao of audioEngineContext.audioObjects)
|
nickjillings@1318
|
2977 {
|
nickjillings@1340
|
2978 if(ao.metric.wasListenedTo == false)
|
nickjillings@1318
|
2979 {
|
nickjillings@1340
|
2980 failed.push(ao.interfaceDOM.getPresentedId());
|
nickjillings@1318
|
2981 }
|
nickjillings@1318
|
2982 }
|
nickjillings@1318
|
2983 if (failed.length == 0)
|
nickjillings@1318
|
2984 {
|
nickjillings@1318
|
2985 return true;
|
nickjillings@1318
|
2986 } else if (failed.length == 1)
|
nickjillings@1318
|
2987 {
|
nickjillings@1318
|
2988 str += 'track '+failed[0];
|
nickjillings@1318
|
2989 } else {
|
nickjillings@1318
|
2990 str += 'tracks ';
|
nickjillings@1318
|
2991 for (var i=0; i<failed.length-1; i++)
|
nickjillings@1318
|
2992 {
|
nickjillings@1318
|
2993 str += failed[i]+', ';
|
nickjillings@1318
|
2994 }
|
nickjillings@1318
|
2995 str += 'and '+failed[i];
|
nickjillings@1318
|
2996 }
|
nickjillings@1318
|
2997 str +='.';
|
nickjillings@1318
|
2998 alert(str);
|
nickjillings@1318
|
2999 console.log(str);
|
nickjillings@1367
|
3000 this.storeErrorNode(str);
|
nickjillings@1318
|
3001 return false;
|
nickjillings@1318
|
3002 };
|
nickjillings@1367
|
3003
|
nickjillings@1367
|
3004 this.storeErrorNode = function(errorMessage)
|
nickjillings@1367
|
3005 {
|
nickjillings@1367
|
3006 var time = audioEngineContext.timer.getTestTime();
|
nickjillings@1367
|
3007 var node = storage.document.createElement('error');
|
nickjillings@1367
|
3008 node.setAttribute('time',time);
|
nickjillings@1367
|
3009 node.textContent = errorMessage;
|
nickjillings@1367
|
3010 testState.currentStore.XMLDOM.appendChild(node);
|
nickjillings@1367
|
3011 };
|
nickjillings@1324
|
3012 }
|
nickjillings@1324
|
3013
|
nickjillings@1324
|
3014 function Storage()
|
nickjillings@1324
|
3015 {
|
nickjillings@1324
|
3016 // Holds results in XML format until ready for collection
|
nickjillings@1324
|
3017 this.globalPreTest = null;
|
nickjillings@1324
|
3018 this.globalPostTest = null;
|
nickjillings@1324
|
3019 this.testPages = [];
|
nickjillings@1324
|
3020 this.document = document.implementation.createDocument(null,"waetresult");
|
nickjillings@1324
|
3021 this.root = this.document.children[0];
|
nickjillings@1324
|
3022 this.state = 0;
|
nickjillings@1324
|
3023
|
nickjillings@1324
|
3024 this.initialise = function()
|
nickjillings@1324
|
3025 {
|
nickjillings@1342
|
3026 if (specification.preTest != undefined){this.globalPreTest = new this.surveyNode(this,this.root,specification.preTest);}
|
nickjillings@1342
|
3027 if (specification.postTest != undefined){this.globalPostTest = new this.surveyNode(this,this.root,specification.postTest);}
|
nickjillings@1324
|
3028 };
|
nickjillings@1324
|
3029
|
nickjillings@1324
|
3030 this.createTestPageStore = function(specification)
|
nickjillings@1324
|
3031 {
|
nickjillings@1324
|
3032 var store = new this.pageNode(this,specification);
|
nickjillings@1324
|
3033 this.testPages.push(store);
|
nickjillings@1324
|
3034 return this.testPages[this.testPages.length-1];
|
nickjillings@1324
|
3035 };
|
nickjillings@1324
|
3036
|
nickjillings@1324
|
3037 this.surveyNode = function(parent,root,specification)
|
nickjillings@1324
|
3038 {
|
nickjillings@1324
|
3039 this.specification = specification;
|
nickjillings@1324
|
3040 this.parent = parent;
|
nickjillings@1324
|
3041 this.XMLDOM = this.parent.document.createElement('survey');
|
nickjillings@1324
|
3042 this.XMLDOM.setAttribute('location',this.specification.location);
|
nickjillings@1324
|
3043 for (var optNode of this.specification.options)
|
nickjillings@1324
|
3044 {
|
nickjillings@1324
|
3045 if (optNode.type != 'statement')
|
nickjillings@1324
|
3046 {
|
nickjillings@1324
|
3047 var node = this.parent.document.createElement('surveyresult');
|
nickjillings@1324
|
3048 node.id = optNode.id;
|
nickjillings@1324
|
3049 node.setAttribute('type',optNode.type);
|
nickjillings@1324
|
3050 this.XMLDOM.appendChild(node);
|
nickjillings@1324
|
3051 }
|
nickjillings@1324
|
3052 }
|
nickjillings@1324
|
3053 root.appendChild(this.XMLDOM);
|
nickjillings@1324
|
3054
|
nickjillings@1324
|
3055 this.postResult = function(node)
|
nickjillings@1324
|
3056 {
|
nickjillings@1324
|
3057 // From popup: node is the popupOption node containing both spec. and results
|
nickjillings@1324
|
3058 // ID is the position
|
nickjillings@1324
|
3059 if (node.specification.type == 'statement'){return;}
|
nickjillings@1324
|
3060 var surveyresult = this.parent.document.getElementById(node.specification.id);
|
nickjillings@1324
|
3061 switch(node.specification.type)
|
nickjillings@1324
|
3062 {
|
nickjillings@1324
|
3063 case "number":
|
nickjillings@1324
|
3064 case "question":
|
nickjillings@1324
|
3065 var child = this.parent.document.createElement('response');
|
nickjillings@1324
|
3066 child.textContent = node.response;
|
nickjillings@1324
|
3067 surveyresult.appendChild(child);
|
nickjillings@1324
|
3068 break;
|
nickjillings@1324
|
3069 case "radio":
|
nickjillings@1324
|
3070 var child = this.parent.document.createElement('response');
|
nickjillings@1324
|
3071 child.setAttribute('name',node.response.name);
|
nickjillings@1324
|
3072 child.textContent = node.response.text;
|
nickjillings@1324
|
3073 surveyresult.appendChild(child);
|
nickjillings@1324
|
3074 break;
|
nickjillings@1324
|
3075 case "checkbox":
|
nickjillings@1324
|
3076 for (var i=0; i<node.response.length; i++)
|
nickjillings@1324
|
3077 {
|
nickjillings@1324
|
3078 var checkNode = this.parent.document.createElement('response');
|
nickjillings@1347
|
3079 checkNode.setAttribute('name',node.response[i].name);
|
nickjillings@1347
|
3080 checkNode.setAttribute('checked',node.response[i].checked);
|
nickjillings@1326
|
3081 surveyresult.appendChild(checkNode);
|
nickjillings@1324
|
3082 }
|
nickjillings@1324
|
3083 break;
|
nickjillings@1324
|
3084 }
|
nickjillings@1324
|
3085 };
|
nickjillings@1324
|
3086 };
|
nickjillings@1324
|
3087
|
nickjillings@1324
|
3088 this.pageNode = function(parent,specification)
|
nickjillings@1324
|
3089 {
|
nickjillings@1324
|
3090 // Create one store per test page
|
nickjillings@1324
|
3091 this.specification = specification;
|
nickjillings@1324
|
3092 this.parent = parent;
|
nickjillings@1324
|
3093 this.XMLDOM = this.parent.document.createElement('page');
|
nickjillings@1324
|
3094 this.XMLDOM.setAttribute('id',specification.id);
|
nickjillings@1324
|
3095 this.XMLDOM.setAttribute('presentedId',specification.presentedId);
|
nickjillings@1345
|
3096 if (specification.preTest != undefined){this.preTest = new this.parent.surveyNode(this.parent,this.XMLDOM,this.specification.preTest);}
|
nickjillings@1345
|
3097 if (specification.postTest != undefined){this.postTest = new this.parent.surveyNode(this.parent,this.XMLDOM,this.specification.postTest);}
|
nickjillings@1324
|
3098
|
nickjillings@1324
|
3099 // Add any page metrics
|
nickjillings@1324
|
3100 var page_metric = this.parent.document.createElement('metric');
|
nickjillings@1324
|
3101 this.XMLDOM.appendChild(page_metric);
|
nickjillings@1324
|
3102
|
nickjillings@1324
|
3103 // Add the audioelement
|
nickjillings@1324
|
3104 for (var element of this.specification.audioElements)
|
nickjillings@1324
|
3105 {
|
nickjillings@1324
|
3106 var aeNode = this.parent.document.createElement('audioelement');
|
nickjillings@1324
|
3107 aeNode.id = element.id;
|
nickjillings@1324
|
3108 aeNode.setAttribute('type',element.type);
|
nickjillings@1324
|
3109 aeNode.setAttribute('url', element.url);
|
nickjillings@1324
|
3110 aeNode.setAttribute('gain', element.gain);
|
nickjillings@1324
|
3111 if (element.type == 'anchor' || element.type == 'reference')
|
nickjillings@1324
|
3112 {
|
nickjillings@1324
|
3113 if (element.marker > 0)
|
nickjillings@1324
|
3114 {
|
nickjillings@1324
|
3115 aeNode.setAttribute('marker',element.marker);
|
nickjillings@1324
|
3116 }
|
nickjillings@1324
|
3117 }
|
nickjillings@1324
|
3118 var ae_metric = this.parent.document.createElement('metric');
|
nickjillings@1324
|
3119 aeNode.appendChild(ae_metric);
|
nickjillings@1324
|
3120 this.XMLDOM.appendChild(aeNode);
|
nickjillings@1324
|
3121 }
|
nickjillings@1324
|
3122
|
nickjillings@1324
|
3123 // Add any commentQuestions
|
nickjillings@1324
|
3124 for (var element of this.specification.commentQuestions)
|
nickjillings@1324
|
3125 {
|
nickjillings@1324
|
3126 var cqNode = this.parent.document.createElement('commentquestion');
|
nickjillings@1324
|
3127 cqNode.id = element.id;
|
nickjillings@1324
|
3128 cqNode.setAttribute('type',element.type);
|
nickjillings@1324
|
3129 var statement = this.parent.document.createElement('statement');
|
nickjillings@1324
|
3130 statement.textContent = cqNode.statement;
|
nickjillings@1324
|
3131 cqNode.appendChild(statement);
|
nickjillings@1324
|
3132 var response = this.parent.document.createElement('response');
|
nickjillings@1324
|
3133 cqNode.appendChild(response);
|
nickjillings@1324
|
3134 this.XMLDOM.appendChild(cqNode);
|
nickjillings@1324
|
3135 }
|
nickjillings@1324
|
3136
|
nickjillings@1324
|
3137 this.parent.root.appendChild(this.XMLDOM);
|
nickjillings@1324
|
3138 };
|
nickjillings@1324
|
3139 this.finish = function()
|
nickjillings@1324
|
3140 {
|
nickjillings@1324
|
3141 if (this.state == 0)
|
nickjillings@1324
|
3142 {
|
nickjillings@1324
|
3143 var projectDocument = specification.projectXML;
|
nickjillings@1324
|
3144 projectDocument.setAttribute('file-name',url);
|
nickjillings@1324
|
3145 this.root.appendChild(projectDocument);
|
nickjillings@1324
|
3146 this.root.appendChild(returnDateNode());
|
nickjillings@1324
|
3147 this.root.appendChild(interfaceContext.returnNavigator());
|
nickjillings@1324
|
3148 }
|
nickjillings@1324
|
3149 this.state = 1;
|
nickjillings@1324
|
3150 return this.root;
|
nickjillings@1324
|
3151 };
|
nickjillings@1324
|
3152 }
|