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