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