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