Skip to content

Commit 3966d5b

Browse files
committed
midi: tightened up status/event decoding logic (cf. #1004 (comment))
1 parent 9c7f7f9 commit 3966d5b

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

format/midi/midi.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,10 @@ func decodeEvent(d *decode.D, ctx *context) {
106106
decodeSysExEvent(d, status, ctx)
107107
} else if status == 0xff {
108108
decodeMetaEvent(d, event, ctx)
109-
} else {
109+
} else if status < 0xf0 {
110110
decodeMIDIEvent(d, status, ctx)
111+
} else {
112+
d.Errorf("invalid status byte (%02x)", status)
111113
}
112114
}
113115

@@ -131,12 +133,17 @@ func peekEvent(d *decode.D) (uint64, uint8, uint8) {
131133
status := bytes[ix]
132134
ix++
133135

136+
// ... MIDI event?
137+
if status < 0xf0 {
138+
return delta, status, 0x00
139+
}
140+
134141
// ... sysex?
135142
if status == 0xf0 || status == 0xf7 {
136143
return delta, status, 0x00
137144
}
138145

139-
// ... MIDI event?
146+
// ... (invalid) real-time event
140147
if status != 0xff {
141148
return delta, status, 0x00
142149
}

0 commit comments

Comments
 (0)