@litfamily/litcodex 1.0.29 → 1.0.31

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 (388) hide show
  1. package/README-Ko-KR.md +11 -11
  2. package/README.md +11 -11
  3. package/dist/install/generated-skill-payload-hashes.d.ts +191 -85
  4. package/dist/install/generated-skill-payload-hashes.js +191 -85
  5. package/dist/install/marketplace.js +10 -1
  6. package/dist/install/skill-catalog.d.ts +1 -1
  7. package/dist/install/skill-catalog.js +12 -1
  8. package/dist/install/skill-resource-hashes.d.ts +1 -1
  9. package/dist/install/skill-resource-hashes.js +1 -1
  10. package/marketplace/.agents/plugins/marketplace.json +4 -1
  11. package/marketplace/plugins/litcodex/.codex-plugin/plugin.json +14 -2
  12. package/marketplace/plugins/litcodex/assets/screenshot-lit-ignited.png +0 -0
  13. package/marketplace/plugins/litcodex/components/auto-update/package.json +1 -1
  14. package/marketplace/plugins/litcodex/components/comment-checker/package.json +1 -1
  15. package/marketplace/plugins/litcodex/components/git-bash/package.json +1 -1
  16. package/marketplace/plugins/litcodex/components/lit-loop/directive.md +10 -4
  17. package/marketplace/plugins/litcodex/components/lit-loop/directives/lit-adhd.md +191 -0
  18. package/marketplace/plugins/litcodex/components/lit-loop/directives/lit-handoff.md +2 -0
  19. package/marketplace/plugins/litcodex/components/lit-loop/directives/lit-hijack.md +219 -0
  20. package/marketplace/plugins/litcodex/components/lit-loop/directives/lit-recap.md +2 -0
  21. package/marketplace/plugins/litcodex/components/lit-loop/directives/lit-schematic.md +199 -0
  22. package/marketplace/plugins/litcodex/components/lit-loop/directives/litwork.md +2 -1
  23. package/marketplace/plugins/litcodex/components/lit-loop/dist/adhd-suggest.d.ts +10 -0
  24. package/marketplace/plugins/litcodex/components/lit-loop/dist/adhd-suggest.js +67 -0
  25. package/marketplace/plugins/litcodex/components/lit-loop/dist/card-html.d.ts +1 -1
  26. package/marketplace/plugins/litcodex/components/lit-loop/dist/card-html.js +128 -8
  27. package/marketplace/plugins/litcodex/components/lit-loop/dist/card-looks.d.ts +19 -0
  28. package/marketplace/plugins/litcodex/components/lit-loop/dist/card-looks.js +58 -0
  29. package/marketplace/plugins/litcodex/components/lit-loop/dist/card-status.d.ts +27 -0
  30. package/marketplace/plugins/litcodex/components/lit-loop/dist/card-status.js +94 -7
  31. package/marketplace/plugins/litcodex/components/lit-loop/dist/cli.js +13 -3
  32. package/marketplace/plugins/litcodex/components/lit-loop/dist/codex-hook.d.ts +2 -0
  33. package/marketplace/plugins/litcodex/components/lit-loop/dist/codex-hook.js +8 -9
  34. package/marketplace/plugins/litcodex/components/lit-loop/dist/control-chars.d.ts +5 -0
  35. package/marketplace/plugins/litcodex/components/lit-loop/dist/control-chars.js +23 -0
  36. package/marketplace/plugins/litcodex/components/lit-loop/dist/hook-cli.d.ts +8 -0
  37. package/marketplace/plugins/litcodex/components/lit-loop/dist/hook-cli.js +118 -11
  38. package/marketplace/plugins/litcodex/components/lit-loop/dist/hud.d.ts +1 -1
  39. package/marketplace/plugins/litcodex/components/lit-loop/dist/hud.js +29 -13
  40. package/marketplace/plugins/litcodex/components/lit-loop/dist/lane-events.d.ts +13 -0
  41. package/marketplace/plugins/litcodex/components/lit-loop/dist/lane-events.js +85 -0
  42. package/marketplace/plugins/litcodex/components/lit-loop/dist/lane-state.d.ts +55 -0
  43. package/marketplace/plugins/litcodex/components/lit-loop/dist/lane-state.js +227 -0
  44. package/marketplace/plugins/litcodex/components/lit-loop/dist/live-step.d.ts +5 -1
  45. package/marketplace/plugins/litcodex/components/lit-loop/dist/live-step.js +17 -1
  46. package/marketplace/plugins/litcodex/components/lit-loop/dist/markers.d.ts +6 -0
  47. package/marketplace/plugins/litcodex/components/lit-loop/dist/markers.js +6 -0
  48. package/marketplace/plugins/litcodex/components/lit-loop/dist/modes.d.ts +1 -1
  49. package/marketplace/plugins/litcodex/components/lit-loop/dist/modes.js +25 -1
  50. package/marketplace/plugins/litcodex/components/lit-loop/dist/motion-gate.d.ts +79 -0
  51. package/marketplace/plugins/litcodex/components/lit-loop/dist/motion-gate.js +310 -0
  52. package/marketplace/plugins/litcodex/components/lit-loop/dist/motion-route.js +5 -1
  53. package/marketplace/plugins/litcodex/components/lit-loop/dist/plan-persistence.js +10 -0
  54. package/marketplace/plugins/litcodex/components/lit-loop/dist/redaction.js +18 -0
  55. package/marketplace/plugins/litcodex/components/lit-loop/dist/reentry.d.ts +15 -0
  56. package/marketplace/plugins/litcodex/components/lit-loop/dist/reentry.js +46 -9
  57. package/marketplace/plugins/litcodex/components/lit-loop/dist/rewind-cli.d.ts +10 -0
  58. package/marketplace/plugins/litcodex/components/lit-loop/dist/rewind-cli.js +88 -0
  59. package/marketplace/plugins/litcodex/components/lit-loop/dist/rewind-go.d.ts +20 -0
  60. package/marketplace/plugins/litcodex/components/lit-loop/dist/rewind-go.js +84 -0
  61. package/marketplace/plugins/litcodex/components/lit-loop/dist/rewind-look.d.ts +6 -0
  62. package/marketplace/plugins/litcodex/components/lit-loop/dist/rewind-look.js +41 -0
  63. package/marketplace/plugins/litcodex/components/lit-loop/dist/rewind-redact.d.ts +3 -0
  64. package/marketplace/plugins/litcodex/components/lit-loop/dist/rewind-redact.js +40 -0
  65. package/marketplace/plugins/litcodex/components/lit-loop/dist/rewind-rollout.d.ts +48 -0
  66. package/marketplace/plugins/litcodex/components/lit-loop/dist/rewind-rollout.js +292 -0
  67. package/marketplace/plugins/litcodex/components/lit-loop/dist/rewind.d.ts +162 -0
  68. package/marketplace/plugins/litcodex/components/lit-loop/dist/rewind.js +773 -0
  69. package/marketplace/plugins/litcodex/components/lit-loop/dist/route-heads.js +44 -2
  70. package/marketplace/plugins/litcodex/components/lit-loop/dist/run-panel.js +1 -0
  71. package/marketplace/plugins/litcodex/components/lit-loop/dist/schematic-route.d.ts +6 -0
  72. package/marketplace/plugins/litcodex/components/lit-loop/dist/schematic-route.js +35 -0
  73. package/marketplace/plugins/litcodex/components/lit-loop/dist/screen-card.d.ts +3 -0
  74. package/marketplace/plugins/litcodex/components/lit-loop/dist/screen-card.js +15 -5
  75. package/marketplace/plugins/litcodex/components/lit-loop/dist/skill-mention-scope.js +6 -0
  76. package/marketplace/plugins/litcodex/components/lit-loop/dist/stack-hook.d.ts +8 -0
  77. package/marketplace/plugins/litcodex/components/lit-loop/dist/stack-hook.js +57 -0
  78. package/marketplace/plugins/litcodex/components/lit-loop/dist/statusline.js +8 -3
  79. package/marketplace/plugins/litcodex/components/lit-loop/dist/threads.d.ts +50 -0
  80. package/marketplace/plugins/litcodex/components/lit-loop/dist/threads.js +178 -0
  81. package/marketplace/plugins/litcodex/components/lit-loop/dist/trigger.d.ts +1 -1
  82. package/marketplace/plugins/litcodex/components/lit-loop/dist/trigger.js +31 -6
  83. package/marketplace/plugins/litcodex/components/lit-loop/dist/workflow-map.d.ts +10 -0
  84. package/marketplace/plugins/litcodex/components/lit-loop/dist/workflow-map.js +11 -1
  85. package/marketplace/plugins/litcodex/components/lit-loop/dist/workflow-stack.d.ts +132 -0
  86. package/marketplace/plugins/litcodex/components/lit-loop/dist/workflow-stack.js +488 -0
  87. package/marketplace/plugins/litcodex/components/lit-loop/package.json +1 -1
  88. package/marketplace/plugins/litcodex/components/lsp/package.json +1 -1
  89. package/marketplace/plugins/litcodex/components/rules/node_modules/picomatch/README.md +15 -21
  90. package/marketplace/plugins/litcodex/components/rules/node_modules/picomatch/lib/parse.js +49 -10
  91. package/marketplace/plugins/litcodex/components/rules/node_modules/picomatch/lib/picomatch.js +14 -2
  92. package/marketplace/plugins/litcodex/components/rules/node_modules/picomatch/lib/scan.js +30 -18
  93. package/marketplace/plugins/litcodex/components/rules/node_modules/picomatch/package.json +3 -2
  94. package/marketplace/plugins/litcodex/components/rules/package.json +1 -1
  95. package/marketplace/plugins/litcodex/components/start-work-continuation/dist/codex-hook.d.ts +6 -0
  96. package/marketplace/plugins/litcodex/components/start-work-continuation/dist/codex-hook.js +65 -0
  97. package/marketplace/plugins/litcodex/components/start-work-continuation/package.json +1 -1
  98. package/marketplace/plugins/litcodex/components/telemetry/package.json +1 -1
  99. package/marketplace/plugins/litcodex/components/wikify-knowledge/package.json +1 -1
  100. package/marketplace/plugins/litcodex/hooks/hooks.json +24 -0
  101. package/marketplace/plugins/litcodex/skills/frontend-ui-ux/SKILL.md +6 -0
  102. package/marketplace/plugins/litcodex/skills/frontend-ui-ux/kit/components.css +414 -0
  103. package/marketplace/plugins/litcodex/skills/frontend-ui-ux/kit/fonts.json +22 -0
  104. package/marketplace/plugins/litcodex/skills/frontend-ui-ux/kit/layouts/landing.html +164 -0
  105. package/marketplace/plugins/litcodex/skills/frontend-ui-ux/kit/layouts/settings.html +114 -0
  106. package/marketplace/plugins/litcodex/skills/frontend-ui-ux/kit/layouts/workspace.html +115 -0
  107. package/marketplace/plugins/litcodex/skills/frontend-ui-ux/kit/styles/computational-brutalism.json +227 -0
  108. package/marketplace/plugins/litcodex/skills/frontend-ui-ux/kit/styles/field-notes.json +205 -0
  109. package/marketplace/plugins/litcodex/skills/frontend-ui-ux/kit/styles/graphite.json +200 -0
  110. package/marketplace/plugins/litcodex/skills/frontend-ui-ux/kit/styles/meadow.json +199 -0
  111. package/marketplace/plugins/litcodex/skills/frontend-ui-ux/kit/styles/neo-brutalism.json +222 -0
  112. package/marketplace/plugins/litcodex/skills/frontend-ui-ux/kit/ui.js +228 -0
  113. package/marketplace/plugins/litcodex/skills/frontend-ui-ux/references/brand-and-imagery.md +1 -1
  114. package/marketplace/plugins/litcodex/skills/frontend-ui-ux/references/complete-contract.md +1 -0
  115. package/marketplace/plugins/litcodex/skills/frontend-ui-ux/references/craft-floor.md +2 -2
  116. package/marketplace/plugins/litcodex/skills/frontend-ui-ux/references/default-editorial-pixel.json +15 -8
  117. package/marketplace/plugins/litcodex/skills/frontend-ui-ux/references/design-choice.md +19 -0
  118. package/marketplace/plugins/litcodex/skills/frontend-ui-ux/references/house-styles.md +235 -0
  119. package/marketplace/plugins/litcodex/skills/frontend-ui-ux/references/motion-guide.md +2 -2
  120. package/marketplace/plugins/litcodex/skills/frontend-ui-ux/references/probe-and-review.md +6 -0
  121. package/marketplace/plugins/litcodex/skills/frontend-ui-ux/references/production-interview.md +2 -0
  122. package/marketplace/plugins/litcodex/skills/frontend-ui-ux/references/slop-register.md +4 -4
  123. package/marketplace/plugins/litcodex/skills/frontend-ui-ux/scripts/design-lock.mjs +400 -0
  124. package/marketplace/plugins/litcodex/skills/frontend-ui-ux/scripts/lock-probe.mjs +196 -0
  125. package/marketplace/plugins/litcodex/skills/frontend-ui-ux/scripts/page-probe.mjs +22 -4
  126. package/marketplace/plugins/litcodex/skills/frontend-ui-ux/scripts/pixel-art.mjs +60 -0
  127. package/marketplace/plugins/litcodex/skills/frontend-ui-ux/scripts/probe.mjs +59 -13
  128. package/marketplace/plugins/litcodex/skills/frontend-ui-ux/scripts/rule-data.mjs +38 -4
  129. package/marketplace/plugins/litcodex/skills/lit-adhd/SKILL.md +181 -0
  130. package/marketplace/plugins/litcodex/skills/lit-adhd/agents/openai.yaml +6 -0
  131. package/marketplace/plugins/litcodex/skills/lit-adhd/references/card-examples.md +147 -0
  132. package/marketplace/plugins/litcodex/skills/lit-adhd/references/status-taxonomy.md +37 -0
  133. package/marketplace/plugins/litcodex/skills/lit-diagram-drawer/SKILL.md +18 -7
  134. package/marketplace/plugins/litcodex/skills/lit-diagram-drawer/references/style-guide.md +20 -11
  135. package/marketplace/plugins/litcodex/skills/lit-diagram-drawer/references/type-architecture.md +3 -3
  136. package/marketplace/plugins/litcodex/skills/lit-diagram-drawer/references/type-dependency.md +1 -1
  137. package/marketplace/plugins/litcodex/skills/lit-diagram-drawer/references/type-swimlane.md +1 -1
  138. package/marketplace/plugins/litcodex/skills/lit-diagram-drawer/references/type-tree-block-decomposition.md +1 -1
  139. package/marketplace/plugins/litcodex/skills/lit-diagram-drawer/references/type-tree.md +3 -3
  140. package/marketplace/plugins/litcodex/skills/lit-diagram-drawer/references/type-wardley.md +1 -1
  141. package/marketplace/plugins/litcodex/skills/lit-diagram-drawer/references/verifier-guide.md +1 -0
  142. package/marketplace/plugins/litcodex/skills/lit-diagram-drawer/scripts/diagram-craft-rules.mjs +1 -2
  143. package/marketplace/plugins/litcodex/skills/lit-diagram-drawer/scripts/visual-quality.mjs +1 -2
  144. package/marketplace/plugins/litcodex/skills/lit-docx/SKILL.md +12 -3
  145. package/marketplace/plugins/litcodex/skills/lit-docx/references/direction-step.md +6 -3
  146. package/marketplace/plugins/litcodex/skills/lit-hijack/SKILL.md +449 -0
  147. package/marketplace/plugins/litcodex/skills/lit-hijack/agents/openai.yaml +6 -0
  148. package/marketplace/plugins/litcodex/skills/lit-hijack/references/capture-and-provenance.md +100 -0
  149. package/marketplace/plugins/litcodex/skills/lit-hijack/references/clean-room-build.md +111 -0
  150. package/marketplace/plugins/litcodex/skills/lit-hijack/references/distil-and-licence.md +102 -0
  151. package/marketplace/plugins/litcodex/skills/lit-hijack/references/gap-and-port-design.md +125 -0
  152. package/marketplace/plugins/litcodex/skills/lit-hijack/references/parity-and-report.md +108 -0
  153. package/marketplace/plugins/litcodex/skills/lit-hijack/scripts/hijack.mjs +1050 -0
  154. package/marketplace/plugins/litcodex/skills/lit-loop/SKILL.md +13 -4
  155. package/marketplace/plugins/litcodex/skills/lit-plan/SKILL.md +6 -0
  156. package/marketplace/plugins/litcodex/skills/lit-pptx/NOTICE +1 -0
  157. package/marketplace/plugins/litcodex/skills/lit-pptx/SKILL.md +35 -8
  158. package/marketplace/plugins/litcodex/skills/lit-pptx/fonts/jetbrains-mono/JetBrainsMono-Bold.ttf +0 -0
  159. package/marketplace/plugins/litcodex/skills/lit-pptx/fonts/jetbrains-mono/JetBrainsMono-Regular.ttf +0 -0
  160. package/marketplace/plugins/litcodex/skills/lit-pptx/fonts/jetbrains-mono/OFL.txt +93 -0
  161. package/marketplace/plugins/litcodex/skills/lit-pptx/fonts/jetbrains-mono/SOURCE.md +21 -0
  162. package/marketplace/plugins/litcodex/skills/lit-pptx/references/anti-slop-checklist.md +5 -2
  163. package/marketplace/plugins/litcodex/skills/lit-pptx/references/authoring-guide.md +3 -4
  164. package/marketplace/plugins/litcodex/skills/lit-pptx/references/density-and-fill.md +20 -6
  165. package/marketplace/plugins/litcodex/skills/lit-pptx/references/direction-step.md +26 -8
  166. package/marketplace/plugins/litcodex/skills/lit-pptx/references/examples/14-engineering-review-computational-brutalism-ko.md +173 -0
  167. package/marketplace/plugins/litcodex/skills/lit-pptx/references/examples/15-launch-pitch-neo-brutalism-ko.md +154 -0
  168. package/marketplace/plugins/litcodex/skills/lit-pptx/references/examples/16-design-lecture-bauhaus-ko.md +139 -0
  169. package/marketplace/plugins/litcodex/skills/lit-pptx/references/examples/17-community-programme-riso-ko.md +158 -0
  170. package/marketplace/plugins/litcodex/skills/lit-pptx/references/examples/18-public-data-briefing-newsroom-ko.md +179 -0
  171. package/marketplace/plugins/litcodex/skills/lit-pptx/references/layout-families.md +42 -27
  172. package/marketplace/plugins/litcodex/skills/lit-pptx/references/title-treatments.md +31 -27
  173. package/marketplace/plugins/litcodex/skills/lit-pptx/references/tonalities/bauhaus.md +136 -0
  174. package/marketplace/plugins/litcodex/skills/lit-pptx/references/tonalities/chalk.md +1 -1
  175. package/marketplace/plugins/litcodex/skills/lit-pptx/references/tonalities/computational-brutalism.md +145 -0
  176. package/marketplace/plugins/litcodex/skills/lit-pptx/references/tonalities/neo-brutalism.md +155 -0
  177. package/marketplace/plugins/litcodex/skills/lit-pptx/references/tonalities/newsroom.md +141 -0
  178. package/marketplace/plugins/litcodex/skills/lit-pptx/references/tonalities/riso.md +133 -0
  179. package/marketplace/plugins/litcodex/skills/lit-pptx/references/tonalities/signal.md +1 -1
  180. package/marketplace/plugins/litcodex/skills/lit-pptx/references/tonalities/studio.md +1 -1
  181. package/marketplace/plugins/litcodex/skills/lit-pptx/scripts/compile-deck.js +1 -1
  182. package/marketplace/plugins/litcodex/skills/lit-pptx/scripts/craft_extras.py +136 -94
  183. package/marketplace/plugins/litcodex/skills/lit-pptx/scripts/embed_fonts.py +13 -1
  184. package/marketplace/plugins/litcodex/skills/lit-pptx/scripts/lib/grid-resolver.js +101 -110
  185. package/marketplace/plugins/litcodex/skills/lit-pptx/scripts/lib/layout-resolver.js +9 -15
  186. package/marketplace/plugins/litcodex/skills/lit-pptx/scripts/lib/render-pack.js +386 -579
  187. package/marketplace/plugins/litcodex/skills/lit-pptx/scripts/lib/slide-grid.js +104 -0
  188. package/marketplace/plugins/litcodex/skills/lit-pptx/scripts/lib/template-registry.js +57 -6
  189. package/marketplace/plugins/litcodex/skills/lit-pptx/scripts/office-run.mjs +2 -1
  190. package/marketplace/plugins/litcodex/skills/lit-pptx/scripts/qa_deck.py +7 -13
  191. package/marketplace/plugins/litcodex/skills/lit-pptx/scripts/render_pages.py +124 -0
  192. package/marketplace/plugins/litcodex/skills/lit-pptx/templates/tonalities/atlas/pack.yaml +1 -1
  193. package/marketplace/plugins/litcodex/skills/lit-pptx/templates/tonalities/bauhaus/pack.yaml +98 -0
  194. package/marketplace/plugins/litcodex/skills/lit-pptx/templates/tonalities/chalk/pack.yaml +1 -1
  195. package/marketplace/plugins/litcodex/skills/lit-pptx/templates/tonalities/computational-brutalism/pack.yaml +100 -0
  196. package/marketplace/plugins/litcodex/skills/lit-pptx/templates/tonalities/gazette/pack.yaml +1 -1
  197. package/marketplace/plugins/litcodex/skills/lit-pptx/templates/tonalities/ledger/pack.yaml +1 -1
  198. package/marketplace/plugins/litcodex/skills/lit-pptx/templates/tonalities/neo-brutalism/pack.yaml +107 -0
  199. package/marketplace/plugins/litcodex/skills/lit-pptx/templates/tonalities/newsroom/pack.yaml +99 -0
  200. package/marketplace/plugins/litcodex/skills/lit-pptx/templates/tonalities/night/pack.yaml +1 -1
  201. package/marketplace/plugins/litcodex/skills/lit-pptx/templates/tonalities/paper/pack.yaml +1 -1
  202. package/marketplace/plugins/litcodex/skills/lit-pptx/templates/tonalities/riso/pack.yaml +99 -0
  203. package/marketplace/plugins/litcodex/skills/lit-pptx/templates/tonalities/signal/pack.yaml +2 -2
  204. package/marketplace/plugins/litcodex/skills/lit-pptx/templates/tonalities/studio/pack.yaml +1 -1
  205. package/marketplace/plugins/litcodex/skills/lit-recap/SKILL.md +2 -0
  206. package/marketplace/plugins/litcodex/skills/lit-schematic/SKILL.md +198 -0
  207. package/marketplace/plugins/litcodex/skills/lit-schematic/agents/openai.yaml +6 -0
  208. package/marketplace/plugins/litcodex/skills/lit-schematic/examples/iso-heat-exchanger/build.mjs +38 -0
  209. package/marketplace/plugins/litcodex/skills/lit-schematic/examples/iso-heat-exchanger/scene.mjs +133 -0
  210. package/marketplace/plugins/litcodex/skills/lit-schematic/examples/journal-adsorption-rig/build.mjs +87 -0
  211. package/marketplace/plugins/litcodex/skills/lit-schematic/examples/pid-dosing-skid/build.mjs +85 -0
  212. package/marketplace/plugins/litcodex/skills/lit-schematic/references/cutaway-outputs.md +70 -0
  213. package/marketplace/plugins/litcodex/skills/lit-schematic/references/isometric-craft.md +101 -0
  214. package/marketplace/plugins/litcodex/skills/lit-schematic/references/journal-figures.md +72 -0
  215. package/marketplace/plugins/litcodex/skills/lit-schematic/references/kit-api.md +134 -0
  216. package/marketplace/plugins/litcodex/skills/lit-schematic/references/pfd-and-layout.md +53 -0
  217. package/marketplace/plugins/litcodex/skills/lit-schematic/references/pid-drafting.md +103 -0
  218. package/marketplace/plugins/litcodex/skills/lit-schematic/references/pid-symbols.md +163 -0
  219. package/marketplace/plugins/litcodex/skills/lit-schematic/references/verification.md +100 -0
  220. package/marketplace/plugins/litcodex/skills/lit-schematic/scripts/doctor.mjs +57 -0
  221. package/marketplace/plugins/litcodex/skills/lit-schematic/scripts/lib/figure.mjs +81 -0
  222. package/marketplace/plugins/litcodex/skills/lit-schematic/scripts/lib/fonts.mjs +28 -0
  223. package/marketplace/plugins/litcodex/skills/lit-schematic/scripts/lib/geom.mjs +113 -0
  224. package/marketplace/plugins/litcodex/skills/lit-schematic/scripts/lib/interactive.mjs +292 -0
  225. package/marketplace/plugins/litcodex/skills/lit-schematic/scripts/lib/isa.mjs +115 -0
  226. package/marketplace/plugins/litcodex/skills/lit-schematic/scripts/lib/iso.mjs +719 -0
  227. package/marketplace/plugins/litcodex/skills/lit-schematic/scripts/lib/legend-sheet.mjs +162 -0
  228. package/marketplace/plugins/litcodex/skills/lit-schematic/scripts/lib/pid.mjs +937 -0
  229. package/marketplace/plugins/litcodex/skills/lit-schematic/scripts/lib/png.mjs +132 -0
  230. package/marketplace/plugins/litcodex/skills/lit-schematic/scripts/lib/qa-core.mjs +658 -0
  231. package/marketplace/plugins/litcodex/skills/lit-schematic/scripts/lib/route.mjs +218 -0
  232. package/marketplace/plugins/litcodex/skills/lit-schematic/scripts/lib/sheet.mjs +890 -0
  233. package/marketplace/plugins/litcodex/skills/lit-schematic/scripts/lib/svg.mjs +82 -0
  234. package/marketplace/plugins/litcodex/skills/lit-schematic/scripts/lib/theme.mjs +115 -0
  235. package/marketplace/plugins/litcodex/skills/lit-schematic/scripts/motion.mjs +129 -0
  236. package/marketplace/plugins/litcodex/skills/lit-schematic/scripts/qa.mjs +92 -0
  237. package/marketplace/plugins/litcodex/skills/lit-schematic/scripts/render.mjs +233 -0
  238. package/marketplace/plugins/litcodex/skills/lit-schematic/scripts/scaffold.mjs +60 -0
  239. package/marketplace/plugins/litcodex/skills/lit-scientific-visualization/SKILL.md +34 -8
  240. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/SKILL.md +18 -14
  241. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/THIRD_PARTY_NOTICES +12 -0
  242. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/assets.mjs +388 -0
  243. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/blender/runner.py +221 -0
  244. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/blender.mjs +132 -0
  245. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/board.mjs +142 -0
  246. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/constants.mjs +6 -0
  247. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/cover-assets.mjs +7 -4
  248. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/cover-capture.mjs +8 -7
  249. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/cover-init.js +14 -2
  250. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/cover-treatment.mjs +38 -3
  251. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/cover.mjs +19 -4
  252. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/driver.mjs +8 -8
  253. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/gallery.mjs +147 -0
  254. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/house.mjs +45 -0
  255. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/image.mjs +89 -0
  256. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/look.mjs +58 -25
  257. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/runtime.mjs +59 -14
  258. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/safe-read.mjs +32 -0
  259. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/scaffold.mjs +208 -0
  260. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/score.mjs +668 -0
  261. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/sound.mjs +174 -31
  262. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/stage-gate.mjs +45 -3
  263. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/stage-kit.js +99 -1
  264. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/stage-qa.js +8 -1
  265. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/stage-qa.mjs +180 -11
  266. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/stage-render.mjs +42 -12
  267. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/stage-worker.mjs +7 -4
  268. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/stage.mjs +96 -10
  269. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/styles.mjs +233 -0
  270. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/treatment.mjs +291 -14
  271. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/vendor/three/LICENSE +21 -0
  272. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/vendor/three/addons/environments/RoomEnvironment.js +144 -0
  273. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/vendor/three/addons/geometries/RoundedBoxGeometry.js +155 -0
  274. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/vendor/three/three.module.js +54571 -0
  275. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/recipes/hero-3d/expected.json +33 -0
  276. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/recipes/hero-3d/index.html +139 -0
  277. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/references/cover.md +44 -7
  278. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/references/depth.md +156 -0
  279. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/references/design-choice.md +22 -0
  280. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/references/quality-gate.md +29 -7
  281. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/references/runtime.md +1 -1
  282. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/references/sound.md +87 -0
  283. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/references/stage.md +19 -7
  284. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/references/studio.md +246 -0
  285. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/references/style-bibles.md +2 -2
  286. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/references/treatment.md +41 -21
  287. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/runtime/requirements-audio.txt +3 -3
  288. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/scripts/render.mjs +51 -4
  289. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/styles/paper.json +185 -0
  290. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/styles/swiss-signal.json +188 -0
  291. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/styles/terminalcore.json +182 -0
  292. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/styles/tidal.json +187 -0
  293. package/marketplace/plugins/litcodex/skills/litresearch/SKILL.md +7 -0
  294. package/marketplace/plugins/litcodex/skills/litwork/SKILL.md +2 -1
  295. package/marketplace/plugins/litcodex/skills/lsp-setup/SKILL.md +2 -1
  296. package/marketplace/plugins/litcodex/skills/readme-studio/SKILL.md +10 -0
  297. package/marketplace/plugins/litcodex/skills/readme-studio/templates/hyperframes-cover/package-lock.json +3 -3
  298. package/marketplace/plugins/litcodex/skills/readme-studio/templates/remotion-cover/package-lock.json +3 -3
  299. package/marketplace/plugins/litcodex/skills/review-work/SKILL.md +7 -1
  300. package/marketplace/plugins/litcodex/skills/start-work/SKILL.md +10 -0
  301. package/node_modules/@litcodex/lit-loop/directive.md +10 -4
  302. package/node_modules/@litcodex/lit-loop/directives/lit-adhd.md +191 -0
  303. package/node_modules/@litcodex/lit-loop/directives/lit-handoff.md +2 -0
  304. package/node_modules/@litcodex/lit-loop/directives/lit-hijack.md +219 -0
  305. package/node_modules/@litcodex/lit-loop/directives/lit-recap.md +2 -0
  306. package/node_modules/@litcodex/lit-loop/directives/lit-schematic.md +199 -0
  307. package/node_modules/@litcodex/lit-loop/directives/litwork.md +2 -1
  308. package/node_modules/@litcodex/lit-loop/dist/adhd-suggest.d.ts +10 -0
  309. package/node_modules/@litcodex/lit-loop/dist/adhd-suggest.js +67 -0
  310. package/node_modules/@litcodex/lit-loop/dist/card-html.d.ts +1 -1
  311. package/node_modules/@litcodex/lit-loop/dist/card-html.js +128 -8
  312. package/node_modules/@litcodex/lit-loop/dist/card-looks.d.ts +19 -0
  313. package/node_modules/@litcodex/lit-loop/dist/card-looks.js +58 -0
  314. package/node_modules/@litcodex/lit-loop/dist/card-status.d.ts +27 -0
  315. package/node_modules/@litcodex/lit-loop/dist/card-status.js +94 -7
  316. package/node_modules/@litcodex/lit-loop/dist/cli.js +13 -3
  317. package/node_modules/@litcodex/lit-loop/dist/codex-hook.d.ts +2 -0
  318. package/node_modules/@litcodex/lit-loop/dist/codex-hook.js +8 -9
  319. package/node_modules/@litcodex/lit-loop/dist/control-chars.d.ts +5 -0
  320. package/node_modules/@litcodex/lit-loop/dist/control-chars.js +23 -0
  321. package/node_modules/@litcodex/lit-loop/dist/hook-cli.d.ts +8 -0
  322. package/node_modules/@litcodex/lit-loop/dist/hook-cli.js +118 -11
  323. package/node_modules/@litcodex/lit-loop/dist/hud.d.ts +1 -1
  324. package/node_modules/@litcodex/lit-loop/dist/hud.js +29 -13
  325. package/node_modules/@litcodex/lit-loop/dist/lane-events.d.ts +13 -0
  326. package/node_modules/@litcodex/lit-loop/dist/lane-events.js +85 -0
  327. package/node_modules/@litcodex/lit-loop/dist/lane-state.d.ts +55 -0
  328. package/node_modules/@litcodex/lit-loop/dist/lane-state.js +227 -0
  329. package/node_modules/@litcodex/lit-loop/dist/live-step.d.ts +5 -1
  330. package/node_modules/@litcodex/lit-loop/dist/live-step.js +17 -1
  331. package/node_modules/@litcodex/lit-loop/dist/markers.d.ts +6 -0
  332. package/node_modules/@litcodex/lit-loop/dist/markers.js +6 -0
  333. package/node_modules/@litcodex/lit-loop/dist/modes.d.ts +1 -1
  334. package/node_modules/@litcodex/lit-loop/dist/modes.js +25 -1
  335. package/node_modules/@litcodex/lit-loop/dist/motion-gate.d.ts +79 -0
  336. package/node_modules/@litcodex/lit-loop/dist/motion-gate.js +310 -0
  337. package/node_modules/@litcodex/lit-loop/dist/motion-route.js +5 -1
  338. package/node_modules/@litcodex/lit-loop/dist/plan-persistence.js +10 -0
  339. package/node_modules/@litcodex/lit-loop/dist/redaction.js +18 -0
  340. package/node_modules/@litcodex/lit-loop/dist/reentry.d.ts +15 -0
  341. package/node_modules/@litcodex/lit-loop/dist/reentry.js +46 -9
  342. package/node_modules/@litcodex/lit-loop/dist/rewind-cli.d.ts +10 -0
  343. package/node_modules/@litcodex/lit-loop/dist/rewind-cli.js +88 -0
  344. package/node_modules/@litcodex/lit-loop/dist/rewind-go.d.ts +20 -0
  345. package/node_modules/@litcodex/lit-loop/dist/rewind-go.js +84 -0
  346. package/node_modules/@litcodex/lit-loop/dist/rewind-look.d.ts +6 -0
  347. package/node_modules/@litcodex/lit-loop/dist/rewind-look.js +41 -0
  348. package/node_modules/@litcodex/lit-loop/dist/rewind-redact.d.ts +3 -0
  349. package/node_modules/@litcodex/lit-loop/dist/rewind-redact.js +40 -0
  350. package/node_modules/@litcodex/lit-loop/dist/rewind-rollout.d.ts +48 -0
  351. package/node_modules/@litcodex/lit-loop/dist/rewind-rollout.js +292 -0
  352. package/node_modules/@litcodex/lit-loop/dist/rewind.d.ts +162 -0
  353. package/node_modules/@litcodex/lit-loop/dist/rewind.js +773 -0
  354. package/node_modules/@litcodex/lit-loop/dist/route-heads.js +44 -2
  355. package/node_modules/@litcodex/lit-loop/dist/run-panel.js +1 -0
  356. package/node_modules/@litcodex/lit-loop/dist/schematic-route.d.ts +6 -0
  357. package/node_modules/@litcodex/lit-loop/dist/schematic-route.js +35 -0
  358. package/node_modules/@litcodex/lit-loop/dist/screen-card.d.ts +3 -0
  359. package/node_modules/@litcodex/lit-loop/dist/screen-card.js +15 -5
  360. package/node_modules/@litcodex/lit-loop/dist/skill-mention-scope.js +6 -0
  361. package/node_modules/@litcodex/lit-loop/dist/stack-hook.d.ts +8 -0
  362. package/node_modules/@litcodex/lit-loop/dist/stack-hook.js +57 -0
  363. package/node_modules/@litcodex/lit-loop/dist/statusline.js +8 -3
  364. package/node_modules/@litcodex/lit-loop/dist/threads.d.ts +50 -0
  365. package/node_modules/@litcodex/lit-loop/dist/threads.js +178 -0
  366. package/node_modules/@litcodex/lit-loop/dist/trigger.d.ts +1 -1
  367. package/node_modules/@litcodex/lit-loop/dist/trigger.js +31 -6
  368. package/node_modules/@litcodex/lit-loop/dist/workflow-map.d.ts +10 -0
  369. package/node_modules/@litcodex/lit-loop/dist/workflow-map.js +11 -1
  370. package/node_modules/@litcodex/lit-loop/dist/workflow-stack.d.ts +132 -0
  371. package/node_modules/@litcodex/lit-loop/dist/workflow-stack.js +488 -0
  372. package/node_modules/@litcodex/lit-loop/package.json +1 -1
  373. package/node_modules/@litcodex/lit-loop/skills/lit-adhd/SKILL.md +181 -0
  374. package/node_modules/@litcodex/lit-loop/skills/lit-hijack/SKILL.md +449 -0
  375. package/node_modules/@litcodex/lit-loop/skills/lit-loop/SKILL.md +13 -4
  376. package/node_modules/@litcodex/lit-loop/skills/lit-plan/SKILL.md +6 -0
  377. package/node_modules/@litcodex/lit-loop/skills/lit-recap/SKILL.md +2 -0
  378. package/node_modules/@litcodex/lit-loop/skills/lit-schematic/SKILL.md +198 -0
  379. package/node_modules/@litcodex/lit-loop/skills/lit-scientific-visualization/SKILL.md +34 -8
  380. package/node_modules/@litcodex/lit-loop/skills/litresearch/SKILL.md +7 -0
  381. package/node_modules/@litcodex/lit-loop/skills/litwork/SKILL.md +2 -1
  382. package/node_modules/@litcodex/lit-loop/skills/review-work/SKILL.md +7 -1
  383. package/node_modules/@litcodex/lit-loop/skills/start-work/SKILL.md +10 -0
  384. package/package.json +2 -2
  385. package/readme-assets/badge-version.svg +1 -1
  386. package/readme-assets/skills/lit-adhd.webp +0 -0
  387. package/readme-assets/skills/lit-hijack.webp +0 -0
  388. package/readme-assets/skills/lit-schematic.webp +0 -0
@@ -0,0 +1,668 @@
1
+ // The per-film score (sound mode `score`, the default for rich films): a layered house-family track
2
+ // built in product code from the film itself, with no samples and no borrowed melodies. The film's
3
+ // own words seed its key, mode, tempo, progression, motif and percussion; its beats give the
4
+ // arrangement (intro, builds, the drop on the story's turn, a break, an outro) and the drop lands on
5
+ // a bar line. Each stem is its own buffer with its own pattern: kick, clap, hats, perc, bass (sub and
6
+ // line), chords (stabs and pad), lead, arrangement fx and on-screen events. The mix high-passes the
7
+ // stems, pans them, ducks bass, chords and lead under the kick, sends to a reverb and a tempo delay,
8
+ // compresses the bus and ends in the shared master stage (-16 LUFS BS.1770-4, lookahead limiter under
9
+ // -2 dBFS). Every stem is kept next to the mix, with a manifest, so the next round can rebalance.
10
+ import { createHash } from "node:crypto";
11
+ import { mkdirSync, writeFileSync } from "node:fs";
12
+ import { join } from "node:path";
13
+ import { SCORE_GENRES } from "./constants.mjs";
14
+ import { accentsFor, drawEvent, eventCues, masterTo, SOUND, writeWav } from "./sound.mjs";
15
+ import { DEFAULT_STYLE, readStyle } from "./styles.mjs";
16
+ import { fnv1a32, mulberry32 } from "./util.mjs";
17
+
18
+ // Not read from SOUND at load time: sound.mjs imports this module for prepareTrack, so SOUND may not
19
+ // exist yet while this file evaluates. buildScore checks the two agree.
20
+ const SR = 48000;
21
+ const TABLE = 4096;
22
+
23
+ /** Each genre's kit: tempo band, kick/bass/stab step patterns (16 steps a bar), swing, open hats, pad. */
24
+ const KITS = Object.freeze({
25
+ house: { bpm: [120, 126], kick: [0, 4, 8, 12], bass: [2, 6, 10, 14], stab: [3, 6, 11, 14], openHat: true, pad: false, swing: 0 },
26
+ "tech-house": { bpm: [124, 128], kick: [0, 4, 8, 12], bass: [1, 2, 3, 5, 6, 7, 9, 10, 11, 13, 14, 15], stab: [6, 14], openHat: true, pad: false, swing: 0.04 },
27
+ "deep-house": { bpm: [118, 122], kick: [0, 4, 8, 12], bass: [3, 6, 10, 14], stab: [2, 10], openHat: true, pad: true, swing: 0.08 },
28
+ garage: { bpm: [130, 134], kick: [0, 10], bass: [0, 3, 7, 10], stab: [3, 7, 11, 15], openHat: false, pad: true, swing: 0.16 },
29
+ });
30
+ if (SCORE_GENRES.some((g) => !KITS[g]) || Object.keys(KITS).length !== SCORE_GENRES.length) throw new Error("score kits and SCORE_GENRES disagree");
31
+
32
+ const KEY_NAMES = ["C", "Db", "D", "Eb", "E", "F", "F#", "G", "Ab", "A", "Bb", "B"];
33
+ const QUALITY = { maj: [0, 4, 7], min: [0, 3, 7], maj7: [0, 4, 7, 11], min7: [0, 3, 7, 10], dom7: [0, 4, 7, 10], maj9: [0, 4, 7, 11, 14], min9: [0, 3, 7, 10, 14] };
34
+ const ROMAN = ["I", "bII", "II", "bIII", "III", "IV", "#IV", "V", "bVI", "VI", "bVII", "VII"];
35
+ // Four-chord loops as [semitones above the tonic, quality]; one chord per bar.
36
+ const PROGRESSIONS = {
37
+ major: [
38
+ [[0, "maj"], [7, "maj"], [9, "min"], [5, "maj"]],
39
+ [[9, "min7"], [5, "maj7"], [0, "maj"], [7, "maj"]],
40
+ [[0, "maj7"], [4, "min7"], [5, "maj7"], [7, "dom7"]],
41
+ [[5, "maj7"], [7, "maj"], [4, "min7"], [9, "min7"]],
42
+ [[0, "maj7"], [9, "min7"], [2, "min7"], [7, "dom7"]],
43
+ [[2, "min9"], [7, "dom7"], [0, "maj9"], [0, "maj9"]],
44
+ ],
45
+ minor: [
46
+ [[0, "min"], [8, "maj"], [3, "maj"], [10, "maj"]],
47
+ [[0, "min7"], [5, "min7"], [10, "maj"], [3, "maj7"]],
48
+ [[0, "min"], [10, "maj"], [8, "maj"], [10, "maj"]],
49
+ [[0, "min7"], [7, "min7"], [8, "maj7"], [5, "min7"]],
50
+ [[8, "maj7"], [10, "maj"], [0, "min9"], [0, "min9"]],
51
+ [[0, "min9"], [5, "min7"], [0, "min9"], [7, "min7"]],
52
+ ],
53
+ };
54
+ const PENTATONIC = { major: [0, 2, 4, 7, 9], minor: [0, 3, 5, 7, 10] };
55
+ const chordName = ([offset, quality]) => `${quality.startsWith("min") ? ROMAN[offset].toLowerCase() : ROMAN[offset]}${quality.replace(/^(?:maj|min)$/u, "").replace(/^min/u, "")}`;
56
+
57
+ /** The stems in mix order: gain, pan, high-pass Hz, sidechain depth and the reverb and delay sends. */
58
+ const MIX = Object.freeze({
59
+ kick: { gain: 1.0, pan: 0, hp: 0, duck: 0, reverb: 0, delay: 0 },
60
+ clap: { gain: 0.5, pan: 0, hp: 180, duck: 0, reverb: 0.22, delay: 0 },
61
+ hats: { gain: 0.3, pan: 0.28, hp: 5000, duck: 0, reverb: 0.06, delay: 0 },
62
+ perc: { gain: 0.34, pan: -0.32, hp: 220, duck: 0.15, reverb: 0.16, delay: 0.1 },
63
+ bass: { gain: 0.62, pan: 0, hp: 0, duck: 0.85, reverb: 0, delay: 0 },
64
+ chords: { gain: 0.36, pan: 0, hp: 160, duck: 0.6, reverb: 0.3, delay: 0.12 },
65
+ lead: { gain: 0.3, pan: 0.16, hp: 260, duck: 0.3, reverb: 0.34, delay: 0.3 },
66
+ fx: { gain: 0.42, pan: 0, hp: 90, duck: 0, reverb: 0.28, delay: 0 },
67
+ events: { gain: 0.62, pan: 0, hp: 60, duck: 0, reverb: 0.12, delay: 0 },
68
+ });
69
+ export const SCORE_STEMS = Object.freeze(Object.keys(MIX));
70
+
71
+ const sectionAt = (sections, t) => sections.find((s) => t >= s.t0 && t < s.t1) ?? null;
72
+ const round6 = (x) => Math.round(x * 1e6) / 1e6;
73
+
74
+ /** The beats as an arrangement: intro, builds, the drop on the turn beat, a break before a second drop, an outro. */
75
+ function arrange(beats, turn) {
76
+ const last = beats.length - 1;
77
+ const after = last - turn;
78
+ return beats.map((b, i) => {
79
+ let kind;
80
+ if (i === turn) kind = "drop";
81
+ else if (i < turn) kind = i === 0 ? "intro" : "build";
82
+ else if (i === last) kind = "outro";
83
+ else kind = after >= 3 && i === turn + 1 ? "break" : "drop";
84
+ return { kind, t0: Number(b.t0), t1: Number(b.t1), beat: i };
85
+ });
86
+ }
87
+
88
+ /**
89
+ * The film's score plan: genre, key, mode, tempo, progression, motif, sections, kick times and the
90
+ * arrangement fx. Pure and seeded from the treatment, so two films differ and one film always plans
91
+ * the same. The genre is `sound.genre` or else the style's own (`style.score.genre`).
92
+ */
93
+ export function planScore({ treatment, durationSec }) {
94
+ const style = readStyle(treatment.style ?? DEFAULT_STYLE);
95
+ const genre = treatment.sound?.genre ?? style.score.genre;
96
+ const kit = KITS[genre];
97
+ if (!kit) throw new Error(`unknown score genre: ${genre} (choose ${SCORE_GENRES.join(", ")})`);
98
+ const beats = Array.isArray(treatment.beats) && treatment.beats.length ? treatment.beats : [{ t0: 0, t1: durationSec }];
99
+ const fingerprint = [treatment.request, treatment.idea, treatment.story?.turn, treatment.protagonist?.name, ...beats.map((b) => `${b.purpose}|${b.t0}|${b.t1}`)].join("\n");
100
+ const seed = fnv1a32(fingerprint);
101
+ const rand = mulberry32(seed);
102
+ const tonic = Math.floor(rand() * 12);
103
+ const mode = rand() < (genre === "deep-house" ? 0.45 : 0.62) ? "minor" : "major";
104
+ const bpm = kit.bpm[0] + Math.floor(rand() * (kit.bpm[1] - kit.bpm[0] + 1));
105
+ const progression = PROGRESSIONS[mode][Math.floor(rand() * PROGRESSIONS[mode].length)];
106
+ const turn = Number.isInteger(treatment.story?.beat) && treatment.story.beat < beats.length ? treatment.story.beat : Math.min(beats.length - 1, Math.floor(beats.length / 2));
107
+ const sections = arrange(beats, turn).map((s, i, all) => ({ ...s, t1: i === all.length - 1 ? durationSec : s.t1 }));
108
+ const drop = sections.find((s) => s.kind === "drop");
109
+ const stepSec = 60 / bpm / 4;
110
+ const barSec = 16 * stepSec;
111
+ // The grid is placed so that a bar line falls exactly on the drop; it may begin before 0 s.
112
+ const origin = drop.t0 - Math.ceil(drop.t0 / barSec - 1e-9) * barSec;
113
+ const steps = [];
114
+ for (let n = Math.ceil(-origin / stepSec - 1e-9); origin + n * stepSec < durationSec - 1e-9; n++) {
115
+ const pos = ((n % 16) + 16) % 16;
116
+ const t = origin + n * stepSec + (pos % 2 ? kit.swing * stepSec : 0);
117
+ if (t < 0 || t >= durationSec) continue;
118
+ steps.push({ n, pos, bar: Math.floor(n / 16), t, section: sectionAt(sections, t) });
119
+ }
120
+ // Kicks run from the first build on, leave the half bar before the drop empty and stop short of the outro's end.
121
+ const preDrop = drop.t0 - barSec / 2;
122
+ const kicks = steps
123
+ .filter((s) => s.section && ["build", "drop", "outro"].includes(s.section.kind) && kit.kick.includes(s.pos) && !(s.t >= preDrop && s.t < drop.t0) && !(s.section.kind === "outro" && s.t > s.section.t1 - barSec / 2))
124
+ .map((s) => round6(s.t));
125
+ // A motif of one bar: a random walk on the pentatonic scale.
126
+ const motif = [];
127
+ let degree = Math.floor(rand() * 3);
128
+ for (let pos = 0; pos < 16; pos++) {
129
+ if (rand() < (pos % 4 === 0 ? 0.62 : 0.4)) {
130
+ degree = Math.max(0, Math.min(7, degree + Math.floor(rand() * 5) - 2));
131
+ motif.push({ pos, degree });
132
+ }
133
+ }
134
+ const percPattern = Array.from({ length: 16 }, (_, pos) => (pos % 4 !== 0 && rand() < 0.38 ? 1 + Math.floor(rand() * 3) : 0));
135
+ const fx = [];
136
+ sections.forEach((s, i) => {
137
+ if (i === 0) return;
138
+ const into = s.kind === "drop";
139
+ const span = Math.min(into ? 2 * barSec : barSec / 2, s.t0 - sections[i - 1].t0);
140
+ fx.push({ kind: "riser", start: round6(s.t0 - span), t: s.t0, strength: into ? 1 : 0.45 });
141
+ if (into) fx.push({ kind: "impact", t: s.t0 });
142
+ if (sections[i - 1].kind === "drop" && !into) fx.push({ kind: "downlifter", t: s.t0, end: round6(Math.min(s.t1, s.t0 + barSec)) });
143
+ if (!into) fx.push({ kind: "reverse", start: round6(s.t0 - Math.min(barSec / 2, s.t0 - sections[i - 1].t0)), t: s.t0 });
144
+ });
145
+ return { genre, key: KEY_NAMES[tonic], tonic, mode, bpm, seed, progression: progression.map(chordName), chords: progression, motif, percPattern, sections, kicks, fx, stepSec, barSec, origin, steps };
146
+ }
147
+
148
+ // ---------------------------------------------------------------------------- synthesis helpers
149
+
150
+ const midiHz = (m) => 440 * 2 ** ((m - 69) / 12);
151
+ // A one-pole coefficient, stable for any cutoff (below 1 Hz an unclamped one turns negative and diverges).
152
+ const onePole = (cutoff) => 1 - Math.exp((-2 * Math.PI * Math.max(1, cutoff)) / SR);
153
+
154
+ function biquadCoefficients(type, cutoff, q = 0.707) {
155
+ const w = (2 * Math.PI * Math.min(cutoff, SR * 0.45)) / SR;
156
+ const cos = Math.cos(w);
157
+ const alpha = Math.sin(w) / (2 * q);
158
+ const a0 = 1 + alpha;
159
+ const b = type === "hp" ? [(1 + cos) / 2, -(1 + cos), (1 + cos) / 2] : [(1 - cos) / 2, 1 - cos, (1 - cos) / 2];
160
+ return { b: b.map((v) => v / a0), a: [1, (-2 * cos) / a0, (1 - alpha) / a0] };
161
+ }
162
+
163
+ /** A biquad run over `x` in place. */
164
+ function filter(x, { b, a }) {
165
+ let x1 = 0;
166
+ let x2 = 0;
167
+ let y1 = 0;
168
+ let y2 = 0;
169
+ for (let i = 0; i < x.length; i++) {
170
+ const y = b[0] * x[i] + b[1] * x1 + b[2] * x2 - a[1] * y1 - a[2] * y2;
171
+ x2 = x1;
172
+ x1 = x[i];
173
+ y2 = y1;
174
+ y1 = y;
175
+ x[i] = y;
176
+ }
177
+ return x;
178
+ }
179
+
180
+ /** A normalized single-cycle table of additive partials, wrapped by one sample. */
181
+ function wavetable(harmonics) {
182
+ const table = new Float32Array(TABLE + 1);
183
+ let peak = 0;
184
+ for (let i = 0; i < TABLE; i++) {
185
+ let v = 0;
186
+ harmonics.forEach((amp, h) => {
187
+ if (amp) v += amp * Math.sin((2 * Math.PI * (h + 1) * i) / TABLE);
188
+ });
189
+ table[i] = v;
190
+ peak = Math.max(peak, Math.abs(v));
191
+ }
192
+ for (let i = 0; i < TABLE; i++) table[i] /= peak || 1;
193
+ table[TABLE] = table[0];
194
+ return table;
195
+ }
196
+ const SAW = wavetable([1, 0.5, 0.33, 0.25, 0.2, 0.16, 0.14, 0.12, 0.1, 0.08]);
197
+ const SQUARE = wavetable([1, 0, 0.33, 0, 0.2, 0, 0.14, 0, 0.11]);
198
+
199
+ /** A stereo buffer a stem writes into; `add` places a mono voice at sample s0 with constant-power pan. */
200
+ class Stem {
201
+ constructor(n) {
202
+ this.L = new Float64Array(n);
203
+ this.R = new Float64Array(n);
204
+ }
205
+
206
+ add(s0, mono, pan = 0, gain = 1) {
207
+ const gl = Math.cos(((pan + 1) * Math.PI) / 4) * Math.SQRT2 * gain;
208
+ const gr = Math.sin(((pan + 1) * Math.PI) / 4) * Math.SQRT2 * gain;
209
+ const end = Math.min(this.L.length, s0 + mono.length);
210
+ for (let s = Math.max(0, s0); s < end; s++) {
211
+ this.L[s] += gl * mono[s - s0];
212
+ this.R[s] += gr * mono[s - s0];
213
+ }
214
+ }
215
+ }
216
+
217
+ const buffer = (sec) => new Float64Array(Math.max(1, Math.round(sec * SR)));
218
+
219
+ function kickVoice() {
220
+ const b = buffer(0.36);
221
+ let ph = 0;
222
+ for (let i = 0; i < b.length; i++) {
223
+ const t = i / SR;
224
+ ph += (2 * Math.PI * (46 + 110 * Math.exp(-t / 0.035))) / SR;
225
+ b[i] = Math.exp(-t / 0.2) * Math.sin(ph) + (t < 0.004 ? 0.3 * (1 - t / 0.004) : 0);
226
+ }
227
+ return b;
228
+ }
229
+
230
+ function noiseVoice(rand, sec, decay, { hp = 0, lp = 0, bursts = 1, gap = 0.011 } = {}) {
231
+ const b = buffer(sec);
232
+ for (let i = 0; i < b.length; i++) {
233
+ const t = i / SR;
234
+ let env = 0;
235
+ for (let k = 0; k < bursts; k++) if (t >= k * gap) env = Math.max(env, Math.exp(-(t - k * gap) / (k === bursts - 1 ? decay : 0.006)));
236
+ b[i] = (rand() * 2 - 1) * env;
237
+ }
238
+ if (hp) filter(b, biquadCoefficients("hp", hp));
239
+ if (lp) filter(b, biquadCoefficients("lp", lp));
240
+ return b;
241
+ }
242
+
243
+ function toneVoice(hz, sec, decay, { partials = [1], attack = 0.002 } = {}) {
244
+ const b = buffer(sec);
245
+ for (let i = 0; i < b.length; i++) {
246
+ const t = i / SR;
247
+ let v = 0;
248
+ partials.forEach((a, k) => {
249
+ v += a * Math.sin(2 * Math.PI * hz * (k + 1) * t);
250
+ });
251
+ b[i] = v * Math.min(1, t / attack) * Math.exp(-t / decay);
252
+ }
253
+ return b;
254
+ }
255
+
256
+ /** A filtered table voice: each note as a detuned pair, an amp envelope and a low-pass that moves over the note. */
257
+ function tableVoice(table, notes, sec, { attack = 0.004, decay = 0.25, sustain = 0, release = 0.05, cutoff = 2400, cutoffEnd = 600, detune = 8, phase = 0 } = {}) {
258
+ const b = buffer(sec + release);
259
+ const hold = Math.round(sec * SR);
260
+ for (const note of notes) {
261
+ for (const cents of [-detune, detune]) {
262
+ const inc = (midiHz(note) * 2 ** (cents / 1200) * TABLE) / SR;
263
+ let ph = (phase * TABLE + (cents > 0 ? TABLE / 3 : 0)) % TABLE;
264
+ for (let i = 0; i < b.length; i++) {
265
+ const t = i / SR;
266
+ const env = Math.min(1, t / attack) * (sustain + (1 - sustain) * Math.exp(-t / decay)) * (i < hold ? 1 : Math.max(0, 1 - (i - hold) / (release * SR)));
267
+ ph = (ph + inc) % TABLE;
268
+ b[i] += (env * table[ph | 0]) / notes.length;
269
+ }
270
+ }
271
+ }
272
+ let f = 0;
273
+ for (let i = 0; i < b.length; i++) {
274
+ const u = Math.min(1, i / Math.max(1, b.length));
275
+ f += onePole(cutoff + (cutoffEnd - cutoff) * u) * (b[i] - f);
276
+ b[i] = f;
277
+ }
278
+ return b;
279
+ }
280
+
281
+ function voicing(plan, chord, octave = 48) {
282
+ const [offset, quality] = chord;
283
+ const root = octave + plan.tonic + offset - (offset > 6 ? 12 : 0);
284
+ return QUALITY[quality].map((iv) => root + iv);
285
+ }
286
+
287
+ /** The chord under time t: one per bar from the grid's origin; the film's last bar resolves home. */
288
+ function chordAt(plan, t, durationSec) {
289
+ if (t >= durationSec - plan.barSec && plan.sections.length > 1) return [0, plan.mode === "major" ? "maj7" : "min9"];
290
+ const bar = Math.floor((t - plan.origin) / plan.barSec);
291
+ return plan.chords[((bar % plan.chords.length) + plan.chords.length) % plan.chords.length];
292
+ }
293
+
294
+ /** Cue sheet entries for the look round: every section change on its cut, and every accent a beat asks for. */
295
+ function sectionCues(plan, beats) {
296
+ const cues = [];
297
+ plan.sections.forEach((s, i) => {
298
+ if (i > 0) cues.push({ kind: s.kind, t: s.t0, beat: s.beat, cutT: s.t0, delta: 0 });
299
+ for (const kind of accentsFor(beats[s.beat]?.sound)) if (kind === "hit" || kind === "cadence") cues.push({ kind, t: s.t0, beat: s.beat, cutT: s.t0, delta: 0 });
300
+ if (accentsFor(beats[s.beat]?.sound).includes("chime")) cues.push({ kind: "chime", t: round6((s.t0 + s.t1) / 2), beat: s.beat, cutT: round6((s.t0 + s.t1) / 2), delta: 0 });
301
+ });
302
+ return cues;
303
+ }
304
+
305
+ // ---------------------------------------------------------------------------- the score
306
+
307
+ /**
308
+ * Build the score for a film of `frameCount` frames at `fps`: the mixed track (`left`, `right`),
309
+ * every stem, the two send returns, the plan and the cue list. `cutTimes` are the picture's cuts
310
+ * (default: every beat's t0 after the first).
311
+ */
312
+ export function buildScore({ treatment, frameCount, fps, cutTimes = null }) {
313
+ if (SOUND.sampleRate !== SR) throw new Error("the score is written for 48 kHz");
314
+ const sampleCount = Math.round((frameCount * SR) / fps);
315
+ const durationSec = sampleCount / SR;
316
+ const plan = planScore({ treatment, durationSec });
317
+ const beats = Array.isArray(treatment.beats) ? treatment.beats : [];
318
+ const cuts = cutTimes ?? beats.slice(1).map((b) => b.t0);
319
+ const cues = [...sectionCues(plan, beats), ...eventCues({ events: treatment.sound?.events, durationSec, cutTimes: cuts, beats })].sort((a, b) => a.t - b.t || a.beat - b.beat || a.kind.localeCompare(b.kind));
320
+ const rand = mulberry32(plan.seed ^ 0x9e3779b9);
321
+ const kit = KITS[plan.genre];
322
+ const stems = Object.fromEntries(SCORE_STEMS.map((k) => [k, new Stem(sampleCount)]));
323
+ const at = (t) => Math.round(t * SR);
324
+ const kick = kickVoice();
325
+ const drop = plan.sections.find((s) => s.kind === "drop");
326
+
327
+ for (const t of plan.kicks) stems.kick.add(at(t), kick);
328
+ for (const step of plan.steps) {
329
+ const sec = step.section;
330
+ if (!sec) continue;
331
+ const { kind } = sec;
332
+ const full = kind === "build" || kind === "drop";
333
+ const progress = (step.t - sec.t0) / Math.max(1e-6, sec.t1 - sec.t0);
334
+ const inRoll = step.t >= drop.t0 - plan.barSec && step.t < drop.t0;
335
+ // Clap on two and four; a roll that tightens over the last bar into the drop.
336
+ if (full && (step.pos === 4 || step.pos === 12) && !inRoll) stems.clap.add(at(step.t), noiseVoice(rand, 0.3, 0.13, { hp: 900, lp: 5200, bursts: 3 }), 0, 1);
337
+ if (inRoll) {
338
+ const u = 1 - (drop.t0 - step.t) / plan.barSec;
339
+ if (u < 0.5 ? step.pos % 2 === 0 : true) stems.clap.add(at(step.t), noiseVoice(rand, 0.12, 0.05, { hp: 700, lp: 6000 }), 0, 0.35 + 0.65 * u);
340
+ if (u >= 0.75) stems.clap.add(at(step.t + plan.stepSec / 2), noiseVoice(rand, 0.08, 0.03, { hp: 700, lp: 6000 }), 0, 0.8 * u);
341
+ }
342
+ // Hats: closed sixteenths with offbeat accents, open hats on the offbeat in the drop.
343
+ const hatsOn = kind === "intro" ? step.pos % 2 === 0 : kind === "break" ? false : kind === "outro" ? step.pos % 2 === 0 : true;
344
+ if (hatsOn) stems.hats.add(at(step.t), noiseVoice(rand, 0.06, 0.018, { hp: 7000 }), 0, (step.pos % 4 === 2 ? 0.9 : 0.5) * (kind === "intro" ? 0.35 + 0.5 * progress : 1));
345
+ if (kind === "drop" && kit.openHat && step.pos % 4 === 2) stems.hats.add(at(step.t), noiseVoice(rand, 0.3, 0.12, { hp: 6000 }), -0.4, 0.55);
346
+ // Perc: the film's own sixteen-step pattern of rims and toms, silent in the break's first half.
347
+ const hit = plan.percPattern[step.pos];
348
+ if (hit && !(kind === "break" && progress < 0.5)) {
349
+ const tone = toneVoice([0, 520, 380, 760][hit], 0.16, hit === 3 ? 0.03 : 0.06, { partials: [1, 0.3] });
350
+ const click = noiseVoice(rand, 0.02, 0.004, { hp: 2000 });
351
+ for (let i = 0; i < click.length; i++) tone[i] += 0.5 * click[i];
352
+ stems.perc.add(at(step.t), tone, hit === 2 ? -0.5 : 0.35, kind === "intro" ? 0.5 : 0.85);
353
+ }
354
+ if (kind !== "intro" && kind !== "break" && step.pos % 2 === 1) stems.perc.add(at(step.t), noiseVoice(rand, 0.05, 0.012, { hp: 4500 }), 0.6, 0.25);
355
+ // Bass line: the kit's pattern on the chord root, from the middle of the builds on, out in the break.
356
+ const chord = chordAt(plan, step.t, durationSec);
357
+ const root = 36 + plan.tonic + chord[0] - (chord[0] > 6 ? 12 : 0);
358
+ if (((kind === "build" && progress > 0.25) || kind === "drop" || (kind === "outro" && progress < 0.5)) && kit.bass.includes(step.pos)) {
359
+ const octave = step.pos % 8 === 6 && plan.genre !== "deep-house" ? 12 : 0;
360
+ stems.bass.add(at(step.t), tableVoice(SAW, [root + octave], plan.stepSec * 0.9, { decay: 0.12, sustain: 0.5, cutoff: 1400, cutoffEnd: 300, detune: 4 }), 0, 0.75);
361
+ }
362
+ // Chord stabs on the kit's steps in builds and drops.
363
+ if (full && kit.stab.includes(step.pos)) {
364
+ stems.chords.add(at(step.t), tableVoice(SAW, voicing(plan, chord, 60), plan.stepSec * 1.4, { decay: 0.09, cutoff: kind === "drop" ? 4200 : 1800 + 2200 * progress, cutoffEnd: 900, detune: 11 }), 0, 0.9);
365
+ }
366
+ // Lead: the motif in the drop and the break (an octave up and drier in the break).
367
+ if (kind === "drop" || kind === "break") {
368
+ const note = plan.motif.find((m) => m.pos === step.pos);
369
+ if (note) {
370
+ const scale = PENTATONIC[plan.mode];
371
+ const d = note.degree + (step.bar % 4 === 3 && note.pos >= 8 ? 2 : 0);
372
+ const midi = 72 + plan.tonic + scale[d % 5] + 12 * Math.floor(d / 5) + (kind === "break" ? 12 : 0);
373
+ stems.lead.add(at(step.t), tableVoice(SQUARE, [midi], plan.stepSec * 1.8, { decay: 0.16, sustain: 0.2, cutoff: 5200, cutoffEnd: 1400, detune: 6 }), 0, kind === "break" ? 0.6 : 1);
374
+ }
375
+ }
376
+ }
377
+
378
+ // Sustained layers, one chord per bar: the sub under the drop and outro, the pad in the intro,
379
+ // builds, break and outro (and under the drop for the pad genres), its filter opening over the section.
380
+ for (let bar = Math.floor(-plan.origin / plan.barSec) - 1; plan.origin + bar * plan.barSec < durationSec; bar++) {
381
+ const t0 = Math.max(0, plan.origin + bar * plan.barSec);
382
+ const t1 = Math.min(durationSec, plan.origin + (bar + 1) * plan.barSec);
383
+ if (t1 <= t0) continue;
384
+ const chord = chordAt(plan, (t0 + t1) / 2, durationSec);
385
+ const sec = sectionAt(plan.sections, (t0 + t1) / 2);
386
+ if (!sec) continue;
387
+ const root = 36 + plan.tonic + chord[0] - (chord[0] > 6 ? 12 : 0);
388
+ if (sec.kind === "drop" || sec.kind === "outro") {
389
+ const sub = toneVoice(midiHz(root), t1 - t0 + 0.05, 1e6, { attack: 0.01 });
390
+ const tail = Math.round(0.05 * SR);
391
+ for (let i = 0; i < Math.min(tail, sub.length); i++) sub[sub.length - 1 - i] *= i / tail;
392
+ stems.bass.add(at(t0), sub, 0, 0.55);
393
+ }
394
+ if (sec.kind !== "drop" || kit.pad) {
395
+ // A bar may start before its section (the grid can begin before 0 s or before the beat), so clamp.
396
+ const u = Math.min(1, Math.max(0, (t0 - sec.t0) / Math.max(1e-6, sec.t1 - sec.t0)));
397
+ const open = sec.kind === "intro" || sec.kind === "build" ? 700 + 3000 * u : sec.kind === "break" ? 2600 : 1800;
398
+ stems.chords.add(at(t0), tableVoice(SAW, voicing(plan, chord, 48), t1 - t0, { attack: 0.25, decay: 1e6, sustain: 1, release: 0.4, cutoff: open, cutoffEnd: open * 1.3, detune: 14, phase: (bar * 0.37) % 1 }), 0, sec.kind === "drop" ? 0.35 : 0.6);
399
+ }
400
+ }
401
+
402
+ // Arrangement fx: a riser into each change (the strongest into the drop), the impact on the drop,
403
+ // a downlifter after it, and a reverse swell of the coming chord into each change that is not a drop.
404
+ for (const f of plan.fx) {
405
+ if (f.kind === "riser") {
406
+ const len = Math.max(1, at(f.t) - at(f.start));
407
+ const b = new Float64Array(len);
408
+ let lp = 0;
409
+ let ph = 0;
410
+ for (let i = 0; i < len; i++) {
411
+ const u = i / len;
412
+ lp += onePole(300 + 7000 * u * u) * (rand() * 2 - 1 - lp);
413
+ ph += (2 * Math.PI * midiHz(60 + plan.tonic + 24 * u)) / SR;
414
+ b[i] = f.strength * u * u * (0.8 * lp + 0.25 * Math.sin(ph));
415
+ }
416
+ stems.fx.add(at(f.start), b, 0, 1);
417
+ } else if (f.kind === "impact") {
418
+ const boom = toneVoice(42, 1.6, 0.5, { attack: 0.001 });
419
+ const crash = noiseVoice(rand, 1.4, 0.45, { hp: 3000 });
420
+ for (let i = 0; i < boom.length; i++) boom[i] = 0.9 * boom[i] + 0.35 * (crash[i] ?? 0);
421
+ stems.fx.add(at(f.t), boom, 0, 1);
422
+ } else if (f.kind === "reverse") {
423
+ const sec = Math.max(1 / SR, f.t - f.start);
424
+ const tail = tableVoice(SAW, voicing(plan, chordAt(plan, f.t, durationSec), 60), sec, { attack: 0.002, decay: sec * 0.45, sustain: 0, release: 0.01, cutoff: 4200, cutoffEnd: 900, detune: 10 });
425
+ tail.reverse();
426
+ stems.fx.add(at(f.start), tail, 0, 0.5);
427
+ } else {
428
+ const len = Math.max(1, at(f.end) - at(f.t));
429
+ const b = new Float64Array(len);
430
+ let lp = 0;
431
+ for (let i = 0; i < len; i++) {
432
+ const u = 1 - i / len;
433
+ lp += onePole(200 + 5000 * u * u) * (rand() * 2 - 1 - lp);
434
+ b[i] = 0.6 * u * u * lp;
435
+ }
436
+ stems.fx.add(at(f.t), b, 0, 1);
437
+ }
438
+ }
439
+
440
+ // Cues: the beats' own asks (a hit on a cut, a cadence, a chime) and every on-screen event on its time.
441
+ const eventRand = mulberry32(plan.seed ^ 0x51ed270b);
442
+ for (const cue of cues) {
443
+ if (cue.kind === "hit") stems.fx.add(at(cue.t), toneVoice(55, 0.5, 0.18, { partials: [1, 0.4] }), 0, 0.7);
444
+ else if (cue.kind === "cadence") stems.chords.add(at(cue.t), tableVoice(SAW, voicing(plan, [0, plan.mode === "major" ? "maj9" : "min9"], 60), 1.2, { attack: 0.01, decay: 0.8, cutoff: 3200, cutoffEnd: 800 }), 0, 0.7);
445
+ else if (cue.kind === "chime") stems.fx.add(at(cue.t), toneVoice(midiHz(84 + plan.tonic), 1.2, 0.4, { partials: [1, 0, 0.2] }), 0.2, 0.4);
446
+ else if (cue.kind === "event") drawEvent(stems.events.L, stems.events.R, cue, { tonicMidi: 60 + plan.tonic, minor: plan.mode === "minor", rand: eventRand });
447
+ }
448
+
449
+ // The mix: high-pass, gain and pan per stem, the sidechain from the kick times, then the sends.
450
+ const duck = new Float64Array(sampleCount).fill(1);
451
+ for (const t of plan.kicks) {
452
+ const s0 = at(t);
453
+ for (let i = 0; i < at(0.4) && s0 + i < sampleCount; i++) {
454
+ const dt = i / SR;
455
+ duck[s0 + i] = Math.min(duck[s0 + i], 1 - (dt < 0.004 ? dt / 0.004 : Math.exp(-(dt - 0.004) / 0.07)));
456
+ }
457
+ }
458
+ const reverbIn = [new Float64Array(sampleCount), new Float64Array(sampleCount)];
459
+ const delayIn = [new Float64Array(sampleCount), new Float64Array(sampleCount)];
460
+ for (const name of SCORE_STEMS) {
461
+ const m = MIX[name];
462
+ const { L, R } = stems[name];
463
+ if (m.hp) {
464
+ const hp = biquadCoefficients("hp", m.hp);
465
+ filter(L, hp);
466
+ filter(R, hp);
467
+ }
468
+ const pl = Math.cos(((m.pan + 1) * Math.PI) / 4) * Math.SQRT2;
469
+ const pr = Math.sin(((m.pan + 1) * Math.PI) / 4) * Math.SQRT2;
470
+ for (let s = 0; s < sampleCount; s++) {
471
+ const g = m.gain * (1 - m.duck * (1 - duck[s]));
472
+ L[s] *= g * pl;
473
+ R[s] *= g * pr;
474
+ reverbIn[0][s] += m.reverb * L[s];
475
+ reverbIn[1][s] += m.reverb * R[s];
476
+ delayIn[0][s] += m.delay * L[s];
477
+ delayIn[1][s] += m.delay * R[s];
478
+ }
479
+ }
480
+ const reverb = reverbReturn(reverbIn);
481
+ const delay = delayReturn(delayIn, (60 / plan.bpm) * 0.75, (60 / plan.bpm) * 0.5);
482
+
483
+ // The bus: every stem and both returns, compressed, faded at the end, then mastered.
484
+ const busL = new Float64Array(sampleCount);
485
+ const busR = new Float64Array(sampleCount);
486
+ for (const { L, R } of [...SCORE_STEMS.map((k) => stems[k]), reverb, delay]) {
487
+ for (let s = 0; s < sampleCount; s++) {
488
+ busL[s] += L[s];
489
+ busR[s] += R[s];
490
+ }
491
+ }
492
+ let peak = 0;
493
+ for (let s = 0; s < sampleCount; s++) peak = Math.max(peak, Math.abs(busL[s]), Math.abs(busR[s]));
494
+ const norm = peak > 0 ? 1 / peak : 1;
495
+ const comp = compressor(busL, busR, norm);
496
+ const fade = Math.min(at(0.4), Math.floor(sampleCount / 10));
497
+ for (let i = 0; i < fade; i++) {
498
+ busL[sampleCount - 1 - i] *= i / fade;
499
+ busR[sampleCount - 1 - i] *= i / fade;
500
+ }
501
+ const { left, right, gain, lufs } = masterTo(busL, busR);
502
+ const scale = norm * gain * comp.meanGain;
503
+ const out = (st) => ({ left: Float32Array.from(st.L, (v) => v * scale), right: Float32Array.from(st.R, (v) => v * scale) });
504
+ return {
505
+ left,
506
+ right,
507
+ sampleCount,
508
+ plan,
509
+ cues,
510
+ stems: Object.fromEntries(SCORE_STEMS.map((k) => [k, out(stems[k])])),
511
+ returns: { reverb: out(reverb), delay: out(delay) },
512
+ lufs: Math.round(lufs * 100) / 100,
513
+ loudnessMethod: "BS.1770-4",
514
+ bus: { ratio: comp.ratio, thresholdDbfs: comp.thresholdDbfs, maxReductionDb: Math.round(comp.maxReductionDb * 100) / 100 },
515
+ };
516
+ }
517
+
518
+ /** A small Schroeder reverb per channel: four damped combs into two all-passes, the right channel offset. */
519
+ function reverbReturn([inL, inR]) {
520
+ const pre = biquadCoefficients("hp", 300);
521
+ const run = (input, spread) => {
522
+ const x = filter(Float64Array.from(input), pre);
523
+ const y = new Float64Array(x.length);
524
+ for (const d of [1687, 1601, 1491, 1422].map((n) => n + spread)) {
525
+ const line = new Float64Array(d);
526
+ let k = 0;
527
+ let damp = 0;
528
+ for (let i = 0; i < x.length; i++) {
529
+ const heard = line[k];
530
+ damp = heard * 0.7 + damp * 0.3;
531
+ line[k] = x[i] + damp * 0.8;
532
+ y[i] += heard * 0.25;
533
+ k = (k + 1) % d;
534
+ }
535
+ }
536
+ for (const d of [556, 441].map((n) => n + spread)) {
537
+ const line = new Float64Array(d);
538
+ let k = 0;
539
+ for (let i = 0; i < y.length; i++) {
540
+ const held = line[k];
541
+ const v = -0.5 * y[i] + held;
542
+ line[k] = y[i] + 0.5 * held;
543
+ y[i] = v;
544
+ k = (k + 1) % d;
545
+ }
546
+ }
547
+ return y;
548
+ };
549
+ return { L: run(inL, 0), R: run(inR, 23) };
550
+ }
551
+
552
+ /** A tempo delay: a dotted eighth left and an eighth right, low-passed in the feedback path. */
553
+ function delayReturn([inL, inR], leftSec, rightSec) {
554
+ const run = (input, sec) => {
555
+ const d = Math.max(1, Math.round(sec * SR));
556
+ const y = new Float64Array(input.length);
557
+ const c = onePole(3200);
558
+ let lp = 0;
559
+ for (let i = 0; i < input.length; i++) {
560
+ lp += c * ((i >= d ? y[i - d] : 0) - lp);
561
+ y[i] = (i >= d ? input[i - d] : 0) + 0.36 * lp;
562
+ }
563
+ return y;
564
+ };
565
+ return { L: run(inL, leftSec), R: run(inR, rightSec) };
566
+ }
567
+
568
+ /** Bus compression in place on the peak-normalized bus: 10 ms attack, 150 ms release, 2.5:1 over -10 dBFS. */
569
+ function compressor(L, R, norm) {
570
+ const thresholdDbfs = -10;
571
+ const ratio = 2.5;
572
+ const attack = Math.exp(-1 / (0.01 * SR));
573
+ const release = Math.exp(-1 / (0.15 * SR));
574
+ let env = 0;
575
+ let sum = 0;
576
+ let maxReductionDb = 0;
577
+ for (let s = 0; s < L.length; s++) {
578
+ const x = Math.max(Math.abs(L[s]), Math.abs(R[s])) * norm;
579
+ env = x > env ? attack * env + (1 - attack) * x : release * env + (1 - release) * x;
580
+ const over = Math.max(0, 20 * Math.log10(Math.max(env, 1e-9)) - thresholdDbfs);
581
+ const reductionDb = over - over / ratio;
582
+ maxReductionDb = Math.max(maxReductionDb, reductionDb);
583
+ const g = 10 ** (-reductionDb / 20);
584
+ L[s] *= g;
585
+ R[s] *= g;
586
+ sum += g;
587
+ }
588
+ return { thresholdDbfs, ratio, maxReductionDb, meanGain: L.length ? sum / L.length : 1 };
589
+ }
590
+
591
+ const rmsDbfs = (st) => {
592
+ let s = 0;
593
+ for (let i = 0; i < st.left.length; i++) s += st.left[i] * st.left[i] + st.right[i] * st.right[i];
594
+ const v = Math.sqrt(s / Math.max(1, 2 * st.left.length));
595
+ return v > 0 ? Math.round(20 * Math.log10(v) * 100) / 100 : -200;
596
+ };
597
+
598
+ /** How far the bass dips right after a kick in the drop against 150-210 ms later (dB); 0 when it cannot be measured. */
599
+ export function sidechainDepth(score) {
600
+ const drop = score.plan.sections.find((x) => x.kind === "drop");
601
+ const bass = score.stems.bass.left;
602
+ const window = (a, b) => {
603
+ let s = 0;
604
+ for (let i = a; i < b; i++) s += bass[i] * bass[i];
605
+ return Math.sqrt(s / Math.max(1, b - a));
606
+ };
607
+ let near = 0;
608
+ let away = 0;
609
+ for (const k of score.plan.kicks.filter((t) => t >= drop.t0 && t + 0.25 < drop.t1)) {
610
+ const i = Math.round(k * SR);
611
+ near += window(i + Math.round(0.005 * SR), i + Math.round(0.035 * SR));
612
+ away += window(i + Math.round(0.15 * SR), i + Math.round(0.21 * SR));
613
+ }
614
+ return near > 0 && away > 0 ? Math.round(20 * Math.log10(away / near) * 100) / 100 : 0;
615
+ }
616
+
617
+ /**
618
+ * Write `sound/score.wav`, every stem and send return under `sound/stems/` with
619
+ * `sound/stems/manifest.json` (per-stem RMS and SHA-256), and the cue sheet `sound-cues.json`.
620
+ * Returns the summary that is also the cue sheet's body.
621
+ */
622
+ export function writeScore({ treatment, frameCount, fps, cutTimes = null, dir }) {
623
+ const score = buildScore({ treatment, frameCount, fps, cutTimes });
624
+ const stemsDir = join(dir, "sound", "stems");
625
+ mkdirSync(stemsDir, { recursive: true });
626
+ const file = join(dir, "sound", "score.wav");
627
+ const wav = writeWav([score.left, score.right], SR);
628
+ writeFileSync(file, wav);
629
+ const stems = [];
630
+ for (const [name, st] of [...Object.entries(score.stems), ...Object.entries(score.returns).map(([k, v]) => [`return-${k}`, v])]) {
631
+ const bytes = writeWav([st.left, st.right], SR);
632
+ const rel = join("sound", "stems", `${name}.wav`);
633
+ writeFileSync(join(dir, rel), bytes);
634
+ const send = name.startsWith("return-");
635
+ stems.push({ name, file: rel, rmsDbfs: rmsDbfs(st), sha256: createHash("sha256").update(bytes).digest("hex"), ...(send ? { kind: "return" } : { gain: MIX[name].gain, pan: MIX[name].pan, highpassHz: MIX[name].hp, sidechain: MIX[name].duck }) });
636
+ }
637
+ let peak = 0;
638
+ for (const ch of [score.left, score.right]) for (let i = 0; i < ch.length; i++) peak = Math.max(peak, Math.abs(ch[i]));
639
+ const { plan } = score;
640
+ const summary = {
641
+ schema: "litcodex.motion-sound-cues/v1",
642
+ mode: "score",
643
+ file,
644
+ sha256: createHash("sha256").update(wav).digest("hex"),
645
+ sampleRate: SR,
646
+ sampleCount: score.sampleCount,
647
+ durationSec: round6(score.sampleCount / SR),
648
+ frameCount,
649
+ fps,
650
+ genre: plan.genre,
651
+ key: `${plan.key} ${plan.mode}`,
652
+ tempo: plan.bpm,
653
+ progression: plan.progression.join(" - "),
654
+ sections: plan.sections.map(({ kind, t0, t1, beat }) => ({ kind, t0, t1, beat })),
655
+ fx: plan.fx,
656
+ stems,
657
+ sidechainDb: sidechainDepth(score),
658
+ bus: score.bus,
659
+ lufs: score.lufs,
660
+ peakDb: peak > 0 ? Math.round(20 * Math.log10(peak) * 100) / 100 : -200,
661
+ loudnessMethod: score.loudnessMethod,
662
+ cutTimes: (cutTimes ?? []).map((t) => Math.round(t * 1e4) / 1e4),
663
+ cues: score.cues,
664
+ };
665
+ writeFileSync(join(stemsDir, "manifest.json"), `${JSON.stringify({ schema: "litcodex.motion-stems/v1", genre: plan.genre, key: summary.key, tempo: plan.bpm, stems }, null, 2)}\n`);
666
+ writeFileSync(join(dir, "sound-cues.json"), `${JSON.stringify(summary, null, 2)}\n`);
667
+ return summary;
668
+ }