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