42 template <
typename ValueType>
54 :
start (other.start),
end (other.end),
57 convertFrom0To1Function (std::move (other.convertFrom0To1Function)),
58 convertTo0To1Function (std::move (other.convertTo0To1Function)),
59 snapToLegalValueFunction (std::move (other.snapToLegalValueFunction))
71 convertFrom0To1Function = std::move (other.convertFrom0To1Function);
72 convertTo0To1Function = std::move (other.convertTo0To1Function);
73 snapToLegalValueFunction = std::move (other.snapToLegalValueFunction);
81 ValueType intervalValue,
83 bool useSymmetricSkew =
false) noexcept
92 ValueType rangeEnd) noexcept
101 ValueType intervalValue) noexcept
132 std::function<ValueType (ValueType currentRangeStart, ValueType currentRangeEnd, ValueType normalisedValue)> convertFrom0To1Func,
133 std::function<ValueType (ValueType currentRangeStart, ValueType currentRangeEnd, ValueType mappedValue)> convertTo0To1Func,
134 std::function<ValueType (ValueType currentRangeStart, ValueType currentRangeEnd, ValueType valueToSnap)> snapToLegalValueFunc =
nullptr) noexcept
135 :
start (rangeStart),
137 convertFrom0To1Function (convertFrom0To1Func),
138 convertTo0To1Function (convertTo0To1Func),
139 snapToLegalValueFunction (snapToLegalValueFunc)
149 if (convertTo0To1Function !=
nullptr)
150 return clampTo0To1 (convertTo0To1Function (
start,
end, v));
154 if (
skew == static_cast<ValueType> (1))
158 return std::pow (proportion,
skew);
160 auto distanceFromMiddle =
static_cast<ValueType
> (2) * proportion - static_cast<ValueType> (1);
162 return (static_cast<ValueType> (1) + std::pow (std::abs (distanceFromMiddle),
skew)
163 * (distanceFromMiddle < ValueType() ? static_cast<ValueType> (-1)
164 : static_cast<ValueType> (1)))
165 /
static_cast<ValueType
> (2);
173 proportion = clampTo0To1 (proportion);
175 if (convertFrom0To1Function !=
nullptr)
176 return convertFrom0To1Function (
start,
end, proportion);
180 if (
skew != static_cast<ValueType> (1) && proportion > ValueType())
181 proportion = std::exp (std::log (proportion) /
skew);
186 auto distanceFromMiddle =
static_cast<ValueType
> (2) * proportion - static_cast<ValueType> (1);
188 if (
skew != static_cast<ValueType> (1) && distanceFromMiddle !=
static_cast<ValueType
> (0))
189 distanceFromMiddle = std::exp (std::log (std::abs (distanceFromMiddle)) /
skew)
190 * (distanceFromMiddle < ValueType() ? static_cast<ValueType> (-1)
191 : static_cast<ValueType> (1));
193 return start + (
end -
start) / static_cast<ValueType> (2) * (
static_cast<ValueType
> (1) + distanceFromMiddle);
201 if (snapToLegalValueFunction !=
nullptr)
202 return snapToLegalValueFunction (
start,
end, v);
223 jassert (centrePointValue >
start);
224 jassert (centrePointValue <
end);
227 skew = std::log (static_cast<ValueType> (0.5)) / std::log ((centrePointValue -
start) / (
end -
start));
263 void checkInvariants()
const 265 jassert (end > start);
266 jassert (interval >= ValueType());
267 jassert (skew > ValueType());
270 static ValueType clampTo0To1 (ValueType value)
272 auto clampedValue = jlimit (static_cast<ValueType> (0), static_cast<ValueType> (1), value);
276 jassert (clampedValue == value);
281 using ConversionFunction = std::function<ValueType(ValueType, ValueType, ValueType)>;
283 ConversionFunction convertFrom0To1Function = {},
284 convertTo0To1Function = {},
285 snapToLegalValueFunction = {};
Range< ValueType > getRange() const noexcept
Returns the extent of the normalisable range.
void setSkewForCentre(ValueType centrePointValue) noexcept
Given a value which is between the start and end points, this sets the skew such that convertFrom0to1...
NormalisableRange(Range< ValueType > range) noexcept
Creates a NormalisableRange with a given range, continuous interval, but a dummy skew-factor.
ValueType start
The minimum value of the non-normalised range.
NormalisableRange(ValueType rangeStart, ValueType rangeEnd, ValueType intervalValue) noexcept
Creates a NormalisableRange with a given range and interval, but a dummy skew-factor.
ValueType convertTo0to1(ValueType v) const noexcept
Uses the properties of this mapping to convert a non-normalised value to its 0->1 representation...
ValueType skew
An optional skew factor that alters the way values are distribute across the range.
bool symmetricSkew
If true, the skew factor applies from the middle of the slider to each of its ends.
ValueType snapToLegalValue(ValueType v) const noexcept
Takes a non-normalised value and snaps it based on either the interval property of this NormalisedRan...
Represents a mapping between an arbitrary range of values and a normalised 0->1 range.
NormalisableRange(ValueType rangeStart, ValueType rangeEnd, std::function< ValueType(ValueType currentRangeStart, ValueType currentRangeEnd, ValueType normalisedValue)> convertFrom0To1Func, std::function< ValueType(ValueType currentRangeStart, ValueType currentRangeEnd, ValueType mappedValue)> convertTo0To1Func, std::function< ValueType(ValueType currentRangeStart, ValueType currentRangeEnd, ValueType valueToSnap)> snapToLegalValueFunc=nullptr) noexcept
Creates a NormalisableRange with a given range and an injective mapping function. ...
NormalisableRange(Range< ValueType > range, ValueType intervalValue) noexcept
Creates a NormalisableRange with a given range and interval, but a dummy skew-factor.
ValueType convertFrom0to1(ValueType proportion) const noexcept
Uses the properties of this mapping to convert a normalised 0->1 value to its full-range representati...
NormalisableRange(ValueType rangeStart, ValueType rangeEnd) noexcept
Creates a NormalisableRange with a given range, continuous interval, but a dummy skew-factor.
ValueType interval
The snapping interval that should be used (for a non-normalised value).
NormalisableRange(ValueType rangeStart, ValueType rangeEnd, ValueType intervalValue, ValueType skewFactor, bool useSymmetricSkew=false) noexcept
Creates a NormalisableRange with a given range, interval and skew factor.
ValueType end
The maximum value of the non-normalised range.
NormalisableRange()=default
Creates a continuous range that performs a dummy mapping.
A general-purpose range object, that simply represents any linear range with a start and end point...