comparison core.js @ 1567:e159ee9fc725

Feature #1246: Scrubber bar included. Not interactive yet
author Nicholas Jillings <nickjillings@users.noreply.github.com>
date Thu, 11 Jun 2015 10:06:58 +0100
parents 8ad4aa8d0fd5
children 070a90d1117c
comparison
equal deleted inserted replaced
1566:8ad4aa8d0fd5 1567:e159ee9fc725
686 this.timer.startTest(); 686 this.timer.startTest();
687 this.status = 1; 687 this.status = 1;
688 } 688 }
689 } 689 }
690 if (this.status== 1) { 690 if (this.status== 1) {
691 if (id == undefined) {id = -1;} 691 if (id == undefined) {
692 id = -1;
693 } else {
694 interfaceContext.playhead.setTimePerPixel(this.audioObjects[id]);
695 }
692 if (this.loopPlayback) { 696 if (this.loopPlayback) {
693 for (var i=0; i<this.audioObjects.length; i++) 697 for (var i=0; i<this.audioObjects.length; i++)
694 { 698 {
695 this.audioObjects[i].play(this.timer.getTestTime()+1); 699 this.audioObjects[i].play(this.timer.getTestTime()+1);
696 if (id == i) { 700 if (id == i) {
709 this.audioObjects[id].outputGain.gain.value = 1.0; 713 this.audioObjects[id].outputGain.gain.value = 1.0;
710 this.audioObjects[id].play(audioContext.currentTime+0.01); 714 this.audioObjects[id].play(audioContext.currentTime+0.01);
711 } 715 }
712 } 716 }
713 } 717 }
718 interfaceContext.playhead.start();
714 } 719 }
715 }; 720 };
716 721
717 this.stop = function() { 722 this.stop = function() {
718 // 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)
719 if (this.status == 1) { 724 if (this.status == 1) {
720 for (var i=0; i<this.audioObjects.length; i++) 725 for (var i=0; i<this.audioObjects.length; i++)
721 { 726 {
722 this.audioObjects[i].stop(); 727 this.audioObjects[i].stop();
723 } 728 }
729 interfaceContext.playhead.stop();
724 this.status = 0; 730 this.status = 0;
725 } 731 }
726 }; 732 };
727 733
728 this.newTrack = function(element) { 734 this.newTrack = function(element) {
1697 this.object.appendChild(this.scrubberTrack); 1703 this.object.appendChild(this.scrubberTrack);
1698 1704
1699 this.timePerPixel = 0; 1705 this.timePerPixel = 0;
1700 this.maxTime = 0; 1706 this.maxTime = 0;
1701 1707
1702 this.startPlay = function(maxTime) { 1708 this.playbackObject;
1709
1710 this.setTimePerPixel = function(audioObject) {
1703 //maxTime must be in seconds 1711 //maxTime must be in seconds
1712 this.playbackObject = audioObject;
1713 this.maxTime = audioObject.buffer.duration;
1704 var width = 490; //500 - 10, 5 each side of the tracker head 1714 var width = 490; //500 - 10, 5 each side of the tracker head
1705 this.timePerPixel = maxTime/490; 1715 this.timePerPixel = this.maxTime/490;
1706 this.maxTime = maxTime; 1716 if (this.maxTime < 60) {
1707 if (maxTime < 60) {
1708 this.curTimeSpan.textContent = '0.00'; 1717 this.curTimeSpan.textContent = '0.00';
1709 } else { 1718 } else {
1710 this.curTimeSpan.textContent = '00:00'; 1719 this.curTimeSpan.textContent = '00:00';
1711 } 1720 }
1712 }; 1721 };
1713 1722
1714 this.update = function(time) { 1723 this.update = function() {
1715 // Update the playhead position, startPlay must be called 1724 // Update the playhead position, startPlay must be called
1716 if (this.timePerPixel > 0) { 1725 if (this.timePerPixel > 0) {
1726 var time = this.playbackObject.getCurrentPosition();
1717 var width = 490; 1727 var width = 490;
1718 var pix = Math.floor(width*time); 1728 var pix = Math.floor(time/this.timePerPixel);
1719 this.scrubberHead.style.left = pix+'px'; 1729 this.scrubberHead.style.left = pix+'px';
1720 if (this.maxTime > 60.0) { 1730 if (this.maxTime > 60.0) {
1721 var secs = time%60; 1731 var secs = time%60;
1722 var mins = Math.floor((time-secs)/60); 1732 var mins = Math.floor((time-secs)/60);
1723 secs = secs.toString(); 1733 secs = secs.toString();
1728 time = time.toString(); 1738 time = time.toString();
1729 this.curTimeSpan.textContent = time.substr(0,4); 1739 this.curTimeSpan.textContent = time.substr(0,4);
1730 } 1740 }
1731 } 1741 }
1732 }; 1742 };
1743
1744 this.interval = undefined;
1745
1746 this.start = function() {
1747 if (this.playbackObject != undefined && this.interval == undefined) {
1748 this.interval = setInterval(function(){interfaceContext.playhead.update();},100);
1749 }
1750 };
1751 this.stop = function() {
1752 clearInterval(this.interval);
1753 this.interval = undefined;
1754 };
1733 }; 1755 };
1734 } 1756 }
1735 1757