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