Skip to content

Commit

Permalink
Merge pull request #20 from kainosk/fix-#19
Browse files Browse the repository at this point in the history
* fix #19: ignore corrupted SysEx correctly
  • Loading branch information
kainosk authored Jul 27, 2022
2 parents 25f8799 + 9a30628 commit fdfb837
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Swimi/MIDI/Parser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class Parser {
notifier.notify(messageData: parsingData)
clearData()
return
case (_, .some(_), .some(.endOfExclusive)):
case (_, _, .some(.endOfExclusive)):
// error case:
// End Of Exclusive received but not parsing System Exclusive now.
// We will just ignore this.
Expand Down
21 changes: 21 additions & 0 deletions SwimiTests/MIDI/ParserSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1921,6 +1921,27 @@ class ParserSpec: QuickSpec {
]))
}
}
context("when input corrupted (head dropped) SyEx") {
beforeEach {
subject.input(data: [
// Corrupted SysEx
// last '247 (0xF7)' is EndOfExclusive
// but there is no '0xF0' SystemExclusive status byte.
114, 97, 0, 110, 103, 101, 109, 101, 110, 116, 0, 115, 47, 67,
108, 97, 115, 115, 0, 105, 99, 48, 49, 46, 83, 48, 0, 48, 48, 46,
109, 105, 100, 247,

// Simple, NoteOn
0x90, 0x7F, 0x7F,
])

}
it("ignore them then parse next data correctly") {
expect(parsedEvents) == [
.noteOn(channel: 0, note: 0x7F, velocity: 0x7F)
]
}
}
}
}
}

0 comments on commit fdfb837

Please sign in to comment.