comparison core.js @ 895:e2e39f867db3

Removed selected track. audioEngineContext.play(id) now controls audioObject playbacks
author Nicholas Jillings <n.g.r.jillings@se14.qmul.ac.uk>
date Thu, 11 Jun 2015 09:38:09 +0100
parents 1af8a548cab2
children ce1f952a36f3
comparison
equal deleted inserted replaced
894:1af8a548cab2 895:e2e39f867db3
673 this.loopPlayback = false; 673 this.loopPlayback = false;
674 674
675 // Create store for new audioObjects 675 // Create store for new audioObjects
676 this.audioObjects = []; 676 this.audioObjects = [];
677 677
678 this.play = function() { 678 this.play = function(id) {
679 // Start the timer and set the audioEngine state to playing (1) 679 // Start the timer and set the audioEngine state to playing (1)
680 if (this.status == 0) { 680 if (this.status == 0) {
681 // Check if all audioObjects are ready 681 // Check if all audioObjects are ready
682 if (this.audioObjectsReady == false) { 682 if (this.audioObjectsReady == false) {
683 this.audioObjectsReady = this.checkAllReady(); 683 this.audioObjectsReady = this.checkAllReady();
684 } 684 }
685 if (this.audioObjectsReady == true) { 685 if (this.audioObjectsReady == true) {
686 this.timer.startTest(); 686 this.timer.startTest();
687 if (this.loopPlayback) { 687 this.status = 1;
688 for(var i=0; i<this.audioObjects.length; i++) { 688 }
689 this.audioObjects[i].play(this.timer.getTestTime()+1); 689 }
690 if (this.status== 1) {
691 if (id == undefined) {id = -1;}
692 if (this.loopPlayback) {
693 for (var i=0; i<this.audioObjects.length; i++)
694 {
695 this.audioObjects[i].play(this.timer.getTestTime()+1);
696 if (id == i) {
697 this.audioObjects[i].loopStart();
698 } else {
699 this.audioObjects[i].loopStop();
690 } 700 }
691 } 701 }
692 this.status = 1; 702 } else {
703 for (var i=0; i<this.audioObjects.length; i++)
704 {
705 if (i != id) {
706 this.audioObjects[i].outputGain.gain.value = 0.0;
707 this.audioObjects[i].stop();
708 } else if (i == id) {
709 this.audioObjects[id].outputGain.gain.value = 1.0;
710 this.audioObjects[id].play(audioContext.currentTime+0.01);
711 }
712 }
693 } 713 }
694 } 714 }
695 }; 715 };
696 716
697 this.stop = function() { 717 this.stop = function() {
702 this.audioObjects[i].stop(); 722 this.audioObjects[i].stop();
703 } 723 }
704 this.status = 0; 724 this.status = 0;
705 } 725 }
706 }; 726 };
707
708 727
709 this.newTrack = function(element) { 728 this.newTrack = function(element) {
710 // Pull data from given URL into new audio buffer 729 // Pull data from given URL into new audio buffer
711 // URLs must either be from the same source OR be setup to 'Access-Control-Allow-Origin' 730 // URLs must either be from the same source OR be setup to 'Access-Control-Allow-Origin'
712 731
789 this.metric.stopListening(audioEngineContext.timer.getTestTime()); 808 this.metric.stopListening(audioEngineContext.timer.getTestTime());
790 } 809 }
791 }; 810 };
792 811
793 this.play = function(startTime) { 812 this.play = function(startTime) {
794 this.bufferNode = audioContext.createBufferSource(); 813 if (this.bufferNode == undefined) {
795 this.bufferNode.owner = this; 814 this.bufferNode = audioContext.createBufferSource();
796 this.bufferNode.connect(this.outputGain); 815 this.bufferNode.owner = this;
797 this.bufferNode.buffer = this.buffer; 816 this.bufferNode.connect(this.outputGain);
798 this.bufferNode.loop = audioEngineContext.loopPlayback; 817 this.bufferNode.buffer = this.buffer;
799 this.bufferNode.onended = function() { 818 this.bufferNode.loop = audioEngineContext.loopPlayback;
800 // Safari does not like using 'this' to reference the calling object! 819 this.bufferNode.onended = function() {
801 event.srcElement.owner.metric.stopListening(audioEngineContext.timer.getTestTime()); 820 // Safari does not like using 'this' to reference the calling object!
802 }; 821 event.srcElement.owner.metric.stopListening(audioEngineContext.timer.getTestTime());
803 if (this.bufferNode.loop == false) { 822 };
804 this.metric.startListening(audioEngineContext.timer.getTestTime()); 823 if (this.bufferNode.loop == false) {
805 } 824 this.metric.startListening(audioEngineContext.timer.getTestTime());
806 this.bufferNode.start(startTime); 825 }
826 this.bufferNode.start(startTime);
827 }
807 }; 828 };
808 829
809 this.stop = function() { 830 this.stop = function() {
810 if (this.bufferNode != undefined) 831 if (this.bufferNode != undefined)
811 { 832 {