From af02b1fc1c4930c91cc6b68c4f0729f8ae1ab48f Mon Sep 17 00:00:00 2001 From: Benjamin Hardy Date: Tue, 3 Nov 2026 08:49:26 +0100 Subject: [PATCH] Implemented performance mode settings --- CLAUDE.md | 14 +- frontend/src/components/AppSettings.tsx | 152 ++++++++++++++++++- frontend/src/components/PrepStrip.tsx | 28 +++- frontend/src/components/ShortcutsDialog.tsx | 6 +- frontend/src/components/deck/useDeck.tsx | 16 +- frontend/src/components/mixer/MixerPanel.tsx | 35 ++--- frontend/src/lib/audio/mixer.ts | 30 ++-- frontend/src/lib/audio/mixerMath.test.ts | 7 +- frontend/src/lib/audio/mixerMath.ts | 12 +- frontend/src/lib/audio/mixerState.ts | 37 +++-- frontend/src/lib/shortcuts.ts | 38 +++-- 11 files changed, 290 insertions(+), 85 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index c4d0525..b59cc75 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -1174,7 +1174,7 @@ Two independent apps that talk over HTTP: / Try again (`backend_restart`). The shell has no timeout of its own. Before ready it answers quit requests itself — nothing can be unsaved — and stops at ready so it never races `QuitGuard`), `SaveBar` (+ "Discard changes…" when - dirty, and the settings gear beside it, whose menu (or `?` anywhere) opens `ShortcutsDialog` — a KEYBOARD MAP (decided 2026-10-15): keys lit in the colour of what they do, a caption explaining the key pointed at or pressed (pressing explains, it never acts: a capture-phase listener keeps the deck's and table's keys from firing), holding or picking ⇧ / Cmd-Ctrl relights it with that layer, mouse gestures listed beneath. It shrinks to fit the dialog and drops the words on the keys when too small. Its content is `lib/shortcuts.ts`, written out BY HAND, so a new or changed shortcut in `lib/deckKeys.ts` / `TrackTable` must be added there too — and `AppSettings` ("Konduktor Settings…": app-level prefs, each with its default in `APP_SETTING_DEFAULTS` and read through `useAppSetting`; today `expandPlaylistFolders` and `exportRootFolder`, both default off — the latter read by the backend at `run_export` and passed down as `ExportPayload.root_folder` — and `timeReadoutDecimals` (0–3, default 1: the deck's ELAPSED / REMAIN, truncated, never rounded). The Sidebar holds folder open state as per-id overrides of that setting, reset on a new library or a change of the setting, and carried to the new ids when a rename/move changes a folder's path id)), `Toolbar` (search/filters; columns are chosen by right-clicking the table header), + dirty, and the settings gear beside it, whose menu (or `?` anywhere) opens `ShortcutsDialog` — a KEYBOARD MAP (decided 2026-10-15): keys lit in the colour of what they do, a caption explaining the key pointed at or pressed (pressing explains, it never acts: a capture-phase listener keeps the deck's and table's keys from firing), holding or picking ⇧ / Cmd-Ctrl relights it with that layer, mouse gestures listed beneath. It shrinks to fit the dialog and drops the words on the keys when too small. Its content is `lib/shortcuts.ts`, written out BY HAND, so a new or changed shortcut in `lib/deckKeys.ts` / `TrackTable` must be added there too — and `AppSettings` ("Konduktor Settings…": app-level prefs, each with its default in `APP_SETTING_DEFAULTS` and read through `useAppSetting`; today `expandPlaylistFolders` and `exportRootFolder`, both default off — the latter read by the backend at `run_export` and passed down as `ExportPayload.root_folder` — and `timeReadoutDecimals` (0–3, default 1: the deck's ELAPSED / REMAIN, truncated, never rounded); and the Performance mode section — `perfStems` (default on: a stem track loaded INTO performance mode plays its stems, else its mix; read at load, never reloads a deck), `keylockDefault` (on), `eqKill` (off = -26 dB), `crossfaderCurve` (smooth), and the colour effects' one parameter each, `fxFilterResonance` / `fxEchoBeats` / `fxSpaceSize` / `fxNoiseResonance` / `fxCrushDrive` (decided 2026-11-03: the mixer's per-channel PRM knob was removed; PrepStrip copies these into `mixerState`). The Sidebar holds folder open state as per-id overrides of that setting, reset on a new library or a change of the setting, and carried to the new ids when a rename/move changes a folder's path id)), `Toolbar` (search/filters; columns are chosen by right-clicking the table header), `TrackTable` (**the one track list** — All Tracks, playlists, exports and devices. TanStack Table + **virtualized** grid; per-row play button, configurable columns, header sorting, inline double-click editing, and @@ -2689,6 +2689,14 @@ that number and nothing else — everything derives from it: laptop. One computer at a time, with takeover. See "Remote libraries" under Architecture. Not yet: verified on a real TrueNAS (the image is published by CI's `server-image` job), a web UI served by the server (decided: not now). +- ✅ **Performance mode** (2026-11-03) — a second deck and a mixer to try + transitions: stacked waveforms, 3-band isolator, per-channel colour FX, + crossfader, limiter, pitch with Rubber Band keylock, SYNC with a tempo + master, a phase meter you can drag to bend. See `lib/audio/`, + `components/deck/`, `components/mixer/` and "Prep strip" / "Prep engine"; + [the discussion](.claude/discussions/discuss-performance-mode-2026-11-02.md). + Not yet: MIDI controllers (decided: later; WKWebView has no Web MIDI, so + through Tauri), headphone cue (decided: not needed), recording the mix. - ⬜ Serato adapter - ⬜ Bulk metadata editing; ⬜ Phase 4 — polish + optional Tauri desktop packaging @@ -2792,7 +2800,9 @@ The prep strip plays every track through the **Web Audio API** (a plain all-pass, so the bands sum flat — measured 0.0000 dB; Web Audio's lowpass/highpass Q is in DB, Butterworth = -3.01, its allpass Q linear) → the colour FX (Filter / Echo / Space / Noise / Crush, chosen PER CHANNEL, - one bipolar knob + one parameter, all built once and switched by gains) → + one bipolar COLOR knob; each effect's one parameter is an APP SETTING, not + a knob — `mixerState.fx`, decided 2026-11-03; all built once and switched + by gains) → fader → crossfader (smooth = constant power, sharp) → bus → limiter (DynamicsCompressor at -1.5 dBFS 20:1 — Web Audio adds an automatic MAKE-UP gain, +0.57 dB at -1/20:1, which let two loud decks peak at +0.3 diff --git a/frontend/src/components/AppSettings.tsx b/frontend/src/components/AppSettings.tsx index d70830e..3397d2c 100644 --- a/frontend/src/components/AppSettings.tsx +++ b/frontend/src/components/AppSettings.tsx @@ -21,6 +21,21 @@ export const APP_SETTING_DEFAULTS = { levelMeasure: 'lufs' as 'lufs' | 'rms', levelTarget: -9, levelCeiling: -1, + // Performance mode (decided 2026-11-02 / -03). + /** Stem tracks load as stems into a performance deck (else their mix: one + * time-stretcher instead of four). Read when a track loads. */ + perfStems: true, + /** A deck's keylock starts on. */ + keylockDefault: true, + /** EQ full left kills the band (else -26 dB, DJM-style). */ + eqKill: false, + crossfaderCurve: 'smooth' as 'smooth' | 'sharp', + /** The colour effects' one parameter each (the mixer has no knob for it). */ + fxFilterResonance: 0.3, + fxEchoBeats: 0.5, + fxSpaceSize: 2.5, + fxNoiseResonance: 0.3, + fxCrushDrive: 2, } type AppSettingKey = keyof typeof APP_SETTING_DEFAULTS @@ -40,6 +55,15 @@ export function AppSettings({ onClose }: { onClose: () => void }) { const levelMeasure = useAppSetting('levelMeasure') const levelTarget = useAppSetting('levelTarget') const levelCeiling = useAppSetting('levelCeiling') + const perfStems = useAppSetting('perfStems') + const keylockDefault = useAppSetting('keylockDefault') + const eqKill = useAppSetting('eqKill') + const crossfaderCurve = useAppSetting('crossfaderCurve') + const fxFilterResonance = useAppSetting('fxFilterResonance') + const fxEchoBeats = useAppSetting('fxEchoBeats') + const fxSpaceSize = useAppSetting('fxSpaceSize') + const fxNoiseResonance = useAppSetting('fxNoiseResonance') + const fxCrushDrive = useAppSetting('fxCrushDrive') const [error, setError] = useState(null) const set = async (patch: Partial) => { @@ -60,7 +84,7 @@ export function AppSettings({ onClose }: { onClose: () => void }) { × -
+

Sidebar

+
+

Performance mode

+ void set({ perfStems: v })} + title="Load stem tracks as stems" + text="A stem track loaded into a deck in performance mode plays its four stems (mute and solo work). Off, it plays its mix: lighter on an older computer, since keylock then stretches one stream instead of four. Applies to the next track loaded." + /> + void set({ keylockDefault: v })} + title="Keylock on" + text="Each deck starts with keylock on: a tempo change keeps the pitch. Each deck's KEY button still switches it." + /> + void set({ eqKill: v === 'kill' })} + /> + void set({ crossfaderCurve: v as 'smooth' | 'sharp' })} + /> + + The colour effects: what each one's setting is, on both channels. + + void set({ fxFilterResonance: Number(v) })} + /> + void set({ fxEchoBeats: Number(v) })} + /> + void set({ fxSpaceSize: Number(v) })} + /> + void set({ fxNoiseResonance: Number(v) })} + /> + void set({ fxCrushDrive: Number(v) })} + /> +
{error &&
{error}
}
@@ -160,6 +265,51 @@ export function AppSettings({ onClose }: { onClose: () => void }) { ) } +/** Resonance amounts offered (0..1 of the effect's maximum). */ +const LEVELS: [string, string][] = [ + ['0', 'None'], + ['0.3', 'Gentle'], + ['0.6', 'Medium'], + ['1', 'Strong'], +] + +function Check({ checked, onChange, title, text }: { + checked: boolean; onChange: (v: boolean) => void; title: string; text: string +}) { + return ( + + ) +} + +/** A setting picked from a list. A stored value not in the list (an older + * build's) shows as the list's first entry until changed. */ +function Choice({ title, value, options, onChange }: { + title: string; value: string; options: [string, string][]; onChange: (v: string) => void +}) { + return ( + + ) +} + /** A dB value typed in place, committed on blur / Enter, clamped to its range. */ export function LevelInput({ value, unit, min, max, onCommit }: { value: number; unit: string; min: number; max: number; onCommit: (v: number) => void diff --git a/frontend/src/components/PrepStrip.tsx b/frontend/src/components/PrepStrip.tsx index 659b285..4865d0c 100644 --- a/frontend/src/components/PrepStrip.tsx +++ b/frontend/src/components/PrepStrip.tsx @@ -6,6 +6,8 @@ import { useDropTarget, type DragPayload } from '../lib/drag' import { Icon } from '../lib/icons' import { usePrefsWriter } from '../lib/prefs' import { mixer } from '../lib/audio/mixer' +import { setMixer } from '../lib/audio/mixerState' +import { useAppSetting } from './AppSettings' import { alignedPosition, effectiveBpm, octaveFor, phaseOffset, syncRate, type DeckTempo as Tempo } from '../lib/sync' import { DeckControls } from './deck/DeckControls' import { DeckHeader } from './deck/DeckHeader' @@ -116,17 +118,38 @@ export function PrepStrip({ onEditTags, }: Props) { const view = useDeckView() + // Performance-mode settings (Settings ▸ Performance mode). + const perfStems = useAppSetting('perfStems') + const keylockDefault = useAppSetting('keylockDefault') + const eqKill = useAppSetting('eqKill') + const curve = useAppSetting('crossfaderCurve') + const filterResonance = useAppSetting('fxFilterResonance') + const echoBeats = useAppSetting('fxEchoBeats') + const spaceSize = useAppSetting('fxSpaceSize') + const noiseResonance = useAppSetting('fxNoiseResonance') + const crushDrive = useAppSetting('fxCrushDrive') + useEffect(() => { + setMixer({ eqKill, curve, fx: { filterResonance, echoBeats, spaceSize, noiseResonance, crushDrive } }) + }, [eqKill, curve, filterResonance, echoBeats, spaceSize, noiseResonance, crushDrive]) const lead: DeckId = performance ? focused : 'A' const playingA = useCallback((p: boolean) => onPlayingChange('A', p), [onPlayingChange]) const playingB = useCallback((p: boolean) => onPlayingChange('B', p), [onPlayingChange]) - const common = { secPerView: view.secPerView, onError, onNotify } + const common = { + secPerView: view.secPerView, + onError, + onNotify, + tempoActive: performance, + // A stem track loaded INTO performance mode follows the setting; the prep + // deck always loads stems. + stemsAllowed: !performance || perfStems, + keylockDefault, + } const editTags = (slot: DeckSlot) => (onEditTags && slot.origin === 'collection' ? onEditTags : undefined) const a = useDeck({ ...common, ...decks.A, caps: caps.A, channel: 'A', - tempoActive: performance, onPlayingChange: playingA, onEditTags: editTags(decks.A), persist: true, @@ -137,7 +160,6 @@ export function PrepStrip({ ...decks.B, caps: caps.B, channel: 'B', - tempoActive: performance, onPlayingChange: playingB, onEditTags: editTags(decks.B), persist: false, diff --git a/frontend/src/components/ShortcutsDialog.tsx b/frontend/src/components/ShortcutsDialog.tsx index 04f1b8c..eb245c9 100644 --- a/frontend/src/components/ShortcutsDialog.tsx +++ b/frontend/src/components/ShortcutsDialog.tsx @@ -55,7 +55,7 @@ export function ShortcutsDialog({ onClose }: Props) { const [pressed, setPressed] = useState(null) const [query, setQuery] = useState('') const [areas, setAreas] = useState>(new Set(ALL_AREAS)) - const layer: Layer = held.has('mod') ? 'mod' : held.has('shift') ? 'shift' : sticky + const layer: Layer = held.has('mod') ? 'mod' : held.has('alt') ? 'alt' : held.has('shift') ? 'shift' : sticky const q = query.trim().toLowerCase() // ---- fit: one key unit from the width the map has ---- @@ -424,8 +424,8 @@ function Caption({ <> Point at a key, or press it, to see what it does. - Hold {MODIFIER_KEY.shift} or {MODIFIER_KEY.mod}, or pick one above, to see what each - modifier changes. + Hold {MODIFIER_KEY.shift}, {MODIFIER_KEY.mod} or {MODIFIER_KEY.alt}, or pick + one above, to see what each modifier changes. {padRange(slots)} are this library's {slots} hotcue pads; Q W E R are the stems of a stem track. diff --git a/frontend/src/components/deck/useDeck.tsx b/frontend/src/components/deck/useDeck.tsx index 1ce53c9..8f77ca8 100644 --- a/frontend/src/components/deck/useDeck.tsx +++ b/frontend/src/components/deck/useDeck.tsx @@ -79,6 +79,11 @@ export interface DeckOptions { /** Performance mode: the pitch fader and keylock apply (else the deck plays * at the file's own tempo). */ tempoActive?: boolean + /** Load a stem track as its stems (else its mix). Read when a track loads, + * so changing it never reloads the deck. */ + stemsAllowed?: boolean + /** Keylock's starting state (the `keylockDefault` setting). */ + keylockDefault?: boolean /** The mixer channel this deck plays into (default A). */ channel?: Channel /** Persist this deck's loop size and cue bank (deck A; default true). */ @@ -99,6 +104,8 @@ export function useDeck({ onPlayingChange, onEditTags, tempoActive = false, + stemsAllowed = true, + keylockDefault = true, channel = 'A', persist = true, leadsAmbient = true, @@ -265,6 +272,9 @@ export function useDeck({ void setAmbientFromArt(trackId && origin === 'collection' ? api.artUrl(trackId) : null) }, [trackId, origin, leadsAmbient]) + const stemsAllowedRef = useRef(stemsAllowed) + stemsAllowedRef.current = stemsAllowed + // Analyse once per track; the decoded buffer feeds both the playback and // scratch engines (no re-decode) and both waveform views share the columns. useEffect(() => { @@ -284,7 +294,7 @@ export function useDeck({ setWaveStatus('loading') // A stem FILE loads its four stems and plays their sum (decided: always, // for every stem track); anything else loads as one buffer, as before. - const load = trackStemsFor(origin, trackId) + const load = (stemsAllowedRef.current ? trackStemsFor(origin, trackId) : Promise.resolve([] as StemInfo[])) .catch(() => [] as StemInfo[]) .then(async (found) => { if (found.length) { @@ -1198,7 +1208,9 @@ export function useDeck({ // coming back to performance mode finds the fader where it was. const [pitch, setPitchState] = useState(0) const [pitchRange, setPitchRange] = useState(PITCH_RANGES[0]) - const [keylock, setKeylock] = useState(true) + const [keylock, setKeylock] = useState(keylockDefault) + // The setting changing (or arriving with the prefs) sets every deck. + useEffect(() => setKeylock(keylockDefault), [keylockDefault]) // A pitch BEND: a momentary push or drag on top of the fader (the phase // meter's drag), 1 = none. Part of `rate`, so the readout and a follower see it. const [bend, setBend] = useState(1) diff --git a/frontend/src/components/mixer/MixerPanel.tsx b/frontend/src/components/mixer/MixerPanel.tsx index 8ea3372..d359e78 100644 --- a/frontend/src/components/mixer/MixerPanel.tsx +++ b/frontend/src/components/mixer/MixerPanel.tsx @@ -1,15 +1,14 @@ import { useEffect, useRef, useState, type RefObject } from 'react' import { mixer } from '../../lib/audio/mixer' -import { faderGain, filterSweep, echoBeats, eqGain, gainToDb, TRIM_RANGE_DB, EQ_CUT_DB } from '../../lib/audio/mixerMath' +import { faderGain, filterSweep, eqGain, gainToDb, TRIM_RANGE_DB, EQ_CUT_DB } from '../../lib/audio/mixerMath' import { - DEFAULT_CHANNEL, FX_LABELS, - FX_PARAM, FX_TYPES, setChannel, setMixer, useMixer, type Channel, + type FxSettings, type FxType, } from '../../lib/audio/mixerState' import { Icon } from '../../lib/icons' @@ -23,23 +22,23 @@ const METER_TOP = 3 const fmtDb = (db: number, places = 1) => !isFinite(db) ? '−∞ dB' : `${db > 0 ? '+' : db < 0 ? '−' : ''}${Math.abs(db).toFixed(places)} dB` -function describeFx(fx: FxType, c: number, param: number): string { +function describeFx(fx: FxType, c: number, set: FxSettings): string { const a = Math.round(Math.abs(c) * 100) if (Math.abs(c) < 0.02) return `${FX_LABELS[fx]}: off (turn left or right)` switch (fx) { case 'filter': { const s = filterSweep(c)! const hz = s.freq >= 1000 ? `${(s.freq / 1000).toFixed(1)} kHz` : `${Math.round(s.freq)} Hz` - return `Filter: ${s.type === 'lowpass' ? 'low-pass' : 'high-pass'} at ${hz}` + return `Filter: ${s.type === 'lowpass' ? 'low-pass' : 'high-pass'} at ${hz} · resonance ${Math.round(set.filterResonance * 100)}%` } case 'echo': - return `Echo ${a}% · ${beatsLabel(echoBeats(param))} · ${c < 0 ? 'darker' : 'thinner'} repeats` + return `Echo ${a}% · ${beatsLabel(set.echoBeats)} · ${c < 0 ? 'darker' : 'thinner'} repeats` case 'space': - return `Space ${a}% · ${c < 0 ? 'darker' : 'thinner'}` + return `Space ${a}% · ${set.spaceSize} s · ${c < 0 ? 'darker' : 'thinner'}` case 'noise': return `Noise ${a}% · ${c < 0 ? 'low-pass' : 'high-pass'} sweep` case 'crush': - return `Crush ${a}%` + return `Crush ${a}% · drive ×${set.crushDrive}` } } @@ -50,7 +49,8 @@ function beatsLabel(b: number): string { /** * The mixer, between the decks in performance mode (decided 2026-11-02): per * channel TRIM (on top of the track's auto gain), HI / MID / LOW, a colour - * effect with its own selector and parameter, a fader and its meter; between + * effect with its own selector (its one parameter is an app setting, under + * Performance mode in Settings), a fader and its meter; between * them the master meter and the limiter's light; the crossfader beneath. The * values live in `mixerState` and the audio in `mixer.ts`. */ @@ -155,6 +155,7 @@ function Strip({ }) { const s = useMixer((m) => m[ch]) const eqKill = useMixer((m) => m.eqKill) + const fxSettings = useMixer((m) => m.fx) const [fxMenu, setFxMenu] = useState<{ x: number; y: number } | null>(null) const set = (patch: Parameters[1]) => setChannel(ch, patch) const describeEq = (band: string) => (v: number) => { @@ -199,7 +200,7 @@ function Strip({ setFxMenu({ x: r.left, y: r.bottom + 4 }) }} title="Which effect the COLOR knob drives" - className="btn-glass col-span-2 mt-0.5 flex h-6 items-center justify-center gap-0.5 self-start rounded-md text-[10px] font-semibold uppercase tracking-[0.06em] text-text" + className="btn-glass col-span-3 mt-0.5 flex h-6 items-center justify-center gap-0.5 self-start rounded-md text-[10px] font-semibold uppercase tracking-[0.06em] text-text" > {FX_LABELS[s.fx]} @@ -213,19 +214,7 @@ function Strip({ color="var(--color-gold)" onChange={(v) => set({ color: Math.abs(v) < 0.02 ? 0 : v })} label="Color" - describe={(v) => describeFx(s.fx, v, s.param)} - /> - set({ param: v })} - label="Prm" - describe={(v) => - `${FX_PARAM[s.fx]}: ${s.fx === 'echo' ? beatsLabel(echoBeats(v)) : `${Math.round(v * 100)}%`}` - } + describe={(v) => describeFx(s.fx, v, fxSettings)} />
) diff --git a/frontend/src/lib/audio/mixer.ts b/frontend/src/lib/audio/mixer.ts index 3e950d3..c275937 100644 --- a/frontend/src/lib/audio/mixer.ts +++ b/frontend/src/lib/audio/mixer.ts @@ -34,7 +34,7 @@ import { TRIM_RANGE_DB, xfadeGains, } from './mixerMath' -import { getMixerState, subscribeMixer, type Channel, type ChannelState, type FxType } from './mixerState' +import { getMixerState, subscribeMixer, type Channel, type ChannelState, type FxSettings, type FxType } from './mixerState' /** Butterworth Q in Web Audio's lowpass/highpass units (dB). */ const BUTTERWORTH_DB = 20 * Math.log10(Math.SQRT1_2) @@ -101,7 +101,8 @@ function crushCurve(bits: number): Float32Array { /** * One channel's colour effect: ONE knob, -1..1, out of the path at the centre; - * which effect it drives is the channel's own choice (decided 2026-11-02). + * which effect it drives is the channel's own choice (decided 2026-11-02), its + * one parameter an app setting (`FxSettings`, decided 2026-11-03). * Every effect is built once and switched by gains, so a change never clicks; * echo and reverb tails ring out after the knob returns. */ @@ -176,7 +177,7 @@ class ColorFx { this.input.connect(this.crushDrive).connect(this.shaper).connect(this.crushWet).connect(this.output) } - apply(type: FxType, color: number, param: number, bpm: number): void { + apply(type: FxType, color: number, fx: FxSettings, bpm: number): void { const ctx = this.ctx const a = Math.min(1, Math.abs(color)) const on = a >= FX_CENTRE @@ -190,7 +191,7 @@ class ColorFx { if (filtering) { if (this.filter.type !== sweep.type) this.filter.type = sweep.type ramp(this.filter.frequency, sweep.freq, ctx) - ramp(this.filter.Q, param * 15, ctx) + ramp(this.filter.Q, fx.filterResonance * 15, ctx) } ramp(this.filterWet.gain, filtering ? take : 0, ctx) @@ -199,7 +200,7 @@ class ColorFx { ramp(this.echoSend.gain, echoing ? a * 0.8 : 0, ctx) ramp(this.feedback.gain, echoing ? 0.35 + 0.5 * a : 0.45, ctx, 0.05) if (type === 'echo') { - ramp(this.delay.delayTime, echoSeconds(param, bpm), ctx, 0.05) + ramp(this.delay.delayTime, echoSeconds(fx.echoBeats, bpm), ctx, 0.05) const tone = color < 0 ? 'lowpass' : 'highpass' if (this.echoTone.type !== tone) this.echoTone.type = tone ramp(this.echoTone.frequency, color < 0 ? 2500 : 600, ctx) @@ -209,7 +210,7 @@ class ColorFx { const spacing = type === 'space' && on ramp(this.spaceSend.gain, spacing ? a : 0, ctx) if (type === 'space') { - const size = Math.round((0.8 + param * 4) * 10) / 10 + const size = Math.round(Math.max(0.3, Math.min(8, fx.spaceSize)) * 10) / 10 if (size !== this.spaceSize) { this.spaceSize = size this.convolver.buffer = impulse(ctx, size) @@ -224,11 +225,11 @@ class ColorFx { if (noising) { if (this.noiseFilter.type !== sweep.type) this.noiseFilter.type = sweep.type ramp(this.noiseFilter.frequency, sweep.freq, ctx) - ramp(this.noiseFilter.Q, param * 15, ctx) + ramp(this.noiseFilter.Q, fx.noiseResonance * 15, ctx) } ramp(this.noiseGain.gain, noising ? a * 0.25 : 0, ctx) - // Crush: fewer bits as the knob opens (16 → 3), driven by the parameter. + // Crush: fewer bits as the knob opens (16 → 3), driven by the setting. const crushing = type === 'crush' && on if (crushing) { const bits = Math.round(16 - a * 13) @@ -236,10 +237,9 @@ class ColorFx { this.crushBits = bits this.shaper.curve = crushCurve(bits) } - const drive = 1 + param * 3 - ramp(this.crushDrive.gain, drive, ctx) + ramp(this.crushDrive.gain, fx.crushDrive, ctx) } - ramp(this.crushWet.gain, crushing ? take / (1 + param * 3) ** 0.5 : 0, ctx) + ramp(this.crushWet.gain, crushing ? take / Math.max(1, fx.crushDrive) ** 0.5 : 0, ctx) ramp(this.dry.gain, filtering || crushing ? 1 - take : 1, ctx) } @@ -298,14 +298,14 @@ class Strip { this.input.connect(this.dryGate).connect(bus) } - apply(s: ChannelState, xfade: number, eqKill: boolean): void { + apply(s: ChannelState, xfade: number, eqKill: boolean, fx: FxSettings): void { const ctx = this.ctx const trimDb = this.autoGainDb + Math.max(-TRIM_RANGE_DB, Math.min(TRIM_RANGE_DB, s.trim)) ramp(this.trim.gain, dbToGain(trimDb), ctx) ramp(this.bands[0].gain, eqGain(s.low, eqKill), ctx) ramp(this.bands[1].gain, eqGain(s.mid, eqKill), ctx) ramp(this.bands[2].gain, eqGain(s.high, eqKill), ctx) - this.fx.apply(s.fx, s.color, s.param, this.bpm) + this.fx.apply(s.fx, s.color, fx, this.bpm) ramp(this.fader.gain, faderGain(s.fader), ctx) ramp(this.xfade.gain, xfade, ctx) } @@ -396,8 +396,8 @@ export class Mixer { private apply(): void { const s = getMixerState() const [ga, gb] = xfadeGains(s.crossfader, s.curve) - this.strips.A.apply(s.A, ga, s.eqKill) - this.strips.B.apply(s.B, gb, s.eqKill) + this.strips.A.apply(s.A, ga, s.eqKill, s.fx) + this.strips.B.apply(s.B, gb, s.eqKill, s.fx) } private peak(meter: AnalyserNode): number { diff --git a/frontend/src/lib/audio/mixerMath.test.ts b/frontend/src/lib/audio/mixerMath.test.ts index 001c3da..4fdaf34 100644 --- a/frontend/src/lib/audio/mixerMath.test.ts +++ b/frontend/src/lib/audio/mixerMath.test.ts @@ -1,5 +1,5 @@ import { describe, expect, it } from 'vitest' -import { echoBeats, echoSeconds, eqGain, faderGain, filterSweep, gainToDb, xfadeGains } from './mixerMath' +import { echoSeconds, eqGain, faderGain, filterSweep, gainToDb, xfadeGains } from './mixerMath' describe('eqGain', () => { it('is flat at the centre, +6 dB at full right', () => { @@ -63,10 +63,7 @@ describe('filterSweep', () => { }) describe('echo', () => { - it('picks its length in beats from the parameter and follows the tempo', () => { - expect(echoBeats(0)).toBe(1 / 8) - expect(echoBeats(0.5)).toBe(1 / 2) - expect(echoBeats(1)).toBe(1) + it('is its length in beats at the deck’s tempo', () => { expect(echoSeconds(1, 120)).toBeCloseTo(0.5, 9) expect(echoSeconds(0.5, 128)).toBeCloseTo(60 / 128 / 2, 9) expect(echoSeconds(1, 0)).toBeCloseTo(0.5, 9) // unknown tempo: 120 diff --git a/frontend/src/lib/audio/mixerMath.ts b/frontend/src/lib/audio/mixerMath.ts index 26232e7..f71d0c9 100644 --- a/frontend/src/lib/audio/mixerMath.ts +++ b/frontend/src/lib/audio/mixerMath.ts @@ -66,14 +66,10 @@ export function filterSweep(c: number): { type: 'lowpass' | 'highpass'; freq: nu : { type: 'highpass', freq: 20 * (8000 / 20) ** a } } -/** The echo's lengths in beats, picked by the parameter knob. */ +/** The echo lengths offered (beats). */ export const ECHO_BEATS = [1 / 8, 1 / 4, 1 / 2, 3 / 4, 1] -export function echoBeats(param: number): number { - return ECHO_BEATS[Math.round(clamp(param, 0, 1) * (ECHO_BEATS.length - 1))] -} - -/** Seconds of echo for `param` at `bpm` (120 when the tempo is unknown). */ -export function echoSeconds(param: number, bpm: number): number { - return (echoBeats(param) * 60) / (bpm > 0 ? bpm : 120) +/** Seconds of echo for `beats` at `bpm` (120 when the tempo is unknown). */ +export function echoSeconds(beats: number, bpm: number): number { + return (beats * 60) / (bpm > 0 ? bpm : 120) } diff --git a/frontend/src/lib/audio/mixerState.ts b/frontend/src/lib/audio/mixerState.ts index 87c8342..f5fee47 100644 --- a/frontend/src/lib/audio/mixerState.ts +++ b/frontend/src/lib/audio/mixerState.ts @@ -19,13 +19,29 @@ export const FX_LABELS: Record = { noise: 'Noise', crush: 'Crush', } -/** What each effect's parameter knob does. */ -export const FX_PARAM: Record = { - filter: 'Resonance', - echo: 'Echo length (beats)', - space: 'Reverb size', - noise: 'Noise resonance', - crush: 'Drive', +/** + * Each effect's one setting — app settings, not knobs (decided 2026-11-03: the + * per-channel parameter knob was removed), the same for both channels. + */ +export interface FxSettings { + /** Filter resonance, 0..1. */ + filterResonance: number + /** Echo length in beats of the deck's tempo. */ + echoBeats: number + /** Space: the reverb's decay (s). */ + spaceSize: number + /** Noise sweep resonance, 0..1. */ + noiseResonance: number + /** Crush drive, 1..4. */ + crushDrive: number +} + +export const DEFAULT_FX: FxSettings = { + filterResonance: 0.3, + echoBeats: 0.5, + spaceSize: 2.5, + noiseResonance: 0.3, + crushDrive: 2, } export interface ChannelState { @@ -38,8 +54,6 @@ export interface ChannelState { fx: FxType /** The colour knob, -1..1 (centre = effect off). */ color: number - /** The effect's parameter, 0..1. */ - param: number /** The channel fader, 0..1. */ fader: number } @@ -52,6 +66,7 @@ export interface MixerState { curve: CrossfaderCurve /** EQ cuts to silence at full left (else to -26 dB). */ eqKill: boolean + fx: FxSettings } export const DEFAULT_CHANNEL: ChannelState = { @@ -61,7 +76,6 @@ export const DEFAULT_CHANNEL: ChannelState = { high: 0, fx: 'filter', color: 0, - param: 0.5, fader: 1, } @@ -71,6 +85,7 @@ let state: MixerState = { crossfader: 0, curve: 'smooth', eqKill: false, + fx: DEFAULT_FX, } const listeners = new Set<() => void>() @@ -92,7 +107,7 @@ export function setChannel(ch: Channel, patch: Partial): void { commit({ ...state, [ch]: { ...state[ch], ...patch } }) } -export function setMixer(patch: Partial>): void { +export function setMixer(patch: Partial>): void { commit({ ...state, ...patch }) } diff --git a/frontend/src/lib/shortcuts.ts b/frontend/src/lib/shortcuts.ts index 3e26e54..715d9f2 100644 --- a/frontend/src/lib/shortcuts.ts +++ b/frontend/src/lib/shortcuts.ts @@ -5,17 +5,18 @@ import { cueTypeColor, GRID_MARKER_ACTIVE_COLOR } from './cues' import { IS_MAC } from './modKey' /** A modifier layer of the keyboard. `mod` is Cmd on macOS, Ctrl elsewhere — - * the handlers accept either, but the map names your key. */ -export type Layer = 'base' | 'shift' | 'mod' -export const LAYERS: Layer[] = ['base', 'shift', 'mod'] + * the handlers accept either, but the map names your key. `alt` (Option on + * macOS) sends a deck key to the OTHER deck in performance mode. */ +export type Layer = 'base' | 'shift' | 'mod' | 'alt' +export const LAYERS: Layer[] = ['base', 'shift', 'mod', 'alt'] export const MODIFIER_KEY: Record, string> = IS_MAC - ? { shift: '⇧', mod: '⌘' } - : { shift: 'Shift', mod: 'Ctrl' } + ? { shift: '⇧', mod: '⌘', alt: '⌥' } + : { shift: 'Shift', mod: 'Ctrl', alt: 'Alt' } export const LAYER_NAMES: Record = IS_MAC - ? { base: 'No modifier', shift: '⇧ Shift', mod: '⌘ Command' } - : { base: 'No modifier', shift: 'Shift', mod: 'Ctrl' } + ? { base: 'No modifier', shift: '⇧ Shift', mod: '⌘ Command', alt: '⌥ Option' } + : { base: 'No modifier', shift: 'Shift', mod: 'Ctrl', alt: 'Alt' } /** Where a shortcut acts. The colour lights its key on the map. */ export type Area = 'deck' | 'list' | 'any' @@ -61,7 +62,7 @@ export function padRange(slots: number): string { } export function bindings(slots: number): Bindings { - const b: Bindings = { base: {}, shift: {}, mod: {} } + const b: Bindings = { base: {}, shift: {}, mod: {}, alt: {} } const pad = cueTypeColor('cue') padCodes(slots).forEach((code, i) => { const n = i + 1 @@ -125,6 +126,15 @@ export function bindings(slots: number): Bindings { ArrowUp: [{ area: 'deck', label: 'Size ×2', text: 'Double the loop and beat-jump size (up to 32 beats)' }], KeyA: [{ area: 'list', label: 'All', text: 'Select every track in the list' }], } satisfies Record) + // Alt / Option: every deck key, on the OTHER deck (performance mode). + for (const [code, binds] of Object.entries(b.base)) { + const deck = binds.filter((x) => x.area === 'deck') + if (!deck.length || code === 'KeyP') continue + b.alt[code] = deck.map((x) => ({ + ...x, + text: `Performance mode — on the other deck: ${x.text.charAt(0).toLowerCase()}${x.text.slice(1)}`, + })) + } return b } @@ -152,6 +162,9 @@ export const MOUSE: { title: string; rows: MouseGesture[] }[] = [ { gesture: 'Right-click', on: 'pad', text: 'Hotcue type, colour, rename, delete' }, { gesture: 'Click', on: 'memory cue', text: 'Jump there and make it the CUE point (a memory loop engages)' }, { gesture: 'Right-click', on: 'memory cue', text: 'Memory cue type, colour, rename, delete' }, + { gesture: 'Click', on: 'deck (performance mode)', text: 'Aim the keys at that deck' }, + { gesture: 'Drag', on: 'phase meter', text: 'Bend the deck’s speed while held (right faster, left slower)' }, + { gesture: 'Drag', on: 'knob', text: 'Turn it (⇧ for finer); double-click resets it' }, ], }, { @@ -208,18 +221,18 @@ export const KEY_ROWS: KeyDef[][] = (() => { ? [ key('Fn', 'fn'), key('ControlLeft', 'control', 1.25, undefined, 'ctrl'), - key('AltLeft', 'option ⌥', 1.25, undefined, '⌥'), + key('AltLeft', 'option ⌥', 1.25, 'alt', '⌥'), key('MetaLeft', 'command ⌘', 1.5, 'mod', '⌘'), key('Space', 'space', 6.75), key('MetaRight', 'command ⌘', 1.5, 'mod', '⌘'), - key('AltRight', 'option ⌥', 1.25, undefined, '⌥'), + key('AltRight', 'option ⌥', 1.25, 'alt', '⌥'), ] : [ key('ControlLeft', 'Ctrl', 1.25, 'mod'), key('MetaLeft', 'Win', 1.25), - key('AltLeft', 'Alt', 1.25), + key('AltLeft', 'Alt', 1.25, 'alt'), key('Space', 'space', 6.75), - key('AltRight', 'Alt', 1.25), + key('AltRight', 'Alt', 1.25, 'alt'), key('MetaRight', 'Win', 1.25), key('ControlRight', 'Ctrl', 1.5, 'mod'), ] @@ -254,6 +267,7 @@ export const KEYS_BY_CODE: Record = Object.fromEntries( /** The modifier layer a physical key holds, if it is one. */ export function modifierLayer(code: string): Exclude | null { if (code === 'ShiftLeft' || code === 'ShiftRight') return 'shift' + if (code === 'AltLeft' || code === 'AltRight') return 'alt' const mod = IS_MAC ? ['MetaLeft', 'MetaRight'] : ['ControlLeft', 'ControlRight'] return mod.includes(code) ? 'mod' : null }