Compare commits
3 commits
68f7d681fe
...
acb8cb7696
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
acb8cb7696 | ||
|
|
1461779e23 | ||
|
|
b853113ac1 |
14 changed files with 580 additions and 58 deletions
1
MAP.md
1
MAP.md
|
|
@ -112,6 +112,7 @@ the "BUILD DELTAS" block at the top of `vcv/SPEC.md`). `src/MEMLNaut.cpp` (modul
|
||||||
|
|
||||||
### `scripts/` — build + verify entry points
|
### `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-firmware.sh`, `flash-firmware.sh`, `build-and-flash-firmware.sh`, `firmware-common.sh` — Arduino-CLI wrapper for RP2350 target with C++20 flag.
|
||||||
|
- `flash-useq-main.sh`, `flash-useq-expander.sh` — build + flash the uSEQ-CV firmware (`firmware/useq-celium/{main,expander}`) via PlatformIO (nix-shell fallback for `pio`).
|
||||||
- `build-wasm.sh` — Emscripten compile producing `playground/public/nisps.{wasm,js}`.
|
- `build-wasm.sh` — Emscripten compile producing `playground/public/nisps.{wasm,js}`.
|
||||||
- `build-cpp-tests.sh` — CMake configure + build + ctest (Ninja).
|
- `build-cpp-tests.sh` — CMake configure + build + ctest (Ninja).
|
||||||
- `parity-check.sh` — runs native + WASM and diffs binary outputs.
|
- `parity-check.sh` — runs native + WASM and diffs binary outputs.
|
||||||
|
|
|
||||||
|
|
@ -104,13 +104,21 @@ vary sequence count.
|
||||||
|
|
||||||
### Browser (Manifold) — dynamic, switchable live
|
### Browser (Manifold) — dynamic, switchable live
|
||||||
|
|
||||||
Same three **plus** a fourth, and with **as many ratio sequences as the user wants**
|
Same three **plus** a fourth, and with **more ratio sequences than the firmware's 2**.
|
||||||
(each gate sequence = its own independent 7-param track; the net reshapes to suit):
|
|
||||||
|
|
||||||
- **Continuous & Rhythm (split nets)** — Continuous MLP + a separate Rhythm MLP.
|
**How extra tracks work (IMPLEMENTED, 2026-06-29).** The browser WASM net is fixed
|
||||||
Browser-only (two MLP heads; hardware uses one). `output_size`: shared net =
|
at `MLP<32,…,126>` — it does **not** reshape per mode. MEMLCelium maps the first
|
||||||
`continuous + 7 × n_gates` (mind the 126-output WASM cap → ~16 gates max shared);
|
56 outputs (14 rhythm + 42 synth); outputs **[56..125] are computed but unused**.
|
||||||
split net = the Rhythm net is sized independently, so it scales further.
|
So the browser borrows them: native tracks 0–1 read the real rhythm at [0..13]
|
||||||
|
(in sync with the audio); browser-only tracks 2+ read the spare window
|
||||||
|
[56, 63, …] — **up to 12 tracks total** ((126−56)/7 = 10 extra). The firmware is
|
||||||
|
untouched (still 2). Caveat: it's ONE shared net, so RL feedback that shapes the
|
||||||
|
synth also nudges the extra tracks — they are not *independently* trained. (Per-
|
||||||
|
engine layout lives in `manifold/src/backends/useBackendManager.ts` `RHYTHM_LAYOUTS`.)
|
||||||
|
|
||||||
|
- **Continuous & Rhythm (split nets)** — Continuous MLP + a separate, independently
|
||||||
|
trained Rhythm MLP. Browser-only, NOT yet built — this is the upgrade that
|
||||||
|
decouples the extra tracks from the synth (two MLP heads; hardware uses one).
|
||||||
|
|
||||||
The browser mode is implied by the Outputs config (§4), not a separate picker:
|
The browser mode is implied by the Outputs config (§4), not a separate picker:
|
||||||
choosing continuous-count > 0 and gate-sequences = 0 ⇒ Continuous-only;
|
choosing continuous-count > 0 and gate-sequences = 0 ⇒ Continuous-only;
|
||||||
|
|
|
||||||
|
|
@ -27,12 +27,22 @@ expander/ uSEQ expander: I2C slave → CV4..11 (8× PWM)
|
||||||
The main board forwards CV4–CV11 to the expander over I2C (addr `0x10`, 400 kHz)
|
The main board forwards CV4–CV11 to the expander over I2C (addr `0x10`, 400 kHz)
|
||||||
and rescans every 2 s until the expander is found (hot-attach friendly).
|
and rescans every 2 s until the expander is found (hot-attach friendly).
|
||||||
|
|
||||||
## Build / flash (PlatformIO)
|
## Build / flash
|
||||||
|
|
||||||
|
Convenience scripts (resolve PlatformIO via `nix-shell` if `pio` isn't on PATH;
|
||||||
|
extra args pass through to `pio`, e.g. `--upload-port /dev/ttyACM0`):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
scripts/flash-useq-main.sh # build + flash the main module
|
||||||
|
scripts/flash-useq-expander.sh # build + flash the expander
|
||||||
|
```
|
||||||
|
|
||||||
|
If an upload can't auto-reset the board, hold **BOOTSEL** while plugging in USB.
|
||||||
|
|
||||||
|
Raw PlatformIO, equivalently:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# main board
|
|
||||||
cd firmware/useq-celium/main && pio run -e main -t upload
|
cd firmware/useq-celium/main && pio run -e main -t upload
|
||||||
# expander board
|
|
||||||
cd firmware/useq-celium/expander && pio run -e expander -t upload
|
cd firmware/useq-celium/expander && pio run -e expander -t upload
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,10 +31,15 @@ import {
|
||||||
encodeOutput,
|
encodeOutput,
|
||||||
FRAME_IDENTIFY_LEN,
|
FRAME_IDENTIFY_LEN,
|
||||||
} from './useq-protocol';
|
} from './useq-protocol';
|
||||||
|
import { RatioSeqEngine, decodeTrack } from './ratio-seq';
|
||||||
|
|
||||||
const SEND_INTERVAL_MS = 1000 / STREAM_HZ; // ~10 ms
|
const SEND_INTERVAL_MS = 1000 / STREAM_HZ; // ~10 ms
|
||||||
const CV_DEAD_ZONE = 8; // on the 12-bit value (~0.2%)
|
const CV_DEAD_ZONE = 8; // on the 12-bit value (~0.2%)
|
||||||
const IDENTIFY_TIMEOUT_MS = 5000;
|
const IDENTIFY_TIMEOUT_MS = 5000;
|
||||||
|
const MAX_TRACKS = 16; // gate-sequence RatioSeq tracks (7 rhythm params each)
|
||||||
|
// The firmware streams INPUT frames at 20 Hz, so a live module proves itself
|
||||||
|
// within ~50 ms. Allow for a USB-CDC (DTR) reset on open before giving up.
|
||||||
|
const HANDSHAKE_TIMEOUT_MS = 2500;
|
||||||
|
|
||||||
/** Resolve a channel id into a fast {kind, index} target (or null for 'none'). */
|
/** Resolve a channel id into a fast {kind, index} target (or null for 'none'). */
|
||||||
type Target = { kind: 'cv'; idx: number } | { kind: 'gate'; idx: number } | null;
|
type Target = { kind: 'cv'; idx: number } | { kind: 'gate'; idx: number } | null;
|
||||||
|
|
@ -57,10 +62,14 @@ export class UseqCvBackend implements OutputBackend {
|
||||||
private writer: WritableStreamDefaultWriter<Uint8Array> | null = null;
|
private writer: WritableStreamDefaultWriter<Uint8Array> | null = null;
|
||||||
private reader: ReadableStreamDefaultReader<Uint8Array> | null = null;
|
private reader: ReadableStreamDefaultReader<Uint8Array> | null = null;
|
||||||
private parser = new UseqRxParser(
|
private parser = new UseqRxParser(
|
||||||
() => {},
|
() => this.onDeviceFrame(), // any INPUT frame proves the module is alive
|
||||||
(ok) => this.onAck(ok),
|
(ok) => this.onAck(ok),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/** True once a valid device→host frame has been received (handshake OK). */
|
||||||
|
private handshook = false;
|
||||||
|
private handshakeTimer: ReturnType<typeof setTimeout> | null = null;
|
||||||
|
|
||||||
private cvVals = new Uint16Array(NUM_CV); // last computed 12-bit CV per channel
|
private cvVals = new Uint16Array(NUM_CV); // last computed 12-bit CV per channel
|
||||||
private gateBits = 0;
|
private gateBits = 0;
|
||||||
private lastCv = new Int32Array(NUM_CV).fill(-1);
|
private lastCv = new Int32Array(NUM_CV).fill(-1);
|
||||||
|
|
@ -68,6 +77,19 @@ export class UseqCvBackend implements OutputBackend {
|
||||||
private lastSendMs = 0;
|
private lastSendMs = 0;
|
||||||
private writing = false; // in-flight write guard (avoid serial backpressure)
|
private writing = false; // in-flight write guard (avoid serial backpressure)
|
||||||
|
|
||||||
|
// Gate sequencer (the rhythm stream): RatioSeq tracks decoded from the rhythm
|
||||||
|
// slice of the routed output vector. `trackDone` memoises one eval per tick.
|
||||||
|
private seq = new RatioSeqEngine();
|
||||||
|
private trackGate = new Uint8Array(MAX_TRACKS);
|
||||||
|
private trackDone = new Uint8Array(MAX_TRACKS);
|
||||||
|
/**
|
||||||
|
* track → output base index for the 7-param rhythm slice. The native tracks
|
||||||
|
* point at the engine's real rhythm params; browser-only extra tracks borrow
|
||||||
|
* the net's spare outputs (beyond the engine's param count). Empty ⇒ contiguous
|
||||||
|
* `track*7` fallback. Set by the dock from the active engine's layout.
|
||||||
|
*/
|
||||||
|
private rhythmBases: number[] = [];
|
||||||
|
|
||||||
private pendingIdentify: (() => void) | null = null;
|
private pendingIdentify: (() => void) | null = null;
|
||||||
|
|
||||||
private statusState: BackendStatus = { state: 'idle', message: 'CV idle' };
|
private statusState: BackendStatus = { state: 'idle', message: 'CV idle' };
|
||||||
|
|
@ -84,7 +106,11 @@ export class UseqCvBackend implements OutputBackend {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (this.port) {
|
if (this.port) {
|
||||||
this.setStatus({ state: 'ready', message: 'uSEQ connected' });
|
this.setStatus(
|
||||||
|
this.handshook
|
||||||
|
? { state: 'ready', message: 'uSEQ handshake OK' }
|
||||||
|
: { state: 'connecting', message: 'uSEQ port open — waiting for module…' },
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Try to silently re-open a previously-granted port (no user gesture needed).
|
// Try to silently re-open a previously-granted port (no user gesture needed).
|
||||||
|
|
@ -97,14 +123,14 @@ export class UseqCvBackend implements OutputBackend {
|
||||||
} catch {
|
} catch {
|
||||||
/* ignore — fall through to the idle "connect" prompt */
|
/* ignore — fall through to the idle "connect" prompt */
|
||||||
}
|
}
|
||||||
this.setStatus({ state: 'ready', message: 'uSEQ ready — click Connect device' });
|
this.setStatus({ state: 'idle', message: 'No uSEQ — click Connect device' });
|
||||||
}
|
}
|
||||||
|
|
||||||
setContext(ctx: BackendContext): void {
|
setContext(ctx: BackendContext): void {
|
||||||
this.ctx = ctx;
|
this.ctx = ctx;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Update the per-output CV specs (channel + gate threshold). */
|
/** Update the per-output CV specs (channel, gate source/track/threshold). */
|
||||||
setCvConfig(specs: CvSpec[]): void {
|
setCvConfig(specs: CvSpec[]): void {
|
||||||
this.specs = specs;
|
this.specs = specs;
|
||||||
this.targets = specs.map((s) => resolveTarget(s.channel));
|
this.targets = specs.map((s) => resolveTarget(s.channel));
|
||||||
|
|
@ -112,6 +138,20 @@ export class UseqCvBackend implements OutputBackend {
|
||||||
this.lastGateBits = -1;
|
this.lastGateBits = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Tempo for the gate sequencer (BPM, 4/4). */
|
||||||
|
setBpm(bpm: number): void {
|
||||||
|
this.seq.setBpm(bpm);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the rhythm track → output-base mapping (per active engine). Native tracks
|
||||||
|
* read real rhythm params; browser-only extra tracks read the net's spare
|
||||||
|
* outputs. Pass `[]` to fall back to contiguous `track*7`.
|
||||||
|
*/
|
||||||
|
setRhythmLayout(bases: number[]): void {
|
||||||
|
this.rhythmBases = bases;
|
||||||
|
}
|
||||||
|
|
||||||
/** User-gesture path: pick + open a serial port. Throws if the user cancels. */
|
/** User-gesture path: pick + open a serial port. Throws if the user cancels. */
|
||||||
async connect(): Promise<void> {
|
async connect(): Promise<void> {
|
||||||
if (!this.isAvailable()) {
|
if (!this.isAvailable()) {
|
||||||
|
|
@ -123,7 +163,7 @@ export class UseqCvBackend implements OutputBackend {
|
||||||
try {
|
try {
|
||||||
port = await navigator.serial.requestPort();
|
port = await navigator.serial.requestPort();
|
||||||
} catch {
|
} catch {
|
||||||
this.setStatus({ state: 'ready', message: 'uSEQ ready — click Connect device' });
|
this.setStatus({ state: 'idle', message: 'No uSEQ — click Connect device' });
|
||||||
return; // user dismissed the picker
|
return; // user dismissed the picker
|
||||||
}
|
}
|
||||||
await this.open(port);
|
await this.open(port);
|
||||||
|
|
@ -140,11 +180,43 @@ export class UseqCvBackend implements OutputBackend {
|
||||||
this.writer = port.writable?.getWriter() ?? null;
|
this.writer = port.writable?.getWriter() ?? null;
|
||||||
this.lastCv.fill(-1);
|
this.lastCv.fill(-1);
|
||||||
this.lastGateBits = -1;
|
this.lastGateBits = -1;
|
||||||
|
this.handshook = false;
|
||||||
if (typeof port.addEventListener === 'function') {
|
if (typeof port.addEventListener === 'function') {
|
||||||
port.addEventListener('disconnect', () => this.handleDisconnect());
|
port.addEventListener('disconnect', () => this.handleDisconnect());
|
||||||
}
|
}
|
||||||
this.startReadLoop();
|
this.startReadLoop();
|
||||||
this.setStatus({ state: 'ready', message: 'uSEQ connected' });
|
// Port is open, but a handshake isn't confirmed until the module talks back.
|
||||||
|
this.setStatus({ state: 'connecting', message: 'uSEQ port open — waiting for module…' });
|
||||||
|
this.armHandshakeWatchdog();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** If no device frame arrives within the timeout, surface a clear error. */
|
||||||
|
private armHandshakeWatchdog(): void {
|
||||||
|
this.clearHandshakeWatchdog();
|
||||||
|
this.handshakeTimer = setTimeout(() => {
|
||||||
|
this.handshakeTimer = null;
|
||||||
|
if (this.port && !this.handshook) {
|
||||||
|
this.setStatus({
|
||||||
|
state: 'error',
|
||||||
|
message: 'No response from module — check firmware / cable, then Identify',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, HANDSHAKE_TIMEOUT_MS);
|
||||||
|
}
|
||||||
|
|
||||||
|
private clearHandshakeWatchdog(): void {
|
||||||
|
if (this.handshakeTimer !== null) {
|
||||||
|
clearTimeout(this.handshakeTimer);
|
||||||
|
this.handshakeTimer = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** A valid device→host frame arrived → the module is alive (handshake OK). */
|
||||||
|
private onDeviceFrame(): void {
|
||||||
|
this.clearHandshakeWatchdog();
|
||||||
|
if (this.handshook) return;
|
||||||
|
this.handshook = true;
|
||||||
|
if (this.port) this.setStatus({ state: 'ready', message: 'uSEQ handshake OK' });
|
||||||
}
|
}
|
||||||
|
|
||||||
private async startReadLoop(): Promise<void> {
|
private async startReadLoop(): Promise<void> {
|
||||||
|
|
@ -175,22 +247,30 @@ export class UseqCvBackend implements OutputBackend {
|
||||||
if (!w) return;
|
if (!w) return;
|
||||||
const frame = new Uint8Array(FRAME_IDENTIFY_LEN);
|
const frame = new Uint8Array(FRAME_IDENTIFY_LEN);
|
||||||
encodeIdentify(frame);
|
encodeIdentify(frame);
|
||||||
this.setStatus({ state: 'connecting', message: 'Identify… (watch the LEDs)' });
|
this.setStatus({ state: 'connecting', message: 'Identify sent — watch the LEDs…' });
|
||||||
let settled = false;
|
let settled = false;
|
||||||
const done = (msg: string) => {
|
const done = (s: BackendStatus) => {
|
||||||
if (settled) return;
|
if (settled) return;
|
||||||
settled = true;
|
settled = true;
|
||||||
this.pendingIdentify = null;
|
this.pendingIdentify = null;
|
||||||
if (this.port) this.setStatus({ state: 'ready', message: msg });
|
if (this.port) this.setStatus(s);
|
||||||
};
|
};
|
||||||
this.pendingIdentify = () => done('uSEQ connected — identify ack');
|
this.pendingIdentify = () => done({ state: 'ready', message: 'uSEQ handshake OK — LEDs flashed' });
|
||||||
w.write(frame).catch(() => done('uSEQ connected'));
|
w.write(frame).catch(() => done({ state: 'error', message: 'Identify failed — module not responding' }));
|
||||||
setTimeout(() => done('uSEQ connected'), IDENTIFY_TIMEOUT_MS);
|
setTimeout(
|
||||||
|
() =>
|
||||||
|
done(
|
||||||
|
this.handshook
|
||||||
|
? { state: 'ready', message: 'uSEQ handshake OK' }
|
||||||
|
: { state: 'error', message: 'No identify ack — check firmware / cable' },
|
||||||
|
),
|
||||||
|
IDENTIFY_TIMEOUT_MS,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private onAck(ok: boolean): void {
|
private onAck(_ok: boolean): void {
|
||||||
|
this.onDeviceFrame(); // an ack is also proof the module is alive
|
||||||
if (this.pendingIdentify) this.pendingIdentify();
|
if (this.pendingIdentify) this.pendingIdentify();
|
||||||
else if (ok && this.port) this.setStatus({ state: 'ready', message: 'uSEQ connected' });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
send(routed: Float32Array): void {
|
send(routed: Float32Array): void {
|
||||||
|
|
@ -200,11 +280,16 @@ export class UseqCvBackend implements OutputBackend {
|
||||||
|
|
||||||
const now = typeof performance !== 'undefined' ? performance.now() : Date.now();
|
const now = typeof performance !== 'undefined' ? performance.now() : Date.now();
|
||||||
if (now - this.lastSendMs < SEND_INTERVAL_MS) return;
|
if (now - this.lastSendMs < SEND_INTERVAL_MS) return;
|
||||||
|
// Advance the gate-sequencer clock every tick (even if we end up not
|
||||||
|
// transmitting), clamping any backgrounded-tab jump.
|
||||||
|
const dt = Math.min(0.1, (now - this.lastSendMs) / 1000);
|
||||||
this.lastSendMs = now;
|
this.lastSendMs = now;
|
||||||
|
this.seq.advance(dt);
|
||||||
if (this.writing) return; // previous frame still draining — drop this one
|
if (this.writing) return; // previous frame still draining — drop this one
|
||||||
|
|
||||||
// Rebuild the 14-channel snapshot from the routed outputs.
|
// Rebuild the 14-channel snapshot from the routed outputs.
|
||||||
this.cvVals.fill(0);
|
this.cvVals.fill(0);
|
||||||
|
this.trackDone.fill(0);
|
||||||
let gates = 0;
|
let gates = 0;
|
||||||
const n = Math.min(routed.length, ctx.mappings.length, this.targets.length);
|
const n = Math.min(routed.length, ctx.mappings.length, this.targets.length);
|
||||||
for (let i = 0; i < n; i++) {
|
for (let i = 0; i < n; i++) {
|
||||||
|
|
@ -212,11 +297,15 @@ export class UseqCvBackend implements OutputBackend {
|
||||||
if (!t) continue;
|
if (!t) continue;
|
||||||
const m = ctx.mappings[i];
|
const m = ctx.mappings[i];
|
||||||
if (isSilent(m)) continue;
|
if (isSilent(m)) continue;
|
||||||
const mapped = mapOutput(routed[i], m); // 0..1 in [min,max]
|
|
||||||
if (t.kind === 'cv') {
|
if (t.kind === 'cv') {
|
||||||
if (t.idx >= 0 && t.idx < NUM_CV) this.cvVals[t.idx] = cvToWire(mapped);
|
if (t.idx >= 0 && t.idx < NUM_CV) this.cvVals[t.idx] = cvToWire(mapOutput(routed[i], m));
|
||||||
} else if (t.idx >= 0 && t.idx < 3) {
|
} else if (t.idx >= 0 && t.idx < 3) {
|
||||||
if (mapped >= (this.specs[i]?.gateThreshold ?? 0.5)) gates |= 1 << t.idx;
|
const spec = this.specs[i];
|
||||||
|
const on =
|
||||||
|
spec?.gateSource === 'threshold'
|
||||||
|
? mapOutput(routed[i], m) >= (spec.gateThreshold ?? 0.5)
|
||||||
|
: this.seqGate(spec?.seqTrack ?? 0, routed);
|
||||||
|
if (on) gates |= 1 << t.idx;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -243,8 +332,25 @@ export class UseqCvBackend implements OutputBackend {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gate level for RatioSeq `track`, evaluated at most once per tick. The track's
|
||||||
|
* 7 params are the rhythm slice of the routed vector at [track*7 .. +6] — which
|
||||||
|
* for the MEMLCelium / SLP-Workshop engine are outputs [0..13] (its 2 tracks).
|
||||||
|
*/
|
||||||
|
private seqGate(track: number, routed: Float32Array): boolean {
|
||||||
|
if (track < 0 || track >= MAX_TRACKS) return false;
|
||||||
|
if (!this.trackDone[track]) {
|
||||||
|
const base = this.rhythmBases.length ? (this.rhythmBases[track] ?? -1) : track * 7;
|
||||||
|
this.trackGate[track] = base >= 0 && this.seq.evalTrack(track, decodeTrack(routed, base)).gate ? 1 : 0;
|
||||||
|
this.trackDone[track] = 1;
|
||||||
|
}
|
||||||
|
return this.trackGate[track] === 1;
|
||||||
|
}
|
||||||
|
|
||||||
private handleDisconnect(): void {
|
private handleDisconnect(): void {
|
||||||
if (!this.port) return;
|
if (!this.port) return;
|
||||||
|
this.clearHandshakeWatchdog();
|
||||||
|
this.handshook = false;
|
||||||
this.port = null;
|
this.port = null;
|
||||||
this.writer = null;
|
this.writer = null;
|
||||||
this.setStatus({ state: 'error', message: 'uSEQ disconnected — click Connect device' });
|
this.setStatus({ state: 'error', message: 'uSEQ disconnected — click Connect device' });
|
||||||
|
|
@ -252,10 +358,12 @@ export class UseqCvBackend implements OutputBackend {
|
||||||
|
|
||||||
async disconnect(): Promise<void> {
|
async disconnect(): Promise<void> {
|
||||||
await this.closePort();
|
await this.closePort();
|
||||||
this.setStatus({ state: 'ready', message: 'uSEQ ready — click Connect device' });
|
this.setStatus({ state: 'idle', message: 'No uSEQ — click Connect device' });
|
||||||
}
|
}
|
||||||
|
|
||||||
private async closePort(): Promise<void> {
|
private async closePort(): Promise<void> {
|
||||||
|
this.clearHandshakeWatchdog();
|
||||||
|
this.handshook = false;
|
||||||
try {
|
try {
|
||||||
this.reader?.cancel().catch(() => {});
|
this.reader?.cancel().catch(() => {});
|
||||||
this.writer?.releaseLock();
|
this.writer?.releaseLock();
|
||||||
|
|
|
||||||
66
manifold/src/backends/ratio-seq.test.ts
Normal file
66
manifold/src/backends/ratio-seq.test.ts
Normal file
|
|
@ -0,0 +1,66 @@
|
||||||
|
/**
|
||||||
|
* RatioSeqEngine tests (bun test) — pin the gate generator against the C++
|
||||||
|
* engine's decode + ratio_seq semantics so the browser stays in parity.
|
||||||
|
*/
|
||||||
|
import { expect, test } from 'bun:test';
|
||||||
|
import { RatioSeqEngine, decodeTrack, ratioSeq } from './ratio-seq';
|
||||||
|
|
||||||
|
test('decodeTrack matches the C++ set_params decode', () => {
|
||||||
|
// params all 0.5 → ratios int(1.5)=1 +1 = 2; phasorMul muls[int(1.999..)&3]=muls[1]=2;
|
||||||
|
// phaseOff int(2.0)*0.25 = 0.5; ampRatios int(1.5)+1 = 2.
|
||||||
|
const d = decodeTrack([0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5]);
|
||||||
|
expect(d.ratios).toEqual([2, 2, 2]);
|
||||||
|
expect(d.ratioSum).toBe(6);
|
||||||
|
expect(d.phasorMul).toBe(2);
|
||||||
|
expect(d.phaseOff).toBe(0.5);
|
||||||
|
expect(d.ampRatios).toEqual([2, 2]);
|
||||||
|
expect(d.ampRatioSum).toBe(4);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('decodeTrack extremes: 0 → minimum 1, ~1 → maximum 4', () => {
|
||||||
|
const lo = decodeTrack([0, 0, 0, 0, 0, 0, 0]);
|
||||||
|
expect(lo.ratios).toEqual([1, 1, 1]);
|
||||||
|
expect(lo.phasorMul).toBe(1); // muls[0]
|
||||||
|
expect(lo.phaseOff).toBe(0);
|
||||||
|
const hi = decodeTrack([0.99, 0.99, 0.99, 0.99, 0.5, 0.99, 0.99]);
|
||||||
|
expect(hi.ratios).toEqual([3, 3, 3]); // int(2.97)+1
|
||||||
|
expect(hi.phasorMul).toBe(8); // muls[int(3.95)&3=3]
|
||||||
|
});
|
||||||
|
|
||||||
|
test('ratioSeq: phasor 0 is on (start of first segment), pulse-width boundary', () => {
|
||||||
|
const ratios = [1, 1, 1];
|
||||||
|
const sum = 3;
|
||||||
|
expect(ratioSeq(0, sum, ratios, 0.5)).toBe(true); // beatPhase 0 ≤ 0.5
|
||||||
|
// Just inside segment 0: phaseAdj = 3*0.1 = 0.3, segment0 [0,1], beatPhase 0.3 ≤ 0.5 → on
|
||||||
|
expect(ratioSeq(0.1, sum, ratios, 0.5)).toBe(true);
|
||||||
|
// Late in segment 0: phaseAdj = 3*0.3 = 0.9, beatPhase 0.9 > 0.5 → off
|
||||||
|
expect(ratioSeq(0.3, sum, ratios, 0.5)).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('clock advances a 4/4 bar at the set BPM and wraps', () => {
|
||||||
|
const seq = new RatioSeqEngine();
|
||||||
|
seq.setBpm(120); // bar = (60/120)*4 = 2 s
|
||||||
|
expect(seq.phase()).toBe(0);
|
||||||
|
seq.advance(0.5); // quarter of a bar
|
||||||
|
expect(seq.phase()).toBeCloseTo(0.25, 6);
|
||||||
|
seq.advance(2.0); // a full bar later → wraps back to 0.25
|
||||||
|
expect(seq.phase()).toBeCloseTo(0.25, 6);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('evalTrack reports rising/falling edges across ticks', () => {
|
||||||
|
const seq = new RatioSeqEngine();
|
||||||
|
seq.setBpm(120);
|
||||||
|
const d = decodeTrack([0, 0, 0, 0, 0, 0.99, 0.99]); // ratios 1,1,1; phasorMul 1; phaseOff 0
|
||||||
|
// At phase 0 → gate on (rising on first eval).
|
||||||
|
const a = seq.evalTrack(0, d);
|
||||||
|
expect(a.gate).toBe(true);
|
||||||
|
expect(a.rising).toBe(true);
|
||||||
|
expect(a.falling).toBe(false);
|
||||||
|
expect(a.velocity).toBe(1); // ampRatios decode → high
|
||||||
|
// Advance past the pulse (into the off part of the cycle) → falling edge.
|
||||||
|
seq.advance(0.6); // 0.3 of the bar; phaseAdj = 3*0.3 = 0.9 > pw → off
|
||||||
|
const b = seq.evalTrack(0, d);
|
||||||
|
expect(b.gate).toBe(false);
|
||||||
|
expect(b.falling).toBe(true);
|
||||||
|
expect(b.rising).toBe(false);
|
||||||
|
});
|
||||||
136
manifold/src/backends/ratio-seq.ts
Normal file
136
manifold/src/backends/ratio-seq.ts
Normal file
|
|
@ -0,0 +1,136 @@
|
||||||
|
/**
|
||||||
|
* RatioSeqEngine — browser-side gate sequencer, a faithful TS port of the
|
||||||
|
* MEMLCelium / SLP-Workshop engine's internal ratio sequencer
|
||||||
|
* (`nisps/engines/memlcelium.hpp` + `ratio_seq` in `nisps/engines/breakor.hpp`).
|
||||||
|
*
|
||||||
|
* It turns the **rhythm** slice of the model output vector — 7 params per track,
|
||||||
|
* exactly as the C++ engine decodes outputs [0..13] into its 2 sequences — into
|
||||||
|
* clock-driven gate events. This is the gate generator the spec calls for so the
|
||||||
|
* CV and MIDI backends can emit gate sequences without running the audio engine
|
||||||
|
* (docs/slp-workshop/SPEC.md §2). Pure + framework-neutral; unit-tested.
|
||||||
|
*
|
||||||
|
* Per-track raw params (each 0..1, in this order):
|
||||||
|
* [0,1,2] ratios → int(p*3)+1 (1..4)
|
||||||
|
* [3] phasorMul→ {1,2,4,8}[int(p*3.999999) & 3]
|
||||||
|
* [4] phaseOff → int(p*4) * 0.25 ({0,.25,.5,.75})
|
||||||
|
* [5,6] ampRatios→ int(p*3)+1 (1..4)
|
||||||
|
*
|
||||||
|
* Clock: a 4/4 bar phasor (matches `update_bpm`: bar = 4 beats); advance() moves
|
||||||
|
* it by dt/bar_seconds. Gate per track = `ratioSeq(seqPhasor, ratios, pw=0.5)`;
|
||||||
|
* a second ratio set picks a 2-level velocity (firmware parity: 127/64 → 1.0/0.5).
|
||||||
|
*/
|
||||||
|
|
||||||
|
const PULSE_WIDTH = 0.5; // firmware parity (per-track pulse width is a deferred extension)
|
||||||
|
const VELOCITY_HIGH = 1.0;
|
||||||
|
const VELOCITY_LOW = 64 / 127; // ≈0.504, mirrors the engine's 64/127
|
||||||
|
const PHASOR_MULS = [1, 2, 4, 8] as const;
|
||||||
|
|
||||||
|
/** Decoded per-track sequence parameters. */
|
||||||
|
export interface SeqParams {
|
||||||
|
ratios: [number, number, number];
|
||||||
|
ratioSum: number;
|
||||||
|
phasorMul: number;
|
||||||
|
phaseOff: number;
|
||||||
|
ampRatios: [number, number];
|
||||||
|
ampRatioSum: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Per-track evaluation result for one tick. */
|
||||||
|
export interface GateState {
|
||||||
|
/** Gate level — true while inside a pulse. */
|
||||||
|
gate: boolean;
|
||||||
|
/** 2-level velocity / accent in [0,1] for the current pulse. */
|
||||||
|
velocity: number;
|
||||||
|
/** Gate just went high this tick (note-on edge). */
|
||||||
|
rising: boolean;
|
||||||
|
/** Gate just went low this tick (note-off edge). */
|
||||||
|
falling: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Decode 7 raw params (starting at `off`) into sequence params (matches set_params). */
|
||||||
|
export function decodeTrack(p: ArrayLike<number>, off = 0): SeqParams {
|
||||||
|
const q = (i: number) => p[off + i] ?? 0;
|
||||||
|
const r0 = ((q(0) * 3) | 0) + 1;
|
||||||
|
const r1 = ((q(1) * 3) | 0) + 1;
|
||||||
|
const r2 = ((q(2) * 3) | 0) + 1;
|
||||||
|
const a0 = ((q(5) * 3) | 0) + 1;
|
||||||
|
const a1 = ((q(6) * 3) | 0) + 1;
|
||||||
|
return {
|
||||||
|
ratios: [r0, r1, r2],
|
||||||
|
ratioSum: r0 + r1 + r2,
|
||||||
|
phasorMul: PHASOR_MULS[((q(3) * 3.999999) | 0) & 3],
|
||||||
|
phaseOff: ((q(4) * 4) | 0) * 0.25,
|
||||||
|
ampRatios: [a0, a1],
|
||||||
|
ampRatioSum: a0 + a1,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The ratio sequencer pulse test (port of `ratio_seq` in breakor.hpp): carve the
|
||||||
|
* cycle into segments proportional to `ratios`; the segment the phasor lands in
|
||||||
|
* is "on" for its first `pulseWidth` fraction.
|
||||||
|
*/
|
||||||
|
export function ratioSeq(phasor: number, ratioSum: number, ratios: ArrayLike<number>, pulseWidth: number): boolean {
|
||||||
|
let offsetPhase = phasor;
|
||||||
|
if (offsetPhase >= 1) offsetPhase -= 1;
|
||||||
|
const phaseAdj = ratioSum * offsetPhase;
|
||||||
|
let accum = 0;
|
||||||
|
let last = 0;
|
||||||
|
for (let i = 0; i < ratios.length; i++) {
|
||||||
|
accum += ratios[i];
|
||||||
|
if (phaseAdj <= accum) {
|
||||||
|
const beatPhase = (phaseAdj - last) / (accum - last);
|
||||||
|
return beatPhase <= pulseWidth;
|
||||||
|
}
|
||||||
|
last = accum;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class RatioSeqEngine {
|
||||||
|
private barPhasor = 0;
|
||||||
|
private bpm = 120;
|
||||||
|
private lastTrig: boolean[] = [];
|
||||||
|
|
||||||
|
/** Set tempo (BPM, 4/4). */
|
||||||
|
setBpm(bpm: number): void {
|
||||||
|
this.bpm = bpm > 0 ? bpm : 120;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Reset the clock + per-track edge memory (e.g. on stop / reconfigure). */
|
||||||
|
reset(): void {
|
||||||
|
this.barPhasor = 0;
|
||||||
|
this.lastTrig.length = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Advance the bar phasor by `dtSeconds` of wall-clock time. */
|
||||||
|
advance(dtSeconds: number): void {
|
||||||
|
const barSeconds = (60 / this.bpm) * 4; // 4/4
|
||||||
|
this.barPhasor += dtSeconds / barSeconds;
|
||||||
|
if (this.barPhasor >= 1) this.barPhasor -= Math.floor(this.barPhasor);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Current bar phasor (0..1), for visualisation. */
|
||||||
|
phase(): number {
|
||||||
|
return this.barPhasor;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Evaluate one track. `idx` keys the rising/falling edge memory; `params` are
|
||||||
|
* already decoded (call {@link decodeTrack} on the rhythm output slice).
|
||||||
|
*/
|
||||||
|
evalTrack(idx: number, params: SeqParams): GateState {
|
||||||
|
let seqPhasor = this.barPhasor * params.phasorMul;
|
||||||
|
seqPhasor = (seqPhasor + params.phaseOff) % 1;
|
||||||
|
const trig = ratioSeq(seqPhasor, params.ratioSum, params.ratios, PULSE_WIDTH);
|
||||||
|
const highAmp = ratioSeq(seqPhasor, params.ampRatioSum, params.ampRatios, PULSE_WIDTH);
|
||||||
|
const prev = this.lastTrig[idx] ?? false;
|
||||||
|
this.lastTrig[idx] = trig;
|
||||||
|
return {
|
||||||
|
gate: trig,
|
||||||
|
velocity: highAmp ? VELOCITY_HIGH : VELOCITY_LOW,
|
||||||
|
rising: trig && !prev,
|
||||||
|
falling: !trig && prev,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -21,6 +21,28 @@ import type { BackendContext, BackendStatus, OutputMapping } from './backend';
|
||||||
import type { BackendId, CvSpec, MidiCcSpec, OscSpec, VcvSpec } from '../dock/output-state';
|
import type { BackendId, CvSpec, MidiCcSpec, OscSpec, VcvSpec } from '../dock/output-state';
|
||||||
import { defaultCvSpec, defaultMidiSpec, defaultOscSpec, defaultVcvSpec } from '../dock/output-state';
|
import { defaultCvSpec, defaultMidiSpec, defaultOscSpec, defaultVcvSpec } from '../dock/output-state';
|
||||||
import { BackendManager } from './manager';
|
import { BackendManager } from './manager';
|
||||||
|
import { modeEngineId } from '../console/model';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Per-engine rhythm layout: how many native RatioSeq tracks the engine has and
|
||||||
|
* its real param count (where the net's spare outputs begin). Browser-only extra
|
||||||
|
* gate-sequence tracks borrow those spare outputs (up to the net width). These
|
||||||
|
* are fixed C++ engine facts (e.g. MEMLCelium: 2 sequences × 7 params at [0..13],
|
||||||
|
* 56 params total), NOT derivable from manifold's UI-param mock.
|
||||||
|
*/
|
||||||
|
const RHYTHM_LAYOUTS: Record<string, { nativeTracks: number; paramCount: number }> = {
|
||||||
|
memlcelium: { nativeTracks: 2, paramCount: 56 }, // also the slp_workshop engine
|
||||||
|
};
|
||||||
|
|
||||||
|
/** Build the track → output-base mapping for an engine (native + spare). */
|
||||||
|
function rhythmBasesFor(engineId: string, netOut: number): number[] {
|
||||||
|
const lay = RHYTHM_LAYOUTS[engineId];
|
||||||
|
if (!lay) return [];
|
||||||
|
const bases: number[] = [];
|
||||||
|
for (let t = 0; t < lay.nativeTracks; t++) bases.push(t * 7); // native rhythm params
|
||||||
|
for (let b = lay.paramCount; b + 7 <= netOut; b += 7) bases.push(b); // browser-only spare tracks
|
||||||
|
return bases;
|
||||||
|
}
|
||||||
|
|
||||||
export interface MidiSettings {
|
export interface MidiSettings {
|
||||||
outputId: string | null;
|
outputId: string | null;
|
||||||
|
|
@ -72,6 +94,7 @@ export function useBackendManager(
|
||||||
midiSettings: MidiSettings,
|
midiSettings: MidiSettings,
|
||||||
oscSettings: OscSettings,
|
oscSettings: OscSettings,
|
||||||
vcvSettings: VcvSettings,
|
vcvSettings: VcvSettings,
|
||||||
|
bpm: number,
|
||||||
): UseBackendManager {
|
): UseBackendManager {
|
||||||
const managerRef = useRef<BackendManager | null>(null);
|
const managerRef = useRef<BackendManager | null>(null);
|
||||||
const [status, setStatus] = useState<BackendStatus>({ state: 'idle', message: 'idle' });
|
const [status, setStatus] = useState<BackendStatus>({ state: 'idle', message: 'idle' });
|
||||||
|
|
@ -154,13 +177,19 @@ export function useBackendManager(
|
||||||
vcv.setVcvConfig(specs, { url: vcvSettings.url, sendRaw: vcvSettings.sendRaw });
|
vcv.setVcvConfig(specs, { url: vcvSettings.url, sendRaw: vcvSettings.sendRaw });
|
||||||
}, [manager, params, vcvSettings.url, vcvSettings.sendRaw]);
|
}, [manager, params, vcvSettings.url, vcvSettings.sendRaw]);
|
||||||
|
|
||||||
// Push per-output uSEQ CV config (channel + gate threshold) whenever it changes.
|
// Push per-output uSEQ CV config (channel + gate source/track/threshold) and
|
||||||
|
// the gate-sequencer tempo whenever they change.
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const cv = manager?.cv();
|
const cv = manager?.cv();
|
||||||
if (!cv) return;
|
if (!cv) return;
|
||||||
const specs: CvSpec[] = params.map((p, i) => (p.cv as CvSpec | undefined) ?? defaultCvSpec(i));
|
const specs: CvSpec[] = params.map((p, i) => (p.cv as CvSpec | undefined) ?? defaultCvSpec(i));
|
||||||
cv.setCvConfig(specs);
|
cv.setCvConfig(specs);
|
||||||
}, [manager, params]);
|
cv.setBpm(bpm);
|
||||||
|
// Native rhythm tracks read the engine's real params; browser-only extra
|
||||||
|
// tracks borrow the net's spare outputs (the firmware stays at its native count).
|
||||||
|
const netOut = engine?.architecture.outputSize ?? 126;
|
||||||
|
cv.setRhythmLayout(rhythmBasesFor(modeEngineId(modeId), netOut));
|
||||||
|
}, [manager, params, bpm, modeId, engine]);
|
||||||
|
|
||||||
const cvConnect = () => void manager?.cv()?.connect();
|
const cvConnect = () => void manager?.cv()?.connect();
|
||||||
const cvIdentify = () => manager?.cv()?.identify();
|
const cvIdentify = () => manager?.cv()?.identify();
|
||||||
|
|
|
||||||
|
|
@ -287,6 +287,7 @@ export function ConsoleApp({ focus: initialFocus = 'composite' }: ConsoleAppProp
|
||||||
{ outputId: midiOutputId, ccCount: midiCcCount },
|
{ outputId: midiOutputId, ccCount: midiCcCount },
|
||||||
{ url: oscUrl, sendRaw: oscSendRaw },
|
{ url: oscUrl, sendRaw: oscSendRaw },
|
||||||
{ url: vcvUrl, sendRaw: vcvSendRaw },
|
{ url: vcvUrl, sendRaw: vcvSendRaw },
|
||||||
|
bpm,
|
||||||
);
|
);
|
||||||
|
|
||||||
// VCV bridge: forward a verdict op to the module's embedded learner. No-op
|
// VCV bridge: forward a verdict op to the module's embedded learner. No-op
|
||||||
|
|
|
||||||
|
|
@ -45,8 +45,8 @@ export interface MFParam {
|
||||||
osc?: { path: string; rangeMin: number; rangeMax: number };
|
osc?: { path: string; rangeMin: number; rangeMax: number };
|
||||||
/** VCV backend spec ({ bipolar }). */
|
/** VCV backend spec ({ bipolar }). */
|
||||||
vcv?: { bipolar: boolean };
|
vcv?: { bipolar: boolean };
|
||||||
/** uSEQ CV/gate backend spec ({ channel, gateThreshold }). */
|
/** uSEQ CV/gate backend spec ({ channel, gateSource, seqTrack, gateThreshold }). */
|
||||||
cv?: { channel: string; gateThreshold: number };
|
cv?: { channel: string; gateSource: 'sequence' | 'threshold'; seqTrack: number; gateThreshold: number };
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface MFMode {
|
export interface MFMode {
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@
|
||||||
* inline config in OutputsBackendConfig; both write the same store.
|
* inline config in OutputsBackendConfig; both write the same store.
|
||||||
*/
|
*/
|
||||||
import type { MFParam } from '../console/model';
|
import type { MFParam } from '../console/model';
|
||||||
import type { BackendId, CvChannelId } from './output-state';
|
import type { BackendId, CvChannelId, CvSpec } from './output-state';
|
||||||
import { CV_CHANNELS, defaultCvSpec, defaultMidiSpec, defaultOscSpec } from './output-state';
|
import { CV_CHANNELS, defaultCvSpec, defaultMidiSpec, defaultOscSpec } from './output-state';
|
||||||
|
|
||||||
function num(s: string, fallback: number): number {
|
function num(s: string, fallback: number): number {
|
||||||
|
|
@ -296,7 +296,7 @@ function CvChannelEditor({
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{params.map((p, i) => {
|
{params.map((p, i) => {
|
||||||
const c = (p.cv as { channel: CvChannelId; gateThreshold: number } | undefined) ?? defaultCvSpec(i);
|
const c = (p.cv as CvSpec | undefined) ?? defaultCvSpec(i);
|
||||||
const isGate = c.channel.startsWith('gate');
|
const isGate = c.channel.startsWith('gate');
|
||||||
return (
|
return (
|
||||||
<tr key={i}>
|
<tr key={i}>
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@
|
||||||
*/
|
*/
|
||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import type { ConsoleCtx } from '../console/types';
|
import type { ConsoleCtx } from '../console/types';
|
||||||
import type { BackendId, CvChannelId } from './output-state';
|
import type { BackendId, CvChannelId, CvSpec } from './output-state';
|
||||||
import { CV_CHANNELS, defaultCvSpec, defaultMidiSpec, defaultOscSpec, defaultVcvSpec } from './output-state';
|
import { CV_CHANNELS, defaultCvSpec, defaultMidiSpec, defaultOscSpec, defaultVcvSpec } from './output-state';
|
||||||
import {
|
import {
|
||||||
applyPreset,
|
applyPreset,
|
||||||
|
|
@ -587,8 +587,22 @@ function VcvConfig({ ctx }: { ctx: ConsoleCtx }) {
|
||||||
|
|
||||||
function CvConfig({ ctx }: { ctx: ConsoleCtx }) {
|
function CvConfig({ ctx }: { ctx: ConsoleCtx }) {
|
||||||
const s = ctx.backendStatus;
|
const s = ctx.backendStatus;
|
||||||
const statusColor =
|
// Green ONLY when the module has actually talked back (handshake confirmed);
|
||||||
s.state === 'ready' ? 'var(--good)' : s.state === 'connecting' ? 'var(--warn)' : 'var(--danger)';
|
// amber while waiting, red on error, grey when nothing is connected.
|
||||||
|
const dotColor =
|
||||||
|
s.state === 'ready'
|
||||||
|
? 'var(--good)'
|
||||||
|
: s.state === 'connecting'
|
||||||
|
? 'var(--warn)'
|
||||||
|
: s.state === 'idle'
|
||||||
|
? 'var(--fg-mute)'
|
||||||
|
: 'var(--danger)';
|
||||||
|
const handshakeLabel =
|
||||||
|
s.state === 'ready'
|
||||||
|
? 'Module handshake OK'
|
||||||
|
: s.state === 'idle'
|
||||||
|
? 'Not connected'
|
||||||
|
: s.message;
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<SectionLabel>uSEQ device (USB serial)</SectionLabel>
|
<SectionLabel>uSEQ device (USB serial)</SectionLabel>
|
||||||
|
|
@ -602,26 +616,56 @@ function CvConfig({ ctx }: { ctx: ConsoleCtx }) {
|
||||||
<button type="button" style={btn('var(--danger)')} onClick={ctx.cvDisconnect}>
|
<button type="button" style={btn('var(--danger)')} onClick={ctx.cvDisconnect}>
|
||||||
Disconnect
|
Disconnect
|
||||||
</button>
|
</button>
|
||||||
<span style={{ fontSize: 9, color: statusColor }}>{s.message}</span>
|
</div>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
gap: 7,
|
||||||
|
padding: '4px 8px',
|
||||||
|
background: 'var(--bg-2)',
|
||||||
|
border: '1px solid var(--line)',
|
||||||
|
borderRadius: 'var(--r-1)',
|
||||||
|
}}
|
||||||
|
title={s.message}
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
style={{
|
||||||
|
width: 10,
|
||||||
|
height: 10,
|
||||||
|
borderRadius: '50%',
|
||||||
|
flex: '0 0 auto',
|
||||||
|
background: dotColor,
|
||||||
|
boxShadow: s.state === 'ready' ? `0 0 6px ${dotColor}` : 'none',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<span style={{ fontSize: 'var(--fs-xs)', fontFamily: 'var(--font-mono)', color: dotColor }}>
|
||||||
|
{handshakeLabel}
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<p style={{ fontSize: 9, color: 'var(--fg-dim)', margin: 0, lineHeight: 1.6 }}>
|
<p style={{ fontSize: 9, color: 'var(--fg-dim)', margin: 0, lineHeight: 1.6 }}>
|
||||||
Flash the uSEQ main + expander with <code>firmware/useq-celium</code>, connect over USB, then assign each
|
Flash the uSEQ main + expander with <code>firmware/useq-celium</code>, connect over USB, then assign each
|
||||||
model output to a CV jack or gate. 11 CV (3 main + 8 expander) + 3 gates, streamed at 100 Hz.
|
model output to a CV jack or gate. 11 CV (3 main + 8 expander) + 3 gates, streamed at 100 Hz.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<SectionLabel>Per-output channel · gate threshold</SectionLabel>
|
<SectionLabel>Per-output channel · gate source</SectionLabel>
|
||||||
|
<p style={{ fontSize: 9, color: 'var(--fg-dim)', margin: 0, lineHeight: 1.6 }}>
|
||||||
|
Gate channels run a clock-driven <b>Sequence</b> (RatioSeq track, tempo = app BPM) — tracks 0–1 are the
|
||||||
|
engine's native rhythm; tracks 2+ are browser-only extras on the net's spare outputs (up to ~12 total). Or
|
||||||
|
<b> Threshold</b> a continuous output. CV channels carry the mapped value.
|
||||||
|
</p>
|
||||||
<div style={{ maxHeight: 320, overflow: 'auto' }}>
|
<div style={{ maxHeight: 320, overflow: 'auto' }}>
|
||||||
<table style={{ width: '100%', borderCollapse: 'collapse' }}>
|
<table style={{ width: '100%', borderCollapse: 'collapse' }}>
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<Th>Output</Th>
|
<Th>Output</Th>
|
||||||
<Th>uSEQ channel</Th>
|
<Th>uSEQ channel</Th>
|
||||||
<Th>Gate ≥</Th>
|
<Th>Gate source</Th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{ctx.params.map((p, i) => {
|
{ctx.params.map((p, i) => {
|
||||||
const c = (p.cv as { channel: CvChannelId; gateThreshold: number } | undefined) ?? defaultCvSpec(i);
|
const c = (p.cv as CvSpec | undefined) ?? defaultCvSpec(i);
|
||||||
const isGate = c.channel.startsWith('gate');
|
const isGate = c.channel.startsWith('gate');
|
||||||
return (
|
return (
|
||||||
<tr key={i}>
|
<tr key={i}>
|
||||||
|
|
@ -640,14 +684,44 @@ function CvConfig({ ctx }: { ctx: ConsoleCtx }) {
|
||||||
))}
|
))}
|
||||||
</select>
|
</select>
|
||||||
</td>
|
</td>
|
||||||
<td style={{ padding: '3px 6px', width: 80 }}>
|
<td style={{ padding: '3px 6px', width: 200 }}>
|
||||||
|
{isGate ? (
|
||||||
|
<div style={{ display: 'flex', gap: 4, alignItems: 'center' }}>
|
||||||
|
<select
|
||||||
|
value={c.gateSource}
|
||||||
|
onChange={(e) =>
|
||||||
|
ctx.setParam(i, { cv: { ...c, gateSource: e.target.value as 'sequence' | 'threshold' } })
|
||||||
|
}
|
||||||
|
style={{ ...cellInput, width: 'auto', cursor: 'pointer' }}
|
||||||
|
>
|
||||||
|
<option value="sequence">Sequence</option>
|
||||||
|
<option value="threshold">Threshold</option>
|
||||||
|
</select>
|
||||||
|
{c.gateSource === 'sequence' ? (
|
||||||
|
<label style={{ display: 'flex', gap: 3, alignItems: 'center', fontSize: 9, color: 'var(--fg-dim)' }}>
|
||||||
|
trk
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
min={0}
|
||||||
|
max={15}
|
||||||
|
style={{ ...cellInput, width: 46 }}
|
||||||
|
value={c.seqTrack}
|
||||||
|
onChange={(e) =>
|
||||||
|
ctx.setParam(i, {
|
||||||
|
cv: { ...c, seqTrack: Math.max(0, Math.min(15, num(e.target.value, c.seqTrack) | 0)) },
|
||||||
|
})
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
) : (
|
||||||
|
<label style={{ display: 'flex', gap: 3, alignItems: 'center', fontSize: 9, color: 'var(--fg-dim)' }}>
|
||||||
|
≥
|
||||||
<input
|
<input
|
||||||
type="number"
|
type="number"
|
||||||
min={0}
|
min={0}
|
||||||
max={1}
|
max={1}
|
||||||
step={0.05}
|
step={0.05}
|
||||||
disabled={!isGate}
|
style={{ ...cellInput, width: 56 }}
|
||||||
style={{ ...cellInput, opacity: isGate ? 1 : 0.4 }}
|
|
||||||
value={c.gateThreshold}
|
value={c.gateThreshold}
|
||||||
onChange={(e) =>
|
onChange={(e) =>
|
||||||
ctx.setParam(i, {
|
ctx.setParam(i, {
|
||||||
|
|
@ -655,6 +729,12 @@ function CvConfig({ ctx }: { ctx: ConsoleCtx }) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
</label>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<span style={{ fontSize: 'var(--fs-xs)', color: 'var(--fg-mute)' }}>— CV —</span>
|
||||||
|
)}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -107,7 +107,16 @@ export const CV_CHANNELS: readonly CvChannelDesc[] = [
|
||||||
export interface CvSpec {
|
export interface CvSpec {
|
||||||
/** Physical uSEQ channel this output drives, or 'none' to skip it. */
|
/** Physical uSEQ channel this output drives, or 'none' to skip it. */
|
||||||
channel: CvChannelId;
|
channel: CvChannelId;
|
||||||
/** For gate channels: gate goes HIGH when the mapped 0..1 value ≥ this. */
|
/**
|
||||||
|
* For GATE channels: how the gate is produced.
|
||||||
|
* - 'sequence' → a clock-driven RatioSeq track (the rhythm stream; the
|
||||||
|
* track's 7 params come from outputs [seqTrack*7 .. +6]).
|
||||||
|
* - 'threshold' → the continuous stream: gate HIGH when mapped value ≥ gateThreshold.
|
||||||
|
*/
|
||||||
|
gateSource: 'sequence' | 'threshold';
|
||||||
|
/** RatioSeq track index driving this gate when gateSource==='sequence'. */
|
||||||
|
seqTrack: number;
|
||||||
|
/** Threshold on the mapped 0..1 value when gateSource==='threshold'. */
|
||||||
gateThreshold: number;
|
gateThreshold: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -185,5 +194,7 @@ export function defaultVcvSpec(): VcvSpec {
|
||||||
*/
|
*/
|
||||||
export function defaultCvSpec(index: number): CvSpec {
|
export function defaultCvSpec(index: number): CvSpec {
|
||||||
const ch = CV_CHANNELS[index]?.id ?? 'none';
|
const ch = CV_CHANNELS[index]?.id ?? 'none';
|
||||||
return { channel: ch, gateThreshold: 0.5 };
|
// Gate channels default to the rhythm stream (RatioSeq), one track per gate.
|
||||||
|
const gateNum = ch.startsWith('gate') ? parseInt(ch.slice(4), 10) - 1 : 0;
|
||||||
|
return { channel: ch, gateSource: 'sequence', seqTrack: gateNum, gateThreshold: 0.5 };
|
||||||
}
|
}
|
||||||
|
|
|
||||||
36
scripts/flash-useq-expander.sh
Executable file
36
scripts/flash-useq-expander.sh
Executable file
|
|
@ -0,0 +1,36 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
# Build + flash the uSEQ-CV **expander** firmware (firmware/useq-celium/expander).
|
||||||
|
# Target: uSEQ USEQHARDWARE_EXPANDER_OUT_0_1 (RP2040). Any extra args are passed
|
||||||
|
# to pio (e.g. --upload-port /dev/ttyACM1).
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
BOARD_DIR="$SCRIPT_DIR/../firmware/useq-celium/expander"
|
||||||
|
ENV="expander"
|
||||||
|
|
||||||
|
if [[ "${1:-}" == "-h" || "${1:-}" == "--help" ]]; then
|
||||||
|
echo "Usage: scripts/flash-useq-expander.sh [extra pio args]"
|
||||||
|
echo " Builds firmware/useq-celium/expander and uploads it to the uSEQ EXPANDER board."
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Resolve PlatformIO (nix-friendly: fall back to an ephemeral nix-shell).
|
||||||
|
run_pio() {
|
||||||
|
if command -v pio >/dev/null 2>&1; then
|
||||||
|
pio "$@"
|
||||||
|
elif command -v platformio >/dev/null 2>&1; then
|
||||||
|
platformio "$@"
|
||||||
|
elif command -v nix-shell >/dev/null 2>&1; then
|
||||||
|
nix-shell -p platformio --run "pio $*"
|
||||||
|
else
|
||||||
|
echo "error: PlatformIO not found. Install it, e.g.:" >&2
|
||||||
|
echo " nix-shell -p platformio # or: pipx install platformio" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "==> Build + flash uSEQ EXPANDER (env: $ENV)"
|
||||||
|
echo " If the upload can't auto-reset the board, hold BOOTSEL while plugging in USB."
|
||||||
|
cd "$BOARD_DIR"
|
||||||
|
run_pio run -e "$ENV" -t upload "$@"
|
||||||
|
echo "==> Done. The expander LEDs sweep when the main board forwards an Identify."
|
||||||
36
scripts/flash-useq-main.sh
Executable file
36
scripts/flash-useq-main.sh
Executable file
|
|
@ -0,0 +1,36 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
# Build + flash the uSEQ-CV **main** module firmware (firmware/useq-celium/main).
|
||||||
|
# Target: uSEQ USEQHARDWARE_1_0 (RP2040). Any extra args are passed to pio
|
||||||
|
# (e.g. --upload-port /dev/ttyACM0).
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
BOARD_DIR="$SCRIPT_DIR/../firmware/useq-celium/main"
|
||||||
|
ENV="main"
|
||||||
|
|
||||||
|
if [[ "${1:-}" == "-h" || "${1:-}" == "--help" ]]; then
|
||||||
|
echo "Usage: scripts/flash-useq-main.sh [extra pio args]"
|
||||||
|
echo " Builds firmware/useq-celium/main and uploads it to the uSEQ MAIN board."
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Resolve PlatformIO (nix-friendly: fall back to an ephemeral nix-shell).
|
||||||
|
run_pio() {
|
||||||
|
if command -v pio >/dev/null 2>&1; then
|
||||||
|
pio "$@"
|
||||||
|
elif command -v platformio >/dev/null 2>&1; then
|
||||||
|
platformio "$@"
|
||||||
|
elif command -v nix-shell >/dev/null 2>&1; then
|
||||||
|
nix-shell -p platformio --run "pio $*"
|
||||||
|
else
|
||||||
|
echo "error: PlatformIO not found. Install it, e.g.:" >&2
|
||||||
|
echo " nix-shell -p platformio # or: pipx install platformio" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "==> Build + flash uSEQ MAIN module (env: $ENV)"
|
||||||
|
echo " If the upload can't auto-reset the board, hold BOOTSEL while plugging in USB."
|
||||||
|
cd "$BOARD_DIR"
|
||||||
|
run_pio run -e "$ENV" -t upload "$@"
|
||||||
|
echo "==> Done. The main board's LEDs sweep on Identify from the Manifold CV panel."
|
||||||
Loading…
Reference in a new issue