-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpage.html
134 lines (120 loc) · 3.02 KB
/
page.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<!DOCTYPE html>
<html><head>
<script src="Tone.min.js"></script>
</head>
<style>
.card{
max-width: 400px;
min-height: 250px;
background: #ff0000;
padding: 30px;
box-sizing: border-box;
color: #FFF;
margin:20px;
box-shadow: 0px 2px 18px -4px rgba(0,0,0,0.75);
}
</style>
<body>
<h1>Piano Man</h1>
<input type="button" id="btn_mute" value="Enable Sound"/>
<div class="card">
<table width = 400>
<tr>
<td><h1><span id="touch1">0</h1></span></td>
<td><h1><span id="touch2">0</h1></span></td>
<td><h1><span id="touch3">0</h1></span></td>
<td><h1><span id="touch4">0</h1></span></td>
</tr>
</div>
<script>
var btn_mute = document.getElementById("btn_mute");
btn_mute.addEventListener("click", function(){
if (Tone.context.state !== 'running') {
Tone.context.resume();
btn_mute.value = "Disable Sound";
}else{
Tone.context.suspend();
btn_mute.value = "Enable Sound";
}
});
var synth = new Tone.PolySynth(4, Tone.Synth).toMaster();
//synth.triggerAttack("C3");
//var volume = new Tone.Volume();
//volume.set("mute", true);
//volume.set("volume", -6); // now signal isn’t muted any more
setInterval(function() {
// Call a function repetatively with 2 Second interval
getData();
}, 300); //100mSeconds update rate
var t1active = false;
var t2active = false;
var t3active = false;
var t4active = false;
function handleTouchThresh(arr){
var thresh = 6000;
if(!t1active && arr[0]>thresh){
synth.triggerAttack("C3");
t1active = true;
}else if(t1active && arr[0]<thresh){
synth.triggerRelease("C3");
t1active = false;
}
if(!t2active && arr[1]>thresh){
synth.triggerAttack("E3");
t2active = true;
}else if(t2active && arr[1]<thresh){
synth.triggerRelease("E3");
t2active = false;
}
if(!t3active && arr[2]>thresh){
synth.triggerAttack("G3");
t3active = true;
}else if(t3active && arr[2]<thresh){
synth.triggerRelease("G3");
t3active = false;
}
if(!t4active && arr[3]>thresh){
synth.triggerAttack("C4");
t4active = true;
}else if(t4active && arr[3]<thresh){
synth.triggerRelease("C4");
t4active = false;
}
//synth.triggerAttack("C3");
/*
if(touchid == 1){
if (value<thresh){
if(!t1active){
synth.triggerAttackRelease("C3", 1);
t1active = true;
}//otherwise do nothing, it is already active
}else{
synth.triggerRelease();
t1active = false;
//alert("released");
}
}*/
}
function getData() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var arr = this.responseText.split(',');
handleTouchThresh(arr);
//var arr = ["5", "10", "15", "20"];
document.getElementById("touch1").innerHTML =
arr[0];
document.getElementById("touch2").innerHTML =
arr[1];
document.getElementById("touch3").innerHTML =
arr[2];
document.getElementById("touch4").innerHTML =
arr[3];
}
};
xhttp.open("GET", "/readTouch", true);
xhttp.send();
}
</script>
</body>
</html>