Skip to content

Commit 5c9ced4

Browse files
committed
merge fix.
2 parents 5cd9ec3 + 3ce6e5c commit 5c9ced4

File tree

2 files changed

+69
-2
lines changed

2 files changed

+69
-2
lines changed

chords.html

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<title>Chords</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('C')"></td>
20+
</tr>
21+
<tr>
22+
<td onclick="play('G')"></td>
23+
</tr>
24+
<tr>
25+
<td onclick="play('Am')"></td>
26+
</tr>
27+
<tr>
28+
<td onclick="play('F')"></td>
29+
</tr>
30+
</table>
31+
<script>
32+
var socket = io(),
33+
34+
play = function (chord) {
35+
socket.emit('chord', chord);
36+
};
37+
38+
if ('addEventListener' in document) {
39+
document.addEventListener('DOMContentLoaded', function() {
40+
FastClick.attach(document.body);
41+
}, false);
42+
}
43+
</script>
44+
</body>
45+
</html>

server.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,41 @@ var express = require('express'),
77
io = require('socket.io')(http),
88
url = require('url'),
99
shell = require('shelljs'),
10-
port = 3000;
10+
11+
port = 3000,
12+
chords = {
13+
'C': ['C3', 'E3', 'G3'],
14+
'Dm': ['D3', 'F3', 'A3'],
15+
'Em': ['E3', 'G3', 'B3'],
16+
'F': ['F3', 'A3', 'C3'],
17+
'G': ['G3', 'B3', 'D3'],
18+
'Am': ['A3', 'C3', 'E3']
19+
};
1120

1221
app.use('/static', express.static(__dirname + '/node_modules'));
1322

1423
app.get('/', function (req, res) {
1524
res.sendFile(__dirname + '/index.html');
1625
});
1726

27+
app.get('/chords', function (req, res) {
28+
res.sendFile(__dirname + '/chords.html');
29+
});
30+
1831
io.on('connection', function (socket){
1932
console.log('a user connected');
2033

2134
socket.on('play', function (msg) {
22-
shell.exec('play -qn synth 2 pluck ' + msg, {async: true});
35+
var command = 'play -qn synth 2 pluck ' + msg;
36+
37+
shell.exec(command, {async: true});
38+
});
39+
40+
socket.on('chord', function (msg) {
41+
var chord = chords[msg],
42+
command = 'play -qn synth sin ' + chord[0] + ' sin ' + chord[1] + ' sin ' + chord[2] + ' delay 0 .01 .02 remix - fade 0 2 .1 norm -1';
43+
44+
shell.exec(command, {async: true});
2345
});
2446

2547
socket.on('disconnect', function() {

0 commit comments

Comments
 (0)