textmode.synth.js 1.0.0-beta.4 → 1.0.0-beta.5
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.
- package/dist/textmode.synth.esm.js +264 -261
- package/dist/textmode.synth.umd.js +18 -17
- package/dist/types/compiler/GLSLGenerator.d.ts +2 -0
- package/dist/types/compiler/GLSLGenerator.d.ts.map +1 -1
- package/dist/types/compiler/types.d.ts +2 -0
- package/dist/types/compiler/types.d.ts.map +1 -1
- package/dist/types/core/ISynthSource.d.ts +7 -6
- package/dist/types/core/ISynthSource.d.ts.map +1 -1
- package/dist/types/core/SynthSource.d.ts +1 -9
- package/dist/types/core/SynthSource.d.ts.map +1 -1
- package/dist/types/lifecycle/synthRender.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const X = { src: { returnType: "vec4", args: [{ type: "vec2", name: "_st" }] }, coord: { returnType: "vec2", args: [{ type: "vec2", name: "_st" }] }, color: { returnType: "vec4", args: [{ type: "vec4", name: "_c0" }] }, combine: { returnType: "vec4", args: [{ type: "vec4", name: "_c0" }, { type: "vec4", name: "_c1" }] }, combineCoord: { returnType: "vec2", args: [{ type: "vec2", name: "_st" }, { type: "vec4", name: "_c0" }] } };
|
|
2
2
|
function D(t) {
|
|
3
|
-
const e = X[t.type],
|
|
4
|
-
${e.returnType} ${t.name}(${
|
|
3
|
+
const e = X[t.type], r = [...e.args, ...t.inputs.map((n) => ({ type: n.type, name: n.name }))].map((n) => `${n.type} ${n.name}`).join(", "), a = `
|
|
4
|
+
${e.returnType} ${t.name}(${r}) {
|
|
5
5
|
${t.glsl}
|
|
6
6
|
}`;
|
|
7
7
|
return { ...t, glslFunction: a };
|
|
@@ -13,24 +13,24 @@ class j {
|
|
|
13
13
|
this._transforms.has(e.name) && console.warn(`[TransformRegistry] Overwriting existing transform: ${e.name}`), this._transforms.set(e.name, e), this._processedCache.delete(e.name);
|
|
14
14
|
}
|
|
15
15
|
registerMany(e) {
|
|
16
|
-
for (const
|
|
16
|
+
for (const r of e) this.register(r);
|
|
17
17
|
}
|
|
18
18
|
get(e) {
|
|
19
19
|
return this._transforms.get(e);
|
|
20
20
|
}
|
|
21
21
|
getProcessed(e) {
|
|
22
|
-
let
|
|
23
|
-
if (!
|
|
22
|
+
let r = this._processedCache.get(e);
|
|
23
|
+
if (!r) {
|
|
24
24
|
const a = this._transforms.get(e);
|
|
25
|
-
a && (
|
|
25
|
+
a && (r = D(a), this._processedCache.set(e, r));
|
|
26
26
|
}
|
|
27
|
-
return
|
|
27
|
+
return r;
|
|
28
28
|
}
|
|
29
29
|
has(e) {
|
|
30
30
|
return this._transforms.has(e);
|
|
31
31
|
}
|
|
32
32
|
getByType(e) {
|
|
33
|
-
return Array.from(this._transforms.values()).filter((
|
|
33
|
+
return Array.from(this._transforms.values()).filter((r) => r.type === e);
|
|
34
34
|
}
|
|
35
35
|
getNames() {
|
|
36
36
|
return Array.from(this._transforms.keys());
|
|
@@ -59,26 +59,26 @@ class G {
|
|
|
59
59
|
this._synthSourceClass = e;
|
|
60
60
|
}
|
|
61
61
|
injectMethods(e) {
|
|
62
|
-
const
|
|
63
|
-
for (const a of
|
|
64
|
-
}
|
|
65
|
-
_injectMethod(e,
|
|
66
|
-
const { name: a, inputs:
|
|
67
|
-
e[a] = o === "combine" || o === "combineCoord" ? function(
|
|
68
|
-
const i =
|
|
69
|
-
return this.addCombineTransform(a,
|
|
70
|
-
} : function(...
|
|
71
|
-
const s =
|
|
62
|
+
const r = k.getAll();
|
|
63
|
+
for (const a of r) this._injectMethod(e, a);
|
|
64
|
+
}
|
|
65
|
+
_injectMethod(e, r) {
|
|
66
|
+
const { name: a, inputs: n, type: o } = r;
|
|
67
|
+
e[a] = o === "combine" || o === "combineCoord" ? function(l, ...s) {
|
|
68
|
+
const i = n.map((m, h) => s[h] ?? m.default);
|
|
69
|
+
return this.addCombineTransform(a, l, i);
|
|
70
|
+
} : function(...l) {
|
|
71
|
+
const s = n.map((i, m) => l[m] ?? i.default);
|
|
72
72
|
return this.addTransform(a, s);
|
|
73
73
|
};
|
|
74
74
|
}
|
|
75
75
|
generateStandaloneFunctions() {
|
|
76
76
|
if (!this._synthSourceClass) throw new Error("[TransformFactory] SynthSource class not set. Call setSynthSourceClass first.");
|
|
77
|
-
const e = {},
|
|
78
|
-
for (const
|
|
79
|
-
const { name: o, inputs:
|
|
77
|
+
const e = {}, r = k.getAll(), a = this._synthSourceClass;
|
|
78
|
+
for (const n of r) if (O.has(n.type)) {
|
|
79
|
+
const { name: o, inputs: l } = n;
|
|
80
80
|
e[o] = (...s) => {
|
|
81
|
-
const i = new a(), m =
|
|
81
|
+
const i = new a(), m = l.map((h, y) => s[y] ?? h.default);
|
|
82
82
|
return i.addTransform(o, m);
|
|
83
83
|
};
|
|
84
84
|
}
|
|
@@ -87,12 +87,12 @@ class G {
|
|
|
87
87
|
getGeneratedFunctions() {
|
|
88
88
|
return this._generatedFunctions;
|
|
89
89
|
}
|
|
90
|
-
addTransform(e,
|
|
91
|
-
if (k.register(e),
|
|
92
|
-
const a = this._synthSourceClass, { name:
|
|
93
|
-
this._generatedFunctions[
|
|
94
|
-
const s = new a(), i = o.map((m, h) =>
|
|
95
|
-
return s.addTransform(
|
|
90
|
+
addTransform(e, r) {
|
|
91
|
+
if (k.register(e), r && this._injectMethod(r, e), O.has(e.type) && this._synthSourceClass) {
|
|
92
|
+
const a = this._synthSourceClass, { name: n, inputs: o } = e;
|
|
93
|
+
this._generatedFunctions[n] = (...l) => {
|
|
94
|
+
const s = new a(), i = o.map((m, h) => l[h] ?? m.default);
|
|
95
|
+
return s.addTransform(n, i);
|
|
96
96
|
};
|
|
97
97
|
}
|
|
98
98
|
}
|
|
@@ -147,12 +147,12 @@ const P = new G(), q = { name: "osc", type: "src", inputs: [{ name: "frequency",
|
|
|
147
147
|
xy = mat2(cos(ang), -sin(ang), sin(ang), cos(ang)) * xy;
|
|
148
148
|
xy += 0.5;
|
|
149
149
|
return xy;
|
|
150
|
-
`, description: "Rotate coordinates" },
|
|
150
|
+
`, description: "Rotate coordinates" }, re = { name: "scale", type: "coord", inputs: [{ name: "amount", type: "float", default: 1.5 }, { name: "xMult", type: "float", default: 1 }, { name: "yMult", type: "float", default: 1 }, { name: "offsetX", type: "float", default: 0.5 }, { name: "offsetY", type: "float", default: 0.5 }], glsl: `
|
|
151
151
|
vec2 xy = _st - vec2(offsetX, offsetY);
|
|
152
152
|
xy *= (1.0 / vec2(amount * xMult, amount * yMult));
|
|
153
153
|
xy += vec2(offsetX, offsetY);
|
|
154
154
|
return xy;
|
|
155
|
-
`, description: "Scale coordinates" },
|
|
155
|
+
`, description: "Scale coordinates" }, ne = { name: "scroll", type: "coord", inputs: [{ name: "scrollX", type: "float", default: 0.5 }, { name: "scrollY", type: "float", default: 0.5 }, { name: "speedX", type: "float", default: 0 }, { name: "speedY", type: "float", default: 0 }], glsl: `
|
|
156
156
|
vec2 st = _st;
|
|
157
157
|
st.x += scrollX + time * speedX;
|
|
158
158
|
st.y += scrollY + time * speedY;
|
|
@@ -190,7 +190,7 @@ const P = new G(), q = { name: "osc", type: "src", inputs: [{ name: "frequency",
|
|
|
190
190
|
a = mod(a, pi / nSides);
|
|
191
191
|
a = abs(a - pi / nSides / 2.0);
|
|
192
192
|
return r * vec2(cos(a), sin(a));
|
|
193
|
-
`, description: "Kaleidoscope effect" }, fe = [te,
|
|
193
|
+
`, description: "Kaleidoscope effect" }, fe = [te, re, ne, ae, oe, se, ce, le, ie, ue], pe = { name: "brightness", type: "color", inputs: [{ name: "amount", type: "float", default: 0.4 }], glsl: `
|
|
194
194
|
return vec4(_c0.rgb + vec3(amount), _c0.a);
|
|
195
195
|
`, description: "Adjust brightness" }, me = { name: "contrast", type: "color", inputs: [{ name: "amount", type: "float", default: 1.6 }], glsl: `
|
|
196
196
|
vec4 c = (_c0 - vec4(0.5)) * vec4(amount) + vec4(0.5);
|
|
@@ -312,16 +312,16 @@ const P = new G(), q = { name: "osc", type: "src", inputs: [{ name: "frequency",
|
|
|
312
312
|
`, description: "Modulate Y repeat with another source" }, Ke = { name: "modulateHue", type: "combineCoord", inputs: [{ name: "amount", type: "float", default: 1 }], glsl: `
|
|
313
313
|
return _st + (vec2(_c0.g - _c0.r, _c0.b - _c0.g) * amount * 1.0 / resolution);
|
|
314
314
|
`, description: "Modulate coordinates based on hue differences" }, Qe = [Ve, Ee, Be, Ne, Ye, Xe, De, je, Ge, qe, Ke], He = [...ee, ...fe, ...Te, ...Ue, ...Qe];
|
|
315
|
-
class
|
|
315
|
+
class F {
|
|
316
316
|
_transforms;
|
|
317
317
|
constructor(e) {
|
|
318
318
|
this._transforms = e;
|
|
319
319
|
}
|
|
320
320
|
static empty() {
|
|
321
|
-
return new
|
|
321
|
+
return new F([]);
|
|
322
322
|
}
|
|
323
323
|
static from(e) {
|
|
324
|
-
return new
|
|
324
|
+
return new F([...e]);
|
|
325
325
|
}
|
|
326
326
|
get transforms() {
|
|
327
327
|
return this._transforms;
|
|
@@ -336,7 +336,7 @@ class w {
|
|
|
336
336
|
return this._transforms.length === 0;
|
|
337
337
|
}
|
|
338
338
|
append(e) {
|
|
339
|
-
return new
|
|
339
|
+
return new F([...this._transforms, e]);
|
|
340
340
|
}
|
|
341
341
|
get(e) {
|
|
342
342
|
return this._transforms[e];
|
|
@@ -345,7 +345,7 @@ class w {
|
|
|
345
345
|
return this._transforms[Symbol.iterator]();
|
|
346
346
|
}
|
|
347
347
|
}
|
|
348
|
-
class
|
|
348
|
+
class S {
|
|
349
349
|
_chain;
|
|
350
350
|
_charMapping;
|
|
351
351
|
_nestedSources;
|
|
@@ -353,32 +353,31 @@ class b {
|
|
|
353
353
|
_colorSource;
|
|
354
354
|
_cellColorSource;
|
|
355
355
|
_charSource;
|
|
356
|
-
_charCount;
|
|
357
356
|
constructor(e) {
|
|
358
|
-
this._chain = e?.chain ??
|
|
357
|
+
this._chain = e?.chain ?? F.empty(), this._charMapping = e?.charMapping, this._colorSource = e?.colorSource, this._cellColorSource = e?.cellColorSource, this._charSource = e?.charSource, this._nestedSources = e?.nestedSources ?? /* @__PURE__ */ new Map(), this._externalLayerRefs = e?.externalLayerRefs ?? /* @__PURE__ */ new Map();
|
|
359
358
|
}
|
|
360
|
-
addTransform(e,
|
|
361
|
-
const a = { name: e, userArgs:
|
|
359
|
+
addTransform(e, r) {
|
|
360
|
+
const a = { name: e, userArgs: r };
|
|
362
361
|
return this._chain.push(a), this;
|
|
363
362
|
}
|
|
364
|
-
addCombineTransform(e,
|
|
365
|
-
const
|
|
366
|
-
return this._nestedSources.set(
|
|
363
|
+
addCombineTransform(e, r, a) {
|
|
364
|
+
const n = this._chain.length;
|
|
365
|
+
return this._nestedSources.set(n, r), this.addTransform(e, a);
|
|
367
366
|
}
|
|
368
367
|
addExternalLayerRef(e) {
|
|
369
|
-
const
|
|
370
|
-
return this._externalLayerRefs.set(
|
|
368
|
+
const r = this._chain.length;
|
|
369
|
+
return this._externalLayerRefs.set(r, e), this.addTransform("src", []);
|
|
371
370
|
}
|
|
372
371
|
charMap(e) {
|
|
373
|
-
const
|
|
374
|
-
for (const
|
|
372
|
+
const r = Array.from(e), a = [];
|
|
373
|
+
for (const n of r) a.push(n.codePointAt(0) ?? 32);
|
|
375
374
|
return this._charMapping = { chars: e, indices: a }, this;
|
|
376
375
|
}
|
|
377
376
|
charColor(e) {
|
|
378
377
|
return this._colorSource = e, this;
|
|
379
378
|
}
|
|
380
|
-
char(e
|
|
381
|
-
return this._charSource = e, this
|
|
379
|
+
char(e) {
|
|
380
|
+
return this._charSource = e, this;
|
|
382
381
|
}
|
|
383
382
|
cellColor(e) {
|
|
384
383
|
return this._cellColorSource = e, this;
|
|
@@ -388,10 +387,10 @@ class b {
|
|
|
388
387
|
}
|
|
389
388
|
clone() {
|
|
390
389
|
const e = /* @__PURE__ */ new Map();
|
|
391
|
-
for (const [a,
|
|
392
|
-
const
|
|
393
|
-
for (const [a,
|
|
394
|
-
return new
|
|
390
|
+
for (const [a, n] of this._nestedSources) e.set(a, n.clone());
|
|
391
|
+
const r = /* @__PURE__ */ new Map();
|
|
392
|
+
for (const [a, n] of this._externalLayerRefs) r.set(a, { ...n });
|
|
393
|
+
return new S({ chain: F.from(this._chain.transforms), charMapping: this._charMapping, colorSource: this._colorSource?.clone(), cellColorSource: this._cellColorSource?.clone(), charSource: this._charSource?.clone(), nestedSources: e, externalLayerRefs: r });
|
|
395
394
|
}
|
|
396
395
|
get transforms() {
|
|
397
396
|
return this._chain.transforms;
|
|
@@ -408,9 +407,6 @@ class b {
|
|
|
408
407
|
get charSource() {
|
|
409
408
|
return this._charSource;
|
|
410
409
|
}
|
|
411
|
-
get charCount() {
|
|
412
|
-
return this._charCount;
|
|
413
|
-
}
|
|
414
410
|
get nestedSources() {
|
|
415
411
|
return this._nestedSources;
|
|
416
412
|
}
|
|
@@ -422,8 +418,8 @@ const I = { linear: (t) => t, easeInQuad: (t) => t * t, easeOutQuad: (t) => t *
|
|
|
422
418
|
function T(t, e) {
|
|
423
419
|
return (t % e + e) % e;
|
|
424
420
|
}
|
|
425
|
-
function We(t, e,
|
|
426
|
-
return (t - e) * (
|
|
421
|
+
function We(t, e, r, a, n) {
|
|
422
|
+
return (t - e) * (n - a) / (r - e) + a;
|
|
427
423
|
}
|
|
428
424
|
function Je() {
|
|
429
425
|
"fast" in Array.prototype || (Array.prototype.fast = function(t = 1) {
|
|
@@ -435,24 +431,24 @@ function Je() {
|
|
|
435
431
|
}, Array.prototype.offset = function(t = 0.5) {
|
|
436
432
|
return this._offset = t % 1, this;
|
|
437
433
|
}, Array.prototype.fit = function(t = 0, e = 1) {
|
|
438
|
-
const
|
|
439
|
-
return
|
|
434
|
+
const r = Math.min(...this), a = Math.max(...this), n = this.map((o) => We(o, r, a, t, e));
|
|
435
|
+
return n._speed = this._speed, n._smooth = this._smooth, n._ease = this._ease, n._offset = this._offset, n;
|
|
440
436
|
});
|
|
441
437
|
}
|
|
442
438
|
function Ze(t, e) {
|
|
443
|
-
const
|
|
444
|
-
let
|
|
439
|
+
const r = t._speed ?? 1, a = t._smooth ?? 0;
|
|
440
|
+
let n = e.time * r * (e.bpm / 60) + (t._offset ?? 0);
|
|
445
441
|
if (a !== 0) {
|
|
446
|
-
const o = t._ease ?? I.linear,
|
|
447
|
-
return o(Math.min(T(
|
|
442
|
+
const o = t._ease ?? I.linear, l = n - a / 2, s = t[Math.floor(T(l, t.length))], i = t[Math.floor(T(l + 1, t.length))];
|
|
443
|
+
return o(Math.min(T(l, 1) / a, 1)) * (i - s) + s;
|
|
448
444
|
}
|
|
449
|
-
return t[Math.floor(T(
|
|
445
|
+
return t[Math.floor(T(n, t.length))];
|
|
450
446
|
}
|
|
451
447
|
function et(t) {
|
|
452
448
|
return Array.isArray(t) && t.length > 0 && typeof t[0] == "number";
|
|
453
449
|
}
|
|
454
|
-
Je(), k.registerMany(He), P.setSynthSourceClass(
|
|
455
|
-
const
|
|
450
|
+
Je(), k.registerMany(He), P.setSynthSourceClass(S), P.injectMethods(S.prototype);
|
|
451
|
+
const $ = P.generateStandaloneFunctions(), b = "textmode.synth.js";
|
|
456
452
|
class tt {
|
|
457
453
|
_usesFeedback = !1;
|
|
458
454
|
_usesCharFeedback = !1;
|
|
@@ -488,26 +484,26 @@ class tt {
|
|
|
488
484
|
return this._usesCellColorFeedback;
|
|
489
485
|
}
|
|
490
486
|
}
|
|
491
|
-
class
|
|
487
|
+
class rt {
|
|
492
488
|
_externalLayers = /* @__PURE__ */ new Map();
|
|
493
489
|
_counter = 0;
|
|
494
490
|
_layerIdToPrefix = /* @__PURE__ */ new Map();
|
|
495
491
|
getPrefix(e) {
|
|
496
|
-
let
|
|
497
|
-
return
|
|
492
|
+
let r = this._layerIdToPrefix.get(e);
|
|
493
|
+
return r || (r = "extLayer" + this._counter++, this._layerIdToPrefix.set(e, r)), r;
|
|
498
494
|
}
|
|
499
|
-
trackUsage(e,
|
|
495
|
+
trackUsage(e, r) {
|
|
500
496
|
const a = this.getPrefix(e.layerId);
|
|
501
|
-
let
|
|
502
|
-
switch (
|
|
497
|
+
let n = this._externalLayers.get(e.layerId);
|
|
498
|
+
switch (n || (n = { layerId: e.layerId, uniformPrefix: a, usesChar: !1, usesCharColor: !1, usesCellColor: !1 }, this._externalLayers.set(e.layerId, n)), r) {
|
|
503
499
|
case "char":
|
|
504
|
-
|
|
500
|
+
n.usesChar = !0;
|
|
505
501
|
break;
|
|
506
502
|
case "cellColor":
|
|
507
|
-
|
|
503
|
+
n.usesCellColor = !0;
|
|
508
504
|
break;
|
|
509
505
|
default:
|
|
510
|
-
|
|
506
|
+
n.usesCharColor = !0;
|
|
511
507
|
}
|
|
512
508
|
}
|
|
513
509
|
hasLayer(e) {
|
|
@@ -529,58 +525,58 @@ class nt {
|
|
|
529
525
|
this._externalLayers.clear(), this._counter = 0, this._layerIdToPrefix.clear();
|
|
530
526
|
}
|
|
531
527
|
}
|
|
532
|
-
const
|
|
528
|
+
const nt = { char: "prevCharBuffer", charColor: "prevCharColorBuffer", cellColor: "prevCellColorBuffer", main: "prevCharColorBuffer" };
|
|
533
529
|
class at {
|
|
534
|
-
getContextAwareGlslFunction(e,
|
|
535
|
-
return
|
|
530
|
+
getContextAwareGlslFunction(e, r, a, n, o) {
|
|
531
|
+
return r !== "src" ? e.glslFunction : n && o ? this._generateExternalSrcFunction(n, a, o) : this._generateSelfFeedbackSrcFunction(a);
|
|
536
532
|
}
|
|
537
|
-
getFunctionName(e,
|
|
538
|
-
return e.name !== "src" ? e.name : a &&
|
|
533
|
+
getFunctionName(e, r, a, n) {
|
|
534
|
+
return e.name !== "src" ? e.name : a && n ? `src_ext_${n(a.layerId)}_${r}` : `src_${r}`;
|
|
539
535
|
}
|
|
540
|
-
generateTransformCode(e,
|
|
541
|
-
const p = this.getFunctionName(
|
|
542
|
-
let
|
|
543
|
-
switch (
|
|
536
|
+
generateTransformCode(e, r, a, n, o, l, s, i, m, h, y, d, v) {
|
|
537
|
+
const p = this.getFunctionName(r, h, d, v), f = (...u) => [...u, ...m].join(", ");
|
|
538
|
+
let c = o, g = l, _ = s, C = i;
|
|
539
|
+
switch (r.type) {
|
|
544
540
|
case "src": {
|
|
545
|
-
const
|
|
546
|
-
e.push(` vec4 ${
|
|
541
|
+
const u = `c${a}`;
|
|
542
|
+
e.push(` vec4 ${u} = ${p}(${f(n)});`), c = u;
|
|
547
543
|
break;
|
|
548
544
|
}
|
|
549
545
|
case "coord": {
|
|
550
|
-
const
|
|
551
|
-
e.push(` vec2 ${
|
|
546
|
+
const u = `st${a}`;
|
|
547
|
+
e.push(` vec2 ${u} = ${p}(${f(n)});`), e.push(` ${n} = ${u};`);
|
|
552
548
|
break;
|
|
553
549
|
}
|
|
554
550
|
case "color": {
|
|
555
|
-
const
|
|
556
|
-
e.push(` vec4 ${
|
|
551
|
+
const u = `c${a}`;
|
|
552
|
+
e.push(` vec4 ${u} = ${p}(${f(o)});`), c = u;
|
|
557
553
|
break;
|
|
558
554
|
}
|
|
559
555
|
case "combine": {
|
|
560
|
-
const
|
|
561
|
-
e.push(` vec4 ${
|
|
556
|
+
const u = `c${a}`;
|
|
557
|
+
e.push(` vec4 ${u} = ${p}(${f(o, y ?? "vec4(0.0)")});`), c = u;
|
|
562
558
|
break;
|
|
563
559
|
}
|
|
564
560
|
case "combineCoord": {
|
|
565
|
-
const
|
|
566
|
-
e.push(` vec2 ${
|
|
561
|
+
const u = `st${a}`;
|
|
562
|
+
e.push(` vec2 ${u} = ${p}(${f(n, y ?? "vec4(0.0)")});`), e.push(` ${n} = ${u};`);
|
|
567
563
|
break;
|
|
568
564
|
}
|
|
569
565
|
}
|
|
570
|
-
return { colorVar:
|
|
566
|
+
return { colorVar: c, charVar: g, flagsVar: _, rotationVar: C };
|
|
571
567
|
}
|
|
572
|
-
_generateExternalSrcFunction(e,
|
|
573
|
-
const
|
|
568
|
+
_generateExternalSrcFunction(e, r, a) {
|
|
569
|
+
const n = a(e.layerId);
|
|
574
570
|
return `
|
|
575
|
-
vec4 ${`src_ext_${
|
|
576
|
-
return texture(${{ char: `${
|
|
571
|
+
vec4 ${`src_ext_${n}_${r}`}(vec2 _st) {
|
|
572
|
+
return texture(${{ char: `${n}_char`, charColor: `${n}_primary`, cellColor: `${n}_cell`, main: `${n}_primary` }[r]}, fract(_st));
|
|
577
573
|
}
|
|
578
574
|
`;
|
|
579
575
|
}
|
|
580
576
|
_generateSelfFeedbackSrcFunction(e) {
|
|
581
577
|
return `
|
|
582
578
|
vec4 ${`src_${e}`}(vec2 _st) {
|
|
583
|
-
return texture(${
|
|
579
|
+
return texture(${nt[e]}, fract(_st));
|
|
584
580
|
}
|
|
585
581
|
`;
|
|
586
582
|
}
|
|
@@ -588,27 +584,27 @@ vec4 ${`src_${e}`}(vec2 _st) {
|
|
|
588
584
|
class ot {
|
|
589
585
|
_uniforms = /* @__PURE__ */ new Map();
|
|
590
586
|
_dynamicUpdaters = /* @__PURE__ */ new Map();
|
|
591
|
-
processArgument(e,
|
|
587
|
+
processArgument(e, r, a) {
|
|
592
588
|
if (et(e)) {
|
|
593
|
-
const
|
|
594
|
-
return this._uniforms.set(
|
|
589
|
+
const n = `${a}_${r.name}`, o = { name: n, type: r.type, value: r.default ?? 0, isDynamic: !0 }, l = (s) => Ze(e, s);
|
|
590
|
+
return this._uniforms.set(n, o), this._dynamicUpdaters.set(n, l), { glslValue: n, uniform: o, updater: l };
|
|
595
591
|
}
|
|
596
592
|
if (typeof e == "function") {
|
|
597
|
-
const
|
|
598
|
-
return this._uniforms.set(
|
|
593
|
+
const n = `${a}_${r.name}`, o = { name: n, type: r.type, value: r.default ?? 0, isDynamic: !0 };
|
|
594
|
+
return this._uniforms.set(n, o), this._dynamicUpdaters.set(n, e), { glslValue: n, uniform: o, updater: e };
|
|
599
595
|
}
|
|
600
596
|
if (typeof e == "number") return { glslValue: x(e) };
|
|
601
597
|
if (Array.isArray(e) && typeof e[0] == "number") {
|
|
602
|
-
const
|
|
603
|
-
if (
|
|
604
|
-
if (
|
|
605
|
-
if (
|
|
598
|
+
const n = e;
|
|
599
|
+
if (n.length === 2) return { glslValue: `vec2(${x(n[0])}, ${x(n[1])})` };
|
|
600
|
+
if (n.length === 3) return { glslValue: `vec3(${x(n[0])}, ${x(n[1])}, ${x(n[2])})` };
|
|
601
|
+
if (n.length === 4) return { glslValue: `vec4(${x(n[0])}, ${x(n[1])}, ${x(n[2])}, ${x(n[3])})` };
|
|
606
602
|
}
|
|
607
|
-
return this.processDefault(
|
|
603
|
+
return this.processDefault(r);
|
|
608
604
|
}
|
|
609
605
|
processDefault(e) {
|
|
610
|
-
const
|
|
611
|
-
return typeof
|
|
606
|
+
const r = e.default;
|
|
607
|
+
return typeof r == "number" ? { glslValue: x(r) } : Array.isArray(r) ? { glslValue: `vec${r.length}(${r.map(x).join(", ")})` } : { glslValue: "0.0" };
|
|
612
608
|
}
|
|
613
609
|
getUniforms() {
|
|
614
610
|
return new Map(this._uniforms);
|
|
@@ -722,21 +718,21 @@ float _noise(vec3 v) {
|
|
|
722
718
|
}
|
|
723
719
|
`;
|
|
724
720
|
function ct(t) {
|
|
725
|
-
const { uniforms: e, glslFunctions:
|
|
721
|
+
const { uniforms: e, glslFunctions: r, mainCode: a, charOutputCode: n, primaryColorVar: o, cellColorVar: l, charMapping: s, usesFeedback: i, usesCharFeedback: m, usesCellColorFeedback: h, usesCharSource: y, externalLayers: d } = t, v = Array.from(e.values()).map((u) => `uniform ${u.type} ${u.name};`).join(`
|
|
726
722
|
`);
|
|
727
|
-
let
|
|
728
|
-
s && (
|
|
729
|
-
uniform int u_charMapSize;`,
|
|
723
|
+
let p = "", f = "";
|
|
724
|
+
s && (p = `uniform int u_charMap[${s.indices.length}];
|
|
725
|
+
uniform int u_charMapSize;`, f = `
|
|
730
726
|
// Apply character mapping
|
|
731
727
|
int rawCharIdx = int(charOutput.r * 255.0 + charOutput.g * 255.0 * 256.0);
|
|
732
728
|
int mappedCharIdx = u_charMap[int(mod(float(rawCharIdx), float(u_charMapSize)))];
|
|
733
729
|
charOutput.r = float(mappedCharIdx % 256) / 255.0;
|
|
734
730
|
charOutput.g = float(mappedCharIdx / 256) / 255.0;`);
|
|
735
|
-
const
|
|
736
|
-
i &&
|
|
737
|
-
const
|
|
738
|
-
`),
|
|
739
|
-
if (
|
|
731
|
+
const c = [];
|
|
732
|
+
i && c.push("uniform sampler2D prevCharColorBuffer;"), m && c.push("uniform sampler2D prevCharBuffer;"), h && c.push("uniform sampler2D prevCellColorBuffer;");
|
|
733
|
+
const g = c.join(`
|
|
734
|
+
`), _ = y ? "uniform float u_charSourceCount;" : "", C = [];
|
|
735
|
+
if (d) for (const [, u] of d) u.usesChar && C.push(`uniform sampler2D ${u.uniformPrefix}_char;`), u.usesCharColor && C.push(`uniform sampler2D ${u.uniformPrefix}_primary;`), u.usesCellColor && C.push(`uniform sampler2D ${u.uniformPrefix}_cell;`);
|
|
740
736
|
return `#version 300 es
|
|
741
737
|
precision highp float;
|
|
742
738
|
|
|
@@ -751,19 +747,20 @@ layout(location = 2) out vec4 o_secondaryColor;
|
|
|
751
747
|
// Standard uniforms
|
|
752
748
|
uniform float time;
|
|
753
749
|
uniform vec2 resolution;
|
|
754
|
-
${
|
|
755
|
-
${
|
|
756
|
-
${
|
|
750
|
+
${g}
|
|
751
|
+
${C.length > 0 ? `// External layer samplers
|
|
752
|
+
${C.join(`
|
|
757
753
|
`)}` : ""}
|
|
758
|
-
${
|
|
754
|
+
${p}
|
|
755
|
+
${_}
|
|
759
756
|
|
|
760
757
|
// Dynamic uniforms
|
|
761
|
-
${
|
|
758
|
+
${v}
|
|
762
759
|
|
|
763
760
|
${st}
|
|
764
761
|
|
|
765
762
|
// Transform functions
|
|
766
|
-
${Array.from(
|
|
763
|
+
${Array.from(r).join(`
|
|
767
764
|
`)}
|
|
768
765
|
|
|
769
766
|
void main() {
|
|
@@ -771,22 +768,22 @@ void main() {
|
|
|
771
768
|
${a.join(`
|
|
772
769
|
`)}
|
|
773
770
|
|
|
774
|
-
${
|
|
775
|
-
${
|
|
771
|
+
${n}
|
|
772
|
+
${f}
|
|
776
773
|
|
|
777
774
|
// Output to MRT
|
|
778
775
|
o_character = charOutput;
|
|
779
776
|
o_primaryColor = ${o};
|
|
780
|
-
o_secondaryColor = ${
|
|
777
|
+
o_secondaryColor = ${l};
|
|
781
778
|
}
|
|
782
779
|
`;
|
|
783
780
|
}
|
|
784
|
-
function lt(t, e,
|
|
781
|
+
function lt(t, e, r) {
|
|
785
782
|
return t ? `
|
|
786
783
|
// Character output from generator
|
|
787
784
|
vec4 charOutput = ${e};` : `
|
|
788
785
|
// Derive character from color luminance
|
|
789
|
-
float lum = _luminance(${
|
|
786
|
+
float lum = _luminance(${r}.rgb);
|
|
790
787
|
int charIdx = int(lum * 255.0);
|
|
791
788
|
vec4 charOutput = vec4(float(charIdx % 256) / 255.0, float(charIdx / 256) / 255.0, 0.0, 0.0);`;
|
|
792
789
|
}
|
|
@@ -796,64 +793,66 @@ function A(t) {
|
|
|
796
793
|
class it {
|
|
797
794
|
_uniformManager = new ot();
|
|
798
795
|
_feedbackTracker = new tt();
|
|
799
|
-
_externalLayerManager = new
|
|
796
|
+
_externalLayerManager = new rt();
|
|
800
797
|
_codeGenerator = new at();
|
|
801
798
|
_glslFunctions = /* @__PURE__ */ new Set();
|
|
802
799
|
_mainCode = [];
|
|
803
800
|
_varCounter = 0;
|
|
804
801
|
_currentTarget = "main";
|
|
802
|
+
_usesCharSource = !1;
|
|
805
803
|
compile(e) {
|
|
806
804
|
this._reset();
|
|
807
|
-
const
|
|
808
|
-
let a =
|
|
805
|
+
const r = this._compileChain(e, "main", "vec4(1.0, 1.0, 1.0, 1.0)", "v_uv", "main");
|
|
806
|
+
let a = r.charVar;
|
|
809
807
|
e.charSource && (a = this._compileCharSource(e));
|
|
810
|
-
let
|
|
811
|
-
e.colorSource && (
|
|
808
|
+
let n = r.colorVar;
|
|
809
|
+
e.colorSource && (n = this._compileChain(e.colorSource, "charColor", "vec4(1.0, 1.0, 1.0, 1.0)", "v_uv", "charColor").colorVar);
|
|
812
810
|
let o = "vec4(0.0, 0.0, 0.0, 0.0)";
|
|
813
811
|
e.cellColorSource && (o = this._compileChain(e.cellColorSource, "cellColor", "vec4(0.0, 0.0, 0.0, 0.0)", "v_uv", "cellColor").colorVar);
|
|
814
|
-
const
|
|
815
|
-
return { fragmentSource: ct({ uniforms: this._uniformManager.getUniforms(), glslFunctions: this._glslFunctions, mainCode: this._mainCode, charOutputCode:
|
|
812
|
+
const l = lt(!!a, a ?? "vec4(0.0)", r.colorVar), s = this._feedbackTracker.getUsage();
|
|
813
|
+
return { fragmentSource: ct({ uniforms: this._uniformManager.getUniforms(), glslFunctions: this._glslFunctions, mainCode: this._mainCode, charOutputCode: l, primaryColorVar: n, cellColorVar: o, charMapping: e.charMapping, usesFeedback: s.usesCharColorFeedback, usesCharFeedback: s.usesCharFeedback, usesCellColorFeedback: s.usesCellColorFeedback, usesCharSource: this._usesCharSource, externalLayers: this._externalLayerManager.getExternalLayers() }), uniforms: this._uniformManager.getUniforms(), dynamicUpdaters: this._uniformManager.getDynamicUpdaters(), charMapping: e.charMapping, usesCharColorFeedback: s.usesCharColorFeedback, usesCharFeedback: s.usesCharFeedback, usesCellColorFeedback: s.usesCellColorFeedback, usesCharSource: this._usesCharSource, externalLayers: this._externalLayerManager.getExternalLayers() };
|
|
816
814
|
}
|
|
817
815
|
_reset() {
|
|
818
|
-
this._varCounter = 0, this._uniformManager.clear(), this._feedbackTracker.reset(), this._externalLayerManager.reset(), this._glslFunctions.clear(), this._mainCode.length = 0, this._currentTarget = "main";
|
|
816
|
+
this._varCounter = 0, this._uniformManager.clear(), this._feedbackTracker.reset(), this._externalLayerManager.reset(), this._glslFunctions.clear(), this._mainCode.length = 0, this._currentTarget = "main", this._usesCharSource = !1;
|
|
819
817
|
}
|
|
820
818
|
_compileCharSource(e) {
|
|
821
|
-
|
|
822
|
-
|
|
819
|
+
this._usesCharSource = !0;
|
|
820
|
+
const r = this._compileChain(e.charSource, "charSrc", "vec4(1.0, 1.0, 1.0, 1.0)", "v_uv", "char"), a = "charFromSource_" + this._varCounter++;
|
|
821
|
+
return this._mainCode.push(" // Convert charSource color to character index"), this._mainCode.push(` float charLum_${a} = _luminance(${r.colorVar}.rgb);`), this._mainCode.push(` int charIdx_${a} = int(charLum_${a} * u_charSourceCount);`), this._mainCode.push(` vec4 ${a} = vec4(float(charIdx_${a} % 256) / 255.0, float(charIdx_${a} / 256) / 255.0, 0.0, 0.0);`), a;
|
|
823
822
|
}
|
|
824
|
-
_compileChain(e,
|
|
825
|
-
const
|
|
823
|
+
_compileChain(e, r, a, n = "v_uv", o = "main") {
|
|
824
|
+
const l = this._currentTarget;
|
|
826
825
|
this._currentTarget = o;
|
|
827
|
-
const s = `${
|
|
828
|
-
let i, m, h, y = `${
|
|
829
|
-
this._mainCode.push(` vec2 ${s} = ${
|
|
830
|
-
const
|
|
831
|
-
const
|
|
832
|
-
if (!
|
|
833
|
-
const
|
|
834
|
-
|
|
835
|
-
const
|
|
836
|
-
this._glslFunctions.add(
|
|
837
|
-
const Y = this._processArguments(
|
|
826
|
+
const s = `${r}_st`;
|
|
827
|
+
let i, m, h, y = `${r}_c`;
|
|
828
|
+
this._mainCode.push(` vec2 ${s} = ${n};`), this._mainCode.push(` vec4 ${y} = ${a};`);
|
|
829
|
+
const d = e.transforms, v = d.map((c) => this._getProcessedTransform(c.name)), p = this._identifyCoordTransforms(v), f = (c) => {
|
|
830
|
+
const g = d[c], _ = v[c];
|
|
831
|
+
if (!_) return void console.warn(`[SynthCompiler] Unknown transform: ${g.name}`);
|
|
832
|
+
const C = e.externalLayerRefs.get(c);
|
|
833
|
+
g.name === "src" && this._trackSrcUsage(C);
|
|
834
|
+
const u = this._codeGenerator.getContextAwareGlslFunction(_, g.name, this._currentTarget, C, (L) => this._externalLayerManager.getPrefix(L));
|
|
835
|
+
this._glslFunctions.add(u);
|
|
836
|
+
const Y = this._processArguments(g.userArgs, _.inputs, `${r}_${c}_${g.name}`), R = e.nestedSources.get(c);
|
|
838
837
|
let z;
|
|
839
|
-
R && (
|
|
840
|
-
const
|
|
841
|
-
y =
|
|
838
|
+
R && (_.type === "combine" || _.type === "combineCoord") && (z = this._compileChain(R, `${r}_nested_${c}`, a, s, o).colorVar);
|
|
839
|
+
const M = this._codeGenerator.generateTransformCode(this._mainCode, _, this._varCounter++, s, y, i, m, h, Y, this._currentTarget, z, C, (L) => this._externalLayerManager.getPrefix(L));
|
|
840
|
+
y = M.colorVar, M.charVar && (i = M.charVar), M.flagsVar && (m = M.flagsVar), M.rotationVar && (h = M.rotationVar);
|
|
842
841
|
};
|
|
843
|
-
for (let
|
|
844
|
-
for (let
|
|
845
|
-
const
|
|
846
|
-
(!
|
|
842
|
+
for (let c = p.length - 1; c >= 0; c--) f(p[c]);
|
|
843
|
+
for (let c = 0; c < d.length; c++) {
|
|
844
|
+
const g = v[c];
|
|
845
|
+
(!g || g.type !== "coord" && g.type !== "combineCoord") && f(c);
|
|
847
846
|
}
|
|
848
|
-
return this._currentTarget =
|
|
847
|
+
return this._currentTarget = l, { coordVar: s, colorVar: y, charVar: i, flagsVar: m, rotationVar: h };
|
|
849
848
|
}
|
|
850
849
|
_identifyCoordTransforms(e) {
|
|
851
|
-
const
|
|
850
|
+
const r = [];
|
|
852
851
|
for (let a = 0; a < e.length; a++) {
|
|
853
|
-
const
|
|
854
|
-
|
|
852
|
+
const n = e[a];
|
|
853
|
+
n && (n.type !== "coord" && n.type !== "combineCoord" || r.push(a));
|
|
855
854
|
}
|
|
856
|
-
return
|
|
855
|
+
return r;
|
|
857
856
|
}
|
|
858
857
|
_trackSrcUsage(e) {
|
|
859
858
|
e ? this._externalLayerManager.trackUsage(e, this._currentTarget) : this._feedbackTracker.trackUsage(this._currentTarget);
|
|
@@ -861,28 +860,28 @@ class it {
|
|
|
861
860
|
_getProcessedTransform(e) {
|
|
862
861
|
return k.getProcessed(e);
|
|
863
862
|
}
|
|
864
|
-
_processArguments(e,
|
|
865
|
-
const
|
|
866
|
-
for (let o = 0; o <
|
|
867
|
-
const
|
|
868
|
-
|
|
863
|
+
_processArguments(e, r, a) {
|
|
864
|
+
const n = [];
|
|
865
|
+
for (let o = 0; o < r.length; o++) {
|
|
866
|
+
const l = r[o], s = e[o] ?? l.default, i = this._uniformManager.processArgument(s, l, a);
|
|
867
|
+
n.push(i.glslValue);
|
|
869
868
|
}
|
|
870
|
-
return
|
|
869
|
+
return n;
|
|
871
870
|
}
|
|
872
871
|
}
|
|
873
872
|
class ut {
|
|
874
873
|
_resolvedIndices;
|
|
875
874
|
_lastFontCharacterCount = 0;
|
|
876
875
|
_lastChars = "";
|
|
877
|
-
resolve(e,
|
|
878
|
-
const a =
|
|
876
|
+
resolve(e, r) {
|
|
877
|
+
const a = r.characters.length;
|
|
879
878
|
if (this._resolvedIndices && this._lastFontCharacterCount === a && this._lastChars === e) return this._resolvedIndices;
|
|
880
|
-
const
|
|
881
|
-
for (let i = 0; i <
|
|
882
|
-
const m =
|
|
879
|
+
const n = Array.from(e), o = new Int32Array(n.length), l = r.characterMap, s = r.characters;
|
|
880
|
+
for (let i = 0; i < n.length; i++) {
|
|
881
|
+
const m = n[i], h = l.get(m);
|
|
883
882
|
if (h !== void 0) o[i] = s.indexOf(h);
|
|
884
883
|
else {
|
|
885
|
-
const y =
|
|
884
|
+
const y = l.get(" ");
|
|
886
885
|
o[i] = y !== void 0 ? s.indexOf(y) : 0;
|
|
887
886
|
}
|
|
888
887
|
}
|
|
@@ -893,25 +892,25 @@ class ut {
|
|
|
893
892
|
}
|
|
894
893
|
}
|
|
895
894
|
function V(t = {}) {
|
|
896
|
-
return { source: t.source ?? new
|
|
895
|
+
return { source: t.source ?? new S(), compiled: t.compiled, shader: t.shader, characterResolver: t.characterResolver ?? new ut(), needsCompile: t.needsCompile ?? !1, pingPongBuffers: t.pingPongBuffers, pingPongIndex: t.pingPongIndex ?? 0, externalLayerMap: t.externalLayerMap, bpm: t.bpm };
|
|
897
896
|
}
|
|
898
897
|
function ft(t) {
|
|
899
898
|
t.extendLayer("synth", function(e) {
|
|
900
|
-
const
|
|
901
|
-
let a = this.getPluginState(
|
|
902
|
-
a ? (a.source = e, a.needsCompile = !0, a.characterResolver.invalidate(),
|
|
899
|
+
const r = this.grid !== void 0 && this.drawFramebuffer !== void 0;
|
|
900
|
+
let a = this.getPluginState(b);
|
|
901
|
+
a ? (a.source = e, a.needsCompile = !0, a.characterResolver.invalidate(), r && (a.compiled = A(e))) : a = V({ source: e, compiled: r ? A(e) : void 0, needsCompile: !0 }), this.setPluginState(b, a);
|
|
903
902
|
});
|
|
904
903
|
}
|
|
905
904
|
function pt(t) {
|
|
906
905
|
t.extendLayer("clearSynth", function() {
|
|
907
|
-
const e = this.getPluginState(
|
|
908
|
-
e && (e.shader?.dispose && e.shader.dispose(), e.pingPongBuffers && (e.pingPongBuffers[0].dispose?.(), e.pingPongBuffers[1].dispose?.()), this.setPluginState(
|
|
906
|
+
const e = this.getPluginState(b);
|
|
907
|
+
e && (e.shader?.dispose && e.shader.dispose(), e.pingPongBuffers && (e.pingPongBuffers[0].dispose?.(), e.pingPongBuffers[1].dispose?.()), this.setPluginState(b, void 0));
|
|
909
908
|
});
|
|
910
909
|
}
|
|
911
910
|
function mt(t) {
|
|
912
911
|
t.extendLayer("bpm", function(e) {
|
|
913
|
-
let
|
|
914
|
-
|
|
912
|
+
let r = this.getPluginState(b);
|
|
913
|
+
r ? r.bpm = e : r = V({ bpm: e }), this.setPluginState(b, r);
|
|
915
914
|
});
|
|
916
915
|
}
|
|
917
916
|
let E = 60;
|
|
@@ -926,24 +925,24 @@ function yt(t) {
|
|
|
926
925
|
return dt(e), e;
|
|
927
926
|
};
|
|
928
927
|
}
|
|
929
|
-
function
|
|
928
|
+
function w(t) {
|
|
930
929
|
const e = /* @__PURE__ */ new Map();
|
|
931
|
-
for (const [,
|
|
932
|
-
for (const [,
|
|
933
|
-
const a =
|
|
934
|
-
for (const [
|
|
930
|
+
for (const [, r] of t.externalLayerRefs) e.set(r.layerId, r.layer);
|
|
931
|
+
for (const [, r] of t.nestedSources) {
|
|
932
|
+
const a = w(r);
|
|
933
|
+
for (const [n, o] of a) e.set(n, o);
|
|
935
934
|
}
|
|
936
935
|
if (t.charSource) {
|
|
937
|
-
const
|
|
938
|
-
for (const [a,
|
|
936
|
+
const r = w(t.charSource);
|
|
937
|
+
for (const [a, n] of r) e.set(a, n);
|
|
939
938
|
}
|
|
940
939
|
if (t.colorSource) {
|
|
941
|
-
const
|
|
942
|
-
for (const [a,
|
|
940
|
+
const r = w(t.colorSource);
|
|
941
|
+
for (const [a, n] of r) e.set(a, n);
|
|
943
942
|
}
|
|
944
943
|
if (t.cellColorSource) {
|
|
945
|
-
const
|
|
946
|
-
for (const [a,
|
|
944
|
+
const r = w(t.cellColorSource);
|
|
945
|
+
for (const [a, n] of r) e.set(a, n);
|
|
947
946
|
}
|
|
948
947
|
return e;
|
|
949
948
|
}
|
|
@@ -951,21 +950,21 @@ let B = null;
|
|
|
951
950
|
function Ct(t) {
|
|
952
951
|
B = t;
|
|
953
952
|
}
|
|
954
|
-
function U(t, e,
|
|
955
|
-
const a =
|
|
953
|
+
function U(t, e, r) {
|
|
954
|
+
const a = r ?? B;
|
|
956
955
|
if (a) try {
|
|
957
956
|
a(t, e);
|
|
958
957
|
} catch {
|
|
959
958
|
}
|
|
960
959
|
}
|
|
961
|
-
function gt(t, e,
|
|
962
|
-
let
|
|
960
|
+
function gt(t, e, r, a = {}) {
|
|
961
|
+
let n;
|
|
963
962
|
try {
|
|
964
|
-
|
|
963
|
+
n = t();
|
|
965
964
|
} catch (o) {
|
|
966
|
-
return U(o, e, a.onError),
|
|
965
|
+
return U(o, e, a.onError), r;
|
|
967
966
|
}
|
|
968
|
-
return _t(
|
|
967
|
+
return _t(n) ? n : (U(new Error(`[textmode.synth.js] Invalid dynamic parameter value for "${e}": ${N(n)}`), e, a.onError), r);
|
|
969
968
|
}
|
|
970
969
|
function N(t) {
|
|
971
970
|
if (t === void 0) return "undefined";
|
|
@@ -975,7 +974,7 @@ function N(t) {
|
|
|
975
974
|
if (!Number.isFinite(t)) return t > 0 ? "Infinity" : "-Infinity";
|
|
976
975
|
}
|
|
977
976
|
if (Array.isArray(t)) {
|
|
978
|
-
const e = t.findIndex((
|
|
977
|
+
const e = t.findIndex((r) => typeof r != "number" || !Number.isFinite(r));
|
|
979
978
|
if (e >= 0) return `array with invalid element at index ${e}: ${N(t[e])}`;
|
|
980
979
|
}
|
|
981
980
|
return String(t);
|
|
@@ -984,97 +983,101 @@ function _t(t) {
|
|
|
984
983
|
return t != null && (typeof t == "number" ? Number.isFinite(t) : !!Array.isArray(t) && t.length > 0 && t.every((e) => typeof e == "number" && Number.isFinite(e)));
|
|
985
984
|
}
|
|
986
985
|
async function vt(t, e) {
|
|
987
|
-
const
|
|
988
|
-
if (!
|
|
989
|
-
const a = t.grid,
|
|
990
|
-
if (!a || !
|
|
991
|
-
const o =
|
|
992
|
-
i && !
|
|
993
|
-
const m = { time: e.secs, frameCount: e.frameCount, width: a.width, height: a.height, cols: a.cols, rows: a.rows, bpm:
|
|
994
|
-
for (const [
|
|
995
|
-
const p =
|
|
996
|
-
h.set(
|
|
997
|
-
}
|
|
998
|
-
const y = (
|
|
986
|
+
const r = t.getPluginState(b);
|
|
987
|
+
if (!r) return;
|
|
988
|
+
const a = t.grid, n = t.drawFramebuffer;
|
|
989
|
+
if (!a || !n || (r.compiled || (r.compiled = A(r.source), r.externalLayerMap = w(r.source), r.needsCompile = !0), r.needsCompile && r.compiled && (r.shader?.dispose && r.shader.dispose(), r.externalLayerMap = w(r.source), r.shader = await e.createFilterShader(r.compiled.fragmentSource), r.needsCompile = !1), !r.shader || !r.compiled)) return;
|
|
990
|
+
const o = r.compiled.usesCharColorFeedback, l = r.compiled.usesCharFeedback, s = r.compiled.usesCellColorFeedback, i = o || l || s;
|
|
991
|
+
i && !r.pingPongBuffers && (r.pingPongBuffers = [e.createFramebuffer({ width: a.cols, height: a.rows, attachments: 3 }), e.createFramebuffer({ width: a.cols, height: a.rows, attachments: 3 })], r.pingPongIndex = 0);
|
|
992
|
+
const m = { time: e.secs, frameCount: e.frameCount, width: a.width, height: a.height, cols: a.cols, rows: a.rows, bpm: r.bpm ?? ht() }, h = /* @__PURE__ */ new Map();
|
|
993
|
+
for (const [d, v] of r.compiled.dynamicUpdaters) {
|
|
994
|
+
const p = r.compiled.uniforms.get(d), f = gt(() => v(m), d, p?.value ?? 0, { onError: r.onDynamicError });
|
|
995
|
+
h.set(d, f);
|
|
996
|
+
}
|
|
997
|
+
const y = (d) => {
|
|
999
998
|
e.setUniform("time", e.secs), e.setUniform("resolution", [m.cols, m.rows]);
|
|
1000
|
-
for (const [p,
|
|
1001
|
-
for (const [p,
|
|
1002
|
-
if (
|
|
1003
|
-
const p =
|
|
999
|
+
for (const [p, f] of h) e.setUniform(p, f);
|
|
1000
|
+
for (const [p, f] of r.compiled.uniforms) f.isDynamic || typeof f.value == "function" || e.setUniform(p, f.value);
|
|
1001
|
+
if (r.compiled.charMapping) {
|
|
1002
|
+
const p = r.characterResolver.resolve(r.compiled.charMapping.chars, t.font);
|
|
1004
1003
|
e.setUniform("u_charMap", p), e.setUniform("u_charMapSize", p.length);
|
|
1005
1004
|
}
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1005
|
+
if (r.compiled.usesCharSource) {
|
|
1006
|
+
const p = r.compiled.charMapping ? r.compiled.charMapping.chars.length : t.font.characters.length;
|
|
1007
|
+
e.setUniform("u_charSourceCount", p);
|
|
1008
|
+
}
|
|
1009
|
+
d && (o && e.setUniform("prevCharColorBuffer", d.textures[1]), l && e.setUniform("prevCharBuffer", d.textures[0]), s && e.setUniform("prevCellColorBuffer", d.textures[2]));
|
|
1010
|
+
const v = r.compiled.externalLayers;
|
|
1011
|
+
if (v && v.size > 0 && r.externalLayerMap) for (const [p, f] of v) {
|
|
1012
|
+
const c = r.externalLayerMap.get(p);
|
|
1013
|
+
if (!c) {
|
|
1011
1014
|
console.warn(`[textmode.synth.js] External layer not found: ${p}`);
|
|
1012
1015
|
continue;
|
|
1013
1016
|
}
|
|
1014
|
-
const
|
|
1015
|
-
let
|
|
1016
|
-
|
|
1017
|
+
const g = c.getPluginState(b);
|
|
1018
|
+
let _;
|
|
1019
|
+
g?.pingPongBuffers ? _ = g.pingPongBuffers[g.pingPongIndex].textures : c.drawFramebuffer && (_ = c.drawFramebuffer.textures), _ && (f.usesChar && e.setUniform(`${f.uniformPrefix}_char`, _[0]), f.usesCharColor && e.setUniform(`${f.uniformPrefix}_primary`, _[1]), f.usesCellColor && e.setUniform(`${f.uniformPrefix}_cell`, _[2]));
|
|
1017
1020
|
}
|
|
1018
1021
|
};
|
|
1019
|
-
if (i &&
|
|
1020
|
-
const
|
|
1021
|
-
v.begin(), e.clear(), e.shader(
|
|
1022
|
-
} else
|
|
1022
|
+
if (i && r.pingPongBuffers) {
|
|
1023
|
+
const d = r.pingPongBuffers[r.pingPongIndex], v = r.pingPongBuffers[1 - r.pingPongIndex];
|
|
1024
|
+
v.begin(), e.clear(), e.shader(r.shader), y(d), e.rect(a.cols, a.rows), v.end(), n.begin(), e.clear(), e.shader(r.shader), y(d), e.rect(a.cols, a.rows), n.end(), r.pingPongIndex = 1 - r.pingPongIndex;
|
|
1025
|
+
} else n.begin(), e.clear(), e.shader(r.shader), y(null), e.rect(a.cols, a.rows), n.end();
|
|
1023
1026
|
}
|
|
1024
1027
|
function xt(t) {
|
|
1025
|
-
const e = t.getPluginState(
|
|
1028
|
+
const e = t.getPluginState(b);
|
|
1026
1029
|
e && (e.shader?.dispose && e.shader.dispose(), e.pingPongBuffers && (e.pingPongBuffers[0].dispose?.(), e.pingPongBuffers[1].dispose?.()));
|
|
1027
1030
|
}
|
|
1028
|
-
const bt = { name:
|
|
1029
|
-
yt(t), ft(e), mt(e), pt(e), e.registerLayerPreRenderHook((
|
|
1031
|
+
const bt = { name: b, version: "1.0.0", install(t, e) {
|
|
1032
|
+
yt(t), ft(e), mt(e), pt(e), e.registerLayerPreRenderHook((r) => vt(r, t)), e.registerLayerDisposedHook(xt);
|
|
1030
1033
|
}, uninstall(t, e) {
|
|
1031
|
-
const
|
|
1032
|
-
for (const a of
|
|
1033
|
-
const
|
|
1034
|
-
|
|
1034
|
+
const r = [e.layerManager.base, ...e.layerManager.all];
|
|
1035
|
+
for (const a of r) {
|
|
1036
|
+
const n = a.getPluginState(b);
|
|
1037
|
+
n && (n.shader?.dispose && n.shader.dispose(), n.pingPongBuffers && (n.pingPongBuffers[0].dispose?.(), n.pingPongBuffers[1].dispose?.()));
|
|
1035
1038
|
}
|
|
1036
1039
|
delete t.bpm, e.removeLayerExtension("synth"), e.removeLayerExtension("bpm"), e.removeLayerExtension("clearSynth");
|
|
1037
1040
|
} }, St = (t) => {
|
|
1038
|
-
const e = new
|
|
1041
|
+
const e = new S();
|
|
1039
1042
|
return e._colorSource = t, e;
|
|
1040
1043
|
}, Mt = (t, e) => {
|
|
1041
|
-
const
|
|
1042
|
-
return
|
|
1044
|
+
const r = new S();
|
|
1045
|
+
return r._charSource = t, r._charCount = e, r;
|
|
1043
1046
|
}, $t = (t) => {
|
|
1044
|
-
const e = new
|
|
1047
|
+
const e = new S();
|
|
1045
1048
|
return e._colorSource = t, e;
|
|
1046
1049
|
};
|
|
1047
1050
|
function wt(t) {
|
|
1048
|
-
return
|
|
1051
|
+
return $.gradient(t);
|
|
1049
1052
|
}
|
|
1050
1053
|
function Ft(t, e) {
|
|
1051
|
-
return
|
|
1054
|
+
return $.noise(t, e);
|
|
1052
1055
|
}
|
|
1053
|
-
function kt(t, e,
|
|
1054
|
-
return
|
|
1056
|
+
function kt(t, e, r) {
|
|
1057
|
+
return $.osc(t, e, r);
|
|
1055
1058
|
}
|
|
1056
1059
|
const Tt = (t) => {
|
|
1057
|
-
const e = new
|
|
1060
|
+
const e = new S();
|
|
1058
1061
|
return e._colorSource = t, e._cellColorSource = t, e;
|
|
1059
1062
|
};
|
|
1060
|
-
function Lt(t, e,
|
|
1061
|
-
return
|
|
1063
|
+
function Lt(t, e, r) {
|
|
1064
|
+
return $.shape(t, e, r);
|
|
1062
1065
|
}
|
|
1063
|
-
function Pt(t, e,
|
|
1064
|
-
return
|
|
1066
|
+
function Pt(t, e, r, a) {
|
|
1067
|
+
return $.solid(t, e, r, a);
|
|
1065
1068
|
}
|
|
1066
1069
|
const It = (t) => {
|
|
1067
|
-
const e =
|
|
1070
|
+
const e = $.src;
|
|
1068
1071
|
if (!t) return e();
|
|
1069
|
-
const
|
|
1070
|
-
return
|
|
1072
|
+
const r = new S(), a = t.id ?? `layer_${Date.now()}_${Math.random().toString(36).slice(2, 9)}`;
|
|
1073
|
+
return r.addExternalLayerRef({ layerId: a, layer: t }), r;
|
|
1071
1074
|
};
|
|
1072
|
-
function At(t, e,
|
|
1073
|
-
return
|
|
1075
|
+
function At(t, e, r) {
|
|
1076
|
+
return $.voronoi(t, e, r);
|
|
1074
1077
|
}
|
|
1075
1078
|
export {
|
|
1076
1079
|
bt as SynthPlugin,
|
|
1077
|
-
|
|
1080
|
+
S as SynthSource,
|
|
1078
1081
|
St as cellColor,
|
|
1079
1082
|
Mt as char,
|
|
1080
1083
|
$t as charColor,
|