This repository has been archived by the owner on Jun 17, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
amen.js
70 lines (62 loc) · 1.54 KB
/
amen.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
drumSampleSort = function(a, b) {
if(a > b) {
return -1
} else {
return 1
}
}
$(document).ready(function(){
var wait = 190;
strike = function() {
if(drumSamples.queue.length == 0) {
return;
}
nextSample = drumSamples.queue.shift();
if(nextSample.src.match(/kick/)) {
$('#kick').animate({marginLeft: '+=10'}, 95);
} else if(nextSample.src.match(/snare/)) {
$('#snare').animate({marginTop: '+=10'}, 95);
}
nextSample.play();
if(nextSample.src.match(/kick/)) {
$('#kick').animate({marginLeft: '0'}, 95)
} else if(nextSample.src.match(/snare/)) {
$('#snare').animate({marginTop: '0'}, 95)
}
chance = Math.floor(Math.random() * 10);
switch(chance)
{
case 0:
drumSamples.queue.splice(4, 0, nextSample);
break;
case 1:
drumSamples.queue.splice(6, 0, nextSample);
break;
case 2:
drumSamples.queue.reverse();
drumSamples.queue.push(nextSample);
break;
case 3:
drumSamples.queue.sort(drumSampleSort);
drumSamples.queue.push(nextSample);
break;
default:
drumSamples.queue.push(nextSample);
break;
}
//$('#debug').text('');
//$.each(drumSamples, function() {
// $('#debug').append(this.src + '<br />');
//});
setTimeout(strike, wait);
}
$('#stop').click(function() {
drumSamples.queue = []
});
$('#start').click(function() {
drumSamples.populateQueue();
sample = drumSamples.queue.shift();
sample.play();
setTimeout(strike, wait);
});
});