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