Skip to content

Commit

Permalink
Midi1SysExChunkProcessor: Make sure to reset pending inputs.
Browse files Browse the repository at this point in the history
This should fix #81 (comment)
  • Loading branch information
atsushieno committed Jul 27, 2024
1 parent 157f9be commit 41e2eb6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Midi1SysExChunkProcessor {
remaining.addAll(input)
else {
yield(remaining + input.take(f7Pos + 1))
remaining.clear()
// process the remaining recursively
yieldAll(process(input.drop(f7Pos + 1)))
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package dev.atsushieno.ktmidi

import kotlin.test.Test
import kotlin.test.assertContentEquals
import kotlin.test.assertFalse

class Midi1SysExChunkProcessorTest {
@Test
fun process1() {
val processor = Midi1SysExChunkProcessor()
(1..3).forEach {
val sysex = listOf(0xF0,
// invalidate MUID example
0x7E, 0x7F, 0x0D, 0x7E, 1,
0x10, 0x10, 0x10, 0x10, 0x7F, 0x7F, 0x7F, 0x7F, 0x20, 0x20, 0x20, 0x20,
0xF7).map { it.toByte() }
val seq1 = processor.process(sysex.take(10)).flatMap { it }
// The inputs are still stored.
assertFalse(seq1.iterator().hasNext(), "round $it: #1")
val seq2 = processor.process(sysex.drop(10)).flatMap { it }
// the pending inputs are flushed now (and should not remain: https://github.com/atsushieno/ktmidi/issues/81#issuecomment-2253261161)
assertContentEquals(sysex, seq2.toList(), "round $it: #2")
}
}
}

0 comments on commit 41e2eb6

Please sign in to comment.