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