b@1608
|
1 /**
|
b@1608
|
2 * ape.js
|
b@1608
|
3 * Create the APE interface
|
b@1608
|
4 */
|
b@1608
|
5
|
b@1608
|
6 // preTest - In preTest state
|
b@1608
|
7 // testRun-ID - In test running, test Id number at the end 'testRun-2'
|
b@1608
|
8 // testRunPost-ID - Post test of test ID
|
b@1608
|
9 // testRunPre-ID - Pre-test of test ID
|
b@1608
|
10 // postTest - End of test, final submission!
|
b@1608
|
11
|
b@1608
|
12
|
b@1608
|
13 // Once this is loaded and parsed, begin execution
|
b@1608
|
14 loadInterface(projectXML);
|
b@1608
|
15
|
b@1608
|
16 function loadInterface(xmlDoc) {
|
b@1608
|
17
|
b@1608
|
18 // Get the dimensions of the screen available to the page
|
b@1608
|
19 var width = window.innerWidth;
|
b@1608
|
20 var height = window.innerHeight;
|
b@1608
|
21
|
b@1608
|
22 // The injection point into the HTML page
|
b@1608
|
23 var insertPoint = document.getElementById("topLevelBody");
|
b@1608
|
24 var testContent = document.createElement('div');
|
b@1608
|
25 testContent.id = 'testContent';
|
b@1608
|
26
|
b@1608
|
27
|
b@1608
|
28 // Decode parts of the xmlDoc that are needed
|
b@1608
|
29 // xmlDoc MUST already be parsed by jQuery!
|
b@1608
|
30 var xmlSetup = xmlDoc.find('setup');
|
b@1608
|
31 // Should put in an error function here incase of malprocessed or malformed XML
|
b@1608
|
32
|
nickjillings@1634
|
33 // Create pre and post test questions
|
nickjillings@1634
|
34
|
nickjillings@1634
|
35 var preTest = xmlSetup.find('PreTest');
|
nickjillings@1634
|
36 var postTest = xmlSetup.find('PostTest');
|
nickjillings@1634
|
37 preTest = preTest[0];
|
nickjillings@1634
|
38 postTest = postTest[0];
|
nickjillings@1634
|
39
|
nickjillings@1634
|
40 if (preTest == undefined) {preTest = document.createElement("preTest");}
|
nickjillings@1634
|
41 if (postTest == undefined){postTest= document.createElement("postTest");}
|
nickjillings@1634
|
42
|
nickjillings@1634
|
43 testState.stateMap.push(preTest);
|
nickjillings@1634
|
44
|
b@1608
|
45 // Extract the different test XML DOM trees
|
b@1608
|
46 var audioHolders = xmlDoc.find('audioHolder');
|
nickjillings@1634
|
47 var testXMLSetups = [];
|
b@1608
|
48 audioHolders.each(function(index,element) {
|
b@1608
|
49 var repeatN = element.attributes['repeatCount'].value;
|
b@1608
|
50 for (var r=0; r<=repeatN; r++) {
|
nickjillings@1634
|
51 testXMLSetups.push(element);
|
b@1608
|
52 }
|
b@1608
|
53 });
|
b@1608
|
54
|
b@1608
|
55 // New check if we need to randomise the test order
|
b@1608
|
56 var randomise = xmlSetup[0].attributes['randomiseOrder'];
|
b@1608
|
57 if (randomise != undefined) {
|
nickjillings@1616
|
58 if (randomise.value === 'true'){
|
nickjillings@1616
|
59 randomise = true;
|
nickjillings@1616
|
60 } else {
|
nickjillings@1616
|
61 randomise = false;
|
nickjillings@1616
|
62 }
|
b@1608
|
63 } else {
|
b@1608
|
64 randomise = false;
|
b@1608
|
65 }
|
nickjillings@1616
|
66
|
b@1608
|
67 if (randomise)
|
b@1608
|
68 {
|
b@1608
|
69 testXMLSetups = randomiseOrder(testXMLSetups);
|
b@1608
|
70 }
|
nickjillings@1634
|
71
|
nickjillings@1634
|
72 $(testXMLSetups).each(function(index,elem){
|
nickjillings@1634
|
73 testState.stateMap.push(elem);
|
nickjillings@1634
|
74 })
|
nickjillings@1634
|
75
|
nickjillings@1634
|
76 testState.stateMap.push(postTest);
|
b@1608
|
77
|
b@1608
|
78 // Obtain the metrics enabled
|
b@1608
|
79 var metricNode = xmlSetup.find('Metric');
|
b@1608
|
80 var metricNode = metricNode.find('metricEnable');
|
b@1608
|
81 metricNode.each(function(index,node){
|
b@1608
|
82 var enabled = node.textContent;
|
b@1608
|
83 switch(enabled)
|
b@1608
|
84 {
|
b@1608
|
85 case 'testTimer':
|
b@1608
|
86 sessionMetrics.prototype.enableTestTimer = true;
|
b@1608
|
87 break;
|
b@1608
|
88 case 'elementTimer':
|
b@1608
|
89 sessionMetrics.prototype.enableElementTimer = true;
|
b@1608
|
90 break;
|
b@1608
|
91 case 'elementTracker':
|
b@1608
|
92 sessionMetrics.prototype.enableElementTracker = true;
|
b@1608
|
93 break;
|
b@1608
|
94 case 'elementInitalPosition':
|
b@1608
|
95 sessionMetrics.prototype.enableElementInitialPosition = true;
|
b@1608
|
96 break;
|
b@1608
|
97 case 'elementFlagListenedTo':
|
b@1608
|
98 sessionMetrics.prototype.enableFlagListenedTo = true;
|
b@1608
|
99 break;
|
b@1608
|
100 case 'elementFlagMoved':
|
b@1608
|
101 sessionMetrics.prototype.enableFlagMoved = true;
|
b@1608
|
102 break;
|
b@1608
|
103 case 'elementFlagComments':
|
b@1608
|
104 sessionMetrics.prototype.enableFlagComments = true;
|
b@1608
|
105 break;
|
b@1608
|
106 }
|
b@1608
|
107 });
|
b@1608
|
108
|
b@1608
|
109 // Create APE specific metric functions
|
b@1608
|
110 audioEngineContext.metric.initialiseTest = function()
|
b@1608
|
111 {
|
b@1608
|
112 var sliders = document.getElementsByClassName('track-slider');
|
b@1608
|
113 for (var i=0; i<sliders.length; i++)
|
b@1608
|
114 {
|
b@1608
|
115 audioEngineContext.audioObjects[i].metric.initialised(convSliderPosToRate(i));
|
b@1608
|
116 }
|
b@1608
|
117 };
|
b@1608
|
118
|
b@1608
|
119 audioEngineContext.metric.sliderMoveStart = function(id)
|
b@1608
|
120 {
|
b@1608
|
121 if (this.data == -1)
|
b@1608
|
122 {
|
b@1608
|
123 this.data = id;
|
b@1608
|
124 } else {
|
b@1608
|
125 console.log('ERROR: Metric tracker detecting two moves!');
|
b@1608
|
126 this.data = -1;
|
b@1608
|
127 }
|
b@1608
|
128 };
|
b@1608
|
129 audioEngineContext.metric.sliderMoved = function()
|
b@1608
|
130 {
|
b@1608
|
131 var time = audioEngineContext.timer.getTestTime();
|
b@1608
|
132 var id = this.data;
|
b@1608
|
133 this.data = -1;
|
b@1608
|
134 var position = convSliderPosToRate(id);
|
b@1606
|
135 console.log('slider ' + id + ': '+ position + ' (' + time + ')'); // DEBUG/SAFETY: show position and slider id
|
b@1608
|
136 if (audioEngineContext.timer.testStarted)
|
b@1608
|
137 {
|
b@1608
|
138 audioEngineContext.audioObjects[id].metric.moved(time,position);
|
b@1608
|
139 }
|
b@1608
|
140 };
|
b@1608
|
141
|
b@1608
|
142 audioEngineContext.metric.sliderPlayed = function(id)
|
b@1608
|
143 {
|
b@1608
|
144 var time = audioEngineContext.timer.getTestTime();
|
b@1608
|
145 if (audioEngineContext.timer.testStarted)
|
b@1608
|
146 {
|
b@1608
|
147 if (this.lastClicked >= 0)
|
b@1608
|
148 {
|
b@1608
|
149 audioEngineContext.audioObjects[this.lastClicked].metric.listening(time);
|
b@1608
|
150 }
|
b@1608
|
151 this.lastClicked = id;
|
b@1608
|
152 audioEngineContext.audioObjects[id].metric.listening(time);
|
b@1608
|
153 }
|
b@1606
|
154 console.log('slider ' + id + ' played (' + time + ')'); // DEBUG/SAFETY: show played slider id
|
b@1608
|
155 };
|
b@1608
|
156
|
b@1608
|
157 // Create the top div for the Title element
|
b@1608
|
158 var titleAttr = xmlSetup[0].attributes['title'];
|
b@1608
|
159 var title = document.createElement('div');
|
b@1608
|
160 title.className = "title";
|
b@1608
|
161 title.align = "center";
|
b@1608
|
162 var titleSpan = document.createElement('span');
|
b@1608
|
163
|
b@1608
|
164 // Set title to that defined in XML, else set to default
|
b@1608
|
165 if (titleAttr != undefined) {
|
b@1608
|
166 titleSpan.innerHTML = titleAttr.value;
|
b@1608
|
167 } else {
|
b@1608
|
168 titleSpan.innerHTML = 'Listening test';
|
b@1608
|
169 }
|
b@1608
|
170 // Insert the titleSpan element into the title div element.
|
b@1608
|
171 title.appendChild(titleSpan);
|
b@1608
|
172
|
b@1608
|
173 var pagetitle = document.createElement('div');
|
b@1608
|
174 pagetitle.className = "pageTitle";
|
b@1608
|
175 pagetitle.align = "center";
|
b@1608
|
176 var titleSpan = document.createElement('span');
|
b@1608
|
177 titleSpan.id = "pageTitle";
|
b@1608
|
178 pagetitle.appendChild(titleSpan);
|
b@1608
|
179
|
b@1608
|
180 // Store the return URL path in global projectReturn
|
b@1608
|
181 projectReturn = xmlSetup[0].attributes['projectReturn'].value;
|
b@1608
|
182
|
b@1608
|
183 // Create Interface buttons!
|
b@1608
|
184 var interfaceButtons = document.createElement('div');
|
b@1608
|
185 interfaceButtons.id = 'interface-buttons';
|
b@1608
|
186
|
b@1608
|
187 // MANUAL DOWNLOAD POINT
|
b@1608
|
188 // If project return is null, this MUST be specified as the location to create the download link
|
b@1608
|
189 var downloadPoint = document.createElement('div');
|
b@1608
|
190 downloadPoint.id = 'download-point';
|
b@1608
|
191
|
b@1608
|
192 // Create playback start/stop points
|
b@1608
|
193 var playback = document.createElement("button");
|
b@1609
|
194 playback.innerHTML = 'Stop';
|
b@1608
|
195 playback.id = 'playback-button';
|
b@1608
|
196 // onclick function. Check if it is playing or not, call the correct function in the
|
b@1608
|
197 // audioEngine, change the button text to reflect the next state.
|
b@1608
|
198 playback.onclick = function() {
|
b@1609
|
199 if (audioEngineContext.status == 1) {
|
b@1609
|
200 audioEngineContext.stop();
|
b@1608
|
201 this.innerHTML = 'Stop';
|
b@1606
|
202 var time = audioEngineContext.timer.getTestTime();
|
b@1606
|
203 console.log('Stopped at ' + time); // DEBUG/SAFETY
|
b@1608
|
204 }
|
b@1608
|
205 };
|
b@1608
|
206 // Create Submit (save) button
|
b@1608
|
207 var submit = document.createElement("button");
|
b@1608
|
208 submit.innerHTML = 'Submit';
|
b@1608
|
209 submit.onclick = buttonSubmitClick;
|
b@1608
|
210 submit.id = 'submit-button';
|
b@1608
|
211 // Append the interface buttons into the interfaceButtons object.
|
b@1608
|
212 interfaceButtons.appendChild(playback);
|
b@1608
|
213 interfaceButtons.appendChild(submit);
|
b@1608
|
214 interfaceButtons.appendChild(downloadPoint);
|
b@1608
|
215
|
b@1608
|
216 // Now create the slider and HTML5 canvas boxes
|
b@1608
|
217
|
b@1608
|
218 // Create the div box to center align
|
b@1608
|
219 var sliderBox = document.createElement('div');
|
b@1608
|
220 sliderBox.className = 'sliderCanvasDiv';
|
b@1608
|
221 sliderBox.id = 'sliderCanvasHolder';
|
b@1608
|
222
|
b@1608
|
223 // Create the slider box to hold the slider elements
|
b@1608
|
224 var canvas = document.createElement('div');
|
b@1608
|
225 canvas.id = 'slider';
|
nickjillings@1633
|
226 canvas.align = "left";
|
nickjillings@1633
|
227 canvas.addEventListener('dragover',function(event){
|
nickjillings@1633
|
228 event.preventDefault();
|
nickjillings@1633
|
229 return false;
|
nickjillings@1633
|
230 },false);
|
nickjillings@1633
|
231 var sliderMargin = document.createAttribute('marginsize');
|
nickjillings@1633
|
232 sliderMargin.nodeValue = 42; // Set default margins to 42px either side
|
b@1608
|
233 // Must have a known EXACT width, as this is used later to determine the ratings
|
nickjillings@1633
|
234 var w = (Number(sliderMargin.nodeValue)+8)*2;
|
nickjillings@1633
|
235 canvas.style.width = width - w +"px";
|
nickjillings@1633
|
236 canvas.style.marginLeft = sliderMargin.nodeValue +'px';
|
nickjillings@1633
|
237 canvas.setAttributeNode(sliderMargin);
|
b@1608
|
238 sliderBox.appendChild(canvas);
|
b@1608
|
239
|
b@1608
|
240 // Create the div to hold any scale objects
|
b@1608
|
241 var scale = document.createElement('div');
|
b@1608
|
242 scale.className = 'sliderScale';
|
b@1608
|
243 scale.id = 'sliderScaleHolder';
|
b@1608
|
244 scale.align = 'left';
|
b@1608
|
245 sliderBox.appendChild(scale);
|
b@1608
|
246
|
b@1608
|
247 // Global parent for the comment boxes on the page
|
b@1608
|
248 var feedbackHolder = document.createElement('div');
|
b@1608
|
249 feedbackHolder.id = 'feedbackHolder';
|
b@1608
|
250
|
b@1608
|
251 testContent.style.zIndex = 1;
|
b@1608
|
252 insertPoint.innerHTML = null; // Clear the current schema
|
b@1608
|
253
|
b@1608
|
254 currentState = 'preTest';
|
b@1608
|
255
|
b@1608
|
256 // Inject into HTML
|
b@1608
|
257 testContent.appendChild(title); // Insert the title
|
b@1608
|
258 testContent.appendChild(pagetitle);
|
b@1608
|
259 testContent.appendChild(interfaceButtons);
|
b@1608
|
260 testContent.appendChild(sliderBox);
|
b@1608
|
261 testContent.appendChild(feedbackHolder);
|
b@1608
|
262 insertPoint.appendChild(testContent);
|
b@1608
|
263
|
b@1608
|
264 // Load the full interface
|
nickjillings@1634
|
265 testState.initialise();
|
nickjillings@1634
|
266 testState.advanceState();
|
b@1608
|
267 }
|
b@1608
|
268
|
nickjillings@1634
|
269 function loadTest(textXML)
|
b@1608
|
270 {
|
nickjillings@1617
|
271
|
nickjillings@1617
|
272 // Reset audioEngineContext.Metric globals for new test
|
nickjillings@1620
|
273 audioEngineContext.newTestPage();
|
nickjillings@1617
|
274
|
nickjillings@1634
|
275 var id = textXML.id;
|
b@1608
|
276
|
b@1608
|
277 var feedbackHolder = document.getElementById('feedbackHolder');
|
b@1608
|
278 var canvas = document.getElementById('slider');
|
b@1608
|
279 feedbackHolder.innerHTML = null;
|
b@1608
|
280 canvas.innerHTML = null;
|
b@1608
|
281
|
b@1608
|
282 // Setup question title
|
b@1608
|
283 var interfaceObj = $(textXML).find('interface');
|
b@1608
|
284 var titleNode = interfaceObj.find('title');
|
b@1608
|
285 if (titleNode[0] != undefined)
|
b@1608
|
286 {
|
b@1608
|
287 document.getElementById('pageTitle').textContent = titleNode[0].textContent;
|
b@1608
|
288 }
|
b@1608
|
289 var positionScale = canvas.style.width.substr(0,canvas.style.width.length-2);
|
nickjillings@1633
|
290 var offset = Number(document.getElementById('slider').attributes['marginsize'].value);
|
b@1608
|
291 var scale = document.getElementById('sliderScaleHolder');
|
b@1608
|
292 scale.innerHTML = null;
|
b@1608
|
293 interfaceObj.find('scale').each(function(index,scaleObj){
|
nickjillings@1633
|
294 var value = document.createAttribute('value');
|
b@1608
|
295 var position = Number(scaleObj.attributes['position'].value)*0.01;
|
nickjillings@1633
|
296 value.nodeValue = position;
|
b@1608
|
297 var pixelPosition = (position*positionScale)+offset;
|
b@1608
|
298 var scaleDOM = document.createElement('span');
|
b@1608
|
299 scaleDOM.textContent = scaleObj.textContent;
|
b@1608
|
300 scale.appendChild(scaleDOM);
|
b@1608
|
301 scaleDOM.style.left = Math.floor((pixelPosition-($(scaleDOM).width()/2)))+'px';
|
nickjillings@1633
|
302 scaleDOM.setAttributeNode(value);
|
b@1608
|
303 });
|
b@1608
|
304
|
b@1608
|
305 // Extract the hostURL attribute. If not set, create an empty string.
|
b@1608
|
306 var hostURL = textXML.attributes['hostURL'];
|
b@1608
|
307 if (hostURL == undefined) {
|
b@1608
|
308 hostURL = "";
|
b@1608
|
309 } else {
|
b@1608
|
310 hostURL = hostURL.value;
|
b@1608
|
311 }
|
b@1608
|
312 // Extract the sampleRate. If set, convert the string to a Number.
|
b@1608
|
313 var hostFs = textXML.attributes['sampleRate'];
|
b@1608
|
314 if (hostFs != undefined) {
|
b@1608
|
315 hostFs = Number(hostFs.value);
|
b@1608
|
316 }
|
b@1608
|
317
|
b@1608
|
318 /// CHECK FOR SAMPLE RATE COMPATIBILITY
|
b@1608
|
319 if (hostFs != undefined) {
|
b@1608
|
320 if (Number(hostFs) != audioContext.sampleRate) {
|
b@1608
|
321 var errStr = 'Sample rates do not match! Requested '+Number(hostFs)+', got '+audioContext.sampleRate+'. Please set the sample rate to match before completing this test.';
|
b@1608
|
322 alert(errStr);
|
b@1608
|
323 return;
|
b@1608
|
324 }
|
b@1608
|
325 }
|
b@1608
|
326
|
b@1608
|
327 var commentShow = textXML.attributes['elementComments'];
|
b@1608
|
328 if (commentShow != undefined) {
|
b@1608
|
329 if (commentShow.value == 'false') {commentShow = false;}
|
b@1608
|
330 else {commentShow = true;}
|
b@1608
|
331 } else {commentShow = true;}
|
b@1608
|
332
|
b@1608
|
333 var loopPlayback = textXML.attributes['loop'];
|
b@1608
|
334 if (loopPlayback != undefined)
|
b@1608
|
335 {
|
b@1608
|
336 loopPlayback = loopPlayback.value;
|
b@1608
|
337 if (loopPlayback == 'true') {
|
b@1608
|
338 loopPlayback = true;
|
b@1608
|
339 } else {
|
b@1608
|
340 loopPlayback = false;
|
b@1608
|
341 }
|
b@1608
|
342 } else {
|
b@1608
|
343 loopPlayback = false;
|
b@1608
|
344 }
|
b@1608
|
345 audioEngineContext.loopPlayback = loopPlayback;
|
b@1608
|
346 // Create AudioEngine bindings for playback
|
b@1608
|
347 if (loopPlayback) {
|
b@1608
|
348 audioEngineContext.selectedTrack = function(id) {
|
b@1608
|
349 for (var i=0; i<this.audioObjects.length; i++)
|
b@1608
|
350 {
|
b@1608
|
351 if (id == i) {
|
nickjillings@1637
|
352 this.audioObjects[i].loopStart();
|
b@1608
|
353 } else {
|
nickjillings@1637
|
354 this.audioObjects[i].loopStop();
|
b@1608
|
355 }
|
b@1608
|
356 }
|
b@1608
|
357 };
|
b@1608
|
358 } else {
|
b@1608
|
359 audioEngineContext.selectedTrack = function(id) {
|
b@1608
|
360 for (var i=0; i<this.audioObjects.length; i++)
|
b@1608
|
361 {
|
b@1607
|
362 this.audioObjects[i].outputGain.gain.value = 0.0;
|
b@1607
|
363 this.audioObjects[i].stop();
|
b@1607
|
364 }
|
b@1607
|
365 if (this.status == 1) {
|
b@1607
|
366 this.audioObjects[id].outputGain.gain.value = 1.0;
|
b@1607
|
367 this.audioObjects[id].play(audioContext.currentTime+0.01);
|
b@1608
|
368 }
|
b@1608
|
369 };
|
b@1608
|
370 }
|
b@1608
|
371
|
b@1608
|
372 currentTestHolder = document.createElement('audioHolder');
|
b@1608
|
373 currentTestHolder.id = textXML.id;
|
b@1608
|
374 currentTestHolder.repeatCount = textXML.attributes['repeatCount'].value;
|
b@1608
|
375
|
b@1608
|
376 var randomise = textXML.attributes['randomiseOrder'];
|
b@1608
|
377 if (randomise != undefined) {randomise = randomise.value;}
|
b@1608
|
378 else {randomise = false;}
|
b@1608
|
379
|
b@1608
|
380 var audioElements = $(textXML).find('audioElements');
|
b@1608
|
381 currentTrackOrder = [];
|
b@1608
|
382 audioElements.each(function(index,element){
|
b@1608
|
383 // Find any blind-repeats
|
b@1608
|
384 // Not implemented yet, but just in case
|
b@1608
|
385 currentTrackOrder[index] = element;
|
b@1608
|
386 });
|
b@1608
|
387 if (randomise) {
|
b@1608
|
388 currentTrackOrder = randomiseOrder(currentTrackOrder);
|
b@1608
|
389 }
|
b@1608
|
390
|
b@1608
|
391 // Delete any previous audioObjects associated with the audioEngine
|
b@1608
|
392 audioEngineContext.audioObjects = [];
|
b@1608
|
393
|
b@1608
|
394 // Find all the audioElements from the audioHolder
|
b@1608
|
395 $(currentTrackOrder).each(function(index,element){
|
b@1608
|
396 // Find URL of track
|
b@1608
|
397 // In this jQuery loop, variable 'this' holds the current audioElement.
|
b@1608
|
398
|
b@1608
|
399 // Now load each audio sample. First create the new track by passing the full URL
|
b@1608
|
400 var trackURL = hostURL + this.attributes['url'].value;
|
b@1608
|
401 audioEngineContext.newTrack(trackURL);
|
b@1608
|
402
|
b@1608
|
403 if (commentShow) {
|
b@1608
|
404 // Create document objects to hold the comment boxes
|
b@1608
|
405 var trackComment = document.createElement('div');
|
b@1608
|
406 trackComment.className = 'comment-div';
|
b@1608
|
407 // Create a string next to each comment asking for a comment
|
b@1608
|
408 var trackString = document.createElement('span');
|
b@1608
|
409 trackString.innerHTML = 'Comment on track '+index;
|
b@1608
|
410 // Create the HTML5 comment box 'textarea'
|
b@1608
|
411 var trackCommentBox = document.createElement('textarea');
|
b@1608
|
412 trackCommentBox.rows = '4';
|
b@1608
|
413 trackCommentBox.cols = '100';
|
b@1608
|
414 trackCommentBox.name = 'trackComment'+index;
|
b@1608
|
415 trackCommentBox.className = 'trackComment';
|
b@1608
|
416 var br = document.createElement('br');
|
b@1608
|
417 // Add to the holder.
|
b@1608
|
418 trackComment.appendChild(trackString);
|
b@1608
|
419 trackComment.appendChild(br);
|
b@1608
|
420 trackComment.appendChild(trackCommentBox);
|
b@1608
|
421 feedbackHolder.appendChild(trackComment);
|
b@1608
|
422 }
|
b@1608
|
423
|
b@1608
|
424 // Create a slider per track
|
b@1608
|
425
|
b@1608
|
426 var trackSliderObj = document.createElement('div');
|
b@1608
|
427 trackSliderObj.className = 'track-slider';
|
b@1608
|
428 trackSliderObj.id = 'track-slider-'+index;
|
b@1608
|
429 // Distribute it randomnly
|
b@1608
|
430 var w = window.innerWidth - 100;
|
b@1608
|
431 w = Math.random()*w;
|
b@1608
|
432 trackSliderObj.style.left = Math.floor(w)+50+'px';
|
b@1608
|
433 trackSliderObj.innerHTML = '<span>'+index+'</span>';
|
b@1608
|
434 trackSliderObj.draggable = true;
|
b@1608
|
435 trackSliderObj.ondragend = dragEnd;
|
b@1608
|
436 trackSliderObj.ondragstart = function()
|
b@1608
|
437 {
|
b@1608
|
438 var id = Number(this.id.substr(13,2)); // Maximum theoretical tracks is 99!
|
b@1608
|
439 audioEngineContext.metric.sliderMoveStart(id);
|
b@1608
|
440 };
|
b@1608
|
441
|
b@1608
|
442 // Onclick, switch playback to that track
|
b@1608
|
443 trackSliderObj.onclick = function() {
|
nickjillings@1615
|
444 // Start the test on first click, that way timings are more accurate.
|
nickjillings@1615
|
445 audioEngineContext.play();
|
b@1608
|
446 // Get the track ID from the object ID
|
b@1608
|
447 var id = Number(this.id.substr(13,2)); // Maximum theoretical tracks is 99!
|
nickjillings@1617
|
448 //audioEngineContext.metric.sliderPlayed(id);
|
b@1608
|
449 audioEngineContext.selectedTrack(id);
|
b@1608
|
450 // Currently playing track red, rest green
|
b@1608
|
451 document.getElementById('track-slider-'+index).style.backgroundColor = "#FF0000";
|
b@1608
|
452 for (var i = 0; i<$(currentTrackOrder).length; i++)
|
b@1608
|
453 {
|
b@1610
|
454 if (i!=index) // Make all other sliders green
|
b@1608
|
455 {
|
b@1608
|
456 document.getElementById('track-slider-'+i).style.backgroundColor = "rgb(100,200,100)";
|
b@1608
|
457 }
|
b@1608
|
458
|
b@1608
|
459 }
|
b@1608
|
460 };
|
b@1608
|
461
|
b@1608
|
462 canvas.appendChild(trackSliderObj);
|
b@1610
|
463
|
b@1608
|
464 });
|
b@1608
|
465
|
b@1608
|
466 // Append any commentQuestion boxes
|
b@1608
|
467 var commentQuestions = $(textXML).find('CommentQuestion');
|
b@1608
|
468 $(commentQuestions).each(function(index,element) {
|
b@1608
|
469 // Create document objects to hold the comment boxes
|
b@1608
|
470 var trackComment = document.createElement('div');
|
b@1608
|
471 trackComment.className = 'comment-div commentQuestion';
|
b@1608
|
472 trackComment.id = element.attributes['id'].value;
|
b@1608
|
473 // Create a string next to each comment asking for a comment
|
b@1608
|
474 var trackString = document.createElement('span');
|
b@1608
|
475 trackString.innerHTML = element.textContent;
|
b@1608
|
476 // Create the HTML5 comment box 'textarea'
|
b@1608
|
477 var trackCommentBox = document.createElement('textarea');
|
b@1608
|
478 trackCommentBox.rows = '4';
|
b@1608
|
479 trackCommentBox.cols = '100';
|
b@1608
|
480 trackCommentBox.name = 'commentQuestion'+index;
|
b@1608
|
481 trackCommentBox.className = 'trackComment';
|
b@1608
|
482 var br = document.createElement('br');
|
b@1608
|
483 // Add to the holder.
|
b@1608
|
484 trackComment.appendChild(trackString);
|
b@1608
|
485 trackComment.appendChild(br);
|
b@1608
|
486 trackComment.appendChild(trackCommentBox);
|
b@1608
|
487 feedbackHolder.appendChild(trackComment);
|
b@1608
|
488 });
|
b@1608
|
489 }
|
b@1608
|
490
|
nickjillings@1625
|
491
|
b@1608
|
492 function dragEnd(ev) {
|
b@1608
|
493 // Function call when a div has been dropped
|
b@1608
|
494 var slider = document.getElementById('slider');
|
nickjillings@1633
|
495 var marginSize = Number(slider.attributes['marginsize'].value);
|
b@1608
|
496 var w = slider.style.width;
|
b@1608
|
497 w = Number(w.substr(0,w.length-2));
|
nickjillings@1633
|
498 var x = ev.x - ev.view.screenX;
|
nickjillings@1633
|
499 if (x >= marginSize && x < w+marginSize) {
|
b@1608
|
500 this.style.left = (x)+'px';
|
b@1608
|
501 } else {
|
nickjillings@1633
|
502 if (x<marginSize) {
|
nickjillings@1633
|
503 this.style.left = marginSize+'px';
|
b@1608
|
504 } else {
|
nickjillings@1633
|
505 this.style.left = (w+marginSize) + 'px';
|
b@1608
|
506 }
|
b@1608
|
507 }
|
b@1608
|
508 audioEngineContext.metric.sliderMoved();
|
b@1608
|
509 }
|
b@1608
|
510
|
b@1609
|
511 function buttonSubmitClick() // TODO: Only when all songs have been played!
|
b@1608
|
512 {
|
nickjillings@1614
|
513 hasBeenPlayed = audioEngineContext.checkAllPlayed();
|
nickjillings@1614
|
514 if (hasBeenPlayed.length == 0) {
|
nickjillings@1614
|
515 if (audioEngineContext.status == 1) {
|
nickjillings@1614
|
516 var playback = document.getElementById('playback-button');
|
nickjillings@1614
|
517 playback.click();
|
nickjillings@1614
|
518 // This function is called when the submit button is clicked. Will check for any further tests to perform, or any post-test options
|
nickjillings@1614
|
519 } else
|
nickjillings@1614
|
520 {
|
nickjillings@1614
|
521 if (audioEngineContext.timer.testStarted == false)
|
nickjillings@1614
|
522 {
|
nickjillings@1614
|
523 alert('You have not started the test! Please press start to begin the test!');
|
nickjillings@1614
|
524 return;
|
nickjillings@1614
|
525 }
|
nickjillings@1614
|
526 }
|
nickjillings@1634
|
527 testState.advanceState();
|
b@1610
|
528 } else // if a fragment has not been played yet
|
b@1610
|
529 {
|
nickjillings@1614
|
530 str = "";
|
nickjillings@1614
|
531 if (hasBeenPlayed.length > 1) {
|
nickjillings@1614
|
532 for (var i=0; i<hasBeenPlayed.length; i++) {
|
nickjillings@1614
|
533 str = str + hasBeenPlayed[i];
|
nickjillings@1614
|
534 if (i < hasBeenPlayed.length-2){
|
nickjillings@1614
|
535 str += ", ";
|
nickjillings@1614
|
536 } else if (i == hasBeenPlayed.length-2) {
|
nickjillings@1614
|
537 str += " or ";
|
nickjillings@1614
|
538 }
|
nickjillings@1614
|
539 }
|
nickjillings@1614
|
540 alert('You have not played fragments ' + str + ' yet. Please listen, rate and comment all samples before submitting.');
|
nickjillings@1614
|
541 } else {
|
nickjillings@1614
|
542 alert('You have not played fragment ' + hasBeenPlayed[0] + ' yet. Please listen, rate and comment all samples before submitting.');
|
nickjillings@1614
|
543 }
|
b@1610
|
544 return;
|
b@1610
|
545 }
|
b@1608
|
546 }
|
b@1608
|
547
|
b@1608
|
548 function convSliderPosToRate(id)
|
b@1608
|
549 {
|
b@1608
|
550 var w = document.getElementById('slider').style.width;
|
nickjillings@1633
|
551 var marginsize = Number(document.getElementById('slider').attributes['marginsize'].value);
|
b@1608
|
552 var maxPix = w.substr(0,w.length-2);
|
b@1608
|
553 var slider = document.getElementsByClassName('track-slider')[id];
|
b@1608
|
554 var pix = slider.style.left;
|
b@1608
|
555 pix = pix.substr(0,pix.length-2);
|
nickjillings@1633
|
556 var rate = (pix-marginsize)/maxPix;
|
b@1608
|
557 return rate;
|
b@1608
|
558 }
|
b@1608
|
559
|
nickjillings@1633
|
560 function resizeWindow(event){
|
nickjillings@1633
|
561 // Function called when the window has been resized.
|
nickjillings@1633
|
562 // MANDATORY FUNCTION
|
nickjillings@1633
|
563
|
nickjillings@1633
|
564 // Store the slider marker values
|
nickjillings@1633
|
565 var holdValues = [];
|
nickjillings@1633
|
566 $(".track-slider").each(function(index,sliderObj){
|
nickjillings@1633
|
567 holdValues.push(convSliderPosToRate(index));
|
nickjillings@1633
|
568 });
|
nickjillings@1633
|
569
|
nickjillings@1633
|
570 var width = event.target.innerWidth;
|
nickjillings@1633
|
571 var canvas = document.getElementById('sliderCanvasHolder');
|
nickjillings@1633
|
572 var sliderDiv = canvas.children[0];
|
nickjillings@1633
|
573 var sliderScaleDiv = canvas.children[1];
|
nickjillings@1633
|
574 var marginsize = Number(sliderDiv.attributes['marginsize'].value);
|
nickjillings@1633
|
575 var w = (marginsize+8)*2;
|
nickjillings@1633
|
576 sliderDiv.style.width = width - w + 'px';
|
nickjillings@1633
|
577 var width = width - w;
|
nickjillings@1633
|
578 // Move sliders into new position
|
nickjillings@1633
|
579 $(".track-slider").each(function(index,sliderObj){
|
nickjillings@1633
|
580 var pos = holdValues[index];
|
nickjillings@1633
|
581 var pix = pos * width;
|
nickjillings@1633
|
582 sliderObj.style.left = pix+marginsize+'px';
|
nickjillings@1633
|
583 });
|
nickjillings@1633
|
584
|
nickjillings@1633
|
585 // Move scale labels
|
nickjillings@1633
|
586 $(sliderScaleDiv.children).each(function(index,scaleObj){
|
nickjillings@1633
|
587 var position = Number(scaleObj.attributes['value'].value);
|
nickjillings@1633
|
588 var pixelPosition = (position*width)+marginsize;
|
nickjillings@1633
|
589 scaleObj.style.left = Math.floor((pixelPosition-($(scaleObj).width()/2)))+'px';
|
nickjillings@1633
|
590 });
|
nickjillings@1633
|
591 }
|
nickjillings@1633
|
592
|
nickjillings@1634
|
593 function pageXMLSave(store, testXML, testId)
|
b@1608
|
594 {
|
b@1608
|
595 // Saves a specific test page
|
nickjillings@1634
|
596 var xmlDoc = store;
|
b@1608
|
597 // Check if any session wide metrics are enabled
|
b@1608
|
598
|
nickjillings@1634
|
599 var commentShow = testXML.attributes['elementComments'];
|
b@1608
|
600 if (commentShow != undefined) {
|
b@1608
|
601 if (commentShow.value == 'false') {commentShow = false;}
|
b@1608
|
602 else {commentShow = true;}
|
b@1608
|
603 } else {commentShow = true;}
|
b@1608
|
604
|
b@1608
|
605 var metric = document.createElement('metric');
|
b@1608
|
606 if (audioEngineContext.metric.enableTestTimer)
|
b@1608
|
607 {
|
b@1608
|
608 var testTime = document.createElement('metricResult');
|
b@1608
|
609 testTime.id = 'testTime';
|
b@1608
|
610 testTime.textContent = audioEngineContext.timer.testDuration;
|
b@1608
|
611 metric.appendChild(testTime);
|
b@1608
|
612 }
|
b@1608
|
613 xmlDoc.appendChild(metric);
|
b@1608
|
614 var trackSliderObjects = document.getElementsByClassName('track-slider');
|
b@1608
|
615 var commentObjects = document.getElementsByClassName('comment-div');
|
b@1608
|
616 for (var i=0; i<trackSliderObjects.length; i++)
|
b@1608
|
617 {
|
b@1608
|
618 var audioElement = document.createElement('audioElement');
|
b@1608
|
619 audioElement.id = currentTrackOrder[i].attributes['id'].value;
|
b@1608
|
620 audioElement.url = currentTrackOrder[i].attributes['url'].value;
|
b@1608
|
621 var value = document.createElement('value');
|
b@1608
|
622 value.innerHTML = convSliderPosToRate(i);
|
b@1608
|
623 if (commentShow) {
|
b@1608
|
624 var comment = document.createElement("comment");
|
b@1608
|
625 var question = document.createElement("question");
|
b@1608
|
626 var response = document.createElement("response");
|
b@1608
|
627 question.textContent = commentObjects[i].children[0].textContent;
|
b@1608
|
628 response.textContent = commentObjects[i].children[2].value;
|
b@1606
|
629 console.log('Comment ' + i + ': ' + commentObjects[i].children[2].value); // DEBUG/SAFETY
|
b@1608
|
630 comment.appendChild(question);
|
b@1608
|
631 comment.appendChild(response);
|
b@1608
|
632 audioElement.appendChild(comment);
|
b@1608
|
633 }
|
b@1608
|
634 audioElement.appendChild(value);
|
b@1608
|
635 // Check for any per element metrics
|
b@1608
|
636 var metric = document.createElement('metric');
|
b@1608
|
637 var elementMetric = audioEngineContext.audioObjects[i].metric;
|
b@1608
|
638 if (audioEngineContext.metric.enableElementTimer) {
|
b@1608
|
639 var elementTimer = document.createElement('metricResult');
|
b@1608
|
640 elementTimer.id = 'elementTimer';
|
b@1608
|
641 elementTimer.textContent = elementMetric.listenedTimer;
|
b@1608
|
642 metric.appendChild(elementTimer);
|
b@1608
|
643 }
|
b@1608
|
644 if (audioEngineContext.metric.enableElementTracker) {
|
b@1608
|
645 var elementTrackerFull = document.createElement('metricResult');
|
b@1608
|
646 elementTrackerFull.id = 'elementTrackerFull';
|
b@1608
|
647 var data = elementMetric.movementTracker;
|
b@1608
|
648 for (var k=0; k<data.length; k++)
|
b@1608
|
649 {
|
b@1608
|
650 var timePos = document.createElement('timePos');
|
b@1608
|
651 timePos.id = k;
|
b@1608
|
652 var time = document.createElement('time');
|
b@1608
|
653 time.textContent = data[k][0];
|
b@1608
|
654 var position = document.createElement('position');
|
b@1608
|
655 position.textContent = data[k][1];
|
b@1608
|
656 timePos.appendChild(time);
|
b@1608
|
657 timePos.appendChild(position);
|
b@1608
|
658 elementTrackerFull.appendChild(timePos);
|
b@1608
|
659 }
|
b@1608
|
660 metric.appendChild(elementTrackerFull);
|
b@1608
|
661 }
|
b@1608
|
662 if (audioEngineContext.metric.enableElementInitialPosition) {
|
b@1608
|
663 var elementInitial = document.createElement('metricResult');
|
b@1608
|
664 elementInitial.id = 'elementInitialPosition';
|
b@1608
|
665 elementInitial.textContent = elementMetric.initialPosition;
|
b@1608
|
666 metric.appendChild(elementInitial);
|
b@1608
|
667 }
|
b@1608
|
668 if (audioEngineContext.metric.enableFlagListenedTo) {
|
b@1608
|
669 var flagListenedTo = document.createElement('metricResult');
|
b@1608
|
670 flagListenedTo.id = 'elementFlagListenedTo';
|
b@1608
|
671 flagListenedTo.textContent = elementMetric.wasListenedTo;
|
b@1608
|
672 metric.appendChild(flagListenedTo);
|
b@1608
|
673 }
|
b@1608
|
674 if (audioEngineContext.metric.enableFlagMoved) {
|
b@1608
|
675 var flagMoved = document.createElement('metricResult');
|
b@1608
|
676 flagMoved.id = 'elementFlagMoved';
|
b@1608
|
677 flagMoved.textContent = elementMetric.wasMoved;
|
b@1608
|
678 metric.appendChild(flagMoved);
|
b@1608
|
679 }
|
b@1608
|
680 if (audioEngineContext.metric.enableFlagComments) {
|
b@1608
|
681 var flagComments = document.createElement('metricResult');
|
b@1608
|
682 flagComments.id = 'elementFlagComments';
|
b@1608
|
683 if (response.textContent.length == 0) {flag.textContent = 'false';}
|
b@1608
|
684 else {flag.textContet = 'true';}
|
b@1608
|
685 metric.appendChild(flagComments);
|
b@1608
|
686 }
|
b@1608
|
687 audioElement.appendChild(metric);
|
b@1608
|
688 xmlDoc.appendChild(audioElement);
|
b@1608
|
689 }
|
b@1608
|
690 var commentQuestion = document.getElementsByClassName('commentQuestion');
|
b@1608
|
691 for (var i=0; i<commentQuestion.length; i++)
|
b@1608
|
692 {
|
b@1608
|
693 var cqHolder = document.createElement('CommentQuestion');
|
b@1608
|
694 var comment = document.createElement('comment');
|
b@1608
|
695 var question = document.createElement('question');
|
b@1608
|
696 cqHolder.id = commentQuestion[i].id;
|
b@1608
|
697 comment.textContent = commentQuestion[i].children[2].value;
|
b@1608
|
698 question.textContent = commentQuestion[i].children[0].textContent;
|
nickjillings@1630
|
699 console.log('Question ' + i + ': ' + commentQuestion[i].children[2].value); // DEBUG/SAFETY
|
b@1608
|
700 cqHolder.appendChild(question);
|
b@1608
|
701 cqHolder.appendChild(comment);
|
b@1608
|
702 xmlDoc.appendChild(cqHolder);
|
b@1608
|
703 }
|
nickjillings@1634
|
704 store = xmlDoc;
|
b@1608
|
705 } |