-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.html
141 lines (108 loc) · 3.83 KB
/
index.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
135
136
137
138
139
140
141
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<title>Chirrrrp</title>
</head>
<!-- <button id="triggerButton">Chirrrp</button> -->
<body>
<script src="bird.js"></script>
<script src="xgui.js"></script>
<script>
window.addEventListener("load", function(){
var ac;
window.AudioContext = window.AudioContext || window.webkitAudioContext;
if (window.AudioContext) ac = new AudioContext();
var count = 0;
var birds = [new bird(ac), new bird(ac), new bird(ac), new bird(ac)];
var gui = new xgui( {width: 640, height: 660, backgroundColor: "rgb(65, 104, 137)", frontColor: "rgb(153, 193, 226)", dimColor: "rgb(90, 137, 177)"} );
var pk = ['ifrq', 'atk', 'dcy', 'fmod1', 'atkf1', 'dcyf1', 'fmod2', 'atkf2', 'dcyf2', 'amod1', 'atka1', 'dcya1', 'amod2', 'atka2', 'dcya2'];
var presets = generatePresets();
var options = Object.keys(presets);
var params = presets['lesser-spotted-grinchwarbler'];
var initifrq = params.ifrq;
var frqKnob;
var knob, key;
var i = 0;
function makeCb(key) {
return function(a, up) {
if (key) params[key] = a;
if (up) chirp(key);
};
}
var knobs = [];
for (var y = 0; y < 5; y ++) {
for (var x = 0; x < 3; x ++ ) {
key = pk[i];
knob = new gui.Knob( {x: x * 100 + 80, y: y * 100 + 70, radius: 25, value: params[key], min: 0, max: 1, decimals: 7 } );
if (key == "ifrq"){
frqKnob = knob;
}
knob.value.bind(makeCb(key));
new gui.Label( {x: x * 100 + 80, y: y * 100 + 135, text: key} );
i++;
knobs.push(knob);
}
}
var dropdown = new gui.DropDown( {x: 80, y: 7, height:20, width:148, values:options , texts:options } );
dropdown.value.bind(function(key){
params = presets[key];
knobs.forEach(function (knob, i){
knob.value.v = params[pk[i]];
knob.draw();
});
initifrq = params.ifrq;
});
var button = new gui.Button({x: 90+180, y: 5, text: "Chirp", height: 25, font: "20px Arial"});
button.value.bind(makeCb(null));
var generate = new gui.CheckBox( {x: 90 +240, y: 10, text: "Repeat",width:15, height: 15} );
generate.value.bind(function(a, up){
if(up){
console.log("checked");
if (chirpGen){
window.clearInterval(chirpGen);
chirpGen = null;
}else{
chirpGen = window.setInterval(function(){
chirp(null,ac.currentTime+(Math.random()*0.4));
},(params.atk*1000*0.9));
}
}
});
var tp0 = new gui.TrackPad( {x: 90 + 100 + 100 + 100, y: 5 + 70, min: 0, max: 4, value1: 1.5, value2:3.8 } );
tp0.value1.bind(makeCb(null));
var rPos = new gui.CheckBox( {x: 90 + 410, y: 90, text: "Rand",width:15, height: 15} );
var rIfqr = new gui.CheckBox( {x: 30, y: 85, text: "Rand",width:15, height: 15} );
var chirpGen;
document.body.appendChild( gui.getDomElement() );
//var trigButton=document.getElementById("triggerButton");
function chirp(caller, time){
var b = birds[count];
//console.log(caller);
if(rIfqr.value.v && !caller){
params.ifrq = initifrq + (rnd_snd()*0.01);
frqKnob.value.v = params.ifrq;
frqKnob.draw();
}
if(rPos.value.v && !caller){
tp0.value1.v = Math.random()*tp0.max;
tp0.value2.v = Math.random()*tp0.max;
tp0.draw();
}
b.position = {x:tp0.value1.v-tp0.max/2, y: 0, z: (40-tp0.value2.v*10)};
b.velocity = {x:(Math.random()-0.5)*10, y: 0, z: 0};
//console.log(tp0);
console.log(JSON.stringify(params, null, '\t' ));
b.applyParams(params);
b.chirp(time);
count = (count+1) % birds.length;
}
function rnd_snd() {
return (Math.random()*2-1)+(Math.random()*2-1)+(Math.random()*2-1);
}
});
</script>
</body>