Implemented performance mode settings

This commit is contained in:
patben8 committed 2026-11-03 08:49:26 +01:00
1 parent fe91a46bae
commit af02b1fc1c
11 files changed
+290 -85

No files matched your search

+15 -15
View File
@@ -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<ArrayBuffer> {
/**
* 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 {
+2 -5
View File
@@ -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
+4 -8
View File
@@ -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)
}
+26 -11
View File
@@ -19,13 +19,29 @@ export const FX_LABELS: Record<FxType, string> = {
noise: 'Noise',
crush: 'Crush',
}
/** What each effect's parameter knob does. */
export const FX_PARAM: Record<FxType, string> = {
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<ChannelState>): void {
commit({ ...state, [ch]: { ...state[ch], ...patch } })
}
export function setMixer(patch: Partial<Pick<MixerState, 'crossfader' | 'curve' | 'eqKill'>>): void {
export function setMixer(patch: Partial<Pick<MixerState, 'crossfader' | 'curve' | 'eqKill' | 'fx'>>): void {
commit({ ...state, ...patch })
}
+26 -12
View File
@@ -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<Exclude<Layer, 'base'>, string> = IS_MAC
? { shift: '⇧', mod: '⌘' }
: { shift: 'Shift', mod: 'Ctrl' }
? { shift: '⇧', mod: '⌘', alt: '⌥' }
: { shift: 'Shift', mod: 'Ctrl', alt: 'Alt' }
export const LAYER_NAMES: Record<Layer, string> = 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<string, Binding[]>)
// 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<string, KeyDef> = Object.fromEntries(
/** The modifier layer a physical key holds, if it is one. */
export function modifierLayer(code: string): Exclude<Layer, 'base'> | 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
}