XYPad
Edit two values with one drag.
Use XYPad when two parameters belong together, such as a filter's cutoff and resonance. A drag edits both, and the arrow keys edit one axis at a time. Each axis takes the numeric control props.
import { XYPad } from '@soundor/components';
import { useState } from 'react';
export default function Demo() {
const [x, setX] = useState(0.5);
const [y, setY] = useState(0.3);
return (
<XYPad
title="Filter"
x={{ label: 'Cutoff', value: x, onChange: setX }}
y={{ label: 'Resonance', value: y, onChange: setY }}
width={220}
height={150}
/>
);
}xy-pad.tsx, running in the web runtime.SourceUsage
With a parameter
Give each axis a generated parameter and the pad inherits its range, mapping, formatting, parser and reset value. It opens and closes host gestures and records undo history; set history={false} to opt out, or history={{ label: 'Adjust feedback' }} to name the entry.
<XYPad
title="Filter"
x={{ parameter: parameters.cutoff }}
y={{ parameter: parameters.resonance }}
/>Without a parameter
Give each axis its own value and onChange with the range you need. A controlled control should update value in response to onChange.
<XYPad
title="Filter"
x={{
label: 'Cutoff',
min: 20,
max: 20000,
scale: 'log',
value: cutoff,
onChange: setCutoff,
}}
y={{ label: 'Resonance', value: resonance, onChange: setResonance }}
/>Examples
Drive a response curve
Put the pad's values in state and draw them: the pad edits cutoff and resonance, and a Plot beside it shows the filter they describe. The cutoff axis is scale: 'log', so equal drags cover equal musical distances.
import { Plot, XYPad, formatters } from '@soundor/components';
import { View } from '@soundor/react';
import { useState } from 'react';
const frequencies = Array.from({ length: 96 }, (_, i) => 20 * 1000 ** (i / 95));
// A resonant low-pass, as magnitude in dB.
function lowPass(hz: number, cutoff: number, resonance: number) {
const r = hz / cutoff;
const q = 0.5 + resonance * 9.5;
const magnitude = 1 / Math.sqrt((1 - r * r) ** 2 + (r / q) ** 2);
return 20 * Math.log10(magnitude);
}
export default function Demo() {
const [cutoff, setCutoff] = useState(1200);
const [resonance, setResonance] = useState(0.35);
return (
<View style={{ flexDirection: 'row', gap: 12, alignItems: 'center' }}>
<XYPad
title="Filter"
x={{
label: 'Cutoff',
min: 20,
max: 20_000,
scale: 'log',
value: cutoff,
onChange: setCutoff,
format: formatters.frequency,
}}
y={{
label: 'Resonance',
value: resonance,
onChange: setResonance,
format: formatters.percent,
}}
width={170}
height={170}
/>
<Plot width={260} height={170}>
<Plot.XAxis
domain={[20, 20_000]}
scale="log"
ticks={[100, 1000, 10_000]}
format={formatters.frequency}
/>
<Plot.YAxis
domain={[-24, 24]}
ticks={[-24, 0, 24]}
format={formatters.decibels}
/>
<Plot.Grid />
<Plot.Area
label="Filter"
baseline={-24}
points={frequencies.map((hz) => [hz, lowPass(hz, cutoff, resonance)])}
/>
</Plot>
</View>
);
}xy-pad-filter.tsx, running in the web runtime.SourceKeyboard and accessibility
The pad is one tab stop. ← → change X, ↓ ↑ change Y, and Shift makes the step ten times finer. A press on the handle grabs it where it is, and a press elsewhere jumps it to the pointer. A double-click on the handle or an Alt-click (Option-click on a Mac) anywhere resets both axes, as do Delete and Backspace; a double-click elsewhere jumps, and resets nothing. A screen reader hears both values together, such as "Cutoff 1.20 kHz, Resonance 35%", and gets actions to increase and decrease each axis. Give the axes labels so they read well. See Keyboard and accessibility.
Props
XYPad props
Prop
Type
Range props
Prop
Type