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