diff --git a/CLAUDE.md b/CLAUDE.md index 95d46e8..a64fe0f 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -1037,8 +1037,10 @@ Two independent apps that talk over HTTP: badge, the readout well (ELAPSED / REMAIN to tenths, KEY, and `BpmReadout` — click to type an exact BPM; with no grid, a typed or tapped BPM CREATES one at the playhead, and Set grid on a track with no BPM opens the readout to ask rather than failing), SNAP, Analyze, Auto hotcues. **Waveforms**: - `MainWaveform` (scrolling; zoom +/− in its corner and Cmd/Ctrl+scroll, owned - by `PrepStrip` so it survives track switches and persists) over + `MainWaveform` (scrolling; zoom +/− in its corner and Cmd/Ctrl+scroll, + 0.25–64 s across, owned by `PrepStrip` so it survives track switches and + persists; a toggle under the zoom buttons draws the RAW signal instead + of bars — `lib/rawWave.ts`, below; persisted as `mainWaveRaw`) over `OverviewWaveform`, which frames the main view's visible range around the playhead (it takes `secPerView` for exactly that). **Controls**: play, CUE, `LoopControls`, then EITHER `HotcueBar` OR — in **Grid mode** — `GridEditStrip`, then `TempoControls` @@ -2166,6 +2168,38 @@ The prep strip plays every track through the **Web Audio API** (a plain full scale for whole sections, so a linear map draws a solid orange wall instead of the kick pulse. The main view draws 2 px bars with a 1 px gap, **binned in track space** so bars scroll rather than flicker. +- `rawWave.ts` — **the raw waveform** (decided 2026-10-15, + [the discussion](.claude/discussions/discuss-raw-waveform-2026-10-15.md)): + the bars' ~7 ms columns of unsigned band energy hide where a kick starts, so + the main view can draw the signal itself as a thin line, after Traktor at + full zoom. Its own toggle (under the zoom buttons), NOT tied to Grid mode — + tried first, changed after use. + **Shape exact, colour approximate**: the tint is the bar palette weighted by + the ~7 ms band columns, lerped, mixed in OKLab with the CHROMA restored + (`bandColour`) — a plain RGB mean of orange/violet/cyan lands near grey and + read as mud; chosen from five variants rendered on real tracks; the scale is fixed by the track's loudest + sample (no per-view gain, so nothing pumps while scrolling). Each pixel is a + min→max stroke stretched to touch its neighbour's, so it reads as an + envelope zoomed out and a line zoomed in with no switch-over. Data: min/max + per 32 samples summarised at load (~4 MB / 6 min) for wide views; below 128 + samples a pixel, the visible window read straight from the `AudioBuffer` + (`copyFromChannel` — no full-length mono copy). Bins sit on a track-space + grid like the bars'. A stem track's lanes each draw their own raw line, in + the stem's colour, each at its own peak floored at 5% of the loudest. + Measured in WKWebView: 0.3 ms a frame at 0.25 s, ~5 ms at 64 s. +- `decodeAlign.ts` — **the deck's decode vs the grid's time base.** Positions + are in the backend's PyAV decode; the deck decodes with `decodeAudioData`. + Measured 2026-10-15 with click files: identical on every format and engine + EXCEPT a **header-less MP3 under WebKit** (the macOS app), decoded 529 + samples (12 ms) EARLY — CoreAudio trims the decoder delay with no header to + say so; FFmpeg (and Chromium/WebView2) do not. Invisible under bars, a + 12 ms miss on the raw line. The engine's offset is MEASURED once per session + by decoding a built-in 2.7 KB header-less MP3 (`decodeProbe.ts`, click at a + known FFmpeg sample), and a header-less MP3's buffer (`mp3HeaderFrame`, a + port of `core/mp3_gapless.parse` behind an is-it-an-MP3 gate) is padded by + it in `decodeUrl` — so playback, scratch and both waveforms move together. + Not measured: a header without a trusted encoder-delay field; Edge on a real + Windows machine (Chromium on macOS matched). - `cues.ts` — canvas drawers for cue markers (type-colored), the active loop band, the beatgrid (per-segment white beats/brighter downbeats, plus marker lines — gold for the one governing the playhead, accent otherwise, with the diff --git a/frontend/src/components/MainWaveform.tsx b/frontend/src/components/MainWaveform.tsx index 62fefdb..c889449 100644 --- a/frontend/src/components/MainWaveform.tsx +++ b/frontend/src/components/MainWaveform.tsx @@ -1,11 +1,19 @@ import { useEffect, useRef } from 'react' import type { CuePoint } from '../api' import type { BeatGrid } from '../lib/beatgrid' +import { Icon } from '../lib/icons' import { drawBeatgrid, drawCuePoint, drawCues, drawLoop, drawLoopIn, drawPlayhead } from '../lib/cues' +import { laneScales, makeSpans, paintRaw, rawSpans, tintAt, type RawWave } from '../lib/rawWave' import { paintLane, paintWave, type WaveColumn } from '../lib/waveform' interface Props { cols: WaveColumn[] + /** The samples, for the raw view. */ + raw?: RawWave | null + /** Draw the raw signal as a thin line instead of bars (the toggle under + the zoom buttons; owned by the parent, which persists it). */ + rawMode?: boolean + onRawModeChange?: (raw: boolean) => void currentTime: number duration: number cues: CuePoint[] @@ -36,6 +44,8 @@ interface Props { export interface StemLane { data: Float32Array + /** The stem's samples, for the raw view. */ + raw?: RawWave | null name: string color: string /** Not muted. */ @@ -50,7 +60,7 @@ const ALT = typeof navigator !== 'undefined' && /Mac/.test(navigator.platform) ? const DRAG_THRESHOLD = 3 // px before a press becomes a scratch (vs a click-seek) -export const MIN_SEC = 2 // most zoomed-in (seconds across the view) +export const MIN_SEC = 0.25 // most zoomed-in (seconds across the view): a kick's attack spans dozens of px export const MAX_SEC = 64 // most zoomed-out export const DEFAULT_SEC = 16 @@ -62,6 +72,9 @@ export const DEFAULT_SEC = 16 */ export function MainWaveform({ cols, + raw = null, + rawMode = false, + onRawModeChange, currentTime, duration, cues, @@ -89,6 +102,7 @@ export function MainWaveform({ const dragRef = useRef<{ startX: number; startTime: number; lastT: number; moved: boolean } | null>( null, ) + const spansRef = useRef(makeSpans()) // Draw closes over the latest props/state; a ref lets the ResizeObserver call // the current version without re-subscribing. @@ -111,7 +125,25 @@ export function MainWaveform({ // 2 px bars with a 1 px gap: the texture that makes the scrolling view // read as discrete energy rather than a smear. const bars = { bar: Math.max(1, Math.round(2 * dpr)), gap: Math.max(1, Math.round(dpr)) } - if (lanes && lanes.length) { + // The raw line's minimum stroke, so silence and flat stretches still read. + const thick = Math.max(1, 1.25 * dpr) + const spans = spansRef.current + if (rawMode && lanes && lanes.length && lanes.every((l) => l.raw)) { + const laneH = h / lanes.length + const scales = laneScales(lanes.map((l) => l.raw!.peak), laneH / 2 - thick) + lanes.forEach((lane, k) => { + rawSpans(lane.raw!, startSec, endSec, w, spans) + ctx.globalAlpha = lane.audible ? 0.92 : 0.18 + paintRaw(ctx, spans, k * laneH, laneH, scales[k], thick, lane.color) + }) + ctx.globalAlpha = 1 + ctx.fillStyle = 'rgba(255,255,255,0.06)' + for (let k = 1; k < lanes.length; k++) ctx.fillRect(0, Math.round(k * laneH), w, Math.max(1, Math.round(dpr))) + } else if (rawMode && !lanes?.length && raw) { + rawSpans(raw, startSec, endSec, w, spans) + const scale = (h / 2 - thick) / Math.max(raw.peak, 1e-6) + paintRaw(ctx, spans, 0, h, scale, thick, (t) => tintAt(cols, duration, t)) + } else if (lanes && lanes.length) { // Stem lanes, Traktor-style: each stem its own strip in its own colour. const laneH = h / lanes.length lanes.forEach((lane, k) => { @@ -263,9 +295,10 @@ export function MainWaveform({ )} - {/* Zoom controls (Traktor-style +/-). stopPropagation on down so tapping a - button doesn't begin a scratch drag. */} -
+ {/* Zoom in · raw/bars · zoom out, centred on the waveform's height. + stopPropagation on down so tapping a button doesn't begin a scratch + drag. */} +
+