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