@johnhenry/mallory-cli 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +60 -2
- package/bin/mallory.mjs +51 -0
- package/package.json +51 -4
- package/src/a2a/client.js +511 -0
- package/src/a2a/demo-agent.js +396 -0
- package/src/a2a/hub.js +578 -0
- package/src/a2a/settings.js +88 -0
- package/src/a2a/task.js +358 -0
- package/src/acp/client.js +573 -0
- package/src/acp/demo-agent.js +332 -0
- package/src/acp/hub.js +632 -0
- package/src/acp/settings.js +78 -0
- package/src/actions/map.js +524 -0
- package/src/agent/cloud.js +77 -0
- package/src/agent/compact.js +84 -0
- package/src/agent/constants.js +39 -0
- package/src/agent/diff.js +101 -0
- package/src/agent/fork.js +159 -0
- package/src/agent/grounding.js +73 -0
- package/src/agent/guards.js +129 -0
- package/src/agent/local-transport.js +152 -0
- package/src/agent/loop.js +479 -0
- package/src/agent/park-store.js +77 -0
- package/src/agent/park.js +76 -0
- package/src/agent/ports.js +28 -0
- package/src/agent/providers.js +591 -0
- package/src/agent/restart.js +51 -0
- package/src/agent/router.js +380 -0
- package/src/agent/run.js +861 -0
- package/src/agent/tools.js +247 -0
- package/src/agent-library/engine.js +43 -0
- package/src/ai/bridge.js +155 -0
- package/src/ai/policy.js +131 -0
- package/src/aimatey/vendor.js +18 -0
- package/src/audio/container-duration.js +35 -0
- package/src/audio/instruments.js +776 -0
- package/src/audio/lanes.js +230 -0
- package/src/audio/patch.js +1410 -0
- package/src/audio/plan.js +276 -0
- package/src/audio/rack.js +1006 -0
- package/src/audio/sample-trim.js +293 -0
- package/src/audio/soundfont.js +243 -0
- package/src/audio/take-store.js +87 -0
- package/src/audio/takes.js +129 -0
- package/src/audio/wav.js +170 -0
- package/src/audio/zzfx.js +333 -0
- package/src/autonomy/bundle.js +207 -0
- package/src/autonomy/confine.js +61 -0
- package/src/autonomy/enforce.js +155 -0
- package/src/autonomy/file-kv.js +88 -0
- package/src/autonomy/ledger.js +203 -0
- package/src/autonomy/pins.js +50 -0
- package/src/autonomy/psl/index.js +32 -0
- package/src/autonomy/psl/suffixes.json +1 -0
- package/src/autonomy/record.js +28 -0
- package/src/autonomy/routines.js +107 -0
- package/src/autonomy/server.js +175 -0
- package/src/autonomy/signer-node.js +167 -0
- package/src/autonomy/store.js +43 -0
- package/src/autonomy/unattended.js +13 -0
- package/src/bytes/bytes.js +378 -0
- package/src/calc/syntax.js +125 -0
- package/src/calc/tex.js +28 -0
- package/src/calendar/vendor.js +2 -0
- package/src/clipboard.js +130 -0
- package/src/clsh/clsh.js +3417 -0
- package/src/codec/capnp.js +1804 -0
- package/src/codec/core.js +2043 -0
- package/src/codec/vendor/avro.js +136 -0
- package/src/codec/vendor/cbor.js +25 -0
- package/src/codec/vendor/flatbuffers.js +206 -0
- package/src/codec/vendor/msgpack.js +9 -0
- package/src/codec/vendor/protobuf.js +53 -0
- package/src/delegation/caps.js +60 -0
- package/src/delegation/config.js +32 -0
- package/src/device/model.js +246 -0
- package/src/device/recording.js +198 -0
- package/src/device/stream-model.js +151 -0
- package/src/documents/documents.js +1224 -0
- package/src/effects/catalog.js +63 -0
- package/src/effects/extras.js +133 -0
- package/src/effects/parse.js +339 -0
- package/src/embed/protocol.js +131 -0
- package/src/env/env.js +159 -0
- package/src/exact/vendor.js +45 -0
- package/src/example-meta.js +164 -0
- package/src/examples.js +94 -0
- package/src/export/canvas-image.js +217 -0
- package/src/export/expr-latex-lazy.js +8 -0
- package/src/export/formats.js +322 -0
- package/src/export/latex.js +183 -0
- package/src/export/pane.js +184 -0
- package/src/export/value.js +452 -0
- package/src/export/zip.js +214 -0
- package/src/ext/access.js +58 -0
- package/src/ext/btasks.js +225 -0
- package/src/ext/client.js +209 -0
- package/src/ext/tools.js +69 -0
- package/src/ext/view.js +105 -0
- package/src/ext/webmcp-tabs.js +299 -0
- package/src/files/archive.js +232 -0
- package/src/files/files.js +317 -0
- package/src/formats/json.js +24 -0
- package/src/formats/jupyter.js +188 -0
- package/src/formats/markdown.js +254 -0
- package/src/formats/n8n.js +276 -0
- package/src/formats/node-red.js +363 -0
- package/src/formats/registry.js +177 -0
- package/src/formats/rivet.js +259 -0
- package/src/formats/shared.js +98 -0
- package/src/formats/structure.js +182 -0
- package/src/formats/yaml.js +127 -0
- package/src/frame/frame.js +962 -0
- package/src/frame/vendor.js +1484 -0
- package/src/gate/audit.js +116 -0
- package/src/gate/gate.js +365 -0
- package/src/gate/policy.js +295 -0
- package/src/gate/scripted.js +110 -0
- package/src/gate/seams.js +32 -0
- package/src/gate/store.js +66 -0
- package/src/geometry/model.js +533 -0
- package/src/grant-key.js +149 -0
- package/src/graph/model.js +381 -0
- package/src/headless/a2a-push.js +123 -0
- package/src/headless/channels/config.js +142 -0
- package/src/headless/channels/connectors.js +283 -0
- package/src/headless/channels/index.js +257 -0
- package/src/headless/channels/mail.js +197 -0
- package/src/headless/channels/mailnet.js +223 -0
- package/src/headless/channels/platforms.js +194 -0
- package/src/headless/channels/replay.js +49 -0
- package/src/headless/cli.js +1397 -0
- package/src/headless/companion-client.js +182 -0
- package/src/headless/cost-cli.js +177 -0
- package/src/headless/deprecations-cli.js +102 -0
- package/src/headless/examples.js +48 -0
- package/src/headless/ffmpeg-exec.js +217 -0
- package/src/headless/gateways/config.js +213 -0
- package/src/headless/gateways/homeassistant.js +159 -0
- package/src/headless/gateways/index.js +121 -0
- package/src/headless/gateways/matter.js +150 -0
- package/src/headless/gateways/mqtt-client.js +177 -0
- package/src/headless/gateways/mqtt.js +70 -0
- package/src/headless/gateways/netway.js +226 -0
- package/src/headless/gateways/serverpod-worker.mjs +16 -0
- package/src/headless/gateways/serverpod.js +71 -0
- package/src/headless/gateways/util.js +27 -0
- package/src/headless/grant-cli.js +208 -0
- package/src/headless/guard.js +125 -0
- package/src/headless/guards.js +124 -0
- package/src/headless/machine-cli.js +853 -0
- package/src/headless/mcp-endpoint.js +287 -0
- package/src/headless/mcp-roots.js +38 -0
- package/src/headless/model-endpoint.js +88 -0
- package/src/headless/net.js +151 -0
- package/src/headless/node.js +263 -0
- package/src/headless/npm-tarball.js +29 -0
- package/src/headless/operator-page.js +112 -0
- package/src/headless/operator.js +242 -0
- package/src/headless/people.js +34 -0
- package/src/headless/pkg-cli.js +1103 -0
- package/src/headless/pkg-serve.js +138 -0
- package/src/headless/process-worker.js +88 -0
- package/src/headless/runner-remote.js +477 -0
- package/src/headless/sandbox-child.mjs +21 -0
- package/src/headless/scheduled.js +557 -0
- package/src/headless/serve-stream.js +97 -0
- package/src/headless/serve.js +2238 -0
- package/src/headless/short-links.js +158 -0
- package/src/headless/static-dirs.js +207 -0
- package/src/headless/trust-file.js +51 -0
- package/src/headless/watch.js +291 -0
- package/src/headless/ws-connect.js +65 -0
- package/src/headless/ws-connections.js +44 -0
- package/src/headless/ws-echo.js +150 -0
- package/src/headless/ws-proxy.js +354 -0
- package/src/headless/ws-ticket.js +48 -0
- package/src/hooks/config.js +50 -0
- package/src/hooks/engine.js +189 -0
- package/src/input/log.js +613 -0
- package/src/input/player.js +217 -0
- package/src/input/replay.js +209 -0
- package/src/jth/vendor.js +28 -0
- package/src/ledger/tx.js +94 -0
- package/src/machine/apply.js +193 -0
- package/src/machine/diff.js +168 -0
- package/src/machine/drive.js +296 -0
- package/src/machine/engine.js +478 -0
- package/src/machine/files-tool.js +76 -0
- package/src/machine/lint.js +139 -0
- package/src/machine/llmtm-trace.js +117 -0
- package/src/machine/llmtm.js +475 -0
- package/src/machine/otel.js +80 -0
- package/src/machine/pane-provider.js +51 -0
- package/src/machine/propose.js +159 -0
- package/src/machine/random.js +52 -0
- package/src/machine/risk.js +107 -0
- package/src/machine/session.js +1017 -0
- package/src/machine/shell-tool.js +45 -0
- package/src/machine/tape.js +349 -0
- package/src/machine/templates.js +104 -0
- package/src/machine/trace.js +664 -0
- package/src/machine/view.js +73 -0
- package/src/machine/vm-tool.js +47 -0
- package/src/machine/watchdog.js +46 -0
- package/src/mcp/app-args.js +51 -0
- package/src/mcp/app-run.js +56 -0
- package/src/mcp/apps.js +468 -0
- package/src/mcp/cache.js +232 -0
- package/src/mcp/client.js +507 -0
- package/src/mcp/demo-app.js +183 -0
- package/src/mcp/demo-server.js +602 -0
- package/src/mcp/elicitation.js +116 -0
- package/src/mcp/hub.js +1326 -0
- package/src/mcp/roots.js +139 -0
- package/src/mcp/sampling.js +105 -0
- package/src/mcp/settings.js +125 -0
- package/src/mcp/tape.js +292 -0
- package/src/mcp/uri-template.js +156 -0
- package/src/mcp/wsh-client.js +164 -0
- package/src/media/animated-codec.js +7 -0
- package/src/media/animated.js +623 -0
- package/src/media/compare-agent.js +70 -0
- package/src/media/compare-job.js +63 -0
- package/src/media/compare-page.js +296 -0
- package/src/media/compare-worker.js +14 -0
- package/src/media/compare.js +600 -0
- package/src/media/contract.js +62 -0
- package/src/media/decode-frame.js +57 -0
- package/src/media/decode-pool.js +188 -0
- package/src/media/ffmpeg-edit.js +344 -0
- package/src/media/ffmpeg-wasm-client.js +121 -0
- package/src/media/ffmpeg-wasm-session.js +79 -0
- package/src/media/ffmpeg-wasm.js +139 -0
- package/src/media/ffmpeg-worker.js +23 -0
- package/src/media/ffmpeg.js +903 -0
- package/src/media/helpers.js +419 -0
- package/src/media/keep.js +108 -0
- package/src/media/metadata-worker.js +16 -0
- package/src/media/metadata.js +2518 -0
- package/src/media/mime.js +102 -0
- package/src/media/page-decode.js +74 -0
- package/src/media/persist.js +114 -0
- package/src/media/png.js +226 -0
- package/src/media/sample-input.js +67 -0
- package/src/media/store.js +86 -0
- package/src/media/wav.js +109 -0
- package/src/midi/mappings.js +250 -0
- package/src/midi/message.js +125 -0
- package/src/model/action-hub.js +143 -0
- package/src/model/adapters.js +284 -0
- package/src/model/agent-runs.js +12 -0
- package/src/model/arrange.js +308 -0
- package/src/model/automation-clock.js +494 -0
- package/src/model/automation.js +653 -0
- package/src/model/batches.js +78 -0
- package/src/model/binary-view.js +195 -0
- package/src/model/breakpoints.js +392 -0
- package/src/model/calc-settings.js +65 -0
- package/src/model/calendar.js +254 -0
- package/src/model/canvas-id.js +5 -0
- package/src/model/canvas.js +5048 -0
- package/src/model/channel-names.js +29 -0
- package/src/model/channels.js +692 -0
- package/src/model/chart-clock.js +631 -0
- package/src/model/chart-code.js +69 -0
- package/src/model/codecs.js +60 -0
- package/src/model/companion-access.js +271 -0
- package/src/model/companion-pane.js +50 -0
- package/src/model/composite.js +324 -0
- package/src/model/context.js +380 -0
- package/src/model/controls.js +231 -0
- package/src/model/converter-presets.js +368 -0
- package/src/model/cost.js +580 -0
- package/src/model/curve-transform.js +122 -0
- package/src/model/cycles.js +176 -0
- package/src/model/debug-log.js +168 -0
- package/src/model/decision-clock.js +100 -0
- package/src/model/decisions.js +265 -0
- package/src/model/desk.js +87 -0
- package/src/model/device-hub.js +400 -0
- package/src/model/diff.js +445 -0
- package/src/model/emit-events.js +179 -0
- package/src/model/errors.js +238 -0
- package/src/model/event-presets.js +297 -0
- package/src/model/events.js +1303 -0
- package/src/model/explicit-setters.js +139 -0
- package/src/model/field-mapping.js +623 -0
- package/src/model/files-pane.js +263 -0
- package/src/model/flow-idle.js +89 -0
- package/src/model/foreach.js +549 -0
- package/src/model/frame-loop.js +71 -0
- package/src/model/frame-pressure.js +180 -0
- package/src/model/function-scaffold.js +1000 -0
- package/src/model/geometry-settings.js +54 -0
- package/src/model/goals.js +176 -0
- package/src/model/graph-settings.js +76 -0
- package/src/model/grid-widget.js +175 -0
- package/src/model/groups.js +332 -0
- package/src/model/hash.js +21 -0
- package/src/model/history.js +259 -0
- package/src/model/http-copy.js +88 -0
- package/src/model/http-send-companion.js +110 -0
- package/src/model/http-send.js +163 -0
- package/src/model/http-tap.js +521 -0
- package/src/model/http-tools.js +1138 -0
- package/src/model/import-lock.js +78 -0
- package/src/model/imports.js +258 -0
- package/src/model/infer-outputs.js +822 -0
- package/src/model/ink-connect.js +150 -0
- package/src/model/ink-diff.js +75 -0
- package/src/model/ink-gone.js +71 -0
- package/src/model/ink-route.js +120 -0
- package/src/model/ink-svg.js +206 -0
- package/src/model/ink.js +739 -0
- package/src/model/input-log-hub.js +456 -0
- package/src/model/input-split.js +69 -0
- package/src/model/json-schema-host.js +9 -0
- package/src/model/json-schema.js +368 -0
- package/src/model/jth.js +78 -0
- package/src/model/latex-expr.js +528 -0
- package/src/model/layout-history.js +120 -0
- package/src/model/lazy-map.js +88 -0
- package/src/model/ledger-pane.js +101 -0
- package/src/model/legacy-viaframe.js +90 -0
- package/src/model/lessons.js +448 -0
- package/src/model/links.js +981 -0
- package/src/model/live.js +411 -0
- package/src/model/math-widget.js +53 -0
- package/src/model/memory-settings.js +33 -0
- package/src/model/midi-controls.js +350 -0
- package/src/model/nl-time.js +408 -0
- package/src/model/notebook.js +137 -0
- package/src/model/pane-view-store.js +15 -0
- package/src/model/partial.js +115 -0
- package/src/model/pause-clock.js +53 -0
- package/src/model/peer-pane.js +32 -0
- package/src/model/persist-state.js +290 -0
- package/src/model/person-only.js +122 -0
- package/src/model/pin.js +209 -0
- package/src/model/plot-3d.js +213 -0
- package/src/model/plot-series.js +157 -0
- package/src/model/plot-settings.js +531 -0
- package/src/model/ports.js +312 -0
- package/src/model/presentation.js +222 -0
- package/src/model/preset-apply.js +316 -0
- package/src/model/preset-banks.js +335 -0
- package/src/model/preset-morph.js +263 -0
- package/src/model/preset-ops.js +205 -0
- package/src/model/preset-player.js +283 -0
- package/src/model/preset-states.js +172 -0
- package/src/model/profile-settings.js +109 -0
- package/src/model/promote.js +103 -0
- package/src/model/protected.js +10 -0
- package/src/model/proxy-log.js +230 -0
- package/src/model/proxy.js +367 -0
- package/src/model/quantity-widget.js +61 -0
- package/src/model/queue-book.js +359 -0
- package/src/model/quick-add.js +224 -0
- package/src/model/rate-limit.js +313 -0
- package/src/model/rate.js +95 -0
- package/src/model/recovery.js +216 -0
- package/src/model/rename-follow.js +113 -0
- package/src/model/repeater.js +1126 -0
- package/src/model/retention.js +664 -0
- package/src/model/route-edit.js +132 -0
- package/src/model/router.js +155 -0
- package/src/model/runaway.js +232 -0
- package/src/model/runlog.js +1033 -0
- package/src/model/runners/a2a.js +2 -0
- package/src/model/runners/acp.js +2 -0
- package/src/model/runners/actions.js +4 -0
- package/src/model/runners/agent.js +4 -0
- package/src/model/runners/audio.js +21 -0
- package/src/model/runners/automation.js +2 -0
- package/src/model/runners/calc.js +23 -0
- package/src/model/runners/catch.js +10 -0
- package/src/model/runners/codec.js +24 -0
- package/src/model/runners/companion-run.js +2 -0
- package/src/model/runners/device.js +7 -0
- package/src/model/runners/dom.js +13 -0
- package/src/model/runners/effects.js +2 -0
- package/src/model/runners/embed.js +11 -0
- package/src/model/runners/eval.js +2 -0
- package/src/model/runners/files.js +19 -0
- package/src/model/runners/geometry.js +23 -0
- package/src/model/runners/goals.js +18 -0
- package/src/model/runners/graph.js +23 -0
- package/src/model/runners/html.js +2 -0
- package/src/model/runners/http-proxy.js +185 -0
- package/src/model/runners/http-send.js +61 -0
- package/src/model/runners/http-static.js +83 -0
- package/src/model/runners/http-tap.js +26 -0
- package/src/model/runners/http.js +40 -0
- package/src/model/runners/import.js +2 -0
- package/src/model/runners/index.js +74 -0
- package/src/model/runners/input.js +14 -0
- package/src/model/runners/inputlog.js +7 -0
- package/src/model/runners/ledger.js +15 -0
- package/src/model/runners/machine.js +4 -0
- package/src/model/runners/mcp.js +2 -0
- package/src/model/runners/mcpapp.js +2 -0
- package/src/model/runners/media.js +18 -0
- package/src/model/runners/memory.js +28 -0
- package/src/model/runners/mesh-inspect.js +13 -0
- package/src/model/runners/peer.js +14 -0
- package/src/model/runners/plot.js +22 -0
- package/src/model/runners/render.js +14 -0
- package/src/model/runners/respond.js +2 -0
- package/src/model/runners/sample-soundfont.js +85 -0
- package/src/model/runners/sample.js +159 -0
- package/src/model/runners/scene.js +8 -0
- package/src/model/runners/score.js +24 -0
- package/src/model/runners/secret.js +10 -0
- package/src/model/runners/select.js +2 -0
- package/src/model/runners/shared.js +4 -0
- package/src/model/runners/shares.js +15 -0
- package/src/model/runners/shell.js +7 -0
- package/src/model/runners/skill.js +26 -0
- package/src/model/runners/state.js +2 -0
- package/src/model/runners/statechart.js +4 -0
- package/src/model/runners/subgraph.js +9 -0
- package/src/model/runners/tabs.js +25 -0
- package/src/model/runners/terminal.js +5 -0
- package/src/model/runners/text.js +4 -0
- package/src/model/runners/timer.js +7 -0
- package/src/model/runners/traffic.js +65 -0
- package/src/model/runners/trigger.js +2 -0
- package/src/model/runners/verdict.js +29 -0
- package/src/model/runners/vm.js +7 -0
- package/src/model/runners/wait.js +4 -0
- package/src/model/runners/ws-client.js +57 -0
- package/src/model/safe-regex.js +719 -0
- package/src/model/sample-settings.js +43 -0
- package/src/model/sample-source.js +47 -0
- package/src/model/saved-mapping.js +153 -0
- package/src/model/score-controllers.js +87 -0
- package/src/model/score-edit.js +399 -0
- package/src/model/score-instruments.js +300 -0
- package/src/model/score-library.js +407 -0
- package/src/model/score-markup.js +235 -0
- package/src/model/score-mix.js +248 -0
- package/src/model/score-patterns.js +276 -0
- package/src/model/score-selection.js +34 -0
- package/src/model/score-time.js +139 -0
- package/src/model/score-transforms.js +336 -0
- package/src/model/score-transport.js +192 -0
- package/src/model/selection.js +351 -0
- package/src/model/serial-controls.js +328 -0
- package/src/model/shares-pane.js +17 -0
- package/src/model/shell-pane.js +106 -0
- package/src/model/signature.js +1122 -0
- package/src/model/size-hints.js +106 -0
- package/src/model/size-ratio.js +12 -0
- package/src/model/skill-settings.js +23 -0
- package/src/model/snapping.js +466 -0
- package/src/model/split.js +375 -0
- package/src/model/spring-player.js +222 -0
- package/src/model/statecharts.js +1369 -0
- package/src/model/states-preset.js +208 -0
- package/src/model/static-route.js +100 -0
- package/src/model/step-words.js +45 -0
- package/src/model/subgraph.js +1042 -0
- package/src/model/switch.js +98 -0
- package/src/model/tabs-store.js +10 -0
- package/src/model/tensor-view.js +146 -0
- package/src/model/timer-clock.js +361 -0
- package/src/model/timers.js +422 -0
- package/src/model/timing.js +212 -0
- package/src/model/traffic-agent.js +111 -0
- package/src/model/traffic-store.js +20 -0
- package/src/model/traffic.js +665 -0
- package/src/model/transport.js +364 -0
- package/src/model/turns.js +86 -0
- package/src/model/types.js +425 -0
- package/src/model/value-path.js +138 -0
- package/src/model/versions.js +535 -0
- package/src/model/view-outputs.js +144 -0
- package/src/model/viewport-bookmarks.js +194 -0
- package/src/model/virtual-clock.js +85 -0
- package/src/model/vm-pane.js +258 -0
- package/src/model/wait-clock.js +715 -0
- package/src/model/wait-persist.js +248 -0
- package/src/model/waits.js +431 -0
- package/src/model/watch.js +80 -0
- package/src/model/webhook.js +496 -0
- package/src/model/when.js +48 -0
- package/src/model/widget-values.js +392 -0
- package/src/model/window-commands.js +278 -0
- package/src/model/windows.js +348 -0
- package/src/model/wire-inspect.js +343 -0
- package/src/model/wire-ops.js +324 -0
- package/src/model/wire-pipeline.js +378 -0
- package/src/model/wire-route.js +637 -0
- package/src/model/workspaces.js +122 -0
- package/src/model/ws-client.js +155 -0
- package/src/model/ws-demo.js +31 -0
- package/src/model/ws-frames.js +141 -0
- package/src/model/ws-hub.js +219 -0
- package/src/model/ws-served.js +13 -0
- package/src/model/xstate.js +374 -0
- package/src/narrative/narrative.js +1557 -0
- package/src/network/auth.js +224 -0
- package/src/network/csp-frame.js +197 -0
- package/src/network/declarative-shadow.js +27 -0
- package/src/network/frame-net-shim.js +962 -0
- package/src/network/hosts.js +157 -0
- package/src/network/policy.js +520 -0
- package/src/network/rtc-shim.js +418 -0
- package/src/network/secret-gate.js +78 -0
- package/src/network/secrets.js +261 -0
- package/src/network/sockets.js +287 -0
- package/src/network/store.js +186 -0
- package/src/network/streams.js +99 -0
- package/src/packages/asset-values.js +50 -0
- package/src/packages/assets.js +99 -0
- package/src/packages/deprecation.js +203 -0
- package/src/packages/fetch.js +152 -0
- package/src/packages/function-canvas.js +73 -0
- package/src/packages/module.js +120 -0
- package/src/packages/package.js +474 -0
- package/src/packages/published.js +27 -0
- package/src/packages/requires.js +83 -0
- package/src/packages/signing.js +145 -0
- package/src/packages/trust.js +107 -0
- package/src/panes/a2a.js +51 -0
- package/src/panes/acp.js +60 -0
- package/src/panes/actions.js +54 -0
- package/src/panes/agent.js +83 -0
- package/src/panes/audio.js +103 -0
- package/src/panes/automation.js +112 -0
- package/src/panes/calc.js +67 -0
- package/src/panes/catch.js +52 -0
- package/src/panes/codec.js +59 -0
- package/src/panes/colors.js +12 -0
- package/src/panes/companion.js +54 -0
- package/src/panes/decision.js +65 -0
- package/src/panes/device.js +56 -0
- package/src/panes/dom.js +37 -0
- package/src/panes/effects.js +118 -0
- package/src/panes/embed.js +30 -0
- package/src/panes/eval.js +186 -0
- package/src/panes/fields.js +299 -0
- package/src/panes/files.js +45 -0
- package/src/panes/gate.js +70 -0
- package/src/panes/geometry.js +64 -0
- package/src/panes/goals.js +75 -0
- package/src/panes/graph.js +66 -0
- package/src/panes/html.js +54 -0
- package/src/panes/http.js +82 -0
- package/src/panes/import.js +38 -0
- package/src/panes/input.js +124 -0
- package/src/panes/inputlog.js +66 -0
- package/src/panes/ledger.js +56 -0
- package/src/panes/machine.js +138 -0
- package/src/panes/mcp.js +85 -0
- package/src/panes/mcpapp.js +64 -0
- package/src/panes/media.js +38 -0
- package/src/panes/memory.js +46 -0
- package/src/panes/mesh-inspect.js +49 -0
- package/src/panes/note.js +38 -0
- package/src/panes/peer.js +44 -0
- package/src/panes/plot.js +196 -0
- package/src/panes/registry.js +475 -0
- package/src/panes/render.js +87 -0
- package/src/panes/respond.js +44 -0
- package/src/panes/router.js +84 -0
- package/src/panes/sample.js +75 -0
- package/src/panes/scene.js +55 -0
- package/src/panes/score.js +87 -0
- package/src/panes/secret.js +38 -0
- package/src/panes/select.js +67 -0
- package/src/panes/shader.js +166 -0
- package/src/panes/shared.js +33 -0
- package/src/panes/shares.js +43 -0
- package/src/panes/shell.js +47 -0
- package/src/panes/skill.js +44 -0
- package/src/panes/state.js +91 -0
- package/src/panes/statechart.js +63 -0
- package/src/panes/story.js +33 -0
- package/src/panes/subgraph.js +94 -0
- package/src/panes/tabs.js +52 -0
- package/src/panes/terminal.js +57 -0
- package/src/panes/text.js +36 -0
- package/src/panes/timer.js +55 -0
- package/src/panes/traffic.js +59 -0
- package/src/panes/verdict.js +62 -0
- package/src/panes/vm.js +46 -0
- package/src/panes/wait.js +61 -0
- package/src/panes/watch.js +57 -0
- package/src/panes/webhook.js +67 -0
- package/src/panes/ws-client.js +67 -0
- package/src/persist.js +281 -0
- package/src/plot/tex.js +19 -0
- package/src/plot/vendor.js +59 -0
- package/src/plot/view-vendor.js +5 -0
- package/src/privacy/levels.js +108 -0
- package/src/protocol/devtools.js +116 -0
- package/src/protocol/inspector.js +368 -0
- package/src/render/time.js +381 -0
- package/src/rooms/mesh-metrics.js +162 -0
- package/src/run/companion.js +355 -0
- package/src/run/describe.js +114 -0
- package/src/run/local-model.js +150 -0
- package/src/run/monitor.js +208 -0
- package/src/run/publish.js +360 -0
- package/src/run/respond-outcome.js +12 -0
- package/src/run/run.js +820 -0
- package/src/run/runner-pairing.js +243 -0
- package/src/run/values.js +122 -0
- package/src/runtime/compile.js +122 -0
- package/src/runtime/console-tag.js +64 -0
- package/src/runtime/frame-signals.js +126 -0
- package/src/runtime/iteration-push.js +19 -0
- package/src/runtime/keys.js +474 -0
- package/src/runtime/midi-input.js +170 -0
- package/src/runtime/person-waits.js +140 -0
- package/src/runtime/resource-timing.js +56 -0
- package/src/runtime/runtime.js +2150 -0
- package/src/runtime/sandbox-modules.js +163 -0
- package/src/runtime/spring.js +246 -0
- package/src/runtime/strict.js +215 -0
- package/src/runtime/transfer.js +75 -0
- package/src/runtime/tween.js +158 -0
- package/src/runtime/wasm-fuel.js +596 -0
- package/src/runtime/worker/00-prelude.js +88 -0
- package/src/runtime/worker/10-helpers.js +295 -0
- package/src/runtime/worker/20-io.js +645 -0
- package/src/runtime/worker/30-previews.js +210 -0
- package/src/runtime/worker/40-profile-lineage.js +278 -0
- package/src/runtime/worker/50-own-worker.js +233 -0
- package/src/runtime/worker/60-timers.js +172 -0
- package/src/runtime/worker/70-state-keyed.js +193 -0
- package/src/runtime/worker/80-each-compile-generators.js +619 -0
- package/src/runtime/worker/90-events-operators.js +655 -0
- package/src/runtime/worker/95-agents-batches.js +1820 -0
- package/src/runtime/worker/96-plot.js +47 -0
- package/src/runtime/worker/97-calc.js +28 -0
- package/src/runtime/worker/98-geometry.js +24 -0
- package/src/runtime/worker/99-graph.js +30 -0
- package/src/runtime/worker/99-shell.js +30 -0
- package/src/safety/config.js +57 -0
- package/src/safety/engine.js +324 -0
- package/src/scene/pixi-scene.js +806 -0
- package/src/scene/scene-assets.js +241 -0
- package/src/scene/scene-edit.js +319 -0
- package/src/secret/settings.js +41 -0
- package/src/security/multipart.js +257 -0
- package/src/security/redact.js +261 -0
- package/src/serial/broker.js +473 -0
- package/src/serial/config.js +185 -0
- package/src/serial/framers.js +389 -0
- package/src/serial/packets.js +64 -0
- package/src/shader/audio-texture.js +87 -0
- package/src/shader/channels.js +496 -0
- package/src/shader/common.js +90 -0
- package/src/shader/model.js +867 -0
- package/src/shader/passes.js +150 -0
- package/src/shader/shadertoy.js +198 -0
- package/src/shell/hub.js +287 -0
- package/src/sim/checkpoints.js +850 -0
- package/src/sim/compile.js +37 -0
- package/src/sim/fixed.js +377 -0
- package/src/sim/headless.js +205 -0
- package/src/sim/physics.js +399 -0
- package/src/smf-helper/vendor.js +2 -0
- package/src/sources/config.js +435 -0
- package/src/storage.js +153 -0
- package/src/table/table-geo.js +2344 -0
- package/src/table/table-lineage.js +808 -0
- package/src/table/table-quality.js +355 -0
- package/src/table/table-schema.js +392 -0
- package/src/table/table-sql.js +1650 -0
- package/src/table/table-stats.js +480 -0
- package/src/table/table.js +2102 -0
- package/src/tensor/tensor.js +1153 -0
- package/src/terminal/hub.js +715 -0
- package/src/terminal/screen.js +516 -0
- package/src/tests/capture.js +88 -0
- package/src/tests/compare.js +480 -0
- package/src/tests/dataset.js +170 -0
- package/src/tests/evaluate.js +286 -0
- package/src/tests/from-runs.js +99 -0
- package/src/tests/judge.js +134 -0
- package/src/tests/matchers.js +263 -0
- package/src/tests/matrix-spec.js +87 -0
- package/src/tests/matrix.js +397 -0
- package/src/tests/metrics.js +369 -0
- package/src/tests/no-value.js +42 -0
- package/src/tests/pane-check.js +45 -0
- package/src/tests/report.js +124 -0
- package/src/tests/reporters.js +140 -0
- package/src/tests/run.js +155 -0
- package/src/tilemap/tilemap.js +1122 -0
- package/src/units/units.js +3 -0
- package/src/util/bytes-text.js +21 -0
- package/src/util/num.js +10 -0
- package/src/util/regexp.js +2 -0
- package/src/util/text.js +38 -0
- package/src/verdict/engine.js +154 -0
- package/src/vm/guest-wsh.js +108 -0
- package/src/vm/hub.js +457 -0
- package/src/vm/image-files.js +4 -0
- package/src/vm/image.js +33 -0
- package/src/vm/image.lock.json +13 -0
- package/src/vm/link.js +266 -0
- package/src/vm/mount.js +212 -0
- package/src/vm/net.js +85 -0
- package/src/vm/pipe-ws.js +187 -0
- package/src/vm/v86-loader.js +11 -0
- package/src/webmcp/args.js +212 -0
- package/src/webmcp/hidden.js +218 -0
- package/src/webmcp/text.js +250 -0
- package/src/webmcp/tools/bookmark-tools.js +106 -0
- package/src/webmcp/tools/breakpoint-tools.js +48 -0
- package/src/webmcp/tools/canvases.js +208 -0
- package/src/webmcp/tools/context-tools.js +84 -0
- package/src/webmcp/tools/core.js +170 -0
- package/src/webmcp/tools/devices.js +41 -0
- package/src/webmcp/tools/edit.js +357 -0
- package/src/webmcp/tools/event-tools.js +145 -0
- package/src/webmcp/tools/image-tools.js +173 -0
- package/src/webmcp/tools/ink-tools.js +247 -0
- package/src/webmcp/tools/input-log-tools.js +163 -0
- package/src/webmcp/tools/live.js +166 -0
- package/src/webmcp/tools/machine-tools.js +74 -0
- package/src/webmcp/tools/media.js +161 -0
- package/src/webmcp/tools/midi-tools.js +32 -0
- package/src/webmcp/tools/preset-tools.js +184 -0
- package/src/webmcp/tools/quick-add-tools.js +95 -0
- package/src/webmcp/tools/reshape.js +152 -0
- package/src/webmcp/tools/run-tools.js +309 -0
- package/src/webmcp/tools/runs.js +101 -0
- package/src/webmcp/tools/scaffold-tools.js +161 -0
- package/src/webmcp/tools/serial-tools.js +36 -0
- package/src/webmcp/tools/shared.js +338 -0
- package/src/webmcp/tools/subgraphs.js +360 -0
- package/src/webmcp/tools/tests.js +170 -0
- package/src/webmcp/tools/traffic-tools.js +70 -0
- package/src/webmcp/tools/transport-tools.js +65 -0
- package/src/webmcp/tools/version-tools.js +126 -0
- package/src/webmcp/tools/versions.js +11 -0
- package/src/webmcp/tools/wire-tools.js +90 -0
- package/src/webmcp/tools/workspace-tools.js +93 -0
- package/src/webmcp/tools.js +1323 -0
- package/src/wsh/connect.js +347 -0
- package/src/wsh/demo-host.js +361 -0
- package/src/wsh/e2e.js +27 -0
- package/src/wsh/keys.js +154 -0
- package/src/wsh/known-hosts.js +39 -0
- package/src/wsh/private-key.js +95 -0
- package/src/wsh/reverse.js +34 -0
- package/src/wsh/settings.js +118 -0
- package/src/wsh/transfer.js +62 -0
- package/src/wsh/vendor.js +5 -0
- package/src/x402/challenge.js +171 -0
- package/src/x402/demo-server.js +127 -0
- package/src/x402/pay.js +125 -0
- package/src/x402/retry.js +95 -0
- package/src/x402/store.js +76 -0
|
@@ -0,0 +1,653 @@
|
|
|
1
|
+
// Automation lanes and cue sequences: the pure rules. An automation
|
|
2
|
+
// pane holds a timeline, saved with the canvas as its `automation` setting:
|
|
3
|
+
//
|
|
4
|
+
// duration seconds of timeline (0.1 to 3600)
|
|
5
|
+
// loop wrap at the end (cues and lanes carry on into the next pass)
|
|
6
|
+
// rate value updates per second while the canvas transport plays it (1 to 60)
|
|
7
|
+
// speed a multiplier on how fast play moves the playhead against the wall clock (0.1 to 10, default 1; steps and seeks are unaffected)
|
|
8
|
+
// step seconds one transport step advances
|
|
9
|
+
// seek what a seek does with the cues it jumps over: "skip" (none fire) or
|
|
10
|
+
// "chase" (the latest cue of each name at or before the target fires once)
|
|
11
|
+
// playhead the name of an input that drives the position (an external playhead);
|
|
12
|
+
// the pane then has no clock of its own
|
|
13
|
+
// noteCues where the "notes" cues are played: "events" (the default: on the pane's `notes` output, when
|
|
14
|
+
// the playhead crosses them) or "audio" (in the timeline an audio pane receives, which plays
|
|
15
|
+
// them on its own audio clock at their exact time, following this playhead)
|
|
16
|
+
// lanes [{ name, min, max, curve: { interpolation, points: [{ x, y }] }, target?, source? }]
|
|
17
|
+
// cues [{ at, name, kind: "event" | "notes", value?, notes? }]
|
|
18
|
+
//
|
|
19
|
+
// A lane's curve is the value shape of src/model/widget-values.js (x in seconds,
|
|
20
|
+
// y between the lane's min and max) with one more interpolation, "ease"
|
|
21
|
+
// (smoothstep between points); its sampling is src/audio/lanes.js, which the
|
|
22
|
+
// audio frame uses too. `target` ("<module>.<param>") binds a lane to a DSP
|
|
23
|
+
// patch parameter in an audio pane that receives this pane's timeline: the
|
|
24
|
+
// frame schedules it on the AudioContext's clock, not this one. `source` names
|
|
25
|
+
// an input whose value capture records into the lane.
|
|
26
|
+
//
|
|
27
|
+
// Nothing here has a clock: `Playhead` is advanced by whoever owns the time
|
|
28
|
+
// (src/model/automation-clock.js on the canvas, a test with numbers), so a
|
|
29
|
+
// replay of the same moves is the same frames and the same cues, whatever the
|
|
30
|
+
// step sizes. Pure: it runs under node --test.
|
|
31
|
+
import { curveProblems, curveInsert, curveMove, curveRemove, curveSet, MAX_POINTS, INTERPOLATIONS } from "./widget-values.js";
|
|
32
|
+
import { sampleLane, positionAt, KIND } from "../audio/lanes.js";
|
|
33
|
+
import { parseDuration } from "./nl-time.js";
|
|
34
|
+
import { clamp } from "../util/num.js";
|
|
35
|
+
|
|
36
|
+
export { KIND };
|
|
37
|
+
export const LANE_INTERPOLATIONS = [...INTERPOLATIONS, "ease"];
|
|
38
|
+
export const SEEK_MODES = ["skip", "chase"];
|
|
39
|
+
export const CUE_KINDS = ["event", "notes"];
|
|
40
|
+
export const NOTE_CUE_MODES = ["events", "audio"];
|
|
41
|
+
export const LIMITS = { duration: [0.1, 3600], rate: [1, 60], speed: [0.1, 10], lanes: 32, cues: 512, notes: 32, nameLength: 40 };
|
|
42
|
+
/** The most passes one advance walks through when it loops (a hidden tab's long catch-up): the rest are counted, not replayed. */
|
|
43
|
+
export const MAX_PASSES = 64;
|
|
44
|
+
/** The shortest gap between two points of a lane (seconds) and the finest value step, as widget-values' step settings. */
|
|
45
|
+
export const X_STEP = 0.01;
|
|
46
|
+
|
|
47
|
+
const isNum = (v) => typeof v === "number" && Number.isFinite(v);
|
|
48
|
+
const isObject = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
|
|
49
|
+
const round = (n) => Math.round(n * 1e6) / 1e6;
|
|
50
|
+
const snapT = (n) => Math.round(n * 1e9) / 1e9;
|
|
51
|
+
/**
|
|
52
|
+
* Seconds for a time written as a number, as numeric text ("1.5") or in words ("90 seconds", "1 min 30 s", "250ms"); anything else
|
|
53
|
+
* comes back as it is, for the problem check to name. Times in words are read once, here: what a canvas keeps is always seconds.
|
|
54
|
+
*/
|
|
55
|
+
export function secondsOf(v) {
|
|
56
|
+
if (typeof v !== "string") return v;
|
|
57
|
+
const text = v.trim();
|
|
58
|
+
if (/^\d+(\.\d+)?$/.test(text)) return Number(text);
|
|
59
|
+
const ms = parseDuration(text);
|
|
60
|
+
return ms === undefined ? v : ms / 1000;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** `raw` with the times written in words (the duration, the step, each cue's time) as seconds. */
|
|
64
|
+
function readWords(raw) {
|
|
65
|
+
if (!isObject(raw)) return raw;
|
|
66
|
+
const out = { ...raw };
|
|
67
|
+
for (const key of ["duration", "step"]) if (key in out) out[key] = secondsOf(out[key]);
|
|
68
|
+
if (Array.isArray(out.cues)) out.cues = out.cues.map((cue) => (isObject(cue) && "at" in cue ? { ...cue, at: secondsOf(cue.at) } : cue));
|
|
69
|
+
return out;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** The widget-values settings for a lane: x is 0 to the duration, y is the lane's range. */
|
|
73
|
+
export const rangeOf = (lane, duration) => ({ xMin: 0, xMax: duration, xStep: X_STEP, yMin: lane.min, yMax: lane.max, yStep: Number(((lane.max - lane.min) / 1000).toPrecision(2)) });
|
|
74
|
+
|
|
75
|
+
/** A lane's curve in widget-values' terms (its "ease" is a linear curve there; only sampling differs). */
|
|
76
|
+
const asCurve = (curve) => ({ ...curve, interpolation: curve?.interpolation === "ease" ? "linear" : curve?.interpolation });
|
|
77
|
+
|
|
78
|
+
export function defaultLane(name, duration = 8, min = 0, max = 1) {
|
|
79
|
+
return { name, min, max, curve: { interpolation: "linear", points: [{ x: 0, y: min }, { x: duration, y: max }] } };
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** A new automation pane's timeline: eight seconds, one lane, one cue at the start. */
|
|
83
|
+
export function defaultAutomation() {
|
|
84
|
+
return {
|
|
85
|
+
duration: 8,
|
|
86
|
+
loop: false,
|
|
87
|
+
rate: 10,
|
|
88
|
+
speed: 1,
|
|
89
|
+
step: 0.25,
|
|
90
|
+
seek: "skip",
|
|
91
|
+
lanes: [defaultLane("level")],
|
|
92
|
+
cues: [{ at: 0, name: "start", kind: "event" }],
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// ── checking ───────────────────────────────────────────────────────────────
|
|
97
|
+
|
|
98
|
+
const noteProblem = (n, at) => {
|
|
99
|
+
if (!isObject(n)) return `${at} is { note, velocity?, dur?, time?, params? }`;
|
|
100
|
+
if (!(isNum(n.note) || typeof n.note === "string")) return `${at}: note is a MIDI number or a name like "C4"`;
|
|
101
|
+
for (const key of ["velocity", "dur", "time"]) if (n[key] !== undefined && !isNum(n[key])) return `${at}: ${key} is a number`;
|
|
102
|
+
return "";
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Every reason `raw` isn't a sound timeline (sentences, at most `limit`): bad numbers, lanes with a
|
|
107
|
+
* malformed or out-of-range curve, duplicate lane names, cues outside the timeline. Unknown keys are not
|
|
108
|
+
* a problem (they are dropped by `automationSettings`).
|
|
109
|
+
*/
|
|
110
|
+
export function automationProblems(given, limit = 8) {
|
|
111
|
+
const raw = readWords(given);
|
|
112
|
+
const out = [];
|
|
113
|
+
const add = (text) => out.length < limit && out.push(text);
|
|
114
|
+
if (!isObject(raw)) return ["an automation is { duration, loop?, lanes, cues }"];
|
|
115
|
+
const [dlo, dhi] = LIMITS.duration;
|
|
116
|
+
if (!isNum(raw.duration) || raw.duration < dlo || raw.duration > dhi) add(`duration is a number of seconds from ${dlo} to ${dhi} (or words like "90 seconds")`);
|
|
117
|
+
if (raw.loop !== undefined && typeof raw.loop !== "boolean") add("loop is true or false");
|
|
118
|
+
if (raw.rate !== undefined && (!isNum(raw.rate) || raw.rate < LIMITS.rate[0] || raw.rate > LIMITS.rate[1])) add(`rate is a number of updates per second from ${LIMITS.rate[0]} to ${LIMITS.rate[1]}`);
|
|
119
|
+
if (raw.speed !== undefined && (!isNum(raw.speed) || raw.speed < LIMITS.speed[0] || raw.speed > LIMITS.speed[1])) add(`speed is a number from ${LIMITS.speed[0]} to ${LIMITS.speed[1]} (1 plays in real time)`);
|
|
120
|
+
if (raw.step !== undefined && (!isNum(raw.step) || !(raw.step > 0))) add("step is a number of seconds above 0 (or words like \"half a second\")");
|
|
121
|
+
if (raw.seek !== undefined && !SEEK_MODES.includes(raw.seek)) add(`seek is ${SEEK_MODES.join(" or ")}`);
|
|
122
|
+
if (raw.playhead !== undefined && typeof raw.playhead !== "string") add("playhead is the name of an input");
|
|
123
|
+
if (raw.noteCues !== undefined && !NOTE_CUE_MODES.includes(raw.noteCues)) add(`noteCues is ${NOTE_CUE_MODES.join(" or ")}`);
|
|
124
|
+
const duration = isNum(raw.duration) ? raw.duration : 8;
|
|
125
|
+
if (!Array.isArray(raw.lanes ?? [])) add("lanes is a list");
|
|
126
|
+
else {
|
|
127
|
+
const lanes = raw.lanes ?? [];
|
|
128
|
+
if (lanes.length > LIMITS.lanes) add(`at most ${LIMITS.lanes} lanes (there are ${lanes.length})`);
|
|
129
|
+
const seen = new Set();
|
|
130
|
+
lanes.slice(0, LIMITS.lanes).forEach((lane, i) => {
|
|
131
|
+
const at = `lane ${i + 1}`;
|
|
132
|
+
if (!isObject(lane)) return add(`${at} is { name, min, max, curve }`);
|
|
133
|
+
const name = typeof lane.name === "string" ? lane.name.trim() : "";
|
|
134
|
+
if (!name || name.length > LIMITS.nameLength) return add(`${at}: name is 1 to ${LIMITS.nameLength} characters`);
|
|
135
|
+
if (seen.has(name)) add(`${at}: another lane is called "${name}"`);
|
|
136
|
+
seen.add(name);
|
|
137
|
+
if (!isNum(lane.min) || !isNum(lane.max) || !(lane.max > lane.min)) return add(`lane "${name}": max must be a number above min`);
|
|
138
|
+
if (lane.target !== undefined && !/^[\w-]+\.[\w-]+$/.test(String(lane.target)) && !/^mix\.[\w-]+\.(volume|pan|send\.[\w-]+)$/.test(String(lane.target))) add(`lane "${name}": target is "<module>.<param>", or "mix.<track>.volume", "mix.<track>.pan" or "mix.<track>.send.<bus>"`);
|
|
139
|
+
if (lane.source !== undefined && typeof lane.source !== "string") add(`lane "${name}": source is the name of an input`);
|
|
140
|
+
if (lane.curve?.interpolation !== undefined && !LANE_INTERPOLATIONS.includes(lane.curve.interpolation)) add(`lane "${name}": interpolation is ${LANE_INTERPOLATIONS.join(", ")}`);
|
|
141
|
+
for (const p of curveProblems(asCurve(lane.curve), rangeOf(lane, duration), 3)) add(`lane "${name}": ${p}`);
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
if (!Array.isArray(raw.cues ?? [])) add("cues is a list");
|
|
145
|
+
else {
|
|
146
|
+
const cues = raw.cues ?? [];
|
|
147
|
+
if (cues.length > LIMITS.cues) add(`at most ${LIMITS.cues} cues (there are ${cues.length})`);
|
|
148
|
+
cues.slice(0, LIMITS.cues).forEach((cue, i) => {
|
|
149
|
+
const at = `cue ${i + 1}`;
|
|
150
|
+
if (!isObject(cue)) return add(`${at} is { at, name, kind }`);
|
|
151
|
+
if (!isNum(cue.at) || cue.at < 0 || cue.at > duration) add(`${at}: at is a time from 0 to the duration (${round(duration)} s)`);
|
|
152
|
+
if (typeof cue.name !== "string" || !cue.name.trim() || cue.name.length > LIMITS.nameLength) add(`${at}: name is 1 to ${LIMITS.nameLength} characters`);
|
|
153
|
+
if (cue.kind !== undefined && !CUE_KINDS.includes(cue.kind)) add(`${at}: kind is ${CUE_KINDS.join(" or ")}`);
|
|
154
|
+
if (cue.kind === "notes") {
|
|
155
|
+
if (!Array.isArray(cue.notes) || !cue.notes.length) add(`${at}: a notes cue has a list of notes`);
|
|
156
|
+
else if (cue.notes.length > LIMITS.notes) add(`${at}: at most ${LIMITS.notes} notes in one cue`);
|
|
157
|
+
else for (const [j, n] of cue.notes.entries()) { const p = noteProblem(n, `${at}, note ${j + 1}`); if (p) { add(p); break; } }
|
|
158
|
+
}
|
|
159
|
+
if (cue.value !== undefined) {
|
|
160
|
+
try {
|
|
161
|
+
JSON.stringify(cue.value);
|
|
162
|
+
} catch {
|
|
163
|
+
add(`${at}: value is JSON`);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
return out;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/** The first of automationProblems, or "". */
|
|
172
|
+
export const automationProblem = (raw) => automationProblems(raw, 1)[0] ?? "";
|
|
173
|
+
|
|
174
|
+
const jsonCopy = (v) => (v === undefined ? undefined : JSON.parse(JSON.stringify(v)));
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* The timeline as saved: defaults filled in, unknown keys dropped, cues sorted by time (equal times keep their
|
|
178
|
+
* order), lanes' points sorted. Call it with what `automationProblems` accepted; for anything else it does
|
|
179
|
+
* its best (a malformed field takes its default) and never throws.
|
|
180
|
+
*/
|
|
181
|
+
export function automationSettings(given) {
|
|
182
|
+
const base = defaultAutomation();
|
|
183
|
+
const r = isObject(given) ? readWords(given) : {};
|
|
184
|
+
const duration = isNum(r.duration) ? clamp(r.duration, ...LIMITS.duration) : base.duration;
|
|
185
|
+
const lanes = (Array.isArray(r.lanes) ? r.lanes : base.lanes)
|
|
186
|
+
.filter(isObject)
|
|
187
|
+
.slice(0, LIMITS.lanes)
|
|
188
|
+
.map((lane, i) => {
|
|
189
|
+
const name = typeof lane.name === "string" && lane.name.trim() ? lane.name.trim().slice(0, LIMITS.nameLength) : `lane${i + 1}`;
|
|
190
|
+
const min = isNum(lane.min) ? lane.min : 0;
|
|
191
|
+
const max = isNum(lane.max) && lane.max > min ? lane.max : min + 1;
|
|
192
|
+
const points = (Array.isArray(lane.curve?.points) ? lane.curve.points : defaultLane(name, duration, min, max).curve.points)
|
|
193
|
+
.filter((p) => isObject(p) && isNum(p.x) && isNum(p.y))
|
|
194
|
+
.map((p) => ({ x: clamp(p.x, 0, duration), y: clamp(p.y, min, max) }))
|
|
195
|
+
.sort((a, b) => a.x - b.x)
|
|
196
|
+
.filter((p, k, all) => k === 0 || p.x !== all[k - 1].x)
|
|
197
|
+
.slice(0, MAX_POINTS);
|
|
198
|
+
return {
|
|
199
|
+
name,
|
|
200
|
+
min,
|
|
201
|
+
max,
|
|
202
|
+
curve: { interpolation: LANE_INTERPOLATIONS.includes(lane.curve?.interpolation) ? lane.curve.interpolation : "linear", points: points.length >= 2 ? points : defaultLane(name, duration, min, max).curve.points },
|
|
203
|
+
...(typeof lane.target === "string" && lane.target ? { target: lane.target } : {}),
|
|
204
|
+
...(typeof lane.source === "string" && lane.source ? { source: lane.source } : {}),
|
|
205
|
+
};
|
|
206
|
+
});
|
|
207
|
+
const cues = (Array.isArray(r.cues) ? r.cues : base.cues)
|
|
208
|
+
.filter((c) => isObject(c) && typeof c.name === "string" && c.name.trim() && isNum(c.at))
|
|
209
|
+
.slice(0, LIMITS.cues)
|
|
210
|
+
.map((c) => ({
|
|
211
|
+
at: clamp(c.at, 0, duration),
|
|
212
|
+
name: c.name.trim().slice(0, LIMITS.nameLength),
|
|
213
|
+
kind: c.kind === "notes" ? "notes" : "event",
|
|
214
|
+
...(c.value !== undefined ? { value: jsonCopy(c.value) } : {}),
|
|
215
|
+
...(c.kind === "notes" && Array.isArray(c.notes) ? { notes: jsonCopy(c.notes.filter(isObject).slice(0, LIMITS.notes)) } : {}),
|
|
216
|
+
}))
|
|
217
|
+
.map((c, i) => ({ c, i }))
|
|
218
|
+
.sort((a, b) => a.c.at - b.c.at || a.i - b.i)
|
|
219
|
+
.map(({ c }) => c);
|
|
220
|
+
return {
|
|
221
|
+
duration,
|
|
222
|
+
loop: r.loop === true,
|
|
223
|
+
rate: isNum(r.rate) ? clamp(Math.round(r.rate), ...LIMITS.rate) : base.rate,
|
|
224
|
+
speed: isNum(r.speed) ? clamp(r.speed, ...LIMITS.speed) : base.speed,
|
|
225
|
+
step: isNum(r.step) && r.step > 0 ? r.step : base.step,
|
|
226
|
+
seek: SEEK_MODES.includes(r.seek) ? r.seek : base.seek,
|
|
227
|
+
...(typeof r.playhead === "string" && r.playhead ? { playhead: r.playhead } : {}),
|
|
228
|
+
...(r.noteCues === "audio" ? { noteCues: "audio" } : {}),
|
|
229
|
+
lanes,
|
|
230
|
+
cues,
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* The part of a timeline an audio pane schedules on its own clock: `{ kind: "automation", duration, loop, lanes: [{ name, target, curve }] }`
|
|
236
|
+
* (lanes with a target) and, when `noteCues` is "audio", `cues`: the notes cues, `[{ at, name, notes }]`.
|
|
237
|
+
*/
|
|
238
|
+
export function timelineOf(settings) {
|
|
239
|
+
const s = automationSettings(settings);
|
|
240
|
+
const cues = s.noteCues === "audio" ? s.cues.filter((c) => c.kind === "notes" && c.notes?.length).map((c) => ({ at: c.at, name: c.name, notes: jsonCopy(c.notes) })) : [];
|
|
241
|
+
return { kind: KIND, duration: s.duration, loop: s.loop, lanes: s.lanes.filter((l) => l.target).map((l) => ({ name: l.name, target: l.target, curve: jsonCopy(l.curve) })), ...(cues.length ? { cues } : {}) };
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/** Is this value an automation pane's value (what an audio pane looks for among its inputs)? */
|
|
245
|
+
export const isAutomationValue = (v) => isObject(v) && v.kind === KIND && isObject(v.timeline) && Array.isArray(v.timeline.lanes);
|
|
246
|
+
|
|
247
|
+
// ── values at a time ───────────────────────────────────────────────────────
|
|
248
|
+
|
|
249
|
+
/** Every lane's value at timeline position `t`: `{ [name]: number }`. */
|
|
250
|
+
export function lanesAt(settings, t) {
|
|
251
|
+
const out = {};
|
|
252
|
+
for (const lane of settings.lanes) out[lane.name] = round(sampleLane(lane.curve, t));
|
|
253
|
+
return out;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/** The cues in (after, upTo]: a cue is crossed when `after < at <= upTo`. `after` of -1 includes a cue at 0. */
|
|
257
|
+
function crossed(cues, after, upTo, pass) {
|
|
258
|
+
const out = [];
|
|
259
|
+
for (const cue of cues) if (cue.at > after && cue.at <= upTo) out.push(cueEvent(cue, pass));
|
|
260
|
+
return out;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/** What a cue is when it fires: `{ name, kind, at, pass, value?, notes? }`. */
|
|
264
|
+
export const cueEvent = (cue, pass = 0) => ({ name: cue.name, kind: cue.kind ?? "event", at: cue.at, pass, ...(cue.value !== undefined ? { value: cue.value } : {}), ...(cue.notes ? { notes: cue.notes } : {}) });
|
|
265
|
+
|
|
266
|
+
// ── the playhead ───────────────────────────────────────────────────────────
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* A timeline's position and what moving it does. States: "stopped" (at 0, not run), "playing" (the owner is
|
|
270
|
+
* advancing it), "paused" and "ended" (a non-looping timeline reached its duration).
|
|
271
|
+
*
|
|
272
|
+
* The cue rule (docs/guide/media-and-audio.md, "Automation lanes"): a cue fires once each time the position crosses it going
|
|
273
|
+
* forward: `advance` fires every cue in (the old position, the new one], in time order, wrapping into the next
|
|
274
|
+
* pass when looping (a cue at the very end fires, then the next pass begins with the cue at 0). A seek never
|
|
275
|
+
* fires the cues it jumps over: with seek "skip" none fire; with "chase" the latest cue of each name at or
|
|
276
|
+
* before the target fires once (so a "set the scene" cue is not lost). A seek to 0 is a rewind: the cue at 0
|
|
277
|
+
* fires when the position next moves. Lane values do not depend on how the position got there.
|
|
278
|
+
*/
|
|
279
|
+
export class Playhead {
|
|
280
|
+
constructor(settings = defaultAutomation()) {
|
|
281
|
+
this.settings = automationSettings(settings);
|
|
282
|
+
this.t = 0;
|
|
283
|
+
this.cursor = -1; // the last position cues were fired up to (-1: before the start, a cue at 0 is still to fire)
|
|
284
|
+
this.passes = 0; // finished passes of a looping timeline
|
|
285
|
+
this.state = "stopped";
|
|
286
|
+
this.dropped = 0; // passes a long advance did not replay (MAX_PASSES)
|
|
287
|
+
this.extLast = null; // an external playhead's last unwrapped position
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/** New settings (an edit): the position stays, kept inside the new duration; cues behind it are not fired. */
|
|
291
|
+
update(settings) {
|
|
292
|
+
this.settings = automationSettings(settings);
|
|
293
|
+
if (this.t > this.settings.duration) this.t = this.settings.duration;
|
|
294
|
+
if (this.cursor > this.t) this.cursor = this.t;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/** Move forward by `dt` seconds. Returns the cues crossed, in order. */
|
|
298
|
+
advance(dt) {
|
|
299
|
+
const { duration, loop, cues } = this.settings;
|
|
300
|
+
const out = [];
|
|
301
|
+
if (!(dt > 0)) return out;
|
|
302
|
+
let pos = this.t;
|
|
303
|
+
let left = dt;
|
|
304
|
+
let after = this.cursor;
|
|
305
|
+
let walked = 0;
|
|
306
|
+
for (;;) {
|
|
307
|
+
if (snapT(pos + left) <= duration) {
|
|
308
|
+
pos = snapT(pos + left);
|
|
309
|
+
out.push(...crossed(cues, after, pos, this.passes));
|
|
310
|
+
after = pos;
|
|
311
|
+
break;
|
|
312
|
+
}
|
|
313
|
+
out.push(...crossed(cues, after, duration, this.passes));
|
|
314
|
+
left -= duration - pos;
|
|
315
|
+
if (!loop) {
|
|
316
|
+
pos = duration;
|
|
317
|
+
after = duration;
|
|
318
|
+
this.state = "ended";
|
|
319
|
+
left = 0;
|
|
320
|
+
break;
|
|
321
|
+
}
|
|
322
|
+
this.passes += 1;
|
|
323
|
+
pos = 0;
|
|
324
|
+
after = -1;
|
|
325
|
+
walked += 1;
|
|
326
|
+
if (walked >= MAX_PASSES) {
|
|
327
|
+
const skipped = Math.floor(left / duration);
|
|
328
|
+
this.dropped += skipped;
|
|
329
|
+
this.passes += skipped;
|
|
330
|
+
left -= skipped * duration;
|
|
331
|
+
walked = 0;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
this.t = pos;
|
|
335
|
+
this.cursor = after;
|
|
336
|
+
if (this.state === "ended" && loop) this.state = "playing";
|
|
337
|
+
return out;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
/** Jump to position `t` (kept in the timeline). Returns the cues the "chase" mode fires (none for "skip"). */
|
|
341
|
+
seek(t) {
|
|
342
|
+
const { duration, cues, seek } = this.settings;
|
|
343
|
+
const to = clamp(Number(t) || 0, 0, duration);
|
|
344
|
+
this.t = to;
|
|
345
|
+
if (this.state === "ended" && to < duration) this.state = "paused";
|
|
346
|
+
if (to === 0 && seek === "skip") {
|
|
347
|
+
this.cursor = -1; // a rewind: the cue at 0 is still to come
|
|
348
|
+
return [];
|
|
349
|
+
}
|
|
350
|
+
this.cursor = to;
|
|
351
|
+
if (seek !== "chase") return [];
|
|
352
|
+
const latest = new Map();
|
|
353
|
+
for (const cue of cues) if (cue.at <= to) latest.set(cue.name, cue);
|
|
354
|
+
return [...latest.values()].sort((a, b) => a.at - b.at).map((c) => cueEvent(c, this.passes));
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
/** Back to the start, stopped, with nothing fired. */
|
|
358
|
+
stop() {
|
|
359
|
+
this.t = 0;
|
|
360
|
+
this.cursor = -1;
|
|
361
|
+
this.passes = 0;
|
|
362
|
+
this.dropped = 0;
|
|
363
|
+
this.extLast = null;
|
|
364
|
+
this.state = "stopped";
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/** Start moving: from the start again when a non-looping timeline had ended. */
|
|
368
|
+
play() {
|
|
369
|
+
if (this.state === "ended" || (!this.settings.loop && this.t >= this.settings.duration)) {
|
|
370
|
+
this.t = 0;
|
|
371
|
+
this.cursor = -1;
|
|
372
|
+
this.passes = 0;
|
|
373
|
+
}
|
|
374
|
+
this.state = "playing";
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
pause() {
|
|
378
|
+
if (this.state === "playing") this.state = "paused";
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* An external playhead (`settings.playhead`): `x` is unwrapped seconds. Moving forward advances (its cues fire);
|
|
383
|
+
* moving back, or the first reading, seeks (no cues, see `seek`). Returns the cues crossed.
|
|
384
|
+
*/
|
|
385
|
+
follow(x) {
|
|
386
|
+
if (!isNum(x)) return [];
|
|
387
|
+
const last = this.extLast;
|
|
388
|
+
this.extLast = x;
|
|
389
|
+
if (last === null || x < last) {
|
|
390
|
+
this.passes = this.settings.loop && this.settings.duration > 0 ? Math.max(0, Math.floor(x / this.settings.duration)) : 0;
|
|
391
|
+
return this.seek(positionAt(x, this.settings.duration, this.settings.loop));
|
|
392
|
+
}
|
|
393
|
+
this.state = "playing";
|
|
394
|
+
return this.advance(x - last);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/** The values and position now, with the cues just crossed: the pane's value. */
|
|
398
|
+
frame(crossedNow = [], extra = {}) {
|
|
399
|
+
const { duration, loop } = this.settings;
|
|
400
|
+
const lanes = lanesAt(this.settings, this.t);
|
|
401
|
+
return {
|
|
402
|
+
kind: KIND,
|
|
403
|
+
t: round(this.t),
|
|
404
|
+
duration,
|
|
405
|
+
position: round(this.t / duration),
|
|
406
|
+
state: this.state,
|
|
407
|
+
loop,
|
|
408
|
+
pass: this.passes,
|
|
409
|
+
lanes,
|
|
410
|
+
cue: crossedNow.length ? crossedNow[crossedNow.length - 1] : null,
|
|
411
|
+
cues: crossedNow,
|
|
412
|
+
...extra,
|
|
413
|
+
};
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
/**
|
|
418
|
+
* Replay a list of moves on a fresh playhead: `[{ advance: dt } | { seek: t } | { follow: x } | { stop: true }]`.
|
|
419
|
+
* Returns `{ frames, cues }`: the frame after each move, and every cue fired in order. The same moves give the
|
|
420
|
+
* same result (the test of "deterministic replay"); the same total time in different step sizes fires the same cues.
|
|
421
|
+
*/
|
|
422
|
+
export function replay(settings, moves) {
|
|
423
|
+
const head = new Playhead(settings);
|
|
424
|
+
head.play();
|
|
425
|
+
const frames = [];
|
|
426
|
+
const cues = [];
|
|
427
|
+
for (const move of moves) {
|
|
428
|
+
let fired = [];
|
|
429
|
+
if ("advance" in move) fired = head.advance(move.advance);
|
|
430
|
+
else if ("seek" in move) fired = head.seek(move.seek);
|
|
431
|
+
else if ("follow" in move) fired = head.follow(move.follow);
|
|
432
|
+
else if ("stop" in move) head.stop(), head.play();
|
|
433
|
+
cues.push(...fired);
|
|
434
|
+
frames.push(head.frame(fired));
|
|
435
|
+
}
|
|
436
|
+
return { frames, cues };
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
// ── editing ────────────────────────────────────────────────────────────────
|
|
440
|
+
|
|
441
|
+
const mapLane = (settings, name, fn) => {
|
|
442
|
+
const at = settings.lanes.findIndex((l) => l.name === name);
|
|
443
|
+
if (at < 0) return { problem: `no lane called "${name}"` };
|
|
444
|
+
const lane = settings.lanes[at];
|
|
445
|
+
const result = fn(lane, rangeOf(lane, settings.duration));
|
|
446
|
+
if (result.problem) return result;
|
|
447
|
+
const lanes = settings.lanes.map((l, i) => (i === at ? { ...l, curve: { interpolation: l.curve.interpolation, points: result.points } } : l));
|
|
448
|
+
return { settings: { ...settings, lanes }, index: result.index };
|
|
449
|
+
};
|
|
450
|
+
|
|
451
|
+
const keep = (curve, next) => ({ interpolation: curve.interpolation, points: next.points });
|
|
452
|
+
|
|
453
|
+
/** Add a keyframe at (x, y) to lane `name` (snapped to the lane's grid; a point already at that x moves its y). */
|
|
454
|
+
export function addKey(settings, name, x, y) {
|
|
455
|
+
return mapLane(settings, name, (lane, w) => {
|
|
456
|
+
const r = curveInsert(asCurve(lane.curve), w, x, y);
|
|
457
|
+
return r.index < 0 ? { problem: `a lane has at most ${MAX_POINTS} keyframes` } : { points: r.value.points, index: r.index };
|
|
458
|
+
});
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
/** Move keyframe `i` of lane `name` to (x, y), snapped and kept between its neighbours: a move in x alone keeps the stored y exactly. */
|
|
462
|
+
export function moveKey(settings, name, i, x, y, options) {
|
|
463
|
+
return mapLane(settings, name, (lane, w) => {
|
|
464
|
+
if (!lane.curve.points[i]) return { problem: "no such keyframe" };
|
|
465
|
+
return { points: curveMove(asCurve(lane.curve), w, i, x, y, options).points, index: i };
|
|
466
|
+
});
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
/** Set keyframe `i` of lane `name` exactly (the table: typed numbers), refusing a value outside the ranges or at another keyframe's time. */
|
|
470
|
+
export function setKey(settings, name, i, { x, y }) {
|
|
471
|
+
return mapLane(settings, name, (lane, w) => {
|
|
472
|
+
const r = curveSet(asCurve(lane.curve), w, i, { x, y });
|
|
473
|
+
return r.problem ? { problem: r.problem } : { points: r.value.points, index: r.index };
|
|
474
|
+
});
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
/** Delete keyframe `i` of lane `name` (a lane keeps at least two). */
|
|
478
|
+
export function removeKey(settings, name, i) {
|
|
479
|
+
return mapLane(settings, name, (lane) => {
|
|
480
|
+
const next = curveRemove(asCurve(lane.curve), i);
|
|
481
|
+
return next.points.length === lane.curve.points.length ? { problem: "a lane keeps at least two keyframes" } : { points: next.points, index: Math.min(i, next.points.length - 1) };
|
|
482
|
+
});
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
/** Change lane `name`'s interpolation. */
|
|
486
|
+
export function setInterpolation(settings, name, interpolation) {
|
|
487
|
+
if (!LANE_INTERPOLATIONS.includes(interpolation)) return { problem: `interpolation is ${LANE_INTERPOLATIONS.join(", ")}` };
|
|
488
|
+
const at = settings.lanes.findIndex((l) => l.name === name);
|
|
489
|
+
if (at < 0) return { problem: `no lane called "${name}"` };
|
|
490
|
+
return { settings: { ...settings, lanes: settings.lanes.map((l, i) => (i === at ? { ...l, curve: keep({ interpolation }, l.curve) } : l)) } };
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
/** Add a lane (named `name`, 0 to 1 unless the range is given). */
|
|
494
|
+
export function addLane(settings, name, { min = 0, max = 1, target, source } = {}) {
|
|
495
|
+
const clean = String(name ?? "").trim();
|
|
496
|
+
if (!clean || clean.length > LIMITS.nameLength) return { problem: `a lane's name is 1 to ${LIMITS.nameLength} characters` };
|
|
497
|
+
if (settings.lanes.some((l) => l.name === clean)) return { problem: `another lane is called "${clean}"` };
|
|
498
|
+
if (settings.lanes.length >= LIMITS.lanes) return { problem: `at most ${LIMITS.lanes} lanes` };
|
|
499
|
+
if (!(isNum(min) && isNum(max) && max > min)) return { problem: "max must be above min" };
|
|
500
|
+
const lane = { ...defaultLane(clean, settings.duration, min, max), ...(target ? { target } : {}), ...(source ? { source } : {}) };
|
|
501
|
+
return { settings: { ...settings, lanes: [...settings.lanes, lane] } };
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
/** Remove lane `name`. */
|
|
505
|
+
export function removeLane(settings, name) {
|
|
506
|
+
if (!settings.lanes.some((l) => l.name === name)) return { problem: `no lane called "${name}"` };
|
|
507
|
+
return { settings: { ...settings, lanes: settings.lanes.filter((l) => l.name !== name) } };
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
/** Add a cue; it is placed in time order. */
|
|
511
|
+
export function addCue(settings, cue) {
|
|
512
|
+
if (settings.cues.length >= LIMITS.cues) return { problem: `at most ${LIMITS.cues} cues` };
|
|
513
|
+
const next = { ...settings, cues: [...settings.cues, cue] };
|
|
514
|
+
const problem = automationProblem(next);
|
|
515
|
+
return problem ? { problem } : { settings: automationSettings(next) };
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
/** Change cue `i` (by its place in time order); the cues are sorted again. */
|
|
519
|
+
export function editCue(settings, i, patch) {
|
|
520
|
+
if (!settings.cues[i]) return { problem: "no such cue" };
|
|
521
|
+
const next = { ...settings, cues: settings.cues.map((c, j) => (j === i ? { ...c, ...patch } : c)) };
|
|
522
|
+
const problem = automationProblem(next);
|
|
523
|
+
return problem ? { problem } : { settings: automationSettings(next) };
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
/** Delete cue `i`. */
|
|
527
|
+
export function removeCue(settings, i) {
|
|
528
|
+
if (!settings.cues[i]) return { problem: "no such cue" };
|
|
529
|
+
return { settings: { ...settings, cues: settings.cues.filter((_, j) => j !== i) } };
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
/** A new duration: lanes' keyframes and cues beyond it are pulled in to the end (a keyframe landing on another's time is dropped). */
|
|
533
|
+
export function setDuration(settings, duration) {
|
|
534
|
+
const d = clamp(Number(duration), ...LIMITS.duration);
|
|
535
|
+
if (!isNum(d)) return { problem: "duration is a number of seconds" };
|
|
536
|
+
return { settings: automationSettings({ ...settings, duration: d }) };
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
// ── capture ────────────────────────────────────────────────────────────────
|
|
540
|
+
|
|
541
|
+
/**
|
|
542
|
+
* Fewer points that follow `samples` ([{ x, y }], time-ordered) within `epsilon` (Ramer–Douglas–Peucker),
|
|
543
|
+
* and never more than `limit`: the tolerance grows until they fit.
|
|
544
|
+
*/
|
|
545
|
+
export function simplify(samples, epsilon, limit = MAX_POINTS) {
|
|
546
|
+
if (samples.length <= 2) return samples.map((p) => ({ ...p }));
|
|
547
|
+
const run = (eps) => {
|
|
548
|
+
const keepAt = new Set([0, samples.length - 1]);
|
|
549
|
+
const stack = [[0, samples.length - 1]];
|
|
550
|
+
while (stack.length) {
|
|
551
|
+
const [lo, hi] = stack.pop();
|
|
552
|
+
const a = samples[lo];
|
|
553
|
+
const b = samples[hi];
|
|
554
|
+
let worst = -1;
|
|
555
|
+
let at = -1;
|
|
556
|
+
for (let i = lo + 1; i < hi; i++) {
|
|
557
|
+
const f = b.x === a.x ? 0 : (samples[i].x - a.x) / (b.x - a.x);
|
|
558
|
+
const d = Math.abs(samples[i].y - (a.y + (b.y - a.y) * f));
|
|
559
|
+
if (d > worst) (worst = d), (at = i);
|
|
560
|
+
}
|
|
561
|
+
if (worst > eps) {
|
|
562
|
+
keepAt.add(at);
|
|
563
|
+
stack.push([lo, at], [at, hi]);
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
return [...keepAt].sort((x, y) => x - y).map((i) => ({ ...samples[i] }));
|
|
567
|
+
};
|
|
568
|
+
let eps = epsilon;
|
|
569
|
+
let out = run(eps);
|
|
570
|
+
while (out.length > limit) out = run((eps *= 2));
|
|
571
|
+
return out;
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
/**
|
|
575
|
+
* A capture: armed lanes record the values their `source` inputs have as the playhead moves. Stopping it
|
|
576
|
+
* makes a TAKE (curves proposed for those lanes); the take is never the pane's settings until `accept`.
|
|
577
|
+
*/
|
|
578
|
+
export class Capture {
|
|
579
|
+
constructor() {
|
|
580
|
+
this.state = "idle"; // "idle" | "armed" | "take"
|
|
581
|
+
this.lanes = [];
|
|
582
|
+
this.samples = new Map(); // lane name -> [{ x, y }]
|
|
583
|
+
this.from = 0;
|
|
584
|
+
this.to = 0;
|
|
585
|
+
this.take = null; // { lanes: { [name]: [{ x, y }] }, from, to }
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
arm(names, at = 0) {
|
|
589
|
+
this.state = "armed";
|
|
590
|
+
this.lanes = [...names];
|
|
591
|
+
this.samples = new Map(this.lanes.map((n) => [n, []]));
|
|
592
|
+
this.from = at;
|
|
593
|
+
this.to = at;
|
|
594
|
+
this.take = null;
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
/** A value for lane `name` at timeline position `t` (ignored unless armed; a value equal to the last one is kept once). */
|
|
598
|
+
sample(name, t, value) {
|
|
599
|
+
if (this.state !== "armed" || !this.samples.has(name) || !isNum(value)) return false;
|
|
600
|
+
const list = this.samples.get(name);
|
|
601
|
+
const last = list[list.length - 1];
|
|
602
|
+
if (last && last.x === t && last.y === value) return false;
|
|
603
|
+
while (list.length && list[list.length - 1].x > t) list.pop(); // the playhead moved back: the take is rerecorded from here
|
|
604
|
+
const x = round(t);
|
|
605
|
+
if (list.length && list[list.length - 1].x === x) list[list.length - 1].y = value; // one value per time: the newest
|
|
606
|
+
else list.push({ x, y: value });
|
|
607
|
+
this.to = Math.max(this.to, t);
|
|
608
|
+
return true;
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
/** Stop recording: the take (curves for the lanes that recorded something), or null when nothing was recorded. */
|
|
612
|
+
stop(settings) {
|
|
613
|
+
if (this.state !== "armed") return this.take;
|
|
614
|
+
const lanes = {};
|
|
615
|
+
for (const [name, list] of this.samples) {
|
|
616
|
+
const lane = settings.lanes.find((l) => l.name === name);
|
|
617
|
+
if (!lane || list.length < 1) continue;
|
|
618
|
+
const clipped = list.map((p) => ({ x: clamp(p.x, 0, settings.duration), y: clamp(p.y, lane.min, lane.max) }));
|
|
619
|
+
if (lane.curve.interpolation === "step") {
|
|
620
|
+
const changes = clipped.filter((p, i) => i === 0 || p.y !== clipped[i - 1].y);
|
|
621
|
+
lanes[name] = changes.length >= 2 ? changes : [...changes, { x: Math.max(this.to, changes[0].x + X_STEP), y: changes[0].y }];
|
|
622
|
+
} else {
|
|
623
|
+
const pts = clipped.length >= 2 ? clipped : [...clipped, { x: Math.max(this.to, clipped[0].x + X_STEP), y: clipped[0].y }];
|
|
624
|
+
lanes[name] = simplify(pts, (lane.max - lane.min) * 0.01);
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
this.state = Object.keys(lanes).length ? "take" : "idle";
|
|
628
|
+
this.take = Object.keys(lanes).length ? { lanes, from: this.from, to: this.to } : null;
|
|
629
|
+
return this.take;
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
discard() {
|
|
633
|
+
this.state = "idle";
|
|
634
|
+
this.take = null;
|
|
635
|
+
this.samples = new Map();
|
|
636
|
+
this.lanes = [];
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
/** `settings` with a take applied: each captured lane's keyframes between the take's start and end replaced by the take's. Pure: the original is untouched. */
|
|
641
|
+
export function applyTake(settings, take) {
|
|
642
|
+
if (!take) return settings;
|
|
643
|
+
const lanes = settings.lanes.map((lane) => {
|
|
644
|
+
const mine = take.lanes[lane.name];
|
|
645
|
+
if (!mine) return lane;
|
|
646
|
+
const lo = mine[0].x;
|
|
647
|
+
const hi = mine[mine.length - 1].x;
|
|
648
|
+
const outside = lane.curve.points.filter((p) => p.x < lo || p.x > hi);
|
|
649
|
+
const points = [...outside, ...mine].sort((a, b) => a.x - b.x).filter((p, i, all) => i === 0 || p.x !== all[i - 1].x).slice(0, MAX_POINTS);
|
|
650
|
+
return { ...lane, curve: { interpolation: lane.curve.interpolation, points: points.length >= 2 ? points : lane.curve.points } };
|
|
651
|
+
});
|
|
652
|
+
return { ...settings, lanes };
|
|
653
|
+
}
|