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