1 // Javascript functions for controlling audio
7 var song, interval, scroll, body;
12 const rightarrow = 39;
16 const return2start = 82;
18 const howmanysecs = 10;
21 const scrollTime = 400;
24 // If endtime is not set then we can't loop
25 if (endtime == 0) return;
27 // if we're past the endtime then it's time to start back at the A marker
28 if (song.currentTime > endtime) {
29 song.currentTime = starttime;
30 if (ascrollpoint != 0) window.scrollTo(0, ascrollpoint);
34 function scrollLyrics(x, y) {
35 window.scrollBy(0, scrollby);
38 window.onload = function() {
39 song = document.getElementById('song');
41 starttime = song.currentTime;
42 endtime = song.duration;
43 body = document.getElementsByTagName('body')[0]
47 interval = setInterval(loop, oneSec);
48 scroll = setInterval(scrollLyrics, scrollTime);
54 if (ev.keyCode == spacebar) {
63 clearInterval(interval);
64 clearInterval(scroll);
69 if (ascrollpoint != 0) {
70 window.scrollTo(0, ascrollpoint);
72 window.scrollTo(0, 0);
76 song.currentTime = starttime;
80 interval = setInterval(loop, oneSec);
81 scroll = setInterval(scrollLyrics, scrollTime);
83 if (ascrollpoint != 0) window.scrollTo(0, ascrollpoint);
93 } else if (ev.keyCode == return2start) {
95 song.currentTime = starttime;
102 } else if (ev.keyCode == leftarrow) {
103 song.currentTime -= howmanysecs;
104 body.scrollBy(0, 50);
108 } else if (ev.keyCode == rightarrow) {
109 song.currentTime += howmanysecs;
110 bosy.scrollBy(0, -50);
114 } else if (ev.keyCode == seta) {
115 // Reset endtime if setting a new A marker
116 if (endtime != song.duration) endtime = song.duration;
118 starttime = song.currentTime;
120 // Translate seconds to timecode
121 secs = Math.floor(starttime % 60);
122 if (secs < 10) secs = '0' + secs;
124 document.getElementById('a').innerHTML =
125 Math.floor(starttime / 60) + ':' + secs;
127 ascrollpoint = window.pageYOffset;
130 } else if (ev.keyCode == setb) {
131 if (song.currentTime > starttime) {
132 endtime = song.currentTime;
133 song.currentTime = starttime;
135 // Translate seconds to timecode
136 secs = Math.floor(endtime % 60);
137 if (secs < 10) secs = '0' + secs;
139 document.getElementById('b').innerHTML =
140 Math.floor(endtime / 60) + ':' + secs;
142 bscrollpoint = window.pageYOffset;
144 } else if (ev.keyCode == cleara) {
146 endtime = song.duration;
150 document.getElementById('a').innerHTML = '<font color=#666><i>not set</i></font>';
151 document.getElementById('b').innerHTML = '<font color=#666><i>not set</i></font>';
156 } // getElementByTagName