-
Notifications
You must be signed in to change notification settings - Fork 1
/
music.html
76 lines (54 loc) · 1.83 KB
/
music.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
<!DOCTYPE html>
<html>
<head>
<title>Pan 1</title>
<script type="text/javascript" src="js/sb-1.4.1.js">//this is the spacebrew library</script>
</head>
<body>
<script type="text/javascript">
//when everything (window, HTML, css, resources) is loaded, run the spacebrew setup
window.onload = function(){
setupSpacebrew();
}
var sb; //spacebrew global initialization
//setup spacebrew
function setupSpacebrew () {
//a function that defines all the variables, servers, publishers and subscribers and defines a new function for when message arrive
sb = new Spacebrew.Client(); //this is a client
sb.name("Pan_Song_1"); //name the client
sb.server = "104.131.48.13"; //change this to change the server, e.g. for a local server
sb.addSubscribe("on&off", "boolean", "false"); //add a subscriber
sb.addSubscribe("volume", "vvolume"); //add a subscriber
var opts = ["guitar", "bass", "drums", "vocals"];
var id = opts[Math.floor(Math.random()*opts.length)];
sb.onBooleanMessage = onBooleanMessage; //override the blank function that is in the library with our own custom version
sb.onCustomMessage = onCustomMessage;
sb.connect(); //connect to the server
}
//this is the message for incoming range data
function onBooleanMessage (name, value) {
var myAudio = document.getElementById("sound");
if(value == true){
myAudio.play();
} else if(value == false){
myAudio.pause();
}
}
function onCustomMessage (name, value, type) {
if (type == "vvolume"){
var volumes = JSON.parse(value);
var v0 = volumes.v0;
var v1 = volumes.v1;
var v2 = volumes.v2;
var v3 = volumes.v3;
var myAudio = document.getElementById("sound");
myAudio.volume = v0/1023;
}
}
</script>
<audio id="sound" preload>
<source src="drums.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
</body>
</html>