/** * OutputsBackendConfig — the editable, per-backend specialisation of the Outputs * panel (backends-spec §4) plus the named-preset bar (§5). * * Layout: ONE preset bar (save-as / restore / rename / delete, per-backend * namespace) on top, then a per-backend config section: * - MIDI → output-port picker, number-of-CCs, per-output CC#/channel/name. * - OSC → bridge URL + connect status + send-raw toggle, per-output path/range. * - VCV/CV→ bridge URL + connect status + send-raw toggle, per-output polarity * (uni 0–10 V / bipolar ±5 V). The browser drives + trains the VCV * module over the same Deno bridge. * - Synth/Particle/Editor → handled by ModeConfig in Drawers (no extra config here). * * Everything is editable inline; writes go through the shared MFParam store * (ctx.setParam) — never a second data path. The full-depth modal reuses the * same sections via BackendAdvanced. */ import { useEffect, useState } from 'react'; import type { ConsoleCtx } from '../console/types'; import type { BackendId, CvChannelId, CvSpec } from './output-state'; import { CV_CHANNELS, defaultCvSpec, defaultMidiSpec, defaultOscSpec, defaultVcvSpec } from './output-state'; import { applyPreset, deletePreset, getPreset, listPresets, renamePreset, savePreset, type OutputPreset, } from '../backends/presets'; import { MIDI_DEVICES, MIDI_DEVICES_BY_ID, type MidiDeviceParam } from '../midi-devices'; function num(s: string, fallback: number): number { const v = parseFloat(s); return Number.isFinite(v) ? v : fallback; } const cellInput: React.CSSProperties = { width: '100%', background: 'var(--bg-1)', border: '1px solid var(--line)', borderRadius: 'var(--r-1)', color: 'var(--fg)', fontFamily: 'var(--font-mono)', fontSize: 'var(--fs-xs)', padding: '3px 6px', boxSizing: 'border-box', }; const btn = (color: string): React.CSSProperties => ({ fontSize: 'var(--fs-xs)', fontFamily: 'var(--font-mono)', padding: '3px 9px', cursor: 'pointer', borderRadius: 'var(--r-pill)', border: `1px solid ${color}`, background: 'transparent', color, }); function SectionLabel({ children }: { children: React.ReactNode }) { return (
{children}
); } function Th({ children }: { children: React.ReactNode }) { return ( {children} ); } // ---- Named-preset bar (backends-spec §5) ----------------------------------- function PresetBar({ ctx, backend }: { ctx: ConsoleCtx; backend: BackendId }) { const [presets, setPresets] = useState([]); const [name, setName] = useState(''); const [selected, setSelected] = useState(''); const refresh = () => setPresets(listPresets(backend)); useEffect(() => { refresh(); setSelected(''); setName(''); // eslint-disable-next-line react-hooks/exhaustive-deps }, [backend]); const backendSettings = (): Record => { if (backend === 'midi') return { outputId: ctx.midiOutputId, ccCount: ctx.midiCcCount }; if (backend === 'osc') return { url: ctx.oscUrl, sendRaw: ctx.oscSendRaw }; if (backend === 'vcv') return { url: ctx.vcvUrl, sendRaw: ctx.vcvSendRaw }; return {}; }; const applySettings = (s?: Record) => { if (!s) return; if (backend === 'midi') { if ('outputId' in s) ctx.setMidiOutputId((s.outputId as string | null) ?? null); if ('ccCount' in s) ctx.setMidiCcCount(Number(s.ccCount) || ctx.midiCcCount); } else if (backend === 'osc') { if ('url' in s) ctx.setOscUrl(String(s.url)); if ('sendRaw' in s) ctx.setOscSendRaw(Boolean(s.sendRaw)); } else if (backend === 'vcv') { if ('url' in s) ctx.setVcvUrl(String(s.url)); if ('sendRaw' in s) ctx.setVcvSendRaw(Boolean(s.sendRaw)); } }; const doSave = () => { const n = name.trim(); if (!n) return; savePreset(backend, n, ctx.params, backendSettings()); refresh(); setSelected(n); }; const doRestore = (n: string) => { const p = getPreset(backend, n); if (!p) return; ctx.setParams(applyPreset(ctx.params, p)); applySettings(p.settings); }; const doDelete = () => { if (!selected) return; deletePreset(backend, selected); refresh(); setSelected(''); }; const doRename = () => { const to = name.trim(); if (!selected || !to) return; if (renamePreset(backend, selected, to)) { refresh(); setSelected(to); } }; return (
Presets · {backend} setName(e.target.value)} />
); } // ---- Device template picker (synth-midi-cc templates) ---------------------- /** * Pick an external synth (e.g. Moog Sub 37), see its parameters BY NAME, tick the * ones to control, and "Apply" — this fills the per-output CC table (CC#, channel, * name) from the device template and sets the CC count. Pure local state + the * existing setParam/setMidiCcCount; the applied result lives in the shared params * store, so it is saved/restored by the named-preset bar like any other config. */ function DeviceTemplatePicker({ ctx }: { ctx: ConsoleCtx }) { const [deviceId, setDeviceId] = useState(''); const [selected, setSelected] = useState>(new Set()); const device = deviceId ? MIDI_DEVICES_BY_ID[deviceId] : undefined; const limit = ctx.params.length; // engine output count caps how many CCs we can drive const pickDevice = (id: string) => { setDeviceId(id); setSelected(new Set()); }; const toggle = (id: string) => setSelected((prev) => { const next = new Set(prev); if (next.has(id)) next.delete(id); else next.add(id); return next; }); const selectFirst = (n: number) => { if (!device) return; setSelected(new Set(device.params.slice(0, n).map((p) => p.id))); }; const apply = () => { if (!device) return; const chosen = device.params.filter((p) => selected.has(p.id)).slice(0, limit); if (chosen.length === 0) return; ctx.setMidiCcCount(chosen.length); chosen.forEach((p, i) => ctx.setParam(i, { name: p.label, midi: { cc: p.cc, channel: device.default_channel, name: p.label, value: 0 }, }), ); }; // Stable, first-seen-order grouping for the checklist. const groups: { group: string; params: MidiDeviceParam[] }[] = []; if (device) { const byGroup = new Map(); for (const p of device.params) { if (!byGroup.has(p.group)) { const arr: MidiDeviceParam[] = []; byGroup.set(p.group, arr); groups.push({ group: p.group, params: arr }); } byGroup.get(p.group)!.push(p); } } const willApply = device ? Math.min(selected.size, limit) : 0; const overflow = selected.size > limit; return ( <> Device template
{device && ( <> )}
{device && ( <>

{device.manufacturer} · default ch {device.default_channel} · {selected.size} selected {overflow ? ` (only the first ${limit} will map — engine has ${limit} outputs)` : ''}. Tick the parameters the model should drive, then Apply. You can still tweak CC#/channel below.

{groups.map(({ group, params }) => (
{group}
{params.map((p) => ( ))}
))}
)} ); } // ---- MIDI config (backends-spec §2.3 / §4.1) ------------------------------- function MidiConfig({ ctx }: { ctx: ConsoleCtx }) { const s = ctx.backendStatus; const statusColor = s.state === 'ready' ? 'var(--good)' : s.state === 'error' || s.state === 'unavailable' ? 'var(--danger)' : 'var(--warn)'; return ( <> MIDI output
{s.message}
Per-output CC · name · channel
{ctx.params.slice(0, ctx.midiCcCount).map((p, i) => { const m = p.midi ?? defaultMidiSpec(i); return ( ); })}
Name CC# Ch State
ctx.setParam(i, { midi: { ...m, name: e.target.value } })} /> ctx.setParam(i, { midi: { ...m, cc: Math.max(0, Math.min(127, num(e.target.value, m.cc))) } }) } /> ctx.setParam(i, { midi: { ...m, channel: Math.max(1, Math.min(16, num(e.target.value, m.channel))) }, }) } /> {p.status} {p.muted ? ' · muted' : ''}
); } // ---- OSC config (backends-spec §2.4 / §4.2) -------------------------------- function OscConfig({ ctx }: { ctx: ConsoleCtx }) { const s = ctx.backendStatus; const statusColor = s.state === 'ready' ? 'var(--good)' : s.state === 'connecting' ? 'var(--warn)' : 'var(--danger)'; const [draftUrl, setDraftUrl] = useState(ctx.oscUrl); useEffect(() => setDraftUrl(ctx.oscUrl), [ctx.oscUrl]); return ( <> OSC bridge
setDraftUrl(e.target.value)} onBlur={() => ctx.setOscUrl(draftUrl)} placeholder="ws://localhost:8765" /> {s.message}

The Deno OSC bridge process must be running locally (see manifold/osc-bridge). The browser sends over WebSocket; the bridge encodes OSC and forwards over UDP.

Per-output address · physical range
{ctx.params.map((p, i) => { const o = p.osc ?? defaultOscSpec(p.name); return ( ); })}
OSC path range min range max
ctx.setParam(i, { osc: { ...o, path: e.target.value } })} /> ctx.setParam(i, { osc: { ...o, rangeMin: num(e.target.value, o.rangeMin) } })} /> ctx.setParam(i, { osc: { ...o, rangeMax: num(e.target.value, o.rangeMax) } })} />
); } // ---- VCV / CV config (backends-spec §2.6 / §4.3) --------------------------- function VcvConfig({ ctx }: { ctx: ConsoleCtx }) { const s = ctx.backendStatus; const statusColor = s.state === 'ready' ? 'var(--good)' : s.state === 'connecting' ? 'var(--warn)' : 'var(--danger)'; const [draftUrl, setDraftUrl] = useState(ctx.vcvUrl); useEffect(() => setDraftUrl(ctx.vcvUrl), [ctx.vcvUrl]); return ( <> VCV bridge
setDraftUrl(e.target.value)} onBlur={() => ctx.setVcvUrl(draftUrl)} placeholder="ws://localhost:8765" /> {s.message}

The VCV Rack NISPS module AND the Deno OSC bridge (manifold/osc-bridge) must both be running. The browser drives the module's inputs and forwards the verdict loop (thumbs up/down, explore-and-place) over the bridge, so the module's embedded net trains in lock-step. Default module UDP port 7001.

Per-output polarity
{ctx.params.map((p, i) => { const v = p.vcv ?? defaultVcvSpec(); return ( ); })}
output range
{p.name}
); } // ---- uSEQ CV / gate config (backends-spec §2.5; docs/useq-celium) ----------- function CvConfig({ ctx }: { ctx: ConsoleCtx }) { const s = ctx.backendStatus; // Green ONLY when the module has actually talked back (handshake confirmed); // 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 ( <> uSEQ device (USB serial)
{handshakeLabel}

Flash the uSEQ main + expander with firmware/useq-celium, 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.

Per-output channel · gate source

Gate channels run a clock-driven Sequence (RatioSeq, tempo = app BPM) whose 7 params come from rhythm outputs [track×7…]; or Threshold a continuous output. CV channels carry the mapped value.

{ctx.params.map((p, i) => { const c = (p.cv as CvSpec | undefined) ?? defaultCvSpec(i); const isGate = c.channel.startsWith('gate'); return ( ); })}
Output uSEQ channel Gate source
{p.name} {isGate ? (
{c.gateSource === 'sequence' ? ( ) : ( )}
) : ( — CV — )}
); } // ---- Public entry ---------------------------------------------------------- export interface OutputsBackendConfigProps { ctx: ConsoleCtx; backend: BackendId; } /** The specialised, editable per-backend config + preset bar for the Outputs panel. */ export function OutputsBackendConfig({ ctx, backend }: OutputsBackendConfigProps) { // MIDI / OSC / VCV / CV carry a config + preset surface here; synth/particle/editor // config is rendered by ModeConfig in Drawers. The full-depth BackendAdvanced // modal reuses the same per-channel sections. if (backend !== 'midi' && backend !== 'osc' && backend !== 'vcv' && backend !== 'cvgate') return null; return (
{backend === 'midi' ? ( ) : backend === 'osc' ? ( ) : backend === 'vcv' ? ( ) : ( )}
); } export { PresetBar as OutputPresetBar }; /** Tiny status pill for the Outputs drawer header. */ export function BackendStatusChip({ ctx }: { ctx: ConsoleCtx }) { const s = ctx.backendStatus; if (s.state === 'idle') return null; const color = s.state === 'ready' ? 'var(--good)' : s.state === 'error' || s.state === 'unavailable' ? 'var(--danger)' : 'var(--warn)'; return ( {s.message} ); }