Moved performance settings to their own panel

This commit is contained in:
patben8 committed 2026-11-03 09:14:02 +01:00
1 parent af02b1fc1c
commit 341f12e275
11 files changed
+319 -139

No files matched your search

+1 -1
View File
@@ -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)
}
+25 -9
View File
@@ -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
})
})
+17 -11
View File
@@ -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. */
+4 -4
View File
@@ -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<ChannelState>): void {
commit({ ...state, [ch]: { ...state[ch], ...patch } })
}
export function setMixer(patch: Partial<Pick<MixerState, 'crossfader' | 'curve' | 'eqKill' | 'fx'>>): void {
export function setMixer(patch: Partial<Pick<MixerState, 'crossfader' | 'sharpness' | 'eqKill' | 'fx'>>): void {
commit({ ...state, ...patch })
}