Skip to content

Commit bfecf02

Browse files
committed
Merge
2 parents 80b458f + 833e537 commit bfecf02

File tree

5 files changed

+115
-42
lines changed

5 files changed

+115
-42
lines changed

chords.html

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@
77
<script src="/static/socket.io/node_modules/socket.io-client/socket.io.js"></script>
88

99
<!-- CSS -->
10-
<link href="http://getbootstrap.com/dist/css/bootstrap.min.css" rel="stylesheet">
10+
<link href="/static/bootstrap/dist/css/bootstrap.css" rel="stylesheet">
1111
<link href="torsk.css" rel="stylesheet">
12+
13+
<!-- JS -->
14+
<script type="text/javascript" src="torsk.js"></script>
1215
</head>
1316
<body>
1417
<div class="container">
@@ -18,25 +21,12 @@ <h1>Torsk-Synth! Play for Lofoten :)</h1>
1821
</div>
1922

2023
<div class="row marketing">
21-
<button type="button" class="btn btn-default torsk-btn col-md-12" onclick="play('C')">-</button>
22-
<button type="button" class="btn btn-default torsk-btn col-md-12" onclick="play('G')">-</button>
23-
<button type="button" class="btn btn-default torsk-btn col-md-12" onclick="play('Am')">-</button>
24-
<button type="button" class="btn btn-default torsk-btn col-md-12" onclick="play('F')">-</button>
24+
<button type="button" class="btn btn-default torsk-btn col-md-12" onclick="playChord('C')">-</button>
25+
<button type="button" class="btn btn-default torsk-btn col-md-12" onclick="playChord('G')">-</button>
26+
<button type="button" class="btn btn-default torsk-btn col-md-12" onclick="playChord('Am')">-</button>
27+
<button type="button" class="btn btn-default torsk-btn col-md-12" onclick="playChord('F')">-</button>
2528
</div>
2629

2730
</div>
28-
<script>
29-
var socket = io(),
30-
31-
play = function (chord) {
32-
socket.emit('chord', chord);
33-
};
34-
35-
if ('addEventListener' in document) {
36-
document.addEventListener('DOMContentLoaded', function() {
37-
FastClick.attach(document.body);
38-
}, false);
39-
}
40-
</script>
4131
</body>
4232
</html>

index.html

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,40 +9,28 @@
99
<!-- CSS -->
1010
<link href="/static/bootstrap/dist/css/bootstrap.css" rel="stylesheet">
1111
<link href="torsk.css" rel="stylesheet">
12+
13+
<!-- JS -->
14+
<script type="text/javascript" src="torsk.js"></script>
1215
</head>
1316
<body>
14-
1517
<div class="container">
1618

1719
<div class="jumbotron">
1820
<h1>Torsk-Synth! Play for Lofoten :)</h1>
1921
</div>
2022

2123
<div class="row marketing">
22-
<button type="button" class="btn btn-default torsk-btn col-md-3" onclick="play('C')">C</button>
24+
<button type="button" class="btn btn-default torsk-btn col-md-3" onclick="play('C5')">C5</button>
2325
<button type="button" class="btn btn-default torsk-btn col-md-3" onclick="play('B')">H</button>
2426
<button type="button" class="btn btn-default torsk-btn col-md-3" onclick="play('A')">A</button>
2527
<button type="button" class="btn btn-default torsk-btn col-md-3" onclick="play('G')">G</button>
2628
<button type="button" class="btn btn-default torsk-btn col-md-3" onclick="play('F')">F</button>
27-
<button type="button" class="btn btn-default torsk-btn col-md-3" onclick="play('E')">E</button>
29+
<button type="button" class="btn btn-default torsk-btn col-md-3" onclick="play('E')">E</button>
2830
<button type="button" class="btn btn-default torsk-btn col-md-3" onclick="play('D')">D</button>
29-
<button type="button" class="btn btn-default torsk-btn col-md-3" onclick="play('C5')">C5</button>
31+
<button type="button" class="btn btn-default torsk-btn col-md-3" onclick="play('C')">C</button>
3032
</div>
3133

3234
</div>
33-
<script>
34-
if ('addEventListener' in document) {
35-
document.addEventListener('DOMContentLoaded', function() {
36-
FastClick.attach(document.body);
37-
}, false);
38-
}
39-
40-
var socket = io(),
41-
42-
play = function (note) {
43-
socket.emit('play', note);
44-
};
45-
</script>
4635
</body>
47-
4836
</html>

sequence.html

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Sequence | Torsk</title>
6+
<script src="/static/fastclick/lib/fastclick.js"></script>
7+
<script src="/static/socket.io/node_modules/socket.io-client/socket.io.js"></script>
8+
9+
<!-- CSS -->
10+
<link href="/static/bootstrap/dist/css/bootstrap.css" rel="stylesheet">
11+
<link href="torsk.css" rel="stylesheet">
12+
13+
<!-- JS -->
14+
<script type="text/javascript" src="torsk.js"></script>
15+
</head>
16+
<body>
17+
<div class="container">
18+
19+
<div class="jumbotron">
20+
<h1>Torsk-Synth! Play for Lofoten :)</h1>
21+
</div>
22+
23+
<div class="row marketing">
24+
<p>possible notes: c,d,e,f,g,a,b,c </p>
25+
<form>
26+
<input id="chordSequence" type="text" name="sequence"/>
27+
<button type="button" onclick="playSequence()">Play sequence</button>
28+
</form>
29+
</div>
30+
31+
</div>
32+
</body>
33+
</html>

server.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ var express = require('express'),
3131

3232
app.use('/static', express.static(__dirname + '/node_modules'));
3333
app.use('/torsk.css', express.static(__dirname + '/torsk.css'));
34+
app.use('/torsk.js', express.static(__dirname + '/torsk.js'));
3435

3536
app.get('/', function (req, res) {
3637
res.sendFile(__dirname + '/index.html');
@@ -41,7 +42,11 @@ app.get('/chords', function (req, res) {
4142
});
4243

4344
app.get('/drums', function (req, res) {
44-
res.sendFile(__dirname + '/drums.html');
45+
res.sendFile(__dirname + '/drums.html');
46+
});
47+
48+
app.get('/sequence', function (req, res) {
49+
res.sendFile(__dirname + '/sequence.html');
4550
});
4651

4752
io.on('connection', function (socket){
@@ -60,12 +65,17 @@ io.on('connection', function (socket){
6065
shell.exec(command, {async: true});
6166
});
6267

63-
socket.on('beat', function (msg) {
64-
var drum = drums[msg],
65-
command = 'play -q ' + drum;
68+
socket.on('beat', function (msg) {
69+
var drum = drums[msg],
70+
command = 'play -q ' + drum;
6671

67-
shell.exec(command, {async: true, silent: true});
68-
});
72+
shell.exec(command, {async: true, silent: true});
73+
});
74+
75+
socket.on('playSequence', function (msg) {
76+
console.log(msg);
77+
// todo play sequences.
78+
});
6979

7080
socket.on('disconnect', function() {
7181
console.log('a user disconnected');

torsk.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/**
2+
* Created by kiro on 14/11/15.
3+
*/
4+
5+
6+
if ('addEventListener' in document) {
7+
document.addEventListener('DOMContentLoaded', function() {
8+
FastClick.attach(document.body);
9+
}, false);
10+
}
11+
12+
var socket = io();
13+
14+
playSequence = function () {
15+
console.log("sequence!");
16+
var value = document.getElementById('chordSequence').value;
17+
console.log(value);
18+
var res = value.split("");
19+
20+
res = transformToArray(res);
21+
22+
socket.emit('playSequence', res);
23+
};
24+
25+
play = function (chord) {
26+
console.log("play!");
27+
socket.emit('play', chord);
28+
};
29+
30+
playChord = function (chord) {
31+
console.log("chord!");
32+
socket.emit('chord', chord);
33+
};
34+
35+
transformToArray = function ( res ) {
36+
// transform strings to arrays, so we gat a nice format.
37+
// str: 'aefg' -> [ [a], [e], [f], [g] ]
38+
var out;
39+
for ( var chord in res ) {
40+
if ( typeof res[chord] === 'string' ) {
41+
//console.log("not an array");
42+
out = [ res[chord] ];
43+
} else {
44+
//console.log("already an array");
45+
out = res[chord];
46+
}
47+
//console.log(out);
48+
res[chord] = out;
49+
}
50+
return res;
51+
};
52+

0 commit comments

Comments
 (0)