Mercurial > hg > webaudioevaluationtool
comparison ape.js @ 1581:284251e3a6a3
Everything tied into Specification object which needs information from specification document.
author | Nicholas Jillings <nickjillings@users.noreply.github.com> |
---|---|
date | Thu, 04 Jun 2015 15:54:56 +0100 |
parents | 4ffbccf448c2 |
children | b84004661558 |
comparison
equal
deleted
inserted
replaced
1580:b6c808cac38c | 1581:284251e3a6a3 |
---|---|
9 // testRunPre-ID - Pre-test of test ID | 9 // testRunPre-ID - Pre-test of test ID |
10 // postTest - End of test, final submission! | 10 // postTest - End of test, final submission! |
11 | 11 |
12 | 12 |
13 // Once this is loaded and parsed, begin execution | 13 // Once this is loaded and parsed, begin execution |
14 loadInterface(projectXML); | 14 loadInterface(); |
15 | 15 |
16 function loadInterface(xmlDoc) { | 16 function loadInterface() { |
17 | 17 |
18 // Get the dimensions of the screen available to the page | 18 // Get the dimensions of the screen available to the page |
19 var width = window.innerWidth; | 19 var width = window.innerWidth; |
20 var height = window.innerHeight; | 20 var height = window.innerHeight; |
21 | 21 |
22 // The injection point into the HTML page | 22 // The injection point into the HTML page |
23 var insertPoint = document.getElementById("topLevelBody"); | 23 var insertPoint = document.getElementById("topLevelBody"); |
24 var testContent = document.createElement('div'); | 24 var testContent = document.createElement('div'); |
25 | 25 |
26 testContent.id = 'testContent'; | 26 testContent.id = 'testContent'; |
27 | |
28 | |
29 // Decode parts of the xmlDoc that are needed | |
30 // xmlDoc MUST already be parsed by jQuery! | |
31 var xmlSetup = xmlDoc.find('setup'); | |
32 // Should put in an error function here incase of malprocessed or malformed XML | |
33 | 27 |
34 | 28 |
35 // Create APE specific metric functions | 29 // Create APE specific metric functions |
36 audioEngineContext.metric.initialiseTest = function() | 30 audioEngineContext.metric.initialiseTest = function() |
37 { | 31 { |
76 }; | 70 }; |
77 | 71 |
78 // Bindings for audioObjects | 72 // Bindings for audioObjects |
79 | 73 |
80 // Create the top div for the Title element | 74 // Create the top div for the Title element |
81 var titleAttr = xmlSetup[0].attributes['title']; | 75 var titleAttr = specification.title; |
82 var title = document.createElement('div'); | 76 var title = document.createElement('div'); |
83 title.className = "title"; | 77 title.className = "title"; |
84 title.align = "center"; | 78 title.align = "center"; |
85 var titleSpan = document.createElement('span'); | 79 var titleSpan = document.createElement('span'); |
86 | 80 |
87 // Set title to that defined in XML, else set to default | 81 // Set title to that defined in XML, else set to default |
88 if (titleAttr != undefined) { | 82 if (titleAttr != undefined) { |
89 titleSpan.innerHTML = titleAttr.value; | 83 titleSpan.textContent = titleAttr; |
90 } else { | 84 } else { |
91 titleSpan.innerHTML = 'Listening test'; | 85 titleSpan.textContent = 'Listening test'; |
92 } | 86 } |
93 // Insert the titleSpan element into the title div element. | 87 // Insert the titleSpan element into the title div element. |
94 title.appendChild(titleSpan); | 88 title.appendChild(titleSpan); |
95 | 89 |
96 var pagetitle = document.createElement('div'); | 90 var pagetitle = document.createElement('div'); |
98 pagetitle.align = "center"; | 92 pagetitle.align = "center"; |
99 var titleSpan = document.createElement('span'); | 93 var titleSpan = document.createElement('span'); |
100 titleSpan.id = "pageTitle"; | 94 titleSpan.id = "pageTitle"; |
101 pagetitle.appendChild(titleSpan); | 95 pagetitle.appendChild(titleSpan); |
102 | 96 |
103 // Store the return URL path in global projectReturn | |
104 projectReturn = xmlSetup[0].attributes['projectReturn']; | |
105 if (projectReturn == undefined) { | |
106 console.log("WARNING - projectReturn not specified! Will assume null."); | |
107 projectReturn = "null"; | |
108 } else { | |
109 projectReturn = projectReturn.value; | |
110 } | |
111 | |
112 // Create Interface buttons! | 97 // Create Interface buttons! |
113 var interfaceButtons = document.createElement('div'); | 98 var interfaceButtons = document.createElement('div'); |
114 interfaceButtons.id = 'interface-buttons'; | 99 interfaceButtons.id = 'interface-buttons'; |
115 | |
116 // MANUAL DOWNLOAD POINT | |
117 // If project return is null, this MUST be specified as the location to create the download link | |
118 var downloadPoint = document.createElement('div'); | |
119 downloadPoint.id = 'download-point'; | |
120 | 100 |
121 // Create playback start/stop points | 101 // Create playback start/stop points |
122 var playback = document.createElement("button"); | 102 var playback = document.createElement("button"); |
123 playback.innerHTML = 'Stop'; | 103 playback.innerHTML = 'Stop'; |
124 playback.id = 'playback-button'; | 104 playback.id = 'playback-button'; |
138 submit.onclick = buttonSubmitClick; | 118 submit.onclick = buttonSubmitClick; |
139 submit.id = 'submit-button'; | 119 submit.id = 'submit-button'; |
140 // Append the interface buttons into the interfaceButtons object. | 120 // Append the interface buttons into the interfaceButtons object. |
141 interfaceButtons.appendChild(playback); | 121 interfaceButtons.appendChild(playback); |
142 interfaceButtons.appendChild(submit); | 122 interfaceButtons.appendChild(submit); |
143 interfaceButtons.appendChild(downloadPoint); | |
144 | 123 |
145 // Now create the slider and HTML5 canvas boxes | 124 // Now create the slider and HTML5 canvas boxes |
146 | 125 |
147 // Create the div box to center align | 126 // Create the div box to center align |
148 var sliderBox = document.createElement('div'); | 127 var sliderBox = document.createElement('div'); |
192 testState.initialise(); | 171 testState.initialise(); |
193 testState.advanceState(); | 172 testState.advanceState(); |
194 | 173 |
195 } | 174 } |
196 | 175 |
197 function loadTest(textXML) | 176 function loadTest(audioHolderObject) |
198 { | 177 { |
199 | 178 |
200 // Reset audioEngineContext.Metric globals for new test | 179 // Reset audioEngineContext.Metric globals for new test |
201 audioEngineContext.newTestPage(); | 180 audioEngineContext.newTestPage(); |
202 | 181 |
203 var id = textXML.id; | 182 var id = audioHolderObject.id; |
204 | 183 |
205 var feedbackHolder = document.getElementById('feedbackHolder'); | 184 var feedbackHolder = document.getElementById('feedbackHolder'); |
206 var canvas = document.getElementById('slider'); | 185 var canvas = document.getElementById('slider'); |
207 feedbackHolder.innerHTML = null; | 186 feedbackHolder.innerHTML = null; |
208 canvas.innerHTML = null; | 187 canvas.innerHTML = null; |
209 | 188 |
210 // Setup question title | 189 // Setup question title |
211 var interfaceObj = $(textXML).find('interface'); | 190 var interfaceObj = $(audioHolderObject).find('interface'); |
212 var titleNode = interfaceObj.find('title'); | 191 var titleNode = interfaceObj.find('title'); |
213 if (titleNode[0] != undefined) | 192 if (titleNode[0] != undefined) |
214 { | 193 { |
215 document.getElementById('pageTitle').textContent = titleNode[0].textContent; | 194 document.getElementById('pageTitle').textContent = titleNode[0].textContent; |
216 } | 195 } |
235 commentBoxPrefix = commentBoxPrefix[0].textContent; | 214 commentBoxPrefix = commentBoxPrefix[0].textContent; |
236 } else { | 215 } else { |
237 commentBoxPrefix = "Comment on track"; | 216 commentBoxPrefix = "Comment on track"; |
238 } | 217 } |
239 | 218 |
240 // Extract the hostURL attribute. If not set, create an empty string. | |
241 var hostURL = textXML.attributes['hostURL']; | |
242 if (hostURL == undefined) { | |
243 hostURL = ""; | |
244 } else { | |
245 hostURL = hostURL.value; | |
246 } | |
247 // Extract the sampleRate. If set, convert the string to a Number. | |
248 var hostFs = textXML.attributes['sampleRate']; | |
249 if (hostFs != undefined) { | |
250 hostFs = Number(hostFs.value); | |
251 } | |
252 | |
253 /// CHECK FOR SAMPLE RATE COMPATIBILITY | 219 /// CHECK FOR SAMPLE RATE COMPATIBILITY |
254 if (hostFs != undefined) { | 220 if (audioHolderObject.sampleRate != undefined) { |
255 if (Number(hostFs) != audioContext.sampleRate) { | 221 if (Number(audioHolderObject.sampleRate) != audioContext.sampleRate) { |
256 var errStr = 'Sample rates do not match! Requested '+Number(hostFs)+', got '+audioContext.sampleRate+'. Please set the sample rate to match before completing this test.'; | 222 var errStr = 'Sample rates do not match! Requested '+Number(hostFs)+', got '+audioContext.sampleRate+'. Please set the sample rate to match before completing this test.'; |
257 alert(errStr); | 223 alert(errStr); |
258 return; | 224 return; |
259 } | 225 } |
260 } | 226 } |
261 | 227 |
262 var commentShow = textXML.attributes['elementComments']; | 228 var commentShow = audioHolderObject.elementComments; |
263 if (commentShow != undefined) { | 229 |
264 if (commentShow.value == 'false') {commentShow = false;} | 230 var loopPlayback = audioHolderObject.loop; |
265 else {commentShow = true;} | 231 |
266 } else {commentShow = true;} | |
267 | |
268 var loopPlayback = textXML.attributes['loop']; | |
269 if (loopPlayback != undefined) | |
270 { | |
271 loopPlayback = loopPlayback.value; | |
272 if (loopPlayback == 'true') { | |
273 loopPlayback = true; | |
274 } else { | |
275 loopPlayback = false; | |
276 } | |
277 } else { | |
278 loopPlayback = false; | |
279 } | |
280 audioEngineContext.loopPlayback = loopPlayback; | 232 audioEngineContext.loopPlayback = loopPlayback; |
281 // Create AudioEngine bindings for playback | 233 // Create AudioEngine bindings for playback |
282 if (loopPlayback) { | 234 if (loopPlayback) { |
283 audioEngineContext.selectedTrack = function(id) { | 235 audioEngineContext.selectedTrack = function(id) { |
284 for (var i=0; i<this.audioObjects.length; i++) | 236 for (var i=0; i<this.audioObjects.length; i++) |
303 } | 255 } |
304 }; | 256 }; |
305 } | 257 } |
306 | 258 |
307 currentTestHolder = document.createElement('audioHolder'); | 259 currentTestHolder = document.createElement('audioHolder'); |
308 currentTestHolder.id = textXML.id; | 260 currentTestHolder.id = audioHolderObject.id; |
309 currentTestHolder.repeatCount = textXML.attributes['repeatCount'].value; | 261 currentTestHolder.repeatCount = audioHolderObject.repeatCount; |
310 | 262 |
311 var randomise = textXML.attributes['randomiseOrder']; | 263 var randomise = audioHolderObject.randomiseOrder; |
312 if (randomise != undefined) {randomise = randomise.value;} | 264 |
313 else {randomise = false;} | 265 var audioElements = audioHolderObject.audioElements; |
314 | |
315 var audioElements = $(textXML).find('audioElements'); | |
316 currentTrackOrder = []; | 266 currentTrackOrder = []; |
317 audioElements.each(function(index,element){ | |
318 // Find any blind-repeats | |
319 // Not implemented yet, but just in case | |
320 currentTrackOrder[index] = element; | |
321 }); | |
322 if (randomise) { | 267 if (randomise) { |
323 currentTrackOrder = randomiseOrder(currentTrackOrder); | 268 audioHolderObject.audioElements = randomiseOrder(audioHolderObject.audioElements); |
324 } | 269 } |
325 | 270 |
326 // Delete any previous audioObjects associated with the audioEngine | 271 // Delete any previous audioObjects associated with the audioEngine |
327 audioEngineContext.audioObjects = []; | 272 audioEngineContext.audioObjects = []; |
328 | 273 |
329 // Find all the audioElements from the audioHolder | 274 // Find all the audioElements from the audioHolder |
330 $(currentTrackOrder).each(function(index,element){ | 275 $(audioHolderObject.audioElements).each(function(index,element){ |
331 // Find URL of track | 276 // Find URL of track |
332 // In this jQuery loop, variable 'this' holds the current audioElement. | 277 // In this jQuery loop, variable 'this' holds the current audioElement. |
333 | 278 |
334 // Now load each audio sample. First create the new track by passing the full URL | 279 // Now load each audio sample. First create the new track by passing the full URL |
335 var trackURL = hostURL + this.attributes['url'].value; | 280 var trackURL = audioHolderObject.hostURL + element.url; |
336 var audioObject = audioEngineContext.newTrack(trackURL); | 281 var audioObject = audioEngineContext.newTrack(trackURL); |
337 audioObject.id = this.attributes['id'].value; | |
338 | 282 |
339 if (commentShow) { | 283 if (commentShow) { |
340 // Create document objects to hold the comment boxes | 284 // Create document objects to hold the comment boxes |
341 var trackComment = document.createElement('div'); | 285 var trackComment = document.createElement('div'); |
342 trackComment.className = 'comment-div'; | 286 trackComment.className = 'comment-div'; |
410 audioObject.metric.initialised(convSliderPosToRate(index)); | 354 audioObject.metric.initialised(convSliderPosToRate(index)); |
411 | 355 |
412 }); | 356 }); |
413 | 357 |
414 // Append any commentQuestion boxes | 358 // Append any commentQuestion boxes |
415 var commentQuestions = $(textXML).find('CommentQuestion'); | 359 $(audioHolderObject.commentQuestions).each(function(index,element) { |
416 $(commentQuestions).each(function(index,element) { | |
417 // Create document objects to hold the comment boxes | 360 // Create document objects to hold the comment boxes |
418 var trackComment = document.createElement('div'); | 361 var trackComment = document.createElement('div'); |
419 trackComment.className = 'comment-div commentQuestion'; | 362 trackComment.className = 'comment-div commentQuestion'; |
420 trackComment.id = element.attributes['id'].value; | 363 trackComment.id = element.id; |
421 // Create a string next to each comment asking for a comment | 364 // Create a string next to each comment asking for a comment |
422 var trackString = document.createElement('span'); | 365 var trackString = document.createElement('span'); |
423 trackString.innerHTML = element.textContent; | 366 trackString.innerHTML = element.question; |
424 // Create the HTML5 comment box 'textarea' | 367 // Create the HTML5 comment box 'textarea' |
425 var trackCommentBox = document.createElement('textarea'); | 368 var trackCommentBox = document.createElement('textarea'); |
426 trackCommentBox.rows = '4'; | 369 trackCommentBox.rows = '4'; |
427 trackCommentBox.cols = '100'; | 370 trackCommentBox.cols = '100'; |
428 trackCommentBox.name = 'commentQuestion'+index; | 371 trackCommentBox.name = 'commentQuestion'+index; |
539 var pixelPosition = (position*width)+marginsize; | 482 var pixelPosition = (position*width)+marginsize; |
540 scaleObj.style.left = Math.floor((pixelPosition-($(scaleObj).width()/2)))+'px'; | 483 scaleObj.style.left = Math.floor((pixelPosition-($(scaleObj).width()/2)))+'px'; |
541 }); | 484 }); |
542 } | 485 } |
543 | 486 |
544 function pageXMLSave(store, testXML, testId) | 487 function pageXMLSave(store, testXML) |
545 { | 488 { |
546 // Saves a specific test page | 489 // Saves a specific test page |
547 var xmlDoc = store; | 490 var xmlDoc = store; |
548 // Check if any session wide metrics are enabled | 491 // Check if any session wide metrics are enabled |
549 | 492 |
550 var commentShow = testXML.attributes['elementComments']; | 493 var commentShow = testXML.elementComments; |
551 if (commentShow != undefined) { | |
552 if (commentShow.value == 'false') {commentShow = false;} | |
553 else {commentShow = true;} | |
554 } else {commentShow = true;} | |
555 | 494 |
556 var metric = document.createElement('metric'); | 495 var metric = document.createElement('metric'); |
557 if (audioEngineContext.metric.enableTestTimer) | 496 if (audioEngineContext.metric.enableTestTimer) |
558 { | 497 { |
559 var testTime = document.createElement('metricResult'); | 498 var testTime = document.createElement('metricResult'); |