Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MIDI: Ignore SysEx messages #710

Merged
merged 4 commits into from
Oct 23, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update TrackEvent.java
  • Loading branch information
loki666 authored and christosts committed Oct 23, 2023
commit b27b65199ada2db2a77665e64aaef89623e52c51
Original file line number Diff line number Diff line change
Expand Up @@ -115,44 +115,42 @@ public boolean populateFrom(ParsableByteArray parsableTrackEventBytes, int previ
}

statusByte = firstByte;
} else {
if (firstByte == META_EVENT_STATUS) { // This is a Meta event.
int metaEventMessageType = parsableTrackEventBytes.readUnsignedByte();
int eventLength = readVariableLengthInt(parsableTrackEventBytes);

statusByte = firstByte;

switch (metaEventMessageType) {
case META_TEMPO_CHANGE:
usPerQuarterNote = parsableTrackEventBytes.readUnsignedInt24();

if (usPerQuarterNote <= 0) {
throw ParserException.createForUnsupportedContainerFeature(
"Tempo event data value must be a non-zero positive value. Parsed value: "
+ usPerQuarterNote);
}

parsableTrackEventBytes.skipBytes(eventLength - /* tempoDataLength */ 3);
break;
case META_END_OF_TRACK:
parsableTrackEventBytes.setPosition(startingPosition);
reset();
return false;
default: // Ignore all other Meta events.
parsableTrackEventBytes.skipBytes(eventLength);
}
} else if (firstByte == SYSEX_BEGIN_STATUS) {
// TODO(b/228838584): Handle this gracefully.
statusByte = firstByte;

int currentByte;
do { // eat SysEx Message
currentByte = parsableTrackEventBytes.readUnsignedByte();
} while (currentByte != SYSEX_END_STATUS);
} else {
throw ParserException.createForUnsupportedContainerFeature(
"Unknown track events.");
} else if (firstByte == META_EVENT_STATUS) { // This is a Meta event.
int metaEventMessageType = parsableTrackEventBytes.readUnsignedByte();
int eventLength = readVariableLengthInt(parsableTrackEventBytes);

statusByte = firstByte;

switch (metaEventMessageType) {
case META_TEMPO_CHANGE:
usPerQuarterNote = parsableTrackEventBytes.readUnsignedInt24();

if (usPerQuarterNote <= 0) {
throw ParserException.createForUnsupportedContainerFeature(
"Tempo event data value must be a non-zero positive value. Parsed value: "
+ usPerQuarterNote);
}

parsableTrackEventBytes.skipBytes(eventLength - /* tempoDataLength */ 3);
break;
case META_END_OF_TRACK:
parsableTrackEventBytes.setPosition(startingPosition);
reset();
return false;
default: // Ignore all other Meta events.
parsableTrackEventBytes.skipBytes(eventLength);
}
} else if (firstByte == SYSEX_BEGIN_STATUS) {
// TODO(b/228838584): Handle this gracefully.
statusByte = firstByte;

int currentByte;
do { // eat SysEx Message
currentByte = parsableTrackEventBytes.readUnsignedByte();
} while (currentByte != SYSEX_END_STATUS);
} else {
throw ParserException.createForUnsupportedContainerFeature(
"Unknown track event: " + firstByte);
}

eventFileSizeBytes = parsableTrackEventBytes.getPosition() - startingPosition;
Expand Down