mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
MidiMessage: Added VariableLengthValue::isValid() and removed assertion from MidiMessage::readVariableLengthValue()
This commit is contained in:
parent
66311c798f
commit
2fb3637e25
3 changed files with 7 additions and 4 deletions
|
|
@ -231,7 +231,7 @@ namespace MidiFileHelpers
|
||||||
{
|
{
|
||||||
const auto delay = MidiMessage::readVariableLengthValue (data, (int) size);
|
const auto delay = MidiMessage::readVariableLengthValue (data, (int) size);
|
||||||
|
|
||||||
if (delay.bytesUsed == 0)
|
if (! delay.isValid())
|
||||||
break;
|
break;
|
||||||
|
|
||||||
data += delay.bytesUsed;
|
data += delay.bytesUsed;
|
||||||
|
|
|
||||||
|
|
@ -79,7 +79,6 @@ MidiMessage::VariableLengthValue MidiMessage::readVariableLengthValue (const uin
|
||||||
// bytes of input to construct a full value, or no terminating byte was
|
// bytes of input to construct a full value, or no terminating byte was
|
||||||
// found. This implementation only supports variable-length values of up
|
// found. This implementation only supports variable-length values of up
|
||||||
// to four bytes.
|
// to four bytes.
|
||||||
jassertfalse;
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1225,6 +1224,7 @@ struct MidiMessageTest : public UnitTest
|
||||||
const auto result = MidiMessage::readVariableLengthValue (copy.data(),
|
const auto result = MidiMessage::readVariableLengthValue (copy.data(),
|
||||||
(int) copy.size());
|
(int) copy.size());
|
||||||
|
|
||||||
|
expect (result.isValid());
|
||||||
expectEquals (result.value, outputs[index]);
|
expectEquals (result.value, outputs[index]);
|
||||||
expectEquals (result.bytesUsed, (int) inputs[index].size());
|
expectEquals (result.bytesUsed, (int) inputs[index].size());
|
||||||
|
|
||||||
|
|
@ -1252,6 +1252,7 @@ struct MidiMessageTest : public UnitTest
|
||||||
const auto result = MidiMessage::readVariableLengthValue (input.data(),
|
const auto result = MidiMessage::readVariableLengthValue (input.data(),
|
||||||
(int) input.size());
|
(int) input.size());
|
||||||
|
|
||||||
|
expect (! result.isValid());
|
||||||
expectEquals (result.value, 0);
|
expectEquals (result.value, 0);
|
||||||
expectEquals (result.bytesUsed, 0);
|
expectEquals (result.bytesUsed, 0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -872,7 +872,6 @@ public:
|
||||||
from a stream of bytes.
|
from a stream of bytes.
|
||||||
|
|
||||||
A valid value requires that `bytesUsed` is greater than 0.
|
A valid value requires that `bytesUsed` is greater than 0.
|
||||||
If `bytesUsed <= 0` this object should be considered invalid.
|
|
||||||
*/
|
*/
|
||||||
struct VariableLengthValue
|
struct VariableLengthValue
|
||||||
{
|
{
|
||||||
|
|
@ -881,6 +880,8 @@ public:
|
||||||
VariableLengthValue (int valueIn, int bytesUsedIn)
|
VariableLengthValue (int valueIn, int bytesUsedIn)
|
||||||
: value (valueIn), bytesUsed (bytesUsedIn) {}
|
: value (valueIn), bytesUsed (bytesUsedIn) {}
|
||||||
|
|
||||||
|
bool isValid() const noexcept { return bytesUsed > 0; }
|
||||||
|
|
||||||
int value = 0;
|
int value = 0;
|
||||||
int bytesUsed = 0;
|
int bytesUsed = 0;
|
||||||
};
|
};
|
||||||
|
|
@ -891,7 +892,8 @@ public:
|
||||||
@param maxBytesToUse the number of bytes in the region following `data`
|
@param maxBytesToUse the number of bytes in the region following `data`
|
||||||
@returns a struct containing the parsed value, and the number
|
@returns a struct containing the parsed value, and the number
|
||||||
of bytes that were read. If parsing fails, both the
|
of bytes that were read. If parsing fails, both the
|
||||||
`value` and `bytesUsed` fields will be set to 0.
|
`value` and `bytesUsed` fields will be set to 0 and
|
||||||
|
`isValid()` will return false
|
||||||
*/
|
*/
|
||||||
static VariableLengthValue readVariableLengthValue (const uint8* data,
|
static VariableLengthValue readVariableLengthValue (const uint8* data,
|
||||||
int maxBytesToUse) noexcept;
|
int maxBytesToUse) noexcept;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue