Mercurial > hg > webaudioevaluationtool
comparison core.js @ 212:b5cb42422f4a
Merge into main for bug fixes
author | Nicholas Jillings <nicholas.jillings@eecs.qmul.ac.uk> |
---|---|
date | Tue, 16 Jun 2015 14:51:44 +0100 |
parents | 5d251b4aabd6 |
children | 28525223b3c0 |
comparison
equal
deleted
inserted
replaced
208:43dc4a1c3adf | 212:b5cb42422f4a |
---|---|
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) { | |
692 id = -1; | |
693 } else { | |
694 interfaceContext.playhead.setTimePerPixel(this.audioObjects[id]); | |
695 } | |
696 if (this.loopPlayback) { | |
697 for (var i=0; i<this.audioObjects.length; i++) | |
698 { | |
699 this.audioObjects[i].play(this.timer.getTestTime()+1); | |
700 if (id == i) { | |
701 this.audioObjects[i].loopStart(); | |
702 } else { | |
703 this.audioObjects[i].loopStop(); | |
690 } | 704 } |
691 } | 705 } |
692 this.status = 1; | 706 } else { |
693 } | 707 for (var i=0; i<this.audioObjects.length; i++) |
708 { | |
709 if (i != id) { | |
710 this.audioObjects[i].outputGain.gain.value = 0.0; | |
711 this.audioObjects[i].stop(); | |
712 } else if (i == id) { | |
713 this.audioObjects[id].outputGain.gain.value = 1.0; | |
714 this.audioObjects[id].play(audioContext.currentTime+0.01); | |
715 } | |
716 } | |
717 } | |
718 interfaceContext.playhead.start(); | |
694 } | 719 } |
695 }; | 720 }; |
696 | 721 |
697 this.stop = function() { | 722 this.stop = function() { |
698 // Send stop and reset command to all playback buffers and set audioEngine state to stopped (1) | 723 // Send stop and reset command to all playback buffers and set audioEngine state to stopped (1) |
699 if (this.status == 1) { | 724 if (this.status == 1) { |
700 for (var i=0; i<this.audioObjects.length; i++) | 725 for (var i=0; i<this.audioObjects.length; i++) |
701 { | 726 { |
702 this.audioObjects[i].stop(); | 727 this.audioObjects[i].stop(); |
703 } | 728 } |
729 interfaceContext.playhead.stop(); | |
704 this.status = 0; | 730 this.status = 0; |
705 } | 731 } |
706 }; | 732 }; |
707 | |
708 | 733 |
709 this.newTrack = function(element) { | 734 this.newTrack = function(element) { |
710 // Pull data from given URL into new audio buffer | 735 // 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' | 736 // URLs must either be from the same source OR be setup to 'Access-Control-Allow-Origin' |
712 | 737 |
789 this.metric.stopListening(audioEngineContext.timer.getTestTime()); | 814 this.metric.stopListening(audioEngineContext.timer.getTestTime()); |
790 } | 815 } |
791 }; | 816 }; |
792 | 817 |
793 this.play = function(startTime) { | 818 this.play = function(startTime) { |
794 this.bufferNode = audioContext.createBufferSource(); | 819 if (this.bufferNode == undefined) { |
795 this.bufferNode.owner = this; | 820 this.bufferNode = audioContext.createBufferSource(); |
796 this.bufferNode.connect(this.outputGain); | 821 this.bufferNode.owner = this; |
797 this.bufferNode.buffer = this.buffer; | 822 this.bufferNode.connect(this.outputGain); |
798 this.bufferNode.loop = audioEngineContext.loopPlayback; | 823 this.bufferNode.buffer = this.buffer; |
799 this.bufferNode.onended = function() { | 824 this.bufferNode.loop = audioEngineContext.loopPlayback; |
800 // Safari does not like using 'this' to reference the calling object! | 825 this.bufferNode.onended = function() { |
801 event.srcElement.owner.metric.stopListening(audioEngineContext.timer.getTestTime()); | 826 // Safari does not like using 'this' to reference the calling object! |
802 }; | 827 event.srcElement.owner.metric.stopListening(audioEngineContext.timer.getTestTime(),event.srcElement.owner.getCurrentPosition()); |
803 if (this.bufferNode.loop == false) { | 828 }; |
804 this.metric.startListening(audioEngineContext.timer.getTestTime()); | 829 if (this.bufferNode.loop == false) { |
805 } | 830 this.metric.startListening(audioEngineContext.timer.getTestTime()); |
806 this.bufferNode.start(startTime); | 831 } |
832 this.bufferNode.start(startTime); | |
833 } | |
807 }; | 834 }; |
808 | 835 |
809 this.stop = function() { | 836 this.stop = function() { |
810 if (this.bufferNode != undefined) | 837 if (this.bufferNode != undefined) |
811 { | 838 { |
839 this.metric.stopListening(audioEngineContext.timer.getTestTime(),this.getCurrentPosition()); | |
812 this.bufferNode.stop(0); | 840 this.bufferNode.stop(0); |
813 this.bufferNode = undefined; | 841 this.bufferNode = undefined; |
814 this.metric.stopListening(audioEngineContext.timer.getTestTime()); | |
815 } | 842 } |
816 }; | 843 }; |
817 | 844 |
818 this.getCurrentPosition = function() { | 845 this.getCurrentPosition = function() { |
819 var time = audioEngineContext.timer.getTestTime(); | 846 var time = audioEngineContext.timer.getTestTime(); |
978 | 1005 |
979 console.log('slider ' + this.parent.id + ' played (' + time + ')'); // DEBUG/SAFETY: show played slider id | 1006 console.log('slider ' + this.parent.id + ' played (' + time + ')'); // DEBUG/SAFETY: show played slider id |
980 } | 1007 } |
981 }; | 1008 }; |
982 | 1009 |
983 this.stopListening = function(time) | 1010 this.stopListening = function(time,bufferStopTime) |
984 { | 1011 { |
985 if (this.listenHold == true) | 1012 if (this.listenHold == true) |
986 { | 1013 { |
987 var diff = time - this.listenStart; | 1014 var diff = time - this.listenStart; |
988 this.listenedTimer += (diff); | 1015 this.listenedTimer += (diff); |
991 | 1018 |
992 var evnt = this.listenTracker[this.listenTracker.length-1]; | 1019 var evnt = this.listenTracker[this.listenTracker.length-1]; |
993 var testTime = evnt.getElementsByTagName('testTime')[0]; | 1020 var testTime = evnt.getElementsByTagName('testTime')[0]; |
994 var bufferTime = evnt.getElementsByTagName('bufferTime')[0]; | 1021 var bufferTime = evnt.getElementsByTagName('bufferTime')[0]; |
995 testTime.setAttribute('stop',time); | 1022 testTime.setAttribute('stop',time); |
996 bufferTime.setAttribute('stop',this.parent.getCurrentPosition()); | 1023 if (bufferStopTime == undefined) { |
1024 bufferTime.setAttribute('stop',this.parent.getCurrentPosition()); | |
1025 } else { | |
1026 bufferTime.setAttribute('stop',bufferStopTime); | |
1027 } | |
997 console.log('slider ' + this.parent.id + ' played for (' + diff + ')'); // DEBUG/SAFETY: show played slider id | 1028 console.log('slider ' + this.parent.id + ' played for (' + diff + ')'); // DEBUG/SAFETY: show played slider id |
998 } | 1029 } |
999 }; | 1030 }; |
1000 | 1031 |
1001 this.exportXMLDOM = function() { | 1032 this.exportXMLDOM = function() { |
1647 for (var i=0; i<interfaceContext.commentBoxes.length; i++) { | 1678 for (var i=0; i<interfaceContext.commentBoxes.length; i++) { |
1648 inject.appendChild(this.commentBoxes[i].trackComment); | 1679 inject.appendChild(this.commentBoxes[i].trackComment); |
1649 } | 1680 } |
1650 }; | 1681 }; |
1651 | 1682 |
1683 this.deleteCommentBoxes = function() { | |
1684 this.commentBoxes = []; | |
1685 } | |
1686 | |
1652 this.createCommentQuestion = function(element) { | 1687 this.createCommentQuestion = function(element) { |
1653 var node; | 1688 var node; |
1654 if (element.type == 'text') { | 1689 if (element.type == 'text') { |
1655 node = new this.commentBox(element); | 1690 node = new this.commentBox(element); |
1656 } else if (element.type == 'radio') { | 1691 } else if (element.type == 'radio') { |
1659 node = new this.checkboxBox(element); | 1694 node = new this.checkboxBox(element); |
1660 } | 1695 } |
1661 this.commentQuestions.push(node); | 1696 this.commentQuestions.push(node); |
1662 return node; | 1697 return node; |
1663 }; | 1698 }; |
1699 | |
1700 this.playhead = new function() | |
1701 { | |
1702 this.object = document.createElement('div'); | |
1703 this.object.className = 'playhead'; | |
1704 this.object.align = 'left'; | |
1705 var curTime = document.createElement('div'); | |
1706 curTime.style.width = '50px'; | |
1707 this.curTimeSpan = document.createElement('span'); | |
1708 this.curTimeSpan.textContent = '00:00'; | |
1709 curTime.appendChild(this.curTimeSpan); | |
1710 this.object.appendChild(curTime); | |
1711 this.scrubberTrack = document.createElement('div'); | |
1712 this.scrubberTrack.className = 'playhead-scrub-track'; | |
1713 | |
1714 this.scrubberHead = document.createElement('div'); | |
1715 this.scrubberHead.id = 'playhead-scrubber'; | |
1716 this.scrubberTrack.appendChild(this.scrubberHead); | |
1717 this.object.appendChild(this.scrubberTrack); | |
1718 | |
1719 this.timePerPixel = 0; | |
1720 this.maxTime = 0; | |
1721 | |
1722 this.playbackObject; | |
1723 | |
1724 this.setTimePerPixel = function(audioObject) { | |
1725 //maxTime must be in seconds | |
1726 this.playbackObject = audioObject; | |
1727 this.maxTime = audioObject.buffer.duration; | |
1728 var width = 490; //500 - 10, 5 each side of the tracker head | |
1729 this.timePerPixel = this.maxTime/490; | |
1730 if (this.maxTime < 60) { | |
1731 this.curTimeSpan.textContent = '0.00'; | |
1732 } else { | |
1733 this.curTimeSpan.textContent = '00:00'; | |
1734 } | |
1735 }; | |
1736 | |
1737 this.update = function() { | |
1738 // Update the playhead position, startPlay must be called | |
1739 if (this.timePerPixel > 0) { | |
1740 var time = this.playbackObject.getCurrentPosition(); | |
1741 var width = 490; | |
1742 var pix = Math.floor(time/this.timePerPixel); | |
1743 this.scrubberHead.style.left = pix+'px'; | |
1744 if (this.maxTime > 60.0) { | |
1745 var secs = time%60; | |
1746 var mins = Math.floor((time-secs)/60); | |
1747 secs = secs.toString(); | |
1748 secs = secs.substr(0,2); | |
1749 mins = mins.toString(); | |
1750 this.curTimeSpan.textContent = mins+':'+secs; | |
1751 } else { | |
1752 time = time.toString(); | |
1753 this.curTimeSpan.textContent = time.substr(0,4); | |
1754 } | |
1755 } | |
1756 }; | |
1757 | |
1758 this.interval = undefined; | |
1759 | |
1760 this.start = function() { | |
1761 if (this.playbackObject != undefined && this.interval == undefined) { | |
1762 this.interval = setInterval(function(){interfaceContext.playhead.update();},100); | |
1763 } | |
1764 }; | |
1765 this.stop = function() { | |
1766 clearInterval(this.interval); | |
1767 this.interval = undefined; | |
1768 }; | |
1769 }; | |
1664 } | 1770 } |
1665 | 1771 |