From 341f12e27532ebe5ec3d4cbd33c028f2d590d261 Mon Sep 17 00:00:00 2001 From: Benjamin Hardy Date: Tue, 3 Nov 2026 09:14:02 +0100 Subject: [PATCH] Moved performance settings to their own panel --- CLAUDE.md | 7 +- frontend/src/components/AppSettings.tsx | 110 +--------- .../src/components/PerformanceSettings.tsx | 196 ++++++++++++++++++ frontend/src/components/PrepStrip.tsx | 8 +- frontend/src/components/SettingsMenu.tsx | 15 +- .../src/components/mixer/CrossfaderCurve.tsx | 42 ++++ frontend/src/components/mixer/MixerPanel.tsx | 8 +- frontend/src/lib/audio/mixer.ts | 2 +- frontend/src/lib/audio/mixerMath.test.ts | 34 ++- frontend/src/lib/audio/mixerMath.ts | 28 ++- frontend/src/lib/audio/mixerState.ts | 8 +- 11 files changed, 319 insertions(+), 139 deletions(-) create mode 100644 frontend/src/components/PerformanceSettings.tsx create mode 100644 frontend/src/components/mixer/CrossfaderCurve.tsx diff --git a/CLAUDE.md b/CLAUDE.md index b59cc75..329d35b 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); 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), + 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 its own panel, `PerformanceSettings` ("Performance mode…", decided 2026-11-03), whose values sit in the same `APP_SETTING_DEFAULTS`: `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), `crossfaderSharpness` (0..1, default 0 = smooth: a slider beside `CrossfaderCurveGraph`, which draws both channels' curves and where the crossfader is; dragging it moves the mixer at once and saves through the debounced prefs writer), and the colour effects' one parameter each, `fxFilterResonance` / `fxEchoBeats` / `fxSpaceSize` / `fxNoiseResonance` / `fxCrushDrive` (the mixer's per-channel PRM knob was removed). PrepStrip copies them 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 @@ -2803,7 +2803,10 @@ The prep strip plays every track through the **Web Audio API** (a plain 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 + fader → crossfader (`xfadeGains(x, sharpness)`: each channel fades on a + quarter-cosine over the last `xfadeWidth` of the travel — the whole of it + at 0, constant power, -3 dB in the middle; 4% at 1, a cut; no dip in the + middle above ~0.52) → 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 dBFS until a gain after it took it back off) → speakers. Channel meters are diff --git a/frontend/src/components/AppSettings.tsx b/frontend/src/components/AppSettings.tsx index 3397d2c..fe5e19e 100644 --- a/frontend/src/components/AppSettings.tsx +++ b/frontend/src/components/AppSettings.tsx @@ -21,7 +21,8 @@ export const APP_SETTING_DEFAULTS = { levelMeasure: 'lufs' as 'lufs' | 'rms', levelTarget: -9, levelCeiling: -1, - // Performance mode (decided 2026-11-02 / -03). + // Performance mode (decided 2026-11-02 / -03) — its own panel, + // PerformanceSettings.tsx. /** 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, @@ -29,7 +30,8 @@ export const APP_SETTING_DEFAULTS = { keylockDefault: true, /** EQ full left kills the band (else -26 dB, DJM-style). */ eqKill: false, - crossfaderCurve: 'smooth' as 'smooth' | 'sharp', + /** The crossfader curve: 0 smooth (constant power) .. 1 sharp (a cut). */ + crossfaderSharpness: 0, /** The colour effects' one parameter each (the mixer has no knob for it). */ fxFilterResonance: 0.3, fxEchoBeats: 0.5, @@ -55,15 +57,6 @@ 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) => { @@ -84,7 +77,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}
}
@@ -265,15 +177,7 @@ 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 }: { +export function Check({ checked, onChange, title, text }: { checked: boolean; onChange: (v: boolean) => void; title: string; text: string }) { return ( @@ -289,7 +193,7 @@ function Check({ checked, onChange, title, text }: { /** 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 }: { +export function Choice({ title, value, options, onChange }: { title: string; value: string; options: [string, string][]; onChange: (v: string) => void }) { return ( diff --git a/frontend/src/components/PerformanceSettings.tsx b/frontend/src/components/PerformanceSettings.tsx new file mode 100644 index 0000000..4e1c564 --- /dev/null +++ b/frontend/src/components/PerformanceSettings.tsx @@ -0,0 +1,196 @@ +import { useEffect, useState } from 'react' +import { useQueryClient } from '@tanstack/react-query' +import { api } from '../api' +import { setMixer } from '../lib/audio/mixerState' +import { usePrefsWriter } from '../lib/prefs' +import { APP_SETTING_DEFAULTS, Check, Choice, useAppSetting } from './AppSettings' +import { Modal } from './Modal' +import { Fader } from './mixer/Controls' +import { CrossfaderCurveGraph } from './mixer/CrossfaderCurve' + +/** Resonance amounts offered (0..1 of the effect's maximum). */ +const LEVELS: [string, string][] = [ + ['0', 'None'], + ['0.3', 'Gentle'], + ['0.6', 'Medium'], + ['1', 'Strong'], +] + +const section = 'text-[11px] font-semibold uppercase tracking-wider text-faint' + +/** + * Settings ▸ Performance mode… (its own panel, decided 2026-11-03): the decks, + * the mixer and the colour effects' parameters. Values live in the app + * settings (userprefs.json, `APP_SETTING_DEFAULTS`); PrepStrip copies the + * mixer's into `mixerState`. + */ +export function PerformanceSettings({ onClose }: { onClose: () => void }) { + const qc = useQueryClient() + const writePrefs = usePrefsWriter() + const perfStems = useAppSetting('perfStems') + const keylockDefault = useAppSetting('keylockDefault') + const eqKill = useAppSetting('eqKill') + const sharpnessSetting = useAppSetting('crossfaderSharpness') + 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) + + // The curve moves with the slider at once — mixer included, so it can be + // heard while dragging — and is saved through the debounced prefs writer. + const [sharpness, setSharpness] = useState(sharpnessSetting) + useEffect(() => setSharpness(sharpnessSetting), [sharpnessSetting]) + const changeSharpness = (v: number) => { + const s = Math.round(v * 100) / 100 + setSharpness(s) + setMixer({ sharpness: s }) + writePrefs({ crossfaderSharpness: s }) + } + + const set = async (patch: Partial) => { + setError(null) + try { + qc.setQueryData(['prefs'], await api.patchPrefs(patch)) + } catch (e) { + setError((e as Error).message) + } + } + + const curveName = + sharpness === 0 ? 'Smooth' : sharpness === 1 ? 'Sharp' : sharpness < 0.52 ? 'Blend' : 'Cut' + + return ( + +
+
+

Performance mode

+ +
+
+

+ The second deck and the mixer (P, or the decks button in the deck's header). +

+
+

Decks

+ 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." + /> +
+
+

Mixer

+ void set({ eqKill: v === 'kill' })} + /> +
+
+ Crossfader curve + + {curveName} · {Math.round(sharpness * 100)}% + +
+
+ +
+ `${Math.round(v * 100)}% sharp — double-click for smooth`} + className="w-full" + /> +
+ Smooth + Sharp +
+
+
+ + Smooth blends: each channel fades across the whole travel, both at −3 dB in the middle. + Sharper keeps both at full level across a widening middle and fades only near the ends — + at full, a cut over the last few percent, for scratching. + +
+
+
+

Colour effects

+ Each effect's setting, 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}
} +
+
+ +
+
+
+ ) +} diff --git a/frontend/src/components/PrepStrip.tsx b/frontend/src/components/PrepStrip.tsx index 4865d0c..19288fe 100644 --- a/frontend/src/components/PrepStrip.tsx +++ b/frontend/src/components/PrepStrip.tsx @@ -118,19 +118,19 @@ export function PrepStrip({ onEditTags, }: Props) { const view = useDeckView() - // Performance-mode settings (Settings ▸ Performance mode). + // Performance-mode settings (Settings ▸ Performance mode…). const perfStems = useAppSetting('perfStems') const keylockDefault = useAppSetting('keylockDefault') const eqKill = useAppSetting('eqKill') - const curve = useAppSetting('crossfaderCurve') + const sharpness = useAppSetting('crossfaderSharpness') 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]) + setMixer({ eqKill, sharpness, fx: { filterResonance, echoBeats, spaceSize, noiseResonance, crushDrive } }) + }, [eqKill, sharpness, 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]) diff --git a/frontend/src/components/SettingsMenu.tsx b/frontend/src/components/SettingsMenu.tsx index 408f504..a419b29 100644 --- a/frontend/src/components/SettingsMenu.tsx +++ b/frontend/src/components/SettingsMenu.tsx @@ -4,6 +4,7 @@ import { api } from '../api' import { AppSettings } from './AppSettings' import { useCaps } from '../lib/capabilities' import { LocalLibrariesSettings } from './LocalLibrariesSettings' +import { PerformanceSettings } from './PerformanceSettings' import { RemoteCacheSettings } from './RemoteCacheSettings' import { ShortcutsDialog } from './ShortcutsDialog' import { StemsSettings } from './StemsSettings' @@ -15,7 +16,7 @@ interface Props { } /** Overflow menu for low-frequency settings: the app's own (Konduktor - * settings), path remapping, Stems and the shortcut list. The dialogs are owned + * settings), path remapping, Stems, Performance mode and the shortcut list. The dialogs are owned * here, since nothing else opens them. */ export function SettingsMenu({ onOpenPathMapping, up = false }: Props) { const [open, setOpen] = useState(false) @@ -24,6 +25,7 @@ export function SettingsMenu({ onOpenPathMapping, up = false }: Props) { const [showCache, setShowCache] = useState(false) const [showApp, setShowApp] = useState(false) const [showLocal, setShowLocal] = useState(false) + const [showPerformance, setShowPerformance] = useState(false) const ref = useRef(null) // Path remapping is a library on THIS computer's business; a remote's // mapping is its server's configuration. @@ -145,6 +147,16 @@ export function SettingsMenu({ onOpenPathMapping, up = false }: Props) { Stems… The stem engine, device and conversion defaults +
) } diff --git a/frontend/src/components/mixer/CrossfaderCurve.tsx b/frontend/src/components/mixer/CrossfaderCurve.tsx new file mode 100644 index 0000000..0c8f987 --- /dev/null +++ b/frontend/src/components/mixer/CrossfaderCurve.tsx @@ -0,0 +1,42 @@ +import { xfadeGains } from '../../lib/audio/mixerMath' +import { useMixer } from '../../lib/audio/mixerState' + +const W = 200 +const H = 72 +const PAD = 6 +const STEPS = 120 + +/** The crossfader's two gain curves at `sharpness`: A falling left to right, + * B rising, over the whole travel, with where the crossfader is now. */ +export function CrossfaderCurveGraph({ sharpness }: { sharpness: number }) { + const position = useMixer((m) => m.crossfader) + const x = (t: number) => PAD + t * (W - 2 * PAD) + const y = (g: number) => H - PAD - g * (H - 2 * PAD) + const line = (ch: 0 | 1) => + Array.from({ length: STEPS + 1 }, (_, i) => { + const t = i / STEPS + const g = xfadeGains(t * 2 - 1, sharpness)[ch] + return `${i ? 'L' : 'M'}${x(t).toFixed(1)} ${y(g).toFixed(1)}` + }).join(' ') + const at = (position + 1) / 2 + return ( + + {/* full level, the -3 dB line, the centre */} + + + + + + + A + B + + ) +} diff --git a/frontend/src/components/mixer/MixerPanel.tsx b/frontend/src/components/mixer/MixerPanel.tsx index d359e78..4fcde03 100644 --- a/frontend/src/components/mixer/MixerPanel.tsx +++ b/frontend/src/components/mixer/MixerPanel.tsx @@ -49,8 +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 (its one parameter is an app setting, under - * Performance mode in Settings), a fader and its meter; between + * effect with its own selector (its one parameter is an app setting, in + * Settings ▸ Performance mode…), 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`. */ @@ -91,7 +91,7 @@ export function MixerPanel({ autoGain }: { autoGain: Record s.crossfader) - const curve = useMixer((s) => s.curve) + const sharpness = useMixer((s) => s.sharpness) return (
@@ -121,7 +121,7 @@ export function MixerPanel({ autoGain }: { autoGain: Record setMixer({ crossfader: Math.abs(v) < 0.03 ? 0 : v })} label="Crossfader" describe={(v) => - `Crossfader (${curve === 'smooth' ? 'smooth' : 'sharp'} curve) — ${ + `Crossfader (curve ${Math.round(sharpness * 100)}% sharp — Settings ▸ Performance mode…) — ${ Math.abs(v) < 0.03 ? 'centre' : v < 0 ? `toward A ${Math.round(-v * 100)}%` : `toward B ${Math.round(v * 100)}%` }` } diff --git a/frontend/src/lib/audio/mixer.ts b/frontend/src/lib/audio/mixer.ts index c275937..61c83ca 100644 --- a/frontend/src/lib/audio/mixer.ts +++ b/frontend/src/lib/audio/mixer.ts @@ -395,7 +395,7 @@ export class Mixer { private apply(): void { const s = getMixerState() - const [ga, gb] = xfadeGains(s.crossfader, s.curve) + const [ga, gb] = xfadeGains(s.crossfader, s.sharpness) this.strips.A.apply(s.A, ga, s.eqKill, s.fx) this.strips.B.apply(s.B, gb, s.eqKill, s.fx) } diff --git a/frontend/src/lib/audio/mixerMath.test.ts b/frontend/src/lib/audio/mixerMath.test.ts index 4fdaf34..1edd23b 100644 --- a/frontend/src/lib/audio/mixerMath.test.ts +++ b/frontend/src/lib/audio/mixerMath.test.ts @@ -25,19 +25,35 @@ describe('eqGain', () => { }) describe('xfadeGains', () => { - it('smooth: constant power, -3 dB each at the centre', () => { + it('sharpness 0: constant power, -3 dB each at the centre', () => { for (const x of [-1, -0.4, 0, 0.3, 1]) { - const [a, b] = xfadeGains(x, 'smooth') + const [a, b] = xfadeGains(x, 0) expect(a * a + b * b).toBeCloseTo(1, 9) } - expect(gainToDb(xfadeGains(0, 'smooth')[0])).toBeCloseTo(-3.01, 2) - expect(xfadeGains(-1, 'smooth')).toEqual([1, expect.closeTo(0, 9)]) + expect(gainToDb(xfadeGains(0, 0)[0])).toBeCloseTo(-3.01, 2) + expect(xfadeGains(-1, 0)).toEqual([1, expect.closeTo(0, 9)]) }) - it('sharp: both full until the last tenth', () => { - expect(xfadeGains(0, 'sharp')).toEqual([1, 1]) - expect(xfadeGains(0.9, 'sharp')).toEqual([1, 1]) - expect(xfadeGains(1, 'sharp')).toEqual([0, 1]) - expect(xfadeGains(-0.95, 'sharp')[1]).toBeCloseTo(0.5, 9) + it('sharpness 1: both full until the last 4%, then a cut', () => { + expect(xfadeGains(0, 1)).toEqual([1, 1]) + expect(xfadeGains(0.9, 1)).toEqual([1, 1]) + expect(xfadeGains(1, 1)).toEqual([expect.closeTo(0, 9), 1]) + expect(xfadeGains(-0.96, 1)[1]).toBeCloseTo(Math.SQRT1_2, 9) // halfway through its fade + }) + it('in between: the centre rises from -3 dB to full, and every curve falls monotonically', () => { + let centre = 0 + for (let s = 0; s <= 1; s += 0.1) { + const c = xfadeGains(0, s)[0] + expect(c).toBeGreaterThanOrEqual(centre - 1e-12) + centre = c + let prev = Infinity + for (let x = -1; x <= 1; x += 0.05) { + const [a, b] = xfadeGains(x, s) + expect(a).toBeLessThanOrEqual(prev + 1e-12) + expect(b).toBeCloseTo(xfadeGains(-x, s)[0], 9) // mirror images + prev = a + } + } + expect(xfadeGains(0, 0.6)[0]).toBe(1) // past ~0.52 the fades no longer reach the middle: no dip }) }) diff --git a/frontend/src/lib/audio/mixerMath.ts b/frontend/src/lib/audio/mixerMath.ts index f71d0c9..451dbb3 100644 --- a/frontend/src/lib/audio/mixerMath.ts +++ b/frontend/src/lib/audio/mixerMath.ts @@ -33,20 +33,26 @@ export const TRIM_RANGE_DB = 12 /** A channel fader (0..1) as a gain: an audio taper, -6 dB at ~0.7. */ export const faderGain = (f: number): number => clamp(f, 0, 1) ** 2 -export type CrossfaderCurve = 'smooth' | 'sharp' +/** The narrowest fade a fully sharp crossfader leaves (of its whole travel). */ +export const XF_MIN_WIDTH = 0.04 + +/** How much of the travel a channel takes to fade out, at `sharpness` 0..1. */ +export const xfadeWidth = (sharpness: number): number => 1 - clamp(sharpness, 0, 1) * (1 - XF_MIN_WIDTH) /** - * The crossfader (-1 = all A, 1 = all B) as the two channels' gains. Smooth is - * constant-power: both at -3 dB in the middle, for blends. Sharp keeps both at - * full until the last tenth of the travel, for cuts and scratching. + * The crossfader (-1 = all A, 1 = all B) as the two channels' gains, at a + * SHARPNESS from 0 to 1 (decided 2026-11-03: fully adjustable). Each channel + * fades on a quarter-cosine over the last `xfadeWidth` of the travel toward the + * other side and is at full level before it. At 0 that is the whole travel — + * constant power, both at -3 dB in the middle, for blends; turned up, both stay + * full across a widening middle (no dip), until at 1 a channel cuts over the + * last 4%, for cuts and scratching. */ -export function xfadeGains(x: number, curve: CrossfaderCurve): [number, number] { - x = clamp(x, -1, 1) - if (curve === 'smooth') { - const t = ((x + 1) / 2) * (Math.PI / 2) - return [Math.cos(t), Math.sin(t)] - } - return [x <= 0.9 ? 1 : (1 - x) / 0.1, x >= -0.9 ? 1 : (1 + x) / 0.1] +export function xfadeGains(x: number, sharpness: number): [number, number] { + const t = (clamp(x, -1, 1) + 1) / 2 // 0 = all A + const w = xfadeWidth(sharpness) + const fade = (u: number) => Math.cos((Math.PI / 2) * clamp((u - (1 - w)) / w, 0, 1)) + return [fade(t), fade(1 - t)] } /** The colour knob's dead centre: inside it, the effect is out of the path. */ diff --git a/frontend/src/lib/audio/mixerState.ts b/frontend/src/lib/audio/mixerState.ts index f5fee47..e93cc2f 100644 --- a/frontend/src/lib/audio/mixerState.ts +++ b/frontend/src/lib/audio/mixerState.ts @@ -5,7 +5,6 @@ // mixer starts flat. import { useSyncExternalStore } from 'react' -import type { CrossfaderCurve } from './mixerMath' export type Channel = 'A' | 'B' export const CHANNELS: Channel[] = ['A', 'B'] @@ -63,7 +62,8 @@ export interface MixerState { B: ChannelState /** -1 = all A, 1 = all B. */ crossfader: number - curve: CrossfaderCurve + /** The crossfader curve, 0 (smooth) .. 1 (sharp): `mixerMath.xfadeGains`. */ + sharpness: number /** EQ cuts to silence at full left (else to -26 dB). */ eqKill: boolean fx: FxSettings @@ -83,7 +83,7 @@ let state: MixerState = { A: DEFAULT_CHANNEL, B: DEFAULT_CHANNEL, crossfader: 0, - curve: 'smooth', + sharpness: 0, eqKill: false, fx: DEFAULT_FX, } @@ -107,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 }) }