8000 feat(fx): uniform Punch-In modulation — envelope ⊗ LFO|sidechain, 2 macros/effect, Ableton-style sidechain scope by johannboehme · Pull Request #61 · johannboehme/tk-1 · GitHub
[go: up one dir, main page]

Skip to content

feat(fx): uniform Punch-In modulation — envelope ⊗ LFO|sidechain, 2 macros/effect, Ableton-style sidechain scope - #61

Merged
johannboehme merged 15 commits into
mainfrom
worktree-pfx-modulation-engine
Jun 20, 2026
Merged

johannboehme merged 15 commits into
mainfrom
worktree-pfx-modulation-engine

Conversation

@johannboehme
Copy link
Copy Markdown
Owner

What

Reworks the Punch-In effect (P-FX) system into one uniform modulation interface and fixes the stuck-pad bug.

Every effect now has the exact same control surface:

  • 2 opinionated macros (OP-1 synth-engine-knob style) instead of raw/bipolar params.
  • an always-on ADSR envelope.
  • exactly one time-modulator — LFO or Sidechain (never both) — chosen per effect.
  • Intensity(t) = Envelope(t) ⊗ Modulator(t), driving every effect's strength via the existing applyWetness bus, so even VIGNETTE/RGB/UV get time-movement.

Highlights

  • Lock-bug fixed — a persistent (recording) hold whose pad pointer-up was lost (blur / tab-switch / auto-stop at song end) used to dangle forever (outS growing, un-deletable). setPlaying(false) now finalizes holds + the pad has a window pointerup/blur/unmount guard.
  • Uniform engine (fx/modulation.ts, pure + tested): envelope ⊗ lfo|sidechain, depth blend, { level, phase }.
  • Correct, BPM-aware intervals: beat divisions come from the real song BPM (not a hardcoded 120); label and rendered period share one table (the old UI↔backend inversion is structurally impossible); beat-synced LFO is grid-anchored so pulses land on the beat.
  • Catalog refactor: 2 linear macros per effect; bipolar movement params + the per-effect LFO helpers removed (VIGN DEPTH/EDGE · RGB SPLIT/ANGLE · UV GLOW/TINT · WEAR AGE/ROLL · ZOOM PUNCH/PUSH · ECHO SPREAD/FEED · TAPE STOP/WARP). 3-backend parity preserved (Canvas2D / WebGL2 / WebGPU).
  • Ableton-style sidechain scope (SidechainScope.tsx): a 1:1 lens over the timeline's master-audio lane — same visible window (reconstructed from ui.zoom/ui.scrollX/arrTotal), arr→master per column, peak-bucketed; draggable threshold + live effect-strength band + beat grid-lines.
  • Sidechain alignment fix: the amplitude envelope stored the requested fps (120) instead of the true sampleRate/hop (119.84 after whole-sample rounding) — a 0.14% time-scale drift = ~0.4 s off 5 min in. Now stores the true rate; alignment pinned by tests.
  • Export parity + persistence: the same computeIntensity runs in the export compositor; bpm/beatPhase + the sidechain audio-envelope thread through jobs → worker → compositor; modulation persists on PunchFxRecord.

Merge with main

main landed #60 (global color grade + opinionated filters) in parallel, touching the same FX/render files. Merged here; both features coexist — buildFx/compositor order is grade → filters → punch-in accents (with modulation).

UI

M-screen (P/E/M) with an LFO|SIDE toggle, reusing the canonical Encoder knob look (shared EncoderKnob) — no bespoke knobs.

Tests

  • 1202 unit tests + 69 browser render tests green; tsc clean.
  • New: modulation engine, envelope time-axis accuracy (22.05/44.1/48 kHz, deep-track), scope↔timeline window + arr→master equivalence, end-to-end transient alignment in a reordered long-form arrangement, and stuck-hold lifecycle.

🤖 Generated with Claude Code

johannboehme and others added 15 commits June 20, 2026 15:58
…rever

A persistent (recording) FX hold whose pad pointer-up never arrived — window
blur, tab switch, or the auto-stop at song end — stayed in `fxHolds` forever:
its `outS` kept growing on the next play and clearAllFx couldn't remove it
(clear-all preserves live recordings by design, which is correct). The pad
deliberately skips setPointerCapture for multi-touch, so a lost pointer-up
is realistic.

- store.setPlaying(false) now finalizes every persistent hold via the normal
  release path → it becomes an ordinary committed capsule (erasable/clearable).
- FxPad adds an off-pad release guard (window pointerup/pointercancel/blur)
  and an unmount cleanup, both ending only persistent holds — preview holds
  latch by design.
- clearAllFx left unchanged (the inverted-filter diagnosis was wrong; its
  filter matches the X-hold-to-clear contract).

Tests cover finalize-on-stop, post-finalize deletability, and that clear-all
still preserves a genuinely live recording.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…tested

New `fx/modulation.ts` — the single source of truth for P-FX intensity:
- intensity = envelope (always on) ⊗ one time-modulator (LFO XOR sidechain),
  blended by `depth`; returns { level, phase }.
- Beat divisions derive from the REAL bpm (60/bpm·beats), not a hardcoded
  120. `bipolarRateLabel` and `bipolarRatePeriodS` share one table, so the
  displayed division can never disagree with what renders (kills the old
  UI↔backend inversion). TE direction: near-centre = slowest, far = fastest.
- beat-synced LFO is grid-anchored in master-time → pulses land on the song
  beats with a crisp onset, independent of where the punch started.
- LFO shapes (sine/triangle/saw/ramp/square) peak on the beat at phase 0.
- sidechain follower: threshold → normalize → asymmetric one-pole
  (attack/release) → invert, as a reusable curve so renderer and the
  preview band agree exactly.

Pure module, no store/DOM/time-source deps. 15 unit tests. Not yet wired
into the render path (next commits).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…y-safe)

Wire `computeIntensity` into the live descriptor so P-FX intensity is the
unified envelope ⊗ (lfo|sidechain). Legacy fx (only an `envelope`) are
wrapped as a depth-0 modulation → identical render (all 38 existing
build-descriptor tests pass unchanged).

- PunchFx gains optional `modulation`; FrameFx gains optional `phase`
  (centralized cycle phase for effects with internal geometry).
- buildFx now takes tMaster and reads bpm/beatPhaseS/beatsPerBar/audioEnv
  from the snapshot; sidechain follower curves are memoized per
  (audio-env, config).
- defaultReadSnapshot threads real bpm + grid phase (selectors/timing) and
  the new store `audioEnv` field (+ setAudioEnv; null until Part D fills it
  from decoded PCM).

New tests prove the live path: beat-synced LFO modulates on/off the beat at
the real BPM, sidechain follows the master envelope (loud→stronger, culled
below threshold), and legacy fx stay bit-identical.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…chain data, export

Wires the engine into every effect and both render paths.

Catalog: each effect now exposes exactly 2 opinionated linear macros (no
bipolar). Removed bipolarPeriodS/lfoPhase/oneShotPhase/BEAT_STOPS_S — no
effect runs its own LFO; intensity arrives centrally via applyWetness. Per
effect: VIGN DEPTH/EDGE · RGB SPLIT/ANGLE · UV GLOW/TINT · WEAR AGE/ROLL
(tracking-bar drift now from master-time) · ZOOM PUNCH/PUSH · ECHO
SPREAD/FEED · TAPE STOP/WARP. 3-backend parity kept (shader uniforms fed
from t / macros / wetness, no .wgsl/.frag source changes).

Store: per-kind `fxModulations` (ModConfig = timeMod+depth+lfo+side) with
setFxTimeMod/setFxModDepth/setFxLfo/setFxSidechain; beginFxHold freezes the
full Modulation (envelope ⊗ modulator) into each new capsule. Persisted via
PunchFxRecord.modulation so it round-trips. New `audioEnv` (master-loudness
curve) computed at load from the already-decoded PCM (buildLoudnessEnvelope).

Descriptor: the selected kind's live ModConfig drives the preview
(recording-head); committed fx keep their baked modulation. legacyModulation
+ followerFor centralized in modulation.ts and shared by preview + export.

Export parity: compositor runs the same computeIntensity; bpm/beatPhase +
the sidechain audioEnv thread jobs.ts → worker → edit.ts → compositor
(audioEnv only built when an fx actually uses sidechain).

DEFAULT_MODULATION depth 0 → new fx are envelope-only until the user
engages the modulator. Engine/store/descriptor/export tests green (179).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…hain scope

Adds the modulation control surface to the FX hardware panel, reusing the
existing TE chrome (LCD phosphor/scanlines, screws, brushed metal, JetBrains
Mono, SegmentedControl).

- ScreenModeColumn gains a third "M" button (P/E/M); ScreenMode is now
  params|env|mod. Lcd renders LcdModView in mod mode (LFO/SIDE readout:
  shape glyph + rate label, or THR%, plus DEPTH and SYNC/GATE state).
- ModControls in the encoder slot: SegmentedControl LFO|SIDE →
  setFxTimeMod. LFO branch = shape cycler (∿△◺◹⊓) + RATE knob (shows
  bipolarRateLabel — note division on the synced half, Hz on the free
  half) + DEPTH + SYNC toggle. SIDE branch = ATK/REL/DEPTH knobs + INV
  toggle.
- SidechainScope.tsx (new): phosphor-LCD widget drawing the master
  audioEnv as a filled loudness curve, a draggable dashed THRESHOLD line
  (window pointerup/blur drag guard → setFxSidechain), and the resulting
  effect-strength preview band via buildFollowerCurve tinted in the kind's
  capsuleColor, plus a playhead line. "NO AUDIO" placeholder when audioEnv
  is null. The panel grows only in mod+SIDE so the scope gets a strip
  under the controls; every other panel state stays pixel-identical.
- New mini primitives (MiniKnob/MiniToggle/ShapeButton) for the modulator
  controls (the existing Encoder is bound to fxDefaults).

Full suite green (1119 tests), tsc clean.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…t before

The master-loudness envelope was computed and stored before loadJob ran,
but loadJob resets per-job state (including audioEnv) to null — so the
value was immediately clobbered and the sidechain scope always read empty.
Move the setAudioEnv call to after loadJob completes.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…on-engine

# Conflicts:
#	frontend/src/pages/Editor.tsx
The M-screen modulation controls were bespoke MiniKnobs that didn't match
the FX macro knobs. Extract a shared presentational `EncoderKnob` from
`Encoder` (etched scale, the #58 active-range arc, body/cap/indicator, drag
+ click-on-scale + double-click reset + off-window release guard; props
value/min/max/kind/tint/label/onChange/onReset/size). `Encoder` is now a
thin fxDefaults-bound wrapper (macro knobs unchanged); ModControls renders
RATE/DEPTH (LFO) and ATK/REL/DEPTH (sidechain) via EncoderKnob at size 36.
MiniKnob deleted. SYNC/INV reuse MiniToggle, SHAPE the ShapeButton — same
hardware family. tsc clean, 1149 unit tests green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The scope drew the whole song squashed to ~270 buckets — individual hits
were unreadable, so you couldn't tune a threshold to the kick. Replace it
with an Ableton-style zoomed window:
- ~8 beats wide, playhead-centred, scrolls with playback; sampled per-pixel
  so each kick/snare is a clear separate peak.
- faint beat grid-lines (downbeats brighter) from bpm/beatPhase so you can
  see exactly where the beats fall and tune the threshold against them.
- master loudness fill + the tinted effect-strength band (memoized follower
  curve, sampled in the window) responding live; threshold line + readout.

Also: the SIDE-mode LCD now shows the actual knob values (THR / DEP / A ms /
R ms) so ATK/REL/DEPTH aren't opaque. tsc clean, 696 editor tests green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…h timeline)

The scope drew the loudness in raw master-audio time centred on the master
playhead (currentTime), while the timeline's MASTER·AUDIO lane draws in
arrangement/timeline time. In a long-form arrangement those are two
different orderings of the same audio, so the peaks didn't line up.

Now the scope is centred on timelineT and every window x is mapped
arr→master (arrToMaster) before sampling the master-indexed loudness +
follower curve; beat grid-lines use the arrangement beat anchor
(arrBeatPhaseS). Same musical content as the timeline → peaks correspond.
(It's still a zoomed ~8-beat detail view, so it shows fewer beats than the
full timeline span; exact 1:1 would need the timeline's view range lifted
to the store.) tsc clean.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…, 120fps)

The scope's peaks sat a beat-fraction off the timeline's audio peaks even on
the same axis: the envelope was RMS with window-START placement, so it both
read off the transient (energy lives in the note body) and led by up to a
full window. The timeline draws a min/max PEAK waveform.

Match it: build a PEAK (max-abs) envelope, window CENTRED on each timestamp,
at 120 fps. The envelope's peaks now sit on the loudest samples — the kick
transients — exactly where the timeline shows them, and the sidechain
triggers on the transient (what you actually want to tune to). Arr→master
mapping is unchanged (shared with the timeline audio lane), so multi-pill /
long-form stays aligned. tsc clean; envelope + modulation tests green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…t, no wobble)

The scope had its own playhead-centred window in master time; the timeline
draws in arrangement time over a different, paged window — so even with the
same audio source the peaks landed off, and centring on the (per-frame)
playhead made the waveform shimmer ("wabern") while playing.

Now the scope reconstructs the timeline's EXACT visible window from the
shared ui.zoom + ui.scrollX + totalArrDuration(segments) (liveTimelineRange
is always [0, arrTotal]), maps every column arr→master before sampling the
amplitude envelope, and draws PEAK-bucketed columns (max per column) instead
of point samples. Result: peaks line up 1:1 with the timeline audio lane,
the playhead sits at its true position, and the waveform is stable as the
window pages. Long-form / multi-pill stays correct because the arr→master
mapping and the segment set are exactly the timeline's. tsc clean.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Root cause of the drift (peaks further off the deeper into the track): the
amplitude envelope stored the REQUESTED fps (120) but hop is whole-sample
rounded (22050/120 = 183.75 → 184), so the true rate is 22050/184 = 119.84.
Sampling at index = t·120 read t·22080 instead of t·22050 — a 0.14% time
scale error = ~0.4s off at 5 minutes. Store the true rate (sampleRate/hop).

Hardening so it can't silently regress:
- export `sampleEnv` from modulation (single sampler for follower/render/scope).
- add `timelineVisibleWindow(arrTotal, zoom, scrollX)` to arrangement-time as
  the one source of the timeline's visible window; the scope uses it.
- tests: envelope time-axis accuracy at 22.05/44.1/48 kHz at 300s (would have
  caught the drift); scope window == timeline window across zoom/scroll;
  arr→master == the timeline's inline projection in every segment incl. a
  duplicate; and an end-to-end check that a transient lands in the same column
  in scope and timeline deep in a reordered long-form arrangement.

703 editor tests green, tsc clean.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Per the alignment audit's cosmetic notes: drop the scope's horizontal inset
(PAD_X 4→0) so its time axis fills the width exactly like the timeline
canvas — pixel-for-pixel cross-panel x. And make per-column peak sub-sampling
adaptive (cover the env samples a column spans, capped) so peak HEIGHT isn't
under-shown when zoomed out. No time-axis change. tsc clean.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…on-engine

# Conflicts:
#	frontend/src/editor/render/build-descriptor.test.ts
#	frontend/src/editor/render/build-descriptor.ts
#	frontend/src/local/jobs.ts
#	frontend/src/local/render/compositor.ts
#	frontend/src/local/render/edit.ts
#	frontend/src/local/render/edit.worker.ts
@johannboehme
johannboehme merged commit 8c7bc18 into main Jun 20, 2026
1 check passed
@johannboehme
johannboehme deleted the worktree-pfx-modulation-engine branch June 20, 2026 17:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

0