nicholas@2
|
1 /**
|
nicholas@2
|
2 * ape.js
|
nicholas@2
|
3 * Create the APE interface
|
nicholas@2
|
4 */
|
nicholas@2
|
5
|
n@32
|
6 /*
|
n@32
|
7 *
|
n@32
|
8 * WARNING!!!
|
n@32
|
9 *
|
n@32
|
10 * YOU ARE VIEWING THE DEV VERSION. THERE IS NO GUARANTEE THIS WILL BE FULLY FUNCTIONAL
|
n@32
|
11 *
|
n@32
|
12 * WARNING!!!
|
n@32
|
13 *
|
n@32
|
14 */
|
n@32
|
15
|
n@38
|
16 var currentState; // Keep track of the current state (pre/post test, which test, final test? first test?)
|
n@38
|
17 // preTest - In preTest state
|
n@38
|
18 // testRun-ID - In test running, test Id number at the end 'testRun-2'
|
n@38
|
19 // testRunPost-ID - Post test of test ID
|
n@38
|
20 // testRunPre-ID - Pre-test of test ID
|
n@38
|
21 // postTest - End of test, final submission!
|
n@38
|
22
|
n@32
|
23
|
nicholas@2
|
24 // Once this is loaded and parsed, begin execution
|
nicholas@2
|
25 loadInterface(projectXML);
|
nicholas@2
|
26
|
nicholas@2
|
27 function loadInterface(xmlDoc) {
|
nicholas@2
|
28
|
n@16
|
29 // Get the dimensions of the screen available to the page
|
nicholas@2
|
30 var width = window.innerWidth;
|
nicholas@2
|
31 var height = window.innerHeight;
|
nicholas@2
|
32
|
nicholas@2
|
33 // The injection point into the HTML page
|
nicholas@2
|
34 var insertPoint = document.getElementById("topLevelBody");
|
n@22
|
35 var testContent = document.createElement('div');
|
n@22
|
36 testContent.id = 'testContent';
|
nicholas@2
|
37
|
nicholas@7
|
38
|
nicholas@2
|
39 // Decode parts of the xmlDoc that are needed
|
nicholas@2
|
40 // xmlDoc MUST already be parsed by jQuery!
|
nicholas@2
|
41 var xmlSetup = xmlDoc.find('setup');
|
nicholas@2
|
42 // Should put in an error function here incase of malprocessed or malformed XML
|
nicholas@2
|
43
|
n@34
|
44 // Extract the different test XML DOM trees
|
n@50
|
45 var audioHolders = xmlDoc.find('audioHolder');
|
n@50
|
46 audioHolders.each(function(index,element) {
|
n@50
|
47 var repeatN = element.attributes['repeatCount'].value;
|
n@50
|
48 for (var r=0; r<=repeatN; r++) {
|
n@50
|
49 testXMLSetups[testXMLSetups.length] = element;
|
n@50
|
50 }
|
n@50
|
51 });
|
n@44
|
52
|
n@50
|
53 // New check if we need to randomise the test order
|
n@50
|
54 var randomise = xmlSetup[0].attributes['randomiseOrder'];
|
n@50
|
55 if (randomise != undefined) {
|
n@50
|
56 randomise = Boolean(randomise.value);
|
n@50
|
57 } else {
|
n@50
|
58 randomise = false;
|
n@50
|
59 }
|
n@50
|
60 if (randomise)
|
n@50
|
61 {
|
n@54
|
62 testXMLSetups = randomiseOrder(testXMLSetups);
|
n@50
|
63 }
|
n@44
|
64
|
n@50
|
65 // Obtain the metrics enabled
|
n@50
|
66 var metricNode = xmlSetup.find('Metric');
|
n@50
|
67 var metricNode = metricNode.find('metricEnable');
|
n@50
|
68 metricNode.each(function(index,node){
|
n@50
|
69 var enabled = node.textContent;
|
n@50
|
70 switch(enabled)
|
n@50
|
71 {
|
n@50
|
72 case 'testTimer':
|
n@50
|
73 sessionMetrics.prototype.enableTestTimer = true;
|
n@50
|
74 break;
|
n@50
|
75 case 'elementTimer':
|
n@50
|
76 sessionMetrics.prototype.enableElementTimer = true;
|
n@50
|
77 break;
|
n@50
|
78 case 'elementTracker':
|
n@50
|
79 sessionMetrics.prototype.enableElementTracker = true;
|
n@50
|
80 break;
|
n@50
|
81 case 'elementInitalPosition':
|
n@50
|
82 sessionMetrics.prototype.enableElementInitialPosition = true;
|
n@50
|
83 break;
|
n@50
|
84 case 'elementFlagListenedTo':
|
n@50
|
85 sessionMetrics.prototype.enableFlagListenedTo = true;
|
n@50
|
86 break;
|
n@50
|
87 case 'elementFlagMoved':
|
n@50
|
88 sessionMetrics.prototype.enableFlagMoved = true;
|
n@50
|
89 break;
|
n@50
|
90 case 'elementFlagComments':
|
n@50
|
91 sessionMetrics.prototype.enableFlagComments = true;
|
n@50
|
92 break;
|
n@50
|
93 }
|
n@50
|
94 });
|
n@34
|
95
|
n@52
|
96 // Create APE specific metric functions
|
n@52
|
97 audioEngineContext.metric.initialiseTest = function()
|
n@52
|
98 {
|
n@52
|
99 var sliders = document.getElementsByClassName('track-slider');
|
n@52
|
100 for (var i=0; i<sliders.length; i++)
|
n@52
|
101 {
|
n@52
|
102 audioEngineContext.audioObjects[i].metric.initialised(convSliderPosToRate(i));
|
n@52
|
103 }
|
n@52
|
104 };
|
n@52
|
105
|
n@52
|
106 audioEngineContext.metric.sliderMoveStart = function(id)
|
n@52
|
107 {
|
n@52
|
108 if (this.data == -1)
|
n@52
|
109 {
|
n@52
|
110 this.data = id;
|
n@52
|
111 } else {
|
n@52
|
112 console.log('ERROR: Metric tracker detecting two moves!');
|
n@52
|
113 this.data = -1;
|
n@52
|
114 }
|
n@52
|
115 };
|
n@52
|
116 audioEngineContext.metric.sliderMoved = function()
|
n@52
|
117 {
|
n@52
|
118 var time = audioEngineContext.timer.getTestTime();
|
n@52
|
119 var id = this.data;
|
n@52
|
120 this.data = -1;
|
n@52
|
121 var position = convSliderPosToRate(id);
|
n@52
|
122 if (audioEngineContext.timer.testStarted)
|
n@52
|
123 {
|
n@52
|
124 audioEngineContext.audioObjects[id].metric.moved(time,position);
|
n@52
|
125 }
|
n@52
|
126 };
|
n@52
|
127
|
n@52
|
128 audioEngineContext.metric.sliderPlayed = function(id)
|
n@52
|
129 {
|
n@52
|
130 var time = audioEngineContext.timer.getTestTime();
|
n@52
|
131 if (audioEngineContext.timer.testStarted)
|
n@52
|
132 {
|
n@52
|
133 if (this.lastClicked >= 0)
|
n@52
|
134 {
|
n@52
|
135 audioEngineContext.audioObjects[this.lastClicked].metric.listening(time);
|
n@52
|
136 }
|
n@52
|
137 this.lastClicked = id;
|
n@52
|
138 audioEngineContext.audioObjects[id].metric.listening(time);
|
n@52
|
139 }
|
n@52
|
140 };
|
n@52
|
141
|
nicholas@2
|
142 // Create the top div for the Title element
|
nicholas@2
|
143 var titleAttr = xmlSetup[0].attributes['title'];
|
nicholas@2
|
144 var title = document.createElement('div');
|
nicholas@2
|
145 title.className = "title";
|
nicholas@2
|
146 title.align = "center";
|
nicholas@2
|
147 var titleSpan = document.createElement('span');
|
nicholas@2
|
148
|
nicholas@2
|
149 // Set title to that defined in XML, else set to default
|
nicholas@2
|
150 if (titleAttr != undefined) {
|
n@25
|
151 titleSpan.innerHTML = titleAttr.value;
|
nicholas@2
|
152 } else {
|
n@25
|
153 titleSpan.innerHTML = 'APE Tool';
|
nicholas@2
|
154 }
|
nicholas@2
|
155 // Insert the titleSpan element into the title div element.
|
nicholas@2
|
156 title.appendChild(titleSpan);
|
nicholas@2
|
157
|
n@47
|
158 var pagetitle = document.createElement('div');
|
n@47
|
159 pagetitle.className = "pageTitle";
|
n@47
|
160 pagetitle.align = "center";
|
n@47
|
161 var titleSpan = document.createElement('span');
|
n@47
|
162 titleSpan.id = "pageTitle";
|
n@47
|
163 pagetitle.appendChild(titleSpan);
|
n@47
|
164
|
nicholas@7
|
165 // Store the return URL path in global projectReturn
|
nicholas@7
|
166 projectReturn = xmlSetup[0].attributes['projectReturn'].value;
|
nicholas@7
|
167
|
nicholas@7
|
168 // Create Interface buttons!
|
nicholas@7
|
169 var interfaceButtons = document.createElement('div');
|
nicholas@7
|
170 interfaceButtons.id = 'interface-buttons';
|
nicholas@7
|
171
|
nicholas@7
|
172 // MANUAL DOWNLOAD POINT
|
nicholas@7
|
173 // If project return is null, this MUST be specified as the location to create the download link
|
nicholas@7
|
174 var downloadPoint = document.createElement('div');
|
nicholas@7
|
175 downloadPoint.id = 'download-point';
|
nicholas@7
|
176
|
nicholas@7
|
177 // Create playback start/stop points
|
nicholas@7
|
178 var playback = document.createElement("button");
|
n@25
|
179 playback.innerHTML = 'Start';
|
n@49
|
180 playback.id = 'playback-button';
|
n@16
|
181 // onclick function. Check if it is playing or not, call the correct function in the
|
n@16
|
182 // audioEngine, change the button text to reflect the next state.
|
nicholas@7
|
183 playback.onclick = function() {
|
nicholas@7
|
184 if (audioEngineContext.status == 0) {
|
nicholas@7
|
185 audioEngineContext.play();
|
n@25
|
186 this.innerHTML = 'Stop';
|
nicholas@7
|
187 } else {
|
nicholas@7
|
188 audioEngineContext.stop();
|
n@25
|
189 this.innerHTML = 'Start';
|
nicholas@7
|
190 }
|
n@16
|
191 };
|
nicholas@7
|
192 // Create Submit (save) button
|
nicholas@7
|
193 var submit = document.createElement("button");
|
n@25
|
194 submit.innerHTML = 'Submit';
|
n@43
|
195 submit.onclick = buttonSubmitClick;
|
n@49
|
196 submit.id = 'submit-button';
|
n@16
|
197 // Append the interface buttons into the interfaceButtons object.
|
nicholas@7
|
198 interfaceButtons.appendChild(playback);
|
nicholas@7
|
199 interfaceButtons.appendChild(submit);
|
nicholas@7
|
200 interfaceButtons.appendChild(downloadPoint);
|
nicholas@7
|
201
|
nicholas@2
|
202 // Now create the slider and HTML5 canvas boxes
|
nicholas@2
|
203
|
n@16
|
204 // Create the div box to center align
|
nicholas@2
|
205 var sliderBox = document.createElement('div');
|
nicholas@2
|
206 sliderBox.className = 'sliderCanvasDiv';
|
n@16
|
207 sliderBox.id = 'sliderCanvasHolder';
|
nicholas@2
|
208 sliderBox.align = 'center';
|
nicholas@2
|
209
|
n@16
|
210 // Create the slider box to hold the slider elements
|
nicholas@5
|
211 var canvas = document.createElement('div');
|
nicholas@2
|
212 canvas.id = 'slider';
|
n@16
|
213 // Must have a known EXACT width, as this is used later to determine the ratings
|
nicholas@5
|
214 canvas.style.width = width - 100 +"px";
|
nicholas@5
|
215 canvas.align = "left";
|
nicholas@2
|
216 sliderBox.appendChild(canvas);
|
n@16
|
217
|
n@47
|
218 // Create the div to hold any scale objects
|
n@47
|
219 var scale = document.createElement('div');
|
n@47
|
220 scale.className = 'sliderScale';
|
n@47
|
221 scale.id = 'sliderScaleHolder';
|
n@47
|
222 scale.align = 'left';
|
n@47
|
223 sliderBox.appendChild(scale);
|
n@47
|
224
|
n@16
|
225 // Global parent for the comment boxes on the page
|
nicholas@3
|
226 var feedbackHolder = document.createElement('div');
|
n@34
|
227 feedbackHolder.id = 'feedbackHolder';
|
nicholas@2
|
228
|
n@38
|
229 testContent.style.zIndex = 1;
|
n@38
|
230 insertPoint.innerHTML = null; // Clear the current schema
|
n@38
|
231
|
n@22
|
232 // Create pre and post test questions
|
n@38
|
233 var blank = document.createElement('div');
|
n@38
|
234 blank.className = 'testHalt';
|
n@22
|
235
|
n@38
|
236 var popupHolder = document.createElement('div');
|
n@38
|
237 popupHolder.id = 'popupHolder';
|
n@38
|
238 popupHolder.className = 'popupHolder';
|
n@38
|
239 popupHolder.style.position = 'absolute';
|
n@38
|
240 popupHolder.style.left = (window.innerWidth/2)-250 + 'px';
|
n@38
|
241 popupHolder.style.top = (window.innerHeight/2)-125 + 'px';
|
n@38
|
242 insertPoint.appendChild(popupHolder);
|
n@38
|
243 insertPoint.appendChild(blank);
|
n@38
|
244 hidePopup();
|
n@22
|
245
|
n@36
|
246 var preTest = xmlSetup.find('PreTest');
|
n@36
|
247 var postTest = xmlSetup.find('PostTest');
|
n@22
|
248 preTest = preTest[0];
|
n@22
|
249 postTest = postTest[0];
|
n@38
|
250
|
n@38
|
251 currentState = 'preTest';
|
n@22
|
252
|
n@22
|
253 // Create Pre-Test Box
|
n@22
|
254 if (preTest != undefined && preTest.children.length >= 1)
|
n@22
|
255 {
|
n@38
|
256 showPopup();
|
n@39
|
257 preTestPopupStart(preTest);
|
n@22
|
258 }
|
n@38
|
259
|
n@38
|
260 // Inject into HTML
|
n@38
|
261 testContent.appendChild(title); // Insert the title
|
n@47
|
262 testContent.appendChild(pagetitle);
|
n@38
|
263 testContent.appendChild(interfaceButtons);
|
n@38
|
264 testContent.appendChild(sliderBox);
|
n@38
|
265 testContent.appendChild(feedbackHolder);
|
n@38
|
266 insertPoint.appendChild(testContent);
|
n@22
|
267
|
n@36
|
268 // Load the full interface
|
n@39
|
269
|
nicholas@2
|
270 }
|
nicholas@5
|
271
|
n@39
|
272 function loadTest(id)
|
n@34
|
273 {
|
n@34
|
274 // Used to load a specific test page
|
n@39
|
275 var textXML = testXMLSetups[id];
|
n@34
|
276
|
n@34
|
277 var feedbackHolder = document.getElementById('feedbackHolder');
|
n@34
|
278 var canvas = document.getElementById('slider');
|
n@34
|
279 feedbackHolder.innerHTML = null;
|
n@34
|
280 canvas.innerHTML = null;
|
n@47
|
281
|
n@47
|
282 // Setup question title
|
n@47
|
283 var interfaceObj = $(textXML).find('interface');
|
n@47
|
284 var titleNode = interfaceObj.find('title');
|
n@47
|
285 if (titleNode[0] != undefined)
|
n@47
|
286 {
|
n@47
|
287 document.getElementById('pageTitle').textContent = titleNode[0].textContent;
|
n@47
|
288 }
|
n@47
|
289 var positionScale = canvas.style.width.substr(0,canvas.style.width.length-2);
|
n@47
|
290 var offset = 50-8; // Half the offset of the slider (window width -100) minus the body padding of 8
|
n@47
|
291 // TODO: AUTOMATE ABOVE!!
|
n@47
|
292 var scale = document.getElementById('sliderScaleHolder');
|
n@47
|
293 scale.innerHTML = null;
|
n@47
|
294 interfaceObj.find('scale').each(function(index,scaleObj){
|
n@47
|
295 var position = Number(scaleObj.attributes['position'].value)*0.01;
|
n@47
|
296 var pixelPosition = (position*positionScale)+offset;
|
n@47
|
297 var scaleDOM = document.createElement('span');
|
n@47
|
298 scaleDOM.textContent = scaleObj.textContent;
|
n@47
|
299 scale.appendChild(scaleDOM);
|
n@47
|
300 scaleDOM.style.left = Math.floor((pixelPosition-($(scaleDOM).width()/2)))+'px';
|
n@47
|
301 });
|
n@34
|
302
|
n@34
|
303 // Extract the hostURL attribute. If not set, create an empty string.
|
n@34
|
304 var hostURL = textXML.attributes['hostURL'];
|
n@34
|
305 if (hostURL == undefined) {
|
n@34
|
306 hostURL = "";
|
n@34
|
307 } else {
|
n@34
|
308 hostURL = hostURL.value;
|
n@34
|
309 }
|
n@34
|
310 // Extract the sampleRate. If set, convert the string to a Number.
|
n@34
|
311 var hostFs = textXML.attributes['sampleRate'];
|
n@34
|
312 if (hostFs != undefined) {
|
n@34
|
313 hostFs = Number(hostFs.value);
|
n@34
|
314 }
|
n@34
|
315
|
n@34
|
316 /// CHECK FOR SAMPLE RATE COMPATIBILITY
|
n@34
|
317 if (hostFs != undefined) {
|
n@34
|
318 if (Number(hostFs) != audioContext.sampleRate) {
|
n@34
|
319 var errStr = 'Sample rates do not match! Requested '+Number(hostFs)+', got '+audioContext.sampleRate+'. Please set the sample rate to match before completing this test.';
|
n@34
|
320 alert(errStr);
|
n@34
|
321 return;
|
n@34
|
322 }
|
n@34
|
323 }
|
n@45
|
324
|
n@57
|
325 var loopPlayback = textXML.attributes['loop'];
|
n@57
|
326 if (loopPlayback != undefined)
|
n@57
|
327 {
|
n@57
|
328 loopPlayback = loopPlayback.value;
|
n@57
|
329 if (loopPlayback == 'true') {
|
n@57
|
330 loopPlayback = true;
|
n@57
|
331 } else {
|
n@57
|
332 loopPlayback = false;
|
n@57
|
333 }
|
n@57
|
334 } else {
|
n@57
|
335 loopPlayback = false;
|
n@57
|
336 }
|
n@57
|
337 audioEngineContext.loopPlayback = loopPlayback;
|
n@57
|
338
|
n@57
|
339 // Create AudioEngine bindings for playback
|
n@57
|
340 if (loopPlayback) {
|
n@57
|
341 audioEngineContext.play = function() {
|
n@57
|
342 // Send play command to all playback buffers for synchronised start
|
n@57
|
343 // Also start timer callbacks to detect if playback has finished
|
n@57
|
344 if (this.status == 0) {
|
n@57
|
345 this.timer.startTest();
|
n@57
|
346 // First get current clock
|
n@57
|
347 var timer = audioContext.currentTime;
|
n@57
|
348 // Add 3 seconds
|
n@57
|
349 timer += 3.0;
|
n@57
|
350 // Send play to all tracks
|
n@57
|
351 for (var i=0; i<this.audioObjects.length; i++)
|
n@57
|
352 {
|
n@57
|
353 this.audioObjects[i].play(timer);
|
n@57
|
354 }
|
n@57
|
355 this.status = 1;
|
n@57
|
356 }
|
n@57
|
357 };
|
n@57
|
358
|
n@57
|
359 audioEngineContext.stop = function() {
|
n@57
|
360 // Send stop and reset command to all playback buffers
|
n@57
|
361 if (this.status == 1) {
|
n@57
|
362 if (this.loopPlayback) {
|
n@57
|
363 for (var i=0; i<this.audioObjects.length; i++)
|
n@57
|
364 {
|
n@57
|
365 this.audioObjects[i].stop();
|
n@57
|
366 }
|
n@57
|
367 }
|
n@57
|
368 this.status = 0;
|
n@57
|
369 }
|
n@57
|
370 };
|
n@57
|
371
|
n@57
|
372 audioEngineContext.selectedTrack = function(id) {
|
n@57
|
373 for (var i=0; i<this.audioObjects.length; i++)
|
n@57
|
374 {
|
n@57
|
375 if (id == i) {
|
n@57
|
376 this.audioObjects[i].outputGain.gain.value = 1.0;
|
n@57
|
377 } else {
|
n@57
|
378 this.audioObjects[i].outputGain.gain.value = 0.0;
|
n@57
|
379 }
|
n@57
|
380 }
|
n@57
|
381 };
|
n@57
|
382 } else {
|
n@57
|
383 audioEngineContext.play = function() {
|
n@57
|
384 // Send play command to all playback buffers for synchronised start
|
n@57
|
385 // Also start timer callbacks to detect if playback has finished
|
n@57
|
386 if (this.status == 0) {
|
n@57
|
387 this.timer.startTest();
|
n@57
|
388 this.status = 1;
|
n@57
|
389 }
|
n@57
|
390 };
|
n@57
|
391
|
n@57
|
392 audioEngineContext.stop = function() {
|
n@57
|
393 // Send stop and reset command to all playback buffers
|
n@57
|
394 if (this.status == 1) {
|
n@57
|
395 if (this.loopPlayback) {
|
n@57
|
396 for (var i=0; i<this.audioObjects.length; i++)
|
n@57
|
397 {
|
n@57
|
398 this.audioObjects[i].stop();
|
n@57
|
399 }
|
n@57
|
400 }
|
n@57
|
401 this.status = 0;
|
n@57
|
402 }
|
n@57
|
403 };
|
n@57
|
404
|
n@57
|
405 audioEngineContext.selectedTrack = function(id) {
|
n@57
|
406 for (var i=0; i<this.audioObjects.length; i++)
|
n@57
|
407 {
|
n@57
|
408 if (id == i) {
|
n@57
|
409 this.audioObjects[i].outputGain.gain.value = 1.0;
|
n@57
|
410 this.audioObjects[i].play(audioContext.currentTime+0.01);
|
n@57
|
411 } else {
|
n@57
|
412 this.audioObjects[i].outputGain.gain.value = 0.0;
|
n@57
|
413 }
|
n@57
|
414 }
|
n@57
|
415 };
|
n@57
|
416 }
|
n@57
|
417
|
n@46
|
418 currentTestHolder = document.createElement('audioHolder');
|
n@46
|
419 currentTestHolder.id = textXML.id;
|
n@46
|
420 currentTestHolder.repeatCount = textXML.attributes['repeatCount'].value;
|
n@46
|
421 var currentPreTestHolder = document.createElement('preTest');
|
n@46
|
422 var currentPostTestHolder = document.createElement('postTest');
|
n@46
|
423 currentTestHolder.appendChild(currentPreTestHolder);
|
n@46
|
424 currentTestHolder.appendChild(currentPostTestHolder);
|
n@46
|
425
|
n@45
|
426 var randomise = textXML.attributes['randomiseOrder'];
|
n@45
|
427 if (randomise != undefined) {randomise = randomise.value;}
|
n@45
|
428 else {randomise = false;}
|
n@45
|
429
|
n@34
|
430 var audioElements = $(textXML).find('audioElements');
|
n@34
|
431 audioElements.each(function(index,element){
|
n@45
|
432 // Find any blind-repeats
|
n@45
|
433 // Not implemented yet, but just incase
|
n@45
|
434 currentTrackOrder[index] = element;
|
n@45
|
435 });
|
n@45
|
436 if (randomise) {
|
n@54
|
437 currentTrackOrder = randomiseOrder(currentTrackOrder);
|
n@45
|
438 }
|
n@45
|
439
|
n@45
|
440 // Find all the audioElements from the audioHolder
|
n@45
|
441 $(currentTrackOrder).each(function(index,element){
|
n@34
|
442 // Find URL of track
|
n@34
|
443 // In this jQuery loop, variable 'this' holds the current audioElement.
|
n@34
|
444
|
n@34
|
445 // Now load each audio sample. First create the new track by passing the full URL
|
n@34
|
446 var trackURL = hostURL + this.attributes['url'].value;
|
n@34
|
447 audioEngineContext.newTrack(trackURL);
|
n@34
|
448 // Create document objects to hold the comment boxes
|
n@34
|
449 var trackComment = document.createElement('div');
|
n@37
|
450 trackComment.className = 'comment-div';
|
n@34
|
451 // Create a string next to each comment asking for a comment
|
n@34
|
452 var trackString = document.createElement('span');
|
n@34
|
453 trackString.innerHTML = 'Comment on track '+index;
|
n@34
|
454 // Create the HTML5 comment box 'textarea'
|
n@34
|
455 var trackCommentBox = document.createElement('textarea');
|
n@34
|
456 trackCommentBox.rows = '4';
|
n@34
|
457 trackCommentBox.cols = '100';
|
n@34
|
458 trackCommentBox.name = 'trackComment'+index;
|
n@34
|
459 trackCommentBox.className = 'trackComment';
|
n@34
|
460 var br = document.createElement('br');
|
n@34
|
461 // Add to the holder.
|
n@34
|
462 trackComment.appendChild(trackString);
|
n@34
|
463 trackComment.appendChild(br);
|
n@34
|
464 trackComment.appendChild(trackCommentBox);
|
n@34
|
465 feedbackHolder.appendChild(trackComment);
|
n@34
|
466
|
n@34
|
467 // Create a slider per track
|
n@34
|
468
|
n@34
|
469 var trackSliderObj = document.createElement('div');
|
n@34
|
470 trackSliderObj.className = 'track-slider';
|
n@34
|
471 trackSliderObj.id = 'track-slider-'+index;
|
n@34
|
472 // Distribute it randomnly
|
n@34
|
473 var w = window.innerWidth - 100;
|
n@34
|
474 w = Math.random()*w;
|
n@34
|
475 trackSliderObj.style.left = Math.floor(w)+50+'px';
|
n@34
|
476 trackSliderObj.innerHTML = '<span>'+index+'</span>';
|
n@34
|
477 trackSliderObj.draggable = true;
|
n@34
|
478 trackSliderObj.ondragend = dragEnd;
|
n@49
|
479 trackSliderObj.ondragstart = function()
|
n@49
|
480 {
|
n@49
|
481 var id = Number(this.id.substr(13,2)); // Maximum theoretical tracks is 99!
|
n@49
|
482 audioEngineContext.metric.sliderMoveStart(id);
|
n@49
|
483 };
|
n@34
|
484
|
n@34
|
485 // Onclick, switch playback to that track
|
n@34
|
486 trackSliderObj.onclick = function() {
|
n@34
|
487 // Get the track ID from the object ID
|
n@34
|
488 var id = Number(this.id.substr(13,2)); // Maximum theoretical tracks is 99!
|
n@49
|
489 audioEngineContext.metric.sliderPlayed(id);
|
n@34
|
490 audioEngineContext.selectedTrack(id);
|
n@34
|
491 };
|
n@34
|
492
|
n@34
|
493 canvas.appendChild(trackSliderObj);
|
n@34
|
494 });
|
n@39
|
495
|
n@39
|
496 // Now process any pre-test commands
|
n@39
|
497
|
n@44
|
498 var preTest = $(testXMLSetups[id]).find('PreTest')[0];
|
n@39
|
499 if (preTest.children.length > 0)
|
n@39
|
500 {
|
n@39
|
501 currentState = 'testRunPre-'+id;
|
n@39
|
502 preTestPopupStart(preTest);
|
n@39
|
503 showPopup();
|
n@39
|
504 } else {
|
n@39
|
505 currentState = 'testRun-'+id;
|
n@39
|
506 }
|
n@39
|
507 }
|
n@39
|
508
|
n@39
|
509 function preTestPopupStart(preTest)
|
n@39
|
510 {
|
n@39
|
511 var popupHolder = document.getElementById('popupHolder');
|
n@39
|
512 popupHolder.innerHTML = null;
|
n@39
|
513 // Parse the first box
|
n@39
|
514 var preTestOption = document.createElement('div');
|
n@39
|
515 preTestOption.id = 'preTest';
|
n@39
|
516 preTestOption.style.marginTop = '25px';
|
n@39
|
517 preTestOption.align = "center";
|
n@39
|
518 var child = preTest.children[0];
|
n@39
|
519 if (child.nodeName == 'statement')
|
n@39
|
520 {
|
n@39
|
521 preTestOption.innerHTML = '<span>'+child.innerHTML+'</span>';
|
n@39
|
522 } else if (child.nodeName == 'question')
|
n@39
|
523 {
|
n@39
|
524 var questionId = child.attributes['id'].value;
|
n@39
|
525 var textHold = document.createElement('span');
|
n@39
|
526 textHold.innerHTML = child.innerHTML;
|
n@39
|
527 textHold.id = questionId + 'response';
|
n@39
|
528 var textEnter = document.createElement('textarea');
|
n@39
|
529 preTestOption.appendChild(textHold);
|
n@39
|
530 preTestOption.appendChild(textEnter);
|
n@39
|
531 }
|
n@39
|
532 var nextButton = document.createElement('button');
|
n@39
|
533 nextButton.className = 'popupButton';
|
n@39
|
534 nextButton.value = '0';
|
n@39
|
535 nextButton.innerHTML = 'Next';
|
n@39
|
536 nextButton.onclick = popupButtonClick;
|
n@39
|
537
|
n@39
|
538 popupHolder.appendChild(preTestOption);
|
n@39
|
539 popupHolder.appendChild(nextButton);
|
n@34
|
540 }
|
n@34
|
541
|
n@38
|
542 function popupButtonClick()
|
n@38
|
543 {
|
n@38
|
544 // Global call from the 'Next' button click
|
n@38
|
545 if (currentState == 'preTest')
|
n@38
|
546 {
|
n@38
|
547 // At the start of the preTest routine!
|
n@39
|
548 var xmlTree = projectXML.find('setup');
|
n@39
|
549 var preTest = xmlTree.find('PreTest')[0];
|
n@39
|
550 this.value = preTestButtonClick(preTest,this.value);
|
n@39
|
551 } else if (currentState.substr(0,10) == 'testRunPre')
|
n@39
|
552 {
|
n@39
|
553 //Specific test pre-test
|
n@39
|
554 var testId = currentState.substr(11,currentState.length-10);
|
n@44
|
555 var preTest = $(testXMLSetups[testId]).find('PreTest')[0];
|
n@39
|
556 this.value = preTestButtonClick(preTest,this.value);
|
n@42
|
557 } else if (currentState.substr(0,11) == 'testRunPost')
|
n@42
|
558 {
|
n@42
|
559 // Specific test post-test
|
n@42
|
560 var testId = currentState.substr(12,currentState.length-11);
|
n@44
|
561 var preTest = $(testXMLSetups[testId]).find('PostTest')[0];
|
n@42
|
562 this.value = preTestButtonClick(preTest,this.value);
|
n@41
|
563 } else if (currentState == 'postTest')
|
n@41
|
564 {
|
n@41
|
565 // At the end of the test, running global post test
|
n@41
|
566 var xmlTree = projectXML.find('setup');
|
n@41
|
567 var PostTest = xmlTree.find('PostTest')[0];
|
n@41
|
568 this.value = preTestButtonClick(PostTest,this.value);
|
n@38
|
569 }
|
n@38
|
570 }
|
n@38
|
571
|
n@39
|
572 function preTestButtonClick(preTest,index)
|
n@34
|
573 {
|
n@34
|
574 // Called on click of pre-test button
|
n@36
|
575 // Need to find and parse preTest again!
|
n@36
|
576 var preTestOption = document.getElementById('preTest');
|
n@36
|
577 // Check if current state is a question!
|
n@38
|
578 if (preTest.children[index].nodeName == 'question') {
|
n@38
|
579 var questionId = preTest.children[index].attributes['id'].value;
|
n@36
|
580 var questionHold = document.createElement('comment');
|
n@36
|
581 var questionResponse = document.getElementById(questionId + 'response');
|
n@36
|
582 questionHold.id = questionId;
|
n@36
|
583 questionHold.innerHTML = questionResponse.value;
|
n@46
|
584 postPopupResponse(questionHold);
|
n@36
|
585 }
|
n@38
|
586 index++;
|
n@38
|
587 if (index < preTest.children.length)
|
n@36
|
588 {
|
n@36
|
589 // More to process
|
n@38
|
590 var child = preTest.children[index];
|
n@36
|
591 if (child.nodeName == 'statement')
|
n@36
|
592 {
|
n@36
|
593 preTestOption.innerHTML = '<span>'+child.innerHTML+'</span>';
|
n@36
|
594 } else if (child.nodeName == 'question')
|
n@36
|
595 {
|
n@36
|
596 var textHold = document.createElement('span');
|
n@36
|
597 textHold.innerHTML = child.innerHTML;
|
n@36
|
598 var textEnter = document.createElement('textarea');
|
n@36
|
599 textEnter.id = child.attributes['id'].value + 'response';
|
n@36
|
600 var br = document.createElement('br');
|
n@36
|
601 preTestOption.innerHTML = null;
|
n@36
|
602 preTestOption.appendChild(textHold);
|
n@36
|
603 preTestOption.appendChild(br);
|
n@36
|
604 preTestOption.appendChild(textEnter);
|
n@36
|
605 }
|
n@36
|
606 } else {
|
n@36
|
607 // Time to clear
|
n@37
|
608 preTestOption.innerHTML = null;
|
n@43
|
609 if (currentState != 'postTest') {
|
n@43
|
610 hidePopup();
|
n@43
|
611 // Progress the state!
|
n@43
|
612 advanceState();
|
n@43
|
613 } else {
|
n@43
|
614 a = createProjectSave(projectReturn);
|
n@43
|
615 preTestOption.appendChild(a);
|
n@43
|
616 }
|
n@36
|
617 }
|
n@38
|
618 return index;
|
n@36
|
619 }
|
n@36
|
620
|
n@46
|
621 function postPopupResponse(response)
|
n@46
|
622 {
|
n@46
|
623 if (currentState == 'preTest') {
|
n@46
|
624 preTestQuestions.appendChild(response);
|
n@46
|
625 } else if (currentState == 'postTest') {
|
n@46
|
626 postTestQuestions.appendChild(response);
|
n@46
|
627 } else {
|
n@46
|
628 // Inside a specific test
|
n@46
|
629 if (currentState.substr(0,10) == 'testRunPre') {
|
n@46
|
630 // Pre Test
|
n@46
|
631 var store = $(currentTestHolder).find('preTest');
|
n@46
|
632 } else {
|
n@46
|
633 // Post Test
|
n@46
|
634 var store = $(currentTestHolder).find('postTest');
|
n@46
|
635 }
|
n@46
|
636 store[0].appendChild(response);
|
n@46
|
637 }
|
n@46
|
638 }
|
n@46
|
639
|
n@36
|
640 function showPopup()
|
n@36
|
641 {
|
n@37
|
642 var popupHolder = document.getElementById('popupHolder');
|
n@38
|
643 popupHolder.style.zIndex = 3;
|
n@37
|
644 popupHolder.style.visibility = 'visible';
|
n@37
|
645 var blank = document.getElementsByClassName('testHalt')[0];
|
n@37
|
646 blank.style.zIndex = 2;
|
n@37
|
647 blank.style.visibility = 'visible';
|
n@36
|
648 }
|
n@36
|
649
|
n@36
|
650 function hidePopup()
|
n@36
|
651 {
|
n@37
|
652 var popupHolder = document.getElementById('popupHolder');
|
n@37
|
653 popupHolder.style.zIndex = -1;
|
n@37
|
654 popupHolder.style.visibility = 'hidden';
|
n@37
|
655 var blank = document.getElementsByClassName('testHalt')[0];
|
n@37
|
656 blank.style.zIndex = -2;
|
n@37
|
657 blank.style.visibility = 'hidden';
|
n@34
|
658 }
|
n@34
|
659
|
nicholas@5
|
660 function dragEnd(ev) {
|
nicholas@5
|
661 // Function call when a div has been dropped
|
n@33
|
662 var slider = document.getElementById('slider');
|
n@51
|
663 var w = slider.style.width;
|
n@51
|
664 w = Number(w.substr(0,w.length-2));
|
n@51
|
665 var x = ev.x;
|
n@51
|
666 if (x >= 42 && x < w+42) {
|
n@51
|
667 this.style.left = (x)+'px';
|
nicholas@5
|
668 } else {
|
n@51
|
669 if (x<42) {
|
n@51
|
670 this.style.left = '42px';
|
nicholas@5
|
671 } else {
|
n@51
|
672 this.style.left = (w+42) + 'px';
|
nicholas@5
|
673 }
|
nicholas@5
|
674 }
|
n@49
|
675 audioEngineContext.metric.sliderMoved();
|
nicholas@5
|
676 }
|
nicholas@7
|
677
|
n@39
|
678 function advanceState()
|
n@39
|
679 {
|
n@39
|
680 console.log(currentState);
|
n@39
|
681 if (currentState == 'preTest')
|
n@39
|
682 {
|
n@39
|
683 // End of pre-test, begin the test
|
n@39
|
684 loadTest(0);
|
n@39
|
685 } else if (currentState.substr(0,10) == 'testRunPre')
|
n@39
|
686 {
|
n@39
|
687 // Start the test
|
n@39
|
688 var testId = currentState.substr(11,currentState.length-10);
|
n@39
|
689 currentState = 'testRun-'+testId;
|
n@42
|
690 } else if (currentState.substr(0,11) == 'testRunPost')
|
n@42
|
691 {
|
n@44
|
692 var testId = currentState.substr(12,currentState.length-11);
|
n@42
|
693 testEnded(testId);
|
n@40
|
694 } else if (currentState.substr(0,7) == 'testRun')
|
n@40
|
695 {
|
n@40
|
696 var testId = currentState.substr(8,currentState.length-7);
|
n@40
|
697 // Check if we have any post tests to perform
|
n@44
|
698 var postXML = $(testXMLSetups[testId]).find('PostTest')[0];
|
n@40
|
699 if (postXML.children.length > 0)
|
n@40
|
700 {
|
n@42
|
701 currentState = 'testRunPost-'+testId;
|
n@42
|
702 showPopup();
|
n@42
|
703 preTestPopupStart(postXML);
|
n@40
|
704 }
|
n@42
|
705 else {
|
n@40
|
706
|
n@40
|
707
|
n@42
|
708 // No post tests, check if we have another test to perform instead
|
n@42
|
709 testEnded(testId);
|
n@40
|
710 }
|
n@39
|
711 }
|
n@39
|
712 console.log(currentState);
|
n@39
|
713 }
|
n@39
|
714
|
n@42
|
715 function testEnded(testId)
|
n@42
|
716 {
|
n@45
|
717 pageXMLSave(testId);
|
n@42
|
718 if (testXMLSetups.length-1 > testId)
|
n@42
|
719 {
|
n@42
|
720 // Yes we have another test to perform
|
n@44
|
721 testId = (Number(testId)+1);
|
n@44
|
722 currentState = 'testRun-'+testId;
|
n@44
|
723 loadTest(testId);
|
n@42
|
724 } else {
|
n@42
|
725 console.log('Testing Completed!');
|
n@42
|
726 currentState = 'postTest';
|
n@42
|
727 // Check for any post tests
|
n@42
|
728 var xmlSetup = projectXML.find('setup');
|
n@42
|
729 var postTest = xmlSetup.find('PostTest')[0];
|
n@42
|
730 showPopup();
|
n@42
|
731 preTestPopupStart(postTest);
|
n@42
|
732 }
|
n@42
|
733 }
|
n@42
|
734
|
n@40
|
735 function buttonSubmitClick()
|
n@40
|
736 {
|
n@49
|
737 if (audioEngineContext.status == 1) {
|
n@49
|
738 var playback = document.getElementById('playback-button');
|
n@49
|
739 playback.click();
|
n@40
|
740 // This function is called when the submit button is clicked. Will check for any further tests to perform, or any post-test options
|
n@55
|
741 } else
|
n@55
|
742 {
|
n@55
|
743 if (audioEngineContext.timer.testStarted == false)
|
n@55
|
744 {
|
n@55
|
745 alert('You have not started the test! Please press start to begin the test!');
|
n@55
|
746 return;
|
n@55
|
747 }
|
n@49
|
748 }
|
n@40
|
749 if (currentState.substr(0,7) == 'testRun')
|
n@40
|
750 {
|
n@49
|
751 audioEngineContext.timer.stopTest();
|
n@40
|
752 advanceState();
|
n@40
|
753 }
|
n@40
|
754 }
|
n@40
|
755
|
n@51
|
756 function convSliderPosToRate(id)
|
n@51
|
757 {
|
n@51
|
758 var w = document.getElementById('slider').style.width;
|
n@51
|
759 var maxPix = w.substr(0,w.length-2);
|
n@51
|
760 var slider = document.getElementsByClassName('track-slider')[id];
|
n@51
|
761 var pix = slider.style.left;
|
n@51
|
762 pix = pix.substr(0,pix.length-2);
|
n@51
|
763 var rate = (pix-42)/maxPix;
|
n@51
|
764 return rate;
|
n@51
|
765 }
|
n@51
|
766
|
n@44
|
767 function pageXMLSave(testId)
|
n@44
|
768 {
|
n@44
|
769 // Saves a specific test page
|
n@46
|
770 var xmlDoc = currentTestHolder;
|
n@50
|
771 // Check if any session wide metrics are enabled
|
n@50
|
772 var metric = document.createElement('metric');
|
n@50
|
773 if (audioEngineContext.metric.enableTestTimer)
|
n@50
|
774 {
|
n@50
|
775 var testTime = document.createElement('metricResult');
|
n@50
|
776 testTime.id = 'testTime';
|
n@50
|
777 testTime.textContent = audioEngineContext.timer.testDuration;
|
n@50
|
778 metric.appendChild(testTime);
|
n@50
|
779 }
|
n@50
|
780 xmlDoc.appendChild(metric);
|
n@45
|
781 var trackSliderObjects = document.getElementsByClassName('track-slider');
|
n@45
|
782 var commentObjects = document.getElementsByClassName('comment-div');
|
n@45
|
783 for (var i=0; i<trackSliderObjects.length; i++)
|
n@45
|
784 {
|
n@45
|
785 var audioElement = document.createElement('audioElement');
|
n@45
|
786 audioElement.id = currentTrackOrder[i].attributes['id'].value;
|
n@45
|
787 audioElement.url = currentTrackOrder[i].attributes['url'].value;
|
n@51
|
788 var value = document.createElement('value');
|
n@51
|
789 value.innerHTML = convSliderPosToRate(i);
|
n@45
|
790 var comment = document.createElement("comment");
|
n@45
|
791 var question = document.createElement("question");
|
n@45
|
792 var response = document.createElement("response");
|
n@45
|
793 question.textContent = commentObjects[i].children[0].textContent;
|
n@45
|
794 response.textContent = commentObjects[i].children[2].value;
|
n@45
|
795 comment.appendChild(question);
|
n@45
|
796 comment.appendChild(response);
|
n@45
|
797 audioElement.appendChild(value);
|
n@45
|
798 audioElement.appendChild(comment);
|
n@50
|
799 // Check for any per element metrics
|
n@50
|
800 var metric = document.createElement('metric');
|
n@50
|
801 var elementMetric = audioEngineContext.audioObjects[i].metric;
|
n@50
|
802 if (audioEngineContext.metric.enableElementTimer) {
|
n@50
|
803 var elementTimer = document.createElement('metricResult');
|
n@50
|
804 elementTimer.id = 'elementTimer';
|
n@50
|
805 elementTimer.textContent = elementMetric.listenedTimer;
|
n@50
|
806 metric.appendChild(elementTimer);
|
n@50
|
807 }
|
n@50
|
808 if (audioEngineContext.metric.enableElementTracker) {
|
n@50
|
809 var elementTrackerFull = document.createElement('metricResult');
|
n@50
|
810 elementTrackerFull.id = 'elementTrackerFull';
|
n@50
|
811 var data = elementMetric.movementTracker;
|
n@50
|
812 for (var k=0; k<data.length; k++)
|
n@50
|
813 {
|
n@50
|
814 var timePos = document.createElement('timePos');
|
n@50
|
815 timePos.id = k;
|
n@50
|
816 var time = document.createElement('time');
|
n@50
|
817 time.textContent = data[k][0];
|
n@50
|
818 var position = document.createElement('position');
|
n@50
|
819 position.textContent = data[k][1];
|
n@50
|
820 timePos.appendChild(time);
|
n@50
|
821 timePos.appendChild(position);
|
n@50
|
822 elementTrackerFull.appendChild(timePos);
|
n@50
|
823 }
|
n@50
|
824 metric.appendChild(elementTrackerFull);
|
n@50
|
825 }
|
n@50
|
826 if (audioEngineContext.metric.enableElementInitialPosition) {
|
n@50
|
827 var elementInitial = document.createElement('metricResult');
|
n@50
|
828 elementInitial.id = 'elementInitialPosition';
|
n@50
|
829 elementInitial.textContent = elementMetric.initialPosition;
|
n@50
|
830 metric.appendChild(elementInitial);
|
n@50
|
831 }
|
n@50
|
832 if (audioEngineContext.metric.enableFlagListenedTo) {
|
n@50
|
833 var flagListenedTo = document.createElement('metricResult');
|
n@50
|
834 flagListenedTo.id = 'elementFlagListenedTo';
|
n@50
|
835 flagListenedTo.textContent = elementMetric.wasListenedTo;
|
n@50
|
836 metric.appendChild(flagListenedTo);
|
n@50
|
837 }
|
n@50
|
838 if (audioEngineContext.metric.enableFlagMoved) {
|
n@50
|
839 var flagMoved = document.createElement('metricResult');
|
n@50
|
840 flagMoved.id = 'elementFlagMoved';
|
n@50
|
841 flagMoved.textContent = elementMetric.wasMoved;
|
n@50
|
842 metric.appendChild(flagMoved);
|
n@50
|
843 }
|
n@50
|
844 if (audioEngineContext.metric.enableFlagComments) {
|
n@50
|
845 var flagComments = document.createElement('metricResult');
|
n@50
|
846 flagComments.id = 'elementFlagComments';
|
n@50
|
847 if (response.textContent.length == 0) {flag.textContent = 'false';}
|
n@50
|
848 else {flag.textContet = 'true';}
|
n@50
|
849 metric.appendChild(flagComments);
|
n@50
|
850 }
|
n@50
|
851 audioElement.appendChild(metric);
|
n@45
|
852 xmlDoc.appendChild(audioElement);
|
n@45
|
853 }
|
n@45
|
854 testResultsHolders[testId] = xmlDoc;
|
n@44
|
855 }
|
n@44
|
856
|
nicholas@7
|
857 // Only other global function which must be defined in the interface class. Determines how to create the XML document.
|
nicholas@7
|
858 function interfaceXMLSave(){
|
nicholas@7
|
859 // Create the XML string to be exported with results
|
nicholas@7
|
860 var xmlDoc = document.createElement("BrowserEvaluationResult");
|
n@45
|
861 for (var i=0; i<testResultsHolders.length; i++)
|
nicholas@7
|
862 {
|
n@45
|
863 xmlDoc.appendChild(testResultsHolders[i]);
|
nicholas@7
|
864 }
|
n@23
|
865 // Append Pre/Post Questions
|
n@23
|
866 xmlDoc.appendChild(preTestQuestions);
|
n@23
|
867 xmlDoc.appendChild(postTestQuestions);
|
n@23
|
868
|
nicholas@7
|
869 return xmlDoc;
|
nicholas@7
|
870 }
|
nicholas@7
|
871
|