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