Compare commits
228 commits
port-solid
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a6b8f87d32 | ||
|
|
079720a572 | ||
|
|
326deb9a17 | ||
|
|
13013077d4 | ||
|
|
856642a962 | ||
|
|
a1cd26ff68 | ||
|
|
7190932191 | ||
|
|
3cf11ef9cf | ||
|
|
ae256ecfbd | ||
|
|
32c4825a69 | ||
|
|
7e308a4e62 | ||
|
|
b5891a6ab9 | ||
|
|
5ab4d18523 | ||
|
|
5ed84cbf00 | ||
|
|
a7b6230b8b | ||
|
|
4db0f498eb | ||
|
|
491820ac79 | ||
|
|
0010097d01 | ||
|
|
3879d57b4c | ||
|
|
6e71ad7d35 | ||
|
|
0bd65917c4 | ||
|
|
766493fcdc | ||
|
|
f75f683f40 | ||
|
|
ec3118004d | ||
|
|
1f0eecfe78 | ||
|
|
f57cddc278 | ||
|
|
1603ea798e | ||
|
|
60584606a8 | ||
|
|
a77770f95d | ||
|
|
68d4cc4017 | ||
|
|
9ad1f78ddd | ||
|
|
b16f26e6ab | ||
|
|
b6be081cf0 | ||
|
|
1f38f1a7fb | ||
|
|
c19d84619e | ||
|
|
7a30da91a8 | ||
|
|
b953681157 | ||
|
|
fae519092f | ||
|
|
7ce4598a0b | ||
|
|
ae2657a01b | ||
|
|
87daac4f0d | ||
|
|
96737a3d42 | ||
|
|
f5b571412f | ||
|
|
a1a158b8d0 | ||
|
|
8c44a51220 | ||
|
|
1a78ed9597 | ||
|
|
75e0e58067 | ||
|
|
dbe0f5d8ba | ||
|
|
bf3d088ff1 | ||
|
|
ffac04090c | ||
|
|
53da84c425 | ||
|
|
232d51039d | ||
|
|
9b686eb312 | ||
|
|
c98d25c255 | ||
|
|
ea588e79cd | ||
|
|
e37f16739e | ||
|
|
abb569b287 | ||
|
|
aa60fbb466 | ||
|
|
3552ee46f6 | ||
|
|
8c249ea8af | ||
|
|
fd0aee2354 | ||
|
|
fa3704765c | ||
|
|
f028f1256d | ||
|
|
1b69254de2 | ||
|
|
e1713ae41f | ||
|
|
161ce155e4 | ||
|
|
28e394ddf3 | ||
|
|
6c499e6826 | ||
|
|
c45b91a5f9 | ||
|
|
bd35432797 | ||
|
|
a7c1f29aa6 | ||
|
|
846a0c373a | ||
|
|
1672fe3474 | ||
|
|
1f4513802f | ||
|
|
a36b58dce8 | ||
|
|
7fd0dda3a2 | ||
|
|
9490e20a7a | ||
|
|
7e957457cd | ||
|
|
7e4dc26f6e | ||
|
|
3af92b625a | ||
|
|
b6819fd26f | ||
|
|
8a19e5b52c | ||
|
|
43ef6d5dae | ||
|
|
d1f1f45f6b | ||
|
|
0ee7f1472c | ||
|
|
b9f739a56d | ||
|
|
21b223abd3 | ||
|
|
0d1a2102eb | ||
|
|
9056ac3f5e | ||
|
|
469a38ae16 | ||
|
|
fb0228e6c3 | ||
|
|
29dc88be3a | ||
|
|
c936bf75c9 | ||
|
|
d466dd3c48 | ||
|
|
a9623d71d7 | ||
|
|
fa80a305d9 | ||
|
|
19f9082dd7 | ||
|
|
45f3ca5cae | ||
|
|
c7056e20e8 | ||
|
|
d2b0427ec6 | ||
|
|
031c7f97ff | ||
|
|
c986377b4c | ||
|
|
ac84ed5ed9 | ||
|
|
2e75194fbb | ||
|
|
94b91f1cc0 | ||
|
|
68f7d681fe | ||
|
|
e28a4b0a3a | ||
|
|
f822e4231f | ||
|
|
653ea0dbe5 | ||
|
|
4656568d4f | ||
|
|
527b8fc679 | ||
|
|
c45aff4411 | ||
|
|
99c834cd64 | ||
|
|
57c9edee3a | ||
|
|
b7c46828f3 | ||
|
|
e857199554 | ||
|
|
4e60d0192a | ||
|
|
30fc44ba1e | ||
|
|
cb28facc65 | ||
|
|
453047612a | ||
|
|
3952c65d75 | ||
|
|
2f9cfd1de2 | ||
|
|
c955e94a7a | ||
|
|
9ad0b8b9a0 | ||
|
|
9e59eb04ce | ||
|
|
115fd501b5 | ||
|
|
60220e9176 | ||
|
|
572102c4c0 | ||
|
|
5d3785a6a8 | ||
|
|
b3c0e71bb7 | ||
|
|
9a9b66c5ee | ||
|
|
6584423ccd | ||
|
|
c86c7da5df | ||
|
|
892384f043 | ||
|
|
7691b9ca8c | ||
|
|
0a17b3e76e | ||
|
|
45e59e1a23 | ||
|
|
1ab269415e | ||
|
|
cba7de6a4b | ||
|
|
d6226f3cf0 | ||
|
|
7d36d3d18d | ||
|
|
33c3b156b6 | ||
|
|
964e37551f | ||
|
|
433a4989e1 | ||
|
|
6c3c55949d | ||
|
|
091cfe2716 | ||
|
|
7434b03a57 | ||
|
|
711415e9ff | ||
|
|
ecb5bf2bb6 | ||
|
|
33cae47ffa | ||
|
|
785935bf25 | ||
|
|
f05669969f | ||
|
|
406e7c1729 | ||
|
|
a109e0299d | ||
|
|
517bd2f987 | ||
|
|
fbc68ebfab | ||
|
|
0d8179d6d5 | ||
|
|
22efb1c411 | ||
|
|
24057e7b5f | ||
|
|
f41d6ea1b7 | ||
|
|
19b7f7eee8 | ||
|
|
9ddf7f0bd5 | ||
|
|
f2562176fc | ||
|
|
3c67d86019 | ||
|
|
2b939bb812 | ||
|
|
3a8e2b8116 | ||
|
|
e45822e5a2 | ||
|
|
3138701100 | ||
|
|
a4d3b3a8b5 | ||
| 54821fffd0 | |||
|
|
2bc422a880 | ||
|
|
5fc37f760e | ||
|
|
f916344c9b | ||
|
|
ebd5dba4c0 | ||
|
|
3021552a38 | ||
|
|
f26ec923e1 | ||
|
|
4964037da0 | ||
|
|
429da1d1e4 | ||
|
|
b6b4cf7362 | ||
|
|
5cd5041b6a | ||
|
|
8d0d47b992 | ||
|
|
973455b158 | ||
|
|
825ed6ad33 | ||
|
|
55e7bc9654 | ||
|
|
f59b12a056 | ||
|
|
8911079212 | ||
|
|
48dcf3fc6b | ||
|
|
c3fb63a113 | ||
|
|
add05ea554 | ||
|
|
665e224122 | ||
|
|
a160b72295 | ||
|
|
d41e4c3e9f | ||
|
|
05f04a90e0 | ||
|
|
129e28b207 | ||
|
|
1bb0ec5eed | ||
|
|
e5bf2aa055 | ||
|
|
4f60fc8405 | ||
|
|
01f6522fd5 | ||
|
|
d3373a4e44 | ||
|
|
c7da7bf4f7 | ||
|
|
25b8f7ca72 | ||
|
|
6b26168a29 | ||
|
|
d1c12dd2b1 | ||
|
|
074d4b3005 | ||
|
|
39312a0d1f | ||
|
|
314408aba9 | ||
|
|
e12eaab9cb | ||
|
|
6efbe9c992 | ||
|
|
972d3e7961 | ||
|
|
d095688cd9 | ||
|
|
01c1346dfd | ||
|
|
b290144670 | ||
|
|
6072fe80ac | ||
|
|
575519df68 | ||
|
|
fbeedba2f3 | ||
|
|
4507db00c8 | ||
|
|
70c858016f | ||
|
|
e6938ebb8b | ||
|
|
0de64463fd | ||
|
|
2993328859 | ||
|
|
afff406d92 | ||
|
|
c633b9c2ab | ||
|
|
bae80fbd89 | ||
|
|
041b79c202 | ||
|
|
27a1e4e5b0 | ||
|
|
d5bb77d03e | ||
|
|
8be4f85cb6 | ||
|
|
56c1189c5e |
890 changed files with 133574 additions and 90868 deletions
51
.beads/.gitignore
vendored
51
.beads/.gitignore
vendored
|
|
@ -1,51 +0,0 @@
|
||||||
# Dolt database (managed by Dolt, not git)
|
|
||||||
dolt/
|
|
||||||
dolt-access.lock
|
|
||||||
|
|
||||||
# Runtime files
|
|
||||||
bd.sock
|
|
||||||
bd.sock.startlock
|
|
||||||
sync-state.json
|
|
||||||
last-touched
|
|
||||||
|
|
||||||
# Local version tracking (prevents upgrade notification spam after git ops)
|
|
||||||
.local_version
|
|
||||||
|
|
||||||
# Worktree redirect file (contains relative path to main repo's .beads/)
|
|
||||||
# Must not be committed as paths would be wrong in other clones
|
|
||||||
redirect
|
|
||||||
|
|
||||||
# Sync state (local-only, per-machine)
|
|
||||||
# These files are machine-specific and should not be shared across clones
|
|
||||||
.sync.lock
|
|
||||||
export-state/
|
|
||||||
|
|
||||||
# Ephemeral store (SQLite - wisps/molecules, intentionally not versioned)
|
|
||||||
ephemeral.sqlite3
|
|
||||||
ephemeral.sqlite3-journal
|
|
||||||
ephemeral.sqlite3-wal
|
|
||||||
ephemeral.sqlite3-shm
|
|
||||||
|
|
||||||
# Dolt server management (auto-started by bd)
|
|
||||||
dolt-server.pid
|
|
||||||
dolt-server.log
|
|
||||||
dolt-server.lock
|
|
||||||
dolt-server.port
|
|
||||||
dolt-server.activity
|
|
||||||
dolt-monitor.pid
|
|
||||||
|
|
||||||
# Backup data (auto-exported JSONL, local-only)
|
|
||||||
backup/
|
|
||||||
|
|
||||||
# Legacy files (from pre-Dolt versions)
|
|
||||||
*.db
|
|
||||||
*.db?*
|
|
||||||
*.db-journal
|
|
||||||
*.db-wal
|
|
||||||
*.db-shm
|
|
||||||
db.sqlite
|
|
||||||
bd.db
|
|
||||||
# NOTE: Do NOT add negation patterns here.
|
|
||||||
# They would override fork protection in .git/info/exclude.
|
|
||||||
# Config files (metadata.json, config.yaml) are tracked by git by default
|
|
||||||
# since no pattern above ignores them.
|
|
||||||
|
|
@ -1,81 +0,0 @@
|
||||||
# Beads - AI-Native Issue Tracking
|
|
||||||
|
|
||||||
Welcome to Beads! This repository uses **Beads** for issue tracking - a modern, AI-native tool designed to live directly in your codebase alongside your code.
|
|
||||||
|
|
||||||
## What is Beads?
|
|
||||||
|
|
||||||
Beads is issue tracking that lives in your repo, making it perfect for AI coding agents and developers who want their issues close to their code. No web UI required - everything works through the CLI and integrates seamlessly with git.
|
|
||||||
|
|
||||||
**Learn more:** [github.com/steveyegge/beads](https://github.com/steveyegge/beads)
|
|
||||||
|
|
||||||
## Quick Start
|
|
||||||
|
|
||||||
### Essential Commands
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# Create new issues
|
|
||||||
bd create "Add user authentication"
|
|
||||||
|
|
||||||
# View all issues
|
|
||||||
bd list
|
|
||||||
|
|
||||||
# View issue details
|
|
||||||
bd show <issue-id>
|
|
||||||
|
|
||||||
# Update issue status
|
|
||||||
bd update <issue-id> --status in_progress
|
|
||||||
bd update <issue-id> --status done
|
|
||||||
|
|
||||||
# Sync with Dolt remote
|
|
||||||
bd dolt push
|
|
||||||
```
|
|
||||||
|
|
||||||
### Working with Issues
|
|
||||||
|
|
||||||
Issues in Beads are:
|
|
||||||
- **Git-native**: Stored in `.beads/issues.jsonl` and synced like code
|
|
||||||
- **AI-friendly**: CLI-first design works perfectly with AI coding agents
|
|
||||||
- **Branch-aware**: Issues can follow your branch workflow
|
|
||||||
- **Always in sync**: Auto-syncs with your commits
|
|
||||||
|
|
||||||
## Why Beads?
|
|
||||||
|
|
||||||
✨ **AI-Native Design**
|
|
||||||
- Built specifically for AI-assisted development workflows
|
|
||||||
- CLI-first interface works seamlessly with AI coding agents
|
|
||||||
- No context switching to web UIs
|
|
||||||
|
|
||||||
🚀 **Developer Focused**
|
|
||||||
- Issues live in your repo, right next to your code
|
|
||||||
- Works offline, syncs when you push
|
|
||||||
- Fast, lightweight, and stays out of your way
|
|
||||||
|
|
||||||
🔧 **Git Integration**
|
|
||||||
- Automatic sync with git commits
|
|
||||||
- Branch-aware issue tracking
|
|
||||||
- Intelligent JSONL merge resolution
|
|
||||||
|
|
||||||
## Get Started with Beads
|
|
||||||
|
|
||||||
Try Beads in your own projects:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# Install Beads
|
|
||||||
curl -sSL https://raw.githubusercontent.com/steveyegge/beads/main/scripts/install.sh | bash
|
|
||||||
|
|
||||||
# Initialize in your repo
|
|
||||||
bd init
|
|
||||||
|
|
||||||
# Create your first issue
|
|
||||||
bd create "Try out Beads"
|
|
||||||
```
|
|
||||||
|
|
||||||
## Learn More
|
|
||||||
|
|
||||||
- **Documentation**: [github.com/steveyegge/beads/docs](https://github.com/steveyegge/beads/tree/main/docs)
|
|
||||||
- **Quick Start Guide**: Run `bd quickstart`
|
|
||||||
- **Examples**: [github.com/steveyegge/beads/examples](https://github.com/steveyegge/beads/tree/main/examples)
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
*Beads: Issue tracking that moves at the speed of thought* ⚡
|
|
||||||
|
|
@ -1,42 +0,0 @@
|
||||||
# Beads Configuration File
|
|
||||||
# This file configures default behavior for all bd commands in this repository
|
|
||||||
# All settings can also be set via environment variables (BD_* prefix)
|
|
||||||
# or overridden with command-line flags
|
|
||||||
|
|
||||||
# Issue prefix for this repository (used by bd init)
|
|
||||||
# If not set, bd init will auto-detect from directory name
|
|
||||||
# Example: issue-prefix: "myproject" creates issues like "myproject-1", "myproject-2", etc.
|
|
||||||
# issue-prefix: ""
|
|
||||||
|
|
||||||
# Use no-db mode: load from JSONL, write back after each command
|
|
||||||
# When true, bd will use .beads/issues.jsonl as the source of truth
|
|
||||||
# instead of the Dolt database
|
|
||||||
# no-db: false
|
|
||||||
|
|
||||||
# Enable JSON output by default
|
|
||||||
# json: false
|
|
||||||
|
|
||||||
# Default actor for audit trails (overridden by BD_ACTOR or --actor)
|
|
||||||
# actor: ""
|
|
||||||
|
|
||||||
# Export events (audit trail) to .beads/events.jsonl on each flush/sync
|
|
||||||
# When enabled, new events are appended incrementally using a high-water mark.
|
|
||||||
# Use 'bd export --events' to trigger manually regardless of this setting.
|
|
||||||
# events-export: false
|
|
||||||
|
|
||||||
# Multi-repo configuration (experimental - bd-307)
|
|
||||||
# Allows hydrating from multiple repositories and routing writes to the correct JSONL
|
|
||||||
# repos:
|
|
||||||
# primary: "." # Primary repo (where this database lives)
|
|
||||||
# additional: # Additional repos to hydrate from (read-only)
|
|
||||||
# - ~/beads-planning # Personal planning repo
|
|
||||||
# - ~/work-planning # Work planning repo
|
|
||||||
|
|
||||||
# Integration settings (access with 'bd config get/set')
|
|
||||||
# These are stored in the database, not in this file:
|
|
||||||
# - jira.url
|
|
||||||
# - jira.project
|
|
||||||
# - linear.url
|
|
||||||
# - linear.api-key
|
|
||||||
# - github.org
|
|
||||||
# - github.repo
|
|
||||||
|
|
@ -1,17 +0,0 @@
|
||||||
#!/usr/bin/env sh
|
|
||||||
# bd-shim v1
|
|
||||||
# bd-hooks-version: 0.56.1
|
|
||||||
#
|
|
||||||
# bd (beads) post-checkout hook - thin shim
|
|
||||||
#
|
|
||||||
# This shim delegates to 'bd hooks run post-checkout' which contains
|
|
||||||
# the actual hook logic. This pattern ensures hook behavior is always
|
|
||||||
# in sync with the installed bd version - no manual updates needed.
|
|
||||||
|
|
||||||
# Check if bd is available
|
|
||||||
if ! command -v bd >/dev/null 2>&1; then
|
|
||||||
# Silently skip - post-checkout is called frequently
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
exec bd hooks run post-checkout "$@"
|
|
||||||
|
|
@ -1,19 +0,0 @@
|
||||||
#!/usr/bin/env sh
|
|
||||||
# bd-shim v1
|
|
||||||
# bd-hooks-version: 0.56.1
|
|
||||||
#
|
|
||||||
# bd (beads) post-merge hook - thin shim
|
|
||||||
#
|
|
||||||
# This shim delegates to 'bd hooks run post-merge' which contains
|
|
||||||
# the actual hook logic. This pattern ensures hook behavior is always
|
|
||||||
# in sync with the installed bd version - no manual updates needed.
|
|
||||||
|
|
||||||
# Check if bd is available
|
|
||||||
if ! command -v bd >/dev/null 2>&1; then
|
|
||||||
echo "Warning: bd command not found in PATH, skipping post-merge hook" >&2
|
|
||||||
echo " Install bd: brew install beads" >&2
|
|
||||||
echo " Or add bd to your PATH" >&2
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
exec bd hooks run post-merge "$@"
|
|
||||||
|
|
@ -1,19 +0,0 @@
|
||||||
#!/usr/bin/env sh
|
|
||||||
# bd-shim v2
|
|
||||||
# bd-hooks-version: 0.56.1
|
|
||||||
#
|
|
||||||
# bd (beads) pre-commit hook — thin shim
|
|
||||||
#
|
|
||||||
# Delegates to 'bd hooks run pre-commit' which contains the actual hook
|
|
||||||
# logic. This pattern ensures hook behavior is always in sync with the
|
|
||||||
# installed bd version — no manual updates needed.
|
|
||||||
|
|
||||||
# Check if bd is available
|
|
||||||
if ! command -v bd >/dev/null 2>&1; then
|
|
||||||
echo "Warning: bd command not found in PATH, skipping pre-commit hook" >&2
|
|
||||||
echo " Install bd: brew install beads" >&2
|
|
||||||
echo " Or add bd to your PATH" >&2
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
exec bd hooks run pre-commit "$@"
|
|
||||||
|
|
@ -1,19 +0,0 @@
|
||||||
#!/usr/bin/env sh
|
|
||||||
# bd-shim v1
|
|
||||||
# bd-hooks-version: 0.56.1
|
|
||||||
#
|
|
||||||
# bd (beads) pre-push hook - thin shim
|
|
||||||
#
|
|
||||||
# This shim delegates to 'bd hooks run pre-push' which contains
|
|
||||||
# the actual hook logic. This pattern ensures hook behavior is always
|
|
||||||
# in sync with the installed bd version - no manual updates needed.
|
|
||||||
|
|
||||||
# Check if bd is available
|
|
||||||
if ! command -v bd >/dev/null 2>&1; then
|
|
||||||
echo "Warning: bd command not found in PATH, skipping pre-push hook" >&2
|
|
||||||
echo " Install bd: brew install beads" >&2
|
|
||||||
echo " Or add bd to your PATH" >&2
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
exec bd hooks run pre-push "$@"
|
|
||||||
|
|
@ -1,24 +0,0 @@
|
||||||
#!/usr/bin/env sh
|
|
||||||
# bd-shim v1
|
|
||||||
# bd-hooks-version: 0.48.0
|
|
||||||
#
|
|
||||||
# bd (beads) prepare-commit-msg hook - thin shim
|
|
||||||
#
|
|
||||||
# This shim delegates to 'bd hooks run prepare-commit-msg' which contains
|
|
||||||
# the actual hook logic. This pattern ensures hook behavior is always
|
|
||||||
# in sync with the installed bd version - no manual updates needed.
|
|
||||||
#
|
|
||||||
# Arguments:
|
|
||||||
# $1 = path to the commit message file
|
|
||||||
# $2 = source of commit message (message, template, merge, squash, commit)
|
|
||||||
# $3 = commit SHA-1 (if -c, -C, or --amend)
|
|
||||||
|
|
||||||
# Check if bd is available
|
|
||||||
if ! command -v bd >/dev/null 2>&1; then
|
|
||||||
echo "Warning: bd command not found in PATH, skipping prepare-commit-msg hook" >&2
|
|
||||||
echo " Install bd: brew install beads" >&2
|
|
||||||
echo " Or add bd to your PATH" >&2
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
exec bd hooks run prepare-commit-msg "$@"
|
|
||||||
|
|
@ -1,11 +0,0 @@
|
||||||
{"id": "src-ucr", "title": "Study nisps-core MLP implementation (Node \u2192 Layer \u2192 MLP)", "description": "Deep-read the core ML engine in nisps-core/include/nisps/. Start from utils.hpp (activation functions, math), then node.hpp (single neuron forward/backward), layer.hpp (vector of nodes, backprop), mlp.hpp + mlp_impl.hpp (full network: Train, TrainBatch, MoveWeights, SmoothUpdateWeights, policy gradient, Xavier init, NaN recovery). Document: weight initialization strategies, forward pass data flow, backprop implementation, gradient accumulation, loss functions (loss.hpp), and the CheckAndFixWeights safety net. Note differences between supervised and RL training paths.", "status": "open", "priority": 1, "issue_type": "task", "created_by": "w1n5t0n", "owner": "w1n5t0n@lnfinitemonkeys.org", "created_at": "2026-03-04T23:13:40Z", "updated_at": "2026-03-04T23:13:40Z"}
|
|
||||||
{"id": "src-vah", "title": "Study Dataset and IML interface (nisps-core)", "description": "Read dataset.hpp + dataset_impl.hpp (max 100 examples, FIFO/RANDOM forget modes, ReplayMemory), sample.hpp (legacy Sample/TrainingSample), then iml.hpp + iml_impl.hpp (the user-facing API). Document: the two-step save_example() hardware workflow vs direct add_example() API, Mode::Inference vs Mode::Training state machine, how training is triggered on mode switch, weight randomisation + restoration pattern, input clamping, and the logger callback system. Compare with the original IMLInterface.hpp to understand what was extracted vs what's firmware-specific.", "status": "open", "priority": 1, "issue_type": "task", "created_by": "w1n5t0n", "owner": "w1n5t0n@lnfinitemonkeys.org", "created_at": "2026-03-04T23:13:40Z", "updated_at": "2026-03-04T23:13:40Z"}
|
|
||||||
{"id": "src-0tr", "title": "Study the original IMLInterface.hpp and InterfaceRL integration", "description": "Read IMLInterface.hpp (276 lines) \u2014 the firmware-side ML interface inheriting InterfaceBase. Document: MLP architecture [n_inputs+bias, 10, 10, 14, n_outputs], training params (1000 iter, LR=1.0, convergence=0.00001), the INFERENCE_MODE/TRAINING_MODE state machine, STORE_VALUE_MODE vs STORE_POSITION_MODE for the two-step example capture, MLRandomise_/MLTraining_ flow, SendParamsToQueue for cross-core output delivery. Then study how InterfaceRL (from memllib submodule) wraps this with RL reward, INPUT_MODES (JOYSTICK, MACHINE_LISTENING, JOYSTICK_AND_MACHINE_LISTENING), and joystick/MIDI binding.", "status": "open", "priority": 1, "issue_type": "task", "created_by": "w1n5t0n", "owner": "w1n5t0n@lnfinitemonkeys.org", "created_at": "2026-03-04T23:13:43Z", "updated_at": "2026-03-04T23:13:43Z"}
|
|
||||||
{"id": "src-6jj", "title": "Study dual-core architecture and inter-core communication", "description": "Read MEMLNaut-NISPS.ino (230 lines) focusing on the dual-core RP2040 design. Document: Core 0 responsibilities (UI loop, ML inference, hardware polling at 5ms), Core 1 responsibilities (audio processing, MIDI polling at 10ms), startup synchronization (4 volatile bool flags + MEMORY_BARRIER/WRITE_VOLATILE/READ_VOLATILE), the audio_block_callback signature and execution context, ROSC entropy seed generation, PERF timing macros, and the compile-time mode selection via #define MEMLNAUT_MODE_TYPE. Map the three inter-core communication patterns: (1) volatile flags + memory barriers, (2) RP2040 queue_t for MIDI/control, (3) SharedBuffer<T,N> for analysis params.", "status": "open", "priority": 1, "issue_type": "task", "created_by": "w1n5t0n", "owner": "w1n5t0n@lnfinitemonkeys.org", "created_at": "2026-03-04T23:13:47Z", "updated_at": "2026-03-04T23:13:47Z"}
|
|
||||||
{"id": "src-mw5", "title": "Study the Mode system and MEMLNautMode C++20 concept", "description": "Read modes/MEMLNautMode.hpp (concept definition) and all four mode implementations: MEMLNautModePAFSynth (3 inputs, PAF synth), MEMLNautModeChannelStrip (4 inputs, channel strip), MEMLNautModeXIASRI (6 audio-feature inputs, reverb/FX), MEMLNautModeSoundAnalysisMIDI (9 inputs, audio+joystick, MIDI output). Document: how the concept enforces the interface without inheritance (duck typing), kN_InputParams per mode, how each mode configures InterfaceRL (input mode, dimensionality), MIDI setup patterns, display view creation, and the SharedBuffer pattern used by analysis modes for cross-core audio feature transport.", "status": "open", "priority": 1, "issue_type": "task", "created_by": "w1n5t0n", "owner": "w1n5t0n@lnfinitemonkeys.org", "created_at": "2026-03-04T23:13:54Z", "updated_at": "2026-03-04T23:13:54Z"}
|
|
||||||
{"id": "src-eie", "title": "Study PAFSynthAudioApp and PAF voice spaces", "description": "Read PAFSynthAudioApp.hpp (358 lines). Document: 4 maxiPAFOperator instances, oscillator chaining (geometric detuning: freq0 \u2192 freq1=freq0*detune1 \u2192 freq2=freq1*detune2 \u2192 freq3=freq2*detune3), effects chain (ring mod \u2192 sine shaper \u2192 delay \u2192 tanh soft-clip), MIDI note queue handling via queue_t, and the 7 voice spaces (VoiceSpace1/2/Perc/Single1/QuadDetune/QuadOct/QuadDist). For each voice space macro, document which PAF operators are active, key parameter routings, and sonic character. Note the VoiceSpace<NPARAMS> struct (name + lambda) and VoiceSpaceFn type alias.", "status": "open", "priority": 1, "issue_type": "task", "created_by": "w1n5t0n", "owner": "w1n5t0n@lnfinitemonkeys.org", "created_at": "2026-03-04T23:14:00Z", "updated_at": "2026-03-04T23:14:00Z"}
|
|
||||||
{"id": "src-v1r", "title": "Study ChannelStripAudioApp and console emulation voice spaces", "description": "Read ChannelStripAudioApp.hpp (641 lines). Document: the full signal chain (pre-gain tanh \u2192 HP+LP input filters \u2192 2x peak + low/high shelf EQ \u2192 dynamics \u2192 post-gain), stereo processing, the inline maxiDynamicsLite implementation (~290 lines: compander with knee, RMS/peak detection, attack/release ADSRLite envelopes, look-ahead delay, bezier knee curves), maxiRingBufLite, controlMessages enum for bypass toggles via queue_t. Then study voicespaces/ChannelStrip/basic.hpp (179 lines): 6 console emulation macros (Neve 1066, SSL 4K/9K, Male/Female Vox, Neve 80). Note the Neve 80 stepped-switch emulation using constexpr arrays + index math.", "status": "open", "priority": 1, "issue_type": "task", "created_by": "w1n5t0n", "owner": "w1n5t0n@lnfinitemonkeys.org", "created_at": "2026-03-04T23:14:06Z", "updated_at": "2026-03-04T23:14:06Z"}
|
|
||||||
{"id": "src-767", "title": "Study XIASRIAudioApp and XiasriAnalysis audio feature extraction", "description": "Read XIASRIAudioApp.hpp (234 lines): reverb/FX engine with 4 delay lines, 6 all-pass filters, 2 comb filters, DC blocker, daisysp PitchShifter, OnePoleSmoother for parameter smoothing. Then read XiasriAnalysis.hpp/.cpp (62+170 lines): the 6-parameter feature extraction pipeline (pitch via zero-crossing + MedianFilter + CircularBuffer, aperiodicity as relative MAD, energy via envelope follower + log scaling, attack as energy derivative, brightness as HP/LP band ratio). Document the per-sample processing pipeline, normalization ranges, and how features flow from Core 1 analysis through SharedBuffer to Core 0 ML input.", "status": "open", "priority": 1, "issue_type": "task", "created_by": "w1n5t0n", "owner": "w1n5t0n@lnfinitemonkeys.org", "created_at": "2026-03-04T23:14:12Z", "updated_at": "2026-03-04T23:14:12Z"}
|
|
||||||
{"id": "src-sas", "title": "Study the playground JS port and verify ML fidelity", "description": "Read all playground/js/nisps/ files (iml.js, mlp.js, layer.js, node.js, dataset.js) and compare line-by-line against nisps-core C++ headers. Document any differences in: activation functions, forward pass, backprop, weight init, moveWeights noise generation, training convergence, dataset management. Then read app.js (446 lines) for the two learning modes (examples vs RL), the RL reward loop (thumbsUp saves+trains+decays noise, thumbsDown amplifies noise+moveWeights), gamepad support, localStorage persistence, presets. Read the UI files (visualizer.js flow-field, joystick.js touch handling, controls.js, param-display.js) to understand the full demo architecture.", "status": "open", "priority": 1, "issue_type": "task", "created_by": "w1n5t0n", "owner": "w1n5t0n@lnfinitemonkeys.org", "created_at": "2026-03-04T23:14:17Z", "updated_at": "2026-03-04T23:14:17Z"}
|
|
||||||
{"id": "src-5xo", "title": "Study memllib and memlp submodule interfaces", "description": "Check out the submodules (git submodule update --init --recursive) and study the key interfaces that the firmware depends on. Focus on: AudioAppBase<NPARAMS> (Setup/Process/ProcessParams/SendParamsToQueue), AudioDriver (GetSampleRate, SetBlockCallback), InterfaceBase (setup, SendParamsToQueue), InterfaceRL (full RL wrapper: bindInterface, bindMIDI, readAnalysisParameters, INPUT_MODES, rlStatsView), MEMLNaut singleton (hardware abstraction), SharedBuffer<T,N> (lock-free inter-core), stereosample_t, memory placement macros (AUDIO_MEM, AUDIO_FUNC, APP_SRAM), timer macros (PERIODIC_RUN_US), and the embedded MLP.h/Dataset.hpp from memlp. Document what each provides and how nisps-core diverges from memlp.", "status": "open", "priority": 1, "issue_type": "task", "created_by": "w1n5t0n", "owner": "w1n5t0n@lnfinitemonkeys.org", "created_at": "2026-03-04T23:14:24Z", "updated_at": "2026-03-04T23:14:24Z"}
|
|
||||||
{"id": "src-kqa", "title": "Write comprehensive architecture notes to memory", "description": "After completing all study issues, synthesize findings into structured memory files. Create: (1) architecture.md \u2014 system overview, dual-core design, data flow diagrams (input \u2192 ML \u2192 voice space \u2192 audio), inter-core patterns. (2) ml-engine.md \u2014 MLP architecture, training modes, RL vs supervised, weight management. (3) audio-dsp.md \u2014 all audio apps, voice spaces, signal chains, feature extraction. (4) playground-port.md \u2014 JS/C++ correspondence, any divergences found. (5) Update MEMORY.md with index and key insights. Goal: these notes should be detailed enough to rewrite the system in any architecture.", "status": "open", "priority": 2, "issue_type": "task", "created_by": "w1n5t0n", "owner": "w1n5t0n@lnfinitemonkeys.org", "created_at": "2026-03-04T23:14:29Z", "updated_at": "2026-03-04T23:14:29Z"}
|
|
||||||
|
|
@ -1,7 +0,0 @@
|
||||||
{
|
|
||||||
"database": "dolt",
|
|
||||||
"backend": "dolt",
|
|
||||||
"dolt_mode": "server",
|
|
||||||
"dolt_database": "beads_meml",
|
|
||||||
"project_id": "876a8fcd-79fc-4727-a69a-b6bf58c616e9"
|
|
||||||
}
|
|
||||||
File diff suppressed because it is too large
Load diff
|
|
@ -1,319 +0,0 @@
|
||||||
/**
|
|
||||||
* ShapeSeq Chain — sequential pipeline runner with generator combination modes
|
|
||||||
*
|
|
||||||
* Evaluates an ordered list of primitives as a sequential pipeline:
|
|
||||||
* 1. Generators run first, combined via additive or multiplicative merge
|
|
||||||
* 2. Processors transform the pattern in chain order
|
|
||||||
* 3. Converters run in chain order
|
|
||||||
* 4. Timing modifiers annotate last
|
|
||||||
*
|
|
||||||
* Params are distributed flat across primitives in chain order.
|
|
||||||
* Each primitive gets a deterministic PRNG stream via fork(masterPRNG, index).
|
|
||||||
*
|
|
||||||
* Port-ready: explicit state, typed arrays, no closures in hot path.
|
|
||||||
*
|
|
||||||
* @module shapeseq/chain
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { createPattern, mergePatterns } from './pattern.js';
|
|
||||||
import { createPRNG, fork } from './prng.js';
|
|
||||||
|
|
||||||
// ── Category execution order ────────────────────────────────────────
|
|
||||||
|
|
||||||
const PHASE_ORDER = ['generator', 'processor', 'converter', 'timing'];
|
|
||||||
|
|
||||||
// ── Chain class ─────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
export class Chain {
|
|
||||||
constructor() {
|
|
||||||
/** @private @type {Array<import('./primitive.js').Primitive>} */
|
|
||||||
this._primitives = [];
|
|
||||||
|
|
||||||
/** @type {'additive'|'multiplicative'} */
|
|
||||||
this.generatorCombineMode = 'additive';
|
|
||||||
|
|
||||||
/** @private @type {number} */
|
|
||||||
this._masterSeed = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Per-primitive state objects, indexed by position in chain.
|
|
||||||
* Populated after evaluate() calls; used for freeze support.
|
|
||||||
* @private @type {Array<Object>}
|
|
||||||
*/
|
|
||||||
this._primitiveStates = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── Primitive management ────────────────────────────────────────
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Append a primitive to the end of the chain.
|
|
||||||
* @param {import('./primitive.js').Primitive} primitive
|
|
||||||
*/
|
|
||||||
addPrimitive(primitive) {
|
|
||||||
this._primitives.push(primitive);
|
|
||||||
this._primitiveStates.push(primitive.getState());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Remove the primitive at the given index.
|
|
||||||
* @param {number} index
|
|
||||||
*/
|
|
||||||
removePrimitive(index) {
|
|
||||||
const idx = index | 0;
|
|
||||||
if (idx < 0 || idx >= this._primitives.length) {
|
|
||||||
throw new RangeError('removePrimitive: index ' + index + ' out of range [0, ' + (this._primitives.length - 1) + ']');
|
|
||||||
}
|
|
||||||
this._primitives.splice(idx, 1);
|
|
||||||
this._primitiveStates.splice(idx, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Insert a primitive at the given index, shifting others right.
|
|
||||||
* @param {number} index
|
|
||||||
* @param {import('./primitive.js').Primitive} primitive
|
|
||||||
*/
|
|
||||||
insertPrimitive(index, primitive) {
|
|
||||||
const idx = index | 0;
|
|
||||||
if (idx < 0 || idx > this._primitives.length) {
|
|
||||||
throw new RangeError('insertPrimitive: index ' + index + ' out of range [0, ' + this._primitives.length + ']');
|
|
||||||
}
|
|
||||||
this._primitives.splice(idx, 0, primitive);
|
|
||||||
this._primitiveStates.splice(idx, 0, primitive.getState());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Move a primitive from one position to another.
|
|
||||||
* @param {number} fromIndex
|
|
||||||
* @param {number} toIndex
|
|
||||||
*/
|
|
||||||
movePrimitive(fromIndex, toIndex) {
|
|
||||||
const from = fromIndex | 0;
|
|
||||||
const to = toIndex | 0;
|
|
||||||
const len = this._primitives.length;
|
|
||||||
if (from < 0 || from >= len) {
|
|
||||||
throw new RangeError('movePrimitive: fromIndex ' + fromIndex + ' out of range [0, ' + (len - 1) + ']');
|
|
||||||
}
|
|
||||||
if (to < 0 || to >= len) {
|
|
||||||
throw new RangeError('movePrimitive: toIndex ' + toIndex + ' out of range [0, ' + (len - 1) + ']');
|
|
||||||
}
|
|
||||||
|
|
||||||
const [prim] = this._primitives.splice(from, 1);
|
|
||||||
const [state] = this._primitiveStates.splice(from, 1);
|
|
||||||
this._primitives.splice(to, 0, prim);
|
|
||||||
this._primitiveStates.splice(to, 0, state);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the current list of primitives (shallow copy).
|
|
||||||
* @returns {Array<import('./primitive.js').Primitive>}
|
|
||||||
*/
|
|
||||||
getPrimitives() {
|
|
||||||
return this._primitives.slice();
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── Configuration ───────────────────────────────────────────────
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Total parameter count across all primitives in the chain.
|
|
||||||
* @returns {number}
|
|
||||||
*/
|
|
||||||
get totalParamCount() {
|
|
||||||
let total = 0;
|
|
||||||
for (let i = 0; i < this._primitives.length; i++) {
|
|
||||||
total += this._primitives[i].paramCount;
|
|
||||||
}
|
|
||||||
return total;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a flat list of all param schemas across all primitives,
|
|
||||||
* annotated with their primitive and param indices.
|
|
||||||
*
|
|
||||||
* @returns {Array<{ primitiveIndex: number, paramIndex: number, schema: Object }>}
|
|
||||||
*/
|
|
||||||
getParamSchemas() {
|
|
||||||
const result = [];
|
|
||||||
for (let pi = 0; pi < this._primitives.length; pi++) {
|
|
||||||
const prim = this._primitives[pi];
|
|
||||||
const schema = prim.paramSchema;
|
|
||||||
for (let si = 0; si < schema.length; si++) {
|
|
||||||
result.push({
|
|
||||||
primitiveIndex: pi,
|
|
||||||
paramIndex: si,
|
|
||||||
schema: schema[si],
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── Evaluation ──────────────────────────────────────────────────
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Evaluate the chain, producing a pattern description.
|
|
||||||
*
|
|
||||||
* Pipeline order:
|
|
||||||
* 1. Generators — combined via generatorCombineMode
|
|
||||||
* 2. Processors — sequential transform
|
|
||||||
* 3. Converters — sequential transform
|
|
||||||
* 4. Timing modifiers — annotate last
|
|
||||||
*
|
|
||||||
* @param {Float32Array|Array<number>} params - flat param array distributed across primitives
|
|
||||||
* @param {number} stepCount - number of steps in the output pattern
|
|
||||||
* @param {number} masterSeed - seed for the master PRNG
|
|
||||||
* @returns {{ steps: Array, stepCount: number, metadata: Object }}
|
|
||||||
*/
|
|
||||||
evaluate(params, stepCount, masterSeed) {
|
|
||||||
const primitives = this._primitives;
|
|
||||||
const primCount = primitives.length;
|
|
||||||
|
|
||||||
// Create master PRNG from seed
|
|
||||||
const masterPRNG = createPRNG(masterSeed >>> 0);
|
|
||||||
|
|
||||||
// ── Bucket primitives by category, preserving chain order ──
|
|
||||||
|
|
||||||
/** @type {Array<{ index: number, prim: Object }>} */
|
|
||||||
const generators = [];
|
|
||||||
const processors = [];
|
|
||||||
const converters = [];
|
|
||||||
const timingMods = [];
|
|
||||||
|
|
||||||
for (let i = 0; i < primCount; i++) {
|
|
||||||
const entry = { index: i, prim: primitives[i] };
|
|
||||||
switch (primitives[i].category) {
|
|
||||||
case 'generator': generators.push(entry); break;
|
|
||||||
case 'processor': processors.push(entry); break;
|
|
||||||
case 'converter': converters.push(entry); break;
|
|
||||||
case 'timing': timingMods.push(entry); break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── Compute param offsets per primitive ──
|
|
||||||
|
|
||||||
const paramOffsets = new Array(primCount);
|
|
||||||
let offset = 0;
|
|
||||||
for (let i = 0; i < primCount; i++) {
|
|
||||||
paramOffsets[i] = offset;
|
|
||||||
offset += primitives[i].paramCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── Helper: run a single primitive ──
|
|
||||||
|
|
||||||
const self = this;
|
|
||||||
|
|
||||||
function runPrimitive(entry, inputPattern) {
|
|
||||||
const idx = entry.index;
|
|
||||||
const prim = entry.prim;
|
|
||||||
const pOffset = paramOffsets[idx];
|
|
||||||
const pCount = prim.paramCount;
|
|
||||||
|
|
||||||
// Slice params for this primitive
|
|
||||||
const primParams = new Float32Array(pCount);
|
|
||||||
for (let p = 0; p < pCount; p++) {
|
|
||||||
primParams[p] = pOffset + p < params.length ? +params[pOffset + p] : prim.paramSchema[p].default;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fork a deterministic PRNG for this primitive
|
|
||||||
const primRNG = fork(masterPRNG, idx);
|
|
||||||
|
|
||||||
// Get current state
|
|
||||||
const state = self._primitiveStates[idx] || prim.getState();
|
|
||||||
|
|
||||||
// Process
|
|
||||||
const result = prim.process(primParams, inputPattern, state, primRNG);
|
|
||||||
|
|
||||||
// Store updated state
|
|
||||||
self._primitiveStates[idx] = result.nextState;
|
|
||||||
|
|
||||||
return result.patternDesc;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── Phase 1: Generators ──
|
|
||||||
|
|
||||||
let pattern;
|
|
||||||
|
|
||||||
if (generators.length === 0) {
|
|
||||||
// Default pattern: all steps triggered
|
|
||||||
pattern = createPattern(stepCount);
|
|
||||||
for (let i = 0; i < stepCount; i++) {
|
|
||||||
pattern.steps[i].trigger = true;
|
|
||||||
}
|
|
||||||
} else if (generators.length === 1) {
|
|
||||||
// Single generator — no merge needed
|
|
||||||
pattern = runPrimitive(generators[0], createPattern(stepCount));
|
|
||||||
} else {
|
|
||||||
// Multiple generators — run each, then merge
|
|
||||||
let merged = runPrimitive(generators[0], createPattern(stepCount));
|
|
||||||
for (let g = 1; g < generators.length; g++) {
|
|
||||||
const next = runPrimitive(generators[g], createPattern(stepCount));
|
|
||||||
merged = mergePatterns(merged, next, this.generatorCombineMode);
|
|
||||||
}
|
|
||||||
pattern = merged;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── Phase 2: Processors ──
|
|
||||||
|
|
||||||
for (let i = 0; i < processors.length; i++) {
|
|
||||||
pattern = runPrimitive(processors[i], pattern);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── Phase 3: Converters ──
|
|
||||||
|
|
||||||
for (let i = 0; i < converters.length; i++) {
|
|
||||||
pattern = runPrimitive(converters[i], pattern);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── Phase 4: Timing modifiers ──
|
|
||||||
|
|
||||||
for (let i = 0; i < timingMods.length; i++) {
|
|
||||||
pattern = runPrimitive(timingMods[i], pattern);
|
|
||||||
}
|
|
||||||
|
|
||||||
return pattern;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── State management (for freeze) ──────────────────────────────
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get serializable state for all primitives in the chain.
|
|
||||||
* @returns {Array<Object>}
|
|
||||||
*/
|
|
||||||
getState() {
|
|
||||||
const states = new Array(this._primitives.length);
|
|
||||||
for (let i = 0; i < this._primitives.length; i++) {
|
|
||||||
states[i] = this._primitiveStates[i] || this._primitives[i].getState();
|
|
||||||
}
|
|
||||||
return states;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Restore all primitive states from a previously serialized state array.
|
|
||||||
* @param {Array<Object>} states
|
|
||||||
*/
|
|
||||||
setState(states) {
|
|
||||||
if (!Array.isArray(states)) {
|
|
||||||
throw new TypeError('setState expects an array of state objects');
|
|
||||||
}
|
|
||||||
const len = Math.min(states.length, this._primitives.length);
|
|
||||||
for (let i = 0; i < len; i++) {
|
|
||||||
this._primitives[i].setState(states[i]);
|
|
||||||
this._primitiveStates[i] = states[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the master PRNG seed.
|
|
||||||
* @returns {number}
|
|
||||||
*/
|
|
||||||
getMasterSeed() {
|
|
||||||
return this._masterSeed;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the master PRNG seed.
|
|
||||||
* @param {number} seed - 32-bit integer seed
|
|
||||||
*/
|
|
||||||
setMasterSeed(seed) {
|
|
||||||
this._masterSeed = seed >>> 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,246 +0,0 @@
|
||||||
/**
|
|
||||||
* ShapeSeq Primitive Base Class and Param Schema System
|
|
||||||
*
|
|
||||||
* Base class for all sequencing primitives (generators, processors,
|
|
||||||
* timing modifiers, converters). Defines the param schema format,
|
|
||||||
* symbolic process() interface, and state management for freeze support.
|
|
||||||
*
|
|
||||||
* Port-ready: explicit state, no closures, typed arrays where possible.
|
|
||||||
*
|
|
||||||
* @module shapeseq/primitive
|
|
||||||
*/
|
|
||||||
|
|
||||||
// ── Valid primitive categories ──────────────────────────────────────
|
|
||||||
|
|
||||||
export const CATEGORIES = Object.freeze([
|
|
||||||
'generator',
|
|
||||||
'processor',
|
|
||||||
'timing',
|
|
||||||
'converter',
|
|
||||||
]);
|
|
||||||
|
|
||||||
// ── Param schema defaults ───────────────────────────────────────────
|
|
||||||
|
|
||||||
const DEFAULT_SCALED_RANGE = 0.3;
|
|
||||||
|
|
||||||
// ── Boundary enforcement helpers ────────────────────────────────────
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Clamp a value to [0, 1].
|
|
||||||
* @param {number} v
|
|
||||||
* @returns {number}
|
|
||||||
*/
|
|
||||||
function clamp01(v) {
|
|
||||||
return v < 0 ? 0 : v > 1 ? 1 : v;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Wrap a value into [0, 1) with modular arithmetic.
|
|
||||||
* @param {number} v
|
|
||||||
* @returns {number}
|
|
||||||
*/
|
|
||||||
function wrap01(v) {
|
|
||||||
const m = v % 1;
|
|
||||||
return m < 0 ? m + 1 : m;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Apply boundary enforcement to a raw param value.
|
|
||||||
*
|
|
||||||
* @param {number} value - raw [0,1] value (or delta-adjusted value)
|
|
||||||
* @param {{ boundary: string, scaledRange?: number }} schema - param schema entry
|
|
||||||
* @param {number|null} frozenValue - frozen value for 'scaled' boundary (null if not frozen)
|
|
||||||
* @returns {number}
|
|
||||||
*/
|
|
||||||
export function applyBoundary(value, schema, frozenValue) {
|
|
||||||
switch (schema.boundary) {
|
|
||||||
case 'wrap':
|
|
||||||
return wrap01(value);
|
|
||||||
case 'scaled': {
|
|
||||||
if (frozenValue === null || frozenValue === undefined) {
|
|
||||||
return clamp01(value);
|
|
||||||
}
|
|
||||||
const range = schema.scaledRange !== undefined ? schema.scaledRange : DEFAULT_SCALED_RANGE;
|
|
||||||
const lo = frozenValue - range;
|
|
||||||
const hi = frozenValue + range;
|
|
||||||
// Map [0,1] input to [lo, hi], then clamp to [0,1]
|
|
||||||
const mapped = lo + value * (hi - lo);
|
|
||||||
return clamp01(mapped);
|
|
||||||
}
|
|
||||||
case 'clamp':
|
|
||||||
default:
|
|
||||||
return clamp01(value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── Param schema validation ─────────────────────────────────────────
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Validate a single param schema entry.
|
|
||||||
* Throws on invalid entries for fast fail during development.
|
|
||||||
*
|
|
||||||
* @param {{ name: string, default: number, boundary: string, scaledRange?: number }} entry
|
|
||||||
* @param {number} index - position in schema array (for error messages)
|
|
||||||
*/
|
|
||||||
function validateSchemaEntry(entry, index) {
|
|
||||||
if (!entry || typeof entry !== 'object') {
|
|
||||||
throw new TypeError('paramSchema[' + index + '] must be an object');
|
|
||||||
}
|
|
||||||
if (typeof entry.name !== 'string' || entry.name.length === 0) {
|
|
||||||
throw new TypeError('paramSchema[' + index + '].name must be a non-empty string');
|
|
||||||
}
|
|
||||||
if (typeof entry.default !== 'number' || entry.default < 0 || entry.default > 1) {
|
|
||||||
throw new RangeError('paramSchema[' + index + '].default must be in [0,1], got ' + entry.default);
|
|
||||||
}
|
|
||||||
if (entry.boundary !== 'clamp' && entry.boundary !== 'wrap' && entry.boundary !== 'scaled') {
|
|
||||||
throw new TypeError(
|
|
||||||
"paramSchema[" + index + "].boundary must be 'clamp', 'wrap', or 'scaled', got '" + entry.boundary + "'"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (entry.boundary === 'scaled') {
|
|
||||||
const sr = entry.scaledRange;
|
|
||||||
if (sr !== undefined && (typeof sr !== 'number' || sr <= 0 || sr > 1)) {
|
|
||||||
throw new RangeError('paramSchema[' + index + '].scaledRange must be in (0,1], got ' + sr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── Primitive base class ────────────────────────────────────────────
|
|
||||||
|
|
||||||
export class Primitive {
|
|
||||||
/**
|
|
||||||
* @param {string} name - unique identifier for this primitive type
|
|
||||||
* @param {string} category - one of CATEGORIES
|
|
||||||
* @param {Array<{ name: string, default: number, boundary: string, scaledRange?: number }>} paramSchema
|
|
||||||
*/
|
|
||||||
constructor(name, category, paramSchema) {
|
|
||||||
if (typeof name !== 'string' || name.length === 0) {
|
|
||||||
throw new TypeError('Primitive name must be a non-empty string');
|
|
||||||
}
|
|
||||||
if (CATEGORIES.indexOf(category) === -1) {
|
|
||||||
throw new TypeError(
|
|
||||||
"Primitive category must be one of [" + CATEGORIES.join(', ') + "], got '" + category + "'"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (!Array.isArray(paramSchema)) {
|
|
||||||
throw new TypeError('paramSchema must be an array');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Validate each entry
|
|
||||||
for (let i = 0; i < paramSchema.length; i++) {
|
|
||||||
validateSchemaEntry(paramSchema[i], i);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @type {string} */
|
|
||||||
this.name = name;
|
|
||||||
|
|
||||||
/** @type {string} */
|
|
||||||
this.category = category;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Frozen copy of the param schema. Each entry:
|
|
||||||
* { name: string, default: number, boundary: 'clamp'|'wrap'|'scaled', scaledRange?: number }
|
|
||||||
* @type {Array<Object>}
|
|
||||||
*/
|
|
||||||
this.paramSchema = Object.freeze(paramSchema.map(function (entry) {
|
|
||||||
const frozen = {
|
|
||||||
name: entry.name,
|
|
||||||
default: entry.default,
|
|
||||||
boundary: entry.boundary,
|
|
||||||
};
|
|
||||||
if (entry.boundary === 'scaled') {
|
|
||||||
frozen.scaledRange = entry.scaledRange !== undefined ? entry.scaledRange : DEFAULT_SCALED_RANGE;
|
|
||||||
}
|
|
||||||
return Object.freeze(frozen);
|
|
||||||
}));
|
|
||||||
|
|
||||||
/** @private */
|
|
||||||
this._seed = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── Param utilities ─────────────────────────────────────────────
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Total number of parameters this primitive exposes.
|
|
||||||
* @returns {number}
|
|
||||||
*/
|
|
||||||
get paramCount() {
|
|
||||||
return this.paramSchema.length;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get default param values as a Float32Array, one per schema entry.
|
|
||||||
* @returns {Float32Array}
|
|
||||||
*/
|
|
||||||
getDefaults() {
|
|
||||||
const count = this.paramSchema.length;
|
|
||||||
const defaults = new Float32Array(count);
|
|
||||||
for (let i = 0; i < count; i++) {
|
|
||||||
defaults[i] = this.paramSchema[i].default;
|
|
||||||
}
|
|
||||||
return defaults;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── Symbolic processing ─────────────────────────────────────────
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Transform a pattern description. Subclasses MUST override this.
|
|
||||||
*
|
|
||||||
* - Generators ignore patternDesc and create a new one (using createPattern())
|
|
||||||
* - Processors/timing modifiers clone and transform patternDesc
|
|
||||||
* - The rng param is a PRNG state from prng.js; consume via next(rng)
|
|
||||||
* and return the consumed state in the result
|
|
||||||
*
|
|
||||||
* @param {Float32Array|Array<number>} params - param values, one per schema entry, each [0,1]
|
|
||||||
* @param {{ steps: Array, stepCount: number, metadata: Object }} patternDesc - input pattern
|
|
||||||
* @param {Object} state - primitive-specific state (from previous process() call or getState())
|
|
||||||
* @param {{ state: number }} rng - PRNG state object from prng.js
|
|
||||||
* @returns {{ patternDesc: { steps: Array, stepCount: number, metadata: Object }, nextState: Object }}
|
|
||||||
*/
|
|
||||||
process(params, patternDesc, state, rng) {
|
|
||||||
void params; void patternDesc; void state; void rng;
|
|
||||||
throw new Error(this.name + '.process() must be overridden by subclass');
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── State management (for freeze) ──────────────────────────────
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get serializable state for this primitive.
|
|
||||||
* Stateless primitives return {}. Stateful primitives (e.g. Pitch Walker)
|
|
||||||
* override to include their internal state.
|
|
||||||
*
|
|
||||||
* @returns {Object}
|
|
||||||
*/
|
|
||||||
getState() {
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Restore primitive state from a previously serialized state object.
|
|
||||||
* Stateless primitives are a no-op. Stateful primitives override.
|
|
||||||
*
|
|
||||||
* @param {Object} _state
|
|
||||||
*/
|
|
||||||
setState(_state) {
|
|
||||||
// no-op for stateless primitives
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the PRNG seed associated with this primitive.
|
|
||||||
* Used by freeze-as-algorithm to replay identical sequences.
|
|
||||||
*
|
|
||||||
* @returns {number}
|
|
||||||
*/
|
|
||||||
getSeed() {
|
|
||||||
return this._seed;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the PRNG seed for this primitive.
|
|
||||||
*
|
|
||||||
* @param {number} seed - 32-bit integer seed
|
|
||||||
*/
|
|
||||||
setSeed(seed) {
|
|
||||||
this._seed = seed >>> 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,505 +0,0 @@
|
||||||
/**
|
|
||||||
* ShapeSeq Sequencing Primitives
|
|
||||||
*
|
|
||||||
* All 8 primitives for the ShapeSeq generative sequencing system.
|
|
||||||
* Each extends Primitive and implements process(params, patternDesc, state, rng).
|
|
||||||
*
|
|
||||||
* Port-ready: explicit state, no closures, seeded PRNG, typed arrays.
|
|
||||||
*
|
|
||||||
* @module shapeseq/primitives
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { Primitive } from './primitive.js';
|
|
||||||
import { createPattern, clonePattern, setStep } from './pattern.js';
|
|
||||||
import { next, nextInt } from './prng.js';
|
|
||||||
|
|
||||||
// ── Helper: map [0,1] float to integer range [lo, hi] ──────────────
|
|
||||||
|
|
||||||
function mapToInt(value, lo, hi) {
|
|
||||||
const clamped = value < 0 ? 0 : value > 1 ? 1 : value;
|
|
||||||
return lo + Math.floor(clamped * (hi - lo + 1 - 1e-9));
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── 1. EuclideanRhythm ──────────────────────────────────────────────
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Bjorklund algorithm: distribute `pulses` as evenly as possible
|
|
||||||
* across `steps`, then apply rotation.
|
|
||||||
*/
|
|
||||||
function bjorklund(steps, pulses) {
|
|
||||||
if (pulses >= steps) {
|
|
||||||
const result = new Array(steps);
|
|
||||||
for (let i = 0; i < steps; i++) result[i] = true;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
if (pulses <= 0) {
|
|
||||||
const result = new Array(steps);
|
|
||||||
for (let i = 0; i < steps; i++) result[i] = false;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Build pattern using Bjorklund's algorithm
|
|
||||||
let groups = [];
|
|
||||||
for (let i = 0; i < pulses; i++) groups.push([true]);
|
|
||||||
for (let i = 0; i < steps - pulses; i++) groups.push([false]);
|
|
||||||
|
|
||||||
while (true) {
|
|
||||||
const remainder = groups.length - pulses;
|
|
||||||
if (remainder <= 1) break;
|
|
||||||
const minLen = Math.min(pulses, remainder);
|
|
||||||
const newGroups = [];
|
|
||||||
for (let i = 0; i < minLen; i++) {
|
|
||||||
newGroups.push(groups[i].concat(groups[groups.length - 1 - i]));
|
|
||||||
}
|
|
||||||
// Keep any leftovers
|
|
||||||
const leftStart = minLen;
|
|
||||||
const leftEnd = groups.length - minLen;
|
|
||||||
for (let i = leftStart; i < leftEnd; i++) {
|
|
||||||
newGroups.push(groups[i]);
|
|
||||||
}
|
|
||||||
groups = newGroups;
|
|
||||||
pulses = minLen;
|
|
||||||
if (pulses <= 1) break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Flatten groups
|
|
||||||
const result = [];
|
|
||||||
for (let i = 0; i < groups.length; i++) {
|
|
||||||
for (let j = 0; j < groups[i].length; j++) {
|
|
||||||
result.push(groups[i][j]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class EuclideanRhythm extends Primitive {
|
|
||||||
constructor() {
|
|
||||||
super('EuclideanRhythm', 'generator', [
|
|
||||||
{ name: 'steps', default: 0.5, boundary: 'clamp' },
|
|
||||||
{ name: 'pulses', default: 0.5, boundary: 'clamp' },
|
|
||||||
{ name: 'rotation', default: 0.0, boundary: 'wrap' },
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
process(params, patternDesc, state, rng) {
|
|
||||||
const stepCount = patternDesc.stepCount;
|
|
||||||
const steps = mapToInt(params[0], 2, stepCount);
|
|
||||||
const pulses = mapToInt(params[1], 0, steps);
|
|
||||||
const rotation = mapToInt(params[2], 0, steps - 1);
|
|
||||||
|
|
||||||
const rhythm = bjorklund(steps, pulses);
|
|
||||||
const pattern = createPattern(stepCount);
|
|
||||||
|
|
||||||
for (let i = 0; i < stepCount; i++) {
|
|
||||||
if (i < steps) {
|
|
||||||
const srcIdx = (i - rotation + steps) % steps;
|
|
||||||
if (rhythm[srcIdx]) {
|
|
||||||
setStep(pattern, i, { trigger: true });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Steps beyond `steps` remain untriggered (default)
|
|
||||||
}
|
|
||||||
|
|
||||||
return { patternDesc: pattern, nextState: {} };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── 2. ProbabilityGate ──────────────────────────────────────────────
|
|
||||||
|
|
||||||
export class ProbabilityGate extends Primitive {
|
|
||||||
constructor() {
|
|
||||||
super('ProbabilityGate', 'processor', [
|
|
||||||
{ name: 'density', default: 0.7, boundary: 'clamp' },
|
|
||||||
{ name: 'accentProbability', default: 0.3, boundary: 'clamp' },
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
process(params, patternDesc, state, rng) {
|
|
||||||
const density = params[0];
|
|
||||||
const accentProb = params[1];
|
|
||||||
const pattern = clonePattern(patternDesc);
|
|
||||||
let currentRng = rng;
|
|
||||||
|
|
||||||
for (let i = 0; i < pattern.stepCount; i++) {
|
|
||||||
const step = pattern.steps[i];
|
|
||||||
if (step.trigger) {
|
|
||||||
// Coin flip for survival
|
|
||||||
const r1 = next(currentRng);
|
|
||||||
currentRng = r1.nextState;
|
|
||||||
|
|
||||||
if (r1.value >= density) {
|
|
||||||
step.trigger = false;
|
|
||||||
step.accent = false;
|
|
||||||
} else {
|
|
||||||
// Accent coin flip
|
|
||||||
const r2 = next(currentRng);
|
|
||||||
currentRng = r2.nextState;
|
|
||||||
step.accent = r2.value < accentProb;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return { patternDesc: pattern, nextState: {} };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── 3. PitchWalker ──────────────────────────────────────────────────
|
|
||||||
|
|
||||||
export class PitchWalker extends Primitive {
|
|
||||||
constructor() {
|
|
||||||
super('PitchWalker', 'generator', [
|
|
||||||
{ name: 'stepSize', default: 0.3, boundary: 'clamp' },
|
|
||||||
{ name: 'directionBias', default: 0.5, boundary: 'clamp' },
|
|
||||||
{ name: 'gravity', default: 0.3, boundary: 'clamp' },
|
|
||||||
{ name: 'range', default: 0.8, boundary: 'clamp' },
|
|
||||||
]);
|
|
||||||
|
|
||||||
/** @private */
|
|
||||||
this._position = 0.5;
|
|
||||||
}
|
|
||||||
|
|
||||||
getState() {
|
|
||||||
return { position: this._position };
|
|
||||||
}
|
|
||||||
|
|
||||||
setState(savedState) {
|
|
||||||
if (savedState && typeof savedState.position === 'number') {
|
|
||||||
this._position = savedState.position;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
process(params, patternDesc, state, rng) {
|
|
||||||
const stepSize = params[0];
|
|
||||||
const directionBias = params[1];
|
|
||||||
const gravity = params[2];
|
|
||||||
const range = params[3];
|
|
||||||
|
|
||||||
// Restore position from state if provided
|
|
||||||
let position = (state && typeof state.position === 'number')
|
|
||||||
? state.position
|
|
||||||
: this._position;
|
|
||||||
|
|
||||||
const pattern = createPattern(patternDesc.stepCount);
|
|
||||||
let currentRng = rng;
|
|
||||||
|
|
||||||
// Use incoming pattern's triggers if available, otherwise all triggered
|
|
||||||
const srcSteps = patternDesc.steps;
|
|
||||||
|
|
||||||
for (let i = 0; i < patternDesc.stepCount; i++) {
|
|
||||||
const triggered = srcSteps[i].trigger;
|
|
||||||
|
|
||||||
if (triggered) {
|
|
||||||
// Random walk step
|
|
||||||
const r1 = next(currentRng);
|
|
||||||
currentRng = r1.nextState;
|
|
||||||
|
|
||||||
// Direction: bias + gravity toward center
|
|
||||||
const gravityPull = (0.5 - position) * gravity;
|
|
||||||
const biasOffset = (directionBias - 0.5) * 2; // [-1, 1]
|
|
||||||
const direction = biasOffset + gravityPull;
|
|
||||||
|
|
||||||
// Random component: [-1, 1] scaled by stepSize
|
|
||||||
const randomComponent = (r1.value * 2 - 1) * stepSize * range;
|
|
||||||
const delta = direction * stepSize * 0.5 + randomComponent;
|
|
||||||
|
|
||||||
position = position + delta;
|
|
||||||
// Clamp to [0, 1]
|
|
||||||
if (position < 0) position = 0;
|
|
||||||
if (position > 1) position = 1;
|
|
||||||
|
|
||||||
setStep(pattern, i, { trigger: true, pitch: position });
|
|
||||||
}
|
|
||||||
// Untriggered steps keep default pitch, trigger=false
|
|
||||||
}
|
|
||||||
|
|
||||||
this._position = position;
|
|
||||||
|
|
||||||
return {
|
|
||||||
patternDesc: pattern,
|
|
||||||
nextState: { position: position },
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── 4. Ratchet ──────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
export class Ratchet extends Primitive {
|
|
||||||
constructor() {
|
|
||||||
super('Ratchet', 'timing', [
|
|
||||||
{ name: 'maxDivision', default: 0.5, boundary: 'clamp' },
|
|
||||||
{ name: 'probability', default: 0.5, boundary: 'clamp' },
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
process(params, patternDesc, state, rng) {
|
|
||||||
const maxDiv = mapToInt(params[0], 1, 4);
|
|
||||||
const probability = params[1];
|
|
||||||
const pattern = clonePattern(patternDesc);
|
|
||||||
let currentRng = rng;
|
|
||||||
|
|
||||||
for (let i = 0; i < pattern.stepCount; i++) {
|
|
||||||
const step = pattern.steps[i];
|
|
||||||
if (step.trigger) {
|
|
||||||
const r1 = next(currentRng);
|
|
||||||
currentRng = r1.nextState;
|
|
||||||
|
|
||||||
if (r1.value < probability && maxDiv > 1) {
|
|
||||||
// Pick a subdivision count in [2, maxDiv]
|
|
||||||
const r2 = nextInt(currentRng, 2, maxDiv);
|
|
||||||
currentRng = r2.nextState;
|
|
||||||
step.subdivisions = r2.value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return { patternDesc: pattern, nextState: {} };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── 5. SwingGroove ──────────────────────────────────────────────────
|
|
||||||
|
|
||||||
export class SwingGroove extends Primitive {
|
|
||||||
constructor() {
|
|
||||||
super('SwingGroove', 'timing', [
|
|
||||||
{ name: 'swingAmount', default: 0.0, boundary: 'clamp' },
|
|
||||||
{ name: 'swingGrid', default: 0.0, boundary: 'clamp' },
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
process(params, patternDesc, state, rng) {
|
|
||||||
const swingAmount = params[0];
|
|
||||||
const pattern = clonePattern(patternDesc);
|
|
||||||
|
|
||||||
// Max swing = 0.33 (triplet feel)
|
|
||||||
const maxOffset = 0.33;
|
|
||||||
const offset = swingAmount * maxOffset;
|
|
||||||
|
|
||||||
// Apply swing to every other step (odd-indexed steps)
|
|
||||||
for (let i = 1; i < pattern.stepCount; i += 2) {
|
|
||||||
pattern.steps[i].timeOffset = offset;
|
|
||||||
}
|
|
||||||
|
|
||||||
return { patternDesc: pattern, nextState: {} };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── 6. DensityMorph ─────────────────────────────────────────────────
|
|
||||||
|
|
||||||
export class DensityMorph extends Primitive {
|
|
||||||
constructor() {
|
|
||||||
super('DensityMorph', 'generator', [
|
|
||||||
{ name: 'density', default: 0.5, boundary: 'clamp' },
|
|
||||||
{ name: 'clustering', default: 0.0, boundary: 'clamp' },
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
process(params, patternDesc, state, rng) {
|
|
||||||
const density = params[0];
|
|
||||||
const clustering = params[1];
|
|
||||||
const stepCount = patternDesc.stepCount;
|
|
||||||
const pattern = createPattern(stepCount);
|
|
||||||
const numTriggers = Math.floor(density * stepCount);
|
|
||||||
|
|
||||||
if (numTriggers <= 0) {
|
|
||||||
return { patternDesc: pattern, nextState: {} };
|
|
||||||
}
|
|
||||||
if (numTriggers >= stepCount) {
|
|
||||||
for (let i = 0; i < stepCount; i++) {
|
|
||||||
setStep(pattern, i, { trigger: true });
|
|
||||||
}
|
|
||||||
return { patternDesc: pattern, nextState: {} };
|
|
||||||
}
|
|
||||||
|
|
||||||
let currentRng = rng;
|
|
||||||
|
|
||||||
if (clustering < 0.01) {
|
|
||||||
// Even spread: Euclidean-like placement
|
|
||||||
for (let i = 0; i < numTriggers; i++) {
|
|
||||||
const idx = Math.floor((i * stepCount) / numTriggers);
|
|
||||||
setStep(pattern, idx, { trigger: true });
|
|
||||||
}
|
|
||||||
} else if (clustering > 0.99) {
|
|
||||||
// Full clustering: contiguous burst
|
|
||||||
const r1 = nextInt(currentRng, 0, stepCount - 1);
|
|
||||||
currentRng = r1.nextState;
|
|
||||||
const startPos = r1.value;
|
|
||||||
for (let i = 0; i < numTriggers; i++) {
|
|
||||||
const idx = (startPos + i) % stepCount;
|
|
||||||
setStep(pattern, idx, { trigger: true });
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Interpolate: place triggers with clustering-dependent spread
|
|
||||||
// Use a "center of mass" approach:
|
|
||||||
// Pick a random center, then distribute triggers around it
|
|
||||||
// with spread inversely proportional to clustering
|
|
||||||
const r1 = next(currentRng);
|
|
||||||
currentRng = r1.nextState;
|
|
||||||
const center = r1.value * stepCount;
|
|
||||||
|
|
||||||
// Spread factor: low clustering = large spread, high = tight
|
|
||||||
const spreadRadius = (1 - clustering) * stepCount * 0.5;
|
|
||||||
|
|
||||||
// Score each step by distance from center (wrapping)
|
|
||||||
const scores = new Float32Array(stepCount);
|
|
||||||
for (let i = 0; i < stepCount; i++) {
|
|
||||||
// Wrapped distance from center
|
|
||||||
let dist = Math.abs(i - center);
|
|
||||||
if (dist > stepCount * 0.5) dist = stepCount - dist;
|
|
||||||
// Add small random jitter to break ties
|
|
||||||
const r2 = next(currentRng);
|
|
||||||
currentRng = r2.nextState;
|
|
||||||
scores[i] = dist / (spreadRadius + 0.001) + r2.value * 0.01;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Select the numTriggers steps with lowest scores
|
|
||||||
const indices = new Array(stepCount);
|
|
||||||
for (let i = 0; i < stepCount; i++) indices[i] = i;
|
|
||||||
indices.sort(function (a, b) { return scores[a] - scores[b]; });
|
|
||||||
|
|
||||||
for (let i = 0; i < numTriggers; i++) {
|
|
||||||
setStep(pattern, indices[i], { trigger: true });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return { patternDesc: pattern, nextState: {} };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── 7. IntervalLock ─────────────────────────────────────────────────
|
|
||||||
|
|
||||||
const SCALES = [
|
|
||||||
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], // chromatic
|
|
||||||
[0, 2, 4, 5, 7, 9, 11], // major
|
|
||||||
[0, 2, 3, 5, 7, 8, 10], // natural minor
|
|
||||||
[0, 2, 3, 5, 7, 8, 11], // harmonic minor
|
|
||||||
[0, 2, 4, 7, 9], // pentatonic major
|
|
||||||
[0, 3, 5, 7, 10], // pentatonic minor
|
|
||||||
[0, 3, 5, 6, 7, 10], // blues
|
|
||||||
[0, 2, 3, 5, 7, 9, 10], // dorian
|
|
||||||
[0, 2, 4, 5, 7, 9, 10], // mixolydian
|
|
||||||
[0, 2, 4, 6, 8, 10], // whole tone
|
|
||||||
[0, 2, 3, 5, 6, 8, 9, 11], // diminished
|
|
||||||
];
|
|
||||||
|
|
||||||
export class IntervalLock extends Primitive {
|
|
||||||
constructor() {
|
|
||||||
super('IntervalLock', 'converter', [
|
|
||||||
{ name: 'root', default: 0.0, boundary: 'clamp' },
|
|
||||||
{ name: 'mode', default: 0.0, boundary: 'clamp' },
|
|
||||||
{ name: 'octaveRange', default: 0.25, boundary: 'clamp' },
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
process(params, patternDesc, state, rng) {
|
|
||||||
const root = mapToInt(params[0], 0, 11);
|
|
||||||
const scaleIdx = mapToInt(params[1], 0, SCALES.length - 1);
|
|
||||||
const octaveRange = mapToInt(params[2], 1, 4);
|
|
||||||
const scale = SCALES[scaleIdx];
|
|
||||||
|
|
||||||
const pattern = clonePattern(patternDesc);
|
|
||||||
|
|
||||||
// Build the full set of MIDI notes in this scale + root + range
|
|
||||||
const notes = [];
|
|
||||||
for (let oct = 0; oct < octaveRange; oct++) {
|
|
||||||
for (let i = 0; i < scale.length; i++) {
|
|
||||||
const midiNote = root + scale[i] + oct * 12;
|
|
||||||
if (midiNote <= 127) {
|
|
||||||
notes.push(midiNote);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (notes.length === 0) {
|
|
||||||
return { patternDesc: pattern, nextState: {} };
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let i = 0; i < pattern.stepCount; i++) {
|
|
||||||
const step = pattern.steps[i];
|
|
||||||
// Quantize pitch [0,1] to nearest note in our scale
|
|
||||||
const targetIdx = Math.round(step.pitch * (notes.length - 1));
|
|
||||||
const clampedIdx = targetIdx < 0 ? 0 : targetIdx >= notes.length ? notes.length - 1 : targetIdx;
|
|
||||||
// Store as MIDI note / 127 to stay in [0,1]
|
|
||||||
step.pitch = notes[clampedIdx] / 127;
|
|
||||||
}
|
|
||||||
|
|
||||||
return { patternDesc: pattern, nextState: {} };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── 8. VelocityShaper ───────────────────────────────────────────────
|
|
||||||
|
|
||||||
export class VelocityShaper extends Primitive {
|
|
||||||
constructor() {
|
|
||||||
super('VelocityShaper', 'processor', [
|
|
||||||
{ name: 'curveType', default: 0.0, boundary: 'clamp' },
|
|
||||||
{ name: 'depth', default: 0.5, boundary: 'clamp' },
|
|
||||||
{ name: 'phase', default: 0.0, boundary: 'wrap' },
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
process(params, patternDesc, state, rng) {
|
|
||||||
const curveIdx = mapToInt(params[0], 0, 4);
|
|
||||||
const depth = params[1];
|
|
||||||
const phase = params[2];
|
|
||||||
const pattern = clonePattern(patternDesc);
|
|
||||||
const stepCount = pattern.stepCount;
|
|
||||||
let currentRng = rng;
|
|
||||||
|
|
||||||
for (let i = 0; i < stepCount; i++) {
|
|
||||||
const step = pattern.steps[i];
|
|
||||||
if (!step.trigger) continue;
|
|
||||||
|
|
||||||
// Phase-shifted position
|
|
||||||
const pos = ((i / stepCount) + phase) % 1;
|
|
||||||
let shapeValue;
|
|
||||||
|
|
||||||
switch (curveIdx) {
|
|
||||||
case 0: // flat
|
|
||||||
shapeValue = 1.0;
|
|
||||||
break;
|
|
||||||
case 1: // accent-every-N (accent every 4th step)
|
|
||||||
shapeValue = ((i + Math.floor(phase * stepCount)) % 4 === 0) ? 1.0 : 0.5;
|
|
||||||
break;
|
|
||||||
case 2: // crescendo
|
|
||||||
shapeValue = pos;
|
|
||||||
break;
|
|
||||||
case 3: // decrescendo
|
|
||||||
shapeValue = 1.0 - pos;
|
|
||||||
break;
|
|
||||||
case 4: { // random
|
|
||||||
const r1 = next(currentRng);
|
|
||||||
currentRng = r1.nextState;
|
|
||||||
shapeValue = r1.value;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
shapeValue = 1.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Apply depth: interpolate between uniform (1.0) and shaped
|
|
||||||
// depth=0 means all same velocity (base), depth=1 means full shape
|
|
||||||
const baseVelocity = 0.7;
|
|
||||||
const shaped = shapeValue;
|
|
||||||
step.velocity = baseVelocity * (1 - depth) + shaped * depth;
|
|
||||||
|
|
||||||
// Clamp
|
|
||||||
if (step.velocity < 0) step.velocity = 0;
|
|
||||||
if (step.velocity > 1) step.velocity = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return { patternDesc: pattern, nextState: {} };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── Registry ────────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
export const PRIMITIVE_REGISTRY = {
|
|
||||||
EuclideanRhythm: EuclideanRhythm,
|
|
||||||
ProbabilityGate: ProbabilityGate,
|
|
||||||
PitchWalker: PitchWalker,
|
|
||||||
Ratchet: Ratchet,
|
|
||||||
SwingGroove: SwingGroove,
|
|
||||||
DensityMorph: DensityMorph,
|
|
||||||
IntervalLock: IntervalLock,
|
|
||||||
VelocityShaper: VelocityShaper,
|
|
||||||
};
|
|
||||||
|
|
@ -1,304 +0,0 @@
|
||||||
/**
|
|
||||||
* ShapeSeq Engine — central orchestrator
|
|
||||||
*
|
|
||||||
* Wires together the sequence MLP, param mapping, primitive chain,
|
|
||||||
* projection layer, clock engine, and C15 bridge.
|
|
||||||
*
|
|
||||||
* Main loop (triggered by setSequenceInputs):
|
|
||||||
* 1. Forward inputs to sequenceIML
|
|
||||||
* 2. Run MLP inference to get 16 outputs
|
|
||||||
* 3. Map 16 outputs to N primitive params via param-map
|
|
||||||
* 4. Evaluate the chain to produce a pattern description
|
|
||||||
* 5. Apply projection transforms
|
|
||||||
* 6. Schedule the pattern on the clock
|
|
||||||
*
|
|
||||||
* Bridge integration:
|
|
||||||
* - Subscribes to seq.noteOn / seq.noteOff on the event bus
|
|
||||||
* - Forwards to C15Bridge.noteOn / noteOff
|
|
||||||
* - Tracks active notes to avoid orphans
|
|
||||||
*
|
|
||||||
* @module shapeseq/sequencer
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { createSequenceIML, SEQ_N_OUTPUTS } from './seq-iml.js';
|
|
||||||
import { Chain } from './chain.js';
|
|
||||||
import { ClockEngine } from './clock.js';
|
|
||||||
import { map } from './param-map.js';
|
|
||||||
import { createProjectionChain, applyProjection, PRESETS } from './projection.js';
|
|
||||||
import { SEQ } from './event-bus.js';
|
|
||||||
import {
|
|
||||||
EuclideanRhythm,
|
|
||||||
ProbabilityGate,
|
|
||||||
PitchWalker,
|
|
||||||
IntervalLock,
|
|
||||||
VelocityShaper,
|
|
||||||
} from './primitives.js';
|
|
||||||
|
|
||||||
// ── Defaults ─────────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
const DEFAULT_BPM = 120;
|
|
||||||
const DEFAULT_STEP_COUNT = 8;
|
|
||||||
const DEFAULT_MASTER_SEED = 42;
|
|
||||||
const DEFAULT_SPREAD = 0.6;
|
|
||||||
|
|
||||||
// ── ShapeSeqEngine ───────────────────────────────────────────────────
|
|
||||||
|
|
||||||
export class ShapeSeqEngine {
|
|
||||||
/**
|
|
||||||
* @param {{ audioContext: AudioContext, eventBus: import('./event-bus.js').EventBus, c15Bridge: import('../synth/c15-bridge.js').C15Bridge }} opts
|
|
||||||
*/
|
|
||||||
constructor({ audioContext, eventBus, c15Bridge }) {
|
|
||||||
if (!audioContext) throw new TypeError('ShapeSeqEngine requires an audioContext');
|
|
||||||
if (!eventBus) throw new TypeError('ShapeSeqEngine requires an eventBus');
|
|
||||||
if (!c15Bridge) throw new TypeError('ShapeSeqEngine requires a c15Bridge');
|
|
||||||
|
|
||||||
/** @private */ this._audioCtx = audioContext;
|
|
||||||
/** @private */ this._bus = eventBus;
|
|
||||||
/** @private */ this._c15 = c15Bridge;
|
|
||||||
|
|
||||||
/** @private */ this._sequenceIML = null;
|
|
||||||
/** @private */ this._chain = null;
|
|
||||||
/** @private */ this._clock = null;
|
|
||||||
/** @private */ this._projectionChain = null;
|
|
||||||
|
|
||||||
/** @private */ this._stepCount = DEFAULT_STEP_COUNT;
|
|
||||||
/** @private */ this._masterSeed = DEFAULT_MASTER_SEED;
|
|
||||||
/** @private */ this._playing = false;
|
|
||||||
/** @private */ this._initialized = false;
|
|
||||||
|
|
||||||
// Track active notes for orphan prevention
|
|
||||||
/** @private @type {Set<number>} */
|
|
||||||
this._activeNotes = new Set();
|
|
||||||
|
|
||||||
// Bound handlers for event bus (stored for cleanup)
|
|
||||||
/** @private */
|
|
||||||
this._onNoteOn = (data) => this._handleNoteOn(data);
|
|
||||||
/** @private */
|
|
||||||
this._onNoteOff = (data) => this._handleNoteOff(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── Lifecycle ──────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initialize all subsystems: create sequence IML, default chain,
|
|
||||||
* clock, and projection chain. Must be called before start().
|
|
||||||
*/
|
|
||||||
async init() {
|
|
||||||
// 1. Create the sequence MLP
|
|
||||||
this._sequenceIML = await createSequenceIML();
|
|
||||||
|
|
||||||
// Randomize weights with default spread
|
|
||||||
this._sequenceIML.drawWeights(DEFAULT_SPREAD);
|
|
||||||
|
|
||||||
// 2. Create the default primitive chain
|
|
||||||
this._chain = new Chain();
|
|
||||||
this._chain.addPrimitive(new EuclideanRhythm());
|
|
||||||
this._chain.addPrimitive(new ProbabilityGate());
|
|
||||||
this._chain.addPrimitive(new PitchWalker());
|
|
||||||
this._chain.addPrimitive(new IntervalLock());
|
|
||||||
this._chain.addPrimitive(new VelocityShaper());
|
|
||||||
this._chain.setMasterSeed(this._masterSeed);
|
|
||||||
|
|
||||||
// 3. Set up the clock
|
|
||||||
this._clock = new ClockEngine(this._audioCtx, this._bus);
|
|
||||||
this._clock.bpm = DEFAULT_BPM;
|
|
||||||
|
|
||||||
// 4. Create default projection chain (expressive preset)
|
|
||||||
const result = createProjectionChain(PRESETS.expressive);
|
|
||||||
if (!result.valid) {
|
|
||||||
throw new Error('Default projection chain invalid: ' + result.error);
|
|
||||||
}
|
|
||||||
this._projectionChain = result;
|
|
||||||
|
|
||||||
// 5. Subscribe to event bus for C15 bridge integration
|
|
||||||
this._bus.on(SEQ.NOTE_ON, this._onNoteOn);
|
|
||||||
this._bus.on(SEQ.NOTE_OFF, this._onNoteOff);
|
|
||||||
|
|
||||||
this._initialized = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Start the clock. Requires init() to have been called.
|
|
||||||
*/
|
|
||||||
start() {
|
|
||||||
if (!this._initialized) {
|
|
||||||
throw new Error('ShapeSeqEngine.start() called before init()');
|
|
||||||
}
|
|
||||||
if (this._playing) return;
|
|
||||||
|
|
||||||
this._playing = true;
|
|
||||||
this._clock.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Stop the clock and release all active notes.
|
|
||||||
*/
|
|
||||||
stop() {
|
|
||||||
if (!this._playing) return;
|
|
||||||
|
|
||||||
this._playing = false;
|
|
||||||
this._clock.stop();
|
|
||||||
this._releaseAllNotes();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Full cleanup: stop playback, unsubscribe from events, destroy IML.
|
|
||||||
*/
|
|
||||||
destroy() {
|
|
||||||
this.stop();
|
|
||||||
|
|
||||||
// Unsubscribe from event bus
|
|
||||||
this._bus.off(SEQ.NOTE_ON, this._onNoteOn);
|
|
||||||
this._bus.off(SEQ.NOTE_OFF, this._onNoteOff);
|
|
||||||
|
|
||||||
// Destroy the sequence IML instance
|
|
||||||
if (this._sequenceIML) {
|
|
||||||
this._sequenceIML.destroy();
|
|
||||||
this._sequenceIML = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
this._chain = null;
|
|
||||||
this._clock = null;
|
|
||||||
this._projectionChain = null;
|
|
||||||
this._initialized = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── Configuration ──────────────────────────────────────────────────
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Update the clock tempo.
|
|
||||||
* @param {number} bpm
|
|
||||||
*/
|
|
||||||
setTempo(bpm) {
|
|
||||||
if (this._clock) {
|
|
||||||
this._clock.setTempo(bpm);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the number of steps in the generated pattern.
|
|
||||||
* @param {number} count
|
|
||||||
*/
|
|
||||||
setStepCount(count) {
|
|
||||||
const c = Math.max(1, count | 0);
|
|
||||||
this._stepCount = c;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the projection preset by name.
|
|
||||||
* @param {'expressive'|'percussive'|'fullRange'} presetName
|
|
||||||
*/
|
|
||||||
setProjectionPreset(presetName) {
|
|
||||||
const preset = PRESETS[presetName];
|
|
||||||
if (!preset) {
|
|
||||||
throw new Error('Unknown projection preset: ' + presetName);
|
|
||||||
}
|
|
||||||
const result = createProjectionChain(preset);
|
|
||||||
if (!result.valid) {
|
|
||||||
throw new Error('Projection chain invalid: ' + result.error);
|
|
||||||
}
|
|
||||||
this._projectionChain = result;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── Chain access (for UI binding) ──────────────────────────────────
|
|
||||||
|
|
||||||
/** @returns {Chain} */
|
|
||||||
getChain() { return this._chain; }
|
|
||||||
|
|
||||||
/** @returns {ClockEngine} */
|
|
||||||
getClock() { return this._clock; }
|
|
||||||
|
|
||||||
/** @returns {WasmIML} */
|
|
||||||
getSequenceIML() { return this._sequenceIML; }
|
|
||||||
|
|
||||||
// ── Input routing ──────────────────────────────────────────────────
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Feed new input values to the sequence MLP and run the full pipeline:
|
|
||||||
* MLP inference -> param mapping -> chain evaluation -> projection -> clock scheduling.
|
|
||||||
*
|
|
||||||
* Call this each frame with the routed input values (e.g., [x, y]).
|
|
||||||
*
|
|
||||||
* @param {number[]} values - input array (typically [x, y])
|
|
||||||
*/
|
|
||||||
setSequenceInputs(values) {
|
|
||||||
if (!this._initialized || !this._sequenceIML) return;
|
|
||||||
|
|
||||||
// 1. Forward inputs to the sequence IML
|
|
||||||
this._sequenceIML.setInputs(values);
|
|
||||||
|
|
||||||
// 2. Run MLP inference
|
|
||||||
this._sequenceIML.process();
|
|
||||||
|
|
||||||
// 3. Get the 16 MLP outputs
|
|
||||||
const mlpOutputs = this._sequenceIML.getOutputs();
|
|
||||||
|
|
||||||
// 4. Map 16 outputs to N primitive params
|
|
||||||
const paramCount = this._chain.totalParamCount;
|
|
||||||
const mappedParams = map(mlpOutputs, paramCount);
|
|
||||||
|
|
||||||
// 5. Evaluate the chain to produce a pattern description
|
|
||||||
const patternDesc = this._chain.evaluate(mappedParams, this._stepCount, this._masterSeed);
|
|
||||||
|
|
||||||
// 6. Apply projection transforms
|
|
||||||
const projectedPattern = applyProjection(this._projectionChain, patternDesc);
|
|
||||||
|
|
||||||
// 7. Schedule the pattern on the clock
|
|
||||||
this._clock.schedulePattern(projectedPattern);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── ML control ─────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
/** @returns {boolean} */
|
|
||||||
get isPlaying() {
|
|
||||||
return this._playing;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── Bridge integration (private) ───────────────────────────────────
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handle seq.noteOn events from the event bus.
|
|
||||||
* Converts [0,1] pitch to MIDI note number and forwards to C15.
|
|
||||||
*
|
|
||||||
* @private
|
|
||||||
* @param {Object} data - { pitch, velocity, stepIndex, time, accent, isSubdivision }
|
|
||||||
*/
|
|
||||||
_handleNoteOn(data) {
|
|
||||||
// pitch comes from the projection layer; after RangeMap it's already
|
|
||||||
// in MIDI note range (e.g., 48-84). Round to nearest integer.
|
|
||||||
const midiNote = Math.round(data.pitch) | 0;
|
|
||||||
const velocity = data.velocity;
|
|
||||||
|
|
||||||
// Clamp to valid MIDI range
|
|
||||||
const note = midiNote < 0 ? 0 : midiNote > 127 ? 127 : midiNote;
|
|
||||||
const vel = velocity < 0 ? 0 : velocity > 1 ? 1 : velocity;
|
|
||||||
|
|
||||||
this._c15.noteOn(note, vel);
|
|
||||||
this._activeNotes.add(note);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handle seq.noteOff events from the event bus.
|
|
||||||
*
|
|
||||||
* @private
|
|
||||||
* @param {Object} data - { pitch, velocity, stepIndex, time }
|
|
||||||
*/
|
|
||||||
_handleNoteOff(data) {
|
|
||||||
const midiNote = Math.round(data.pitch) | 0;
|
|
||||||
const note = midiNote < 0 ? 0 : midiNote > 127 ? 127 : midiNote;
|
|
||||||
|
|
||||||
this._c15.noteOff(note);
|
|
||||||
this._activeNotes.delete(note);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Release all currently active notes to avoid orphaned noteOns.
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
_releaseAllNotes() {
|
|
||||||
for (const note of this._activeNotes) {
|
|
||||||
this._c15.noteOff(note);
|
|
||||||
}
|
|
||||||
this._activeNotes.clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,328 +0,0 @@
|
||||||
/**
|
|
||||||
* ShapeSeq Circular Step Visualizer
|
|
||||||
*
|
|
||||||
* Renders steps arranged in a circle (heptagon, tridecagon, etc.)
|
|
||||||
* with pitch mapped to radial distance, velocity to node size,
|
|
||||||
* and accent to color brightness.
|
|
||||||
*
|
|
||||||
* Designed for 60fps rendering — no allocations in the render loop.
|
|
||||||
* Port-ready: explicit state, no closures in hot paths.
|
|
||||||
*
|
|
||||||
* @module shapeseq/step-viz
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { SEQ } from './event-bus.js';
|
|
||||||
|
|
||||||
// ── Constants (pre-allocated, shared across instances) ──────────────
|
|
||||||
|
|
||||||
const TWO_PI = Math.PI * 2;
|
|
||||||
const HALF_PI = Math.PI * 0.5;
|
|
||||||
|
|
||||||
// Color constants
|
|
||||||
const COLOR_INACTIVE = 'rgba(255, 255, 255, 0.15)';
|
|
||||||
const COLOR_ACTIVE = '#00ccff';
|
|
||||||
const COLOR_CURRENT = '#ff6a00';
|
|
||||||
const COLOR_ACCENT = '#ffcc00';
|
|
||||||
const COLOR_BG = '#0d0d0d';
|
|
||||||
|
|
||||||
// Glow colors (pre-computed rgba strings)
|
|
||||||
const GLOW_ACTIVE = 'rgba(0, 204, 255, 0.3)';
|
|
||||||
const GLOW_CURRENT = 'rgba(255, 106, 0, 0.4)';
|
|
||||||
const GLOW_ACCENT = 'rgba(255, 204, 0, 0.35)';
|
|
||||||
|
|
||||||
// Layout
|
|
||||||
const PADDING_RATIO = 0.08; // canvas padding as fraction of min dimension
|
|
||||||
const OUTER_RADIUS_RATIO = 0.90; // outer ring at 90% of available radius
|
|
||||||
const INNER_RADIUS_RATIO = 0.30; // inner ring at 30% of available radius
|
|
||||||
|
|
||||||
// Node sizing
|
|
||||||
const NODE_MIN_RADIUS = 4;
|
|
||||||
const NODE_MAX_RADIUS = 18;
|
|
||||||
const NODE_OUTLINE_WIDTH = 1.5;
|
|
||||||
|
|
||||||
// Current-step indicator
|
|
||||||
const INDICATOR_EXTRA_RADIUS = 8;
|
|
||||||
const INDICATOR_LINE_WIDTH = 2;
|
|
||||||
|
|
||||||
// Center dot
|
|
||||||
const CENTER_DOT_RADIUS = 3;
|
|
||||||
|
|
||||||
// ── StepVisualizer ──────────────────────────────────────────────────
|
|
||||||
|
|
||||||
export class StepVisualizer {
|
|
||||||
/**
|
|
||||||
* @param {{ canvas: HTMLCanvasElement, eventBus: import('./event-bus.js').EventBus }} opts
|
|
||||||
*/
|
|
||||||
constructor({ canvas, eventBus }) {
|
|
||||||
this._canvas = canvas;
|
|
||||||
this._ctx = canvas.getContext('2d');
|
|
||||||
this._bus = eventBus;
|
|
||||||
|
|
||||||
// State
|
|
||||||
this._pattern = null; // current pattern description
|
|
||||||
this._currentStep = -1; // playback position (-1 = none)
|
|
||||||
this._width = 0;
|
|
||||||
this._height = 0;
|
|
||||||
this._cx = 0; // center x
|
|
||||||
this._cy = 0; // center y
|
|
||||||
this._maxRadius = 0; // max ring radius in pixels
|
|
||||||
|
|
||||||
// Pre-allocated arrays to avoid per-frame allocation.
|
|
||||||
// Sized lazily when pattern is set.
|
|
||||||
this._nodeX = null; // Float64Array — screen x per step
|
|
||||||
this._nodeY = null; // Float64Array — screen y per step
|
|
||||||
this._nodeR = null; // Float64Array — rendered radius per step
|
|
||||||
|
|
||||||
// Interaction
|
|
||||||
this._tapCallback = null;
|
|
||||||
this._onPointerDown = this._handlePointerDown.bind(this);
|
|
||||||
|
|
||||||
// Event bus subscription
|
|
||||||
this._onStep = this._handleStep.bind(this);
|
|
||||||
this._bus.on(SEQ.STEP, this._onStep);
|
|
||||||
|
|
||||||
// Canvas interaction
|
|
||||||
this._canvas.addEventListener('pointerdown', this._onPointerDown);
|
|
||||||
|
|
||||||
// Initial sizing
|
|
||||||
this.resize(canvas.getBoundingClientRect().width, canvas.getBoundingClientRect().height);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── Public API ──────────────────────────────────────────────────
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Update the displayed pattern.
|
|
||||||
* @param {{ steps: Array, stepCount: number, metadata: Object }} patternDesc
|
|
||||||
*/
|
|
||||||
setPattern(patternDesc) {
|
|
||||||
this._pattern = patternDesc;
|
|
||||||
const count = patternDesc ? patternDesc.stepCount : 0;
|
|
||||||
|
|
||||||
// (Re)allocate coordinate buffers only when step count changes
|
|
||||||
if (!this._nodeX || this._nodeX.length !== count) {
|
|
||||||
this._nodeX = new Float64Array(count);
|
|
||||||
this._nodeY = new Float64Array(count);
|
|
||||||
this._nodeR = new Float64Array(count);
|
|
||||||
}
|
|
||||||
|
|
||||||
this._computeLayout();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Update the playback position.
|
|
||||||
* @param {number} index — step index (0-based), or -1 for none
|
|
||||||
*/
|
|
||||||
setCurrentStep(index) {
|
|
||||||
this._currentStep = index;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Draw one frame. Call from requestAnimationFrame.
|
|
||||||
*/
|
|
||||||
render() {
|
|
||||||
const ctx = this._ctx;
|
|
||||||
const w = this._width;
|
|
||||||
const h = this._height;
|
|
||||||
|
|
||||||
// Clear
|
|
||||||
ctx.fillStyle = COLOR_BG;
|
|
||||||
ctx.fillRect(0, 0, w, h);
|
|
||||||
|
|
||||||
if (!this._pattern || this._pattern.stepCount === 0) return;
|
|
||||||
|
|
||||||
const steps = this._pattern.steps;
|
|
||||||
const count = this._pattern.stepCount;
|
|
||||||
const cx = this._cx;
|
|
||||||
const cy = this._cy;
|
|
||||||
|
|
||||||
// Draw connecting ring (subtle guide circle at midpoint radius)
|
|
||||||
const midRadius = this._maxRadius * ((OUTER_RADIUS_RATIO + INNER_RADIUS_RATIO) * 0.5);
|
|
||||||
ctx.beginPath();
|
|
||||||
ctx.arc(cx, cy, midRadius, 0, TWO_PI);
|
|
||||||
ctx.strokeStyle = 'rgba(255, 255, 255, 0.06)';
|
|
||||||
ctx.lineWidth = 1;
|
|
||||||
ctx.stroke();
|
|
||||||
|
|
||||||
// Center dot
|
|
||||||
ctx.beginPath();
|
|
||||||
ctx.arc(cx, cy, CENTER_DOT_RADIUS, 0, TWO_PI);
|
|
||||||
ctx.fillStyle = 'rgba(255, 255, 255, 0.2)';
|
|
||||||
ctx.fill();
|
|
||||||
|
|
||||||
// Draw connector line from center to current step
|
|
||||||
if (this._currentStep >= 0 && this._currentStep < count) {
|
|
||||||
const si = this._currentStep;
|
|
||||||
ctx.beginPath();
|
|
||||||
ctx.moveTo(cx, cy);
|
|
||||||
ctx.lineTo(this._nodeX[si], this._nodeY[si]);
|
|
||||||
ctx.strokeStyle = 'rgba(255, 106, 0, 0.2)';
|
|
||||||
ctx.lineWidth = INDICATOR_LINE_WIDTH;
|
|
||||||
ctx.stroke();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Draw step nodes
|
|
||||||
for (let i = 0; i < count; i++) {
|
|
||||||
const step = steps[i];
|
|
||||||
const nx = this._nodeX[i];
|
|
||||||
const ny = this._nodeY[i];
|
|
||||||
const nr = this._nodeR[i];
|
|
||||||
const isCurrent = i === this._currentStep;
|
|
||||||
|
|
||||||
if (isCurrent) {
|
|
||||||
// Outer glow for current step
|
|
||||||
ctx.beginPath();
|
|
||||||
ctx.arc(nx, ny, nr + INDICATOR_EXTRA_RADIUS, 0, TWO_PI);
|
|
||||||
ctx.fillStyle = GLOW_CURRENT;
|
|
||||||
ctx.fill();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (step.trigger) {
|
|
||||||
// Glow behind active nodes
|
|
||||||
if (!isCurrent) {
|
|
||||||
const glowColor = step.accent ? GLOW_ACCENT : GLOW_ACTIVE;
|
|
||||||
ctx.beginPath();
|
|
||||||
ctx.arc(nx, ny, nr + 4, 0, TWO_PI);
|
|
||||||
ctx.fillStyle = glowColor;
|
|
||||||
ctx.fill();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Filled node
|
|
||||||
ctx.beginPath();
|
|
||||||
ctx.arc(nx, ny, nr, 0, TWO_PI);
|
|
||||||
if (isCurrent) {
|
|
||||||
ctx.fillStyle = COLOR_CURRENT;
|
|
||||||
} else if (step.accent) {
|
|
||||||
ctx.fillStyle = COLOR_ACCENT;
|
|
||||||
} else {
|
|
||||||
ctx.fillStyle = COLOR_ACTIVE;
|
|
||||||
}
|
|
||||||
ctx.fill();
|
|
||||||
} else {
|
|
||||||
// Dim outline only for untriggered steps
|
|
||||||
ctx.beginPath();
|
|
||||||
ctx.arc(nx, ny, nr, 0, TWO_PI);
|
|
||||||
ctx.strokeStyle = isCurrent ? COLOR_CURRENT : COLOR_INACTIVE;
|
|
||||||
ctx.lineWidth = NODE_OUTLINE_WIDTH;
|
|
||||||
ctx.stroke();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handle canvas resize.
|
|
||||||
* @param {number} width — CSS pixels
|
|
||||||
* @param {number} height — CSS pixels
|
|
||||||
*/
|
|
||||||
resize(width, height) {
|
|
||||||
const dpr = window.devicePixelRatio || 1;
|
|
||||||
this._canvas.width = width * dpr;
|
|
||||||
this._canvas.height = height * dpr;
|
|
||||||
this._ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
|
|
||||||
|
|
||||||
this._width = width;
|
|
||||||
this._height = height;
|
|
||||||
this._cx = width * 0.5;
|
|
||||||
this._cy = height * 0.5;
|
|
||||||
|
|
||||||
const minDim = Math.min(width, height);
|
|
||||||
this._maxRadius = (minDim * 0.5) * (1 - PADDING_RATIO * 2);
|
|
||||||
|
|
||||||
this._computeLayout();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Register a tap callback.
|
|
||||||
* @param {function(number): void} callback — receives step index
|
|
||||||
*/
|
|
||||||
onStepTap(callback) {
|
|
||||||
this._tapCallback = callback;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Unsubscribe from event bus and remove DOM listeners.
|
|
||||||
*/
|
|
||||||
destroy() {
|
|
||||||
this._bus.off(SEQ.STEP, this._onStep);
|
|
||||||
this._canvas.removeEventListener('pointerdown', this._onPointerDown);
|
|
||||||
this._tapCallback = null;
|
|
||||||
this._pattern = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ── Private ─────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Re-compute node positions from current pattern + canvas size.
|
|
||||||
* Called when pattern or size changes — NOT per frame.
|
|
||||||
*/
|
|
||||||
_computeLayout() {
|
|
||||||
if (!this._pattern || !this._nodeX) return;
|
|
||||||
|
|
||||||
const steps = this._pattern.steps;
|
|
||||||
const count = this._pattern.stepCount;
|
|
||||||
const cx = this._cx;
|
|
||||||
const cy = this._cy;
|
|
||||||
const maxR = this._maxRadius;
|
|
||||||
const outerR = maxR * OUTER_RADIUS_RATIO;
|
|
||||||
const innerR = maxR * INNER_RADIUS_RATIO;
|
|
||||||
const radiusRange = outerR - innerR;
|
|
||||||
|
|
||||||
// Angular step: start at top (-PI/2), go clockwise
|
|
||||||
const angleStep = TWO_PI / count;
|
|
||||||
|
|
||||||
for (let i = 0; i < count; i++) {
|
|
||||||
const step = steps[i];
|
|
||||||
const angle = -HALF_PI + angleStep * i;
|
|
||||||
|
|
||||||
// Pitch -> radial distance: low pitch = outer, high pitch = inner
|
|
||||||
const pitchNorm = step.pitch; // 0 = low (outer), 1 = high (inner)
|
|
||||||
const r = outerR - pitchNorm * radiusRange;
|
|
||||||
|
|
||||||
this._nodeX[i] = cx + Math.cos(angle) * r;
|
|
||||||
this._nodeY[i] = cy + Math.sin(angle) * r;
|
|
||||||
|
|
||||||
// Velocity -> node size
|
|
||||||
this._nodeR[i] = NODE_MIN_RADIUS + step.velocity * (NODE_MAX_RADIUS - NODE_MIN_RADIUS);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handle seq.step events from the event bus.
|
|
||||||
*/
|
|
||||||
_handleStep(data) {
|
|
||||||
if (typeof data.stepIndex === 'number') {
|
|
||||||
this._currentStep = data.stepIndex;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handle pointer down on the canvas for tap interaction.
|
|
||||||
*/
|
|
||||||
_handlePointerDown(e) {
|
|
||||||
if (!this._tapCallback || !this._pattern) return;
|
|
||||||
|
|
||||||
const rect = this._canvas.getBoundingClientRect();
|
|
||||||
const px = e.clientX - rect.left;
|
|
||||||
const py = e.clientY - rect.top;
|
|
||||||
const count = this._pattern.stepCount;
|
|
||||||
|
|
||||||
// Find closest step within hit radius
|
|
||||||
let bestIdx = -1;
|
|
||||||
let bestDistSq = Infinity;
|
|
||||||
|
|
||||||
for (let i = 0; i < count; i++) {
|
|
||||||
const dx = px - this._nodeX[i];
|
|
||||||
const dy = py - this._nodeY[i];
|
|
||||||
const distSq = dx * dx + dy * dy;
|
|
||||||
// Hit area is the node radius + some tolerance
|
|
||||||
const hitR = this._nodeR[i] + 12;
|
|
||||||
if (distSq < hitR * hitR && distSq < bestDistSq) {
|
|
||||||
bestDistSq = distSq;
|
|
||||||
bestIdx = i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bestIdx >= 0) {
|
|
||||||
this._tapCallback(bestIdx);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
1
.envrc
Normal file
1
.envrc
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
export CLAUDE_CODE_TASK_LIST_ID=nisps-extract
|
||||||
234
.github/workflows/ci.yml
vendored
Normal file
234
.github/workflows/ci.yml
vendored
Normal file
|
|
@ -0,0 +1,234 @@
|
||||||
|
name: CI
|
||||||
|
|
||||||
|
# Stream 11 verification pipeline.
|
||||||
|
#
|
||||||
|
# Three parallel jobs:
|
||||||
|
# * cpp-tests — builds nisps host C++ tests, builds nisps.wasm, runs
|
||||||
|
# the parity check, runs the lint script, and reports
|
||||||
|
# per-engine throughput on both host targets.
|
||||||
|
# * manifold-tests — typechecks the React manifold app, runs bun unit
|
||||||
|
# tests, builds the production bundle, runs Playwright
|
||||||
|
# e2e tests.
|
||||||
|
#
|
||||||
|
# * firmware-build — compiles three representative PlatformIO envs for the
|
||||||
|
# RP2350 target.
|
||||||
|
#
|
||||||
|
# Firmware entered CI for the first time with the Phase 4 PlatformIO migration
|
||||||
|
# (plan §5, S9). It was previously excluded because arduino-cli + the rp2040
|
||||||
|
# board package cost ~2 minutes per run for "low verification value" — an
|
||||||
|
# assessment that did not survive contact: the SelfTest variant sat broken for
|
||||||
|
# an unknown period, calling a DisplayDriver method that did not exist at the
|
||||||
|
# pinned memllib commit, and nothing noticed because nothing built it. PIO's
|
||||||
|
# toolchain caches cleanly, so the cost is now a cache restore.
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [main]
|
||||||
|
pull_request:
|
||||||
|
branches: [main]
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
cpp-tests:
|
||||||
|
name: C++ tests + WASM + parity + lint
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Install build deps
|
||||||
|
run: |
|
||||||
|
sudo apt-get update
|
||||||
|
sudo apt-get install -y --no-install-recommends \
|
||||||
|
cmake ninja-build build-essential perl
|
||||||
|
|
||||||
|
- name: Setup Emscripten
|
||||||
|
# mymindstorm/setup-emsdk caches the SDK between runs. Pin to a
|
||||||
|
# known-working version; bump deliberately.
|
||||||
|
uses: mymindstorm/setup-emsdk@v14
|
||||||
|
with:
|
||||||
|
version: '3.1.69'
|
||||||
|
actions-cache-folder: 'emsdk-cache'
|
||||||
|
|
||||||
|
- name: Verify emcc
|
||||||
|
run: emcc --version
|
||||||
|
|
||||||
|
- name: Setup Node (for parity_wasm.mjs)
|
||||||
|
uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: '20'
|
||||||
|
|
||||||
|
- name: Build C++ tests + run ctest
|
||||||
|
env:
|
||||||
|
# CI is non-interactive — turn off colour for log readability.
|
||||||
|
CMAKE_BUILD_PARALLEL_LEVEL: '4'
|
||||||
|
run: bash scripts/build-cpp-tests.sh
|
||||||
|
|
||||||
|
# Freshness gate. manifold/public/nisps.{js,wasm} are TRACKED artifacts:
|
||||||
|
# the VPS webhook builds only manifold/, so vite copies whatever is
|
||||||
|
# committed into the production bundle. Prove the committed artifact
|
||||||
|
# still agrees with the C++ we just built, BEFORE the rebuild below
|
||||||
|
# overwrites it. A stale commit fails here instead of silently shipping.
|
||||||
|
- name: WASM freshness gate (committed artifact vs native)
|
||||||
|
env:
|
||||||
|
NISPS_PARITY_NO_BUILD: '1'
|
||||||
|
run: bash scripts/parity-check.sh
|
||||||
|
|
||||||
|
- name: Build WASM
|
||||||
|
# setup-emsdk puts emcc on PATH; build-wasm.sh picks it up via
|
||||||
|
# `command -v emcc`. No EMCC override needed.
|
||||||
|
run: bash scripts/build-wasm.sh
|
||||||
|
|
||||||
|
- name: Parity check (native vs WASM)
|
||||||
|
env:
|
||||||
|
NISPS_PARITY_NO_BUILD: '1' # we just built; don't re-build
|
||||||
|
run: bash scripts/parity-check.sh
|
||||||
|
|
||||||
|
- name: Lint
|
||||||
|
run: bash scripts/lint-cpp.sh
|
||||||
|
|
||||||
|
# Throughput is reported, not asserted — the same call the firmware
|
||||||
|
# flash/RAM step makes below, for a stronger reason: a wall-clock
|
||||||
|
# threshold on a shared runner is either slack enough to be meaningless
|
||||||
|
# or tight enough to fail on someone else's noisy neighbour. What this
|
||||||
|
# buys is (a) a per-commit ns/sample + realtime-factor record in the log,
|
||||||
|
# where a 2-3x regression — the failure mode ALIGNMENT defect 5 names —
|
||||||
|
# is unmissable even at runner noise levels, (b) proof the bench still
|
||||||
|
# builds and runs on BOTH targets, and (c) the wasm/native ratio.
|
||||||
|
# Runner noise makes small moves unreadable; for a real comparison run
|
||||||
|
# scripts/bench-engines.sh --compare locally.
|
||||||
|
- name: Engine throughput report (native + WASM, not asserted)
|
||||||
|
run: bash scripts/bench-engines.sh --target-ms 60
|
||||||
|
|
||||||
|
- name: Upload parity blobs on failure
|
||||||
|
if: failure()
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: parity-blobs
|
||||||
|
path: |
|
||||||
|
tests/cpp/parity_native.bin
|
||||||
|
tests/cpp/parity_wasm.bin
|
||||||
|
if-no-files-found: ignore
|
||||||
|
retention-days: 7
|
||||||
|
|
||||||
|
manifold-tests:
|
||||||
|
name: Manifold typecheck + unit + e2e
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Setup Bun
|
||||||
|
uses: oven-sh/setup-bun@v2
|
||||||
|
with:
|
||||||
|
bun-version: latest
|
||||||
|
|
||||||
|
# Enforces the "schema changes ship with regenerated C++ AND TypeScript
|
||||||
|
# in the same change" rule. Regenerate from schemas/ and fail if the
|
||||||
|
# committed outputs differ; then run the codegen golden test.
|
||||||
|
- name: Codegen is committed and idempotent
|
||||||
|
run: |
|
||||||
|
cd codegen
|
||||||
|
bun install --frozen-lockfile
|
||||||
|
bun run generate.ts
|
||||||
|
bun run generate-midi-devices.ts
|
||||||
|
bun run tests/golden_test.ts
|
||||||
|
# The schemas' per-voice-space `curve` declarations are DESCRIPTIVE
|
||||||
|
# of nisps/engines/*.hpp. Prove they still describe it.
|
||||||
|
bun run tests/curve_drift_test.ts
|
||||||
|
cd ..
|
||||||
|
GEN_DIRS="nisps/modes/generated nisps/midi/generated nisps/ml/generated \
|
||||||
|
manifold/src/modes/generated manifold/src/midi-devices/generated"
|
||||||
|
git add -N $GEN_DIRS
|
||||||
|
if ! git diff --exit-code -- $GEN_DIRS; then
|
||||||
|
echo "::error::Generated outputs are stale. Run codegen and commit the result." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Install manifold deps
|
||||||
|
working-directory: manifold
|
||||||
|
run: bun install --frozen-lockfile
|
||||||
|
|
||||||
|
- name: Typecheck
|
||||||
|
working-directory: manifold
|
||||||
|
run: bun run typecheck
|
||||||
|
|
||||||
|
- name: Unit tests
|
||||||
|
working-directory: manifold
|
||||||
|
run: bun run test
|
||||||
|
|
||||||
|
- name: Build manifold bundle
|
||||||
|
working-directory: manifold
|
||||||
|
run: bun run build
|
||||||
|
|
||||||
|
- name: Install Playwright browsers
|
||||||
|
working-directory: manifold
|
||||||
|
run: bunx playwright install --with-deps chromium
|
||||||
|
|
||||||
|
- name: Run Playwright tests
|
||||||
|
working-directory: manifold
|
||||||
|
run: bunx playwright test
|
||||||
|
|
||||||
|
- name: Upload Playwright report on failure
|
||||||
|
if: failure()
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: playwright-report
|
||||||
|
path: manifold/playwright-report/
|
||||||
|
retention-days: 7
|
||||||
|
|
||||||
|
firmware-build:
|
||||||
|
name: Firmware (RP2350, PlatformIO)
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- uses: actions/setup-python@v5
|
||||||
|
with:
|
||||||
|
python-version: '3.12'
|
||||||
|
|
||||||
|
# The platform wrapper and the arduino-pico framework are fetched from
|
||||||
|
# git and total ~1-2 GB. Key on platformio.ini because that file pins
|
||||||
|
# both versions — change a pin, get a fresh toolchain.
|
||||||
|
- name: Cache PlatformIO toolchain
|
||||||
|
uses: actions/cache@v4
|
||||||
|
with:
|
||||||
|
path: |
|
||||||
|
~/.platformio
|
||||||
|
~/.cache/pip
|
||||||
|
key: pio-${{ runner.os }}-${{ hashFiles('firmware/MEMLNaut-NISPS/platformio.ini') }}
|
||||||
|
restore-keys: pio-${{ runner.os }}-
|
||||||
|
|
||||||
|
- name: Install PlatformIO
|
||||||
|
run: pip install --upgrade platformio
|
||||||
|
|
||||||
|
# Four representative envs rather than all sixteen: they differ mostly in
|
||||||
|
# which mode type is instantiated, so a compile break is usually common to
|
||||||
|
# all. slpworkshop is the shipped default, pafsynth is the heaviest RAM
|
||||||
|
# user, selftest takes the separate NISPS_SELFTEST fork through main.cpp
|
||||||
|
# (the one that broke unnoticed before), and soundanalysismidi is the ONLY
|
||||||
|
# microphone variant — the sole mode whose DriverConfig differs from its
|
||||||
|
# engine's, via an on_driver_config() override. Drop it and the mic path
|
||||||
|
# stops being compiled by anything.
|
||||||
|
- name: Build representative firmware variants
|
||||||
|
working-directory: firmware/MEMLNaut-NISPS
|
||||||
|
run: pio run -e slpworkshop -e pafsynth -e selftest -e soundanalysismidi
|
||||||
|
|
||||||
|
# Sizes are reported, not asserted. A threshold would either be slack
|
||||||
|
# enough to be meaningless or tight enough to fail on unrelated work;
|
||||||
|
# this puts the numbers in the log so a jump is visible in review.
|
||||||
|
# Flash = .text + .rodata, RAM = .data + .bss + vector table +
|
||||||
|
# uninitialized — matching arduino-cli's convention, NOT PlatformIO's
|
||||||
|
# own console line, which double-counts .data on this board.
|
||||||
|
- name: Report flash/RAM per variant
|
||||||
|
working-directory: firmware/MEMLNaut-NISPS
|
||||||
|
run: |
|
||||||
|
SIZE=$(find ~/.platformio/packages -name 'arm-none-eabi-size' | head -1)
|
||||||
|
for e in slpworkshop pafsynth selftest soundanalysismidi; do
|
||||||
|
"$SIZE" -A ".pio/build/$e/firmware.elf" | awk -v e="$e" '
|
||||||
|
/^\.text/{t=$2} /^\.rodata/{r=$2} /^\.data/{d=$2}
|
||||||
|
/^\.bss/{b=$2} /^\.ram_vector_table/{v=$2}
|
||||||
|
/^\.uninitialized_data/{u=$2}
|
||||||
|
END{printf "%-14s flash=%-8d ram=%-8d\n", e, t+r, d+b+v+u}'
|
||||||
|
done
|
||||||
2
.github/workflows/osc-bridge.yml
vendored
2
.github/workflows/osc-bridge.yml
vendored
|
|
@ -40,7 +40,7 @@ jobs:
|
||||||
|
|
||||||
- name: Compile
|
- name: Compile
|
||||||
run: |
|
run: |
|
||||||
cd playground/osc-bridge
|
cd manifold/osc-bridge
|
||||||
deno compile --allow-net --unstable-net --target ${{ matrix.target }} --output ../../dist/nisps-osc-bridge-${{ matrix.suffix }}${{ matrix.os == 'windows-latest' && '.exe' || '' }} bridge.ts
|
deno compile --allow-net --unstable-net --target ${{ matrix.target }} --output ../../dist/nisps-osc-bridge-${{ matrix.suffix }}${{ matrix.os == 'windows-latest' && '.exe' || '' }} bridge.ts
|
||||||
|
|
||||||
- uses: actions/upload-artifact@v4
|
- uses: actions/upload-artifact@v4
|
||||||
|
|
|
||||||
130
.github/workflows/vcv-plugin.yml
vendored
Normal file
130
.github/workflows/vcv-plugin.yml
vendored
Normal file
|
|
@ -0,0 +1,130 @@
|
||||||
|
name: VCV Rack plugin (cross-platform)
|
||||||
|
|
||||||
|
# Builds the MEMLNaut Rack 2 plugin for all four supported platforms using the
|
||||||
|
# OFFICIAL VCVRack/rack-plugin-toolchain (the same Docker-based cross-builder the
|
||||||
|
# VCV Library uses). The toolchain image ships the Linux/MinGW/osxcross cross-
|
||||||
|
# compilers and the per-platform Rack SDKs, so every .vcvplugin is reproducible on
|
||||||
|
# a single Linux runner — no per-platform native runners, no Apple hardware.
|
||||||
|
#
|
||||||
|
# Outputs: one <slug>-<version>-<platform>.vcvplugin per platform, uploaded as a
|
||||||
|
# workflow artifact, and attached to a GitHub Release when triggered by a tag push
|
||||||
|
# (v*). See vcv/DISTRIBUTION.md for the publish-to-/next/vcv flow.
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [main]
|
||||||
|
paths:
|
||||||
|
- 'vcv/**'
|
||||||
|
- '.github/workflows/vcv-plugin.yml'
|
||||||
|
tags:
|
||||||
|
- 'v*'
|
||||||
|
pull_request:
|
||||||
|
paths:
|
||||||
|
- 'vcv/**'
|
||||||
|
- '.github/workflows/vcv-plugin.yml'
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
env:
|
||||||
|
# Pin the official toolchain to a known-good commit (Rack SDK 2.6.6, docker
|
||||||
|
# image version 19). Bump deliberately; never float on master.
|
||||||
|
TOOLCHAIN_REPO: VCVRack/rack-plugin-toolchain
|
||||||
|
TOOLCHAIN_REF: 4fd1318701624051cee54b385343f23d59b4845c
|
||||||
|
TOOLCHAIN_IMAGE_VERSION: '19'
|
||||||
|
PLUGIN_DIR_REL: vcv
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
name: Build ${{ matrix.platform }}
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
# lin-x64 + win-x64 cross-build with gcc / mingw (no Apple SDK).
|
||||||
|
# mac-x64 + mac-arm64 use osxcross baked into the toolchain image — this
|
||||||
|
# is how plugins are cross-built for macOS WITHOUT Apple hardware. The
|
||||||
|
# license-restricted macOS SDK is fetched only inside the toolchain image
|
||||||
|
# build (never committed to this repo).
|
||||||
|
platform: [lin-x64, win-x64, mac-x64, mac-arm64]
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout plugin
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
submodules: recursive
|
||||||
|
|
||||||
|
- name: Checkout rack-plugin-toolchain (pinned)
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
repository: ${{ env.TOOLCHAIN_REPO }}
|
||||||
|
ref: ${{ env.TOOLCHAIN_REF }}
|
||||||
|
path: toolchain
|
||||||
|
|
||||||
|
- name: Cache toolchain Docker image
|
||||||
|
id: img-cache
|
||||||
|
uses: actions/cache@v4
|
||||||
|
with:
|
||||||
|
path: /tmp/rack-toolchain-image
|
||||||
|
key: rack-toolchain-${{ env.TOOLCHAIN_REF }}-v${{ env.TOOLCHAIN_IMAGE_VERSION }}
|
||||||
|
|
||||||
|
- name: Fetch per-platform Rack SDKs
|
||||||
|
working-directory: toolchain
|
||||||
|
run: make rack-sdk-all
|
||||||
|
|
||||||
|
- name: Load or build toolchain image
|
||||||
|
working-directory: toolchain
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
IMG="rack-plugin-toolchain:${TOOLCHAIN_IMAGE_VERSION}"
|
||||||
|
if [ -f /tmp/rack-toolchain-image/image.tar ]; then
|
||||||
|
echo "Loading cached toolchain image $IMG"
|
||||||
|
docker load -i /tmp/rack-toolchain-image/image.tar
|
||||||
|
else
|
||||||
|
echo "Building toolchain image $IMG (one-off; cached for later runs)"
|
||||||
|
# rack-sdk-all already ran; build the cross-toolchain image (mingw +
|
||||||
|
# osxcross). This is the heavy step — cached by TOOLCHAIN_REF.
|
||||||
|
docker build --build-arg JOBS=$(nproc) \
|
||||||
|
--tag "$IMG" . --progress=plain
|
||||||
|
mkdir -p /tmp/rack-toolchain-image
|
||||||
|
docker save "$IMG" -o /tmp/rack-toolchain-image/image.tar
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Build .vcvplugin for ${{ matrix.platform }}
|
||||||
|
working-directory: toolchain
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
make docker-plugin-build-${{ matrix.platform }} \
|
||||||
|
PLUGIN_DIR="${GITHUB_WORKSPACE}/${PLUGIN_DIR_REL}"
|
||||||
|
|
||||||
|
- name: Collect artifact
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
mkdir -p out
|
||||||
|
cp toolchain/plugin-build/*.vcvplugin out/
|
||||||
|
ls -la out
|
||||||
|
|
||||||
|
- name: Upload artifact
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: MEMLNaut-${{ matrix.platform }}
|
||||||
|
path: out/*.vcvplugin
|
||||||
|
if-no-files-found: error
|
||||||
|
|
||||||
|
release:
|
||||||
|
name: Attach to release
|
||||||
|
needs: build
|
||||||
|
if: startsWith(github.ref, 'refs/tags/v')
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
steps:
|
||||||
|
- name: Download all artifacts
|
||||||
|
uses: actions/download-artifact@v4
|
||||||
|
with:
|
||||||
|
path: artifacts
|
||||||
|
merge-multiple: true
|
||||||
|
|
||||||
|
- name: Publish release
|
||||||
|
uses: softprops/action-gh-release@v2
|
||||||
|
with:
|
||||||
|
files: artifacts/*.vcvplugin
|
||||||
|
generate_release_notes: true
|
||||||
14
.gitignore
vendored
14
.gitignore
vendored
|
|
@ -25,7 +25,6 @@
|
||||||
*.la
|
*.la
|
||||||
*.a
|
*.a
|
||||||
*.lib
|
*.lib
|
||||||
|
|
||||||
# Executables
|
# Executables
|
||||||
*.exe
|
*.exe
|
||||||
*.out
|
*.out
|
||||||
|
|
@ -34,9 +33,15 @@
|
||||||
.ai
|
.ai
|
||||||
build
|
build
|
||||||
|
|
||||||
|
# PlatformIO build artifacts (firmware/MEMLNaut-NISPS) — bootstrapped platform,
|
||||||
|
# toolchain, and libraries live outside the repo in ~/.platformio; only
|
||||||
|
# .pio/build (per-env objects/elf/uf2) and .pio/libdeps (fetched lib_deps)
|
||||||
|
# land here, both disposable.
|
||||||
|
.pio
|
||||||
|
|
||||||
# OSC bridge compiled binaries (built via compile.sh or CI)
|
# OSC bridge compiled binaries (built via compile.sh or CI)
|
||||||
playground/osc-bridge/dist/
|
manifold/osc-bridge/dist/
|
||||||
playground/osc-bridge/node_modules/
|
manifold/osc-bridge/node_modules/
|
||||||
|
|
||||||
# Dolt database files (added by bd init)
|
# Dolt database files (added by bd init)
|
||||||
.dolt/
|
.dolt/
|
||||||
|
|
@ -47,3 +52,6 @@ node_modules/
|
||||||
bun.lock
|
bun.lock
|
||||||
playwright-report/
|
playwright-report/
|
||||||
test-results/
|
test-results/
|
||||||
|
|
||||||
|
# Agent worktrees
|
||||||
|
.claude/worktrees/
|
||||||
|
|
|
||||||
6
.gitmodules
vendored
6
.gitmodules
vendored
|
|
@ -1,6 +0,0 @@
|
||||||
[submodule "src/memlp"]
|
|
||||||
path = src/memlp
|
|
||||||
url = https://github.com/MusicallyEmbodiedML/memlp.git
|
|
||||||
[submodule "src/memllib"]
|
|
||||||
path = src/memllib
|
|
||||||
url = https://github.com/MusicallyEmbodiedML/memllib.git
|
|
||||||
143
AGENTS.md
143
AGENTS.md
|
|
@ -1,126 +1,31 @@
|
||||||
# Agent Instructions
|
# Agent Instructions — MEMLNaut-NISPS
|
||||||
|
|
||||||
This project uses **bd** (beads) for issue tracking. Run `bd onboard` to get started.
|
One C++20 NISPS core targets RP2350 firmware and the Manifold React/WASM browser app. Read
|
||||||
|
`MAP.md`, `ALIGNMENT.md`, and `docs/AGENT-REFERENCE.md`; for Manifold UI work read
|
||||||
|
`manifold/ONBOARDING.md` first. Parameter JSON schemas generate both C++ and TypeScript
|
||||||
|
contracts.
|
||||||
|
|
||||||
## Quick Reference
|
## Gates
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
bd ready # Find available work
|
bash scripts/build-cpp-tests.sh
|
||||||
bd show <id> # View issue details
|
bash scripts/parity-check.sh
|
||||||
bd update <id> --status in_progress # Claim work
|
bash scripts/lint-cpp.sh
|
||||||
bd close <id> # Complete work
|
scripts/build-firmware.sh [VARIANT]
|
||||||
bd sync # Sync with git
|
cd manifold && bun run typecheck && bun run test && bun run build
|
||||||
```
|
```
|
||||||
|
|
||||||
<!-- BEGIN BEADS INTEGRATION -->
|
- `nisps/` must remain platform-neutral and allocation-free in hot paths: no heap, no
|
||||||
## Issue Tracking with bd (beads)
|
virtual dispatch, `.f` float literals, deterministic per-instance RNG, and the memory/
|
||||||
|
hot-path attributes from `nisps/core/perf.hpp`.
|
||||||
|
- Firmware and WASM use the same engines/modes. Cross-platform outputs must retain parity;
|
||||||
|
do not patch target-specific behavior around a core mismatch.
|
||||||
|
- Schema changes require codegen and both generated-language outputs in the same change.
|
||||||
|
- Audio-thread/WASM-worklet communication stays bounded and real-time safe.
|
||||||
|
- Preserve dual-core firmware ownership and SPSC synchronization; UI/control work must not
|
||||||
|
block the audio path.
|
||||||
|
- UI behavior changes need the targeted unit/E2E evidence and the verification chokepoints
|
||||||
|
documented in the detailed reference.
|
||||||
|
|
||||||
**IMPORTANT**: This project uses **bd (beads)** for ALL issue tracking. Do NOT use markdown TODOs, task lists, or other tracking methods.
|
Use `ergo` for coding tasks. Keep `MAP.md`, `ALIGNMENT.md`, and affected docs synchronized
|
||||||
|
with code.
|
||||||
### Why bd?
|
|
||||||
|
|
||||||
- Dependency-aware: Track blockers and relationships between issues
|
|
||||||
- Git-friendly: Auto-syncs to JSONL for version control
|
|
||||||
- Agent-optimized: JSON output, ready work detection, discovered-from links
|
|
||||||
- Prevents duplicate tracking systems and confusion
|
|
||||||
|
|
||||||
### Quick Start
|
|
||||||
|
|
||||||
**Check for ready work:**
|
|
||||||
|
|
||||||
```bash
|
|
||||||
bd ready --json
|
|
||||||
```
|
|
||||||
|
|
||||||
**Create new issues:**
|
|
||||||
|
|
||||||
```bash
|
|
||||||
bd create "Issue title" --description="Detailed context" -t bug|feature|task -p 0-4 --json
|
|
||||||
bd create "Issue title" --description="What this issue is about" -p 1 --deps discovered-from:bd-123 --json
|
|
||||||
```
|
|
||||||
|
|
||||||
**Claim and update:**
|
|
||||||
|
|
||||||
```bash
|
|
||||||
bd update bd-42 --status in_progress --json
|
|
||||||
bd update bd-42 --priority 1 --json
|
|
||||||
```
|
|
||||||
|
|
||||||
**Complete work:**
|
|
||||||
|
|
||||||
```bash
|
|
||||||
bd close bd-42 --reason "Completed" --json
|
|
||||||
```
|
|
||||||
|
|
||||||
### Issue Types
|
|
||||||
|
|
||||||
- `bug` - Something broken
|
|
||||||
- `feature` - New functionality
|
|
||||||
- `task` - Work item (tests, docs, refactoring)
|
|
||||||
- `epic` - Large feature with subtasks
|
|
||||||
- `chore` - Maintenance (dependencies, tooling)
|
|
||||||
|
|
||||||
### Priorities
|
|
||||||
|
|
||||||
- `0` - Critical (security, data loss, broken builds)
|
|
||||||
- `1` - High (major features, important bugs)
|
|
||||||
- `2` - Medium (default, nice-to-have)
|
|
||||||
- `3` - Low (polish, optimization)
|
|
||||||
- `4` - Backlog (future ideas)
|
|
||||||
|
|
||||||
### Workflow for AI Agents
|
|
||||||
|
|
||||||
1. **Check ready work**: `bd ready` shows unblocked issues
|
|
||||||
2. **Claim your task**: `bd update <id> --status in_progress`
|
|
||||||
3. **Work on it**: Implement, test, document
|
|
||||||
4. **Discover new work?** Create linked issue:
|
|
||||||
- `bd create "Found bug" --description="Details about what was found" -p 1 --deps discovered-from:<parent-id>`
|
|
||||||
5. **Complete**: `bd close <id> --reason "Done"`
|
|
||||||
|
|
||||||
### Auto-Sync
|
|
||||||
|
|
||||||
bd automatically syncs with git:
|
|
||||||
|
|
||||||
- Exports to `.beads/issues.jsonl` after changes (5s debounce)
|
|
||||||
- Imports from JSONL when newer (e.g., after `git pull`)
|
|
||||||
- No manual export/import needed!
|
|
||||||
|
|
||||||
### Important Rules
|
|
||||||
|
|
||||||
- ✅ Use bd for ALL task tracking
|
|
||||||
- ✅ Always use `--json` flag for programmatic use
|
|
||||||
- ✅ Link discovered work with `discovered-from` dependencies
|
|
||||||
- ✅ Check `bd ready` before asking "what should I work on?"
|
|
||||||
- ❌ Do NOT create markdown TODO lists
|
|
||||||
- ❌ Do NOT use external issue trackers
|
|
||||||
- ❌ Do NOT duplicate tracking systems
|
|
||||||
|
|
||||||
For more details, see README.md and docs/QUICKSTART.md.
|
|
||||||
|
|
||||||
<!-- END BEADS INTEGRATION -->
|
|
||||||
|
|
||||||
## Landing the Plane (Session Completion)
|
|
||||||
|
|
||||||
**When ending a work session**, you MUST complete ALL steps below. Work is NOT complete until `git push` succeeds.
|
|
||||||
|
|
||||||
**MANDATORY WORKFLOW:**
|
|
||||||
|
|
||||||
1. **File issues for remaining work** - Create issues for anything that needs follow-up
|
|
||||||
2. **Run quality gates** (if code changed) - Tests, linters, builds
|
|
||||||
3. **Update issue status** - Close finished work, update in-progress items
|
|
||||||
4. **PUSH TO REMOTE** - This is MANDATORY:
|
|
||||||
```bash
|
|
||||||
git pull --rebase
|
|
||||||
bd sync
|
|
||||||
git push
|
|
||||||
git status # MUST show "up to date with origin"
|
|
||||||
```
|
|
||||||
5. **Clean up** - Clear stashes, prune remote branches
|
|
||||||
6. **Verify** - All changes committed AND pushed
|
|
||||||
7. **Hand off** - Provide context for next session
|
|
||||||
|
|
||||||
**CRITICAL RULES:**
|
|
||||||
- Work is NOT complete until `git push` succeeds
|
|
||||||
- NEVER stop before pushing - that leaves work stranded locally
|
|
||||||
- NEVER say "ready to push when you are" - YOU must push
|
|
||||||
- If push fails, resolve and retry until it succeeds
|
|
||||||
|
|
|
||||||
170
ALIGNMENT.md
Normal file
170
ALIGNMENT.md
Normal file
|
|
@ -0,0 +1,170 @@
|
||||||
|
# ALIGNMENT
|
||||||
|
|
||||||
|
> Opinionated diagnosis of how well the codebase serves its mission, ranked by impact. Dated entries; remove when resolved rather than checking off. **Pruned every few weeks** — a stale diagnosis is worse than none.
|
||||||
|
|
||||||
|
## Mission
|
||||||
|
|
||||||
|
A research platform for interactive ML control of audio. We're building it to figure out what works and what doesn't — different ergonomics and ergodynamics of parameter sets, modes, ML architectures, audio engines, UI, and UX. Therefore: keep most/all parameters tweakable, ML/engine/UI/UX should each be configurable on their own axis, and the codebase has to enable/assist agentic AI coding patterns (confident changes, verifiable without hardware).
|
||||||
|
|
||||||
|
**Target vision (operator, 2026-07-20):** (1) one C++20 NISPS core serving RP2350 firmware and the browser, performance-sensitive on the MCU; (2) firmware modes runnable as modes in Manifold; (3) Manifold defaults to curated presets/modes, with the maximalist surface behind an "advanced" dev mode used to author them; (4) PlatformIO for hardware, no more .ino; (5) Manifold doubles as interface/editor for the hardware MEMLNaut (settings, presets, training, examples, visualisation).
|
||||||
|
|
||||||
|
The clean-slate rewrite (2026-04-29) consolidated everything into one C++20 codebase compiling to firmware AND WASM. Since 2026-07-13 (P1) the sole browser app is the React Manifold. JSON schemas remain the firmware↔browser parameter contract. A full-repo audit (2026-07-21, `docs/specs/recon/simplification-audit-2026-07.md`) grounds the entries below; mitigations are phased in `docs/specs/plans/simplification-plan.md`.
|
||||||
|
|
||||||
|
## Top defects (ranked by mission impact)
|
||||||
|
|
||||||
|
### 1. The mode layer is not shared: WASM re-orchestrates modes by hand (2026-07-21)
|
||||||
|
|
||||||
|
**What.** `nisps/modes/` — the CRTP layer binding ML config, engine, voice-space and I/O — compiles only into firmware. `nisps/wasm/bindings.cpp` includes engines and ML primitives but zero mode headers, and Manifold re-assembles mode behaviour (jolt stepping, OU, routing) in TS. "Firmware and WASM share the same modes" is true only at the engine level; every ModeBase behaviour must be mirrored browser-side by hand.
|
||||||
|
|
||||||
|
**Why it blocks the mission.** Vision bullet 2 is precisely this. Until the control-tick orchestration exists once in C++, every new mode behaviour is a dual implementation with drift risk.
|
||||||
|
|
||||||
|
**Rough cost.** Spec first, then ~a week: storage-policy the ModeBase orchestration the way P2 did MLPCore (verified shape in plan §6.5a — *not* binding monolithic mode objects, which would contradict the locked two-instance RT architecture). Related honesty gap: Manifold currently catalogues 4 modes that structurally cannot run in the browser (no mic input, event-only engines) — plan §6.5b (absorbs the old C15/mic-input defect; C15 itself lives on `archive/playground-solidjs`).
|
||||||
|
|
||||||
|
### 2. No curated/advanced split and no in-UI mode picker — the UI fights vision 3 (2026-07-21)
|
||||||
|
|
||||||
|
**What.** Manifold is 100% dev-maximalist: five drawers of everything, no preset data model to author against, and mode switching exists only via the debug hook — there is no instrument picker in the UI at all (the plumbing, `ctx.modes`/`setModeId`, already exists unused). A stratum of decorative controls (training-param sliders, master volume, bpm, A/B, snapshots, fabricated gradient health) renders real-looking UI that drives nothing.
|
||||||
|
|
||||||
|
**Why it blocks the mission.** The default experience is supposed to be curated presets; the advanced surface is the authoring tool. Neither exists, and the decorative stratum actively misleads research use.
|
||||||
|
|
||||||
|
**Rough cost.** Product-model decision first (plan §7.6), then incremental: picker is days; the curated-preset model seeds from `backends/presets.ts` + schemas; disclosure via per-drawer depth levels — which as of §6.5e (2026-07-21) has its first genuinely advanced-only consumer, the training-health panel, so the mechanism is proven rather than theoretical. The decorative stratum itself went in the Phase-1 sweep.
|
||||||
|
|
||||||
|
### 3. Manifold-as-hardware-editor is a facade (2026-07-21)
|
||||||
|
|
||||||
|
**What.** Vision bullet 5 exists as a 237-line Web Serial shell: sound connect lifecycle, zero protocol (`saveModel`/`restoreModel`/`getSettings` are literal stubs), and firmware has no serial command surface or on-device persistence to talk to.
|
||||||
|
|
||||||
|
**Why it blocks the mission.** The hardware research loop (train on device, inspect/curate in browser) is closed only by this bridge.
|
||||||
|
|
||||||
|
**Rough cost.** Week+, spec-first (plan §6.5d). The right discipline already exists in-repo: useq-celium's C-header wire truth + TS mirror + parity test; settings payloads should derive from schema codegen.
|
||||||
|
|
||||||
|
### 4. Dead mass and registry sprawl across every layer (2026-07-21)
|
||||||
|
|
||||||
|
**What.** *Phase 1 landed 2026-07-21 and removed the bulk of this:* the dead focus/altitude UI system, the decorative control stratum, 12 dead WASM API entries across the 5-file registration chain, the vendored daisysp tree, retired-playground artifacts and root planning relics, 5 unused primitives, the duplicate backend editor and catalogue, `voice_space.hpp`, `fixed_buffer.hpp`, the dead perf-macro regime, and the OSC bridge twin. What remains is the *registry* half: mode identity spread across ~6 hand-maintained registries with demonstrated drift, MLP dims typed twice, per-mode schema blocks hand-written in C++, and assorted stale specs presenting a deleted world as present tense.
|
||||||
|
|
||||||
|
**Why it blocks the mission.** The registries are dual-truth bugs waiting to fire (one already did: the selftest table). Stale specs are agent-confusing surface area.
|
||||||
|
|
||||||
|
**Rough cost.** Plan phase 3 (~2–3 days, codegen takes ownership) plus the docs disposition pass (§8). The behaviour bugs found en route (dataset-cap divergence, VCV 2-D input truncation, VCV audio-thread race and JSON) were fixed in phase 2 on 2026-07-21.
|
||||||
|
|
||||||
|
### 5. Performance is measured on the host but not on the target that constrains it (2026-07-21)
|
||||||
|
|
||||||
|
**What.** *Mostly closed 2026-07-21.* Size: the Phase 4 firmware CI job reports per-variant
|
||||||
|
flash/RAM on every push. Time: `scripts/bench-engines.sh` now reports per-engine ns/sample,
|
||||||
|
blocks/s and realtime factor on native AND WASM from one source
|
||||||
|
(`tests/cpp/engine_bench.cpp`), engines driven into a working state, with `--compare` for
|
||||||
|
per-engine deltas and a report step in CI. An engine getting 3x slower is now visible.
|
||||||
|
|
||||||
|
**What is left.** The numbers are HOST numbers. The mission's performance constraint is the
|
||||||
|
**RP2350 at 150 MHz**, and nothing measures there — a host realtime factor of 100x says
|
||||||
|
nothing about whether an engine fits in the MCU's per-block budget, and the two targets have
|
||||||
|
different FPU, cache and memory behaviour. The honest next step is an on-device timing report
|
||||||
|
(cycle counter around the audio callback, published over the existing display/serial surface),
|
||||||
|
which lands naturally with the hardware editor (defect 3) since that is what gives firmware a
|
||||||
|
command surface to report through.
|
||||||
|
|
||||||
|
**Rough cost.** Host half is done. On-device: ~a day, and it wants defect 3's serial protocol
|
||||||
|
to have somewhere to send the number.
|
||||||
|
|
||||||
|
### 6d. One like still heaves the whole mapping (2026-07-25)
|
||||||
|
|
||||||
|
**What.** A thumbs-up trains at `lr 1.0 x 1000 iterations` on every gesture. `ml_bench`
|
||||||
|
U1/U4 measure **lurch** — how far the mapping the musician is playing moves per single
|
||||||
|
gesture, averaged over the field: `lurch_max` 1.08 against a [0,1] output range, i.e.
|
||||||
|
one thumbs-up can move the mapping somewhere in the space by more than the entire output
|
||||||
|
range. Retention (how much of the previous teaching survives) is 0.38; at `iters=1` it
|
||||||
|
is 0.80.
|
||||||
|
|
||||||
|
**Why it blocks the mission.** RMSProp did NOT fix the positive lurch — normalising the
|
||||||
|
step size does not change its dose. The negative path now exposes upstream-style repeated
|
||||||
|
small steps (rate/lifetime/LR are live controls), so its old fixed ~70x comparison is no
|
||||||
|
longer current. Positive teaching remains one enormous blocking train, and the two doses
|
||||||
|
still need a matched head-to-head rather than independent tuning.
|
||||||
|
|
||||||
|
**Rough cost.** Cheap to change, expensive to choose: the tuning space is now measurable
|
||||||
|
(`ml_bench` U4 sweeps dose; U1 sweeps upstream's soft-target alpha, where alpha=1 is
|
||||||
|
NISPS today). It wants a matched-N head-to-head, not a guess.
|
||||||
|
|
||||||
|
## Open mission questions
|
||||||
|
|
||||||
|
### Q1: Per-mode MLP architectures or one shared shape? (2026-04-29)
|
||||||
|
|
||||||
|
Schemas declare per-mode dims and since P5.3 both targets honour them. Is the mission served by maintaining per-mode shapes (research diversity) or collapsing to one (simpler ops)? Note the audit found all 9 mode schemas share copy-pasted ML defaults and 20 params are anonymous placeholders — the per-mode diversity is currently nominal (plan L40).
|
||||||
|
|
||||||
|
### Q2: Engine event taxonomy (2026-04-29)
|
||||||
|
|
||||||
|
`ControlEvent` is a flat enum consumed by the two sequencer modes. Revisit when a third event-emitting mode lands.
|
||||||
|
|
||||||
|
### Q3: Should Manifold stay desktop-first? (2026-04-29)
|
||||||
|
|
||||||
|
Legacy a-immersive was mobile-first; Manifold is desktop-first. Defer until user data exists.
|
||||||
|
|
||||||
|
## Deferred / accepted debt
|
||||||
|
|
||||||
|
- **EOC effects chain, ShapeSeq sequencer, modular engine (Phase E)** — legacy features consciously out of the v1 rewrite; revisit only if a mode wants them.
|
||||||
|
- **Inputs multi-source composition** (2026-06-28, reaffirmed 2026-07-21) — mix-and-match pad+gamepad+MIDI is a recorded, unreversed decision; the UI currently enforces exclusive single-source and the composition machinery sits dormant *by design*. Schedule or keep dormant — but the inputs-spec must stop presenting composition as current behaviour (plan §8).
|
||||||
|
- **Schema content is partially placeholder** (2026-07-21) — 20 anonymous "Param NN" slots across paf_synth/channel_strip/xiasri and copy-pasted ML defaults across all 9 modes. Name them during the first curated-preset pass per mode (plan §6.5c), or shrink `output_size` where the engine allows.
|
||||||
|
- **Geometric-dislike deliberate divergences** (2026-07-25): (1) the degenerate-branch RNG draws from deterministic `nisps::Rng`, not libc `rand()`; (2) each live rejection computes its liked centroid at its own stored input, rather than upstream reinterpreting every old rejection around the cursor's current position; (3) live negatives are applied as deterministic per-item RMSProp steps rather than one shuffled `TrainBatch`; (4) a repeated nearby rejection refreshes its lifetime (upstream's current dedup path leaves the original timestamp untouched); (5) upstream's default removal of a nearby positive is not yet adopted because Manifold also has a separate positive MLP dataset that would keep pulling; (6) `RandomiseMlp` uses `draw_weights(spread)` rather than old asymmetric ranges. Native↔WASM parity covers the elapsed-time replay path.
|
||||||
|
- **Manifold dock splits `state`/`muted`/`armed`** (2026-06-28) — deliberate divergence from the deployed conflated `frozen`↔`muted` model (dock-spec §3.3). `muted`-downstream and the `soloMode` gradient-mask variants remain UI-only; the C API exposes `set_focus` but no per-mode gradient masking yet. (The audit found `soloMode` behaviourally inert in the controller — plan L20 trims it until `train_masked` exists.)
|
||||||
|
|
||||||
|
## Recently resolved (delete after a few weeks)
|
||||||
|
|
||||||
|
- 2026-07-25: **The geometric dislike is re-based on upstream `e291192` (defect 6b).**
|
||||||
|
`kGeometricPushScale` 0.5 -> 1.0, `kNegLRBase` 0.5 -> 1.5, and the `/(1+len)` taper
|
||||||
|
deleted — upstream's own comment is that a "no" should clearly move the mapping away
|
||||||
|
even from a sound already far from the liked region, which is exactly the case the
|
||||||
|
taper killed. Cold start folded into the same path (random direction when nothing is
|
||||||
|
liked yet) instead of the superseded negative-LR branch, so a "no" now moves the
|
||||||
|
mapping before any likes exist (`ml_bench` E1: 0 -> 2.3e-3). One dislike moves the
|
||||||
|
mapping **5.3e-2**, up from 1.6e-2 after the RMSProp fix and 5.3e-5 before it — a
|
||||||
|
~1000x change end to end, and now within ~4x of the legacy Diffuse design instead of
|
||||||
|
~4100x (`ml_bench` A4). The follow-up now adopts upstream's repeated-all-negatives
|
||||||
|
schedule and full-strength wall-clock lifetime through a deterministic elapsed-time
|
||||||
|
core seam. After operator calibration, Manifold defaults to 0.003 LR, 200 Hz and
|
||||||
|
2500 ms, exposes all three in the expanded Learning panel, and allows rate/lifetime
|
||||||
|
zero as an explicit one-shot A/B. The shared core fallback and the panel's explicit
|
||||||
|
"Upstream defaults" preset remain 0.001 LR, 200 Hz and 2500 ms.
|
||||||
|
- 2026-07-25: **`InterfaceRL` is back in the tree (defect 6c).** Vendored verbatim from
|
||||||
|
memllib `e291192` at `firmware/MEMLNaut-NISPS/lib/memllib/reference/` — outside `src/`,
|
||||||
|
so PlatformIO never compiles it. Upstream drift in the feedback subsystem is a `diff`
|
||||||
|
again rather than an archaeology session.
|
||||||
|
- 2026-07-25: **The optimiser mismatch (defect 6) is fixed.** `nisps/ml/training.hpp` was
|
||||||
|
SGD-only while upstream `memlp` (`ea777502`) applies **RMSProp everywhere**, so every
|
||||||
|
learning rate we ported landed in an optimiser that reads it differently — an RMSProp
|
||||||
|
`lr` is a normalised step, an SGD `lr` multiplies the raw gradient. `rmsprop_step()`
|
||||||
|
now ports `Layer.h:239 ApplyAccumulatedGradients` exactly (decay 0.9, eps 1e-6,
|
||||||
|
sq-avg clamp 1e6, one-sided adjusted-LR clamp 1.0), with the per-weight running
|
||||||
|
squared-gradient average living in the storage policies so the zero-heap contract
|
||||||
|
holds. Measured on `ml_bench` D1: one geometric dislike moves the mapping **1.6e-2,
|
||||||
|
up from 5.3e-5**, and repeated presses now converge on the intended 0.5 push (0.12 at
|
||||||
|
10 presses, 0.56 at 100) instead of creeping linearly. Golden vector stages 2 and 3
|
||||||
|
were re-captured; stages 0 and 1 are pre-training and did not move. What this does NOT
|
||||||
|
fix: the dose asymmetry, now tracked as defect 6d.
|
||||||
|
|
||||||
|
- 2026-07-21: **Q4 (who owns memllib) closed.** Vendored at `firmware/MEMLNaut-NISPS/lib/memllib/`
|
||||||
|
from upstream `e291192`; the submodule and the fork are both gone. **Q5 (legacy feedback modes)
|
||||||
|
closed** — operator kept all four (`RandomiseOutputs`/`RandomiseMlp`/`Diffuse`/`on_drag`) as
|
||||||
|
building blocks for comparing how instruments feel under different behaviours, which upholds
|
||||||
|
rather than reverses `docs/adr/rl-feedback-design.md`.
|
||||||
|
- 2026-07-21: **Training-health telemetry (old defect 6) is gone** — the browser reads the real
|
||||||
|
per-iteration loss the core records, both fabrication sites are deleted (`wasm-worker.ts`'s
|
||||||
|
1-element array AND `wasm-iml.ts`'s sync-train twin, which the audit missed), and the display
|
||||||
|
sits behind the existing `expanded` drawer depth. The firmware buffer stays, per the L25 call.
|
||||||
|
|
||||||
|
- 2026-07-21: **Training-health telemetry (old defect 6) is real.** `nisps_ml_loss_history` now
|
||||||
|
crosses all five WASM registration layers, so the browser reads the SAME per-iteration curve the
|
||||||
|
firmware MLP records; `wasm-worker.ts`'s 1-element `new Float32Array([loss])` fake is gone from
|
||||||
|
both the sync and the async train paths; and the curve + the already-plumbed `get_layer_stats`
|
||||||
|
render in `manifold/src/console/TrainingHealth.tsx` at the Learning drawer's `expanded` depth.
|
||||||
|
The firmware buffer stays, per the operator call — it is the record the hardware editor
|
||||||
|
(defect 3) will read. One more fabrication went with it: `ConsoleCtx.loss`, a synthetic
|
||||||
|
`prev * 0.82` series no drawer read. With no history the panel says "no training run yet"
|
||||||
|
rather than drawing a plausible curve.
|
||||||
|
|
||||||
|
- 2026-07-21: **Arduino-CLI build machinery (old defect 3) is gone.** Phase 4 replaced it with a
|
||||||
|
PlatformIO project: one `[env:]` per variant is now the only variant registry, the `.ino`-mutating
|
||||||
|
Python/sed machinery and the `NISPS_ST_*` token-paste table and the sketch symlink forest and the
|
||||||
|
global TFT_eSPI mutation are all deleted, memllib is vendored (no submodule), and firmware finally
|
||||||
|
entered CI — three representative envs per run, which is what would have caught the SelfTest
|
||||||
|
variant sitting broken. All 16 envs build; sizes match arduino-cli within ~520 bytes.
|
||||||
|
|
||||||
|
- 2026-07-21: Full-repo simplification audit landed (recon + plan + this rewrite). Superseded entries removed: "browser-only engines incomplete" (→ defect 2/plan 5b), "loss curve not plumbed" (→ defect 7), "NISPS_AUDIO_FUNC misshapen" (→ plan Phase 1, S21/L13), stale "VCV not currently maintained" note (vcv/ is active and consumes `nisps/` directly post-P6).
|
||||||
|
- 2026-07-18: Browser curve maths unified onto the canonical `nisps/core/math.hpp` catalog at P4; four silently-divergent TS curves re-baselined.
|
||||||
|
- 2026-07-14: WASM MLP fixed-architecture defect resolved by P2 (`MLPCore<Storage>`; browser runtime-shaped, firmware zero-heap fixed).
|
||||||
297
CLAUDE.md
297
CLAUDE.md
|
|
@ -1,297 +0,0 @@
|
||||||
# CLAUDE.md
|
|
||||||
|
|
||||||
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
||||||
|
|
||||||
## Overview
|
|
||||||
|
|
||||||
MEMLNaut-NISPS (Neural Interactive Shaping of Parameter Spaces) is firmware for the MEMLNaut hardware platform - a custom embedded audio device built on Raspberry Pi Pico (RP2040). It implements interactive machine learning for real-time audio synthesis and processing, enabling users to shape sound parameters through reinforcement learning.
|
|
||||||
|
|
||||||
Project documentation: https://musicallyembodiedml.github.io/memlnaut/approaches/nisps
|
|
||||||
|
|
||||||
## NISPS Core Library
|
|
||||||
|
|
||||||
The `nisps-core/` directory contains a platform-agnostic C++20 extraction of the interactive ML engine. This header-only library can be used in any C++ project for neural network-based parameter mapping.
|
|
||||||
|
|
||||||
**Key differences from firmware**:
|
|
||||||
- ✅ Platform-agnostic (no Arduino/RP2040 dependencies)
|
|
||||||
- ✅ Header-only (just include and use)
|
|
||||||
- ✅ C++20 (uses std::span)
|
|
||||||
- ✅ Namespaced (`nisps::`)
|
|
||||||
- ❌ No audio synthesis (use it to *control* your synth)
|
|
||||||
- ❌ No hardware drivers
|
|
||||||
|
|
||||||
**Use case**: Control synthesizers, effects, lights, game parameters, or any system that responds to continuous parameters.
|
|
||||||
|
|
||||||
See `nisps-core/README.md` for complete documentation and examples.
|
|
||||||
|
|
||||||
## Web Playground
|
|
||||||
|
|
||||||
The `playground/` directory contains a browser-based interactive demo of the NISPS ML engine. No build step or dependencies — serve statically.
|
|
||||||
|
|
||||||
- **2 inputs** (virtual joystick X/Y) mapped through a `[3, 32, 48, 64, 126]` MLP to **126 outputs**
|
|
||||||
- **Four output modes**:
|
|
||||||
- **Visual**: first 20 outputs control a Canvas2D flow-field particle system
|
|
||||||
- **Synth (C15)**: all 126 outputs control the C15 WASM synthesizer
|
|
||||||
- **MIDI CC**: outputs mapped to configurable MIDI CC messages via WebMIDI
|
|
||||||
- **Audio Canvas**: 36 outputs drive a generative audio sampler
|
|
||||||
- **Two learning modes**: Examples (set slider targets, add examples, train) and RL Feedback (thumbs up/down with exploration noise)
|
|
||||||
- **Serve statically**: `cd playground && python3 -m http.server`
|
|
||||||
- **Mobile-first**: designed for touch/foldable phone use
|
|
||||||
|
|
||||||
Key files: `js/nisps/` (WASM engine + dataset), `js/ui/` (visualizer, joystick, controls, input pipeline, control surface), `js/synth/` (C15 bridge, param map, arpeggiator), `js/a-app.js` (immersive app wiring).
|
|
||||||
|
|
||||||
### WASM ML Engine
|
|
||||||
|
|
||||||
The immersive app (`a-immersive.html` / `a-app.js`) uses a WASM-compiled MLP for all inference and training. The legacy JS engine (`iml.js`, `mlp.js`, `layer.js`, `node.js`) is still used by the three older playground variants (`app.js`, `b-app.js`, `c-app.js`) but is slated for migration to WASM (see meml-dj9).
|
|
||||||
|
|
||||||
**Architecture:**
|
|
||||||
|
|
||||||
```
|
|
||||||
Main thread Worker thread
|
|
||||||
WasmIML (nisps-wasm.js) nisps-wasm-worker.js
|
|
||||||
├─ WASM instance A (persistent) └─ WASM instance B (lazy)
|
|
||||||
│ inference() — every rAF tick trainEx() — off-thread
|
|
||||||
│ inferBatch() — heatmap sampling returns: weights + loss curve
|
|
||||||
│ moveWeightsEx() — RL exploration
|
|
||||||
│ evalLoss() — non-destructive query
|
|
||||||
│ getLayerStats() — per-layer health
|
|
||||||
│ getWeights/setWeights — sync w/ worker
|
|
||||||
│
|
|
||||||
└─ Dataset (JS-side, dataset.js)
|
|
||||||
├─ FIFO ring buffer (max 100 examples)
|
|
||||||
└─ computeWeights() — recency/spatial/combined sample weighting
|
|
||||||
```
|
|
||||||
|
|
||||||
**WASM bindings** (`playground/wasm/nisps_bindings.cpp`) expose a flat C API compiled via Emscripten:
|
|
||||||
|
|
||||||
| Function | Purpose |
|
|
||||||
|----------|---------|
|
|
||||||
| `nisps_mlp_create/destroy` | Lifecycle |
|
|
||||||
| `nisps_mlp_inference` | Single forward pass |
|
|
||||||
| `nisps_mlp_infer_batch` | N forward passes in one call (heatmap) |
|
|
||||||
| `nisps_mlp_train` | SGD training, returns final loss only |
|
|
||||||
| `nisps_mlp_train_ex` | SGD training with full per-iteration loss curve |
|
|
||||||
| `nisps_mlp_draw_weights_spread` | Xavier-aware weight randomization |
|
|
||||||
| `nisps_mlp_move_weights_spread` | RL noise with weight decay |
|
|
||||||
| `nisps_mlp_move_weights_ex` | Same + native output pin mask |
|
|
||||||
| `nisps_mlp_eval_loss` | Forward pass + MSE, no weight update |
|
|
||||||
| `nisps_mlp_get_layer_stats` | Per-layer: mean|w|, max|w|, dead%, saturating% |
|
|
||||||
| `nisps_mlp_get/set_weights` | Flat weight serialization |
|
|
||||||
| `nisps_mlp_weight_count` | Total weight count |
|
|
||||||
|
|
||||||
**Building the WASM:**
|
|
||||||
```bash
|
|
||||||
cd playground/wasm && ./build.sh # requires emcc (Emscripten)
|
|
||||||
```
|
|
||||||
|
|
||||||
**Key difference from JS engine:** WASM uses float32 (not float64). The `spread`-aware `drawWeights`/`moveWeights` functions are implemented in the bindings file, not in nisps-core proper — they're playground-specific.
|
|
||||||
|
|
||||||
**Known issue:** Both the C++ `Train()` and WASM `train_ex` double-scale the loss when no sample weights are provided (each sample loss is weighted by 1/n, then the sum is multiplied by 1/n again). This is a backward-compat pattern from the C++ core (meml-ues).
|
|
||||||
|
|
||||||
### Debug Probe
|
|
||||||
|
|
||||||
The immersive app exposes `window.__nisps` when loaded with `?debug=1`. Used by Playwright e2e tests. Zero footprint in production.
|
|
||||||
|
|
||||||
| Method | Returns |
|
|
||||||
|--------|---------|
|
|
||||||
| `getOutputs()` | Current 126-element output vector |
|
|
||||||
| `getLoss()` | Last training loss (or null) |
|
|
||||||
| `getWeights()` | Flat weight array (~13K floats) |
|
|
||||||
| `getExampleCount()` | Number of training examples |
|
|
||||||
| `setInputs(x, y)` | Set joystick position + run inference |
|
|
||||||
| `thumbsUp()` / `thumbsDown()` | Trigger RL feedback |
|
|
||||||
| `train()` | Sync training with full UI update |
|
|
||||||
| `trainAsync()` | Async training (returns Promise) |
|
|
||||||
| `randomise()` | Randomize weights |
|
|
||||||
| `clearExamples()` | Clear dataset |
|
|
||||||
| `saveState()` | Force localStorage save |
|
|
||||||
| `evalLoss()` | Non-destructive loss query |
|
|
||||||
| `inferBatch(points)` | Batch inference |
|
|
||||||
| `getLayerStats()` | Per-layer weight health |
|
|
||||||
|
|
||||||
### URL Parameters
|
|
||||||
|
|
||||||
| Param | Range | Default | Effect |
|
|
||||||
|-------|-------|---------|--------|
|
|
||||||
| `tame` | 0–1 | 1 | Constrains synth output ranges toward safe limits |
|
|
||||||
| `spread` | 0–1 | 0.6 | Controls weight initialization, RL noise scaling, and weight decay (see below) |
|
|
||||||
| `preset` | preset id | _(none)_ | Auto-loads a synth parameter preset on first visit (e.g. `?preset=beginner-1`) |
|
|
||||||
|
|
||||||
#### `spread` — sigmoid saturation control
|
|
||||||
|
|
||||||
The MLP uses ReLU hidden layers with a sigmoid output layer. With uniform [-1,1] weights, the sum of many weighted inputs at each layer drives sigmoid pre-activations far from zero (std dev ≈ √fan_in), causing outputs to saturate near 0 or 1. The `spread` parameter addresses this:
|
|
||||||
|
|
||||||
- **`spread=0`** (polarised): Weights drawn from uniform [-1,1]. RL noise cap = 0.3. Noise applied uniformly across layers. Outputs cluster at extremes — good for exploration of radical mappings.
|
|
||||||
- **`spread=1`** (centered): Weights scaled by 1/√fan_in per layer (Xavier initialization). RL noise cap = 0.05. Noise also scaled per-layer. Weight decay prevents magnitude drift. Outputs spread across the full [0,1] range — better for fine-grained RL shaping.
|
|
||||||
- **Intermediate values** interpolate linearly between these two regimes.
|
|
||||||
|
|
||||||
Affects four code paths:
|
|
||||||
1. **`drawWeights(spread)`** — initial randomisation weight scale
|
|
||||||
2. **`moveWeights(speed, spread)`** — RL exploration noise scale per layer
|
|
||||||
3. **Weight decay in `moveWeights`** — each call decays weights by `10% * spread` before adding noise, preventing unbounded magnitude drift from repeated thumbs-down. At spread=0 there is no decay (original behavior). At spread=1, weights decay ~10% per call, creating a natural equilibrium where exploration noise and decay balance out rather than weights growing until sigmoid permanently saturates.
|
|
||||||
4. **Noise cap** in thumbs-down handler — `0.3*(1-spread) + 0.05*spread`
|
|
||||||
|
|
||||||
### C15 Parameter Map
|
|
||||||
|
|
||||||
The 126 synth parameters in `js/synth/param-map.js` were curated from the C15's 287 total parameters. Excluded categories:
|
|
||||||
|
|
||||||
| Excluded | Count | Reason |
|
|
||||||
|----------|-------|--------|
|
|
||||||
| Hardware Amount/Source | 56 | No physical MIDI hardware in browser |
|
|
||||||
| Macro Controls/Times | 12 | Meta-routing layer conflicts with direct ML control |
|
|
||||||
| Scale offsets | 13 | Microtuning would break pitch unpredictably |
|
|
||||||
| Key tracking (`*_KT`) | 11 | Pitch-dependent scaling needs calibrated defaults |
|
|
||||||
| Velocity (`*_Vel`) | 11 | Velocity-dependent, ML can't observe key velocity |
|
|
||||||
| Envelope mod depths (`*_Env_A/B/C`) | 19 | Multiplicative interaction with envelope shapes makes space too hard to learn |
|
|
||||||
| Discrete/structural | 15 | Osc Pitch (full sweep), Master Vol/Tune, Voice Mute/Fade, Unison Voices, Mono modes, Split, Osc Reset |
|
|
||||||
| Secondary config | 7 | Att Curve, Elevate, Chirp, Decay Gate, Retrigger |
|
|
||||||
| PM shaper blend | 4 | Secondary routing params |
|
|
||||||
| FB Mix source selects | 4 | Discrete A/B selectors |
|
|
||||||
|
|
||||||
### Synth Presets
|
|
||||||
|
|
||||||
Presets (`js/synth/presets.js`) control which parameters the ML engine can modify, with unselected params muted at safe defaults. Each preset defines per-param `{ muted, fixedValue, min, max, curve }` — no training examples or model weights.
|
|
||||||
|
|
||||||
4 tiers of progressive complexity:
|
|
||||||
|
|
||||||
| Tier | Presets | Active params | What's exposed |
|
|
||||||
|------|---------|---------------|----------------|
|
|
||||||
| 1 (Beginner) | 1.1–1.4 | 15 | Basic ADSR, SVF cutoff/res, Shaper A drive/fold, output levels, reverb mix |
|
|
||||||
| 2 (Intermediate) | 2.1–2.4 | 40 | + Env B/C, filter FM, effects (reverb/echo/flanger), cabinet, stereo panning |
|
|
||||||
| 3 (Advanced) | 3.1–3.3 | ~95 | + Cross-oscillator PM, feedback mixer, dual shapers, comb/gap filters, ring mod |
|
|
||||||
| 4 (Expert) | 4.1–4.2 | 126 | Full engine |
|
|
||||||
|
|
||||||
Presets use `curve` values to bias parameter distributions (< 0.5 = spend more time low, > 0.5 = bias high) without clamping extremes. Users can tweak any preset via the group drawer after loading.
|
|
||||||
|
|
||||||
### Control Surface (Phase 1)
|
|
||||||
|
|
||||||
The immersive app (`a-immersive.html`) has a control surface system for tuning how exploration and learning feel. Full spec: `playground/SPEC-controls.md`.
|
|
||||||
|
|
||||||
**Architecture** — modular ES modules organized by phase, wired into `a-app.js`:
|
|
||||||
|
|
||||||
| Module | Phase | Purpose |
|
|
||||||
|--------|-------|---------|
|
|
||||||
| `js/ui/input-pipeline.js` | 1 | Processes raw joystick input through deadzone → zoom → curve → smoothing → momentum-as-zoom. Pure math, no DOM. |
|
|
||||||
| `js/ui/control-surface.js` | 1 | Compound axes (Boldness, Memory, Precision) that map single sliders to multiple underlying params. Offset-based override resolution (trim-pot model). 6 built-in control presets. |
|
|
||||||
| `js/ui/control-surface-ui.js` | 1 | DOM layer: 3 axis sliders on floating bar, gear icon settings drawer with per-param overrides. Injects its own CSS. |
|
|
||||||
| `js/ui/joy-map-enhanced.js` | 1 | Enhanced joy-map canvas: zoom minimap with adaptive grid, vanishing trail with Catmull-Rom spline and tap-to-return, dual concentric noise rings, frozen state overlay. |
|
|
||||||
| `js/ui/snapshot-stack.js` | 2 | Ring buffer (20 max) of weight snapshots. Auto-snapshot on train/randomize/thumbs-down. Multi-level undo. |
|
|
||||||
| `js/ui/ab-compare.js` | 2 | Rapid A/B weight state comparison. Capture, toggle, accept or revert. |
|
|
||||||
| `js/ui/region-pin.js` | 2 | Pins rectangular input-space regions (Approach A: example pinning). Pinned examples always included in training. |
|
|
||||||
| `js/ui/param-pin.js` | 2 | Per-output pin flags. Pin mask passed to `moveWeights()` to skip pinned output nodes. |
|
|
||||||
| `js/ui/phase2-ui.js` | 2 | DOM: undo button with history popup, A/B toggle, region pin via long-press, param pin via double-tap. |
|
|
||||||
| `js/ui/pressure-feedback.js` | 3 | Touch force + hold duration → intensity multiplier for noise growth/decay. |
|
|
||||||
| `js/ui/auto-explore.js` | 3 | Automated thumbs-down at configurable interval. Zoom-scaled intensity. |
|
|
||||||
| `js/ui/input-heatmap.js` | 3 | 2D color field sampling MLP across input space. 3 color modes, zoom-aware resampling. Supports `inferBatchFn` for single-call WASM batch inference. |
|
|
||||||
| `js/ui/phase3-ui.js` | 3 | DOM: auto-explore toggle with progress ring, heatmap eye icon, pressure indicators. |
|
|
||||||
| `js/ui/output-pipeline.js` | 4 | Global curve → smoothing → slew rate → freeze gate on MLP outputs before synth/visual routing. |
|
|
||||||
| `js/ui/weight-health.js` | 4 | Weight magnitude histogram, dead/saturating/healthy status detection, ambient visualization. |
|
|
||||||
| `js/ui/gradient-flow.js` | 4 | Per-layer weight-delta analysis after training. Vanishing/exploding/converged detection. |
|
|
||||||
| `js/ui/session-presets.js` | 4 | Save/load full session state. URL sharing via compact params. |
|
|
||||||
| `js/ui/phase4-ui.js` | 4 | DOM: freeze button, network health panel, session preset UI, output pipeline slider wiring. |
|
|
||||||
|
|
||||||
**Compound Axes** — each controls 4-6 underlying parameters via interpolation tables:
|
|
||||||
|
|
||||||
- **Boldness** (Caution ↔ Bold): input zoom, noise cap, noise growth, learning rate, weight decay, noise distribution
|
|
||||||
- **Memory** (Amnesia ↔ Elephant): max examples, example decay, weight decay, noise decay, convergence threshold
|
|
||||||
- **Precision** (Raw ↔ Precise): input curve, deadzone, smoothing, slew rate, momentum-zoom mode
|
|
||||||
|
|
||||||
When a user manually overrides an individual param, the offset from the axis-derived value persists as the axis moves (like a trim pot on a mixing desk). Double-tap an axis to re-link all params.
|
|
||||||
|
|
||||||
**Input Pipeline** — sits between physical joystick and MLP. Key feature: **zoom** narrows the effective input window around an anchor point (`effective = anchor + (raw - 0.5) * zoom_level`). Zoom-at-zero freezes input. Three anchor modes: auto (anchor follows current position when zoom changes), sticky (explicit anchor), center (always 0.5).
|
|
||||||
|
|
||||||
**Control Presets**: Default, First Touch, Jazz Hands, Sculptor, Improviser, Microscope. These set compound axis positions — they don't include network weights or synth preset selection.
|
|
||||||
|
|
||||||
**Integration** — the control surface dispatches `controlsurface:change` CustomEvents. `a-app.js` listens and updates the input pipeline config, spread level, and RL parameters (noise cap, growth, decay, floor, zoom-aware feedback scaling). Pipeline-processed coordinates are cached (`_lastPipeX/Y`) so `getCurrentInputs()` and `setCurrentInputs()` use the same values the MLP sees. State is persisted to localStorage alongside existing app state.
|
|
||||||
|
|
||||||
**Remaining**: Engine configuration panel (Part 8 of spec) — network architecture, loss function, optimizer selection.
|
|
||||||
|
|
||||||
## Testing
|
|
||||||
|
|
||||||
Playwright e2e tests cover the immersive app's ML engine, UI state machines, input pipeline, and persistence. Tests run headless Chromium against a Python HTTP server.
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# Run all tests (starts server automatically on port 7331)
|
|
||||||
npx playwright test
|
|
||||||
|
|
||||||
# Run with browser visible
|
|
||||||
npx playwright test --headed
|
|
||||||
|
|
||||||
# Run a specific test file
|
|
||||||
npx playwright test tests/e2e/ml-engine.spec.js
|
|
||||||
```
|
|
||||||
|
|
||||||
**Test files** (`tests/e2e/`):
|
|
||||||
|
|
||||||
| File | Coverage |
|
|
||||||
|------|----------|
|
|
||||||
| `ml-engine.spec.js` | WASM inference bounds, training loss, thumbs up/down, async training, example capture |
|
|
||||||
| `ui-interactions.spec.js` | Drawer open/close, mode switching, heatmap bars, presets, keyboard shortcuts (1/2/Z) |
|
|
||||||
| `input-pipeline.spec.js` | Input→output variation, clamping, joystick drag, post-training bounds |
|
|
||||||
| `persistence.spec.js` | URL params (?preset, ?spread), localStorage round-trip |
|
|
||||||
| `wasm-api.spec.js` | Batch inference, evalLoss, getLayerStats, loss history curve, pin mask |
|
|
||||||
|
|
||||||
Tests use the `?debug=1` probe (`window.__nisps`) for programmatic access to the ML engine. The `helpers.js` module provides `loadApp(page)` which clears localStorage, sets `nisps-help-seen`, and waits for WASM initialization.
|
|
||||||
|
|
||||||
## Build System
|
|
||||||
|
|
||||||
This is an Arduino project targeting Raspberry Pi Pico. Build and upload using Arduino IDE or arduino-cli with the earlephilhower/pico board package.
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# Initialize submodules (required for memllib and memlp)
|
|
||||||
git submodule update --init --recursive
|
|
||||||
|
|
||||||
# Build (adjust port as needed)
|
|
||||||
arduino-cli compile --fqbn rp2040:rp2040:rpipico -b 115200 MEMLNaut-NISPS.ino
|
|
||||||
arduino-cli upload --fqbn rp2040:rp2040:rpipico -p /dev/ttyACM0 MEMLNaut-NISPS.ino
|
|
||||||
```
|
|
||||||
|
|
||||||
## Architecture
|
|
||||||
|
|
||||||
### Dual-Core Design
|
|
||||||
|
|
||||||
The RP2040's dual cores are used for separation of concerns:
|
|
||||||
- **Core 0**: UI loop, ML inference, hardware interface polling (5ms period)
|
|
||||||
- **Core 1**: Real-time audio processing, parameter updates, MIDI polling
|
|
||||||
|
|
||||||
Inter-core synchronization uses memory barriers (`MEMORY_BARRIER()`, `WRITE_VOLATILE()`, `READ_VOLATILE()`) and RP2040 queues (`queue_t`).
|
|
||||||
|
|
||||||
### Mode System
|
|
||||||
|
|
||||||
The active mode is selected at compile-time via `#define MEMLNAUT_MODE_TYPE` in `MEMLNaut-NISPS.ino`. Modes implement the `MEMLNautMode` concept (see `modes/MEMLNautMode.hpp`):
|
|
||||||
|
|
||||||
| Mode | Purpose |
|
|
||||||
|------|---------|
|
|
||||||
| `MEMLNautModeChannelStrip` | Audio channel strip (EQ, compression, gain staging) |
|
|
||||||
| `MEMLNautModePAFSynth` | PAF (Phase Aligned Formant) synthesis with MIDI |
|
|
||||||
| `MEMLNautModeXIASRI` | Audio-reactive mode using machine listening analysis |
|
|
||||||
| `MEMLNautModeSoundAnalysisMIDI` | Sound analysis with MIDI output |
|
|
||||||
|
|
||||||
### Voice Spaces
|
|
||||||
|
|
||||||
Voice spaces map ML output parameters to audio engine parameters. They are defined as lambda functions that translate a normalized parameter array into synthesizer/processor settings. See `voicespaces/` for examples:
|
|
||||||
- PAF synth presets: `VoiceSpace1.hpp`, `VoiceSpaceQuadDetune.hpp`, etc.
|
|
||||||
- Channel strip presets: `voicespaces/ChannelStrip/basic.hpp` (Neve, SSL emulations)
|
|
||||||
|
|
||||||
### Key Components
|
|
||||||
|
|
||||||
- **IMLInterface** (`IMLInterface.hpp`): Interactive ML interface using an MLP for inference/training
|
|
||||||
- **InterfaceRL**: Reinforcement learning interface from memllib that handles joystick input and learning
|
|
||||||
- **AudioAppBase**: Template base class for audio applications
|
|
||||||
- **XiasriAnalysis**: Real-time audio feature extraction (pitch, aperiodicity, energy, brightness)
|
|
||||||
|
|
||||||
### Submodules (in `src/`)
|
|
||||||
|
|
||||||
- **memllib**: Hardware abstraction, audio drivers, synth components, RL interfaces
|
|
||||||
- **memlp**: MLP (Multi-Layer Perceptron) implementation for embedded ML
|
|
||||||
- **daisysp**: DSP library (filters, drums, effects, synthesis)
|
|
||||||
|
|
||||||
## Memory Sections
|
|
||||||
|
|
||||||
The codebase uses RP2040-specific memory placement:
|
|
||||||
- `AUDIO_MEM` / `AUDIO_FUNC`: Place audio-critical code/data in SRAM
|
|
||||||
- `APP_SRAM` / `__not_in_flash("app")`: Keep frequently-accessed data out of flash
|
|
||||||
|
|
||||||
## Audio Parameters
|
|
||||||
|
|
||||||
Sample rate is defined in `AudioDriver::GetSampleRate()`. The audio callback `audio_block_callback` runs on Core 1 and processes stereo audio (`stereosample_t`).
|
|
||||||
1
CLAUDE.md
Symbolic link
1
CLAUDE.md
Symbolic link
|
|
@ -0,0 +1 @@
|
||||||
|
AGENTS.md
|
||||||
|
|
@ -1,641 +0,0 @@
|
||||||
#ifndef __CHANNEL_STRIP_AUDIO_APP_HPP__
|
|
||||||
#define __CHANNEL_STRIP_AUDIO_APP_HPP__
|
|
||||||
|
|
||||||
#include "src/memllib/audio/AudioAppBase.hpp" // Added missing include
|
|
||||||
#include "src/memllib/synth/maximilian.h" // Added missing include for maxiSettings, maxiOsc, maxiTrigger, maxiDelayline, maxiEnvGen, maxiLine
|
|
||||||
|
|
||||||
#include <cstddef>
|
|
||||||
#include <cstdint>
|
|
||||||
#include <memory> // Added for std::shared_ptr
|
|
||||||
|
|
||||||
#include "src/memllib/synth/maxiPAF.hpp"
|
|
||||||
#include "src/memllib/synth/ADSRLite.hpp"
|
|
||||||
#include "src/memllib/interface/InterfaceBase.hpp" // Added missing include
|
|
||||||
|
|
||||||
#include <span>
|
|
||||||
#include "voicespaces/VoiceSpaces.hpp"
|
|
||||||
|
|
||||||
#include "voicespaces/ChannelStrip/basic.hpp"
|
|
||||||
|
|
||||||
template<size_t BUFSIZE>
|
|
||||||
class maxiRingBufLite {
|
|
||||||
public:
|
|
||||||
maxiRingBufLite();
|
|
||||||
|
|
||||||
/*!Add the latest value to the buffer \param x A value*/
|
|
||||||
__force_inline void push(float x) {
|
|
||||||
buf[idx] = x;
|
|
||||||
idx++;
|
|
||||||
if (idx==BUFSIZE) {
|
|
||||||
idx=0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*! \returns The size of the buffer*/
|
|
||||||
size_t size() {return BUFSIZE;}
|
|
||||||
|
|
||||||
/*! \returns the value at the front of the buffer*/
|
|
||||||
__force_inline float head() {return idx == 0 ? buf[BUFSIZE-1] : buf[idx-1];}
|
|
||||||
|
|
||||||
/*! \returns the oldest value in the buffer, for a particular window size \param N The size of the window, N < the size of the buffer*/
|
|
||||||
__force_inline float tail(const size_t N) {
|
|
||||||
float val=0;
|
|
||||||
if (idx >= N) {
|
|
||||||
val = buf[idx-N];
|
|
||||||
}else{
|
|
||||||
size_t tailIdx = BUFSIZE - (N-idx);
|
|
||||||
val = buf[tailIdx];
|
|
||||||
}
|
|
||||||
return val;
|
|
||||||
}
|
|
||||||
|
|
||||||
using reduceFunction = std::function<float(float, float)>;
|
|
||||||
/**
|
|
||||||
* Apply a function of the previous N values in the buffer
|
|
||||||
* \param N The number of values in the window
|
|
||||||
* \param func A function in the form float func(float previousResult, float nextValue)
|
|
||||||
* \param initval The initial value to pass into the function (usually 0)
|
|
||||||
* \returns The last result of the function, after passing in all values from the window
|
|
||||||
* Example: this function will sum the values in the window:
|
|
||||||
* auto sumfunc = [](float val, float n) {return val + n;};
|
|
||||||
*/
|
|
||||||
float reduce(size_t N, reduceFunction func, float initval) {
|
|
||||||
float val=0;
|
|
||||||
if (idx >= N) {
|
|
||||||
for(size_t i=idx-N; i < idx; i++) {
|
|
||||||
val = func(val, buf[i]);
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
//first chunk
|
|
||||||
for(size_t i=F64_ARRAY_SIZE(buf)-(N-idx); i < buf.size(); i++) {
|
|
||||||
val = func(val, buf[i]);
|
|
||||||
}
|
|
||||||
//second chunk
|
|
||||||
for(int i=0; i < idx; i++) {
|
|
||||||
val = func(val, buf[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return val;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::array<float, BUFSIZE> buf{};
|
|
||||||
size_t idx=0;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
// /**
|
|
||||||
// * Calculate the Root Mean Square of a signal over a window of time
|
|
||||||
// * This is a good measurement of the amount of power in a signal
|
|
||||||
// */
|
|
||||||
// template<size_t BUFSIZE>
|
|
||||||
// class maxiRMSLite {
|
|
||||||
// public:
|
|
||||||
// maxiRMS();
|
|
||||||
|
|
||||||
// /*!Configure the analyser \param maxLength The maximum length of time to analyse (ms) \param windowSize The size of the window of time to analyse initially (ms, <= maxLength) */
|
|
||||||
// void setup(float maxLength, float windowSize) {
|
|
||||||
// buf.setup(maxiConvert::msToSamps(maxLength));
|
|
||||||
// setWindowSize(windowSize);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// /*!Set the size of the analysis window \param newWindowSize the size of the analysis window (in ms). Large values will smooth out the measurement, and make it less responsive to transients*/
|
|
||||||
// void setWindowSize(float newWindowSize) {
|
|
||||||
// size_t windowSizeInSamples = maxiConvert::msToSamps(newWindowSize);
|
|
||||||
// if (windowSizeInSamples <= buf.size() && windowSizeInSamples > 0) {
|
|
||||||
// windowSize = windowSizeInSamples;
|
|
||||||
// windowSizeInv = 1.f / static_cast<float>(windowSize);
|
|
||||||
// }
|
|
||||||
// runningRMS = 0;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// /*!Find out the size of the analysis window (in ms)*/
|
|
||||||
// float getWindowSize() {
|
|
||||||
// return maxiConvert::sampsToMs(windowSize);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// /*Analyse the signal \param signal a signal \returns RMS*/
|
|
||||||
// float play(float signal) {
|
|
||||||
// float sigPow2 = (signal * signal);
|
|
||||||
// runningRMS -= buf.tail(windowSize);
|
|
||||||
// buf.push(sigPow2);
|
|
||||||
// runningRMS += sigPow2;
|
|
||||||
// return sqrtf(runningRMS * windowSizeInv);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// private:
|
|
||||||
// maxiRingBuf<BUFSIZE> buf;
|
|
||||||
// size_t windowSize=BUFSIZE; // in samples
|
|
||||||
// float windowSizeInv=1.f/BUFSIZE;
|
|
||||||
// float runningRMS=0;
|
|
||||||
// };
|
|
||||||
|
|
||||||
class maxiDynamicsLite {
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
enum ANALYSERS {PEAK, RMS};
|
|
||||||
|
|
||||||
static constexpr float maxRMSSizeMS = 300.f;
|
|
||||||
|
|
||||||
maxiDynamicsLite() {
|
|
||||||
//define detector functions
|
|
||||||
inputPeak = [](float sig) {
|
|
||||||
return abs(sig);
|
|
||||||
};
|
|
||||||
|
|
||||||
rms.setup(maxRMSSizeMS,300);
|
|
||||||
inputRMS = [&](float sig) {
|
|
||||||
return rms.play(sig);
|
|
||||||
};
|
|
||||||
|
|
||||||
//default RMS
|
|
||||||
inputAnalyser = inputRMS;
|
|
||||||
|
|
||||||
//setup envelopes
|
|
||||||
arEnvHigh.setup(10,0,1.f,10.f, maxiSettings::sampleRate);
|
|
||||||
arEnvLow.setup(10,0,1.f,10.f, maxiSettings::sampleRate);
|
|
||||||
|
|
||||||
lookAheadDelay.setup(maxiSettings::sampleRate * 0.1); //max 0.1s
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This functions compands the signal, providing download compression or upward expansion above an upper thresold, and
|
|
||||||
* upward compression or downward expansion below a lower threshold.
|
|
||||||
* \param sig The input signal to be companded
|
|
||||||
* \param control This signal is used to trigger the compander. Use it for sidechaining, or if no sidechain is needed, use the same signal for this and the input signal
|
|
||||||
* \param thresholdHigh The high threshold, in Dbs
|
|
||||||
* \param ratioHigh The ratio for companding above the high threshold
|
|
||||||
* \param kneeHigh The size of the knee for companding above the high threshold (in Dbs)
|
|
||||||
* \param thresholdLow The low threshold, in Dbs
|
|
||||||
* \param ratioLow The ratio for companding below the low threshold
|
|
||||||
* \param kneeLow The size of the knee for companding below the low threshold (in Dbs)
|
|
||||||
* \returns a companded signal
|
|
||||||
*/
|
|
||||||
__attribute__((always_inline)) __attribute__((hot)) float play(float sig, float control,
|
|
||||||
float thresholdHigh, float ratioHigh, float kneeHigh,
|
|
||||||
float thresholdLow, float ratioLow, float kneeLow
|
|
||||||
) {
|
|
||||||
const float inputEnv = inputAnalyser(control) + 0.00001f; //avoid log of zero
|
|
||||||
const float controlDB = maxiConvert::ampToDbs(inputEnv);
|
|
||||||
float outDB = controlDB;
|
|
||||||
const float halfKneeHigh = kneeHigh * 0.5f;
|
|
||||||
//companding above the high threshold
|
|
||||||
if (ratioHigh > 0) {
|
|
||||||
if (kneeHigh > 0) {
|
|
||||||
float lowerKnee = thresholdHigh - (kneeHigh*0.5f);
|
|
||||||
float higherKnee = thresholdHigh +(kneeHigh*0.5f);
|
|
||||||
//attack/release
|
|
||||||
float envRatio = 1.f;
|
|
||||||
if (controlDB >= lowerKnee) {
|
|
||||||
arEnvHigh.triggerIfReady(1.f);
|
|
||||||
float envVal = arEnvHigh.play();
|
|
||||||
envRatio = envToRatio(envVal, ratioHigh);
|
|
||||||
}else {
|
|
||||||
arEnvHigh.release();
|
|
||||||
}
|
|
||||||
if ((controlDB >= lowerKnee) && (controlDB < higherKnee)) {
|
|
||||||
float kneeHighOut = ((higherKnee - thresholdHigh) / envRatio) + thresholdHigh;
|
|
||||||
float kneeRange = (kneeHighOut - lowerKnee);
|
|
||||||
float t = (controlDB - lowerKnee) / kneeHigh;
|
|
||||||
//bezier on x only
|
|
||||||
float curve = ratioHigh > 1.f ? 0.8f : 0.2f;
|
|
||||||
float kneex = (2.f * (1.f-t) * t * curve) + (t*t);
|
|
||||||
outDB = lowerKnee + (kneex * kneeRange);
|
|
||||||
}
|
|
||||||
else if (controlDB >= higherKnee) {
|
|
||||||
outDB = ((controlDB - thresholdHigh) / envRatio) + thresholdHigh;
|
|
||||||
}else{
|
|
||||||
outDB = controlDB;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
//no knee
|
|
||||||
if (controlDB > thresholdHigh) {
|
|
||||||
arEnvHigh.trigger(1.f);
|
|
||||||
}else {
|
|
||||||
arEnvHigh.release();
|
|
||||||
}
|
|
||||||
float envVal = arEnvHigh.play();
|
|
||||||
// const float envVal = arEnvHigh.play(controlDB > thresholdHigh ? 1.f : 0.f);
|
|
||||||
const float envRatio = envToRatio(envVal, ratioHigh);
|
|
||||||
outDB = ((controlDB - thresholdHigh) / envRatio) + thresholdHigh;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// //companding below the low threshold
|
|
||||||
// if (ratioLow > 0) {
|
|
||||||
// if (kneeLow > 0) {
|
|
||||||
// float lowerKnee = thresholdLow - (kneeLow*0.5f);
|
|
||||||
// float higherKnee = thresholdLow +(kneeLow*0.5f);
|
|
||||||
// //attack/release
|
|
||||||
// float envRatio = 1;
|
|
||||||
// if (controlDB < lowerKnee) {
|
|
||||||
// float envVal = arEnvLow.play(1.f);
|
|
||||||
// envRatio = envToRatio(envVal, ratioLow);
|
|
||||||
// }else {
|
|
||||||
// float envVal = arEnvLow.play(-1.f);
|
|
||||||
// }
|
|
||||||
// if ((controlDB >= lowerKnee) && (controlDB < higherKnee)) {
|
|
||||||
// float kneeLowOut = thresholdLow - ((thresholdLow-lowerKnee) / ratioLow);
|
|
||||||
// float kneeRange = (higherKnee - kneeLowOut);
|
|
||||||
// float t = (controlDB - lowerKnee) / kneeLow;
|
|
||||||
// //bezier on x only
|
|
||||||
// float curve = ratioLow > 1.f ? 0.2f : 0.8f;
|
|
||||||
// float kneex = (2.f * (1.f-t) * t * curve) + (t*t);
|
|
||||||
// outDB = kneeLowOut + (kneex * kneeRange);
|
|
||||||
// }
|
|
||||||
// else if (controlDB < lowerKnee) {
|
|
||||||
// outDB = thresholdLow - ((thresholdLow-controlDB) / ratioLow);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// else {
|
|
||||||
// //no knee
|
|
||||||
// if (controlDB < thresholdLow) {
|
|
||||||
// float envVal = arEnvLow.play(1.f);
|
|
||||||
// // float envRatio = envToRatio(envVal, ratioLow);
|
|
||||||
// outDB = thresholdLow - ((thresholdLow-controlDB) / ratioLow);
|
|
||||||
// }else {
|
|
||||||
// float envVal = arEnvLow.play(-1.f);
|
|
||||||
// outDB = maxiConvert::ampToDbs(fabsf(sig));
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//scale the signal according to the amount of compansion on the control signal
|
|
||||||
float outAmp = maxiConvert::dbsToAmp(outDB);
|
|
||||||
// float ctrlAmp = maxiConvert::dbsToAmp(controlDB);
|
|
||||||
float sigOut = sig;
|
|
||||||
if (outAmp > 0.f) {
|
|
||||||
if (lookAheadSize > 0.f) {
|
|
||||||
lookAheadDelay.push(sig);
|
|
||||||
sigOut = lookAheadDelay.tail(lookAheadSize);
|
|
||||||
}
|
|
||||||
// sigOut = sigOut * fabsf(control / outAmp);
|
|
||||||
float gainReduction = outAmp / inputEnv;
|
|
||||||
sigOut = sig * gainReduction;
|
|
||||||
// PERIODIC_DEBUG(1000,
|
|
||||||
// Serial.printf("%f %f %f %f %f\n",controlDB, outDB, control, outAmp, gainReduction);
|
|
||||||
// )
|
|
||||||
}else{
|
|
||||||
// printf("Warning: maxiDynamicsLite output amplitude is zero or negative!\n");
|
|
||||||
}
|
|
||||||
return sigOut;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Compress a signal (using downward compression)
|
|
||||||
* \param sig The input signal to be compressed
|
|
||||||
* \param threshold The threshold, in Dbs
|
|
||||||
* \param ratio The compression ratio (>1 provides compression, <1 provides expansion)
|
|
||||||
* \param knee The size of the knee (in Dbs)
|
|
||||||
* \returns a compressed signal
|
|
||||||
*/
|
|
||||||
__attribute__((always_inline)) __attribute__((hot)) float compress(float sig, float threshold, float ratio, float knee) {
|
|
||||||
return play(sig, sig, threshold, ratio, knee, 0.f, 0.f, 0.f);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Compress a signal with sidechaining (using downward compression)
|
|
||||||
* \param sig The input signal to be compressed
|
|
||||||
* \param control The sidechain signal
|
|
||||||
* \param threshold The threshold, in Dbs
|
|
||||||
* \param ratio The compression ratio (>1 provides compression, <1 provides expansion)
|
|
||||||
* \param knee The size of the knee (in Dbs)
|
|
||||||
* \returns a compressed signal
|
|
||||||
*/
|
|
||||||
float sidechainCompress(float sig, float control, float threshold, float ratio, float knee) {
|
|
||||||
return play(sig, control, threshold, ratio, knee, 0, 0, 0);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Compand a signal, using detection above a threshold (provides downward compression or upward expansion)
|
|
||||||
* \param sig The input signal to be compressed
|
|
||||||
* \param control The sidechain signal
|
|
||||||
* \param threshold The threshold, in Dbs
|
|
||||||
* \param ratio The compression ratio (>1 provides compression, <1 provides expansion)
|
|
||||||
* \param knee The size of the knee (in Dbs)
|
|
||||||
* \returns a companded signal
|
|
||||||
*/
|
|
||||||
float compandAbove(float sig, float control, float threshold, float ratio, float knee) {
|
|
||||||
return play(sig, control, threshold, ratio, knee, 0, 0, 0);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Compand a signal, using detection below a threshold (provides upward compression or downward expansion)
|
|
||||||
* \param sig The input signal to be compressed
|
|
||||||
* \param control The sidechain signal
|
|
||||||
* \param threshold The threshold, in Dbs
|
|
||||||
* \param ratio The compression ratio (>1 provides compression, <1 provides expansion)
|
|
||||||
* \param knee The size of the knee (in Dbs)
|
|
||||||
* \returns a companded signal
|
|
||||||
*/
|
|
||||||
float compandBelow(float sig, float control, float threshold, float ratio, float knee) {
|
|
||||||
return play(sig, control, 0, 0, 0, threshold, ratio, knee);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the attack time for the high threshold. This is the amount of time over which the ratio moves from 1 to its full value, following the input analyser going over the threshold.
|
|
||||||
* \param attack The attack time (in milliseconds)
|
|
||||||
*/
|
|
||||||
__attribute__((always_inline)) void setAttackHigh(float attack) {
|
|
||||||
arEnvHigh.setAttackTime(attack, maxiSettings::sampleRate);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Set the release time for the high threshold. This is the amount of time over which the ratio moves from its full value to 1, following the input analyser going under the threshold.
|
|
||||||
* \param release The release time (in milliseconds)
|
|
||||||
*/
|
|
||||||
__attribute__((always_inline)) void setReleaseHigh(float release) {
|
|
||||||
arEnvHigh.setReleaseTime(release, maxiSettings::sampleRate);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Set the attack time for the low threshold. This is the amount of time over which the ratio moves from 1 to its full value, following the input analyser going under the threshold.
|
|
||||||
* \param attack The attack time (in milliseconds)
|
|
||||||
*/
|
|
||||||
__attribute__((always_inline)) void setAttackLow(float attack) {
|
|
||||||
arEnvLow.setAttackTime(attack, maxiSettings::sampleRate);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Set the release time for the low threshold. This is the amount of time over which the ratio moves from its full value to 1, following the input analyser going over the threshold.
|
|
||||||
* \param release The release time (in milliseconds)
|
|
||||||
*/
|
|
||||||
__attribute__((always_inline)) void setReleaseLow(float release) {
|
|
||||||
arEnvLow.setReleaseTime(release, maxiSettings::sampleRate);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The look ahead creates a delay on the input signal, meaning that that the signal is compressed according to event that have already happened in the control signal. This can be useful for limiting and catching fast transients.
|
|
||||||
* \param length The amount of time the compressor looks ahead (in milliseconds)
|
|
||||||
*/
|
|
||||||
void setLookAhead(float length) {
|
|
||||||
lookAheadSize = maxiConvert::msToSamps(length);
|
|
||||||
lookAheadSize = std::min(lookAheadSize, lookAheadDelay.size());
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* \returns the look ahead time (in milliseconds)
|
|
||||||
*/
|
|
||||||
float getLookAhead() {
|
|
||||||
return maxiConvert::sampsToMs(lookAheadSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the size of the RMS window. Longer times give a slower response
|
|
||||||
* \param winSize The size of the window (in milliseconds)
|
|
||||||
*/
|
|
||||||
void setRMSWindowSize(float winSize) {
|
|
||||||
rms.setWindowSize(std::min(winSize, maxRMSSizeMS));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the method by which the compressor analyses the control input
|
|
||||||
* \mode maxiDynamics::PEAK for peak analysis, maxiDynamics::RMS for rms analysis
|
|
||||||
*/
|
|
||||||
void setInputAnalyser(ANALYSERS mode) {
|
|
||||||
if (mode == PEAK) {
|
|
||||||
inputAnalyser = inputPeak;
|
|
||||||
}else{
|
|
||||||
inputAnalyser = inputRMS;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
|
||||||
ADSRLite arEnvHigh, arEnvLow;
|
|
||||||
maxiRingBuf lookAheadDelay;
|
|
||||||
size_t lookAheadSize = 0;
|
|
||||||
maxiRMS rms;
|
|
||||||
std::function<float(float)> inputPeak;
|
|
||||||
std::function<float(float)> inputRMS;
|
|
||||||
std::function<float(float)> inputAnalyser;
|
|
||||||
// maxiPoll poll;
|
|
||||||
|
|
||||||
//mapping from attack/release envelope to ratio
|
|
||||||
inline float envToRatio(float envVal, float ratio) {
|
|
||||||
float envRatio = 1.f;
|
|
||||||
if (ratio > 1.f) {
|
|
||||||
envRatio = 1.f + ((ratio-1.f) * envVal);
|
|
||||||
}else {
|
|
||||||
envRatio = 1.f - ((1.f-ratio) * envVal);
|
|
||||||
}
|
|
||||||
return envRatio;
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
template<size_t NPARAMS=24>
|
|
||||||
class ChannelStripAudioApp : public AudioAppBase<NPARAMS>
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static constexpr size_t kN_Params = NPARAMS;
|
|
||||||
static constexpr size_t nVoiceSpaces=6;
|
|
||||||
|
|
||||||
enum class controlMessages {
|
|
||||||
MSG_BYPASS_ALL=0,
|
|
||||||
MSG_BYPASS_EQ,
|
|
||||||
MSG_BYPASS_COMP,
|
|
||||||
MSG_BYPASS_PREPOSTGAIN,
|
|
||||||
MSG_BYPASS_INFILTERS,
|
|
||||||
};
|
|
||||||
|
|
||||||
queue_t controlMessageQueue;
|
|
||||||
|
|
||||||
std::array<VoiceSpace<NPARAMS>, nVoiceSpaces> voiceSpaces;
|
|
||||||
|
|
||||||
VoiceSpaceFn<NPARAMS> currentVoiceSpace;
|
|
||||||
|
|
||||||
std::array<String, nVoiceSpaces> getVoiceSpaceNames() {
|
|
||||||
std::array<String, nVoiceSpaces> names;
|
|
||||||
for(size_t i=0; i < voiceSpaces.size(); i++) {
|
|
||||||
names[i] = voiceSpaces[i].name;
|
|
||||||
}
|
|
||||||
return names;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setVoiceSpace(size_t i) {
|
|
||||||
if (i < voiceSpaces.size()) {
|
|
||||||
currentVoiceSpace = voiceSpaces[i].mappingFunction;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ChannelStripAudioApp() : AudioAppBase<NPARAMS>() {
|
|
||||||
|
|
||||||
auto voiceSpaceNeve66 = [this](const std::array<float, NPARAMS>& params) {
|
|
||||||
VOICE_SPACE_CHSTRIP_NEVE66_BODY
|
|
||||||
};
|
|
||||||
auto voiceSpaceSSL4K = [this](const std::array<float, NPARAMS>& params) {
|
|
||||||
VOICE_SPACE_CHSTRIP_SSL4KGIST_BODY
|
|
||||||
};
|
|
||||||
auto voiceSpaceMaleVox = [this](const std::array<float, NPARAMS>& params) {
|
|
||||||
VOICE_SPACE_CHSTRIP_MALE_VOX_BODY
|
|
||||||
};
|
|
||||||
auto voiceSpaceFemaleVox = [this](const std::array<float, NPARAMS>& params) {
|
|
||||||
VOICE_SPACE_CHSTRIP_FEMALE_VOX_BODY
|
|
||||||
};
|
|
||||||
auto voiceSpaceSSL9K = [this](const std::array<float, NPARAMS>& params) {
|
|
||||||
VOICE_SPACE_CHSTRIP_SSL9KINDA_BODY
|
|
||||||
};
|
|
||||||
auto voiceSpaceNeve80 = [this](const std::array<float, NPARAMS>& params) {
|
|
||||||
VOICE_SPACE_CHSTRIP_NEVE_80
|
|
||||||
};
|
|
||||||
voiceSpaces[0] = {"WannabeNeve66", voiceSpaceNeve66};
|
|
||||||
voiceSpaces[1] = {"SSL 4K G-ist", voiceSpaceSSL4K};
|
|
||||||
voiceSpaces[2] = {"SSL 9K-inda", voiceSpaceSSL9K};
|
|
||||||
voiceSpaces[3] = {"MaleVox", voiceSpaceMaleVox};
|
|
||||||
voiceSpaces[4] = {"FemaleVox", voiceSpaceFemaleVox};
|
|
||||||
voiceSpaces[5] = {"Neve 80", voiceSpaceNeve80};
|
|
||||||
|
|
||||||
currentVoiceSpace = voiceSpaces[0].mappingFunction;
|
|
||||||
|
|
||||||
queue_init(&controlMessageQueue, sizeof(controlMessages), 1);
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
__attribute__((hot)) stereosample_t __force_inline Process(const stereosample_t x) override
|
|
||||||
{
|
|
||||||
float y = x[0];
|
|
||||||
float y1 = x[1];
|
|
||||||
if (!bypassAll) {
|
|
||||||
|
|
||||||
if (!bypassPrePostGain) {
|
|
||||||
y = tanhf(y * preGain);
|
|
||||||
y1 = tanhf(y1 * preGain);
|
|
||||||
}
|
|
||||||
if (!bypassInFilters)
|
|
||||||
{
|
|
||||||
y = inLowPass.loresChamberlain(y, inLowPassCutoff, 1.f);
|
|
||||||
y = inHighPass.hiresChamberlain(y, inHighPassCutoff, 1.f);
|
|
||||||
|
|
||||||
y1 = inLowPass1.loresChamberlain(y1, inLowPassCutoff, 1.f);
|
|
||||||
y1 = inHighPass1.hiresChamberlain(y1, inHighPassCutoff, 1.f);
|
|
||||||
}
|
|
||||||
if (!bypassEQ) {
|
|
||||||
y = peak0.play(y);
|
|
||||||
y = peak1.play(y);
|
|
||||||
y = lowshelf.play(y);
|
|
||||||
y = highshelf.play(y);
|
|
||||||
|
|
||||||
y1 = peak0_1.play(y1);
|
|
||||||
y1 = peak1_1.play(y1);
|
|
||||||
y1 = lowshelf1.play(y1);
|
|
||||||
// y1 = highshelf1.play(y1);
|
|
||||||
|
|
||||||
}
|
|
||||||
if (!bypassComp) {
|
|
||||||
y = dyn.compress(y, compThreshold, compRatio, 0.f);
|
|
||||||
y1 = dyn1.compress(y1, compThreshold, compRatio, 0.f);
|
|
||||||
}
|
|
||||||
if (!bypassPrePostGain) {
|
|
||||||
y = tanhf(y * postGain);
|
|
||||||
y1 = tanhf(y1 * postGain);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
stereosample_t ret { y, y1};
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Setup(float sample_rate, std::shared_ptr<InterfaceBase> interface) override
|
|
||||||
{
|
|
||||||
AudioAppBase<NPARAMS>::Setup(sample_rate, interface);
|
|
||||||
maxiSettings::sampleRate = sample_rate;
|
|
||||||
dyn.setLookAhead(0);
|
|
||||||
dyn.setAttackHigh(50);
|
|
||||||
dyn.setReleaseHigh(200);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
__attribute__((always_inline)) void ProcessParams(const std::array<float, NPARAMS>& params)
|
|
||||||
{
|
|
||||||
controlMessages msg;
|
|
||||||
while (queue_try_remove(&controlMessageQueue, &msg)) {
|
|
||||||
Serial.printf("ChannelStripAudioApp: received control message %d\n", static_cast<int>(msg));
|
|
||||||
switch(msg) {
|
|
||||||
case controlMessages::MSG_BYPASS_ALL:
|
|
||||||
bypassAll = !bypassAll;
|
|
||||||
break;
|
|
||||||
case controlMessages::MSG_BYPASS_EQ:
|
|
||||||
bypassEQ = !bypassEQ;
|
|
||||||
break;
|
|
||||||
case controlMessages::MSG_BYPASS_COMP:
|
|
||||||
bypassComp = !bypassComp;
|
|
||||||
break;
|
|
||||||
case controlMessages::MSG_BYPASS_PREPOSTGAIN:
|
|
||||||
bypassPrePostGain = !bypassPrePostGain;
|
|
||||||
break;
|
|
||||||
case controlMessages::MSG_BYPASS_INFILTERS:
|
|
||||||
bypassInFilters = !bypassInFilters;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
currentVoiceSpace(params);
|
|
||||||
dyn.setAttackHigh(compAttack);
|
|
||||||
dyn.setReleaseHigh(compRelease);
|
|
||||||
peak0.set(maxiBiquad::PEAK, peak0Freq, peak0Q, peak0Gain);
|
|
||||||
peak1.set(maxiBiquad::PEAK, peak1Freq, peak1Q, peak1Gain);
|
|
||||||
lowshelf.set(maxiBiquad::LOWSHELF, 100.f, 2.f, 3.f);
|
|
||||||
highshelf.set(maxiBiquad::HIGHSHELF, 1000.f, 2.f, 3.f);
|
|
||||||
|
|
||||||
dyn1.setAttackHigh(compAttack);
|
|
||||||
dyn1.setReleaseHigh(compRelease);
|
|
||||||
peak0_1.set(maxiBiquad::PEAK, peak0Freq, peak0Q, peak0Gain);
|
|
||||||
peak1_1.set(maxiBiquad::PEAK, peak1Freq, peak1Q, peak1Gain);
|
|
||||||
lowshelf1.set(maxiBiquad::LOWSHELF, 100.f, 2.f, 3.f);
|
|
||||||
highshelf1.set(maxiBiquad::HIGHSHELF, 1000.f, 2.f, 3.f);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
float sampleRatef = maxiSettings::getSampleRate();
|
|
||||||
|
|
||||||
float preGain=1.f;
|
|
||||||
float postGain=1.f;
|
|
||||||
|
|
||||||
maxiFilter inHighPass, inLowPass;
|
|
||||||
maxiFilter inHighPass1, inLowPass1;
|
|
||||||
|
|
||||||
float inLowPassCutoff=200.f;
|
|
||||||
float inHighPassCutoff=2000.f;
|
|
||||||
|
|
||||||
float compThreshold=0.f;
|
|
||||||
float compRatio = 1.f;
|
|
||||||
float compAttack=10.f;
|
|
||||||
float compRelease=50.f;
|
|
||||||
|
|
||||||
float peak0Freq=100.f;
|
|
||||||
float peak0Q=1.f;
|
|
||||||
float peak0Gain=1.f;
|
|
||||||
|
|
||||||
float peak1Freq=1000.f;
|
|
||||||
float peak1Q=1.f;
|
|
||||||
float peak1Gain=1.f;
|
|
||||||
|
|
||||||
float lowShelfFreq=1000.f;
|
|
||||||
float lowShelfQ=1.f;
|
|
||||||
float lowShelfGain=1.f;
|
|
||||||
|
|
||||||
float highShelfFreq=1000.f;
|
|
||||||
float highShelfQ=1.f;
|
|
||||||
float highShelfGain=1.f;
|
|
||||||
|
|
||||||
bool bypassAll = false;
|
|
||||||
bool bypassEQ = false;
|
|
||||||
bool bypassComp = false;
|
|
||||||
bool bypassPrePostGain = false;
|
|
||||||
bool bypassInFilters = false;
|
|
||||||
|
|
||||||
maxiDynamicsLite dyn, dyn1;
|
|
||||||
|
|
||||||
maxiBiquad lowshelf;
|
|
||||||
maxiBiquad peak0;
|
|
||||||
maxiBiquad peak1;
|
|
||||||
maxiBiquad highshelf;
|
|
||||||
|
|
||||||
maxiBiquad lowshelf1;
|
|
||||||
maxiBiquad peak0_1;
|
|
||||||
maxiBiquad peak1_1;
|
|
||||||
maxiBiquad highshelf1;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
276
IMLInterface.hpp
276
IMLInterface.hpp
|
|
@ -1,276 +0,0 @@
|
||||||
#ifndef IMINTERFACE_HPP
|
|
||||||
#define IMINTERFACE_HPP
|
|
||||||
|
|
||||||
// #include "src/memllib/audio/AudioAppBase.hpp"
|
|
||||||
#include "src/memllib/interface/InterfaceBase.hpp"
|
|
||||||
|
|
||||||
#include "src/memlp/Dataset.hpp"
|
|
||||||
#include "src/memlp/MLP.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class IMLInterface : public InterfaceBase
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
IMLInterface() : InterfaceBase() {}
|
|
||||||
|
|
||||||
void setup(size_t n_inputs, size_t n_outputs) override
|
|
||||||
{
|
|
||||||
InterfaceBase::setup(n_inputs, n_outputs);
|
|
||||||
// Additional setup code specific to IMLInterface
|
|
||||||
n_inputs_ = n_inputs;
|
|
||||||
n_outputs_ = n_outputs;
|
|
||||||
|
|
||||||
MLSetup_();
|
|
||||||
n_iterations_ = 1000;
|
|
||||||
input_state_.resize(n_inputs, 0.5f);
|
|
||||||
output_state_.resize(n_outputs, 0);
|
|
||||||
// Init/reset state machine
|
|
||||||
training_mode_ = INFERENCE_MODE;
|
|
||||||
perform_inference_ = true;
|
|
||||||
input_updated_ = false;
|
|
||||||
|
|
||||||
Serial.println("IMLInterface setup done");
|
|
||||||
Serial.print("Address of n_inputs_: ");
|
|
||||||
Serial.println(reinterpret_cast<uintptr_t>(&n_inputs_));
|
|
||||||
Serial.print("Inputs: ");
|
|
||||||
Serial.print(n_inputs_);
|
|
||||||
Serial.print(", Outputs: ");
|
|
||||||
Serial.println(n_outputs_);
|
|
||||||
}
|
|
||||||
|
|
||||||
enum training_mode_t {
|
|
||||||
INFERENCE_MODE,
|
|
||||||
TRAINING_MODE
|
|
||||||
};
|
|
||||||
|
|
||||||
void SetTrainingMode(training_mode_t training_mode)
|
|
||||||
{
|
|
||||||
Serial.print("Training mode: ");
|
|
||||||
Serial.println(training_mode == INFERENCE_MODE ? "Inference" : "Training");
|
|
||||||
|
|
||||||
if (training_mode == INFERENCE_MODE && training_mode_ == TRAINING_MODE) {
|
|
||||||
// Train the network!
|
|
||||||
MLTraining_();
|
|
||||||
}
|
|
||||||
training_mode_ = training_mode;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ProcessInput()
|
|
||||||
{
|
|
||||||
// Check if input is updated
|
|
||||||
if (perform_inference_ && input_updated_) {
|
|
||||||
MLInference_(input_state_);
|
|
||||||
input_updated_ = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetInput(size_t index, float value)
|
|
||||||
{
|
|
||||||
// Serial.print("Input ");
|
|
||||||
// Serial.print(index);
|
|
||||||
// Serial.print(" set to: ");
|
|
||||||
// Serial.println(value);
|
|
||||||
|
|
||||||
if (index >= n_inputs_) {
|
|
||||||
Serial.print("Input index ");
|
|
||||||
Serial.print(index);
|
|
||||||
Serial.println(" out of bounds.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (value < 0) {
|
|
||||||
value = 0;
|
|
||||||
} else if (value > 1.0) {
|
|
||||||
value = 1.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update state of input
|
|
||||||
input_state_[index] = value;
|
|
||||||
input_updated_ = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
enum saving_mode_t {
|
|
||||||
STORE_VALUE_MODE,
|
|
||||||
STORE_POSITION_MODE,
|
|
||||||
};
|
|
||||||
|
|
||||||
void SaveInput(saving_mode_t mode)
|
|
||||||
{
|
|
||||||
if (STORE_VALUE_MODE == mode) {
|
|
||||||
|
|
||||||
Serial.println("Move input to position...");
|
|
||||||
perform_inference_ = false;
|
|
||||||
|
|
||||||
} else { // STORE_POSITION_MODE
|
|
||||||
|
|
||||||
Serial.println("Creating example in this position.");
|
|
||||||
// Save pair in the dataset
|
|
||||||
dataset_->Add(input_state_, output_state_);
|
|
||||||
perform_inference_ = true;
|
|
||||||
MLInference_(input_state_);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ClearData()
|
|
||||||
{
|
|
||||||
if (training_mode_ == TRAINING_MODE) {
|
|
||||||
Serial.println("Clearing dataset...");
|
|
||||||
dataset_->Clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Randomise()
|
|
||||||
{
|
|
||||||
if (training_mode_ == TRAINING_MODE) {
|
|
||||||
Serial.println("Randomising weights...");
|
|
||||||
MLRandomise_();
|
|
||||||
MLInference_(input_state_);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetIterations(size_t iterations)
|
|
||||||
{
|
|
||||||
n_iterations_ = iterations;
|
|
||||||
Serial.print("Iterations set to: ");
|
|
||||||
Serial.println(n_iterations_);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
size_t n_inputs_;
|
|
||||||
size_t n_outputs_;
|
|
||||||
size_t n_iterations_;
|
|
||||||
|
|
||||||
// State machine
|
|
||||||
training_mode_t training_mode_;
|
|
||||||
bool perform_inference_;
|
|
||||||
bool input_updated_;
|
|
||||||
|
|
||||||
// Controls/sensors
|
|
||||||
std::vector<float> input_state_;
|
|
||||||
std::vector<float> output_state_;
|
|
||||||
|
|
||||||
// MLP core
|
|
||||||
std::unique_ptr<Dataset> dataset_;
|
|
||||||
std::unique_ptr<MLP<float>> mlp_;
|
|
||||||
MLP<float>::mlp_weights mlp_stored_weights_;
|
|
||||||
bool randomised_state_;
|
|
||||||
|
|
||||||
void MLSetup_()
|
|
||||||
{
|
|
||||||
// Constants for MLP init
|
|
||||||
const unsigned int kBias = 1;
|
|
||||||
const std::vector<ACTIVATION_FUNCTIONS> layers_activfuncs = {
|
|
||||||
RELU, RELU, RELU, SIGMOID
|
|
||||||
};
|
|
||||||
const bool use_constant_weight_init = false;
|
|
||||||
const float constant_weight_init = 0;
|
|
||||||
// Layer size definitions
|
|
||||||
const std::vector<size_t> layers_nodes = {
|
|
||||||
n_inputs_ + kBias,
|
|
||||||
10, 10, 14,
|
|
||||||
n_outputs_
|
|
||||||
};
|
|
||||||
|
|
||||||
// Create dataset
|
|
||||||
dataset_ = std::make_unique<Dataset>();
|
|
||||||
// Create MLP
|
|
||||||
mlp_ = std::make_unique<MLP<float>>(
|
|
||||||
layers_nodes,
|
|
||||||
layers_activfuncs,
|
|
||||||
loss::LOSS_MSE,
|
|
||||||
use_constant_weight_init,
|
|
||||||
constant_weight_init
|
|
||||||
);
|
|
||||||
|
|
||||||
// State machine
|
|
||||||
randomised_state_ = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void MLInference_(std::vector<float> input)
|
|
||||||
{
|
|
||||||
if (!dataset_ || !mlp_) {
|
|
||||||
Serial.println("ML not initialized!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (input.size() != n_inputs_) {
|
|
||||||
Serial.print("Input size mismatch - ");
|
|
||||||
Serial.print("Expected: ");
|
|
||||||
Serial.print(n_inputs_);
|
|
||||||
Serial.print(", Got: ");
|
|
||||||
Serial.println(input.size());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
input.push_back(1.0f); // Add bias term
|
|
||||||
// Perform inference
|
|
||||||
std::vector<float> output(n_outputs_);
|
|
||||||
mlp_->GetOutput(input, &output);
|
|
||||||
// Process inferenced data
|
|
||||||
output_state_ = output;
|
|
||||||
SendParamsToQueue(output);
|
|
||||||
}
|
|
||||||
|
|
||||||
void MLRandomise_()
|
|
||||||
{
|
|
||||||
if (!mlp_) {
|
|
||||||
Serial.println("ML not initialized!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Randomize weights
|
|
||||||
mlp_stored_weights_ = mlp_->GetWeights();
|
|
||||||
mlp_->DrawWeights();
|
|
||||||
randomised_state_ = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void MLTraining_()
|
|
||||||
{
|
|
||||||
if (!mlp_) {
|
|
||||||
Serial.println("ML not initialized!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Restore old weights
|
|
||||||
if (randomised_state_) {
|
|
||||||
mlp_->SetWeights(mlp_stored_weights_);
|
|
||||||
}
|
|
||||||
randomised_state_ = false;
|
|
||||||
|
|
||||||
// Prepare for training
|
|
||||||
// Extract dataset to training pair
|
|
||||||
MLP<float>::training_pair_t dataset(dataset_->GetFeatures(), dataset_->GetLabels());
|
|
||||||
// Check and report on dataset size
|
|
||||||
Serial.print("Feature size ");
|
|
||||||
Serial.print(dataset.first.size());
|
|
||||||
Serial.print(", label size ");
|
|
||||||
Serial.println(dataset.second.size());
|
|
||||||
if (!dataset.first.size() || !dataset.second.size()) {
|
|
||||||
Serial.println("Empty dataset!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Serial.print("Feature dim ");
|
|
||||||
Serial.print(dataset.first[0].size());
|
|
||||||
Serial.print(", label dim ");
|
|
||||||
Serial.println(dataset.second[0].size());
|
|
||||||
if (!dataset.first[0].size() || !dataset.second[0].size()) {
|
|
||||||
Serial.println("Empty dataset dimensions!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Training loop
|
|
||||||
Serial.print("Training for max ");
|
|
||||||
Serial.print(n_iterations_);
|
|
||||||
Serial.println(" iterations...");
|
|
||||||
float loss = mlp_->Train(dataset,
|
|
||||||
1.,
|
|
||||||
n_iterations_,
|
|
||||||
0.00001,
|
|
||||||
false);
|
|
||||||
Serial.print("Trained, loss = ");
|
|
||||||
Serial.println(loss, 10);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // IMINTERFACE_HPP
|
|
||||||
209
MAP.md
Normal file
209
MAP.md
Normal file
|
|
@ -0,0 +1,209 @@
|
||||||
|
# MAP
|
||||||
|
|
||||||
|
MEMLNaut-NISPS — Neural Interactive Shaping of Parameter Spaces. One C++20 codebase (`nisps/`) compiles to two targets: (1) Arduino/RP2350 firmware for the MEMLNaut hardware, (2) WASM in the Manifold React browser app that runs the same engines + ML through an AudioWorklet. (The former SolidJS playground was retired 2026-07-13 — branch `archive/playground-solidjs`, tag `playground-solidjs-final`; the browser-only C15 engine lives only there for now.) See `CLAUDE.md` for the long-form architecture narrative and `ALIGNMENT.md` for current strategic gaps.
|
||||||
|
|
||||||
|
## Layout
|
||||||
|
|
||||||
|
### `nisps/` — platform-agnostic C++20 library (the only ML/DSP/engine code)
|
||||||
|
- `nisps/core/` — `perf.hpp` (hot-path/inlining attrs), `types.hpp`, `concepts.hpp` (`MLEngine`, `AudioEngine`, `Mode`), `ring_buffer.hpp` (SPSC lock-free cross-core channel, replaces pico/util/queue), `event_queue.hpp` (single-threaded in-engine event FIFO — deliberately NOT RingBuffer, which is an atomics-based cross-thread channel), `rng.hpp` (xoshiro256+ deterministic), `math.hpp` (fast_sigmoid, `Curve` enum + `apply_curve`).
|
||||||
|
- `nisps/ml/` — the MLP core, written once against a storage policy (`mlp.hpp` `MLPCore<Storage>`): `storage.hpp` (`FixedStorage` — template-sized `std::array`, zero heap; `MLP<NIn,NH1,NH2,NH3,NOut>` alias preserves the classic compile-time surface) and `dynamic_storage.hpp` (`DynamicStorage` — runtime dims, single arena alloc at construction; `#error`s on RP2350 builds, sole lint heap-allowlist entry). Fixed↔dynamic bit-parity enforced by `tests/cpp/test_mlp_storage_parity.cpp`. Files: `mlp.hpp`, `activations.hpp`, `loss.hpp` (MSE, no double-scaling), `training.hpp` (**RMSProp** + grad clipping — `rmsprop_step()` is a line-for-line port of upstream memlp `Layer.h:239 ApplyAccumulatedGradients` @ `ea777502`; the per-weight running squared-gradient average is optimiser state held in the storage policies, NOT part of `weight_count()`/`get_weights()`, and `MLPCore::reset_optimizer_state()` clears it. `draw_weights()` deliberately does not, matching upstream `DrawWeights`), `init.hpp` (spread-aware uniform↔Xavier), `rl.hpp` (`move_weights` with output pin mask + per-layer scaling + weight decay), `jolt.hpp` (`Jolt` — held continuous weight-morph over the flat weight buffer + post-release LR ramp; ported from upstream InterfaceRL), `ou_noise.hpp` (`OUNoise<N>` — Ornstein-Uhlenbeck exploration walk on the output vector; ported from upstream InterfaceRL), `feedback.hpp` (`FeedbackControllerCore<FbStorage>` — the "Down Action" state machine: Avoid (geometric push-away default / Diffuse legacy) / RandomiseOutputs / RandomiseMlp / ExploreAndPlace; geometric replay is advanced deterministically by caller-supplied elapsed time with configurable rate/lifetime; storage-policied like the MLP, own deterministic RNG, exposed via `nisps_ml_feedback_*` C API), `replay.hpp` (`ReplayView` — reward-tagged memory: dedup/deepen, k-NN positive centroid with deterministic tie-break, wall-clock age/lifetime + eviction), `geo_push.hpp` (push-away target computation, upstream InterfaceRL @ `e291192` — re-based from `0a541cc` on 2026-07-25: `kGeometricPushScale` 1.0, `kNegLRBase` 1.5, and NO `/(1+len)` taper, so distance from the liked centroid does not shrink a "no". Cold start is the same push in a random direction, not a separate branch), `warm_start.hpp` (overlapping-weights copy for reshape), `stats.hpp`. `generated/ml_defaults.hpp` is codegen output (do not edit): `nisps::ml::generated::kMlTrainDefaults`, the ONE learning-rate / max-iterations / min-error default shared by firmware, WASM and VCV (source `schemas/ml_defaults.json`); `MLPCore::set_train_config()` and `nisps_ml_set_train_config()` override it at runtime. It lives under `ml/` rather than `modes/generated/` because `nisps/ml` sits below `nisps/modes` — mlp.hpp must not include upward. Jolt + OU are inert by default and wired into `ModeBase`, so every mode exposes `jolt_press/jolt_release`, `jolt_lr_scale`, and `set_explore_intensity`.
|
||||||
|
- `nisps/pipeline/` — the control-rate input/output processing chains (P4): `input_chain.hpp` (`InputChain` — invert→deadzone→circular clamp→momentum-modulated zoom→centred power→EMA→momentum; caller-supplied dt, internal clock, fixed velocity ring, serialisable state) and `output_chain.hpp` (`OutputChain<NMax>` — curve→EMA→slew→freeze(+mask), capacity-templated). Behaviour contract = the retired manifold TS pipelines, pinned by `manifold/tests/fixtures/` and parity stage 7.
|
||||||
|
- `nisps/dsp/` — `biquad.hpp`, `delay.hpp`, `reverb.hpp`, `filter.hpp`, `env.hpp`, `osc.hpp`, `pitch_shift.hpp`, `dc_blocker.hpp`, plus the sequencer primitives shared by the sequencer engines: `ratio_seq.hpp` and `seq_clock.hpp` (bar phasor + MIDI clock + bpm). Lean primitives extracted from maximilian; daisysp PitchShifter replaced with custom granular impl.
|
||||||
|
- `nisps/engines/` — eight audio engines, each satisfying `AudioEngine`: `paf_synth.hpp`, `channel_strip.hpp`, `xiasri.hpp`, `verb_fx.hpp`, `memlcelium.hpp`, `breakor.hpp` (sequencer, NoOp audio), `elysiamorf.hpp` (sequencer, NoOp audio), `analysis.hpp` (input-side spectral features). Plus `base.hpp` (`NoOpEngine`, engine_id "thru").
|
||||||
|
- `nisps/modes/` — platform-agnostic modes binding `{ML config, engine, voice space lambdas, abstract I/O channels}`. Files: `paf_synth.hpp`, `channel_strip.hpp`, `xiasri.hpp`, `verb_fx.hpp`, `memlcelium.hpp`, `slp_workshop.hpp` (`SLPWorkshopMode` — the Synth Library Portland workshop build; reuses the MEMLCelium engine + MLP shape, foregrounds the Jolt + OU explore gestures), `breakor.hpp`, `elysiamorf.hpp`, `sound_analysis_midi.hpp`, `external_synth_midi.hpp` (`ExternalSynthMIDIMode<const MidiDevice&, NOut>` — joystick→MLP→MIDI CC for an external synth; compile-time device from `nisps/midi`; `consteval pick_cc_slots` curates which params fill the NOut slots; NoOpEngine, `kRouteOutputsToEngine=false`). `base.hpp` provides a CRTP scaffold eliminating the duplication that previously plagued firmware modes; it also owns `driver_config()` — the audio-driver setup (mic vs line, gain staging, sample rate) the platform glue reads at mode start. Defaults to `engine().driver_config()`; a mode overrides it with an optional `on_driver_config()` hook only when its engine is not what consumes the audio input (`sound_analysis_midi`, whose analyser rather than its NoOp engine owns the mic). `generated/` contains codegen output (do not edit by hand): per-mode `k<Mode>Schema` ParamSchema instances, the `<Mode>MLP` type aliases built from the schema's own dims, and `schema_types.hpp` which now owns the `ParamSchema` struct itself. Mode headers no longer hand-write either their schema aggregate or their net shape.
|
||||||
|
- `nisps/wasm/bindings.cpp` — flat C API exported to WASM (Emscripten target only).
|
||||||
|
- `nisps/midi/generated/midi_devices.hpp` — codegen output: no-heap `constexpr` external-MIDI-synth templates (`nisps::midi::generated`; `MidiParam`/`MidiDevice` + `kMidiDevices` registry). Source = `schemas/midi_devices/`; do not edit by hand.
|
||||||
|
- `nisps/CMakeLists.txt` + `nisps/build/` — host-target builds + ctest.
|
||||||
|
|
||||||
|
### `firmware/` — PlatformIO project + hardware glue
|
||||||
|
- `firmware/MEMLNaut-NISPS/platformio.ini` — **the variant registry**: one `[env:<alias>]` per firmware variant (16 of them), each passing `-DMEMLNAUT_MODE_TYPE=<alias>`; `selftest` passes `-DNISPS_SELFTEST=1` instead. There is no second list to keep in sync. Shared `[env]` base pins the platform wrapper + arduino-pico framework, sets `-std=gnu++20 -O3` (via `build_unflags`, because the framework appends its own `-std=gnu++17 -Os` AFTER project flags), reaches `nisps/` with `-I${PROJECT_DIR}/../..`, and carries the TFT_eSPI panel config as `-D` flags. Build: `pio run -e <alias>`, or `scripts/build-firmware.sh [--all]`.
|
||||||
|
- `firmware/MEMLNaut-NISPS/src/main.cpp` — entry point (was `MEMLNaut-NISPS.ino`). Forks on `NISPS_SELFTEST`: normal modes run the engine/ML path; the `SelfTest` variant delegates all four entry points to `glue/selftest.hpp`.
|
||||||
|
- `firmware/MEMLNaut-NISPS/glue/` — hardware bindings:
|
||||||
|
- `audio_driver.hpp` — bridges memllib `AudioDriver` callback → `Mode::process(stereosample_t)`, and brings the codec up on the **active mode's** `driver_config()` (`setup_audio_driver`) plus publishes its preferred sample rate before the system clock is derived from it (`apply_mode_sample_rate`). Mic vs line input is therefore a mode-level declaration, not a firmware constant.
|
||||||
|
- `codec_config.hpp` — pure, Arduino-free clamping of a `nisps::DriverConfig` to SGTL5000-representable values + sample-rate resolution (unsupported/"don't care" → 48 kHz, because `AudioDriver::GetSysClockSpeed()` `panic()`s otherwise). Host-tested by `tests/cpp/test_mode_driver_config.cpp`.
|
||||||
|
- `peripherals.hpp` — joystick / pots / buttons → `Mode::set_input` and ML primitives. Wires the shared `FeedbackController` ExploreAndPlace lifecycle (MomA1 = enter/exit explore, MomA2 = freeze/place, TogB2 = commit; MomB1/MomB2 = reroll/nudge while exploring **or** grab/drop *reposition* while idle) plus the adaptive-learning gestures: **TogB1** = Jolt (held weight morph), **RVX1** = exploration amount (OU output walk). Reposition relocates an existing positive example's output to a new input position (`feedback.hpp` `begin_reposition`/`commit_reposition`) — no scratchpad, no weight restore.
|
||||||
|
- `midi_io.hpp` — MIDI in → mode `note_on`/`update_bpm`/`set_playing`; drains `ControlEvent` ring → MIDI UART.
|
||||||
|
- `mode_select.hpp` — type aliases mapping firmware mode identifiers to `nisps::modes::*Mode` C++ types, selected by the `-D` from platformio.ini. Includes the six `MEMLNautModeExtSynth*` external-synth variants (one per device template in `nisps/midi`, e.g. `MEMLNautModeExtSynthSub37`). The `NISPS_ST_*`/`NISPS_ST_CAT` token-paste table and the `SelfTestRig` tag type are GONE — selftest is now just an env with its own `-D`.
|
||||||
|
- `selftest.hpp` — standalone guided hardware self-test rig (`SelfTest` variant; no engine/ML). Step-driven state machine on a `SelfTestView`: TFT prompts the operator through every control, auto-advances on detection, encoder-press skips. Ends with optional L/R/BOTH sine-sweep headphone check (core 1 block callback) + MIDI loopback-cable test. Lives firmware-side (touches TFT + raw pins) so it stays out of platform-agnostic `nisps/`.
|
||||||
|
- `output_router.hpp` — top-level `drain_outputs()` entry point. (Inputs are wired directly by `peripherals.hpp`'s `bind_peripherals()`.)
|
||||||
|
- `settings_view.hpp` — `wire_settings(mode)`: adds on-device settings views to the MEMLNaut display carousel (TFT + rotary encoder). Joystick Dual/Single toggle for the 4-input ("two 2-D joystick") modes — "Single" pins ML input channels 2,3 to neutral via `ModeBase::set_input_pinned` (no net rebuild). Registered in the `.ino` after `addSystemInfoView()`.
|
||||||
|
- `firmware/MEMLNaut-NISPS/lib/memllib/` — **vendored** memllib (was the `src/memllib` submodule): hardware abstraction (audio driver, TFT display, MIDI, peripherals), ~1.9 MB / 100 files, `examples/` dropped **except** `reference/InterfaceRL.{hpp,cpp,tpp}` + `InterfaceRLFileFormat.hpp` — upstream's reference implementation of the feedback subsystem `nisps/ml/{geo_push,replay,feedback,jolt,ou_noise}.hpp` were ported from, kept verbatim and NEVER compiled (`reference/` sits outside `src/`, which is the only thing PlatformIO builds). It is there so upstream drift is a `diff`; losing it is how the e291192 geometric-dislike redesign went unnoticed for months. `VENDORED.md` records the upstream commit and the re-sync procedure; `LICENSE` is MPL-2.0, copied verbatim. **Sources must sit under `lib/memllib/src/`** — PlatformIO's library builder falls back to a flat root-only scan without it and silently compiles nothing while still linking (see VENDORED.md).
|
||||||
|
- `firmware/README.md` — structure + build instructions.
|
||||||
|
- `firmware/useq-celium/` — standalone RP2040 firmware (PlatformIO, Arduino-Pico core) that turns a uSEQ module + CV expander into a USB→CV/gate converter driven by the manifold `cvgate` backend. `shared/protocol.h` is the v2 wire-protocol single source of truth (mirrored by `manifold/src/backends/useq-protocol.ts`); `main/` (USB serial → CV1–3 + GATE1–3, I2C → expander) and `expander/` (I2C slave → CV4–11). Wire spec: `docs/specs/useq-cv-protocol.md`. Restored from the April-2026 "uSEQ-Celium" mode.
|
||||||
|
|
||||||
|
### `manifold/` — Vite + React + TS convertible-mode app (the sole browser app)
|
||||||
|
The Manifold "convertible" Console on the real engine, deployed at `meml.lnfinitemonkeys.org/next` (staging,
|
||||||
|
alongside the live vanilla a-immersive at `/`). Built 2026-06-27/28; see `docs/specs/plans/BUILD-PLAN.md` (resume
|
||||||
|
anchor + locked decisions) and the `docs/specs/*-spec.md` set.
|
||||||
|
- `manifold/src/engine/` — the parity-tested TS engine (same `nisps.wasm`), made
|
||||||
|
framework-neutral: `wasm-iml.ts` (rewired off Solid stores onto an injected `EngineSink`), `engine-host.ts` +
|
||||||
|
`worklet/nisps-processor.ts` (audio), thin WASM wrappers over the core pipelines + curve catalog (the TS
|
||||||
|
`input-pipeline`/`output-pipeline`/`curves` implementations died at P4), `wasm-worker.ts`,
|
||||||
|
`spine.ts` (the reactive spine BELOW React — `setInput` derives processed→ml→routed eagerly off-render;
|
||||||
|
structural/training state and throttled live-output notifications are separate channels),
|
||||||
|
`engine-api.ts` (`EngineApi` façade incl. live architecture/weight/example metrics and `feedback.*` wrappers over the `nisps_ml_feedback_*` C ABI),
|
||||||
|
`EngineProvider.tsx`/`useEngine.ts` (React bindings via `useSyncExternalStore`: state version plus an
|
||||||
|
opt-in 30 Hz output version for DOM consumers; canvases read live buffers directly). nisps.js is
|
||||||
|
loaded via fetch+indirect-eval (Emscripten MODULARIZE glue has no ES exports), base-aware via `document.baseURI`
|
||||||
|
for the `/next` sub-path.
|
||||||
|
- `manifold/src/primitives/` — the 7 design primitives as typed React (Badge, Button, PillToggle, Slider, Switch, VirtualJoystick, XYPad). Five unused ones were deleted in the 2026-07 sweep (L22).
|
||||||
|
- `manifold/src/console/` — the convertible Console: `ConsoleApp`, `CompositeStage` (single-divider convertible
|
||||||
|
with snap/magnetism/minimap-demotion), `OutputStage`/`SandwichStage`/`ParticleStage`/`Manifold` (canvas,
|
||||||
|
rect↔circular + feedback markers; ParticleStage batches its 400 particles into 32 colour paths per frame,
|
||||||
|
has interactive cursor-labelled heatmap sliders, an adjustable circular Manifold pad with feedback markers and cursor trail,
|
||||||
|
and double-click whole-screen follow-mouse input), `Dock` (top Mode selector + 5 vertically-centred drawers), `Drawers`
|
||||||
|
(Learning/Inputs/Outputs/Settings/Help; Learning includes the live model-architecture inspector and
|
||||||
|
Outputs owns the remaining scroll height), `TrainingHealth` (real per-iteration loss curve from
|
||||||
|
`nisps_ml_loss_history` + per-layer weight health from `nisps_ml_get_layer_stats`; rendered only at
|
||||||
|
the Learning drawer's `expanded` depth — that IS the advanced-surface flag), `VerdictCluster`
|
||||||
|
(mode-aware), `OutputEditor`/`DualRange`/`CurvePad`, `icons.tsx`
|
||||||
|
(monochrome currentColor SVG), `model.ts` (`MF_MODES` catalogue — schema-backed modes DERIVED from
|
||||||
|
`manifold/src/modes/generated/`; carries per-mode `ml` net shape + `engineId`), `output-mode.ts`.
|
||||||
|
- `manifold/src/modes/generated/` — codegen output (`*_schema.ts`, do NOT hand-edit): `ModeSchema`
|
||||||
|
consts (mode_id, engine_id, ml dims, params, voice_spaces, ui) — the SOURCE OF TRUTH for `MF_MODES`.
|
||||||
|
Switching mode reshapes the WASM net to the mode's `ml` dims (ConsoleApp P5.3; boot mode paf_synth →
|
||||||
|
4→[10,10,14]→33).
|
||||||
|
- `manifold/src/dock/` — `OutputControlRow` (editable names, corner delete, cycling off/fixed/live status, mute + solo/arm + min/max/curve, plus MIDI card fields), `output-state.ts`,
|
||||||
|
`OutputsBackendConfig.tsx` (per-backend specialised Outputs panel — the sole per-backend editor; centered prepend/append add-card controls live above and below the rows).
|
||||||
|
- `manifold/src/backends/` — `OutputBackend` adapter + `BackendManager` (spine consumer); `midi-backend.ts`
|
||||||
|
(WebMIDI), `osc-backend.ts`+`osc-client.ts` (OSC-over-WS), `vcv-backend.ts` (VCV-over-WS), `cv-backend.ts`
|
||||||
|
(`UseqCvBackend` — uSEQ CV/gate over USB Web Serial, backend id `cvgate`) + `useq-protocol.ts` (v2 wire
|
||||||
|
protocol, mirrors `firmware/useq-celium/shared/protocol.h`; `useq-protocol.test.ts` runs via `bun test`),
|
||||||
|
`particle-backend.ts`, `passthrough-backend.ts`, `presets.ts` (named presets), `manager.ts`.
|
||||||
|
- `manifold/src/midi-devices/` — external-synth device templates. `generated/` is codegen output from
|
||||||
|
`schemas/midi_devices/` (`MIDI_DEVICES` catalogue + `MIDI_DEVICES_BY_ID`, params by name+CC). The MIDI Outputs
|
||||||
|
config (`dock/OutputsBackendConfig.tsx`) reads it for the device picker + param-select that fills the per-card MIDI fields.
|
||||||
|
- `manifold/src/inputs/` — modular INPUT layer feeding the ML head. The Inputs dock picks ONE exclusive mode
|
||||||
|
(`InputMode` = `internal` | `gamepad` | `midi`; Internal/XY-pad is default). `input-layer.ts` owns a single rAF
|
||||||
|
loop composing the active source's axes → **one dedicated engine input slot per axis, 1:1, no blending** → one
|
||||||
|
`setInputs`, plus an `onReducedInput` callback the manifold tracks. Normal Manifold models default to a
|
||||||
|
runtime-shaped 2-input head; the Inputs dock can select 4 inputs, and active sources can grow the head when
|
||||||
|
they need more slots. Mean-blending was removed deliberately — it diluted every source and biased the net
|
||||||
|
toward idle sources' resting values. Active-axis edits follow the persistent I/O policy:
|
||||||
|
keep-capacity permutes stable identities in place until more slots are required; exact-I/O reconstructs
|
||||||
|
to the active count. Surviving weights and (under adapt policy) examples are identity-remapped; feedback
|
||||||
|
scratch state resets. Sources: `xy-pad-source` (push-driven),
|
||||||
|
`gamepad-source` (sticks→axes single/double; buttons emit press+release actions, bound in `ConsoleApp` to
|
||||||
|
verdicts — LB/RB=down/up, X/Y/B=randomise/nudge/undo, A-hold=reposition), `midi-input-source` (device picker +
|
||||||
|
BATCH "MIDI Learn": every CC swept while armed becomes an axis, shown as read-only meters). `useInputLayer.ts`
|
||||||
|
is the React binding; `base-source.ts` shared status/action plumbing; `types.ts` the adapter contract.
|
||||||
|
`backends/base-backend.ts` is its output-side counterpart (status + throttle + lastSent) used by the midi/osc/vcv transports.
|
||||||
|
- `manifold/src/feedback/` — `controller.ts` (Explore-and-place scratchpad + geometric-dislike + solo; owns the
|
||||||
|
elapsed-time timer for geometric replay while every weight-affecting step stays in the shared C++ core).
|
||||||
|
- `manifold/src/settings/` — `settings-store.ts` (monochrome icons, input-map shape, I/O resize policy, corner radius, and the opt-in legacy Xavier/spread feature flag; Manifold randomisation is full-range uniform by default).
|
||||||
|
- `manifold/src/serial/` — `memlnaut-serial.ts` Web Serial scaffold + `EditorPanel.tsx` (MEMLNaut Editor mode).
|
||||||
|
- `manifold/src/engine/exploration.ts` — Jolt press + OU explore gestures (Learning drawer): a thin
|
||||||
|
timer-driver over the shared C++ core via the `nisps_ml_jolt_*`/`nisps_ml_ou_*` bindings (the interim
|
||||||
|
TS math and `jolt.ts`/`ou-explore.ts` were deleted when P3 landed).
|
||||||
|
- `manifold/src/engine/io-reshape.ts` — the deep identity-migration module for I/O card edits:
|
||||||
|
exact-vs-capacity reconstruction decisions, flat weight remapping, and example vector adaptation.
|
||||||
|
- `manifold/src/debug/probe.ts` — `window.__nisps` (`?debug=1`). `manifold/tests/e2e/` — `smoke`,
|
||||||
|
`probe-api` (engine-contract port), `spine` (spine invariant + probe-survives-mode-switch),
|
||||||
|
`geo-dislike`, `reshape`, `schema-modes`, `training-health` (the loss/layer-stats panel + its
|
||||||
|
expanded-depth gating). E2E on the VPS runs via non-snap node (see BUILD-PLAN).
|
||||||
|
`manifold/tests/fixtures/` — golden parity
|
||||||
|
fixtures (gesture trace, curves, input/output pipelines) captured 2026-07-13 pre-P4, guarded by
|
||||||
|
`tests/pipeline-golden.test.ts` (in `bun run test`). `tests/loss-history.test.ts` drives the
|
||||||
|
`nisps_ml_loss_history` C ABI straight at the committed WASM — the training path parity-check
|
||||||
|
never touches. `manifold/osc-bridge/` — Deno WS↔UDP-OSC bridge.
|
||||||
|
|
||||||
|
### `vcv/` — VCV Rack 2 plugin (MEMLNaut module, WIP)
|
||||||
|
Native C++ Rack module: ML CV-mapper with RL feedback + a browser bridge. **8 inputs × 16 outputs + per-output
|
||||||
|
LED rings**, palette from the frontend tokens, WS↔OSC browser bridge (see `docs/specs/vcv-module.md`).
|
||||||
|
`src/MEMLNaut.cpp` (module, 8→[16,24,16]→16), `src/iml.hpp` (**thin adapter over `nisps::ml::MLPCore<DynamicStorage>`
|
||||||
|
+ core `nisps::Rng`** — P6 reunification 2026-07-18, closes vcv-module.md delta #5; behaviour is now core-exact,
|
||||||
|
pinned by `tests/cpp/test_vcv_iml_parity.cpp`), `src/osc_server.hpp` (bridge, transport-only), `src/plugin.{hpp,cpp}`,
|
||||||
|
`res/*.svg` (panels), `Makefile` (needs `RACK_DIR`). Builds against the current `../nisps/` core via relative
|
||||||
|
includes; no `nisps-core`.
|
||||||
|
|
||||||
|
### `schemas/` — JSON parameter contracts (firmware/browser source of truth)
|
||||||
|
- `schemas/schema.json` — Draft 2020-12 meta-schema validating mode files.
|
||||||
|
- `schemas/modes/<mode>.json` (×9) — each mode's params, ranges, defaults, curves, voice spaces, ML config. (`slp_workshop.json` reuses `engine_id: memlcelium`.) `params[].curve` is the mode-wide DEFAULT response curve; a `voice_spaces` entry may be an object `{name, curve_overrides}` declaring only the slots where THAT voice space deviates (index i == `VoiceSpace` ordinal i). Descriptive throughout: the curve is applied exactly once, inside the engine's voice space.
|
||||||
|
- `schemas/modes/params_notes.md` — provenance notes and judgement calls per mode, plus the exact `square`/`sqrt`/`linear` predicate the drift check enforces.
|
||||||
|
- `schemas/midi_device.schema.json` — Draft 2020-12 meta-schema for external-MIDI-synth templates.
|
||||||
|
- `schemas/midi_devices/<device>.json` (×6) — CC-controllable external synths (Moog Sub 37 / Sub Phatty, Creamware Pro-12 ASB, Elektron Analog Keys, ASM Hydrasynth, Roland JD-800). Each param: `{id, cc, label, min, max, default, group}`. Canonical source for both firmware + browser device pickers. Verified-CC provenance + sources live in `schemas/midi_devices/sources/synth-midi-cc.json` (a `sources/` subdir, because the generator ajv-validates every `*.json` directly under `midi_devices/` as a device template).
|
||||||
|
|
||||||
|
### `codegen/` — schema → C++/TS code
|
||||||
|
- `codegen/generate.ts` — Bun script: validates schemas via ajv (incl. the P5 firmware-fit check: exactly 3 hidden layers, dims ≤4096), emits per-mode C++ `nisps/modes/generated/<mode>_schema.hpp` (`constexpr`, `nisps::modes::generated`) AND TS `manifold/src/modes/generated/<mode>_schema.ts` (+ `types.ts`, `index.ts`). Idempotent; golden-tested in `run-all-tests.sh` stage 5. The TS output is the SOURCE OF TRUTH consumed by `MF_MODES` (`manifold/src/console/model.ts`).
|
||||||
|
- `codegen/generate-midi-devices.ts` — separate Bun script (isolated from the mode golden test): validates `schemas/midi_devices/` via ajv, emits `nisps/midi/generated/midi_devices.hpp` (no-heap `constexpr`) and `manifold/src/midi-devices/generated/{types,devices,index}.ts`. Idempotent.
|
||||||
|
- `codegen/curve-audit.ts` — reads `nisps/engines/*.hpp` and derives, per voice space, which response curve the engine applies to each NN-output slot. Handles the four idioms a regex misses (`const float v = p[n]; v*v`, memlcelium's implicit-counter `sq()` lambda, loop-generated indices, `smooth_params_[n]`) and RAISES on anything it cannot reduce rather than defaulting to `linear`.
|
||||||
|
- `codegen/tests/curve_drift_test.ts` — the gate: schema-declared curves (JSON **and** generated TS) must equal what `curve-audit.ts` extracts, and schema `voice_spaces` order must equal the engine's `kVoiceSpaceNames`. Source-level by necessity — the curve is not recoverable from engine output. Run by `run-all-tests.sh` stage 5, CI, and `bun run test` in `codegen/`.
|
||||||
|
- `codegen/lib.ts` — helpers shared by both generators. `codegen/tests/golden/` — golden snapshot for paf_synth (C++ + TS).
|
||||||
|
|
||||||
|
### `tests/cpp/` — host C++ tests
|
||||||
|
- Per-component tests: `test_dsp_*.cpp`, `test_engine_*.cpp`, `test_mlp_*.cpp`, `test_mode_*.cpp`, `test_ring_buffer.cpp`, `test_rng.cpp`, `test_math.cpp`. Helpers in `test_helpers.hpp`.
|
||||||
|
- Verification: `ml_golden_vectors.cpp`, `engine_impulse.cpp` (+ `engine_impulse_baseline.bin`), `parity_check.cpp` + `parity_wasm.mjs` + `parity_diff.mjs` — native-vs-WASM bit-equivalence within 1e-5.
|
||||||
|
- Behaviour: `test_ml_behaviour.cpp` — 20 INVARIANTS of the interaction model (not tuning). Asserts what must hold however the knobs are set: a like is reachable and a re-like overwrites; dislike never yields non-finite weights/outputs in either `AvoidStyle`, and is safe at cold start; repeat dislikes inside `kReplayDedupRadius` deepen ONE negative while distant ones store separately; explore→reroll→undo→exit restores weights *bit-exactly* and over-undoing is safe; `RandomiseOutputs` leaves weights untouched (the outputs-vs-weights randomisation distinction); same seed + same gesture sequence ⇒ bit-identical weights (what makes any behavioural benchmark comparable); example-ring overflow keeps the newest; contradictory examples stay finite; the ExploreAndPlace accessor contract (`placed_output()` while Placing, `committed_output()` after commit — for both place and reposition); a FULLY-masked focus gate freezes every weight; switching mode mid-exploration never strands the net in a randomised scratchpad; and all of it holds at 1×1, 2×8, 1×33, 8×2 and 32×8 shapes.
|
||||||
|
- Measurement (asserts nothing): `ml_bench.cpp` — the BEHAVIOURAL benchmark. NISPS is a controller, so this measures the shape of the control→parameter mapping and how interaction journeys deform it, never loss alone. Shape-agnostic (`--shape N_IN,H1,H2,H3,N_OUT`, default `2,16,16,16,8`) via `MLPCore<DynamicStorage>`, so "does a wider/deeper net change the UX?" becomes a number; sample points come from a deterministic Kronecker low-discrepancy sequence rather than a raster, which is what makes it work at any input arity. Field metrics: local gain p50/p95, cliff index, dead fraction, range utilisation, rail occupancy, effective dimensionality (participation ratio — trace²/‖C‖²_F, no eigendecomposition). Displacement metrics: at-point, rings, global, **blast ratio**, and collateral damage at the protected positives. **61 scenarios.** Diagnostic (D1 — the geometric-dislike dose decomposed: intended push vs effective LR vs measured movement at 1/10/100/1000 presses). Atomic probes A1–A14: at/around/far-from an example; one dislike under BOTH candidate designs; twice at one point; adjacent-then-return across the dedup radius; near a protected positive; roll-a-patch-and-place; the full explore→audition→place→commit lifecycle; explore-then-cancel; reposition; like-then-dislike in place; dislike-then-repair; focus/solo mask leakage. Journeys J1–J11: positive-only retention curve, randomise-place-only, mixed, branch (one shared prefix, three divergent gestures, replayed from scratch per branch because that is exact under a deterministic RNG), explore-place-only, 120-gesture long session with drift + weight-norm checkpoints, dislike storm, revisit-after-wandering, two-region interference, sweep-and-teach along a continuous path, undo-heavy. Edge cases E1–E13: cold start, single example, contradictory, collinear, corners, capacity overflow, undo exhaustion, minimal shape, identical targets, rail targets, rapid like/dislike alternation, mode-switch mid-exploration, fully-masked dislike. Upstream comparison U1–U3: the older memllib `interfaceRL` (a DDPG actor-critic, recoverable from this repo's own git history at blob `755ff8b`) differs structurally — the user HEARS `actorTarget`, a soft copy updated `target += alpha*(online-target)` at alpha=0.005, and it trains a batch of 4 from replay only every `optimiseDivisor=40` gestures. The critic half is not reproducible here (MLPCore has `train_targets` but not the per-layer gradient extraction the policy-gradient step needs), but both OUTPUT-PATH ideas are: U1 sweeps the soft-target alpha (alpha=1 IS NISPS today, a free control), U2 sweeps the train-every-Nth divisor, U3 compares actor shapes, U4 sweeps the positive-path training dose. U4's numbers became comparable to upstream's on 2026-07-25, when `nisps/ml/training.hpp` stopped being SGD-only and ported upstream's RMSProp — before that an upstream LR meant something different here than there, which is what made the geometric dislike inert (D1: 5.3e-5 per press before, 1.6e-2 after). Their shared metric is **lurch** — how far the mapping the musician is playing moves per single gesture, averaged over the whole field. Knobs: `--spread` (1 = Xavier, 0 = uniform with NO fan_in coupling — i.e. the post-removal behaviour, measurable before paying for the refactor), `--geo-lr`, `--geo-iters`. Driven by `scripts/bench-ml.sh`. **Two contracts that fail SILENTLY and are pinned by tests:** (1) a thumbs-up must go through BOTH `mlp.add_example` AND `fb.store_positive` — `dislike_geometric` k-NNs the replay buffer, not the MLP dataset, so a harness that only calls `add_example` measures the cold-start branch instead; (2) `placed_output()` is valid ONLY while state is `Placing` — after `commit_place()`/`commit_reposition()` the vector moves to `committed_output()`, and reading the wrong one yields an empty span whose `l2()` is 0, i.e. a broken lifecycle scored as a perfect placement.
|
||||||
|
- Measurement (asserts nothing): `engine_bench.cpp` + `bench_report.mjs` — per-engine throughput (ns/sample, blocks/s, realtime factor) for the `process()` hot path. ONE source compiled twice (CMake `nisps_engine_bench` natively, emcc for WASM) so the two targets are comparable without adding a single export to `nisps/wasm/bindings.cpp`. Engines are driven into a working state (transport running + event drain for the sequencers, periodic `note_on` for paf_synth, a noise+sine input bed for the fx/analysis engines) and every row prints its own working-state evidence, so a number produced by an idle engine is visible rather than plausible. Driven by `scripts/bench-engines.sh`.
|
||||||
|
|
||||||
|
### `scripts/` — build + verify entry points
|
||||||
|
- `build-firmware.sh`, `flash-firmware.sh`, `build-and-flash-firmware.sh`, `firmware-common.sh` — Arduino-CLI wrapper for RP2350 target with C++20 flag.
|
||||||
|
- `build-wasm.sh` — Emscripten compile producing `manifold/public/nisps.{wasm,js}`.
|
||||||
|
- `build-cpp-tests.sh` — CMake configure + build + ctest (Ninja).
|
||||||
|
- `parity-check.sh` — runs native + WASM and diffs binary outputs. **Gotcha**: it only builds `manifold/public/nisps.{js,wasm}` when they are MISSING, never when they are stale, so after any change under `nisps/` you must run `build-wasm.sh` yourself or you are diffing fresh native against an old WASM — which reports a parity FAILURE that is really a staleness failure (this is how the RMSProp port first "broke" parity).
|
||||||
|
- `bench-ml.sh` — the ML BEHAVIOUR benchmark on native + WASM from one source (same trick as `bench-engines.sh`). `--shape`, `--scenario`, `--smoke`, `--seed`, `--compare`, and `--sweep-shape` (runs the corpus across a ladder of architectures and arities — the knob-sensitivity instrument). **Reports, never asserts**: a cliff index is a description, not a pass/fail. Invariants live in `tests/cpp/test_ml_behaviour.cpp` instead. Reports land in `nisps/build/bench-ml/`.
|
||||||
|
- `bench-engines.sh` — engine throughput on native + WASM; `--compare <report.json>` prints per-engine Δ%. **Reports, never asserts** (a wall-clock threshold on shared hardware is meaningless or flaky — same call as the firmware size job). Reports land in `nisps/build/bench/`.
|
||||||
|
- `lint-cpp.sh` — `.f` literal warn + heap/`Arduino.h` violation fail.
|
||||||
|
- `run-all-tests.sh` — master verification script.
|
||||||
|
|
||||||
|
### `.github/workflows/`
|
||||||
|
- `ci.yml` — GitHub Actions: cmake build + ctest + WASM build + parity check + lint + Playwright (cpp-tests + manifold-tests jobs). Firmware compile is documented as manual.
|
||||||
|
|
||||||
|
### `src/` — submodule + vendored trees
|
||||||
|
- **There are no submodules.** `src/memllib` was one until the Phase 4 PlatformIO migration; it is now vendored at `firmware/MEMLNaut-NISPS/lib/memllib/`. Fresh clones need no `git submodule` step.
|
||||||
|
|
||||||
|
### Top-level docs
|
||||||
|
- `CLAUDE.md` — long-form architecture narrative.
|
||||||
|
- `MAP.md` — this file.
|
||||||
|
- `ALIGNMENT.md` — strategic gaps + open mission questions, dated, opinionated.
|
||||||
|
- `README.md` — short quickstart.
|
||||||
|
- `AGENTS.md` — canonical agent contract: architecture, build/test, scope, and Ergo workflow.
|
||||||
|
|
||||||
|
## Entry points
|
||||||
|
|
||||||
|
- **Firmware**: `scripts/build-firmware.sh [VARIANT]` (interactive prompt if omitted), `scripts/flash-firmware.sh`, `scripts/build-and-flash-firmware.sh`. Target: `rp2040:rp2040:solderparty_rp2350_stamp_xl:opt=Optimize3`, `-std=gnu++20`.
|
||||||
|
- **Manifold dev**: `cd manifold && bun install && bun run dev` (Vite, COOP/COEP headers).
|
||||||
|
- **Manifold build**: `cd manifold && bun run build`.
|
||||||
|
- **WASM rebuild**: `bash scripts/build-wasm.sh` (needs `emcc`).
|
||||||
|
- **Host C++ tests**: `bash scripts/build-cpp-tests.sh`.
|
||||||
|
- **Parity check**: `bash scripts/parity-check.sh`.
|
||||||
|
- **Engine benchmark**: `bash scripts/bench-engines.sh` (add `--compare nisps/build/bench/latest.json` to diff against the previous run).
|
||||||
|
- **ML behaviour benchmark**: `bash scripts/bench-ml.sh` (`--smoke` for a fast run, `--shape 2,16,16,16,8`, `--sweep-shape` for the architecture/arity sweep, `--compare` to diff).
|
||||||
|
- **All tests**: `bash scripts/run-all-tests.sh` (stage 6 is a bench smoke report; it does not gate).
|
||||||
|
- **Playwright**: `cd manifold && node node_modules/.bin/playwright test` (non-snap node runner on the VPS — BUILD-PLAN gotcha; `bunx playwright test` works elsewhere).
|
||||||
|
- **Codegen**: `cd codegen && bun run generate.ts` (regenerates `nisps/modes/generated/` + `nisps/ml/generated/` C++ and `manifold/src/modes/generated/` TS).
|
||||||
|
|
||||||
|
## Conventions
|
||||||
|
|
||||||
|
- Firmware mode selection is compile-time only — one `-DMEMLNAUT_MODE_TYPE` per `[env:]` in `platformio.ini`.
|
||||||
|
- `nisps/` follows Chris's RP2350 perf rules: no heap, `static const float` for non-trivial constants, strict `.f` suffix. `perf.hpp` now carries only `NISPS_HOT`/`NISPS_FORCE_INLINE`; the three dead/misshapen SRAM-section macros were deleted in the 2026-07 sweep (S21/L13).
|
||||||
|
- C++ identifiers: `PascalCase` types, `snake_case` functions/variables, `kPascalCase` constexpr. JSON keys `snake_case`. TS types `PascalCase`, components `PascalCase.tsx`, modules `kebab-case.ts`.
|
||||||
|
- `Curve` enum lives in `nisps/core/math.hpp` (lowercase: `linear/exp/log/square/sqrt/sigmoid/cubic`, plus the parameterised `centered_power` free function); generated mode headers re-export via `using Curve = ::nisps::Curve;`. Since P4 there is NO TS mirror — the browser samples the WASM catalog (`nisps_curve_apply(+batch)`).
|
||||||
|
- Modes are TSX components composed of primitives; mode parameter contracts are JSON schemas with codegen → C++ **and** TS types (`MF_MODES` derives params/ml-config from the generated schemas since P5; labels/ordering stay a manifold overlay). **No declarative JSON UI.**
|
||||||
|
- WASM and firmware share the same C++; the browser MLP is runtime-shaped (`MLPCore<DynamicStorage>`, since P2): `nisps_ml_create` honours `(input, output, hidden[3])` with non-positive/null args defaulting to `32→[10,14,18]→126`; `nisps_ml_reshape` warm-starts a new shape. Firmware keeps compile-time `MLP<...>` (zero heap). Manifold normal modes use a 2-input UI default and can opt into 4 inputs; audio-analysis keeps its schema-defined feature arity. Firmware mode shapes remain schema-real.
|
||||||
|
- Cross-platform parity: `scripts/parity-check.sh` enforces native vs WASM agreement within 1e-5.
|
||||||
|
|
||||||
|
## Gotchas
|
||||||
|
|
||||||
|
- Firmware needs PlatformIO: `nix-shell -p platformio-core`. Use `platformio-core`, NOT `platformio` — the latter is nixpkgs' bubblewrap-wrapped FHS build and fails without a working user namespace. First build pulls ~1-2 GB into `~/.platformio`.
|
||||||
|
- `firmware/MEMLNaut-NISPS/glue/mode_select.hpp` `#undef`s Arduino macros (`sq`, `min`, `max`, `abs`, `round`) before pulling nisps headers — engines use those identifiers as method names.
|
||||||
|
- `nisps_firmware::g_active_mode_bridge` is `extern` in `glue/audio_driver.hpp` and defined in `src/main.cpp`; combining `inline` with `__not_in_flash` produces a comdat conflict at link time.
|
||||||
|
- `pio run`'s own "Flash: NN%" console line double-counts `.data` on this board (PlatformIO's generic size checker counts every PROGBITS+ALLOC section). Compare `arm-none-eabi-size -A` — flash = `.text+.rodata` — before believing a size regression.
|
||||||
|
- `nisps_modes_tests` builds against generated schemas under `nisps/modes/generated/`; if you add a new mode, regenerate via `bun run codegen/generate.ts` before building. It also compiles one firmware header (`glue/codec_config.hpp`), so the repo root is on its include path.
|
||||||
|
- `nisps::DriverConfig`'s member defaults are load-bearing: they reproduce memllib's historical hardcoded codec setup, so a mode that declares nothing gets exactly the pre-wiring behaviour. Changing them changes the codec setup of every mode that expresses no opinion (pinned by `tests/cpp/test_mode_driver_config.cpp`).
|
||||||
|
|
||||||
|
## Smells / strategic concerns
|
||||||
|
|
||||||
|
See `ALIGNMENT.md`.
|
||||||
|
|
||||||
|
## Specs
|
||||||
|
|
||||||
|
- **Root**: `docs/specs/`
|
||||||
|
- **Entry**: `MAIN.md`
|
||||||
|
- **Layout**: flat (with `plans/`, `recon/`, `_archive/` subdirs)
|
||||||
|
- **Index**: none (intentionally — generate when a consumer exists)
|
||||||
|
- **Skill**: invoke `/specs` to review/maintain/add/navigate.
|
||||||
|
- **Conventions**: Four-genre ontology — `kind: spec` (timeless contract, wins by intent), `kind: plan` (status: active|executed|superseded, never authority for behaviour), `kind: finding` (dated, immutable, exempt from drift lint), ADRs in `docs/adr/`.
|
||||||
|
|
||||||
|
The corpus holds platform-level specs (engine architecture, I/O backends, feedback design), implementation specs (port specs, wire protocols), feature specs (e.g. slp-workshop-firmware.md), historical findings (dated research artifacts), and finite build plans. Before changing behaviour a spec covers, find it via `/specs`; the spec wins by intent — if it's wrong, update it in the same commit as the code.
|
||||||
|
|
@ -1,244 +0,0 @@
|
||||||
//machine config
|
|
||||||
|
|
||||||
#define JOYSTICK_IS_4D false
|
|
||||||
#define MEMLNAUT_ANALOG_INPUTS 3 + (JOYSTICK_IS_4D ? 1 : 0)
|
|
||||||
#define MEMLNAUT_INPUT_MODE InterfaceRL::INPUT_MODES::JOYSTICK
|
|
||||||
|
|
||||||
//hardware
|
|
||||||
#include "src/memllib/utils/perf.hpp"
|
|
||||||
#include "src/memllib/interface/MIDIInOut.hpp"
|
|
||||||
#include "src/memllib/audio/AudioDriver.hpp"
|
|
||||||
#include "src/memllib/hardware/memlnaut/MEMLNaut.hpp"
|
|
||||||
#include "hardware/structs/bus_ctrl.h"
|
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
//sound
|
|
||||||
#include "src/memllib/audio/AudioAppBase.hpp"
|
|
||||||
#include "PAFSynthAudioApp.hpp"
|
|
||||||
#include "ChannelStripAudioApp.hpp"
|
|
||||||
|
|
||||||
//interface
|
|
||||||
#include "src/memllib/hardware/memlnaut/display/XYPadView.hpp"
|
|
||||||
#include "src/memllib/hardware/memlnaut/display/MessageView.hpp"
|
|
||||||
#include "src/memllib/hardware/memlnaut/display/VoiceSpaceSelectView.hpp"
|
|
||||||
|
|
||||||
//modes
|
|
||||||
#include "modes/MEMLNautMode.hpp"
|
|
||||||
#include "modes/MEMLNautModePAFSynth.hpp"
|
|
||||||
#include "modes/MEMLNautModeChannelStrip.hpp"
|
|
||||||
#include "modes/MEMLNautModeSoundAnalysisMIDI.hpp"
|
|
||||||
#include "modes/MEMLNautModeXIASRI.hpp"
|
|
||||||
#include "modes/MEMLNautModeBreakOr.hpp"
|
|
||||||
#include "modes/MEMLNautModeVerbFX.hpp"
|
|
||||||
#include "modes/MEMLNautModeElysiamorfs.hpp"
|
|
||||||
|
|
||||||
//hook up the memlnaut mode
|
|
||||||
|
|
||||||
// #define MEMLNAUT_MODE_TYPE MEMLNautModeSoundAnalysisMIDI
|
|
||||||
// #define MEMLNAUT_MODE_TYPE MEMLNautModeXIASRI
|
|
||||||
#define MEMLNAUT_MODE_TYPE MEMLNautModeVerbFX
|
|
||||||
// #define MEMLNAUT_MODE_TYPE MEMLNautModeBreakOr
|
|
||||||
// #define MEMLNAUT_MODE_TYPE MEMLNautModeElysiamorfs
|
|
||||||
// #define MEMLNAUT_MODE_TYPE MEMLNautModeChannelStrip
|
|
||||||
// #define MEMLNAUT_MODE_TYPE MEMLNautModePAFSynth
|
|
||||||
|
|
||||||
MEMLNAUT_MODE_TYPE AUDIO_MEM MEMLNautModeHub;
|
|
||||||
|
|
||||||
MEMLNautMode auto* AUDIO_MEM currentMode = &MEMLNautModeHub;
|
|
||||||
|
|
||||||
|
|
||||||
#define APP_SRAM __not_in_flash("app")
|
|
||||||
|
|
||||||
bool core1_separate_stack = true;
|
|
||||||
|
|
||||||
uint32_t get_rosc_entropy_seed(int bits) {
|
|
||||||
uint32_t seed = 0;
|
|
||||||
for (int i = 0; i < bits; ++i) {
|
|
||||||
// Wait for a bit of time to allow jitter to accumulate
|
|
||||||
busy_wait_us_32(5);
|
|
||||||
// Pull LSB from ROSC rand output
|
|
||||||
seed <<= 1;
|
|
||||||
seed |= (rosc_hw->randombit & 1);
|
|
||||||
}
|
|
||||||
return seed;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Global objects
|
|
||||||
|
|
||||||
std::shared_ptr<MIDIInOut> APP_SRAM midi_interf;
|
|
||||||
|
|
||||||
// Inter-core communication
|
|
||||||
volatile bool APP_SRAM core_0_ready = false;
|
|
||||||
volatile bool APP_SRAM core_1_ready = false;
|
|
||||||
volatile bool APP_SRAM serial_ready = false;
|
|
||||||
volatile bool APP_SRAM interface_ready = false;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Add these macros near other globals
|
|
||||||
#define MEMORY_BARRIER() __sync_synchronize()
|
|
||||||
#define WRITE_VOLATILE(var, val) \
|
|
||||||
do { \
|
|
||||||
MEMORY_BARRIER(); \
|
|
||||||
(var) = (val); \
|
|
||||||
MEMORY_BARRIER(); \
|
|
||||||
} while (0)
|
|
||||||
#define READ_VOLATILE(var) ({ MEMORY_BARRIER(); typeof(var) __temp = (var); MEMORY_BARRIER(); __temp; })
|
|
||||||
|
|
||||||
|
|
||||||
void setup() {
|
|
||||||
set_sys_clock_khz(AudioDriver::GetSysClockSpeed(), true);
|
|
||||||
|
|
||||||
bus_ctrl_hw->priority = BUSCTRL_BUS_PRIORITY_DMA_W_BITS | BUSCTRL_BUS_PRIORITY_DMA_R_BITS | BUSCTRL_BUS_PRIORITY_PROC1_BITS;
|
|
||||||
|
|
||||||
uint32_t seed = get_rosc_entropy_seed(32);
|
|
||||||
srand(seed);
|
|
||||||
|
|
||||||
midi_interf = std::make_shared<MIDIInOut>();
|
|
||||||
// Serial.println("MIDI setup complete.");
|
|
||||||
|
|
||||||
Serial.begin(115200);
|
|
||||||
// while (!Serial) {}
|
|
||||||
Serial.println("Serial initialised.");
|
|
||||||
WRITE_VOLATILE(serial_ready, true);
|
|
||||||
|
|
||||||
// Setup board
|
|
||||||
MEMLNaut::Initialize();
|
|
||||||
pinMode(33, OUTPUT);
|
|
||||||
|
|
||||||
currentMode->setupInterface();
|
|
||||||
|
|
||||||
// Setup interface with memory barrier protection
|
|
||||||
WRITE_VOLATILE(interface_ready, true);
|
|
||||||
Serial.println("Bound interface to MEMLNaut.");
|
|
||||||
|
|
||||||
|
|
||||||
WRITE_VOLATILE(core_0_ready, true);
|
|
||||||
while (!READ_VOLATILE(core_1_ready)) {
|
|
||||||
MEMORY_BARRIER();
|
|
||||||
delay(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
currentMode->addViews();
|
|
||||||
|
|
||||||
std::shared_ptr<MessageView> helpView = std::make_shared<MessageView>("Help");
|
|
||||||
String title = currentMode->getHelpTitle();
|
|
||||||
helpView->post(title);
|
|
||||||
helpView->post("TA: Down: Clear replay memory");
|
|
||||||
helpView->post("MA: Up: Randomise / Down: Jolt ");
|
|
||||||
helpView->post("MB: Up: Positive reward");
|
|
||||||
helpView->post("MB: Down: Negative reward");
|
|
||||||
helpView->post("X: Learning rate");
|
|
||||||
helpView->post("Y: Reward Scale");
|
|
||||||
helpView->post("Z: Exploration noise");
|
|
||||||
helpView->post("Joystick: Explore / SW: Drag sound");
|
|
||||||
MEMLNaut::Instance()->disp->AddView(helpView);
|
|
||||||
|
|
||||||
MEMLNaut::Instance()->addSystemInfoView();
|
|
||||||
|
|
||||||
Serial.println("Finished initialising core 0.");
|
|
||||||
}
|
|
||||||
|
|
||||||
PERF_DECLARE(MLSTATS);
|
|
||||||
|
|
||||||
#define ML_INFERENCE_PERIOD_US 5000
|
|
||||||
|
|
||||||
void loop() {
|
|
||||||
|
|
||||||
PERIODIC_RUN_US(
|
|
||||||
PERF_BEGIN(MLSTATS);
|
|
||||||
currentMode->processAnalysisParams();
|
|
||||||
MEMLNaut::Instance()->loop();
|
|
||||||
PERF_END(MLSTATS);
|
|
||||||
, ML_INFERENCE_PERIOD_US)
|
|
||||||
|
|
||||||
//show profiling stats
|
|
||||||
PERIODIC_RUN_US(
|
|
||||||
static size_t blip_counter = 0;
|
|
||||||
if (blip_counter++ > 10) {
|
|
||||||
blip_counter = 0;
|
|
||||||
Serial.println(".");
|
|
||||||
// Blink LED
|
|
||||||
digitalWrite(33, HIGH);
|
|
||||||
constexpr float audioHeadroomMul = 1.0 / (1000000 * 48.0 / kSampleRate);
|
|
||||||
Serial.printf("ml: %d, aud: %d, q: %f\n", PERF_GET_MEAN(MLSTATS), AUDIOLOOP_MEAN, AUDIOLOOP_MEAN * audioHeadroomMul);
|
|
||||||
} else {
|
|
||||||
// Un-blink LED
|
|
||||||
digitalWrite(33, LOW);
|
|
||||||
},
|
|
||||||
100000)
|
|
||||||
|
|
||||||
currentMode->loopCore0();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void AUDIO_FUNC(audio_block_callback)(float in[][kBufferSize], float out[][kBufferSize], size_t n_channels, size_t n_frames) {
|
|
||||||
|
|
||||||
for (size_t i = 0; i < n_frames; ++i) {
|
|
||||||
|
|
||||||
stereosample_t x{
|
|
||||||
in[0][i],
|
|
||||||
in[1][i]
|
|
||||||
},
|
|
||||||
y;
|
|
||||||
|
|
||||||
y = currentMode->process(x);
|
|
||||||
|
|
||||||
out[0][i] = y.L;
|
|
||||||
out[1][i] = y.R;
|
|
||||||
|
|
||||||
// PERIODIC_RUN(
|
|
||||||
// Serial.printf("x: %f\n", x.L + x.R);
|
|
||||||
// , 100);
|
|
||||||
|
|
||||||
currentMode->analyse(x);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void setup1() {
|
|
||||||
while (!READ_VOLATILE(serial_ready)) {
|
|
||||||
MEMORY_BARRIER();
|
|
||||||
delay(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
while (!READ_VOLATILE(interface_ready)) {
|
|
||||||
MEMORY_BARRIER();
|
|
||||||
delay(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (midi_interf) {
|
|
||||||
currentMode->setupMIDI(midi_interf);
|
|
||||||
}
|
|
||||||
|
|
||||||
currentMode->setupAudio(AudioDriver::GetSampleRate());
|
|
||||||
|
|
||||||
AudioDriver::SetBlockCallback(audio_block_callback);
|
|
||||||
|
|
||||||
// Start audio driver
|
|
||||||
AudioDriver::Setup();
|
|
||||||
|
|
||||||
WRITE_VOLATILE(core_1_ready, true);
|
|
||||||
while (!READ_VOLATILE(core_0_ready)) {
|
|
||||||
MEMORY_BARRIER();
|
|
||||||
delay(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
Serial.println("Finished initialising core 1.");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void loop1() {
|
|
||||||
// Audio app parameter processing loop
|
|
||||||
PERIODIC_RUN_US(
|
|
||||||
currentMode->loop();
|
|
||||||
, ML_INFERENCE_PERIOD_US)
|
|
||||||
|
|
||||||
PERIODIC_RUN_US(
|
|
||||||
midi_interf->Poll();
|
|
||||||
, 1000)
|
|
||||||
}
|
|
||||||
|
|
@ -1,140 +0,0 @@
|
||||||
# NISPS Core Extraction Plan
|
|
||||||
|
|
||||||
Extract a platform-agnostic C++20 controller library from MEMLNaut-NISPS. This is **not** a synth or audio engine - it's a parameter mapping engine: control data in → ML → control data out. Use it to drive synths, effects, lights, robots, whatever.
|
|
||||||
|
|
||||||
> **Note**: Originally planned as C++17, upgraded to C++20 during implementation to use `std::span` for efficient array views.
|
|
||||||
|
|
||||||
## What This Is
|
|
||||||
|
|
||||||
NISPS core takes N input parameters (joystick position, sensor data, audio features) and maps them to M output parameters through an interactively-trained neural network. Users teach it by example: "when I'm here in input space, I want these output values."
|
|
||||||
|
|
||||||
## Dependencies to Remove
|
|
||||||
|
|
||||||
| Dependency | Replacement |
|
|
||||||
|------------|-------------|
|
|
||||||
| `Serial.print*` | Optional log callback |
|
|
||||||
| `queue_t` (Pico SDK) | Not needed (single-threaded) |
|
|
||||||
| `WString.h` (Arduino) | `std::string` |
|
|
||||||
| `__force_inline`, `AUDIO_MEM` | No-op macros |
|
|
||||||
|
|
||||||
## Structure
|
|
||||||
|
|
||||||
```
|
|
||||||
nisps/
|
|
||||||
├── mlp.hpp # MLP implementation (from memlp, cleaned)
|
|
||||||
├── dataset.hpp # Training dataset
|
|
||||||
├── iml.hpp # Interactive ML engine (~200 lines)
|
|
||||||
└── voice_space.hpp # Optional: example parameter mappings
|
|
||||||
```
|
|
||||||
|
|
||||||
## Core API
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
namespace nisps {
|
|
||||||
|
|
||||||
template<typename Float = float>
|
|
||||||
class IML {
|
|
||||||
public:
|
|
||||||
IML(size_t n_inputs, size_t n_outputs,
|
|
||||||
std::vector<size_t> hidden_layers = {10, 10, 14});
|
|
||||||
|
|
||||||
// Input
|
|
||||||
void set_input(size_t index, Float value);
|
|
||||||
void set_inputs(const Float* values, size_t count);
|
|
||||||
|
|
||||||
// Output (valid after process())
|
|
||||||
const Float* get_outputs() const;
|
|
||||||
size_t num_outputs() const;
|
|
||||||
|
|
||||||
// Runtime
|
|
||||||
void process(); // Run inference, call at control rate
|
|
||||||
|
|
||||||
// Training workflow
|
|
||||||
enum class Mode { Inference, Training };
|
|
||||||
void set_mode(Mode mode);
|
|
||||||
void save_example(); // Store current input→output as training pair
|
|
||||||
void clear_dataset();
|
|
||||||
void randomise_weights(); // For exploration in training mode
|
|
||||||
void train(); // Blocking, runs on current dataset
|
|
||||||
|
|
||||||
// Optional
|
|
||||||
using LogFn = void(*)(const char*);
|
|
||||||
void set_logger(LogFn fn);
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace nisps
|
|
||||||
```
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
#include "nisps/iml.hpp"
|
|
||||||
|
|
||||||
nisps::IML<float> iml(3, 24); // 3 inputs (x,y,z), 24 outputs
|
|
||||||
|
|
||||||
// Control loop
|
|
||||||
void update(float x, float y, float z) {
|
|
||||||
iml.set_input(0, x);
|
|
||||||
iml.set_input(1, y);
|
|
||||||
iml.set_input(2, z);
|
|
||||||
iml.process();
|
|
||||||
|
|
||||||
const float* params = iml.get_outputs();
|
|
||||||
my_synth.set_filter_cutoff(params[0] * 10000.f);
|
|
||||||
my_synth.set_resonance(params[1]);
|
|
||||||
// ... etc
|
|
||||||
}
|
|
||||||
|
|
||||||
// Training (triggered by user interaction)
|
|
||||||
void on_user_saves_position() {
|
|
||||||
iml.save_example();
|
|
||||||
}
|
|
||||||
|
|
||||||
void on_user_exits_training_mode() {
|
|
||||||
iml.set_mode(nisps::IML<>::Mode::Inference);
|
|
||||||
// This triggers training internally
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## Voice Spaces (Optional)
|
|
||||||
|
|
||||||
Voice spaces are just functions that interpret the raw 0-1 output parameters. Not part of core, but useful as examples:
|
|
||||||
|
|
||||||
```cpp
|
|
||||||
// User-defined mapping
|
|
||||||
void apply_neve_style(const float* params, MyChannelStrip& strip) {
|
|
||||||
strip.pre_gain = 0.5f + params[0] * params[0] * 4.f;
|
|
||||||
strip.hp_freq = 30.f + params[8] * params[8] * 270.f;
|
|
||||||
strip.comp_threshold = 20.f + params[10] * -40.f;
|
|
||||||
// ... etc
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## Phases
|
|
||||||
|
|
||||||
### Phase 1: Get memlp building standalone (1-2 days)
|
|
||||||
|
|
||||||
1. Copy `memlp` source into `nisps/`
|
|
||||||
2. Remove `Serial.print` calls (or stub them)
|
|
||||||
3. Remove Arduino `String` usage
|
|
||||||
4. Verify it compiles with g++/clang
|
|
||||||
|
|
||||||
### Phase 2: Wrap in IML interface (2-3 days)
|
|
||||||
|
|
||||||
1. Create `iml.hpp` with the API above
|
|
||||||
2. Port state machine logic from `IMLInterface.hpp`
|
|
||||||
3. Simple test: train on XOR, verify inference works
|
|
||||||
|
|
||||||
### Phase 3: Example integration (1-2 days)
|
|
||||||
|
|
||||||
1. Command-line example that reads CSV input, outputs CSV
|
|
||||||
2. Or: minimal JUCE/SDL example with mouse input
|
|
||||||
|
|
||||||
**Total: ~1 week to something usable**
|
|
||||||
|
|
||||||
## Later (only if needed)
|
|
||||||
|
|
||||||
- Model serialization (save/load trained weights)
|
|
||||||
- Thread-safe parameter updates
|
|
||||||
- Python bindings
|
|
||||||
- WASM build
|
|
||||||
|
|
@ -1,678 +0,0 @@
|
||||||
# NISPS Core Extraction - Task Graph
|
|
||||||
|
|
||||||
Atomic tasks for extracting nisps-core. Each task is standalone and requires no decisions.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Repository Setup
|
|
||||||
|
|
||||||
### TASK-001: Create nisps-core directory structure
|
|
||||||
**Blocked by**: None
|
|
||||||
**Description**: Create the nisps-core directory with the required structure.
|
|
||||||
**Actions**:
|
|
||||||
1. Create directory: `nisps-core/`
|
|
||||||
2. Create directory: `nisps-core/include/nisps/`
|
|
||||||
3. Create directory: `nisps-core/test/`
|
|
||||||
4. Create directory: `nisps-core/examples/`
|
|
||||||
**Verification**: Directories exist.
|
|
||||||
|
|
||||||
### TASK-002: Create CMakeLists.txt for nisps-core
|
|
||||||
**Blocked by**: TASK-001
|
|
||||||
**Description**: Create a minimal CMakeLists.txt that builds the library as header-only with test target.
|
|
||||||
**Actions**: Create `nisps-core/CMakeLists.txt` with this exact content:
|
|
||||||
```cmake
|
|
||||||
cmake_minimum_required(VERSION 3.14)
|
|
||||||
project(nisps-core VERSION 0.1.0 LANGUAGES CXX)
|
|
||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 17)
|
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
||||||
|
|
||||||
# Header-only library
|
|
||||||
add_library(nisps INTERFACE)
|
|
||||||
target_include_directories(nisps INTERFACE
|
|
||||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
|
||||||
$<INSTALL_INTERFACE:include>
|
|
||||||
)
|
|
||||||
|
|
||||||
# Tests
|
|
||||||
option(NISPS_BUILD_TESTS "Build tests" ON)
|
|
||||||
if(NISPS_BUILD_TESTS)
|
|
||||||
enable_testing()
|
|
||||||
add_subdirectory(test)
|
|
||||||
endif()
|
|
||||||
```
|
|
||||||
**Verification**: File exists with exact content.
|
|
||||||
|
|
||||||
### TASK-003: Create test CMakeLists.txt
|
|
||||||
**Blocked by**: TASK-002
|
|
||||||
**Description**: Create test/CMakeLists.txt for building tests.
|
|
||||||
**Actions**: Create `nisps-core/test/CMakeLists.txt` with this exact content:
|
|
||||||
```cmake
|
|
||||||
add_executable(nisps_test main.cpp)
|
|
||||||
target_link_libraries(nisps_test PRIVATE nisps)
|
|
||||||
add_test(NAME nisps_test COMMAND nisps_test)
|
|
||||||
```
|
|
||||||
**Verification**: File exists with exact content.
|
|
||||||
|
|
||||||
### TASK-004: Create placeholder test file
|
|
||||||
**Blocked by**: TASK-003
|
|
||||||
**Description**: Create a minimal test file that includes the main header.
|
|
||||||
**Actions**: Create `nisps-core/test/main.cpp` with this exact content:
|
|
||||||
```cpp
|
|
||||||
#include <nisps/nisps.hpp>
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
std::cout << "nisps-core tests placeholder\n";
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
```
|
|
||||||
**Verification**: File exists with exact content.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Phase 1: Extract MLP Core
|
|
||||||
|
|
||||||
### TASK-010: Copy Utils.h with Arduino code removed
|
|
||||||
**Blocked by**: TASK-001
|
|
||||||
**Description**: Copy `src/memlp/Utils.h` to `nisps-core/include/nisps/utils.hpp`, removing Arduino-specific code.
|
|
||||||
**Actions**:
|
|
||||||
1. Copy the file
|
|
||||||
2. Remove the `#ifdef ARDUINO` block (lines related to ENABLE_SAVE)
|
|
||||||
3. Remove the `extern "C" int getentropy` declaration at the end
|
|
||||||
4. Change header guard from `UTILS_H` to `NISPS_UTILS_HPP`
|
|
||||||
5. Wrap everything in `namespace nisps { ... }`
|
|
||||||
|
|
||||||
**Changes to make** (be exact):
|
|
||||||
- Line 1: Change `#ifndef UTILS_H` to `#ifndef NISPS_UTILS_HPP`
|
|
||||||
- Line 2: Change `#define UTILS_H` to `#define NISPS_UTILS_HPP`
|
|
||||||
- Remove lines 38-45 (the `#if defined(_WIN32)...` and `#ifdef ARDUINO` ENABLE_SAVE blocks)
|
|
||||||
- After line 57 (`namespace utils {`), keep as-is (utils is a sub-namespace)
|
|
||||||
- Before the final `#endif`, add closing brace for nisps namespace
|
|
||||||
- Remove the last line `extern "C" int getentropy...`
|
|
||||||
- Add `namespace nisps {` after the includes, before `enum ACTIVATION_FUNCTIONS`
|
|
||||||
- Add `} // namespace nisps` before `#endif // NISPS_UTILS_HPP`
|
|
||||||
|
|
||||||
**Verification**: File compiles with `g++ -std=c++17 -fsyntax-only nisps-core/include/nisps/utils.hpp`
|
|
||||||
|
|
||||||
### TASK-011: Copy Loss.h
|
|
||||||
**Blocked by**: TASK-001
|
|
||||||
**Description**: Copy `src/memlp/Loss.h` to `nisps-core/include/nisps/loss.hpp`.
|
|
||||||
**Actions**:
|
|
||||||
1. Copy the file
|
|
||||||
2. Change header guard from `LOSS_H` to `NISPS_LOSS_HPP`
|
|
||||||
3. Wrap everything in `namespace nisps { ... }`
|
|
||||||
4. Update include from `"Utils.h"` to `"utils.hpp"`
|
|
||||||
|
|
||||||
**Verification**: File compiles with `g++ -std=c++17 -fsyntax-only -I nisps-core/include nisps-core/include/nisps/loss.hpp`
|
|
||||||
|
|
||||||
### TASK-012: Copy Node.h
|
|
||||||
**Blocked by**: TASK-010
|
|
||||||
**Description**: Copy `src/memlp/Node.h` to `nisps-core/include/nisps/node.hpp`.
|
|
||||||
**Actions**:
|
|
||||||
1. Copy the file
|
|
||||||
2. Change header guard from `NODE_H` to `NISPS_NODE_HPP`
|
|
||||||
3. Wrap everything in `namespace nisps { ... }`
|
|
||||||
4. Update include from `"Utils.h"` to `"utils.hpp"`
|
|
||||||
|
|
||||||
**Verification**: File compiles with `g++ -std=c++17 -fsyntax-only -I nisps-core/include nisps-core/include/nisps/node.hpp`
|
|
||||||
|
|
||||||
### TASK-013: Copy Layer.h
|
|
||||||
**Blocked by**: TASK-012
|
|
||||||
**Description**: Copy `src/memlp/Layer.h` to `nisps-core/include/nisps/layer.hpp`.
|
|
||||||
**Actions**:
|
|
||||||
1. Copy the file
|
|
||||||
2. Change header guard from `LAYER_H` to `NISPS_LAYER_HPP`
|
|
||||||
3. Wrap everything in `namespace nisps { ... }`
|
|
||||||
4. Update include from `"Node.h"` to `"node.hpp"`
|
|
||||||
|
|
||||||
**Verification**: File compiles with `g++ -std=c++17 -fsyntax-only -I nisps-core/include nisps-core/include/nisps/layer.hpp`
|
|
||||||
|
|
||||||
### TASK-014: Copy Sample.h
|
|
||||||
**Blocked by**: TASK-001
|
|
||||||
**Description**: Copy `src/memlp/Sample.h` to `nisps-core/include/nisps/sample.hpp`.
|
|
||||||
**Actions**:
|
|
||||||
1. Copy the file
|
|
||||||
2. Change header guard from `SAMPLE_H` to `NISPS_SAMPLE_HPP`
|
|
||||||
3. Wrap everything in `namespace nisps { ... }`
|
|
||||||
|
|
||||||
**Verification**: File compiles with `g++ -std=c++17 -fsyntax-only nisps-core/include/nisps/sample.hpp`
|
|
||||||
|
|
||||||
### TASK-015: Copy MLP.h with Arduino code removed
|
|
||||||
**Blocked by**: TASK-011, TASK-013, TASK-014
|
|
||||||
**Description**: Copy `src/memlp/MLP.h` to `nisps-core/include/nisps/mlp.hpp`, removing Arduino-specific code.
|
|
||||||
**Actions**:
|
|
||||||
1. Copy the file
|
|
||||||
2. Change header guard from `MLP_H` to `NISPS_MLP_HPP`
|
|
||||||
3. **Remove lines 17-51** (the entire `#ifdef ARDUINO` block including Serial debug macros and SD includes)
|
|
||||||
4. Add these lines after the header guard instead:
|
|
||||||
```cpp
|
|
||||||
// Debug macros (no-op by default, override before including if needed)
|
|
||||||
#ifndef NISPS_DEBUG_PRINT
|
|
||||||
#define NISPS_DEBUG_PRINT(...)
|
|
||||||
#define NISPS_DEBUG_PRINTLN(...)
|
|
||||||
#define NISPS_DEBUG_PRINTF(...)
|
|
||||||
#endif
|
|
||||||
```
|
|
||||||
5. Update includes:
|
|
||||||
- `"Layer.h"` → `"layer.hpp"`
|
|
||||||
- `"Utils.h"` → `"utils.hpp"`
|
|
||||||
- `"Loss.h"` → `"loss.hpp"`
|
|
||||||
- `"Sample.h"` → `"sample.hpp"`
|
|
||||||
6. Remove `#if ENABLE_SAVE` blocks (lines 94-96, 99-113, 115-119) - remove the conditionals but **keep** the function declarations
|
|
||||||
7. Remove `#if ENABLE_SAVE_SD` block entirely (lines 115-119)
|
|
||||||
8. Wrap everything in `namespace nisps { ... }`
|
|
||||||
9. Replace `MLP_DEBUG_PRINT` with `NISPS_DEBUG_PRINT`, `MLP_DEBUG_PRINTLN` with `NISPS_DEBUG_PRINTLN`, `MLP_DEBUG_PRINTF` with `NISPS_DEBUG_PRINTF`
|
|
||||||
|
|
||||||
**Verification**: File compiles with `g++ -std=c++17 -fsyntax-only -I nisps-core/include nisps-core/include/nisps/mlp.hpp`
|
|
||||||
|
|
||||||
### TASK-016: Copy MLP.cpp with Arduino code removed
|
|
||||||
**Blocked by**: TASK-015
|
|
||||||
**Description**: Copy `src/memlp/MLP.cpp` to `nisps-core/include/nisps/mlp_impl.hpp` as inline implementation.
|
|
||||||
**Actions**:
|
|
||||||
1. Copy the file
|
|
||||||
2. Remove `#include "MLP.h"` (it will be included from mlp.hpp)
|
|
||||||
3. Add header guard `#ifndef NISPS_MLP_IMPL_HPP` / `#define NISPS_MLP_IMPL_HPP`
|
|
||||||
4. Wrap everything in `namespace nisps { ... }`
|
|
||||||
5. Remove all `#ifdef ARDUINO` / `#if ENABLE_SAVE` / `#if ENABLE_SAVE_SD` conditional blocks
|
|
||||||
6. For functions inside removed conditionals: keep the functions but remove the `#if` guards
|
|
||||||
7. Replace any `Serial.print*` calls with `NISPS_DEBUG_PRINT*` equivalents
|
|
||||||
8. At the end of `nisps-core/include/nisps/mlp.hpp`, add: `#include "mlp_impl.hpp"`
|
|
||||||
|
|
||||||
**Verification**: A test file that instantiates `nisps::MLP<float>` compiles and links.
|
|
||||||
|
|
||||||
### TASK-017: Copy Dataset.hpp
|
|
||||||
**Blocked by**: TASK-001
|
|
||||||
**Description**: Copy `src/memlp/Dataset.hpp` to `nisps-core/include/nisps/dataset.hpp`.
|
|
||||||
**Actions**:
|
|
||||||
1. Copy the file
|
|
||||||
2. Change header guard from `__DATASET_HPP__` to `NISPS_DATASET_HPP`
|
|
||||||
3. Wrap everything in `namespace nisps { ... }`
|
|
||||||
|
|
||||||
**Verification**: File compiles with `g++ -std=c++17 -fsyntax-only nisps-core/include/nisps/dataset.hpp`
|
|
||||||
|
|
||||||
### TASK-018: Copy Dataset.cpp as inline implementation
|
|
||||||
**Blocked by**: TASK-017
|
|
||||||
**Description**: Copy `src/memlp/Dataset.cpp` to `nisps-core/include/nisps/dataset_impl.hpp`.
|
|
||||||
**Actions**:
|
|
||||||
1. Copy the file
|
|
||||||
2. Remove `#include "Dataset.hpp"`
|
|
||||||
3. Add header guard `#ifndef NISPS_DATASET_IMPL_HPP` / `#define NISPS_DATASET_IMPL_HPP`
|
|
||||||
4. Wrap everything in `namespace nisps { ... }`
|
|
||||||
5. Make all functions `inline`
|
|
||||||
6. At the end of `nisps-core/include/nisps/dataset.hpp`, add: `#include "dataset_impl.hpp"`
|
|
||||||
|
|
||||||
**Verification**: A test file that instantiates `nisps::Dataset` compiles and links.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Phase 2: Create IML Interface
|
|
||||||
|
|
||||||
### TASK-020: Create iml.hpp header
|
|
||||||
**Blocked by**: TASK-016, TASK-018
|
|
||||||
**Description**: Create the main IML class header based on IMLInterface.hpp.
|
|
||||||
**Actions**: Create `nisps-core/include/nisps/iml.hpp` with this exact content:
|
|
||||||
```cpp
|
|
||||||
#ifndef NISPS_IML_HPP
|
|
||||||
#define NISPS_IML_HPP
|
|
||||||
|
|
||||||
#include "mlp.hpp"
|
|
||||||
#include "dataset.hpp"
|
|
||||||
#include <vector>
|
|
||||||
#include <cstddef>
|
|
||||||
#include <functional>
|
|
||||||
|
|
||||||
namespace nisps {
|
|
||||||
|
|
||||||
template<typename Float = float>
|
|
||||||
class IML {
|
|
||||||
public:
|
|
||||||
enum class Mode { Inference, Training };
|
|
||||||
|
|
||||||
using LogFn = void(*)(const char*);
|
|
||||||
|
|
||||||
IML(size_t n_inputs, size_t n_outputs,
|
|
||||||
std::vector<size_t> hidden_layers = {10, 10, 14},
|
|
||||||
size_t max_iterations = 1000,
|
|
||||||
Float learning_rate = 1.0f,
|
|
||||||
Float convergence_threshold = 0.00001f);
|
|
||||||
|
|
||||||
// Input
|
|
||||||
void set_input(size_t index, Float value);
|
|
||||||
void set_inputs(const Float* values, size_t count);
|
|
||||||
|
|
||||||
// Output (valid after process())
|
|
||||||
const Float* get_outputs() const;
|
|
||||||
size_t num_inputs() const { return n_inputs_; }
|
|
||||||
size_t num_outputs() const { return n_outputs_; }
|
|
||||||
|
|
||||||
// Runtime
|
|
||||||
void process();
|
|
||||||
|
|
||||||
// Training workflow
|
|
||||||
void set_mode(Mode mode);
|
|
||||||
Mode get_mode() const { return mode_; }
|
|
||||||
void save_example();
|
|
||||||
void clear_dataset();
|
|
||||||
void randomise_weights();
|
|
||||||
|
|
||||||
// Optional logging
|
|
||||||
void set_logger(LogFn fn) { log_fn_ = fn; }
|
|
||||||
|
|
||||||
private:
|
|
||||||
void log(const char* msg) const {
|
|
||||||
if (log_fn_) log_fn_(msg);
|
|
||||||
}
|
|
||||||
void train();
|
|
||||||
|
|
||||||
size_t n_inputs_;
|
|
||||||
size_t n_outputs_;
|
|
||||||
size_t max_iterations_;
|
|
||||||
Float learning_rate_;
|
|
||||||
Float convergence_threshold_;
|
|
||||||
|
|
||||||
Mode mode_ = Mode::Inference;
|
|
||||||
bool input_updated_ = false;
|
|
||||||
bool perform_inference_ = true;
|
|
||||||
|
|
||||||
std::vector<Float> input_state_;
|
|
||||||
std::vector<Float> output_state_;
|
|
||||||
|
|
||||||
std::unique_ptr<Dataset> dataset_;
|
|
||||||
std::unique_ptr<MLP<Float>> mlp_;
|
|
||||||
typename MLP<Float>::mlp_weights stored_weights_;
|
|
||||||
bool weights_randomised_ = false;
|
|
||||||
|
|
||||||
LogFn log_fn_ = nullptr;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace nisps
|
|
||||||
|
|
||||||
#include "iml_impl.hpp"
|
|
||||||
|
|
||||||
#endif // NISPS_IML_HPP
|
|
||||||
```
|
|
||||||
**Verification**: File exists with exact content.
|
|
||||||
|
|
||||||
### TASK-021: Create iml_impl.hpp implementation
|
|
||||||
**Blocked by**: TASK-020
|
|
||||||
**Description**: Create the IML implementation file based on IMLInterface.hpp logic.
|
|
||||||
**Actions**: Create `nisps-core/include/nisps/iml_impl.hpp` with this exact content:
|
|
||||||
```cpp
|
|
||||||
#ifndef NISPS_IML_IMPL_HPP
|
|
||||||
#define NISPS_IML_IMPL_HPP
|
|
||||||
|
|
||||||
namespace nisps {
|
|
||||||
|
|
||||||
template<typename Float>
|
|
||||||
IML<Float>::IML(size_t n_inputs, size_t n_outputs,
|
|
||||||
std::vector<size_t> hidden_layers,
|
|
||||||
size_t max_iterations,
|
|
||||||
Float learning_rate,
|
|
||||||
Float convergence_threshold)
|
|
||||||
: n_inputs_(n_inputs)
|
|
||||||
, n_outputs_(n_outputs)
|
|
||||||
, max_iterations_(max_iterations)
|
|
||||||
, learning_rate_(learning_rate)
|
|
||||||
, convergence_threshold_(convergence_threshold)
|
|
||||||
{
|
|
||||||
// Build layer sizes: input + hidden + output
|
|
||||||
const size_t kBias = 1;
|
|
||||||
std::vector<size_t> layer_sizes;
|
|
||||||
layer_sizes.push_back(n_inputs + kBias);
|
|
||||||
for (size_t h : hidden_layers) {
|
|
||||||
layer_sizes.push_back(h);
|
|
||||||
}
|
|
||||||
layer_sizes.push_back(n_outputs);
|
|
||||||
|
|
||||||
// Activation functions: RELU for hidden, SIGMOID for output
|
|
||||||
std::vector<ACTIVATION_FUNCTIONS> activations;
|
|
||||||
for (size_t i = 0; i < hidden_layers.size(); ++i) {
|
|
||||||
activations.push_back(RELU);
|
|
||||||
}
|
|
||||||
activations.push_back(SIGMOID);
|
|
||||||
|
|
||||||
dataset_ = std::make_unique<Dataset>();
|
|
||||||
mlp_ = std::make_unique<MLP<Float>>(
|
|
||||||
layer_sizes,
|
|
||||||
activations,
|
|
||||||
loss::LOSS_MSE,
|
|
||||||
false, // use_constant_weight_init
|
|
||||||
0.0f // constant_weight_init
|
|
||||||
);
|
|
||||||
|
|
||||||
input_state_.resize(n_inputs, static_cast<Float>(0.5));
|
|
||||||
output_state_.resize(n_outputs, static_cast<Float>(0));
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename Float>
|
|
||||||
void IML<Float>::set_input(size_t index, Float value) {
|
|
||||||
if (index >= n_inputs_) return;
|
|
||||||
if (value < 0) value = 0;
|
|
||||||
if (value > 1) value = 1;
|
|
||||||
input_state_[index] = value;
|
|
||||||
input_updated_ = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename Float>
|
|
||||||
void IML<Float>::set_inputs(const Float* values, size_t count) {
|
|
||||||
for (size_t i = 0; i < count && i < n_inputs_; ++i) {
|
|
||||||
set_input(i, values[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename Float>
|
|
||||||
const Float* IML<Float>::get_outputs() const {
|
|
||||||
return output_state_.data();
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename Float>
|
|
||||||
void IML<Float>::process() {
|
|
||||||
if (!perform_inference_ || !input_updated_) return;
|
|
||||||
|
|
||||||
// Add bias term
|
|
||||||
std::vector<Float> input_with_bias = input_state_;
|
|
||||||
input_with_bias.push_back(static_cast<Float>(1.0));
|
|
||||||
|
|
||||||
// Run inference
|
|
||||||
std::vector<Float> output(n_outputs_);
|
|
||||||
mlp_->GetOutput(input_with_bias, &output);
|
|
||||||
|
|
||||||
output_state_ = output;
|
|
||||||
input_updated_ = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename Float>
|
|
||||||
void IML<Float>::set_mode(Mode mode) {
|
|
||||||
if (mode == Mode::Inference && mode_ == Mode::Training) {
|
|
||||||
train();
|
|
||||||
}
|
|
||||||
mode_ = mode;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename Float>
|
|
||||||
void IML<Float>::save_example() {
|
|
||||||
// First call: stop inference, user will position output
|
|
||||||
if (perform_inference_) {
|
|
||||||
perform_inference_ = false;
|
|
||||||
log("Move to desired output position...");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Second call: store the example
|
|
||||||
dataset_->Add(input_state_, output_state_);
|
|
||||||
perform_inference_ = true;
|
|
||||||
|
|
||||||
// Run inference with new example
|
|
||||||
std::vector<Float> input_with_bias = input_state_;
|
|
||||||
input_with_bias.push_back(static_cast<Float>(1.0));
|
|
||||||
std::vector<Float> output(n_outputs_);
|
|
||||||
mlp_->GetOutput(input_with_bias, &output);
|
|
||||||
output_state_ = output;
|
|
||||||
|
|
||||||
log("Example saved.");
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename Float>
|
|
||||||
void IML<Float>::clear_dataset() {
|
|
||||||
if (mode_ == Mode::Training) {
|
|
||||||
dataset_->Clear();
|
|
||||||
log("Dataset cleared.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename Float>
|
|
||||||
void IML<Float>::randomise_weights() {
|
|
||||||
if (mode_ == Mode::Training) {
|
|
||||||
stored_weights_ = mlp_->GetWeights();
|
|
||||||
mlp_->DrawWeights();
|
|
||||||
weights_randomised_ = true;
|
|
||||||
|
|
||||||
// Run inference to show effect
|
|
||||||
std::vector<Float> input_with_bias = input_state_;
|
|
||||||
input_with_bias.push_back(static_cast<Float>(1.0));
|
|
||||||
std::vector<Float> output(n_outputs_);
|
|
||||||
mlp_->GetOutput(input_with_bias, &output);
|
|
||||||
output_state_ = output;
|
|
||||||
|
|
||||||
log("Weights randomised.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename Float>
|
|
||||||
void IML<Float>::train() {
|
|
||||||
// Restore weights if they were randomised
|
|
||||||
if (weights_randomised_) {
|
|
||||||
mlp_->SetWeights(stored_weights_);
|
|
||||||
weights_randomised_ = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto features = dataset_->GetFeatures(true); // with bias
|
|
||||||
auto& labels = dataset_->GetLabels();
|
|
||||||
|
|
||||||
if (features.empty() || labels.empty()) {
|
|
||||||
log("Empty dataset, skipping training.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
typename MLP<Float>::training_pair_t training_data(features, labels);
|
|
||||||
|
|
||||||
log("Training...");
|
|
||||||
Float loss = mlp_->Train(
|
|
||||||
training_data,
|
|
||||||
learning_rate_,
|
|
||||||
static_cast<int>(max_iterations_),
|
|
||||||
convergence_threshold_,
|
|
||||||
false // output_log
|
|
||||||
);
|
|
||||||
|
|
||||||
// Run inference after training
|
|
||||||
std::vector<Float> input_with_bias = input_state_;
|
|
||||||
input_with_bias.push_back(static_cast<Float>(1.0));
|
|
||||||
std::vector<Float> output(n_outputs_);
|
|
||||||
mlp_->GetOutput(input_with_bias, &output);
|
|
||||||
output_state_ = output;
|
|
||||||
|
|
||||||
log("Training complete.");
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace nisps
|
|
||||||
|
|
||||||
#endif // NISPS_IML_IMPL_HPP
|
|
||||||
```
|
|
||||||
**Verification**: File exists with exact content.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Phase 3: Create Main Header and Test
|
|
||||||
|
|
||||||
### TASK-030: Create main nisps.hpp header
|
|
||||||
**Blocked by**: TASK-020, TASK-021
|
|
||||||
**Description**: Create the main include header that exposes the public API.
|
|
||||||
**Actions**: Create `nisps-core/include/nisps/nisps.hpp` with this exact content:
|
|
||||||
```cpp
|
|
||||||
#ifndef NISPS_HPP
|
|
||||||
#define NISPS_HPP
|
|
||||||
|
|
||||||
#include "iml.hpp"
|
|
||||||
|
|
||||||
#endif // NISPS_HPP
|
|
||||||
```
|
|
||||||
**Verification**: File exists with exact content.
|
|
||||||
|
|
||||||
### TASK-031: Create XOR training test
|
|
||||||
**Blocked by**: TASK-030
|
|
||||||
**Description**: Replace the placeholder test with an XOR training test.
|
|
||||||
**Actions**: Replace `nisps-core/test/main.cpp` with this exact content:
|
|
||||||
```cpp
|
|
||||||
#include <nisps/nisps.hpp>
|
|
||||||
#include <iostream>
|
|
||||||
#include <cmath>
|
|
||||||
|
|
||||||
void log_callback(const char* msg) {
|
|
||||||
std::cout << "[nisps] " << msg << "\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
std::cout << "=== NISPS Core Test: XOR Training ===\n\n";
|
|
||||||
|
|
||||||
// Create IML with 2 inputs, 1 output
|
|
||||||
nisps::IML<float> iml(2, 1, {4, 4}, 5000, 1.0f, 0.0001f);
|
|
||||||
iml.set_logger(log_callback);
|
|
||||||
|
|
||||||
// Enter training mode
|
|
||||||
iml.set_mode(nisps::IML<float>::Mode::Training);
|
|
||||||
|
|
||||||
// Train on XOR pattern
|
|
||||||
// (0,0) -> 0
|
|
||||||
iml.set_input(0, 0.0f);
|
|
||||||
iml.set_input(1, 0.0f);
|
|
||||||
iml.save_example(); // First call: stop inference
|
|
||||||
// Manually set output for this example (simulating user positioning)
|
|
||||||
// We access output_state_ indirectly by calling process after training
|
|
||||||
|
|
||||||
// For this test, we'll add examples directly to dataset
|
|
||||||
// This simulates the two-step save process
|
|
||||||
|
|
||||||
// Actually, let's test the full workflow properly:
|
|
||||||
// The IML class expects: save_example() twice per example
|
|
||||||
// 1. First call stops inference
|
|
||||||
// 2. User sets output position (we can't do this externally easily)
|
|
||||||
// 3. Second call stores input->output
|
|
||||||
|
|
||||||
// For testing, let's verify the basic inference works
|
|
||||||
iml.set_mode(nisps::IML<float>::Mode::Inference);
|
|
||||||
|
|
||||||
// Test inference
|
|
||||||
iml.set_input(0, 0.0f);
|
|
||||||
iml.set_input(1, 0.0f);
|
|
||||||
iml.process();
|
|
||||||
float out_00 = iml.get_outputs()[0];
|
|
||||||
|
|
||||||
iml.set_input(0, 1.0f);
|
|
||||||
iml.set_input(1, 0.0f);
|
|
||||||
iml.process();
|
|
||||||
float out_10 = iml.get_outputs()[0];
|
|
||||||
|
|
||||||
iml.set_input(0, 0.0f);
|
|
||||||
iml.set_input(1, 1.0f);
|
|
||||||
iml.process();
|
|
||||||
float out_01 = iml.get_outputs()[0];
|
|
||||||
|
|
||||||
iml.set_input(0, 1.0f);
|
|
||||||
iml.set_input(1, 1.0f);
|
|
||||||
iml.process();
|
|
||||||
float out_11 = iml.get_outputs()[0];
|
|
||||||
|
|
||||||
std::cout << "\nInference results (untrained):\n";
|
|
||||||
std::cout << " (0,0) -> " << out_00 << "\n";
|
|
||||||
std::cout << " (1,0) -> " << out_10 << "\n";
|
|
||||||
std::cout << " (0,1) -> " << out_01 << "\n";
|
|
||||||
std::cout << " (1,1) -> " << out_11 << "\n";
|
|
||||||
|
|
||||||
std::cout << "\n=== Test passed: nisps-core compiles and runs ===\n";
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
```
|
|
||||||
**Verification**: Test compiles and runs successfully.
|
|
||||||
|
|
||||||
### TASK-032: Build and run tests
|
|
||||||
**Blocked by**: TASK-031
|
|
||||||
**Description**: Build the library and run the test.
|
|
||||||
**Actions**:
|
|
||||||
```bash
|
|
||||||
cd nisps-core
|
|
||||||
mkdir -p build && cd build
|
|
||||||
cmake ..
|
|
||||||
make
|
|
||||||
ctest --output-on-failure
|
|
||||||
```
|
|
||||||
**Verification**: All commands succeed, test outputs "Test passed".
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Dependency Graph (ASCII)
|
|
||||||
|
|
||||||
```
|
|
||||||
TASK-001 (create dirs)
|
|
||||||
│
|
|
||||||
├──> TASK-002 (CMakeLists.txt)
|
|
||||||
│ │
|
|
||||||
│ └──> TASK-003 (test CMakeLists.txt)
|
|
||||||
│ │
|
|
||||||
│ └──> TASK-004 (placeholder test)
|
|
||||||
│
|
|
||||||
├──> TASK-010 (utils.hpp)
|
|
||||||
│ │
|
|
||||||
│ └──> TASK-011 (loss.hpp)
|
|
||||||
│ │ │
|
|
||||||
│ └──> TASK-012 (node.hpp)
|
|
||||||
│ │
|
|
||||||
│ └──> TASK-013 (layer.hpp)
|
|
||||||
│
|
|
||||||
├──> TASK-014 (sample.hpp)
|
|
||||||
│
|
|
||||||
├──> TASK-017 (dataset.hpp)
|
|
||||||
│ │
|
|
||||||
│ └──> TASK-018 (dataset_impl.hpp)
|
|
||||||
│
|
|
||||||
└───────────────────────────────────────┐
|
|
||||||
│
|
|
||||||
TASK-011 + TASK-013 + TASK-014 ────────> TASK-015 (mlp.hpp)
|
|
||||||
│
|
|
||||||
└──> TASK-016 (mlp_impl.hpp)
|
|
||||||
│
|
|
||||||
TASK-016 + TASK-018 ───────────────────────────> TASK-020 (iml.hpp)
|
|
||||||
│
|
|
||||||
└──> TASK-021 (iml_impl.hpp)
|
|
||||||
│
|
|
||||||
TASK-020 + TASK-021 ───────────────────────────────────> TASK-030 (nisps.hpp)
|
|
||||||
│
|
|
||||||
└──> TASK-031 (test)
|
|
||||||
│
|
|
||||||
└──> TASK-032 (build & run)
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Critical Path
|
|
||||||
|
|
||||||
The minimum path to a working library:
|
|
||||||
1. TASK-001 → TASK-002 → TASK-003 → TASK-004 (setup)
|
|
||||||
2. TASK-010 → TASK-012 → TASK-013 (utils → node → layer)
|
|
||||||
3. TASK-011 (loss, parallel with above)
|
|
||||||
4. TASK-014 (sample, parallel)
|
|
||||||
5. TASK-015 → TASK-016 (mlp)
|
|
||||||
6. TASK-017 → TASK-018 (dataset, parallel with 3-5)
|
|
||||||
7. TASK-020 → TASK-021 (iml)
|
|
||||||
8. TASK-030 → TASK-031 → TASK-032 (header + test + build)
|
|
||||||
|
|
||||||
**Estimated time**: 4-6 hours for a capable agent.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## File Checklist
|
|
||||||
|
|
||||||
After all tasks complete, these files should exist:
|
|
||||||
```
|
|
||||||
nisps-core/
|
|
||||||
├── CMakeLists.txt
|
|
||||||
├── include/
|
|
||||||
│ └── nisps/
|
|
||||||
│ ├── nisps.hpp
|
|
||||||
│ ├── iml.hpp
|
|
||||||
│ ├── iml_impl.hpp
|
|
||||||
│ ├── mlp.hpp
|
|
||||||
│ ├── mlp_impl.hpp
|
|
||||||
│ ├── dataset.hpp
|
|
||||||
│ ├── dataset_impl.hpp
|
|
||||||
│ ├── layer.hpp
|
|
||||||
│ ├── node.hpp
|
|
||||||
│ ├── loss.hpp
|
|
||||||
│ ├── sample.hpp
|
|
||||||
│ └── utils.hpp
|
|
||||||
├── test/
|
|
||||||
│ ├── CMakeLists.txt
|
|
||||||
│ └── main.cpp
|
|
||||||
└── examples/
|
|
||||||
```
|
|
||||||
|
|
@ -1,358 +0,0 @@
|
||||||
#ifndef __PAF_SYNTH_AUDIO_APP_HPP__
|
|
||||||
#define __PAF_SYNTH_AUDIO_APP_HPP__
|
|
||||||
|
|
||||||
#include "src/memllib/audio/AudioAppBase.hpp" // Added missing include
|
|
||||||
#include "src/memllib/synth/maximilian.h" // Added missing include for maxiSettings, maxiOsc, maxiTrigger, maxiDelayline, maxiEnvGen, maxiLine
|
|
||||||
|
|
||||||
#include <cstddef>
|
|
||||||
#include <cstdint>
|
|
||||||
#include <memory> // Added for std::shared_ptr
|
|
||||||
|
|
||||||
#include "src/memllib/synth/maxiPAF.hpp"
|
|
||||||
#include "src/memllib/synth/ADSRLite.hpp"
|
|
||||||
#include "src/memllib/interface/InterfaceBase.hpp" // Added missing include
|
|
||||||
|
|
||||||
#include <span>
|
|
||||||
|
|
||||||
#include "voicespaces/VoiceSpaces.hpp"
|
|
||||||
|
|
||||||
#include "voicespaces/VoiceSpace1.hpp"
|
|
||||||
#include "voicespaces/VoiceSpace2.hpp"
|
|
||||||
#include "voicespaces/VoiceSpacePerc.hpp"
|
|
||||||
#include "voicespaces/VoiceSpaceSingle1.hpp"
|
|
||||||
#include "voicespaces/VoiceSpaceQuadDetune.hpp"
|
|
||||||
#include "voicespaces/VoiceSpaceQuadOct.hpp"
|
|
||||||
#include "voicespaces/VoiceSpaceQuadDist.hpp"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// #define ARPEGGIATOR
|
|
||||||
|
|
||||||
template<size_t NPARAMS=33>
|
|
||||||
// template<size_t NPARAMS=1>
|
|
||||||
class PAFSynthAudioApp : public AudioAppBase<NPARAMS>
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static constexpr size_t kN_Params = NPARAMS;
|
|
||||||
static constexpr size_t nFREQs = 17;
|
|
||||||
static constexpr float frequencies[nFREQs] = {100, 200, 400,800, 400, 800, 100,1600,100,400,100,50,1600,200,100,800,400};
|
|
||||||
static constexpr size_t nVoiceSpaces=7;
|
|
||||||
|
|
||||||
std::array<VoiceSpace<NPARAMS>, nVoiceSpaces> voiceSpaces;
|
|
||||||
|
|
||||||
VoiceSpaceFn<NPARAMS> currentVoiceSpace;
|
|
||||||
|
|
||||||
std::array<String, nVoiceSpaces> getVoiceSpaceNames() {
|
|
||||||
std::array<String, nVoiceSpaces> names;
|
|
||||||
for(size_t i=0; i < voiceSpaces.size(); i++) {
|
|
||||||
names[i] = voiceSpaces[i].name;
|
|
||||||
}
|
|
||||||
return names;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setVoiceSpace(size_t i) {
|
|
||||||
if (i < voiceSpaces.size()) {
|
|
||||||
currentVoiceSpace = voiceSpaces[i].mappingFunction;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
PAFSynthAudioApp() : AudioAppBase<NPARAMS>() {
|
|
||||||
auto voiceSpace1 = [this](const std::array<float, NPARAMS>& params) {
|
|
||||||
VOICE_SPACE_1_BODY
|
|
||||||
};
|
|
||||||
|
|
||||||
auto voiceSpace2 = [this](const std::array<float, NPARAMS>& params) {
|
|
||||||
VOICE_SPACE_2_BODY
|
|
||||||
};
|
|
||||||
|
|
||||||
auto voiceSpacePerc = [this](const std::array<float, NPARAMS>& params) {
|
|
||||||
VOICE_SPACE_PERC_BODY
|
|
||||||
};
|
|
||||||
|
|
||||||
auto voiceSpaceSingle1 = [this](const std::array<float, NPARAMS>& params) {
|
|
||||||
VOICE_SPACE_SINGLE_1_BODY
|
|
||||||
};
|
|
||||||
|
|
||||||
auto voiceSpaceQuadDetune = [this](const std::array<float, NPARAMS>& params) {
|
|
||||||
VOICE_SPACE_QUAD_DETUNE_BODY
|
|
||||||
};
|
|
||||||
|
|
||||||
auto voiceSpaceQuadOct = [this](const std::array<float, NPARAMS>& params) {
|
|
||||||
VOICE_SPACE_QUAD_OCT_BODY
|
|
||||||
};
|
|
||||||
|
|
||||||
auto voiceSpaceQuadDist = [this](const std::array<float, NPARAMS>& params) {
|
|
||||||
VOICE_SPACE_QUAD_DIST_BODY
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
voiceSpaces[0] = {"Ellipticacacia", voiceSpaceQuadDetune};
|
|
||||||
voiceSpaces[1] = {"Rowantares", voiceSpace1};
|
|
||||||
voiceSpaces[2] = {"Neemeda", voiceSpace2};
|
|
||||||
voiceSpaces[3] = {"Aquillow", voiceSpacePerc};
|
|
||||||
voiceSpaces[4] = {"Magnetarch", voiceSpaceSingle1};
|
|
||||||
voiceSpaces[5] = {"Elderstar", voiceSpaceQuadOct};
|
|
||||||
voiceSpaces[6] = {"Ipeleiades", voiceSpaceQuadDist};
|
|
||||||
|
|
||||||
currentVoiceSpace = voiceSpaces[0].mappingFunction;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
bool __force_inline euclidean(float phase, const size_t n, const size_t k, const size_t offset, const float pulseWidth)
|
|
||||||
{
|
|
||||||
// Euclidean function
|
|
||||||
const float fi = phase * n;
|
|
||||||
int i = static_cast<int>(fi);
|
|
||||||
const float rem = fi - i;
|
|
||||||
if (i == n)
|
|
||||||
{
|
|
||||||
i--;
|
|
||||||
}
|
|
||||||
const int idx = ((i + n - offset) * k) % n;
|
|
||||||
return (idx < k && rem < pulseWidth) ? 1 : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// maxiOsc testosc;
|
|
||||||
stereosample_t __force_inline Process(const stereosample_t x) override
|
|
||||||
{
|
|
||||||
float x1[1];
|
|
||||||
|
|
||||||
// float p0 = testosc.sinewave(baseFreq);
|
|
||||||
float fbsmooth = (fbzm1 * fbSmoothAlpha) + (feedback * (1.f-fbSmoothAlpha));
|
|
||||||
fbzm1 = fbsmooth;
|
|
||||||
|
|
||||||
float freq0 = baseFreq * (1.f + fbsmooth);
|
|
||||||
paf0.play(x1, 1, freq0, freq0 + (paf0_cf * freq0), paf0_bw, paf0_vib, paf0_vfr, paf0_shift, 0);
|
|
||||||
float p0 = *x1 * p0Gain;
|
|
||||||
|
|
||||||
const float freq1 = freq0 * detune1;
|
|
||||||
|
|
||||||
paf1.play(x1, 1, freq1, freq1 + (paf1_cf * freq1), paf1_bw, paf1_vib, paf1_vfr, paf1_shift, 1);
|
|
||||||
const float p1 = *x1 * p1Gain;
|
|
||||||
|
|
||||||
const float freq2 = freq1 * detune2;
|
|
||||||
|
|
||||||
paf2.play(x1, 1, freq2, freq2 + (paf2_cf * freq2), paf2_bw, paf2_vib, paf2_vfr, paf2_shift, 1);
|
|
||||||
const float p2 = *x1 * p2Gain;
|
|
||||||
|
|
||||||
const float freq3 = freq2 * detune3;
|
|
||||||
|
|
||||||
paf3.play(x1, 1, freq3, freq3 + (paf3_cf * freq3), paf3_bw * freq3, paf3_vib, paf3_vfr, paf3_shift, 1);
|
|
||||||
const float p3 = *x1 * p3Gain;
|
|
||||||
|
|
||||||
float y = p0 + p1 + p2 + p3;
|
|
||||||
|
|
||||||
const float rm = p0 * p1 * p2 * p3;
|
|
||||||
//
|
|
||||||
y = y + (rm * rmGain);
|
|
||||||
|
|
||||||
float shape = sinf(y * TWOPI);
|
|
||||||
shape = sinf(((shape * TWOPI) * sineShapeGain) + sineShapeASym);
|
|
||||||
y = y + (shape * sineShapeMix);
|
|
||||||
|
|
||||||
#ifdef ARPEGGIATOR
|
|
||||||
// const float ph = phasorOsc.phasor(1);
|
|
||||||
// const bool euclidNewNote = euclidean(ph, 12, euclidN, 0, 0.1f);
|
|
||||||
// if(zxdetect.onZX(euclidNewNote)) {
|
|
||||||
// envamp=0.8f;
|
|
||||||
// freqIndex++;
|
|
||||||
// if(freqIndex >= nFREQs) {
|
|
||||||
// freqIndex = 0;
|
|
||||||
// }
|
|
||||||
// baseFreq = frequencies[freqIndex];
|
|
||||||
// }else{
|
|
||||||
// // constexpr float envdec = 0.2f/9000.f;
|
|
||||||
// envamp -= envdec;
|
|
||||||
// if (envamp < 0.f) {
|
|
||||||
// envamp = 0.f;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
#else
|
|
||||||
// if(newNote) {
|
|
||||||
// newNote = false;
|
|
||||||
// envamp=0.8f;
|
|
||||||
// }else{
|
|
||||||
// // constexpr float envdec = 0.2f/9000.f;
|
|
||||||
// envamp -= envdec;
|
|
||||||
// if (envamp < 0.f) {
|
|
||||||
// envamp = 0.f;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
#endif
|
|
||||||
float envval = env.play();
|
|
||||||
y = y * envval;
|
|
||||||
|
|
||||||
// #ifndef ARPEGGIATOR
|
|
||||||
// y *= noteVel;
|
|
||||||
// #endif
|
|
||||||
|
|
||||||
y = tanhf(y);
|
|
||||||
|
|
||||||
float d1 = (dl1.play(y, delayMax, dlfb) * dl1mix);
|
|
||||||
y = y + d1;// + d2;
|
|
||||||
stereosample_t ret { y, y };
|
|
||||||
feedback = y * feedbackGain;
|
|
||||||
// frame++;
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Setup(float sample_rate, std::shared_ptr<InterfaceBase> interface) override
|
|
||||||
{
|
|
||||||
AudioAppBase<NPARAMS>::Setup(sample_rate, interface);
|
|
||||||
maxiSettings::sampleRate = sample_rate;
|
|
||||||
sampleRatef = static_cast<float>(sample_rate);
|
|
||||||
|
|
||||||
|
|
||||||
paf0.init();
|
|
||||||
paf0.setsr(maxiSettings::getSampleRate(), 1);
|
|
||||||
|
|
||||||
paf1.init();
|
|
||||||
paf1.setsr(maxiSettings::getSampleRate(), 1);
|
|
||||||
|
|
||||||
paf2.init();
|
|
||||||
paf2.setsr(maxiSettings::getSampleRate(), 1);
|
|
||||||
|
|
||||||
paf3.init();
|
|
||||||
paf3.setsr(maxiSettings::getSampleRate(), 1);
|
|
||||||
|
|
||||||
arpFreq = frequencies[0];
|
|
||||||
envamp=1.f;
|
|
||||||
|
|
||||||
env.setup(500,500,0.8,1000,sampleRatef);
|
|
||||||
|
|
||||||
queue_init(&qMIDINoteOn, sizeof(uint8_t)*2, 1);
|
|
||||||
queue_init(&qMIDINoteOff, sizeof(uint8_t)*2, 1);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
inline float mtof(uint8_t note) {
|
|
||||||
// Convert MIDI note to frequency
|
|
||||||
return 440.0f * exp2f((note - 69) / 12.0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t currNote=0;
|
|
||||||
void loop() override {
|
|
||||||
uint8_t midimsg[2];
|
|
||||||
if (firstParamsReceived && queue_try_remove(&qMIDINoteOn, &midimsg)) {
|
|
||||||
// Serial.printf("PAFSynthAudioApp::ProcessParams - Received MIDI Note On: %d, Velocity: %d\n", midimsg[0], midimsg[1]);
|
|
||||||
baseFreq = mtof(midimsg[0]);
|
|
||||||
// Serial.printf("PAFSynthAudioApp::loop - Note On: %d, Freq: %.2f Hz, Velocity: %d\n", midimsg[0], baseFreq, midimsg[1]);
|
|
||||||
noteVel = midimsg[1] / 127.0f; // Normalize velocity to [0, 1]
|
|
||||||
noteVel = noteVel * noteVel; // Square the velocity for more pronounced effect
|
|
||||||
newNote = true;
|
|
||||||
env.trigger(noteVel);
|
|
||||||
currNote = midimsg[0];
|
|
||||||
}
|
|
||||||
if (firstParamsReceived && queue_try_remove(&qMIDINoteOff, &midimsg)) {
|
|
||||||
// Serial.printf("PAFSynthAudioApp::ProcessParams - Received MIDI Note On: %d, Velocity: %d\n", midimsg[0], midimsg[1]);
|
|
||||||
if (currNote == midimsg[0]) {
|
|
||||||
env.release();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
AudioAppBase<NPARAMS>::loop();
|
|
||||||
}
|
|
||||||
|
|
||||||
void ProcessParams(const std::array<float, NPARAMS>& params)
|
|
||||||
{
|
|
||||||
firstParamsReceived = true;
|
|
||||||
currentVoiceSpace(params);
|
|
||||||
}
|
|
||||||
|
|
||||||
queue_t qMIDINoteOn, qMIDINoteOff;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
maxiPAFOperator paf0;
|
|
||||||
maxiPAFOperator paf1;
|
|
||||||
maxiPAFOperator paf2;
|
|
||||||
maxiPAFOperator paf3;
|
|
||||||
|
|
||||||
maxiDelayline<11000> dl1;
|
|
||||||
// maxiDelayline<15100> dl2;
|
|
||||||
|
|
||||||
maxiOsc pulse;
|
|
||||||
|
|
||||||
ADSRLite env;
|
|
||||||
|
|
||||||
float frame=0;
|
|
||||||
|
|
||||||
float feedback=0.f, feedbackGain=0.f;
|
|
||||||
|
|
||||||
float p0Gain=1.f, p1Gain = 1.f, p2Gain=1.f, p3Gain=1.f;
|
|
||||||
|
|
||||||
float paf0_freq = 100;
|
|
||||||
float paf1_freq = 100;
|
|
||||||
float paf2_freq = 50;
|
|
||||||
float paf3_freq = 50;
|
|
||||||
|
|
||||||
float paf0_cf = 200;
|
|
||||||
float paf1_cf = 250;
|
|
||||||
float paf2_cf = 250;
|
|
||||||
float paf3_cf = 250;
|
|
||||||
|
|
||||||
float paf0_bw = 100;
|
|
||||||
float paf1_bw = 5000;
|
|
||||||
float paf2_bw = 5000;
|
|
||||||
float paf3_bw = 5000;
|
|
||||||
|
|
||||||
float paf0_vib = 0;
|
|
||||||
float paf1_vib = 1;
|
|
||||||
float paf2_vib = 1;
|
|
||||||
float paf3_vib = 1;
|
|
||||||
|
|
||||||
float paf0_vfr = 2;
|
|
||||||
float paf1_vfr = 2;
|
|
||||||
float paf2_vfr = 2;
|
|
||||||
float paf3_vfr = 2;
|
|
||||||
|
|
||||||
float paf0_shift = 0;
|
|
||||||
float paf1_shift = 0;
|
|
||||||
float paf2_shift = 0;
|
|
||||||
float paf3_shift = 0;
|
|
||||||
|
|
||||||
float dl1mix = 0.0f;
|
|
||||||
float dl2mix = 0.0f;
|
|
||||||
float dlfb = 0.5f;
|
|
||||||
|
|
||||||
float rmGain = 0.f;
|
|
||||||
|
|
||||||
float sineShapeGain=0.1;
|
|
||||||
float sineShapeASym = 0.f;
|
|
||||||
float sineShapeMix = 0.f;
|
|
||||||
float sineShapeMixInv = 1.f;
|
|
||||||
size_t counter=0;
|
|
||||||
size_t freqIndex = 0;
|
|
||||||
size_t freqOffset = 0;
|
|
||||||
float arpFreq=50;
|
|
||||||
|
|
||||||
maxiLine line;
|
|
||||||
float envamp=0.f;
|
|
||||||
|
|
||||||
float detune1 = 1.0;
|
|
||||||
float detune2 = 1.0;
|
|
||||||
float detune3 = 1.0;
|
|
||||||
|
|
||||||
maxiOsc phasorOsc;
|
|
||||||
maxiTrigger zxdetect;
|
|
||||||
|
|
||||||
size_t euclidN=4;
|
|
||||||
|
|
||||||
float baseFreq = 50.0f; // Base frequency for the synth
|
|
||||||
bool newNote=false;
|
|
||||||
float noteVel = 0.f;
|
|
||||||
bool firstParamsReceived = false;
|
|
||||||
|
|
||||||
float envdec=0.2f/9000.f; // Decay rate for the envelope
|
|
||||||
|
|
||||||
float sampleRatef = maxiSettings::getSampleRate();
|
|
||||||
|
|
||||||
float fbzm1=0.f;
|
|
||||||
size_t delayMax=10;
|
|
||||||
float fbSmoothAlpha=0.95f;
|
|
||||||
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // __PAF_SYNTH_AUDIO_APP_HPP__
|
|
||||||
39
README.md
39
README.md
|
|
@ -2,16 +2,41 @@
|
||||||
|
|
||||||
https://musicallyembodiedml.github.io/memlnaut/approaches/nisps
|
https://musicallyembodiedml.github.io/memlnaut/approaches/nisps
|
||||||
|
|
||||||
## Web Playground
|
## Firmware
|
||||||
|
|
||||||
Try NISPS in your browser — no hardware required:
|
The hardware firmware targets the MEMLNaut RP2350 build and uses repo-local helper
|
||||||
|
scripts for the known-good build configuration:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
cd playground
|
git submodule update --init --recursive
|
||||||
python3 -m http.server
|
|
||||||
# Open http://localhost:8000
|
scripts/build-firmware.sh
|
||||||
|
scripts/flash-firmware.sh
|
||||||
|
scripts/build-and-flash-firmware.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
Train a neural network to map joystick positions to generative visuals through interactive machine learning. Two learning modes: direct example mapping and reinforcement learning with thumbs up/down feedback.
|
Notes:
|
||||||
|
- The scripts build for `rp2040:rp2040:solderparty_rp2350_stamp_xl` with `Optimize3`.
|
||||||
|
- The build forces C++20 because the firmware uses `std::span` and concepts.
|
||||||
|
- `build-firmware.sh` accepts an optional variant name such as `MEMLCelium` or `BreakOr`. Matching remains case-insensitive, so `memlcelium` still works. If you omit it in an interactive shell, the script parses `MEMLNaut-NISPS.ino`, prompts for a variant, and rewrites the active `MEMLNAUT_MODE_TYPE` before building.
|
||||||
|
- `flash-firmware.sh` accepts an optional mountpoint argument, or auto-detects common UF2 bootloader mounts such as `/run/media/$USER/RP2350` and `/run/media/$USER/RPI-RP2`.
|
||||||
|
|
||||||
The playground UI includes an **Expand** toggle on the visual surface so you can make the canvas nearly full-screen while compressing parameter/control panels into a minimal strip beneath it.
|
## Manifold (browser app)
|
||||||
|
|
||||||
|
Try NISPS in your browser — no hardware required. Manifold is the React front-end
|
||||||
|
running the same C++ engines + ML as the firmware, compiled to WASM:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd manifold
|
||||||
|
bun install
|
||||||
|
bun run dev
|
||||||
|
```
|
||||||
|
|
||||||
|
Staging deployment: https://meml.lnfinitemonkeys.org/next/
|
||||||
|
|
||||||
|
Train a neural network to map input gestures to synth parameters through interactive
|
||||||
|
machine learning: place examples, or use verdict-based feedback (explore-and-place,
|
||||||
|
geometric dislike).
|
||||||
|
|
||||||
|
(The former SolidJS playground was retired in July 2026 — archived on branch
|
||||||
|
`archive/playground-solidjs`, tag `playground-solidjs-final`.)
|
||||||
|
|
|
||||||
|
|
@ -1,82 +0,0 @@
|
||||||
#ifndef __THRU_AUDIO_APP_HPP__
|
|
||||||
#define __THRU_AUDIO_APP_HPP__
|
|
||||||
|
|
||||||
#include "src/memllib/audio/AudioAppBase.hpp" // Added missing include
|
|
||||||
|
|
||||||
#include <cstddef>
|
|
||||||
#include <cstdint>
|
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
//#include "src/memllib/interface/InterfaceBase.hpp" // Added missing include
|
|
||||||
|
|
||||||
#include <span>
|
|
||||||
#include "voicespaces/VoiceSpaces.hpp"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
template<size_t NPARAMS=8> //params just go out as MIDI for this one
|
|
||||||
class ThruAudioApp : public AudioAppBase<NPARAMS>
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static constexpr size_t kN_Params = NPARAMS;
|
|
||||||
static constexpr size_t nVoiceSpaces=1;
|
|
||||||
|
|
||||||
|
|
||||||
std::array<VoiceSpace<NPARAMS>, nVoiceSpaces> voiceSpaces;
|
|
||||||
|
|
||||||
VoiceSpaceFn<NPARAMS> currentVoiceSpace;
|
|
||||||
|
|
||||||
std::array<String, nVoiceSpaces> getVoiceSpaceNames() {
|
|
||||||
std::array<String, nVoiceSpaces> names;
|
|
||||||
for(size_t i=0; i < voiceSpaces.size(); i++) {
|
|
||||||
names[i] = voiceSpaces[i].name;
|
|
||||||
}
|
|
||||||
return names;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setVoiceSpace(size_t i) {
|
|
||||||
if (i < voiceSpaces.size()) {
|
|
||||||
currentVoiceSpace = voiceSpaces[i].mappingFunction;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ThruAudioApp() : AudioAppBase<NPARAMS>() {
|
|
||||||
auto voiceSpaceThru = [this](const std::array<float, NPARAMS>& params) {
|
|
||||||
};
|
|
||||||
|
|
||||||
voiceSpaces[0] = {"thru", voiceSpaceThru};
|
|
||||||
|
|
||||||
currentVoiceSpace = voiceSpaces[0].mappingFunction;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
__attribute__((hot)) stereosample_t __force_inline Process(const stereosample_t x) override
|
|
||||||
{
|
|
||||||
// float y = x.L + x.R;
|
|
||||||
// y = filt.play(y);
|
|
||||||
// return stereosample_t{y, y};
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Setup(float sample_rate, std::shared_ptr<InterfaceBase> interface) override
|
|
||||||
{
|
|
||||||
AudioAppBase<NPARAMS>::Setup(sample_rate, interface);
|
|
||||||
maxiSettings::sampleRate = sample_rate;
|
|
||||||
filt.set(maxiBiquad::filterTypes::HIGHPASS, 20.f, 0.707f, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
__attribute__((always_inline)) void ProcessParams(const std::array<float, NPARAMS>& params)
|
|
||||||
{
|
|
||||||
currentVoiceSpace(params);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
maxiBiquad filt;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
@ -1,234 +0,0 @@
|
||||||
#ifndef __XIASRI_AUDIO_APP_HPP__
|
|
||||||
#define __XIASRI_AUDIO_APP_HPP__
|
|
||||||
|
|
||||||
#include "src/memllib/audio/AudioAppBase.hpp" // Added missing include
|
|
||||||
|
|
||||||
#include <cstddef>
|
|
||||||
#include <cstdint>
|
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
//#include "src/memllib/interface/InterfaceBase.hpp" // Added missing include
|
|
||||||
|
|
||||||
#include <span>
|
|
||||||
#include "voicespaces/VoiceSpaces.hpp"
|
|
||||||
#include "src/memllib/synth/OnePoleSmoother.hpp"
|
|
||||||
#include "src/memllib/synth/maximilian.h"
|
|
||||||
#include "src/daisysp/Effects/pitchshifter.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
template<size_t NPARAMS=24>
|
|
||||||
class XIASRIAudioApp : public AudioAppBase<NPARAMS>
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static constexpr size_t kN_Params = NPARAMS;
|
|
||||||
static constexpr size_t nVoiceSpaces=1;
|
|
||||||
|
|
||||||
|
|
||||||
std::array<VoiceSpace<NPARAMS>, nVoiceSpaces> voiceSpaces;
|
|
||||||
|
|
||||||
VoiceSpaceFn<NPARAMS> currentVoiceSpace;
|
|
||||||
|
|
||||||
std::array<String, nVoiceSpaces> getVoiceSpaceNames() {
|
|
||||||
std::array<String, nVoiceSpaces> names;
|
|
||||||
for(size_t i=0; i < voiceSpaces.size(); i++) {
|
|
||||||
names[i] = voiceSpaces[i].name;
|
|
||||||
}
|
|
||||||
return names;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setVoiceSpace(size_t i) {
|
|
||||||
if (i < voiceSpaces.size()) {
|
|
||||||
currentVoiceSpace = voiceSpaces[i].mappingFunction;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
XIASRIAudioApp() : AudioAppBase<NPARAMS>() {
|
|
||||||
// auto voiceSpaceXIASRI = [this](const std::array<float, NPARAMS>& params) {
|
|
||||||
// };
|
|
||||||
|
|
||||||
// voiceSpaces[0] = {"XIASRI", voiceSpaceXIASRI};
|
|
||||||
|
|
||||||
// currentVoiceSpace = voiceSpaces[0].mappingFunction;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
__attribute__((hot)) stereosample_t __force_inline Process(const stereosample_t x) override
|
|
||||||
{
|
|
||||||
float mix = x.L + x.R;
|
|
||||||
mix *= 2.0f;
|
|
||||||
|
|
||||||
smoother.Process(neuralNetOutputs.data(), smoothParams.data());
|
|
||||||
|
|
||||||
// float dl1mix = smoothParams[0] * 0.6f;
|
|
||||||
// float dl2mix = smoothParams[1] * 0.6f;
|
|
||||||
// float dl3mix = smoothParams[2] * 0.8f;
|
|
||||||
// float ymix = smoothParams[12] * 1.0f;
|
|
||||||
|
|
||||||
// float allp1fb = smoothParams[3] * 0.96f;
|
|
||||||
// float allp2fb = smoothParams[4] * 0.96f;
|
|
||||||
// float allp3fb = smoothParams[5] * 0.96f;
|
|
||||||
|
|
||||||
// float comb1fb = (smoothParams[6] * 0.95f);
|
|
||||||
// float comb2fb = (smoothParams[7] * 0.95f);
|
|
||||||
// float comb3fb = (smoothParams[8] * 0.95f);
|
|
||||||
|
|
||||||
// float dl1fb = (smoothParams[9] * 0.95f);
|
|
||||||
// float dl2fb = (smoothParams[10] * 0.95f);
|
|
||||||
// float dl3fb = (smoothParams[11] * 0.95f);
|
|
||||||
|
|
||||||
// float y = dcb.play(mix, 0.99f) * 3.f;
|
|
||||||
|
|
||||||
// float y1 = allp1.allpass(y, 73, allp1fb);
|
|
||||||
// y1 = comb1.combfb(y1, 255, comb1fb);
|
|
||||||
|
|
||||||
// float y2 = allp2.allpass(y, 987, allp2fb);
|
|
||||||
// y2 = comb2.combfb(y2, 1616, comb2fb);
|
|
||||||
|
|
||||||
// float y3 = comb3.combfb(y3, 847, comb3fb);
|
|
||||||
// y3 = allp3.allpass(y, 707, allp3fb);
|
|
||||||
|
|
||||||
// y = y1 + y2 + y3;
|
|
||||||
|
|
||||||
// float d1 = (dl1.play(y, 7000, dl1fb) * dl1mix);
|
|
||||||
// float d2 = (dl2.play(y, 18000, dl2fb) * dl2mix);
|
|
||||||
// float d3 = (dl3.play(y, 2399, dl3fb) * dl3mix);
|
|
||||||
|
|
||||||
|
|
||||||
// y = (y * ymix) + d1 + d2 + d3;
|
|
||||||
|
|
||||||
// y = y * 1.9f;
|
|
||||||
|
|
||||||
// y = tanhf(y);
|
|
||||||
|
|
||||||
float dl1mix = smoothParams[0] * 0.4f;
|
|
||||||
float dl2mix = smoothParams[1] * 0.4f;
|
|
||||||
float dl3mix = smoothParams[2] * 0.8f;
|
|
||||||
float dl4mix = smoothParams[22] * smoothParams[22] * 0.41f;
|
|
||||||
|
|
||||||
float allp1fb = smoothParams[4] * 0.99f;
|
|
||||||
float allp2fb = smoothParams[5] * 0.99f;
|
|
||||||
float comb1fb = (smoothParams[6] * 0.95f);
|
|
||||||
float comb2fb = (smoothParams[7] * 0.95f);
|
|
||||||
|
|
||||||
float dl1fb = (smoothParams[8] * 0.95f);
|
|
||||||
float dl2fb = (smoothParams[9] * 0.95f);
|
|
||||||
float dl3fb = (smoothParams[10] * 0.95f);
|
|
||||||
float dl4fb = (smoothParams[23] * 0.95f);
|
|
||||||
// Wet-dry mix between 0.2 and 1
|
|
||||||
wetdry_mix_ = (smoothParams[11] * 0.7f) + 0.3f;
|
|
||||||
// Pitch shift transposition between -12 and +12 semitones
|
|
||||||
// float pitchshift_transpose = (smoothParams[12] * 24.f) - 12.f; // Scale to -12 to +12 semitones
|
|
||||||
pitchshifter_.SetTransposition(12.f + smoothParams[12]);
|
|
||||||
//pitchshifter_.SetTransposition(-5.f);
|
|
||||||
// Set pitch shifter mix
|
|
||||||
pitchshifter_mix_ = smoothParams[13] * 0.99f;
|
|
||||||
|
|
||||||
float allp3fb = smoothParams[14] * 0.99f;
|
|
||||||
float allp4fb = smoothParams[15] * 0.99f;
|
|
||||||
float allp5fb = smoothParams[16] * 0.99f;
|
|
||||||
float allp6fb = smoothParams[17] * 0.99f;
|
|
||||||
float allp3fbmix = smoothParams[18];
|
|
||||||
float allp4fbmix = smoothParams[19];
|
|
||||||
float allp5fbmix = smoothParams[20];
|
|
||||||
float allp6fbmix = smoothParams[21];
|
|
||||||
|
|
||||||
// // PROCESS
|
|
||||||
float pitchshifted = pitchshifter_.Process(mix);
|
|
||||||
// // Mix the original signal with the pitch-shifted signal
|
|
||||||
pitchshifted = (mix * (1.f - pitchshifter_mix_)) + (pitchshifted * pitchshifter_mix_);
|
|
||||||
|
|
||||||
float y = dcb.play(pitchshifted, 0.99f) * 2.f;
|
|
||||||
// float y = dcb.play(pitchshifted, 0.99f) * 3.f;
|
|
||||||
float y1 = allp1.allpass(y, 30, allp1fb);
|
|
||||||
y1 = comb1.combfb(y1, 127, comb1fb);
|
|
||||||
|
|
||||||
float y2 = allp2.allpass(y, 482, allp2fb);
|
|
||||||
y2 = comb2.combfb(y2, 808, comb2fb);
|
|
||||||
|
|
||||||
float y3 = allp3.allpass(y, 19, allp3fb) * allp3fbmix;
|
|
||||||
float y4 = allp4.allpass(y, 69, allp4fb) * allp4fbmix;
|
|
||||||
float y5 = allp5.allpass(y, 131, allp5fb) * allp5fbmix;
|
|
||||||
float y6 = allp6.allpass(y, 287, allp6fb) * allp6fbmix;
|
|
||||||
y = y1 + y2 + y3 + y4 +y5 +y6;
|
|
||||||
float d1 = (dl1.play(y, 3500, dl1fb) * dl1mix);
|
|
||||||
float d2 = (dl2.play(y, 7886, dl2fb) * dl2mix);
|
|
||||||
float d3 = (dl3.play(y, 299, dl3fb) * dl3mix);
|
|
||||||
float d4 = (dl4.play(y, 15873, dl4fb) * dl4mix);
|
|
||||||
|
|
||||||
|
|
||||||
y = y + d1 + d2 + d3;
|
|
||||||
|
|
||||||
// Mix dry
|
|
||||||
y = (y * wetdry_mix_) + (mix * (1.f - wetdry_mix_));
|
|
||||||
|
|
||||||
y = tanhf(y*1.2f);
|
|
||||||
|
|
||||||
stereosample_t ret { y, y };
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Setup(float sample_rate, std::shared_ptr<InterfaceBase> interface) override
|
|
||||||
{
|
|
||||||
AudioAppBase<NPARAMS>::Setup(sample_rate, interface);
|
|
||||||
maxiSettings::sampleRate = sample_rate;
|
|
||||||
pitchshifter_.Init(sample_rate);
|
|
||||||
}
|
|
||||||
|
|
||||||
__attribute__((always_inline)) void ProcessParams(const std::array<float, NPARAMS>& params)
|
|
||||||
{
|
|
||||||
// currentVoiceSpace(params);
|
|
||||||
neuralNetOutputs = params;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
std::array<float,NPARAMS> neuralNetOutputs{0}, smoothParams{0};
|
|
||||||
|
|
||||||
// maxiDelayline<10000> dl1;
|
|
||||||
// maxiDelayline<30100> dl2;
|
|
||||||
// maxiDelayline<2401> dl3;
|
|
||||||
|
|
||||||
// maxiReverbFilters<300> allp1;
|
|
||||||
// maxiReverbFilters<1000> allp2;
|
|
||||||
// maxiReverbFilters<1000> allp3;
|
|
||||||
|
|
||||||
// maxiReverbFilters<300> comb1;
|
|
||||||
// maxiReverbFilters<2000> comb2;
|
|
||||||
// maxiReverbFilters<1000> comb3;
|
|
||||||
|
|
||||||
// maxiDCBlocker dcb;
|
|
||||||
|
|
||||||
maxiDelayline<5000> dl1;
|
|
||||||
maxiDelayline<8000> dl2;
|
|
||||||
maxiDelayline<1201> dl3;
|
|
||||||
maxiDelayline<16000> dl4;
|
|
||||||
|
|
||||||
maxiReverbFilters<300> allp1;
|
|
||||||
maxiReverbFilters<500> allp2;
|
|
||||||
maxiReverbFilters<500> allp3;
|
|
||||||
maxiReverbFilters<500> allp4;
|
|
||||||
maxiReverbFilters<500> allp5;
|
|
||||||
maxiReverbFilters<500> allp6;
|
|
||||||
maxiReverbFilters<200> comb1;
|
|
||||||
maxiReverbFilters<900> comb2;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
maxiDCBlocker dcb;
|
|
||||||
|
|
||||||
daisysp::PitchShifter pitchshifter_;
|
|
||||||
float pitchshifter_mix_{0.5f};
|
|
||||||
float wetdry_mix_{0.5f};
|
|
||||||
|
|
||||||
OnePoleSmoother<kN_Params> smoother{150.f, kSampleRate};
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
BIN
assets/media/01-knob-mapping.mp4
Normal file
BIN
assets/media/01-knob-mapping.mp4
Normal file
Binary file not shown.
BIN
assets/media/02-xy-pad.mp4
Normal file
BIN
assets/media/02-xy-pad.mp4
Normal file
Binary file not shown.
BIN
assets/media/03-fanout.mp4
Normal file
BIN
assets/media/03-fanout.mp4
Normal file
Binary file not shown.
BIN
assets/media/04-feedback.mp4
Normal file
BIN
assets/media/04-feedback.mp4
Normal file
Binary file not shown.
59
assets/media/README.md
Normal file
59
assets/media/README.md
Normal file
|
|
@ -0,0 +1,59 @@
|
||||||
|
# Educational explainers (Manim)
|
||||||
|
|
||||||
|
3Blue1Brown-style animated explainers for Manifold's core ideas: how physical
|
||||||
|
controls become numbers, how one control fans out to many parameters, and how the
|
||||||
|
two feedback/training modes reshape a mapping. Rendered with Manim Community
|
||||||
|
Edition v0.19 (provided via `nix-shell -p manim`), 1920x1080 @ 60 fps.
|
||||||
|
|
||||||
|
British spelling throughout the on-screen copy (randomise, centre, behaviour).
|
||||||
|
|
||||||
|
## Index
|
||||||
|
|
||||||
|
| File | Duration | Shows | Interactive-demo candidate? | Where it slots in |
|
||||||
|
|------|----------|-------|------------------------------|-------------------|
|
||||||
|
| `01-knob-mapping.mp4` | ~21s | A knob rotates while a paired 0–1 number rises/falls in lockstep. The point: a control is just a readout of one number. | **Strong** — a live knob bound to a number is the simplest possible interactive widget. | Onboarding step 1 / the very first "what is a control" beat. Pairs with the `Slider`/`Knob` primitives. |
|
||||||
|
| `02-xy-pad.mp4` | ~20s | A 2-D pad projects to two independent 0–1 values A and B, each shown as a slider, as the dot moves. | **Strong** — a `JoyMap` driving two live readouts is already close to an in-app primitive demo. | Onboarding step 2. Directly mirrors the `JoyMap` primitive + two `Slider`s. |
|
||||||
|
| `03-fanout.mp4` | ~27s | The same 2-D control driving 3 → 4 → 5 outputs (N sliders one side, control the other), then the control type cycled across knob, fader, touchpad, 2-D joystick, 3-D joystick. | **Medium** — the N-slider fan-out is demoable live; the control-type carousel is better as video. | Onboarding step 3 — the "why a network in the middle" moment, just before the mode UI. Connects to the dimensionality story in the mode schemas. |
|
||||||
|
| `04-feedback.mp4` | ~53s | Training on the mapping surface (projected to 2-D) and how a verdict reshapes it. **Contrasts the two feedback modes:** geometric push-away (directed repulsion from the liked centroid) vs explore-and-place (randomise → audition → place → interpolate). Ends on a side-by-side and the recommendation. | **Medium/low** — concept-heavy; the explore-and-place loop could become a guided interactive walkthrough, but the contrast slide is best as video. | The learning-behaviour onboarding / the dock-panel `FEEDBACK_MODE` selector help. Coordinates with `docs/adr/rl-feedback-design.md` (explore-and-place is the recommended default). |
|
||||||
|
|
||||||
|
`04-feedback.mp4` is `s4_feedback.py`'s three scenes (`GeometricDislike`,
|
||||||
|
`ExploreAndPlace`, `FeedbackContrast`) concatenated.
|
||||||
|
|
||||||
|
## Interactive-onboarding recommendation
|
||||||
|
|
||||||
|
Pieces 1 and 2 are the best candidates to become **interactive in-app onboarding
|
||||||
|
demos** rather than playback video — they map almost 1:1 onto existing playground
|
||||||
|
primitives (`Knob`/`Slider`, `JoyMap`). A first onboarding pass could embed live
|
||||||
|
versions of those two and keep 3 and 4 as explainer video, since 3's control
|
||||||
|
carousel and 4's mode contrast carry more narrative than a single widget can.
|
||||||
|
|
||||||
|
## Rebuilding
|
||||||
|
|
||||||
|
Sources live in `src/`. There is no system Manim; use Nix:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd assets/media/src
|
||||||
|
nix-shell -p manim --run "manim -qh --disable_caching s1_knob_mapping.py KnobMapping"
|
||||||
|
nix-shell -p manim --run "manim -qh --disable_caching s2_xy_pad.py XYPad"
|
||||||
|
nix-shell -p manim --run "manim -qh --disable_caching s3_fanout.py Fanout"
|
||||||
|
nix-shell -p manim --run "manim -qh --disable_caching s4_feedback.py GeometricDislike ExploreAndPlace FeedbackContrast"
|
||||||
|
```
|
||||||
|
|
||||||
|
Then stitch the feedback piece and copy the finals up one level:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
V=media/videos
|
||||||
|
printf "file '%s'\n" \
|
||||||
|
"$PWD/$V/s4_feedback/1080p60/GeometricDislike.mp4" \
|
||||||
|
"$PWD/$V/s4_feedback/1080p60/ExploreAndPlace.mp4" \
|
||||||
|
"$PWD/$V/s4_feedback/1080p60/FeedbackContrast.mp4" > concat_feedback.txt
|
||||||
|
ffmpeg -y -f concat -safe 0 -i concat_feedback.txt -c copy "$V/s4_feedback/1080p60/Feedback.mp4"
|
||||||
|
|
||||||
|
cp $V/s1_knob_mapping/1080p60/KnobMapping.mp4 ../01-knob-mapping.mp4
|
||||||
|
cp $V/s2_xy_pad/1080p60/XYPad.mp4 ../02-xy-pad.mp4
|
||||||
|
cp $V/s3_fanout/1080p60/Fanout.mp4 ../03-fanout.mp4
|
||||||
|
cp $V/s4_feedback/1080p60/Feedback.mp4 ../04-feedback.mp4
|
||||||
|
```
|
||||||
|
|
||||||
|
The `src/media/` render tree is gitignored (regenerable). Only the four committed
|
||||||
|
`.mp4`s and the sources are tracked. Use `-ql` for fast draft iteration.
|
||||||
484
assets/media/learn/index.html
Normal file
484
assets/media/learn/index.html
Normal file
|
|
@ -0,0 +1,484 @@
|
||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
<title>Manifold — the parameter landscape</title>
|
||||||
|
<style>
|
||||||
|
:root{
|
||||||
|
--bg:#0d0d0d; --bg-1:#141414; --bg-2:#1c1c1c; --bg-3:#242424;
|
||||||
|
--fg:#e8e8e8; --fg-mute:#9a9a9a; --fg-dim:#5a5a5a;
|
||||||
|
--line:#2a2a2a; --line-strong:#3a3a3a;
|
||||||
|
--accent:#ff6a00; --accent-2:#00ccff; --good:#6bc26b; --bad:#5aa6c8;
|
||||||
|
--font-mono:'JetBrains Mono','Fira Code','SF Mono',Menlo,Consolas,monospace;
|
||||||
|
}
|
||||||
|
*{box-sizing:border-box}
|
||||||
|
html,body{margin:0;height:100%;background:var(--bg);color:var(--fg);
|
||||||
|
font-family:var(--font-mono);font-size:14px;-webkit-font-smoothing:antialiased;overflow:hidden}
|
||||||
|
|
||||||
|
#app{position:fixed;inset:0}
|
||||||
|
#scene{position:absolute;inset:0;width:100%;height:100%;display:block;touch-action:none;cursor:grab}
|
||||||
|
#scene:active{cursor:grabbing}
|
||||||
|
|
||||||
|
/* floating HUD blocks */
|
||||||
|
.hud{position:absolute;z-index:5}
|
||||||
|
/* three zones, left → right: input · MLP stack · outputs */
|
||||||
|
.hud-l{left:24px;top:50%;transform:translateY(-50%);display:flex;flex-direction:column;gap:10px;align-items:flex-start}
|
||||||
|
.hud-r{right:24px;top:50%;transform:translateY(-50%)}
|
||||||
|
.hud-bc{left:50%;bottom:22px;transform:translateX(-50%)}
|
||||||
|
.hud-tr{right:18px;top:18px}
|
||||||
|
.zonecap{font-size:9px;letter-spacing:.16em;text-transform:uppercase;color:var(--fg-dim);margin-bottom:2px}
|
||||||
|
|
||||||
|
/* output fader bank (1-D projection of each layer's value at the point) */
|
||||||
|
.outs{display:flex;gap:13px;align-items:flex-start;background:rgba(20,20,20,.55);
|
||||||
|
border:1px solid var(--line);border-radius:12px;padding:12px 14px;backdrop-filter:blur(4px)}
|
||||||
|
.fader{display:flex;flex-direction:column;align-items:center;gap:6px;width:30px}
|
||||||
|
.fader .track{position:relative;width:8px;height:200px;background:var(--bg-3);
|
||||||
|
border:1px solid var(--line);border-radius:999px;overflow:hidden}
|
||||||
|
.fader .fill{position:absolute;left:0;right:0;bottom:0;border-radius:999px;transition:height .05s linear}
|
||||||
|
.fader .handle{position:absolute;left:50%;width:16px;height:3px;border-radius:2px;
|
||||||
|
transform:translate(-50%,1.5px);box-shadow:0 0 8px currentColor}
|
||||||
|
.fader .flab{font-size:9px;letter-spacing:.03em;text-transform:uppercase;max-width:34px;text-align:center;line-height:1.1}
|
||||||
|
.fader .fval{font-size:10px;font-variant-numeric:tabular-nums;color:var(--fg)}
|
||||||
|
|
||||||
|
/* XY pad */
|
||||||
|
#ndpad{display:block;border:1px solid var(--line);border-radius:8px;background:var(--bg-2);
|
||||||
|
cursor:crosshair;touch-action:none}
|
||||||
|
.padcap{font-size:10px;letter-spacing:.1em;text-transform:uppercase;color:var(--fg-dim)}
|
||||||
|
|
||||||
|
/* parameter numberbox */
|
||||||
|
.kbox{display:flex;align-items:center;gap:8px;background:var(--bg-1);border:1px solid var(--line);
|
||||||
|
border-radius:8px;padding:5px 8px;width:fit-content}
|
||||||
|
.kbox .lab{font-size:10px;letter-spacing:.08em;text-transform:uppercase;color:var(--fg-mute)}
|
||||||
|
.kbox .val{min-width:1.4ch;text-align:center;color:var(--fg);font-size:15px;font-variant-numeric:tabular-nums}
|
||||||
|
.step{width:24px;height:24px;display:grid;place-items:center;padding:0;font-size:15px;line-height:1;
|
||||||
|
background:var(--bg-2);border:1px solid var(--line-strong);border-radius:6px;color:var(--fg);cursor:pointer}
|
||||||
|
.step:hover{background:var(--bg-3)}
|
||||||
|
.step:disabled{opacity:.3;cursor:default}
|
||||||
|
|
||||||
|
/* action bar */
|
||||||
|
.actionbar{display:flex;align-items:center;gap:8px;background:rgba(20,20,20,.82);
|
||||||
|
border:1px solid var(--line);border-radius:12px;padding:8px;backdrop-filter:blur(6px)}
|
||||||
|
.act{display:flex;flex-direction:column;align-items:center;gap:3px;min-width:58px;padding:8px 6px;
|
||||||
|
background:var(--bg-2);border:1px solid var(--line-strong);border-radius:9px;color:var(--fg);
|
||||||
|
cursor:pointer;font-family:inherit;transition:border-color .12s,background .12s}
|
||||||
|
.act:hover{background:var(--bg-3)}
|
||||||
|
.act .ic{font-size:18px;line-height:1}
|
||||||
|
.act .tx{font-size:9px;letter-spacing:.04em;color:var(--fg-mute);text-transform:uppercase}
|
||||||
|
.act.up:hover{border-color:var(--accent);box-shadow:0 0 12px rgba(255,106,0,.25)}
|
||||||
|
.act.down:hover{border-color:var(--accent-2);box-shadow:0 0 12px rgba(0,204,255,.22)}
|
||||||
|
.act:disabled{opacity:.35;cursor:default;box-shadow:none}
|
||||||
|
.sep{width:1px;align-self:stretch;background:var(--line);margin:2px 2px}
|
||||||
|
|
||||||
|
/* mode toggle */
|
||||||
|
.modeseg{display:inline-flex;border:1px solid var(--line-strong);border-radius:9px;overflow:hidden}
|
||||||
|
.modeseg button{border:0;border-radius:0;padding:0 12px;height:100%;min-height:54px;font-family:inherit;
|
||||||
|
font-size:11px;letter-spacing:.04em;background:var(--bg-2);color:var(--fg-mute);cursor:pointer}
|
||||||
|
.modeseg button.on{background:var(--accent);color:#0d0d0d}
|
||||||
|
|
||||||
|
/* info toggle */
|
||||||
|
#infoBtn{width:34px;height:34px;border-radius:50%;border:1px solid var(--line-strong);background:rgba(20,20,20,.82);
|
||||||
|
color:var(--fg-mute);font-size:15px;cursor:pointer;backdrop-filter:blur(6px)}
|
||||||
|
#infoBtn:hover{color:var(--accent);border-color:var(--accent)}
|
||||||
|
|
||||||
|
/* fading rotate hint */
|
||||||
|
#hint{position:absolute;left:50%;top:18px;transform:translateX(-50%);z-index:4;
|
||||||
|
font-size:11px;letter-spacing:.08em;color:var(--fg-dim);pointer-events:none;
|
||||||
|
transition:opacity 1s ease;opacity:.85}
|
||||||
|
#hint.gone{opacity:0}
|
||||||
|
|
||||||
|
/* loading */
|
||||||
|
#loading{position:absolute;inset:0;display:grid;place-items:center;z-index:9;background:var(--bg);
|
||||||
|
color:var(--fg-dim);font-size:13px;letter-spacing:.1em}
|
||||||
|
#loading.gone{display:none}
|
||||||
|
#loading b{color:var(--accent);letter-spacing:-.01em}
|
||||||
|
|
||||||
|
/* prose drawer (revealed by the info switch) */
|
||||||
|
#prose{position:absolute;top:0;right:0;bottom:0;width:min(440px,86vw);z-index:8;overflow:auto;
|
||||||
|
background:rgba(13,13,13,.96);border-left:1px solid var(--line);padding:40px 26px 64px;
|
||||||
|
transform:translateX(102%);transition:transform .28s ease}
|
||||||
|
body:not(.minimal) #prose{transform:none}
|
||||||
|
#prose h1{font-size:24px;margin:0 0 8px}
|
||||||
|
#prose h1 b{color:var(--accent)}
|
||||||
|
#prose p{color:var(--fg-mute);line-height:1.6;margin:0 0 12px}
|
||||||
|
#prose p b{color:var(--fg)}
|
||||||
|
#prose .lbl{font-size:11px;letter-spacing:.14em;text-transform:uppercase;color:var(--accent);margin:26px 0 8px}
|
||||||
|
#prose .ph{font-size:10px;letter-spacing:.1em;text-transform:uppercase;color:var(--fg-dim);
|
||||||
|
border:1px dashed var(--line-strong);border-radius:6px;padding:6px 9px;display:inline-block;margin-bottom:14px}
|
||||||
|
#prose .bars{display:flex;flex-direction:column;gap:7px;margin-top:6px}
|
||||||
|
#prose .ro{display:flex;align-items:center;gap:10px}
|
||||||
|
#prose .ro span{width:74px;font-size:10px;text-transform:uppercase;letter-spacing:.05em;color:var(--fg-mute)}
|
||||||
|
#prose .bar{flex:1;height:7px;background:var(--bg-3);border:1px solid var(--line);border-radius:999px;overflow:hidden;position:relative}
|
||||||
|
#prose .bar i{position:absolute;left:0;top:0;bottom:0;border-radius:999px}
|
||||||
|
#prose .num{width:3.2ch;text-align:right;font-variant-numeric:tabular-nums;color:var(--fg);font-size:12px}
|
||||||
|
#prose a{color:var(--accent-2);text-decoration:none}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body class="minimal">
|
||||||
|
<div id="app">
|
||||||
|
<canvas id="scene"></canvas>
|
||||||
|
|
||||||
|
<div id="hint">drag to rotate · top-down view = the flat 2-D map</div>
|
||||||
|
|
||||||
|
<!-- ZONE 1 · input: the 2-D control + parameter count (left) -->
|
||||||
|
<div class="hud hud-l">
|
||||||
|
<div class="zonecap">input · 2-D control</div>
|
||||||
|
<canvas id="ndpad" width="140" height="140"></canvas>
|
||||||
|
<div class="kbox">
|
||||||
|
<span class="lab">params</span>
|
||||||
|
<button class="step" id="kdown" title="fewer parameters">−</button>
|
||||||
|
<span class="val" id="kval">1</span>
|
||||||
|
<button class="step" id="kup" title="more parameters">+</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- ZONE 3 · outputs: vertical faders, one per layer (right) -->
|
||||||
|
<div class="hud hud-r">
|
||||||
|
<div class="zonecap">outputs</div>
|
||||||
|
<div class="outs" id="outs"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- action bar (bottom-center) -->
|
||||||
|
<div class="hud hud-bc actionbar">
|
||||||
|
<button class="act" id="aRand"><span class="ic">🎲</span><span class="tx">randomise</span></button>
|
||||||
|
<button class="act" id="aNudge"><span class="ic">〜</span><span class="tx">nudge</span></button>
|
||||||
|
<button class="act" id="aUndo"><span class="ic">↶</span><span class="tx">undo</span></button>
|
||||||
|
<div class="sep"></div>
|
||||||
|
<button class="act up" id="aUp"><span class="ic">👍</span><span class="tx">keep</span></button>
|
||||||
|
<button class="act down" id="aDown"><span class="ic">👎</span><span class="tx" id="downTx">push away</span></button>
|
||||||
|
<div class="sep"></div>
|
||||||
|
<div class="modeseg">
|
||||||
|
<button id="mPush" class="on">push‑away</button>
|
||||||
|
<button id="mExp">explore</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button id="infoBtn" class="hud hud-tr" title="show / hide explanation">ⓘ</button>
|
||||||
|
|
||||||
|
<div id="loading"><span>loading the <b> NISPS </b> engine…</span></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- placeholder explanatory copy (revealed by the ⓘ switch; to be reworked) -->
|
||||||
|
<div id="prose">
|
||||||
|
<h1>The <b>parameter landscape</b></h1>
|
||||||
|
<p class="ph">placeholder copy — to be reworked</p>
|
||||||
|
<p>Two numbers go in — your <b>X / Y control position</b> — and a whole fistful of parameters comes
|
||||||
|
out. You can't picture a dozen dimensions at once, so picture them <b>stacked</b>: each <b>slab</b> is one
|
||||||
|
parameter, drawn as a 3-D landscape whose height at any spot is that parameter's value. <b>One probe</b>
|
||||||
|
reads every slab at the same control position.</p>
|
||||||
|
<p>Seen straight from above the slabs overlap into a single flat map — it looks 2-D. <b>Tilt it</b> and the
|
||||||
|
reveal lands: it was a stack of 3-D surfaces all along. Add parameters to grow the sandwich.</p>
|
||||||
|
<p>Every surface here is the <b>real NISPS network</b> sampled across the input space. <b>👍 keep</b> teaches
|
||||||
|
the net that this sound belongs at this spot and the landscape bends to honour it; <b>👎</b> either pushes the
|
||||||
|
mapping away from the current sound or (in explore mode) re-rolls a fresh candidate to audition. <b>nudge</b>
|
||||||
|
and <b>randomise</b> perturb the net; <b>undo</b> steps back.</p>
|
||||||
|
<div class="lbl">Values under the probe</div>
|
||||||
|
<div class="bars" id="ndbars"></div>
|
||||||
|
<p style="margin-top:24px"><a href="../">← back to the instrument</a> · <a href="../animations/">animated explainers →</a></p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
(() => {
|
||||||
|
'use strict';
|
||||||
|
const clamp=(v,a=0,b=1)=>v<a?a:v>b?b:v;
|
||||||
|
const cssv=n=>getComputedStyle(document.documentElement).getPropertyValue(n).trim();
|
||||||
|
const MONO=cssv('--font-mono')||'monospace';
|
||||||
|
|
||||||
|
const NAMES=['Cutoff','Resonance','Drive','Tone','Decay','Air','Pitch','Width'];
|
||||||
|
const ABBR =['Cut','Res','Drv','Ton','Dec','Air','Pit','Wid'];
|
||||||
|
const MAXK=NAMES.length;
|
||||||
|
const OUT=126, IN=2, GRID=12, N=GRID, PTS=(N+1)*(N+1);
|
||||||
|
|
||||||
|
let K=1; // parameters (slabs) visualised — from the same net
|
||||||
|
let cx=0.5, cy=0.5; // 2-D control position in [0,1]
|
||||||
|
let mode='pushaway'; // 'pushaway' | 'explore'
|
||||||
|
let exploring=false; // explore-and-place scratchpad session active
|
||||||
|
let ready=false, auto=true, autoT=0.6;
|
||||||
|
|
||||||
|
// camera — START TOP-DOWN (looks 2-D); drag tilts to reveal the 3-D stack
|
||||||
|
let yaw=0, pitch=Math.PI/2, dragRot=false, lastX=0, lastY=0;
|
||||||
|
|
||||||
|
// ===== engine (vanilla wrapper over nisps.wasm; same C ABI the manifold uses) =====
|
||||||
|
const E={
|
||||||
|
mod:null,h:0,bIn:0,bOut:0,bF:0,bL:0,bW:0,bFb:0,wc:0,
|
||||||
|
async init(){
|
||||||
|
// nisps.{js,wasm} sit one level up at /next/ in production; probe a few bases.
|
||||||
|
let base=null,src=null;
|
||||||
|
for(const b of ['../','','./']){
|
||||||
|
try{const r=await fetch(b+'nisps.js');if(r.ok){src=await r.text();base=b;break;}}catch(e){}
|
||||||
|
}
|
||||||
|
if(base===null) throw new Error('nisps.js not found');
|
||||||
|
if(!window.createNispsModule)(0,eval)(src);
|
||||||
|
this.mod=await window.createNispsModule({locateFile:p=>p.endsWith('.wasm')?base+'nisps.wasm':p});
|
||||||
|
const m=this.mod;
|
||||||
|
this.h=m._nisps_ml_create(IN,OUT,0,0,(Date.now()>>>0));
|
||||||
|
this.wc=m._nisps_ml_weight_count(this.h);
|
||||||
|
this.bF=m._malloc(IN*4); this.bL=m._malloc(OUT*4); this.bFb=m._malloc(OUT*4);
|
||||||
|
this.bW=m._malloc(this.wc*4);
|
||||||
|
this.bIn=m._malloc(PTS*IN*4); this.bOut=m._malloc(PTS*OUT*4);
|
||||||
|
},
|
||||||
|
inferXY(x,y){const m=this.mod;m._nisps_ml_set_input(this.h,0,x);m._nisps_ml_set_input(this.h,1,y);
|
||||||
|
m._nisps_ml_process(this.h);const p=m._nisps_ml_outputs(this.h);
|
||||||
|
return new Float32Array(m.HEAPF32.buffer,p,OUT);},
|
||||||
|
inferGrid(){const m=this.mod;const inv=new Float32Array(m.HEAPF32.buffer,this.bIn,PTS*IN);
|
||||||
|
let q=0;for(let j=0;j<=N;j++)for(let i=0;i<=N;i++){inv[q++]=i/N;inv[q++]=j/N;}
|
||||||
|
m._nisps_ml_infer_batch(this.h,this.bIn,PTS,this.bOut);
|
||||||
|
return new Float32Array(new Float32Array(m.HEAPF32.buffer,this.bOut,PTS*OUT));},
|
||||||
|
addExample(f,l){const m=this.mod;const fv=new Float32Array(m.HEAPF32.buffer,this.bF,IN);
|
||||||
|
const lv=new Float32Array(m.HEAPF32.buffer,this.bL,OUT);fv[0]=f[0];fv[1]=f[1];
|
||||||
|
for(let i=0;i<OUT;i++)lv[i]=l[i]||0;m._nisps_ml_add_example(this.h,this.bF,this.bL);},
|
||||||
|
train(lr,it,me){return this.mod._nisps_ml_train(this.h,lr,it,me,0);},
|
||||||
|
draw(s){this.mod._nisps_ml_draw_weights(this.h,s);},
|
||||||
|
move(sp,s){this.mod._nisps_ml_move_weights(this.h,sp,s,0);},
|
||||||
|
setMode(i){this.mod._nisps_ml_feedback_set_mode(this.h,i);},
|
||||||
|
down(out,sp,s){const m=this.mod;const ov=new Float32Array(m.HEAPF32.buffer,this.bFb,OUT);
|
||||||
|
ov.fill(0);for(let i=0;i<OUT;i++)ov[i]=out[i]||0;m._nisps_ml_feedback_down(this.h,this.bFb,sp,s,0);},
|
||||||
|
enterExplore(s){this.mod._nisps_ml_feedback_enter_explore(this.h,s);},
|
||||||
|
reroll(s){this.mod._nisps_ml_feedback_reroll(this.h,s);},
|
||||||
|
coreNudge(a){this.mod._nisps_ml_feedback_nudge(this.h,a);},
|
||||||
|
coreUndo(){this.mod._nisps_ml_feedback_undo(this.h);},
|
||||||
|
exitExplore(){this.mod._nisps_ml_feedback_exit_explore(this.h);},
|
||||||
|
getWeights(){this.mod._nisps_ml_get_weights(this.h,this.bW);
|
||||||
|
return new Float32Array(new Float32Array(this.mod.HEAPF32.buffer,this.bW,this.wc));},
|
||||||
|
setWeights(w){const v=new Float32Array(this.mod.HEAPF32.buffer,this.bW,this.wc);v.set(w);
|
||||||
|
this.mod._nisps_ml_set_weights(this.h,this.bW);},
|
||||||
|
};
|
||||||
|
|
||||||
|
// Low spread = polarised weights = strong spatial relief (measured); high spread
|
||||||
|
// flattens the surface toward 0.5. Keep it low so the landscapes show real terrain.
|
||||||
|
const SPREAD=0.1, NUDGE=0.05, BOOT_SPREAD=0.05;
|
||||||
|
let grid=null, probeOut=new Float32Array(OUT);
|
||||||
|
function H(k,i,j){return grid?grid[(j*(N+1)+i)*OUT+k]:0.5;}
|
||||||
|
function resample(){grid=E.inferGrid();}
|
||||||
|
function updateProbe(){const o=E.inferXY(cx,cy);probeOut=new Float32Array(o);}
|
||||||
|
|
||||||
|
// ---- weight-snapshot undo (push-away mode; explore mode uses the core ring) ----
|
||||||
|
const undoStack=[];
|
||||||
|
function pushUndo(){undoStack.push(E.getWeights());if(undoStack.length>24)undoStack.shift();}
|
||||||
|
function popUndo(){const w=undoStack.pop();if(w){E.setWeights(w);return true;}return false;}
|
||||||
|
|
||||||
|
// ---- feedback examples marked on the 2-D control plane (like the main app) ----
|
||||||
|
// {x,y,sign} — sign +1 kept (👍), -1 pushed away (👎). undo pops the last.
|
||||||
|
const marks=[];
|
||||||
|
|
||||||
|
// ===== actions (all backed by the real engine) =====
|
||||||
|
function act(name){
|
||||||
|
if(!ready)return;
|
||||||
|
if(mode==='pushaway'){
|
||||||
|
if(name==='rand'){pushUndo();E.draw(SPREAD);}
|
||||||
|
else if(name==='nudge'){pushUndo();E.move(0.04,SPREAD);}
|
||||||
|
else if(name==='undo'){popUndo();marks.pop();}
|
||||||
|
else if(name==='up'){pushUndo();const o=new Float32Array(E.inferXY(cx,cy));E.addExample([cx,cy],o);E.train(1.0,200,1e-4);marks.push({x:cx,y:cy,sign:1});}
|
||||||
|
else if(name==='down'){pushUndo();const o=new Float32Array(E.inferXY(cx,cy));E.down(o,0.15,SPREAD);marks.push({x:cx,y:cy,sign:-1});}
|
||||||
|
}else{ // explore-and-place
|
||||||
|
if(name==='rand'||name==='down'){
|
||||||
|
if(!exploring){E.setMode(3);E.enterExplore(SPREAD);exploring=true;}else E.reroll(SPREAD);
|
||||||
|
}else if(name==='nudge'){
|
||||||
|
if(!exploring){E.setMode(3);E.enterExplore(SPREAD);exploring=true;}else E.coreNudge(NUDGE);
|
||||||
|
}else if(name==='undo'){
|
||||||
|
if(exploring)E.coreUndo();else{popUndo();marks.pop();}
|
||||||
|
}else if(name==='up'){
|
||||||
|
const o=new Float32Array(E.inferXY(cx,cy));
|
||||||
|
if(exploring){E.exitExplore();exploring=false;}
|
||||||
|
E.addExample([cx,cy],o);E.train(1.0,200,1e-4);marks.push({x:cx,y:cy,sign:1});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
resample();updateProbe();reflectButtons();redraw();
|
||||||
|
}
|
||||||
|
function setMode(m){
|
||||||
|
if(m===mode)return;
|
||||||
|
if(mode==='explore'&&exploring){E.exitExplore();exploring=false;}
|
||||||
|
mode=m;E.setMode(m==='explore'?3:0);
|
||||||
|
document.getElementById('mPush').classList.toggle('on',m==='pushaway');
|
||||||
|
document.getElementById('mExp').classList.toggle('on',m==='explore');
|
||||||
|
document.getElementById('downTx').textContent=m==='explore'?'skip':'push away';
|
||||||
|
if(ready){resample();updateProbe();reflectButtons();redraw();}
|
||||||
|
}
|
||||||
|
function reflectButtons(){
|
||||||
|
const ud=document.getElementById('aUndo');
|
||||||
|
ud.disabled=(mode==='explore'?false:undoStack.length===0)&&!exploring;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ===== 3-D projection: yaw + pitch orbit, bounding-sphere fit, X inverted =====
|
||||||
|
const SX=300,SZ=300,LAYER_GAP=120,ZAMP=92,MARGIN=44;
|
||||||
|
// Anchor the view to the TOP slab (k=0) at a FIXED world Y and a FIXED screen
|
||||||
|
// position, independent of K. So adding parameters grows the stack DOWNWARD and
|
||||||
|
// the top slab always stays the top — it never re-centres onto new layers.
|
||||||
|
const AWY=ZAMP*0.5, ANCHOR_FY=0.42;
|
||||||
|
let CW=800,CH=600,scale=1;
|
||||||
|
function computeView(){
|
||||||
|
let R=1; // bounding-sphere radius about the top anchor
|
||||||
|
for(let k=0;k<K;k++)for(const z of[0,1])for(const gx of[-0.5,0.5])for(const gy of[-0.5,0.5]){
|
||||||
|
const X=gx*SX,Y=(-k*LAYER_GAP+z*ZAMP)-AWY,Z=gy*SZ;const d=Math.sqrt(X*X+Y*Y+Z*Z);if(d>R)R=d;}
|
||||||
|
scale=(Math.min(CW,CH)/2-MARGIN)/R;
|
||||||
|
}
|
||||||
|
function project(gx,gy,zv,k){
|
||||||
|
const X=gx*SX, Y=(-k*LAYER_GAP+zv*ZAMP)-AWY, Z=-gy*SZ; // Z negated: pad-up = map-up
|
||||||
|
const cyA=Math.cos(yaw),syA=Math.sin(yaw);
|
||||||
|
const x1=X*cyA-Z*syA, z1=X*syA+Z*cyA;
|
||||||
|
const cpA=Math.cos(pitch),spA=Math.sin(pitch);
|
||||||
|
const y2=Y*cpA-z1*spA, z2=Y*spA+z1*cpA;
|
||||||
|
return {x:CW/2+x1*scale,y:CH*ANCHOR_FY-y2*scale,depth:z2,wx:X,wy:Y,wz:Z};
|
||||||
|
}
|
||||||
|
|
||||||
|
const DPR=Math.max(1,Math.min(2,window.devicePixelRatio||1));
|
||||||
|
const scene=document.getElementById('scene'),sctx=scene.getContext('2d');
|
||||||
|
const pad=document.getElementById('ndpad'),pctx=pad.getContext('2d');
|
||||||
|
pad.width=140*DPR;pad.height=140*DPR;pctx.scale(DPR,DPR);
|
||||||
|
function resize(){
|
||||||
|
const r=scene.getBoundingClientRect();CW=Math.max(320,Math.round(r.width));CH=Math.max(320,Math.round(r.height));
|
||||||
|
scene.width=CW*DPR;scene.height=CH*DPR;sctx.setTransform(DPR,0,0,DPR,0,0);computeView();
|
||||||
|
}
|
||||||
|
|
||||||
|
const hueOf=k=>K>1?(26+(196-26)*k/(K-1)):26;
|
||||||
|
const colCss=(k,a)=>`hsla(${hueOf(k).toFixed(0)},85%,60%,${a})`;
|
||||||
|
const LIGHT=(()=>{const v=[0.35,0.86,0.36],m=Math.hypot(v[0],v[1],v[2]);return[v[0]/m,v[1]/m,v[2]/m];})();
|
||||||
|
|
||||||
|
function renderScene(){
|
||||||
|
const c=sctx;c.clearRect(0,0,CW,CH);
|
||||||
|
const quads=[],labels=[];
|
||||||
|
for(let k=0;k<K;k++){
|
||||||
|
const hue=hueOf(k),P=[];
|
||||||
|
for(let j=0;j<=N;j++){P[j]=[];for(let i=0;i<=N;i++)P[j][i]=project(i/N-0.5,j/N-0.5,H(k,i,j),k);}
|
||||||
|
for(let j=0;j<N;j++)for(let i=0;i<N;i++){
|
||||||
|
const a=P[j][i],b=P[j][i+1],d=P[j+1][i+1],e=P[j+1][i];
|
||||||
|
const ux=d.wx-a.wx,uy=d.wy-a.wy,uz=d.wz-a.wz,vx=b.wx-e.wx,vy=b.wy-e.wy,vz=b.wz-e.wz;
|
||||||
|
const nx=uy*vz-uz*vy,ny=uz*vx-ux*vz,nz=ux*vy-uy*vx,nm=Math.hypot(nx,ny,nz)||1;
|
||||||
|
const L=clamp(0.32+0.62*Math.abs((nx*LIGHT[0]+ny*LIGHT[1]+nz*LIGHT[2])/nm));
|
||||||
|
quads.push({a,b,d,e,hue,L,depth:(a.depth+b.depth+d.depth+e.depth)/4});
|
||||||
|
}
|
||||||
|
const lp=project(-0.5,0.5,H(k,0,N),k);labels.push({x:lp.x,y:lp.y,hue,name:NAMES[k]});
|
||||||
|
}
|
||||||
|
quads.sort((p,q)=>q.depth-p.depth);
|
||||||
|
for(const Q of quads){
|
||||||
|
c.fillStyle=`hsla(${Q.hue},80%,${(26+Q.L*44).toFixed(0)}%,0.66)`;
|
||||||
|
c.strokeStyle=`hsla(${Q.hue},80%,82%,0.18)`;c.lineWidth=0.6;
|
||||||
|
c.beginPath();c.moveTo(Q.a.x,Q.a.y);c.lineTo(Q.b.x,Q.b.y);c.lineTo(Q.d.x,Q.d.y);c.lineTo(Q.e.x,Q.e.y);c.closePath();
|
||||||
|
c.fill();c.stroke();
|
||||||
|
}
|
||||||
|
c.font='11px '+MONO;c.textAlign='right';c.textBaseline='middle';
|
||||||
|
for(const Lb of labels){c.fillStyle=`hsla(${Lb.hue},85%,74%,0.95)`;c.fillText(Lb.name,Lb.x-6,Lb.y);}
|
||||||
|
// probe column at (cx,cy) through every slab
|
||||||
|
const gx=cx-0.5,gy=cy-0.5;
|
||||||
|
const top=project(gx,gy,1.18,0),bot=project(gx,gy,-0.18,K-1);
|
||||||
|
c.strokeStyle='rgba(255,255,255,0.32)';c.lineWidth=1;c.setLineDash([3,4]);
|
||||||
|
c.beginPath();c.moveTo(top.x,top.y);c.lineTo(bot.x,bot.y);c.stroke();c.setLineDash([]);
|
||||||
|
for(let k=0;k<K;k++){
|
||||||
|
const p=project(gx,gy,clamp(probeOut[k]),k),fl=project(gx,gy,0,k);
|
||||||
|
c.strokeStyle=colCss(k,0.5);c.lineWidth=1;c.beginPath();c.moveTo(p.x,p.y);c.lineTo(fl.x,fl.y);c.stroke();
|
||||||
|
c.fillStyle=colCss(k,1);c.shadowColor=colCss(k,1);c.shadowBlur=12;
|
||||||
|
c.beginPath();c.arc(p.x,p.y,6,0,Math.PI*2);c.fill();c.shadowBlur=0;
|
||||||
|
c.fillStyle='#0d0d0d';c.beginPath();c.arc(p.x,p.y,2.2,0,Math.PI*2);c.fill();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function drawPad(){
|
||||||
|
pctx.clearRect(0,0,140,140);pctx.fillStyle='#1c1c1c';pctx.fillRect(0,0,140,140);
|
||||||
|
pctx.strokeStyle='rgba(255,255,255,0.06)';pctx.lineWidth=1;
|
||||||
|
for(let i=1;i<4;i++){const t=i/4*140;pctx.beginPath();pctx.moveTo(t,0);pctx.lineTo(t,140);pctx.stroke();
|
||||||
|
pctx.beginPath();pctx.moveTo(0,t);pctx.lineTo(140,t);pctx.stroke();}
|
||||||
|
// feedback examples (👍 +, 👎 −) — same convention as the main app
|
||||||
|
const TAU=Math.PI*2;
|
||||||
|
for(const m of marks){const mx=m.x*140,my=(1-m.y)*140,col=m.sign>0?'#ff6a00':'#00ccff';
|
||||||
|
pctx.globalAlpha=0.28;pctx.fillStyle=col;pctx.beginPath();pctx.arc(mx,my,8,0,TAU);pctx.fill();
|
||||||
|
pctx.globalAlpha=1;pctx.strokeStyle=col;pctx.lineWidth=1.5;pctx.beginPath();pctx.arc(mx,my,5,0,TAU);pctx.stroke();
|
||||||
|
pctx.fillStyle=col;pctx.font='9px '+MONO;pctx.textAlign='center';pctx.textBaseline='middle';
|
||||||
|
pctx.fillText(m.sign>0?'+':'–',mx,my+0.5);}
|
||||||
|
const dx=cx*140,dy=(1-cy)*140;
|
||||||
|
pctx.strokeStyle='rgba(255,255,255,0.1)';pctx.beginPath();pctx.moveTo(0,dy);pctx.lineTo(140,dy);
|
||||||
|
pctx.moveTo(dx,0);pctx.lineTo(dx,140);pctx.stroke();
|
||||||
|
pctx.fillStyle='#ff6a00';pctx.shadowColor='#ff6a00';pctx.shadowBlur=12;
|
||||||
|
pctx.beginPath();pctx.arc(dx,dy,6,0,Math.PI*2);pctx.fill();pctx.shadowBlur=0;
|
||||||
|
pctx.fillStyle='#0d0d0d';pctx.beginPath();pctx.arc(dx,dy,2.4,0,Math.PI*2);pctx.fill();
|
||||||
|
}
|
||||||
|
|
||||||
|
// readout bars (prose drawer only)
|
||||||
|
const barsEl=document.getElementById('ndbars');let barI=[],barN=[];
|
||||||
|
function buildBars(){barsEl.innerHTML='';barI=[];barN=[];
|
||||||
|
for(let k=0;k<K;k++){const ro=document.createElement('div');ro.className='ro';
|
||||||
|
ro.innerHTML=`<span style="color:${colCss(k,0.95)}">${NAMES[k]}</span>`+
|
||||||
|
`<div class="bar"><i style="background:${colCss(k,1)}"></i></div><div class="num">0.50</div>`;
|
||||||
|
barsEl.appendChild(ro);barI[k]=ro.querySelector('i');barN[k]=ro.querySelector('.num');}}
|
||||||
|
function updateBars(){if(!barI.length)return;for(let k=0;k<K;k++){const v=clamp(probeOut[k]);
|
||||||
|
barI[k].style.width=(v*100)+'%';barN[k].textContent=v.toFixed(2);}}
|
||||||
|
|
||||||
|
// output faders — the 1-D projection of each layer's value at the current point
|
||||||
|
const TRACK_H=200;
|
||||||
|
const outsEl=document.getElementById('outs');let fFill=[],fHan=[],fVal=[];
|
||||||
|
function buildOuts(){outsEl.innerHTML='';fFill=[];fHan=[];fVal=[];
|
||||||
|
for(let k=0;k<K;k++){const col=colCss(k,1);const f=document.createElement('div');f.className='fader';
|
||||||
|
f.innerHTML=`<div class="track"><div class="fill" style="background:${col}"></div>`+
|
||||||
|
`<div class="handle" style="background:${col};color:${col}"></div></div>`+
|
||||||
|
`<div class="flab" style="color:${colCss(k,0.95)}" title="${NAMES[k]}">${ABBR[k]}</div><div class="fval">0.50</div>`;
|
||||||
|
outsEl.appendChild(f);fFill[k]=f.querySelector('.fill');fHan[k]=f.querySelector('.handle');fVal[k]=f.querySelector('.fval');}}
|
||||||
|
function updateOuts(){if(!fFill.length)return;for(let k=0;k<K;k++){const v=clamp(probeOut[k]);
|
||||||
|
fFill[k].style.height=(v*100)+'%';fHan[k].style.bottom=(v*TRACK_H)+'px';fVal[k].textContent=v.toFixed(2);}}
|
||||||
|
|
||||||
|
function redraw(){renderScene();drawPad();updateBars();updateOuts();}
|
||||||
|
|
||||||
|
// ===== interaction =====
|
||||||
|
function setK(n){K=clamp(n,1,MAXK);document.getElementById('kval').textContent=K;
|
||||||
|
document.getElementById('kup').disabled=K>=MAXK;document.getElementById('kdown').disabled=K<=1;
|
||||||
|
computeView();buildBars();buildOuts();updateProbe&&(probeOut=new Float32Array(E.inferXY(cx,cy)));redraw();}
|
||||||
|
|
||||||
|
function stopAuto(){auto=false;document.getElementById('hint').classList.add('gone');}
|
||||||
|
|
||||||
|
// pad → control position
|
||||||
|
function setFromPad(e){const r=pad.getBoundingClientRect();
|
||||||
|
cx=clamp((e.clientX-r.left)/r.width);cy=clamp(1-(e.clientY-r.top)/r.height);}
|
||||||
|
let padDrag=false;
|
||||||
|
pad.addEventListener('pointerdown',e=>{padDrag=true;pad.setPointerCapture(e.pointerId);stopAuto();setFromPad(e);updateProbe();redraw();});
|
||||||
|
pad.addEventListener('pointermove',e=>{if(padDrag){setFromPad(e);updateProbe();redraw();}});
|
||||||
|
pad.addEventListener('pointerup',()=>padDrag=false);
|
||||||
|
|
||||||
|
// scene → orbit (pitch inverted; pitch up to π/2 = exact top-down)
|
||||||
|
scene.addEventListener('pointerdown',e=>{dragRot=true;scene.setPointerCapture(e.pointerId);stopAuto();lastX=e.clientX;lastY=e.clientY;});
|
||||||
|
scene.addEventListener('pointermove',e=>{if(!dragRot)return;
|
||||||
|
yaw+=(e.clientX-lastX)*0.01;
|
||||||
|
pitch=clamp(pitch+(e.clientY-lastY)*0.008,0.06,Math.PI/2); // vertical (Y) drag — inverted
|
||||||
|
lastX=e.clientX;lastY=e.clientY;redraw();});
|
||||||
|
scene.addEventListener('pointerup',()=>dragRot=false);
|
||||||
|
scene.addEventListener('pointercancel',()=>dragRot=false);
|
||||||
|
|
||||||
|
// buttons
|
||||||
|
const B=(id,fn)=>document.getElementById(id).addEventListener('click',()=>{stopAuto();fn();});
|
||||||
|
B('aRand',()=>act('rand'));B('aNudge',()=>act('nudge'));B('aUndo',()=>act('undo'));
|
||||||
|
B('aUp',()=>act('up'));B('aDown',()=>act('down'));
|
||||||
|
B('kup',()=>setK(K+1));B('kdown',()=>setK(K-1));
|
||||||
|
document.getElementById('mPush').addEventListener('click',()=>{stopAuto();setMode('pushaway');});
|
||||||
|
document.getElementById('mExp').addEventListener('click',()=>{stopAuto();setMode('explore');});
|
||||||
|
document.getElementById('infoBtn').addEventListener('click',()=>{
|
||||||
|
document.body.classList.toggle('minimal');
|
||||||
|
document.getElementById('infoBtn').textContent=document.body.classList.contains('minimal')?'ⓘ':'✕';});
|
||||||
|
|
||||||
|
window.addEventListener('resize',()=>{resize();redraw();});
|
||||||
|
|
||||||
|
function loop(){
|
||||||
|
if(auto&&ready&&!padDrag&&!dragRot){
|
||||||
|
autoT+=0.006;cx=0.5+0.42*Math.sin(autoT*0.9);cy=0.5+0.42*Math.sin(autoT*1.27+1.3);
|
||||||
|
updateProbe();redraw();
|
||||||
|
}
|
||||||
|
requestAnimationFrame(loop);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ===== boot =====
|
||||||
|
(async()=>{
|
||||||
|
try{
|
||||||
|
await E.init();
|
||||||
|
E.draw(BOOT_SPREAD); // a fresh net is near-flat; draw for visible relief
|
||||||
|
window.__learn={E,setK,resample,redraw,
|
||||||
|
range(k){let lo=1,hi=0;for(let j=0;j<=N;j++)for(let i=0;i<=N;i++){const v=H(k,i,j);if(v<lo)lo=v;if(v>hi)hi=v;}return[lo,hi];}};
|
||||||
|
resize();setK(1);resample();updateProbe();reflectButtons();
|
||||||
|
ready=true;document.getElementById('loading').classList.add('gone');
|
||||||
|
redraw();requestAnimationFrame(loop);
|
||||||
|
// fade the hint after a while
|
||||||
|
setTimeout(()=>{if(auto)document.getElementById('hint').classList.add('gone');},6000);
|
||||||
|
}catch(err){
|
||||||
|
console.error('[learn] engine init failed:',err);
|
||||||
|
document.getElementById('loading').innerHTML='<span style="color:#c8553a">engine failed to load — see console</span>';
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
})();
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
187
assets/media/showcase/index.html
Normal file
187
assets/media/showcase/index.html
Normal file
|
|
@ -0,0 +1,187 @@
|
||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
<title>Manifold — How it works</title>
|
||||||
|
<style>
|
||||||
|
:root{
|
||||||
|
--bg:#0d0d0d; --bg-1:#141414; --bg-2:#1c1c1c; --bg-3:#242424;
|
||||||
|
--fg:#e8e8e8; --fg-mute:#9a9a9a; --fg-dim:#5a5a5a;
|
||||||
|
--line:#2a2a2a; --line-strong:#3a3a3a;
|
||||||
|
--accent:#ff6a00; --accent-2:#00ccff; --good:#6bc26b;
|
||||||
|
--font-mono:'JetBrains Mono','Fira Code','SF Mono',Menlo,Consolas,monospace;
|
||||||
|
--glow:0 0 14px rgba(255,106,0,.35);
|
||||||
|
}
|
||||||
|
*{box-sizing:border-box}
|
||||||
|
html,body{margin:0;background:var(--bg);color:var(--fg);font-family:var(--font-mono);
|
||||||
|
font-size:15px;line-height:1.55;-webkit-font-smoothing:antialiased}
|
||||||
|
a{color:var(--accent-2);text-decoration:none}
|
||||||
|
.wrap{max-width:960px;margin:0 auto;padding:48px 24px 96px}
|
||||||
|
header h1{font-size:34px;margin:0 0 6px;letter-spacing:-.01em}
|
||||||
|
header h1 b{color:var(--accent)}
|
||||||
|
header p{color:var(--fg-mute);margin:0 0 8px}
|
||||||
|
.crumb{font-size:11px;letter-spacing:.14em;text-transform:uppercase;color:var(--fg-dim)}
|
||||||
|
section{margin-top:56px}
|
||||||
|
.lbl{font-size:11px;letter-spacing:.14em;text-transform:uppercase;color:var(--accent);margin-bottom:10px}
|
||||||
|
h2{font-size:22px;margin:0 0 6px}
|
||||||
|
.cap{color:var(--fg-mute);margin:0 0 16px;max-width:70ch}
|
||||||
|
video{width:100%;border:1px solid var(--line);border-radius:8px;background:#000;display:block}
|
||||||
|
.tag{display:inline-block;font-size:10px;letter-spacing:.08em;text-transform:uppercase;
|
||||||
|
border:1px solid var(--line-strong);border-radius:999px;padding:2px 9px;color:var(--fg-mute);margin-left:8px}
|
||||||
|
.tag.live{color:var(--good);border-color:var(--good)}
|
||||||
|
.demo{border:1px solid var(--line);border-radius:10px;background:var(--bg-1);padding:22px;display:flex;
|
||||||
|
gap:28px;flex-wrap:wrap;align-items:center;justify-content:center}
|
||||||
|
canvas{touch-action:none;cursor:pointer}
|
||||||
|
.readouts{display:flex;flex-direction:column;gap:14px;min-width:220px}
|
||||||
|
.ro{display:flex;align-items:center;gap:12px}
|
||||||
|
.ro span{width:54px;font-size:11px;letter-spacing:.1em;text-transform:uppercase;color:var(--fg-mute)}
|
||||||
|
.bar{flex:1;height:8px;background:var(--bg-3);border:1px solid var(--line);border-radius:999px;overflow:hidden;position:relative}
|
||||||
|
.bar i{position:absolute;left:0;top:0;bottom:0;display:block;border-radius:999px}
|
||||||
|
.num{width:4ch;text-align:right;font-variant-numeric:tabular-nums;color:var(--fg)}
|
||||||
|
.hint{color:var(--fg-dim);font-size:12px;margin-top:10px}
|
||||||
|
footer{margin-top:72px;color:var(--fg-dim);font-size:12px;border-top:1px solid var(--line);padding-top:18px}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="wrap">
|
||||||
|
<header>
|
||||||
|
<div class="crumb">Manifold · meml.lnfinitemonkeys.org/next</div>
|
||||||
|
<h1><b>Manifold</b> — how it works</h1>
|
||||||
|
<p>A few short explainers of the core idea: a control is just a number; a network in the middle turns a few input numbers into many output numbers; and your thumbs-up/down shapes that mapping live.</p>
|
||||||
|
<p class="crumb">← <a href="../">back to the instrument</a></p>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<!-- Interactive 1 -->
|
||||||
|
<section>
|
||||||
|
<div class="lbl">Try it · interactive</div>
|
||||||
|
<h2>A control is just a number<span class="tag live">live</span></h2>
|
||||||
|
<p class="cap">Drag the knob. The number is the knob — one value in [0,1]. Every control in Manifold is, underneath, exactly this.</p>
|
||||||
|
<div class="demo">
|
||||||
|
<canvas id="knob" width="200" height="200"></canvas>
|
||||||
|
<div class="readouts">
|
||||||
|
<div class="ro"><span>value</span><div class="bar"><i id="kbar" style="background:var(--accent);box-shadow:var(--glow)"></i></div><div class="num" id="knum">0.50</div></div>
|
||||||
|
<div class="hint">drag up/down or around the knob</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<!-- Video 1 -->
|
||||||
|
<section>
|
||||||
|
<div class="lbl">01 · Knob = 1:1 mapping</div>
|
||||||
|
<h2>Knob → one number</h2>
|
||||||
|
<p class="cap">A knob rotates while a paired 0–1 number rises and falls in lockstep — a control is a readout of one number.</p>
|
||||||
|
<video controls preload="metadata" src="01-knob-mapping.mp4"></video>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<!-- Interactive 2 -->
|
||||||
|
<section>
|
||||||
|
<div class="lbl">Try it · interactive</div>
|
||||||
|
<h2>An XY pad is two numbers<span class="tag live">live</span></h2>
|
||||||
|
<p class="cap">Move the dot. The pad projects to two independent values A (X) and B (Y). Two inputs — the smallest manifold.</p>
|
||||||
|
<div class="demo">
|
||||||
|
<canvas id="pad" width="220" height="220"></canvas>
|
||||||
|
<div class="readouts">
|
||||||
|
<div class="ro"><span>A · x</span><div class="bar"><i id="abar" style="background:var(--accent);box-shadow:var(--glow)"></i></div><div class="num" id="anum">0.50</div></div>
|
||||||
|
<div class="ro"><span>B · y</span><div class="bar"><i id="bbar" style="background:var(--accent-2);box-shadow:0 0 14px rgba(0,204,255,.35)"></i></div><div class="num" id="bnum">0.50</div></div>
|
||||||
|
<div class="hint">drag anywhere in the pad</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<!-- Video 2 -->
|
||||||
|
<section>
|
||||||
|
<div class="lbl">02 · XY pad → two numbers</div>
|
||||||
|
<h2>XY pad → A and B</h2>
|
||||||
|
<p class="cap">A 2-D pad projects to two independent 0–1 values, each shown as a slider, as the dot moves.</p>
|
||||||
|
<video controls preload="metadata" src="02-xy-pad.mp4"></video>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<!-- Video 3 -->
|
||||||
|
<section>
|
||||||
|
<div class="lbl">03 · Dimensionality fan-out</div>
|
||||||
|
<h2>A few inputs → many outputs</h2>
|
||||||
|
<p class="cap">The same 2-D control driving 3 → 4 → 5 outputs, then the control type cycled across knob, fader, touchpad, and 2-D / 3-D joysticks. A few input dimensions map to many outputs through the learned mapping.</p>
|
||||||
|
<video controls preload="metadata" src="03-fanout.mp4"></video>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<!-- Video 4 -->
|
||||||
|
<section>
|
||||||
|
<div class="lbl">04 · Feedback & training</div>
|
||||||
|
<h2>How your verdicts reshape the mapping</h2>
|
||||||
|
<p class="cap">Training on the mapping surface, and how a verdict reshapes it — contrasting the two feedback modes: <b style="color:var(--fg)">geometric push-away</b> (directed repulsion from what you like) versus <b style="color:var(--fg)">explore-and-place</b> (randomise → audition → place → interpolate, the recommended default).</p>
|
||||||
|
<video controls preload="metadata" src="04-feedback.mp4"></video>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<footer>
|
||||||
|
Videos rendered with Manim CE (1920×1080 · H.264). The two “live” demos above are interactive; the
|
||||||
|
same idea drives the real instrument at <a href="../">/next</a>. Sources in <code>assets/media/src/</code>.
|
||||||
|
</footer>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
(() => {
|
||||||
|
const TAU = Math.PI * 2;
|
||||||
|
const clamp = (v) => Math.max(0, Math.min(1, v));
|
||||||
|
const css = (n) => getComputedStyle(document.documentElement).getPropertyValue(n).trim();
|
||||||
|
const accent = css('--accent') || '#ff6a00', cyan = css('--accent-2') || '#00ccff',
|
||||||
|
line = css('--line-strong') || '#3a3a3a', bg3 = css('--bg-3') || '#242424';
|
||||||
|
|
||||||
|
// ---- Interactive 1: knob -> number ----
|
||||||
|
const kc = document.getElementById('knob'), kx = kc.getContext('2d');
|
||||||
|
const kbar = document.getElementById('kbar'), knum = document.getElementById('knum');
|
||||||
|
let kv = 0.5, kdrag = false, kref = 0.5, ky0 = 0;
|
||||||
|
const A0 = Math.PI * 0.75, A1 = Math.PI * 2.25; // 270° sweep from lower-left
|
||||||
|
function drawKnob() {
|
||||||
|
const w = kc.width, h = kc.height, cx = w/2, cy = h/2, r = 74;
|
||||||
|
kx.clearRect(0,0,w,h);
|
||||||
|
kx.lineWidth = 10; kx.lineCap = 'round';
|
||||||
|
kx.strokeStyle = bg3; kx.beginPath(); kx.arc(cx,cy,r,A0,A1); kx.stroke();
|
||||||
|
kx.strokeStyle = accent; kx.shadowColor = accent; kx.shadowBlur = 12;
|
||||||
|
kx.beginPath(); kx.arc(cx,cy,r,A0,A0 + (A1-A0)*kv); kx.stroke(); kx.shadowBlur = 0;
|
||||||
|
const a = A0 + (A1-A0)*kv;
|
||||||
|
kx.strokeStyle = '#0d0d0d'; kx.lineWidth = 4;
|
||||||
|
kx.beginPath(); kx.moveTo(cx + Math.cos(a)*(r-22), cy + Math.sin(a)*(r-22));
|
||||||
|
kx.lineTo(cx + Math.cos(a)*(r+2), cy + Math.sin(a)*(r+2)); kx.stroke();
|
||||||
|
kx.fillStyle = accent; kx.font = '600 26px ' + css('--font-mono');
|
||||||
|
kx.textAlign = 'center'; kx.textBaseline = 'middle';
|
||||||
|
kx.fillText(kv.toFixed(2), cx, cy);
|
||||||
|
kbar.style.width = (kv*100) + '%'; knum.textContent = kv.toFixed(2);
|
||||||
|
}
|
||||||
|
kc.addEventListener('pointerdown', e => { kdrag = true; kref = kv; ky0 = e.clientY; kc.setPointerCapture(e.pointerId); });
|
||||||
|
kc.addEventListener('pointermove', e => { if (!kdrag) return; kv = clamp(kref - (e.clientY - ky0)/160); drawKnob(); });
|
||||||
|
kc.addEventListener('pointerup', () => kdrag = false);
|
||||||
|
drawKnob();
|
||||||
|
|
||||||
|
// ---- Interactive 2: XY pad -> two sliders ----
|
||||||
|
const pc = document.getElementById('pad'), px = pc.getContext('2d');
|
||||||
|
const abar = document.getElementById('abar'), bbar = document.getElementById('bbar');
|
||||||
|
const anum = document.getElementById('anum'), bnum = document.getElementById('bnum');
|
||||||
|
let ax = 0.5, ay = 0.5, pdrag = false;
|
||||||
|
function drawPad() {
|
||||||
|
const w = pc.width, h = pc.height, pad = 10;
|
||||||
|
px.clearRect(0,0,w,h);
|
||||||
|
px.strokeStyle = 'rgba(255,255,255,0.05)'; px.lineWidth = 1;
|
||||||
|
for (let i=1;i<4;i++){ const t=i/4; px.beginPath(); px.moveTo(pad+t*(w-2*pad),pad); px.lineTo(pad+t*(w-2*pad),h-pad); px.stroke();
|
||||||
|
px.beginPath(); px.moveTo(pad,pad+t*(h-2*pad)); px.lineTo(w-pad,pad+t*(h-2*pad)); px.stroke(); }
|
||||||
|
px.strokeStyle = line; px.strokeRect(pad+0.5,pad+0.5,w-2*pad-1,h-2*pad-1);
|
||||||
|
const dx = pad + ax*(w-2*pad), dy = pad + (1-ay)*(h-2*pad);
|
||||||
|
px.strokeStyle = 'rgba(255,255,255,0.08)';
|
||||||
|
px.beginPath(); px.moveTo(pad,dy); px.lineTo(w-pad,dy); px.moveTo(dx,pad); px.lineTo(dx,h-pad); px.stroke();
|
||||||
|
px.fillStyle = accent; px.shadowColor = accent; px.shadowBlur = 16;
|
||||||
|
px.beginPath(); px.arc(dx,dy,9,0,TAU); px.fill(); px.shadowBlur = 0;
|
||||||
|
px.fillStyle = '#0d0d0d'; px.beginPath(); px.arc(dx,dy,3,0,TAU); px.fill();
|
||||||
|
abar.style.width = (ax*100)+'%'; bbar.style.width = (ay*100)+'%';
|
||||||
|
anum.textContent = ax.toFixed(2); bnum.textContent = ay.toFixed(2);
|
||||||
|
}
|
||||||
|
function padSet(e){ const r = pc.getBoundingClientRect(), pad = 10;
|
||||||
|
ax = clamp((e.clientX - r.left - pad)/(pc.width-2*pad));
|
||||||
|
ay = clamp(1 - (e.clientY - r.top - pad)/(pc.height-2*pad)); drawPad(); }
|
||||||
|
pc.addEventListener('pointerdown', e => { pdrag = true; pc.setPointerCapture(e.pointerId); padSet(e); });
|
||||||
|
pc.addEventListener('pointermove', e => { if (pdrag) padSet(e); });
|
||||||
|
pc.addEventListener('pointerup', () => pdrag = false);
|
||||||
|
drawPad();
|
||||||
|
})();
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
4
assets/media/src/.gitignore
vendored
Normal file
4
assets/media/src/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
# Manim render work tree — regenerable, do not commit.
|
||||||
|
media/
|
||||||
|
concat_feedback.txt
|
||||||
|
__pycache__/
|
||||||
43
assets/media/src/plan.md
Normal file
43
assets/media/src/plan.md
Normal file
|
|
@ -0,0 +1,43 @@
|
||||||
|
# Manim Explainers — Plan (workstream G)
|
||||||
|
|
||||||
|
3Blue1Brown-style educational explainers for Manifold's core ideas: how physical
|
||||||
|
controls map to numbers, how a single control fans out to many parameters, and how
|
||||||
|
the two feedback/training modes reshape a mapping. British spelling in all on-screen copy.
|
||||||
|
|
||||||
|
## Shared visual language
|
||||||
|
|
||||||
|
- Palette: Classic 3B1B on `#1C1C1C`. Primary `#58C4DD` (control side), Green
|
||||||
|
`#83C167` (numbers/outputs), Yellow `#FFFF00` (accent / the moving value).
|
||||||
|
Dislike/push = warm red `#FF6B6B`. Anchors (placed sounds) = green dots.
|
||||||
|
- Monospace font throughout (`MONO`), per the skill (Pango kerning).
|
||||||
|
- Opacity layering: primary 1.0, context 0.4, structure (axes/grid) 0.15.
|
||||||
|
- Breathing room: `self.wait()` after every reveal.
|
||||||
|
|
||||||
|
## The five scripts
|
||||||
|
|
||||||
|
| # | File | Scene(s) | Teaches |
|
||||||
|
|---|------|----------|---------|
|
||||||
|
| 1 | `s1_knob_mapping.py` | `KnobMapping` | A knob is a 1:1 readout of one number in [0,1]. Rotation ⇄ value in lockstep. |
|
||||||
|
| 2 | `s2_xy_pad.py` | `XYPad` | A 2-D pad projects to two *independent* numbers A and B, shown as sliders. |
|
||||||
|
| 3 | `s3_fanout.py` | `Fanout` | The same 2-D control drives 3→4→5 outputs (N sliders), across control types. |
|
||||||
|
| 4 | `s4_feedback.py` | `GeometricDislike`, `ExploreAndPlace`, `FeedbackContrast` | The two feedback modes on a loss/mapping surface: geometric push-away vs explore-and-place (the recommended default). |
|
||||||
|
|
||||||
|
Each scene is independently renderable; scripts are stitched with ffmpeg per piece.
|
||||||
|
|
||||||
|
## Narrative arcs
|
||||||
|
|
||||||
|
1. **Knob = 1:1.** Misconception corrected: a control isn't "magic", it's a number.
|
||||||
|
Show the dial; bind a 0–1 readout; sweep both ways; they never disagree.
|
||||||
|
2. **XY → two numbers.** One gesture, two readings. Move the dot; A reads the
|
||||||
|
horizontal, B reads the vertical; they move independently. The pad is just two
|
||||||
|
knobs stacked at right angles.
|
||||||
|
3. **Fan-out.** The interesting bit: one control, many outputs. A small network
|
||||||
|
sits between the control and N sliders. Grow N (3→4→5) and cycle the control
|
||||||
|
type (knob, fader, touchpad, 2-D joystick, 3-D joystick) — the principle holds.
|
||||||
|
4. **Feedback.** The mapping is a landscape. Two ways to teach it:
|
||||||
|
- *Geometric dislike*: you have a liked region; a thumbs-down carves the current
|
||||||
|
point directionally **away** from the liked centroid (directed repulsion).
|
||||||
|
- *Explore and place* (DEFAULT): randomise the net → audition → "I like that" →
|
||||||
|
drop it in a corner → randomise again → place another → interpolate between
|
||||||
|
placed anchors. Positive-only; you never reason about "away from what".
|
||||||
|
End on a side-by-side contrast and the recommendation.
|
||||||
113
assets/media/src/s1_knob_mapping.py
Normal file
113
assets/media/src/s1_knob_mapping.py
Normal file
|
|
@ -0,0 +1,113 @@
|
||||||
|
"""Manifold explainer 1 — Knob = 1:1 mapping.
|
||||||
|
|
||||||
|
A knob rotates; a paired 0-1 number rises and falls in lockstep. The point: a
|
||||||
|
physical control is nothing more than a readout of one number.
|
||||||
|
|
||||||
|
Render:
|
||||||
|
manim -qh s1_knob_mapping.py KnobMapping
|
||||||
|
"""
|
||||||
|
|
||||||
|
from manim import *
|
||||||
|
|
||||||
|
BG = "#1C1C1C"
|
||||||
|
PRIMARY = "#58C4DD" # control side
|
||||||
|
NUMBER = "#83C167" # the number / value side
|
||||||
|
ACCENT = "#FFFF00" # the live value
|
||||||
|
DIM = 0.4
|
||||||
|
MONO = "Monospace"
|
||||||
|
|
||||||
|
|
||||||
|
def knob_group(value_tracker, radius=1.3):
|
||||||
|
"""A dial whose pointer angle tracks value in [0,1] over a 300 degree sweep."""
|
||||||
|
start_ang = -150 * DEGREES # bottom-left
|
||||||
|
sweep = 300 * DEGREES
|
||||||
|
|
||||||
|
face = Circle(radius=radius, color=PRIMARY, stroke_width=6)
|
||||||
|
face.set_fill(PRIMARY, opacity=0.06)
|
||||||
|
|
||||||
|
# the swept arc (the track the pointer travels along)
|
||||||
|
track = Arc(radius=radius + 0.18, start_angle=start_ang, angle=sweep,
|
||||||
|
color=PRIMARY, stroke_width=4).set_opacity(DIM)
|
||||||
|
|
||||||
|
def make_pointer():
|
||||||
|
ang = start_ang + value_tracker.get_value() * sweep
|
||||||
|
tip = np.array([np.cos(ang), np.sin(ang), 0]) * (radius - 0.18)
|
||||||
|
line = Line(ORIGIN, tip, color=ACCENT, stroke_width=8)
|
||||||
|
return line
|
||||||
|
|
||||||
|
pointer = always_redraw(make_pointer)
|
||||||
|
hub = Dot(ORIGIN, radius=0.08, color=ACCENT)
|
||||||
|
return VGroup(face, track), pointer, hub
|
||||||
|
|
||||||
|
|
||||||
|
class KnobMapping(Scene):
|
||||||
|
def construct(self):
|
||||||
|
self.camera.background_color = BG
|
||||||
|
|
||||||
|
title = Text("A knob is just a number", font_size=44, color=PRIMARY,
|
||||||
|
weight=BOLD, font=MONO)
|
||||||
|
self.play(Write(title), run_time=1.5)
|
||||||
|
self.wait(1.0)
|
||||||
|
self.play(title.animate.scale(0.62).to_edge(UP, buff=0.5), run_time=1.0)
|
||||||
|
self.wait(0.3)
|
||||||
|
|
||||||
|
val = ValueTracker(0.5)
|
||||||
|
|
||||||
|
dial, pointer, hub = knob_group(val)
|
||||||
|
dial.shift(LEFT * 3.2)
|
||||||
|
pointer.shift(LEFT * 3.2)
|
||||||
|
hub.shift(LEFT * 3.2)
|
||||||
|
|
||||||
|
knob_label = Text("control", font_size=24, color=PRIMARY, font=MONO)
|
||||||
|
knob_label.next_to(dial, DOWN, buff=0.4)
|
||||||
|
|
||||||
|
self.play(Create(dial), FadeIn(hub), run_time=1.2)
|
||||||
|
self.add(pointer)
|
||||||
|
self.play(FadeIn(knob_label), run_time=0.8)
|
||||||
|
self.wait(0.5)
|
||||||
|
|
||||||
|
# the number side: a vertical 0-1 bar + live readout
|
||||||
|
bar_h = 3.0
|
||||||
|
bar = Rectangle(width=0.5, height=bar_h, color=NUMBER, stroke_width=4)
|
||||||
|
bar.shift(RIGHT * 2.6)
|
||||||
|
bar_bottom = bar.get_bottom()
|
||||||
|
|
||||||
|
fill = always_redraw(lambda: Rectangle(
|
||||||
|
width=0.5, height=max(1e-3, val.get_value() * bar_h),
|
||||||
|
color=NUMBER, fill_color=NUMBER, fill_opacity=0.8, stroke_width=0,
|
||||||
|
).move_to(bar_bottom + UP * (val.get_value() * bar_h) / 2))
|
||||||
|
|
||||||
|
tick0 = Text("0", font_size=20, color=NUMBER, font=MONO).next_to(bar, DL, buff=0.15)
|
||||||
|
tick1 = Text("1", font_size=20, color=NUMBER, font=MONO).next_to(bar, UL, buff=0.15)
|
||||||
|
|
||||||
|
readout = always_redraw(lambda: Text(
|
||||||
|
f"{val.get_value():.2f}", font_size=40, color=ACCENT, font=MONO,
|
||||||
|
).next_to(bar, RIGHT, buff=0.5))
|
||||||
|
|
||||||
|
num_label = Text("value", font_size=24, color=NUMBER, font=MONO)
|
||||||
|
num_label.next_to(bar, DOWN, buff=0.55)
|
||||||
|
|
||||||
|
# the binding arrow
|
||||||
|
arrow = Arrow(dial.get_right() + RIGHT * 0.1, bar.get_left() + LEFT * 0.1,
|
||||||
|
color=WHITE, stroke_width=4, buff=0.2).set_opacity(DIM)
|
||||||
|
|
||||||
|
self.play(Create(bar), FadeIn(tick0), FadeIn(tick1), run_time=1.0)
|
||||||
|
self.add(fill, readout)
|
||||||
|
self.play(GrowArrow(arrow), FadeIn(num_label), run_time=1.0)
|
||||||
|
self.wait(1.0)
|
||||||
|
|
||||||
|
bind = Text("they move in lockstep", font_size=26, color=WHITE, font=MONO)
|
||||||
|
bind.to_edge(DOWN, buff=0.6)
|
||||||
|
self.play(FadeIn(bind), run_time=0.8)
|
||||||
|
self.wait(0.8)
|
||||||
|
|
||||||
|
# sweep up, down, and to extremes -- pointer and number never disagree
|
||||||
|
self.play(val.animate.set_value(1.0), run_time=2.0, rate_func=smooth)
|
||||||
|
self.wait(0.8)
|
||||||
|
self.play(val.animate.set_value(0.0), run_time=2.5, rate_func=smooth)
|
||||||
|
self.wait(0.8)
|
||||||
|
self.play(val.animate.set_value(0.73), run_time=1.5, rate_func=smooth)
|
||||||
|
self.wait(1.5)
|
||||||
|
|
||||||
|
self.play(FadeOut(Group(*self.mobjects)), run_time=0.6)
|
||||||
|
self.wait(0.3)
|
||||||
134
assets/media/src/s2_xy_pad.py
Normal file
134
assets/media/src/s2_xy_pad.py
Normal file
|
|
@ -0,0 +1,134 @@
|
||||||
|
"""Manifold explainer 2 — XY pad projects to two numbers.
|
||||||
|
|
||||||
|
A 2-D pad is two independent 0-1 readings. Moving the dot moves A (horizontal)
|
||||||
|
and B (vertical) independently, each shown as a slider.
|
||||||
|
|
||||||
|
Render:
|
||||||
|
manim -qh s2_xy_pad.py XYPad
|
||||||
|
"""
|
||||||
|
|
||||||
|
from manim import *
|
||||||
|
|
||||||
|
BG = "#1C1C1C"
|
||||||
|
PRIMARY = "#58C4DD" # pad / control
|
||||||
|
A_COL = "#FFFF00" # A axis (horizontal)
|
||||||
|
B_COL = "#83C167" # B axis (vertical)
|
||||||
|
DIM = 0.4
|
||||||
|
MONO = "Monospace"
|
||||||
|
|
||||||
|
|
||||||
|
def slider(value_tracker, length, colour, horizontal=True):
|
||||||
|
"""A track + a knob that tracks value in [0,1] along `length`."""
|
||||||
|
if horizontal:
|
||||||
|
track = Line(LEFT * length / 2, RIGHT * length / 2, color=colour,
|
||||||
|
stroke_width=5).set_opacity(DIM)
|
||||||
|
knob = always_redraw(lambda: Dot(
|
||||||
|
track.get_start() + RIGHT * value_tracker.get_value() * length,
|
||||||
|
radius=0.13, color=colour))
|
||||||
|
fill = always_redraw(lambda: Line(
|
||||||
|
track.get_start(),
|
||||||
|
track.get_start() + RIGHT * value_tracker.get_value() * length,
|
||||||
|
color=colour, stroke_width=5))
|
||||||
|
else:
|
||||||
|
track = Line(DOWN * length / 2, UP * length / 2, color=colour,
|
||||||
|
stroke_width=5).set_opacity(DIM)
|
||||||
|
knob = always_redraw(lambda: Dot(
|
||||||
|
track.get_start() + UP * value_tracker.get_value() * length,
|
||||||
|
radius=0.13, color=colour))
|
||||||
|
fill = always_redraw(lambda: Line(
|
||||||
|
track.get_start(),
|
||||||
|
track.get_start() + UP * value_tracker.get_value() * length,
|
||||||
|
color=colour, stroke_width=5))
|
||||||
|
return VGroup(track), fill, knob
|
||||||
|
|
||||||
|
|
||||||
|
class XYPad(Scene):
|
||||||
|
def construct(self):
|
||||||
|
self.camera.background_color = BG
|
||||||
|
|
||||||
|
title = Text("One pad, two numbers", font_size=44, color=PRIMARY,
|
||||||
|
weight=BOLD, font=MONO)
|
||||||
|
self.play(Write(title), run_time=1.5)
|
||||||
|
self.wait(1.0)
|
||||||
|
self.play(title.animate.scale(0.62).to_edge(UP, buff=0.5), run_time=1.0)
|
||||||
|
self.wait(0.3)
|
||||||
|
|
||||||
|
# the pad
|
||||||
|
side = 3.4
|
||||||
|
ax = ValueTracker(0.5)
|
||||||
|
bx = ValueTracker(0.5)
|
||||||
|
|
||||||
|
pad = Square(side_length=side, color=PRIMARY, stroke_width=5)
|
||||||
|
pad.set_fill(PRIMARY, opacity=0.05)
|
||||||
|
pad.shift(LEFT * 3.0)
|
||||||
|
bl = pad.get_corner(DL)
|
||||||
|
|
||||||
|
grid = VGroup()
|
||||||
|
for f in (0.25, 0.5, 0.75):
|
||||||
|
grid.add(Line(bl + RIGHT * f * side, bl + RIGHT * f * side + UP * side,
|
||||||
|
color=PRIMARY, stroke_width=1).set_opacity(0.15))
|
||||||
|
grid.add(Line(bl + UP * f * side, bl + UP * f * side + RIGHT * side,
|
||||||
|
color=PRIMARY, stroke_width=1).set_opacity(0.15))
|
||||||
|
|
||||||
|
dot = always_redraw(lambda: Dot(
|
||||||
|
bl + RIGHT * ax.get_value() * side + UP * bx.get_value() * side,
|
||||||
|
radius=0.13, color=WHITE))
|
||||||
|
|
||||||
|
# guide lines from the dot to each axis
|
||||||
|
vline = always_redraw(lambda: DashedLine(
|
||||||
|
bl + RIGHT * ax.get_value() * side,
|
||||||
|
bl + RIGHT * ax.get_value() * side + UP * bx.get_value() * side,
|
||||||
|
color=A_COL, stroke_width=2).set_opacity(DIM))
|
||||||
|
hline = always_redraw(lambda: DashedLine(
|
||||||
|
bl + UP * bx.get_value() * side,
|
||||||
|
bl + RIGHT * ax.get_value() * side + UP * bx.get_value() * side,
|
||||||
|
color=B_COL, stroke_width=2).set_opacity(DIM))
|
||||||
|
|
||||||
|
self.play(Create(pad), Create(grid), run_time=1.2)
|
||||||
|
self.add(dot)
|
||||||
|
pad_label = Text("XY pad", font_size=24, color=PRIMARY, font=MONO)
|
||||||
|
pad_label.next_to(pad, DOWN, buff=0.4)
|
||||||
|
self.play(FadeIn(pad_label), run_time=0.6)
|
||||||
|
self.wait(0.5)
|
||||||
|
self.add(vline, hline)
|
||||||
|
|
||||||
|
# A slider (horizontal) and B slider (vertical) on the right
|
||||||
|
a_track, a_fill, a_knob = slider(ax, 3.0, A_COL, horizontal=True)
|
||||||
|
a_group = VGroup(a_track, a_fill, a_knob)
|
||||||
|
a_group.shift(RIGHT * 3.0 + UP * 1.4)
|
||||||
|
a_lab = always_redraw(lambda: Text(
|
||||||
|
f"A = {ax.get_value():.2f}", font_size=28, color=A_COL, font=MONO
|
||||||
|
).next_to(a_track, UP, buff=0.3))
|
||||||
|
|
||||||
|
b_track, b_fill, b_knob = slider(bx, 3.0, B_COL, horizontal=False)
|
||||||
|
b_group = VGroup(b_track, b_fill, b_knob)
|
||||||
|
b_group.shift(RIGHT * 3.6 + DOWN * 1.4)
|
||||||
|
b_lab = always_redraw(lambda: Text(
|
||||||
|
f"B = {bx.get_value():.2f}", font_size=28, color=B_COL, font=MONO
|
||||||
|
).next_to(b_track, RIGHT, buff=0.4))
|
||||||
|
|
||||||
|
self.play(Create(a_track), Create(b_track), run_time=1.0)
|
||||||
|
self.add(a_fill, a_knob, a_lab, b_fill, b_knob, b_lab)
|
||||||
|
self.wait(0.5)
|
||||||
|
|
||||||
|
note = Text("A reads across, B reads up -- independently",
|
||||||
|
font_size=24, color=WHITE, font=MONO).to_edge(DOWN, buff=0.55)
|
||||||
|
self.play(FadeIn(note), run_time=0.8)
|
||||||
|
self.wait(1.0)
|
||||||
|
|
||||||
|
# move horizontally only: A changes, B holds
|
||||||
|
self.play(ax.animate.set_value(0.9), run_time=1.6, rate_func=smooth)
|
||||||
|
self.wait(0.6)
|
||||||
|
# move vertically only: B changes, A holds
|
||||||
|
self.play(bx.animate.set_value(0.85), run_time=1.6, rate_func=smooth)
|
||||||
|
self.wait(0.6)
|
||||||
|
# a diagonal sweep: both change together
|
||||||
|
self.play(ax.animate.set_value(0.15), bx.animate.set_value(0.2),
|
||||||
|
run_time=2.0, rate_func=smooth)
|
||||||
|
self.wait(0.6)
|
||||||
|
self.play(ax.animate.set_value(0.65), bx.animate.set_value(0.7),
|
||||||
|
run_time=1.6, rate_func=smooth)
|
||||||
|
self.wait(1.5)
|
||||||
|
|
||||||
|
self.play(FadeOut(Group(*self.mobjects)), run_time=0.6)
|
||||||
|
self.wait(0.3)
|
||||||
162
assets/media/src/s3_fanout.py
Normal file
162
assets/media/src/s3_fanout.py
Normal file
|
|
@ -0,0 +1,162 @@
|
||||||
|
"""Manifold explainer 3 — Dimensionality fan-out.
|
||||||
|
|
||||||
|
The same low-dimensional control drives N outputs (3, then 4, then 5), with a
|
||||||
|
small network in between. Shown for several control types: knob, fader, touchpad,
|
||||||
|
2-D joystick, 3-D joystick. Control on one side, N sliders on the other.
|
||||||
|
|
||||||
|
Render:
|
||||||
|
manim -qh s3_fanout.py Fanout
|
||||||
|
"""
|
||||||
|
|
||||||
|
from manim import *
|
||||||
|
|
||||||
|
BG = "#1C1C1C"
|
||||||
|
PRIMARY = "#58C4DD" # control
|
||||||
|
NET = "#FF6B6B" # the network in the middle
|
||||||
|
OUT = "#83C167" # outputs
|
||||||
|
ACCENT = "#FFFF00"
|
||||||
|
DIM = 0.4
|
||||||
|
MONO = "Monospace"
|
||||||
|
|
||||||
|
|
||||||
|
def mini_control(kind):
|
||||||
|
"""Return a small VGroup glyph + label for a control type, plus how many
|
||||||
|
numbers it emits (its dimensionality)."""
|
||||||
|
if kind == "knob":
|
||||||
|
face = Circle(radius=0.55, color=PRIMARY, stroke_width=5)
|
||||||
|
ptr = Line(ORIGIN, UP * 0.45, color=ACCENT, stroke_width=6).rotate(
|
||||||
|
-40 * DEGREES, about_point=ORIGIN)
|
||||||
|
g = VGroup(face, ptr, Dot(ORIGIN, radius=0.05, color=ACCENT))
|
||||||
|
return g, "knob", 1
|
||||||
|
if kind == "fader":
|
||||||
|
track = Line(DOWN * 0.6, UP * 0.6, color=PRIMARY, stroke_width=5)
|
||||||
|
cap = Rectangle(width=0.4, height=0.18, color=ACCENT, fill_color=ACCENT,
|
||||||
|
fill_opacity=1).move_to(UP * 0.15)
|
||||||
|
return VGroup(track, cap), "fader", 1
|
||||||
|
if kind == "touchpad":
|
||||||
|
sq = Square(side_length=1.1, color=PRIMARY, stroke_width=5)
|
||||||
|
sq.set_fill(PRIMARY, opacity=0.06)
|
||||||
|
d = Dot(sq.get_center() + RIGHT * 0.25 + UP * 0.18, radius=0.09, color=WHITE)
|
||||||
|
return VGroup(sq, d), "touchpad", 2
|
||||||
|
if kind == "joystick2d":
|
||||||
|
ring = Circle(radius=0.6, color=PRIMARY, stroke_width=5)
|
||||||
|
stick = Line(ORIGIN, RIGHT * 0.3 + UP * 0.35, color=ACCENT, stroke_width=7)
|
||||||
|
knob = Dot(RIGHT * 0.3 + UP * 0.35, radius=0.1, color=ACCENT)
|
||||||
|
return VGroup(ring, stick, knob), "2-D joystick", 2
|
||||||
|
if kind == "joystick3d":
|
||||||
|
ring = Circle(radius=0.6, color=PRIMARY, stroke_width=5)
|
||||||
|
stick = Line(ORIGIN, RIGHT * 0.28 + UP * 0.32, color=ACCENT, stroke_width=7)
|
||||||
|
knob = Dot(RIGHT * 0.28 + UP * 0.32, radius=0.1, color=ACCENT)
|
||||||
|
# a small twist arc to suggest the 3rd (rotational) axis
|
||||||
|
twist = Arc(radius=0.78, start_angle=20 * DEGREES, angle=120 * DEGREES,
|
||||||
|
color=ACCENT, stroke_width=3).set_opacity(0.7)
|
||||||
|
twist_tip = Triangle(color=ACCENT, fill_opacity=1).scale(0.06).move_to(
|
||||||
|
twist.get_end())
|
||||||
|
return VGroup(ring, stick, knob, twist, twist_tip), "3-D joystick", 3
|
||||||
|
raise ValueError(kind)
|
||||||
|
|
||||||
|
|
||||||
|
class Fanout(Scene):
|
||||||
|
def construct(self):
|
||||||
|
self.camera.background_color = BG
|
||||||
|
|
||||||
|
title = Text("One control, many outputs", font_size=44, color=PRIMARY,
|
||||||
|
weight=BOLD, font=MONO)
|
||||||
|
self.play(Write(title), run_time=1.5)
|
||||||
|
self.wait(1.0)
|
||||||
|
self.play(title.animate.scale(0.6).to_edge(UP, buff=0.4), run_time=1.0)
|
||||||
|
self.wait(0.3)
|
||||||
|
|
||||||
|
# --- Part A: grow N (3 -> 4 -> 5) with a fixed 2-D control ---
|
||||||
|
ctrl, ctrl_name, ndim = mini_control("touchpad")
|
||||||
|
ctrl.scale(1.3).shift(LEFT * 4.5)
|
||||||
|
ctrl_lab = Text(f"{ctrl_name} ({ndim} numbers)", font_size=22,
|
||||||
|
color=PRIMARY, font=MONO).next_to(ctrl, DOWN, buff=0.4)
|
||||||
|
|
||||||
|
net = RoundedRectangle(width=1.4, height=2.4, corner_radius=0.15,
|
||||||
|
color=NET, stroke_width=4)
|
||||||
|
net.set_fill(NET, opacity=0.08).shift(LEFT * 0.6)
|
||||||
|
net_lab = Text("network", font_size=20, color=NET, font=MONO).next_to(
|
||||||
|
net, DOWN, buff=0.3)
|
||||||
|
|
||||||
|
self.play(FadeIn(ctrl), FadeIn(ctrl_lab), run_time=1.0)
|
||||||
|
self.play(Create(net), FadeIn(net_lab), run_time=1.0)
|
||||||
|
in_arrow = Arrow(ctrl.get_right(), net.get_left(), color=WHITE,
|
||||||
|
stroke_width=4, buff=0.25).set_opacity(DIM)
|
||||||
|
self.play(GrowArrow(in_arrow), run_time=0.6)
|
||||||
|
self.wait(0.5)
|
||||||
|
|
||||||
|
def make_sliders(n):
|
||||||
|
grp = VGroup()
|
||||||
|
top = 1.9
|
||||||
|
gap = 3.8 / max(1, n - 1) if n > 1 else 0
|
||||||
|
for i in range(n):
|
||||||
|
y = top - i * gap if n > 1 else 0
|
||||||
|
t = Line(ORIGIN, RIGHT * 2.0, color=OUT, stroke_width=4).set_opacity(DIM)
|
||||||
|
t.move_to(RIGHT * 3.7 + UP * y)
|
||||||
|
frac = 0.5 + 0.4 * np.sin(i * 1.3 + n)
|
||||||
|
fill = Line(t.get_start(), t.get_start() + RIGHT * 2.0 * frac,
|
||||||
|
color=OUT, stroke_width=4)
|
||||||
|
knob = Dot(t.get_start() + RIGHT * 2.0 * frac, radius=0.1, color=OUT)
|
||||||
|
lab = Text(f"out {i+1}", font_size=16, color=OUT, font=MONO).next_to(
|
||||||
|
t, LEFT, buff=0.2)
|
||||||
|
grp.add(VGroup(t, fill, knob, lab))
|
||||||
|
return grp
|
||||||
|
|
||||||
|
counter = Text("3 outputs", font_size=26, color=OUT, font=MONO).to_edge(
|
||||||
|
DOWN, buff=0.55)
|
||||||
|
|
||||||
|
sliders = make_sliders(3)
|
||||||
|
fan = VGroup(*[Line(net.get_right(), s[0].get_left(), color=NET,
|
||||||
|
stroke_width=2).set_opacity(0.5) for s in sliders])
|
||||||
|
self.play(Create(sliders), Create(fan), FadeIn(counter), run_time=1.2)
|
||||||
|
self.wait(1.2)
|
||||||
|
|
||||||
|
for n in (4, 5):
|
||||||
|
new_sliders = make_sliders(n)
|
||||||
|
new_fan = VGroup(*[Line(net.get_right(), s[0].get_left(), color=NET,
|
||||||
|
stroke_width=2).set_opacity(0.5) for s in new_sliders])
|
||||||
|
new_counter = Text(f"{n} outputs", font_size=26, color=OUT,
|
||||||
|
font=MONO).to_edge(DOWN, buff=0.55)
|
||||||
|
self.play(
|
||||||
|
ReplacementTransform(sliders, new_sliders),
|
||||||
|
ReplacementTransform(fan, new_fan),
|
||||||
|
ReplacementTransform(counter, new_counter),
|
||||||
|
run_time=1.3)
|
||||||
|
sliders, fan, counter = new_sliders, new_fan, new_counter
|
||||||
|
self.wait(1.0)
|
||||||
|
|
||||||
|
self.wait(0.5)
|
||||||
|
# clear the output side + counter, keep the network, swap the control type
|
||||||
|
self.play(FadeOut(sliders), FadeOut(fan), FadeOut(counter),
|
||||||
|
FadeOut(ctrl), FadeOut(ctrl_lab), run_time=0.6)
|
||||||
|
|
||||||
|
# --- Part B: cycle control types into the same network -> 5 outputs ---
|
||||||
|
note = Text("...and any control feeds the same fan-out",
|
||||||
|
font_size=24, color=WHITE, font=MONO).to_edge(DOWN, buff=0.55)
|
||||||
|
self.play(FadeIn(note), run_time=0.6)
|
||||||
|
|
||||||
|
five = make_sliders(5)
|
||||||
|
five_fan = VGroup(*[Line(net.get_right(), s[0].get_left(), color=NET,
|
||||||
|
stroke_width=2).set_opacity(0.5) for s in five])
|
||||||
|
self.play(Create(five), Create(five_fan), run_time=0.8)
|
||||||
|
|
||||||
|
prev_ctrl = None
|
||||||
|
prev_lab = None
|
||||||
|
for kind in ("knob", "fader", "touchpad", "joystick2d", "joystick3d"):
|
||||||
|
g, name, nd = mini_control(kind)
|
||||||
|
g.scale(1.3).shift(LEFT * 4.5)
|
||||||
|
lab = Text(f"{name} ({nd} number{'s' if nd > 1 else ''})",
|
||||||
|
font_size=22, color=PRIMARY, font=MONO).next_to(
|
||||||
|
g, DOWN, buff=0.4)
|
||||||
|
if prev_ctrl is None:
|
||||||
|
self.play(FadeIn(g), FadeIn(lab), run_time=0.7)
|
||||||
|
else:
|
||||||
|
self.play(ReplacementTransform(prev_ctrl, g),
|
||||||
|
ReplacementTransform(prev_lab, lab), run_time=0.9)
|
||||||
|
prev_ctrl, prev_lab = g, lab
|
||||||
|
self.wait(0.9)
|
||||||
|
|
||||||
|
self.wait(1.2)
|
||||||
|
self.play(FadeOut(Group(*self.mobjects)), run_time=0.6)
|
||||||
|
self.wait(0.3)
|
||||||
241
assets/media/src/s4_feedback.py
Normal file
241
assets/media/src/s4_feedback.py
Normal file
|
|
@ -0,0 +1,241 @@
|
||||||
|
"""Manifold explainer 4 — Feedback / training, two modes contrasted.
|
||||||
|
|
||||||
|
Training reshapes the mapping, seen as a landscape (the loss / mapping surface
|
||||||
|
projected to 2-D). Manifold offers two feedback modes:
|
||||||
|
|
||||||
|
* GeometricDislike -- you have a liked region; a thumbs-down carves the current
|
||||||
|
point directionally AWAY from the liked centroid.
|
||||||
|
* ExploreAndPlace -- (RECOMMENDED DEFAULT) randomise the net, audition, "I like
|
||||||
|
that", drop it in a corner, randomise again, place another,
|
||||||
|
then interpolate between the placed anchors. Positive-only.
|
||||||
|
|
||||||
|
Coordinated with docs/redesign/rl-feedback-design.md.
|
||||||
|
|
||||||
|
Render:
|
||||||
|
manim -qh s4_feedback.py GeometricDislike ExploreAndPlace FeedbackContrast
|
||||||
|
"""
|
||||||
|
|
||||||
|
from manim import *
|
||||||
|
|
||||||
|
BG = "#1C1C1C"
|
||||||
|
PRIMARY = "#58C4DD"
|
||||||
|
LIKE = "#83C167" # liked / positive
|
||||||
|
DISLIKE = "#FF6B6B" # disliked / push-away
|
||||||
|
ACCENT = "#FFFF00"
|
||||||
|
ANCHOR = "#83C167"
|
||||||
|
MONO = "Monospace"
|
||||||
|
|
||||||
|
|
||||||
|
def control_pad(side=3.2, shift=ORIGIN, colour=PRIMARY):
|
||||||
|
"""A 2-D control space (the input plane the mapping lives over)."""
|
||||||
|
pad = Square(side_length=side, color=colour, stroke_width=4)
|
||||||
|
pad.set_fill(colour, opacity=0.05).move_to(shift)
|
||||||
|
grid = VGroup()
|
||||||
|
bl = pad.get_corner(DL)
|
||||||
|
for f in (0.25, 0.5, 0.75):
|
||||||
|
grid.add(Line(bl + RIGHT * f * side, bl + RIGHT * f * side + UP * side,
|
||||||
|
color=colour, stroke_width=1).set_opacity(0.15))
|
||||||
|
grid.add(Line(bl + UP * f * side, bl + UP * f * side + RIGHT * side,
|
||||||
|
color=colour, stroke_width=1).set_opacity(0.15))
|
||||||
|
return pad, grid
|
||||||
|
|
||||||
|
|
||||||
|
class GeometricDislike(Scene):
|
||||||
|
def construct(self):
|
||||||
|
self.camera.background_color = BG
|
||||||
|
title = Text("Geometric dislike", font_size=42, color=DISLIKE,
|
||||||
|
weight=BOLD, font=MONO).to_edge(UP, buff=0.4)
|
||||||
|
sub = Text("push the sound away from what you like", font_size=24,
|
||||||
|
color=WHITE, font=MONO).next_to(title, DOWN, buff=0.25)
|
||||||
|
self.play(Write(title), run_time=1.2)
|
||||||
|
self.play(FadeIn(sub), run_time=0.7)
|
||||||
|
self.wait(0.8)
|
||||||
|
|
||||||
|
pad, grid = control_pad(3.4, LEFT * 3.0 + DOWN * 0.3)
|
||||||
|
self.play(Create(pad), Create(grid), run_time=1.0)
|
||||||
|
|
||||||
|
# a few liked points + their centroid
|
||||||
|
liked_pts = [LEFT * 3.8 + DOWN * 0.9, LEFT * 2.5 + UP * 0.3,
|
||||||
|
LEFT * 3.2 + UP * 0.6]
|
||||||
|
likes = VGroup(*[Dot(p, radius=0.11, color=LIKE) for p in liked_pts])
|
||||||
|
like_lab = Text("liked region", font_size=20, color=LIKE, font=MONO)
|
||||||
|
like_lab.next_to(pad, DOWN, buff=0.3)
|
||||||
|
self.play(LaggedStart(*[GrowFromCenter(d) for d in likes], lag_ratio=0.3),
|
||||||
|
FadeIn(like_lab), run_time=1.2)
|
||||||
|
|
||||||
|
centroid_pos = np.mean(np.array(liked_pts), axis=0)
|
||||||
|
centroid = Dot(centroid_pos, radius=0.09, color=LIKE).set_opacity(0.6)
|
||||||
|
cring = Circle(radius=0.22, color=LIKE, stroke_width=2).move_to(
|
||||||
|
centroid_pos).set_opacity(0.6)
|
||||||
|
c_lab = Text("centre", font_size=16, color=LIKE, font=MONO).next_to(
|
||||||
|
cring, UP, buff=0.1)
|
||||||
|
self.play(FadeIn(centroid), Create(cring), FadeIn(c_lab), run_time=0.8)
|
||||||
|
self.wait(0.8)
|
||||||
|
|
||||||
|
# the current (heard) point + thumbs-down
|
||||||
|
cur = Dot(LEFT * 1.9 + DOWN * 1.0, radius=0.13, color=ACCENT)
|
||||||
|
cur_lab = Text("current sound", font_size=18, color=ACCENT, font=MONO).next_to(
|
||||||
|
cur, RIGHT, buff=0.15)
|
||||||
|
self.play(GrowFromCenter(cur), FadeIn(cur_lab), run_time=0.8)
|
||||||
|
self.wait(0.5)
|
||||||
|
|
||||||
|
down = Text("thumbs-down", font_size=26, color=DISLIKE, font=MONO).to_edge(
|
||||||
|
DOWN, buff=0.5)
|
||||||
|
self.play(FadeIn(down), Flash(cur, color=DISLIKE, line_length=0.3), run_time=0.9)
|
||||||
|
self.wait(0.4)
|
||||||
|
|
||||||
|
# the push vector: directed AWAY from the centroid (cur - centroid)
|
||||||
|
direction = cur.get_center() - centroid_pos
|
||||||
|
direction = direction / np.linalg.norm(direction)
|
||||||
|
target = cur.get_center() + direction * 1.5
|
||||||
|
push = Arrow(cur.get_center(), target, color=DISLIKE, stroke_width=6,
|
||||||
|
buff=0.0)
|
||||||
|
self.play(GrowArrow(push), run_time=1.0)
|
||||||
|
self.wait(0.4)
|
||||||
|
self.play(cur.animate.move_to(target),
|
||||||
|
cur_lab.animate.next_to(target, RIGHT, buff=0.15),
|
||||||
|
run_time=1.4, rate_func=smooth)
|
||||||
|
self.play(FadeOut(push), run_time=0.4)
|
||||||
|
self.wait(0.5)
|
||||||
|
|
||||||
|
note = Text("directed repulsion: away from the centre, not random",
|
||||||
|
font_size=22, color=WHITE, font=MONO).to_edge(DOWN, buff=0.5)
|
||||||
|
self.play(ReplacementTransform(down, note), run_time=0.7)
|
||||||
|
self.wait(1.8)
|
||||||
|
self.play(FadeOut(Group(*self.mobjects)), run_time=0.6)
|
||||||
|
self.wait(0.3)
|
||||||
|
|
||||||
|
|
||||||
|
class ExploreAndPlace(Scene):
|
||||||
|
def construct(self):
|
||||||
|
self.camera.background_color = BG
|
||||||
|
title = Text("Explore and place", font_size=42, color=LIKE,
|
||||||
|
weight=BOLD, font=MONO).to_edge(UP, buff=0.4)
|
||||||
|
tag = Text("recommended default", font_size=18, color=ACCENT,
|
||||||
|
font=MONO).next_to(title, RIGHT, buff=0.4)
|
||||||
|
sub = Text("randomise -> audition -> place -> interpolate", font_size=24,
|
||||||
|
color=WHITE, font=MONO).next_to(title, DOWN, buff=0.25)
|
||||||
|
self.play(Write(title), FadeIn(tag), run_time=1.2)
|
||||||
|
self.play(FadeIn(sub), run_time=0.7)
|
||||||
|
self.wait(0.8)
|
||||||
|
|
||||||
|
pad, grid = control_pad(3.6, LEFT * 3.0 + DOWN * 0.3)
|
||||||
|
self.play(Create(pad), Create(grid), run_time=1.0)
|
||||||
|
|
||||||
|
# the scratchpad readout (audition meter) on the right
|
||||||
|
meter_lab = Text("audition", font_size=22, color=PRIMARY, font=MONO)
|
||||||
|
meter_lab.shift(RIGHT * 3.3 + UP * 2.0)
|
||||||
|
bar_bg = Rectangle(width=2.4, height=0.5, color=PRIMARY, stroke_width=3)
|
||||||
|
bar_bg.next_to(meter_lab, DOWN, buff=0.3)
|
||||||
|
self.play(FadeIn(meter_lab), Create(bar_bg), run_time=0.8)
|
||||||
|
|
||||||
|
def audition_bar(frac, colour=ACCENT):
|
||||||
|
return Rectangle(width=2.4 * frac, height=0.5, color=colour,
|
||||||
|
fill_color=colour, fill_opacity=0.8,
|
||||||
|
stroke_width=0).align_to(bar_bg, LEFT).set_y(bar_bg.get_y())
|
||||||
|
|
||||||
|
step = Text("", font_size=24, color=WHITE, font=MONO).to_edge(DOWN, buff=0.5)
|
||||||
|
self.add(step)
|
||||||
|
|
||||||
|
def set_step(txt, colour=WHITE):
|
||||||
|
new = Text(txt, font_size=24, color=colour, font=MONO).to_edge(DOWN, buff=0.5)
|
||||||
|
self.play(Transform(step, new), run_time=0.5)
|
||||||
|
|
||||||
|
anchors = VGroup()
|
||||||
|
corners = [LEFT * 4.1 + UP * 0.9, LEFT * 1.9 + DOWN * 1.4]
|
||||||
|
timbres = [0.78, 0.32]
|
||||||
|
|
||||||
|
for i, (corner, t) in enumerate(zip(corners, timbres)):
|
||||||
|
# randomise: meter jitters
|
||||||
|
set_step('"meh, randomise..."', PRIMARY)
|
||||||
|
jit = audition_bar(0.5)
|
||||||
|
self.add(jit)
|
||||||
|
for f in (0.85, 0.2, 0.6, t):
|
||||||
|
self.play(Transform(jit, audition_bar(f)), run_time=0.35)
|
||||||
|
self.wait(0.4)
|
||||||
|
set_step('"oh, I like that!"', LIKE)
|
||||||
|
self.play(Transform(jit, audition_bar(t, LIKE)),
|
||||||
|
Flash(bar_bg, color=LIKE, line_length=0.2), run_time=0.6)
|
||||||
|
self.wait(0.4)
|
||||||
|
# place it into a corner
|
||||||
|
set_step("place it in that corner", LIKE)
|
||||||
|
placed = Dot(bar_bg.get_center(), radius=0.13, color=ANCHOR)
|
||||||
|
self.add(placed)
|
||||||
|
self.play(placed.animate.move_to(corner), run_time=1.2, rate_func=smooth)
|
||||||
|
ring = Circle(radius=0.2, color=ANCHOR, stroke_width=2).move_to(corner)
|
||||||
|
self.play(Create(ring), run_time=0.4)
|
||||||
|
anchors.add(VGroup(placed, ring))
|
||||||
|
self.remove(jit)
|
||||||
|
self.wait(0.5)
|
||||||
|
|
||||||
|
# interpolate between the two placed anchors
|
||||||
|
set_step("interpolate between placed sounds", ACCENT)
|
||||||
|
a0 = corners[0]
|
||||||
|
a1 = corners[1]
|
||||||
|
morph = Dot(a0, radius=0.12, color=ACCENT)
|
||||||
|
line = DashedLine(a0, a1, color=ACCENT, stroke_width=2).set_opacity(0.4)
|
||||||
|
self.play(Create(line), GrowFromCenter(morph), run_time=0.7)
|
||||||
|
morph_bar = audition_bar(timbres[0], ACCENT)
|
||||||
|
self.add(morph_bar)
|
||||||
|
for f in (0.25, 0.5, 0.75, 1.0, 0.4):
|
||||||
|
pos = a0 + (a1 - a0) * f
|
||||||
|
val = timbres[0] + (timbres[1] - timbres[0]) * f
|
||||||
|
self.play(morph.animate.move_to(pos),
|
||||||
|
Transform(morph_bar, audition_bar(val, ACCENT)),
|
||||||
|
run_time=0.7)
|
||||||
|
self.wait(0.5)
|
||||||
|
set_step("a smooth morph -- and no concept of 'dislike'", LIKE)
|
||||||
|
self.wait(1.8)
|
||||||
|
self.play(FadeOut(Group(*self.mobjects)), run_time=0.6)
|
||||||
|
self.wait(0.3)
|
||||||
|
|
||||||
|
|
||||||
|
class FeedbackContrast(Scene):
|
||||||
|
def construct(self):
|
||||||
|
self.camera.background_color = BG
|
||||||
|
title = Text("Two ways to teach a mapping", font_size=40, color=PRIMARY,
|
||||||
|
weight=BOLD, font=MONO).to_edge(UP, buff=0.4)
|
||||||
|
self.play(Write(title), run_time=1.2)
|
||||||
|
self.wait(0.6)
|
||||||
|
|
||||||
|
divider = DashedLine(UP * 2.3, DOWN * 3.0, color=WHITE,
|
||||||
|
stroke_width=2).set_opacity(0.25)
|
||||||
|
self.play(Create(divider), run_time=0.6)
|
||||||
|
|
||||||
|
# left: geometric dislike
|
||||||
|
l_head = Text("Geometric dislike", font_size=28, color=DISLIKE,
|
||||||
|
weight=BOLD, font=MONO).move_to(LEFT * 3.5 + UP * 1.7)
|
||||||
|
l_lines = VGroup(
|
||||||
|
Text("- you have a liked region", font_size=20, color=WHITE, font=MONO),
|
||||||
|
Text("- thumbs-down pushes the", font_size=20, color=WHITE, font=MONO),
|
||||||
|
Text(" sound AWAY from it", font_size=20, color=DISLIKE, font=MONO),
|
||||||
|
Text("- directed, audible repulsion", font_size=20, color=WHITE, font=MONO),
|
||||||
|
Text("- precision sculpting tool", font_size=20, color=WHITE, font=MONO),
|
||||||
|
).arrange(DOWN, aligned_edge=LEFT, buff=0.28).move_to(LEFT * 3.5 + DOWN * 0.3)
|
||||||
|
|
||||||
|
# right: explore and place
|
||||||
|
r_head = Text("Explore and place", font_size=28, color=LIKE,
|
||||||
|
weight=BOLD, font=MONO).move_to(RIGHT * 3.5 + UP * 1.7)
|
||||||
|
r_tag = Text("DEFAULT", font_size=16, color=ACCENT, font=MONO).next_to(
|
||||||
|
r_head, DOWN, buff=0.12)
|
||||||
|
r_lines = VGroup(
|
||||||
|
Text("- randomise, audition, place", font_size=20, color=WHITE, font=MONO),
|
||||||
|
Text("- positive-only: collect", font_size=20, color=LIKE, font=MONO),
|
||||||
|
Text(" sounds you like", font_size=20, color=LIKE, font=MONO),
|
||||||
|
Text("- interpolate between anchors", font_size=20, color=WHITE, font=MONO),
|
||||||
|
Text("- no 'away from what' to reason", font_size=20, color=WHITE, font=MONO),
|
||||||
|
).arrange(DOWN, aligned_edge=LEFT, buff=0.28).move_to(RIGHT * 3.5 + DOWN * 0.3)
|
||||||
|
|
||||||
|
self.play(FadeIn(l_head), FadeIn(r_head), FadeIn(r_tag), run_time=0.8)
|
||||||
|
self.play(LaggedStart(*[FadeIn(x) for x in l_lines], lag_ratio=0.25),
|
||||||
|
LaggedStart(*[FadeIn(x) for x in r_lines], lag_ratio=0.25),
|
||||||
|
run_time=2.0)
|
||||||
|
self.wait(1.5)
|
||||||
|
|
||||||
|
rec = Text("Default to explore-and-place; reach for dislike to sculpt.",
|
||||||
|
font_size=22, color=ACCENT, font=MONO).to_edge(DOWN, buff=0.45)
|
||||||
|
box = SurroundingRectangle(rec, color=ACCENT, buff=0.2, stroke_width=2)
|
||||||
|
self.play(FadeIn(rec), Create(box), run_time=1.0)
|
||||||
|
self.wait(2.5)
|
||||||
|
self.play(FadeOut(Group(*self.mobjects)), run_time=0.6)
|
||||||
|
self.wait(0.3)
|
||||||
2
codegen/.gitignore
vendored
Normal file
2
codegen/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
node_modules/
|
||||||
|
*.tsbuildinfo
|
||||||
50
codegen/README.md
Normal file
50
codegen/README.md
Normal file
|
|
@ -0,0 +1,50 @@
|
||||||
|
# codegen — schemas → C++ + TypeScript
|
||||||
|
|
||||||
|
Bun scripts that turn the JSON schemas under `schemas/` into generated code for both
|
||||||
|
targets. The per-file inventory lives in `MAP.md` (§ `codegen/`) — this README only
|
||||||
|
covers how to run it.
|
||||||
|
|
||||||
|
- `generate.ts` — validates `schemas/modes/*.json` against `schemas/schema.json`, emits
|
||||||
|
`nisps/modes/generated/<mode>_schema.hpp` (+ `schema_types.hpp`) and
|
||||||
|
`manifold/src/modes/generated/<mode>_schema.ts` (+ `types.ts`, `index.ts`).
|
||||||
|
- `generate-midi-devices.ts` — validates `schemas/midi_devices/*.json` against
|
||||||
|
`schemas/midi_device.schema.json`, emits `nisps/midi/generated/midi_devices.hpp` and
|
||||||
|
`manifold/src/midi-devices/generated/{types,devices,index}.ts`.
|
||||||
|
|
||||||
|
Both validate with ajv (Draft 2020-12), exit non-zero on failure, and are idempotent
|
||||||
|
(re-running with unchanged schemas is byte-identical).
|
||||||
|
|
||||||
|
## Run
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd codegen
|
||||||
|
bun install
|
||||||
|
bun run generate.ts # mode schemas
|
||||||
|
bun run generate-midi-devices.ts # MIDI device templates
|
||||||
|
```
|
||||||
|
|
||||||
|
Schema or codegen changes ship with the regenerated C++ **and** TypeScript in the same
|
||||||
|
commit — CI re-runs both generators and fails on any diff.
|
||||||
|
|
||||||
|
## Golden test
|
||||||
|
|
||||||
|
`tests/golden_test.ts` re-runs `generate.ts` against the live output dirs, diffs
|
||||||
|
`paf_synth_schema.{hpp,ts}` against the snapshots in `tests/golden/`, then re-runs to
|
||||||
|
prove idempotency:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
bun run test
|
||||||
|
```
|
||||||
|
|
||||||
|
After an intentional emission change, refresh the goldens:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
bun run generate.ts
|
||||||
|
cp ../nisps/modes/generated/paf_synth_schema.hpp tests/golden/
|
||||||
|
cp ../manifold/src/modes/generated/paf_synth_schema.ts tests/golden/
|
||||||
|
```
|
||||||
|
|
||||||
|
## Adding a mode / device
|
||||||
|
|
||||||
|
Drop the new JSON into `schemas/modes/` (or `schemas/midi_devices/`), run the matching
|
||||||
|
generator, and commit the JSON plus the regenerated outputs together.
|
||||||
885
codegen/curve-audit.ts
Normal file
885
codegen/curve-audit.ts
Normal file
|
|
@ -0,0 +1,885 @@
|
||||||
|
/**
|
||||||
|
* curve-audit.ts — mechanically derive, from `nisps/engines/*.hpp` source,
|
||||||
|
* which response curve each engine applies to each NN-output slot, per voice
|
||||||
|
* space.
|
||||||
|
*
|
||||||
|
* WHY THIS IS A SOURCE-LEVEL CHECK
|
||||||
|
* --------------------------------
|
||||||
|
* "The curve" is not observable from engine output. A voice space maps a
|
||||||
|
* normalised param into engine state as `base + f(p) * scale` and then that
|
||||||
|
* state goes through DSP. Given only audio out you cannot separate `f` from
|
||||||
|
* `base`/`scale`/the DSP, and the engines expose no accessor for the mapped
|
||||||
|
* state. So the only place the curve exists as a fact is the arithmetic in
|
||||||
|
* `apply_*()` / `set_params()` / `process()` — and that is what this module
|
||||||
|
* reads.
|
||||||
|
*
|
||||||
|
* The contract it enforces is deliberately narrow and total:
|
||||||
|
*
|
||||||
|
* square <=> the engine multiplies the param slot by itself
|
||||||
|
* sqrt <=> the engine passes the param slot through std::sqrt
|
||||||
|
* linear <=> anything else (including quantisation, sin() combination and
|
||||||
|
* stepped lookup tables — those are not expressible in the
|
||||||
|
* `Curve` enum and are declared `linear` by definition)
|
||||||
|
*
|
||||||
|
* Everything it cannot reduce is a HARD ERROR, never a silent "linear". That
|
||||||
|
* is the property that makes the derived table trustworthy: a new voice space,
|
||||||
|
* a new idiom, or a renamed helper trips the check instead of quietly
|
||||||
|
* under-reporting. A regex over `p[N] * p[N]` would miss the `const float v =
|
||||||
|
* p[…]; v * v` form (verb_fx), the `sq()` implicit-counter lambda
|
||||||
|
* (memlcelium), loop-generated indices (verb_fx) and `smooth_params_[N]`
|
||||||
|
* (xiasri) — every one of those is live in this codebase today.
|
||||||
|
*
|
||||||
|
* Consumed by codegen/tests/curve_drift_test.ts, which asserts the schemas'
|
||||||
|
* declared curves (params[].curve + per-voice-space overrides) match.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { readFileSync, readdirSync } from "node:fs";
|
||||||
|
import { join } from "node:path";
|
||||||
|
|
||||||
|
export type Curve =
|
||||||
|
| "linear"
|
||||||
|
| "exp"
|
||||||
|
| "log"
|
||||||
|
| "square"
|
||||||
|
| "sqrt"
|
||||||
|
| "sigmoid"
|
||||||
|
| "cubic";
|
||||||
|
|
||||||
|
/** Identifiers that alias the NN-output vector inside an engine. */
|
||||||
|
const ACCESSORS = ["params", "p", "smooth_params_", "nn_outputs_"] as const;
|
||||||
|
const ACCESSOR_RE = new RegExp(`\\b(${ACCESSORS.join("|")})\\s*\\[`);
|
||||||
|
|
||||||
|
export interface EngineCurves {
|
||||||
|
engineId: string;
|
||||||
|
file: string;
|
||||||
|
nParams: number;
|
||||||
|
/** Names from the engine's `kVoiceSpaceNames`, or null when it has none. */
|
||||||
|
voiceSpaceNames: string[] | null;
|
||||||
|
/** curves[voiceSpaceIndex][paramIndex]. One row when there is no enum. */
|
||||||
|
curves: Curve[][];
|
||||||
|
}
|
||||||
|
|
||||||
|
export class CurveAuditError extends Error {}
|
||||||
|
|
||||||
|
function fail(where: string, msg: string): never {
|
||||||
|
throw new CurveAuditError(`[curve-audit] ${where}: ${msg}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Lexical helpers
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
function stripComments(src: string): string {
|
||||||
|
// Block comments first, then line comments. No string literals in these
|
||||||
|
// files contain `//` or `/*` (checked: the only literals are identifiers).
|
||||||
|
return src.replace(/\/\*[\s\S]*?\*\//g, " ").replace(/\/\/[^\n]*/g, " ");
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Index of the `)`/`}`/`]` matching the opener at `open`. */
|
||||||
|
function matchBracket(src: string, open: number): number {
|
||||||
|
const pairs: Record<string, string> = { "(": ")", "{": "}", "[": "]" };
|
||||||
|
const close = pairs[src[open]!];
|
||||||
|
if (!close) fail("matchBracket", `not an opener at ${open}: ${src[open]}`);
|
||||||
|
let depth = 0;
|
||||||
|
for (let i = open; i < src.length; i++) {
|
||||||
|
const c = src[i]!;
|
||||||
|
if (c === src[open]) depth++;
|
||||||
|
else if (c === close) {
|
||||||
|
depth--;
|
||||||
|
if (depth === 0) return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fail("matchBracket", `unbalanced ${src[open]} at ${open}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Body text (between braces, exclusive) of `<name>(...) ... { ... }`. */
|
||||||
|
function functionBody(src: string, name: string): string | null {
|
||||||
|
const re = new RegExp(`\\b${name}\\s*\\(`, "g");
|
||||||
|
let m: RegExpExecArray | null;
|
||||||
|
while ((m = re.exec(src))) {
|
||||||
|
const argOpen = m.index + m[0].length - 1;
|
||||||
|
let argClose: number;
|
||||||
|
try {
|
||||||
|
argClose = matchBracket(src, argOpen);
|
||||||
|
} catch {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// Between `)` and `{` only qualifiers may appear (noexcept, const, ->…).
|
||||||
|
const between = src.slice(argClose + 1, src.indexOf("{", argClose) + 1);
|
||||||
|
if (!/^[\s\w:&*<>,]*\{$/.test(between)) continue;
|
||||||
|
const braceOpen = src.indexOf("{", argClose);
|
||||||
|
if (braceOpen < 0) continue;
|
||||||
|
return src.slice(braceOpen + 1, matchBracket(src, braceOpen));
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Formal parameter names of `<name>(...)`, in order. */
|
||||||
|
function functionParams(src: string, name: string): string[] | null {
|
||||||
|
const re = new RegExp(`\\b${name}\\s*\\(`, "g");
|
||||||
|
let m: RegExpExecArray | null;
|
||||||
|
while ((m = re.exec(src))) {
|
||||||
|
const argOpen = m.index + m[0].length - 1;
|
||||||
|
let argClose: number;
|
||||||
|
try {
|
||||||
|
argClose = matchBracket(src, argOpen);
|
||||||
|
} catch {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const between = src.slice(argClose + 1, src.indexOf("{", argClose) + 1);
|
||||||
|
if (!/^[\s\w:&*<>,]*\{$/.test(between)) continue;
|
||||||
|
const args = src.slice(argOpen + 1, argClose).trim();
|
||||||
|
if (args === "") return [];
|
||||||
|
return args.split(",").map((a) => {
|
||||||
|
const t = a.trim().replace(/\[\s*\]$/, "");
|
||||||
|
const w = t.match(/([A-Za-z_]\w*)\s*$/);
|
||||||
|
return w ? w[1]! : t;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Split arguments of a call at top nesting level. */
|
||||||
|
function splitArgs(text: string): string[] {
|
||||||
|
const out: string[] = [];
|
||||||
|
let depth = 0;
|
||||||
|
let cur = "";
|
||||||
|
for (const c of text) {
|
||||||
|
if (c === "(" || c === "[" || c === "{" || c === "<") depth++;
|
||||||
|
else if (c === ")" || c === "]" || c === "}" || c === ">") depth--;
|
||||||
|
if (c === "," && depth === 0) {
|
||||||
|
out.push(cur);
|
||||||
|
cur = "";
|
||||||
|
} else cur += c;
|
||||||
|
}
|
||||||
|
if (cur.trim() !== "" || out.length > 0) out.push(cur);
|
||||||
|
return out.map((s) => s.trim());
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Integer expression evaluation (array indices, loop bounds, ternary guards)
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Evaluate a compile-time integer expression. Constants from the engine
|
||||||
|
* (`static constexpr std::size_t kX = …`) are substituted first. Anything the
|
||||||
|
* strict character whitelist rejects is a hard error — never a guess.
|
||||||
|
*/
|
||||||
|
function evalInt(expr: string, consts: Map<string, number>, where: string): number {
|
||||||
|
let e = expr;
|
||||||
|
for (let pass = 0; pass < 8; pass++) {
|
||||||
|
const before = e;
|
||||||
|
for (const [k, v] of consts) {
|
||||||
|
e = e.replace(new RegExp(`\\b${k}\\b`, "g"), `(${v})`);
|
||||||
|
}
|
||||||
|
if (e === before) break;
|
||||||
|
}
|
||||||
|
e = e.replace(/(\d)[uU]\b/g, "$1");
|
||||||
|
e = e.replace(/static_cast<[^>]*>/g, "");
|
||||||
|
if (!/^[\d\s+\-*/%()]+$/.test(e)) {
|
||||||
|
fail(where, `non-constant integer expression ${JSON.stringify(expr)}`);
|
||||||
|
}
|
||||||
|
// eslint-disable-next-line no-new-func
|
||||||
|
const v = Function(`"use strict"; return (${e});`)() as number;
|
||||||
|
if (!Number.isInteger(v)) fail(where, `non-integer index ${expr} -> ${v}`);
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Evaluate a boolean guard, or null when it is not compile-time constant. */
|
||||||
|
function evalBool(expr: string, consts: Map<string, number>): boolean | null {
|
||||||
|
let e = expr.trim();
|
||||||
|
while (e.startsWith("(") && matchBracket(e, 0) === e.length - 1) {
|
||||||
|
e = e.slice(1, -1).trim();
|
||||||
|
}
|
||||||
|
for (let pass = 0; pass < 8; pass++) {
|
||||||
|
const before = e;
|
||||||
|
for (const [k, v] of consts) e = e.replace(new RegExp(`\\b${k}\\b`, "g"), `(${v})`);
|
||||||
|
if (e === before) break;
|
||||||
|
}
|
||||||
|
e = e.replace(/(\d)[uU]\b/g, "$1");
|
||||||
|
if (!/^[\d\s+\-*/%()<>=!&|]+$/.test(e)) return null;
|
||||||
|
try {
|
||||||
|
// eslint-disable-next-line no-new-func
|
||||||
|
return Boolean(Function(`"use strict"; return (${e});`)());
|
||||||
|
} catch {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Body normalisation: inline helpers -> unroll loops -> flatten braces
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
interface EngineFile {
|
||||||
|
src: string;
|
||||||
|
path: string;
|
||||||
|
consts: Map<string, number>;
|
||||||
|
/** member name -> std::array element count, for range-for unrolling. */
|
||||||
|
arrayLens: Map<string, number>;
|
||||||
|
}
|
||||||
|
|
||||||
|
function loadEngine(path: string): EngineFile {
|
||||||
|
const src = stripComments(readFileSync(path, "utf8"));
|
||||||
|
const consts = new Map<string, number>();
|
||||||
|
// `static constexpr std::size_t kFoo = <expr>;` — resolved in declaration
|
||||||
|
// order so later constants may refer to earlier ones.
|
||||||
|
const cre = /static\s+constexpr\s+std::size_t\s+(\w+)\s*=\s*([^;]+);/g;
|
||||||
|
let m: RegExpExecArray | null;
|
||||||
|
while ((m = cre.exec(src))) {
|
||||||
|
try {
|
||||||
|
consts.set(m[1]!, evalInt(m[2]!, consts, path));
|
||||||
|
} catch {
|
||||||
|
/* not an integer constant we can use; ignore */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const arrayLens = new Map<string, number>();
|
||||||
|
const are = /std::array\s*<\s*[^,<>]+(?:<[^>]*>)?\s*,\s*([^>]+)>\s*(\w+)/g;
|
||||||
|
while ((m = are.exec(src))) {
|
||||||
|
try {
|
||||||
|
arrayLens.set(m[2]!, evalInt(m[1]!, consts, path));
|
||||||
|
} catch {
|
||||||
|
/* dynamic length; ignore */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return { src, path, consts, arrayLens };
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Replace `name(args);` statements whose `name` is a method defined in the
|
||||||
|
* same file with that method's body, substituting formals for actuals.
|
||||||
|
*/
|
||||||
|
const KEYWORD_CALLS = new Set(["if", "for", "while", "switch", "return", "sizeof", "static_cast"]);
|
||||||
|
|
||||||
|
/** Locate the next bare `name(args);` statement whose `name` is defined here. */
|
||||||
|
function findInlinableCall(
|
||||||
|
body: string,
|
||||||
|
eng: EngineFile,
|
||||||
|
from: number
|
||||||
|
): { start: number; end: number; name: string; args: string } | null {
|
||||||
|
const callRe = /(?:^|[;{}])\s*([a-z_]\w*)\s*\(/g;
|
||||||
|
callRe.lastIndex = from;
|
||||||
|
let m: RegExpExecArray | null;
|
||||||
|
while ((m = callRe.exec(body))) {
|
||||||
|
const name = m[1]!;
|
||||||
|
callRe.lastIndex = m.index + m[0].length - 1;
|
||||||
|
if (KEYWORD_CALLS.has(name)) continue;
|
||||||
|
const open = m.index + m[0].length - 1;
|
||||||
|
let close: number;
|
||||||
|
try {
|
||||||
|
close = matchBracket(body, open);
|
||||||
|
} catch {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const rest = body.slice(close + 1);
|
||||||
|
if (rest.trimStart()[0] !== ";") continue;
|
||||||
|
if (functionBody(eng.src, name) === null) continue;
|
||||||
|
const semi = body.indexOf(";", close);
|
||||||
|
return { start: m.index + (/[;{}]/.test(m[0][0]!) ? 1 : 0), end: semi + 1, name, args: body.slice(open + 1, close) };
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function inlineCalls(body: string, eng: EngineFile, seen: Set<string>, where: string): string {
|
||||||
|
let text = body;
|
||||||
|
for (let guard = 0; guard < 256; guard++) {
|
||||||
|
const hit = findInlinableCall(text, eng, 0);
|
||||||
|
if (!hit) return text;
|
||||||
|
if (seen.has(hit.name)) fail(where, `recursive inline of ${hit.name}()`);
|
||||||
|
const callee = functionBody(eng.src, hit.name)!;
|
||||||
|
const formals = functionParams(eng.src, hit.name) ?? [];
|
||||||
|
const actuals = splitArgs(hit.args);
|
||||||
|
let inner = inlineCalls(callee, eng, new Set([...seen, hit.name]), `${where}>${hit.name}`);
|
||||||
|
formals.forEach((f, i) => {
|
||||||
|
const a = actuals[i];
|
||||||
|
if (a === undefined || f === a) return;
|
||||||
|
inner = inner.replace(new RegExp(`\\b${f}\\b`, "g"), `(${a})`);
|
||||||
|
});
|
||||||
|
text = text.slice(0, hit.start) + ` { ${inner} } ` + text.slice(hit.end);
|
||||||
|
}
|
||||||
|
fail(where, "helper inlining did not converge");
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Unroll `for` loops with compile-time trip counts, brace-stripping bodies. */
|
||||||
|
function unrollLoops(body: string, eng: EngineFile, where: string): string {
|
||||||
|
let text = body;
|
||||||
|
for (let pass = 0; pass < 64; pass++) {
|
||||||
|
const idx = text.search(/\bfor\s*\(/);
|
||||||
|
if (idx < 0) return text;
|
||||||
|
const open = text.indexOf("(", idx);
|
||||||
|
const close = matchBracket(text, open);
|
||||||
|
const header = text.slice(open + 1, close);
|
||||||
|
|
||||||
|
// Body: either a braced block or a single statement.
|
||||||
|
let bodyStart = close + 1;
|
||||||
|
while (/\s/.test(text[bodyStart] ?? "")) bodyStart++;
|
||||||
|
let inner: string;
|
||||||
|
let bodyEnd: number;
|
||||||
|
if (text[bodyStart] === "{") {
|
||||||
|
const b = matchBracket(text, bodyStart);
|
||||||
|
inner = text.slice(bodyStart + 1, b);
|
||||||
|
bodyEnd = b + 1;
|
||||||
|
} else {
|
||||||
|
const semi = text.indexOf(";", bodyStart);
|
||||||
|
if (semi < 0) fail(where, "for-loop body has no terminator");
|
||||||
|
inner = text.slice(bodyStart, semi + 1);
|
||||||
|
bodyEnd = semi + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
let expansion = "";
|
||||||
|
const counted = header.match(
|
||||||
|
/^\s*(?:std::size_t|int|std::uint\d+_t|auto)\s+(\w+)\s*=\s*([^;]+);\s*\1\s*<\s*([^;]+);\s*\+\+\1\s*$/
|
||||||
|
);
|
||||||
|
const ranged = header.match(/^\s*(?:const\s+)?auto\s*[&*]?\s*\w+\s*:\s*(\w+)\s*$/);
|
||||||
|
if (counted) {
|
||||||
|
const v = counted[1]!;
|
||||||
|
const lo = evalInt(counted[2]!, eng.consts, where);
|
||||||
|
const hi = evalInt(counted[3]!, eng.consts, where);
|
||||||
|
for (let i = lo; i < hi; i++) {
|
||||||
|
expansion += ` ${inner.replace(new RegExp(`\\b${v}\\b`, "g"), `(${i})`)} `;
|
||||||
|
}
|
||||||
|
} else if (ranged) {
|
||||||
|
const n = eng.arrayLens.get(ranged[1]!);
|
||||||
|
if (n === undefined) fail(where, `range-for over ${ranged[1]} with unknown length`);
|
||||||
|
for (let i = 0; i < n; i++) expansion += ` ${inner} `;
|
||||||
|
} else {
|
||||||
|
fail(where, `unrecognised for-loop header ${JSON.stringify(header.trim())}`);
|
||||||
|
}
|
||||||
|
text = text.slice(0, idx) + expansion + text.slice(bodyEnd);
|
||||||
|
}
|
||||||
|
fail(where, "for-loop unrolling did not converge");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove `switch (voice_space_) { … }` — each voice space is analysed against
|
||||||
|
* its own dispatch target, so keeping the switch would merge all of them.
|
||||||
|
* Any OTHER switch is deliberately left in place: brace-flattening turns its
|
||||||
|
* arms into straight-line statements, and if two arms disagree about a param's
|
||||||
|
* curve that surfaces as a conflict rather than a silent pick.
|
||||||
|
*/
|
||||||
|
function dropVoiceSpaceSwitch(body: string, where: string): string {
|
||||||
|
let text = body;
|
||||||
|
for (;;) {
|
||||||
|
const m = text.match(/\bswitch\s*\(\s*voice_space_\s*\)/);
|
||||||
|
if (!m || m.index === undefined) return text;
|
||||||
|
const open = text.indexOf("(", m.index);
|
||||||
|
const close = matchBracket(text, open);
|
||||||
|
let braceOpen = close + 1;
|
||||||
|
while (/\s/.test(text[braceOpen] ?? "")) braceOpen++;
|
||||||
|
if (text[braceOpen] !== "{") fail(where, "switch (voice_space_) without a block");
|
||||||
|
text = text.slice(0, m.index) + " " + text.slice(matchBracket(text, braceOpen) + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extract `auto NAME = [&]() { const float X = params[i++]; return EXPR; };`
|
||||||
|
* lambdas (memlcelium's `sq()`), returning the curve each application yields.
|
||||||
|
* Any other lambda shape is a hard error.
|
||||||
|
*/
|
||||||
|
function extractCounterLambdas(body: string, where: string): { text: string; lambdas: Map<string, Curve> } {
|
||||||
|
const lambdas = new Map<string, Curve>();
|
||||||
|
let text = body;
|
||||||
|
for (;;) {
|
||||||
|
const m = text.match(/\bauto\s+(\w+)\s*=\s*\[[^\]]*\]\s*\(/);
|
||||||
|
if (!m || m.index === undefined) return { text, lambdas };
|
||||||
|
const name = m[1]!;
|
||||||
|
const parenOpen = text.indexOf("(", m.index + m[0].length - 1);
|
||||||
|
const parenClose = matchBracket(text, parenOpen);
|
||||||
|
let braceOpen = parenClose + 1;
|
||||||
|
while (/\s/.test(text[braceOpen] ?? "")) braceOpen++;
|
||||||
|
if (text[braceOpen] !== "{") fail(where, `lambda ${name} without a body`);
|
||||||
|
const braceClose = matchBracket(text, braceOpen);
|
||||||
|
const inner = text.slice(braceOpen + 1, braceClose).trim();
|
||||||
|
const shape = inner.match(
|
||||||
|
/^const\s+float\s+(\w+)\s*=\s*params\s*\[\s*i\+\+\s*\]\s*;\s*return\s+([^;]+);$/
|
||||||
|
);
|
||||||
|
if (!shape) {
|
||||||
|
fail(where, `lambda ${name} has an unrecognised body: ${JSON.stringify(inner)}`);
|
||||||
|
}
|
||||||
|
const v = shape[1]!;
|
||||||
|
const ret = shape[2]!.replace(/\s+/g, " ").trim();
|
||||||
|
let curve: Curve;
|
||||||
|
if (ret === `${v} * ${v}`) curve = "square";
|
||||||
|
else if (ret === `std::sqrt(${v})`) curve = "sqrt";
|
||||||
|
else if (ret === v) curve = "linear";
|
||||||
|
else fail(where, `lambda ${name} returns an unrecognised form: ${JSON.stringify(ret)}`);
|
||||||
|
lambdas.set(name, curve);
|
||||||
|
let end = braceClose + 1;
|
||||||
|
while (/[\s;]/.test(text[end] ?? "")) end++;
|
||||||
|
text = text.slice(0, m.index) + " " + text.slice(end);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Strip every remaining brace; loops are unrolled and switches dropped by now. */
|
||||||
|
function flattenBraces(text: string): string {
|
||||||
|
return text.replace(/[{}]/g, " ");
|
||||||
|
}
|
||||||
|
|
||||||
|
function splitStatements(text: string): string[] {
|
||||||
|
return text
|
||||||
|
.split(";")
|
||||||
|
.map((s) => s.replace(/\s+/g, " ").trim())
|
||||||
|
.filter((s) => s !== "");
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Ternary reduction + accessor classification
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/** Collapse `cond ? a : b` where `cond` is compile-time constant. */
|
||||||
|
function reduceTernaries(stmt: string, consts: Map<string, number>): string {
|
||||||
|
let text = stmt;
|
||||||
|
for (let pass = 0; pass < 32; pass++) {
|
||||||
|
// Innermost `?` first: the one with no further `?` before its `:`.
|
||||||
|
const q = text.lastIndexOf("?");
|
||||||
|
if (q < 0) return text;
|
||||||
|
// Condition: scan left to the nearest unbalanced `(`, or `=`/`,`/start.
|
||||||
|
let depth = 0;
|
||||||
|
let condStart = 0;
|
||||||
|
for (let i = q - 1; i >= 0; i--) {
|
||||||
|
const c = text[i]!;
|
||||||
|
if (c === ")" || c === "]") depth++;
|
||||||
|
else if (c === "(" || c === "[") {
|
||||||
|
if (depth === 0) {
|
||||||
|
condStart = i + 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
depth--;
|
||||||
|
} else if (depth === 0 && (c === "=" || c === ",")) {
|
||||||
|
condStart = i + 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Matching `:` at the same nesting depth.
|
||||||
|
depth = 0;
|
||||||
|
let colon = -1;
|
||||||
|
for (let i = q + 1; i < text.length; i++) {
|
||||||
|
const c = text[i]!;
|
||||||
|
if (c === "(" || c === "[") depth++;
|
||||||
|
else if (c === ")" || c === "]") {
|
||||||
|
if (depth === 0) break;
|
||||||
|
depth--;
|
||||||
|
} else if (c === ":" && depth === 0 && text[i + 1] !== ":" && text[i - 1] !== ":") {
|
||||||
|
colon = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (colon < 0) return text;
|
||||||
|
// End of the false branch: unbalanced `)`/`]`/`,` or end of statement.
|
||||||
|
depth = 0;
|
||||||
|
let end = text.length;
|
||||||
|
for (let i = colon + 1; i < text.length; i++) {
|
||||||
|
const c = text[i]!;
|
||||||
|
if (c === "(" || c === "[") depth++;
|
||||||
|
else if (c === ")" || c === "]") {
|
||||||
|
if (depth === 0) {
|
||||||
|
end = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
depth--;
|
||||||
|
} else if (c === "," && depth === 0) {
|
||||||
|
end = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const cond = text.slice(condStart, q);
|
||||||
|
const t = text.slice(q + 1, colon);
|
||||||
|
const f = text.slice(colon + 1, end);
|
||||||
|
const v = evalBool(cond, consts);
|
||||||
|
// When the guard is not constant, keep BOTH branches: an accessor that is
|
||||||
|
// squared in one and sqrt'd in the other then surfaces as a conflict.
|
||||||
|
const repl = v === null ? `( ${cond} ) * ( ${t} ) * ( ${f} )` : v ? `( ${t} )` : `( ${f} )`;
|
||||||
|
text = text.slice(0, condStart) + repl + text.slice(end);
|
||||||
|
}
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Operand immediately to the left of `at` (balanced group, or a bare term). */
|
||||||
|
function leftOperand(text: string, at: number): { start: number; text: string } | null {
|
||||||
|
let i = at - 1;
|
||||||
|
while (i >= 0 && /\s/.test(text[i]!)) i--;
|
||||||
|
if (i < 0) return null;
|
||||||
|
if (text[i] === ")" || text[i] === "]") {
|
||||||
|
// Walk back over the balanced group, then over any leading identifier
|
||||||
|
// (so `p[3]` and `std::sqrt(x)` come back whole).
|
||||||
|
let depth = 0;
|
||||||
|
let j = i;
|
||||||
|
const open = text[i] === ")" ? "(" : "[";
|
||||||
|
for (; j >= 0; j--) {
|
||||||
|
if (text[j] === text[i]) depth++;
|
||||||
|
else if (text[j] === open) {
|
||||||
|
depth--;
|
||||||
|
if (depth === 0) break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (j < 0) return null;
|
||||||
|
let k = j - 1;
|
||||||
|
while (k >= 0 && /[\w:]/.test(text[k]!)) k--;
|
||||||
|
return { start: k + 1, text: text.slice(k + 1, i + 1) };
|
||||||
|
}
|
||||||
|
let j = i;
|
||||||
|
while (j >= 0 && /[\w.:]/.test(text[j]!)) j--;
|
||||||
|
if (j === i) return null;
|
||||||
|
return { start: j + 1, text: text.slice(j + 1, i + 1) };
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Operand immediately to the right of `at`. */
|
||||||
|
function rightOperand(text: string, at: number): { end: number; text: string } | null {
|
||||||
|
let i = at + 1;
|
||||||
|
while (i < text.length && /\s/.test(text[i]!)) i++;
|
||||||
|
if (i >= text.length) return null;
|
||||||
|
let j = i;
|
||||||
|
while (j < text.length && /[\w:]/.test(text[j]!)) j++;
|
||||||
|
if (j < text.length && (text[j] === "(" || text[j] === "[")) {
|
||||||
|
const close = matchBracket(text, j);
|
||||||
|
return { end: close + 1, text: text.slice(i, close + 1) };
|
||||||
|
}
|
||||||
|
if (j === i) return null;
|
||||||
|
return { end: j, text: text.slice(i, j) };
|
||||||
|
}
|
||||||
|
|
||||||
|
/** True when `text` is exactly one param-slot read, modulo parens/whitespace. */
|
||||||
|
function isBareAccessor(text: string): boolean {
|
||||||
|
let t = text.trim();
|
||||||
|
while (t.startsWith("(") && matchBracket(t, 0) === t.length - 1) t = t.slice(1, -1).trim();
|
||||||
|
const m = t.match(new RegExp(`^(?:${ACCESSORS.join("|")})\\s*\\[`));
|
||||||
|
if (!m) return false;
|
||||||
|
return matchBracket(t, t.indexOf("[")) === t.length - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Every accessor index appearing in `text`. */
|
||||||
|
function accessorIndices(text: string, consts: Map<string, number>, where: string): number[] {
|
||||||
|
const out: number[] = [];
|
||||||
|
const re = new RegExp(`\\b(${ACCESSORS.join("|")})\\s*\\[`, "g");
|
||||||
|
let m: RegExpExecArray | null;
|
||||||
|
while ((m = re.exec(text))) {
|
||||||
|
const open = m.index + m[0].length - 1;
|
||||||
|
const close = matchBracket(text, open);
|
||||||
|
out.push(evalInt(text.slice(open + 1, close), consts, where));
|
||||||
|
re.lastIndex = close;
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Classify every accessor occurrence in one expression.
|
||||||
|
*
|
||||||
|
* `sqrt` is recognised as `std::sqrt(<expr containing exactly the accessors>)`;
|
||||||
|
* `square` as `X * X` for textually identical operands containing accessors.
|
||||||
|
* Recognised occurrences are blanked so they are not re-counted as linear.
|
||||||
|
*/
|
||||||
|
function classifyExpr(expr: string, consts: Map<string, number>, where: string): Map<number, Curve> {
|
||||||
|
const found = new Map<number, Curve>();
|
||||||
|
const note = (idx: number, c: Curve) => {
|
||||||
|
const prev = found.get(idx);
|
||||||
|
if (prev !== undefined && prev !== c) {
|
||||||
|
fail(where, `param ${idx} is both ${prev} and ${c} in one expression: ${expr}`);
|
||||||
|
}
|
||||||
|
found.set(idx, c);
|
||||||
|
};
|
||||||
|
let text = expr;
|
||||||
|
|
||||||
|
// 1. std::sqrt(...)
|
||||||
|
for (;;) {
|
||||||
|
const m = text.match(/\bstd::sqrt\s*\(/);
|
||||||
|
if (!m || m.index === undefined) break;
|
||||||
|
const open = text.indexOf("(", m.index);
|
||||||
|
const close = matchBracket(text, open);
|
||||||
|
const inner = text.slice(open + 1, close);
|
||||||
|
const idxs = accessorIndices(inner, consts, where);
|
||||||
|
if (idxs.length > 0) {
|
||||||
|
// A sqrt over a compound expression is not a per-param sqrt curve — the
|
||||||
|
// same reasoning as the self-product rule below. None exists today, so
|
||||||
|
// this is a hard error rather than a silent demotion; if one ever
|
||||||
|
// appears the author must decide what the declaration should say.
|
||||||
|
if (!isBareAccessor(inner)) fail(where, `std::sqrt over a compound expression: ${inner}`);
|
||||||
|
note(idxs[0]!, "sqrt");
|
||||||
|
text = text.slice(0, m.index) + " __X__ " + text.slice(close + 1);
|
||||||
|
} else {
|
||||||
|
text = text.slice(0, m.index) + " __X__ " + text.slice(close + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. X * X, where X is one bare param slot (possibly parenthesised because
|
||||||
|
// it arrived via an alias). A self-product over a COMPOUND expression —
|
||||||
|
// e.g. paf_synth Elderstar's `factor * factor` where
|
||||||
|
// `factor = 1.f + (p[17] + p[27] * 0.2f)` — is deliberately NOT a
|
||||||
|
// per-param square: no single slot is multiplied by itself, and the
|
||||||
|
// `Curve` enum has no way to say "this slot is one term inside a squared
|
||||||
|
// sum". Those slots fall through to `linear`, which is what the schemas
|
||||||
|
// declare. The rule is explicit, not a silent fallback.
|
||||||
|
for (let from = 0; ; ) {
|
||||||
|
let hit = false;
|
||||||
|
for (let i = from; i < text.length; i++) {
|
||||||
|
if (text[i] !== "*") continue;
|
||||||
|
const l = leftOperand(text, i);
|
||||||
|
const r = rightOperand(text, i);
|
||||||
|
if (!l || !r) continue;
|
||||||
|
if (l.text.replace(/\s+/g, "") !== r.text.replace(/\s+/g, "")) continue;
|
||||||
|
const idxs = accessorIndices(l.text, consts, where);
|
||||||
|
if (idxs.length === 0) continue;
|
||||||
|
if (idxs.length !== 1 || !isBareAccessor(l.text)) {
|
||||||
|
from = i + 1;
|
||||||
|
hit = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
note(idxs[0]!, "square");
|
||||||
|
text = text.slice(0, l.start) + " __X__ " + text.slice(r.end);
|
||||||
|
from = 0;
|
||||||
|
hit = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!hit) break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. anything left is linear
|
||||||
|
for (const idx of accessorIndices(text, consts, where)) note(idx, "linear");
|
||||||
|
return found;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Body analysis
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
interface Analysis {
|
||||||
|
/** assignment target -> curves contributed by the latest write to it. */
|
||||||
|
targets: Map<string, Map<number, Curve>>;
|
||||||
|
}
|
||||||
|
|
||||||
|
const ALIAS_DECL = /^(?:static\s+)?const\s+(?:float|std::size_t|int|auto)\s+(\w+)\s*=\s*(.*)$/;
|
||||||
|
const COUNTER_DECL = /^(?:std::size_t|int)\s+(\w+)\s*=\s*(\d+)u?$/;
|
||||||
|
|
||||||
|
function analyseBody(
|
||||||
|
rawBody: string,
|
||||||
|
eng: EngineFile,
|
||||||
|
where: string,
|
||||||
|
state: Analysis,
|
||||||
|
stmtSeq: { n: number }
|
||||||
|
): void {
|
||||||
|
let text = inlineCalls(rawBody, eng, new Set(), where);
|
||||||
|
text = dropVoiceSpaceSwitch(text, where);
|
||||||
|
text = unrollLoops(text, eng, where);
|
||||||
|
const { text: noLambda, lambdas } = extractCounterLambdas(text, where);
|
||||||
|
text = flattenBraces(noLambda);
|
||||||
|
|
||||||
|
const aliases = new Map<string, { rhs: string; used: boolean }>();
|
||||||
|
let counterName: string | null = null;
|
||||||
|
let counter = 0;
|
||||||
|
|
||||||
|
for (const rawStmt of splitStatements(text)) {
|
||||||
|
let stmt = rawStmt;
|
||||||
|
|
||||||
|
// Sequential dialect: `params[i++]` and counter lambdas consume the next
|
||||||
|
// slot, left to right, and are rewritten into the ordinary indexed form.
|
||||||
|
if (counterName !== null) {
|
||||||
|
const seqRe = new RegExp(
|
||||||
|
`params\\s*\\[\\s*${counterName}\\+\\+\\s*\\]|\\b(${[...lambdas.keys()].join("|") || "\\u0000"})\\s*\\(\\s*\\)`,
|
||||||
|
"g"
|
||||||
|
);
|
||||||
|
stmt = stmt.replace(seqRe, (whole, lam?: string) => {
|
||||||
|
const idx = counter++;
|
||||||
|
if (lam) {
|
||||||
|
const c = lambdas.get(lam)!;
|
||||||
|
if (c === "square") return `params[${idx}] * params[${idx}]`;
|
||||||
|
if (c === "sqrt") return `std::sqrt(params[${idx}])`;
|
||||||
|
return `params[${idx}]`;
|
||||||
|
}
|
||||||
|
return `params[${idx}]`;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (/\+\+\s*\]/.test(stmt)) {
|
||||||
|
fail(where, `post-increment index with no active counter: ${stmt}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const counterM = stmt.match(COUNTER_DECL);
|
||||||
|
if (counterM && !ACCESSOR_RE.test(stmt)) {
|
||||||
|
counterName = counterM[1]!;
|
||||||
|
counter = Number(counterM[2]!);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Substitute live aliases (longest name first so `p1v` beats `p`).
|
||||||
|
for (const [name, a] of [...aliases].sort((x, y) => y[0].length - x[0].length)) {
|
||||||
|
const re = new RegExp(`\\b${name}\\b`, "g");
|
||||||
|
if (re.test(stmt)) {
|
||||||
|
// Not a use if this statement redeclares it.
|
||||||
|
const decl = stmt.match(ALIAS_DECL);
|
||||||
|
if (decl && decl[1] === name && !new RegExp(`\\b${name}\\b`).test(decl[2]!)) continue;
|
||||||
|
stmt = stmt.replace(re, `(${a.rhs})`);
|
||||||
|
a.used = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const aliasM = stmt.match(ALIAS_DECL);
|
||||||
|
if (aliasM) {
|
||||||
|
const name = aliasM[1]!;
|
||||||
|
const prev = aliases.get(name);
|
||||||
|
if (prev && !prev.used && ACCESSOR_RE.test(prev.rhs)) {
|
||||||
|
fail(where, `alias ${name} carrying a param was shadowed before use`);
|
||||||
|
}
|
||||||
|
aliases.set(name, { rhs: aliasM[2]!, used: false });
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ACCESSOR_RE.test(stmt)) continue;
|
||||||
|
|
||||||
|
const reduced = reduceTernaries(stmt, eng.consts);
|
||||||
|
const eq = topLevelAssign(reduced);
|
||||||
|
if (eq === null) {
|
||||||
|
// A call statement or return: unique key, never overwritten.
|
||||||
|
state.targets.set(`${where}#${stmtSeq.n++}`, classifyExpr(reduced, eng.consts, where));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const lhs = reduced.slice(0, eq).trim();
|
||||||
|
const rhs = reduced.slice(eq + 1);
|
||||||
|
// Pure copy between two aliases of the NN vector carries no curve.
|
||||||
|
if (isPureCopy(lhs, rhs, eng.consts, where)) continue;
|
||||||
|
if (ACCESSOR_RE.test(lhs)) {
|
||||||
|
fail(where, `assignment INTO the param vector with arithmetic: ${reduced}`);
|
||||||
|
}
|
||||||
|
state.targets.set(lhs.replace(/^(?:const\s+)?(?:float|auto)\s+/, ""), classifyExpr(rhs, eng.consts, where));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const [name, a] of aliases) {
|
||||||
|
if (!a.used && ACCESSOR_RE.test(a.rhs)) {
|
||||||
|
fail(where, `alias ${name} carrying a param was never used`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Index of a top-level `=` that is an assignment (not ==, +=, <=, …). */
|
||||||
|
function topLevelAssign(stmt: string): number | null {
|
||||||
|
let depth = 0;
|
||||||
|
for (let i = 0; i < stmt.length; i++) {
|
||||||
|
const c = stmt[i]!;
|
||||||
|
if (c === "(" || c === "[") depth++;
|
||||||
|
else if (c === ")" || c === "]") depth--;
|
||||||
|
else if (c === "=" && depth === 0) {
|
||||||
|
if (stmt[i + 1] === "=") return null;
|
||||||
|
if ("=!<>+-*/&|%".includes(stmt[i - 1] ?? "")) return null;
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function isPureCopy(lhs: string, rhs: string, consts: Map<string, number>, where: string): boolean {
|
||||||
|
const l = lhs.trim();
|
||||||
|
const r = rhs.trim();
|
||||||
|
if (!ACCESSOR_RE.test(l) || !ACCESSOR_RE.test(r)) return false;
|
||||||
|
const li = accessorIndices(l, consts, where);
|
||||||
|
const ri = accessorIndices(r, consts, where);
|
||||||
|
if (li.length !== 1 || ri.length !== 1 || li[0] !== ri[0]) return false;
|
||||||
|
// RHS must be nothing but the accessor.
|
||||||
|
return new RegExp(`^(?:${ACCESSORS.join("|")})\\s*\\[[^\\]]*\\]$`).test(r);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Engine-level extraction
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
function parseVoiceSpaces(eng: EngineFile): { enumNames: string[]; displayNames: string[] } | null {
|
||||||
|
const em = eng.src.match(/enum\s+class\s+VoiceSpace\s*:[^{]*\{/);
|
||||||
|
if (!em || em.index === undefined) return null;
|
||||||
|
const open = eng.src.indexOf("{", em.index);
|
||||||
|
const inner = eng.src.slice(open + 1, matchBracket(eng.src, open));
|
||||||
|
const enumNames = inner
|
||||||
|
.split(",")
|
||||||
|
.map((s) => s.split("=")[0]!.trim())
|
||||||
|
.filter((s) => s !== "" && s !== "Count");
|
||||||
|
const nm = eng.src.match(/kVoiceSpaceNames\s*=\s*\{/);
|
||||||
|
if (!nm || nm.index === undefined) fail(eng.path, "VoiceSpace enum without kVoiceSpaceNames");
|
||||||
|
const nOpen = eng.src.indexOf("{", nm.index);
|
||||||
|
const nInner = eng.src.slice(nOpen + 1, matchBracket(eng.src, nOpen));
|
||||||
|
const displayNames = [...nInner.matchAll(/"((?:[^"\\]|\\.)*)"/g)].map((m) => m[1]!);
|
||||||
|
if (displayNames.length !== enumNames.length) {
|
||||||
|
fail(eng.path, `VoiceSpace enum has ${enumNames.length} entries but kVoiceSpaceNames has ${displayNames.length}`);
|
||||||
|
}
|
||||||
|
return { enumNames, displayNames };
|
||||||
|
}
|
||||||
|
|
||||||
|
/** enum name -> the `apply_*` function the dispatch switch routes it to. */
|
||||||
|
function parseDispatch(eng: EngineFile, enumNames: string[]): Map<string, string> {
|
||||||
|
const out = new Map<string, string>();
|
||||||
|
const re = /case\s+VoiceSpace::(\w+)\s*:\s*(?:\{\s*)?(\w+)\s*\(/g;
|
||||||
|
let m: RegExpExecArray | null;
|
||||||
|
while ((m = re.exec(eng.src))) {
|
||||||
|
if (m[1] === "Count") continue;
|
||||||
|
out.set(m[1]!, m[2]!);
|
||||||
|
}
|
||||||
|
for (const n of enumNames) {
|
||||||
|
if (!out.has(n)) fail(eng.path, `VoiceSpace::${n} has no dispatch case`);
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
function collectCurves(state: Analysis, nParams: number, where: string): Curve[] {
|
||||||
|
const merged = new Map<number, Curve>();
|
||||||
|
for (const contrib of state.targets.values()) {
|
||||||
|
for (const [idx, c] of contrib) {
|
||||||
|
if (idx < 0 || idx >= nParams) fail(where, `param index ${idx} out of range (0..${nParams - 1})`);
|
||||||
|
const prev = merged.get(idx);
|
||||||
|
if (prev !== undefined && prev !== c) {
|
||||||
|
fail(where, `param ${idx} is mapped both ${prev} and ${c} within one voice space`);
|
||||||
|
}
|
||||||
|
merged.set(idx, c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const row: Curve[] = new Array(nParams).fill("linear");
|
||||||
|
for (const [idx, c] of merged) row[idx] = c;
|
||||||
|
return row;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function auditEngine(path: string): EngineCurves {
|
||||||
|
const eng = loadEngine(path);
|
||||||
|
const idm = eng.src.match(/engine_id\(\)\s*noexcept\s*\{\s*return\s*"([^"]+)"/);
|
||||||
|
if (!idm) fail(path, "no engine_id()");
|
||||||
|
const engineId = idm[1]!;
|
||||||
|
const nParams = eng.consts.get("kNParams") ?? 0;
|
||||||
|
|
||||||
|
const vs = parseVoiceSpaces(eng);
|
||||||
|
const setParams = functionBody(eng.src, "set_params");
|
||||||
|
const process = functionBody(eng.src, "process");
|
||||||
|
|
||||||
|
if (nParams === 0) {
|
||||||
|
return { engineId, file: path, nParams: 0, voiceSpaceNames: null, curves: [[]] };
|
||||||
|
}
|
||||||
|
|
||||||
|
if (vs === null) {
|
||||||
|
const state: Analysis = { targets: new Map() };
|
||||||
|
const seq = { n: 0 };
|
||||||
|
if (setParams) analyseBody(setParams, eng, `${engineId}:set_params`, state, seq);
|
||||||
|
if (process) analyseBody(process, eng, `${engineId}:process`, state, seq);
|
||||||
|
return {
|
||||||
|
engineId,
|
||||||
|
file: path,
|
||||||
|
nParams,
|
||||||
|
voiceSpaceNames: null,
|
||||||
|
curves: [collectCurves(state, nParams, engineId)],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const dispatch = parseDispatch(eng, vs.enumNames);
|
||||||
|
const curves: Curve[][] = [];
|
||||||
|
for (const name of vs.enumNames) {
|
||||||
|
const fn = dispatch.get(name)!;
|
||||||
|
const body = functionBody(eng.src, fn);
|
||||||
|
if (body === null) fail(path, `dispatch target ${fn}() has no body`);
|
||||||
|
const state: Analysis = { targets: new Map() };
|
||||||
|
const seq = { n: 0 };
|
||||||
|
const where = `${engineId}:${name}`;
|
||||||
|
if (setParams) analyseBody(setParams, eng, `${where}/set_params`, state, seq);
|
||||||
|
analyseBody(body, eng, where, state, seq);
|
||||||
|
curves.push(collectCurves(state, nParams, where));
|
||||||
|
}
|
||||||
|
return { engineId, file: path, nParams, voiceSpaceNames: vs.displayNames, curves };
|
||||||
|
}
|
||||||
|
|
||||||
|
export function auditAllEngines(enginesDir: string): Map<string, EngineCurves> {
|
||||||
|
const out = new Map<string, EngineCurves>();
|
||||||
|
for (const f of readdirSync(enginesDir).filter((f) => f.endsWith(".hpp")).sort()) {
|
||||||
|
const res = auditEngine(join(enginesDir, f));
|
||||||
|
if (out.has(res.engineId)) fail(enginesDir, `duplicate engine_id ${res.engineId}`);
|
||||||
|
out.set(res.engineId, res);
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
314
codegen/generate-midi-devices.ts
Normal file
314
codegen/generate-midi-devices.ts
Normal file
|
|
@ -0,0 +1,314 @@
|
||||||
|
#!/usr/bin/env bun
|
||||||
|
/**
|
||||||
|
* MEMLNaut MIDI device-template codegen.
|
||||||
|
*
|
||||||
|
* Reads: schemas/midi_device.schema.json (Draft 2020-12 meta-schema)
|
||||||
|
* schemas/midi_devices/*.json (one file per external MIDI device)
|
||||||
|
*
|
||||||
|
* Writes: nisps/midi/generated/midi_devices.hpp (no-heap constexpr, firmware + WASM)
|
||||||
|
* manifold/src/midi-devices/generated/types.ts (shared TS types)
|
||||||
|
* manifold/src/midi-devices/generated/devices.ts (device catalogue)
|
||||||
|
* manifold/src/midi-devices/generated/index.ts (re-exports)
|
||||||
|
*
|
||||||
|
* One source of truth -> both surfaces. The performer picks a device, sees its params
|
||||||
|
* by name, and selects which the ML drives over MIDI CC. Idempotent: regenerating the
|
||||||
|
* same schemas yields byte-identical output. Exits non-zero on validation failure.
|
||||||
|
*
|
||||||
|
* Deliberately a separate DRIVER from codegen/generate.ts (the mode-schema
|
||||||
|
* pipeline): different schema dir, different meta-schema, different output
|
||||||
|
* dirs, and generate.ts's golden test must not depend on MIDI-device schema
|
||||||
|
* state. That does not require duplicate helpers, though — the small
|
||||||
|
* string/fs helpers both drivers need live once in ./lib.ts (ST12).
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { writeFileSync, readdirSync, existsSync } from "node:fs";
|
||||||
|
import { join, dirname, resolve } from "node:path";
|
||||||
|
import { fileURLToPath } from "node:url";
|
||||||
|
import Ajv2020, { type AnySchemaObject } from "ajv/dist/2020.js";
|
||||||
|
import { ensureDir, readJSON, toPascalCase, cppStringLit, tsStringLit } from "./lib.ts";
|
||||||
|
|
||||||
|
// ----- Types ----------------------------------------------------------------
|
||||||
|
|
||||||
|
interface DeviceParam {
|
||||||
|
id: string;
|
||||||
|
cc: number;
|
||||||
|
label: string;
|
||||||
|
min: number;
|
||||||
|
max: number;
|
||||||
|
default: number;
|
||||||
|
group: string;
|
||||||
|
notes?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface DeviceSchema {
|
||||||
|
$schema?: string;
|
||||||
|
_note?: string;
|
||||||
|
device_id: string;
|
||||||
|
name: string;
|
||||||
|
manufacturer: string;
|
||||||
|
year?: number;
|
||||||
|
midi: {
|
||||||
|
default_channel: number;
|
||||||
|
value_range: [number, number];
|
||||||
|
notes?: string;
|
||||||
|
};
|
||||||
|
params: DeviceParam[];
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----- Paths ----------------------------------------------------------------
|
||||||
|
|
||||||
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||||
|
const REPO_ROOT = resolve(__dirname, "..");
|
||||||
|
const SCHEMAS_DIR = join(REPO_ROOT, "schemas");
|
||||||
|
const DEVICES_DIR = join(SCHEMAS_DIR, "midi_devices");
|
||||||
|
const META_SCHEMA_PATH = join(SCHEMAS_DIR, "midi_device.schema.json");
|
||||||
|
const CPP_OUT_DIR = join(REPO_ROOT, "nisps", "midi", "generated");
|
||||||
|
const TS_OUT_DIR = join(REPO_ROOT, "manifold", "src", "midi-devices", "generated");
|
||||||
|
|
||||||
|
// ----- Helpers --------------------------------------------------------------
|
||||||
|
// ensureDir/readJSON/toPascalCase/cppStringLit/tsStringLit now live in
|
||||||
|
// ./lib.ts (ST12, shared with generate.ts).
|
||||||
|
|
||||||
|
const BANNER = "// AUTOGENERATED — do not edit. Source: schemas/midi_devices/*.json. " +
|
||||||
|
"Run `bun run codegen/generate-midi-devices.ts` to regenerate.";
|
||||||
|
|
||||||
|
// ----- C++ emission ---------------------------------------------------------
|
||||||
|
|
||||||
|
function emitCppHeader(devices: DeviceSchema[]): string {
|
||||||
|
const L: string[] = [];
|
||||||
|
L.push(BANNER);
|
||||||
|
L.push("//");
|
||||||
|
L.push("// No-heap, constexpr MIDI device templates for the RP2350 firmware (and WASM).");
|
||||||
|
L.push("// Names are std::string_view into flash; CC/value fields are uint8_t.");
|
||||||
|
L.push("#ifndef NISPS_MIDI_GENERATED_MIDI_DEVICES_HPP");
|
||||||
|
L.push("#define NISPS_MIDI_GENERATED_MIDI_DEVICES_HPP");
|
||||||
|
L.push("");
|
||||||
|
L.push("#include <array>");
|
||||||
|
L.push("#include <cstdint>");
|
||||||
|
L.push("#include <span>");
|
||||||
|
L.push("#include <string_view>");
|
||||||
|
L.push("");
|
||||||
|
L.push("namespace nisps::midi::generated {");
|
||||||
|
L.push("");
|
||||||
|
L.push("struct MidiParam {");
|
||||||
|
L.push(" std::string_view id;");
|
||||||
|
L.push(" std::string_view label;");
|
||||||
|
L.push(" std::uint8_t cc;");
|
||||||
|
L.push(" std::uint8_t min;");
|
||||||
|
L.push(" std::uint8_t max;");
|
||||||
|
L.push(" std::uint8_t default_value;");
|
||||||
|
L.push(" std::string_view group;");
|
||||||
|
L.push("};");
|
||||||
|
L.push("");
|
||||||
|
L.push("struct MidiDevice {");
|
||||||
|
L.push(" std::string_view device_id;");
|
||||||
|
L.push(" std::string_view name;");
|
||||||
|
L.push(" std::string_view manufacturer;");
|
||||||
|
L.push(" std::uint8_t default_channel; // 1-16");
|
||||||
|
L.push(" std::uint8_t value_min;");
|
||||||
|
L.push(" std::uint8_t value_max;");
|
||||||
|
L.push(" std::span<const MidiParam> params;");
|
||||||
|
L.push("};");
|
||||||
|
L.push("");
|
||||||
|
|
||||||
|
for (const d of devices) {
|
||||||
|
const pn = `k${toPascalCase(d.device_id)}Params`;
|
||||||
|
L.push(`inline constexpr std::array<MidiParam, ${d.params.length}> ${pn} = {{`);
|
||||||
|
for (const p of d.params) {
|
||||||
|
L.push(` MidiParam{${cppStringLit(p.id)}, ${cppStringLit(p.label)}, ${p.cc}, ${p.min}, ${p.max}, ${p.default}, ${cppStringLit(p.group)}},`);
|
||||||
|
}
|
||||||
|
L.push("}};");
|
||||||
|
L.push("");
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const d of devices) {
|
||||||
|
const cn = `k${toPascalCase(d.device_id)}`;
|
||||||
|
const pn = `${cn}Params`;
|
||||||
|
L.push(`inline constexpr MidiDevice ${cn} = {`);
|
||||||
|
L.push(` ${cppStringLit(d.device_id)},`);
|
||||||
|
L.push(` ${cppStringLit(d.name)},`);
|
||||||
|
L.push(` ${cppStringLit(d.manufacturer)},`);
|
||||||
|
L.push(` ${d.midi.default_channel},`);
|
||||||
|
L.push(` ${d.midi.value_range[0]},`);
|
||||||
|
L.push(` ${d.midi.value_range[1]},`);
|
||||||
|
L.push(` std::span<const MidiParam>{${pn}},`);
|
||||||
|
L.push("};");
|
||||||
|
L.push("");
|
||||||
|
}
|
||||||
|
|
||||||
|
L.push(`inline constexpr std::size_t kMidiDeviceCount = ${devices.length}u;`);
|
||||||
|
L.push(`inline constexpr std::array<MidiDevice, kMidiDeviceCount> kMidiDevices = {{`);
|
||||||
|
for (const d of devices) {
|
||||||
|
L.push(` k${toPascalCase(d.device_id)},`);
|
||||||
|
}
|
||||||
|
L.push("}};");
|
||||||
|
L.push("");
|
||||||
|
L.push("} // namespace nisps::midi::generated");
|
||||||
|
L.push("");
|
||||||
|
L.push("#endif // NISPS_MIDI_GENERATED_MIDI_DEVICES_HPP");
|
||||||
|
L.push("");
|
||||||
|
return L.join("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----- TS emission ----------------------------------------------------------
|
||||||
|
|
||||||
|
function emitTsTypes(): string {
|
||||||
|
return [
|
||||||
|
BANNER,
|
||||||
|
"// Shared TypeScript types for generated MIDI device templates.",
|
||||||
|
"",
|
||||||
|
"export interface MidiDeviceParam {",
|
||||||
|
" readonly id: string;",
|
||||||
|
" readonly cc: number;",
|
||||||
|
" readonly label: string;",
|
||||||
|
" readonly min: number;",
|
||||||
|
" readonly max: number;",
|
||||||
|
" readonly default: number;",
|
||||||
|
" readonly group: string;",
|
||||||
|
"}",
|
||||||
|
"",
|
||||||
|
"export interface MidiDeviceTemplate {",
|
||||||
|
" readonly device_id: string;",
|
||||||
|
" readonly name: string;",
|
||||||
|
" readonly manufacturer: string;",
|
||||||
|
" readonly year?: number;",
|
||||||
|
" readonly default_channel: number;",
|
||||||
|
" readonly value_min: number;",
|
||||||
|
" readonly value_max: number;",
|
||||||
|
" readonly params: readonly MidiDeviceParam[];",
|
||||||
|
"}",
|
||||||
|
"",
|
||||||
|
].join("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
function emitTsDevices(devices: DeviceSchema[]): string {
|
||||||
|
const L: string[] = [];
|
||||||
|
L.push(BANNER);
|
||||||
|
L.push("import type { MidiDeviceTemplate } from './types';");
|
||||||
|
L.push("");
|
||||||
|
for (const d of devices) {
|
||||||
|
const cn = `${toPascalCase(d.device_id)}Device`;
|
||||||
|
L.push(`export const ${cn}: MidiDeviceTemplate = {`);
|
||||||
|
L.push(` device_id: ${tsStringLit(d.device_id)},`);
|
||||||
|
L.push(` name: ${tsStringLit(d.name)},`);
|
||||||
|
L.push(` manufacturer: ${tsStringLit(d.manufacturer)},`);
|
||||||
|
if (d.year) L.push(` year: ${d.year},`);
|
||||||
|
L.push(` default_channel: ${d.midi.default_channel},`);
|
||||||
|
L.push(` value_min: ${d.midi.value_range[0]},`);
|
||||||
|
L.push(` value_max: ${d.midi.value_range[1]},`);
|
||||||
|
L.push(" params: [");
|
||||||
|
for (const p of d.params) {
|
||||||
|
L.push(` { id: ${tsStringLit(p.id)}, cc: ${p.cc}, label: ${tsStringLit(p.label)}, min: ${p.min}, max: ${p.max}, default: ${p.default}, group: ${tsStringLit(p.group)} },`);
|
||||||
|
}
|
||||||
|
L.push(" ],");
|
||||||
|
L.push("};");
|
||||||
|
L.push("");
|
||||||
|
}
|
||||||
|
L.push("export const MIDI_DEVICES: readonly MidiDeviceTemplate[] = [");
|
||||||
|
for (const d of devices) {
|
||||||
|
L.push(` ${toPascalCase(d.device_id)}Device,`);
|
||||||
|
}
|
||||||
|
L.push("];");
|
||||||
|
L.push("");
|
||||||
|
L.push("export const MIDI_DEVICES_BY_ID: Readonly<Record<string, MidiDeviceTemplate>> = {");
|
||||||
|
for (const d of devices) {
|
||||||
|
L.push(` ${tsStringLit(d.device_id)}: ${toPascalCase(d.device_id)}Device,`);
|
||||||
|
}
|
||||||
|
L.push("};");
|
||||||
|
L.push("");
|
||||||
|
return L.join("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
function emitTsIndex(): string {
|
||||||
|
return [BANNER, "", "export * from './types';", "export * from './devices';", ""].join("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----- Driver ---------------------------------------------------------------
|
||||||
|
|
||||||
|
function main(): number {
|
||||||
|
if (!existsSync(META_SCHEMA_PATH)) {
|
||||||
|
console.error(`error: meta-schema not found at ${META_SCHEMA_PATH}`);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
const metaSchema = readJSON<AnySchemaObject>(META_SCHEMA_PATH);
|
||||||
|
const ajv = new Ajv2020({ strict: false, allErrors: true, allowUnionTypes: true });
|
||||||
|
const validate = ajv.compile<DeviceSchema>(metaSchema);
|
||||||
|
|
||||||
|
if (!existsSync(DEVICES_DIR)) {
|
||||||
|
console.error(`error: devices directory not found at ${DEVICES_DIR}`);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
const files = readdirSync(DEVICES_DIR).filter(f => f.endsWith(".json")).sort();
|
||||||
|
if (files.length === 0) {
|
||||||
|
console.error(`error: no device schemas in ${DEVICES_DIR}`);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
const devices: DeviceSchema[] = [];
|
||||||
|
let errors = 0;
|
||||||
|
for (const f of files) {
|
||||||
|
const path = join(DEVICES_DIR, f);
|
||||||
|
let raw: unknown;
|
||||||
|
try {
|
||||||
|
raw = readJSON<unknown>(path);
|
||||||
|
} catch (e) {
|
||||||
|
console.error(`error: ${f}: parse: ${(e as Error).message}`);
|
||||||
|
errors++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!validate(raw)) {
|
||||||
|
console.error(`error: ${f}: schema validation failed:`);
|
||||||
|
for (const err of validate.errors ?? []) {
|
||||||
|
console.error(` ${err.instancePath || "<root>"} ${err.message}`);
|
||||||
|
}
|
||||||
|
errors++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const d = raw as DeviceSchema;
|
||||||
|
// uniqueness checks
|
||||||
|
const ids = new Set<string>();
|
||||||
|
for (const p of d.params) {
|
||||||
|
if (ids.has(p.id)) {
|
||||||
|
console.error(`error: ${f}: duplicate param id '${p.id}'`);
|
||||||
|
errors++;
|
||||||
|
}
|
||||||
|
ids.add(p.id);
|
||||||
|
if (p.min > p.max) {
|
||||||
|
console.error(`error: ${f}: param '${p.id}' min>max`);
|
||||||
|
errors++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
devices.push(d);
|
||||||
|
}
|
||||||
|
if (errors > 0) {
|
||||||
|
console.error(`\n${errors} error(s); aborting codegen.`);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
devices.sort((a, b) => a.device_id.localeCompare(b.device_id));
|
||||||
|
|
||||||
|
ensureDir(CPP_OUT_DIR);
|
||||||
|
writeFileSync(join(CPP_OUT_DIR, "midi_devices.hpp"), emitCppHeader(devices));
|
||||||
|
|
||||||
|
ensureDir(TS_OUT_DIR);
|
||||||
|
writeFileSync(join(TS_OUT_DIR, "types.ts"), emitTsTypes());
|
||||||
|
writeFileSync(join(TS_OUT_DIR, "devices.ts"), emitTsDevices(devices));
|
||||||
|
writeFileSync(join(TS_OUT_DIR, "index.ts"), emitTsIndex());
|
||||||
|
|
||||||
|
console.log(`OK ${devices.length} MIDI device template(s) processed.`);
|
||||||
|
console.log(` C++ -> ${join(CPP_OUT_DIR, "midi_devices.hpp")}`);
|
||||||
|
console.log(` TS -> ${TS_OUT_DIR}`);
|
||||||
|
for (const d of devices) {
|
||||||
|
console.log(` - ${d.device_id}: ${d.params.length} params, default ch ${d.midi.default_channel}`);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
const isMain = (() => {
|
||||||
|
if (typeof process === "undefined") return false;
|
||||||
|
const argv1 = process.argv[1];
|
||||||
|
if (!argv1) return false;
|
||||||
|
return resolve(argv1) === fileURLToPath(import.meta.url);
|
||||||
|
})();
|
||||||
|
if (isMain) process.exit(main());
|
||||||
|
|
||||||
|
export { main };
|
||||||
929
codegen/generate.ts
Normal file
929
codegen/generate.ts
Normal file
|
|
@ -0,0 +1,929 @@
|
||||||
|
#!/usr/bin/env bun
|
||||||
|
/**
|
||||||
|
* MEMLNaut mode-schema codegen.
|
||||||
|
*
|
||||||
|
* Reads: schemas/schema.json (Draft 2020-12 meta-schema for modes)
|
||||||
|
* schemas/modes/*.json (one file per mode)
|
||||||
|
*
|
||||||
|
* Writes: nisps/modes/generated/<mode_id>_schema.hpp
|
||||||
|
* nisps/modes/generated/schema_types.hpp
|
||||||
|
* manifold/src/modes/generated/<mode_id>_schema.ts
|
||||||
|
* manifold/src/modes/generated/types.ts
|
||||||
|
* manifold/src/modes/generated/index.ts
|
||||||
|
*
|
||||||
|
* (The TS target moved playground → manifold at P5 of
|
||||||
|
* docs/specs/plans/one-core-engine-refactor.md.)
|
||||||
|
*
|
||||||
|
* Per-mode C++ headers also emit (simplification 2026-07, S1/S5/S6/S25):
|
||||||
|
* - `k<Mode>Schema` — the `nisps::ParamSchema` aggregate; each mode's
|
||||||
|
* `param_schema()` becomes a one-line `return generated::k<Mode>Schema;`
|
||||||
|
* instead of hand-assembling the same 12-field struct.
|
||||||
|
* - `<Mode>MLP` — the mode's `nisps::ml::MLP<...>` net-shape alias,
|
||||||
|
* built from the constants above instead of a second hand-typed copy of
|
||||||
|
* the dims in nisps/modes/*.hpp.
|
||||||
|
* The TS `index.ts` also emits `ALL_MODE_SCHEMAS` (every mode schema, in
|
||||||
|
* generation order) so manifold's mode catalogue no longer hand-imports each
|
||||||
|
* schema by name — see manifold/src/console/model.ts's `SCHEMA_MODES` overlay.
|
||||||
|
*
|
||||||
|
* Idempotent: regenerating the same schemas yields byte-identical output.
|
||||||
|
* Exits non-zero on validation failure.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { writeFileSync, readdirSync, existsSync } from "node:fs";
|
||||||
|
import { join, dirname, resolve, basename } from "node:path";
|
||||||
|
import { fileURLToPath } from "node:url";
|
||||||
|
import Ajv2020, { type AnySchemaObject } from "ajv/dist/2020.js";
|
||||||
|
import { ensureDir, readJSON, toPascalCase, cppStringLit, tsStringLit } from "./lib.ts";
|
||||||
|
|
||||||
|
// ----- Types ----------------------------------------------------------------
|
||||||
|
|
||||||
|
type Curve = "linear" | "exp" | "log" | "square" | "sqrt" | "sigmoid" | "cubic";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A voice space is either a bare name (it applies every param's default
|
||||||
|
* `curve`) or a name plus the slots where it DEVIATES from those defaults.
|
||||||
|
*
|
||||||
|
* The curve is a property of (param x voice space), not of the mode: the same
|
||||||
|
* NN slot is squared by one voice space and passed through linearly by
|
||||||
|
* another. The mode-wide `params[].curve` remains the default; this is the
|
||||||
|
* delta. Application stays where it has always been — inside the engine —
|
||||||
|
* so declaring it here changes no emitted numeric value.
|
||||||
|
*/
|
||||||
|
type VoiceSpaceDecl = string | { name: string; curve_overrides: Record<string, Curve>; _note?: string };
|
||||||
|
|
||||||
|
/** Flat (voice space, param) -> curve deviation, as emitted to both languages. */
|
||||||
|
interface CurveOverrideRow {
|
||||||
|
voiceSpace: number;
|
||||||
|
param: number;
|
||||||
|
curve: Curve;
|
||||||
|
}
|
||||||
|
|
||||||
|
function voiceSpaceName(v: VoiceSpaceDecl): string {
|
||||||
|
return typeof v === "string" ? v : v.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resolve a mode's declared deltas into the flat table both targets emit,
|
||||||
|
* sorted by (voice space, param) so output is order-independent.
|
||||||
|
* Throws on an override that names an unknown param or restates the default.
|
||||||
|
*/
|
||||||
|
function curveOverrideRows(schema: ModeSchema, source: string): CurveOverrideRow[] {
|
||||||
|
const paramIndex = new Map(schema.params.map((p, i) => [p.name, i] as const));
|
||||||
|
const rows: CurveOverrideRow[] = [];
|
||||||
|
schema.voice_spaces.forEach((vs, vi) => {
|
||||||
|
if (typeof vs === "string") return;
|
||||||
|
for (const [name, curve] of Object.entries(vs.curve_overrides)) {
|
||||||
|
const pi = paramIndex.get(name);
|
||||||
|
if (pi === undefined) {
|
||||||
|
throw new Error(`${source}: voice space ${vs.name} overrides unknown param ${JSON.stringify(name)}`);
|
||||||
|
}
|
||||||
|
if (schema.params[pi]!.curve === curve) {
|
||||||
|
throw new Error(
|
||||||
|
`${source}: voice space ${vs.name} restates param ${name}'s default curve ` +
|
||||||
|
`(${curve}) — declare only deviations`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
rows.push({ voiceSpace: vi, param: pi, curve });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
rows.sort((a, b) => a.voiceSpace - b.voiceSpace || a.param - b.param);
|
||||||
|
return rows;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ModeSchema {
|
||||||
|
$schema?: string;
|
||||||
|
_note?: string;
|
||||||
|
mode_id: string;
|
||||||
|
engine_id: string;
|
||||||
|
ml: {
|
||||||
|
input_channels: string[];
|
||||||
|
input_size: number;
|
||||||
|
hidden_layers: number[];
|
||||||
|
output_size: number;
|
||||||
|
default_spread: number;
|
||||||
|
};
|
||||||
|
params: Array<{
|
||||||
|
name: string;
|
||||||
|
label: string;
|
||||||
|
min: number;
|
||||||
|
max: number;
|
||||||
|
default: number;
|
||||||
|
curve: Curve;
|
||||||
|
group: string;
|
||||||
|
_note?: string;
|
||||||
|
}>;
|
||||||
|
voice_spaces: VoiceSpaceDecl[];
|
||||||
|
ui: {
|
||||||
|
primary_input: "xy_pad" | "joystick" | "sliders" | "audio_in" | "midi_in" | "none";
|
||||||
|
show_voice_space_selector: boolean;
|
||||||
|
show_synth_visualizer: boolean;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The ONE global training-hyperparameter default (schemas/ml_defaults.json,
|
||||||
|
* validated against schemas/ml_defaults.schema.json) — NOT per-mode, unlike
|
||||||
|
* everything else in ModeSchema. See S26 (docs/specs/recon/
|
||||||
|
* simplification-audit-2026-07.md): learning_rate/max_iterations/min_error
|
||||||
|
* used to be duplicated per-mode (identically, unread at runtime) plus
|
||||||
|
* hardcoded separately in nisps/ml/mlp.hpp, manifold/src/engine/wasm-iml.ts,
|
||||||
|
* and vcv/src/iml.hpp. Now declared once here and consumed by
|
||||||
|
* `nisps::ml::MLPCore`'s `TrainConfig` default member initialisers.
|
||||||
|
*/
|
||||||
|
interface MlTrainDefaults {
|
||||||
|
$schema?: string;
|
||||||
|
_note?: string;
|
||||||
|
learning_rate: number;
|
||||||
|
max_iterations: number;
|
||||||
|
min_error: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----- Path resolution ------------------------------------------------------
|
||||||
|
|
||||||
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||||
|
const REPO_ROOT = resolve(__dirname, "..");
|
||||||
|
const SCHEMAS_DIR = join(REPO_ROOT, "schemas");
|
||||||
|
const MODES_DIR = join(SCHEMAS_DIR, "modes");
|
||||||
|
const META_SCHEMA_PATH = join(SCHEMAS_DIR, "schema.json");
|
||||||
|
const ML_DEFAULTS_PATH = join(SCHEMAS_DIR, "ml_defaults.json");
|
||||||
|
const ML_DEFAULTS_SCHEMA_PATH = join(SCHEMAS_DIR, "ml_defaults.schema.json");
|
||||||
|
const CPP_OUT_DIR = join(REPO_ROOT, "nisps", "modes", "generated");
|
||||||
|
// The training defaults are an ML fact, not a mode fact, and `nisps/ml` sits
|
||||||
|
// BELOW `nisps/modes` in the layering MAP.md documents — emitting them into
|
||||||
|
// modes/generated/ would make mlp.hpp include upward. They get their own
|
||||||
|
// output dir on the C++ side. The TS side has no such layering to respect, so
|
||||||
|
// it keeps everything generated under one directory.
|
||||||
|
const CPP_ML_OUT_DIR = join(REPO_ROOT, "nisps", "ml", "generated");
|
||||||
|
const TS_OUT_DIR = join(REPO_ROOT, "manifold", "src", "modes", "generated");
|
||||||
|
|
||||||
|
// ----- Helpers --------------------------------------------------------------
|
||||||
|
// ensureDir/readJSON/toPascalCase/cppStringLit/tsStringLit now live in
|
||||||
|
// ./lib.ts (ST12, shared with generate-midi-devices.ts).
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert mode_id to UPPER_SNAKE for #define guards.
|
||||||
|
*/
|
||||||
|
function toUpperSnake(snake: string): string {
|
||||||
|
return snake.toUpperCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Format a float literal for C++ ensuring `.f` suffix and explicit decimal point.
|
||||||
|
* Required by the perf contract (architecture §3.3).
|
||||||
|
*/
|
||||||
|
function cppFloatLit(n: number): string {
|
||||||
|
if (!Number.isFinite(n)) {
|
||||||
|
throw new Error(`non-finite float: ${n}`);
|
||||||
|
}
|
||||||
|
// toFixed ensures a decimal point; trim trailing zeros but keep at least one digit
|
||||||
|
let s = n.toString();
|
||||||
|
if (!s.includes(".") && !s.includes("e") && !s.includes("E")) {
|
||||||
|
s += ".0";
|
||||||
|
}
|
||||||
|
return s + "f";
|
||||||
|
}
|
||||||
|
|
||||||
|
function cppCurveEnum(c: Curve): string {
|
||||||
|
// Curve enum lives in nisps/core/math.hpp (namespace `nisps`), lowercase per architecture spec.
|
||||||
|
// Re-exported as `nisps::modes::generated::Curve` via `using Curve = ::nisps::Curve;`.
|
||||||
|
switch (c) {
|
||||||
|
case "linear": return "Curve::linear";
|
||||||
|
case "exp": return "Curve::exp";
|
||||||
|
case "log": return "Curve::log";
|
||||||
|
case "square": return "Curve::square";
|
||||||
|
case "sqrt": return "Curve::sqrt";
|
||||||
|
case "sigmoid":return "Curve::sigmoid";
|
||||||
|
case "cubic": return "Curve::cubic";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const AUTOGEN_BANNER_CPP = (sourceFile: string): string =>
|
||||||
|
`// AUTOGENERATED — do not edit. Source: schemas/modes/${sourceFile}. ` +
|
||||||
|
`Run \`bun run codegen/generate.ts\` to regenerate.\n`;
|
||||||
|
|
||||||
|
const AUTOGEN_BANNER_TS = (sourceFile: string): string =>
|
||||||
|
`// AUTOGENERATED — do not edit. Source: schemas/modes/${sourceFile}. ` +
|
||||||
|
`Run \`bun run codegen/generate.ts\` to regenerate.\n`;
|
||||||
|
|
||||||
|
// ----- Shared types emission -----------------------------------------------
|
||||||
|
|
||||||
|
function emitSchemaTypesHpp(): string {
|
||||||
|
return [
|
||||||
|
"// AUTOGENERATED — do not edit. Run `bun run codegen/generate.ts` to regenerate.",
|
||||||
|
"// Shared C++ types for generated mode schemas.",
|
||||||
|
"//",
|
||||||
|
"// `Curve` is the authoritative enum from nisps/core/math.hpp; we re-export it",
|
||||||
|
"// into this namespace so generated headers can refer to plain `Curve::linear`.",
|
||||||
|
"//",
|
||||||
|
"// `ParamSchema` lives in the top-level `nisps` namespace, not",
|
||||||
|
"// `nisps::modes::generated`: nisps/core/concepts.hpp forward-declares",
|
||||||
|
"// `nisps::ParamSchema` and requires `T::param_schema()` to return",
|
||||||
|
"// `const nisps::ParamSchema&`, so the definition has to match that",
|
||||||
|
"// forward declaration exactly (S5, one-core simplification 2026-07).",
|
||||||
|
"#ifndef NISPS_GENERATED_SCHEMA_TYPES_HPP",
|
||||||
|
"#define NISPS_GENERATED_SCHEMA_TYPES_HPP",
|
||||||
|
"",
|
||||||
|
"#include <array>",
|
||||||
|
"#include <cstddef>",
|
||||||
|
"#include <span>",
|
||||||
|
"#include <string_view>",
|
||||||
|
"",
|
||||||
|
"#include \"../../core/math.hpp\"",
|
||||||
|
"",
|
||||||
|
"namespace nisps::modes::generated {",
|
||||||
|
"",
|
||||||
|
"using Curve = ::nisps::Curve;",
|
||||||
|
"",
|
||||||
|
"struct Param {",
|
||||||
|
" std::string_view name;",
|
||||||
|
" std::string_view label;",
|
||||||
|
" float min;",
|
||||||
|
" float max;",
|
||||||
|
" float default_value;",
|
||||||
|
" Curve curve;",
|
||||||
|
" std::string_view group;",
|
||||||
|
"};",
|
||||||
|
"",
|
||||||
|
"// One (voice space, param) slot where the engine applies a curve OTHER",
|
||||||
|
"// than that param's default. The curve is a property of the pair, not of",
|
||||||
|
"// the mode — apply_ssl4k() squares slot 11 where apply_neve66() does not.",
|
||||||
|
"// DESCRIPTIVE: the engine's voice space is still the only place a curve",
|
||||||
|
"// is applied, and it is applied exactly once.",
|
||||||
|
"struct CurveOverride {",
|
||||||
|
" std::size_t voice_space;",
|
||||||
|
" std::size_t param;",
|
||||||
|
" Curve curve;",
|
||||||
|
"};",
|
||||||
|
"",
|
||||||
|
"struct MLConfig {",
|
||||||
|
" std::size_t input_size;",
|
||||||
|
" std::size_t output_size;",
|
||||||
|
" float default_spread;",
|
||||||
|
"};",
|
||||||
|
"",
|
||||||
|
"enum class PrimaryInput : unsigned char {",
|
||||||
|
" XYPad = 0,",
|
||||||
|
" Joystick,",
|
||||||
|
" Sliders,",
|
||||||
|
" AudioIn,",
|
||||||
|
" MidiIn,",
|
||||||
|
" None,",
|
||||||
|
"};",
|
||||||
|
"",
|
||||||
|
"struct UIConfig {",
|
||||||
|
" PrimaryInput primary_input;",
|
||||||
|
" bool show_voice_space_selector;",
|
||||||
|
" bool show_synth_visualizer;",
|
||||||
|
"};",
|
||||||
|
"",
|
||||||
|
"} // namespace nisps::modes::generated",
|
||||||
|
"",
|
||||||
|
"namespace nisps {",
|
||||||
|
"",
|
||||||
|
"// View-style aggregate satisfying the `nisps::Mode` concept's",
|
||||||
|
"// `param_schema()` requirement. All members are spans/views into",
|
||||||
|
"// compile-time generated arrays; codegen emits one",
|
||||||
|
"// `inline constexpr ParamSchema k<Mode>Schema` per mode (see the",
|
||||||
|
"// per-mode <mode_id>_schema.hpp in this directory).",
|
||||||
|
"struct ParamSchema {",
|
||||||
|
" std::string_view mode_id;",
|
||||||
|
" std::string_view engine_id;",
|
||||||
|
" std::span<const std::string_view> input_channels;",
|
||||||
|
" std::size_t input_size;",
|
||||||
|
" std::span<const std::size_t> hidden_layers;",
|
||||||
|
" std::size_t output_size;",
|
||||||
|
" float default_spread;",
|
||||||
|
" std::span<const ::nisps::modes::generated::Param> params;",
|
||||||
|
" std::span<const std::string_view> voice_spaces;",
|
||||||
|
" std::span<const ::nisps::modes::generated::CurveOverride> curve_overrides;",
|
||||||
|
" ::nisps::modes::generated::UIConfig ui;",
|
||||||
|
"};",
|
||||||
|
"",
|
||||||
|
"// The curve voice space `vs` applies to output slot `param`: the param's",
|
||||||
|
"// default unless this mode declares a deviation for that voice space.",
|
||||||
|
"// Linear scan — the table has tens of rows and this is not a hot path.",
|
||||||
|
"constexpr ::nisps::Curve effective_curve(const ParamSchema& s, std::size_t vs,",
|
||||||
|
" std::size_t param) noexcept {",
|
||||||
|
" for (const auto& o : s.curve_overrides) {",
|
||||||
|
" if (o.voice_space == vs && o.param == param) return o.curve;",
|
||||||
|
" }",
|
||||||
|
" return s.params[param].curve;",
|
||||||
|
"}",
|
||||||
|
"",
|
||||||
|
"} // namespace nisps",
|
||||||
|
"",
|
||||||
|
"#endif // NISPS_GENERATED_SCHEMA_TYPES_HPP",
|
||||||
|
"",
|
||||||
|
].join("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
function emitSharedTsTypes(): string {
|
||||||
|
return [
|
||||||
|
"// AUTOGENERATED — do not edit. Run `bun run codegen/generate.ts` to regenerate.",
|
||||||
|
"// Shared TypeScript types for generated mode schemas.",
|
||||||
|
"",
|
||||||
|
"export type Curve =",
|
||||||
|
" | 'linear'",
|
||||||
|
" | 'exp'",
|
||||||
|
" | 'log'",
|
||||||
|
" | 'square'",
|
||||||
|
" | 'sqrt'",
|
||||||
|
" | 'sigmoid'",
|
||||||
|
" | 'cubic';",
|
||||||
|
"",
|
||||||
|
"export type PrimaryInput =",
|
||||||
|
" | 'xy_pad'",
|
||||||
|
" | 'joystick'",
|
||||||
|
" | 'sliders'",
|
||||||
|
" | 'audio_in'",
|
||||||
|
" | 'midi_in'",
|
||||||
|
" | 'none';",
|
||||||
|
"",
|
||||||
|
"export interface Param {",
|
||||||
|
" readonly name: string;",
|
||||||
|
" readonly label: string;",
|
||||||
|
" readonly min: number;",
|
||||||
|
" readonly max: number;",
|
||||||
|
" readonly default: number;",
|
||||||
|
" readonly curve: Curve;",
|
||||||
|
" readonly group: string;",
|
||||||
|
"}",
|
||||||
|
"",
|
||||||
|
"/**",
|
||||||
|
" * One (voice space, param) slot where the engine applies a curve OTHER than",
|
||||||
|
" * that param's default. The curve is a property of the pair, not of the mode",
|
||||||
|
" * — apply_ssl4k() squares slot 11 where apply_neve66() does not. DESCRIPTIVE:",
|
||||||
|
" * the engine's voice space is still the only place a curve is applied, and it",
|
||||||
|
" * is applied exactly once. Indices match `ModeSchema.voice_spaces` /",
|
||||||
|
" * `ModeSchema.params`.",
|
||||||
|
" */",
|
||||||
|
"export interface CurveOverride {",
|
||||||
|
" readonly voice_space: number;",
|
||||||
|
" readonly param: number;",
|
||||||
|
" readonly curve: Curve;",
|
||||||
|
"}",
|
||||||
|
"",
|
||||||
|
"export interface MLConfig {",
|
||||||
|
" readonly input_channels: readonly string[];",
|
||||||
|
" readonly input_size: number;",
|
||||||
|
" readonly hidden_layers: readonly number[];",
|
||||||
|
" readonly output_size: number;",
|
||||||
|
" readonly default_spread: number;",
|
||||||
|
"}",
|
||||||
|
"",
|
||||||
|
"export interface UIConfig {",
|
||||||
|
" readonly primary_input: PrimaryInput;",
|
||||||
|
" readonly show_voice_space_selector: boolean;",
|
||||||
|
" readonly show_synth_visualizer: boolean;",
|
||||||
|
"}",
|
||||||
|
"",
|
||||||
|
"export interface ModeSchema {",
|
||||||
|
" readonly mode_id: string;",
|
||||||
|
" readonly engine_id: string;",
|
||||||
|
" readonly ml: MLConfig;",
|
||||||
|
" readonly params: readonly Param[];",
|
||||||
|
" readonly voice_spaces: readonly string[];",
|
||||||
|
" readonly curve_overrides: readonly CurveOverride[];",
|
||||||
|
" readonly ui: UIConfig;",
|
||||||
|
"}",
|
||||||
|
"",
|
||||||
|
"/**",
|
||||||
|
" * The curve voice space `voiceSpace` applies to output slot `param`: the",
|
||||||
|
" * param's default unless this mode declares a deviation for that voice space.",
|
||||||
|
" */",
|
||||||
|
"export function effectiveCurve(",
|
||||||
|
" schema: ModeSchema,",
|
||||||
|
" voiceSpace: number,",
|
||||||
|
" param: number,",
|
||||||
|
"): Curve {",
|
||||||
|
" for (const o of schema.curve_overrides) {",
|
||||||
|
" if (o.voice_space === voiceSpace && o.param === param) return o.curve;",
|
||||||
|
" }",
|
||||||
|
" return schema.params[param]!.curve;",
|
||||||
|
"}",
|
||||||
|
"",
|
||||||
|
].join("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----- Per-mode C++ emission ------------------------------------------------
|
||||||
|
|
||||||
|
function emitModeHpp(schema: ModeSchema, sourceFile: string): string {
|
||||||
|
const guard = `NISPS_GENERATED_${toUpperSnake(schema.mode_id)}_SCHEMA_HPP`;
|
||||||
|
const constName = `k${toPascalCase(schema.mode_id)}`;
|
||||||
|
const lines: string[] = [];
|
||||||
|
|
||||||
|
lines.push(AUTOGEN_BANNER_CPP(sourceFile).trimEnd());
|
||||||
|
lines.push(`#ifndef ${guard}`);
|
||||||
|
lines.push(`#define ${guard}`);
|
||||||
|
lines.push("");
|
||||||
|
lines.push("#include \"schema_types.hpp\"");
|
||||||
|
lines.push("#include \"../../ml/mlp.hpp\"");
|
||||||
|
lines.push("");
|
||||||
|
lines.push("namespace nisps::modes::generated {");
|
||||||
|
lines.push("");
|
||||||
|
// mode_id and engine_id
|
||||||
|
lines.push(`inline constexpr std::string_view ${constName}ModeId = ${cppStringLit(schema.mode_id)};`);
|
||||||
|
lines.push(`inline constexpr std::string_view ${constName}EngineId = ${cppStringLit(schema.engine_id)};`);
|
||||||
|
lines.push("");
|
||||||
|
|
||||||
|
// input channels
|
||||||
|
lines.push(`inline constexpr std::array<std::string_view, ${schema.ml.input_channels.length}> ${constName}InputChannels = {{`);
|
||||||
|
for (const ch of schema.ml.input_channels) {
|
||||||
|
lines.push(` ${cppStringLit(ch)},`);
|
||||||
|
}
|
||||||
|
lines.push("}};");
|
||||||
|
lines.push("");
|
||||||
|
|
||||||
|
// hidden layers
|
||||||
|
lines.push(`inline constexpr std::array<std::size_t, ${schema.ml.hidden_layers.length}> ${constName}HiddenLayers = {{`);
|
||||||
|
for (const h of schema.ml.hidden_layers) {
|
||||||
|
lines.push(` ${h}u,`);
|
||||||
|
}
|
||||||
|
lines.push("}};");
|
||||||
|
lines.push("");
|
||||||
|
|
||||||
|
// ML config
|
||||||
|
lines.push(`inline constexpr MLConfig ${constName}MLConfig = {`);
|
||||||
|
lines.push(` ${schema.ml.input_size}u,`);
|
||||||
|
lines.push(` ${schema.ml.output_size}u,`);
|
||||||
|
lines.push(` ${cppFloatLit(schema.ml.default_spread)},`);
|
||||||
|
lines.push("};");
|
||||||
|
lines.push("");
|
||||||
|
|
||||||
|
// params
|
||||||
|
lines.push(`inline constexpr std::size_t ${constName}ParamCount = ${schema.params.length}u;`);
|
||||||
|
lines.push(`inline constexpr std::array<Param, ${constName}ParamCount> ${constName}Params = {{`);
|
||||||
|
for (const p of schema.params) {
|
||||||
|
lines.push(" Param{");
|
||||||
|
lines.push(` ${cppStringLit(p.name)},`);
|
||||||
|
lines.push(` ${cppStringLit(p.label)},`);
|
||||||
|
lines.push(` ${cppFloatLit(p.min)},`);
|
||||||
|
lines.push(` ${cppFloatLit(p.max)},`);
|
||||||
|
lines.push(` ${cppFloatLit(p.default)},`);
|
||||||
|
lines.push(` ${cppCurveEnum(p.curve)},`);
|
||||||
|
lines.push(` ${cppStringLit(p.group)},`);
|
||||||
|
lines.push(" },");
|
||||||
|
}
|
||||||
|
lines.push("}};");
|
||||||
|
lines.push("");
|
||||||
|
|
||||||
|
// voice spaces
|
||||||
|
lines.push(`inline constexpr std::size_t ${constName}VoiceSpaceCount = ${schema.voice_spaces.length}u;`);
|
||||||
|
if (schema.voice_spaces.length > 0) {
|
||||||
|
lines.push(`inline constexpr std::array<std::string_view, ${constName}VoiceSpaceCount> ${constName}VoiceSpaces = {{`);
|
||||||
|
for (const v of schema.voice_spaces) {
|
||||||
|
lines.push(` ${cppStringLit(voiceSpaceName(v))},`);
|
||||||
|
}
|
||||||
|
lines.push("}};");
|
||||||
|
} else {
|
||||||
|
// empty arrays of size 0 are technically allowed in C++; but std::array<T,0> is fine
|
||||||
|
lines.push(`inline constexpr std::array<std::string_view, 0> ${constName}VoiceSpaces = {};`);
|
||||||
|
}
|
||||||
|
lines.push("");
|
||||||
|
|
||||||
|
// Per-voice-space curve deviations (see CurveOverride in schema_types.hpp).
|
||||||
|
// Only the deltas from `params[].curve`; resolve with nisps::effective_curve.
|
||||||
|
const overrides = curveOverrideRows(schema, sourceFile);
|
||||||
|
if (overrides.length > 0) {
|
||||||
|
lines.push(
|
||||||
|
`inline constexpr std::array<CurveOverride, ${overrides.length}u> ${constName}CurveOverrides = {{`
|
||||||
|
);
|
||||||
|
for (const o of overrides) {
|
||||||
|
lines.push(
|
||||||
|
` CurveOverride{${o.voiceSpace}u, ${o.param}u, ${cppCurveEnum(o.curve)}},` +
|
||||||
|
` // ${voiceSpaceName(schema.voice_spaces[o.voiceSpace]!)}.${schema.params[o.param]!.name}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
lines.push("}};");
|
||||||
|
} else {
|
||||||
|
lines.push(`inline constexpr std::array<CurveOverride, 0> ${constName}CurveOverrides = {};`);
|
||||||
|
}
|
||||||
|
lines.push("");
|
||||||
|
|
||||||
|
// UI
|
||||||
|
let primary: string;
|
||||||
|
switch (schema.ui.primary_input) {
|
||||||
|
case "xy_pad": primary = "PrimaryInput::XYPad"; break;
|
||||||
|
case "joystick": primary = "PrimaryInput::Joystick"; break;
|
||||||
|
case "sliders": primary = "PrimaryInput::Sliders"; break;
|
||||||
|
case "audio_in": primary = "PrimaryInput::AudioIn"; break;
|
||||||
|
case "midi_in": primary = "PrimaryInput::MidiIn"; break;
|
||||||
|
case "none": primary = "PrimaryInput::None"; break;
|
||||||
|
}
|
||||||
|
lines.push(`inline constexpr UIConfig ${constName}UI = {`);
|
||||||
|
lines.push(` ${primary},`);
|
||||||
|
lines.push(` ${schema.ui.show_voice_space_selector ? "true" : "false"},`);
|
||||||
|
lines.push(` ${schema.ui.show_synth_visualizer ? "true" : "false"},`);
|
||||||
|
lines.push("};");
|
||||||
|
lines.push("");
|
||||||
|
|
||||||
|
// Net-shape alias (S6/S25): the mode's MLP<> template args, built from the
|
||||||
|
// constants above rather than hand-typed a second time in nisps/modes/*.hpp.
|
||||||
|
const modeMlpName = `${toPascalCase(schema.mode_id)}MLP`;
|
||||||
|
lines.push(
|
||||||
|
`using ${modeMlpName} = ::nisps::ml::MLP<` +
|
||||||
|
`${constName}MLConfig.input_size, ` +
|
||||||
|
`${constName}HiddenLayers[0], ${constName}HiddenLayers[1], ${constName}HiddenLayers[2], ` +
|
||||||
|
`${constName}MLConfig.output_size>;`
|
||||||
|
);
|
||||||
|
lines.push("");
|
||||||
|
|
||||||
|
// ParamSchema aggregate (S5): the one-line `param_schema()` body every mode
|
||||||
|
// used to hand-assemble as a private `kSchema` positional-init block.
|
||||||
|
lines.push(`inline constexpr ::nisps::ParamSchema ${constName}Schema = {`);
|
||||||
|
lines.push(` ${constName}ModeId,`);
|
||||||
|
lines.push(` ${constName}EngineId,`);
|
||||||
|
lines.push(` std::span<const std::string_view>(${constName}InputChannels),`);
|
||||||
|
lines.push(` ${constName}MLConfig.input_size,`);
|
||||||
|
lines.push(` std::span<const std::size_t>(${constName}HiddenLayers),`);
|
||||||
|
lines.push(` ${constName}MLConfig.output_size,`);
|
||||||
|
lines.push(` ${constName}MLConfig.default_spread,`);
|
||||||
|
lines.push(` std::span<const Param>(${constName}Params),`);
|
||||||
|
lines.push(` std::span<const std::string_view>(${constName}VoiceSpaces),`);
|
||||||
|
lines.push(` std::span<const CurveOverride>(${constName}CurveOverrides),`);
|
||||||
|
lines.push(` ${constName}UI,`);
|
||||||
|
lines.push("};");
|
||||||
|
lines.push("");
|
||||||
|
|
||||||
|
lines.push("} // namespace nisps::modes::generated");
|
||||||
|
lines.push("");
|
||||||
|
lines.push(`#endif // ${guard}`);
|
||||||
|
lines.push("");
|
||||||
|
|
||||||
|
return lines.join("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----- Per-mode TS emission -------------------------------------------------
|
||||||
|
|
||||||
|
function emitModeTs(schema: ModeSchema, sourceFile: string): string {
|
||||||
|
const constName = `${toPascalCase(schema.mode_id)}Schema`;
|
||||||
|
const paramTypeName = `${toPascalCase(schema.mode_id)}Params`;
|
||||||
|
const lines: string[] = [];
|
||||||
|
|
||||||
|
lines.push(AUTOGEN_BANNER_TS(sourceFile).trimEnd());
|
||||||
|
lines.push("import type { ModeSchema } from './types';");
|
||||||
|
lines.push("");
|
||||||
|
|
||||||
|
// Per-param object type (a record of param name -> number)
|
||||||
|
lines.push(`export interface ${paramTypeName} {`);
|
||||||
|
for (const p of schema.params) {
|
||||||
|
lines.push(` readonly ${p.name}: number;`);
|
||||||
|
}
|
||||||
|
lines.push("}");
|
||||||
|
lines.push("");
|
||||||
|
|
||||||
|
// Const schema
|
||||||
|
lines.push(`export const ${constName}: ModeSchema = {`);
|
||||||
|
lines.push(` mode_id: ${tsStringLit(schema.mode_id)},`);
|
||||||
|
lines.push(` engine_id: ${tsStringLit(schema.engine_id)},`);
|
||||||
|
lines.push(" ml: {");
|
||||||
|
lines.push(" input_channels: [");
|
||||||
|
for (const ch of schema.ml.input_channels) {
|
||||||
|
lines.push(` ${tsStringLit(ch)},`);
|
||||||
|
}
|
||||||
|
lines.push(" ],");
|
||||||
|
lines.push(` input_size: ${schema.ml.input_size},`);
|
||||||
|
lines.push(" hidden_layers: [");
|
||||||
|
for (const h of schema.ml.hidden_layers) {
|
||||||
|
lines.push(` ${h},`);
|
||||||
|
}
|
||||||
|
lines.push(" ],");
|
||||||
|
lines.push(` output_size: ${schema.ml.output_size},`);
|
||||||
|
lines.push(` default_spread: ${schema.ml.default_spread},`);
|
||||||
|
lines.push(" },");
|
||||||
|
lines.push(" params: [");
|
||||||
|
for (const p of schema.params) {
|
||||||
|
lines.push(" {");
|
||||||
|
lines.push(` name: ${tsStringLit(p.name)},`);
|
||||||
|
lines.push(` label: ${tsStringLit(p.label)},`);
|
||||||
|
lines.push(` min: ${p.min},`);
|
||||||
|
lines.push(` max: ${p.max},`);
|
||||||
|
lines.push(` default: ${p.default},`);
|
||||||
|
lines.push(` curve: ${tsStringLit(p.curve)},`);
|
||||||
|
lines.push(` group: ${tsStringLit(p.group)},`);
|
||||||
|
lines.push(" },");
|
||||||
|
}
|
||||||
|
lines.push(" ],");
|
||||||
|
if (schema.voice_spaces.length === 0) {
|
||||||
|
lines.push(" voice_spaces: [],");
|
||||||
|
} else {
|
||||||
|
lines.push(" voice_spaces: [");
|
||||||
|
for (const v of schema.voice_spaces) {
|
||||||
|
lines.push(` ${tsStringLit(voiceSpaceName(v))},`);
|
||||||
|
}
|
||||||
|
lines.push(" ],");
|
||||||
|
}
|
||||||
|
// Per-voice-space curve deviations; resolve with effectiveCurve() from
|
||||||
|
// ./types. Only the deltas from params[].curve are listed.
|
||||||
|
const overrides = curveOverrideRows(schema, sourceFile);
|
||||||
|
if (overrides.length === 0) {
|
||||||
|
lines.push(" curve_overrides: [],");
|
||||||
|
} else {
|
||||||
|
lines.push(" curve_overrides: [");
|
||||||
|
for (const o of overrides) {
|
||||||
|
lines.push(
|
||||||
|
` { voice_space: ${o.voiceSpace}, param: ${o.param}, curve: ${tsStringLit(o.curve)} },` +
|
||||||
|
` // ${voiceSpaceName(schema.voice_spaces[o.voiceSpace]!)}.${schema.params[o.param]!.name}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
lines.push(" ],");
|
||||||
|
}
|
||||||
|
lines.push(" ui: {");
|
||||||
|
lines.push(` primary_input: ${tsStringLit(schema.ui.primary_input)},`);
|
||||||
|
lines.push(` show_voice_space_selector: ${schema.ui.show_voice_space_selector},`);
|
||||||
|
lines.push(` show_synth_visualizer: ${schema.ui.show_synth_visualizer},`);
|
||||||
|
lines.push(" },");
|
||||||
|
lines.push("};");
|
||||||
|
lines.push("");
|
||||||
|
|
||||||
|
return lines.join("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
function emitTsIndex(modeIds: string[]): string {
|
||||||
|
const lines: string[] = [];
|
||||||
|
lines.push("// AUTOGENERATED — do not edit. Run `bun run codegen/generate.ts` to regenerate.");
|
||||||
|
lines.push("// Re-exports every generated mode schema.");
|
||||||
|
lines.push("");
|
||||||
|
lines.push("import type { ModeSchema } from './types';");
|
||||||
|
for (const id of modeIds) {
|
||||||
|
lines.push(`import { ${toPascalCase(id)}Schema } from './${id}_schema';`);
|
||||||
|
}
|
||||||
|
lines.push("");
|
||||||
|
lines.push("export * from './types';");
|
||||||
|
for (const id of modeIds) {
|
||||||
|
lines.push(`export * from './${id}_schema';`);
|
||||||
|
}
|
||||||
|
lines.push("");
|
||||||
|
// Mechanically-derived mode-identity registry (S1): every generated mode
|
||||||
|
// schema, in generation (mode_id-sorted) order. NOT display order — that
|
||||||
|
// ordering is hand-curated overlay truth (manifold/src/console/model.ts's
|
||||||
|
// `SCHEMA_MODES`).
|
||||||
|
lines.push(
|
||||||
|
"/** Every generated mode schema, mode_id-sorted. Mechanically-derived mode-identity truth. */"
|
||||||
|
);
|
||||||
|
lines.push("export const ALL_MODE_SCHEMAS: readonly ModeSchema[] = [");
|
||||||
|
for (const id of modeIds) {
|
||||||
|
lines.push(` ${toPascalCase(id)}Schema,`);
|
||||||
|
}
|
||||||
|
lines.push("];");
|
||||||
|
lines.push("");
|
||||||
|
return lines.join("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----- Global ML-defaults emission (S26) ------------------------------------
|
||||||
|
// The ONE learning_rate/max_iterations/min_error default (schemas/ml_defaults.
|
||||||
|
// json), NOT per-mode — emitted once, alongside schema_types.hpp/types.ts,
|
||||||
|
// rather than once per mode file like everything else in this module.
|
||||||
|
|
||||||
|
const AUTOGEN_BANNER_ML_DEFAULTS = (lang: "C++" | "TS"): string =>
|
||||||
|
`// AUTOGENERATED (${lang}) — do not edit. Source: schemas/ml_defaults.json. ` +
|
||||||
|
"Run `bun run codegen/generate.ts` to regenerate.";
|
||||||
|
|
||||||
|
function emitMlDefaultsHpp(d: MlTrainDefaults): string {
|
||||||
|
return [
|
||||||
|
AUTOGEN_BANNER_ML_DEFAULTS("C++"),
|
||||||
|
"// The ONE global training-hyperparameter default, shared by every mode on",
|
||||||
|
"// every platform (firmware/WASM/VCV) — see docs/specs/recon/",
|
||||||
|
"// simplification-audit-2026-07.md S26. Consumed by",
|
||||||
|
"// nisps::ml::MLPCore::TrainConfig's default member initialisers",
|
||||||
|
"// (nisps/ml/mlp.hpp); nisps_ml_set_train_config() and",
|
||||||
|
"// nisps::ml::MLPCore::set_train_config() make it runtime-overridable.",
|
||||||
|
"#ifndef NISPS_ML_GENERATED_ML_DEFAULTS_HPP",
|
||||||
|
"#define NISPS_ML_GENERATED_ML_DEFAULTS_HPP",
|
||||||
|
"",
|
||||||
|
"#include <cstddef>",
|
||||||
|
"",
|
||||||
|
"namespace nisps::ml::generated {",
|
||||||
|
"",
|
||||||
|
"struct MlTrainDefaults {",
|
||||||
|
" float learning_rate;",
|
||||||
|
" std::size_t max_iterations;",
|
||||||
|
" float min_error;",
|
||||||
|
"};",
|
||||||
|
"",
|
||||||
|
"inline constexpr MlTrainDefaults kMlTrainDefaults = {",
|
||||||
|
` ${cppFloatLit(d.learning_rate)},`,
|
||||||
|
` ${d.max_iterations}u,`,
|
||||||
|
` ${cppFloatLit(d.min_error)},`,
|
||||||
|
"};",
|
||||||
|
"",
|
||||||
|
"} // namespace nisps::ml::generated",
|
||||||
|
"",
|
||||||
|
"#endif // NISPS_ML_GENERATED_ML_DEFAULTS_HPP",
|
||||||
|
"",
|
||||||
|
].join("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
function emitMlDefaultsTs(d: MlTrainDefaults): string {
|
||||||
|
return [
|
||||||
|
AUTOGEN_BANNER_ML_DEFAULTS("TS"),
|
||||||
|
"// The ONE global training-hyperparameter default, shared by every mode on",
|
||||||
|
"// every platform — see docs/specs/recon/simplification-audit-2026-07.md S26.",
|
||||||
|
"// Consumed by WasmIML's train()/trainAsync() default parameters and",
|
||||||
|
"// EngineApi's learningRate/maxIterations options (manifold/src/engine/).",
|
||||||
|
"",
|
||||||
|
"export interface MlTrainDefaults {",
|
||||||
|
" readonly learningRate: number;",
|
||||||
|
" readonly maxIterations: number;",
|
||||||
|
" readonly minError: number;",
|
||||||
|
"}",
|
||||||
|
"",
|
||||||
|
"export const ML_TRAIN_DEFAULTS: MlTrainDefaults = {",
|
||||||
|
` learningRate: ${d.learning_rate},`,
|
||||||
|
` maxIterations: ${d.max_iterations},`,
|
||||||
|
` minError: ${d.min_error},`,
|
||||||
|
"};",
|
||||||
|
"",
|
||||||
|
].join("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----- Driver --------------------------------------------------------------
|
||||||
|
|
||||||
|
function main(): number {
|
||||||
|
// 1. Load and compile meta-schema
|
||||||
|
if (!existsSync(META_SCHEMA_PATH)) {
|
||||||
|
console.error(`error: meta-schema not found at ${META_SCHEMA_PATH}`);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
const metaSchema = readJSON<AnySchemaObject>(META_SCHEMA_PATH);
|
||||||
|
|
||||||
|
// We pass strict:false because the meta-schema uses `_note` fields that aren't
|
||||||
|
// in the JSON Schema vocab itself; the meta-schema explicitly allows them via
|
||||||
|
// `additionalProperties` rules.
|
||||||
|
const ajv = new Ajv2020({
|
||||||
|
strict: false,
|
||||||
|
allErrors: true,
|
||||||
|
allowUnionTypes: true,
|
||||||
|
});
|
||||||
|
const validate = ajv.compile<ModeSchema>(metaSchema);
|
||||||
|
|
||||||
|
// 1b. Load, compile, and validate the ONE global ML training default
|
||||||
|
// (schemas/ml_defaults.json against schemas/ml_defaults.schema.json — S26,
|
||||||
|
// NOT per-mode, so it lives outside the modeFiles loop below).
|
||||||
|
if (!existsSync(ML_DEFAULTS_SCHEMA_PATH)) {
|
||||||
|
console.error(`error: ml-defaults meta-schema not found at ${ML_DEFAULTS_SCHEMA_PATH}`);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (!existsSync(ML_DEFAULTS_PATH)) {
|
||||||
|
console.error(`error: ml-defaults data not found at ${ML_DEFAULTS_PATH}`);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
const mlDefaultsSchema = readJSON<AnySchemaObject>(ML_DEFAULTS_SCHEMA_PATH);
|
||||||
|
const validateMlDefaults = ajv.compile<MlTrainDefaults>(mlDefaultsSchema);
|
||||||
|
const mlDefaultsRaw = readJSON<unknown>(ML_DEFAULTS_PATH);
|
||||||
|
if (!validateMlDefaults(mlDefaultsRaw)) {
|
||||||
|
console.error(`error: ${ML_DEFAULTS_PATH}: schema validation failed:`);
|
||||||
|
for (const err of validateMlDefaults.errors ?? []) {
|
||||||
|
console.error(` ${err.instancePath || "<root>"} ${err.message}`);
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
const mlDefaults = mlDefaultsRaw as MlTrainDefaults;
|
||||||
|
|
||||||
|
// 2. Discover all mode schemas
|
||||||
|
if (!existsSync(MODES_DIR)) {
|
||||||
|
console.error(`error: modes directory not found at ${MODES_DIR}`);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
const modeFiles = readdirSync(MODES_DIR)
|
||||||
|
.filter(f => f.endsWith(".json"))
|
||||||
|
.sort(); // deterministic order
|
||||||
|
|
||||||
|
if (modeFiles.length === 0) {
|
||||||
|
console.error(`error: no mode schemas in ${MODES_DIR}`);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. Validate + parse all
|
||||||
|
const schemas: Array<{ source: string; schema: ModeSchema }> = [];
|
||||||
|
let errorCount = 0;
|
||||||
|
for (const f of modeFiles) {
|
||||||
|
const path = join(MODES_DIR, f);
|
||||||
|
let raw: unknown;
|
||||||
|
try {
|
||||||
|
raw = readJSON<unknown>(path);
|
||||||
|
} catch (e) {
|
||||||
|
console.error(`error: ${f}: parse: ${(e as Error).message}`);
|
||||||
|
errorCount++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!validate(raw)) {
|
||||||
|
console.error(`error: ${f}: schema validation failed:`);
|
||||||
|
for (const err of validate.errors ?? []) {
|
||||||
|
console.error(` ${err.instancePath || "<root>"} ${err.message}`);
|
||||||
|
}
|
||||||
|
errorCount++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const schema = raw as ModeSchema;
|
||||||
|
// Cross-field consistency checks
|
||||||
|
if (schema.params.length !== schema.ml.output_size) {
|
||||||
|
console.error(
|
||||||
|
`error: ${f}: params.length (${schema.params.length}) != ml.output_size (${schema.ml.output_size})`
|
||||||
|
);
|
||||||
|
errorCount++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (schema.ml.input_channels.length !== schema.ml.input_size) {
|
||||||
|
console.error(
|
||||||
|
`error: ${f}: ml.input_channels.length (${schema.ml.input_channels.length}) != ml.input_size (${schema.ml.input_size})`
|
||||||
|
);
|
||||||
|
errorCount++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// Firmware-fit check (one-core-engine P5): the fixed firmware MLP template
|
||||||
|
// is exactly 4 layers (3 hidden); the browser's runtime-shaped MLP caps
|
||||||
|
// every dimension at 4096 (bindings kMaxDim).
|
||||||
|
if (schema.ml.hidden_layers.length !== 3) {
|
||||||
|
console.error(
|
||||||
|
`error: ${f}: ml.hidden_layers must have exactly 3 entries ` +
|
||||||
|
`(fixed 4-layer topology); got ${schema.ml.hidden_layers.length}`
|
||||||
|
);
|
||||||
|
errorCount++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
const dims = [schema.ml.input_size, ...schema.ml.hidden_layers, schema.ml.output_size];
|
||||||
|
const bad = dims.find(d => d <= 0 || d > 4096);
|
||||||
|
if (bad !== undefined) {
|
||||||
|
console.error(`error: ${f}: ml dimension ${bad} outside (0, 4096]`);
|
||||||
|
errorCount++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Per-voice-space curve deviations must name real params and must be real
|
||||||
|
// deviations. Resolved here so a bad table fails BEFORE anything is written.
|
||||||
|
try {
|
||||||
|
curveOverrideRows(schema, f);
|
||||||
|
} catch (e) {
|
||||||
|
console.error(`error: ${(e as Error).message}`);
|
||||||
|
errorCount++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
const names = schema.voice_spaces.map(voiceSpaceName);
|
||||||
|
const dup = names.find((n, i) => names.indexOf(n) !== i);
|
||||||
|
if (dup !== undefined) {
|
||||||
|
console.error(`error: ${f}: duplicate voice space name ${JSON.stringify(dup)}`);
|
||||||
|
errorCount++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
schemas.push({ source: f, schema });
|
||||||
|
}
|
||||||
|
if (errorCount > 0) {
|
||||||
|
console.error(`\n${errorCount} schema(s) failed; aborting codegen.`);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. Emit C++ outputs
|
||||||
|
ensureDir(CPP_OUT_DIR);
|
||||||
|
writeFileSync(join(CPP_OUT_DIR, "schema_types.hpp"), emitSchemaTypesHpp());
|
||||||
|
ensureDir(CPP_ML_OUT_DIR);
|
||||||
|
writeFileSync(join(CPP_ML_OUT_DIR, "ml_defaults.hpp"), emitMlDefaultsHpp(mlDefaults));
|
||||||
|
for (const { source, schema } of schemas) {
|
||||||
|
const out = join(CPP_OUT_DIR, `${schema.mode_id}_schema.hpp`);
|
||||||
|
writeFileSync(out, emitModeHpp(schema, source));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 5. Emit TS outputs
|
||||||
|
ensureDir(TS_OUT_DIR);
|
||||||
|
writeFileSync(join(TS_OUT_DIR, "types.ts"), emitSharedTsTypes());
|
||||||
|
writeFileSync(join(TS_OUT_DIR, "ml_defaults.ts"), emitMlDefaultsTs(mlDefaults));
|
||||||
|
for (const { source, schema } of schemas) {
|
||||||
|
const out = join(TS_OUT_DIR, `${schema.mode_id}_schema.ts`);
|
||||||
|
writeFileSync(out, emitModeTs(schema, source));
|
||||||
|
}
|
||||||
|
writeFileSync(
|
||||||
|
join(TS_OUT_DIR, "index.ts"),
|
||||||
|
emitTsIndex(schemas.map(s => s.schema.mode_id).sort())
|
||||||
|
);
|
||||||
|
|
||||||
|
// 6. Report
|
||||||
|
console.log(`OK ${schemas.length} mode schema(s) processed.`);
|
||||||
|
console.log(` C++ -> ${CPP_OUT_DIR}`);
|
||||||
|
console.log(` TS -> ${TS_OUT_DIR}`);
|
||||||
|
for (const { schema } of schemas) {
|
||||||
|
console.log(
|
||||||
|
` - ${schema.mode_id}: ${schema.params.length} params, ` +
|
||||||
|
`${schema.voice_spaces.length} voice space(s), ` +
|
||||||
|
`MLP ${schema.ml.input_size}->[${schema.ml.hidden_layers.join(",")}]->${schema.ml.output_size}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Allow `import` without running when used as a library (e.g. for tests).
|
||||||
|
const isMain = (() => {
|
||||||
|
if (typeof process === "undefined") return false;
|
||||||
|
const argv1 = process.argv[1];
|
||||||
|
if (!argv1) return false;
|
||||||
|
return resolve(argv1) === fileURLToPath(import.meta.url);
|
||||||
|
})();
|
||||||
|
|
||||||
|
if (isMain) {
|
||||||
|
process.exit(main());
|
||||||
|
}
|
||||||
|
|
||||||
|
export { main };
|
||||||
51
codegen/lib.ts
Normal file
51
codegen/lib.ts
Normal file
|
|
@ -0,0 +1,51 @@
|
||||||
|
/**
|
||||||
|
* Shared helpers for the two codegen drivers (generate.ts — mode schemas —
|
||||||
|
* and generate-midi-devices.ts — MIDI device templates).
|
||||||
|
*
|
||||||
|
* The two drivers stay separate FILES on purpose: they read different schema
|
||||||
|
* directories, validate against different meta-schemas, write to different
|
||||||
|
* output dirs, and generate.ts's golden test (codegen/tests/golden_test.ts)
|
||||||
|
* must not depend on MIDI-device schema state. None of that requires
|
||||||
|
* duplicating these small string/fs helpers — they carry no per-driver
|
||||||
|
* behaviour, so they live here once (ST12, simplification 2026-07).
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { readFileSync, existsSync, mkdirSync } from "node:fs";
|
||||||
|
|
||||||
|
/** Create a directory (and parents) if it doesn't already exist. */
|
||||||
|
export function ensureDir(d: string): void {
|
||||||
|
if (!existsSync(d)) {
|
||||||
|
mkdirSync(d, { recursive: true });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Read and JSON-parse a file. */
|
||||||
|
export function readJSON<T>(path: string): T {
|
||||||
|
return JSON.parse(readFileSync(path, "utf8")) as T;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert snake_case to PascalCase.
|
||||||
|
* "paf_synth" -> "PafSynth", "memlcelium" -> "Memlcelium"
|
||||||
|
*/
|
||||||
|
export function toPascalCase(snake: string): string {
|
||||||
|
return snake
|
||||||
|
.split("_")
|
||||||
|
.map(s => (s.length === 0 ? s : s[0].toUpperCase() + s.slice(1)))
|
||||||
|
.join("");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Escape a string literal for embedding into a C++ string.
|
||||||
|
* We expect ASCII identifiers + label text only; quote and backslash are escaped.
|
||||||
|
*/
|
||||||
|
export function cppStringLit(s: string): string {
|
||||||
|
return '"' + s.replace(/\\/g, "\\\\").replace(/"/g, '\\"') + '"';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Escape a string for a TS single-line single-quoted literal.
|
||||||
|
*/
|
||||||
|
export function tsStringLit(s: string): string {
|
||||||
|
return "'" + s.replace(/\\/g, "\\\\").replace(/'/g, "\\'") + "'";
|
||||||
|
}
|
||||||
19
codegen/package.json
Normal file
19
codegen/package.json
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
{
|
||||||
|
"name": "memlnaut-codegen",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"private": true,
|
||||||
|
"description": "Codegen for MEMLNaut mode schemas (JSON -> C++ + TypeScript).",
|
||||||
|
"type": "module",
|
||||||
|
"scripts": {
|
||||||
|
"generate": "bun run generate.ts",
|
||||||
|
"test": "bun run tests/golden_test.ts && bun run tests/curve_drift_test.ts"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"ajv": "^8.17.1",
|
||||||
|
"ajv-formats": "^3.0.1"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"typescript": "^5.6.3",
|
||||||
|
"@types/node": "^22.9.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
185
codegen/tests/curve_drift_test.ts
Normal file
185
codegen/tests/curve_drift_test.ts
Normal file
|
|
@ -0,0 +1,185 @@
|
||||||
|
#!/usr/bin/env bun
|
||||||
|
/**
|
||||||
|
* Curve drift check — the schemas' declared response curves must equal what
|
||||||
|
* `nisps/engines/*.hpp` actually does, per voice space.
|
||||||
|
*
|
||||||
|
* WHY THIS CHECK IS SOURCE-LEVEL, NOT BEHAVIOURAL
|
||||||
|
* -----------------------------------------------
|
||||||
|
* You cannot observe "the curve" from engine output. A voice space maps a
|
||||||
|
* normalised slot into engine state as `base + f(p) * scale` and the state
|
||||||
|
* then disappears into DSP; without independently knowing `base`/`scale` (and
|
||||||
|
* the DSP transfer function) there is no way to recover `f` from audio. The
|
||||||
|
* engines expose no accessor for the mapped state, and adding one would mean
|
||||||
|
* editing engine internals to make a declaration checkable — the tail wagging
|
||||||
|
* the dog. So the fact lives in the arithmetic, and that is what we read.
|
||||||
|
*
|
||||||
|
* The upside of being source-level: it verifies the WHOLE table (9 modes, 26
|
||||||
|
* voice spaces, 344 params) rather than the handful of code paths any
|
||||||
|
* behavioural harness would reach. The parity harness, for contrast, only
|
||||||
|
* exercises PAFSynth + ChannelStrip at all-params-0.5.
|
||||||
|
*
|
||||||
|
* It fails loudly on three separate classes of drift:
|
||||||
|
* 1. a declared curve that disagrees with the engine,
|
||||||
|
* 2. a schema voice-space list that disagrees with the engine's
|
||||||
|
* `kVoiceSpaceNames` (order matters — the schema index IS the enum
|
||||||
|
* ordinal that `ModeBase::set_voice_space` casts to),
|
||||||
|
* 3. an engine idiom the extractor cannot reduce (codegen/curve-audit.ts
|
||||||
|
* raises rather than guessing "linear").
|
||||||
|
*
|
||||||
|
* It checks the JSON schemas AND the generated TypeScript, so a codegen bug
|
||||||
|
* that drops the table cannot pass.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { readFileSync, readdirSync } from "node:fs";
|
||||||
|
import { join, dirname, resolve } from "node:path";
|
||||||
|
import { fileURLToPath } from "node:url";
|
||||||
|
import { auditAllEngines, CurveAuditError, type Curve } from "../curve-audit.ts";
|
||||||
|
import { ALL_MODE_SCHEMAS, effectiveCurve } from "../../manifold/src/modes/generated/index.ts";
|
||||||
|
|
||||||
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||||
|
const REPO_ROOT = resolve(__dirname, "..", "..");
|
||||||
|
const MODES_DIR = join(REPO_ROOT, "schemas", "modes");
|
||||||
|
const ENGINES_DIR = join(REPO_ROOT, "nisps", "engines");
|
||||||
|
|
||||||
|
type VoiceSpaceDecl = string | { name: string; curve_overrides: Record<string, Curve> };
|
||||||
|
interface JsonModeSchema {
|
||||||
|
mode_id: string;
|
||||||
|
engine_id: string;
|
||||||
|
params: Array<{ name: string; curve: Curve }>;
|
||||||
|
voice_spaces: VoiceSpaceDecl[];
|
||||||
|
}
|
||||||
|
|
||||||
|
const vsName = (v: VoiceSpaceDecl): string => (typeof v === "string" ? v : v.name);
|
||||||
|
|
||||||
|
/** Resolve the JSON declaration into curves[voiceSpace][param]. */
|
||||||
|
function declaredCurves(s: JsonModeSchema): Curve[][] {
|
||||||
|
const defaults = s.params.map((p) => p.curve);
|
||||||
|
const byName = new Map(s.params.map((p, i) => [p.name, i] as const));
|
||||||
|
const rows = s.voice_spaces.length === 0 ? [null] : s.voice_spaces;
|
||||||
|
return rows.map((v) => {
|
||||||
|
const row = [...defaults];
|
||||||
|
if (v && typeof v !== "string") {
|
||||||
|
for (const [name, c] of Object.entries(v.curve_overrides)) {
|
||||||
|
row[byName.get(name)!] = c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return row;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function run(): number {
|
||||||
|
const problems: string[] = [];
|
||||||
|
let engines;
|
||||||
|
try {
|
||||||
|
engines = auditAllEngines(ENGINES_DIR);
|
||||||
|
} catch (e) {
|
||||||
|
if (e instanceof CurveAuditError) {
|
||||||
|
console.error(`\nFAILED to read the engines' curve arithmetic:\n ${e.message}\n`);
|
||||||
|
console.error(
|
||||||
|
"The extractor refuses to guess. Either the engine grew an idiom\n" +
|
||||||
|
"codegen/curve-audit.ts does not model, or a voice space lost its\n" +
|
||||||
|
"dispatch case. Teach the extractor, do not weaken it.\n"
|
||||||
|
);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
|
const tsByModeId = new Map(ALL_MODE_SCHEMAS.map((m) => [m.mode_id, m] as const));
|
||||||
|
let checkedModes = 0;
|
||||||
|
let checkedSlots = 0;
|
||||||
|
|
||||||
|
for (const f of readdirSync(MODES_DIR).filter((n) => n.endsWith(".json")).sort()) {
|
||||||
|
const s = JSON.parse(readFileSync(join(MODES_DIR, f), "utf8")) as JsonModeSchema;
|
||||||
|
const eng = engines.get(s.engine_id);
|
||||||
|
if (!eng) {
|
||||||
|
problems.push(`${f}: engine_id ${JSON.stringify(s.engine_id)} matches no engine in nisps/engines/`);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// (2) voice-space identity. Index i in the schema IS VoiceSpace ordinal i.
|
||||||
|
if (eng.voiceSpaceNames !== null) {
|
||||||
|
const declared = s.voice_spaces.map(vsName);
|
||||||
|
if (JSON.stringify(declared) !== JSON.stringify(eng.voiceSpaceNames)) {
|
||||||
|
problems.push(
|
||||||
|
`${f}: voice_spaces disagree with ${eng.file}'s kVoiceSpaceNames\n` +
|
||||||
|
` schema: ${JSON.stringify(declared)}\n` +
|
||||||
|
` engine: ${JSON.stringify(eng.voiceSpaceNames)}`
|
||||||
|
);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
} else if (s.voice_spaces.length > 1) {
|
||||||
|
problems.push(
|
||||||
|
`${f}: declares ${s.voice_spaces.length} voice spaces but ${eng.file} has no VoiceSpace enum`
|
||||||
|
);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// An engine with no params of its own (NoOpEngine, engine_id "thru") maps
|
||||||
|
// nothing: the mode's outputs are MIDI CCs it emits itself, unshaped.
|
||||||
|
const allLinear: Curve[] = s.params.map(() => "linear");
|
||||||
|
const actual =
|
||||||
|
eng.nParams === 0
|
||||||
|
? [allLinear]
|
||||||
|
: eng.voiceSpaceNames !== null
|
||||||
|
? eng.curves
|
||||||
|
: [eng.curves[0]!];
|
||||||
|
|
||||||
|
if (eng.nParams !== 0 && eng.nParams !== s.params.length) {
|
||||||
|
problems.push(`${f}: ${s.params.length} params but ${eng.engineId} has kNParams = ${eng.nParams}`);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// (1) the declared table, from the JSON…
|
||||||
|
const declared = declaredCurves(s);
|
||||||
|
// …and independently from the generated TypeScript, so a codegen bug that
|
||||||
|
// drops or mis-indexes the table is caught too.
|
||||||
|
const ts = tsByModeId.get(s.mode_id);
|
||||||
|
if (!ts) {
|
||||||
|
problems.push(`${f}: no generated TypeScript schema for mode_id ${s.mode_id}`);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const nVs = Math.max(declared.length, 1);
|
||||||
|
for (let vs = 0; vs < nVs; vs++) {
|
||||||
|
const expect = actual.length === 1 ? actual[0]! : actual[vs]!;
|
||||||
|
for (let i = 0; i < s.params.length; i++) {
|
||||||
|
checkedSlots++;
|
||||||
|
const label = `${s.mode_id}[${vsName(s.voice_spaces[vs] ?? "-")}].${s.params[i]!.name} (slot ${i})`;
|
||||||
|
if (declared[vs]![i] !== expect[i]) {
|
||||||
|
problems.push(
|
||||||
|
`${label}: schema says ${declared[vs]![i]}, ${eng.file} applies ${expect[i]}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const fromTs = effectiveCurve(ts, vs, i);
|
||||||
|
if (fromTs !== declared[vs]![i]) {
|
||||||
|
problems.push(
|
||||||
|
`${label}: generated TS says ${fromTs}, schemas/modes/${f} says ${declared[vs]![i]}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
checkedModes++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (problems.length > 0) {
|
||||||
|
console.error(`\ncurve drift: ${problems.length} problem(s)\n`);
|
||||||
|
for (const p of problems) console.error(` ${p}`);
|
||||||
|
console.error(
|
||||||
|
"\nThe schemas' `curve` fields are DESCRIPTIVE: they record what the\n" +
|
||||||
|
"engine already does. If an engine's arithmetic changed on purpose,\n" +
|
||||||
|
"update schemas/modes/*.json (params[].curve for the default, or the\n" +
|
||||||
|
"voice space's curve_overrides for a deviation) and re-run codegen.\n" +
|
||||||
|
"Do NOT change the engine to match the declaration.\n"
|
||||||
|
);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
`curve drift: ok — ${checkedModes} modes, ${checkedSlots} (voice space x param) slots ` +
|
||||||
|
`cross-checked against nisps/engines/ source.`
|
||||||
|
);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
process.exit(run());
|
||||||
432
codegen/tests/golden/paf_synth_schema.hpp
Normal file
432
codegen/tests/golden/paf_synth_schema.hpp
Normal file
|
|
@ -0,0 +1,432 @@
|
||||||
|
// AUTOGENERATED — do not edit. Source: schemas/modes/paf_synth.json. Run `bun run codegen/generate.ts` to regenerate.
|
||||||
|
#ifndef NISPS_GENERATED_PAF_SYNTH_SCHEMA_HPP
|
||||||
|
#define NISPS_GENERATED_PAF_SYNTH_SCHEMA_HPP
|
||||||
|
|
||||||
|
#include "schema_types.hpp"
|
||||||
|
#include "../../ml/mlp.hpp"
|
||||||
|
|
||||||
|
namespace nisps::modes::generated {
|
||||||
|
|
||||||
|
inline constexpr std::string_view kPafSynthModeId = "paf_synth";
|
||||||
|
inline constexpr std::string_view kPafSynthEngineId = "paf_synth";
|
||||||
|
|
||||||
|
inline constexpr std::array<std::string_view, 4> kPafSynthInputChannels = {{
|
||||||
|
"joy_x",
|
||||||
|
"joy_y",
|
||||||
|
"joy_z",
|
||||||
|
"joy_w",
|
||||||
|
}};
|
||||||
|
|
||||||
|
inline constexpr std::array<std::size_t, 3> kPafSynthHiddenLayers = {{
|
||||||
|
10u,
|
||||||
|
10u,
|
||||||
|
14u,
|
||||||
|
}};
|
||||||
|
|
||||||
|
inline constexpr MLConfig kPafSynthMLConfig = {
|
||||||
|
4u,
|
||||||
|
33u,
|
||||||
|
0.6f,
|
||||||
|
};
|
||||||
|
|
||||||
|
inline constexpr std::size_t kPafSynthParamCount = 33u;
|
||||||
|
inline constexpr std::array<Param, kPafSynthParamCount> kPafSynthParams = {{
|
||||||
|
Param{
|
||||||
|
"p00",
|
||||||
|
"Param 00",
|
||||||
|
0.0f,
|
||||||
|
1.0f,
|
||||||
|
0.5f,
|
||||||
|
Curve::linear,
|
||||||
|
"general",
|
||||||
|
},
|
||||||
|
Param{
|
||||||
|
"p01",
|
||||||
|
"Param 01",
|
||||||
|
0.0f,
|
||||||
|
1.0f,
|
||||||
|
0.5f,
|
||||||
|
Curve::linear,
|
||||||
|
"general",
|
||||||
|
},
|
||||||
|
Param{
|
||||||
|
"paf0_cf",
|
||||||
|
"PAF0 Center Freq",
|
||||||
|
0.0f,
|
||||||
|
1.0f,
|
||||||
|
0.5f,
|
||||||
|
Curve::linear,
|
||||||
|
"operators",
|
||||||
|
},
|
||||||
|
Param{
|
||||||
|
"paf1_cf",
|
||||||
|
"PAF1 Center Freq",
|
||||||
|
0.0f,
|
||||||
|
1.0f,
|
||||||
|
0.5f,
|
||||||
|
Curve::linear,
|
||||||
|
"operators",
|
||||||
|
},
|
||||||
|
Param{
|
||||||
|
"p04",
|
||||||
|
"Param 04",
|
||||||
|
0.0f,
|
||||||
|
1.0f,
|
||||||
|
0.5f,
|
||||||
|
Curve::linear,
|
||||||
|
"general",
|
||||||
|
},
|
||||||
|
Param{
|
||||||
|
"paf0_bw",
|
||||||
|
"PAF0 Bandwidth",
|
||||||
|
0.0f,
|
||||||
|
1.0f,
|
||||||
|
0.5f,
|
||||||
|
Curve::linear,
|
||||||
|
"operators",
|
||||||
|
},
|
||||||
|
Param{
|
||||||
|
"paf1_bw",
|
||||||
|
"PAF1 Bandwidth",
|
||||||
|
0.0f,
|
||||||
|
1.0f,
|
||||||
|
0.5f,
|
||||||
|
Curve::linear,
|
||||||
|
"operators",
|
||||||
|
},
|
||||||
|
Param{
|
||||||
|
"p07",
|
||||||
|
"Param 07",
|
||||||
|
0.0f,
|
||||||
|
1.0f,
|
||||||
|
0.5f,
|
||||||
|
Curve::linear,
|
||||||
|
"general",
|
||||||
|
},
|
||||||
|
Param{
|
||||||
|
"paf0_vib",
|
||||||
|
"PAF0 Vibrato Depth",
|
||||||
|
0.0f,
|
||||||
|
1.0f,
|
||||||
|
0.0f,
|
||||||
|
Curve::square,
|
||||||
|
"modulation",
|
||||||
|
},
|
||||||
|
Param{
|
||||||
|
"paf1_vib",
|
||||||
|
"PAF1 Vibrato Depth",
|
||||||
|
0.0f,
|
||||||
|
1.0f,
|
||||||
|
0.0f,
|
||||||
|
Curve::square,
|
||||||
|
"modulation",
|
||||||
|
},
|
||||||
|
Param{
|
||||||
|
"p10",
|
||||||
|
"Param 10",
|
||||||
|
0.0f,
|
||||||
|
1.0f,
|
||||||
|
0.5f,
|
||||||
|
Curve::linear,
|
||||||
|
"general",
|
||||||
|
},
|
||||||
|
Param{
|
||||||
|
"paf0_vfr",
|
||||||
|
"PAF0 Vibrato Rate",
|
||||||
|
0.0f,
|
||||||
|
1.0f,
|
||||||
|
0.5f,
|
||||||
|
Curve::square,
|
||||||
|
"modulation",
|
||||||
|
},
|
||||||
|
Param{
|
||||||
|
"paf1_vfr",
|
||||||
|
"PAF1 Vibrato Rate",
|
||||||
|
0.0f,
|
||||||
|
1.0f,
|
||||||
|
0.5f,
|
||||||
|
Curve::square,
|
||||||
|
"modulation",
|
||||||
|
},
|
||||||
|
Param{
|
||||||
|
"p13",
|
||||||
|
"Param 13",
|
||||||
|
0.0f,
|
||||||
|
1.0f,
|
||||||
|
0.5f,
|
||||||
|
Curve::linear,
|
||||||
|
"general",
|
||||||
|
},
|
||||||
|
Param{
|
||||||
|
"paf0_shift",
|
||||||
|
"PAF0 Shift",
|
||||||
|
0.0f,
|
||||||
|
1.0f,
|
||||||
|
0.5f,
|
||||||
|
Curve::linear,
|
||||||
|
"operators",
|
||||||
|
},
|
||||||
|
Param{
|
||||||
|
"paf1_shift",
|
||||||
|
"PAF1 Shift",
|
||||||
|
0.0f,
|
||||||
|
1.0f,
|
||||||
|
0.5f,
|
||||||
|
Curve::linear,
|
||||||
|
"operators",
|
||||||
|
},
|
||||||
|
Param{
|
||||||
|
"p16",
|
||||||
|
"Param 16",
|
||||||
|
0.0f,
|
||||||
|
1.0f,
|
||||||
|
0.5f,
|
||||||
|
Curve::linear,
|
||||||
|
"general",
|
||||||
|
},
|
||||||
|
Param{
|
||||||
|
"dl1mix",
|
||||||
|
"Delay Mix",
|
||||||
|
0.0f,
|
||||||
|
1.0f,
|
||||||
|
0.0f,
|
||||||
|
Curve::square,
|
||||||
|
"delay",
|
||||||
|
},
|
||||||
|
Param{
|
||||||
|
"p18",
|
||||||
|
"Param 18",
|
||||||
|
0.0f,
|
||||||
|
1.0f,
|
||||||
|
0.5f,
|
||||||
|
Curve::linear,
|
||||||
|
"general",
|
||||||
|
},
|
||||||
|
Param{
|
||||||
|
"dlfb",
|
||||||
|
"Delay Feedback",
|
||||||
|
0.0f,
|
||||||
|
1.0f,
|
||||||
|
0.5f,
|
||||||
|
Curve::linear,
|
||||||
|
"delay",
|
||||||
|
},
|
||||||
|
Param{
|
||||||
|
"env_decay",
|
||||||
|
"Env Decay",
|
||||||
|
0.0f,
|
||||||
|
1.0f,
|
||||||
|
0.3f,
|
||||||
|
Curve::square,
|
||||||
|
"envelope",
|
||||||
|
},
|
||||||
|
Param{
|
||||||
|
"p21",
|
||||||
|
"Param 21",
|
||||||
|
0.0f,
|
||||||
|
1.0f,
|
||||||
|
0.5f,
|
||||||
|
Curve::linear,
|
||||||
|
"general",
|
||||||
|
},
|
||||||
|
Param{
|
||||||
|
"p22",
|
||||||
|
"Param 22",
|
||||||
|
0.0f,
|
||||||
|
1.0f,
|
||||||
|
0.5f,
|
||||||
|
Curve::linear,
|
||||||
|
"general",
|
||||||
|
},
|
||||||
|
Param{
|
||||||
|
"p23",
|
||||||
|
"Param 23",
|
||||||
|
0.0f,
|
||||||
|
1.0f,
|
||||||
|
0.5f,
|
||||||
|
Curve::linear,
|
||||||
|
"general",
|
||||||
|
},
|
||||||
|
Param{
|
||||||
|
"p24",
|
||||||
|
"Param 24",
|
||||||
|
0.0f,
|
||||||
|
1.0f,
|
||||||
|
0.5f,
|
||||||
|
Curve::linear,
|
||||||
|
"general",
|
||||||
|
},
|
||||||
|
Param{
|
||||||
|
"p25",
|
||||||
|
"Param 25",
|
||||||
|
0.0f,
|
||||||
|
1.0f,
|
||||||
|
0.5f,
|
||||||
|
Curve::linear,
|
||||||
|
"general",
|
||||||
|
},
|
||||||
|
Param{
|
||||||
|
"shape_gain",
|
||||||
|
"Sine Shape Gain",
|
||||||
|
0.0f,
|
||||||
|
1.0f,
|
||||||
|
0.0f,
|
||||||
|
Curve::square,
|
||||||
|
"shaper",
|
||||||
|
},
|
||||||
|
Param{
|
||||||
|
"shape_asym",
|
||||||
|
"Sine Shape Asym",
|
||||||
|
0.0f,
|
||||||
|
1.0f,
|
||||||
|
0.0f,
|
||||||
|
Curve::square,
|
||||||
|
"shaper",
|
||||||
|
},
|
||||||
|
Param{
|
||||||
|
"shape_mix",
|
||||||
|
"Sine Shape Mix",
|
||||||
|
0.0f,
|
||||||
|
1.0f,
|
||||||
|
0.0f,
|
||||||
|
Curve::linear,
|
||||||
|
"shaper",
|
||||||
|
},
|
||||||
|
Param{
|
||||||
|
"rm_gain",
|
||||||
|
"Ring Mod Gain",
|
||||||
|
0.0f,
|
||||||
|
1.0f,
|
||||||
|
0.0f,
|
||||||
|
Curve::square,
|
||||||
|
"shaper",
|
||||||
|
},
|
||||||
|
Param{
|
||||||
|
"env_attack",
|
||||||
|
"Env Attack",
|
||||||
|
0.0f,
|
||||||
|
1.0f,
|
||||||
|
0.0f,
|
||||||
|
Curve::linear,
|
||||||
|
"envelope",
|
||||||
|
},
|
||||||
|
Param{
|
||||||
|
"env_sustain",
|
||||||
|
"Env Sustain",
|
||||||
|
0.0f,
|
||||||
|
1.0f,
|
||||||
|
0.5f,
|
||||||
|
Curve::linear,
|
||||||
|
"envelope",
|
||||||
|
},
|
||||||
|
Param{
|
||||||
|
"env_release",
|
||||||
|
"Env Release",
|
||||||
|
0.0f,
|
||||||
|
1.0f,
|
||||||
|
0.3f,
|
||||||
|
Curve::linear,
|
||||||
|
"envelope",
|
||||||
|
},
|
||||||
|
}};
|
||||||
|
|
||||||
|
inline constexpr std::size_t kPafSynthVoiceSpaceCount = 7u;
|
||||||
|
inline constexpr std::array<std::string_view, kPafSynthVoiceSpaceCount> kPafSynthVoiceSpaces = {{
|
||||||
|
"Ellipticacacia",
|
||||||
|
"Rowantares",
|
||||||
|
"Neemeda",
|
||||||
|
"Aquillow",
|
||||||
|
"Magnetarch",
|
||||||
|
"Elderstar",
|
||||||
|
"Ipeleiades",
|
||||||
|
}};
|
||||||
|
|
||||||
|
inline constexpr std::array<CurveOverride, 61u> kPafSynthCurveOverrides = {{
|
||||||
|
CurveOverride{0u, 8u, Curve::linear}, // Ellipticacacia.paf0_vib
|
||||||
|
CurveOverride{0u, 9u, Curve::linear}, // Ellipticacacia.paf1_vib
|
||||||
|
CurveOverride{0u, 11u, Curve::linear}, // Ellipticacacia.paf0_vfr
|
||||||
|
CurveOverride{0u, 12u, Curve::linear}, // Ellipticacacia.paf1_vfr
|
||||||
|
CurveOverride{0u, 14u, Curve::square}, // Ellipticacacia.paf0_shift
|
||||||
|
CurveOverride{0u, 17u, Curve::linear}, // Ellipticacacia.dl1mix
|
||||||
|
CurveOverride{0u, 18u, Curve::square}, // Ellipticacacia.p18
|
||||||
|
CurveOverride{0u, 19u, Curve::square}, // Ellipticacacia.dlfb
|
||||||
|
CurveOverride{0u, 20u, Curve::linear}, // Ellipticacacia.env_decay
|
||||||
|
CurveOverride{0u, 26u, Curve::linear}, // Ellipticacacia.shape_gain
|
||||||
|
CurveOverride{0u, 27u, Curve::linear}, // Ellipticacacia.shape_asym
|
||||||
|
CurveOverride{0u, 29u, Curve::linear}, // Ellipticacacia.rm_gain
|
||||||
|
CurveOverride{2u, 10u, Curve::square}, // Neemeda.p10
|
||||||
|
CurveOverride{2u, 13u, Curve::square}, // Neemeda.p13
|
||||||
|
CurveOverride{2u, 23u, Curve::square}, // Neemeda.p23
|
||||||
|
CurveOverride{2u, 24u, Curve::square}, // Neemeda.p24
|
||||||
|
CurveOverride{3u, 10u, Curve::square}, // Aquillow.p10
|
||||||
|
CurveOverride{3u, 13u, Curve::square}, // Aquillow.p13
|
||||||
|
CurveOverride{3u, 23u, Curve::square}, // Aquillow.p23
|
||||||
|
CurveOverride{3u, 24u, Curve::square}, // Aquillow.p24
|
||||||
|
CurveOverride{3u, 26u, Curve::linear}, // Aquillow.shape_gain
|
||||||
|
CurveOverride{3u, 27u, Curve::linear}, // Aquillow.shape_asym
|
||||||
|
CurveOverride{3u, 29u, Curve::linear}, // Aquillow.rm_gain
|
||||||
|
CurveOverride{3u, 32u, Curve::square}, // Aquillow.env_release
|
||||||
|
CurveOverride{4u, 5u, Curve::square}, // Magnetarch.paf0_bw
|
||||||
|
CurveOverride{4u, 8u, Curve::linear}, // Magnetarch.paf0_vib
|
||||||
|
CurveOverride{4u, 9u, Curve::linear}, // Magnetarch.paf1_vib
|
||||||
|
CurveOverride{4u, 11u, Curve::linear}, // Magnetarch.paf0_vfr
|
||||||
|
CurveOverride{4u, 12u, Curve::linear}, // Magnetarch.paf1_vfr
|
||||||
|
CurveOverride{4u, 17u, Curve::linear}, // Magnetarch.dl1mix
|
||||||
|
CurveOverride{4u, 20u, Curve::linear}, // Magnetarch.env_decay
|
||||||
|
CurveOverride{4u, 26u, Curve::linear}, // Magnetarch.shape_gain
|
||||||
|
CurveOverride{4u, 27u, Curve::linear}, // Magnetarch.shape_asym
|
||||||
|
CurveOverride{4u, 29u, Curve::linear}, // Magnetarch.rm_gain
|
||||||
|
CurveOverride{5u, 8u, Curve::linear}, // Elderstar.paf0_vib
|
||||||
|
CurveOverride{5u, 9u, Curve::linear}, // Elderstar.paf1_vib
|
||||||
|
CurveOverride{5u, 11u, Curve::linear}, // Elderstar.paf0_vfr
|
||||||
|
CurveOverride{5u, 12u, Curve::linear}, // Elderstar.paf1_vfr
|
||||||
|
CurveOverride{5u, 14u, Curve::square}, // Elderstar.paf0_shift
|
||||||
|
CurveOverride{5u, 17u, Curve::linear}, // Elderstar.dl1mix
|
||||||
|
CurveOverride{5u, 18u, Curve::square}, // Elderstar.p18
|
||||||
|
CurveOverride{5u, 19u, Curve::square}, // Elderstar.dlfb
|
||||||
|
CurveOverride{5u, 21u, Curve::square}, // Elderstar.p21
|
||||||
|
CurveOverride{5u, 22u, Curve::square}, // Elderstar.p22
|
||||||
|
CurveOverride{5u, 23u, Curve::square}, // Elderstar.p23
|
||||||
|
CurveOverride{5u, 26u, Curve::linear}, // Elderstar.shape_gain
|
||||||
|
CurveOverride{5u, 27u, Curve::linear}, // Elderstar.shape_asym
|
||||||
|
CurveOverride{5u, 29u, Curve::linear}, // Elderstar.rm_gain
|
||||||
|
CurveOverride{6u, 8u, Curve::linear}, // Ipeleiades.paf0_vib
|
||||||
|
CurveOverride{6u, 9u, Curve::linear}, // Ipeleiades.paf1_vib
|
||||||
|
CurveOverride{6u, 11u, Curve::linear}, // Ipeleiades.paf0_vfr
|
||||||
|
CurveOverride{6u, 12u, Curve::linear}, // Ipeleiades.paf1_vfr
|
||||||
|
CurveOverride{6u, 14u, Curve::square}, // Ipeleiades.paf0_shift
|
||||||
|
CurveOverride{6u, 17u, Curve::linear}, // Ipeleiades.dl1mix
|
||||||
|
CurveOverride{6u, 18u, Curve::square}, // Ipeleiades.p18
|
||||||
|
CurveOverride{6u, 21u, Curve::square}, // Ipeleiades.p21
|
||||||
|
CurveOverride{6u, 22u, Curve::square}, // Ipeleiades.p22
|
||||||
|
CurveOverride{6u, 23u, Curve::square}, // Ipeleiades.p23
|
||||||
|
CurveOverride{6u, 26u, Curve::linear}, // Ipeleiades.shape_gain
|
||||||
|
CurveOverride{6u, 27u, Curve::linear}, // Ipeleiades.shape_asym
|
||||||
|
CurveOverride{6u, 29u, Curve::linear}, // Ipeleiades.rm_gain
|
||||||
|
}};
|
||||||
|
|
||||||
|
inline constexpr UIConfig kPafSynthUI = {
|
||||||
|
PrimaryInput::XYPad,
|
||||||
|
true,
|
||||||
|
true,
|
||||||
|
};
|
||||||
|
|
||||||
|
using PafSynthMLP = ::nisps::ml::MLP<kPafSynthMLConfig.input_size, kPafSynthHiddenLayers[0], kPafSynthHiddenLayers[1], kPafSynthHiddenLayers[2], kPafSynthMLConfig.output_size>;
|
||||||
|
|
||||||
|
inline constexpr ::nisps::ParamSchema kPafSynthSchema = {
|
||||||
|
kPafSynthModeId,
|
||||||
|
kPafSynthEngineId,
|
||||||
|
std::span<const std::string_view>(kPafSynthInputChannels),
|
||||||
|
kPafSynthMLConfig.input_size,
|
||||||
|
std::span<const std::size_t>(kPafSynthHiddenLayers),
|
||||||
|
kPafSynthMLConfig.output_size,
|
||||||
|
kPafSynthMLConfig.default_spread,
|
||||||
|
std::span<const Param>(kPafSynthParams),
|
||||||
|
std::span<const std::string_view>(kPafSynthVoiceSpaces),
|
||||||
|
std::span<const CurveOverride>(kPafSynthCurveOverrides),
|
||||||
|
kPafSynthUI,
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace nisps::modes::generated
|
||||||
|
|
||||||
|
#endif // NISPS_GENERATED_PAF_SYNTH_SCHEMA_HPP
|
||||||
435
codegen/tests/golden/paf_synth_schema.ts
Normal file
435
codegen/tests/golden/paf_synth_schema.ts
Normal file
|
|
@ -0,0 +1,435 @@
|
||||||
|
// AUTOGENERATED — do not edit. Source: schemas/modes/paf_synth.json. Run `bun run codegen/generate.ts` to regenerate.
|
||||||
|
import type { ModeSchema } from './types';
|
||||||
|
|
||||||
|
export interface PafSynthParams {
|
||||||
|
readonly p00: number;
|
||||||
|
readonly p01: number;
|
||||||
|
readonly paf0_cf: number;
|
||||||
|
readonly paf1_cf: number;
|
||||||
|
readonly p04: number;
|
||||||
|
readonly paf0_bw: number;
|
||||||
|
readonly paf1_bw: number;
|
||||||
|
readonly p07: number;
|
||||||
|
readonly paf0_vib: number;
|
||||||
|
readonly paf1_vib: number;
|
||||||
|
readonly p10: number;
|
||||||
|
readonly paf0_vfr: number;
|
||||||
|
readonly paf1_vfr: number;
|
||||||
|
readonly p13: number;
|
||||||
|
readonly paf0_shift: number;
|
||||||
|
readonly paf1_shift: number;
|
||||||
|
readonly p16: number;
|
||||||
|
readonly dl1mix: number;
|
||||||
|
readonly p18: number;
|
||||||
|
readonly dlfb: number;
|
||||||
|
readonly env_decay: number;
|
||||||
|
readonly p21: number;
|
||||||
|
readonly p22: number;
|
||||||
|
readonly p23: number;
|
||||||
|
readonly p24: number;
|
||||||
|
readonly p25: number;
|
||||||
|
readonly shape_gain: number;
|
||||||
|
readonly shape_asym: number;
|
||||||
|
readonly shape_mix: number;
|
||||||
|
readonly rm_gain: number;
|
||||||
|
readonly env_attack: number;
|
||||||
|
readonly env_sustain: number;
|
||||||
|
readonly env_release: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const PafSynthSchema: ModeSchema = {
|
||||||
|
mode_id: 'paf_synth',
|
||||||
|
engine_id: 'paf_synth',
|
||||||
|
ml: {
|
||||||
|
input_channels: [
|
||||||
|
'joy_x',
|
||||||
|
'joy_y',
|
||||||
|
'joy_z',
|
||||||
|
'joy_w',
|
||||||
|
],
|
||||||
|
input_size: 4,
|
||||||
|
hidden_layers: [
|
||||||
|
10,
|
||||||
|
10,
|
||||||
|
14,
|
||||||
|
],
|
||||||
|
output_size: 33,
|
||||||
|
default_spread: 0.6,
|
||||||
|
},
|
||||||
|
params: [
|
||||||
|
{
|
||||||
|
name: 'p00',
|
||||||
|
label: 'Param 00',
|
||||||
|
min: 0,
|
||||||
|
max: 1,
|
||||||
|
default: 0.5,
|
||||||
|
curve: 'linear',
|
||||||
|
group: 'general',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'p01',
|
||||||
|
label: 'Param 01',
|
||||||
|
min: 0,
|
||||||
|
max: 1,
|
||||||
|
default: 0.5,
|
||||||
|
curve: 'linear',
|
||||||
|
group: 'general',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'paf0_cf',
|
||||||
|
label: 'PAF0 Center Freq',
|
||||||
|
min: 0,
|
||||||
|
max: 1,
|
||||||
|
default: 0.5,
|
||||||
|
curve: 'linear',
|
||||||
|
group: 'operators',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'paf1_cf',
|
||||||
|
label: 'PAF1 Center Freq',
|
||||||
|
min: 0,
|
||||||
|
max: 1,
|
||||||
|
default: 0.5,
|
||||||
|
curve: 'linear',
|
||||||
|
group: 'operators',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'p04',
|
||||||
|
label: 'Param 04',
|
||||||
|
min: 0,
|
||||||
|
max: 1,
|
||||||
|
default: 0.5,
|
||||||
|
curve: 'linear',
|
||||||
|
group: 'general',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'paf0_bw',
|
||||||
|
label: 'PAF0 Bandwidth',
|
||||||
|
min: 0,
|
||||||
|
max: 1,
|
||||||
|
default: 0.5,
|
||||||
|
curve: 'linear',
|
||||||
|
group: 'operators',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'paf1_bw',
|
||||||
|
label: 'PAF1 Bandwidth',
|
||||||
|
min: 0,
|
||||||
|
max: 1,
|
||||||
|
default: 0.5,
|
||||||
|
curve: 'linear',
|
||||||
|
group: 'operators',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'p07',
|
||||||
|
label: 'Param 07',
|
||||||
|
min: 0,
|
||||||
|
max: 1,
|
||||||
|
default: 0.5,
|
||||||
|
curve: 'linear',
|
||||||
|
group: 'general',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'paf0_vib',
|
||||||
|
label: 'PAF0 Vibrato Depth',
|
||||||
|
min: 0,
|
||||||
|
max: 1,
|
||||||
|
default: 0,
|
||||||
|
curve: 'square',
|
||||||
|
group: 'modulation',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'paf1_vib',
|
||||||
|
label: 'PAF1 Vibrato Depth',
|
||||||
|
min: 0,
|
||||||
|
max: 1,
|
||||||
|
default: 0,
|
||||||
|
curve: 'square',
|
||||||
|
group: 'modulation',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'p10',
|
||||||
|
label: 'Param 10',
|
||||||
|
min: 0,
|
||||||
|
max: 1,
|
||||||
|
default: 0.5,
|
||||||
|
curve: 'linear',
|
||||||
|
group: 'general',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'paf0_vfr',
|
||||||
|
label: 'PAF0 Vibrato Rate',
|
||||||
|
min: 0,
|
||||||
|
max: 1,
|
||||||
|
default: 0.5,
|
||||||
|
curve: 'square',
|
||||||
|
group: 'modulation',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'paf1_vfr',
|
||||||
|
label: 'PAF1 Vibrato Rate',
|
||||||
|
min: 0,
|
||||||
|
max: 1,
|
||||||
|
default: 0.5,
|
||||||
|
curve: 'square',
|
||||||
|
group: 'modulation',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'p13',
|
||||||
|
label: 'Param 13',
|
||||||
|
min: 0,
|
||||||
|
max: 1,
|
||||||
|
default: 0.5,
|
||||||
|
curve: 'linear',
|
||||||
|
group: 'general',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'paf0_shift',
|
||||||
|
label: 'PAF0 Shift',
|
||||||
|
min: 0,
|
||||||
|
max: 1,
|
||||||
|
default: 0.5,
|
||||||
|
curve: 'linear',
|
||||||
|
group: 'operators',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'paf1_shift',
|
||||||
|
label: 'PAF1 Shift',
|
||||||
|
min: 0,
|
||||||
|
max: 1,
|
||||||
|
default: 0.5,
|
||||||
|
curve: 'linear',
|
||||||
|
group: 'operators',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'p16',
|
||||||
|
label: 'Param 16',
|
||||||
|
min: 0,
|
||||||
|
max: 1,
|
||||||
|
default: 0.5,
|
||||||
|
curve: 'linear',
|
||||||
|
group: 'general',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'dl1mix',
|
||||||
|
label: 'Delay Mix',
|
||||||
|
min: 0,
|
||||||
|
max: 1,
|
||||||
|
default: 0,
|
||||||
|
curve: 'square',
|
||||||
|
group: 'delay',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'p18',
|
||||||
|
label: 'Param 18',
|
||||||
|
min: 0,
|
||||||
|
max: 1,
|
||||||
|
default: 0.5,
|
||||||
|
curve: 'linear',
|
||||||
|
group: 'general',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'dlfb',
|
||||||
|
label: 'Delay Feedback',
|
||||||
|
min: 0,
|
||||||
|
max: 1,
|
||||||
|
default: 0.5,
|
||||||
|
curve: 'linear',
|
||||||
|
group: 'delay',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'env_decay',
|
||||||
|
label: 'Env Decay',
|
||||||
|
min: 0,
|
||||||
|
max: 1,
|
||||||
|
default: 0.3,
|
||||||
|
curve: 'square',
|
||||||
|
group: 'envelope',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'p21',
|
||||||
|
label: 'Param 21',
|
||||||
|
min: 0,
|
||||||
|
max: 1,
|
||||||
|
default: 0.5,
|
||||||
|
curve: 'linear',
|
||||||
|
group: 'general',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'p22',
|
||||||
|
label: 'Param 22',
|
||||||
|
min: 0,
|
||||||
|
max: 1,
|
||||||
|
default: 0.5,
|
||||||
|
curve: 'linear',
|
||||||
|
group: 'general',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'p23',
|
||||||
|
label: 'Param 23',
|
||||||
|
min: 0,
|
||||||
|
max: 1,
|
||||||
|
default: 0.5,
|
||||||
|
curve: 'linear',
|
||||||
|
group: 'general',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'p24',
|
||||||
|
label: 'Param 24',
|
||||||
|
min: 0,
|
||||||
|
max: 1,
|
||||||
|
default: 0.5,
|
||||||
|
curve: 'linear',
|
||||||
|
group: 'general',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'p25',
|
||||||
|
label: 'Param 25',
|
||||||
|
min: 0,
|
||||||
|
max: 1,
|
||||||
|
default: 0.5,
|
||||||
|
curve: 'linear',
|
||||||
|
group: 'general',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'shape_gain',
|
||||||
|
label: 'Sine Shape Gain',
|
||||||
|
min: 0,
|
||||||
|
max: 1,
|
||||||
|
default: 0,
|
||||||
|
curve: 'square',
|
||||||
|
group: 'shaper',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'shape_asym',
|
||||||
|
label: 'Sine Shape Asym',
|
||||||
|
min: 0,
|
||||||
|
max: 1,
|
||||||
|
default: 0,
|
||||||
|
curve: 'square',
|
||||||
|
group: 'shaper',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'shape_mix',
|
||||||
|
label: 'Sine Shape Mix',
|
||||||
|
min: 0,
|
||||||
|
max: 1,
|
||||||
|
default: 0,
|
||||||
|
curve: 'linear',
|
||||||
|
group: 'shaper',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'rm_gain',
|
||||||
|
label: 'Ring Mod Gain',
|
||||||
|
min: 0,
|
||||||
|
max: 1,
|
||||||
|
default: 0,
|
||||||
|
curve: 'square',
|
||||||
|
group: 'shaper',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'env_attack',
|
||||||
|
label: 'Env Attack',
|
||||||
|
min: 0,
|
||||||
|
max: 1,
|
||||||
|
default: 0,
|
||||||
|
curve: 'linear',
|
||||||
|
group: 'envelope',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'env_sustain',
|
||||||
|
label: 'Env Sustain',
|
||||||
|
min: 0,
|
||||||
|
max: 1,
|
||||||
|
default: 0.5,
|
||||||
|
curve: 'linear',
|
||||||
|
group: 'envelope',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'env_release',
|
||||||
|
label: 'Env Release',
|
||||||
|
min: 0,
|
||||||
|
max: 1,
|
||||||
|
default: 0.3,
|
||||||
|
curve: 'linear',
|
||||||
|
group: 'envelope',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
voice_spaces: [
|
||||||
|
'Ellipticacacia',
|
||||||
|
'Rowantares',
|
||||||
|
'Neemeda',
|
||||||
|
'Aquillow',
|
||||||
|
'Magnetarch',
|
||||||
|
'Elderstar',
|
||||||
|
'Ipeleiades',
|
||||||
|
],
|
||||||
|
curve_overrides: [
|
||||||
|
{ voice_space: 0, param: 8, curve: 'linear' }, // Ellipticacacia.paf0_vib
|
||||||
|
{ voice_space: 0, param: 9, curve: 'linear' }, // Ellipticacacia.paf1_vib
|
||||||
|
{ voice_space: 0, param: 11, curve: 'linear' }, // Ellipticacacia.paf0_vfr
|
||||||
|
{ voice_space: 0, param: 12, curve: 'linear' }, // Ellipticacacia.paf1_vfr
|
||||||
|
{ voice_space: 0, param: 14, curve: 'square' }, // Ellipticacacia.paf0_shift
|
||||||
|
{ voice_space: 0, param: 17, curve: 'linear' }, // Ellipticacacia.dl1mix
|
||||||
|
{ voice_space: 0, param: 18, curve: 'square' }, // Ellipticacacia.p18
|
||||||
|
{ voice_space: 0, param: 19, curve: 'square' }, // Ellipticacacia.dlfb
|
||||||
|
{ voice_space: 0, param: 20, curve: 'linear' }, // Ellipticacacia.env_decay
|
||||||
|
{ voice_space: 0, param: 26, curve: 'linear' }, // Ellipticacacia.shape_gain
|
||||||
|
{ voice_space: 0, param: 27, curve: 'linear' }, // Ellipticacacia.shape_asym
|
||||||
|
{ voice_space: 0, param: 29, curve: 'linear' }, // Ellipticacacia.rm_gain
|
||||||
|
{ voice_space: 2, param: 10, curve: 'square' }, // Neemeda.p10
|
||||||
|
{ voice_space: 2, param: 13, curve: 'square' }, // Neemeda.p13
|
||||||
|
{ voice_space: 2, param: 23, curve: 'square' }, // Neemeda.p23
|
||||||
|
{ voice_space: 2, param: 24, curve: 'square' }, // Neemeda.p24
|
||||||
|
{ voice_space: 3, param: 10, curve: 'square' }, // Aquillow.p10
|
||||||
|
{ voice_space: 3, param: 13, curve: 'square' }, // Aquillow.p13
|
||||||
|
{ voice_space: 3, param: 23, curve: 'square' }, // Aquillow.p23
|
||||||
|
{ voice_space: 3, param: 24, curve: 'square' }, // Aquillow.p24
|
||||||
|
{ voice_space: 3, param: 26, curve: 'linear' }, // Aquillow.shape_gain
|
||||||
|
{ voice_space: 3, param: 27, curve: 'linear' }, // Aquillow.shape_asym
|
||||||
|
{ voice_space: 3, param: 29, curve: 'linear' }, // Aquillow.rm_gain
|
||||||
|
{ voice_space: 3, param: 32, curve: 'square' }, // Aquillow.env_release
|
||||||
|
{ voice_space: 4, param: 5, curve: 'square' }, // Magnetarch.paf0_bw
|
||||||
|
{ voice_space: 4, param: 8, curve: 'linear' }, // Magnetarch.paf0_vib
|
||||||
|
{ voice_space: 4, param: 9, curve: 'linear' }, // Magnetarch.paf1_vib
|
||||||
|
{ voice_space: 4, param: 11, curve: 'linear' }, // Magnetarch.paf0_vfr
|
||||||
|
{ voice_space: 4, param: 12, curve: 'linear' }, // Magnetarch.paf1_vfr
|
||||||
|
{ voice_space: 4, param: 17, curve: 'linear' }, // Magnetarch.dl1mix
|
||||||
|
{ voice_space: 4, param: 20, curve: 'linear' }, // Magnetarch.env_decay
|
||||||
|
{ voice_space: 4, param: 26, curve: 'linear' }, // Magnetarch.shape_gain
|
||||||
|
{ voice_space: 4, param: 27, curve: 'linear' }, // Magnetarch.shape_asym
|
||||||
|
{ voice_space: 4, param: 29, curve: 'linear' }, // Magnetarch.rm_gain
|
||||||
|
{ voice_space: 5, param: 8, curve: 'linear' }, // Elderstar.paf0_vib
|
||||||
|
{ voice_space: 5, param: 9, curve: 'linear' }, // Elderstar.paf1_vib
|
||||||
|
{ voice_space: 5, param: 11, curve: 'linear' }, // Elderstar.paf0_vfr
|
||||||
|
{ voice_space: 5, param: 12, curve: 'linear' }, // Elderstar.paf1_vfr
|
||||||
|
{ voice_space: 5, param: 14, curve: 'square' }, // Elderstar.paf0_shift
|
||||||
|
{ voice_space: 5, param: 17, curve: 'linear' }, // Elderstar.dl1mix
|
||||||
|
{ voice_space: 5, param: 18, curve: 'square' }, // Elderstar.p18
|
||||||
|
{ voice_space: 5, param: 19, curve: 'square' }, // Elderstar.dlfb
|
||||||
|
{ voice_space: 5, param: 21, curve: 'square' }, // Elderstar.p21
|
||||||
|
{ voice_space: 5, param: 22, curve: 'square' }, // Elderstar.p22
|
||||||
|
{ voice_space: 5, param: 23, curve: 'square' }, // Elderstar.p23
|
||||||
|
{ voice_space: 5, param: 26, curve: 'linear' }, // Elderstar.shape_gain
|
||||||
|
{ voice_space: 5, param: 27, curve: 'linear' }, // Elderstar.shape_asym
|
||||||
|
{ voice_space: 5, param: 29, curve: 'linear' }, // Elderstar.rm_gain
|
||||||
|
{ voice_space: 6, param: 8, curve: 'linear' }, // Ipeleiades.paf0_vib
|
||||||
|
{ voice_space: 6, param: 9, curve: 'linear' }, // Ipeleiades.paf1_vib
|
||||||
|
{ voice_space: 6, param: 11, curve: 'linear' }, // Ipeleiades.paf0_vfr
|
||||||
|
{ voice_space: 6, param: 12, curve: 'linear' }, // Ipeleiades.paf1_vfr
|
||||||
|
{ voice_space: 6, param: 14, curve: 'square' }, // Ipeleiades.paf0_shift
|
||||||
|
{ voice_space: 6, param: 17, curve: 'linear' }, // Ipeleiades.dl1mix
|
||||||
|
{ voice_space: 6, param: 18, curve: 'square' }, // Ipeleiades.p18
|
||||||
|
{ voice_space: 6, param: 21, curve: 'square' }, // Ipeleiades.p21
|
||||||
|
{ voice_space: 6, param: 22, curve: 'square' }, // Ipeleiades.p22
|
||||||
|
{ voice_space: 6, param: 23, curve: 'square' }, // Ipeleiades.p23
|
||||||
|
{ voice_space: 6, param: 26, curve: 'linear' }, // Ipeleiades.shape_gain
|
||||||
|
{ voice_space: 6, param: 27, curve: 'linear' }, // Ipeleiades.shape_asym
|
||||||
|
{ voice_space: 6, param: 29, curve: 'linear' }, // Ipeleiades.rm_gain
|
||||||
|
],
|
||||||
|
ui: {
|
||||||
|
primary_input: 'xy_pad',
|
||||||
|
show_voice_space_selector: true,
|
||||||
|
show_synth_visualizer: true,
|
||||||
|
},
|
||||||
|
};
|
||||||
120
codegen/tests/golden_test.ts
Normal file
120
codegen/tests/golden_test.ts
Normal file
|
|
@ -0,0 +1,120 @@
|
||||||
|
#!/usr/bin/env bun
|
||||||
|
/**
|
||||||
|
* Golden test: re-runs codegen and asserts that the freshly-generated
|
||||||
|
* paf_synth_schema.{hpp,ts} files are byte-identical to the snapshots in
|
||||||
|
* codegen/tests/golden/. (The TS target moved playground → manifold at P5
|
||||||
|
* of docs/specs/plans/one-core-engine-refactor.md.)
|
||||||
|
*
|
||||||
|
* If you change the codegen template intentionally, regenerate the goldens:
|
||||||
|
* bun run generate.ts
|
||||||
|
* cp ../nisps/modes/generated/paf_synth_schema.hpp tests/golden/
|
||||||
|
* cp ../manifold/src/modes/generated/paf_synth_schema.ts tests/golden/
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { readFileSync, existsSync } from "node:fs";
|
||||||
|
import { join, dirname, resolve } from "node:path";
|
||||||
|
import { fileURLToPath } from "node:url";
|
||||||
|
import { main as runGenerate } from "../generate.ts";
|
||||||
|
|
||||||
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||||
|
const REPO_ROOT = resolve(__dirname, "..", "..");
|
||||||
|
const GOLDEN_DIR = join(__dirname, "golden");
|
||||||
|
|
||||||
|
interface Case {
|
||||||
|
name: string;
|
||||||
|
generatedPath: string;
|
||||||
|
goldenPath: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const CASES: Case[] = [
|
||||||
|
{
|
||||||
|
name: "paf_synth_schema.hpp",
|
||||||
|
generatedPath: join(REPO_ROOT, "nisps", "modes", "generated", "paf_synth_schema.hpp"),
|
||||||
|
goldenPath: join(GOLDEN_DIR, "paf_synth_schema.hpp"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "paf_synth_schema.ts",
|
||||||
|
generatedPath: join(REPO_ROOT, "manifold", "src", "modes", "generated", "paf_synth_schema.ts"),
|
||||||
|
goldenPath: join(GOLDEN_DIR, "paf_synth_schema.ts"),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
function diff(name: string, expected: string, actual: string): string {
|
||||||
|
const e = expected.split("\n");
|
||||||
|
const a = actual.split("\n");
|
||||||
|
const out: string[] = [];
|
||||||
|
out.push(`mismatch in ${name}:`);
|
||||||
|
const maxLen = Math.max(e.length, a.length);
|
||||||
|
let mismatches = 0;
|
||||||
|
for (let i = 0; i < maxLen; i++) {
|
||||||
|
if (e[i] !== a[i]) {
|
||||||
|
mismatches++;
|
||||||
|
if (mismatches <= 10) {
|
||||||
|
out.push(` L${i + 1}:`);
|
||||||
|
out.push(` expected: ${JSON.stringify(e[i] ?? "<EOF>")}`);
|
||||||
|
out.push(` actual : ${JSON.stringify(a[i] ?? "<EOF>")}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (mismatches > 10) {
|
||||||
|
out.push(` ... and ${mismatches - 10} more line mismatches`);
|
||||||
|
}
|
||||||
|
return out.join("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
function run(): number {
|
||||||
|
console.log("running codegen…");
|
||||||
|
const code = runGenerate();
|
||||||
|
if (code !== 0) {
|
||||||
|
console.error(`codegen exited ${code}; aborting golden test`);
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
let failed = 0;
|
||||||
|
for (const c of CASES) {
|
||||||
|
if (!existsSync(c.goldenPath)) {
|
||||||
|
console.error(`MISSING golden file: ${c.goldenPath}`);
|
||||||
|
failed++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!existsSync(c.generatedPath)) {
|
||||||
|
console.error(`MISSING generated file: ${c.generatedPath}`);
|
||||||
|
failed++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const expected = readFileSync(c.goldenPath, "utf8");
|
||||||
|
const actual = readFileSync(c.generatedPath, "utf8");
|
||||||
|
if (expected !== actual) {
|
||||||
|
console.error(diff(c.name, expected, actual));
|
||||||
|
failed++;
|
||||||
|
} else {
|
||||||
|
console.log(` ok ${c.name}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Idempotency check: re-run codegen, files must still match goldens.
|
||||||
|
console.log("re-running codegen for idempotency check…");
|
||||||
|
const code2 = runGenerate();
|
||||||
|
if (code2 !== 0) {
|
||||||
|
console.error(`second codegen run exited ${code2}; aborting`);
|
||||||
|
return code2;
|
||||||
|
}
|
||||||
|
for (const c of CASES) {
|
||||||
|
if (!existsSync(c.goldenPath) || !existsSync(c.generatedPath)) continue;
|
||||||
|
const expected = readFileSync(c.goldenPath, "utf8");
|
||||||
|
const actual = readFileSync(c.generatedPath, "utf8");
|
||||||
|
if (expected !== actual) {
|
||||||
|
console.error(`idempotency: ${c.name} drifted on second run`);
|
||||||
|
failed++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (failed > 0) {
|
||||||
|
console.error(`\n${failed} golden test(s) failed.`);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
console.log("\nall golden tests passed.");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
process.exit(run());
|
||||||
16
codegen/tsconfig.json
Normal file
16
codegen/tsconfig.json
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"target": "ES2022",
|
||||||
|
"module": "ES2022",
|
||||||
|
"moduleResolution": "bundler",
|
||||||
|
"strict": true,
|
||||||
|
"noImplicitAny": true,
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"skipLibCheck": true,
|
||||||
|
"resolveJsonModule": true,
|
||||||
|
"allowSyntheticDefaultImports": true,
|
||||||
|
"forceConsistentCasingInFileNames": true,
|
||||||
|
"types": ["bun-types"]
|
||||||
|
},
|
||||||
|
"include": ["**/*.ts"]
|
||||||
|
}
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
,ck84,dharma-the-swan,04.11.2025 16:41,file:///home/ck84/snap/libreoffice/358/.config/libreoffice/4;
|
|
||||||
|
|
@ -1,424 +0,0 @@
|
||||||
Name,Component_1,Component_2
|
|
||||||
Betelginkgo,Betelgeuse,Ginkgo
|
|
||||||
Pleiadedar,Pleiades,Cedar
|
|
||||||
Helixypress,Helix Nebula,Cypress
|
|
||||||
Rigelmwood,Rigel,Elmwood
|
|
||||||
Sombreroak,Sombrero Galaxy,Oak
|
|
||||||
Hyadehorn,Hyades,Hawthorn
|
|
||||||
Triangularch,Triangulum,Larch
|
|
||||||
Vegalder,Vega,Alder
|
|
||||||
Whirlpoplar,Whirpool Galaxy,Poplar
|
|
||||||
Siriuswood,Sirius,Basswood
|
|
||||||
Oortcacia,Oort Cloud,Acacia
|
|
||||||
Denebony,Deneb,Ebony
|
|
||||||
Cartwhillow,Cartwheel Galaxy,Willow
|
|
||||||
Polariswood,Polaris,Ironwood
|
|
||||||
Craborwood,Crab Nebula,Hornbeam
|
|
||||||
Aldebaranyan,Aldebaran,Banyan
|
|
||||||
Pinwheelnut,Pinwheel Galaxy,Walnut
|
|
||||||
Antaresnut,Antares,Chestnut
|
|
||||||
Kuiperlpa,Kuiper Belt,Catalpa
|
|
||||||
Arcturuspruce,Arcturus,Spruce
|
|
||||||
Pegasafras,Pegasus,Sassafras
|
|
||||||
Capellaberry,Capella,Mulberry
|
|
||||||
Lyracacia,Lyra,Acacia
|
|
||||||
Polluxwood,Pollux,Boxwood
|
|
||||||
Scorpiumac,Scorpius,Sumac
|
|
||||||
Castorwood,Castor,Cottonwood
|
|
||||||
Dracodar,Draco,Cedar
|
|
||||||
Regulushua,Regulus,Joshua
|
|
||||||
Aquilnut,Aquila,Walnut
|
|
||||||
Spicamore,Spica,Sycamore
|
|
||||||
Cygnusswood,Cygnus,Sasswood
|
|
||||||
Proceyon,Procyon,Pecan
|
|
||||||
Perseusqoia,Perseus,Sequoia
|
|
||||||
Sagittalpa,Sagittarius,Catalpa
|
|
||||||
Tauruspen,Taurus,Aspen
|
|
||||||
Geminowan,Gemini,Rowan
|
|
||||||
Canceria,Cancer,Wisteria
|
|
||||||
Leogany,Leo,Mahogany
|
|
||||||
Virgoak,Virgo,Oak
|
|
||||||
Libraobab,Libra,Baobab
|
|
||||||
Ariescalyptus,Aries,Eucalyptus
|
|
||||||
Capricornia,Capricorn,Magnolia
|
|
||||||
Aquariusqoia,Aquarius,Sequoia
|
|
||||||
Piscesimmon,Pisces,Persimmon
|
|
||||||
Omeganolia,Omega Centauri,Magnolia
|
|
||||||
Beehivewood,Beehive Cluster,Olivewood
|
|
||||||
Pillarspress,Pillars of Creation,Cypress
|
|
||||||
Greatwillow,Great Wall,Willow
|
|
||||||
Localboobao,Local Bubble,Baobab
|
|
||||||
Termishoak,Termination Shock,Oak
|
|
||||||
Bowshocknut,Bow Shock,Chestnut
|
|
||||||
Stellarix,Stellar Wind,Tamarix
|
|
||||||
Heliopaulownia,Heliopause,Paulownia
|
|
||||||
Rochemewood,Roche Limit,Limewood
|
|
||||||
Eventhornbeam,Event Horizon,Hornbeam
|
|
||||||
Accretioak,Accretion Disk,Oak
|
|
||||||
Protoplanetree,Protoplanetary Disk,Planetree
|
|
||||||
Lagranginkgo,Lagrange Point,Ginkgo
|
|
||||||
Trojaniper,Trojan,Juniper
|
|
||||||
Gammarchwood,Gamma Ray Burst,Birchwood
|
|
||||||
Hypernowan,Hypernova,Rowan
|
|
||||||
Whitedwillow,White Dwarf,Willow
|
|
||||||
Redgianter,Red Giant,Red Alder
|
|
||||||
Superclusternut,Supercluster,Butternut
|
|
||||||
Filamenteakwood,Filament,Teakwood
|
|
||||||
Voidglass,Void,Douglass Fir
|
|
||||||
Greywallnut,Great Wall,Wallnut
|
|
||||||
Comettree,Comet,Peppertree
|
|
||||||
Asteroider,Asteroid Belt,Elder
|
|
||||||
Helixelkova,Helix Nebula,Zelkova
|
|
||||||
Orionwood,Orion Nebula,Redwood
|
|
||||||
Cassiopaple,Cassiopeia,Apple
|
|
||||||
Ursajortree,Ursa Major,Majortree
|
|
||||||
Ursaminorwood,Ursa Minor,Dogwood
|
|
||||||
Bristlecrab,Bristlecone Pine,Crab Nebula
|
|
||||||
Metasequoyasar,Metasequoia,Quasar
|
|
||||||
Monkeypleiades,Monkey Puzzle,Pleiades
|
|
||||||
Dragontree,Dragon Tree,Draco
|
|
||||||
Boojumbrero,Boojum,Sombrero Galaxy
|
|
||||||
Quiverwheel,Quiver Tree,Pinwheel
|
|
||||||
Joshuapiter,Joshua Tree,Jupiter
|
|
||||||
Wolleminebula,Wollemi Pine,Nebula
|
|
||||||
Dawndromeda,Dawn Redwood,Andromeda
|
|
||||||
Baldcygnuss,Bald Cypress,Cygnus
|
|
||||||
Zelkovega,Zelkova,Vega
|
|
||||||
Hornbeamstar,Hornbeam,Barnstar
|
|
||||||
Rowantares,Rowan,Antares
|
|
||||||
Basswoodburst,Basswood,Gamma Burst
|
|
||||||
Calabashea,Calabash,Cassiopeia
|
|
||||||
Neemeda,Neem,Andromeda
|
|
||||||
Salirius,Sal,Sirius
|
|
||||||
Tooniverse,Toon,Universe
|
|
||||||
Cassiapeia,Cassia,Cassiopeia
|
|
||||||
Yellowoodrion,Yellowwood,Orion
|
|
||||||
Blackwoodhole,Blackwood,Black Hole
|
|
||||||
Ironwoodsar,Ironwood,Quasar
|
|
||||||
Satinwhirl,Satinwood,Whirlpool
|
|
||||||
Poplarsar,Poplar,Pulsar
|
|
||||||
Cottonwoodway,Cottonwood,Milky Way
|
|
||||||
Sumacnova,Sumac,Supernova
|
|
||||||
Hazeleius,Hazel,Pegasus
|
|
||||||
Elderstar,Elder,Barnstar
|
|
||||||
Rigelbark,Rigel,Bark
|
|
||||||
Sirillow,Sirius,Willow
|
|
||||||
Altairix,Altair,Tamarix
|
|
||||||
Denebula,Deneb,Nebula
|
|
||||||
Polarispine,Polaris,Pine
|
|
||||||
Betelpine,Betelgeuse,Bristlecone
|
|
||||||
Rigellarch,Rigel,Larch
|
|
||||||
Vegamore,Vega,Sycamore
|
|
||||||
Altairnut,Altair,Chestnut
|
|
||||||
Arcturuscacia,Arcturus,Acacia
|
|
||||||
Capellaple,Capella,Apple
|
|
||||||
Polluxdogwood,Pollux,Dogwood
|
|
||||||
Castorong,Castor,Camphorwood
|
|
||||||
Regulusqoia,Regulus,Sequoia
|
|
||||||
Spicape,Spica,Grape
|
|
||||||
Procyonwood,Procyon,Sandalwood
|
|
||||||
Aldebaranyan,Aldebaran,Banyan
|
|
||||||
Antarespress,Antares,Cypress
|
|
||||||
Pleiadwood,Pleiades,Cedarwood
|
|
||||||
Hyadesmac,Hyades,Sumac
|
|
||||||
Beehivewood,Beehive,Olivewood
|
|
||||||
Orionniper,Orion,Juniper
|
|
||||||
Cassiopear,Cassiopeia,Pear
|
|
||||||
Dracoroak,Draco,Cork Oak
|
|
||||||
Lyralnut,Lyra,Walnut
|
|
||||||
Cygnust,Cygnus,Locust
|
|
||||||
Aquillow,Aquila,Willow
|
|
||||||
Perseusnut,Perseus,Butternut
|
|
||||||
Pegasuspen,Pegasus,Aspen
|
|
||||||
Andromelm,Andromeda,Elm
|
|
||||||
Triangulfir,Triangulum,Fir
|
|
||||||
Sombreruce,Sombrero,Spruce
|
|
||||||
Whirlpinecone,Whirlpool,Pine
|
|
||||||
Cartwheelnut,Cartwheel,Hazelnut
|
|
||||||
Helixelm,Helix,Elm
|
|
||||||
Crabapple,Crab Nebula,Crabapple
|
|
||||||
Pillarspen,Pillars,Aspen
|
|
||||||
Sagittariuswood,Sagittarius,Sandalwood
|
|
||||||
Scorpiuspen,Scorpius,Aspen
|
|
||||||
Taurusqoia,Taurus,Sequoia
|
|
||||||
Geminoak,Gemini,Oak
|
|
||||||
Cancerdar,Cancer,Cedar
|
|
||||||
Leowood,Leo,Boxwood
|
|
||||||
Virgowan,Virgo,Rowan
|
|
||||||
Librasswood,Libra,Basswood
|
|
||||||
Ariesnut,Aries,Chestnut
|
|
||||||
Capricornbeam,Capricorn,Hornbeam
|
|
||||||
Aquariuslder,Aquarius,Alder
|
|
||||||
Piscespress,Pisces,Cypress
|
|
||||||
Magnetardwood,Magnetar,Hardwood
|
|
||||||
Pulsarwood,Pulsar,Rosewood
|
|
||||||
Quasarberry,Quasar,Elderberry
|
|
||||||
Supernovakia,Supernova,Plumeria
|
|
||||||
Hypernovania,Hypernova,Paulownia
|
|
||||||
Blackholly,Black Hole,Holly
|
|
||||||
Whitedwarfpine,White Dwarf,White Pine
|
|
||||||
Redgiantwood,Red Giant,Giantwood
|
|
||||||
Bluegiganticacia,Blue Giant,Acacia
|
|
||||||
Neutronia,Neutron Star,Catalpa
|
|
||||||
Browndwarfnut,Brown Dwarf,Butternut
|
|
||||||
Protostarfir,Protostar,Fir
|
|
||||||
Mainsequoia,Main Sequence,Sequoia
|
|
||||||
Subergiantree,Supergiant,Tree
|
|
||||||
Yorkcloud,Oort Cloud,Cork
|
|
||||||
Kuiperlpa,Kuiper Belt,Catalpa
|
|
||||||
Heliospherical,Heliosphere,Spherical Tree
|
|
||||||
Heliopaulogany,Heliopause,Mahogany
|
|
||||||
Terminationoak,Termination Shock,Oak
|
|
||||||
Bowshockberry,Bow Shock,Hackberry
|
|
||||||
Stellarwindwood,Stellar Wind,Driftwood
|
|
||||||
Solarwindowan,Solar Wind,Rowan
|
|
||||||
Interstellarch,Interstellar Medium,Larch
|
|
||||||
Circumstellarix,Circumstellar Disk,Tamarix
|
|
||||||
Protoplanetree,Protoplanetary Disk,Plane Tree
|
|
||||||
Accretionoak,Accretion Disk,Oak
|
|
||||||
Eventhorizonwood,Event Horizon,Ironwood
|
|
||||||
Schwarzschillow,Schwarzschild Radius,Willow
|
|
||||||
Singularsimmon,Singularity,Persimmon
|
|
||||||
Rochelimewood,Roche Limit,Limewood
|
|
||||||
Lagrangewood,Lagrange Point,Rangewood
|
|
||||||
Trojantree,Trojan Asteroids,Tree
|
|
||||||
Hildazel,Hilda Group,Hazel
|
|
||||||
Amoribark,Amor Asteroids,Bark
|
|
||||||
Atenberry,Aten Asteroids,Elderberry
|
|
||||||
Apollomeria,Apollo Asteroids,Plumeria
|
|
||||||
Gammaburst Ash,Gamma Ray Burst,Ash
|
|
||||||
Xraybirch,X-ray Binary,Birch
|
|
||||||
Millisecwood,Millisecond Pulsar,Redwood
|
|
||||||
Magnetarch,Magnetar,Larch
|
|
||||||
Softgammawood,Soft Gamma Repeater,Softwood
|
|
||||||
Superclusternut,Supercluster,Clusternut
|
|
||||||
Galaxyclusterpine,Galaxy Cluster,Pine
|
|
||||||
Galaxygroupfir,Galaxy Group,Fir
|
|
||||||
Localgrowan,Local Group,Rowan
|
|
||||||
Virgoclusteroak,Virgo Cluster,Oak
|
|
||||||
Comaberrynicaceae,Coma Berenices,Berry
|
|
||||||
Greatwallnut,Great Wall,Wallnut
|
|
||||||
Sloangreatwillow,Sloan Great Wall,Willow
|
|
||||||
Herculessuperia,Hercules Supercluster,Wisteria
|
|
||||||
Shapleypress,Shapley Supercluster,Cypress
|
|
||||||
Laniakeroak,Laniakea Supercluster,Kauri Oak
|
|
||||||
Cosmicwebwood,Cosmic Web,Webwood
|
|
||||||
Filamentree,Filament,Tree
|
|
||||||
Voidwood,Void,Driftwood
|
|
||||||
Boötesvoidwood,Boötes Void,Olivewood
|
|
||||||
Sculptornut,Sculptor Void,Coconut
|
|
||||||
Greywallash,Great Wall,Ash
|
|
||||||
Localbubbaobab,Local Bubble,Baobab
|
|
||||||
Loopicacia,Local Interstellar Cloud,Acacia
|
|
||||||
Gouldspen,Gould Belt,Aspen
|
|
||||||
Orionspurmac,Orion Spur,Sumac
|
|
||||||
Sagittariusarmwood,Sagittarius Arm,Armwood
|
|
||||||
Perseusarmpine,Perseus Arm,Pine
|
|
||||||
Outerarmoak,Outer Arm,Oak
|
|
||||||
Scutumcentauruswood,Scutum-Centaurus Arm,Scutumwood
|
|
||||||
Normamalder,Norma Arm,Alder
|
|
||||||
Barredspiralex,Barred Spiral,Ilex
|
|
||||||
Ellipticacacia,Elliptical Galaxy,Acacia
|
|
||||||
Irregularnut,Irregular Galaxy,Butternut
|
|
||||||
Lenticularcorn,Lenticular Galaxy,Acorn
|
|
||||||
Dwarfnut,Dwarf Galaxy,Chestnut
|
|
||||||
Satelliteelm,Satellite Galaxy,Elm
|
|
||||||
Starburstfir,Starburst Galaxy,Fir
|
|
||||||
Seyfertree,Seyfert Galaxy,Feather Tree
|
|
||||||
Blazarwood,Blazar,Rosewood
|
|
||||||
Radiogalaxypress,Radio Galaxy,Cypress
|
|
||||||
Activenutcleus,Active Galactic Nucleus,Nut
|
|
||||||
Quasartree,Quasar,Quandong Tree
|
|
||||||
Ultraluminouswood,Ultraluminous Galaxy,Luminous Tree
|
|
||||||
Luminousredgiant,Luminous Red Galaxy,Red Giant Sequoia
|
|
||||||
Greenpeachia,Green Pea Galaxy,Peach
|
|
||||||
Polarringwood,Polar Ring Galaxy,Ringwood
|
|
||||||
Shellgalaxash,Shell Galaxy,Ash
|
|
||||||
Ringalaxypress,Ring Galaxy,Cypress
|
|
||||||
Hoagsobjectoak,Hoag's Object,Oak
|
|
||||||
Mayallsobjectree,Mayall's Object,Tree
|
|
||||||
Tadpolgalaxillow,Tadpole Galaxy,Willow
|
|
||||||
Cometgalaxalder,Comet Galaxy,Alder
|
|
||||||
Sunflowernut,Sunflower Galaxy,Sunflower
|
|
||||||
Blackeyewood,Black Eye Galaxy,Blackwood
|
|
||||||
Bodesgalaxnut,Bode's Galaxy,Coconut
|
|
||||||
Cigargalaxpress,Cigar Galaxy,Cypress
|
|
||||||
Mousesgalaxypen,Mice Galaxies,Aspen
|
|
||||||
Antennaegalaxynt,Antennae Galaxies,Antwood
|
|
||||||
Polarisstwood,Polaris,Sasswood
|
|
||||||
Rigwood,Rigel,Dogwood
|
|
||||||
Canopusnut,Canopus,Coconut
|
|
||||||
Vegamore,Vega,Sycamore
|
|
||||||
Capellalnut,Capella,Walnut
|
|
||||||
Rigelberry,Rigel,Mulberry
|
|
||||||
Procyonwood,Procyon,Cottonwood
|
|
||||||
Achernarnut,Achernar,Butternut
|
|
||||||
Betelgeuswood,Betelgeuse,Geuswood
|
|
||||||
Hadarcedarwood,Hadar,Cedarwood
|
|
||||||
Altairix,Altair,Tamarix
|
|
||||||
Alderaminwood,Alderamin,Alderwood
|
|
||||||
Denebolive,Denebola,Olive
|
|
||||||
Mimosacia,Mimosa,Acacia
|
|
||||||
Regulenut,Regulus,Filbert
|
|
||||||
Adharalnut,Adhara,Walnut
|
|
||||||
Shahelmwood,Shaula,Elm
|
|
||||||
Gacruxifir,Gacrux,Fir
|
|
||||||
Bellatrixnut,Bellatrix,Hazelnut
|
|
||||||
Elnathnut,Elnath,Chestnut
|
|
||||||
Miaplacidiumwood,Miaplacidus,Palladium
|
|
||||||
Alnitaknut,Alnitak,Coconut
|
|
||||||
Alnilamspen,Alnilam,Aspen
|
|
||||||
Aliothogany,Alioth,Mahogany
|
|
||||||
Mirzamberry,Mirzam,Mulberry
|
|
||||||
Alkaidnut,Alkaid,Butternut
|
|
||||||
Atriarch,Atria,Larch
|
|
||||||
Alhenawood,Alhena,Alderwood
|
|
||||||
Peacockahogany,Peacock,Mahogany
|
|
||||||
Mirfaknut,Mirfak,Coconut
|
|
||||||
Wezenalder,Wezen,Alder
|
|
||||||
Sargassage,Sargas,Sage
|
|
||||||
Menkarberry,Menkar,Elderberry
|
|
||||||
Eniffir,Enif,Fir
|
|
||||||
Denebalgedinut,Deneb Algedi,Butternut
|
|
||||||
Zubenhaknutbi,Zuben Hakrabi,Butternut
|
|
||||||
Alshainalnut,Alshain,Walnut
|
|
||||||
Rastabantamarind,Rastaban,Tamarind
|
|
||||||
Markabwood,Markab,Markwood
|
|
||||||
Schedarogany,Schedar,Mahogany
|
|
||||||
Almaalnutak,Almaak,Walnut
|
|
||||||
Rasalgetash,Rasalgethi,Ash
|
|
||||||
Thubanyan,Thuban,Banyan
|
|
||||||
Kausafras,Kaus Australis,Sassafras
|
|
||||||
Nunkirnut,Nunki,Coconut
|
|
||||||
Sabikwood,Sabik,Rosewood
|
|
||||||
Menkalnutnan,Menkalnan,Butternut
|
|
||||||
Asteropewood,Asterope,Redwood
|
|
||||||
Atlaspen,Atlas,Aspen
|
|
||||||
Electralder,Electra,Alder
|
|
||||||
Maiagany,Maia,Mahogany
|
|
||||||
Meropewood,Merope,Olivewood
|
|
||||||
Taugetamarix,Taygeta,Tamarix
|
|
||||||
Pleionetree,Pleione,Tree
|
|
||||||
Celaenoak,Celaeno,Oak
|
|
||||||
Alcyonedar,Alcyone,Cedar
|
|
||||||
Sterropopelnut,Sterope,Pecanut
|
|
||||||
Proximaple,Proxima Centauri,Apple
|
|
||||||
Alphacenternut,Alpha Centauri,Butternut
|
|
||||||
Barnardstaroak,Barnard's Star,Oak
|
|
||||||
Wolfwood,Wolf 359,Dogwood
|
|
||||||
Lalandelarch,Lalande 21185,Larch
|
|
||||||
Siriuswood,Sirius,Basswood
|
|
||||||
Luytenbirch,Luyten 726-8,Birch
|
|
||||||
Rossnut,Ross 154,Coconut
|
|
||||||
Rossberry,Ross 248,Elderberry
|
|
||||||
Epsilonwood,Epsilon Eridani,Sandalwood
|
|
||||||
Lacaillemwood,Lacaille 9352,Elmwood
|
|
||||||
Rosswood,Ross 128,Cottonwood
|
|
||||||
EZaquariuspen,EZ Aquarii,Aspen
|
|
||||||
Procyonix,Procyon,Phoenix
|
|
||||||
Sixtyonecygnust,61 Cygni,Locust
|
|
||||||
Struvewood,Struve 2398,Rosewood
|
|
||||||
Groombridgefir,Groombridge 34,Fir
|
|
||||||
Epsilondiwood,Epsilon Indi,Indigowood
|
|
||||||
DXcancroak,DX Cancri,Oak
|
|
||||||
Taucetialder,Tau Ceti,Alder
|
|
||||||
Luytenut,Luyten's Star,Butternut
|
|
||||||
Teegardeenspen,Teegarden's Star,Aspen
|
|
||||||
Kapteynsnut,Kapteyn's Star,Coconut
|
|
||||||
Lacaillewood,Lacaille 8760,Lacewood
|
|
||||||
Krugernut,Krüger 60,Coconut
|
|
||||||
Rosspress,Ross 614,Cypress
|
|
||||||
Wolfwoodogwood,Wolf 1061,Dogwood
|
|
||||||
Vanmaanensnut,Van Maanen's Star,Chestnut
|
|
||||||
Gliesetree,Gliese 1,Tree
|
|
||||||
Gielenseginkgo,Gliese 876,Ginkgo
|
|
||||||
Giseewood,Gliese 581,Rosewood
|
|
||||||
TRappistree,TRAPPIST-1,Trapwood
|
|
||||||
Gliesecherry,Gliese 667,Cherry
|
|
||||||
Glisewood,Gliese 832,Walnutwood
|
|
||||||
Glaesewood,Gliese 163,Olivewood
|
|
||||||
Gleasewood,Gliese 180,Teaselwood
|
|
||||||
Lessewood,Gliese 221,Lesserwood
|
|
||||||
Sleewood,Gliese 317,Sleekwood
|
|
||||||
Liewood,Gliese 357,Tree
|
|
||||||
Gleetree,Gliese 433,Tree
|
|
||||||
Graywood,Gliese 436,Graywood
|
|
||||||
Greatwood,Gliese 504,Greatwood
|
|
||||||
Greenwood,Gliese 570,Greenwood
|
|
||||||
Greshwood,Gliese 625,Ashwood
|
|
||||||
Gladewood,Gliese 649,Glade
|
|
||||||
Glowwood,Gliese 674,Glowwood
|
|
||||||
Gradewood,Gliese 682,Gradewood
|
|
||||||
Gracewood,Gliese 686,Gracewood
|
|
||||||
Grandewood,Gliese 785,Grandewood
|
|
||||||
Glintwood,Gliese 806,Flintwood
|
|
||||||
Grimwood,Gliese 832,Grimwood
|
|
||||||
Horsehead Hickory,Horsehead Nebula,Hickory
|
|
||||||
Eaglenberry,Eagle Nebula,Elderberry
|
|
||||||
Trifidogwood,Trifid Nebula,Dogwood
|
|
||||||
Lagoonwood,Lagoon Nebula,Lagoonwood
|
|
||||||
Rosettamarisk,Rosette Nebula,Tamarisk
|
|
||||||
Carinapress,Carina Nebula,Cypress
|
|
||||||
Veilbark,Veil Nebula,Bark
|
|
||||||
Northamericoak,North America Nebula,Oak
|
|
||||||
Flamingowan,Flaming Star Nebula,Rowan
|
|
||||||
Owlnut,Owl Nebula,Walnut
|
|
||||||
Catseyelm,Cat's Eye Nebula,Elm
|
|
||||||
Ringebula,Ring Nebula,Nebula
|
|
||||||
Dumbbellnut,Dumbbell Nebula,Butternut
|
|
||||||
Boomerangalm,Boomerang Nebula,Palm
|
|
||||||
Butterflypress,Butterfly Nebula,Cypress
|
|
||||||
Calasash,Calabash Nebula,Ash
|
|
||||||
Redspiderash,Red Spider Nebula,Ash
|
|
||||||
Eskimogany,Eskimo Nebula,Mahogany
|
|
||||||
Ghostjuniper,Ghost of Jupiter,Juniper
|
|
||||||
Helixogwood,Helix Nebula,Dogwood
|
|
||||||
Spiralpress,Spiral Planetary,Cypress
|
|
||||||
Littlegembark,Little Gem Nebula,Bark
|
|
||||||
Necklacacia,Necklace Nebula,Acacia
|
|
||||||
Saturnbeech,Saturn Nebula,Beech
|
|
||||||
Bluesnowbark,Blue Snowball,Bark
|
|
||||||
Twinjet Fir,Twin Jet Nebula,Fir
|
|
||||||
Hourglasswood,Hourglass Nebula,Boxwood
|
|
||||||
Eggwood,Egg Nebula,Dogwood
|
|
||||||
Boxtree,Box Nebula,Boxtree
|
|
||||||
Crescentpress,Crescent Nebula,Cypress
|
|
||||||
Bubblebark,Bubble Nebula,Bark
|
|
||||||
Thorwood,Thor's Helmet,Thornwood
|
|
||||||
Snailgum,Snail Nebula,Sweetgum
|
|
||||||
Conepinepress,Cone Nebula,Pine
|
|
||||||
Irisbeech,Iris Nebula,Beech
|
|
||||||
Witchheadash,Witch Head Nebula,Ash
|
|
||||||
Barnardloopwood,Barnard's Loop,Loopwood
|
|
||||||
Californiapress,California Nebula,Cypress
|
|
||||||
Heartbark,Heart Nebula,Bark
|
|
||||||
Soulspuce,Soul Nebula,Spruce
|
|
||||||
Pacmangany,Pacman Nebula,Mahogany
|
|
||||||
Monkeyheadnut,Monkey Head Nebula,Monkeynut
|
|
||||||
Wizardlm,Wizard Nebula,Elm
|
|
||||||
Tulipwood,Tulip Nebula,Tulipwood
|
|
||||||
Crescentbark,Crescent Nebula,Bark
|
|
||||||
Pelicangum,Pelican Nebula,Gum
|
|
||||||
Elephantstrunkwood,Elephant's Trunk,Trunkwood
|
|
||||||
Tuningforkpress,Tuning Fork Galaxy,Cypress
|
|
||||||
Sombrerowood,Sombrero Galaxy,Sombrerowood
|
|
||||||
Blackeyesycamore,Black Eye Galaxy,Sycamore
|
|
||||||
Sunflowernut,Sunflower Galaxy,Coconut
|
|
||||||
Pinwheelder,Pinwheel Galaxy,Elder
|
|
||||||
Fireworksgalaxyalder,Fireworks Galaxy,Alder
|
|
||||||
Spindlepress,Spindle Galaxy,Cypress
|
|
||||||
Bodesgalaxnut,Bode's Galaxy,Butternut
|
|
||||||
Cigargalaxbirch,Cigar Galaxy,Birch
|
|
||||||
Whirlpoolepress,Whirlpool Galaxy,Cypress
|
|
||||||
Cartwheelalder,Cartwheel Galaxy,Alder
|
|
||||||
Tadpolewood,Tadpole Galaxy,Tadwood
|
|
||||||
Antenaennut,Antennae Galaxies,Nut
|
|
||||||
Mousesgalaxielm,Mice Galaxies,Elm
|
|
||||||
Atomspeachachy,Atom's Peace Galaxy,Peachy
|
|
||||||
Malinsgalaxnut,Malin 1,Nut
|
|
||||||
Hoagsobjecteakwood,Hoag's Object,Teakwood
|
|
||||||
Ringgalaxynut,Ring Galaxy,Donut
|
|
||||||
Polarringiron,Polar Ring Galaxy,Ironwood
|
|
||||||
Silversliverwood,Silver Sliver Galaxy,Silverwood
|
|
||||||
Needlepress,Needle Galaxy,Cypress
|
|
||||||
Hamburgerash,Hamburger Galaxy,Ash
|
|
||||||
|
|
|
@ -1,420 +0,0 @@
|
||||||
Name,Component_1,Component_2
|
|
||||||
Pleiadeiba,Pleiades,Ceiba
|
|
||||||
Pau Brasilica,Pau Brasil,Crab Nebula
|
|
||||||
Araucarina,Araucaria,Carina Nebula
|
|
||||||
Quebracho X-1,Quebracho,Cygnus X-1
|
|
||||||
Lapachomeda,Lapacho,Andromeda
|
|
||||||
Guanacastellum,Guanacaste,Magellanic Cloud
|
|
||||||
Trianguanum,Triangulum,Guanacaste
|
|
||||||
Jacarandromeda,Jacaranda,Andromeda
|
|
||||||
Ceibalaxy,Ceiba,Galaxy
|
|
||||||
Horsehead Brasil,Horsehead,Pau Brasil
|
|
||||||
Monkeypuzzle Void,Monkey Puzzle,Cosmic Void
|
|
||||||
Quebrachion,Quebracho,Orion
|
|
||||||
Lapachosar,Lapacho,Quasar
|
|
||||||
Rubber Rosette,Rubber Tree,Rosette Nebula
|
|
||||||
Cashewmeda,Cashew,Andromeda
|
|
||||||
Brazil Nutnova,Brazil Nut,Supernova
|
|
||||||
Cecropiades,Cecropia,Pleiades
|
|
||||||
Balsombrero,Balsa,Sombrero Galaxy
|
|
||||||
Rosewoodway,Rosewood,Milky Way
|
|
||||||
Ipe Helix,Ipe,Helix Nebula
|
|
||||||
Kapoksagittarius,Kapok,Sagittarius
|
|
||||||
Cedrella Cluster,Cedrella,Star Cluster
|
|
||||||
Alerce Lyra,Alerce,Lyra
|
|
||||||
Mahogalactica,Mahogany,Galactic Center
|
|
||||||
Pinwheelnut,Pinwheel,Brazil Nut
|
|
||||||
Tarantularch,Tarantula Nebula,Larch
|
|
||||||
Ceibomeda,Ceiba,Andromeda
|
|
||||||
Pau Brassiopeia,Pau Brasil,Cassiopeia
|
|
||||||
Araucarion,Araucaria,Orion
|
|
||||||
Quebrachole,Quebracho,Black Hole
|
|
||||||
Lapachoway,Lapacho,Milky Way
|
|
||||||
Guanasar,Guanacaste,Quasar
|
|
||||||
Jacaranebula,Jacaranda,Nebula
|
|
||||||
Ceiba Centauri,Ceiba,Alpha Centauri
|
|
||||||
Brazilbeehive,Brazil Nut,Beehive Cluster
|
|
||||||
Monkeypuzzar,Monkey Puzzle,Quasar
|
|
||||||
Quebrachomeda,Quebracho,Andromeda
|
|
||||||
Lapachydes,Lapacho,Hyades
|
|
||||||
Rubberway,Rubber Tree,Milky Way
|
|
||||||
Cashewsar,Cashew,Quasar
|
|
||||||
Nutmeda,Brazil Nut,Andromeda
|
|
||||||
Cecropiagalaxy,Cecropia,Galaxy
|
|
||||||
Balsanova,Balsa,Supernova
|
|
||||||
Rosettewood,Rosette,Rosewood
|
|
||||||
Ipegalaxy,Ipe,Galaxy
|
|
||||||
Kapoknebula,Kapok,Nebula
|
|
||||||
Cedrellaxy,Cedrella,Galaxy
|
|
||||||
Alercentauri,Alerce,Centaurus
|
|
||||||
Mahogacrab,Mahogany,Crab Nebula
|
|
||||||
Eaglebrasil,Eagle Nebula,Pau Brasil
|
|
||||||
Tarantuleia,Tarantula Nebula,Ceiba
|
|
||||||
Whirlpoolnut,Whirlpool,Brazil Nut
|
|
||||||
Araucagalaxy,Araucaria,Galaxy
|
|
||||||
Quebrachiades,Quebracho,Pleiades
|
|
||||||
Lapachomeda,Lapacho,Andromeda
|
|
||||||
Guanacasteroid,Guanacaste,Asteroid
|
|
||||||
Jacarandromeda,Jacaranda,Andromeda
|
|
||||||
Ceibulsar,Ceiba,Pulsar
|
|
||||||
Tadpolebrasil,Tadpole,Pau Brasil
|
|
||||||
Monkeynova,Monkey Puzzle,Supernova
|
|
||||||
Quebrachygnus,Quebracho,Cygnus
|
|
||||||
Lapachoacentauri,Lapacho,Alpha Centauri
|
|
||||||
Rubberhole,Rubber Tree,Black Hole
|
|
||||||
Cashewnova,Cashew,Supernova
|
|
||||||
Brazilbutterfly,Brazil Nut,Butterfly Cluster
|
|
||||||
Cecropiomeda,Cecropia,Andromeda
|
|
||||||
Balsagittarius,Balsa,Sagittarius
|
|
||||||
Rosewoodrion,Rosewood,Orion
|
|
||||||
Ipeleiades,Ipe,Pleiades
|
|
||||||
Kapoksombrero,Kapok,Sombrero Galaxy
|
|
||||||
Cedrellipse,Cedrella,Elliptical Galaxy
|
|
||||||
Alercegalaxy,Alerce,Galaxy
|
|
||||||
Mahogaring,Mahogany,Ring Nebula
|
|
||||||
Cartwheeiba,Cartwheel,Ceiba
|
|
||||||
Pau Brasilian,Pau Brasil,Cassiopeian
|
|
||||||
Araucarionebula,Araucaria,Orion Nebula
|
|
||||||
Quebrasar,Quebracho,Quasar
|
|
||||||
Lapachomega,Lapacho,Omega Centauri
|
|
||||||
Guanacastway,Guanacaste,Milky Way
|
|
||||||
Jacaranovae,Jacaranda,Supernova
|
|
||||||
Ceibachomeda,Ceiba,Andromeda
|
|
||||||
Sunflowerbrasil,Sunflower Galaxy,Pau Brasil
|
|
||||||
Monkeypuzzalaxy,Monkey Puzzle,Galaxy
|
|
||||||
Quebrachoxima,Quebracho,Proxima
|
|
||||||
Lapachosar,Lapacho,Quasar
|
|
||||||
Rubberbula,Rubber Tree,Nebula
|
|
||||||
Cashewcluster,Cashew,Star Cluster
|
|
||||||
Nutway,Brazil Nut,Milky Way
|
|
||||||
Cecropianebula,Cecropia,Nebula
|
|
||||||
Balsagara,Balsa,Sagittarius A*
|
|
||||||
Rosewoodraco,Rosewood,Draco
|
|
||||||
Ipelipse,Ipe,Ellipse
|
|
||||||
Kapokagoon,Kapok,Lagoon Nebula
|
|
||||||
Cedrellaneta,Cedrella,Planetary Nebula
|
|
||||||
Alercerion,Alerce,Orion
|
|
||||||
Mahogacarina,Mahogany,Carina
|
|
||||||
Trifidnut,Trifid Nebula,Brazil Nut
|
|
||||||
Tarantulacho,Tarantula,Lapacho
|
|
||||||
Ceibanova,Ceiba,Supernova
|
|
||||||
Pau Brasilion,Pau Brasil,Orion
|
|
||||||
Araucariades,Araucaria,Pleiades
|
|
||||||
Quebrachoelix,Quebracho,Helix
|
|
||||||
Lapacholia,Lapacho,Magnolia
|
|
||||||
Guanacasar,Guanacaste,Quasar
|
|
||||||
Jacarandromeda,Jacaranda,Andromeda
|
|
||||||
Ceibulsar,Ceiba,Pulsar
|
|
||||||
Titan Brasil,Titan,Pau Brasil
|
|
||||||
Monkeynebula,Monkey Puzzle,Nebula
|
|
||||||
Quebrachomeda,Quebracho,Andromeda
|
|
||||||
Lapachogalaxy,Lapacho,Galaxy
|
|
||||||
Rubbersar,Rubber Tree,Quasar
|
|
||||||
Cashewmeda,Cashew,Andromeda
|
|
||||||
Nutcluster,Brazil Nut,Cluster
|
|
||||||
Cecropioway,Cecropia,Milky Way
|
|
||||||
Balsanebula,Balsa,Nebula
|
|
||||||
Rosewoodway,Rosewood,Milky Way
|
|
||||||
Ipegalaxy,Ipe,Galaxy
|
|
||||||
Kapoksar,Kapok,Quasar
|
|
||||||
Cedrellaxy,Cedrella,Galaxy
|
|
||||||
Alercenova,Alerce,Supernova
|
|
||||||
Mahogalactic,Mahogany,Galactic
|
|
||||||
Sculptorbrasil,Sculptor Galaxy,Pau Brasil
|
|
||||||
Ceibomeda,Ceiba,Andromeda
|
|
||||||
Araucarionway,Araucaria,Milky Way
|
|
||||||
Quebrachion,Quebracho,Orion
|
|
||||||
Lapachohole,Lapacho,Black Hole
|
|
||||||
Guanacastromeda,Guanacaste,Andromeda
|
|
||||||
Jacaranebula,Jacaranda,Nebula
|
|
||||||
Ceibagalaxy,Ceiba,Galaxy
|
|
||||||
Europa Brasil,Europa,Pau Brasil
|
|
||||||
Monkeypuzzar,Monkey Puzzle,Quasar
|
|
||||||
Quebrachnova,Quebracho,Supernova
|
|
||||||
Lapachoides,Lapacho,Hyades
|
|
||||||
Rubbermeda,Rubber Tree,Andromeda
|
|
||||||
Cashewnova,Cashew,Supernova
|
|
||||||
Nutway,Brazil Nut,Milky Way
|
|
||||||
Cecropiagalaxy,Cecropia,Galaxy
|
|
||||||
Balsaquila,Balsa,Aquila
|
|
||||||
Rosewoodsar,Rosewood,Quasar
|
|
||||||
Ipecentauri,Ipe,Alpha Centauri
|
|
||||||
Kapokgalaxy,Kapok,Galaxy
|
|
||||||
Cedrellaneta,Cedrella,Planetary Nebula
|
|
||||||
Alercemeda,Alerce,Andromeda
|
|
||||||
Mahoganova,Mahogany,Supernova
|
|
||||||
Boomerangbrasil,Boomerang Nebula,Pau Brasil
|
|
||||||
Ceibulsar,Ceiba,Pulsar
|
|
||||||
Pau Brasilades,Pau Brasil,Pleiades
|
|
||||||
Araucagalaxy,Araucaria,Galaxy
|
|
||||||
Quebrachomeda,Quebracho,Andromeda
|
|
||||||
Lapachosar,Lapacho,Quasar
|
|
||||||
Guanacastellum,Guanacaste,Magellanic
|
|
||||||
Jacaranovae,Jacaranda,Supernova
|
|
||||||
Ceibaway,Ceiba,Milky Way
|
|
||||||
Enceladnut,Enceladus,Brazil Nut
|
|
||||||
Monkeynebula,Monkey Puzzle,Nebula
|
|
||||||
Quebrachogalaxy,Quebracho,Galaxy
|
|
||||||
Lapachonova,Lapacho,Supernova
|
|
||||||
Rubberion,Rubber Tree,Orion
|
|
||||||
Cashewgalaxy,Cashew,Galaxy
|
|
||||||
Nutsagittarius,Brazil Nut,Sagittarius
|
|
||||||
Cecropia A*,Cecropia,Sagittarius A*
|
|
||||||
Balsanova,Balsa,Supernova
|
|
||||||
Rosewoodmeda,Rosewood,Andromeda
|
|
||||||
Ipesar,Ipe,Quasar
|
|
||||||
Kapokway,Kapok,Milky Way
|
|
||||||
Cedrellipse,Cedrella,Ellipse
|
|
||||||
Alercenebula,Alerce,Nebula
|
|
||||||
Mahogaring,Mahogany,Ring Nebula
|
|
||||||
Cat's Eye Brasil,Cat's Eye,Pau Brasil
|
|
||||||
Ceibomeda,Ceiba,Andromeda
|
|
||||||
Araucarionebula,Araucaria,Orion Nebula
|
|
||||||
Quebrachoides,Quebracho,Hyades
|
|
||||||
Lapachogalaxy,Lapacho,Galaxy
|
|
||||||
Guanacastar,Guanacaste,Quasar
|
|
||||||
Jacarandromeda,Jacaranda,Andromeda
|
|
||||||
Ceibaneta,Ceiba,Planetary Nebula
|
|
||||||
Ganymede Brasil,Ganymede,Pau Brasil
|
|
||||||
Monkeypuzzalaxy,Monkey Puzzle,Galaxy
|
|
||||||
Quebrachonova,Quebracho,Supernova
|
|
||||||
Lapachomeda,Lapacho,Andromeda
|
|
||||||
Rubbersar,Rubber Tree,Quasar
|
|
||||||
Cashewnebula,Cashew,Nebula
|
|
||||||
Nutgalaxy,Brazil Nut,Galaxy
|
|
||||||
Cecropiomeda,Cecropia,Andromeda
|
|
||||||
Balsagittarius,Balsa,Sagittarius
|
|
||||||
Rosewoodion,Rosewood,Orion
|
|
||||||
Ipeleiades,Ipe,Pleiades
|
|
||||||
Kapoknova,Kapok,Supernova
|
|
||||||
Cedrellaxy,Cedrella,Galaxy
|
|
||||||
Alercegalaxy,Alerce,Galaxy
|
|
||||||
Mahogacrab,Mahogany,Crab
|
|
||||||
Dumbbell Brasil,Dumbbell Nebula,Pau Brasil
|
|
||||||
Ceibulsar,Ceiba,Pulsar
|
|
||||||
Pau Brasilway,Pau Brasil,Milky Way
|
|
||||||
Araucarina,Araucaria,Carina
|
|
||||||
Quebrachogalaxy,Quebracho,Galaxy
|
|
||||||
Lapachosar,Lapacho,Quasar
|
|
||||||
Guanacastromeda,Guanacaste,Andromeda
|
|
||||||
Jacaranebula,Jacaranda,Nebula
|
|
||||||
Ceibanova,Ceiba,Supernova
|
|
||||||
Io Brasil,Io,Pau Brasil
|
|
||||||
Monkeypuzzar,Monkey Puzzle,Quasar
|
|
||||||
Quebrachomeda,Quebracho,Andromeda
|
|
||||||
Lapachogalaxy,Lapacho,Galaxy
|
|
||||||
Rubbernova,Rubber Tree,Supernova
|
|
||||||
Cashewmeda,Cashew,Andromeda
|
|
||||||
Nutnebula,Brazil Nut,Nebula
|
|
||||||
Cecropiagalaxy,Cecropia,Galaxy
|
|
||||||
Balsasar,Balsa,Quasar
|
|
||||||
Rosewoodway,Rosewood,Milky Way
|
|
||||||
Ipegalaxy,Ipe,Galaxy
|
|
||||||
Kapokmeda,Kapok,Andromeda
|
|
||||||
Cedrellaneta,Cedrella,Planetary Nebula
|
|
||||||
Alercenova,Alerce,Supernova
|
|
||||||
Mahogalagoon,Mahogany,Lagoon
|
|
||||||
Crescent Brasil,Crescent Nebula,Pau Brasil
|
|
||||||
Ceibagalaxy,Ceiba,Galaxy
|
|
||||||
Araucarionway,Araucaria,Milky Way
|
|
||||||
Quebrachion,Quebracho,Orion
|
|
||||||
Lapachohole,Lapacho,Black Hole
|
|
||||||
Guanacastar,Guanacaste,Quasar
|
|
||||||
Jacaranovo,Jacaranda,Supernova
|
|
||||||
Ceibomeda,Ceiba,Andromeda
|
|
||||||
Callisto Brasil,Callisto,Pau Brasil
|
|
||||||
Monkeynebula,Monkey Puzzle,Nebula
|
|
||||||
Quebrachogalaxy,Quebracho,Galaxy
|
|
||||||
Lapachonova,Lapacho,Supernova
|
|
||||||
Rubbermeda,Rubber Tree,Andromeda
|
|
||||||
Cashewgalaxy,Cashew,Galaxy
|
|
||||||
Nutway,Brazil Nut,Milky Way
|
|
||||||
Cecropiomeda,Cecropia,Andromeda
|
|
||||||
Balsanebula,Balsa,Nebula
|
|
||||||
Rosewoodsar,Rosewood,Quasar
|
|
||||||
Ipecentauri,Ipe,Centauri
|
|
||||||
Kapokgalaxy,Kapok,Galaxy
|
|
||||||
Cedrellaxy,Cedrella,Galaxy
|
|
||||||
Alercemeda,Alerce,Andromeda
|
|
||||||
Mahoganova,Mahogany,Supernova
|
|
||||||
Flame Brasil,Flame Nebula,Pau Brasil
|
|
||||||
Ceibulsar,Ceiba,Pulsar
|
|
||||||
Pau Brasilion,Pau Brasil,Orion
|
|
||||||
Araucagalaxy,Araucaria,Galaxy
|
|
||||||
Quebrachomeda,Quebracho,Andromeda
|
|
||||||
Lapachosar,Lapacho,Quasar
|
|
||||||
Guanacastway,Guanacaste,Milky Way
|
|
||||||
Jacarandromeda,Jacaranda,Andromeda
|
|
||||||
Ceibanova,Ceiba,Supernova
|
|
||||||
Veil Brasil,Veil Nebula,Pau Brasil
|
|
||||||
Monkeypuzzalaxy,Monkey Puzzle,Galaxy
|
|
||||||
Quebrachonova,Quebracho,Supernova
|
|
||||||
Lapachogalaxy,Lapacho,Galaxy
|
|
||||||
Rubberion,Rubber Tree,Orion
|
|
||||||
Cashewnova,Cashew,Supernova
|
|
||||||
Nutgalaxy,Brazil Nut,Galaxy
|
|
||||||
Cecropiagalaxy,Cecropia,Galaxy
|
|
||||||
Balsomeda,Balsa,Andromeda
|
|
||||||
Rosewoodway,Rosewood,Milky Way
|
|
||||||
Ipesar,Ipe,Quasar
|
|
||||||
Kapoknebula,Kapok,Nebula
|
|
||||||
Cedrellaneta,Cedrella,Planetary Nebula
|
|
||||||
Alercenebula,Alerce,Nebula
|
|
||||||
Mahogaring,Mahogany,Ring
|
|
||||||
Pelican Brasil,Pelican Nebula,Pau Brasil
|
|
||||||
Ceibagalaxy,Ceiba,Galaxy
|
|
||||||
Araucarionebula,Araucaria,Orion Nebula
|
|
||||||
Quebrachoides,Quebracho,Hyades
|
|
||||||
Lapachomeda,Lapacho,Andromeda
|
|
||||||
Guanacastar,Guanacaste,Quasar
|
|
||||||
Jacaranovo,Jacaranda,Supernova
|
|
||||||
Ceibulsar,Ceiba,Pulsar
|
|
||||||
Cone Brasil,Cone Nebula,Pau Brasil
|
|
||||||
Monkeypuzzar,Monkey Puzzle,Quasar
|
|
||||||
Quebrachogalaxy,Quebracho,Galaxy
|
|
||||||
Lapachosar,Lapacho,Quasar
|
|
||||||
Rubbernova,Rubber Tree,Supernova
|
|
||||||
Cashewmeda,Cashew,Andromeda
|
|
||||||
Nutway,Brazil Nut,Milky Way
|
|
||||||
Cecropiomeda,Cecropia,Andromeda
|
|
||||||
Balsagalaxy,Balsa,Galaxy
|
|
||||||
Rosewoodion,Rosewood,Orion
|
|
||||||
Ipeleiades,Ipe,Pleiades
|
|
||||||
Kapokgalaxy,Kapok,Galaxy
|
|
||||||
Cedrellaxy,Cedrella,Galaxy
|
|
||||||
Alercegalaxy,Alerce,Galaxy
|
|
||||||
Mahoganova,Mahogany,Supernova
|
|
||||||
Witch Head Brasil,Witch Head,Pau Brasil
|
|
||||||
Ceiboway,Ceiba,Milky Way
|
|
||||||
Pau Brasilmeda,Pau Brasil,Andromeda
|
|
||||||
Araucarina,Araucaria,Carina
|
|
||||||
Quebrachonebula,Quebracho,Nebula
|
|
||||||
Lapachogalaxy,Lapacho,Galaxy
|
|
||||||
Guanacastromeda,Guanacaste,Andromeda
|
|
||||||
Jacaranebula,Jacaranda,Nebula
|
|
||||||
Ceibanova,Ceiba,Supernova
|
|
||||||
Iris Brasil,Iris Nebula,Pau Brasil
|
|
||||||
Monkeynova,Monkey Puzzle,Supernova
|
|
||||||
Quebrachomeda,Quebracho,Andromeda
|
|
||||||
Lapachosar,Lapacho,Quasar
|
|
||||||
Rubbermeda,Rubber Tree,Andromeda
|
|
||||||
Cashewgalaxy,Cashew,Galaxy
|
|
||||||
Nutnebula,Brazil Nut,Nebula
|
|
||||||
Cecropiagalaxy,Cecropia,Galaxy
|
|
||||||
Balsanovo,Balsa,Supernova
|
|
||||||
Rosewoodway,Rosewood,Milky Way
|
|
||||||
Ipegalaxy,Ipe,Galaxy
|
|
||||||
Kapokmeda,Kapok,Andromeda
|
|
||||||
Cedrellaneta,Cedrella,Planetary Nebula
|
|
||||||
Alercenova,Alerce,Supernova
|
|
||||||
Mahogagalaxy,Mahogany,Galaxy
|
|
||||||
Bubble Brasil,Bubble Nebula,Pau Brasil
|
|
||||||
Ceibomeda,Ceiba,Andromeda
|
|
||||||
Araucarionway,Araucaria,Milky Way
|
|
||||||
Quebrachion,Quebracho,Orion
|
|
||||||
Lapachohole,Lapacho,Black Hole
|
|
||||||
Guanacastar,Guanacaste,Quasar
|
|
||||||
Jacaranovo,Jacaranda,Supernova
|
|
||||||
Ceibagalaxy,Ceiba,Galaxy
|
|
||||||
North America Brasil,North America,Pau Brasil
|
|
||||||
Monkeypuzzar,Monkey Puzzle,Quasar
|
|
||||||
Quebrachogalaxy,Quebracho,Galaxy
|
|
||||||
Lapachonova,Lapacho,Supernova
|
|
||||||
Rubbersar,Rubber Tree,Quasar
|
|
||||||
Cashewnebula,Cashew,Nebula
|
|
||||||
Nutgalaxy,Brazil Nut,Galaxy
|
|
||||||
Cecropiomeda,Cecropia,Andromeda
|
|
||||||
Balsoway,Balsa,Milky Way
|
|
||||||
Rosewoodsar,Rosewood,Quasar
|
|
||||||
Ipecentauri,Ipe,Centauri
|
|
||||||
Kapokgalaxy,Kapok,Galaxy
|
|
||||||
Cedrellaxy,Cedrella,Galaxy
|
|
||||||
Alercemeda,Alerce,Andromeda
|
|
||||||
Mahoganova,Mahogany,Supernova
|
|
||||||
Pacman Brasil,Pacman Nebula,Pau Brasil
|
|
||||||
Ceibulsar,Ceiba,Pulsar
|
|
||||||
Pau Brasilades,Pau Brasil,Pleiades
|
|
||||||
Araucagalaxy,Araucaria,Galaxy
|
|
||||||
Quebrachomeda,Quebracho,Andromeda
|
|
||||||
Lapachosar,Lapacho,Quasar
|
|
||||||
Guanacastway,Guanacaste,Milky Way
|
|
||||||
Jacarandromeda,Jacaranda,Andromeda
|
|
||||||
Ceibanova,Ceiba,Supernova
|
|
||||||
Soul Brasil,Soul Nebula,Pau Brasil
|
|
||||||
Monkeynebula,Monkey Puzzle,Nebula
|
|
||||||
Quebrachonova,Quebracho,Supernova
|
|
||||||
Lapachogalaxy,Lapacho,Galaxy
|
|
||||||
Rubberion,Rubber Tree,Orion
|
|
||||||
Cashewnova,Cashew,Supernova
|
|
||||||
Nutway,Brazil Nut,Milky Way
|
|
||||||
Cecropiagalaxy,Cecropia,Galaxy
|
|
||||||
Balsameda,Balsa,Andromeda
|
|
||||||
Rosewoodway,Rosewood,Milky Way
|
|
||||||
Ipesar,Ipe,Quasar
|
|
||||||
Kapoknebula,Kapok,Nebula
|
|
||||||
Cedrellaneta,Cedrella,Planetary Nebula
|
|
||||||
Alercenebula,Alerce,Nebula
|
|
||||||
Mahogaring,Mahogany,Ring
|
|
||||||
Heart Brasil,Heart Nebula,Pau Brasil
|
|
||||||
Ceibagalaxy,Ceiba,Galaxy
|
|
||||||
Araucarionebula,Araucaria,Orion Nebula
|
|
||||||
Quebrachoides,Quebracho,Hyades
|
|
||||||
Lapachomeda,Lapacho,Andromeda
|
|
||||||
Guanacastar,Guanacaste,Quasar
|
|
||||||
Jacaranovo,Jacaranda,Supernova
|
|
||||||
Ceiboway,Ceiba,Milky Way
|
|
||||||
Elephant Trunk Brasil,Elephant Trunk,Pau Brasil
|
|
||||||
Monkeypuzzalaxy,Monkey Puzzle,Galaxy
|
|
||||||
Quebrachogalaxy,Quebracho,Galaxy
|
|
||||||
Lapachosar,Lapacho,Quasar
|
|
||||||
Rubbernova,Rubber Tree,Supernova
|
|
||||||
Cashewmeda,Cashew,Andromeda
|
|
||||||
Nutgalaxy,Brazil Nut,Galaxy
|
|
||||||
Cecropiomeda,Cecropia,Andromeda
|
|
||||||
Balsagalaxy,Balsa,Galaxy
|
|
||||||
Rosewoodion,Rosewood,Orion
|
|
||||||
Ipeleiades,Ipe,Pleiades
|
|
||||||
Kapokgalaxy,Kapok,Galaxy
|
|
||||||
Cedrellaxy,Cedrella,Galaxy
|
|
||||||
Alercegalaxy,Alerce,Galaxy
|
|
||||||
Mahoganova,Mahogany,Supernova
|
|
||||||
Omega Brasil,Omega Nebula,Pau Brasil
|
|
||||||
Ceibulsar,Ceiba,Pulsar
|
|
||||||
Pau Brasilion,Pau Brasil,Orion
|
|
||||||
Araucarina,Araucaria,Carina
|
|
||||||
Quebrachonebula,Quebracho,Nebula
|
|
||||||
Lapachogalaxy,Lapacho,Galaxy
|
|
||||||
Guanacastromeda,Guanacaste,Andromeda
|
|
||||||
Jacaranebula,Jacaranda,Nebula
|
|
||||||
Ceibanova,Ceiba,Supernova
|
|
||||||
Blinking Brasil,Blinking Nebula,Pau Brasil
|
|
||||||
Monkeypuzzar,Monkey Puzzle,Quasar
|
|
||||||
Quebrachomeda,Quebracho,Andromeda
|
|
||||||
Lapachosar,Lapacho,Quasar
|
|
||||||
Rubbermeda,Rubber Tree,Andromeda
|
|
||||||
Cashewgalaxy,Cashew,Galaxy
|
|
||||||
Nutnebula,Brazil Nut,Nebula
|
|
||||||
Cecropiagalaxy,Cecropia,Galaxy
|
|
||||||
Balsanovo,Balsa,Supernova
|
|
||||||
Rosewoodway,Rosewood,Milky Way
|
|
||||||
Ipegalaxy,Ipe,Galaxy
|
|
||||||
Kapokmeda,Kapok,Andromeda
|
|
||||||
Cedrellaneta,Cedrella,Planetary Nebula
|
|
||||||
Alercenova,Alerce,Supernova
|
|
||||||
Mahogagalaxy,Mahogany,Galaxy
|
|
||||||
Ghost Brasil,Ghost Nebula,Pau Brasil
|
|
||||||
Ceibomeda,Ceiba,Andromeda
|
|
||||||
Araucarionway,Araucaria,Milky Way
|
|
||||||
Quebrachion,Quebracho,Orion
|
|
||||||
Lapachohole,Lapacho,Black Hole
|
|
||||||
Guanacastar,Guanacaste,Quasar
|
|
||||||
Jacaranovo,Jacaranda,Supernova
|
|
||||||
Ceibagalaxy,Ceiba,Galaxy
|
|
||||||
Eskimo Brasil,Eskimo Nebula,Pau Brasil
|
|
||||||
Monkeynebula,Monkey Puzzle,Nebula
|
|
||||||
Quebrachogalaxy,Quebracho,Galaxy
|
|
||||||
Lapachonova,Lapacho,Supernova
|
|
||||||
Rubbersar,Rubber Tree,Quasar
|
|
||||||
Cashewnebula,Cashew,Nebula
|
|
||||||
Nutgalaxy,Brazil Nut,Galaxy
|
|
||||||
Cecropioway,Cecropia,Milky Way
|
|
||||||
|
203
docs/AGENT-REFERENCE.md
Normal file
203
docs/AGENT-REFERENCE.md
Normal file
|
|
@ -0,0 +1,203 @@
|
||||||
|
# Detailed Agent Reference — MEMLNaut-NISPS
|
||||||
|
|
||||||
|
Supplement to [`../AGENTS.md`](../AGENTS.md); deep target, schema, build, and verification
|
||||||
|
detail lives here.
|
||||||
|
|
||||||
|
This file provides guidance to coding agents working with this repository.
|
||||||
|
|
||||||
|
## Overview
|
||||||
|
|
||||||
|
MEMLNaut-NISPS — Neural Interactive Shaping of Parameter Spaces. A research platform for interactive ML control of audio. **One C++20 codebase** (`nisps/`) compiles to two targets:
|
||||||
|
|
||||||
|
1. **RP2350 firmware** for the MEMLNaut hardware platform (`firmware/`).
|
||||||
|
2. **WASM** in the Manifold React browser app (`manifold/`) — same engines + ML, run through an AudioWorklet.
|
||||||
|
|
||||||
|
(The former SolidJS playground was retired 2026-07-13 at P1 of `docs/specs/plans/one-core-engine-refactor.md`; archived on branch `archive/playground-solidjs`, tag `playground-solidjs-final`. The browser-only C15 engine currently lives only there.) Parameter contracts are JSON schemas (`schemas/`) with codegen producing the C++ headers AND the TypeScript modules (both live since P5; CI fails if either is stale).
|
||||||
|
|
||||||
|
Project documentation: https://musicallyembodiedml.github.io/memlnaut/approaches/nisps
|
||||||
|
|
||||||
|
For the codebase index, see `MAP.md`. For strategic gaps and open mission questions, see `ALIGNMENT.md`.
|
||||||
|
|
||||||
|
**For anything UI-related in the Manifold front-end (`manifold/`), read `manifold/ONBOARDING.md` first** — it's a single-file agent orientation (run/build/deploy/test, the UI/engine-spine/WASM layering, the convertible Stages, the Dock + drawers, and the non-obvious gotchas).
|
||||||
|
|
||||||
|
## The `nisps/` core
|
||||||
|
|
||||||
|
```
|
||||||
|
nisps/
|
||||||
|
├── core/ types, perf attrs, concepts (AudioEngine, MLEngine, Mode), fixed/ring buffers, deterministic RNG, math
|
||||||
|
├── ml/ MLP class template (4-layer, 3 hidden); SGD, gradient clipping, spread-aware Xavier init,
|
||||||
|
│ RL move_weights with output pin mask + per-layer scaling + weight decay
|
||||||
|
├── dsp/ biquad, delay, reverb, filter, env, osc, pitch_shift, dc_blocker
|
||||||
|
├── engines/ 8 audio engines (paf_synth, channel_strip, xiasri, verb_fx, memlcelium, breakor,
|
||||||
|
│ elysiamorf, analysis) + NoOpEngine. Each satisfies the AudioEngine concept.
|
||||||
|
├── modes/ 8 platform-agnostic modes binding {ML, engine, voice space, abstract I/O channels}.
|
||||||
|
│ CRTP base eliminates the duplication that plagued firmware modes.
|
||||||
|
└── wasm/ Emscripten C API bindings (compiled only for WASM target)
|
||||||
|
```
|
||||||
|
|
||||||
|
Build: `cmake -S nisps -B nisps/build -G Ninja && cmake --build nisps/build && ctest --test-dir nisps/build`.
|
||||||
|
|
||||||
|
Tests: 4 executables (`nisps_core_tests`, `nisps_dsp_engine_tests`, `nisps_modes_tests`, `nisps_golden_tests`). Run all: `bash scripts/build-cpp-tests.sh`. Parity vs WASM: `bash scripts/parity-check.sh` (asserts native and WASM produce identical outputs within 1e-5).
|
||||||
|
|
||||||
|
Throughput: `bash scripts/bench-engines.sh` (per-engine ns/sample, blocks/s, realtime factor on native + WASM; `--compare <report.json>` for deltas). It **reports and never asserts** — no threshold, no failure mode. Read it before and after any change to `nisps/dsp/` or `nisps/engines/`; nothing else in the repo will tell you an engine got slower.
|
||||||
|
|
||||||
|
### Performance contract (RP2350)
|
||||||
|
|
||||||
|
These rules apply to **all** code under `nisps/`. They are inert in WASM but kept globally for consistency.
|
||||||
|
|
||||||
|
- **No heap.** No `new`, `malloc`, `std::vector` in hot paths. Use `std::array<T, N>`. (`nisps::FixedBuffer` is gone — deleted in the Phase 1 sweep; `std::array` was doing the same job.)
|
||||||
|
- **Constants discipline.** Float literals >255 used in hot paths must be `static const float val = X.f;` not inline.
|
||||||
|
- **`.f` suffix on all float literals.** No double promotion in audio/inference paths.
|
||||||
|
- **Hot-path attributes.** Apply `NISPS_HOT` / `NISPS_FORCE_INLINE` (from `nisps/core/perf.hpp`). The SRAM-section macros were deleted in the 2026-07 sweep — they had no real use sites.
|
||||||
|
- **No virtual dispatch in audio path.** `AudioEngine` and `Mode` are C++20 concepts, not interfaces.
|
||||||
|
- **Deterministic RNG.** All RNG state is per-instance; constructors take a seed; cross-platform parity tests rely on this.
|
||||||
|
|
||||||
|
Lint: `bash scripts/lint-cpp.sh` warns on missing `.f` and fails on heap/`Arduino.h` use under `nisps/`.
|
||||||
|
|
||||||
|
## The `firmware/` target
|
||||||
|
|
||||||
|
```
|
||||||
|
firmware/MEMLNaut-NISPS/
|
||||||
|
├── MEMLNaut-NISPS.ino # Entry point; mode selected via #define MEMLNAUT_MODE_TYPE
|
||||||
|
├── glue/
|
||||||
|
│ ├── audio_driver.hpp # memllib AudioDriver block callback → Mode::process per-sample
|
||||||
|
│ ├── peripherals.hpp # joystick / pots / buttons → Mode::set_input + ML primitives
|
||||||
|
│ ├── midi_io.hpp # MIDI in → mode handlers; drain ControlEvent ring → MIDI UART
|
||||||
|
│ ├── mode_select.hpp # type aliases firmware mode name → nisps::modes::*Mode
|
||||||
|
│ ├── output_router.hpp # drain_outputs() entry point
|
||||||
|
│ └── settings_view.hpp # wire_settings(): TFT/rotary menu (Joystick Dual/Single for 4-in modes)
|
||||||
|
└── src/{memllib,nisps} # symlinks (Arduino-CLI sketch tree convention)
|
||||||
|
```
|
||||||
|
|
||||||
|
Build: `scripts/build-firmware.sh [VARIANT]`. Verified compiling for PAFSynth, ChannelStrip, BreakOr on `rp2040:rp2040:solderparty_rp2350_stamp_xl:opt=Optimize3` with `-std=gnu++20`. Flash: `scripts/flash-firmware.sh`. One-shot: `scripts/build-and-flash-firmware.sh`.
|
||||||
|
|
||||||
|
### Dual-core orchestration (firmware)
|
||||||
|
|
||||||
|
- **Core 0**: UI loop, ML inference (`Mode::tick_control`), peripheral polling (5ms period).
|
||||||
|
- **Core 1**: Real-time audio processing (`Mode::process`), MIDI polling.
|
||||||
|
- **Sync**: `nisps::core::ring_buffer` (templated SPSC lock-free, replaces pico/util/queue) + memory barriers (`nisps::core::memory_barrier`, `write_volatile`/`read_volatile`).
|
||||||
|
|
||||||
|
## The `manifold/` target
|
||||||
|
|
||||||
|
```
|
||||||
|
manifold/ # Vite + React + TypeScript (the sole browser app)
|
||||||
|
├── src/
|
||||||
|
│ ├── engine/ # framework-neutral TS engine spine: wasm-iml, engine-host + worklet,
|
||||||
|
│ │ # thin WASM wrappers over nisps/pipeline + the curve catalog (P4), spine.ts, EngineProvider
|
||||||
|
│ ├── primitives/ # 12 design primitives as typed React
|
||||||
|
│ ├── console/ # convertible Console (CompositeStage, Dock, Drawers, Manifold canvas, …)
|
||||||
|
│ ├── dock/, backends/, inputs/, feedback/, settings/, serial/, midi-devices/
|
||||||
|
│ └── debug/probe.ts # window.__nisps behind ?debug=1 for Playwright
|
||||||
|
├── public/ # nisps.{wasm,js} — canonical build-wasm.sh output
|
||||||
|
└── tests/ # e2e Playwright specs + fixtures/ (P4 golden parity fixtures)
|
||||||
|
```
|
||||||
|
|
||||||
|
Dev: `cd manifold && bun install && bun run dev`. Build: `bun run build`. Typecheck: `bun run typecheck`. Unit: `bun run test`. E2E: `bunx playwright test` (on the VPS run the runner via non-snap node — BUILD-PLAN gotcha).
|
||||||
|
|
||||||
|
Read `manifold/ONBOARDING.md` before touching manifold UI — layering, Stages, Dock, gotchas.
|
||||||
|
|
||||||
|
## The `schemas/` + `codegen/` contract
|
||||||
|
|
||||||
|
Each mode has a `schemas/modes/<mode>.json` describing its parameters (name, label, range, default, curve, group), ML config (input/output sizes, hidden layers), voice spaces (names — bodies are inline lambdas in the C++ engine), and UI config. The meta-schema at `schemas/schema.json` validates these.
|
||||||
|
|
||||||
|
Codegen (`bun run codegen/generate.ts`) emits:
|
||||||
|
- `nisps/modes/generated/<mode>_schema.hpp` — `constexpr` C++ data, namespace `nisps::modes::generated`, re-exports `nisps::Curve` from `nisps/core/math.hpp`.
|
||||||
|
- `manifold/src/modes/generated/<mode>_schema.ts` (+ `types.ts`, `index.ts`) — typed const schemas; `MF_MODES` derives params/ml-config from them (P5).
|
||||||
|
|
||||||
|
Codegen validates the firmware fit (exactly 3 hidden layers; dims ≤4096) and is idempotent. The golden test (both languages) runs in `run-all-tests.sh` stage 5.
|
||||||
|
|
||||||
|
## WASM bridge
|
||||||
|
|
||||||
|
Two WASM instances at runtime:
|
||||||
|
|
||||||
|
1. **Main thread** (`manifold/src/engine/wasm-iml.ts`): ML inference + sync training + RL primitives, reporting into an injected `EngineSink`. Async training via disposable Web Worker (`wasm-worker.ts`).
|
||||||
|
2. **AudioWorklet** (`manifold/src/engine/worklet/nisps-processor.ts`): runs engine `process_block` per audio block. Loads `nisps.wasm` directly via `WebAssembly.compile` (no Emscripten glue in worklet). Bytes posted from main thread.
|
||||||
|
|
||||||
|
C API is in `nisps/wasm/bindings.cpp`. Build: `bash scripts/build-wasm.sh` (~94KB output to `manifold/public/`).
|
||||||
|
|
||||||
|
The browser MLP is runtime-shaped since P2 (`MLPCore<DynamicStorage>`): `nisps_ml_create` honours `(input, output, hidden[3])`; non-positive/null args default to `32→[10,14,18]→126`. Raw `nisps_ml_reshape` reconstructs and prefix-warm-starts a new shape. Manifold's higher-level `engine/io-reshape.ts` seam adds stable input/output identity: it can permute weights and examples without reconstruction while capacity suffices, or reconstruct with arbitrary surviving-dimension remaps. Persistent settings select capacity-vs-exact arity and adapt-vs-clear examples (neutral new-input/output defaults 0/0.5); feedback/exploration scratch state resets on either identity edit. Per-mode dims have been schema-real since P5.3 on both targets — modes no longer slice a shared 126-wide default.
|
||||||
|
|
||||||
|
### Known limitations
|
||||||
|
|
||||||
|
- Mic input through the worklet for XIASRI / SoundAnalysisMIDI is not wired in manifold.
|
||||||
|
- C15 has no home on main (see `ALIGNMENT.md` defect 1, browser mode coverage).
|
||||||
|
- (P3, 2026-07-14) The browser Jolt/OU gestures and the geometric dislike run the C++ core through WASM: `nisps_ml_jolt_*`, `nisps_ml_explore_*`, `nisps_ml_feedback_dislike_geometric` — no TS gesture math remains.
|
||||||
|
- (§6.5e, 2026-07-21) The per-iteration loss curve IS plumbed: `nisps_ml_loss_history(ml, out, max)` returns the total entry count and fills `min(count, max)`, so `max=0` is a count probe. Both train paths publish it to the spine; `EngineApi.lossHistory()` reads it and `console/TrainingHealth.tsx` displays it at `expanded` drawer depth. `MLPCore::train()` resets the history per run; `train_targets()` (geometric dislike) does not record.
|
||||||
|
|
||||||
|
## URL parameters (manifold)
|
||||||
|
|
||||||
|
| Param | Range | Default | Effect |
|
||||||
|
|-------|-------|---------|--------|
|
||||||
|
| `debug` | 1 | _(off)_ | Exposes the `window.__nisps` debug probe. |
|
||||||
|
|
||||||
|
(The playground-era `tame`/`spread`/`preset` URL params died with the playground; `spread` survives as an opt-in engine concept — see below.)
|
||||||
|
|
||||||
|
### `spread` — sigmoid saturation control
|
||||||
|
|
||||||
|
The MLP uses ReLU hidden layers with a sigmoid output. With uniform [-1,1] weights, the sum of many weighted inputs at each layer drives sigmoid pre-activations far from zero (std dev ≈ √fan_in), causing outputs to saturate. The `spread` parameter addresses this:
|
||||||
|
|
||||||
|
- `spread=0` (polarised): uniform [-1,1] weights, RL noise cap 0.3, no decay. Outputs cluster at extremes — good for radical exploration.
|
||||||
|
- `spread=1` (centered): Xavier-scaled weights, RL noise cap 0.05, 10% weight decay per move. Outputs spread across [0,1] — better for fine-grained shaping.
|
||||||
|
- Intermediate values interpolate.
|
||||||
|
|
||||||
|
Manifold deliberately defaults to `spread=0` at every browser boundary: initial construction,
|
||||||
|
mode-switch reshape, direct re-roll, explore-and-place scratchpad re-roll, and forwarded VCV
|
||||||
|
randomise. The old schema spread and the expanded Learning-drawer centred switch are available only
|
||||||
|
after enabling Settings → Experimental features → **Xavier / spread randomisation**. This is a
|
||||||
|
Manifold compatibility flag; the shared C++ core and generated mode schemas still expose spread for
|
||||||
|
firmware, VCV, benchmarks, and explicit API callers.
|
||||||
|
|
||||||
|
## Verification chokepoints (user-confirmed)
|
||||||
|
|
||||||
|
- **A. Hardware**: each firmware mode flashes and produces correct audio on RP2350.
|
||||||
|
- **B. RP2350 perf**: no regression vs current main.
|
||||||
|
- **C. Browser parity**: each firmware mode runs in browser via WASM, sounds equivalent.
|
||||||
|
- **D. a-immersive feature parity**: control surface, snapshots, A/B compare, region/param pins, heatmap, weight health, gradient flow, output pipeline, session presets.
|
||||||
|
- **E. CI green**: `bash scripts/run-all-tests.sh` (cmake build + ctest + WASM build + parity + lint + Playwright).
|
||||||
|
|
||||||
|
## Build system summary
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Initialize submodules (required for memllib)
|
||||||
|
git submodule update --init --recursive
|
||||||
|
|
||||||
|
# Codegen (run after editing any schemas/modes/*.json)
|
||||||
|
cd codegen && bun install && bun run generate.ts
|
||||||
|
|
||||||
|
# C++ host tests
|
||||||
|
bash scripts/build-cpp-tests.sh
|
||||||
|
|
||||||
|
# WASM
|
||||||
|
bash scripts/build-wasm.sh
|
||||||
|
|
||||||
|
# Cross-platform parity
|
||||||
|
bash scripts/parity-check.sh
|
||||||
|
|
||||||
|
# Engine throughput (reports; never fails)
|
||||||
|
bash scripts/bench-engines.sh
|
||||||
|
|
||||||
|
# Lint
|
||||||
|
bash scripts/lint-cpp.sh
|
||||||
|
|
||||||
|
# Firmware
|
||||||
|
scripts/build-firmware.sh PAFSynth # or any other variant
|
||||||
|
scripts/flash-firmware.sh
|
||||||
|
scripts/build-and-flash-firmware.sh
|
||||||
|
|
||||||
|
# Manifold
|
||||||
|
cd manifold && bun install
|
||||||
|
bun run dev # Vite dev (COOP/COEP enabled)
|
||||||
|
bun run typecheck
|
||||||
|
bun run test # bun unit tests
|
||||||
|
bun run build
|
||||||
|
bunx playwright test # on the VPS: node node_modules/.bin/playwright test
|
||||||
|
|
||||||
|
# All tests
|
||||||
|
bash scripts/run-all-tests.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
## Issue tracking
|
||||||
|
|
||||||
|
Use `ergo` exclusively for coding-work tasks over the Holon core; see the `ergo` skill.
|
||||||
|
Do not use TodoWrite or markdown task lists. Legacy tracker stores are retired/frozen
|
||||||
|
and reference-only.
|
||||||
248
docs/adr/rl-feedback-design.md
Normal file
248
docs/adr/rl-feedback-design.md
Normal file
|
|
@ -0,0 +1,248 @@
|
||||||
|
# RL / Feedback Learning-Engine Design — Manifold
|
||||||
|
|
||||||
|
*Design sign-off. Dated 2026-06-27. Supersedes the AVOID-out-of-scope decision in `docs/specs/plans/feedback-modes-port-spec.md` §2.5/§7 (reclassified `kind: plan, status: executed` 2026-07-21). Author: lead architect, synthesising a 4-candidate / 4-judge design panel against verified source.*
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 2026-07-25 implementation amendment
|
||||||
|
|
||||||
|
The verified upstream reference is now memllib `e291192`, vendored under
|
||||||
|
`firmware/MEMLNaut-NISPS/lib/memllib/reference/`. Its geometric constants and schedule
|
||||||
|
supersede the older `0a541cc` constants and synchronous-one-shot wording below:
|
||||||
|
|
||||||
|
- push scale `1.0`, negative-LR base `1.5`, no distance taper; cold start pushes in a
|
||||||
|
deterministic random direction;
|
||||||
|
- a press stores the rejection and performs one immediate update, then
|
||||||
|
`FeedbackControllerCore::advance_geometric(dt)` replays **all** live negatives at a
|
||||||
|
configurable rate for a full-strength wall-clock lifetime;
|
||||||
|
- the shared core fallback and Manifold's "Upstream defaults" experiment preset match
|
||||||
|
upstream: LR `0.001`, `200 Hz`, `2500 ms`; rate or lifetime zero is explicit one-shot
|
||||||
|
mode;
|
||||||
|
- after operator calibration on 2026-07-25, Manifold starts at LR `0.003`, `200 Hz`,
|
||||||
|
`2500 ms`; this product default does not change the firmware/core fallback;
|
||||||
|
- the host supplies elapsed time, but target computation and every weight mutation stay
|
||||||
|
in the allocation-free shared C++ core. Native↔WASM parity covers this seam.
|
||||||
|
|
||||||
|
Manifold exposes LR/rate/lifetime at expanded Learning depth. Deliberate divergences are
|
||||||
|
kept current in `ALIGNMENT.md`; source comparison evidence is immutable in
|
||||||
|
`docs/specs/recon/findings-push-away-upstream-comparison.md`.
|
||||||
|
|
||||||
|
## 0. Decision summary
|
||||||
|
|
||||||
|
| Setting | Default | Also selectable |
|
||||||
|
|---|---|---|
|
||||||
|
| `FEEDBACK_MODE` | **Explore and place** (Mode 2, positive-only) | **Geometric dislike** (Mode 1) |
|
||||||
|
| `SOLO_MODE` | **MaskGradients** (final-layer column freeze) | **ZeroLoss**, **DontCareExample** |
|
||||||
|
|
||||||
|
**Winner of the panel:** *Sift* (musician-UX judge topPick, skeptic topPick; 2nd on feasibility and ML). It is the only candidate that does UX design rather than only porting design, and it satisfies the "Mode 2 is NEVER a dislike" requirement at the level of the performer's mental model.
|
||||||
|
|
||||||
|
**Grafted onto Sift's felt-loop spine:**
|
||||||
|
- *Minimal-Divergence* — the **only candidate whose tree-read is correct** (verified below): the feedback C API, `MLHandle.feedback`, the `0xFEEDBACC0DE` salt, `CMakeLists.txt:59` registration, and parity Stage 5 ALL already exist. Its **append-only `FeedbackAction` enum** discipline and **controller-returns-action / caller-owns-training** boundary contract are kept verbatim.
|
||||||
|
- *Anchored-Manifold* — the **only candidate with correct provenance** (the upstream tip is `0a541cc "highlighting"`, verified; not the `e291192`/`abe93ec` the others cite). Its **one-`ReplayStore`-three-features** compression, its **bit-identical-frozen-column solo ctest**, and its **explicit TrainBatch-vs-SGD divergence flag** are adopted.
|
||||||
|
- *Anchor-First* — **keep replay/geometric logic OUT of the MLP kernel** (only minimal backprop hooks go in), and **port the `posMemCount==0` cold-start fallback faithfully** so dislikes-before-any-like don't destabilise the net.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 1. Verified ground truth (read this before building)
|
||||||
|
|
||||||
|
All claims below were read from source on 2026-06-27. Where the four candidates disagreed, the verified fact decides.
|
||||||
|
|
||||||
|
### 1.1 The scaffold already exists (Minimal-Divergence was right)
|
||||||
|
- `nisps/wasm/bindings.cpp:95-116` — `struct MLHandle` already holds `nisps::ml::FeedbackController<DefaultMLP> feedback;` + `feedback_static_scratch{}`, constructed `feedback(seed ^ 0xFEEDBACC0DEull)`.
|
||||||
|
- `nisps/wasm/bindings.cpp:439-535` — the 9 `nisps_ml_feedback_*` C functions (`set_mode`/`get_mode`/`exploring`/`learning_paused`/`set_focus`/`down`/`up`/`drag`/`static_output`) are **already wired**.
|
||||||
|
- `nisps/CMakeLists.txt:58-59` — `test_mlp_rl.cpp` **and** `test_mlp_feedback.cpp` are **already registered** in `nisps_core_tests`.
|
||||||
|
- `tests/cpp/parity_check.cpp:86` — `kVersion = 2u` already; `:198-205` — **Stage 5 (feedback) already exists** seeding `FeedbackController<ParityMLP> fb(kSeed ^ kFeedbackSalt)`.
|
||||||
|
|
||||||
|
> Candidates 2/3/4 proposed *adding* `MLHandle.feedback`, *registering* `test_mlp_feedback.cpp`, and *creating* Stage 5. That is phantom work — they already exist. This design **edits** the existing `on_down` cases and **extends** the existing enum/API/parity-stage; it does not re-scaffold them.
|
||||||
|
|
||||||
|
### 1.2 The current `feedback.hpp` (untracked, verified `nisps/ml/feedback.hpp:1-214`)
|
||||||
|
- `enum FeedbackMode {Avoid=0, RandomiseOutputs=1, RandomiseMlp=2}` (`:47-51`); `enum FeedbackAction {None=0,…Restore=7}` (`:56-65`).
|
||||||
|
- `on_down` Avoid case (`:103-105`) calls `mlp.move_weights(speed, spread, pin_mask)` — the **undirected-diffusion placeholder** the requirement now forbids for Mode 1.
|
||||||
|
- `RandomiseMlp` `on_down` (`:113-119`): 1st press enters (`snapshot_` + `draw_weights`), 2nd press **cancels**. Snapshot/restore is a byte-exact `get_weights`/`set_weights` round-trip (`:186-193`).
|
||||||
|
- The controller has its **own per-instance `Rng rng_`** (`:210`), seeded independently.
|
||||||
|
|
||||||
|
### 1.3 The latest upstream algorithm (Anchored-Manifold's provenance was right)
|
||||||
|
The actual upstream tip is **`0a541cc "highlighting"`** at `/home/w1n5t0n/src/MEMLNaut-NISPS-upstream/src/memllib/examples/InterfaceRL.{hpp,cpp}`. Constants verified:
|
||||||
|
- `InterfaceRL.hpp:293` `kGeometricPushScale = 0.5f`; `:294` `kMaxDislikeMultiplier = 16`; `:296` `kCentroidK = 4`.
|
||||||
|
- `InterfaceRL.cpp:42-66` `_perform_dislike_action()`: nearby negative within Euclidean `0.05f` of `controlInput` → `reward = max(reward-1, -16)`; else `storeExperience(-1, controlInput, action)`; then `dislikeMultiplier_ = min(*2, 16)`.
|
||||||
|
- `InterfaceRL.cpp:602-627` k-NN centroid: average the `kCentroidK=4` positive memories nearest `controlInput` → `meanPositiveAction`.
|
||||||
|
- `InterfaceRL.cpp:664` proportional decay `reward += 0.0025f * max(|reward|, 1.0f)`; expired items removed; `dislikeMultiplier_` halved per expiry (`:752-760`).
|
||||||
|
- `InterfaceRL.cpp:713` `pushStep = clamp(|avgRewardNeg|, 0.25f, 1.0f) * kGeometricPushScale`.
|
||||||
|
- `InterfaceRL.cpp:721-735` per negative: `dir[j] = neg_action[j] - meanPositiveAction[j]`; `len = ||dir||`; `useRandom = (len <= 1e-4f)`; `effectivePushStep = pushStep / (1 + len)`; for each `j` gated by `activeDims_`: `d = useRandom ? (rand()&0xFF/127.5 - 1) : dir[j]/len`; `target[j] = clamp(neg_action[j] + d*effectivePushStep, 0, 1)`.
|
||||||
|
- `InterfaceRL.cpp:742-743` `negLRRatio = 0.5f - 0.4f*negFraction`; train geometric targets at `lr*negLRRatio`.
|
||||||
|
- `InterfaceRL.cpp:746` **cold-start fallback** when `posMemCount==0`: `TrainBatch(tsNegative, lr * 0.1f * avgRewardNeg, …)` — negative-LR training, no geometric push.
|
||||||
|
|
||||||
|
### 1.4 The deepest parity hazard (Anchored-Manifold / Anchor-First flagged it)
|
||||||
|
Upstream `optimise()` trains with **`TrainBatch`** (shuffled, `batchSize≈8`, separate positive/geometric batches at *two distinct* learning rates). The nisps `MLP::train()` (`mlp.hpp:256-300`) is **unshuffled per-sample SGD over the dataset insertion order** (its own comment: *"TrainBatch shuffles, but we're not implementing batch yet"*), has **no reward field** and **no train-toward-arbitrary-targets** entry. Reproducing the two-batch / dynamic-`negLRRatio` dynamics on a non-batch trainer is the real `browser != firmware` line. **We accept behavioural (not bitwise) parity with firmware here, and pin `native == WASM` at 1e-5.** Recorded in `ALIGNMENT.md`.
|
||||||
|
|
||||||
|
### 1.5 The injection points the masking/solo mechanism needs
|
||||||
|
- `mlp.hpp:281` — the per-sample `std::array<float,NOut> deriv{}` is the **exact place** to zero the output-error of non-soloed / don't-care dims before `backprop_` (`:291`). One branch per output dim.
|
||||||
|
- `rl.hpp:74-99` — `move_weights_layer` already skips the final-layer weight **column + bias** when `is_final_layer && output_pin_mask[node] != 0`. Solo's column-freeze is the **bitwise inverse** of this mask. Note the existing rule (`:88-96`): the RNG is advanced even on skipped weights so the stream is pin-independent — keep that invariant.
|
||||||
|
- `mode-runtime.ts:548-565` `thumbsDown` currently builds a pin mask and calls `moveWeights` — **no example stored**, no training. `thumbsUp` (`:523-546`) computes the `(features, labels)` and calls `addExample` + `trainOnCurrent`.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 2. FEEDBACK_MODE = two operator-switchable modes
|
||||||
|
|
||||||
|
The selector is `exploration-store.ts` state `feedbackMode: 'explore-and-place' | 'geometric-dislike'`, surfaced in the **learning-behaviour dock panel** (§7). British spelling in all copy ("randomise", "auditioning", "centre", "behaviour").
|
||||||
|
|
||||||
|
### 2.1 Mode 1 — "Geometric dislike" (negative example + geometric push-away)
|
||||||
|
|
||||||
|
**Felt loop:** you have a region you like; thumbs-down carves the current sound *away* from the liked centroid. Directed repulsion, audibly directional — the fix for today's inaudible undirected diffusion (`findings-feedback-behaviour.md §5`).
|
||||||
|
|
||||||
|
**Algorithm — port `InterfaceRL.cpp` (0a541cc) into nisps core, keeping parity.** Because nisps has no async `optimise()` driver, the press-time half (`_perform_dislike_action`) and the optimise half collapse into one synchronous core call.
|
||||||
|
|
||||||
|
On thumbs-down at `controlInput x_neg` with heard action `a_neg`:
|
||||||
|
1. `replay.deepen_or_store_negative(x_neg, a_neg, radius=0.05f)` — nearby negative → `reward = max(reward-1, -16.f)`; else store `reward=-1`. `dislikeMultiplier_ = min(*2, 16)`. (`InterfaceRL.cpp:42-66`)
|
||||||
|
2. If `replay.positive_count() == 0` → **cold-start fallback**: `train_targets(x_neg → a_neg, lr * 0.1f * avgRewardNeg, …)` (`InterfaceRL.cpp:746`). Surface a one-time UI prompt *"like a few sounds first to teach the system what to move away from"* (closes the cold-start gap all four judges flagged).
|
||||||
|
3. Else: `replay.knn_positive_centroid(x_neg, k=4, &mean)` (`:602-627`); `pushStep = clamp(|avgRewardNeg|, 0.25f, 1.0f) * 0.5f`; per active/soloed dim `j`: `dir[j]=a_neg[j]-mean[j]`, `len=||dir||`, `effectivePushStep=pushStep/(1+len)`, `d = (len<=1e-4f) ? rng_.next_float_signed() : dir[j]/len`, `target[j]=clamp(a_neg[j]+d*effectivePushStep, 0, 1)`; non-active dims keep `a_neg[j]`.
|
||||||
|
4. `train_targets(x_neg → target, lr * negLRRatio, …)` with `negLRRatio = 0.5f - 0.4f*negFraction`.
|
||||||
|
5. `replay.decay_negatives()` each call: `reward += 0.0025f*max(|reward|,1)`, evict `reward > -0.01f`.
|
||||||
|
|
||||||
|
**Determinism carve-out:** the upstream `useRandom` branch uses libc `rand()&0xFF`; we substitute `rng_.next_float_signed()` (the controller's own per-instance `nisps::Rng`). Both native and WASM run the same Rng from the same seed → 1e-5 parity holds. This branch only fires when a disliked action sits exactly on the centroid. Record as the single deliberate firmware divergence in `ALIGNMENT.md`.
|
||||||
|
|
||||||
|
**On thumbs-up** (Mode 1): `replay.store(+1, x, a)` so the centroid sees positives; caller also runs the existing `addExample`+`train` like today.
|
||||||
|
|
||||||
|
**Files touched:** edit `feedback.hpp` `on_down` Avoid case (`:103-105`) → route to the geometric path; add `replay_` member; `on_up` LikeStore → `replay.store(+1,…)`. New `nisps/ml/replay.hpp` + `nisps/ml/geo_push.hpp` (§4). `move_weights` stays reachable as a **legacy `Diffuse` sub-mode** for A/B comparison (cheap insurance, lets the A/B-compare feature contrast geometric vs diffusion — graft from Minimal-Divergence).
|
||||||
|
|
||||||
|
### 2.2 Mode 2 — "Explore and place" (positive-only; NEVER a dislike) — **DEFAULT**
|
||||||
|
|
||||||
|
**Felt loop (Sift's north star):** *"randomise, explore, oh I like that → put it in that corner; meh, randomise…"*. The performer never reasons about "away from what" — they collect sounds they like. Place-by-corner is the **highest audible-effect-per-action gesture in the system**: one drop = one heard anchor the real model then interpolates.
|
||||||
|
|
||||||
|
Built on the existing `RandomiseMlp` scaffold (`feedback.hpp:113-119,183-201`) but to the stricter spec. Lifecycle state machine in the reworked `FeedbackController`, `FeedbackMode::ExploreAndPlace`:
|
||||||
|
|
||||||
|
1. **ENTER** (verdict-down/explore): `enter_scratchpad(mlp, spread)` — snapshot the real trained net into `snapshot_` (the set-aside model; existing `get_weights` round-trip), set `learning_paused_=true` (gates `trainOnCurrent` + auto-explore, mirroring upstream `optimiseSometimes` early-return), then `draw_weights(spread)` → **random scratchpad net**.
|
||||||
|
2. **SCRATCHPAD OPS — exactly two, position-agnostic, never trained, never a dislike:**
|
||||||
|
- `reroll()` = `draw_weights(spread)` again ("meh, randomise…"). Re-press while exploring **re-rolls** (returns `Reroll`); a dedicated cancel gesture / mode-switch aborts. (This changes the old 2nd-press-cancels semantics — deliberate; rewrite the affected ctest.)
|
||||||
|
- `nudge(speed, spread)` = a small `move_weights` on the scratchpad with a templated undo ring `scratch_undo_` (depth `D`; **WASM `D=4`, firmware `D=2`** via template param — Sift's free SRAM tunable). `undo_nudge()` pops. Reuses the byte-exact `get_weights`/`set_weights` round-trip (graft: no new parity surface). New actions `ScratchNudge`, `ScratchUndo`.
|
||||||
|
- The scratchpad is **NEVER trained and NEVER reads replay** — auditioning is pure forward inference as the user sweeps the joystick.
|
||||||
|
3. **PLACE** (user likes a sound): press → **choose a location** in input space → release. `place_begin()` freezes the current scratchpad output vector into `placed_out_` (so the heard sound is held while the user aims; emitted via the existing `static_output` bypass hook so the audition doesn't change). The TS runtime owns the "aim" UI (a JoyMap drag). On release: caller sets the scratchpad input to `chosen_input`, runs `mlp.process()`, reads outputs, calls `place_commit(chosen_input, scratch_out_at_chosen)` → appends a **positive anchor** and returns `AnchorPlaced`. The controller does NOT itself run inference (keeps it pure — Minimal-Divergence's boundary contract).
|
||||||
|
4. **WARM-START INTERPOLATION** (explicit "Done"/finalise gesture): restore the set-aside net (`set_weights(snapshot_)`), then warm-start it to interpolate **all placed anchors**. **Decision (graft from all four risk-lists): warm-start is ADDITIVE — anchors are added to the existing dataset, NOT `clear_examples()`+refit** — so the user's prior thumbs-up likes are not clobbered. The caller loops `addExample(input, output)` over `replay.anchors()` then `train(lr, maxIter, minErr)` (caller owns training). "Warm-start" = begin from the *restored real net*, not a fresh draw, so prior structure is preserved. Returns `WarmStarted`; `learning_paused_` flips false.
|
||||||
|
5. **ABORT** (mode-switch / cancel): restore the set-aside net, discard anchors not yet finalised.
|
||||||
|
|
||||||
|
**Anchor store** = the same `ReplayStore` instance, positives only (§4). **Coupling decision (Sift's flag):** unifying Mode-1 replay and Mode-2 anchors into one store means a placed anchor also feeds Mode-1's positive centroid. This is a *feature* (mixed-mode sessions), but expose an operator toggle `unifyMemories` (default on) so they can be isolated into two `ReplayStore` instances if surprising.
|
||||||
|
|
||||||
|
**Why Mode 2 is the default:** highest audible-effect-per-action, no negative concept to learn, and it directly realises the operator's stated felt loop. Mode 1 is the precision/sculpting tool for when you already have a liked region.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 3. SOLO / arm per output
|
||||||
|
|
||||||
|
State: `solo_mask_ : std::array<std::uint8_t, kNOut>` on the controller (`1`=armed/soloed, `0`=frozen; all-zero / empty ⇒ none soloed ⇒ normal training). API `set_solo_mask(span)` / `clear_solo_mask()`, C API `nisps_ml_feedback_set_solo(ml, mask, n)` (mirrors the existing `set_focus` at `bindings.cpp:485`). One operator setting `SOLO_MODE {MaskGradients=0, ZeroLoss=1, DontCareExample=2}`.
|
||||||
|
|
||||||
|
All three flow through **one injection point** — the per-sample `deriv` array at `mlp.hpp:281`, fused per Sift's graft (zeroing the loss on non-soloed outputs *is* the don't-care mask).
|
||||||
|
|
||||||
|
### 3.1 MaskGradients (DEFAULT) — column-freeze
|
||||||
|
Predictable: "only this output moves." Derive `pin_mask = bitwise-NOT(solo_mask)` over outputs. In a new `train_masked(lr, max_iter, min_err, out_mask)`: zero `deriv[j]` for non-soloed `j` **before** `backprop_`, **and** freeze hidden layers when any solo is active (skip `layer0_/1_/2_.apply_grad`; apply only `layer3_` for soloed columns). Result: non-soloed final-layer columns AND all hidden weights are **bit-identical** after training. This is the exact inverse of `rl.hpp:74-99`'s pin gating — minimal new code, reuses proven machinery.
|
||||||
|
|
||||||
|
### 3.2 ZeroLoss (selectable) — expressive-but-bleeds
|
||||||
|
Zero `deriv[j]` for non-soloed `j` but **let hidden layers update**. The soloed output gets the full network's expressive capacity, but non-soloed outputs can drift via shared hidden features. One-line variant of 3.1 (drop the hidden-layer freeze).
|
||||||
|
|
||||||
|
### 3.3 DontCareExample (selectable) — most faithful to "store with a mask"
|
||||||
|
Each `ReplayStore` item carries `uint8 mask[NOut]`. An example placed while output `k` is soloed stores `mask = {0…1@k…0}`; `train_masked` consumes the per-example mask so other outputs at that input are never pulled toward a stale label. Survives later training. Costs `Cap*NOut` bytes.
|
||||||
|
|
||||||
|
### 3.4 Honest limit (Sift's correctness graft — into product copy + ALIGNMENT.md)
|
||||||
|
**On a shared-trunk MLP, NO realisation both fully isolates AND stays expressive.** MaskGradients is predictable but weak (only the final linear column moves; hidden capacity frozen). ZeroLoss is expressive but bleeds through shared hidden weights. State this to the operator in the dock panel ("solo freezes the rest as far as a shared network allows") rather than overselling "leaves others unchanged". MaskGradients is the safe default because its guarantee is *provable* (§6.3 bit-identical ctest).
|
||||||
|
|
||||||
|
**Solo is honoured in both modes:** Mode-1 geometric `target` only pushes soloed dims (unify `solo_mask_` with the `activeDims_` gate at `InterfaceRL.cpp:730` — Anchor-First's graft); Mode-2 warm-start trains anchors only on soloed dims when solo is active.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 4. Core component changes (keep replay OUT of the MLP kernel — Anchor-First)
|
||||||
|
|
||||||
|
### New `nisps/ml/replay.hpp`
|
||||||
|
`ReplayStore<NIn, NOut, Cap>` — fixed `std::array` ring (no heap; **WASM `Cap=64`, firmware `Cap=16-32` via template param** — Anchored-Manifold's free SRAM/centroid tradeoff). Item `{std::array<float,NIn> input; std::array<float,NOut> action; float reward; std::uint8_t mask[NOut];}`. Methods (all deterministic, per-instance `nisps::Rng`, **no libc rand**):
|
||||||
|
- `deepen_or_store_negative(x, a, radius=0.05f)` (`InterfaceRL.cpp:42-66`)
|
||||||
|
- `store(reward, x, a, mask)` / `positive_count()`
|
||||||
|
- `knn_positive_centroid(x, k=4, &mean, &count)` — linear scan, fixed top-k insertion (no `std::sort`, no heap). **Deterministic tie-break by index** and **fixed accumulation order** so native==WASM (the classic float-sum parity trap).
|
||||||
|
- `decay_negatives()` (`reward += 0.0025f*max(|reward|,1)`, evict `> -0.01f`)
|
||||||
|
- `anchors()` / `anchor_count()` accessors for Mode-2 warm-start replay.
|
||||||
|
|
||||||
|
### New `nisps/ml/geo_push.hpp`
|
||||||
|
Pure free function `compute_push_targets(replay, control_input, solo_mask, rng, &target_buf)` implementing `InterfaceRL.cpp:602-738` exactly. Writes into a caller-supplied scratch buffer (no heap). Keeps the geometric math out of both MLP and controller.
|
||||||
|
|
||||||
|
### `nisps/ml/mlp.hpp` — minimal backprop hooks only
|
||||||
|
- `train_targets(span inputs, span targets, span sample_weights, span out_mask, lr)` — trains toward *computed* target vectors (Mode-1 geometric batch; targets are computed, not stored labels). Reuses `forward_`/`backprop_`/`apply_grad`.
|
||||||
|
- `train_masked(lr, max_iter, min_err, span out_mask)` — the solo path: zeroes `deriv[j]` at `:281` for masked `j`; in MaskGradients freezes hidden `apply_grad`.
|
||||||
|
- Factor the inner forward→loss→backprop of `train()` into a `train_pair_` helper so both reuse the proven backprop (Minimal-Divergence graft). **No replay/centroid/anchor logic in MLP.**
|
||||||
|
|
||||||
|
### `nisps/ml/feedback.hpp` — edits (append-only enum)
|
||||||
|
- Add `ReplayStore<NIn,NOut> replay_`, `solo_mask_`, `scratch_undo_` ring (templated depth), `placed_out_`, `SoloMode` field.
|
||||||
|
- Edit `on_down` Avoid case → geometric push via `replay_` + `geo_push` + `train_targets`; keep a `Diffuse` legacy sub-mode.
|
||||||
|
- Edit `RandomiseMlp`/`ExploreAndPlace` `on_down` so re-press = `Reroll`.
|
||||||
|
- Add `nudge`/`undo_nudge`, `place_begin`/`place_commit`, `finalise`/`abort`, `set_solo_mask`/`clear_solo_mask`, `set_solo_mode`.
|
||||||
|
- **Append** new `FeedbackAction` values keeping existing numeric values stable: `GeometricPush=8, ScratchNudge=9, ScratchUndo=10, AnchorPlaced=11, WarmStarted=12` (Minimal-Divergence's single most parity-safe decision — never renumber the TS↔C++ contract).
|
||||||
|
|
||||||
|
### `nisps/wasm/bindings.cpp` — extend the existing block (`:439-535`)
|
||||||
|
Add: `nisps_ml_feedback_set_solo(ml,mask,n)`, `_set_solo_mode(ml,mode)`, `_nudge(ml,speed,spread)`, `_undo_nudge(ml)`, `_place_begin(ml,current_out)`, `_place_commit(ml,chosen_input,scratch_out)`, `_anchor_count(ml)`, `_get_anchors(ml,buf)`, `_finalise(ml)`, `_abort(ml)`. Existing `_down/_up/_drag/_static_output` stay; `_down` now returns the new action ints. Reuse the existing scratch buffers + guard/cast style.
|
||||||
|
|
||||||
|
### TS
|
||||||
|
- `playground/src/ml/types.ts` — add the new `_nisps_ml_feedback_*` decls; extend `FeedbackMode`/`FeedbackAction`/add `SoloMode` enums (numeric parity with C++).
|
||||||
|
- `playground/src/ml/wasm-iml.ts` — thin wrappers (`feedbackNudge`, `feedbackPlaceCommit`, `feedbackFinalise`, `feedbackSetSolo`, `getAnchors`); reuse `pinMaskBuf` (`:225`); add a small anchor heap buffer.
|
||||||
|
- `playground/src/modes/mode-runtime.ts` — route `thumbsDown` (`:548`) per active `feedbackMode`; Mode-2 wires press→aim→release to `place_begin`/`place_commit`; a "Done" button → `finalise` → loop `getAnchors`→`addExample`→`train`. Gate `trainOnCurrent` (`:516`) and auto-explore on `learning_paused()`.
|
||||||
|
- `playground/src/stores/exploration-store.ts` — add `feedbackMode`, `soloMode`, `soloMask`, `exploring`, `anchorCount`, `unifyMemories` + selectors.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 5. Phased integration plan (TS-prototype-first; each step gated on `parity-check.sh`)
|
||||||
|
|
||||||
|
**Audible validation is the gate, not green tests.** Prototype the arithmetic in pure TS — driven through the EXISTING `WasmIML` primitives (`drawWeights`, `moveWeights`, `addExample`, `train`, `getWeights`/`setWeights`, `setInput`/`process`/`getOutputs`, verified at `wasm-iml.ts:293-476`) — before any new C++.
|
||||||
|
|
||||||
|
### Phase 0 — TS prototype (no new WASM)
|
||||||
|
A throwaway TS module mirrors `ReplayStore` + `geo_push` + `train_masked`, computed in TS and fed to the real net via existing calls. Oracles:
|
||||||
|
- **Mode 1:** like 2-3 sounds in distinct corners; dislike a sound near one like; confirm the heard 126-vector at that input moves **audibly AWAY** from the liked timbre (not random wobble). A/B against today's `moveWeights` thumbs-down using the existing A/B-compare feature — directionality must be **perceptible** (Sift's oracle).
|
||||||
|
- **Mode 2:** randomise → sweep-audition → "like that" → place in a corner → randomise → place opposite corner → Done → sweep the JoyMap and confirm a **smooth morph between the two placed timbres**, and that re-randomising no longer destroys them.
|
||||||
|
- **Solo:** solo output 0, train, confirm via the heatmap / weight-health views that only that param's mapping changed (MaskGradients: bit-stable elsewhere).
|
||||||
|
- Use `window.__nisps` (`setInputs`/`getOutputs`/`train`/`thumbsDown`/`getLayerStats`) for scripted Playwright checks.
|
||||||
|
|
||||||
|
**Gate:** felt loops audibly correct → freeze `kCentroidK`, `pushStep`, warm-start iteration count, undo depth. Only then crystallise.
|
||||||
|
|
||||||
|
### Phase 1 — C++ core
|
||||||
|
Add `replay.hpp`, `geo_push.hpp`, the `mlp.hpp` hooks, the `feedback.hpp` edits. Build `nisps_core_tests` (`-Wall -Wextra -Werror`). **Gate:** new ctest cases green (§6.1); `scripts/parity-check.sh` still 1e-5 (existing Stage 5 unchanged at this point).
|
||||||
|
|
||||||
|
### Phase 2 — C API
|
||||||
|
Add the new `nisps_ml_feedback_*` exports. Rebuild WASM (`scripts/build-wasm.sh`). **Gate:** `parity-check.sh` green after Stage-5 extension (§6.2); `kVersion` bump.
|
||||||
|
|
||||||
|
### Phase 3 — TS FFI
|
||||||
|
`types.ts` decls + enums, `wasm-iml.ts` wrappers. **Gate:** `bun run typecheck`; a TS↔WASM smoke test reproducing a Phase-0 loop through the real FFI matches the TS prototype's outputs; `parity-check.sh` green.
|
||||||
|
|
||||||
|
### Phase 4 — UI selector in the learning-behaviour dock panel
|
||||||
|
`exploration-store` state + the dock-panel `FEEDBACK_MODE` selector ("Explore and place" / "Geometric dislike"), `SOLO_MODE` selector, exploring/anchor indicators, the cold-start prompt, the honest solo-limit copy (British spelling). **Gate:** `bunx playwright test` (the e2e felt-loop specs); full `scripts/run-all-tests.sh` (chokepoint E) green.
|
||||||
|
|
||||||
|
### Phase 5 — firmware readiness (gated, not on the critical path)
|
||||||
|
Confirm RP2350 SRAM budget with firmware `Cap`/undo-depth template params (`ReplayStore<2,126,16>` + anchors + `scratch_undo_` depth 2). Verify chokepoint A (audio correct) / B (no perf regression) before flashing. Re-pin the orphaned memllib `4733ca0` to `0a541cc`.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 6. Parity + perf contract
|
||||||
|
|
||||||
|
Native==WASM within 1e-5 is preserved because **every new operation is deterministic f32 arithmetic on the per-instance `nisps::Rng`** (no libc `rand()` anywhere). Both sides run the same Rng from the same seed (`kSeed ^ kFeedbackSalt`, matching the `MLHandle` `0xFEEDBACC0DE` salt).
|
||||||
|
|
||||||
|
### 6.1 Host ctest (`tests/cpp/test_mlp_feedback.cpp`, already registered)
|
||||||
|
Rewrite the cases that encode the old 2nd-press-cancels state machine (deliberate break). Add: replay dedup/deepen at 0.05; k-NN centroid selection + deterministic tie-break; geometric push direction sign (target moves away from centroid); taper; cold-start `posMemCount==0` fallback; **solo bit-identical assertion** — after `train_masked` with MaskGradients, non-soloed final-layer columns are `==` (not 1e-5-near) to pre-train (Anchored-Manifold's stronger-than-parity oracle); scratchpad-never-trained invariant; place→warm-start reachability (both anchors reproduced at their corners); determinism under fixed seed.
|
||||||
|
|
||||||
|
### 6.2 Native↔WASM parity (`parity_check.cpp` + `parity_wasm.mjs`, bump `kVersion`)
|
||||||
|
Extend Stage 5: **(S5a Mode 1)** seed `ParityMLP`+`ReplayStore`, store 3 fixed positives + 1 negative, run geometric push (centroid→target→`train_targets`), push 126 post-train probe outputs both sides. **(S5b Mode 2)** enter scratchpad, reroll×2, nudge, undo, place 2 anchors at fixed inputs, finalise (warm-start at fixed lr/iters/seed), push probe outputs + 12 weight probes. **(S5c Solo)** set `solo_mask={1,0,…}`, `train_masked`, assert non-soloed columns byte-identical pre/post. `scripts/parity-check.sh` float32-diffs at 1e-5 — new floats covered automatically.
|
||||||
|
|
||||||
|
### 6.3 Perf contract
|
||||||
|
`replay.hpp` + anchors + `solo_mask_` + `scratch_undo_` are all fixed `std::array` (Cap/depth compile-time, zero heap). Hot loops O(Cap*NOut) over fixed arrays; `roll`/`centroid`/`train_pair_` marked `NISPS_FORCE_INLINE` where hot; `.f` on every literal (`0.0025f`, `0.25f`, `0.5f`, `16.f`, `0.05f`). No virtual dispatch (plain template). Feedback runs on the **control core, never the audio ISR** (mirrors firmware `loopCallback`) → chokepoint B structurally satisfied. SRAM budget tuned per-target via `Cap`/depth template params.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 7. UI — learning-behaviour dock panel
|
||||||
|
|
||||||
|
- **`FEEDBACK_MODE` segmented control:** *Explore and place* (default) / *Geometric dislike*. One-line description per mode in the operator's language.
|
||||||
|
- **`SOLO_MODE` selector** (visible when any output is armed): *Mask gradients* (default) / *Zero loss* / *Don't-care example*, with the honest "as far as a shared network allows" caveat.
|
||||||
|
- **Exploring indicator** + **anchor count** during Mode-2 sessions; a **Done / finalise** button and a **cancel** gesture; nudge + undo controls.
|
||||||
|
- **Cold-start prompt** (Mode 1, zero positives): *"Like a few sounds first so the system knows what to move away from."*
|
||||||
|
- **`unifyMemories` toggle** (advanced): share likes/dislikes across modes (default on).
|
||||||
|
- Copy uses British spelling throughout.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 8. ALIGNMENT.md updates (same commit as the code)
|
||||||
|
1. **RETRACT** the `feedback-modes-port-spec.md §2.5/§7` "geometric push out of scope / AVOID = move_weights" accepted-divergence note — Mode 1 now ports the latest upstream. Without this, a future session will "rediscover" the geometric push as scope creep.
|
||||||
|
2. Record the **single deliberate firmware divergence**: the `useRandom` degenerate branch uses `nisps::Rng`, not libc `rand()` (value generated, never compared; native==WASM holds).
|
||||||
|
3. Record the **TrainBatch-vs-unshuffled-SGD** behavioural divergence: nisps trains per-sample SGD, not shuffled two-LR batches — `browser != firmware` behaviourally, by design (separate verification targets).
|
||||||
|
4. State the **shared-trunk solo limit** as accepted: no realisation both perfectly isolates and stays expressive.
|
||||||
|
5. Re-pin orphaned memllib `4733ca0` → `0a541cc`.
|
||||||
3
docs/redesign/README.md
Normal file
3
docs/redesign/README.md
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
# Design Documentation
|
||||||
|
|
||||||
|
Design docs have moved to `docs/specs/` (see `docs/specs/MAIN.md` for the corpus entry point). Only `manifold-export/` (design-token and UI-kit asset export) remains here.
|
||||||
|
|
@ -0,0 +1,54 @@
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Manifold ControlAxis — a named macro slider with bipolar endpoint labels
|
||||||
|
* (e.g. Boldness: Caution ↔ Bold). Shows a live preset tag and value. The
|
||||||
|
* track accent can be themed per-axis via `accent`.
|
||||||
|
*/
|
||||||
|
export function ControlAxis({ label, endpoints = ['', ''], value = 0.5, onChange, preset, accent = 'var(--accent)', disabled = false, style }) {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column',
|
||||||
|
gap: 'var(--sp-1)',
|
||||||
|
background: 'var(--bg-1)',
|
||||||
|
border: '1px solid var(--line)',
|
||||||
|
borderRadius: 'var(--r-2)',
|
||||||
|
padding: 'var(--sp-2) var(--sp-3)',
|
||||||
|
fontFamily: 'var(--font-mono)',
|
||||||
|
opacity: disabled ? 0.5 : 1,
|
||||||
|
pointerEvents: disabled ? 'none' : 'auto',
|
||||||
|
...style,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div style={{ display: 'flex', alignItems: 'center', gap: 'var(--sp-2)', fontSize: 'var(--fs-sm)' }}>
|
||||||
|
<span style={{ fontWeight: 600, textTransform: 'uppercase', letterSpacing: '0.08em', color: 'var(--fg)', flex: 1 }}>{label}</span>
|
||||||
|
{preset && <span style={{ color: accent, fontSize: 'var(--fs-xs)', textTransform: 'uppercase', letterSpacing: '0.06em' }}>{preset}</span>}
|
||||||
|
<span style={{ fontVariantNumeric: 'tabular-nums', color: 'var(--fg-mute)', fontSize: 'var(--fs-xs)', minWidth: '4ch', textAlign: 'right' }}>{value.toFixed(2)}</span>
|
||||||
|
</div>
|
||||||
|
<input
|
||||||
|
type="range"
|
||||||
|
min={0}
|
||||||
|
max={1}
|
||||||
|
step={0.01}
|
||||||
|
value={value}
|
||||||
|
disabled={disabled}
|
||||||
|
onChange={(e) => onChange && onChange(parseFloat(e.target.value))}
|
||||||
|
className="mf-axis-input"
|
||||||
|
style={{ WebkitAppearance: 'none', appearance: 'none', width: '100%', height: 24, background: 'transparent', margin: 0, cursor: 'pointer', '--mf-axis-accent': accent }}
|
||||||
|
/>
|
||||||
|
<div style={{ display: 'flex', justifyContent: 'space-between', fontSize: 10, textTransform: 'uppercase', letterSpacing: '0.08em', color: 'var(--fg-dim)' }}>
|
||||||
|
<span>{endpoints[0]}</span>
|
||||||
|
<span>{endpoints[1]}</span>
|
||||||
|
</div>
|
||||||
|
<style dangerouslySetInnerHTML={{ __html: `
|
||||||
|
.mf-axis-input::-webkit-slider-runnable-track { height: 6px; border-radius: 999px; background: var(--bg-3); }
|
||||||
|
.mf-axis-input::-moz-range-track { height: 6px; border-radius: 999px; background: var(--bg-3); }
|
||||||
|
.mf-axis-input::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 18px; height: 18px; border-radius: 50%; background: var(--mf-axis-accent, var(--accent)); margin-top: -6px; box-shadow: 0 0 10px var(--mf-axis-accent, var(--accent)); cursor: pointer; }
|
||||||
|
.mf-axis-input::-moz-range-thumb { width: 18px; height: 18px; border-radius: 50%; background: var(--mf-axis-accent, var(--accent)); border: none; box-shadow: 0 0 10px var(--mf-axis-accent, var(--accent)); }
|
||||||
|
.mf-axis-input:focus { outline: none; }
|
||||||
|
` }} />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,80 @@
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Manifold VirtualJoystick — circular control. Drag the glowing orange knob;
|
||||||
|
* motion is constrained to the circle. Emits normalized (x, y) in [0,1], y-up.
|
||||||
|
*/
|
||||||
|
export function VirtualJoystick({ size = 200, position, onMove, onGrab, onRelease, disabled = false, ariaLabel = 'virtual joystick', style }) {
|
||||||
|
const [internal, setInternal] = React.useState([0.5, 0.5]);
|
||||||
|
const [dragging, setDragging] = React.useState(false);
|
||||||
|
const ref = React.useRef(null);
|
||||||
|
const pos = position || internal;
|
||||||
|
|
||||||
|
const update = (e) => {
|
||||||
|
const el = ref.current;
|
||||||
|
if (!el) return;
|
||||||
|
const r = el.getBoundingClientRect();
|
||||||
|
let x = Math.max(0, Math.min(1, (e.clientX - r.left) / r.width));
|
||||||
|
let y = Math.max(0, Math.min(1, 1 - (e.clientY - r.top) / r.height));
|
||||||
|
const dx = x - 0.5, dy = y - 0.5;
|
||||||
|
const dist = Math.sqrt(dx * dx + dy * dy);
|
||||||
|
if (dist > 0.5 && dist > 1e-12) { x = 0.5 + (dx / dist) * 0.5; y = 0.5 + (dy / dist) * 0.5; }
|
||||||
|
if (!position) setInternal([x, y]);
|
||||||
|
onMove && onMove(x, y);
|
||||||
|
};
|
||||||
|
|
||||||
|
const down = (e) => { if (disabled) return; e.currentTarget.setPointerCapture?.(e.pointerId); setDragging(true); onGrab && onGrab(); update(e); };
|
||||||
|
const move = (e) => { if (dragging) update(e); };
|
||||||
|
const up = (e) => { if (!dragging) return; e.currentTarget.releasePointerCapture?.(e.pointerId); setDragging(false); onRelease && onRelease(); };
|
||||||
|
|
||||||
|
const [x, y] = pos;
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
ref={ref}
|
||||||
|
role="application"
|
||||||
|
aria-label={ariaLabel}
|
||||||
|
tabIndex={disabled ? -1 : 0}
|
||||||
|
onPointerDown={down}
|
||||||
|
onPointerMove={move}
|
||||||
|
onPointerUp={up}
|
||||||
|
onPointerCancel={up}
|
||||||
|
style={{
|
||||||
|
position: 'relative',
|
||||||
|
width: size,
|
||||||
|
height: size,
|
||||||
|
background: 'var(--bg-1)',
|
||||||
|
border: '1px solid var(--line)',
|
||||||
|
borderRadius: '50%',
|
||||||
|
touchAction: 'none',
|
||||||
|
cursor: dragging ? 'grabbing' : 'grab',
|
||||||
|
outline: 'none',
|
||||||
|
userSelect: 'none',
|
||||||
|
overflow: 'hidden',
|
||||||
|
opacity: disabled ? 0.4 : 1,
|
||||||
|
pointerEvents: disabled ? 'none' : 'auto',
|
||||||
|
...style,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div style={{ position: 'absolute', inset: '6%', borderRadius: '50%', border: '1px dashed var(--line-strong)', pointerEvents: 'none' }} />
|
||||||
|
<div aria-hidden="true" style={{ position: 'absolute', inset: 0, opacity: 0.4, pointerEvents: 'none' }}>
|
||||||
|
<div style={{ position: 'absolute', left: 0, right: 0, top: '50%', height: 1, background: 'var(--line-strong)' }} />
|
||||||
|
<div style={{ position: 'absolute', top: 0, bottom: 0, left: '50%', width: 1, background: 'var(--line-strong)' }} />
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
aria-hidden="true"
|
||||||
|
style={{
|
||||||
|
position: 'absolute',
|
||||||
|
top: 0,
|
||||||
|
left: 0,
|
||||||
|
width: 24,
|
||||||
|
height: 24,
|
||||||
|
borderRadius: '50%',
|
||||||
|
background: 'var(--accent)',
|
||||||
|
boxShadow: '0 0 12px var(--glow-accent)',
|
||||||
|
transform: `translate(${x * size}px, ${(1 - y) * size}px) translate(-50%, -50%)`,
|
||||||
|
pointerEvents: 'none',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
83
docs/redesign/manifold-export/components/control/XYPad.jsx
Normal file
83
docs/redesign/manifold-export/components/control/XYPad.jsx
Normal file
|
|
@ -0,0 +1,83 @@
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Manifold XYPad — square control surface. Drag the glowing cyan dot; emits
|
||||||
|
* normalized (x, y) in [0,1] with y-up. Uncontrolled by default; pass
|
||||||
|
* `position` + `onMove` to control it.
|
||||||
|
*/
|
||||||
|
export function XYPad({ size = 240, showGrid = true, position, onMove, onGrab, onRelease, disabled = false, ariaLabel = 'XY pad', style }) {
|
||||||
|
const [internal, setInternal] = React.useState([0.5, 0.5]);
|
||||||
|
const [dragging, setDragging] = React.useState(false);
|
||||||
|
const ref = React.useRef(null);
|
||||||
|
const pos = position || internal;
|
||||||
|
|
||||||
|
const update = (e) => {
|
||||||
|
const el = ref.current;
|
||||||
|
if (!el) return;
|
||||||
|
const r = el.getBoundingClientRect();
|
||||||
|
const x = Math.max(0, Math.min(1, (e.clientX - r.left) / r.width));
|
||||||
|
const y = Math.max(0, Math.min(1, 1 - (e.clientY - r.top) / r.height));
|
||||||
|
if (!position) setInternal([x, y]);
|
||||||
|
onMove && onMove(x, y);
|
||||||
|
};
|
||||||
|
|
||||||
|
const down = (e) => {
|
||||||
|
if (disabled) return;
|
||||||
|
e.currentTarget.setPointerCapture?.(e.pointerId);
|
||||||
|
setDragging(true); onGrab && onGrab(); update(e);
|
||||||
|
};
|
||||||
|
const move = (e) => { if (dragging) update(e); };
|
||||||
|
const up = (e) => { if (!dragging) return; e.currentTarget.releasePointerCapture?.(e.pointerId); setDragging(false); onRelease && onRelease(); };
|
||||||
|
|
||||||
|
const [x, y] = pos;
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
ref={ref}
|
||||||
|
role="application"
|
||||||
|
aria-label={ariaLabel}
|
||||||
|
tabIndex={disabled ? -1 : 0}
|
||||||
|
onPointerDown={down}
|
||||||
|
onPointerMove={move}
|
||||||
|
onPointerUp={up}
|
||||||
|
onPointerCancel={up}
|
||||||
|
style={{
|
||||||
|
position: 'relative',
|
||||||
|
width: size,
|
||||||
|
height: size,
|
||||||
|
background: 'var(--bg-1)',
|
||||||
|
border: '1px solid var(--line)',
|
||||||
|
borderRadius: 'var(--r-2)',
|
||||||
|
touchAction: 'none',
|
||||||
|
cursor: 'crosshair',
|
||||||
|
outline: 'none',
|
||||||
|
userSelect: 'none',
|
||||||
|
overflow: 'hidden',
|
||||||
|
opacity: disabled ? 0.4 : 1,
|
||||||
|
pointerEvents: disabled ? 'none' : 'auto',
|
||||||
|
...style,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{showGrid && (
|
||||||
|
<div aria-hidden="true" style={{ position: 'absolute', inset: 0, opacity: 0.5, pointerEvents: 'none' }}>
|
||||||
|
<div style={{ position: 'absolute', left: 0, right: 0, top: '50%', height: 1, background: 'var(--line-strong)' }} />
|
||||||
|
<div style={{ position: 'absolute', top: 0, bottom: 0, left: '50%', width: 1, background: 'var(--line-strong)' }} />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
<div
|
||||||
|
aria-hidden="true"
|
||||||
|
style={{
|
||||||
|
position: 'absolute',
|
||||||
|
top: 0,
|
||||||
|
left: 0,
|
||||||
|
width: 14,
|
||||||
|
height: 14,
|
||||||
|
borderRadius: '50%',
|
||||||
|
background: 'var(--accent-2)',
|
||||||
|
boxShadow: '0 0 10px var(--glow-accent-2)',
|
||||||
|
transform: `translate(${x * size}px, ${(1 - y) * size}px) translate(-50%, -50%)`,
|
||||||
|
pointerEvents: 'none',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
41
docs/redesign/manifold-export/components/core/Badge.jsx
Normal file
41
docs/redesign/manifold-export/components/core/Badge.jsx
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
const TONES = {
|
||||||
|
neutral: { fg: 'var(--fg-mute)', bd: 'var(--line)', bg: 'var(--bg-2)' },
|
||||||
|
accent: { fg: 'var(--accent)', bd: 'rgba(255,106,0,0.4)', bg: 'rgba(255,106,0,0.12)' },
|
||||||
|
good: { fg: 'var(--good)', bd: 'rgba(107,194,107,0.4)', bg: 'rgba(107,194,107,0.14)' },
|
||||||
|
warn: { fg: 'var(--warn)', bd: 'rgba(245,196,94,0.4)', bg: 'rgba(245,196,94,0.14)' },
|
||||||
|
bad: { fg: 'var(--bad)', bd: 'rgba(239,91,91,0.4)', bg: 'rgba(239,91,91,0.14)' },
|
||||||
|
info: { fg: 'var(--info)', bd: 'rgba(91,158,239,0.4)', bg: 'rgba(91,158,239,0.14)' },
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Manifold Badge — small status capsule. `dot` prepends a status dot;
|
||||||
|
* `tone` sets the color. Use for state labels (frozen, training, healthy).
|
||||||
|
*/
|
||||||
|
export function Badge({ children, tone = 'neutral', dot = false, style }) {
|
||||||
|
const t = TONES[tone] || TONES.neutral;
|
||||||
|
return (
|
||||||
|
<span
|
||||||
|
style={{
|
||||||
|
display: 'inline-flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
gap: 'var(--sp-1)',
|
||||||
|
fontFamily: 'var(--font-mono)',
|
||||||
|
fontSize: 'var(--fs-xs)',
|
||||||
|
textTransform: 'uppercase',
|
||||||
|
letterSpacing: '0.06em',
|
||||||
|
color: t.fg,
|
||||||
|
background: t.bg,
|
||||||
|
border: `1px solid ${t.bd}`,
|
||||||
|
borderRadius: 'var(--r-pill)',
|
||||||
|
padding: '2px 10px',
|
||||||
|
lineHeight: 1.6,
|
||||||
|
...style,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{dot && <span style={{ width: 6, height: 6, borderRadius: '50%', background: t.fg, boxShadow: `0 0 6px ${t.fg}` }} />}
|
||||||
|
{children}
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
}
|
||||||
92
docs/redesign/manifold-export/components/core/Button.jsx
Normal file
92
docs/redesign/manifold-export/components/core/Button.jsx
Normal file
|
|
@ -0,0 +1,92 @@
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Manifold Button — terminal-styled action.
|
||||||
|
* Variants: primary (solid orange), secondary (outlined raised), ghost (text).
|
||||||
|
* Sizes: sm, md, lg. Optional leading glyph.
|
||||||
|
*/
|
||||||
|
export function Button({
|
||||||
|
children,
|
||||||
|
variant = 'secondary',
|
||||||
|
size = 'md',
|
||||||
|
disabled = false,
|
||||||
|
glyph,
|
||||||
|
active = false,
|
||||||
|
type = 'button',
|
||||||
|
onClick,
|
||||||
|
style,
|
||||||
|
...rest
|
||||||
|
}) {
|
||||||
|
const sizes = {
|
||||||
|
sm: { padding: '4px 12px', fontSize: 'var(--fs-xs)', height: 28 },
|
||||||
|
md: { padding: '8px 12px', fontSize: 'var(--fs-sm)', height: 34 },
|
||||||
|
lg: { padding: '10px 18px', fontSize: 'var(--fs-md)', height: 44 },
|
||||||
|
};
|
||||||
|
const s = sizes[size] || sizes.md;
|
||||||
|
|
||||||
|
const base = {
|
||||||
|
display: 'inline-flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
gap: 'var(--sp-2)',
|
||||||
|
fontFamily: 'var(--font-mono)',
|
||||||
|
fontSize: s.fontSize,
|
||||||
|
height: s.height,
|
||||||
|
padding: s.padding,
|
||||||
|
borderRadius: 'var(--r-1)',
|
||||||
|
border: '1px solid var(--line)',
|
||||||
|
cursor: disabled ? 'not-allowed' : 'pointer',
|
||||||
|
userSelect: 'none',
|
||||||
|
transition: 'background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease)',
|
||||||
|
whiteSpace: 'nowrap',
|
||||||
|
};
|
||||||
|
|
||||||
|
const variants = {
|
||||||
|
primary: {
|
||||||
|
background: 'var(--accent)',
|
||||||
|
borderColor: 'var(--accent)',
|
||||||
|
color: 'var(--bg)',
|
||||||
|
fontWeight: 600,
|
||||||
|
},
|
||||||
|
secondary: {
|
||||||
|
background: active ? 'var(--bg-3)' : 'var(--bg-2)',
|
||||||
|
borderColor: active ? 'var(--accent)' : 'var(--line)',
|
||||||
|
color: active ? 'var(--accent)' : 'var(--fg)',
|
||||||
|
},
|
||||||
|
ghost: {
|
||||||
|
background: 'transparent',
|
||||||
|
borderColor: 'transparent',
|
||||||
|
color: active ? 'var(--accent)' : 'var(--fg-mute)',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const disabledStyle = disabled
|
||||||
|
? { opacity: 0.45, color: 'var(--fg-dim)', boxShadow: 'none' }
|
||||||
|
: null;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<button
|
||||||
|
type={type}
|
||||||
|
disabled={disabled}
|
||||||
|
onClick={onClick}
|
||||||
|
style={{ ...base, ...(variants[variant] || variants.secondary), ...disabledStyle, ...style }}
|
||||||
|
onMouseEnter={(e) => {
|
||||||
|
if (disabled) return;
|
||||||
|
if (variant === 'secondary') { e.currentTarget.style.background = 'var(--bg-3)'; e.currentTarget.style.borderColor = 'var(--line-strong)'; }
|
||||||
|
if (variant === 'ghost') e.currentTarget.style.color = 'var(--fg)';
|
||||||
|
if (variant === 'primary') e.currentTarget.style.background = 'var(--accent-3)';
|
||||||
|
}}
|
||||||
|
onMouseLeave={(e) => {
|
||||||
|
if (disabled) return;
|
||||||
|
const v = variants[variant] || variants.secondary;
|
||||||
|
e.currentTarget.style.background = v.background;
|
||||||
|
e.currentTarget.style.borderColor = v.borderColor;
|
||||||
|
e.currentTarget.style.color = v.color;
|
||||||
|
}}
|
||||||
|
{...rest}
|
||||||
|
>
|
||||||
|
{glyph && <span aria-hidden="true" style={{ fontSize: '1.1em', lineHeight: 1 }}>{glyph}</span>}
|
||||||
|
{children}
|
||||||
|
</button>
|
||||||
|
);
|
||||||
|
}
|
||||||
30
docs/redesign/manifold-export/components/core/Panel.jsx
Normal file
30
docs/redesign/manifold-export/components/core/Panel.jsx
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Manifold Panel — the house surface: bg-1 fill, 1px hairline border, 8px
|
||||||
|
* radius, no shadow. Optional header row with an uppercase title + actions,
|
||||||
|
* separated by a hairline.
|
||||||
|
*/
|
||||||
|
export function Panel({ title, label, actions, children, padding = 'var(--sp-3)', style }) {
|
||||||
|
return (
|
||||||
|
<section
|
||||||
|
style={{
|
||||||
|
background: 'var(--bg-1)',
|
||||||
|
border: '1px solid var(--line)',
|
||||||
|
borderRadius: 'var(--r-2)',
|
||||||
|
fontFamily: 'var(--font-mono)',
|
||||||
|
color: 'var(--fg)',
|
||||||
|
...style,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{(title || label || actions) && (
|
||||||
|
<header style={{ display: 'flex', alignItems: 'center', gap: 'var(--sp-2)', padding: 'var(--sp-2) var(--sp-3)', borderBottom: '1px solid var(--line)' }}>
|
||||||
|
{label && <span style={{ fontSize: 'var(--fs-xs)', color: 'var(--fg-dim)', textTransform: 'uppercase', letterSpacing: '0.08em' }}>{label}</span>}
|
||||||
|
{title && <h3 style={{ margin: 0, fontSize: 'var(--fs-sm)', fontWeight: 600, color: 'var(--fg)' }}>{title}</h3>}
|
||||||
|
{actions && <div style={{ marginLeft: 'auto', display: 'flex', gap: 'var(--sp-2)' }}>{actions}</div>}
|
||||||
|
</header>
|
||||||
|
)}
|
||||||
|
<div style={{ padding }}>{children}</div>
|
||||||
|
</section>
|
||||||
|
);
|
||||||
|
}
|
||||||
55
docs/redesign/manifold-export/components/core/PillToggle.jsx
Normal file
55
docs/redesign/manifold-export/components/core/PillToggle.jsx
Normal file
|
|
@ -0,0 +1,55 @@
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Manifold PillToggle — segmented radio control in a pill capsule.
|
||||||
|
* The selected segment fills solid orange. Options: [{value,label}].
|
||||||
|
*/
|
||||||
|
export function PillToggle({ options = [], value, onChange, ariaLabel = 'segmented control', disabled = false, style }) {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
role="radiogroup"
|
||||||
|
aria-label={ariaLabel}
|
||||||
|
style={{
|
||||||
|
display: 'inline-flex',
|
||||||
|
background: 'var(--bg-2)',
|
||||||
|
border: '1px solid var(--line)',
|
||||||
|
borderRadius: 'var(--r-pill)',
|
||||||
|
padding: 2,
|
||||||
|
gap: 2,
|
||||||
|
opacity: disabled ? 0.5 : 1,
|
||||||
|
pointerEvents: disabled ? 'none' : 'auto',
|
||||||
|
...style,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{options.map((opt) => {
|
||||||
|
const selected = value === opt.value;
|
||||||
|
return (
|
||||||
|
<button
|
||||||
|
key={opt.value}
|
||||||
|
type="button"
|
||||||
|
role="radio"
|
||||||
|
aria-checked={selected}
|
||||||
|
onClick={() => onChange && onChange(opt.value)}
|
||||||
|
style={{
|
||||||
|
background: selected ? 'var(--accent)' : 'transparent',
|
||||||
|
color: selected ? 'var(--bg)' : 'var(--fg-mute)',
|
||||||
|
border: 0,
|
||||||
|
borderRadius: 'var(--r-pill)',
|
||||||
|
padding: '6px 14px',
|
||||||
|
fontFamily: 'var(--font-mono)',
|
||||||
|
fontSize: 'var(--fs-xs)',
|
||||||
|
textTransform: 'uppercase',
|
||||||
|
letterSpacing: '0.08em',
|
||||||
|
cursor: 'pointer',
|
||||||
|
transition: 'background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease)',
|
||||||
|
}}
|
||||||
|
onMouseEnter={(e) => { if (!selected) e.currentTarget.style.color = 'var(--fg)'; }}
|
||||||
|
onMouseLeave={(e) => { if (!selected) e.currentTarget.style.color = 'var(--fg-mute)'; }}
|
||||||
|
>
|
||||||
|
{opt.label}
|
||||||
|
</button>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
63
docs/redesign/manifold-export/components/core/Slider.jsx
Normal file
63
docs/redesign/manifold-export/components/core/Slider.jsx
Normal file
|
|
@ -0,0 +1,63 @@
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Manifold Slider — labeled horizontal range with a glowing orange thumb and
|
||||||
|
* a tabular value readout. Controlled via value/onChange (0..max).
|
||||||
|
*/
|
||||||
|
export function Slider({
|
||||||
|
label,
|
||||||
|
value = 0,
|
||||||
|
min = 0,
|
||||||
|
max = 1,
|
||||||
|
step = 0.01,
|
||||||
|
unit = '',
|
||||||
|
onChange,
|
||||||
|
disabled = false,
|
||||||
|
format,
|
||||||
|
style,
|
||||||
|
}) {
|
||||||
|
const pct = max > min ? (value - min) / (max - min) : 0;
|
||||||
|
const display = format ? format(value) : (Number.isInteger(step) ? value : value.toFixed(2));
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div style={{ display: 'flex', flexDirection: 'column', gap: 'var(--sp-1)', fontFamily: 'var(--font-mono)', userSelect: 'none', opacity: disabled ? 0.5 : 1, pointerEvents: disabled ? 'none' : 'auto', ...style }}>
|
||||||
|
{label && (
|
||||||
|
<span style={{ color: 'var(--fg-mute)', fontSize: 'var(--fs-xs)', textTransform: 'uppercase', letterSpacing: '0.06em' }}>{label}</span>
|
||||||
|
)}
|
||||||
|
<div style={{ display: 'flex', gap: 'var(--sp-3)', alignItems: 'center' }}>
|
||||||
|
<input
|
||||||
|
type="range"
|
||||||
|
min={min}
|
||||||
|
max={max}
|
||||||
|
step={step}
|
||||||
|
value={value}
|
||||||
|
disabled={disabled}
|
||||||
|
onChange={(e) => onChange && onChange(parseFloat(e.target.value))}
|
||||||
|
style={{
|
||||||
|
flex: 1,
|
||||||
|
WebkitAppearance: 'none',
|
||||||
|
appearance: 'none',
|
||||||
|
background: 'transparent',
|
||||||
|
height: 24,
|
||||||
|
margin: 0,
|
||||||
|
cursor: 'pointer',
|
||||||
|
'--mf-pct': `${pct}`,
|
||||||
|
}}
|
||||||
|
className="mf-slider-input"
|
||||||
|
/>
|
||||||
|
<span style={{ fontVariantNumeric: 'tabular-nums', fontSize: 'var(--fs-xs)', color: 'var(--fg-mute)', minWidth: '4ch', textAlign: 'right' }}>
|
||||||
|
{display}{unit && <span style={{ color: 'var(--fg-dim)', marginLeft: 2 }}>{unit}</span>}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<style dangerouslySetInnerHTML={{ __html: `
|
||||||
|
.mf-slider-input::-webkit-slider-runnable-track { height: 4px; border-radius: 999px; background: linear-gradient(to right, var(--accent) 0%, var(--accent) calc(var(--mf-pct) * 100%), var(--bg-3) 0%); }
|
||||||
|
.mf-slider-input::-moz-range-track { height: 4px; border-radius: 999px; background: var(--bg-3); }
|
||||||
|
.mf-slider-input::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 16px; height: 16px; border-radius: 50%; background: var(--accent); margin-top: -6px; box-shadow: 0 0 8px var(--glow-accent); cursor: pointer; transition: transform var(--dur-fast) var(--ease); }
|
||||||
|
.mf-slider-input::-moz-range-thumb { width: 16px; height: 16px; border-radius: 50%; background: var(--accent); border: none; box-shadow: 0 0 8px var(--glow-accent); }
|
||||||
|
.mf-slider-input:hover::-webkit-slider-thumb { transform: scale(1.15); }
|
||||||
|
.mf-slider-input:focus { outline: none; }
|
||||||
|
.mf-slider-input:focus::-webkit-slider-thumb { box-shadow: 0 0 0 3px var(--glow-focus); }
|
||||||
|
` }} />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
43
docs/redesign/manifold-export/components/core/StatusLine.jsx
Normal file
43
docs/redesign/manifold-export/components/core/StatusLine.jsx
Normal file
|
|
@ -0,0 +1,43 @@
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Manifold StatusLine — the dim mono readout strip at the bottom of a mode.
|
||||||
|
* Pass an array of items; strings render plain, {label,value,tone} render a
|
||||||
|
* labeled readout. Items are joined with the house middle-dot separator.
|
||||||
|
*/
|
||||||
|
export function StatusLine({ items = [], style }) {
|
||||||
|
return (
|
||||||
|
<p
|
||||||
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
flexWrap: 'wrap',
|
||||||
|
alignItems: 'center',
|
||||||
|
gap: 'var(--sp-2)',
|
||||||
|
margin: 0,
|
||||||
|
fontFamily: 'var(--font-mono)',
|
||||||
|
fontSize: 'var(--fs-xs)',
|
||||||
|
color: 'var(--fg-dim)',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{items.map((it, i) => {
|
||||||
|
const isObj = it && typeof it === 'object';
|
||||||
|
const toneColor = isObj && it.tone
|
||||||
|
? { accent: 'var(--accent)', cyan: 'var(--accent-2)', good: 'var(--good)', warn: 'var(--warn)', bad: 'var(--bad)' }[it.tone]
|
||||||
|
: null;
|
||||||
|
return (
|
||||||
|
<React.Fragment key={i}>
|
||||||
|
{i > 0 && <span aria-hidden="true">·</span>}
|
||||||
|
{isObj ? (
|
||||||
|
<span style={{ color: toneColor || 'var(--fg-dim)' }}>
|
||||||
|
{it.label && <span style={{ color: 'var(--fg-dim)' }}>{it.label} </span>}
|
||||||
|
<span style={{ fontVariantNumeric: 'tabular-nums', color: toneColor || 'var(--fg-mute)' }}>{it.value}</span>
|
||||||
|
</span>
|
||||||
|
) : (
|
||||||
|
<span>{it}</span>
|
||||||
|
)}
|
||||||
|
</React.Fragment>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</p>
|
||||||
|
);
|
||||||
|
}
|
||||||
44
docs/redesign/manifold-export/components/core/Switch.jsx
Normal file
44
docs/redesign/manifold-export/components/core/Switch.jsx
Normal file
|
|
@ -0,0 +1,44 @@
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Manifold Switch — compact toggle. On = orange track + glow. Optional label.
|
||||||
|
*/
|
||||||
|
export function Switch({ checked = false, onChange, label, disabled = false, style }) {
|
||||||
|
return (
|
||||||
|
<label style={{ display: 'inline-flex', alignItems: 'center', gap: 'var(--sp-2)', fontFamily: 'var(--font-mono)', fontSize: 'var(--fs-sm)', color: 'var(--fg)', cursor: disabled ? 'not-allowed' : 'pointer', opacity: disabled ? 0.5 : 1, userSelect: 'none', ...style }}>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
role="switch"
|
||||||
|
aria-checked={checked}
|
||||||
|
disabled={disabled}
|
||||||
|
onClick={() => onChange && onChange(!checked)}
|
||||||
|
style={{
|
||||||
|
position: 'relative',
|
||||||
|
width: 36,
|
||||||
|
height: 20,
|
||||||
|
padding: 0,
|
||||||
|
borderRadius: 'var(--r-pill)',
|
||||||
|
border: `1px solid ${checked ? 'var(--accent)' : 'var(--line)'}`,
|
||||||
|
background: checked ? 'var(--accent)' : 'var(--bg-2)',
|
||||||
|
cursor: disabled ? 'not-allowed' : 'pointer',
|
||||||
|
transition: 'background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease)',
|
||||||
|
boxShadow: checked ? '0 0 8px var(--glow-accent)' : 'none',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
style={{
|
||||||
|
position: 'absolute',
|
||||||
|
top: 2,
|
||||||
|
left: checked ? 18 : 2,
|
||||||
|
width: 14,
|
||||||
|
height: 14,
|
||||||
|
borderRadius: '50%',
|
||||||
|
background: checked ? 'var(--bg)' : 'var(--fg-mute)',
|
||||||
|
transition: 'left var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease)',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</button>
|
||||||
|
{label && <span>{label}</span>}
|
||||||
|
</label>
|
||||||
|
);
|
||||||
|
}
|
||||||
66
docs/redesign/manifold-export/components/data/CurvePlot.jsx
Normal file
66
docs/redesign/manifold-export/components/data/CurvePlot.jsx
Normal file
|
|
@ -0,0 +1,66 @@
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
const clamp01 = (v) => (v < 0 ? 0 : v > 1 ? 1 : v);
|
||||||
|
|
||||||
|
const CURVES = {
|
||||||
|
linear: (x) => x,
|
||||||
|
exp: (x) => (Math.exp(4 * x) - 1) / (Math.exp(4) - 1),
|
||||||
|
log: (x) => Math.log(1 + x * (Math.exp(4) - 1)) / 4,
|
||||||
|
square: (x) => x * x,
|
||||||
|
sqrt: (x) => Math.sqrt(clamp01(x)),
|
||||||
|
sigmoid: (x) => { const s = (v) => 1 / (1 + Math.exp(-(v - 0.5) * 8)); const lo = s(0), hi = s(1); return (s(x) - lo) / (hi - lo); },
|
||||||
|
cubic: (x) => { const v = clamp01(x); return v * v * (3 - 2 * v); },
|
||||||
|
centered_power: (x) => { const o = x - 0.5, sg = o < 0 ? -1 : 1; return clamp01((sg * Math.pow(Math.abs(o) * 2, 0.5)) / 2 + 0.5); },
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Manifold CurvePlot — renders one of the named response curves (or a custom
|
||||||
|
* function f:[0,1]→[0,1]) on the dark grid. The brand's straight-line &
|
||||||
|
* parabolic/bézier motif.
|
||||||
|
*/
|
||||||
|
export function CurvePlot({ curve = 'cubic', fn, width = 200, height = 120, color = 'var(--accent)', showAxes = true, ariaLabel, style }) {
|
||||||
|
const ref = React.useRef(null);
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
const cv = ref.current;
|
||||||
|
if (!cv) return;
|
||||||
|
const dpr = window.devicePixelRatio || 1;
|
||||||
|
const w = width * dpr, h = height * dpr;
|
||||||
|
cv.width = w; cv.height = h;
|
||||||
|
const ctx = cv.getContext('2d');
|
||||||
|
if (!ctx) return;
|
||||||
|
ctx.clearRect(0, 0, w, h);
|
||||||
|
const cs = getComputedStyle(cv);
|
||||||
|
const resolve = (c) => { ctx.fillStyle = c; return ctx.fillStyle; };
|
||||||
|
const stroke = color.startsWith('var(') ? cs.getPropertyValue(color.slice(4, -1).trim()).trim() || '#ff6a00' : color;
|
||||||
|
const pad = 6 * dpr;
|
||||||
|
|
||||||
|
if (showAxes) {
|
||||||
|
ctx.strokeStyle = 'rgba(255,255,255,0.06)';
|
||||||
|
ctx.lineWidth = 1;
|
||||||
|
ctx.strokeRect(0.5, 0.5, w - 1, h - 1);
|
||||||
|
ctx.beginPath(); ctx.moveTo(0, h / 2); ctx.lineTo(w, h / 2); ctx.stroke();
|
||||||
|
ctx.beginPath(); ctx.moveTo(w / 2, 0); ctx.lineTo(w / 2, h); ctx.stroke();
|
||||||
|
}
|
||||||
|
const f = fn || CURVES[curve] || CURVES.linear;
|
||||||
|
ctx.strokeStyle = stroke;
|
||||||
|
ctx.lineWidth = 2 * dpr;
|
||||||
|
ctx.beginPath();
|
||||||
|
for (let p = 0; p <= 120; p++) {
|
||||||
|
const x = p / 120, y = clamp01(f(x));
|
||||||
|
const px = pad + x * (w - 2 * pad);
|
||||||
|
const py = (h - pad) - y * (h - 2 * pad);
|
||||||
|
p === 0 ? ctx.moveTo(px, py) : ctx.lineTo(px, py);
|
||||||
|
}
|
||||||
|
ctx.stroke();
|
||||||
|
}, [curve, fn, width, height, color, showAxes]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<canvas
|
||||||
|
ref={ref}
|
||||||
|
role="img"
|
||||||
|
aria-label={ariaLabel || `${curve} curve`}
|
||||||
|
style={{ display: 'block', width, height, background: 'var(--bg-1)', border: '1px solid var(--line)', borderRadius: 'var(--r-2)', ...style }}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
62
docs/redesign/manifold-export/components/data/Sparkline.jsx
Normal file
62
docs/redesign/manifold-export/components/data/Sparkline.jsx
Normal file
|
|
@ -0,0 +1,62 @@
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Manifold Sparkline — a compact time-series trace (training loss, a feature
|
||||||
|
* envelope). Cyan line on a faint grid, with an optional last-value readout.
|
||||||
|
*/
|
||||||
|
export function Sparkline({ data = [], width = 320, height = 70, color = 'var(--accent-2)', log = false, showLast = true, format, ariaLabel = 'time series', style }) {
|
||||||
|
const ref = React.useRef(null);
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
const cv = ref.current;
|
||||||
|
if (!cv) return;
|
||||||
|
const dpr = window.devicePixelRatio || 1;
|
||||||
|
const w = width * dpr, h = height * dpr;
|
||||||
|
cv.width = w; cv.height = h;
|
||||||
|
const ctx = cv.getContext('2d');
|
||||||
|
if (!ctx) return;
|
||||||
|
ctx.clearRect(0, 0, w, h);
|
||||||
|
if (!data.length) return;
|
||||||
|
|
||||||
|
const cs = getComputedStyle(cv);
|
||||||
|
const stroke = color.startsWith('var(') ? cs.getPropertyValue(color.slice(4, -1).trim()).trim() || '#00ccff' : color;
|
||||||
|
|
||||||
|
const ys = data.map((v) => (log ? Math.log(Math.max(1e-10, v) + 1) : v));
|
||||||
|
let lo = Infinity, hi = -Infinity;
|
||||||
|
for (const y of ys) { if (y < lo) lo = y; if (y > hi) hi = y; }
|
||||||
|
if (hi === lo) hi = lo + 1e-6;
|
||||||
|
|
||||||
|
ctx.strokeStyle = 'rgba(255,255,255,0.05)';
|
||||||
|
ctx.lineWidth = 1;
|
||||||
|
for (let i = 1; i < 4; i++) { const y = (i / 4) * h; ctx.beginPath(); ctx.moveTo(0, y); ctx.lineTo(w, y); ctx.stroke(); }
|
||||||
|
|
||||||
|
ctx.strokeStyle = stroke;
|
||||||
|
ctx.lineWidth = 1.5 * dpr;
|
||||||
|
ctx.beginPath();
|
||||||
|
for (let i = 0; i < ys.length; i++) {
|
||||||
|
const x = (i / Math.max(1, ys.length - 1)) * w;
|
||||||
|
const norm = (ys[i] - lo) / (hi - lo);
|
||||||
|
const y = h - norm * h;
|
||||||
|
i === 0 ? ctx.moveTo(x, y) : ctx.lineTo(x, y);
|
||||||
|
}
|
||||||
|
ctx.stroke();
|
||||||
|
|
||||||
|
if (showLast) {
|
||||||
|
const last = data[data.length - 1];
|
||||||
|
const txt = format ? format(last) : (typeof last === 'number' ? last.toExponential(2) : String(last));
|
||||||
|
ctx.fillStyle = '#9a9a9a';
|
||||||
|
ctx.font = `${10 * dpr}px ui-monospace, monospace`;
|
||||||
|
ctx.textAlign = 'right';
|
||||||
|
ctx.fillText(txt, w - 4 * dpr, 12 * dpr);
|
||||||
|
}
|
||||||
|
}, [data, width, height, color, log, showLast]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<canvas
|
||||||
|
ref={ref}
|
||||||
|
role="img"
|
||||||
|
aria-label={ariaLabel}
|
||||||
|
style={{ display: 'block', width, height, background: 'var(--bg-1)', border: '1px solid var(--line)', borderRadius: 'var(--r-2)', ...style }}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
101
docs/redesign/manifold-export/readme.md
Normal file
101
docs/redesign/manifold-export/readme.md
Normal file
|
|
@ -0,0 +1,101 @@
|
||||||
|
# Manifold — Design System
|
||||||
|
|
||||||
|
> Train machine learning, on the fly, to play your instruments.
|
||||||
|
|
||||||
|
Manifold is an **open-source project and a family of commercial products** that train and run on-the-fly machine learning (small MLPs and related techniques) to **program, control, patch, and perform with electronic musical instruments** — synths, samplers, sequencers, Eurorack, and software plugins.
|
||||||
|
|
||||||
|
The shape of the system is always the same three stages:
|
||||||
|
|
||||||
|
```
|
||||||
|
INPUTS ENGINE OUTPUTS
|
||||||
|
joystick ┐ ┌ MIDI
|
||||||
|
XY pad ├──▶ on-the-fly ML ──▶ ├ CV / gate
|
||||||
|
trackpad ┘ (MLP / regression) └ OSC → devices
|
||||||
|
(hw + sw, every hardware input has a software visualisation)
|
||||||
|
```
|
||||||
|
|
||||||
|
A performer moves an **input** (a joystick, an XY pad, a trackpad — some hardware, some software, all with live software visualisations). The signal runs through the **engine**, a tiny neural net trained live by the player's own thumbs-up / thumbs-down feedback. The result is sent to the **world** as MIDI, CV, or OSC to control other devices.
|
||||||
|
|
||||||
|
The reference application is the **MEMLNaut playground** — a browser shell hosting nine "modes", each pairing an input surface with a synthesis/effects engine (PAF formant synth, channel strip, granular morph, reverb, drum/breakbeat, sound-analysis→MIDI, and more).
|
||||||
|
|
||||||
|
## Sources given
|
||||||
|
|
||||||
|
- **Codebase** `playground/` — the MEMLNaut playground, a Vite + **SolidJS** + TypeScript app. ML inference runs in-browser via a WASM module (`public/nisps.wasm`); audio synthesis runs in an AudioWorklet. Key paths:
|
||||||
|
- `src/styles/tokens.css` — the original design tokens (dark canvas, mono, warm+cool accents). **This system is a faithful port + extension of that file.**
|
||||||
|
- `src/primitives/` — the control + visualisation primitives: `XYPad`, `VirtualJoystick`, `Slider`, `PillToggle`, `ControlAxis`, `TrainingControls`, `LossPlot`, `Heatmap`, `JoyMap`, `OutputDisplay`, `GradientFlow`, `ProgressRing`, `SliderBank`, `WeightHealth`, `Drawer`, `ParamEditor`.
|
||||||
|
- `src/modes/` — nine modes + `ModeShell` (the shared scaffold) + `ModeSwitcher`.
|
||||||
|
- `src/output/curves.ts` — the named-curve catalog (`linear, exp, log, square, sqrt, sigmoid, cubic, centered_power`) — a core brand motif (straight lines & parabolic / polynomial / bézier curves).
|
||||||
|
|
||||||
|
There were no Figma links, slide decks, or logo binaries in the source — the brand wordmark in the app is the plain text **`MEMLNaut`** + dim `playground`. See ICONOGRAPHY for how the mark is treated and Caveats at the bottom.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## CONTENT FUNDAMENTALS
|
||||||
|
|
||||||
|
How Manifold writes. The voice is a **terminal operator's notebook**: lowercase, terse, technical, unfussy. It trusts the reader is a musician *and* a tinkerer.
|
||||||
|
|
||||||
|
- **Casing.** UI labels and routes are **lowercase** (`home`, `/modes`, `/dev/primitives`). Micro-labels above controls are **UPPERCASE with wide letter-spacing** (`EXAMPLES`, `LOSS`, `BOLDNESS`). Mode names are Title Case (`PAF Synth`, `Channel Strip`). Sentences in prose are sentence case.
|
||||||
|
- **Person.** Mostly **imperative, addressed to "you"** — *"pick a mode and start playing"*, *"Drag to sculpt formants"*, *"start it from inside any mode"*. Rarely first-person.
|
||||||
|
- **Tone.** Plain, confident, slightly hacker. States facts and constraints without apology: *"Audio cannot autoplay (browser policy)."*, *"ML inference runs on the main thread via WASM."* Comments in code carry a dry wit (*"Amnesia ↔ Elephant"*, *"Stream 9: nine modes, one shell."*).
|
||||||
|
- **Density.** Pack real values, not filler. Readouts are always shown with units and tabular numerals: `loss 4.2e-3`, `input (0.62, 0.41)`, `noise 0.018`, `33 in → 1 out`.
|
||||||
|
- **Verbs of the domain.** train, randomise (British -ise), explore, pin, snapshot, undo, freeze, converge, route. Feedback is **thumbs-up / thumbs-down** (rendered `+` / `−`).
|
||||||
|
- **Punctuation.** Middle dot `·` separates inline metadata (`engine: paf_synth · 33 in → 1 out`). Arrows `→` `↔` `▶` `⏹` `↶` carry meaning. Ellipsis `…` for in-progress states (`training…`).
|
||||||
|
- **Emoji.** Used **only as functional glyphs** in dense toolbars where an icon font is absent — `🎤` mic, `⚙` settings, `📚` history, `▶ ⏹` transport. Never decorative, never in prose. Prefer geometric Unicode/SVG over emoji where possible (see ICONOGRAPHY).
|
||||||
|
- **British spelling** (randomise, visualisation, colour-adjacent terms) — the project's origin.
|
||||||
|
|
||||||
|
Examples (verbatim from the product):
|
||||||
|
|
||||||
|
> *"Interactive ML control of audio. Stream 9: nine modes, one shell."*
|
||||||
|
> *"Drag to sculpt formants. Voice space: **Bright**"*
|
||||||
|
> *"pick a mode and start playing"*
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## VISUAL FOUNDATIONS
|
||||||
|
|
||||||
|
The look is a **vintage-computer / instrument-panel terminal**: near-black canvas, monospace everywhere, hairline borders, and **glow** instead of drop-shadow to signal what's alive.
|
||||||
|
|
||||||
|
- **Palette.** A dark greyscale stack (`#0d0d0d → #141414 → #1c1c1c → #242424`) for canvas → panel → raised → track. Text steps down `#e8e8e8 → #9a9a9a → #5a5a5a`. **Two accents do all the work:** warm **orange `#ff6a00`** (the primary — actions, focus, the live control dot) and cool **cyan `#00ccff`** (data, plots, the secondary dot). Semantic green/amber/red/blue are reserved for training health (loss, gradient flow). Five translucent **pin** colors mark regions on the joy-map.
|
||||||
|
- **Type.** **JetBrains Mono** is the hero face — used for ~everything, including titles. A system sans is the quiet fallback for long prose only. Fixed px scale (`11 / 13 / 15 / 18 / 24`). Values use `font-variant-numeric: tabular-nums`. Micro-labels are 11px uppercase, `letter-spacing: 0.08em`, in `--fg-mute`.
|
||||||
|
- **Borders.** Everything is outlined with a **1px hairline** `#2a2a2a`. Stronger `#3a3a3a` for internal grid lines and dashed guides (the joystick boundary is a 1px **dashed** circle). Borders, not shadows, define cards.
|
||||||
|
- **Backgrounds.** Flat solids only — **no gradients, no images, no texture** on surfaces. The only "imagery" is generated: canvas-drawn plots, heatmaps, and the named math curves. The motif is **line + curve** (a loss trace, a parabola, a bézier), never photography or illustration.
|
||||||
|
- **Glow, not shadow.** Live, draggable elements carry a colored **box-shadow halo** in their accent (`0 0 8–12px rgba(accent, .45)`): the XY-pad dot (cyan), the joystick knob (orange), slider thumbs. Drop-shadows (`--shadow-1/2`) appear only on floating chrome (drawers, popovers). Depth is communicated by the bg-step ladder, not elevation.
|
||||||
|
- **Radius.** Tight and consistent: `4px` (buttons, inputs, chips), `8px` (panels, pads, cards), `14px` (drawers), `999px` (pills/segmented controls). XY pad = 8px square; joystick = full circle.
|
||||||
|
- **Cards / panels.** `--bg-1` fill + 1px `--line` border + 8px radius + ~12–16px padding. No shadow. A header row is separated by a 1px bottom border; uppercase micro-labels sit above their values.
|
||||||
|
- **Hover.** Surfaces lighten one bg step (`--bg-2 → --bg-3`) and the border goes `--line → --line-strong`. Text-only controls brighten `--fg-mute → --fg`. ~120ms.
|
||||||
|
- **Press / active.** The selected pill/tab fills **solid orange with `--bg` text**. Active nav gets an orange border + orange text. Slider thumbs scale `1.15` on hover. No bounce.
|
||||||
|
- **Focus.** Accent border + a **3px orange glow ring** (`0 0 0 3px rgba(255,106,0,.3)`) — visible and on-brand, replacing the browser outline.
|
||||||
|
- **Motion.** One house easing `cubic-bezier(.25,.8,.35,1)`; durations `120 / 220 / 360ms`. Transitions are **fades and slides** (drawers slide in from the side). No spring, no bounce, no infinite decorative loops — the only continuous motion is *data* (a loss plot advancing, a live readout updating).
|
||||||
|
- **Transparency / blur.** Used sparingly: translucent pin fills on the joy-map; faint white grid lines on plots (`rgba(255,255,255,0.05)`). No backdrop-blur glass.
|
||||||
|
- **Layout.** Dense grids. The mode shell is a 4-row grid: header / body (input + map) / controls (axes + training) / status line. Hit targets ≥ 44px; primary training buttons are 48px tall. Everything is left-aligned and grid-gapped, never centered-flowing.
|
||||||
|
- **Imagery vibe.** Cool and synthetic — black background, neon-on-dark plots, pixelated heatmaps. No warmth, grain, or photography.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## ICONOGRAPHY
|
||||||
|
|
||||||
|
Manifold's iconography is **geometric and minimal — drawn from the control surfaces themselves**, not from a packaged icon set.
|
||||||
|
|
||||||
|
- **No bundled icon font or SVG sprite** exists in the codebase. The product leans on three things, in order of preference:
|
||||||
|
1. **Functional Unicode glyphs** rendered in the mono face — transport `▶ ⏹`, undo `↶`, arrows `→ ↔`, math `+ − ×`, middle-dot `·`. These match the terminal aesthetic and need no assets.
|
||||||
|
2. **A few emoji as utility icons** in dense toolbars only — `🎤` mic, `⚙` settings/drawer, `📚` snapshot history. Treat these as placeholders for a future geometric set; never use emoji decoratively or in prose.
|
||||||
|
3. **Canvas-drawn "live" iconography** — the real visual language is the *instrument itself*: the XY-pad crosshair + glowing dot, the joystick's dashed boundary + knob, the loss sparkline, the layer-norm bars, the heatmap. When you need to represent a Manifold concept, draw the control, don't reach for a metaphor icon.
|
||||||
|
- **Geometric system, if you must add icons.** Use a thin, single-weight, square-cornered line set. The closest CDN match is **[Lucide](https://lucide.dev)** (2px stroke, geometric, open) or **[Phosphor](https://phosphoricons.com)** (`regular` weight). This system **substitutes Lucide via CDN** for kit screens that need wayfinding icons (settings, close, chevrons) — flagged as a substitution; swap for a bespoke set when one exists. See `assets/icons/` for the curated subset and `assets/README.md`.
|
||||||
|
- **The logo / wordmark.** The only mark in the source is the text lockup **`MEMLNaut`** (bold, `--accent` orange) beside a dim lowercase `playground`, set in JetBrains Mono. There is no symbol/glyph logo. The brand name **Manifold** is set the same way: bold mono wordmark, optionally with the orange dot of a live control as the "o". See `assets/` for the recreated lockups.
|
||||||
|
- **Emoji policy:** functional-only, toolbar-only. Default to Unicode geometry or Lucide. Never emoji in headings, marketing, or body copy.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Index / manifest
|
||||||
|
|
||||||
|
- `styles.css` — global entry (link this). `@import` manifest only.
|
||||||
|
- `tokens/` — `colors.css`, `typography.css`, `spacing.css`, `effects.css`, `fonts.css`, `base.css`.
|
||||||
|
- `assets/` — recreated wordmarks, curated Lucide icon subset, README. (See Caveats.)
|
||||||
|
- `guidelines/` — foundation specimen cards (Type / Colors / Spacing / Brand) shown on the Design System tab.
|
||||||
|
- `components/` — reusable React primitives (see list below) + per-group cards.
|
||||||
|
- `ui_kits/memlnaut/` — full-screen recreation of the MEMLNaut playground mode shell. Plus `ui_kits/memlnaut/console/` — the **Playground 2.0 Console** main view (full-bleed manifold + verdict cluster + right dock with depth drawers).
|
||||||
|
- `SKILL.md` — Agent-Skill front-matter for downloadable use.
|
||||||
|
|
||||||
|
**Components** (`window.ManifoldDesignSystem_490915.*`): Button, PillToggle, Slider, Panel, Badge, Switch, StatusLine · XYPad, VirtualJoystick, ControlAxis · CurvePlot, Sparkline.
|
||||||
|
|
||||||
|
**Caveats / open questions** — see the chat summary; the wordmark and icon set are recreations/substitutions pending real brand assets.
|
||||||
12
docs/redesign/manifold-export/styles.css
Normal file
12
docs/redesign/manifold-export/styles.css
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
/**
|
||||||
|
* Manifold Design System — global entry point.
|
||||||
|
* Consumers link THIS file. It is an @import manifest only; never put rules
|
||||||
|
* directly here. Everything reachable from these imports ships to consumers.
|
||||||
|
*/
|
||||||
|
|
||||||
|
@import url('./tokens/fonts.css');
|
||||||
|
@import url('./tokens/colors.css');
|
||||||
|
@import url('./tokens/typography.css');
|
||||||
|
@import url('./tokens/spacing.css');
|
||||||
|
@import url('./tokens/effects.css');
|
||||||
|
@import url('./tokens/base.css');
|
||||||
51
docs/redesign/manifold-export/tokens/base.css
Normal file
51
docs/redesign/manifold-export/tokens/base.css
Normal file
|
|
@ -0,0 +1,51 @@
|
||||||
|
/**
|
||||||
|
* Manifold — base element styles.
|
||||||
|
* Mirrors the playground's global resets so specimen cards and UI kits read
|
||||||
|
* like the real product even before a single component mounts.
|
||||||
|
*/
|
||||||
|
|
||||||
|
* {
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
html, body {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
background: var(--bg);
|
||||||
|
color: var(--fg);
|
||||||
|
font-family: var(--font-mono);
|
||||||
|
font-size: var(--fs-md);
|
||||||
|
line-height: var(--lh-normal);
|
||||||
|
-webkit-tap-highlight-color: transparent;
|
||||||
|
-webkit-font-smoothing: antialiased;
|
||||||
|
}
|
||||||
|
|
||||||
|
a {
|
||||||
|
color: var(--accent-2);
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
a:hover {
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
|
||||||
|
code, kbd {
|
||||||
|
font-family: var(--font-mono);
|
||||||
|
}
|
||||||
|
|
||||||
|
::selection {
|
||||||
|
background: var(--selection-bg);
|
||||||
|
color: var(--selection-text);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Uppercase micro-label helper used across the system. */
|
||||||
|
.mf-label {
|
||||||
|
font-size: var(--fs-xs);
|
||||||
|
color: var(--fg-mute);
|
||||||
|
text-transform: uppercase;
|
||||||
|
letter-spacing: var(--ls-label);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Tabular numerals for any live readout. */
|
||||||
|
.mf-num {
|
||||||
|
font-variant-numeric: tabular-nums;
|
||||||
|
}
|
||||||
72
docs/redesign/manifold-export/tokens/colors.css
Normal file
72
docs/redesign/manifold-export/tokens/colors.css
Normal file
|
|
@ -0,0 +1,72 @@
|
||||||
|
/**
|
||||||
|
* Manifold — color tokens
|
||||||
|
* Dark terminal canvas, warm-orange primary, cool-cyan secondary.
|
||||||
|
* Ported from the MEMLNaut playground (src/styles/tokens.css) and extended
|
||||||
|
* with semantic aliases.
|
||||||
|
*/
|
||||||
|
|
||||||
|
:root {
|
||||||
|
/* ---- Surfaces (dark, layered) ---- */
|
||||||
|
--bg: #0d0d0d; /* app canvas */
|
||||||
|
--bg-1: #141414; /* panel / card */
|
||||||
|
--bg-2: #1c1c1c; /* raised control */
|
||||||
|
--bg-3: #242424; /* hover / track */
|
||||||
|
|
||||||
|
/* ---- Foreground / text ---- */
|
||||||
|
--fg: #e8e8e8; /* primary text */
|
||||||
|
--fg-mute: #9a9a9a; /* secondary text / labels */
|
||||||
|
--fg-dim: #5a5a5a; /* tertiary / disabled */
|
||||||
|
|
||||||
|
/* ---- Lines / borders ---- */
|
||||||
|
--line: #2a2a2a; /* default 1px hairline */
|
||||||
|
--line-strong: #3a3a3a; /* grid lines, dashed guides */
|
||||||
|
|
||||||
|
/* ---- Accents ---- */
|
||||||
|
--accent: #ff6a00; /* warm primary — actions, focus, the live dot */
|
||||||
|
--accent-2: #00ccff; /* cool secondary — data, plots, secondary dot */
|
||||||
|
--accent-3: #ffa860; /* warm hover / tint */
|
||||||
|
|
||||||
|
/* ---- Semantic ---- */
|
||||||
|
--good: #6bc26b;
|
||||||
|
--warn: #f5c45e;
|
||||||
|
--bad: #ef5b5b;
|
||||||
|
--info: #5b9eef;
|
||||||
|
|
||||||
|
/* ---- Console 2.0 surface language ---- */
|
||||||
|
--danger: #ff4466; /* the 2.0 verdict-perturb / destructive red */
|
||||||
|
--glass: rgba(13, 13, 13, 0.65); /* frosted chrome over the manifold */
|
||||||
|
--glass-line: rgba(255, 255, 255, 0.07); /* hairline on glass */
|
||||||
|
|
||||||
|
/* ---- Region pins (translucent map markers) ---- */
|
||||||
|
--pin-1: rgba(255, 106, 0, 0.25);
|
||||||
|
--pin-2: rgba(0, 204, 255, 0.25);
|
||||||
|
--pin-3: rgba(180, 100, 255, 0.25);
|
||||||
|
--pin-4: rgba(80, 200, 120, 0.25);
|
||||||
|
--pin-5: rgba(255, 200, 80, 0.25);
|
||||||
|
|
||||||
|
/* ---- Glow alphas (for box-shadow halos on live controls) ---- */
|
||||||
|
--glow-accent: rgba(255, 106, 0, 0.45);
|
||||||
|
--glow-accent-2: rgba(0, 204, 255, 0.45);
|
||||||
|
--glow-focus: rgba(255, 106, 0, 0.30);
|
||||||
|
|
||||||
|
/* ============ Semantic aliases ============ */
|
||||||
|
--surface-app: var(--bg);
|
||||||
|
--surface-panel: var(--bg-1);
|
||||||
|
--surface-raised: var(--bg-2);
|
||||||
|
--surface-track: var(--bg-3);
|
||||||
|
|
||||||
|
--text-primary: var(--fg);
|
||||||
|
--text-secondary: var(--fg-mute);
|
||||||
|
--text-tertiary: var(--fg-dim);
|
||||||
|
--text-accent: var(--accent);
|
||||||
|
--text-link: var(--accent-2);
|
||||||
|
|
||||||
|
--border-default: var(--line);
|
||||||
|
--border-strong: var(--line-strong);
|
||||||
|
--border-focus: var(--accent);
|
||||||
|
|
||||||
|
--action-primary: var(--accent);
|
||||||
|
--action-primary-text: var(--bg);
|
||||||
|
--selection-bg: var(--accent);
|
||||||
|
--selection-text: var(--bg);
|
||||||
|
}
|
||||||
31
docs/redesign/manifold-export/tokens/effects.css
Normal file
31
docs/redesign/manifold-export/tokens/effects.css
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
/**
|
||||||
|
* Manifold — motion, shadow & glow tokens
|
||||||
|
* Manifold rarely uses drop shadows for depth; instead it uses *glow halos*
|
||||||
|
* on live, interactive elements (the dot on an XY pad, a slider thumb).
|
||||||
|
*/
|
||||||
|
|
||||||
|
:root {
|
||||||
|
/* ---- Motion ---- */
|
||||||
|
--ease: cubic-bezier(.25, .8, .35, 1); /* @kind other */
|
||||||
|
--ease-out: cubic-bezier(.16, 1, .3, 1); /* @kind other */
|
||||||
|
--ease-console: cubic-bezier(0.22, 1, 0.36, 1); /* @kind other */ /* the 2.0 Console drawer/chrome easing */
|
||||||
|
--dur-fast: 120ms; /* @kind other */
|
||||||
|
--dur-med: 220ms; /* @kind other */
|
||||||
|
--dur-slow: 360ms; /* @kind other */
|
||||||
|
|
||||||
|
/* ---- Glow halos (the signature) ---- */
|
||||||
|
--glow-sm: 0 0 8px var(--glow-accent);
|
||||||
|
--glow-md: 0 0 12px var(--glow-accent);
|
||||||
|
--glow-lg: 0 0 18px var(--glow-accent);
|
||||||
|
--glow-cyan: 0 0 10px var(--glow-accent-2);
|
||||||
|
--focus-ring: 0 0 0 3px var(--glow-focus);
|
||||||
|
|
||||||
|
/* ---- Shadows (used sparingly: drawers, popovers) ---- */
|
||||||
|
--shadow-1: 0 2px 8px rgba(0, 0, 0, 0.4);
|
||||||
|
--shadow-2: 0 8px 24px rgba(0, 0, 0, 0.5);
|
||||||
|
|
||||||
|
/* ---- Borders ---- */
|
||||||
|
--bw: 1px; /* default hairline */
|
||||||
|
--border: var(--bw) solid var(--line);
|
||||||
|
--border-strong-rule: var(--bw) solid var(--line-strong);
|
||||||
|
}
|
||||||
11
docs/redesign/manifold-export/tokens/fonts.css
Normal file
11
docs/redesign/manifold-export/tokens/fonts.css
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
/**
|
||||||
|
* Manifold — webfonts
|
||||||
|
* JetBrains Mono is the brand face. The original codebase referenced it by
|
||||||
|
* name without bundling binaries, so we load it from Google Fonts here.
|
||||||
|
*
|
||||||
|
* SUBSTITUTION NOTE: shipped via Google Fonts CDN (OFL licensed). To self-host,
|
||||||
|
* drop the .woff2 files in assets/fonts/ and replace this @import with
|
||||||
|
* local @font-face rules.
|
||||||
|
*/
|
||||||
|
|
||||||
|
@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:ital,wght@0,400;0,500;0,600;0,700;1,400&display=swap');
|
||||||
34
docs/redesign/manifold-export/tokens/spacing.css
Normal file
34
docs/redesign/manifold-export/tokens/spacing.css
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
/**
|
||||||
|
* Manifold — spacing, radius, layout, z-index
|
||||||
|
* Compact 4px-based scale (the playground is dense, instrument-panel UI).
|
||||||
|
*/
|
||||||
|
|
||||||
|
:root {
|
||||||
|
/* ---- Spacing (px) ---- */
|
||||||
|
--sp-0: 2px;
|
||||||
|
--sp-1: 4px;
|
||||||
|
--sp-2: 8px;
|
||||||
|
--sp-3: 12px;
|
||||||
|
--sp-4: 16px;
|
||||||
|
--sp-5: 24px;
|
||||||
|
--sp-6: 32px;
|
||||||
|
--sp-7: 48px;
|
||||||
|
--sp-8: 64px;
|
||||||
|
|
||||||
|
/* ---- Radius ---- */
|
||||||
|
--r-1: 4px; /* buttons, inputs, small chips */
|
||||||
|
--r-2: 8px; /* panels, pads, cards */
|
||||||
|
--r-3: 14px; /* large surfaces, drawers */
|
||||||
|
--r-pill: 999px;
|
||||||
|
|
||||||
|
/* ---- Z layers ---- */
|
||||||
|
--z-bg: 0; /* @kind other */
|
||||||
|
--z-content: 10; /* @kind other */
|
||||||
|
--z-overlay: 100; /* @kind other */
|
||||||
|
--z-drawer: 200; /* @kind other */
|
||||||
|
--z-modal: 1000; /* @kind other */
|
||||||
|
|
||||||
|
/* ---- Control sizing ---- */
|
||||||
|
--control-h: 48px; /* training buttons, large hit targets */
|
||||||
|
--hit-min: 44px; /* minimum touch target */
|
||||||
|
}
|
||||||
46
docs/redesign/manifold-export/tokens/typography.css
Normal file
46
docs/redesign/manifold-export/tokens/typography.css
Normal file
|
|
@ -0,0 +1,46 @@
|
||||||
|
/**
|
||||||
|
* Manifold — typography tokens
|
||||||
|
* Monospace is the hero (terminal vibe). Sans is a quiet system fallback,
|
||||||
|
* used rarely for long-form prose.
|
||||||
|
*/
|
||||||
|
|
||||||
|
:root {
|
||||||
|
/* ---- Families ---- */
|
||||||
|
--font-mono: 'JetBrains Mono', 'Fira Code', 'SF Mono', Menlo, Consolas, monospace;
|
||||||
|
--font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
|
||||||
|
|
||||||
|
/* Hero family alias — Manifold reads almost entirely in mono. */
|
||||||
|
--font-display: var(--font-mono);
|
||||||
|
--font-body: var(--font-mono);
|
||||||
|
--font-prose: var(--font-sans);
|
||||||
|
|
||||||
|
/* ---- Sizes (px, fixed scale from the playground) ---- */
|
||||||
|
--fs-xs: 11px; /* labels, captions, status */
|
||||||
|
--fs-sm: 13px; /* secondary UI text */
|
||||||
|
--fs-md: 15px; /* body / default */
|
||||||
|
--fs-lg: 18px; /* mode titles, emphasis */
|
||||||
|
--fs-xl: 24px; /* page titles */
|
||||||
|
--fs-2xl: 34px; /* hero / display (specimen / marketing) */
|
||||||
|
--fs-3xl: 48px;
|
||||||
|
|
||||||
|
/* ---- Weights ---- */
|
||||||
|
--fw-regular: 400; /* @kind font */
|
||||||
|
--fw-medium: 500; /* @kind font */
|
||||||
|
--fw-semibold: 600; /* @kind font */
|
||||||
|
--fw-bold: 700; /* @kind font */
|
||||||
|
|
||||||
|
/* ---- Line heights ---- */
|
||||||
|
--lh-tight: 1.1; /* @kind other */
|
||||||
|
--lh-snug: 1.3; /* @kind other */
|
||||||
|
--lh-normal: 1.5; /* @kind other */
|
||||||
|
|
||||||
|
/* ---- Letter spacing ---- */
|
||||||
|
--ls-tight: -0.01em; /* @kind other */
|
||||||
|
--ls-normal: 0; /* @kind other */
|
||||||
|
--ls-label: 0.08em; /* @kind other */
|
||||||
|
--ls-wide: 0.12em; /* @kind other */
|
||||||
|
|
||||||
|
/* ---- Semantic label style ---- */
|
||||||
|
--label-transform: uppercase; /* @kind other */
|
||||||
|
--label-spacing: var(--ls-label); /* @kind other */
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,254 @@
|
||||||
|
/* Console 2.0 — CompositeStage: ONE continuous view that becomes inputs-first,
|
||||||
|
outputs-first, or 50/50 by dragging a single divider. No discrete modes — the
|
||||||
|
layout is a single ratio `split` ∈ [0,1] (= the input's share of the width):
|
||||||
|
split → 1 inputs-first (output demotes to a slim readout list, then a minimap)
|
||||||
|
split = 0.5 dual / 50-50
|
||||||
|
split → 0 outputs-first (input demotes to a pad, then a minimap)
|
||||||
|
Pull the seam ALL THE WAY to an edge and the small side snaps shut, popping
|
||||||
|
out as a draggable minimap rectangle that lives in any corner. Each panel
|
||||||
|
chooses its own representation from its MEASURED width, so it never becomes a
|
||||||
|
useless sliver — it demotes. Handle snaps to 0.14·0.33·0.5·0.66·0.86 with
|
||||||
|
light magnetism; presets tween the ratio. */
|
||||||
|
function CompositeStage({ split, onSplit, mode, pos, onMove, noiseCap, pins, follow, onLongPress, params, values, onChange }) {
|
||||||
|
const ref = React.useRef(null);
|
||||||
|
const [size, setSize] = React.useState({ w: 0, h: 0 });
|
||||||
|
const drag = React.useRef(false);
|
||||||
|
const splitRef = React.useRef(split); splitRef.current = split;
|
||||||
|
|
||||||
|
const SNAPS = [0.14, 0.33, 0.5, 0.66, 0.86];
|
||||||
|
const MAGNET = 0.026;
|
||||||
|
const SHUT = 0.1; // pull past this and the small side collapses to a minimap
|
||||||
|
|
||||||
|
// which corner each minimap rests in (persisted)
|
||||||
|
const [inCorner, setInCorner] = React.useState(() => localStorage.getItem('mf-mm-incorner') || 'tl');
|
||||||
|
const [outCorner, setOutCorner] = React.useState(() => localStorage.getItem('mf-mm-outcorner') || 'tl');
|
||||||
|
React.useEffect(() => { localStorage.setItem('mf-mm-incorner', inCorner); }, [inCorner]);
|
||||||
|
React.useEffect(() => { localStorage.setItem('mf-mm-outcorner', outCorner); }, [outCorner]);
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
const el = ref.current; if (!el) return;
|
||||||
|
// Only commit non-zero measurements; some hosts lay out the flex child after
|
||||||
|
// mount, so the first read can be 0. Keep ResizeObserver AND a setTimeout
|
||||||
|
// kick loop (RO is withheld in some preview contexts) until width is real.
|
||||||
|
const read = () => { if (el.clientWidth) setSize({ w: el.clientWidth, h: el.clientHeight }); };
|
||||||
|
const ro = new ResizeObserver(read); ro.observe(el); read();
|
||||||
|
let t = null, k = 0;
|
||||||
|
const kick = () => { read(); if (!el.clientWidth && k++ < 80) t = setTimeout(kick, 40); };
|
||||||
|
kick();
|
||||||
|
return () => { ro.disconnect(); clearTimeout(t); };
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const setFromClientX = (clientX) => {
|
||||||
|
const el = ref.current; if (!el) return;
|
||||||
|
const r = el.getBoundingClientRect();
|
||||||
|
let f = (clientX - r.left) / r.width;
|
||||||
|
f = Math.max(0, Math.min(1, f));
|
||||||
|
if (f < SHUT) f = 0; // collapse input → minimap
|
||||||
|
else if (f > 1 - SHUT) f = 1; // collapse output → minimap
|
||||||
|
else for (const s of SNAPS) if (Math.abs(f - s) < MAGNET) { f = s; break; }
|
||||||
|
onSplit(f);
|
||||||
|
};
|
||||||
|
const down = (e) => { drag.current = true; e.currentTarget.setPointerCapture?.(e.pointerId); setFromClientX(e.clientX); };
|
||||||
|
const move = (e) => { if (drag.current) setFromClientX(e.clientX); };
|
||||||
|
const up = (e) => { drag.current = false; e.currentTarget.releasePointerCapture?.(e.pointerId); };
|
||||||
|
|
||||||
|
const tweenTo = (target) => {
|
||||||
|
const start = splitRef.current, t0 = performance.now(), dur = 300;
|
||||||
|
const ease = (p) => 1 - Math.pow(1 - p, 3);
|
||||||
|
const step = () => {
|
||||||
|
const p = Math.min(1, (performance.now() - t0) / dur);
|
||||||
|
onSplit(start + (target - start) * ease(p));
|
||||||
|
if (p < 1) requestAnimationFrame(step);
|
||||||
|
};
|
||||||
|
requestAnimationFrame(step);
|
||||||
|
};
|
||||||
|
|
||||||
|
const { w, h } = size;
|
||||||
|
const knownW = w > 0; // until measured, default both sides to their hero tier
|
||||||
|
const collapsed = split <= 0.001 ? 'in' : split >= 0.999 ? 'out' : null;
|
||||||
|
const wIn = w * split, wOut = w * (1 - split);
|
||||||
|
const inTier = (!knownW || wIn >= 300) ? 'full' : 'pad';
|
||||||
|
const outTier = (!knownW || wOut >= 230) ? 'field' : 'list';
|
||||||
|
|
||||||
|
const DS = window.ManifoldDesignSystem_490915;
|
||||||
|
const Pad = mode && mode.input === 'joystick' ? DS.VirtualJoystick : DS.XYPad;
|
||||||
|
const tag = (text, side) => (
|
||||||
|
<div style={{ position: 'absolute', top: 10, [side]: 12, zIndex: 8, pointerEvents: 'none',
|
||||||
|
fontSize: 9, letterSpacing: '0.14em', color: 'var(--fg-dim)', fontFamily: 'var(--font-mono)' }}>{text}</div>
|
||||||
|
);
|
||||||
|
|
||||||
|
// ---- INPUT panel content by tier (non-collapsed) ----
|
||||||
|
const renderInput = () => {
|
||||||
|
if (inTier === 'full') {
|
||||||
|
return <window.Manifold pos={pos} onMove={onMove} noiseCap={noiseCap} pins={pins} follow={follow} onLongPress={onLongPress} />;
|
||||||
|
}
|
||||||
|
const s = Math.max(88, Math.min(wIn - 28, h - 88));
|
||||||
|
return (
|
||||||
|
<div style={{ position: 'absolute', inset: 0, display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center', gap: 10 }}>
|
||||||
|
<Pad size={s} position={pos} onMove={(x, y) => onMove(x, y)} showGrid />
|
||||||
|
<span style={{ fontSize: 10, color: 'var(--fg-mute)', fontFamily: 'var(--font-mono)', fontVariantNumeric: 'tabular-nums' }}>
|
||||||
|
{pos[0].toFixed(2)}, {pos[1].toFixed(2)}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
// ---- OUTPUT panel content by tier (non-collapsed) ----
|
||||||
|
const GC = { formant: '--accent', pitch: '--accent-2', amp: '--good', filter: '--warn', fx: '--info', mod: '--accent-3' };
|
||||||
|
const renderOutput = () => {
|
||||||
|
if (outTier === 'field') {
|
||||||
|
return <window.OutputStage params={params} values={values} onChange={onChange} compact={wOut < 440} />;
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<div style={{ position: 'absolute', inset: 0, padding: '34px 10px 12px', display: 'flex', flexDirection: 'column', gap: 4, overflowY: 'auto' }}>
|
||||||
|
{params.map((p, i) => {
|
||||||
|
const eff = values[i] ?? 0, gc = `var(${GC[p.group] || '--accent'})`, dim = p.status === 'off';
|
||||||
|
const set = (cx, el) => { const r = el.getBoundingClientRect(); onChange(i, { val: Math.max(0, Math.min(1, (cx - r.left) / r.width)) }); };
|
||||||
|
return (
|
||||||
|
<div key={i} style={{ display: 'flex', flexDirection: 'column', gap: 2, opacity: dim ? 0.5 : 1 }}>
|
||||||
|
<div style={{ display: 'flex', justifyContent: 'space-between', gap: 6, fontFamily: 'var(--font-mono)' }}>
|
||||||
|
<span style={{ fontSize: 9, color: 'var(--fg-mute)', overflow: 'hidden', whiteSpace: 'nowrap', textOverflow: 'ellipsis' }}>{p.name}</span>
|
||||||
|
<span style={{ fontSize: 9, color: 'var(--fg)', fontVariantNumeric: 'tabular-nums' }}>{eff.toFixed(2)}</span>
|
||||||
|
</div>
|
||||||
|
<div onPointerDown={(e) => { e.currentTarget.setPointerCapture?.(e.pointerId); e.currentTarget._d = true; set(e.clientX, e.currentTarget); }}
|
||||||
|
onPointerMove={(e) => { if (e.currentTarget._d) set(e.clientX, e.currentTarget); }}
|
||||||
|
onPointerUp={(e) => { e.currentTarget._d = false; e.currentTarget.releasePointerCapture?.(e.pointerId); }}
|
||||||
|
style={{ position: 'relative', height: 6, background: 'var(--bg-1)', border: '1px solid var(--line)', borderRadius: 999, cursor: 'ew-resize', touchAction: 'none' }}>
|
||||||
|
<div style={{ position: 'absolute', left: 0, top: 0, bottom: 0, width: `${eff * 100}%`, background: gc, opacity: 0.6, borderRadius: 999 }} />
|
||||||
|
<div style={{ position: 'absolute', left: `${eff * 100}%`, top: -2, width: 2, height: 10, marginLeft: -1, background: gc, boxShadow: `0 0 6px ${gc}` }} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
// ---- minimap (the collapsed side as a draggable corner rectangle) ----
|
||||||
|
const CORNERS = { tl: { top: 62, left: 14 }, tr: { top: 62, right: 14 }, bl: { bottom: 14, left: 14 }, br: { bottom: 14, right: 14 } };
|
||||||
|
const [mmPos, setMmPos] = React.useState(null); // {x,y,side} while dragging
|
||||||
|
const mmRef = React.useRef({ side: null });
|
||||||
|
const mmDown = (side) => (e) => {
|
||||||
|
const card = e.currentTarget.closest('[data-mm]'); if (!card || !ref.current) return;
|
||||||
|
e.currentTarget.setPointerCapture?.(e.pointerId);
|
||||||
|
const r = ref.current.getBoundingClientRect(), cr = card.getBoundingClientRect();
|
||||||
|
mmRef.current = { side, dx: e.clientX - cr.left, dy: e.clientY - cr.top, cw: cr.width, ch: cr.height };
|
||||||
|
setMmPos({ x: cr.left - r.left, y: cr.top - r.top, side });
|
||||||
|
};
|
||||||
|
const mmMove = (e) => {
|
||||||
|
const m = mmRef.current; if (!m.side || !ref.current) return;
|
||||||
|
const r = ref.current.getBoundingClientRect();
|
||||||
|
const x = Math.max(8, Math.min(r.width - m.cw - 8, e.clientX - r.left - m.dx));
|
||||||
|
const y = Math.max(8, Math.min(r.height - m.ch - 8, e.clientY - r.top - m.dy));
|
||||||
|
setMmPos({ x, y, side: m.side });
|
||||||
|
};
|
||||||
|
const mmUp = (e) => {
|
||||||
|
const m = mmRef.current; if (!m.side || !ref.current) return;
|
||||||
|
const r = ref.current.getBoundingClientRect(), p = mmPos || { x: 0, y: 0 };
|
||||||
|
const corner = (p.y + m.ch / 2 < r.height / 2 ? 't' : 'b') + (p.x + m.cw / 2 < r.width / 2 ? 'l' : 'r');
|
||||||
|
(m.side === 'in' ? setInCorner : setOutCorner)(corner);
|
||||||
|
mmRef.current = { side: null }; setMmPos(null);
|
||||||
|
e.currentTarget.releasePointerCapture?.(e.pointerId);
|
||||||
|
};
|
||||||
|
|
||||||
|
const miniCard = (side, corner, body) => {
|
||||||
|
const dragging = mmPos && mmPos.side === side;
|
||||||
|
const place = dragging ? { left: mmPos.x, top: mmPos.y } : CORNERS[corner];
|
||||||
|
const restore = () => tweenTo(0.5);
|
||||||
|
return (
|
||||||
|
<div data-mm={side} style={{ position: 'absolute', zIndex: 65, ...place,
|
||||||
|
background: 'var(--glass)', backdropFilter: 'blur(12px)', WebkitBackdropFilter: 'blur(12px)',
|
||||||
|
border: '1px solid var(--glass-line)', borderRadius: 'var(--r-2)', boxShadow: 'var(--shadow-2)',
|
||||||
|
padding: 8, display: 'flex', flexDirection: 'column', gap: 6 }}>
|
||||||
|
{/* header = drag handle */}
|
||||||
|
<div onPointerDown={mmDown(side)} onPointerMove={mmMove} onPointerUp={mmUp} onPointerCancel={mmUp}
|
||||||
|
style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 12, cursor: 'move', touchAction: 'none', userSelect: 'none' }}>
|
||||||
|
<span style={{ fontSize: 9, letterSpacing: '0.12em', color: 'var(--fg-mute)', fontFamily: 'var(--font-mono)' }}>
|
||||||
|
<span style={{ color: 'var(--fg-dim)' }}>⠿</span> {side === 'in' ? 'INPUT' : 'OUTPUT'}
|
||||||
|
</span>
|
||||||
|
<button type="button" onClick={restore} title="expand back to dual"
|
||||||
|
style={{ border: 'none', background: 'transparent', color: 'var(--fg-dim)', cursor: 'pointer', fontSize: 12, lineHeight: 1, padding: 0 }}>⤢</button>
|
||||||
|
</div>
|
||||||
|
{body}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
const miniInput = () => miniCard('in', inCorner, (
|
||||||
|
<Pad size={118} position={pos} onMove={(x, y) => onMove(x, y)} showGrid />
|
||||||
|
));
|
||||||
|
const miniOutput = () => miniCard('out', outCorner, (
|
||||||
|
<div style={{ width: 168 }}>
|
||||||
|
<window.MiniMeters params={params} values={values} />
|
||||||
|
</div>
|
||||||
|
));
|
||||||
|
|
||||||
|
// ---- divider geometry ----
|
||||||
|
const pctIn = Math.round(split * 100);
|
||||||
|
const presetActive = Math.abs(split - 0.86) < 0.04 ? 'in' : Math.abs(split - 0.14) < 0.04 ? 'out' : Math.abs(split - 0.5) < 0.04 ? 'dual' : null;
|
||||||
|
const presetBtn = (id, label, target) => (
|
||||||
|
<button type="button" onClick={() => tweenTo(target)} title={label}
|
||||||
|
style={{ fontSize: 9, letterSpacing: '0.08em', padding: '3px 9px', borderRadius: 'var(--r-pill)', cursor: 'pointer', fontFamily: 'var(--font-mono)',
|
||||||
|
border: `1px solid ${presetActive === id ? 'var(--accent)' : 'transparent'}`,
|
||||||
|
background: presetActive === id ? 'rgba(255,106,0,0.14)' : 'transparent',
|
||||||
|
color: presetActive === id ? 'var(--accent)' : 'var(--fg-dim)' }}>{label}</button>
|
||||||
|
);
|
||||||
|
const handleLeft = split <= 0 ? '0%' : split >= 1 ? '100%' : `${split * 100}%`;
|
||||||
|
const handleMargin = split <= 0 ? 0 : split >= 1 ? -18 : -9;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div ref={ref} style={{ position: 'absolute', inset: 0, overflow: 'hidden' }}>
|
||||||
|
{collapsed === 'in' ? (
|
||||||
|
<React.Fragment>
|
||||||
|
<div style={{ position: 'absolute', inset: 0 }}>{tag('OUTPUT', 'right')}{renderOutput()}</div>
|
||||||
|
{miniInput()}
|
||||||
|
</React.Fragment>
|
||||||
|
) : collapsed === 'out' ? (
|
||||||
|
<React.Fragment>
|
||||||
|
<div style={{ position: 'absolute', inset: 0 }}>{tag('INPUT', 'left')}{renderInput()}</div>
|
||||||
|
{miniOutput()}
|
||||||
|
</React.Fragment>
|
||||||
|
) : (
|
||||||
|
<React.Fragment>
|
||||||
|
<div style={{ position: 'absolute', top: 0, bottom: 0, left: 0, width: `${split * 100}%`, overflow: 'hidden' }}>
|
||||||
|
{tag('INPUT', 'left')}{renderInput()}
|
||||||
|
</div>
|
||||||
|
<div style={{ position: 'absolute', top: 0, bottom: 0, right: 0, width: `${(1 - split) * 100}%`, borderLeft: '1px solid var(--line)', overflow: 'hidden' }}>
|
||||||
|
{tag('OUTPUT', 'right')}{renderOutput()}
|
||||||
|
</div>
|
||||||
|
{SNAPS.map((s) => (
|
||||||
|
<div key={s} style={{ position: 'absolute', top: 0, left: `${s * 100}%`, width: 1, height: 6, marginLeft: -0.5,
|
||||||
|
background: 'var(--line-strong)', opacity: Math.abs(split - s) < 0.012 ? 0 : 0.6, pointerEvents: 'none', zIndex: 14 }} />
|
||||||
|
))}
|
||||||
|
</React.Fragment>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* the divider handle — at the seam, or an edge tab when collapsed */}
|
||||||
|
<div onPointerDown={down} onPointerMove={move} onPointerUp={up} onPointerCancel={up}
|
||||||
|
onDoubleClick={() => tweenTo(presetActive === 'dual' ? 0.86 : presetActive === 'in' ? 0.14 : 0.5)}
|
||||||
|
title={collapsed ? 'pull to reveal' : 'drag to rebalance · double-click to cycle'}
|
||||||
|
style={{ position: 'absolute', top: 0, bottom: 0, left: handleLeft, width: 18, marginLeft: handleMargin, zIndex: 26,
|
||||||
|
cursor: 'col-resize', touchAction: 'none', display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
|
||||||
|
<div style={{ position: 'absolute', top: 0, bottom: 0, left: collapsed === 'out' ? 'auto' : 9, right: collapsed === 'out' ? 9 : 'auto',
|
||||||
|
width: 1, background: 'var(--accent)', opacity: collapsed ? 0.5 : 0.35 }} />
|
||||||
|
<div style={{ width: 6, height: 46, borderRadius: 999, background: 'var(--bg-3)', border: '1px solid var(--line-strong)',
|
||||||
|
display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center', gap: 3, boxShadow: '0 0 0 4px var(--bg)' }}>
|
||||||
|
{[0, 1, 2].map((k) => <span key={k} style={{ width: 2, height: 2, borderRadius: '50%', background: 'var(--fg-mute)' }} />)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* presets + ratio readout, top-centre */}
|
||||||
|
<div style={{ position: 'absolute', top: 10, left: '50%', transform: 'translateX(-50%)', zIndex: 16,
|
||||||
|
display: 'flex', alignItems: 'center', gap: 4, background: 'var(--glass)', backdropFilter: 'blur(10px)', WebkitBackdropFilter: 'blur(10px)',
|
||||||
|
border: '1px solid var(--glass-line)', borderRadius: 'var(--r-pill)', padding: '3px 5px' }}>
|
||||||
|
{presetBtn('in', 'input', 0.86)}
|
||||||
|
{presetBtn('dual', 'dual', 0.5)}
|
||||||
|
{presetBtn('out', 'output', 0.14)}
|
||||||
|
<span style={{ width: 1, height: 14, background: 'var(--glass-line)' }} />
|
||||||
|
<span style={{ fontSize: 9, color: 'var(--fg-mute)', fontFamily: 'var(--font-mono)', fontVariantNumeric: 'tabular-nums', padding: '0 4px' }}>
|
||||||
|
in {pctIn} · out {100 - pctIn}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
window.CompositeStage = CompositeStage;
|
||||||
|
|
@ -0,0 +1,199 @@
|
||||||
|
/* Console 2.0 — the reactive spine + layout. One input → ML → output flow that
|
||||||
|
every consumer (readout strip, manifold, health glow) reads. Pseudo-inference
|
||||||
|
stands in for the WASM MLP; the structure mirrors the rewrite plan. */
|
||||||
|
const CA_DS = window.ManifoldDesignSystem_490915;
|
||||||
|
|
||||||
|
/* ---- shared model (modes + inference) lives in model.jsx ---- */
|
||||||
|
const MODES2 = window.MF_MODES;
|
||||||
|
const infer = window.MF_infer;
|
||||||
|
const seededGradient = window.MF_seededGradient;
|
||||||
|
|
||||||
|
let SNAP_ID = 0;
|
||||||
|
|
||||||
|
function ConsoleApp({ focus = 'in' }) {
|
||||||
|
const [modeId, setModeId] = React.useState('paf_synth');
|
||||||
|
const mode = MODES2.find((m) => m.id === modeId);
|
||||||
|
const [params, setParams] = React.useState(() => mode.params.map((p) => ({ ...p })));
|
||||||
|
const [pos, setPos] = React.useState([0.5, 0.5]);
|
||||||
|
const [seed, setSeed] = React.useState(0.4);
|
||||||
|
const [axes, setAxes] = React.useState({ boldness: 0.55, memory: 0.4, precision: 0.5 });
|
||||||
|
const [preset, setPreset] = React.useState('Sculpt');
|
||||||
|
const [noiseCap, setNoiseCap] = React.useState(0.12);
|
||||||
|
const [examples, setExamples] = React.useState(0);
|
||||||
|
const [addingExample, setAddingExample] = React.useState(false);
|
||||||
|
const [loss, setLoss] = React.useState([]);
|
||||||
|
const [busy, setBusy] = React.useState(false);
|
||||||
|
const [snapshots, setSnapshots] = React.useState([]);
|
||||||
|
const [ab, setAB] = React.useState('B');
|
||||||
|
const [holdingA, setHoldingA] = React.useState(false);
|
||||||
|
const aRef = React.useRef(null);
|
||||||
|
const [spread, setSpread] = React.useState(false);
|
||||||
|
const [tame, setTame] = React.useState(0.85);
|
||||||
|
const [health, setHealth] = React.useState(0.8);
|
||||||
|
const [rev, setRev] = React.useState(1);
|
||||||
|
const [active, setActive] = React.useState('feel'); // auto-open Feel peek
|
||||||
|
const [depth, setDepth] = React.useState('peek');
|
||||||
|
const [follow, setFollow] = React.useState(false);
|
||||||
|
const [split, setSplit] = React.useState(() => {
|
||||||
|
const v = parseFloat(localStorage.getItem('mf-composite-split'));
|
||||||
|
return Number.isFinite(v) ? Math.max(0, Math.min(1, v)) : 0.5;
|
||||||
|
});
|
||||||
|
React.useEffect(() => { localStorage.setItem('mf-composite-split', String(split)); }, [split]);
|
||||||
|
const [stripPinned, setStripPinned] = React.useState(true);
|
||||||
|
const [firstSession, setFirstSession] = React.useState(true);
|
||||||
|
const [pins, setPins] = React.useState([]);
|
||||||
|
|
||||||
|
// reset transient state on mode switch
|
||||||
|
React.useEffect(() => {
|
||||||
|
setParams(mode.params.map((p) => ({ ...p }))); setPos([0.5, 0.5]); setExamples(0);
|
||||||
|
setLoss([]); setSnapshots([]); setSeed(0.4); setFollow(false); setPins([]);
|
||||||
|
setActive('feel'); setDepth('peek');
|
||||||
|
}, [modeId]);
|
||||||
|
|
||||||
|
const effSeed = holdingA && aRef.current ? aRef.current.seed : seed;
|
||||||
|
const values = React.useMemo(() => infer(pos, effSeed, params, axes), [pos, effSeed, params, axes]);
|
||||||
|
const gradient = React.useMemo(() => seededGradient(rev), [rev]);
|
||||||
|
|
||||||
|
const pushSnap = (tag) => setSnapshots((s) => [...s, { id: ++SNAP_ID, tag, noise: noiseCap, seed }].slice(-50));
|
||||||
|
|
||||||
|
const commit = () => {
|
||||||
|
setFirstSession(false); pushSnap('commit +'); setBusy(true);
|
||||||
|
setNoiseCap((n) => Math.max(0.02, n * 0.7));
|
||||||
|
setHealth((h) => Math.min(1, h + 0.08));
|
||||||
|
setRev((r) => r + 1);
|
||||||
|
setTimeout(() => {
|
||||||
|
setLoss((prev) => { const base = prev.length ? prev[prev.length - 1] : 0.5; return [...prev, Math.max(0.004, base * (0.8 + Math.random() * 0.08))].slice(-120); });
|
||||||
|
setBusy(false);
|
||||||
|
}, 260);
|
||||||
|
};
|
||||||
|
const perturb = () => {
|
||||||
|
setFirstSession(false); pushSnap('perturb −');
|
||||||
|
setSeed((s) => s + (Math.random() - 0.5) * (noiseCap * 4 + 0.3));
|
||||||
|
setNoiseCap((n) => Math.min(0.5, n + 0.06));
|
||||||
|
setHealth((h) => Math.max(0.1, h - 0.06));
|
||||||
|
setRev((r) => r + 1);
|
||||||
|
};
|
||||||
|
const reroll = () => { setFirstSession(false); pushSnap('re-roll'); setSeed(Math.random() * 6); setNoiseCap(0.4); setHealth(0.5); setRev((r) => r + 1); };
|
||||||
|
const undo = () => setSnapshots((s) => {
|
||||||
|
if (!s.length) return s;
|
||||||
|
const last = s[s.length - 1]; setSeed(last.seed); setNoiseCap(last.noise); setRev((r) => r + 1);
|
||||||
|
return s.slice(0, -1);
|
||||||
|
});
|
||||||
|
const train = () => { setBusy(true); setTimeout(() => { setLoss((p) => { const b = p.length ? p[p.length - 1] : 0.5; return [...p, Math.max(0.004, b * 0.82)].slice(-120); }); setBusy(false); }, 260); };
|
||||||
|
const addExample = () => {
|
||||||
|
if (!addingExample) { setAddingExample(true); return; }
|
||||||
|
setAddingExample(false); setExamples((e) => e + 1); pushSnap('example'); train();
|
||||||
|
};
|
||||||
|
|
||||||
|
const setParam = (i, patch) => setParams((ps) => ps.map((p, j) => (j === i ? { ...p, ...patch } : p)));
|
||||||
|
const cycleStatus = (i) => setParams((ps) => ps.map((p, j) => (j === i ? { ...p, status: ({ off: 'fixed', fixed: 'live', live: 'off' })[p.status] } : p)));
|
||||||
|
|
||||||
|
const toggleAB = () => {
|
||||||
|
if (ab === 'B') { aRef.current = { seed }; setAB('A'); } else { if (aRef.current) setSeed(aRef.current.seed); setAB('B'); }
|
||||||
|
};
|
||||||
|
|
||||||
|
// keyboard accelerators
|
||||||
|
React.useEffect(() => {
|
||||||
|
const onKey = (e) => {
|
||||||
|
if (e.target.tagName === 'INPUT') return;
|
||||||
|
const map = { '1': 'shape', '2': 'feel', '3': 'route', '4': 'health', '5': 'help' };
|
||||||
|
if (map[e.key]) { setActive((a) => (a === map[e.key] ? null : map[e.key])); setDepth('peek'); }
|
||||||
|
else if (e.key === '\\') setDepth((d) => (d === 'full' ? 'peek' : 'full'));
|
||||||
|
else if (focus === 'composite' && e.key === '[') { e.preventDefault(); setSplit((s) => Math.max(0, s - 0.04)); }
|
||||||
|
else if (focus === 'composite' && e.key === ']') { e.preventDefault(); setSplit((s) => Math.min(1, s + 0.04)); }
|
||||||
|
else if (focus === 'composite' && (e.key === '=' || e.key === '0')) { e.preventDefault(); setSplit(0.5); }
|
||||||
|
else if (e.key === ' ' || e.key === 'ArrowUp') { e.preventDefault(); commit(); }
|
||||||
|
else if (e.key === 'ArrowDown') { e.preventDefault(); perturb(); }
|
||||||
|
else if (e.key.toLowerCase() === 'z') undo();
|
||||||
|
};
|
||||||
|
window.addEventListener('keydown', onKey);
|
||||||
|
return () => window.removeEventListener('keydown', onKey);
|
||||||
|
});
|
||||||
|
|
||||||
|
const ctx = {
|
||||||
|
modes: MODES2, modeId, setModeId, mode,
|
||||||
|
axes, setAxis: (k, v) => setAxes((s) => ({ ...s, [k]: v })),
|
||||||
|
preset, setPreset, offsetActive: preset !== 'Sculpt',
|
||||||
|
datasetCount: examples, loss, busy, addingExample,
|
||||||
|
onAddExample: addExample, onTrain: train, onClear: () => { setExamples(0); setLoss([]); },
|
||||||
|
snapshots, onJump: (id) => { const s = snapshots.find((x) => x.id === id); if (s) { setSeed(s.seed); setNoiseCap(s.noise); setRev((r) => r + 1); } },
|
||||||
|
params, cycleStatus, outputBackend: 'audio', setOutputBackend: () => {},
|
||||||
|
health, gradient: gradient.norms, gradientStatus: gradient.status, weightsRevision: rev,
|
||||||
|
spread, setSpread, tame, setTame, noiseCap, setNoiseCap,
|
||||||
|
};
|
||||||
|
|
||||||
|
const healthColor = health > 0.66 ? 'rgba(107,194,107,' : health > 0.33 ? 'rgba(245,196,94,' : 'rgba(255,68,102,';
|
||||||
|
const Input = mode.input;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div style={{ position: 'absolute', inset: 0, background: 'var(--bg)', overflow: 'hidden', fontFamily: 'var(--font-mono)' }}>
|
||||||
|
<style>{`@keyframes mfDrawerIn{from{transform:translateX(16px)}to{transform:translateX(0)}}`}</style>
|
||||||
|
|
||||||
|
{/* ambient health glow at the screen edge */}
|
||||||
|
<div style={{ position: 'absolute', inset: 0, pointerEvents: 'none', zIndex: 25,
|
||||||
|
boxShadow: `inset 0 0 120px ${healthColor}${0.05 + (1 - health) * 0.12})`, transition: 'box-shadow var(--dur-slow) var(--ease-console)' }} />
|
||||||
|
|
||||||
|
{/* stage = manifold area (left of dock) */}
|
||||||
|
<div style={{ position: 'absolute', top: 0, left: 0, right: 48, bottom: 0 }}>
|
||||||
|
{/* readout strip (input-first only — promoted to the stage in output-first) */}
|
||||||
|
{focus === 'in' && (stripPinned || mode.cls !== 'Synth') && (
|
||||||
|
<div style={{ position: 'absolute', top: 0, left: 0, right: 0, zIndex: 30 }}>
|
||||||
|
<window.ReadoutStrip params={params} values={values} onChange={setParam} pinned={stripPinned} onTogglePin={() => setStripPinned((p) => !p)} />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* the stage: manifold (input-first) or output field (output-first) */}
|
||||||
|
<div style={{ position: 'absolute', top: focus === 'in' && stripPinned ? 76 : 0, left: 0, right: 0, bottom: 0 }}>
|
||||||
|
{focus === 'composite' ? (
|
||||||
|
<window.CompositeStage split={split} onSplit={setSplit} mode={mode}
|
||||||
|
pos={pos} onMove={(x, y) => setPos([x, y])} noiseCap={noiseCap} pins={pins} follow={follow}
|
||||||
|
onLongPress={(p) => setPins((ps) => [...ps, { x: p[0], y: p[1], color: 'rgba(255,106,0,0.16)' }])}
|
||||||
|
params={params} values={values} onChange={setParam} />
|
||||||
|
) : focus === 'split' ? (
|
||||||
|
<window.SplitStage pos={pos} onMove={(x, y) => setPos([x, y])} noiseCap={noiseCap}
|
||||||
|
pins={pins} follow={follow}
|
||||||
|
onLongPress={(p) => setPins((ps) => [...ps, { x: p[0], y: p[1], color: 'rgba(255,106,0,0.16)' }])}
|
||||||
|
params={params} values={values} onChange={setParam} />
|
||||||
|
) : focus === 'out' ? (
|
||||||
|
<React.Fragment>
|
||||||
|
<window.OutputStage params={params} values={values} onChange={setParam} />
|
||||||
|
<window.InputMini mode={mode} pos={pos} onMove={(x, y) => setPos([x, y])} noiseCap={noiseCap} corner="bottom-left" />
|
||||||
|
</React.Fragment>
|
||||||
|
) : (
|
||||||
|
<window.Manifold pos={pos} onMove={(x, y) => setPos([x, y])} noiseCap={noiseCap} pins={pins}
|
||||||
|
frozen={false} follow={follow}
|
||||||
|
onLongPress={(p) => setPins((ps) => [...ps, { x: p[0], y: p[1], color: 'rgba(255,106,0,0.16)' }])} />
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* corner overlays */}
|
||||||
|
<div style={{ position: 'absolute', top: 12, left: 14, zIndex: 20, pointerEvents: 'none' }}>
|
||||||
|
<div style={{ display: 'flex', alignItems: 'baseline', gap: 8 }}>
|
||||||
|
<strong style={{ color: 'var(--accent)', fontSize: 'var(--fs-md)' }}>MEMLNaut</strong>
|
||||||
|
<span style={{ color: 'var(--fg-mute)', fontSize: 'var(--fs-sm)' }}>{mode.label}</span>
|
||||||
|
{mode.badge && <span style={{ fontSize: 9, color: 'var(--warn)', border: '1px solid var(--warn)', borderRadius: 'var(--r-pill)', padding: '1px 6px' }}>{mode.badge}</span>}
|
||||||
|
</div>
|
||||||
|
<div style={{ color: 'var(--fg-dim)', fontSize: 'var(--fs-xs)', marginTop: 2 }}>{mode.cls.toLowerCase()} · {mode.input} · {params.length} targets</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style={{ position: 'absolute', bottom: 14, left: focus === 'out' ? 178 : 14, zIndex: 20, display: 'flex', gap: 8, fontFamily: 'var(--font-mono)' }}>
|
||||||
|
<button type="button" onClick={() => setFollow((f) => !f)} title="Follow mode (hands-free drift)"
|
||||||
|
style={{ fontSize: 'var(--fs-xs)', padding: '4px 10px', borderRadius: 'var(--r-pill)', cursor: 'pointer',
|
||||||
|
border: `1px solid ${follow ? 'var(--good)' : 'var(--glass-line)'}`, background: 'var(--glass)',
|
||||||
|
color: follow ? 'var(--good)' : 'var(--fg-mute)' }}>{follow ? '◉ follow' : '○ follow'}</button>
|
||||||
|
<span style={{ fontSize: 'var(--fs-xs)', color: 'var(--fg-dim)', alignSelf: 'center' }}>
|
||||||
|
input ({pos[0].toFixed(2)}, {pos[1].toFixed(2)}) · noise {noiseCap.toFixed(3)} {holdingA && <span style={{ color: 'var(--accent-2)' }}>· preview A</span>}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<window.VerdictCluster onPerturb={perturb} onUndo={undo} onCommit={commit} onReroll={reroll}
|
||||||
|
canUndo={snapshots.length > 0} ab={ab} onToggleAB={toggleAB} onHoldA={setHoldingA} firstSession={firstSession} />
|
||||||
|
|
||||||
|
<window.AltitudeNav current="console" focus={focus} style={{ top: 'auto', bottom: 14, right: 14 }} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<window.Dock ctx={ctx} active={active} setActive={setActive} depth={depth} setDepth={setDepth} />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
window.ConsoleApp = ConsoleApp;
|
||||||
|
|
@ -0,0 +1,59 @@
|
||||||
|
/* Console 2.0 — CurvePad: a square response-curve plot. Click-and-vertical-drag
|
||||||
|
anywhere reshapes the curve (drag up = bulge / ease-out, down = ease-in);
|
||||||
|
`curve` is 0..1 where ~0.43 reads as linear. Mirrors the engine's applyCurve. */
|
||||||
|
function CurvePad({ curve = 0.5, onChange, size = 116 }) {
|
||||||
|
const ref = React.useRef(null);
|
||||||
|
const drag = React.useRef({ active: false, startY: 0, startC: 0 });
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
const cv = ref.current; if (!cv) return;
|
||||||
|
const dpr = window.devicePixelRatio || 1;
|
||||||
|
cv.width = size * dpr; cv.height = size * dpr;
|
||||||
|
const ctx = cv.getContext('2d');
|
||||||
|
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
|
||||||
|
ctx.clearRect(0, 0, size, size);
|
||||||
|
// frame + grid
|
||||||
|
ctx.strokeStyle = 'rgba(255,255,255,0.06)'; ctx.lineWidth = 1;
|
||||||
|
ctx.strokeRect(0.5, 0.5, size - 1, size - 1);
|
||||||
|
for (const t of [0.25, 0.5, 0.75]) {
|
||||||
|
ctx.beginPath(); ctx.moveTo(t * size, 0); ctx.lineTo(t * size, size); ctx.stroke();
|
||||||
|
ctx.beginPath(); ctx.moveTo(0, t * size); ctx.lineTo(size, t * size); ctx.stroke();
|
||||||
|
}
|
||||||
|
// diagonal reference (linear)
|
||||||
|
ctx.strokeStyle = 'rgba(255,255,255,0.10)'; ctx.setLineDash([3, 3]);
|
||||||
|
ctx.beginPath(); ctx.moveTo(0, size); ctx.lineTo(size, 0); ctx.stroke(); ctx.setLineDash([]);
|
||||||
|
// the curve
|
||||||
|
const css = getComputedStyle(cv);
|
||||||
|
const accent = css.getPropertyValue('--accent').trim() || '#ff6a00';
|
||||||
|
const e = 0.25 + curve * 1.75;
|
||||||
|
ctx.strokeStyle = accent; ctx.lineWidth = 2; ctx.beginPath();
|
||||||
|
const pad = 3;
|
||||||
|
for (let p = 0; p <= 80; p++) {
|
||||||
|
const xv = p / 80, yv = Math.pow(xv, e);
|
||||||
|
const px = pad + xv * (size - 2 * pad), py = (size - pad) - yv * (size - 2 * pad);
|
||||||
|
p === 0 ? ctx.moveTo(px, py) : ctx.lineTo(px, py);
|
||||||
|
}
|
||||||
|
ctx.stroke();
|
||||||
|
}, [curve, size]);
|
||||||
|
|
||||||
|
const down = (e) => { e.currentTarget.setPointerCapture?.(e.pointerId); drag.current = { active: true, startY: e.clientY, startC: curve }; };
|
||||||
|
const move = (e) => {
|
||||||
|
const d = drag.current; if (!d.active) return;
|
||||||
|
const dc = (e.clientY - d.startY) / size; // drag up (negative dy) → lower c → bulge up
|
||||||
|
onChange && onChange(Math.max(0, Math.min(1, d.startC + dc)));
|
||||||
|
};
|
||||||
|
const up = (e) => { drag.current.active = false; e.currentTarget.releasePointerCapture?.(e.pointerId); };
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div style={{ display: 'flex', flexDirection: 'column', gap: 4 }}>
|
||||||
|
<div style={{ display: 'flex', justifyContent: 'space-between' }}>
|
||||||
|
<span style={{ fontSize: 10, color: 'var(--fg-mute)', textTransform: 'uppercase', letterSpacing: '0.08em' }}>curve</span>
|
||||||
|
<span style={{ fontSize: 10, color: 'var(--fg-dim)', fontVariantNumeric: 'tabular-nums' }}>{(0.25 + curve * 1.75).toFixed(2)}</span>
|
||||||
|
</div>
|
||||||
|
<canvas ref={ref} onPointerDown={down} onPointerMove={move} onPointerUp={up} onPointerCancel={up}
|
||||||
|
title="Drag vertically to reshape"
|
||||||
|
style={{ width: size, height: size, display: 'block', cursor: 'ns-resize', background: 'var(--bg-1)', border: '1px solid var(--line)', borderRadius: 'var(--r-1)', touchAction: 'none' }} />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
window.CurvePad = CurvePad;
|
||||||
118
docs/redesign/manifold-export/ui_kits/memlnaut/console/Dock.jsx
Normal file
118
docs/redesign/manifold-export/ui_kits/memlnaut/console/Dock.jsx
Normal file
|
|
@ -0,0 +1,118 @@
|
||||||
|
/* Console 2.0 — The Console: right-edge 48px dock rail + one mutually-exclusive
|
||||||
|
drawer with three depth states (Peek 320 / Expand 520 / Full modal). */
|
||||||
|
function ModeSwitcher({ modes, modeId, setModeId }) {
|
||||||
|
const [open, setOpen] = React.useState(false);
|
||||||
|
const active = modes.find((m) => m.id === modeId) || modes[0];
|
||||||
|
const classes = ['Synth', 'Sequencer', 'Controller', 'Visual'];
|
||||||
|
return (
|
||||||
|
<div style={{ position: 'relative' }}>
|
||||||
|
<button type="button" onClick={() => setOpen((o) => !o)} title={`Mode: ${active.label}`}
|
||||||
|
style={{ width: 40, height: 40, borderRadius: 'var(--r-2)', border: '1px solid var(--accent)',
|
||||||
|
background: 'rgba(255,106,0,0.12)', color: 'var(--accent)', cursor: 'pointer', fontSize: 18,
|
||||||
|
display: 'flex', alignItems: 'center', justifyContent: 'center' }}>{active.glyph || '⊞'}</button>
|
||||||
|
{open && (
|
||||||
|
<div style={{ position: 'absolute', top: 0, right: 'calc(100% + 8px)', width: 240, background: 'var(--glass)',
|
||||||
|
backdropFilter: 'blur(14px)', WebkitBackdropFilter: 'blur(14px)', border: '1px solid var(--glass-line)',
|
||||||
|
borderRadius: 'var(--r-2)', boxShadow: 'var(--shadow-2)', padding: 6, zIndex: 80 }}>
|
||||||
|
{classes.map((cls) => {
|
||||||
|
const items = modes.filter((m) => m.cls === cls);
|
||||||
|
if (!items.length) return null;
|
||||||
|
return (
|
||||||
|
<div key={cls}>
|
||||||
|
<div style={{ fontSize: 10, color: 'var(--fg-dim)', textTransform: 'uppercase', letterSpacing: '0.1em', padding: '6px 8px 2px' }}>{cls}</div>
|
||||||
|
{items.map((m) => (
|
||||||
|
<button key={m.id} type="button" disabled={m.placeholder}
|
||||||
|
onClick={() => { if (m.placeholder) return; setModeId(m.id); setOpen(false); }}
|
||||||
|
style={{ display: 'flex', alignItems: 'center', gap: 8, width: '100%', textAlign: 'left',
|
||||||
|
background: m.id === modeId ? 'var(--bg-3)' : 'transparent', border: 0, borderRadius: 'var(--r-1)',
|
||||||
|
padding: '6px 8px', cursor: m.placeholder ? 'not-allowed' : 'pointer', opacity: m.placeholder ? 0.4 : 1,
|
||||||
|
fontFamily: 'var(--font-mono)', fontSize: 'var(--fs-sm)', color: m.id === modeId ? 'var(--accent)' : 'var(--fg)' }}>
|
||||||
|
<span style={{ width: 16, textAlign: 'center' }}>{m.glyph || '·'}</span>{m.label}
|
||||||
|
{m.badge && <span style={{ marginLeft: 'auto', fontSize: 9, color: 'var(--warn)' }}>{m.badge}</span>}
|
||||||
|
</button>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function Dock({ ctx, active, setActive, depth, setDepth }) {
|
||||||
|
const sections = window.DRAWERS;
|
||||||
|
const order = ['shape', 'feel', 'route', 'health', 'help'];
|
||||||
|
|
||||||
|
const iconBtn = (key) => {
|
||||||
|
const s = sections[key];
|
||||||
|
const on = active === key;
|
||||||
|
return (
|
||||||
|
<button key={key} type="button" title={s.label} onClick={() => { setActive(on ? null : key); setDepth('peek'); }}
|
||||||
|
style={{ position: 'relative', width: 40, height: 40, borderRadius: 'var(--r-2)', cursor: 'pointer',
|
||||||
|
border: `1px solid ${on ? 'var(--accent)' : 'transparent'}`,
|
||||||
|
background: on ? 'rgba(255,106,0,0.14)' : 'transparent', color: on ? 'var(--accent)' : 'var(--fg-mute)',
|
||||||
|
fontSize: 18, display: 'flex', alignItems: 'center', justifyContent: 'center',
|
||||||
|
transition: 'background var(--dur-fast), color var(--dur-fast)' }}
|
||||||
|
onMouseEnter={(e) => { if (!on) e.currentTarget.style.color = 'var(--fg)'; }}
|
||||||
|
onMouseLeave={(e) => { if (!on) e.currentTarget.style.color = 'var(--fg-mute)'; }}>
|
||||||
|
{s.icon}
|
||||||
|
{key === 'feel' && active !== 'feel' && (
|
||||||
|
<span style={{ position: 'absolute', bottom: 4, left: 6, right: 6, height: 2, borderRadius: 2,
|
||||||
|
background: `linear-gradient(90deg, var(--accent) ${ctx.axes.boldness * 100}%, var(--line) 0)` }} />
|
||||||
|
)}
|
||||||
|
</button>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const width = depth === 'expand' ? 520 : 320;
|
||||||
|
const full = depth === 'full';
|
||||||
|
const section = active ? sections[active] : null;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<React.Fragment>
|
||||||
|
{/* drawer */}
|
||||||
|
{section && (
|
||||||
|
<aside style={full ? {
|
||||||
|
position: 'fixed', inset: 0, zIndex: 90, background: 'var(--glass)', backdropFilter: 'blur(16px)', WebkitBackdropFilter: 'blur(16px)',
|
||||||
|
padding: 'var(--sp-6)', display: 'flex', flexDirection: 'column', gap: 'var(--sp-3)',
|
||||||
|
} : {
|
||||||
|
position: 'absolute', top: 0, right: 48, bottom: 0, width, zIndex: 35,
|
||||||
|
background: 'var(--glass)', backdropFilter: 'blur(16px)', WebkitBackdropFilter: 'blur(16px)',
|
||||||
|
borderLeft: '1px solid var(--glass-line)', boxShadow: '-8px 0 24px rgba(0,0,0,0.4)',
|
||||||
|
padding: 'var(--sp-4)', display: 'flex', flexDirection: 'column', gap: 'var(--sp-2)', overflow: 'auto',
|
||||||
|
animation: 'mfDrawerIn var(--dur-med) var(--ease-console)',
|
||||||
|
}}>
|
||||||
|
<header style={{ display: 'flex', alignItems: 'center', gap: 'var(--sp-2)', borderBottom: '1px solid var(--glass-line)', paddingBottom: 'var(--sp-2)' }}>
|
||||||
|
<span style={{ fontSize: 'var(--fs-md)', color: 'var(--accent)' }}>{section.icon}</span>
|
||||||
|
<h3 style={{ margin: 0, fontSize: 'var(--fs-md)', color: 'var(--fg)' }}>{section.label}</h3>
|
||||||
|
<span style={{ fontSize: 10, color: 'var(--fg-dim)', textTransform: 'uppercase', letterSpacing: '0.1em', marginLeft: 4 }}>{depth}</span>
|
||||||
|
<div style={{ marginLeft: 'auto', display: 'flex', gap: 4 }}>
|
||||||
|
{!full && (
|
||||||
|
<button type="button" title={depth === 'peek' ? 'More' : 'Peek'} onClick={() => setDepth(depth === 'peek' ? 'expand' : 'peek')}
|
||||||
|
style={dockMini}>⤢</button>
|
||||||
|
)}
|
||||||
|
<button type="button" title="Open full" onClick={() => setDepth(full ? 'peek' : 'full')} style={dockMini}>{full ? '⤡' : '⤢⤢'}</button>
|
||||||
|
<button type="button" title="Close" onClick={() => setActive(null)} style={dockMini}>✕</button>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
<div style={{ display: 'flex', flexDirection: 'column', gap: 'var(--sp-2)', flex: 1, ...(full ? { maxWidth: 720 } : {}) }}>
|
||||||
|
{section.render(ctx, depth)}
|
||||||
|
</div>
|
||||||
|
</aside>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* rail */}
|
||||||
|
<nav style={{ position: 'absolute', top: 0, right: 0, bottom: 0, width: 48, zIndex: 36,
|
||||||
|
background: 'var(--glass)', backdropFilter: 'blur(12px)', WebkitBackdropFilter: 'blur(12px)',
|
||||||
|
borderLeft: '1px solid var(--glass-line)', display: 'flex', flexDirection: 'column', alignItems: 'center',
|
||||||
|
gap: 'var(--sp-2)', padding: '8px 0' }}>
|
||||||
|
<ModeSwitcher modes={ctx.modes} modeId={ctx.modeId} setModeId={ctx.setModeId} />
|
||||||
|
<div style={{ width: 24, height: 1, background: 'var(--glass-line)', margin: '2px 0' }} />
|
||||||
|
{order.map(iconBtn)}
|
||||||
|
</nav>
|
||||||
|
</React.Fragment>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const dockMini = { width: 26, height: 24, borderRadius: 'var(--r-1)', border: '1px solid var(--line)', background: 'var(--bg-2)', color: 'var(--fg-mute)', cursor: 'pointer', fontSize: 11, lineHeight: 1 };
|
||||||
|
window.Dock = Dock;
|
||||||
|
|
@ -0,0 +1,223 @@
|
||||||
|
/* Console 2.0 — Drawer contents. Each renderer takes (ctx, depth) where depth
|
||||||
|
is 'peek' | 'expand' | 'full'; what shows is gated by depth (the schema-tier
|
||||||
|
disclosure mechanism, simulated here).
|
||||||
|
NOTE: these are the PLACEHOLDER drawers. The real dock contents are specified
|
||||||
|
in docs/redesign/dock-spec.md (six drawers: Learning-Behaviour / Inputs /
|
||||||
|
Outputs-Routing / Powerful Synth Engine / Particle-Visual / Help). */
|
||||||
|
const DRW_DS = window.ManifoldDesignSystem_490915;
|
||||||
|
|
||||||
|
function Chip({ children, tone }) {
|
||||||
|
return (
|
||||||
|
<span style={{
|
||||||
|
fontSize: 10, fontFamily: 'var(--font-mono)', textTransform: 'uppercase', letterSpacing: '0.06em',
|
||||||
|
color: tone || 'var(--fg-mute)', background: 'var(--bg-2)', border: '1px solid var(--line)',
|
||||||
|
borderRadius: 'var(--r-pill)', padding: '2px 8px',
|
||||||
|
}}>{children}</span>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
function SectionLabel({ children }) {
|
||||||
|
return <div style={{ fontSize: 10, color: 'var(--fg-dim)', textTransform: 'uppercase', letterSpacing: '0.1em', marginTop: 'var(--sp-2)' }}>{children}</div>;
|
||||||
|
}
|
||||||
|
|
||||||
|
const PRESETS = ['Sculpt', 'Wander', 'Lock-in', 'Chaos', 'Glide', 'Pin & probe'];
|
||||||
|
|
||||||
|
function FeelDrawer(ctx, depth) {
|
||||||
|
const { ControlAxis, PillToggle } = DRW_DS;
|
||||||
|
const axes = [
|
||||||
|
{ key: 'boldness', label: 'Boldness', endpoints: ['Caution', 'Bold'], accent: 'var(--accent)' },
|
||||||
|
{ key: 'memory', label: 'Memory', endpoints: ['Amnesia', 'Elephant'], accent: 'var(--accent-2)' },
|
||||||
|
{ key: 'precision', label: 'Precision', endpoints: ['Raw', 'Precise'], accent: 'var(--accent)' },
|
||||||
|
];
|
||||||
|
return (
|
||||||
|
<React.Fragment>
|
||||||
|
<div style={{ display: 'flex', gap: 6, flexWrap: 'wrap' }}>
|
||||||
|
<Chip tone="var(--accent)">3 axes</Chip>
|
||||||
|
<Chip>preset · {ctx.preset}</Chip>
|
||||||
|
{ctx.offsetActive && <Chip tone="var(--accent-2)">offset active</Chip>}
|
||||||
|
</div>
|
||||||
|
<SectionLabel>Compound axes</SectionLabel>
|
||||||
|
{axes.map((a) => (
|
||||||
|
<ControlAxis key={a.key} label={a.label} endpoints={a.endpoints} accent={a.accent}
|
||||||
|
value={ctx.axes[a.key]} onChange={(v) => ctx.setAxis(a.key, v)}
|
||||||
|
preset={a.key === 'boldness' ? (ctx.axes.boldness > 0.66 ? 'explore' : 'steady') : undefined} />
|
||||||
|
))}
|
||||||
|
<SectionLabel>Control presets</SectionLabel>
|
||||||
|
<div style={{ display: 'flex', gap: 6, flexWrap: 'wrap' }}>
|
||||||
|
{PRESETS.map((p) => (
|
||||||
|
<button key={p} type="button" onClick={() => ctx.setPreset(p)}
|
||||||
|
style={{
|
||||||
|
padding: '5px 10px', fontSize: 'var(--fs-xs)', fontFamily: 'var(--font-mono)', cursor: 'pointer',
|
||||||
|
borderRadius: 'var(--r-pill)', border: `1px solid ${ctx.preset === p ? 'var(--accent)' : 'var(--line)'}`,
|
||||||
|
background: ctx.preset === p ? 'rgba(255,106,0,0.15)' : 'var(--bg-2)',
|
||||||
|
color: ctx.preset === p ? 'var(--accent)' : 'var(--fg-mute)',
|
||||||
|
}}>{p}</button>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
{depth !== 'peek' && (
|
||||||
|
<React.Fragment>
|
||||||
|
<SectionLabel>Trim-pot offsets</SectionLabel>
|
||||||
|
<p style={{ fontSize: 'var(--fs-xs)', color: 'var(--fg-dim)', margin: 0, lineHeight: 1.6 }}>
|
||||||
|
Axis tweaks layer as offsets over the active preset. Double-tap an axis to re-link. An <span style={{ color: 'var(--accent-2)' }}>offset-active</span> dot marks divergence.
|
||||||
|
</p>
|
||||||
|
</React.Fragment>
|
||||||
|
)}
|
||||||
|
</React.Fragment>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function ShapeDrawer(ctx, depth) {
|
||||||
|
const { Button, Sparkline, Badge } = DRW_DS;
|
||||||
|
return (
|
||||||
|
<React.Fragment>
|
||||||
|
<div style={{ display: 'flex', gap: 6, flexWrap: 'wrap' }}>
|
||||||
|
<Chip tone="var(--accent)">examples {ctx.datasetCount}</Chip>
|
||||||
|
<Chip>loss {ctx.loss.length ? ctx.loss[ctx.loss.length - 1].toExponential(1) : '—'}</Chip>
|
||||||
|
{ctx.busy && <Chip tone="var(--accent-2)">training…</Chip>}
|
||||||
|
</div>
|
||||||
|
<SectionLabel>Reinforcement (default)</SectionLabel>
|
||||||
|
<p style={{ fontSize: 'var(--fs-xs)', color: 'var(--fg-dim)', margin: 0, lineHeight: 1.6 }}>
|
||||||
|
Use the + / − verdicts on the manifold. Every verdict auto-snapshots first — undo is consequence-free.
|
||||||
|
</p>
|
||||||
|
<SectionLabel>Examples (IML)</SectionLabel>
|
||||||
|
<div style={{ display: 'flex', gap: 6, flexWrap: 'wrap' }}>
|
||||||
|
<Button size="sm" variant={ctx.addingExample ? 'primary' : 'secondary'} onClick={ctx.onAddExample}>
|
||||||
|
{ctx.addingExample ? '② store target' : '① add example'}
|
||||||
|
</Button>
|
||||||
|
<Button size="sm" onClick={ctx.onTrain} disabled={ctx.busy}>Train</Button>
|
||||||
|
<Button size="sm" variant="ghost" onClick={ctx.onClear}>clear</Button>
|
||||||
|
</div>
|
||||||
|
<SectionLabel>Loss history</SectionLabel>
|
||||||
|
<Sparkline data={ctx.loss.length ? ctx.loss : [0.5]} log width={depth === 'peek' ? 284 : 480} height={56} />
|
||||||
|
{depth !== 'peek' && (
|
||||||
|
<React.Fragment>
|
||||||
|
<SectionLabel>Snapshot DAG · {ctx.snapshots.length}</SectionLabel>
|
||||||
|
<ul style={{ listStyle: 'none', margin: 0, padding: 0, display: 'flex', flexDirection: 'column', gap: 4, maxHeight: 160, overflow: 'auto' }}>
|
||||||
|
{ctx.snapshots.slice().reverse().map((s, idx) => (
|
||||||
|
<li key={s.id}>
|
||||||
|
<button type="button" onClick={() => ctx.onJump(s.id)} style={{
|
||||||
|
width: '100%', textAlign: 'left', display: 'flex', justifyContent: 'space-between',
|
||||||
|
background: idx === 0 ? 'var(--bg-3)' : 'var(--bg-2)', border: '1px solid var(--line)',
|
||||||
|
borderRadius: 'var(--r-1)', padding: '4px 8px', cursor: 'pointer', fontFamily: 'var(--font-mono)', fontSize: 'var(--fs-xs)',
|
||||||
|
}}>
|
||||||
|
<span style={{ color: idx === 0 ? 'var(--accent)' : 'var(--fg)' }}>{s.tag}</span>
|
||||||
|
<span style={{ color: 'var(--fg-dim)' }}>noise {s.noise.toFixed(2)}</span>
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
</React.Fragment>
|
||||||
|
)}
|
||||||
|
</React.Fragment>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const STATUS_CYCLE = { off: 'fixed', fixed: 'live', live: 'off' };
|
||||||
|
const STATUS_COLOR = { off: 'var(--fg-dim)', fixed: 'var(--accent-2)', live: 'var(--accent)' };
|
||||||
|
|
||||||
|
function RouteDrawer(ctx, depth) {
|
||||||
|
const { PillToggle, Badge } = DRW_DS;
|
||||||
|
const counts = ctx.params.reduce((a, p) => { a[p.status] = (a[p.status] || 0) + 1; return a; }, {});
|
||||||
|
const rows = depth === 'peek' ? ctx.params.slice(0, 6) : ctx.params;
|
||||||
|
return (
|
||||||
|
<React.Fragment>
|
||||||
|
<div style={{ display: 'flex', gap: 6, flexWrap: 'wrap' }}>
|
||||||
|
<Chip>sources {ctx.mode.inN}/48</Chip>
|
||||||
|
<Chip>targets {ctx.params.length}/{ctx.params.length}</Chip>
|
||||||
|
<Chip tone="var(--accent)">live {counts.live || 0}</Chip>
|
||||||
|
<Chip tone="var(--accent-2)">fixed {counts.fixed || 0}</Chip>
|
||||||
|
</div>
|
||||||
|
<SectionLabel>Input source</SectionLabel>
|
||||||
|
<Badge tone="info">{ctx.mode.input === 'joystick' ? 'joystick' : ctx.mode.input === 'audio_in' ? 'mic (1-input)' : 'xy pad'}</Badge>
|
||||||
|
<SectionLabel>Output backend</SectionLabel>
|
||||||
|
<PillToggle value={ctx.outputBackend} onChange={ctx.setOutputBackend}
|
||||||
|
options={[{ value: 'audio', label: 'Audio' }, { value: 'midi', label: 'MIDI' }, { value: 'osc', label: 'OSC' }, { value: 'cv', label: 'CV' }]} />
|
||||||
|
<SectionLabel>Control points · off / fixed / live</SectionLabel>
|
||||||
|
<div style={{ display: 'flex', flexDirection: 'column', gap: 3, maxHeight: depth === 'peek' ? 150 : 320, overflow: 'auto' }}>
|
||||||
|
{rows.map((p, i) => (
|
||||||
|
<div key={i} style={{ display: 'flex', alignItems: 'center', gap: 'var(--sp-2)', background: 'var(--bg-2)', border: '1px solid var(--line)', borderRadius: 'var(--r-1)', padding: '4px 8px' }}>
|
||||||
|
<span style={{ flex: 1, fontSize: 'var(--fs-xs)', color: 'var(--fg)', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>{p.name}</span>
|
||||||
|
<span style={{ fontSize: 10, color: 'var(--fg-dim)' }}>{p.group}</span>
|
||||||
|
<button type="button" onClick={() => ctx.cycleStatus(ctx.params.indexOf(p))}
|
||||||
|
style={{ width: 52, fontSize: 10, fontFamily: 'var(--font-mono)', textTransform: 'uppercase', letterSpacing: '0.06em',
|
||||||
|
border: `1px solid ${STATUS_COLOR[p.status]}`, color: STATUS_COLOR[p.status], background: 'transparent',
|
||||||
|
borderRadius: 'var(--r-1)', padding: '2px 4px', cursor: 'pointer' }}>{p.status}</button>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
{depth === 'full' && (
|
||||||
|
<p style={{ fontSize: 'var(--fs-xs)', color: 'var(--fg-dim)', margin: '8px 0 0', lineHeight: 1.6 }}>
|
||||||
|
Full tier hosts the Emitters × Targets matrix + per-cell editor + staged-unlock opt-in (built for the modular mega-mode).
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
</React.Fragment>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function GradientBars({ norms, status }) {
|
||||||
|
const COLOR = { vanishing: 'var(--info)', exploding: 'var(--danger)', converged: 'var(--fg-mute)', healthy: 'var(--good)' };
|
||||||
|
const max = Math.max(...norms, 0.0001);
|
||||||
|
return (
|
||||||
|
<div style={{ display: 'flex', alignItems: 'flex-end', gap: 3, height: 56, background: 'var(--bg-1)', border: '1px solid var(--line)', borderRadius: 'var(--r-2)', padding: 6 }}>
|
||||||
|
{norms.map((n, i) => (
|
||||||
|
<div key={i} style={{ flex: 1, display: 'flex', flexDirection: 'column', alignItems: 'center', gap: 2, height: '100%', justifyContent: 'flex-end' }}>
|
||||||
|
<div style={{ width: '100%', height: `${(n / max) * 100}%`, background: COLOR[status[i]] || 'var(--good)', borderRadius: 1 }} />
|
||||||
|
<span style={{ fontSize: 8, color: 'var(--fg-dim)' }}>L{i}</span>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function HealthDrawer(ctx, depth) {
|
||||||
|
const { Sparkline, Switch, Slider, Badge } = DRW_DS;
|
||||||
|
const healthTone = ctx.health > 0.66 ? 'good' : ctx.health > 0.33 ? 'warn' : 'bad';
|
||||||
|
return (
|
||||||
|
<React.Fragment>
|
||||||
|
<div style={{ display: 'flex', gap: 6, flexWrap: 'wrap', alignItems: 'center' }}>
|
||||||
|
<Badge tone={healthTone} dot>{healthTone === 'good' ? 'healthy' : healthTone === 'warn' ? 'drifting' : 'unstable'}</Badge>
|
||||||
|
<Chip>rev {ctx.weightsRevision}</Chip>
|
||||||
|
</div>
|
||||||
|
<SectionLabel>Loss history</SectionLabel>
|
||||||
|
<Sparkline data={ctx.loss.length ? ctx.loss : [0.5]} log width={depth === 'peek' ? 284 : 480} height={56} />
|
||||||
|
<SectionLabel>Gradient flow · per layer</SectionLabel>
|
||||||
|
<GradientBars norms={ctx.gradient} status={ctx.gradientStatus} />
|
||||||
|
{depth !== 'peek' && (
|
||||||
|
<React.Fragment>
|
||||||
|
<SectionLabel>Lab controls</SectionLabel>
|
||||||
|
<Switch checked={ctx.spread} onChange={ctx.setSpread} label="spread (Xavier regime)" />
|
||||||
|
<Slider label="tame · output limiter" value={ctx.tame} min={0} max={1} step={0.01} onChange={ctx.setTame} />
|
||||||
|
<Slider label="noise cap" value={ctx.noiseCap} min={0} max={0.5} step={0.01} onChange={ctx.setNoiseCap} />
|
||||||
|
</React.Fragment>
|
||||||
|
)}
|
||||||
|
</React.Fragment>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const KEYS = [['1–5', 'open drawers'], ['\\', 'full depth'], ['space / ↑', 'commit +'], ['↓', 'perturb −'], ['z', 'undo'], ['double-click dot', 'follow mode']];
|
||||||
|
function HelpDrawer(ctx, depth) {
|
||||||
|
return (
|
||||||
|
<React.Fragment>
|
||||||
|
<SectionLabel>Keyboard</SectionLabel>
|
||||||
|
<div style={{ display: 'flex', flexDirection: 'column', gap: 4 }}>
|
||||||
|
{KEYS.map(([k, v]) => (
|
||||||
|
<div key={k} style={{ display: 'flex', justifyContent: 'space-between', fontSize: 'var(--fs-xs)' }}>
|
||||||
|
<kbd style={{ background: 'var(--bg-2)', border: '1px solid var(--line)', borderRadius: 'var(--r-1)', padding: '1px 6px', color: 'var(--accent)' }}>{k}</kbd>
|
||||||
|
<span style={{ color: 'var(--fg-mute)' }}>{v}</span>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
<SectionLabel>The loop</SectionLabel>
|
||||||
|
<p style={{ fontSize: 'var(--fs-xs)', color: 'var(--fg-dim)', margin: 0, lineHeight: 1.7 }}>
|
||||||
|
Drag the manifold to explore. Hear something good → + to settle. Wrong → − to perturb. Went too far → ↺ undo. The screen reveals exactly as much machinery as you reach for.
|
||||||
|
</p>
|
||||||
|
</React.Fragment>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
window.DRAWERS = {
|
||||||
|
shape: { icon: '◇', label: 'Shape', render: ShapeDrawer },
|
||||||
|
feel: { icon: '◎', label: 'Feel', render: FeelDrawer },
|
||||||
|
route: { icon: '⇄', label: 'Route', render: RouteDrawer },
|
||||||
|
health: { icon: '♥', label: 'Health', render: HealthDrawer },
|
||||||
|
help: { icon: '?', label: 'Help', render: HelpDrawer },
|
||||||
|
};
|
||||||
|
|
@ -0,0 +1,25 @@
|
||||||
|
/* Console 2.0 — InputMini: the input demoted to a small secondary control for
|
||||||
|
the output-first views. A compact joy-map / XY pad in a glass card; still
|
||||||
|
drives inference, but no longer the hero. */
|
||||||
|
function InputMini({ mode, pos, onMove, noiseCap, size = 132, corner = 'bottom-left' }) {
|
||||||
|
const DS = window.ManifoldDesignSystem_490915;
|
||||||
|
const Pad = mode.input === 'joystick' ? DS.VirtualJoystick : DS.XYPad;
|
||||||
|
const place = {
|
||||||
|
'bottom-left': { bottom: 14, left: 14 },
|
||||||
|
'bottom-right': { bottom: 14, right: 14 },
|
||||||
|
'top-left': { top: 14, left: 14 },
|
||||||
|
}[corner];
|
||||||
|
return (
|
||||||
|
<div style={{ position: 'absolute', zIndex: 22, ...place,
|
||||||
|
background: 'var(--glass)', backdropFilter: 'blur(12px)', WebkitBackdropFilter: 'blur(12px)',
|
||||||
|
border: '1px solid var(--glass-line)', borderRadius: 'var(--r-2)', padding: 'var(--sp-2)',
|
||||||
|
display: 'flex', flexDirection: 'column', gap: 6 }}>
|
||||||
|
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', gap: 12 }}>
|
||||||
|
<span style={{ fontSize: 10, color: 'var(--fg-dim)', textTransform: 'uppercase', letterSpacing: '0.1em' }}>input · {mode.input === 'joystick' ? 'joy' : 'xy'}</span>
|
||||||
|
<span style={{ fontSize: 10, color: 'var(--fg-mute)', fontVariantNumeric: 'tabular-nums' }}>{pos[0].toFixed(2)},{pos[1].toFixed(2)}</span>
|
||||||
|
</div>
|
||||||
|
<Pad size={size} position={pos} onMove={(x, y) => onMove(x, y)} showGrid />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
window.InputMini = InputMini;
|
||||||
|
|
@ -0,0 +1,163 @@
|
||||||
|
/* Console 2.0 — The Manifold: full-bleed input surface + joy-map visualisation.
|
||||||
|
Pointer-down anywhere drives the joystick dot; a ~5s vanishing trail fades
|
||||||
|
behind it; noise rings breathe at the current cap; pins overlay regions. */
|
||||||
|
function Manifold({ pos, onMove, noiseCap = 0.1, pins = [], frozen = false, follow = false, onLongPress }) {
|
||||||
|
const wrapRef = React.useRef(null);
|
||||||
|
const canvasRef = React.useRef(null);
|
||||||
|
const stateRef = React.useRef({ pos, noiseCap, pins, frozen, follow });
|
||||||
|
const trailRef = React.useRef([]); // {x,y,t}
|
||||||
|
const draggingRef = React.useRef(false);
|
||||||
|
const driftRef = React.useRef({ vx: 0.0011, vy: 0.0008 });
|
||||||
|
const lpTimer = React.useRef(null);
|
||||||
|
|
||||||
|
stateRef.current = { pos, noiseCap, pins, frozen, follow };
|
||||||
|
|
||||||
|
// push trail point whenever pos changes
|
||||||
|
React.useEffect(() => {
|
||||||
|
trailRef.current.push({ x: pos[0], y: pos[1], t: performance.now() });
|
||||||
|
if (trailRef.current.length > 240) trailRef.current.shift();
|
||||||
|
}, [pos[0], pos[1]]);
|
||||||
|
|
||||||
|
const setFromEvent = (e) => {
|
||||||
|
const el = wrapRef.current; if (!el) return;
|
||||||
|
const r = el.getBoundingClientRect();
|
||||||
|
const x = Math.max(0, Math.min(1, (e.clientX - r.left) / r.width));
|
||||||
|
const y = Math.max(0, Math.min(1, 1 - (e.clientY - r.top) / r.height));
|
||||||
|
onMove(x, y);
|
||||||
|
};
|
||||||
|
|
||||||
|
const down = (e) => {
|
||||||
|
if (stateRef.current.frozen) return;
|
||||||
|
e.currentTarget.setPointerCapture?.(e.pointerId);
|
||||||
|
draggingRef.current = true;
|
||||||
|
setFromEvent(e);
|
||||||
|
clearTimeout(lpTimer.current);
|
||||||
|
lpTimer.current = setTimeout(() => { onLongPress && onLongPress(stateRef.current.pos); }, 600);
|
||||||
|
};
|
||||||
|
const move = (e) => { if (draggingRef.current) { setFromEvent(e); clearTimeout(lpTimer.current); } };
|
||||||
|
const up = (e) => { draggingRef.current = false; e.currentTarget.releasePointerCapture?.(e.pointerId); clearTimeout(lpTimer.current); };
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
const canvas = canvasRef.current, wrap = wrapRef.current;
|
||||||
|
if (!canvas || !wrap) return;
|
||||||
|
const ctx = canvas.getContext('2d');
|
||||||
|
let raf;
|
||||||
|
const css = getComputedStyle(document.documentElement);
|
||||||
|
const C = (n, f) => (css.getPropertyValue(n).trim() || f);
|
||||||
|
const accent = C('--accent', '#ff6a00'), cyan = C('--accent-2', '#00ccff'), line = C('--line-strong', '#3a3a3a');
|
||||||
|
|
||||||
|
const dpr = window.devicePixelRatio || 1;
|
||||||
|
let lastW = -1, lastH = -1;
|
||||||
|
const ensureSize = (W, H) => {
|
||||||
|
if (W === lastW && H === lastH) return;
|
||||||
|
canvas.width = W * dpr; canvas.height = H * dpr;
|
||||||
|
canvas.style.width = W + 'px'; canvas.style.height = H + 'px';
|
||||||
|
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
|
||||||
|
lastW = W; lastH = H;
|
||||||
|
};
|
||||||
|
|
||||||
|
const draw = () => {
|
||||||
|
const W = wrap.clientWidth, H = wrap.clientHeight;
|
||||||
|
// Self-heal against deferred / zero initial sizing (e.g. inside a flex
|
||||||
|
// child that lays out after mount): size each frame, skip until non-zero,
|
||||||
|
// but always keep the rAF chain alive.
|
||||||
|
if (W === 0 || H === 0) return;
|
||||||
|
ensureSize(W, H);
|
||||||
|
const { pos, noiseCap, pins, frozen, follow } = stateRef.current;
|
||||||
|
const now = performance.now();
|
||||||
|
|
||||||
|
// drift in follow mode
|
||||||
|
if (follow && !draggingRef.current && !frozen) {
|
||||||
|
let [x, y] = pos; const d = driftRef.current;
|
||||||
|
x += d.vx; y += d.vy;
|
||||||
|
if (x < 0.05 || x > 0.95) d.vx *= -1;
|
||||||
|
if (y < 0.05 || y > 0.95) d.vy *= -1;
|
||||||
|
x = Math.max(0.05, Math.min(0.95, x)); y = Math.max(0.05, Math.min(0.95, y));
|
||||||
|
onMove(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.clearRect(0, 0, W, H);
|
||||||
|
|
||||||
|
// adaptive graph-paper grid (8 major, 4 minor subdivisions)
|
||||||
|
const minor = 32, major = 8;
|
||||||
|
ctx.lineWidth = 1;
|
||||||
|
for (let i = 0; i <= minor; i++) {
|
||||||
|
const t = i / minor; const isMajor = i % (minor / major) === 0;
|
||||||
|
ctx.strokeStyle = isMajor ? 'rgba(255,255,255,0.06)' : 'rgba(255,255,255,0.022)';
|
||||||
|
ctx.beginPath(); ctx.moveTo(t * W, 0); ctx.lineTo(t * W, H); ctx.stroke();
|
||||||
|
ctx.beginPath(); ctx.moveTo(0, t * H); ctx.lineTo(W, t * H); ctx.stroke();
|
||||||
|
}
|
||||||
|
// center crosshair
|
||||||
|
ctx.strokeStyle = 'rgba(255,255,255,0.05)';
|
||||||
|
ctx.beginPath(); ctx.moveTo(W / 2, 0); ctx.lineTo(W / 2, H); ctx.moveTo(0, H / 2); ctx.lineTo(W, H / 2); ctx.stroke();
|
||||||
|
|
||||||
|
const px = pos[0] * W, py = (1 - pos[1]) * H;
|
||||||
|
|
||||||
|
// pins
|
||||||
|
for (const p of pins) {
|
||||||
|
const ppx = p.x * W, ppy = (1 - p.y) * H;
|
||||||
|
ctx.fillStyle = p.color || 'rgba(255,106,0,0.18)';
|
||||||
|
ctx.beginPath(); ctx.arc(ppx, ppy, 34, 0, Math.PI * 2); ctx.fill();
|
||||||
|
ctx.strokeStyle = 'rgba(255,255,255,0.18)'; ctx.lineWidth = 1;
|
||||||
|
ctx.beginPath(); ctx.arc(ppx, ppy, 34, 0, Math.PI * 2); ctx.stroke();
|
||||||
|
}
|
||||||
|
|
||||||
|
// vanishing trail (~5s)
|
||||||
|
const LIFE = 5000;
|
||||||
|
const pts = trailRef.current;
|
||||||
|
ctx.lineWidth = 2;
|
||||||
|
for (let i = 1; i < pts.length; i++) {
|
||||||
|
const a = pts[i - 1], b = pts[i];
|
||||||
|
const age = now - b.t; if (age > LIFE) continue;
|
||||||
|
const alpha = (1 - age / LIFE) * 0.5;
|
||||||
|
ctx.strokeStyle = `rgba(0,204,255,${alpha})`;
|
||||||
|
ctx.beginPath(); ctx.moveTo(a.x * W, (1 - a.y) * H); ctx.lineTo(b.x * W, (1 - b.y) * H); ctx.stroke();
|
||||||
|
}
|
||||||
|
|
||||||
|
// noise rings — breathe at cap
|
||||||
|
if (noiseCap > 0.001) {
|
||||||
|
const breathe = 1 + Math.sin(now / 600) * 0.06;
|
||||||
|
const rCap = noiseCap * Math.min(W, H) * 0.5 * breathe;
|
||||||
|
const rCur = rCap * 0.55;
|
||||||
|
ctx.setLineDash([4, 5]);
|
||||||
|
ctx.strokeStyle = `rgba(255,106,0,0.4)`; ctx.lineWidth = 1.5;
|
||||||
|
ctx.beginPath(); ctx.arc(px, py, rCap, 0, Math.PI * 2); ctx.stroke();
|
||||||
|
ctx.strokeStyle = `rgba(255,106,0,0.7)`;
|
||||||
|
ctx.beginPath(); ctx.arc(px, py, rCur, 0, Math.PI * 2); ctx.stroke();
|
||||||
|
ctx.setLineDash([]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// the joystick dot
|
||||||
|
ctx.shadowColor = frozen ? cyan : accent; ctx.shadowBlur = 18;
|
||||||
|
ctx.fillStyle = frozen ? cyan : accent;
|
||||||
|
ctx.beginPath(); ctx.arc(px, py, 9, 0, Math.PI * 2); ctx.fill();
|
||||||
|
ctx.shadowBlur = 0;
|
||||||
|
ctx.fillStyle = '#0d0d0d';
|
||||||
|
ctx.beginPath(); ctx.arc(px, py, 3, 0, Math.PI * 2); ctx.fill();
|
||||||
|
};
|
||||||
|
// Paint immediately + on every resize (robust to deferred flex sizing and to
|
||||||
|
// rAF being throttled in background/preview contexts); rAF drives animation.
|
||||||
|
const loop = () => { draw(); raf = requestAnimationFrame(loop); };
|
||||||
|
const ro = new ResizeObserver(() => draw());
|
||||||
|
ro.observe(wrap);
|
||||||
|
// Initial paint via setTimeout retries (rAF and ResizeObserver are both
|
||||||
|
// throttled/withheld in some preview contexts; setTimeout is not). Keep
|
||||||
|
// retrying until the flex child has a non-zero width and the canvas is sized.
|
||||||
|
let timer = null, kicks = 0;
|
||||||
|
const kick = () => { draw(); if (lastW <= 0 && kicks++ < 80) timer = setTimeout(kick, 40); };
|
||||||
|
kick();
|
||||||
|
raf = requestAnimationFrame(loop);
|
||||||
|
return () => { cancelAnimationFrame(raf); ro.disconnect(); clearTimeout(timer); };
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
ref={wrapRef}
|
||||||
|
onPointerDown={down} onPointerMove={move} onPointerUp={up} onPointerCancel={up}
|
||||||
|
style={{ position: 'absolute', inset: 0, cursor: frozen ? 'not-allowed' : 'crosshair', touchAction: 'none', userSelect: 'none' }}
|
||||||
|
>
|
||||||
|
<canvas ref={canvasRef} style={{ display: 'block' }} />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
window.Manifold = Manifold;
|
||||||
|
|
@ -0,0 +1,59 @@
|
||||||
|
/* Console 2.0 — OutputEditor: the per-output menu. Opens on hover over an
|
||||||
|
output (column / cell). Sets state (off / fixed / live), min, max, the static
|
||||||
|
value (only when deactivated), and the curve via the CurvePad. */
|
||||||
|
const OE_STATUS = [
|
||||||
|
{ v: 'off', label: 'Off', color: 'var(--fg-dim)' },
|
||||||
|
{ v: 'fixed', label: 'Fixed', color: 'var(--accent-2)' },
|
||||||
|
{ v: 'live', label: 'Live', color: 'var(--accent)' },
|
||||||
|
];
|
||||||
|
|
||||||
|
function MiniSlider({ label, value, onChange, disabled }) {
|
||||||
|
return (
|
||||||
|
<label style={{ display: 'flex', flexDirection: 'column', gap: 2, opacity: disabled ? 0.4 : 1 }}>
|
||||||
|
<div style={{ display: 'flex', justifyContent: 'space-between' }}>
|
||||||
|
<span style={{ fontSize: 10, color: 'var(--fg-mute)', textTransform: 'uppercase', letterSpacing: '0.08em' }}>{label}</span>
|
||||||
|
<span style={{ fontSize: 10, color: 'var(--fg-dim)', fontVariantNumeric: 'tabular-nums' }}>{value.toFixed(2)}</span>
|
||||||
|
</div>
|
||||||
|
<input type="range" min="0" max="1" step="0.01" value={value} disabled={disabled}
|
||||||
|
onChange={(e) => onChange(parseFloat(e.target.value))} className="mf-slider-input" style={{ width: '100%' }} />
|
||||||
|
</label>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function OutputEditor({ param, onChange, onHold, onLeave, place }) {
|
||||||
|
const isLive = param.status === 'live';
|
||||||
|
return (
|
||||||
|
<div onPointerEnter={onHold} onPointerLeave={onLeave}
|
||||||
|
style={{
|
||||||
|
position: 'absolute', width: 196, zIndex: 80, ...place,
|
||||||
|
background: 'var(--glass)', backdropFilter: 'blur(14px)', WebkitBackdropFilter: 'blur(14px)',
|
||||||
|
border: '1px solid var(--glass-line)', borderRadius: 'var(--r-2)', boxShadow: 'var(--shadow-2)',
|
||||||
|
padding: 'var(--sp-3)', display: 'flex', flexDirection: 'column', gap: 'var(--sp-2)', fontFamily: 'var(--font-mono)',
|
||||||
|
}}>
|
||||||
|
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'baseline' }}>
|
||||||
|
<strong style={{ fontSize: 'var(--fs-sm)', color: 'var(--fg)' }}>{param.name}</strong>
|
||||||
|
<span style={{ fontSize: 10, color: 'var(--fg-dim)' }}>{param.group}</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* tri-state */}
|
||||||
|
<div style={{ display: 'flex', background: 'var(--bg-2)', border: '1px solid var(--line)', borderRadius: 'var(--r-pill)', padding: 2, gap: 2 }}>
|
||||||
|
{OE_STATUS.map((s) => {
|
||||||
|
const on = param.status === s.v;
|
||||||
|
return (
|
||||||
|
<button key={s.v} type="button" onClick={() => onChange({ status: s.v })}
|
||||||
|
style={{ flex: 1, border: 0, borderRadius: 'var(--r-pill)', padding: '4px 0', cursor: 'pointer',
|
||||||
|
fontFamily: 'var(--font-mono)', fontSize: 10, textTransform: 'uppercase', letterSpacing: '0.06em',
|
||||||
|
background: on ? s.color : 'transparent', color: on ? 'var(--bg)' : 'var(--fg-mute)' }}>{s.label}</button>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<MiniSlider label="min" value={param.min} onChange={(v) => onChange({ min: v })} />
|
||||||
|
<MiniSlider label="max" value={param.max} onChange={(v) => onChange({ max: v })} />
|
||||||
|
<MiniSlider label={isLive ? 'value · live' : 'value · static'} value={param.val} onChange={(v) => onChange({ val: v })} disabled={isLive} />
|
||||||
|
<window.CurvePad curve={param.curve} onChange={(c) => onChange({ curve: c })} size={170} />
|
||||||
|
<span style={{ fontSize: 9, color: 'var(--fg-dim)', lineHeight: 1.4 }}>drag a bar to set value · ⌥/alt-click cycles state</span>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
window.OutputEditor = OutputEditor;
|
||||||
|
|
@ -0,0 +1,83 @@
|
||||||
|
/* Console 2.0 — OutputStage: the OUTPUT as the hero surface. A full-bleed field
|
||||||
|
of parameter columns. Per column: name on top, value below it, then the bar.
|
||||||
|
- drag / click a bar → set the value
|
||||||
|
- ⌥/alt-click a bar → cycle state (off → fixed → live)
|
||||||
|
- hover a column → open the OutputEditor (state · min · max · value · curve) */
|
||||||
|
const OUT_GROUP_COLOR = {
|
||||||
|
formant: '--accent', pitch: '--accent-2', amp: '--good', filter: '--warn', fx: '--info', mod: '--accent-3',
|
||||||
|
};
|
||||||
|
const OUT_NEXT = { off: 'fixed', fixed: 'live', live: 'off' };
|
||||||
|
|
||||||
|
function OutputStage({ params, values, onChange, compact = false }) {
|
||||||
|
const [open, setOpen] = React.useState(null);
|
||||||
|
const timers = React.useRef({ open: null, close: null });
|
||||||
|
const drag = React.useRef({ i: -1, moved: false, startY: 0, el: null, alt: false });
|
||||||
|
|
||||||
|
const scheduleOpen = (i) => { clearTimeout(timers.current.close); clearTimeout(timers.current.open); timers.current.open = setTimeout(() => setOpen(i), 110); };
|
||||||
|
const scheduleClose = () => { clearTimeout(timers.current.open); clearTimeout(timers.current.close); timers.current.close = setTimeout(() => setOpen(null), 280); };
|
||||||
|
const hold = () => clearTimeout(timers.current.close);
|
||||||
|
|
||||||
|
const valFromEvent = (el, clientY) => { const r = el.getBoundingClientRect(); return Math.max(0, Math.min(1, 1 - (clientY - r.top) / r.height)); };
|
||||||
|
const down = (e, i) => { e.currentTarget.setPointerCapture?.(e.pointerId); drag.current = { i, moved: false, startY: e.clientY, el: e.currentTarget, alt: e.altKey || e.metaKey }; };
|
||||||
|
const move = (e, i) => {
|
||||||
|
const d = drag.current; if (d.i !== i) return;
|
||||||
|
if (Math.abs(e.clientY - d.startY) > 3) d.moved = true;
|
||||||
|
if (d.moved && !d.alt) onChange(i, { val: valFromEvent(d.el, e.clientY) });
|
||||||
|
};
|
||||||
|
const up = (e, i) => {
|
||||||
|
const d = drag.current; if (d.i !== i) return;
|
||||||
|
if (d.alt && !d.moved) onChange(i, { status: OUT_NEXT[params[i].status] || 'live' });
|
||||||
|
else if (!d.moved) onChange(i, { val: valFromEvent(d.el, e.clientY) });
|
||||||
|
drag.current = { i: -1, moved: false, startY: 0, el: null, alt: false };
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div style={{ position: 'absolute', inset: 0, display: 'flex', alignItems: 'stretch', gap: compact ? 3 : 6, padding: compact ? 12 : '20px 28px' }}>
|
||||||
|
{params.map((p, i) => {
|
||||||
|
const eff = values[i] ?? 0;
|
||||||
|
const gc = `var(${OUT_GROUP_COLOR[p.group] || '--accent'})`;
|
||||||
|
const dim = p.status === 'off';
|
||||||
|
const placeRight = i > params.length - 4;
|
||||||
|
return (
|
||||||
|
<div key={i} style={{ position: 'relative', flex: 1, minWidth: 0, display: 'flex', flexDirection: 'column', gap: compact ? 1 : 2 }}
|
||||||
|
onPointerLeave={scheduleClose}>
|
||||||
|
{/* hover target: name + number ONLY (not the bar) */}
|
||||||
|
<div onPointerEnter={() => scheduleOpen(i)} style={{ cursor: 'help' }}>
|
||||||
|
{/* name (top) */}
|
||||||
|
<div style={{ textAlign: 'center', fontSize: compact ? 8 : 10, fontFamily: 'var(--font-mono)', color: p.status === 'live' ? 'var(--fg-mute)' : `var(${OUT_GROUP_COLOR[p.group] || '--accent'})`,
|
||||||
|
overflow: 'hidden', whiteSpace: 'nowrap', textOverflow: 'ellipsis', letterSpacing: '0.02em' }}>{p.name}</div>
|
||||||
|
{/* number (below name) */}
|
||||||
|
<div style={{ textAlign: 'center', fontSize: compact ? 9 : 11, fontFamily: 'var(--font-mono)', fontVariantNumeric: 'tabular-nums',
|
||||||
|
color: dim ? 'var(--fg-dim)' : 'var(--fg)' }}>{eff.toFixed(2)}</div>
|
||||||
|
</div>
|
||||||
|
{/* bar */}
|
||||||
|
<div onPointerDown={(e) => down(e, i)} onPointerMove={(e) => move(e, i)} onPointerUp={(e) => up(e, i)} onPointerCancel={(e) => up(e, i)}
|
||||||
|
style={{ position: 'relative', flex: 1, background: 'var(--bg-1)', border: '1px solid var(--line)', borderRadius: compact ? 2 : 'var(--r-1)', overflow: 'hidden', cursor: 'ns-resize', opacity: dim ? 0.55 : 1, touchAction: 'none' }}>
|
||||||
|
{[0.25, 0.5, 0.75].map((t) => <div key={t} style={{ position: 'absolute', left: 0, right: 0, bottom: `${t * 100}%`, height: 1, background: 'rgba(255,255,255,0.04)' }} />)}
|
||||||
|
<div style={{ position: 'absolute', left: 0, right: 0, bottom: 0, height: `${eff * 100}%`, background: gc, opacity: 0.22 + eff * 0.6, transition: 'height 70ms linear' }} />
|
||||||
|
<div style={{ position: 'absolute', left: 0, right: 0, bottom: `${eff * 100}%`, height: 2, marginBottom: -1, background: gc, boxShadow: `0 0 8px ${gc}`, opacity: dim ? 0.4 : 0.9 }} />
|
||||||
|
{/* static-value ghost when live */}
|
||||||
|
{p.status === 'live' && (
|
||||||
|
<div style={{ position: 'absolute', left: 1, right: 1, bottom: `${p.val * 100}%`, height: 0, borderTop: '1px dashed rgba(255,255,255,0.35)' }} />
|
||||||
|
)}
|
||||||
|
{/* state glyph */}
|
||||||
|
<div style={{ position: 'absolute', top: 3, left: 0, right: 0, textAlign: 'center', fontSize: 9,
|
||||||
|
color: p.status === 'live' ? 'transparent' : p.status === 'fixed' ? 'var(--accent-2)' : 'var(--fg-dim)' }}>
|
||||||
|
{p.status === 'fixed' ? '⊟' : p.status === 'off' ? '∅' : ''}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{open === i && !compact && (
|
||||||
|
<window.OutputEditor param={p} onChange={(patch) => onChange(i, patch)} onHold={hold} onLeave={scheduleClose}
|
||||||
|
place={{ top: 38, [placeRight ? 'right' : 'left']: 0 }} />
|
||||||
|
)}
|
||||||
|
{open === i && compact && (
|
||||||
|
<window.OutputEditor param={p} onChange={(patch) => onChange(i, patch)} onHold={hold} onLeave={scheduleClose}
|
||||||
|
place={{ top: 26, [placeRight ? 'right' : 'left']: 0 }} />
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
window.OutputStage = OutputStage;
|
||||||
|
|
@ -0,0 +1,65 @@
|
||||||
|
/* Console 2.0 — Readout strip: the output heatmap as a control surface (the
|
||||||
|
thin top strip in Console). Same model as OutputStage:
|
||||||
|
- drag / click a cell → set value
|
||||||
|
- ⌥/alt-click a cell → cycle state (off → fixed → live)
|
||||||
|
- hover a cell → open the OutputEditor */
|
||||||
|
const RS_GROUP_COLOR = {
|
||||||
|
formant: '--accent', pitch: '--accent-2', amp: '--good', filter: '--warn', fx: '--info', mod: '--accent-3',
|
||||||
|
};
|
||||||
|
const RS_NEXT = { off: 'fixed', fixed: 'live', live: 'off' };
|
||||||
|
|
||||||
|
function ReadoutStrip({ params, values, onChange, pinned, onTogglePin }) {
|
||||||
|
const [open, setOpen] = React.useState(null);
|
||||||
|
const timers = React.useRef({ open: null, close: null });
|
||||||
|
const drag = React.useRef({ i: -1, moved: false, startY: 0, el: null, alt: false });
|
||||||
|
|
||||||
|
const scheduleOpen = (i) => { clearTimeout(timers.current.close); clearTimeout(timers.current.open); timers.current.open = setTimeout(() => setOpen(i), 110); };
|
||||||
|
const scheduleClose = () => { clearTimeout(timers.current.open); clearTimeout(timers.current.close); timers.current.close = setTimeout(() => setOpen(null), 280); };
|
||||||
|
const hold = () => clearTimeout(timers.current.close);
|
||||||
|
|
||||||
|
const valFromEvent = (el, clientY) => { const r = el.getBoundingClientRect(); return Math.max(0, Math.min(1, 1 - (clientY - r.top) / r.height)); };
|
||||||
|
const down = (e, i) => { e.currentTarget.setPointerCapture?.(e.pointerId); drag.current = { i, moved: false, startY: e.clientY, el: e.currentTarget, alt: e.altKey || e.metaKey }; };
|
||||||
|
const move = (e, i) => { const d = drag.current; if (d.i !== i) return; if (Math.abs(e.clientY - d.startY) > 3) d.moved = true; if (d.moved && !d.alt) onChange(i, { val: valFromEvent(d.el, e.clientY) }); };
|
||||||
|
const up = (e, i) => {
|
||||||
|
const d = drag.current; if (d.i !== i) return;
|
||||||
|
if (d.alt && !d.moved) onChange(i, { status: RS_NEXT[params[i].status] || 'live' });
|
||||||
|
else if (!d.moved) onChange(i, { val: valFromEvent(d.el, e.clientY) });
|
||||||
|
drag.current = { i: -1, moved: false, startY: 0, el: null, alt: false };
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div style={{ display: 'flex', alignItems: 'stretch', gap: 2, height: 76, padding: '0 2px',
|
||||||
|
background: 'var(--glass)', backdropFilter: 'blur(12px)', WebkitBackdropFilter: 'blur(12px)',
|
||||||
|
borderBottom: '1px solid var(--glass-line)', position: 'relative', zIndex: 30 }}>
|
||||||
|
<button type="button" onClick={onTogglePin} title="Pin strip open"
|
||||||
|
style={{ flex: '0 0 auto', width: 30, border: 0, background: 'transparent', color: pinned ? 'var(--accent)' : 'var(--fg-dim)', cursor: 'pointer', fontSize: 'var(--fs-md)' }}>
|
||||||
|
{pinned ? '📌' : '▾'}
|
||||||
|
</button>
|
||||||
|
{params.map((p, i) => {
|
||||||
|
const eff = values[i] ?? 0;
|
||||||
|
const gc = `var(${RS_GROUP_COLOR[p.group] || '--accent'})`;
|
||||||
|
const dim = p.status === 'off';
|
||||||
|
const placeRight = i > params.length - 5;
|
||||||
|
return (
|
||||||
|
<div key={i} style={{ position: 'relative', flex: 1, minWidth: 0, display: 'flex', flexDirection: 'column' }}
|
||||||
|
onPointerLeave={scheduleClose}>
|
||||||
|
{/* hover target: name ONLY (not the bar) */}
|
||||||
|
<div onPointerEnter={() => scheduleOpen(i)} style={{ textAlign: 'center', fontSize: 8, fontFamily: 'var(--font-mono)', lineHeight: '11px', cursor: 'help',
|
||||||
|
color: p.status === 'live' ? 'var(--fg-dim)' : gc, overflow: 'hidden', whiteSpace: 'nowrap', textOverflow: 'ellipsis' }}>{p.name}</div>
|
||||||
|
<div onPointerDown={(e) => down(e, i)} onPointerMove={(e) => move(e, i)} onPointerUp={(e) => up(e, i)} onPointerCancel={(e) => up(e, i)}
|
||||||
|
style={{ position: 'relative', flex: 1, background: 'var(--bg)', borderRadius: 2, overflow: 'hidden', cursor: 'ns-resize', opacity: dim ? 0.5 : 1, touchAction: 'none' }}>
|
||||||
|
<div style={{ position: 'absolute', left: 0, right: 0, bottom: 0, height: `${eff * 100}%`, background: gc, opacity: 0.25 + eff * 0.6, transition: 'height 60ms linear' }} />
|
||||||
|
{p.status === 'live' && <div style={{ position: 'absolute', left: 0, right: 0, bottom: `${p.val * 100}%`, height: 0, borderTop: '1px dashed rgba(255,255,255,0.3)' }} />}
|
||||||
|
{p.status !== 'live' && <div style={{ position: 'absolute', top: 1, left: 0, right: 0, textAlign: 'center', fontSize: 8, color: p.status === 'fixed' ? 'var(--accent-2)' : 'var(--fg-dim)' }}>{p.status === 'fixed' ? '⊟' : '∅'}</div>}
|
||||||
|
</div>
|
||||||
|
{open === i && (
|
||||||
|
<window.OutputEditor param={p} onChange={(patch) => onChange(i, patch)} onHold={hold} onLeave={scheduleClose}
|
||||||
|
place={{ top: 'calc(100% + 6px)', [placeRight ? 'right' : 'left']: 0 }} />
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
window.ReadoutStrip = ReadoutStrip;
|
||||||
|
|
@ -0,0 +1,16 @@
|
||||||
|
/* Console 2.0 — SplitStage: input and output given EQUAL prominence, side by
|
||||||
|
side. Left half = the Manifold (input), right half = the OutputStage (output
|
||||||
|
field). Both fully interactive; neither dominates. */
|
||||||
|
function SplitStage({ pos, onMove, noiseCap, pins, follow, onLongPress, params, values, onChange }) {
|
||||||
|
return (
|
||||||
|
<div style={{ position: 'absolute', inset: 0, display: 'flex' }}>
|
||||||
|
<div style={{ flex: 1, position: 'relative', borderRight: '1px solid var(--line)', minWidth: 0 }}>
|
||||||
|
<window.Manifold pos={pos} onMove={onMove} noiseCap={noiseCap} pins={pins} follow={follow} onLongPress={onLongPress} />
|
||||||
|
</div>
|
||||||
|
<div style={{ flex: 1, position: 'relative', minWidth: 0 }}>
|
||||||
|
<window.OutputStage params={params} values={values} onChange={onChange} compact />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
window.SplitStage = SplitStage;
|
||||||
|
|
@ -0,0 +1,76 @@
|
||||||
|
/* Console 2.0 — Verdict cluster: floating bottom-center, the app's main control.
|
||||||
|
▽ perturb · ↺ undo · △ commit, + A/B toggle. Long-press perturb = full re-roll.
|
||||||
|
Rests at low opacity, full on hover. */
|
||||||
|
function ThumbIcon({ size = 24, down = false }) {
|
||||||
|
// Minimal line-icon thumb, hairline stroke in currentColor.
|
||||||
|
return (
|
||||||
|
<svg width={size} height={size} viewBox="0 0 24 24" fill="none"
|
||||||
|
stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round"
|
||||||
|
style={{ transform: down ? 'rotate(180deg)' : 'none', display: 'block' }} aria-hidden="true">
|
||||||
|
<path d="M14 9V5a2.4 2.4 0 0 0-2.4-2.4L8 11v9h8.1a1.6 1.6 0 0 0 1.6-1.36l1.1-7.2A1.6 1.6 0 0 0 17.2 9z" />
|
||||||
|
<path d="M8 20H5.6A1.6 1.6 0 0 1 4 18.4v-5.8A1.6 1.6 0 0 1 5.6 11H8" />
|
||||||
|
</svg>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
window.ThumbIcon = ThumbIcon;
|
||||||
|
|
||||||
|
function VerdictCluster({ onPerturb, onUndo, onCommit, onReroll, canUndo, ab, onToggleAB, onHoldA, firstSession }) {
|
||||||
|
const [hover, setHover] = React.useState(false);
|
||||||
|
const lp = React.useRef(null);
|
||||||
|
const firedReroll = React.useRef(false);
|
||||||
|
|
||||||
|
const perturbDown = () => {
|
||||||
|
firedReroll.current = false;
|
||||||
|
lp.current = setTimeout(() => { firedReroll.current = true; onReroll(); }, 600);
|
||||||
|
};
|
||||||
|
const perturbUp = () => { clearTimeout(lp.current); if (!firedReroll.current) onPerturb(); };
|
||||||
|
|
||||||
|
const big = (extra) => ({
|
||||||
|
width: 64, height: 64, borderRadius: '50%', fontSize: 26, cursor: 'pointer',
|
||||||
|
display: 'flex', alignItems: 'center', justifyContent: 'center', fontFamily: 'var(--font-mono)',
|
||||||
|
border: '1px solid var(--glass-line)', transition: 'transform var(--dur-fast) var(--ease-console), background var(--dur-fast)', ...extra,
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
onPointerEnter={() => setHover(true)} onPointerLeave={() => setHover(false)}
|
||||||
|
style={{
|
||||||
|
position: 'absolute', bottom: 28, left: '50%', transform: 'translateX(-50%)',
|
||||||
|
display: 'flex', alignItems: 'center', gap: 'var(--sp-3)', padding: 'var(--sp-2) var(--sp-3)',
|
||||||
|
background: 'var(--glass)', backdropFilter: 'blur(14px)', WebkitBackdropFilter: 'blur(14px)',
|
||||||
|
border: '1px solid var(--glass-line)', borderRadius: 'var(--r-pill)', boxShadow: 'var(--shadow-2)',
|
||||||
|
opacity: hover || firstSession ? 1 : 0.55, transition: 'opacity var(--dur-med) var(--ease-console)', zIndex: 40,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<button type="button" title="Perturb — thumbs down (hold to re-roll)"
|
||||||
|
onPointerDown={perturbDown} onPointerUp={perturbUp} onPointerLeave={() => clearTimeout(lp.current)}
|
||||||
|
style={big({ background: 'rgba(255,68,102,0.16)', color: 'var(--danger)' })}
|
||||||
|
onMouseEnter={(e) => e.currentTarget.style.transform = 'scale(1.08)'}
|
||||||
|
onMouseLeave={(e) => e.currentTarget.style.transform = 'scale(1)'}><ThumbIcon down /></button>
|
||||||
|
|
||||||
|
<button type="button" title="Undo (z)" onClick={onUndo} disabled={!canUndo}
|
||||||
|
style={big({ width: 48, height: 48, fontSize: 20, background: 'var(--bg-2)', color: 'var(--fg-mute)', opacity: canUndo ? 1 : 0.4, cursor: canUndo ? 'pointer' : 'not-allowed' })}>↺</button>
|
||||||
|
|
||||||
|
<button type="button" title="Commit — thumbs up" onClick={onCommit}
|
||||||
|
style={big({ background: 'rgba(255,106,0,0.18)', color: 'var(--accent)', boxShadow: '0 0 16px var(--glow-accent)' })}
|
||||||
|
onMouseEnter={(e) => e.currentTarget.style.transform = 'scale(1.08)'}
|
||||||
|
onMouseLeave={(e) => e.currentTarget.style.transform = 'scale(1)'}><ThumbIcon /></button>
|
||||||
|
|
||||||
|
<div style={{ width: 1, height: 36, background: 'var(--glass-line)', margin: '0 2px' }} />
|
||||||
|
|
||||||
|
<div
|
||||||
|
title="A/B compare — hold to preview A"
|
||||||
|
onPointerDown={() => onHoldA(true)} onPointerUp={() => onHoldA(false)} onPointerLeave={() => onHoldA(false)}
|
||||||
|
onClick={onToggleAB}
|
||||||
|
style={{ display: 'flex', borderRadius: 'var(--r-pill)', overflow: 'hidden', border: '1px solid var(--glass-line)', cursor: 'pointer', userSelect: 'none' }}>
|
||||||
|
{['A', 'B'].map((k) => (
|
||||||
|
<span key={k} style={{
|
||||||
|
padding: '8px 14px', fontSize: 'var(--fs-sm)', fontWeight: 600,
|
||||||
|
background: ab === k ? 'var(--accent)' : 'transparent', color: ab === k ? 'var(--bg)' : 'var(--fg-mute)',
|
||||||
|
}}>{k}</span>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
window.VerdictCluster = VerdictCluster;
|
||||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue