forked from webmedia-lab/the-webaudio-experience
-
Notifications
You must be signed in to change notification settings - Fork 0
/
beat_sequence.html
82 lines (68 loc) · 2.38 KB
/
beat_sequence.html
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
70
71
72
73
74
75
76
77
78
79
80
81
82
<!DOCTYPE html>
<html>
<head>
<title>drum sequencer</title>
<script src="js/WAAClock-latest.js"></script>
<script src="js/jquery-1.9.1.js"></script>
<script src="js/jquery-ui-1.10.3.js"></script>
<script src="js/common.js"></script>
<link href="css/jquery-ui.css" rel="stylesheet" type="text/css" />
<link href="css/rainbow.css" rel="stylesheet" type="text/css" />
<link href="css/styles.css" rel="stylesheet" type="text/css" />
<link href="css/beatSequence.css" rel="stylesheet" type="text/css" />
<script src="js/rainbow-custom.min.js"></script>
</head>
<body>
<h1><span id="signature"></span>/4, <span id="tempo"></span> BPM</h1>
<div class="note">
<b>note :</b> you can change the tempo and the signature. For example go to <a href="?tempo=300&signature=7">?tempo=300&signature=7</a> to have 7 beats played at tempo 300.
</div>
<button id="startButton">Start</button>
<table id="pattern">
<tr data-track="hihat"></tr>
<tr data-track="snare"></tr>
<tr data-track="noise_snare"></tr>
<tr data-track="kick"></tr>
<tr data-track="boom_kick"></tr>
</table>
<script>
// Function for moving the beat cursor
var beatCount = -1;
var uiNextBeat = function() {
beatCount = (beatCount + 1) % signature;
$('#pattern td').removeClass('active');
$('#pattern td:nth-child('+(beatCount+1)+')').addClass('active');
}
</script>
<script src="js/beatSequence.js"></script>
<script>
$('#signature').html(signature);
$('#tempo').html(tempo);
$('#startButton').click(function() {
$('#startButton').hide();
$('#pattern tr').each(function() {
var track = $(this)
, trackName = track.data('track');
loadTrack(trackName);
beats[trackName] = {};
for (var beatInd = 0; beatInd < signature; beatInd++) {
var td = $('<td class="'+beatInd+'"><div class="beat"></div></td>');
td.appendTo(track);
td.find('.beat').click(function(beatInd) {
return function() {
var beat = $(this);
if (!beat.hasClass('active')) {
beat.addClass('active');
startBeat(trackName, beatInd);
} else {
beat.removeClass('active');
stopBeat(trackName, beatInd);
}
}
}(beatInd));
}
})
})
</script>
</body>
</html>