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