forked from lichen-community-systems/Flocking
-
Notifications
You must be signed in to change notification settings - Fork 1
/
playground.html
366 lines (344 loc) · 12.6 KB
/
playground.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Flocking Playground</title>
<link rel="stylesheet" type="text/css" href="../css/playground.css" />
<script src="../lib/jquery.min.js" type="text/javascript"></script>
<script src="../lib/ace_0.2.0/ace.js" type="text/javascript" charset="utf-8"></script>
<script src="../lib/ace_0.2.0/theme-twilight.js" type="text/javascript" charset="utf-8"></script>
<script src="../lib/ace_0.2.0/mode-javascript.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../flocking/flocking-core.js"></script>
<script src="../../../flocking/flocking-parser.js"></script>
<script src="../../../flocking/flocking-ugens.js"></script>
<script src="../../../flocking/flocking-gfx.js"></script>
<script src="../js/playground.js"></script>
</head>
<body>
<h1>Flocking Playground</h1>
<!-- Controls for selecting a demo and playing/pausing the active synth. -->
<div id="navi">
<button id="play-button">Play</button>
<select id="sample_code_sel" size="1">
<optgroup label="Simple Waveforms">
<option value="simple_sin">Sine</option>
<option value="simple_triangle">Triangle</option>
<option value="simple_square">Square</option>
<option value="simple_saw">Saw</option>
</optgroup>
<optgroup label="Noise">
<option value="noise_dust">Dust</option>
<option value="noise_lf">LFNoise</option>
<option value="noise_sin">LFNoise & SinOsc</option>
</optgroup>
<optgroup label="Modulation">
<option value="amp_mod" selected="selected">Amplitude modulation</option>
<option value="freq_mod">Frequency modulation</option>
<option value="phase_mod">Phase modulation</option>
</optgroup>
<optgroup label="Envelopes">
<option value="simpleASR">Simple Attack/Sustain/Release</option>
</optgroup>
<optgroup label="Lines">
<option value="line_freq">SinOsc Freq</option>
<option value="line_mod">Mod SinOsc Freq</option>
<option value="line_phase">SinOsc Phase</option>
</optgroup>
<optgroup label="Mouse">
<option value="mouse_x">Mouse X</option>
<option value="mouse_y">Mouse Y</option>
<option value="mouse_xy">Mouse X & Y</option>
</optgroup>
<option value="freq_stairs">Frequency stairs</option>
<option value="scope">Scope</option>
<option value="stereo">Stereo</option>
</select>
<button id="load-button">Load</button>
</div>
<!-- Placeholder for the Ace interactive editor -->
<pre id="editor">
// Create a new synth consisting of a sine wave,
// modulating its amplitude slowly with another sine wave.
var synth = flock.synth({
id: "carrier",
ugen: "flock.ugen.sinOsc",
freq: 440,
mul: {
id: "mod",
ugen: "flock.ugen.sinOsc",
rate: "control",
freq: 1.0
}
});
</pre>
<script>
var editorView = demo.liveEditorView("editor");
// TODO: Create an environment-level scheduler so that we don't need to worry about cleaning up things like this timer.
var timerId;
</script>
<!-- Scope View area for visualizing the demos -->
<div id="scopeArea">
<span id="gfx-title">#gfx</span>
<canvas id="gfx"></canvas>
</div>
<!-- start of sample codes -->
<script type="application/flocking" id="amp_mod">// Create a new synth consisting of a sine wave,
// modulating its amplitude slowly with another sine wave.
var synth = flock.synth({
id: "carrier",
ugen: "flock.ugen.sinOsc",
freq: 440,
mul: {
id: "mod",
ugen: "flock.ugen.sinOsc",
rate: "control",
freq: 1.0
}
});
</script>
<script type="application/flocking" id="freq_stairs">//Frequency Stair Stepping Demo
var startingFreq = 110;
// Create a new sine tone synth.
var synth = flock.synth({
id: "carrier",
ugen: "flock.ugen.sinOsc",
freq: startingFreq
});
// Every second, increase the frequency of the synth
// by a perfect fourth.
var freq = synth.input("carrier.freq");
timerId = window.setInterval(function () {
if (freq <= 3520) {
freq *= 4/3;
synth.input("carrier.freq", freq);
}
}, 1000);
</script>
<script type="application/flocking" id="freq_mod">//Frequency Modulation (FM) Synthesis Demo
var synth = flock.synth({
id: "carrier",
ugen: "flock.ugen.sinOsc",
freq: 440,
add: {
id: "mod",
ugen: "flock.ugen.sinOsc",
freq: 220
}
});
</script>
<script type="application/flocking" id="line_freq">// An ascending sinOsc glissando using a line ugen.
var synth = flock.synth({
ugen: "flock.ugen.sinOsc",
freq: {
ugen: "flock.ugen.xLine",
rate: "control",
duration: 1.0,
start: 2000,
end: 200
},
mul: 0.5
});
</script>
<script type="application/flocking" id="line_mod">//Line w/ Modulated SinOsc Freq
var synth = flock.synth({
ugen: "flock.ugen.sinOsc",
freq: {
ugen: "flock.ugen.sinOsc",
freq: {
ugen: "flock.ugen.xLine",
rate: "control",
start: 1,
end: 1000,
duration: 9
},
mul: 200,
add: 800
},
mul: 0.25
});
</script>
<script type="application/flocking" id="line_phase">// Line modulating the phase of a sine oscillator.
var synth = flock.synth({
ugen: "flock.ugen.sinOsc",
freq: 800,
phase: {
ugen: "flock.ugen.sinOsc",
freq: {
ugen: "flock.ugen.xLine",
rate: "control",
start: 1,
end: 1000,
duration: 9
},
mul: flock.TWOPI
},
mul: 0.25
});
</script>
<script type="application/flocking" id="simpleASR">// Sine tone shaped by a simple attack/sustain/release envelope and randomly triggered.
var synth = flock.synth({
ugen: "flock.ugen.sinOsc",
freq: 440,
mul: {
ugen: "flock.ugen.env.simpleASR",
start: 0.0,
attack: 0.25,
sustain: 0.6,
release: 1.0,
gate: {
ugen: "flock.ugen.dust",
rate: flock.rates.CONTROL,
density: 1/3
}
}
});
</script>
<script type="application/flocking" id="noise_dust">// Simple example of Dust generating random audio noise.
var synth = flock.synth({
ugen: "flock.ugen.dust",
density: 200,
mul: 0.5
});
</script>
<script type="application/flocking" id="noise_lf">// LFNoise generating random audio noise.
var synth = flock.synth({
ugen: "flock.ugen.lfNoise",
freq: 1000,
mul: 0.25
});
</script>
<script type="application/flocking" id="noise_sin">// LFNoise randomly changing the pitch of a sine
// oscillator every quarter second.
var synth = flock.synth({
ugen: "flock.ugen.sinOsc",
mul: 0.2,
freq: {
ugen: "flock.ugen.lfNoise",
freq: 4,
mul: 400,
add: 450
}
});
</script>
<script type="application/flocking" id="phase_mod">// Create a new synth consisting of a sine wave,
// modulating its phase with another sine wave.
var synth = flock.synth({
id: "carrier",
ugen: "flock.ugen.sinOsc",
freq: 440,
phase: {
id: "mod",
ugen: "flock.ugen.sinOsc",
freq: 20.0,
mul: flock.TWOPI
},
mul: 0.25
});
</script>
<script type="application/flocking" id="scope">// Dynamic scope: create a synth with a scope ugen
//at the end of the ugen graph.
var synth = flock.synth({
ugen: "flock.ugen.scope",
source: {
ugen: "flock.ugen.sinOsc",
freq: 440
},
options: {
canvas: "#gfx",
styles: {
scaleY: 0.75,
strokeColor: "#777777",
strokeWidth: 3
}
}
});
</script>
<script type="application/flocking" id="simple_sin">//Simple sine wave oscillator
var synth = flock.synth({
ugen: "flock.ugen.sinOsc",
freq: 440
});
</script>
<script type="application/flocking" id="simple_triangle">// And a triangle oscillator.
var synth = flock.synth({
ugen: "flock.ugen.triOsc",
freq: 440
});
</script>
<script type="application/flocking" id="simple_square">// And a square wave oscillator.
var synth = flock.synth({
ugen: "flock.ugen.lfPulse",
freq: 440
});
</script>
<script type="application/flocking" id="simple_saw">// And a saw.
var synth = flock.synth({
ugen: "flock.ugen.lfSaw",
freq: 440
});
</script>
<script type="application/flocking" id="stereo">// Create a synth with two different channels.
// The left and the right channels are both sine waves,
//but slightly apart in frequency.
//This creates a stereo beating effect.
var synth = flock.synth([
{
id: "leftSine",
ugen: "flock.ugen.sinOsc",
freq: 440
},
{
id: "rightSine",
ugen: "flock.ugen.sinOsc",
freq: 444
}
]);
</script>
<script type="application/flocking" id="mouse_x">
// Tracks the mouse's horizonal movement across the entire screen.
var synth = flock.synth({
ugen: "flock.ugen.sinOsc",
freq: {
ugen: "flock.ugen.mouse",
mul: 880,
add: 110
}
});
</script>
<script type="application/flocking" id="mouse_y">
// Tracks the mouse's vertical movement across the entire screen.
var synth = flock.synth({
ugen: "flock.ugen.sinOsc",
freq: {
ugen: "flock.ugen.mouse",
mul: 880,
add: 110,
options: {
axis: "height"
}
}
});
</script>
<script type="application/flocking" id="mouse_xy">
// Maps the mouse's vertical position to amplitude
// and its horizontal position to pitch.
var synth = flock.synth({
ugen: "flock.ugen.sinOsc",
freq: {
ugen: "flock.ugen.mouse",
mul: 880,
add: 110,
options: {
axis: "width"
}
},
mul: {
ugen: "flock.ugen.mouse",
options: {
axis: "height"
}
}
});
</script>
</body>
</html>