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