comparison ape.js @ 113:dcb042ed9d76

Fix Bug #1241 and #1213: Added checks each time new test page is loaded that all audioObjects have decoded. Writes to browser console WAIT and does not issue any play command if any audioObjects not ready.
author Nicholas Jillings <n.g.r.jillings@se14.qmul.ac.uk>
date Mon, 25 May 2015 11:14:12 +0100
parents 4d8846186db4
children d9a02dbfbf2c
comparison
equal deleted inserted replaced
112:4d8846186db4 113:dcb042ed9d76
263 263
264 function loadTest(id) 264 function loadTest(id)
265 { 265 {
266 266
267 // Reset audioEngineContext.Metric globals for new test 267 // Reset audioEngineContext.Metric globals for new test
268 audioEngineContext.metric.lastClicked = -1; 268 audioEngineContext.newTestPage();
269 audioEngineContext.metric.data = -1;
270 269
271 // Used to load a specific test page 270 // Used to load a specific test page
272 var textXML = testXMLSetups[id]; 271 var textXML = testXMLSetups[id];
273 272
274 var feedbackHolder = document.getElementById('feedbackHolder'); 273 var feedbackHolder = document.getElementById('feedbackHolder');
339 } 338 }
340 audioEngineContext.loopPlayback = loopPlayback; 339 audioEngineContext.loopPlayback = loopPlayback;
341 loopPlayback = false; 340 loopPlayback = false;
342 // Create AudioEngine bindings for playback 341 // Create AudioEngine bindings for playback
343 if (loopPlayback) { 342 if (loopPlayback) {
344 audioEngineContext.play = function() {
345 // Send play command to all playback buffers for synchronised start
346 // Also start timer callbacks to detect if playback has finished
347 if (this.status == 0) {
348 this.timer.startTest();
349 // First get current clock
350 var timer = audioContext.currentTime;
351 // Add 3 seconds
352 timer += 3.0;
353 // Send play to all tracks
354 for (var i=0; i<this.audioObjects.length; i++)
355 {
356 this.audioObjects[i].play(timer);
357 }
358 this.status = 1;
359 }
360 };
361
362 audioEngineContext.stop = function() {
363 // Send stop and reset command to all playback buffers
364 if (this.status == 1) {
365 if (this.loopPlayback) {
366 for (var i=0; i<this.audioObjects.length; i++)
367 {
368 this.audioObjects[i].stop();
369 }
370 }
371 this.status = 0;
372 }
373 };
374
375 audioEngineContext.selectedTrack = function(id) { 343 audioEngineContext.selectedTrack = function(id) {
376 for (var i=0; i<this.audioObjects.length; i++) 344 for (var i=0; i<this.audioObjects.length; i++)
377 { 345 {
378 if (id == i) { 346 if (id == i) {
379 this.audioObjects[i].outputGain.gain.value = 1.0; 347 this.audioObjects[i].outputGain.gain.value = 1.0;
381 this.audioObjects[i].outputGain.gain.value = 0.0; 349 this.audioObjects[i].outputGain.gain.value = 0.0;
382 } 350 }
383 } 351 }
384 }; 352 };
385 } else { 353 } else {
386 audioEngineContext.play = function() {
387 // Send play command to all playback buffers for synchronised start
388 // Also start timer callbacks to detect if playback has finished
389 if (this.status == 0) {
390 this.timer.startTest();
391 this.status = 1;
392 }
393 };
394
395 audioEngineContext.stop = function() {
396 // Send stop and reset command to all playback buffers
397 if (this.status == 1) {
398 for (var i=0; i<this.audioObjects.length; i++)
399 {
400 this.audioObjects[i].stop();
401 }
402 this.status = 0;
403 }
404 };
405
406 audioEngineContext.selectedTrack = function(id) { 354 audioEngineContext.selectedTrack = function(id) {
407 for (var i=0; i<this.audioObjects.length; i++) 355 for (var i=0; i<this.audioObjects.length; i++)
408 { 356 {
409 this.audioObjects[i].outputGain.gain.value = 0.0; 357 this.audioObjects[i].outputGain.gain.value = 0.0;
410 this.audioObjects[i].stop(); 358 this.audioObjects[i].stop();
751 } else if (currentState.substr(0,7) == 'testRun') 699 } else if (currentState.substr(0,7) == 'testRun')
752 { 700 {
753 var testId = currentState.substr(8,currentState.length-7); 701 var testId = currentState.substr(8,currentState.length-7);
754 // Check if we have any post tests to perform 702 // Check if we have any post tests to perform
755 var postXML = $(testXMLSetups[testId]).find('PostTest')[0]; 703 var postXML = $(testXMLSetups[testId]).find('PostTest')[0];
756 if (postXML == undefined) { 704 if (postXML == undefined || postXML.childElementCount == 0) {
757 testEnded(testId); 705 testEnded(testId);
758 } 706 }
759 else if (postXML.childElementCount > 0) 707 else if (postXML.childElementCount > 0)
760 { 708 {
761 currentState = 'testRunPost-'+testId; 709 currentState = 'testRunPost-'+testId;