@nexart/codemode-sdk 1.5.0 → 1.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/CHANGELOG.md +289 -0
  2. package/CODE_MODE_PROTOCOL.md +471 -0
  3. package/README.md +232 -55
  4. package/dist/builder-manifest.d.ts +79 -0
  5. package/dist/builder-manifest.d.ts.map +1 -0
  6. package/dist/builder-manifest.js +97 -0
  7. package/dist/core-index.d.ts +21 -0
  8. package/dist/core-index.d.ts.map +1 -0
  9. package/dist/core-index.js +26 -0
  10. package/dist/engine.d.ts +17 -39
  11. package/dist/engine.d.ts.map +1 -1
  12. package/dist/engine.js +52 -253
  13. package/dist/execute.d.ts +46 -0
  14. package/dist/execute.d.ts.map +1 -0
  15. package/dist/execute.js +282 -0
  16. package/dist/index.d.ts +24 -17
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js +30 -16
  19. package/dist/noise-bridge.d.ts +44 -0
  20. package/dist/noise-bridge.d.ts.map +1 -0
  21. package/dist/noise-bridge.js +68 -0
  22. package/dist/noise-engine.d.ts +74 -0
  23. package/dist/noise-engine.d.ts.map +1 -0
  24. package/dist/noise-engine.js +132 -0
  25. package/dist/noise-sketches/fractalNoise.d.ts +11 -0
  26. package/dist/noise-sketches/fractalNoise.d.ts.map +1 -0
  27. package/dist/noise-sketches/fractalNoise.js +121 -0
  28. package/dist/noise-sketches/index.d.ts +21 -0
  29. package/dist/noise-sketches/index.d.ts.map +1 -0
  30. package/dist/noise-sketches/index.js +28 -0
  31. package/dist/sound-bridge.d.ts +89 -0
  32. package/dist/sound-bridge.d.ts.map +1 -0
  33. package/dist/sound-bridge.js +128 -0
  34. package/dist/soundart-engine.d.ts +87 -0
  35. package/dist/soundart-engine.d.ts.map +1 -0
  36. package/dist/soundart-engine.js +173 -0
  37. package/dist/soundart-sketches/chladniBloom.d.ts +3 -0
  38. package/dist/soundart-sketches/chladniBloom.d.ts.map +1 -0
  39. package/dist/soundart-sketches/chladniBloom.js +53 -0
  40. package/dist/soundart-sketches/dualVortex.d.ts +3 -0
  41. package/dist/soundart-sketches/dualVortex.d.ts.map +1 -0
  42. package/dist/soundart-sketches/dualVortex.js +67 -0
  43. package/dist/soundart-sketches/geometryIllusion.d.ts +3 -0
  44. package/dist/soundart-sketches/geometryIllusion.d.ts.map +1 -0
  45. package/dist/soundart-sketches/geometryIllusion.js +89 -0
  46. package/dist/soundart-sketches/index.d.ts +39 -0
  47. package/dist/soundart-sketches/index.d.ts.map +1 -0
  48. package/dist/soundart-sketches/index.js +72 -0
  49. package/dist/soundart-sketches/isoflow.d.ts +3 -0
  50. package/dist/soundart-sketches/isoflow.d.ts.map +1 -0
  51. package/dist/soundart-sketches/isoflow.js +60 -0
  52. package/dist/soundart-sketches/loomWeave.d.ts +3 -0
  53. package/dist/soundart-sketches/loomWeave.d.ts.map +1 -0
  54. package/dist/soundart-sketches/loomWeave.js +59 -0
  55. package/dist/soundart-sketches/noiseTerraces.d.ts +3 -0
  56. package/dist/soundart-sketches/noiseTerraces.d.ts.map +1 -0
  57. package/dist/soundart-sketches/noiseTerraces.js +53 -0
  58. package/dist/soundart-sketches/orb.d.ts +3 -0
  59. package/dist/soundart-sketches/orb.d.ts.map +1 -0
  60. package/dist/soundart-sketches/orb.js +50 -0
  61. package/dist/soundart-sketches/pixelGlyphs.d.ts +3 -0
  62. package/dist/soundart-sketches/pixelGlyphs.d.ts.map +1 -0
  63. package/dist/soundart-sketches/pixelGlyphs.js +72 -0
  64. package/dist/soundart-sketches/prismFlowFields.d.ts +3 -0
  65. package/dist/soundart-sketches/prismFlowFields.d.ts.map +1 -0
  66. package/dist/soundart-sketches/prismFlowFields.js +51 -0
  67. package/dist/soundart-sketches/radialBurst.d.ts +3 -0
  68. package/dist/soundart-sketches/radialBurst.d.ts.map +1 -0
  69. package/dist/soundart-sketches/radialBurst.js +60 -0
  70. package/dist/soundart-sketches/resonantSoundBodies.d.ts +3 -0
  71. package/dist/soundart-sketches/resonantSoundBodies.d.ts.map +1 -0
  72. package/dist/soundart-sketches/resonantSoundBodies.js +89 -0
  73. package/dist/soundart-sketches/rings.d.ts +11 -0
  74. package/dist/soundart-sketches/rings.d.ts.map +1 -0
  75. package/dist/soundart-sketches/rings.js +89 -0
  76. package/dist/soundart-sketches/squares.d.ts +3 -0
  77. package/dist/soundart-sketches/squares.d.ts.map +1 -0
  78. package/dist/soundart-sketches/squares.js +52 -0
  79. package/dist/soundart-sketches/waveStripes.d.ts +3 -0
  80. package/dist/soundart-sketches/waveStripes.d.ts.map +1 -0
  81. package/dist/soundart-sketches/waveStripes.js +44 -0
  82. package/dist/types.d.ts +41 -1
  83. package/dist/types.d.ts.map +1 -1
  84. package/dist/types.js +1 -1
  85. package/package.json +24 -15
@@ -0,0 +1,132 @@
1
+ /**
2
+ * Noise → Code Mode Engine
3
+ *
4
+ * This is the orchestrator that runs Noise rendering through the Code Mode engine.
5
+ * It replaces the legacy p5.js-based NoiseCanvas with a protocol-compliant pipeline.
6
+ *
7
+ * Architecture:
8
+ * 1. NoiseParams from UI state
9
+ * 2. NoiseParams → NoiseSnapshot conversion
10
+ * 3. NoiseSnapshot injected as N.* globals into Code Mode
11
+ * 4. Noise sketch executed via Code Mode runtime
12
+ * 5. Result: PNG output (deterministic)
13
+ */
14
+ import { createNoiseSnapshot, validateNoiseSnapshot } from '../../shared/noiseSnapshot';
15
+ import { createP5Runtime } from './p5-runtime';
16
+ import { createNoiseGlobals, injectNoiseGlobals } from './noise-bridge';
17
+ import { getNoiseSketch } from './noise-sketches';
18
+ /**
19
+ * Render noise via Code Mode runtime
20
+ *
21
+ * This is the main entry point for protocol-compliant noise rendering.
22
+ * All rendering goes through the Code Mode runtime for determinism.
23
+ */
24
+ export async function renderNoiseViaCodeMode(options) {
25
+ const { params, canvas, config, onProgress } = options;
26
+ // Protocol enforcement logging
27
+ console.log('[Noise] Protocol enforcement: HARD | renderedVia: codemode');
28
+ onProgress?.(0.1);
29
+ // Create and validate snapshot
30
+ const rawSnapshot = createNoiseSnapshot(params);
31
+ const snapshot = validateNoiseSnapshot(rawSnapshot);
32
+ onProgress?.(0.2);
33
+ // Create N.* globals
34
+ const noiseGlobals = createNoiseGlobals(snapshot);
35
+ // Get the noise sketch
36
+ const sketchName = 'fractalNoise';
37
+ const sketchCode = getNoiseSketch(sketchName);
38
+ // Inject N.* globals into sketch
39
+ const injectedCode = injectNoiseGlobals(sketchCode, noiseGlobals);
40
+ onProgress?.(0.3);
41
+ // Set canvas dimensions
42
+ canvas.width = config.width;
43
+ canvas.height = config.height;
44
+ // Create P5 runtime with correct signature
45
+ const runtimeConfig = {
46
+ seed: config.seed,
47
+ };
48
+ const runtime = createP5Runtime(canvas, config.width, config.height, runtimeConfig);
49
+ onProgress?.(0.5);
50
+ // Build globals with all runtime functions and noise globals
51
+ const globals = {
52
+ ...runtime,
53
+ width: config.width,
54
+ height: config.height,
55
+ };
56
+ // Execute the sketch
57
+ try {
58
+ executeNoiseSketch(injectedCode, globals);
59
+ onProgress?.(0.9);
60
+ console.log('[Noise] Rendered via Code Mode runtime');
61
+ // Build metadata
62
+ const metadata = {
63
+ mode: 'Noise',
64
+ timestamp: new Date().toISOString(),
65
+ enforcement: 'hard',
66
+ renderedVia: 'codemode',
67
+ noiseParams: {
68
+ scale: snapshot.scale,
69
+ octaves: snapshot.octaves,
70
+ persistence: snapshot.persistence,
71
+ lacunarity: snapshot.lacunarity,
72
+ cellDensity: snapshot.cellDensity,
73
+ cellDistortion: snapshot.cellDistortion,
74
+ blendMode: snapshot.blendMode,
75
+ },
76
+ generationParams: {
77
+ seed: config.seed,
78
+ canvasSize: { width: config.width, height: config.height },
79
+ },
80
+ };
81
+ onProgress?.(1.0);
82
+ return {
83
+ mode: 'noise',
84
+ snapshot,
85
+ metadata,
86
+ };
87
+ }
88
+ catch (error) {
89
+ console.error('[Noise] Code Mode execution failed:', error);
90
+ throw error;
91
+ }
92
+ }
93
+ /**
94
+ * Execute a noise sketch string in the context of the runtime globals
95
+ */
96
+ function executeNoiseSketch(code, globals) {
97
+ const globalNames = Object.keys(globals);
98
+ const globalValues = Object.values(globals);
99
+ // Wrap the sketch code to call setup()
100
+ const wrappedCode = `
101
+ ${code}
102
+
103
+ // Execute setup (noise is static - single frame)
104
+ if (typeof setup === 'function') {
105
+ setup();
106
+ }
107
+ `;
108
+ // Create and execute the function
109
+ const sketchFunction = new Function(...globalNames, wrappedCode);
110
+ sketchFunction(...globalValues);
111
+ }
112
+ /**
113
+ * Compile noise params to a Code Mode system
114
+ * This produces a reproducible system definition
115
+ */
116
+ export function compileNoiseSystem(params) {
117
+ const snapshot = validateNoiseSnapshot(createNoiseSnapshot(params));
118
+ const noiseGlobals = createNoiseGlobals(snapshot);
119
+ const sketchCode = injectNoiseGlobals(getNoiseSketch('fractalNoise'), noiseGlobals);
120
+ return {
121
+ sketchCode,
122
+ snapshot,
123
+ seed: params.seed,
124
+ };
125
+ }
126
+ /**
127
+ * Check if noise can be rendered via Code Mode
128
+ * (Always true - no legacy fallback)
129
+ */
130
+ export function canRenderNoiseViaCodeMode() {
131
+ return true;
132
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Fractal Noise - Code Mode Sketch
3
+ *
4
+ * This sketch implements Perlin FBM and Cellular noise rendering
5
+ * through the Code Mode p5-runtime. Uses N.* globals for all parameters.
6
+ *
7
+ * Original: client/src/components/noise-canvas-simple.tsx
8
+ */
9
+ export declare const FRACTAL_NOISE_SKETCH = "\n// Fractal Noise - Code Mode Sketch\n// Uses N.* noise globals and standard p5-like functions\n\nfunction setup() {\n // Set seeded random for reproducibility\n randomSeed(N.seed);\n noiseSeed(N.seed);\n \n // Set background color\n background(N.bgR, N.bgG, N.bgB);\n \n // Noise rendering parameters\n const adjustedScale = N.scale * (1 / N.zoom) * 0.05;\n const cellSize = 4; // Fixed for quality\n \n // Generate cellular points if needed\n const numPoints = Math.floor(20 + N.cellDensity * 180);\n const cellPoints = [];\n for (let i = 0; i < numPoints; i++) {\n cellPoints.push([random(0, width), random(0, height)]);\n }\n \n // Helper: Perlin FBM (Fractional Brownian Motion)\n function perlinFBM(x, y, scale) {\n let value = 0;\n let amplitude = 1;\n let frequency = 1;\n let maxValue = 0;\n \n const oct = Math.min(N.octaves, 6); // Cap for performance\n \n for (let i = 0; i < oct; i++) {\n value += noise(x * scale * frequency, y * scale * frequency) * amplitude;\n maxValue += amplitude;\n amplitude *= N.persistence;\n frequency *= N.lacunarity;\n }\n \n return value / maxValue;\n }\n \n // Helper: Cellular noise (Worley)\n function cellularNoise(x, y, points) {\n let sampleX = x;\n let sampleY = y;\n \n // Warp distortion if using warp mode\n if (N.isWarp && N.cellDistortion > 0) {\n const distortionAmount = N.cellDistortion * 100;\n sampleX += noise(x * 0.01, y * 0.01) * distortionAmount;\n sampleY += noise(y * 0.01, x * 0.01) * distortionAmount;\n }\n \n // Find distances to closest points\n let minDist = 999999;\n let secondMinDist = 999999;\n \n for (let i = 0; i < points.length; i++) {\n const px = points[i][0];\n const py = points[i][1];\n const dx = sampleX - px;\n const dy = sampleY - py;\n const dist = Math.sqrt(dx * dx + dy * dy);\n \n if (dist < minDist) {\n secondMinDist = minDist;\n minDist = dist;\n } else if (dist < secondMinDist) {\n secondMinDist = dist;\n }\n }\n \n // Normalize distance\n return Math.min(1.0, (secondMinDist - minDist) / 50);\n }\n \n // Render the noise grid\n noStroke();\n \n for (let y = 0; y < height; y += cellSize) {\n for (let x = 0; x < width; x += cellSize) {\n // Calculate Perlin value\n const perlinValue = perlinFBM(x, y, adjustedScale);\n \n // Calculate final value based on blend mode\n let finalValue = perlinValue;\n \n if (!N.isPerlinOnly) {\n const cellValue = cellularNoise(x, y, cellPoints);\n \n if (N.isBlend) {\n finalValue = perlinValue * cellValue;\n } else if (N.isWarp) {\n finalValue = (perlinValue + cellValue) / 2;\n } else if (N.isInterleave) {\n finalValue = (Math.floor(x / 20) + Math.floor(y / 20)) % 2 === 0\n ? perlinValue\n : cellValue;\n }\n }\n \n // Set opacity based on noise value\n const alpha = map(finalValue, 0, 1, 0, 255);\n \n // Fill with noise color and calculated alpha\n fill(N.noiseR, N.noiseG, N.noiseB, alpha);\n rect(x, y, cellSize, cellSize);\n }\n }\n}\n";
10
+ export default FRACTAL_NOISE_SKETCH;
11
+ //# sourceMappingURL=fractalNoise.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fractalNoise.d.ts","sourceRoot":"","sources":["../../noise-sketches/fractalNoise.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,eAAO,MAAM,oBAAoB,4sGA+GhC,CAAC;AAEF,eAAe,oBAAoB,CAAC"}
@@ -0,0 +1,121 @@
1
+ /**
2
+ * Fractal Noise - Code Mode Sketch
3
+ *
4
+ * This sketch implements Perlin FBM and Cellular noise rendering
5
+ * through the Code Mode p5-runtime. Uses N.* globals for all parameters.
6
+ *
7
+ * Original: client/src/components/noise-canvas-simple.tsx
8
+ */
9
+ export const FRACTAL_NOISE_SKETCH = `
10
+ // Fractal Noise - Code Mode Sketch
11
+ // Uses N.* noise globals and standard p5-like functions
12
+
13
+ function setup() {
14
+ // Set seeded random for reproducibility
15
+ randomSeed(N.seed);
16
+ noiseSeed(N.seed);
17
+
18
+ // Set background color
19
+ background(N.bgR, N.bgG, N.bgB);
20
+
21
+ // Noise rendering parameters
22
+ const adjustedScale = N.scale * (1 / N.zoom) * 0.05;
23
+ const cellSize = 4; // Fixed for quality
24
+
25
+ // Generate cellular points if needed
26
+ const numPoints = Math.floor(20 + N.cellDensity * 180);
27
+ const cellPoints = [];
28
+ for (let i = 0; i < numPoints; i++) {
29
+ cellPoints.push([random(0, width), random(0, height)]);
30
+ }
31
+
32
+ // Helper: Perlin FBM (Fractional Brownian Motion)
33
+ function perlinFBM(x, y, scale) {
34
+ let value = 0;
35
+ let amplitude = 1;
36
+ let frequency = 1;
37
+ let maxValue = 0;
38
+
39
+ const oct = Math.min(N.octaves, 6); // Cap for performance
40
+
41
+ for (let i = 0; i < oct; i++) {
42
+ value += noise(x * scale * frequency, y * scale * frequency) * amplitude;
43
+ maxValue += amplitude;
44
+ amplitude *= N.persistence;
45
+ frequency *= N.lacunarity;
46
+ }
47
+
48
+ return value / maxValue;
49
+ }
50
+
51
+ // Helper: Cellular noise (Worley)
52
+ function cellularNoise(x, y, points) {
53
+ let sampleX = x;
54
+ let sampleY = y;
55
+
56
+ // Warp distortion if using warp mode
57
+ if (N.isWarp && N.cellDistortion > 0) {
58
+ const distortionAmount = N.cellDistortion * 100;
59
+ sampleX += noise(x * 0.01, y * 0.01) * distortionAmount;
60
+ sampleY += noise(y * 0.01, x * 0.01) * distortionAmount;
61
+ }
62
+
63
+ // Find distances to closest points
64
+ let minDist = 999999;
65
+ let secondMinDist = 999999;
66
+
67
+ for (let i = 0; i < points.length; i++) {
68
+ const px = points[i][0];
69
+ const py = points[i][1];
70
+ const dx = sampleX - px;
71
+ const dy = sampleY - py;
72
+ const dist = Math.sqrt(dx * dx + dy * dy);
73
+
74
+ if (dist < minDist) {
75
+ secondMinDist = minDist;
76
+ minDist = dist;
77
+ } else if (dist < secondMinDist) {
78
+ secondMinDist = dist;
79
+ }
80
+ }
81
+
82
+ // Normalize distance
83
+ return Math.min(1.0, (secondMinDist - minDist) / 50);
84
+ }
85
+
86
+ // Render the noise grid
87
+ noStroke();
88
+
89
+ for (let y = 0; y < height; y += cellSize) {
90
+ for (let x = 0; x < width; x += cellSize) {
91
+ // Calculate Perlin value
92
+ const perlinValue = perlinFBM(x, y, adjustedScale);
93
+
94
+ // Calculate final value based on blend mode
95
+ let finalValue = perlinValue;
96
+
97
+ if (!N.isPerlinOnly) {
98
+ const cellValue = cellularNoise(x, y, cellPoints);
99
+
100
+ if (N.isBlend) {
101
+ finalValue = perlinValue * cellValue;
102
+ } else if (N.isWarp) {
103
+ finalValue = (perlinValue + cellValue) / 2;
104
+ } else if (N.isInterleave) {
105
+ finalValue = (Math.floor(x / 20) + Math.floor(y / 20)) % 2 === 0
106
+ ? perlinValue
107
+ : cellValue;
108
+ }
109
+ }
110
+
111
+ // Set opacity based on noise value
112
+ const alpha = map(finalValue, 0, 1, 0, 255);
113
+
114
+ // Fill with noise color and calculated alpha
115
+ fill(N.noiseR, N.noiseG, N.noiseB, alpha);
116
+ rect(x, y, cellSize, cellSize);
117
+ }
118
+ }
119
+ }
120
+ `;
121
+ export default FRACTAL_NOISE_SKETCH;
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Noise Sketches Index
3
+ *
4
+ * Exports all available noise sketch generators for the Code Mode runtime.
5
+ */
6
+ import FRACTAL_NOISE_SKETCH from './fractalNoise';
7
+ export type NoiseSketchName = 'fractalNoise';
8
+ /**
9
+ * Get a noise sketch by name
10
+ */
11
+ export declare function getNoiseSketch(name: NoiseSketchName): string;
12
+ /**
13
+ * Check if a sketch name is valid
14
+ */
15
+ export declare function isValidNoiseSketch(name: string): name is NoiseSketchName;
16
+ /**
17
+ * Get list of all available noise sketch names
18
+ */
19
+ export declare function getAvailableNoiseSketchNames(): NoiseSketchName[];
20
+ export { FRACTAL_NOISE_SKETCH };
21
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../noise-sketches/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,oBAAoB,MAAM,gBAAgB,CAAC;AAElD,MAAM,MAAM,eAAe,GAAG,cAAc,CAAC;AAM7C;;GAEG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,eAAe,GAAG,MAAM,CAE5D;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,IAAI,eAAe,CAExE;AAED;;GAEG;AACH,wBAAgB,4BAA4B,IAAI,eAAe,EAAE,CAEhE;AAED,OAAO,EAAE,oBAAoB,EAAE,CAAC"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Noise Sketches Index
3
+ *
4
+ * Exports all available noise sketch generators for the Code Mode runtime.
5
+ */
6
+ import FRACTAL_NOISE_SKETCH from './fractalNoise';
7
+ const NOISE_SKETCHES = {
8
+ fractalNoise: FRACTAL_NOISE_SKETCH,
9
+ };
10
+ /**
11
+ * Get a noise sketch by name
12
+ */
13
+ export function getNoiseSketch(name) {
14
+ return NOISE_SKETCHES[name];
15
+ }
16
+ /**
17
+ * Check if a sketch name is valid
18
+ */
19
+ export function isValidNoiseSketch(name) {
20
+ return name in NOISE_SKETCHES;
21
+ }
22
+ /**
23
+ * Get list of all available noise sketch names
24
+ */
25
+ export function getAvailableNoiseSketchNames() {
26
+ return Object.keys(NOISE_SKETCHES);
27
+ }
28
+ export { FRACTAL_NOISE_SKETCH };
@@ -0,0 +1,89 @@
1
+ /**
2
+ * SoundArt → Code Mode Bridge
3
+ *
4
+ * This module injects sound-derived parameters into the Code Mode runtime
5
+ * as read-only `S.*` globals. It is the integration layer between sound
6
+ * analysis and generative art rendering.
7
+ *
8
+ * Usage in Code Mode sketches:
9
+ * S.volume // 0-100: Overall loudness
10
+ * S.bass // 0-100: Bass frequency energy
11
+ * S.treble // 0-100: Treble frequency energy
12
+ * S.aggression // 0-100: Intensity/harshness
13
+ * S.t // 0-1: Normalized time position
14
+ * etc.
15
+ */
16
+ import type { SoundSnapshot } from '../../shared/soundSnapshot';
17
+ /**
18
+ * The injected sound globals interface
19
+ * This is what sketches see as `S`
20
+ */
21
+ export interface SoundGlobals extends Readonly<SoundSnapshot> {
22
+ }
23
+ /**
24
+ * Create a frozen, read-only sound globals object from a snapshot
25
+ */
26
+ export declare function createSoundGlobals(snapshot: SoundSnapshot): SoundGlobals;
27
+ /**
28
+ * Create empty/default sound globals for testing or fallback
29
+ */
30
+ export declare function createEmptySoundGlobals(): SoundGlobals;
31
+ /**
32
+ * Inject sound globals into the p5 runtime context
33
+ *
34
+ * This adds the `S` global object to the runtime so sketches can access
35
+ * sound-derived parameters like S.volume, S.bass, etc.
36
+ *
37
+ * @param runtime - The p5 runtime object
38
+ * @param snapshot - The sound snapshot to inject
39
+ * @returns The runtime with S globals added
40
+ */
41
+ export declare function injectSoundGlobals<T extends Record<string, any>>(runtime: T, snapshot: SoundSnapshot): T & {
42
+ S: SoundGlobals;
43
+ };
44
+ /**
45
+ * Helper function to map S.* values to useful ranges
46
+ *
47
+ * Usage in sketches:
48
+ * const density = mapSound(S.volume, 100, 2000) // Map 0-100 to 100-2000
49
+ */
50
+ export declare function createSoundHelpers(): {
51
+ /**
52
+ * Map a sound value (0-100) to a custom range
53
+ */
54
+ mapSound: (value: number, outMin: number, outMax: number) => number;
55
+ /**
56
+ * Map a sound value (0-100) with easing
57
+ */
58
+ mapSoundEased: (value: number, outMin: number, outMax: number, easing?: number) => number;
59
+ /**
60
+ * Get a value that oscillates based on sound
61
+ */
62
+ soundOscillate: (base: number, amplitude: number, soundValue: number) => number;
63
+ };
64
+ /**
65
+ * Convert SoundSnapshot hue (0-100) to degrees (0-360)
66
+ */
67
+ export declare function hueToDegrees(hue: number): number;
68
+ /**
69
+ * Generate a color palette from sound parameters
70
+ *
71
+ * @param snapshot - The sound snapshot
72
+ * @param paletteSize - Number of colors to generate
73
+ * @returns Array of HSL color strings
74
+ */
75
+ export declare function generateSoundPalette(snapshot: SoundSnapshot, paletteSize?: number): string[];
76
+ /**
77
+ * Infer a genre profile from sound parameters
78
+ * This helps sketches adapt their visual style to the audio content
79
+ */
80
+ export type EnergyLevel = 'low' | 'mid' | 'high';
81
+ export type StructureType = 'chaotic' | 'organic' | 'geometric';
82
+ export type ClarityLevel = 'muddy' | 'clear' | 'sharp';
83
+ export interface GenreProfile {
84
+ energy: EnergyLevel;
85
+ structure: StructureType;
86
+ clarity: ClarityLevel;
87
+ }
88
+ export declare function inferGenreProfile(snapshot: SoundSnapshot): GenreProfile;
89
+ //# sourceMappingURL=sound-bridge.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sound-bridge.d.ts","sourceRoot":"","sources":["../sound-bridge.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAc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C;CACvB;AAED,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,aAAa,GAAG,YAAY,CAiBvE"}
@@ -0,0 +1,128 @@
1
+ /**
2
+ * SoundArt → Code Mode Bridge
3
+ *
4
+ * This module injects sound-derived parameters into the Code Mode runtime
5
+ * as read-only `S.*` globals. It is the integration layer between sound
6
+ * analysis and generative art rendering.
7
+ *
8
+ * Usage in Code Mode sketches:
9
+ * S.volume // 0-100: Overall loudness
10
+ * S.bass // 0-100: Bass frequency energy
11
+ * S.treble // 0-100: Treble frequency energy
12
+ * S.aggression // 0-100: Intensity/harshness
13
+ * S.t // 0-1: Normalized time position
14
+ * etc.
15
+ */
16
+ import { createEmptySoundSnapshot, freezeSoundSnapshot } from '../../shared/soundSnapshot';
17
+ /**
18
+ * Create a frozen, read-only sound globals object from a snapshot
19
+ */
20
+ export function createSoundGlobals(snapshot) {
21
+ return freezeSoundSnapshot(snapshot);
22
+ }
23
+ /**
24
+ * Create empty/default sound globals for testing or fallback
25
+ */
26
+ export function createEmptySoundGlobals() {
27
+ return freezeSoundSnapshot(createEmptySoundSnapshot());
28
+ }
29
+ /**
30
+ * Inject sound globals into the p5 runtime context
31
+ *
32
+ * This adds the `S` global object to the runtime so sketches can access
33
+ * sound-derived parameters like S.volume, S.bass, etc.
34
+ *
35
+ * @param runtime - The p5 runtime object
36
+ * @param snapshot - The sound snapshot to inject
37
+ * @returns The runtime with S globals added
38
+ */
39
+ export function injectSoundGlobals(runtime, snapshot) {
40
+ const globals = createSoundGlobals(snapshot);
41
+ // Create a proxy to make S immutable and prevent modification
42
+ const immutableS = new Proxy(globals, {
43
+ set() {
44
+ console.warn('[SoundBridge] S.* globals are read-only');
45
+ return false;
46
+ },
47
+ deleteProperty() {
48
+ console.warn('[SoundBridge] Cannot delete S.* properties');
49
+ return false;
50
+ },
51
+ defineProperty() {
52
+ console.warn('[SoundBridge] Cannot define new S.* properties');
53
+ return false;
54
+ }
55
+ });
56
+ return {
57
+ ...runtime,
58
+ S: immutableS
59
+ };
60
+ }
61
+ /**
62
+ * Helper function to map S.* values to useful ranges
63
+ *
64
+ * Usage in sketches:
65
+ * const density = mapSound(S.volume, 100, 2000) // Map 0-100 to 100-2000
66
+ */
67
+ export function createSoundHelpers() {
68
+ return {
69
+ /**
70
+ * Map a sound value (0-100) to a custom range
71
+ */
72
+ mapSound: (value, outMin, outMax) => {
73
+ return outMin + (value / 100) * (outMax - outMin);
74
+ },
75
+ /**
76
+ * Map a sound value (0-100) with easing
77
+ */
78
+ mapSoundEased: (value, outMin, outMax, easing = 2) => {
79
+ const t = Math.pow(value / 100, easing);
80
+ return outMin + t * (outMax - outMin);
81
+ },
82
+ /**
83
+ * Get a value that oscillates based on sound
84
+ */
85
+ soundOscillate: (base, amplitude, soundValue) => {
86
+ return base + Math.sin(soundValue * Math.PI / 50) * amplitude;
87
+ }
88
+ };
89
+ }
90
+ /**
91
+ * Convert SoundSnapshot hue (0-100) to degrees (0-360)
92
+ */
93
+ export function hueToDegrees(hue) {
94
+ return (hue / 100) * 360;
95
+ }
96
+ /**
97
+ * Generate a color palette from sound parameters
98
+ *
99
+ * @param snapshot - The sound snapshot
100
+ * @param paletteSize - Number of colors to generate
101
+ * @returns Array of HSL color strings
102
+ */
103
+ export function generateSoundPalette(snapshot, paletteSize = 6) {
104
+ const mainHue = hueToDegrees(snapshot.hue);
105
+ const hueShift = 20 + (snapshot.harmonicity / 100) * 40; // 20-60 degrees
106
+ const sat = 60 + (snapshot.treble / 100) * 30; // 60-90%
107
+ const light = 70 + (snapshot.bass / 100) * 25; // 70-95%
108
+ const palette = [];
109
+ for (let i = 0; i < paletteSize; i++) {
110
+ const hue = (mainHue + i * hueShift) % 360;
111
+ const satVar = sat - (i % 2) * 10;
112
+ const lightVar = light - (i % 3) * 5;
113
+ palette.push(`hsl(${hue}, ${satVar}%, ${lightVar}%)`);
114
+ }
115
+ return palette;
116
+ }
117
+ export function inferGenreProfile(snapshot) {
118
+ // Energy based on volume and aggression
119
+ const energy = (snapshot.volume > 60 || snapshot.aggression > 60) ? 'high' :
120
+ (snapshot.volume > 30) ? 'mid' : 'low';
121
+ // Structure based on rhythmicity and aggression
122
+ const structure = (snapshot.rhythmicity > 50 && snapshot.dynamicRange < 25) ? 'geometric' :
123
+ (snapshot.aggression > 60 && snapshot.dynamicRange > 50) ? 'chaotic' : 'organic';
124
+ // Clarity based on brightness
125
+ const clarity = (snapshot.brightness > 60) ? 'sharp' :
126
+ (snapshot.brightness > 40) ? 'clear' : 'muddy';
127
+ return { energy, structure, clarity };
128
+ }
@@ -0,0 +1,87 @@
1
+ /**
2
+ * SoundArt → Code Mode Engine
3
+ *
4
+ * This is the orchestrator that runs SoundArt styles through the Code Mode engine.
5
+ * It replaces the old Canvas2D-based SoundArt renderer with a Code Mode pipeline.
6
+ *
7
+ * Architecture:
8
+ * 1. Sound analysis produces SoundFeatures (unchanged)
9
+ * 2. SoundFeatures → SoundSnapshot conversion
10
+ * 3. SoundSnapshot injected as S.* globals into Code Mode
11
+ * 4. SoundArt sketch executed via Code Mode runtime
12
+ * 5. Result: PNG or MP4 output
13
+ */
14
+ import type { SoundSnapshot, SoundFeatures } from '../../shared/soundSnapshot';
15
+ import { type SoundArtSketchName } from './soundart-sketches';
16
+ export interface TweakParams {
17
+ volumeRangeFactor?: number;
18
+ centroidBrightnessFactor?: number;
19
+ aggressionPaletteFactor?: number;
20
+ rhythmPatternFactor?: number;
21
+ harmonySmoothnessFactor?: number;
22
+ attackSharpnessFactor?: number;
23
+ dynamicRangeVariationFactor?: number;
24
+ bassThicknessFactor?: number;
25
+ trebleSharpnessFactor?: number;
26
+ }
27
+ export interface SoundArtEngineConfig {
28
+ width: number;
29
+ height: number;
30
+ seed?: number;
31
+ backgroundMode?: 'rgb' | 'black' | 'white';
32
+ tweakParams?: TweakParams;
33
+ }
34
+ export interface SoundArtRenderOptions {
35
+ style: SoundArtSketchName;
36
+ sound: SoundFeatures;
37
+ canvas: HTMLCanvasElement;
38
+ config: SoundArtEngineConfig;
39
+ onProgress?: (progress: number) => void;
40
+ }
41
+ export interface SoundArtRenderResult {
42
+ style: SoundArtSketchName;
43
+ mode: 'soundart';
44
+ snapshot: SoundSnapshot;
45
+ metadata: SoundArtMetadata;
46
+ }
47
+ export interface SoundArtMetadata {
48
+ mode: 'SoundArt';
49
+ style: SoundArtSketchName;
50
+ timestamp: string;
51
+ soundFeatures: {
52
+ duration: number;
53
+ amplitude: number;
54
+ frequency: number;
55
+ bass: number;
56
+ treble: number;
57
+ aggression: number;
58
+ };
59
+ effects: {
60
+ timeFilter: boolean;
61
+ backgroundMode: string;
62
+ };
63
+ generationParams: {
64
+ seed: number;
65
+ canvasSize: {
66
+ width: number;
67
+ height: number;
68
+ };
69
+ };
70
+ }
71
+ /**
72
+ * Render a SoundArt style using Code Mode
73
+ *
74
+ * This is the main entry point for the new SoundArt → Code Mode pipeline.
75
+ */
76
+ export declare function renderSoundArtViaCodeMode(options: SoundArtRenderOptions): Promise<SoundArtRenderResult>;
77
+ /**
78
+ * Check if a SoundArt style can be rendered via Code Mode
79
+ */
80
+ export declare function canRenderViaCodeMode(style: SoundArtSketchName): boolean;
81
+ /**
82
+ * Get the list of SoundArt styles available via Code Mode
83
+ */
84
+ export declare function getCodeModeAvailableStyles(): SoundArtSketchName[];
85
+ export type { SoundSnapshot, SoundFeatures } from '../../shared/soundSnapshot';
86
+ export type { SoundArtSketchName } from './soundart-sketches';
87
+ //# sourceMappingURL=soundart-engine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"soundart-engine.d.ts","sourceRoot":"","sources":["../soundart-engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAI/E,OAAO,EAAqB,KAAK,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAEjF,MAAM,WAAW,WAAW;IAC1B,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,wBAAw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