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);
53 return normalisedValue >> 7;
58 return normalisedValue;
64 return (normalisedValue < 8192)
65 ? jmap<float> (float (normalisedValue), 0.0f, 8192.0f, -1.0f, 0.0f)
66 : jmap<float> (
float (normalisedValue), 8192.0f, 16383.0f, 0.0f, 1.0f);
71 return jmap<float> (float (normalisedValue), 0.0f, 16383.0f, 0.0f, 1.0f);
77 return normalisedValue == other.normalisedValue;
89 class MPEValueTests :
public UnitTest 92 MPEValueTests() :
UnitTest (
"MPEValue class",
"MIDI/MPE") {}
94 void runTest()
override 96 beginTest (
"comparison operator");
102 expect (value1 == value1);
103 expect (value1 == value2);
104 expect (value1 != value3);
107 beginTest (
"special values");
119 beginTest (
"zero/minimum value");
125 beginTest (
"maximum value");
131 beginTest (
"centre value");
137 beginTest (
"value halfway between min and centre");
146 void expectValuesConsistent (
MPEValue value,
147 int expectedValueAs7BitInt,
148 int expectedValueAs14BitInt,
149 float expectedValueAsSignedFloat,
150 float expectedValueAsUnsignedFloat)
152 expectEquals (value.
as7BitInt(), expectedValueAs7BitInt);
153 expectEquals (value.
as14BitInt(), expectedValueAs14BitInt);
154 expectFloatWithinRelativeError (value.
asSignedFloat(), expectedValueAsSignedFloat, 0.0001f);
155 expectFloatWithinRelativeError (value.
asUnsignedFloat(), expectedValueAsUnsignedFloat, 0.0001f);
159 void expectFloatWithinRelativeError (
float actualValue,
float expectedValue,
float maxRelativeError)
161 const float maxAbsoluteError = jmax (1.0f, std::abs (expectedValue)) * maxRelativeError;
162 expect (std::abs (expectedValue - actualValue) < maxAbsoluteError);
166 static MPEValueTests MPEValueUnitTests;
168 #endif // JUCE_UNIT_TESTS bool operator==(const MPEValue &other) const noexcept
Returns true if two values are equal.
MPEValue() noexcept
Default constructor.
static MPEValue from7BitInt(int value) noexcept
Constructs an MPEValue from an integer between 0 and 127 (using 7-bit precision). ...
float asSignedFloat() const noexcept
Retrieves the current value mapped to a float between -1.0f and 1.0f.
int as14BitInt() const noexcept
Retrieves the current value as an integer between 0 and 16383.
This is a base class for classes that perform a unit test.
int as7BitInt() const noexcept
Retrieves the current value as an integer between 0 and 127.
static MPEValue centreValue() noexcept
Constructs an MPEValue corresponding to the centre value.
static MPEValue maxValue() noexcept
Constructs an MPEValue corresponding to the maximum value.
bool operator!=(const MPEValue &other) const noexcept
Returns true if two values are not equal.
float asUnsignedFloat() const noexcept
Retrieves the current value mapped to a float between 0.0f and 1.0f.
static MPEValue from14BitInt(int value) noexcept
Constructs an MPEValue from an integer between 0 and 16383 (using 14-bit precision).
This class represents a single value for any of the MPE dimensions of control.
static MPEValue minValue() noexcept
Constructs an MPEValue corresponding to the minimum value.