32 jassert (value >= 0 && value <= 127);
34 auto valueAs14Bit = value <= 64 ? value << 7
35 : int (jmap<float> (
float (value - 64), 0.0f, 63.0f, 0.0f, 8191.0f)) + 8192;
37 return { valueAs14Bit };
42 jassert (value >= 0 && value <= 16383);
48 jassert (0.0f <= value && value <= 1.0f);
49 return { roundToInt (value * 16383.0f) };
54 jassert (-1.0f <= value && value <= 1.0f);
55 return { roundToInt (((value + 1.0f) * 16383.0f) / 2.0f) };
65 return normalisedValue >> 7;
70 return normalisedValue;
76 return (normalisedValue < 8192)
77 ? jmap<float> (
float (normalisedValue), 0.0f, 8192.0f, -1.0f, 0.0f)
78 : jmap<float> (
float (normalisedValue), 8192.0f, 16383.0f, 0.0f, 1.0f);
83 return jmap<float> (
float (normalisedValue), 0.0f, 16383.0f, 0.0f, 1.0f);
89 return normalisedValue == other.normalisedValue;
94 return ! operator== (other);
102class MPEValueTests final :
public UnitTest
106 :
UnitTest (
"MPEValue class", UnitTestCategories::midi)
109 void runTest()
override
111 beginTest (
"comparison operator");
117 expect (value1 == value1);
118 expect (value1 == value2);
119 expect (value1 != value3);
122 beginTest (
"special values");
134 beginTest (
"zero/minimum value");
142 beginTest (
"maximum value");
150 beginTest (
"centre value");
158 beginTest (
"value halfway between min and centre");
169 void expectValuesConsistent (MPEValue value,
170 int expectedValueAs7BitInt,
171 int expectedValueAs14BitInt,
172 float expectedValueAsSignedFloat,
173 float expectedValueAsUnsignedFloat)
175 expectEquals (value.as7BitInt(), expectedValueAs7BitInt);
176 expectEquals (value.as14BitInt(), expectedValueAs14BitInt);
177 expectFloatWithinRelativeError (value.asSignedFloat(), expectedValueAsSignedFloat, 0.0001f);
178 expectFloatWithinRelativeError (value.asUnsignedFloat(), expectedValueAsUnsignedFloat, 0.0001f);
182 void expectFloatWithinRelativeError (
float actualValue,
float expectedValue,
float maxRelativeError)
184 const float maxAbsoluteError = jmax (1.0f, std::abs (expectedValue)) * maxRelativeError;
185 expect (std::abs (expectedValue - actualValue) < maxAbsoluteError);
189static MPEValueTests MPEValueUnitTests;
float asSignedFloat() const noexcept
static MPEValue maxValue() noexcept
static MPEValue centreValue() noexcept
static MPEValue from14BitInt(int value) noexcept
bool operator==(const MPEValue &other) const noexcept
static MPEValue fromUnsignedFloat(float value) noexcept
static MPEValue fromSignedFloat(float value) noexcept
static MPEValue minValue() noexcept
float asUnsignedFloat() const noexcept
int as7BitInt() const noexcept
int as14BitInt() const noexcept
static MPEValue from7BitInt(int value) noexcept
bool operator!=(const MPEValue &other) const noexcept