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