CsoundUnity 4.0.0-alpha.3
Loading...
Searching...
No Matches
Csound.Unity.Utilities.RemapUtils Class Reference

Utility class for remapping numeric values between ranges, with optional clamping and exponential skewing. More...

Public Types

enum  SkewMode { Cabbage , Normalized }
 Controls how the skew factor is interpreted when remapping values. More...

Static Public Member Functions

static float Remap (float value, float from1, float to1, float from2, float to2, bool clamp=false, float skew=1f, SkewMode mode=SkewMode.Cabbage)
 Remaps a float value from one range to another with optional clamping and skewing. There are two possible modes for skewing: Cabbage and Normalized.
static float RemapTo0to1 (float value, float from, float to, float skew=1f)
 Remaps a value from the given range to a normalised 0–1 value, with an optional power-curve skew. A skew of 1 gives a linear mapping; values below 1 compress the lower end (exponential feel).
static float RemapFrom0to1 (float value, float from, float to, float skew=1f)
 Remaps a normalised 0–1 value to the given output range, with an optional power-curve skew. A skew of 1 gives a linear mapping; values below 1 compress the lower end (exponential feel).

Detailed Description

Utility class for remapping numeric values between ranges, with optional clamping and exponential skewing.

Member Enumeration Documentation

◆ SkewMode

Controls how the skew factor is interpreted when remapping values.

Enumerator
Cabbage 

Skew factor has no upper bound. Values below 1 produce exponential mapping, 1 produces linear mapping, and values above 1 produce logarithmic mapping.

Normalized 

Skew factor is normalised to the 0–1 range. Values below 0.5 produce exponential mapping, 0.5 produces linear mapping, and values above 0.5 produce logarithmic mapping.

Member Function Documentation

◆ Remap()

float Csound.Unity.Utilities.RemapUtils.Remap ( float value,
float from1,
float to1,
float from2,
float to2,
bool clamp = false,
float skew = 1f,
SkewMode mode = SkewMode::Cabbage )
inlinestatic

Remaps a float value from one range to another with optional clamping and skewing. There are two possible modes for skewing: Cabbage and Normalized.

In Cabbage mode, the skew factor has no upper limit and the mapping behaves as follows:

  • Exponential mapping for values above 0 to 1
  • Linear mapping at 1
  • Logarithmic mapping for values above 1

In Normalized mode, the skew factor is bound between 0 and 1, and the mapping behaves as follows:

  • Exponential mapping from values above 0 to 0.5
  • Linear mapping at 0.5
  • Logarithmic mapping for values above 0.5 to 1

Both modes return the lower target bound (from2) when the skew is 0 or below. The Normalized mode returns the upper target bound (to2) when the skew is 1 or above.

Parameters
valueThe input value to be remapped.
from1The lower bound of the source range.
to1The upper bound of the source range.
from2The lower bound of the target range.
to2The upper bound of the target range.
clampDetermines whether the mapped value should be clamped within the target range. Default is false.
skewA skew factor that controls the mapping behavior. Default is 1
modeThe mode for skewing the mapping behavior. Default is Cabbage
Returns
The remapped value within the target range.

◆ RemapFrom0to1()

float Csound.Unity.Utilities.RemapUtils.RemapFrom0to1 ( float value,
float from,
float to,
float skew = 1f )
inlinestatic

Remaps a normalised 0–1 value to the given output range, with an optional power-curve skew. A skew of 1 gives a linear mapping; values below 1 compress the lower end (exponential feel).

Parameters
valueThe normalised input value (0–1). Values outside this range are clamped.
fromThe lower bound of the output range.
toThe upper bound of the output range.
skewPower-curve exponent applied before scaling. Defaults to 1 (linear).
Returns
A float in the range [from , to ] corresponding to the remapped input.

◆ RemapTo0to1()

float Csound.Unity.Utilities.RemapUtils.RemapTo0to1 ( float value,
float from,
float to,
float skew = 1f )
inlinestatic

Remaps a value from the given range to a normalised 0–1 value, with an optional power-curve skew. A skew of 1 gives a linear mapping; values below 1 compress the lower end (exponential feel).

Parameters
valueThe input value to remap.
fromThe lower bound of the input range.
toThe upper bound of the input range.
skewPower-curve exponent applied after normalisation. Defaults to 1 (linear).
Returns
A 0–1 float representing the remapped position of value within [from , to ].

The documentation for this class was generated from the following file: