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