Skip to content

Commit

Permalink
Merge pull request #10 from kainosk/fix-#9-crashes-when-input-noteon-…
Browse files Browse the repository at this point in the history
…between-one-sysex

Fix #9 crashes when input noteon between one sysex
  • Loading branch information
kainosk authored Oct 21, 2019
2 parents 471014a + 7c4c745 commit 2508969
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Swimi/Parser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ public class Parser {
parsingData.append(byte)
notifier.notify(messageData: parsingData)
clearData()
return
case (_, .some(_), .some(.endOfExclusive)):
// error case:
// End Of Exclusive received but not parsing System Exclusive now.
// We will just ignore this.
clearData()
return

case (true, nil, _):
// impossible condition
Expand Down
22 changes: 22 additions & 0 deletions SwimiTests/ParserSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1832,5 +1832,27 @@ class ParserSpec: QuickSpec {
}
}
}

// MARK: Error Cases
describe("error cases") {
context("when input NoteOn between one SysEx") {
// Actually, this behavior is not only about NoteOn.
// This test case describes that the parser should performe this
// behavior for all non-realtime messages.
beforeEach {
subject.input(data: [0xF0])
subject.input(data: [0x90, 0x7F, 0x7F])
subject.input(data: [0xF7])
}
it("parses NoteOn correctly") {
expect(noteOns).to(equal([
NoteOn(channel: 0, note: 0x7F, velocity: 0x7F)
]))
}
it("ignores SysEx") {
expect(systemExclusives).to(haveCount(0))
}
}
}
}
}

0 comments on commit 2508969

Please sign in to comment.