-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexamples.js
491 lines (426 loc) · 9.72 KB
/
examples.js
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
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
require('./kk/app.js');
require('./roswell/app.js');
require('./smb2/app.js');
const channels = ['PWM1', 'PWM2', 'TRIANGLE', 'NOISE'];
const buttons = document.querySelectorAll('footer button[data-song-id]');
for (const button of buttons) {
button.addEventListener('click', () => {
const songId = button.dataset.songId;
// load that song into the text areas
for (const channel of channels) {
document.querySelector(`textarea[data-channel=${channel}]`).value = window[songId][channel];
}
});
}
document.getElementById('play').addEventListener('click', () => {
// play whatever's in the textarea
const sequencerData = {};
for (const channel of channels) {
var textarea = document.querySelector(`textarea[data-channel=${channel}]`);
try {
sequencerData[channel] = NES.Mml.mmlToMelody(textarea.value);
} catch(e) {
sequencerData[channel] = [
{ frequency: 440, volume: 0 }
];
}
}
// play it in the sequencer
NES.Sequencer.stop();
NES.Oscillators.context.resume().then(() => {
NES.Sequencer.play(sequencerData, false);
});
});
document.getElementById('stop').addEventListener('click', () => NES.Sequencer.stop());
document.getElementById('reset').addEventListener('click', () => {
for (const channel of channels) {
var textarea = document.querySelector(`textarea[data-channel=${channel}]`);
textarea.value = '';
}
});
const canvas = document.querySelector('#canvas');
const ctx = canvas.getContext('2d');
const points = {
PWM1: [],
PWM2: [],
TRIANGLE: [],
NOISE: [],
};
const MAX_POINTS = 10;
NES.Events.Bus.addEventListener(NES.Events.Types.OSCILLATOR_CHANGE, function(e) {
points[e.oscillatorIndex].push(Object.assign({ when: Date.now()}, e));
if (points[e.oscillatorIndex].length > MAX_POINTS) {
points[e.oscillatorIndex].shift();
}
});
const drawPoints = (p, color) => {
const W = canvas.width;
ctx.fillStyle = color;
for (let i = 0; i < p.length; i++) {
const x = W * i / MAX_POINTS;
const halfStepsFromA = Math.log(p[i].frequency / 440) / Math.log(Math.pow(2, 1/12))
const y = 70 - halfStepsFromA * 2
const w = W / MAX_POINTS;
const h = p[i].volume * 10;
ctx.fillRect(x, y, W / MAX_POINTS, p[i].volume * 30)
}
};
const draw = () => {
requestAnimationFrame(draw);
const W = canvas.width;
ctx.clearRect(0, 0, W, W);
// just draw PWM1 for now
drawPoints(points.PWM1, '#F87068');
drawPoints(points.PWM2, '#28C020');
drawPoints(points.TRIANGLE, '#20A0F8');
}
requestAnimationFrame(draw);
},{"./kk/app.js":2,"./roswell/app.js":7,"./smb2/app.js":12}],2:[function(require,module,exports){
window.KK = {
tempo: 200,
TRIANGLE: require('./bass.js'),
PWM1: require('./melody.js'),
PWM2: require('./chords.js'),
NOISE: require('./drums.js'),
};
},{"./bass.js":3,"./chords.js":4,"./drums.js":5,"./melody.js":6}],3:[function(require,module,exports){
module.exports = [
't200',
'v75',
'l4 r', // pickup
'<<',
'l12',
// Main theme
'e r6 e r6 e4^6 a',
'r6 a r6 a a4 r4',
'd r6 d r6 d4^6 b',
'r6 b r6 b b4 r4',
'e r6 e r6 e4^6 a',
'r6 a r6 a a4 r4',
'd r6 d r6 d4^6 b',
'r6 b r6 b b4 r4',
'e r6 e r6 e4^6 a',
'r6 a r6 a a4 r4',
'd r6 d r6 d4^6 b',
'r6 b r6 b b4 r4',
'e r6 e r6 e4^6 a',
'r6 a r6 a a4 r4',
'b r6 b r6 b4^6 e',
'r6 e r6 e e4 r4',
// bridge
'g+ r6^6 g+ g+4 r4 g+ r6^6 g+ g+4 r4',
'c+ r6^6 c+ c+4 r4 c+ r6^6 c+ c+4 r4',
'f+ r6^6 f+ f+4 r4 f+ r6^6 f+ f+4 r4',
'l8 br br > cr cr < br l4 rrr l12',
// Reprise
'e r6 e r6 e4^6 a',
'r6 a r6 a a4 r4',
'd r6 d r6 d4^6 b',
'r6 b r6 b b4 r4',
'e r6 e r6 e4^6 a',
'r6 a r6 a a4 r4',
'c r6 c r6 d4^6 e',
'l4 rrrr l12',
'c r6 c r6 d4^6 e',
'l4 rrrr l12',
'c r6 c r6 d4^6 e2',
].join('\n');
},{}],4:[function(require,module,exports){
module.exports = [
't200',
'v20',
'l4 r', // pickup
// melody chords
'l8',
'rr[ e g+ b]r rr[e g+ b]r',
'rr[ e a c+]r rr[e a c+]r',
'rr[ d a f+]r rr[d a f+]r',
'rr[d+ f+ b]r rr[d+ f+ b]r',
'rr[ e g+ b]r rr[e g+ b]r',
'rr[ e a c+]r rr[e a c+]r',
'rr[ d a f+]r rr[d a f+]r',
'rr[d+ f+ b]r rr[d+ f+ b]r',
'rr[ e g+ b]r rr[e g+ b]r',
'rr[ e a c+]r rr[e a c+]r',
'rr[ d a f+]r rr[d a f+]r',
'rr[d+ f+ b]r rr[d+ f+ b]r',
'rr[ e g+ b]r rr[e g+ b]r',
'rr[ e a c+]r rr[e a c+]r',
'rr[d+ f+ b]r rr[d+ f+ b]r',
'rr[ e g+ b]r rr[e g+ b]r',
// bridge chords
'l1 v10',
'[g+ c d+]^',
'[g+ b f]^',
'[f+ a+ c+ e]^',
'l8',
'[b d+ f+]r',
'[b d+ f+]r',
'[e g > c]r',
'[e g > c]r',
'[b d+ f+]r',
'l4 rrr',
// Reprise
'l8 v20',
'rr[ e g+ b]r rr[e g+ b]r',
'rr[ e a c+]r rr[e a c+]r',
'rr[ d a f+]r rr[d a f+]r',
'rr[d+ f+ b]r rr[d+ f+ b]r',
'rr[ e g+ b]r rr[e g+ b]r',
'rr[ e a c+]r rr[e a c+]r',
'l12',
'[ceg] r6 [ceg] r6 [df+a]4^6 [eg+b]',
'l4 rrrr l12',
'[ceg] r6 [ceg] r6 [df+a]4^6 [eg+b]',
'l4 rrrr l12',
'[ceg] r6 [ceg] r6 [df+a]4^6 [eg+b]2',
].join('\n');
},{}],5:[function(require,module,exports){
module.exports = [
't200',
'v15',
'l12',
'b r b /: d r r b r d r r d b r r :/35'
].join('\n');
},{}],6:[function(require,module,exports){
module.exports = [
't200',
'v20',
'l4',
// The melody
'> e6 d+12 e < b g+ a6 b12 r r r',
'> d6 c+12 d e < > c+ < a6 b12 r r r',
'> e6 d+12 e f+ g+ e6 a12 r r r',
'a6 g+12 a g+ f+ e6 f+12 r r r',
'e6 d+12 e < b g+ a6 b12 r r r',
'> d6 c+12 d e < > c+ < a6 b12 r r r',
'> e6 d+12 e f+ g+ e6 a a12 g+ f+ e d+ e f+ d+6 e12 r4 r4 r4 r4',
// bridge
'c4 c+6 d12 d+6 f12 d+6 <b12 >c6 d+12 c6 <g+6^6',
'g+12 g12 f+12',
'e6 f12 g+6 a+12 b6 a+12 g+6 e12 f6 g+12 f6 c+12',
'r6 c+12 d+6 f12',
'l12 f+4 c+d+ef+g+aa+b>cc+d+ef+g+aa+f+d+c+<a+f+',
'l8 br br > cr cr < br l4 rr',
// Reprise
'> e6 d+12 e < b g+ a6 b12 r r r',
'> d6 c+12 d e < > c+ < a6 b12 r r r',
'> e6 d+12 e f+ g+ e6 a12 r r r r6 a12',
'l12',
'g r6 g r6 a4^6 b ',
'l4 rrrr6 l12 a',
'g r6 g r6 a4^6 b',
'l4 rrrr6 l12 a',
'g r6 g r6 a4^6 b2',
].join('\n');
},{}],7:[function(require,module,exports){
window.Roswell = {
PWM1: require('./melody.js'),
PWM2: require('./chords.js'),
TRIANGLE: require('./bass.js'),
NOISE: require('./drums.js'),
}
},{"./bass.js":8,"./chords.js":9,"./drums.js":10,"./melody.js":11}],8:[function(require,module,exports){
module.exports = `
t112.5
v20
l4
<<
/:
e16 r8 e16 r r r
e16 r8 e16 r r r
e16 r8 e16 r r e32 r32 e16 r8
e16 r8 e16 r r r
e16 r8 e16 r r r
e16 r8 e16 r r r
e16 r8 e16 r b8 a+8 f+8 d+8
e16 r8 e16 r r r
:/2
f16 r8 f16 r r r
f16 r8 f16 r r r
f16 r8 f16 r r r
e16 r8 e16 r r8 > d16 e16 c16 < b16 a16 g16
f16 r8 f16 r r r
f16 r8 f16 r r r
f16 r8 f16 r r r
e16 r8 e16 r r r
e16 r8 e16 r r r
e16 r8 e16 r r r
r8 > c8 < b8 g8 a8 f+8 d+8 f8
e16 r8 e16 r r r
e16 r8 e16 r r r
e16 r8 e16 r r e32 r32 e16 r8
e16 r8 e16 r r r
e16 r8 e16 r r r
e16 r8 e16 r r r
e16 r8 e16 r b8 a+8 f+8 d+8
e16 r8 e16 r r r
`;
},{}],9:[function(require,module,exports){
module.exports = `
t112.5
/:
v10
l32
o3
/: <b> e :/32
/: d g :/32
/: c+ f+ :/32
/: c f :/8
l8
b a+ f+ d+
r r r r
r r r r
:/
l4
o4
r r8 b16 > c16 d e
c < b > e2 <
r r8 g16 a16 b > c <
f+16 r8 f+16 r r r <<
r r8 e16 f16 g8 a16 b16 b8 > c16 d16
r > e f b >
c < b e g
b16 r8 b16 r r r
f+16 r8 f+16 r r r
b16 r8 b16 r r r
l8 r c < b g a f+ d+ f
v10
l32
o3
/: <b> e :/32
/: d g :/32
/: c+ f+ :/32
/: c f :/8
l8
b a+ f+ d+
r r r r
r r r r
`;
},{}],10:[function(require,module,exports){
module.exports = `
t112.5
v15
l20
l32
/:
o1 c r r r
o20 c r r r
o4 g r r r
r r r r
o20 c r c r
r r r r
o4 g r r r
o1 c r r r
:/35
`
;
},{}],11:[function(require,module,exports){
module.exports = `
t112.5
v25
/:
o4
l2
e b a+ > e <
b8 g16 e16 r4 r
r r
e b a+ > f+
e8 d16 < b16 r4
l8 b a+ f+ d+
l16 e r r e l4 r r r
:/
l4
r r8 e16 f16 g a
f e b2
r r8 b16 > c16 d e <
b16 r8 b16 r r r
r r8 e16 f16 g8 a16 b16 b8 > c16 d16
r e d g
e d < b > d
e16 r8 e16 r r r
< b16 r8 b16 r r r
> e16 r8 e16 r r r
l8 r c < b g a f+ d+ f
o4
l2
e b a+ > e <
b8 g16 e16 r4 r
r r
e b a+ > f+
e8 d16 < b16 r4
l8 b a+ f+ d+
l16 e r r e l4 r r r
`;
},{}],12:[function(require,module,exports){
window.SMB2 = {
PWM1: require('./top.js'),
PWM2: require('./bottom.js'),
TRIANGLE: require('./bass.js'),
NOISE: require('./drums.js'),
};
},{"./bass.js":13,"./bottom.js":14,"./drums.js":15,"./top.js":16}],13:[function(require,module,exports){
module.exports =
`
t200
v25
o3
l12
d d-6 c < b6 g f6 e d4 > d4 < d4 g4
l4
c g c g
< b > g < b > g
< b- > g < b- > g
< a > g < a > g
f > f < f+ > f+ <
g > g < a > a <
d f < g > g
c1
`
},{}],14:[function(require,module,exports){
module.exports =
`
t200
v25
o4
l12
b b-6 a f6 d c6 < b b4 > b4 < b2
o5
c6 < e g6 > c4 < e g6 > c < e- f+ b > e6 < b b2
b-6 d g6 b-4 d g6 b- e a > d e6 d2 e
a6 g a6 f4 a g6 f+
e6 e- e6 c4 < a b6 > d-
d6 c d6 < g4 > c < b6 g g1
`;
},{}],15:[function(require,module,exports){
module.exports =
`
t200
v10
r12 r4 r2 r1
l24
o5
/:
r4 c r r r r r
r4 c r r r r r
r4 c r r r r r
r4 c r c r c r
:/4
`
},{}],16:[function(require,module,exports){
module.exports =
`
t200
v25
o5
l12
g f+6 f d6 < b a6 a- g4 > g4 < g2
o5
g6 c e6 g4 c e6 g < b > e- g b6 a a2
g6 < b > d6 g4 < b > d6 g d- e g b6 a2 b >
c6 < b > c6 < a4 > c < b6 a
g6 f+ g6 e4 d- d6 e
f6 e f6 < b4 > e d6 c c1
`;
},{}]},{},[1]);