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