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