Skip to content

Commit 0fc3bb5

Browse files
committed
Add drums
1 parent 3ce6e5c commit 0fc3bb5

File tree

8 files changed

+68
-0
lines changed

8 files changed

+68
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
/node_modules
2+
/lib-samples
23
*.log
34
*idea/

drums.html

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<title>Drums</title>
5+
<script src="/static/fastclick/lib/fastclick.js"></script>
6+
<script src="/static/socket.io/node_modules/socket.io-client/socket.io.js"></script>
7+
<style>
8+
table, td, th {
9+
border: 2px solid black;
10+
}
11+
td {
12+
background-color: green;
13+
}
14+
</style>
15+
</head>
16+
<body>
17+
<table width="100%" height="800px">
18+
<tr>
19+
<td onclick="play('kick')"></td>
20+
</tr>
21+
<tr>
22+
<td onclick="play('snare')"></td>
23+
</tr>
24+
<tr>
25+
<td onclick="play('clap')"></td>
26+
</tr>
27+
<tr>
28+
<td onclick="play('hihat')"></td>
29+
</tr>
30+
<tr>
31+
<td onclick="play('crash')"></td>
32+
</tr>
33+
</table>
34+
<script>
35+
var socket = io(),
36+
37+
play = function (drum) {
38+
socket.emit('beat', drum);
39+
};
40+
41+
if ('addEventListener' in document) {
42+
document.addEventListener('DOMContentLoaded', function() {
43+
FastClick.attach(document.body);
44+
}, false);
45+
}
46+
</script>
47+
</body>
48+
</html>

samples/clap-808.wav

140 KB
Binary file not shown.

samples/crash-noise.wav

374 KB
Binary file not shown.

samples/hihat-electro.wav

7.84 KB
Binary file not shown.

samples/kick-808.wav

130 KB
Binary file not shown.

samples/snare-smasher.wav

73.1 KB
Binary file not shown.

server.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ var express = require('express'),
1616
'F': ['F3', 'A3', 'C3'],
1717
'G': ['G3', 'B3', 'D3'],
1818
'Am': ['A3', 'C3', 'E3']
19+
},
20+
21+
drums = {
22+
'clap': __dirname + '/samples/clap-808.wav',
23+
'crash': __dirname + '/samples/crash-noise.wav',
24+
'hihat':__dirname + '/samples/hihat-electro.wav',
25+
'kick': __dirname + '/samples/kick-808.wav',
26+
'snare': __dirname + '/samples/snare-smasher.wav'
1927
};
2028

2129
app.use('/static', express.static(__dirname + '/node_modules'));
@@ -32,6 +40,10 @@ app.get('/chords', function (req, res) {
3240
res.sendFile(__dirname + '/chords.html');
3341
});
3442

43+
app.get('/drums', function (req, res) {
44+
res.sendFile(__dirname + '/drums.html');
45+
});
46+
3547
io.on('connection', function (socket){
3648
console.log('a user connected');
3749

@@ -48,6 +60,13 @@ io.on('connection', function (socket){
4860
shell.exec(command, {async: true});
4961
});
5062

63+
socket.on('beat', function (msg) {
64+
var drum = drums[msg],
65+
command = 'play -q ' + drum;
66+
67+
shell.exec(command, {async: true, silent: true});
68+
});
69+
5170
socket.on('disconnect', function() {
5271
console.log('a user disconnected');
5372
});

0 commit comments

Comments
 (0)