pixi-effects 0.14.0 → 0.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/README.md +13 -6
  3. package/ai/CHAT.md +103 -0
  4. package/ai/SKILL.md +2 -1
  5. package/ai/chat-template.html +113 -0
  6. package/ai/reference/cheatsheet.md +2 -1
  7. package/ai/reference/pitfalls.md +6 -0
  8. package/ai/reference/recipes.md +25 -0
  9. package/ai/template.html +5 -5
  10. package/dist/{Base-CQOlB2VH.d.ts → Base-DPEqyeB0.d.cts} +1 -1
  11. package/dist/{Base-C6ZnJ9pD.d.cts → Base-qvqNxvyt.d.ts} +1 -1
  12. package/dist/Composition-X2VZSVPD.js +5 -0
  13. package/dist/{Composition-HIISJAX2.js.map → Composition-X2VZSVPD.js.map} +1 -1
  14. package/dist/Composition-ZZGSMQ4E.cjs +14 -0
  15. package/dist/{Composition-7TEKHZNQ.cjs.map → Composition-ZZGSMQ4E.cjs.map} +1 -1
  16. package/dist/Controller.d.cts +2 -2
  17. package/dist/Controller.d.ts +2 -2
  18. package/dist/{Movie-BwT6XtGz.d.ts → Movie-BIGDIla0.d.ts} +1 -1
  19. package/dist/{Movie-qmgOU4in.d.cts → Movie-CJMfAizW.d.cts} +1 -1
  20. package/dist/Presenter.d.cts +2 -2
  21. package/dist/Presenter.d.ts +2 -2
  22. package/dist/{chunk-C6QHKYC5.js → chunk-7D7RAQWM.js} +29 -4
  23. package/dist/chunk-7D7RAQWM.js.map +1 -0
  24. package/dist/{chunk-3IPDNC3E.js → chunk-I2YXLHIU.js} +3 -3
  25. package/dist/{chunk-3IPDNC3E.js.map → chunk-I2YXLHIU.js.map} +1 -1
  26. package/dist/{chunk-6NWJLVCA.cjs → chunk-SPPNTV7E.cjs} +29 -4
  27. package/dist/chunk-SPPNTV7E.cjs.map +1 -0
  28. package/dist/{chunk-F7NCHS6Q.cjs → chunk-V54NBCWG.cjs} +26 -26
  29. package/dist/{chunk-F7NCHS6Q.cjs.map → chunk-V54NBCWG.cjs.map} +1 -1
  30. package/dist/index.cjs +40 -25
  31. package/dist/index.cjs.map +1 -1
  32. package/dist/index.d.cts +18 -5
  33. package/dist/index.d.ts +18 -5
  34. package/dist/index.js +18 -4
  35. package/dist/index.js.map +1 -1
  36. package/dist/loader.css +1 -1
  37. package/dist/music-3OF5C6X5.cjs +826 -0
  38. package/dist/music-3OF5C6X5.cjs.map +1 -0
  39. package/dist/music-4HDFULNR.js +809 -0
  40. package/dist/music-4HDFULNR.js.map +1 -0
  41. package/dist/three.cjs +5 -5
  42. package/dist/three.d.cts +2 -2
  43. package/dist/three.d.ts +2 -2
  44. package/dist/three.js +1 -1
  45. package/dist/{types-CBSiUKau.d.cts → types-C8XEUoqe.d.cts} +76 -2
  46. package/dist/{types-CBSiUKau.d.ts → types-C8XEUoqe.d.ts} +76 -2
  47. package/docs/api.md +10 -0
  48. package/docs/dsl.md +39 -0
  49. package/llms-full.txt +83 -2
  50. package/llms.txt +3 -2
  51. package/package.json +1 -1
  52. package/dist/Composition-7TEKHZNQ.cjs +0 -14
  53. package/dist/Composition-HIISJAX2.js +0 -5
  54. package/dist/chunk-6NWJLVCA.cjs.map +0 -1
  55. package/dist/chunk-C6QHKYC5.js.map +0 -1
@@ -0,0 +1,809 @@
1
+ import { warnUnknownOptions, suggestName } from './chunk-DKGG7WD4.js';
2
+
3
+ // src/audio/music/instruments.ts
4
+ var TAU = Math.PI * 2;
5
+ var SR = 44100;
6
+ function setSampleRate(sr) {
7
+ SR = sr;
8
+ }
9
+ var mtof = (m) => 440 * 2 ** ((m - 69) / 12);
10
+ var Biquad = class {
11
+ b0 = 1;
12
+ b1 = 0;
13
+ b2 = 0;
14
+ a1 = 0;
15
+ a2 = 0;
16
+ x1 = 0;
17
+ x2 = 0;
18
+ y1 = 0;
19
+ y2 = 0;
20
+ constructor(type, fc, q = 0.707) {
21
+ this.set(type, fc, q);
22
+ }
23
+ /** Change the cutoff without clearing the state (so it can move while a sound plays). */
24
+ set(type, fc, q = 0.707) {
25
+ const w = TAU * Math.min(fc, SR * 0.45) / SR, c = Math.cos(w), s = Math.sin(w), al = s / (2 * q);
26
+ const a0 = 1 + al;
27
+ let b0, b1, b2;
28
+ if (type === "lp") {
29
+ b0 = (1 - c) / 2;
30
+ b1 = 1 - c;
31
+ b2 = b0;
32
+ } else if (type === "hp") {
33
+ b0 = (1 + c) / 2;
34
+ b1 = -(1 + c);
35
+ b2 = b0;
36
+ } else {
37
+ b0 = al;
38
+ b1 = 0;
39
+ b2 = -al;
40
+ }
41
+ this.b0 = b0 / a0;
42
+ this.b1 = b1 / a0;
43
+ this.b2 = b2 / a0;
44
+ this.a1 = -2 * c / a0;
45
+ this.a2 = (1 - al) / a0;
46
+ }
47
+ run(x) {
48
+ const y = this.b0 * x + this.b1 * this.x1 + this.b2 * this.x2 - this.a1 * this.y1 - this.a2 * this.y2;
49
+ this.x2 = this.x1;
50
+ this.x1 = x;
51
+ this.y2 = this.y1;
52
+ this.y1 = y;
53
+ return y;
54
+ }
55
+ };
56
+ var polyblep = (t, dt) => t < dt ? (t /= dt, t + t - t * t - 1) : t > 1 - dt ? (t = (t - 1) / dt, t * t + t + t + 1) : 0;
57
+ var saw = (ph, dt) => 2 * ph - 1 - polyblep(ph, dt);
58
+ var adsr = (t, dur, a, d, s, r) => {
59
+ if (t < dur) return t < a ? t / a : t < a + d ? 1 - (1 - s) * ((t - a) / d) : s;
60
+ const base = dur < a ? dur / a : dur < a + d ? 1 - (1 - s) * ((dur - a) / d) : s;
61
+ return Math.max(0, base * (1 - (t - dur) / r));
62
+ };
63
+ function addTo(out, start, i, l, r) {
64
+ const k = start + i;
65
+ if (k >= 0 && k < out.L.length) {
66
+ out.L[k] += l;
67
+ out.R[k] += r;
68
+ }
69
+ }
70
+ var INSTRUMENTS = ["keys", "pluck", "pad", "bass", "sub", "lead", "bell", "musicbox"];
71
+ var VOICES = {
72
+ // electric piano: two FM operators (tine + bell), a little stereo chorus
73
+ keys(m, dur, vel, out, start, rnd, o) {
74
+ const f = mtof(m), rel = o.release ?? 0.5, total = dur + rel + 1.2;
75
+ const n = Math.floor(Math.min(total, 6) * SR), idx = 1.1 + 2.2 * vel, det = 1 + (rnd() - 0.5) * 2e-3;
76
+ for (let i = 0; i < n; i++) {
77
+ const t = i / SR;
78
+ const decay = Math.exp(-t * (1.1 + f / 1500));
79
+ const mod = Math.sin(TAU * f * 14 * t) * idx * 0.12 * Math.exp(-t * 18) + Math.sin(TAU * f * t) * idx * Math.exp(-t * 3.2);
80
+ const body = Math.sin(TAU * f * t + mod) * decay;
81
+ const body2 = Math.sin(TAU * f * det * t + mod * 0.9) * decay;
82
+ const env = t < dur ? 1 : Math.max(0, 1 - (t - dur) / rel);
83
+ const a = Math.min(1, t / 4e-3) * env * 0.5 * vel;
84
+ addTo(out, start, i, a * (body * 0.7 + body2 * 0.3), a * (body * 0.3 + body2 * 0.7));
85
+ }
86
+ },
87
+ // plucked string (Karplus–Strong with a darker loss filter): guitar / harp / koto
88
+ pluck(m, dur, vel, out, start, rnd, o) {
89
+ const f = mtof(m), len = Math.max(2, Math.round(SR / f)), buf = new Float32Array(len);
90
+ const lp = new Biquad("lp", 2500 + 3500 * vel, 0.6);
91
+ for (let i = 0; i < len; i++) buf[i] = lp.run(rnd() * 2 - 1);
92
+ const rel = o.release ?? 0.25, total = Math.min(dur + rel + 0.4, 5), n = Math.floor(total * SR), loss = 0.9965 - 0.5 / (f + 100);
93
+ let p = 0, prev = 0;
94
+ const pan = (rnd() - 0.5) * 0.3;
95
+ for (let i = 0; i < n; i++) {
96
+ const cur = buf[p], nxt = buf[(p + 1) % len];
97
+ buf[p] = loss * 0.5 * (cur + nxt);
98
+ p = (p + 1) % len;
99
+ const t = i / SR, env = t < dur ? 1 : Math.max(0, 1 - (t - dur) / rel);
100
+ const y = (cur - prev * 0.2) * env * 0.55 * vel;
101
+ prev = cur;
102
+ addTo(out, start, i, y * (1 - pan), y * (1 + pan));
103
+ }
104
+ },
105
+ // warm pad: five detuned band-limited saws through a slow low-pass
106
+ pad(m, dur, vel, out, start, rnd, o) {
107
+ const f = mtof(m), A = o.attack ?? 0.7, R = o.release ?? 1.4, n = Math.floor((dur + R) * SR);
108
+ const voices = [-0.14, -0.07, 0, 0.07, 0.14].map((c, k) => ({ ph: rnd(), f: f * 2 ** (c / 12 * 0.6), pan: (k - 2) / 2.5 }));
109
+ const cut = Math.min(1800, 500 + f * 1.5);
110
+ const lp = new Biquad("lp", cut, 0.6), lp2 = new Biquad("lp", cut, 0.6);
111
+ for (let i = 0; i < n; i++) {
112
+ const t = i / SR;
113
+ let l = 0, r = 0;
114
+ for (const v of voices) {
115
+ const dt = v.f / SR;
116
+ v.ph += dt;
117
+ if (v.ph >= 1) v.ph -= 1;
118
+ const s = saw(v.ph, dt);
119
+ l += s * (1 - v.pan) * 0.5;
120
+ r += s * (1 + v.pan) * 0.5;
121
+ }
122
+ const env = t < dur ? Math.min(1, t / A) : Math.max(0, Math.min(1, dur / A) * (1 - (t - dur) / R));
123
+ const g = env * 0.11 * vel;
124
+ addTo(out, start, i, lp.run(l) * g, lp2.run(r) * g);
125
+ }
126
+ },
127
+ // synth bass: saw + sine sub, filter envelope
128
+ bass(m, dur, vel, out, start, _rnd, o) {
129
+ const f = mtof(m), rel = o.release ?? 0.12, n = Math.floor((dur + rel) * SR);
130
+ let ph = 0, ph2 = 0;
131
+ const lp = new Biquad("lp", 400, 1.1);
132
+ for (let i = 0; i < n; i++) {
133
+ const t = i / SR, dt = f / SR;
134
+ ph = (ph + dt) % 1;
135
+ ph2 = (ph2 + dt) % 1;
136
+ if (i % 64 === 0) lp.set("lp", Math.min(160 + 900 * Math.exp(-t * 7) * vel, 4e3), 1.1);
137
+ const s = lp.run(saw(ph, dt)) * 0.55 + Math.sin(TAU * ph2) * 0.55;
138
+ const env = t < dur ? Math.min(1, t / 6e-3) * (0.75 + 0.25 * Math.exp(-t * 4)) : Math.max(0, 1 - (t - dur) / rel) * 0.75;
139
+ const y = s * env * 0.5 * vel;
140
+ addTo(out, start, i, y, y);
141
+ }
142
+ },
143
+ // a pure sine bass: a soft heartbeat or sub (no filter sweep, hardly any upper harmonics)
144
+ sub(m, dur, vel, out, start, _rnd, o) {
145
+ const f = mtof(m), rel = o.release ?? 0.2, n = Math.floor((dur + rel) * SR);
146
+ let ph = 0;
147
+ for (let i = 0; i < n; i++) {
148
+ const t = i / SR;
149
+ ph += TAU * f / SR;
150
+ const env = t < dur ? Math.min(1, t / (o.attack ?? 0.012)) * (0.8 + 0.2 * Math.exp(-t * 5)) : Math.max(0, 1 - (t - dur) / rel) * 0.8;
151
+ const y = (Math.sin(ph) + 0.12 * Math.sin(2 * ph)) * env * 0.6 * vel;
152
+ addTo(out, start, i, y, y);
153
+ }
154
+ },
155
+ // lead: soft saw / triangle with a delayed vibrato
156
+ lead(m, dur, vel, out, start, rnd, o) {
157
+ const f = mtof(m), rel = o.release ?? 0.18, A = o.attack ?? 0.02, n = Math.floor((dur + rel) * SR);
158
+ let ph = rnd(), ph2 = rnd();
159
+ const lp = new Biquad("lp", 2600 + 1800 * vel, 0.8);
160
+ for (let i = 0; i < n; i++) {
161
+ const t = i / SR, vib = 1 + 35e-4 * Math.sin(TAU * 5.3 * t) * Math.min(1, Math.max(0, (t - 0.18) / 0.3));
162
+ const dt = f * vib / SR;
163
+ ph = (ph + dt) % 1;
164
+ ph2 = (ph2 + dt * 1.003) % 1;
165
+ const tri = 4 * Math.abs(ph - 0.5) - 1;
166
+ const s = lp.run(saw(ph2, dt) * 0.35 + tri * 0.65);
167
+ const y = s * adsr(t, dur, A, 0.15, 0.7, rel) * 0.28 * vel;
168
+ addTo(out, start, i, y * 0.9, y * 1.1);
169
+ }
170
+ },
171
+ // bell / glockenspiel: inharmonic FM; `ring` is how many seconds it keeps sounding
172
+ bell(m, dur, vel, out, start, rnd, o) {
173
+ const f = mtof(m), ring = o.ring ?? 2.5, n = Math.floor(Math.min(dur + ring, 6) * SR), pan = (rnd() - 0.5) * 0.6;
174
+ const k = 1.5 * (2.5 / ring);
175
+ for (let i = 0; i < n; i++) {
176
+ const t = i / SR;
177
+ const mod = Math.sin(TAU * f * 3.5 * t) * 1.6 * Math.exp(-t * 5);
178
+ const s = Math.sin(TAU * f * t + mod) * Math.exp(-t * k) + Math.sin(TAU * f * 2.76 * t) * 0.25 * Math.exp(-t * 4);
179
+ const y = s * Math.min(1, t / 2e-3) * 0.3 * vel;
180
+ addTo(out, start, i, y * (1 - pan), y * (1 + pan));
181
+ }
182
+ },
183
+ // music box: a bright tine with a strong upper partial and a short, dry ring
184
+ musicbox(m, dur, vel, out, start, rnd, o) {
185
+ const f = mtof(m), ring = o.ring ?? 1.3, n = Math.floor(Math.min(dur + ring, 4) * SR), pan = (rnd() - 0.5) * 0.4;
186
+ for (let i = 0; i < n; i++) {
187
+ const t = i / SR;
188
+ const s = Math.sin(TAU * f * t) * Math.exp(-t * (3.2 / ring * 1.3)) + Math.sin(TAU * f * 4 * t) * 0.22 * Math.exp(-t * (9 / ring)) + Math.sin(TAU * f * 6.8 * t) * 0.08 * Math.exp(-t * 18);
189
+ const y = s * Math.min(1, t / 15e-4) * 0.34 * vel;
190
+ addTo(out, start, i, y * (1 - pan), y * (1 + pan));
191
+ }
192
+ }
193
+ };
194
+ var DRUMS = ["kick", "snare", "hat", "openhat", "clap", "rim", "tom", "crash", "shaker", "sleigh"];
195
+ function hitDrum(kind, vel, out, start, rnd) {
196
+ const mono = (n, f) => {
197
+ for (let i = 0; i < n; i++) {
198
+ const [l, r] = f(i / SR);
199
+ addTo(out, start, i, l, r);
200
+ }
201
+ };
202
+ const len = (s) => Math.floor(s * SR);
203
+ if (kind === "kick") {
204
+ let ph = 0;
205
+ mono(len(0.5), (t) => {
206
+ ph += TAU * (45 + 110 * Math.exp(-t * 28)) / SR;
207
+ const o = (Math.sin(ph) * Math.exp(-t * 7.5) + (t < 4e-3 ? (rnd() - 0.5) * 0.5 : 0)) * 0.95 * vel;
208
+ return [o, o];
209
+ });
210
+ } else if (kind === "snare") {
211
+ const bp = new Biquad("bp", 1900, 0.9), hp = new Biquad("hp", 700, 0.7);
212
+ let ph = 0;
213
+ mono(len(0.4), (t) => {
214
+ ph += TAU * (185 - 40 * t) / SR;
215
+ const nz = hp.run(bp.run(rnd() * 2 - 1)) * 2.2;
216
+ const o = (nz * Math.exp(-t * 17) + Math.sin(ph) * Math.exp(-t * 26) * 0.6) * 0.6 * vel;
217
+ return [o * 0.95, o * 1.05];
218
+ });
219
+ } else if (kind === "clap") {
220
+ const bp = new Biquad("bp", 1500, 1.2);
221
+ mono(len(0.35), (t) => {
222
+ const burst = t < 0.033 ? Math.exp(-(t * 1e3 % 11) * 0.5) : Math.exp(-(t - 0.033) * 22);
223
+ const o = bp.run(rnd() * 2 - 1) * 2.4 * burst * 0.5 * vel;
224
+ return [o, o * 0.9];
225
+ });
226
+ } else if (kind === "hat" || kind === "openhat") {
227
+ const hp = new Biquad("hp", 7500, 0.8), dec = kind === "hat" ? 55 : 9;
228
+ mono(len(kind === "hat" ? 0.12 : 0.6), (t) => {
229
+ const o = hp.run(rnd() * 2 - 1) * Math.exp(-t * dec) * 0.35 * vel;
230
+ return [o * 0.8, o * 1.2];
231
+ });
232
+ } else if (kind === "rim") {
233
+ let ph = 0;
234
+ const bp = new Biquad("bp", 3200, 4);
235
+ mono(len(0.1), (t) => {
236
+ ph += TAU * 1750 / SR;
237
+ const o = (Math.sin(ph) * 0.5 + bp.run(rnd() * 2 - 1)) * Math.exp(-t * 70) * 0.5 * vel;
238
+ return [o, o];
239
+ });
240
+ } else if (kind === "tom") {
241
+ let ph = 0;
242
+ mono(len(0.5), (t) => {
243
+ ph += TAU * (95 + 70 * Math.exp(-t * 15)) / SR;
244
+ const o = Math.sin(ph) * Math.exp(-t * 7) * 0.7 * vel;
245
+ return [o, o];
246
+ });
247
+ } else if (kind === "crash") {
248
+ const hp = new Biquad("hp", 5200, 0.7), bp = new Biquad("bp", 9e3, 0.6);
249
+ mono(len(1.8), (t) => {
250
+ const nz = rnd() * 2 - 1;
251
+ const o = (hp.run(nz) * 0.7 + bp.run(nz) * 0.5) * (0.55 * Math.exp(-t * 2.6) + 0.45 * Math.exp(-t * 11)) * 0.5 * vel;
252
+ return [o * 0.9, o * 1.1];
253
+ });
254
+ } else if (kind === "shaker") {
255
+ const bp = new Biquad("bp", 6500, 1.4);
256
+ mono(len(0.16), (t) => {
257
+ const env = (t < 0.018 ? t / 0.018 : 1) * Math.exp(-t * 28);
258
+ const o = bp.run(rnd() * 2 - 1) * env * 1.4 * 0.3 * vel;
259
+ return [o * 0.85, o * 1.15];
260
+ });
261
+ } else {
262
+ const bp = new Biquad("bp", 7800, 1);
263
+ const partials = [4200, 5630, 6900, 8350];
264
+ mono(len(0.5), (t) => {
265
+ let s = 0;
266
+ for (let k = 0; k < partials.length; k++) s += Math.sin(TAU * partials[k] * t * (1 + k * 7e-4)) * (0.5 + 0.5 * Math.sin(TAU * (19 + k * 3.1) * t + k)) * Math.exp(-t * (7 + k * 2));
267
+ const o = (s * 0.11 + bp.run(rnd() * 2 - 1) * Math.exp(-t * 16) * 0.5) * Math.min(1, t / 3e-3) * vel * 0.8;
268
+ return [o * 0.85, o * 1.15];
269
+ });
270
+ }
271
+ }
272
+ function reverb(send, out, wet, size = 0.8) {
273
+ const L = out.L, R = out.R, sL = send.L, sR = send.R;
274
+ const scale = SR / 44100;
275
+ const comb = (len) => ({ b: new Float32Array(Math.max(8, Math.round(len * scale))), i: 0, fb: size, d: 0, damp: 0.35 });
276
+ const mk = (off) => ({
277
+ c: [1116, 1188, 1277, 1356, 1422, 1491].map((l) => comb(l + off)),
278
+ a: [556, 441, 341].map((l) => ({ b: new Float32Array(Math.max(8, Math.round((l + off) * scale))), i: 0 }))
279
+ });
280
+ const run = (x, ch) => {
281
+ let y = 0;
282
+ for (const c of ch.c) {
283
+ const o = c.b[c.i];
284
+ c.d = o * (1 - c.damp) + c.d * c.damp;
285
+ c.b[c.i] = x * 0.03 + c.d * c.fb;
286
+ c.i = (c.i + 1) % c.b.length;
287
+ y += o;
288
+ }
289
+ for (const a of ch.a) {
290
+ const o = a.b[a.i], inp = y;
291
+ a.b[a.i] = inp + o * 0.5;
292
+ a.i = (a.i + 1) % a.b.length;
293
+ y = o - inp;
294
+ }
295
+ return y;
296
+ };
297
+ const chL = mk(0), chR = mk(23);
298
+ for (let i = 0; i < L.length; i++) {
299
+ const m = (sL[i] + sR[i]) * 0.5;
300
+ L[i] += run(m, chL) * wet;
301
+ R[i] += run(m, chR) * wet;
302
+ }
303
+ }
304
+
305
+ // src/audio/music/notation.ts
306
+ var SEMI = { c: 0, d: 2, e: 4, f: 5, g: 7, a: 9, b: 11 };
307
+ var accidental = (s) => s === "#" ? 1 : s === "b" ? -1 : 0;
308
+ var CHORD_KINDS = {
309
+ "": [0, 4, 7],
310
+ m: [0, 3, 7],
311
+ 5: [0, 7],
312
+ aug: [0, 4, 8],
313
+ dim: [0, 3, 6],
314
+ sus2: [0, 2, 7],
315
+ sus4: [0, 5, 7],
316
+ 6: [0, 4, 7, 9],
317
+ m6: [0, 3, 7, 9],
318
+ add9: [0, 4, 7, 14],
319
+ madd9: [0, 3, 7, 14],
320
+ add11: [0, 4, 7, 17],
321
+ 7: [0, 4, 7, 10],
322
+ maj7: [0, 4, 7, 11],
323
+ m7: [0, 3, 7, 10],
324
+ mMaj7: [0, 3, 7, 11],
325
+ dim7: [0, 3, 6, 9],
326
+ m7b5: [0, 3, 6, 10],
327
+ "7sus4": [0, 5, 7, 10],
328
+ "7b9": [0, 4, 7, 10, 13],
329
+ "7#9": [0, 4, 7, 10, 15],
330
+ 9: [0, 4, 7, 10, 14],
331
+ maj9: [0, 4, 7, 11, 14],
332
+ m9: [0, 3, 7, 10, 14],
333
+ 11: [0, 4, 7, 10, 14, 17],
334
+ m11: [0, 3, 7, 10, 14, 17],
335
+ 13: [0, 4, 7, 10, 14, 21],
336
+ maj13: [0, 4, 7, 11, 14, 21],
337
+ m13: [0, 3, 7, 10, 14, 21],
338
+ "maj7#11": [0, 4, 7, 11, 18]
339
+ };
340
+ var NOTE_FORMS = "a note like c4, f#3, Bb2; a chord like Am7, C@4, Am7/e; [c4 e4 g4]; _ for a rest; ~ to hold";
341
+ function noteToMidi(name) {
342
+ const m = /^([a-gA-G])([#b]?)(-?\d)$/.exec(name);
343
+ if (!m) return null;
344
+ return 12 * (Number(m[3]) + 1) + SEMI[m[1].toLowerCase()] + accidental(m[2]);
345
+ }
346
+ function chordToMidi(sym) {
347
+ const m = /^([A-G])([#b]?)([^@/\s]*)(?:@(\d))?(?:\/([a-gA-G][#b]?))?$/.exec(sym);
348
+ if (!m) return null;
349
+ const kind = CHORD_KINDS[m[3]];
350
+ if (!kind) return null;
351
+ const root = SEMI[m[1].toLowerCase()] + accidental(m[2]);
352
+ const oct = m[4] !== void 0 ? Number(m[4]) : 3;
353
+ const notes = kind.map((i) => 12 * (oct + 1) + root + i);
354
+ if (m[5]) notes.unshift(12 * oct + SEMI[m[5][0].toLowerCase()] + accidental(m[5][1] ?? ""));
355
+ return notes;
356
+ }
357
+ function parseNotes(str, step = 1) {
358
+ const events = [];
359
+ let t = 0;
360
+ for (const raw of String(str).replace(/\|/g, " ").match(/\[[^\]]*\](?::[\d.]+)?[!,]?|\S+/g) ?? []) {
361
+ let tok = raw, vel = 0.8;
362
+ const mark = (c) => {
363
+ vel = c === "!" ? 1 : 0.55;
364
+ };
365
+ if (/[!,]$/.test(tok)) {
366
+ mark(tok.slice(-1));
367
+ tok = tok.slice(0, -1);
368
+ }
369
+ let dur = step;
370
+ const dm = /:([\d.]+)$/.exec(tok);
371
+ if (dm) {
372
+ dur = Number(dm[1]);
373
+ tok = tok.slice(0, dm.index);
374
+ }
375
+ if (/[!,]$/.test(tok)) {
376
+ mark(tok.slice(-1));
377
+ tok = tok.slice(0, -1);
378
+ }
379
+ if (!(dur > 0) || !Number.isFinite(dur)) throw new Error(`"${raw}" has a length of ${dm?.[1]} beats; a length must be a positive number of beats (c4:2)`);
380
+ if (tok === "_") {
381
+ t += dur;
382
+ continue;
383
+ }
384
+ if (tok === "~") {
385
+ if (events.length) events[events.length - 1].dur += dur;
386
+ t += dur;
387
+ continue;
388
+ }
389
+ let midi;
390
+ if (tok.startsWith("[")) midi = tok.slice(1, -1).trim().split(/\s+/).map(noteToMidi);
391
+ else if (noteToMidi(tok) !== null) midi = [noteToMidi(tok)];
392
+ else midi = chordToMidi(tok);
393
+ if (!midi || midi.length === 0 || midi.some((x) => x === null)) throw new Error(`cannot read "${raw}" (${NOTE_FORMS})`);
394
+ events.push({ t, dur, midi, vel });
395
+ t += dur;
396
+ }
397
+ return { events, length: t };
398
+ }
399
+ function parseDrumGrid(grid) {
400
+ const hits = [];
401
+ let i = 0;
402
+ for (const ch of String(grid).replace(/[\s|]/g, "")) {
403
+ if (ch === "x" || ch === "X") hits.push({ i, vel: 1 });
404
+ else if (ch === "o" || ch === "O") hits.push({ i, vel: 0.5 });
405
+ else if (ch !== "." && ch !== "-" && ch !== "_") throw new Error(`"${ch}" in the drum pattern "${grid}": use x (hit), o (soft hit), . (nothing)`);
406
+ i++;
407
+ }
408
+ return { hits, steps: i };
409
+ }
410
+ var TempoMap = class _TempoMap {
411
+ points;
412
+ secAt = [0];
413
+ constructor(bpm) {
414
+ this.points = typeof bpm === "number" ? [[0, bpm]] : [...bpm].sort((a, b) => a[0] - b[0]);
415
+ if (this.points[0][0] > 0) this.points.unshift([0, this.points[0][1]]);
416
+ for (let i = 1; i < this.points.length; i++) {
417
+ const [b0, t0] = this.points[i - 1], [b1, t1] = this.points[i];
418
+ this.secAt.push(this.secAt[i - 1] + _TempoMap.span(b1 - b0, t0, t1));
419
+ }
420
+ }
421
+ /** Seconds taken by `db` beats while the tempo goes from `t0` to `t1` bpm. */
422
+ static span(db, t0, t1) {
423
+ return Math.abs(t1 - t0) < 1e-9 ? 60 * db / t0 : 60 * db * Math.log(t1 / t0) / (t1 - t0);
424
+ }
425
+ seconds(beat) {
426
+ if (beat <= 0) return 60 * beat / this.points[0][1];
427
+ let i = this.points.length - 1;
428
+ while (i > 0 && this.points[i][0] > beat) i--;
429
+ const [b0, t0] = this.points[i];
430
+ const next = this.points[i + 1];
431
+ if (!next) return this.secAt[i] + 60 * (beat - b0) / t0;
432
+ const t = t0 + (next[1] - t0) * (beat - b0) / (next[0] - b0);
433
+ return this.secAt[i] + _TempoMap.span(beat - b0, t0, t);
434
+ }
435
+ /** The tempo at a beat. */
436
+ bpmAt(beat) {
437
+ if (beat <= this.points[0][0]) return this.points[0][1];
438
+ for (let i = 1; i < this.points.length; i++) {
439
+ const [b0, t0] = this.points[i - 1], [b1, t1] = this.points[i];
440
+ if (beat < b1) return t0 + (t1 - t0) * (beat - b0) / (b1 - b0);
441
+ }
442
+ return this.points[this.points.length - 1][1];
443
+ }
444
+ };
445
+
446
+ // src/audio/music/resolve.ts
447
+ var MAX_TRACKS = 16;
448
+ var MAX_SECONDS = 180;
449
+ var MAX_NOTES = 2e4;
450
+ var DEFAULT_TAIL = 2.5;
451
+ var OPTION_KEYS = ["bpm", "tracks", "drums", "grid", "swing", "reverb", "humanize", "drumVol", "transpose", "tail", "seed"];
452
+ var TRACK_KEYS = ["inst", "notes", "vol", "pan", "step", "strum", "legato", "tone", "reverb", "attack", "release", "ring", "transpose"];
453
+ var LAYER_KEYS = ["duration", "length", "volume", "at", "loop"];
454
+ var INSTRUMENT_ALIASES = {
455
+ piano: "keys",
456
+ ep: "keys",
457
+ rhodes: "keys",
458
+ epiano: "keys",
459
+ electricpiano: "keys",
460
+ keyboard: "keys",
461
+ organ: "pad",
462
+ guitar: "pluck",
463
+ harp: "pluck",
464
+ koto: "pluck",
465
+ strings: "pad",
466
+ synth: "lead",
467
+ melody: "lead",
468
+ flute: "lead",
469
+ glockenspiel: "bell",
470
+ glock: "bell",
471
+ chime: "bell",
472
+ vibes: "bell",
473
+ "music-box": "musicbox",
474
+ music_box: "musicbox",
475
+ musicbox: "musicbox",
476
+ sinebass: "sub",
477
+ "808": "sub",
478
+ bassline: "bass"
479
+ };
480
+ var DRUM_ALIASES = {
481
+ bd: "kick",
482
+ bassdrum: "kick",
483
+ sd: "snare",
484
+ hihat: "hat",
485
+ hh: "hat",
486
+ closedhat: "hat",
487
+ oh: "openhat",
488
+ cymbal: "crash",
489
+ tambourine: "shaker",
490
+ sleighbells: "sleigh",
491
+ jingle: "sleigh",
492
+ bells: "sleigh"
493
+ };
494
+ var defaultWarn = (m) => console.warn(m);
495
+ var clamp = (x, lo, hi) => Math.min(hi, Math.max(lo, x));
496
+ var finite = (x) => typeof x === "number" && Number.isFinite(x);
497
+ function resolveMusic(music, who, warn = defaultWarn) {
498
+ if (!music || typeof music !== "object" || Array.isArray(music)) {
499
+ warn(`pixi-effects: ${who}: music must be an object like { bpm: 96, tracks: [{ inst: 'keys', notes: 'Cmaj7:4 Am7:4' }], drums: { kick: 'x...x...' } } (got ${JSON.stringify(music)}). The layer is silent.`);
500
+ return null;
501
+ }
502
+ const o = music;
503
+ const rest = {};
504
+ for (const [k, v] of Object.entries(o)) {
505
+ if (LAYER_KEYS.includes(k)) warn(`pixi-effects: ${who}: "${k}" goes on the audio layer, not inside music${k === "duration" || k === "length" ? " (the music lasts as long as its notes; a shorter layer duration cuts it)" : ""}`);
506
+ else rest[k] = v;
507
+ }
508
+ warnUnknownOptions(`${who} music`, rest, OPTION_KEYS);
509
+ const num = (key, lo, hi, fallback) => {
510
+ const v = o[key];
511
+ if (v === void 0) return fallback;
512
+ if (!finite(v)) {
513
+ warn(`pixi-effects: ${who}: music.${key} must be a number (got ${JSON.stringify(v)}); using ${fallback}`);
514
+ return fallback;
515
+ }
516
+ if (v < lo || v > hi) {
517
+ warn(`pixi-effects: ${who}: music.${key} ${v} is outside ${lo}\u2013${hi}; using ${clamp(v, lo, hi)}`);
518
+ return clamp(v, lo, hi);
519
+ }
520
+ return v;
521
+ };
522
+ let tempo = null;
523
+ if (finite(o.bpm)) tempo = [[0, clamp(o.bpm, 20, 400)]];
524
+ else if (Array.isArray(o.bpm) && o.bpm.length > 0 && o.bpm.every((p) => Array.isArray(p) && finite(p[0]) && finite(p[1]) && p[1] > 0)) {
525
+ tempo = o.bpm.map(([b, t]) => [Math.max(0, b), clamp(t, 20, 400)]).sort((a, b) => a[0] - b[0]);
526
+ }
527
+ if (!tempo) {
528
+ warn(`pixi-effects: ${who}: music.bpm is required: beats per minute (96), or [beat, bpm] points for a tempo change ([[0, 96], [28, 96], [32, 60]]) (got ${JSON.stringify(o.bpm)}). The layer is silent.`);
529
+ return null;
530
+ }
531
+ if (finite(o.bpm) && (o.bpm < 20 || o.bpm > 400)) warn(`pixi-effects: ${who}: music.bpm ${o.bpm} is outside 20\u2013400; using ${tempo[0][1]}`);
532
+ const swing = num("swing", 0, 0.4, 0);
533
+ const reverbAmount = num("reverb", 0, 0.6, 0.22);
534
+ const humanize = num("humanize", 0, 0.06, 0.012);
535
+ const drumVol = num("drumVol", 0, 1, 0.8);
536
+ const grid = Math.round(num("grid", 1, 12, 4));
537
+ const tail = num("tail", 0, 10, DEFAULT_TAIL);
538
+ const transpose = num("transpose", -36, 36, 0);
539
+ const seed = Math.trunc(num("seed", -1e9, 1e9, 1));
540
+ const rawTracks = o.tracks === void 0 ? [] : Array.isArray(o.tracks) ? o.tracks : [];
541
+ if (o.tracks !== void 0 && !Array.isArray(o.tracks)) warn(`pixi-effects: ${who}: music.tracks must be a list of { inst, notes } objects (got ${typeof o.tracks})`);
542
+ if (rawTracks.length > MAX_TRACKS) warn(`pixi-effects: ${who}: music has ${rawTracks.length} tracks; only the first ${MAX_TRACKS} play`);
543
+ const tracks = [];
544
+ let notes = 0;
545
+ rawTracks.slice(0, MAX_TRACKS).forEach((raw, i) => {
546
+ const where = `${who} music.tracks[${i}]`;
547
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) {
548
+ warn(`pixi-effects: ${where} must be an object like { inst: 'keys', notes: 'c4 e4 g4' }. The track is skipped.`);
549
+ return;
550
+ }
551
+ const t = raw;
552
+ warnUnknownOptions(where, t, TRACK_KEYS);
553
+ const name = String(t.inst);
554
+ let inst = INSTRUMENTS.includes(name) ? name : null;
555
+ if (!inst) {
556
+ const guess = INSTRUMENT_ALIASES[name.toLowerCase().replace(/\s+/g, "")] ?? suggestName(name, INSTRUMENTS);
557
+ warn(`pixi-effects: ${where}: unknown instrument "${name}"${guess ? ` \u2014 did you mean "${guess}"?` : ""} (instruments: ${INSTRUMENTS.join(", ")}). The track is skipped.`);
558
+ return;
559
+ }
560
+ if (typeof t.notes !== "string") {
561
+ warn(`pixi-effects: ${where} (${inst}): notes must be a string like 'c4 e4 g4:2 _ Am7:4' (got ${JSON.stringify(t.notes)}). The track is skipped.`);
562
+ return;
563
+ }
564
+ const knob = (key, lo, hi, fallback) => {
565
+ const v = t[key];
566
+ if (v === void 0) return fallback;
567
+ if (!finite(v)) {
568
+ warn(`pixi-effects: ${where}: ${key} must be a number (got ${JSON.stringify(v)}); using ${fallback}`);
569
+ return fallback;
570
+ }
571
+ if (v < lo || v > hi) {
572
+ warn(`pixi-effects: ${where}: ${key} ${v} is outside ${lo}\u2013${hi}; using ${clamp(v, lo, hi)}`);
573
+ return clamp(v, lo, hi);
574
+ }
575
+ return v;
576
+ };
577
+ let parsed;
578
+ try {
579
+ parsed = parseNotes(t.notes, knob("step", 0.0625, 16, 1));
580
+ } catch (e) {
581
+ warn(`pixi-effects: ${where} (${inst}): ${e.message}. The track is skipped.`);
582
+ return;
583
+ }
584
+ notes += parsed.events.length;
585
+ let vol = 0.8;
586
+ if (t.vol !== void 0) {
587
+ if (finite(t.vol)) vol = clamp(t.vol, 0, 1.5);
588
+ else if (Array.isArray(t.vol) && t.vol.length > 0 && t.vol.every((p) => Array.isArray(p) && finite(p[0]) && finite(p[1]))) {
589
+ vol = t.vol.map(([b, v]) => [b, clamp(v, 0, 1.5)]).sort((a, b) => a[0] - b[0]);
590
+ } else warn(`pixi-effects: ${where}: vol must be a number (0.8) or [beat, level] points ([[0, 0], [8, 0.8]]) (got ${JSON.stringify(t.vol)}); using 0.8`);
591
+ }
592
+ const voice = {};
593
+ for (const k of ["attack", "release", "ring"]) if (t[k] !== void 0) voice[k] = knob(k, k === "ring" ? 0.1 : 1e-3, k === "ring" ? 6 : 8, 0.5);
594
+ tracks.push({
595
+ inst,
596
+ events: parsed.events,
597
+ length: parsed.length,
598
+ vol,
599
+ pan: knob("pan", -1, 1, 0),
600
+ strum: knob("strum", 0, 0.2, 0),
601
+ legato: knob("legato", 0.1, 1, 0.96),
602
+ tone: knob("tone", 0, 1, 1),
603
+ reverb: knob("reverb", 0, 1, 1),
604
+ transpose: transpose + knob("transpose", -36, 36, 0),
605
+ voice
606
+ });
607
+ });
608
+ if (notes > MAX_NOTES) {
609
+ warn(`pixi-effects: ${who}: music has ${notes} notes; the limit is ${MAX_NOTES}. The layer is silent.`);
610
+ return null;
611
+ }
612
+ const sections = [];
613
+ const rawDrums = o.drums === void 0 ? [] : Array.isArray(o.drums) ? o.drums : [o.drums];
614
+ rawDrums.forEach((raw, i) => {
615
+ const where = `${who} music.drums${Array.isArray(o.drums) ? `[${i}]` : ""}`;
616
+ if (!raw || typeof raw !== "object") {
617
+ warn(`pixi-effects: ${where} must be an object like { kick: 'x...x...', snare: '....x...' } (steps: x hit, o soft hit, . nothing). It is skipped.`);
618
+ return;
619
+ }
620
+ const d = raw;
621
+ const drums = [];
622
+ let steps = 0;
623
+ for (const [key, pattern] of Object.entries(d)) {
624
+ if (key === "from" || key === "to") continue;
625
+ const kind = DRUMS.includes(key) ? key : null;
626
+ if (!kind) {
627
+ const guess = DRUM_ALIASES[key.toLowerCase()] ?? suggestName(key, DRUMS);
628
+ warn(`pixi-effects: ${where}: unknown drum "${key}"${guess ? ` \u2014 did you mean "${guess}"?` : ""} (drums: ${DRUMS.join(", ")}, and from / to). It is skipped.`);
629
+ continue;
630
+ }
631
+ if (typeof pattern !== "string") {
632
+ warn(`pixi-effects: ${where}.${key} must be a string of steps like 'x...x...' (got ${JSON.stringify(pattern)}). It is skipped.`);
633
+ continue;
634
+ }
635
+ try {
636
+ const g = parseDrumGrid(pattern);
637
+ drums.push({ kind, hits: g.hits });
638
+ steps = Math.max(steps, g.steps);
639
+ } catch (e) {
640
+ warn(`pixi-effects: ${where}.${key}: ${e.message}. It is skipped.`);
641
+ }
642
+ }
643
+ if (drums.length === 0 || steps === 0) return;
644
+ const from = finite(d.from) ? Math.max(0, d.from) : 0, to = finite(d.to) ? d.to : Infinity;
645
+ if (d.from !== void 0 && !finite(d.from)) warn(`pixi-effects: ${where}.from must be a beat number (got ${JSON.stringify(d.from)}); using 0`);
646
+ sections.push({ from, to, repeat: steps / grid, drums });
647
+ });
648
+ const beats = Math.max(0, ...tracks.map((t) => t.length), ...sections.map((s) => Number.isFinite(s.to) ? s.to : 0));
649
+ const map = new TempoMap(tempo);
650
+ const seconds = map.seconds(beats);
651
+ if (beats === 0) {
652
+ warn(`pixi-effects: ${who}: music has no notes${sections.length ? " (drums alone do not set the length: add a track, or a rest such as notes: '_:16')" : ""}. The layer is silent.`);
653
+ return null;
654
+ }
655
+ if (seconds > MAX_SECONDS) {
656
+ warn(`pixi-effects: ${who}: the music lasts ${Math.round(seconds)} s; the limit is ${MAX_SECONDS} s. The layer is silent.`);
657
+ return null;
658
+ }
659
+ return { tempo, swing, reverb: reverbAmount, humanize, drumVol, grid, tail, seed, tracks, drums: sections, beats, seconds };
660
+ }
661
+ function musicKey(m, length, loop) {
662
+ return `music|${JSON.stringify([m.tempo, m.swing, m.reverb, m.humanize, m.drumVol, m.grid, m.tail, m.seed, m.tracks, m.drums, length, loop])}`;
663
+ }
664
+
665
+ // src/audio/music/render.ts
666
+ var MUSIC_PEAK = 0.5;
667
+ var RMS_CAP = 0.12;
668
+ function rng(seed) {
669
+ let a = seed >>> 0;
670
+ return () => {
671
+ a = a + 1831565813 >>> 0;
672
+ let t = a;
673
+ t = Math.imul(t ^ t >>> 15, t | 1);
674
+ t ^= t + Math.imul(t ^ t >>> 7, t | 61);
675
+ return ((t ^ t >>> 14) >>> 0) / 4294967296;
676
+ };
677
+ }
678
+ function musicLength(m) {
679
+ return m.seconds + m.tail;
680
+ }
681
+ function musicBeatTimes(m, until = m.seconds) {
682
+ const map = new TempoMap(m.tempo);
683
+ const times = [];
684
+ if (m.drums.some((s) => s.drums.some((d) => d.kind === "kick"))) {
685
+ for (const s of m.drums) {
686
+ const kick = s.drums.find((d) => d.kind === "kick");
687
+ if (!kick) continue;
688
+ const end = Math.min(s.to, m.beats);
689
+ for (let rep = 0; s.from + rep * s.repeat < end; rep++) for (const h of kick.hits) {
690
+ const b = s.from + rep * s.repeat + h.i / m.grid;
691
+ if (b < end) times.push(map.seconds(b));
692
+ }
693
+ }
694
+ times.sort((a, b) => a - b);
695
+ } else {
696
+ for (let b = 0; b < m.beats; b++) times.push(map.seconds(b));
697
+ }
698
+ return times.filter((t) => t < until);
699
+ }
700
+ function renderMusic(m, sampleRate, length, loop = false) {
701
+ setSampleRate(sampleRate);
702
+ const total = Math.max(2, Math.round(length * sampleRate));
703
+ const rnd = rng(m.seed);
704
+ const map = new TempoMap(m.tempo);
705
+ const loopSec = map.seconds(m.beats);
706
+ const repeats = loop ? Math.max(1, Math.ceil(length / Math.max(0.1, loopSec))) : 1;
707
+ const bus = () => ({ L: new Float32Array(total), R: new Float32Array(total) });
708
+ const out = bus(), send = bus(), scratch = bus();
709
+ const swingShift = (beat) => {
710
+ const frac = beat - Math.floor(beat);
711
+ return beat + (Math.abs(frac - 0.5) < 1e-6 ? m.swing * 0.5 : Math.abs(frac - 0.75) < 1e-6 ? m.swing * 0.25 : 0);
712
+ };
713
+ const levelAt = (vol) => {
714
+ if (typeof vol === "number") return () => vol;
715
+ const pts = vol.map(([b, v]) => [map.seconds(b), v]);
716
+ return (sec) => {
717
+ const t = loop && loopSec > 0 ? sec % loopSec : sec;
718
+ if (t <= pts[0][0]) return pts[0][1];
719
+ for (let i = 1; i < pts.length; i++) {
720
+ if (t < pts[i][0]) return pts[i - 1][1] + (pts[i][1] - pts[i - 1][1]) * (t - pts[i - 1][0]) / (pts[i][0] - pts[i - 1][0]);
721
+ }
722
+ return pts[pts.length - 1][1];
723
+ };
724
+ };
725
+ for (const tr of m.tracks) {
726
+ const inst = VOICES[tr.inst];
727
+ scratch.L.fill(0);
728
+ scratch.R.fill(0);
729
+ for (let r = 0; r < repeats; r++) {
730
+ const offset = r * loopSec;
731
+ for (const e of tr.events) {
732
+ const strum = e.midi.length > 1 ? tr.strum : 0;
733
+ const startBeat = swingShift(e.t);
734
+ const lenSec = Math.max(0.05, (map.seconds(e.t + e.dur) - map.seconds(e.t)) * tr.legato);
735
+ e.midi.forEach((midi, k) => {
736
+ const t0 = offset + map.seconds(startBeat) + (rnd() - 0.5) * m.humanize + k * strum;
737
+ const vel = Math.min(1, e.vel * (0.93 + rnd() * 0.14));
738
+ if (t0 * sampleRate >= total) return;
739
+ inst(midi + tr.transpose, lenSec, vel, scratch, Math.max(0, Math.round(t0 * sampleRate)), rnd, tr.voice);
740
+ });
741
+ }
742
+ }
743
+ if (tr.tone < 1) {
744
+ const fc = 400 * 50 ** tr.tone;
745
+ const a = [new Biquad("lp", fc, 0.7), new Biquad("lp", fc, 0.7)], b = [new Biquad("lp", fc, 0.7), new Biquad("lp", fc, 0.7)];
746
+ for (let i = 0; i < total; i++) {
747
+ scratch.L[i] = a[1].run(a[0].run(scratch.L[i]));
748
+ scratch.R[i] = b[1].run(b[0].run(scratch.R[i]));
749
+ }
750
+ }
751
+ const level = levelAt(tr.vol), pan = Math.max(-1, Math.min(1, tr.pan));
752
+ const gl = Math.cos((pan + 1) * Math.PI / 4) * 1.3, gr = Math.sin((pan + 1) * Math.PI / 4) * 1.3;
753
+ const constant = typeof tr.vol === "number";
754
+ let g = constant ? level(0) : 0;
755
+ for (let i = 0; i < total; i++) {
756
+ if (!constant) g = level(i / sampleRate);
757
+ const l = scratch.L[i] * g * gl, r = scratch.R[i] * g * gr;
758
+ out.L[i] += l;
759
+ out.R[i] += r;
760
+ send.L[i] += l * tr.reverb;
761
+ send.R[i] += r * tr.reverb;
762
+ }
763
+ }
764
+ if (m.drums.length) {
765
+ scratch.L.fill(0);
766
+ scratch.R.fill(0);
767
+ for (let r = 0; r < repeats; r++) {
768
+ const offset = r * loopSec;
769
+ for (const s of m.drums) {
770
+ const end = Math.min(s.to, m.beats);
771
+ for (let rep = 0; s.from + rep * s.repeat < end - 1e-6; rep++) for (const d of s.drums) for (const h of d.hits) {
772
+ const beat = s.from + rep * s.repeat + h.i / m.grid;
773
+ if (beat >= end) continue;
774
+ const vel = h.vel * (0.9 + rnd() * 0.2);
775
+ const t0 = offset + map.seconds(swingShift(beat)) + (rnd() - 0.5) * m.humanize * 0.5;
776
+ if (t0 * sampleRate >= total) continue;
777
+ hitDrum(d.kind, vel, scratch, Math.max(0, Math.round(t0 * sampleRate)), rnd);
778
+ }
779
+ }
780
+ }
781
+ for (let i = 0; i < total; i++) {
782
+ const l = scratch.L[i] * m.drumVol, r = scratch.R[i] * m.drumVol;
783
+ out.L[i] += l;
784
+ out.R[i] += r;
785
+ send.L[i] += l;
786
+ send.R[i] += r;
787
+ }
788
+ }
789
+ reverb(send, out, m.reverb, 0.8);
790
+ let peak = 0, sum = 0;
791
+ for (let i = 0; i < total; i++) {
792
+ const l = out.L[i] = Math.tanh(out.L[i] * 0.9), r = out.R[i] = Math.tanh(out.R[i] * 0.9);
793
+ peak = Math.max(peak, Math.abs(l), Math.abs(r));
794
+ sum += l * l + r * r;
795
+ }
796
+ const rms = Math.sqrt(sum / (2 * total));
797
+ const gain = peak > 0 ? Math.min(MUSIC_PEAK / peak, RMS_CAP / Math.max(rms, 1e-9)) : 0;
798
+ const fade = Math.min(Math.floor(0.4 * sampleRate), total >> 2);
799
+ for (let i = 0; i < total; i++) {
800
+ const f = i >= total - fade ? (total - 1 - i) / fade : 1;
801
+ out.L[i] *= gain * f;
802
+ out.R[i] *= gain * f;
803
+ }
804
+ return [out.L, out.R];
805
+ }
806
+
807
+ export { CHORD_KINDS, DEFAULT_TAIL, DRUMS, INSTRUMENTS, MAX_SECONDS, MUSIC_PEAK, TempoMap, chordToMidi, musicBeatTimes, musicKey, musicLength, noteToMidi, parseDrumGrid, parseNotes, renderMusic, resolveMusic };
808
+ //# sourceMappingURL=music-4HDFULNR.js.map
809
+ //# sourceMappingURL=music-4HDFULNR.js.map