# Live Controls, 60fps Preset Banks & Modulators

> Build 60fps click-free multi-mode consoles with presets() + P.slider(), standalone helpers (select(), pills(), toggle(), stepper(), slider()), portable // @ comment directives, Public vs. Private /listen gating, Auto-Sweep @slider LFOs, and 1-click Copy for strudel.cc vanilla export.

Author rich multi-slider live performance rigs inside LILA with zero audio glitching on mode switches, hide internal calibration sliders from /listen listeners with a single option, and export pure strudel.cc JavaScript anytime in one click.

## 1. Declarative 60fps Preset Banks (`presets()` + `P.slider()`)

Bind dozens of calibrated `slider()` parameters to a single public mode selector (`@select` dropdown or `@pills` bar) without centered-offset math or extra override toggles. When all reads of your preset bank go through `P.slider(...)`, switching modes updates every fader simultaneously at 60fps with zero script re-evaluation or audio phase reset.

- **Syntax**: `const P = presets(initialKey, bankObject, { ui: "select" | "pills", label: "Mode", sliders: "private" | "public" });`.
- **Mode display labels**: Include `label: "Human Name"` inside each mode entry (e.g. `VIBE_CODING: { label: "Vibe Coding", macro: 1.05, ... }`).
- **Positional or options-object `P.slider(...)`**: Write `P.slider("macro", 0, 2, 0.01, "Master Macro")` or `P.slider("t.bass", { min: 0, max: 2, step: 0.02, label: "Trim: Bass" })`. Nested dot-paths (`"t.bass"`) read nested sub-objects cleanly.
- **Per-slider visibility override**: Set `{ sliders: "private" }` on `presets(...)` to hide all bound sliders on `/listen`, then append `.public()` (or `.listen()`) on any single fader you still want to expose publicly.
- **60fps click-free rule**: As long as every live read uses `P.slider(...)` (plus optional `.private()` / `.public()` / `.label()`), changing modes never glitches or restarts long-running LFO/entrainment phases. Reading `P.value("path")`, `P.get("path")`, or `P.key` still works cleanly when a switch genuinely changes non-slider code (`shouldReevaluate` falls back to hot re-eval automatically).

| API / Option | Example | Behavior |
| --- | --- | --- |
| `presets(key, bank, opts)` | `const P = presets("flow", { flow: {...}, sleep: {...} }, { ui: "select", label: "Mode", sliders: "private" })` | Renders 1 mode control (`select` or `pills`) and recalls bound sliders on switch |
| `P.slider(path, min, max, step, label?)` | `const cut = P.slider("t.cut", 200, 3200, 10, "Cutoff")` | Registers a real-time 60fps `slider` initialized from active preset dot-path |
| `.private()` / `.public()` | `P.slider("macro", 0, 2, 0.01, "Depth").public()` | Overrides bank `sliders: "private"` for a single exposed fader |
| `P.value(path)` / `P.key` | `const bankName = P.value("kit")` | Reads non-numeric preset metadata (triggers clean Strudel re-eval on switch) |

### Example: Multi-Parameter Night Console (`presets()` + Nested `P.slider()`)

One public Listening Mode dropdown drives filter, atmosphere, and nested per-layer trims (`t.bass`, `t.pad`) at 60fps while keeping calibration faders private on /listen.

```js
setCpm(32);

const P = presets("focus", {
  focus: { label: "Deep Focus", cutoff: 1550, t: { bass: 0.72, pad: 0.42 } },
  sketch: { label: "Sketch Flow", cutoff: 2400, t: { bass: 0.80, pad: 0.50 } },
  nap: { label: "Power Nap", cutoff: 580, t: { bass: 0.55, pad: 0.34 } },
}, {
  ui: "select",
  label: "Listening Mode",
  sliders: "private",
});

const cutoff = P.slider("cutoff", 260, 3600, 10, "Master Filter");
const trimBass = P.slider("t.bass", 0, 1.2, 0.02, "Trim: Bass");
const trimPad = P.slider("t.pad", 0, 1.2, 0.02, "Trim: Pad").public();

$: note("<c2 g1 ab1 g1>").s("lila_sub").lpf(cutoff).gain(trimBass);
$: chord("<Cm9 Gm7 Abmaj7 G7>").voicing().s("lila_pad").lpf(cutoff).room(0.55).gain(trimPad);
```

## 2. Explicit Helper Functions (`select()`, `pills()`, `toggle()`, `stepper()`, `slider()`)

Standalone self-documenting JS helpers that evaluate transparently to their active value while rendering interactive controls in both the Live Controls rack and inline CodeMirror widgets.

- `select(defaultVal, optionsArray, label?)` — accepts values or `[value, "Display Label"]` pairs.
- `pills(defaultVal, optionsArray, label?)` — renders 1-click mode buttons in Sandbox and `/listen`.
- `toggle(defaultVal, label?)` — accepts `true`/`false` or `1`/`0`.
- `stepper(defaultVal, min, max, step, label?)` — renders bounded `-` / `+` buttons.
- Chain `.label("Name")`, `.private()`, or `.public()` on `slider(...)` or control helpers — or add trailing `// @private` / `| private` comments.

### Example: Helper Function Syntax (`pills`, `select`, `toggle`, `stepper`)

Function-call helpers with optional [value, label] pairs and `.private()` chaining.

```js
setCpm(30);

const kit = pills("tr808", [["tr808", "TR-808"], ["tr909", "TR-909"]], "Drum Machine");
const mode = select("C2:minor", [["C2:minor", "Night Minor"], ["D2:dorian", "Liquid Dorian"]], "Key");
const arpOn = toggle(true, "Arp Layer");
const arpSteps = stepper(4, 2, 8, 1, "Arp Speed").private();

$: s("bd ~ [~ bd] ~, ~ sd ~ ~, hh*8").bank(kit).gain(0.8);
$: arpOn ? n(run(arpSteps)).scale(mode).s("lila_pluck").lpf(1800).gain(0.45) : silence;
```

## 3. Portable Comment Directives (`@select`, `@pills`, `@toggle`, `@stepper`)

Prefer zero-runtime metadata? Annotate any top-level `const` primitive (`number`, `"string"`, or `boolean`) with a trailing `// @...` comment directive. The script stays 100% vanilla `strudel.cc`-valid JavaScript with no helper definitions needed.

- **`@pills` (Segmented Mode Buttons)**: Ideal for 2–5 modes, sections, or intensities (`1`, `2`, `3` or `"flow"`, `"deep"`).
- **`@select` (Dropdown Menu)**: Best when a control has 5+ options, scales, or long preset labels.
- **`@toggle` (Boolean Switch)**: Switches layers or A/B paths (`true`/`false` or `1`/`0`). Follow with your control label (e.g. `// @toggle Rhythm` or `// @toggle Rhythm | private`).
- **`@stepper` (`−` / `+` Step Control)**: Bounded integer or decimal increments (`min..max step S`), ideal for octaves or Euclidean pulse counts.
- **Comma-separated display labels**: Write `value=Display Name` on any `@select` or `@pills` option so listeners see `"Deep Sleep"` while code keeps `0` or `"sleep"`.

| Directive | Syntax Pattern | Default Visibility | Use Case |
| --- | --- | --- | --- |
| `@pills` | `const MODE = "day"; // @pills day=Day Flow, nap=Power Nap, night=Deep Sleep` | Public (`/listen` + Sandbox) | 2–5 instant mode/section buttons |
| `@select` | `const MODE = 0; // @select 0=Vibe Coding, 1=Deep Debug, 2=Music Sketch, 3=Power Nap, 4=Deep Sleep \| label: Focus Mode` | Public (`/listen` + Sandbox) | Compact dropdown for 5+ modes or scales |
| `@toggle` | `const DRUMS_ON = true; // @toggle Rhythm` | Public (`/listen` + Sandbox) | Ternary layer mute or switch |
| `@stepper` | `const PULSES = 5; // @stepper 1..16 step 1 \| label: Euclidean Hits` | Public (`/listen` + Sandbox) | Discrete numeric steps without dragging |

### Example: Four Comment-Annotated Controls Together

Dropdown, segmented pills, boolean toggle, and stepped Euclidean pulses driving one synth groove.

```js
setCpm(31);

const SCALE = "C3:minor"; // @select C3:minor=C Minor, D3:dorian=D Dorian, F3:phrygian=F Phrygian | label: Scale
const VOICING = "warm"; // @pills warm=Warm Rhodes, bright=Acid Pluck | label: Lead Tone
const HATS_ON = true; // @toggle Hi-Hats
const PULSES = 5; // @stepper 1..12 step 1 | label: Kick Density

$: s("bd").euclid(PULSES, 16).gain(0.85);
$: HATS_ON ? s("hh*8").gain(0.28) : silence;
$: n("0 2 4 [6 7]")
  .scale(SCALE)
  .s(VOICING === "bright" ? "lila_acid" : "lila_rhodes")
  .lpf(VOICING === "bright" ? 2200 : 1400)
  .room(0.4)
  .gain(0.5);
```

## 4. Public `/listen` Exposure vs. Private Sandbox Controls (`sliders: "private"`, `.private()`, `@private`)

By default, every control and `slider()` is `public` so listeners opening your creation on `/listen` or `/embed` can play with it. When your script has 20+ engineering or psychoacoustic calibration faders, hide internal controls so `/listen` listeners see ONLY your curated top-level mode switcher.

- In a preset bank, pass `sliders: "private"` in `presets(..., { sliders: "private" })` to hide all `P.slider(...)` faders automatically on `/listen`.
- Chain `.private()` on individual helpers or sliders (`slider(0.5, 0, 1, 0.01).label("Bias").private()`), or append `| private` / `// @private` in comments.
- Listeners on `/listen` and `/embed` only see `public` controls; Sandbox creators still see a lock-badged `Private` shelf inside the sliders rack.
- **Important AST rule for comment tags**: Hoist annotated sliders into top-level `const name = slider(...)` declarations if using trailing `// @label ... | private` comments.

> **Flip visibility in 1 click inside the IDE**: Put your cursor on any control or slider line and press `Alt+Enter` -> "Hide from /listen (`@private`)" or click the eye/lock icon directly on the control pill in the Live Controls rack.

### Example: Public Mode Dropdown + Private Calibration Sliders

Only the Entrainment Mode selector is public; the bank’s internal cutoff and gain sliders stay hidden on /listen via `sliders: "private"`.

```js
setCpm(40);

// PUBLIC listener control — visible on /listen; private calibration faders stay inside Sandbox
const P = presets("vibe", {
  vibe:   { label: "Vibe Coding", cutoff: 1500, gain: 0.48 },
  debug:  { label: "Heavy Debug", cutoff: 1950, gain: 0.45 },
  sketch: { label: "Sketching", cutoff: 1200, gain: 0.52 },
  nap:    { label: "Power Nap", cutoff: 620, gain: 0.40 },
  sleep:  { label: "Deep Sleep", cutoff: 340, gain: 0.34 },
}, {
  ui: "select",
  label: "Entrainment Mode",
  sliders: "private",
});

const effCutoff = P.slider("cutoff", 220, 3600, 10, "Master Cutoff");
const effGain   = P.slider("gain", 0.1, 0.9, 0.01, "Pad Gain");

$: chord("<Cm9 Fm9>").voicing().s("lila_pad").lpf(effCutoff).room(0.6).gain(effGain);
$: note("c2 ~ g1 ~").s("lila_sub").gain(0.65);
```

## 5. Continuous Sliders (`slider()`) & Auto-Sweep `@slider` LFOs

Every `slider(val, min, max, step)` runs at 60fps in LILA without re-evaluating or clicking the audio graph. Toggle Auto-Sweep wave mode (`∿`) on any slider pill — or write a standard `.range(min, max).slow(cycles)` signal paired with a `// @slider` parked-value comment — to modulate smoothly with full `strudel.cc` compatibility.

- **LFO Shapes**: `sine`, `cosine`, `tri`, `itri`, `saw`, `isaw`, `square`, `perlin`, `rand`.
- **Cycle Rates**: `.slow(4)` for a 4-bar sweep, omit for 1 cycle, or `.fast(2)` / `.segment(16)` for stepped rhythmic modulation.
- **Canonical Syntax**: `const cutoff = sine.range(320, 2800).slow(4); // @slider 1100 step 10 | label: Master Filter` (optional trailing `| private`). When turned back into a manual fader, LILA restores the parked manual fallback `1100`.
- **Sandbox Toolbar Mix Helpers**: Pin (`P`) a fader so randomizers skip it, click `Mutate` for constrained variation around your active values, or store/recall snapshots in slots `M1–M3`.

### Example: Calibrated Filter Slider with Auto-Sweep `@slider` LFO

The low-pass filter sweeps smoothly across 4 cycles between 320 Hz and 2800 Hz while retaining the parked manual value `1100`.

```js
setCpm(31);

const cutoff = sine.range(320, 2800).slow(4); // @slider 1100 step 10 | label: Master Filter
const reso = slider(6, 1, 14, 0.5); // @label Filter Resonance

$: note("c2 eb2 g2 bb2 c3 bb2 g2 eb2")
  .s("lila_acid")
  .lpf(cutoff)
  .lpq(reso)
  .gain(0.7);
```

## 6. 1-Click "Copy for strudel.cc" Vanilla Export

Want to share or archive a script built with LILA’s `presets()`, `P.slider()`, `select()`, `pills()`, `toggle()`, `stepper()`, `.label()`, or `.private()` extensions inside external vanilla `strudel.cc`? Click **Copy for strudel.cc** in the Sandbox **More** menu (or `Cmd+K` / `Ctrl+K` Command Palette).

- **Zero LILA-only helpers**: Compiles every `presets(...)` declaration, `P.slider(...)` call, `select()` / `pills()` / `toggle()` / `stepper()` call, and `.label()` / `.private()` / `.public()` modifier chain out cleanly.
- **Live State Baked In**: Active mode presets and any manually adjusted Sandbox slider values are baked directly into standard `slider(val, min, max, step)` calls so the exported script sounds identical in vanilla Strudel.
- **Portable Comment Layer Preserved**: Standard `slider()` calls and Strudel patterns remain untouched and human-readable (no obfuscation or runtime wrappers).
