scales
Interfaces
Scale
Defined in: scales.ts:23
How a value is distributed across the travel of a control.
normalize and denormalize are inverses of each other: the position is
0 at min and 1 at max, and everything in between is up to the scale.
min and max are arguments rather than baked into the scale, so a scale
holds no state and can be a module level constant. Passing the same object
on every render therefore costs nothing.
Example
exponentialScale.denormalize(0.5, 20, 20000) // 632.45…
Properties
denormalize
denormalize: (position, min, max) => number;
Defined in: scales.ts:27
Position on the travel, 0-1, back to a value.
Parameters
| Parameter | Type |
|---|---|
position | number |
min | number |
max | number |
Returns
number
normalize
normalize: (value, min, max) => number;
Defined in: scales.ts:25
Value to its position on the travel, 0-1.
Parameters
| Parameter | Type |
|---|---|
value | number |
min | number |
max | number |
Returns
number
ValueRange
Defined in: scales.ts:246
How a value is scaled: the range it lives in, how it is rounded, and how it is distributed across the travel.
AxisOptions of @tremolo-ui/dom extends this, so a drag and a
wheel / keyboard nudge run the same value pipeline.
Properties
max
max: number;
Defined in: scales.ts:248
min
min: number;
Defined in: scales.ts:247
scale?
optional scale?: Scale;
Defined in: scales.ts:258
How the value is distributed across the travel.
Default
linearScale
step?
optional step?: number;
Defined in: scales.ts:252
Rounding applied to the value. Left unrounded when omitted.
Variables
exponentialScale
const exponentialScale: Scale;
Defined in: scales.ts:103
Equal travel gives an equal ratio, so an octave — or a percentage — takes the same distance wherever it falls.
The scale for frequency (a filter cutoff over 20-20000 Hz), free running rates, and delay times.
Requires min and max to be non-zero and of the same sign, since no
ratio reaches zero or crosses it. Use curveScale for a range that
starts at 0.
linearScale
const linearScale: Scale;
Defined in: scales.ts:40
Equal travel gives an equal change in value.
The right default for anything already linear in perception: dB values, pan, percentages, MIDI note numbers, semitones.
Functions
applyDelta()
function applyDelta(
value,
direction,
options,
__namedParameters,
modifiers?
): number;
Defined in: scales.ts:282
Move a value by an amount of input, as reported by a wheel or an arrow key.
The pipeline matches createDragValue of @tremolo-ui/dom: scale, then
step, then clamp. Which key or which sign of deltaY counts as which
direction is left to the caller, since it differs per component.
Parameters
| Parameter | Type | Description |
|---|---|---|
value | number | - |
direction | number | which way, and how many times, to apply the option. The size of one step is option[1], so this is normally 1 or -1. |
options | InputEventOptions | - |
__namedParameters | ValueRange | - |
modifiers? | ModifierState | the event, for options that name a modifier key. See selectInputEvent. |
Returns
number
Examples
// ArrowDown on a slider whose keyboard option is ['raw', 1]
applyDelta(value, -1, keyboard, { min, max, step, scale })
// Shift+ArrowDown, where `keyboard` is { default: …, shift: ['raw', 0.1] }
applyDelta(value, -1, keyboard, range, event)
curveScale()
function curveScale(curve): Scale;
Defined in: scales.ts:151
An exponential bend that still passes exactly through min and max, so
unlike exponentialScale it works on a range that starts at 0 or
crosses it, and unlike skewScale its slope is neither zero nor
infinite at either end.
The general purpose taper, and the same family as the curve of an envelope
segment (SuperCollider's CurveWarp).
curve > 0gives the lower end more travel — envelope times from 0 ms, delay times, anything that wants fine control near the bottomcurve < 0gives the upper end more travel — a volume fader over -60..+6 dB that should be precise around 0 dB- near 0 it is indistinguishable from linearScale, and is treated as linear to avoid dividing by zero
curveWithCenterValue gives the curve that places a chosen value at the middle of the travel.
Parameters
| Parameter | Type | Description |
|---|---|---|
curve | number | how hard the curve bends, and in which direction |
Returns
curveWithCenterValue()
function curveWithCenterValue(
centerValue,
min,
max
): number;
Defined in: scales.ts:225
The curve for curveScale that puts centerValue at the middle of
the travel — the counterpart of skewWithCenterValue.
Parameters
| Parameter | Type |
|---|---|
centerValue | number |
min | number |
max | number |
Returns
number
skewScale()
function skewScale(skew): Scale;
Defined in: scales.ts:61
The power law of JUCE's NormalisableRange::skew, applied to value - min.
Use it when the value has to agree with a JUCE or iPlug2 parameter — a plugin UI in a WebView, say, where the knob must sit exactly where the host's automation curve puts it. skewWithCenterValue gives the factor that places a chosen value at the middle of the travel.
skew < 1 gives the lower end more travel, skew > 1 the upper end.
For new designs prefer exponentialScale or curveScale: the
slope of this curve is either zero or infinite at min, so the bottom of
the range is a dead zone or jumps.
Parameters
| Parameter | Type | Description |
|---|---|---|
skew | number | the JUCE skew factor |
Returns
skewWithCenterValue()
function skewWithCenterValue(
centerValue,
min,
max
): number;
Defined in: scales.ts:82
The skew factor for skewScale that puts centerValue at the middle
of the travel — JUCE's NormalisableRange::setSkewForCentre.
Parameters
| Parameter | Type |
|---|---|
centerValue | number |
min | number |
max | number |
Returns
number
symmetricSkewScale()
function symmetricSkewScale(skew): Scale;
Defined in: scales.ts:193
skewScale mirrored about the middle of the range, so both halves
bend the same way — JUCE's symmetricSkew.
For a bipolar control whose centre matters: detune over -100..+100 cents, or a bipolar filter envelope amount, where the fine adjustment is around 0 rather than at either end.
skew < 1 gives the middle more travel, skew > 1 the two ends.
Parameters
| Parameter | Type | Description |
|---|---|---|
skew | number | the JUCE skew factor |