-
Notifications
You must be signed in to change notification settings - Fork 0
/
metronome.js
49 lines (39 loc) · 917 Bytes
/
metronome.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
var Metronome = {
playing: false,
bpm: function() {
return parseInt($("#bpm").val());
},
changeSpeed: function(delta) {
$("#bpm").val(Metronome.bpm() + delta);
},
increase: function() {
Metronome.changeSpeed(5);
},
decrease: function() {
Metronome.changeSpeed(-5);
},
play: function() {
if (Metronome.playing) {
$("#play").val("Play");
Metronome.playing = false;
} else {
$("#play").val("Pause");
Metronome.playing = true;
Metronome.click();
}
},
click: function() {
if (Metronome.playing) {
$("#click")[0].play();
console.log("Click!");
var msPerBeat = 60*1000 / Metronome.bpm();
setTimeout(Metronome.click, msPerBeat);
}
}
}
// on document ready
$(function() {
$("#increase").click(Metronome.increase);
$("#decrease").click(Metronome.decrease);
$("#play").click(Metronome.play);
});