textmode.synth.js 1.0.0-beta.3 → 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/README.md +0 -3
- package/dist/textmode.synth.esm.js +403 -358
- package/dist/textmode.synth.umd.js +24 -23
- 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/core/types.d.ts +8 -0
- package/dist/types/core/types.d.ts.map +1 -1
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/lifecycle/synthRender.d.ts +7 -2
- package/dist/types/lifecycle/synthRender.d.ts.map +1 -1
- package/dist/types/utils/SafeEvaluator.d.ts +59 -0
- package/dist/types/utils/SafeEvaluator.d.ts.map +1 -0
- package/dist/types/utils/index.d.ts +1 -5
- package/dist/types/utils/index.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
const
|
|
2
|
-
function
|
|
3
|
-
const e =
|
|
4
|
-
${e.returnType} ${t.name}(${
|
|
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
|
+
function D(t) {
|
|
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 };
|
|
8
8
|
}
|
|
9
|
-
class
|
|
9
|
+
class j {
|
|
10
10
|
_transforms = /* @__PURE__ */ new Map();
|
|
11
11
|
_processedCache = /* @__PURE__ */ new Map();
|
|
12
12
|
register(e) {
|
|
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());
|
|
@@ -51,35 +51,35 @@ class X {
|
|
|
51
51
|
return this._transforms.size;
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
|
-
const k = new
|
|
55
|
-
class
|
|
54
|
+
const k = new j(), O = /* @__PURE__ */ new Set(["src"]);
|
|
55
|
+
class G {
|
|
56
56
|
_generatedFunctions = {};
|
|
57
57
|
_synthSourceClass = null;
|
|
58
58
|
setSynthSourceClass(e) {
|
|
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
|
|
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
|
|
82
|
-
return
|
|
81
|
+
const i = new a(), m = l.map((h, y) => s[y] ?? h.default);
|
|
82
|
+
return i.addTransform(o, m);
|
|
83
83
|
};
|
|
84
84
|
}
|
|
85
85
|
return this._generatedFunctions = e, e;
|
|
@@ -87,25 +87,25 @@ class j {
|
|
|
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(),
|
|
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
|
}
|
|
99
99
|
}
|
|
100
|
-
const P = new
|
|
100
|
+
const P = new G(), q = { name: "osc", type: "src", inputs: [{ name: "frequency", type: "float", default: 60 }, { name: "sync", type: "float", default: 0.1 }, { name: "offset", type: "float", default: 0 }], glsl: `
|
|
101
101
|
vec2 st = _st;
|
|
102
102
|
float r = sin((st.x - offset/frequency + time*sync) * frequency) * 0.5 + 0.5;
|
|
103
103
|
float g = sin((st.x + time*sync) * frequency) * 0.5 + 0.5;
|
|
104
104
|
float b = sin((st.x + offset/frequency + time*sync) * frequency) * 0.5 + 0.5;
|
|
105
105
|
return vec4(r, g, b, 1.0);
|
|
106
|
-
`, description: "Generate oscillating color pattern" },
|
|
106
|
+
`, description: "Generate oscillating color pattern" }, K = { name: "noise", type: "src", inputs: [{ name: "scale", type: "float", default: 10 }, { name: "offset", type: "float", default: 0.1 }], glsl: `
|
|
107
107
|
return vec4(vec3(_noise(vec3(_st * scale, offset * time))), 1.0);
|
|
108
|
-
`, description: "Generate noise pattern" },
|
|
108
|
+
`, description: "Generate noise pattern" }, Q = { name: "voronoi", type: "src", inputs: [{ name: "scale", type: "float", default: 5 }, { name: "speed", type: "float", default: 0.3 }, { name: "blending", type: "float", default: 0.3 }], glsl: `
|
|
109
109
|
vec3 color = vec3(0.0);
|
|
110
110
|
vec2 st = _st * scale;
|
|
111
111
|
vec2 i_st = floor(st);
|
|
@@ -129,59 +129,59 @@ const P = new j(), D = { name: "osc", type: "src", inputs: [{ name: "frequency",
|
|
|
129
129
|
color += dot(m_point, vec2(0.3, 0.6));
|
|
130
130
|
color *= 1.0 - blending * m_dist;
|
|
131
131
|
return vec4(color, 1.0);
|
|
132
|
-
`, description: "Generate voronoi pattern" },
|
|
132
|
+
`, description: "Generate voronoi pattern" }, H = { name: "gradient", type: "src", inputs: [{ name: "speed", type: "float", default: 0 }], glsl: `
|
|
133
133
|
return vec4(_st, sin(time * speed), 1.0);
|
|
134
|
-
`, description: "Generate gradient pattern" },
|
|
134
|
+
`, description: "Generate gradient pattern" }, W = { name: "shape", type: "src", inputs: [{ name: "sides", type: "float", default: 3 }, { name: "radius", type: "float", default: 0.3 }, { name: "smoothing", type: "float", default: 0.01 }], glsl: `
|
|
135
135
|
vec2 st = _st * 2.0 - 1.0;
|
|
136
136
|
float a = atan(st.x, st.y) + 3.1416;
|
|
137
137
|
float r = (2.0 * 3.1416) / sides;
|
|
138
138
|
float d = cos(floor(0.5 + a/r) * r - a) * length(st);
|
|
139
139
|
return vec4(vec3(1.0 - smoothstep(radius, radius + smoothing + 0.0000001, d)), 1.0);
|
|
140
|
-
`, description: "Generate polygon shape" },
|
|
140
|
+
`, description: "Generate polygon shape" }, J = { name: "solid", type: "src", inputs: [{ name: "r", type: "float", default: 0 }, { name: "g", type: "float", default: 0 }, { name: "b", type: "float", default: 0 }, { name: "a", type: "float", default: 1 }], glsl: `
|
|
141
141
|
return vec4(r, g, b, a);
|
|
142
|
-
`, description: "Generate solid color" },
|
|
142
|
+
`, description: "Generate solid color" }, Z = { name: "src", type: "src", inputs: [], glsl: `
|
|
143
143
|
return texture(prevCharColorBuffer, fract(_st));
|
|
144
|
-
`, description: "Sample the previous frame for feedback effects. Context-aware: automatically samples the appropriate texture based on where it is used (char, charColor, or cellColor context)." },
|
|
144
|
+
`, description: "Sample the previous frame for feedback effects. Context-aware: automatically samples the appropriate texture based on where it is used (char, charColor, or cellColor context)." }, ee = [q, K, Q, H, W, J, Z], te = { name: "rotate", type: "coord", inputs: [{ name: "angle", type: "float", default: 10 }, { name: "speed", type: "float", default: 0 }], glsl: `
|
|
145
145
|
vec2 xy = _st - vec2(0.5);
|
|
146
146
|
float ang = angle + speed * time;
|
|
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;
|
|
159
159
|
return fract(st);
|
|
160
|
-
`, description: "Scroll coordinates" },
|
|
160
|
+
`, description: "Scroll coordinates" }, ae = { name: "scrollX", type: "coord", inputs: [{ name: "scrollX", type: "float", default: 0.5 }, { name: "speed", type: "float", default: 0 }], glsl: `
|
|
161
161
|
vec2 st = _st;
|
|
162
162
|
st.x += scrollX + time * speed;
|
|
163
163
|
return fract(st);
|
|
164
|
-
`, description: "Scroll X coordinate" },
|
|
164
|
+
`, description: "Scroll X coordinate" }, oe = { name: "scrollY", type: "coord", inputs: [{ name: "scrollY", type: "float", default: 0.5 }, { name: "speed", type: "float", default: 0 }], glsl: `
|
|
165
165
|
vec2 st = _st;
|
|
166
166
|
st.y += scrollY + time * speed;
|
|
167
167
|
return fract(st);
|
|
168
|
-
`, description: "Scroll Y coordinate" },
|
|
168
|
+
`, description: "Scroll Y coordinate" }, se = { name: "pixelate", type: "coord", inputs: [{ name: "pixelX", type: "float", default: 20 }, { name: "pixelY", type: "float", default: 20 }], glsl: `
|
|
169
169
|
vec2 xy = vec2(pixelX, pixelY);
|
|
170
170
|
return (floor(_st * xy) + 0.5) / xy;
|
|
171
|
-
`, description: "Pixelate coordinates" },
|
|
171
|
+
`, description: "Pixelate coordinates" }, ce = { name: "repeat", type: "coord", inputs: [{ name: "repeatX", type: "float", default: 3 }, { name: "repeatY", type: "float", default: 3 }, { name: "offsetX", type: "float", default: 0 }, { name: "offsetY", type: "float", default: 0 }], glsl: `
|
|
172
172
|
vec2 st = _st * vec2(repeatX, repeatY);
|
|
173
173
|
st.x += step(1.0, mod(st.y, 2.0)) * offsetX;
|
|
174
174
|
st.y += step(1.0, mod(st.x, 2.0)) * offsetY;
|
|
175
175
|
return fract(st);
|
|
176
|
-
`, description: "Repeat pattern" },
|
|
176
|
+
`, description: "Repeat pattern" }, le = { name: "repeatX", type: "coord", inputs: [{ name: "reps", type: "float", default: 3 }, { name: "offset", type: "float", default: 0 }], glsl: `
|
|
177
177
|
vec2 st = _st * vec2(reps, 1.0);
|
|
178
178
|
st.y += step(1.0, mod(st.x, 2.0)) * offset;
|
|
179
179
|
return fract(st);
|
|
180
|
-
`, description: "Repeat pattern horizontally" },
|
|
180
|
+
`, description: "Repeat pattern horizontally" }, ie = { name: "repeatY", type: "coord", inputs: [{ name: "reps", type: "float", default: 3 }, { name: "offset", type: "float", default: 0 }], glsl: `
|
|
181
181
|
vec2 st = _st * vec2(1.0, reps);
|
|
182
182
|
st.x += step(1.0, mod(st.y, 2.0)) * offset;
|
|
183
183
|
return fract(st);
|
|
184
|
-
`, description: "Repeat pattern vertically" },
|
|
184
|
+
`, description: "Repeat pattern vertically" }, ue = { name: "kaleid", type: "coord", inputs: [{ name: "nSides", type: "float", default: 4 }], glsl: `
|
|
185
185
|
vec2 st = _st;
|
|
186
186
|
st -= 0.5;
|
|
187
187
|
float r = length(st);
|
|
@@ -190,97 +190,97 @@ const P = new j(), D = { 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" },
|
|
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
|
-
`, description: "Adjust brightness" },
|
|
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);
|
|
197
197
|
return vec4(c.rgb, _c0.a);
|
|
198
|
-
`, description: "Adjust contrast" },
|
|
198
|
+
`, description: "Adjust contrast" }, de = { name: "invert", type: "color", inputs: [{ name: "amount", type: "float", default: 1 }], glsl: `
|
|
199
199
|
return vec4((1.0 - _c0.rgb) * amount + _c0.rgb * (1.0 - amount), _c0.a);
|
|
200
|
-
`, description: "Invert colors" },
|
|
200
|
+
`, description: "Invert colors" }, he = { name: "saturate", type: "color", inputs: [{ name: "amount", type: "float", default: 2 }], glsl: `
|
|
201
201
|
const vec3 W = vec3(0.2125, 0.7154, 0.0721);
|
|
202
202
|
vec3 intensity = vec3(dot(_c0.rgb, W));
|
|
203
203
|
return vec4(mix(intensity, _c0.rgb, amount), _c0.a);
|
|
204
|
-
`, description: "Adjust saturation" },
|
|
204
|
+
`, description: "Adjust saturation" }, ye = { name: "hue", type: "color", inputs: [{ name: "hue", type: "float", default: 0.4 }], glsl: `
|
|
205
205
|
vec3 c = _rgbToHsv(_c0.rgb);
|
|
206
206
|
c.r += hue;
|
|
207
207
|
return vec4(_hsvToRgb(c), _c0.a);
|
|
208
|
-
`, description: "Shift hue" },
|
|
208
|
+
`, description: "Shift hue" }, ge = { name: "colorama", type: "color", inputs: [{ name: "amount", type: "float", default: 5e-3 }], glsl: `
|
|
209
209
|
vec3 c = _rgbToHsv(_c0.rgb);
|
|
210
210
|
c += vec3(amount);
|
|
211
211
|
c = _hsvToRgb(c);
|
|
212
212
|
c = fract(c);
|
|
213
213
|
return vec4(c, _c0.a);
|
|
214
|
-
`, description: "Color cycle effect" },
|
|
214
|
+
`, description: "Color cycle effect" }, _e = { name: "posterize", type: "color", inputs: [{ name: "bins", type: "float", default: 3 }, { name: "gamma", type: "float", default: 0.6 }], glsl: `
|
|
215
215
|
vec4 c2 = pow(_c0, vec4(gamma));
|
|
216
216
|
c2 *= vec4(bins);
|
|
217
217
|
c2 = floor(c2);
|
|
218
218
|
c2 /= vec4(bins);
|
|
219
219
|
c2 = pow(c2, vec4(1.0 / gamma));
|
|
220
220
|
return vec4(c2.xyz, _c0.a);
|
|
221
|
-
`, description: "Posterize colors" },
|
|
221
|
+
`, description: "Posterize colors" }, ve = { name: "luma", type: "color", inputs: [{ name: "threshold", type: "float", default: 0.5 }, { name: "tolerance", type: "float", default: 0.1 }], glsl: `
|
|
222
222
|
float a = smoothstep(threshold - (tolerance + 0.0000001), threshold + (tolerance + 0.0000001), _luminance(_c0.rgb));
|
|
223
223
|
return vec4(_c0.rgb * a, a);
|
|
224
|
-
`, description: "Luma key" },
|
|
224
|
+
`, description: "Luma key" }, xe = { name: "thresh", type: "color", inputs: [{ name: "threshold", type: "float", default: 0.5 }, { name: "tolerance", type: "float", default: 0.04 }], glsl: `
|
|
225
225
|
return vec4(vec3(smoothstep(threshold - (tolerance + 0.0000001), threshold + (tolerance + 0.0000001), _luminance(_c0.rgb))), _c0.a);
|
|
226
|
-
`, description: "Threshold" },
|
|
226
|
+
`, description: "Threshold" }, Ce = { name: "color", type: "color", inputs: [{ name: "r", type: "float", default: 1 }, { name: "g", type: "float", default: 1 }, { name: "b", type: "float", default: 1 }, { name: "a", type: "float", default: 1 }], glsl: `
|
|
227
227
|
vec4 c = vec4(r, g, b, a);
|
|
228
228
|
vec4 pos = step(0.0, c);
|
|
229
229
|
return vec4(mix((1.0 - _c0.rgb) * abs(c.rgb), c.rgb * _c0.rgb, pos.rgb), c.a * _c0.a);
|
|
230
|
-
`, description: "Multiply by color" },
|
|
230
|
+
`, description: "Multiply by color" }, be = { name: "r", type: "color", inputs: [{ name: "scale", type: "float", default: 1 }, { name: "offset", type: "float", default: 0 }], glsl: `
|
|
231
231
|
return vec4(_c0.r * scale + offset);
|
|
232
|
-
`, description: "Extract red channel" },
|
|
232
|
+
`, description: "Extract red channel" }, Se = { name: "g", type: "color", inputs: [{ name: "scale", type: "float", default: 1 }, { name: "offset", type: "float", default: 0 }], glsl: `
|
|
233
233
|
return vec4(_c0.g * scale + offset);
|
|
234
|
-
`, description: "Extract green channel" },
|
|
234
|
+
`, description: "Extract green channel" }, Me = { name: "b", type: "color", inputs: [{ name: "scale", type: "float", default: 1 }, { name: "offset", type: "float", default: 0 }], glsl: `
|
|
235
235
|
return vec4(_c0.b * scale + offset);
|
|
236
|
-
`, description: "Extract blue channel" },
|
|
236
|
+
`, description: "Extract blue channel" }, $e = { name: "shift", type: "color", inputs: [{ name: "r", type: "float", default: 0.5 }, { name: "g", type: "float", default: 0 }, { name: "b", type: "float", default: 0 }, { name: "a", type: "float", default: 0 }], glsl: `
|
|
237
237
|
vec4 c2 = vec4(_c0);
|
|
238
238
|
c2.r += fract(r);
|
|
239
239
|
c2.g += fract(g);
|
|
240
240
|
c2.b += fract(b);
|
|
241
241
|
c2.a += fract(a);
|
|
242
242
|
return vec4(c2.rgba);
|
|
243
|
-
`, description: "Shift color channels by adding offset values" },
|
|
243
|
+
`, description: "Shift color channels by adding offset values" }, we = { name: "gamma", type: "color", inputs: [{ name: "amount", type: "float", default: 1 }], glsl: `
|
|
244
244
|
return vec4(pow(max(vec3(0.0), _c0.rgb), vec3(1.0 / amount)), _c0.a);
|
|
245
|
-
`, description: "Apply gamma correction" },
|
|
245
|
+
`, description: "Apply gamma correction" }, Fe = { name: "levels", type: "color", inputs: [{ name: "inMin", type: "float", default: 0 }, { name: "inMax", type: "float", default: 1 }, { name: "outMin", type: "float", default: 0 }, { name: "outMax", type: "float", default: 1 }, { name: "gamma", type: "float", default: 1 }], glsl: `
|
|
246
246
|
vec3 v = clamp((_c0.rgb - vec3(inMin)) / (vec3(inMax - inMin) + 0.0000001), 0.0, 1.0);
|
|
247
247
|
v = pow(v, vec3(1.0 / gamma));
|
|
248
248
|
v = mix(vec3(outMin), vec3(outMax), v);
|
|
249
249
|
return vec4(v, _c0.a);
|
|
250
|
-
`, description: "Adjust input/output levels and gamma" },
|
|
250
|
+
`, description: "Adjust input/output levels and gamma" }, ke = { name: "clamp", type: "color", inputs: [{ name: "min", type: "float", default: 0 }, { name: "max", type: "float", default: 1 }], glsl: `
|
|
251
251
|
return vec4(clamp(_c0.rgb, vec3(min), vec3(max)), _c0.a);
|
|
252
|
-
`, description: "Clamp color values to a range" },
|
|
252
|
+
`, description: "Clamp color values to a range" }, Te = [pe, me, de, he, ye, ge, _e, ve, xe, Ce, be, Se, Me, $e, we, Fe, ke], Le = { name: "add", type: "combine", inputs: [{ name: "amount", type: "float", default: 1 }], glsl: `
|
|
253
253
|
return (_c0 + _c1) * amount + _c0 * (1.0 - amount);
|
|
254
|
-
`, description: "Add another source" },
|
|
254
|
+
`, description: "Add another source" }, Pe = { name: "sub", type: "combine", inputs: [{ name: "amount", type: "float", default: 1 }], glsl: `
|
|
255
255
|
return (_c0 - _c1) * amount + _c0 * (1.0 - amount);
|
|
256
|
-
`, description: "Subtract another source" },
|
|
256
|
+
`, description: "Subtract another source" }, Ie = { name: "mult", type: "combine", inputs: [{ name: "amount", type: "float", default: 1 }], glsl: `
|
|
257
257
|
return _c0 * (1.0 - amount) + (_c0 * _c1) * amount;
|
|
258
|
-
`, description: "Multiply with another source" },
|
|
258
|
+
`, description: "Multiply with another source" }, Ae = { name: "blend", type: "combine", inputs: [{ name: "amount", type: "float", default: 0.5 }], glsl: `
|
|
259
259
|
return _c0 * (1.0 - amount) + _c1 * amount;
|
|
260
|
-
`, description: "Blend with another source" },
|
|
260
|
+
`, description: "Blend with another source" }, Re = { name: "diff", type: "combine", inputs: [], glsl: `
|
|
261
261
|
return vec4(abs(_c0.rgb - _c1.rgb), max(_c0.a, _c1.a));
|
|
262
|
-
`, description: "Difference with another source" },
|
|
262
|
+
`, description: "Difference with another source" }, ze = { name: "layer", type: "combine", inputs: [], glsl: `
|
|
263
263
|
return vec4(mix(_c0.rgb, _c1.rgb, _c1.a), clamp(_c0.a + _c1.a, 0.0, 1.0));
|
|
264
|
-
`, description: "Layer another source on top" },
|
|
264
|
+
`, description: "Layer another source on top" }, Oe = { name: "mask", type: "combine", inputs: [], glsl: `
|
|
265
265
|
float a = _luminance(_c1.rgb);
|
|
266
266
|
return vec4(_c0.rgb * a, a * _c0.a);
|
|
267
|
-
`, description: "Mask with another source" },
|
|
267
|
+
`, description: "Mask with another source" }, Ue = [Le, Pe, Ie, Ae, Re, ze, Oe], Ve = { name: "modulate", type: "combineCoord", inputs: [{ name: "amount", type: "float", default: 0.1 }], glsl: `
|
|
268
268
|
return _st + _c0.xy * amount;
|
|
269
|
-
`, description: "Modulate coordinates with another source" },
|
|
269
|
+
`, description: "Modulate coordinates with another source" }, Ee = { name: "modulateScale", type: "combineCoord", inputs: [{ name: "multiple", type: "float", default: 1 }, { name: "offset", type: "float", default: 1 }], glsl: `
|
|
270
270
|
vec2 xy = _st - vec2(0.5);
|
|
271
271
|
xy *= (1.0 / vec2(offset + multiple * _c0.r, offset + multiple * _c0.g));
|
|
272
272
|
xy += vec2(0.5);
|
|
273
273
|
return xy;
|
|
274
|
-
`, description: "Modulate scale with another source" },
|
|
274
|
+
`, description: "Modulate scale with another source" }, Be = { name: "modulateRotate", type: "combineCoord", inputs: [{ name: "multiple", type: "float", default: 1 }, { name: "offset", type: "float", default: 0 }], glsl: `
|
|
275
275
|
vec2 xy = _st - vec2(0.5);
|
|
276
276
|
float angle = offset + _c0.x * multiple;
|
|
277
277
|
xy = mat2(cos(angle), -sin(angle), sin(angle), cos(angle)) * xy;
|
|
278
278
|
xy += 0.5;
|
|
279
279
|
return xy;
|
|
280
|
-
`, description: "Modulate rotation with another source" },
|
|
280
|
+
`, description: "Modulate rotation with another source" }, Ne = { name: "modulatePixelate", type: "combineCoord", inputs: [{ name: "multiple", type: "float", default: 10 }, { name: "offset", type: "float", default: 3 }], glsl: `
|
|
281
281
|
vec2 xy = vec2(offset + _c0.x * multiple, offset + _c0.y * multiple);
|
|
282
282
|
return (floor(_st * xy) + 0.5) / xy;
|
|
283
|
-
`, description: "Modulate pixelation with another source" },
|
|
283
|
+
`, description: "Modulate pixelation with another source" }, Ye = { name: "modulateKaleid", type: "combineCoord", inputs: [{ name: "nSides", type: "float", default: 4 }], glsl: `
|
|
284
284
|
vec2 st = _st - 0.5;
|
|
285
285
|
float r = length(st);
|
|
286
286
|
float a = atan(st.y, st.x);
|
|
@@ -288,40 +288,40 @@ const P = new j(), D = { name: "osc", type: "src", inputs: [{ name: "frequency",
|
|
|
288
288
|
a = mod(a, pi / nSides);
|
|
289
289
|
a = abs(a - pi / nSides / 2.0);
|
|
290
290
|
return (_c0.r + r) * vec2(cos(a), sin(a));
|
|
291
|
-
`, description: "Modulate kaleidoscope with another source" },
|
|
291
|
+
`, description: "Modulate kaleidoscope with another source" }, Xe = { name: "modulateScrollX", type: "combineCoord", inputs: [{ name: "scrollX", type: "float", default: 0.5 }, { name: "speed", type: "float", default: 0 }], glsl: `
|
|
292
292
|
vec2 st = _st;
|
|
293
293
|
st.x += _c0.r * scrollX + time * speed;
|
|
294
294
|
return fract(st);
|
|
295
|
-
`, description: "Modulate X scroll with another source" },
|
|
295
|
+
`, description: "Modulate X scroll with another source" }, De = { name: "modulateScrollY", type: "combineCoord", inputs: [{ name: "scrollY", type: "float", default: 0.5 }, { name: "speed", type: "float", default: 0 }], glsl: `
|
|
296
296
|
vec2 st = _st;
|
|
297
297
|
st.y += _c0.r * scrollY + time * speed;
|
|
298
298
|
return fract(st);
|
|
299
|
-
`, description: "Modulate Y scroll with another source" },
|
|
299
|
+
`, description: "Modulate Y scroll with another source" }, je = { name: "modulateRepeat", type: "combineCoord", inputs: [{ name: "repeatX", type: "float", default: 3 }, { name: "repeatY", type: "float", default: 3 }, { name: "offsetX", type: "float", default: 0.5 }, { name: "offsetY", type: "float", default: 0.5 }], glsl: `
|
|
300
300
|
vec2 st = _st * vec2(repeatX, repeatY);
|
|
301
301
|
st.x += step(1.0, mod(st.y, 2.0)) + _c0.r * offsetX;
|
|
302
302
|
st.y += step(1.0, mod(st.x, 2.0)) + _c0.g * offsetY;
|
|
303
303
|
return fract(st);
|
|
304
|
-
`, description: "Modulate repeat pattern with another source" },
|
|
304
|
+
`, description: "Modulate repeat pattern with another source" }, Ge = { name: "modulateRepeatX", type: "combineCoord", inputs: [{ name: "reps", type: "float", default: 3 }, { name: "offset", type: "float", default: 0.5 }], glsl: `
|
|
305
305
|
vec2 st = _st * vec2(reps, 1.0);
|
|
306
306
|
st.y += step(1.0, mod(st.x, 2.0)) + _c0.r * offset;
|
|
307
307
|
return fract(st);
|
|
308
|
-
`, description: "Modulate X repeat with another source" },
|
|
308
|
+
`, description: "Modulate X repeat with another source" }, qe = { name: "modulateRepeatY", type: "combineCoord", inputs: [{ name: "reps", type: "float", default: 3 }, { name: "offset", type: "float", default: 0.5 }], glsl: `
|
|
309
309
|
vec2 st = _st * vec2(1.0, reps);
|
|
310
310
|
st.x += step(1.0, mod(st.y, 2.0)) + _c0.r * offset;
|
|
311
311
|
return fract(st);
|
|
312
|
-
`, description: "Modulate Y repeat with another source" },
|
|
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
|
-
`, description: "Modulate coordinates based on hue differences" },
|
|
315
|
-
class
|
|
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 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,10 +418,10 @@ 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
|
|
426
|
-
return (t - e) * (
|
|
421
|
+
function We(t, e, r, a, n) {
|
|
422
|
+
return (t - e) * (n - a) / (r - e) + a;
|
|
427
423
|
}
|
|
428
|
-
function
|
|
424
|
+
function Je() {
|
|
429
425
|
"fast" in Array.prototype || (Array.prototype.fast = function(t = 1) {
|
|
430
426
|
return this._speed = t, this;
|
|
431
427
|
}, Array.prototype.smooth = function(t = 1) {
|
|
@@ -435,25 +431,25 @@ function Qe() {
|
|
|
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
|
-
function
|
|
443
|
-
const
|
|
444
|
-
let
|
|
438
|
+
function Ze(t, e) {
|
|
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
|
-
function
|
|
447
|
+
function et(t) {
|
|
452
448
|
return Array.isArray(t) && t.length > 0 && typeof t[0] == "number";
|
|
453
449
|
}
|
|
454
|
-
|
|
455
|
-
const
|
|
456
|
-
class
|
|
450
|
+
Je(), k.registerMany(He), P.setSynthSourceClass(S), P.injectMethods(S.prototype);
|
|
451
|
+
const $ = P.generateStandaloneFunctions(), b = "textmode.synth.js";
|
|
452
|
+
class tt {
|
|
457
453
|
_usesFeedback = !1;
|
|
458
454
|
_usesCharFeedback = !1;
|
|
459
455
|
_usesCellColorFeedback = !1;
|
|
@@ -488,26 +484,26 @@ class Je {
|
|
|
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,86 +525,86 @@ class Ze {
|
|
|
529
525
|
this._externalLayers.clear(), this._counter = 0, this._layerIdToPrefix.clear();
|
|
530
526
|
}
|
|
531
527
|
}
|
|
532
|
-
const
|
|
533
|
-
class
|
|
534
|
-
getContextAwareGlslFunction(e,
|
|
535
|
-
return
|
|
536
|
-
}
|
|
537
|
-
getFunctionName(e,
|
|
538
|
-
return e.name !== "src" ? e.name : a &&
|
|
539
|
-
}
|
|
540
|
-
generateTransformCode(e,
|
|
541
|
-
const
|
|
542
|
-
let
|
|
543
|
-
switch (
|
|
528
|
+
const nt = { char: "prevCharBuffer", charColor: "prevCharColorBuffer", cellColor: "prevCellColorBuffer", main: "prevCharColorBuffer" };
|
|
529
|
+
class at {
|
|
530
|
+
getContextAwareGlslFunction(e, r, a, n, o) {
|
|
531
|
+
return r !== "src" ? e.glslFunction : n && o ? this._generateExternalSrcFunction(n, a, o) : this._generateSelfFeedbackSrcFunction(a);
|
|
532
|
+
}
|
|
533
|
+
getFunctionName(e, r, a, n) {
|
|
534
|
+
return e.name !== "src" ? e.name : a && n ? `src_ext_${n(a.layerId)}_${r}` : `src_${r}`;
|
|
535
|
+
}
|
|
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
|
}
|
|
587
583
|
}
|
|
588
|
-
class
|
|
584
|
+
class ot {
|
|
589
585
|
_uniforms = /* @__PURE__ */ new Map();
|
|
590
586
|
_dynamicUpdaters = /* @__PURE__ */ new Map();
|
|
591
|
-
processArgument(e,
|
|
592
|
-
if (
|
|
593
|
-
const
|
|
594
|
-
return this._uniforms.set(
|
|
587
|
+
processArgument(e, r, a) {
|
|
588
|
+
if (et(e)) {
|
|
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);
|
|
@@ -624,7 +620,7 @@ function x(t) {
|
|
|
624
620
|
const e = t.toString();
|
|
625
621
|
return e.includes(".") ? e : e + ".0";
|
|
626
622
|
}
|
|
627
|
-
const
|
|
623
|
+
const st = `
|
|
628
624
|
// Utility functions
|
|
629
625
|
float _luminance(vec3 rgb) {
|
|
630
626
|
const vec3 W = vec3(0.2125, 0.7154, 0.0721);
|
|
@@ -721,22 +717,22 @@ float _noise(vec3 v) {
|
|
|
721
717
|
return 42.0 * dot(m * m, vec4(dot(p0, x0), dot(p1, x1), dot(p2, x2), dot(p3, x3)));
|
|
722
718
|
}
|
|
723
719
|
`;
|
|
724
|
-
function
|
|
725
|
-
const { uniforms: e, glslFunctions:
|
|
720
|
+
function ct(t) {
|
|
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
|
-
|
|
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,89 +768,91 @@ 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
|
|
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
|
}
|
|
793
|
-
function
|
|
794
|
-
return new
|
|
790
|
+
function A(t) {
|
|
791
|
+
return new it().compile(t);
|
|
795
792
|
}
|
|
796
|
-
class
|
|
797
|
-
_uniformManager = new
|
|
798
|
-
_feedbackTracker = new
|
|
799
|
-
_externalLayerManager = new
|
|
800
|
-
_codeGenerator = new
|
|
793
|
+
class it {
|
|
794
|
+
_uniformManager = new ot();
|
|
795
|
+
_feedbackTracker = new tt();
|
|
796
|
+
_externalLayerManager = new rt();
|
|
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:
|
|
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
|
|
829
|
-
this._mainCode.push(` vec2 ${s} = ${
|
|
830
|
-
const
|
|
831
|
-
const
|
|
832
|
-
if (!
|
|
833
|
-
const
|
|
834
|
-
|
|
835
|
-
const
|
|
836
|
-
this._glslFunctions.add(
|
|
837
|
-
const
|
|
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
|
-
|
|
840
|
-
const
|
|
841
|
-
|
|
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,29 +860,29 @@ class st {
|
|
|
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
|
-
class
|
|
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
|
|
882
|
-
const m =
|
|
883
|
-
if (
|
|
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);
|
|
882
|
+
if (h !== void 0) o[i] = s.indexOf(h);
|
|
884
883
|
else {
|
|
885
|
-
const
|
|
886
|
-
o[
|
|
884
|
+
const y = l.get(" ");
|
|
885
|
+
o[i] = y !== void 0 ? s.indexOf(y) : 0;
|
|
887
886
|
}
|
|
888
887
|
}
|
|
889
888
|
return this._resolvedIndices = o, this._lastFontCharacterCount = a, this._lastChars = e, o;
|
|
@@ -892,157 +891,203 @@ class ct {
|
|
|
892
891
|
this._resolvedIndices = void 0, this._lastFontCharacterCount = 0, this._lastChars = "";
|
|
893
892
|
}
|
|
894
893
|
}
|
|
895
|
-
function
|
|
896
|
-
return { source: t.source ?? new
|
|
894
|
+
function V(t = {}) {
|
|
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
|
-
function
|
|
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
|
-
function
|
|
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
|
-
function
|
|
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
|
-
let
|
|
918
|
-
function
|
|
919
|
-
|
|
916
|
+
let E = 60;
|
|
917
|
+
function dt(t) {
|
|
918
|
+
E = t;
|
|
920
919
|
}
|
|
921
|
-
function
|
|
922
|
-
return
|
|
920
|
+
function ht() {
|
|
921
|
+
return E;
|
|
923
922
|
}
|
|
924
|
-
function
|
|
923
|
+
function yt(t) {
|
|
925
924
|
t.bpm = function(e) {
|
|
926
|
-
return
|
|
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
|
}
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
const
|
|
956
|
-
|
|
957
|
-
|
|
949
|
+
let B = null;
|
|
950
|
+
function Ct(t) {
|
|
951
|
+
B = t;
|
|
952
|
+
}
|
|
953
|
+
function U(t, e, r) {
|
|
954
|
+
const a = r ?? B;
|
|
955
|
+
if (a) try {
|
|
956
|
+
a(t, e);
|
|
957
|
+
} catch {
|
|
958
|
+
}
|
|
959
|
+
}
|
|
960
|
+
function gt(t, e, r, a = {}) {
|
|
961
|
+
let n;
|
|
962
|
+
try {
|
|
963
|
+
n = t();
|
|
964
|
+
} catch (o) {
|
|
965
|
+
return U(o, e, a.onError), r;
|
|
966
|
+
}
|
|
967
|
+
return _t(n) ? n : (U(new Error(`[textmode.synth.js] Invalid dynamic parameter value for "${e}": ${N(n)}`), e, a.onError), r);
|
|
968
|
+
}
|
|
969
|
+
function N(t) {
|
|
970
|
+
if (t === void 0) return "undefined";
|
|
971
|
+
if (t === null) return "null";
|
|
972
|
+
if (typeof t == "number") {
|
|
973
|
+
if (Number.isNaN(t)) return "NaN";
|
|
974
|
+
if (!Number.isFinite(t)) return t > 0 ? "Infinity" : "-Infinity";
|
|
975
|
+
}
|
|
976
|
+
if (Array.isArray(t)) {
|
|
977
|
+
const e = t.findIndex((r) => typeof r != "number" || !Number.isFinite(r));
|
|
978
|
+
if (e >= 0) return `array with invalid element at index ${e}: ${N(t[e])}`;
|
|
979
|
+
}
|
|
980
|
+
return String(t);
|
|
981
|
+
}
|
|
982
|
+
function _t(t) {
|
|
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)));
|
|
984
|
+
}
|
|
985
|
+
async function vt(t, e) {
|
|
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) => {
|
|
958
998
|
e.setUniform("time", e.secs), e.setUniform("resolution", [m.cols, m.rows]);
|
|
959
|
-
for (const [
|
|
960
|
-
for (const [
|
|
961
|
-
if (
|
|
962
|
-
const
|
|
963
|
-
e.setUniform("u_charMap",
|
|
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);
|
|
1003
|
+
e.setUniform("u_charMap", p), e.setUniform("u_charMapSize", p.length);
|
|
1004
|
+
}
|
|
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);
|
|
964
1008
|
}
|
|
965
|
-
|
|
966
|
-
const v =
|
|
967
|
-
if (v && v.size > 0 &&
|
|
968
|
-
const
|
|
969
|
-
if (!
|
|
970
|
-
console.warn(`[textmode.synth.js] External layer not found: ${
|
|
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) {
|
|
1014
|
+
console.warn(`[textmode.synth.js] External layer not found: ${p}`);
|
|
971
1015
|
continue;
|
|
972
1016
|
}
|
|
973
|
-
const
|
|
974
|
-
let
|
|
975
|
-
|
|
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]));
|
|
976
1020
|
}
|
|
977
1021
|
};
|
|
978
|
-
if (
|
|
979
|
-
const
|
|
980
|
-
v.begin(), e.clear(), e.shader(
|
|
981
|
-
} 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();
|
|
982
1026
|
}
|
|
983
|
-
function
|
|
984
|
-
const e = t.getPluginState(
|
|
1027
|
+
function xt(t) {
|
|
1028
|
+
const e = t.getPluginState(b);
|
|
985
1029
|
e && (e.shader?.dispose && e.shader.dispose(), e.pingPongBuffers && (e.pingPongBuffers[0].dispose?.(), e.pingPongBuffers[1].dispose?.()));
|
|
986
1030
|
}
|
|
987
|
-
const
|
|
988
|
-
|
|
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);
|
|
989
1033
|
}, uninstall(t, e) {
|
|
990
|
-
const
|
|
991
|
-
for (const a of
|
|
992
|
-
const
|
|
993
|
-
|
|
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?.()));
|
|
994
1038
|
}
|
|
995
1039
|
delete t.bpm, e.removeLayerExtension("synth"), e.removeLayerExtension("bpm"), e.removeLayerExtension("clearSynth");
|
|
996
|
-
} },
|
|
997
|
-
const e = new
|
|
1040
|
+
} }, St = (t) => {
|
|
1041
|
+
const e = new S();
|
|
998
1042
|
return e._colorSource = t, e;
|
|
999
|
-
},
|
|
1000
|
-
const
|
|
1001
|
-
return
|
|
1002
|
-
},
|
|
1003
|
-
const e = new
|
|
1043
|
+
}, Mt = (t, e) => {
|
|
1044
|
+
const r = new S();
|
|
1045
|
+
return r._charSource = t, r._charCount = e, r;
|
|
1046
|
+
}, $t = (t) => {
|
|
1047
|
+
const e = new S();
|
|
1004
1048
|
return e._colorSource = t, e;
|
|
1005
1049
|
};
|
|
1006
|
-
function
|
|
1007
|
-
return
|
|
1050
|
+
function wt(t) {
|
|
1051
|
+
return $.gradient(t);
|
|
1008
1052
|
}
|
|
1009
|
-
function
|
|
1010
|
-
return
|
|
1053
|
+
function Ft(t, e) {
|
|
1054
|
+
return $.noise(t, e);
|
|
1011
1055
|
}
|
|
1012
|
-
function
|
|
1013
|
-
return
|
|
1056
|
+
function kt(t, e, r) {
|
|
1057
|
+
return $.osc(t, e, r);
|
|
1014
1058
|
}
|
|
1015
|
-
const
|
|
1016
|
-
const e = new
|
|
1059
|
+
const Tt = (t) => {
|
|
1060
|
+
const e = new S();
|
|
1017
1061
|
return e._colorSource = t, e._cellColorSource = t, e;
|
|
1018
1062
|
};
|
|
1019
|
-
function
|
|
1020
|
-
return
|
|
1063
|
+
function Lt(t, e, r) {
|
|
1064
|
+
return $.shape(t, e, r);
|
|
1021
1065
|
}
|
|
1022
|
-
function
|
|
1023
|
-
return
|
|
1066
|
+
function Pt(t, e, r, a) {
|
|
1067
|
+
return $.solid(t, e, r, a);
|
|
1024
1068
|
}
|
|
1025
|
-
const
|
|
1026
|
-
const e =
|
|
1069
|
+
const It = (t) => {
|
|
1070
|
+
const e = $.src;
|
|
1027
1071
|
if (!t) return e();
|
|
1028
|
-
const
|
|
1029
|
-
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;
|
|
1030
1074
|
};
|
|
1031
|
-
function
|
|
1032
|
-
return
|
|
1075
|
+
function At(t, e, r) {
|
|
1076
|
+
return $.voronoi(t, e, r);
|
|
1033
1077
|
}
|
|
1034
1078
|
export {
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1079
|
+
bt as SynthPlugin,
|
|
1080
|
+
S as SynthSource,
|
|
1081
|
+
St as cellColor,
|
|
1082
|
+
Mt as char,
|
|
1083
|
+
$t as charColor,
|
|
1084
|
+
wt as gradient,
|
|
1085
|
+
Ft as noise,
|
|
1086
|
+
kt as osc,
|
|
1087
|
+
Tt as paint,
|
|
1088
|
+
Ct as setGlobalErrorCallback,
|
|
1089
|
+
Lt as shape,
|
|
1090
|
+
Pt as solid,
|
|
1091
|
+
It as src,
|
|
1092
|
+
At as voronoi
|
|
1048
1093
|
};
|