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