@nexart/codemode-sdk 1.8.1 → 1.8.2

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 (137) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/LICENSE.md +5 -5
  3. package/README.md +72 -11
  4. package/dist/sdk/codemode/core-index.d.ts +6 -4
  5. package/dist/sdk/codemode/core-index.d.ts.map +1 -1
  6. package/dist/sdk/codemode/core-index.js +6 -4
  7. package/dist/{entry → sdk/codemode/entry}/browser.d.ts +5 -2
  8. package/dist/sdk/codemode/entry/browser.d.ts.map +1 -0
  9. package/dist/{entry → sdk/codemode/entry}/browser.js +10 -4
  10. package/dist/{entry → sdk/codemode/entry}/node.d.ts +2 -1
  11. package/dist/sdk/codemode/entry/node.d.ts.map +1 -0
  12. package/dist/{entry → sdk/codemode/entry}/node.js +2 -1
  13. package/dist/{runtime.d.ts → sdk/codemode/runtime.d.ts} +2 -2
  14. package/dist/sdk/codemode/runtime.d.ts.map +1 -0
  15. package/dist/{runtime.js → sdk/codemode/runtime.js} +3 -2
  16. package/dist/sdk/codemode/static-engine.d.ts.map +1 -1
  17. package/dist/sdk/codemode/static-engine.js +24 -11
  18. package/dist/sdk/codemode/version.d.ts +18 -0
  19. package/dist/sdk/codemode/version.d.ts.map +1 -0
  20. package/dist/sdk/codemode/version.js +17 -0
  21. package/examples/agent-quickstart.ts +159 -0
  22. package/examples/preflight-test.ts +1 -1
  23. package/package.json +2 -1
  24. package/dist/builder-manifest.d.ts +0 -79
  25. package/dist/builder-manifest.d.ts.map +0 -1
  26. package/dist/builder-manifest.js +0 -97
  27. package/dist/core-index.d.ts +0 -21
  28. package/dist/core-index.d.ts.map +0 -1
  29. package/dist/core-index.js +0 -26
  30. package/dist/engine.d.ts +0 -24
  31. package/dist/engine.d.ts.map +0 -1
  32. package/dist/engine.js +0 -67
  33. package/dist/entry/browser.d.ts.map +0 -1
  34. package/dist/entry/node.d.ts.map +0 -1
  35. package/dist/execute.d.ts +0 -46
  36. package/dist/execute.d.ts.map +0 -1
  37. package/dist/execute.js +0 -283
  38. package/dist/execution-sandbox.d.ts +0 -107
  39. package/dist/execution-sandbox.d.ts.map +0 -1
  40. package/dist/execution-sandbox.js +0 -207
  41. package/dist/index.d.ts +0 -31
  42. package/dist/index.d.ts.map +0 -1
  43. package/dist/index.js +0 -63
  44. package/dist/loop-engine.d.ts +0 -22
  45. package/dist/loop-engine.d.ts.map +0 -1
  46. package/dist/loop-engine.js +0 -229
  47. package/dist/noise-bridge.d.ts +0 -44
  48. package/dist/noise-bridge.d.ts.map +0 -1
  49. package/dist/noise-bridge.js +0 -68
  50. package/dist/noise-engine.d.ts +0 -74
  51. package/dist/noise-engine.d.ts.map +0 -1
  52. package/dist/noise-engine.js +0 -132
  53. package/dist/noise-sketches/fractalNoise.d.ts +0 -11
  54. package/dist/noise-sketches/fractalNoise.d.ts.map +0 -1
  55. package/dist/noise-sketches/fractalNoise.js +0 -121
  56. package/dist/noise-sketches/index.d.ts +0 -21
  57. package/dist/noise-sketches/index.d.ts.map +0 -1
  58. package/dist/noise-sketches/index.js +0 -28
  59. package/dist/p5-runtime.d.ts +0 -75
  60. package/dist/p5-runtime.d.ts.map +0 -1
  61. package/dist/p5-runtime.js +0 -1031
  62. package/dist/runtime.d.ts.map +0 -1
  63. package/dist/sdk/codemode/index.d.ts +0 -31
  64. package/dist/sdk/codemode/index.d.ts.map +0 -1
  65. package/dist/sdk/codemode/index.js +0 -63
  66. package/dist/sdk/codemode/noise-bridge.d.ts +0 -44
  67. package/dist/sdk/codemode/noise-bridge.d.ts.map +0 -1
  68. package/dist/sdk/codemode/noise-bridge.js +0 -68
  69. package/dist/sdk/codemode/noise-engine.d.ts +0 -74
  70. package/dist/sdk/codemode/noise-engine.d.ts.map +0 -1
  71. package/dist/sdk/codemode/noise-engine.js +0 -132
  72. package/dist/sdk/codemode/noise-sketches/fractalNoise.d.ts +0 -11
  73. package/dist/sdk/codemode/noise-sketches/fractalNoise.d.ts.map +0 -1
  74. package/dist/sdk/codemode/noise-sketches/fractalNoise.js +0 -121
  75. package/dist/sdk/codemode/noise-sketches/index.d.ts +0 -21
  76. package/dist/sdk/codemode/noise-sketches/index.d.ts.map +0 -1
  77. package/dist/sdk/codemode/noise-sketches/index.js +0 -28
  78. package/dist/shared/noiseSnapshot.d.ts +0 -59
  79. package/dist/shared/noiseSnapshot.d.ts.map +0 -1
  80. package/dist/shared/noiseSnapshot.js +0 -72
  81. package/dist/sound-bridge.d.ts +0 -89
  82. package/dist/sound-bridge.d.ts.map +0 -1
  83. package/dist/sound-bridge.js +0 -128
  84. package/dist/soundart-engine.d.ts +0 -87
  85. package/dist/soundart-engine.d.ts.map +0 -1
  86. package/dist/soundart-engine.js +0 -173
  87. package/dist/soundart-sketches/chladniBloom.d.ts +0 -3
  88. package/dist/soundart-sketches/chladniBloom.d.ts.map +0 -1
  89. package/dist/soundart-sketches/chladniBloom.js +0 -53
  90. package/dist/soundart-sketches/dualVortex.d.ts +0 -3
  91. package/dist/soundart-sketches/dualVortex.d.ts.map +0 -1
  92. package/dist/soundart-sketches/dualVortex.js +0 -67
  93. package/dist/soundart-sketches/geometryIllusion.d.ts +0 -3
  94. package/dist/soundart-sketches/geometryIllusion.d.ts.map +0 -1
  95. package/dist/soundart-sketches/geometryIllusion.js +0 -89
  96. package/dist/soundart-sketches/index.d.ts +0 -39
  97. package/dist/soundart-sketches/index.d.ts.map +0 -1
  98. package/dist/soundart-sketches/index.js +0 -72
  99. package/dist/soundart-sketches/isoflow.d.ts +0 -3
  100. package/dist/soundart-sketches/isoflow.d.ts.map +0 -1
  101. package/dist/soundart-sketches/isoflow.js +0 -60
  102. package/dist/soundart-sketches/loomWeave.d.ts +0 -3
  103. package/dist/soundart-sketches/loomWeave.d.ts.map +0 -1
  104. package/dist/soundart-sketches/loomWeave.js +0 -59
  105. package/dist/soundart-sketches/noiseTerraces.d.ts +0 -3
  106. package/dist/soundart-sketches/noiseTerraces.d.ts.map +0 -1
  107. package/dist/soundart-sketches/noiseTerraces.js +0 -53
  108. package/dist/soundart-sketches/orb.d.ts +0 -3
  109. package/dist/soundart-sketches/orb.d.ts.map +0 -1
  110. package/dist/soundart-sketches/orb.js +0 -50
  111. package/dist/soundart-sketches/pixelGlyphs.d.ts +0 -3
  112. package/dist/soundart-sketches/pixelGlyphs.d.ts.map +0 -1
  113. package/dist/soundart-sketches/pixelGlyphs.js +0 -72
  114. package/dist/soundart-sketches/prismFlowFields.d.ts +0 -3
  115. package/dist/soundart-sketches/prismFlowFields.d.ts.map +0 -1
  116. package/dist/soundart-sketches/prismFlowFields.js +0 -51
  117. package/dist/soundart-sketches/radialBurst.d.ts +0 -3
  118. package/dist/soundart-sketches/radialBurst.d.ts.map +0 -1
  119. package/dist/soundart-sketches/radialBurst.js +0 -60
  120. package/dist/soundart-sketches/resonantSoundBodies.d.ts +0 -3
  121. package/dist/soundart-sketches/resonantSoundBodies.d.ts.map +0 -1
  122. package/dist/soundart-sketches/resonantSoundBodies.js +0 -89
  123. package/dist/soundart-sketches/rings.d.ts +0 -11
  124. package/dist/soundart-sketches/rings.d.ts.map +0 -1
  125. package/dist/soundart-sketches/rings.js +0 -89
  126. package/dist/soundart-sketches/squares.d.ts +0 -3
  127. package/dist/soundart-sketches/squares.d.ts.map +0 -1
  128. package/dist/soundart-sketches/squares.js +0 -52
  129. package/dist/soundart-sketches/waveStripes.d.ts +0 -3
  130. package/dist/soundart-sketches/waveStripes.d.ts.map +0 -1
  131. package/dist/soundart-sketches/waveStripes.js +0 -44
  132. package/dist/static-engine.d.ts +0 -20
  133. package/dist/static-engine.d.ts.map +0 -1
  134. package/dist/static-engine.js +0 -157
  135. package/dist/types.d.ts +0 -191
  136. package/dist/types.d.ts.map +0 -1
  137. package/dist/types.js +0 -32
@@ -1,59 +0,0 @@
1
- /**
2
- * Noise Snapshot Types
3
- *
4
- * This module defines the canonical NoiseSnapshot interface used by the Code Mode runtime.
5
- * All noise parameters are normalized to deterministic, reproducible values.
6
- *
7
- * Architecture:
8
- * NoiseState (UI) → NoiseSnapshot (normalized) → N.* globals → Code Mode Runtime
9
- */
10
- /**
11
- * Blend modes for combining Perlin and Cellular noise
12
- */
13
- export type NoiseBlendMode = 'perlin_only' | 'blend' | 'warp' | 'interleave';
14
- /**
15
- * Raw noise parameters from the UI
16
- */
17
- export interface NoiseParams {
18
- blendMode: NoiseBlendMode;
19
- scale: number;
20
- octaves: number;
21
- persistence: number;
22
- lacunarity: number;
23
- cellDensity: number;
24
- cellDistortion: number;
25
- seed: number;
26
- backgroundColor: string;
27
- noiseColor: string;
28
- zoomLevel: number;
29
- }
30
- /**
31
- * Normalized snapshot for Code Mode injection
32
- * All values are designed for deterministic rendering
33
- */
34
- export interface NoiseSnapshot {
35
- scale: number;
36
- octaves: number;
37
- persistence: number;
38
- lacunarity: number;
39
- cellDensity: number;
40
- cellDistortion: number;
41
- blendMode: NoiseBlendMode;
42
- bgR: number;
43
- bgG: number;
44
- bgB: number;
45
- noiseR: number;
46
- noiseG: number;
47
- noiseB: number;
48
- seed: number;
49
- zoomLevel: number;
50
- }
51
- /**
52
- * Create a NoiseSnapshot from raw NoiseParams
53
- */
54
- export declare function createNoiseSnapshot(params: NoiseParams): NoiseSnapshot;
55
- /**
56
- * Validate and clamp noise snapshot values
57
- */
58
- export declare function validateNoiseSnapshot(snapshot: NoiseSnapshot): NoiseSnapshot;
59
- //# sourceMappingURL=noiseSnapshot.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"noiseSnapshot.d.ts","sourceRoot":"","sources":["../../../../shared/noiseSnapshot.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,aAAa,GAAG,OAAO,GAAG,MAAM,GAAG,YAAY,CAAC;AAE7E;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,SAAS,EAAE,cAAc,CAAC;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,MAAM,CAAC;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,eAAe,EAAE,MAAM,CAAC;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;GAGG;AACH,MAAM,WAAW,aAAa;IAE5B,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IAGnB,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,MAAM,CAAC;IAGvB,SAAS,EAAE,cAAc,CAAC;IAG1B,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IAGf,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;CACnB;AAmBD;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,WAAW,GAAG,aAAa,CAqBtE;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,aAAa,GAAG,aAAa,CAmB5E"}
@@ -1,72 +0,0 @@
1
- /**
2
- * Noise Snapshot Types
3
- *
4
- * This module defines the canonical NoiseSnapshot interface used by the Code Mode runtime.
5
- * All noise parameters are normalized to deterministic, reproducible values.
6
- *
7
- * Architecture:
8
- * NoiseState (UI) → NoiseSnapshot (normalized) → N.* globals → Code Mode Runtime
9
- */
10
- /**
11
- * Parse a hex color string to RGB values
12
- */
13
- function hexToRgb(hex) {
14
- if (!hex || !hex.startsWith('#') || hex.length !== 7) {
15
- return [255, 255, 255];
16
- }
17
- try {
18
- const r = parseInt(hex.slice(1, 3), 16);
19
- const g = parseInt(hex.slice(3, 5), 16);
20
- const b = parseInt(hex.slice(5, 7), 16);
21
- return [r, g, b];
22
- }
23
- catch {
24
- return [255, 255, 255];
25
- }
26
- }
27
- /**
28
- * Create a NoiseSnapshot from raw NoiseParams
29
- */
30
- export function createNoiseSnapshot(params) {
31
- const [bgR, bgG, bgB] = hexToRgb(params.backgroundColor);
32
- const [noiseR, noiseG, noiseB] = hexToRgb(params.noiseColor);
33
- return {
34
- scale: params.scale,
35
- octaves: Math.floor(params.octaves),
36
- persistence: params.persistence,
37
- lacunarity: params.lacunarity,
38
- cellDensity: params.cellDensity,
39
- cellDistortion: params.cellDistortion,
40
- blendMode: params.blendMode,
41
- bgR,
42
- bgG,
43
- bgB,
44
- noiseR,
45
- noiseG,
46
- noiseB,
47
- seed: params.seed,
48
- zoomLevel: params.zoomLevel,
49
- };
50
- }
51
- /**
52
- * Validate and clamp noise snapshot values
53
- */
54
- export function validateNoiseSnapshot(snapshot) {
55
- const clamp = (v, min, max) => Math.max(min, Math.min(max, v));
56
- return {
57
- ...snapshot,
58
- scale: clamp(snapshot.scale, 0.001, 0.1),
59
- octaves: clamp(Math.floor(snapshot.octaves), 1, 8),
60
- persistence: clamp(snapshot.persistence, 0.1, 1.0),
61
- lacunarity: clamp(snapshot.lacunarity, 1.0, 3.0),
62
- cellDensity: clamp(snapshot.cellDensity, 0.1, 1.0),
63
- cellDistortion: clamp(snapshot.cellDistortion, 0.1, 2.0),
64
- bgR: clamp(snapshot.bgR, 0, 255),
65
- bgG: clamp(snapshot.bgG, 0, 255),
66
- bgB: clamp(snapshot.bgB, 0, 255),
67
- noiseR: clamp(snapshot.noiseR, 0, 255),
68
- noiseG: clamp(snapshot.noiseG, 0, 255),
69
- noiseB: clamp(snapshot.noiseB, 0, 255),
70
- zoomLevel: clamp(snapshot.zoomLevel, 0.1, 2.0),
71
- };
72
- }
@@ -1,89 +0,0 @@
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
@@ -1 +0,0 @@
1
- {"version":3,"file":"sound-bridge.d.ts","sourceRoot":"","sources":["../sound-bridge.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAGhE;;;GAGG;AACH,MAAM,WAAW,YAAa,SAAQ,QAAQ,CAAC,aAAa,CAAC;CAE5D;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,aAAa,GAAG,YAAY,CAExE;AAED;;GAEG;AACH,wBAAgB,uBAAuB,IAAI,YAAY,CAEtD;AAED;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC9D,OAAO,EAAE,CAAC,EACV,QAAQ,EAAE,aAAa,GACtB,CAAC,GAAG;IAAE,CAAC,EAAE,YAAY,CAAA;CAAE,CAuBzB;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB;IAE9B;;OAEG;sBACe,MAAM,UAAU,MAAM,UAAU,MAAM,KAAG,MAAM;IAIjE;;OAEG;2BACoB,MAAM,UAAU,MAAM,UAAU,MAAM,WAAU,MAAM,KAAO,MAAM;IAK1F;;OAEG;2BACoB,MAAM,aAAa,MAAM,cAAc,MAAM,KAAG,MAAM;EAIhF;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEhD;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,aAAa,EACvB,WAAW,GAAE,MAAU,GACtB,MAAM,EAAE,CAeV;AAED;;;GAGG;AACH,MAAM,MAAM,WAAW,GAAG,KAAK,GAAG,KAAK,GAAG,MAAM,CAAC;AACjD,MAAM,MAAM,aAAa,GAAG,SAAS,GAAG,SAAS,GAAG,WAAW,CAAC;AAChE,MAAM,MAAM,YAAY,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,CAAC;AAEvD,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,WAAW,CAAC;IACpB,SAAS,EAAE,aAAa,CAAC;IACzB,OAAO,EAAE,YAAY,CAAC;CACvB;AAED,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,aAAa,GAAG,YAAY,CAiBvE"}
@@ -1,128 +0,0 @@
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
- }
@@ -1,87 +0,0 @@
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
@@ -1 +0,0 @@
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,wBAAwB,CAAC,EAAE,MAAM,CAAC;IAClC,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,2BAA2B,CAAC,EAAE,MAAM,CAAC;IACrC,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAChC;AAED,MAAM,WAAW,oBAAoB;IACnC,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,cAAc,CAAC,EAAE,KAAK,GAAG,OAAO,GAAG,OAAO,CAAC;IAC3C,WAAW,CAAC,EAAE,WAAW,CAAC;CAC3B;AAED,MAAM,WAAW,qBAAqB;IACpC,KAAK,EAAE,kBAAkB,CAAC;IAC1B,KAAK,EAAE,aAAa,CAAC;IACrB,MAAM,EAAE,iBAAiB,CAAC;IAC1B,MAAM,EAAE,oBAAoB,CAAC;IAC7B,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;CACzC;AAED,MAAM,WAAW,oBAAoB;IACnC,KAAK,EAAE,kBAAkB,CAAC;IAC1B,IAAI,EAAE,UAAU,CAAC;IACjB,QAAQ,EAAE,aAAa,CAAC;IACxB,QAAQ,EAAE,gBAAgB,CAAC;CAC5B;AAED,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,UAAU,CAAC;IACjB,KAAK,EAAE,kBAAkB,CAAC;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE;QACb,QAAQ,EAAE,MAAM,CAAC;QACjB,SAAS,EAAE,MAAM,CAAC;QAClB,SAAS,EAAE,MAAM,CAAC;QAClB,IAAI,EAAE,MAAM,CAAC;QACb,MAAM,EAAE,MAAM,CAAC;QACf,UAAU,EAAE,MAAM,CAAC;KACpB,CAAC;IACF,OAAO,EAAE;QACP,UAAU,EAAE,OAAO,CAAC;QACpB,cAAc,EAAE,MAAM,CAAC;KACxB,CAAC;IACF,gBAAgB,EAAE;QAChB,IAAI,EAAE,MAAM,CAAC;QACb,UAAU,EAAE;YAAE,KAAK,EAAE,MAAM,CAAC;YAAC,MAAM,EAAE,MAAM,CAAA;SAAE,CAAC;KAC/C,CAAC;CACH;AAqCD;;;;GAIG;AACH,wBAAsB,yBAAyB,CAC7C,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,oBAAoB,CAAC,CAoG/B;AA4BD;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,kBAAkB,GAAG,OAAO,CAEvE;AAED;;GAEG;AACH,wBAAgB,0BAA0B,IAAI,kBAAkB,EAAE,CAGjE;AAGD,YAAY,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC/E,YAAY,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC"}
@@ -1,173 +0,0 @@
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 { createSoundSnapshot } from '../../shared/soundSnapshot';
15
- import { createP5Runtime } from './p5-runtime';
16
- import { injectSoundGlobals, generateSoundPalette, inferGenreProfile } from './sound-bridge';
17
- import { getSoundArtSketch } from './soundart-sketches';
18
- /**
19
- * Apply tweak multipliers to a SoundSnapshot
20
- */
21
- function applyTweaksToSnapshot(snapshot, tweaks) {
22
- if (!tweaks)
23
- return snapshot;
24
- const clamp = (v, min, max) => Math.max(min, Math.min(max, v));
25
- const tweaked = {
26
- ...snapshot,
27
- volume: snapshot.volume * (tweaks.volumeRangeFactor ?? 1),
28
- brightness: snapshot.brightness * (tweaks.centroidBrightnessFactor ?? 1),
29
- aggression: snapshot.aggression * (tweaks.aggressionPaletteFactor ?? 1),
30
- rhythmicity: snapshot.rhythmicity * (tweaks.rhythmPatternFactor ?? 1),
31
- harmonicity: snapshot.harmonicity * (tweaks.harmonySmoothnessFactor ?? 1),
32
- attack: snapshot.attack * (tweaks.attackSharpnessFactor ?? 1),
33
- dynamicRange: snapshot.dynamicRange * (tweaks.dynamicRangeVariationFactor ?? 1),
34
- bass: snapshot.bass * (tweaks.bassThicknessFactor ?? 1),
35
- treble: snapshot.treble * (tweaks.trebleSharpnessFactor ?? 1),
36
- };
37
- // Clamp all numeric values to reasonable range
38
- tweaked.volume = clamp(tweaked.volume, 0, 250);
39
- tweaked.brightness = clamp(tweaked.brightness, 0, 250);
40
- tweaked.aggression = clamp(tweaked.aggression, 0, 250);
41
- tweaked.rhythmicity = clamp(tweaked.rhythmicity, 0, 250);
42
- tweaked.harmonicity = clamp(tweaked.harmonicity, 0, 250);
43
- tweaked.attack = clamp(tweaked.attack, 0, 250);
44
- tweaked.dynamicRange = clamp(tweaked.dynamicRange, 0, 250);
45
- tweaked.bass = clamp(tweaked.bass, 0, 250);
46
- tweaked.treble = clamp(tweaked.treble, 0, 250);
47
- return tweaked;
48
- }
49
- /**
50
- * Render a SoundArt style using Code Mode
51
- *
52
- * This is the main entry point for the new SoundArt → Code Mode pipeline.
53
- */
54
- export async function renderSoundArtViaCodeMode(options) {
55
- const { style, sound, canvas, config, onProgress } = options;
56
- onProgress?.(0.1);
57
- // 1. Get the sketch code
58
- const sketchCode = getSoundArtSketch(style);
59
- if (!sketchCode) {
60
- throw new Error(`SoundArt style "${style}" has not been converted to Code Mode yet`);
61
- }
62
- onProgress?.(0.2);
63
- // 2. Create SoundSnapshot from SoundFeatures
64
- const baseSnapshot = createSoundSnapshot(sound, sound.frames);
65
- // 3. Apply tweak multipliers to the snapshot
66
- const snapshot = applyTweaksToSnapshot(baseSnapshot, config.tweakParams);
67
- onProgress?.(0.3);
68
- // 3. Create the p5 runtime with seeded randomness
69
- // Derive deterministic seed from sound features if not provided
70
- const deriveSeedFromSound = (sound) => {
71
- // Create a stable hash from sound parameters
72
- const hashInput = (sound.rms * 1000) +
73
- (sound.centroid * 100) +
74
- (sound.durationSec * 10000) +
75
- ((sound.bands?.bass ?? 0) * 500) +
76
- ((sound.bands?.treble ?? 0) * 700);
77
- // Simple hash to integer
78
- return Math.abs(Math.floor(hashInput * 2147483647) % 2147483647) || 123456;
79
- };
80
- const runtimeConfig = {
81
- seed: config.seed ?? deriveSeedFromSound(sound),
82
- };
83
- canvas.width = config.width;
84
- canvas.height = config.height;
85
- const baseRuntime = createP5Runtime(canvas, config.width, config.height, runtimeConfig);
86
- // 4. Inject sound globals (S.*)
87
- const runtime = injectSoundGlobals(baseRuntime, snapshot);
88
- onProgress?.(0.4);
89
- // 5. Add helper globals
90
- const globals = {
91
- ...runtime,
92
- width: config.width,
93
- height: config.height,
94
- backgroundMode: config.backgroundMode ?? 'rgb',
95
- palette: generateSoundPalette(snapshot),
96
- genre: inferGenreProfile(snapshot),
97
- };
98
- onProgress?.(0.5);
99
- // 6. Execute the sketch
100
- try {
101
- executeSketch(sketchCode, globals);
102
- onProgress?.(0.9);
103
- }
104
- catch (error) {
105
- console.error(`[SoundArtEngine] Error executing style "${style}":`, error);
106
- throw new Error(`Style "${style}" execution failed: ${error}`);
107
- }
108
- onProgress?.(1.0);
109
- // 7. Build metadata
110
- const metadata = {
111
- mode: 'SoundArt',
112
- style,
113
- timestamp: new Date().toISOString(),
114
- soundFeatures: {
115
- duration: sound.durationSec,
116
- amplitude: sound.rms,
117
- frequency: sound.centroid,
118
- bass: sound.bands?.bass ?? 0,
119
- treble: sound.bands?.treble ?? 0,
120
- aggression: snapshot.aggression,
121
- },
122
- effects: {
123
- timeFilter: false,
124
- backgroundMode: config.backgroundMode ?? 'rgb',
125
- },
126
- generationParams: {
127
- seed: runtimeConfig.seed,
128
- canvasSize: { width: config.width, height: config.height },
129
- },
130
- };
131
- return {
132
- style,
133
- mode: 'soundart',
134
- snapshot,
135
- metadata,
136
- };
137
- }
138
- /**
139
- * Execute a sketch string in the context of the runtime globals
140
- */
141
- function executeSketch(code, globals) {
142
- // Build the function context with all globals
143
- const globalNames = Object.keys(globals);
144
- const globalValues = Object.values(globals);
145
- // Wrap the sketch code to call setup() and optionally draw()
146
- const wrappedCode = `
147
- ${code}
148
-
149
- // Execute setup
150
- if (typeof setup === 'function') {
151
- setup();
152
- }
153
-
154
- // For static mode, we don't call draw()
155
- // Loop mode would call draw() in a frame loop
156
- `;
157
- // Create and execute the function
158
- const sketchFunction = new Function(...globalNames, wrappedCode);
159
- sketchFunction(...globalValues);
160
- }
161
- /**
162
- * Check if a SoundArt style can be rendered via Code Mode
163
- */
164
- export function canRenderViaCodeMode(style) {
165
- return getSoundArtSketch(style) !== undefined;
166
- }
167
- /**
168
- * Get the list of SoundArt styles available via Code Mode
169
- */
170
- export function getCodeModeAvailableStyles() {
171
- const { getAvailableSoundArtSketches } = require('./soundart-sketches');
172
- return getAvailableSoundArtSketches();
173
- }
@@ -1,3 +0,0 @@
1
- export declare const CHLADNI_BLOOM_SKETCH = "\nfunction setup() {\n const bgMode = typeof backgroundMode !== 'undefined' ? backgroundMode : 'rgb';\n if (bgMode === 'white') background(245, 245, 245);\n else if (bgMode === 'black') background(10, 10, 10);\n else {\n const r = Math.floor((S.brightness / 100) * 255);\n const g = Math.floor((S.rhythmicity / 100) * 255);\n const b = Math.floor((S.harmonicity / 100) * 255);\n background(r, g, b);\n }\n\n translate(width / 2, height / 2);\n \n const layers = Math.floor(map(S.volume + S.rhythmicity, 0, 200, 20, 90));\n const minStrokeW = map(S.volume, 0, 100, 1.0, 3.0);\n const maxStrokeW = map(S.treble, 0, 100, 2.0, 5.0);\n\n noFill();\n\n for (let i = 0; i < layers; i++) {\n const freq1 = Math.floor(map(S.aggression + random() * 50, 0, 150, 3, 20));\n const freq2 = Math.floor(map(S.treble + random() * 50, 0, 150, 2, 8));\n const amp = map(S.dynamicRange + random() * 30, 0, 130, 60, 400);\n const rotation = map(S.harmonicity + random() * 50, 0, 150, 0, PI * 4);\n const radiusOffset = map(S.bass, 0, 100, 40, 80);\n const strokeW = map(S.treble + S.volume * 0.5, 0, 100, minStrokeW, maxStrokeW);\n \n const hBase = (330 + random() * 100) % 360;\n const finalH = (hBase + (random() * 40 - 60) + map(S.hue, 0, 100, -10, 10) + 360) % 360;\n const finalC = constrain(85 + map(S.brightness, 0, 100, -20, 20), 0, 100);\n const finalL = constrain(90 + map(S.brightness, 0, 100, -15, 15), 0, 100);\n const finalA = constrain(0.5 + map(S.attack, 0, 100, 0, 0.5), 0.3, 1);\n\n push();\n rotate(rotation);\n strokeWeight(strokeW);\n stroke('hsla(' + finalH + ',' + finalC + '%,' + finalL + '%,' + finalA + ')');\n \n const angleStep = map(S.treble, 0, 100, 0.07, 0.03);\n beginShape();\n for (let aa = 0; aa < PI * 2; aa += angleStep) {\n const rad = radiusOffset * i + amp * sin(freq1 * aa) * cos(freq2 * aa * map(S.rhythmicity, 0, 100, 0.3, 2));\n const x = rad * cos(aa);\n const y = rad * sin(aa);\n vertex(x, y);\n }\n endShape(CLOSE);\n pop();\n }\n}\n";
2
- export default CHLADNI_BLOOM_SKETCH;
3
- //# sourceMappingURL=chladniBloom.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"chladniBloom.d.ts","sourceRoot":"","sources":["../../soundart-sketches/chladniBloom.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,oBAAoB,+hEAmDhC,CAAC;AAEF,eAAe,oBAAoB,CAAC"}