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