-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
300 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
109 changes: 109 additions & 0 deletions
109
src/commonTest/kotlin/org/wysko/kmidi/ArrayInputStreamTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
package org.wysko.kmidi | ||
|
||
import junit.framework.TestCase.assertEquals | ||
import org.junit.Assert.assertArrayEquals | ||
import org.wysko.kmidi.midi.UnexpectedEndOfFileException | ||
import kotlin.test.Test | ||
|
||
class ArrayInputStreamTest { | ||
@Test | ||
fun `Test read`() { | ||
val inputStream = ArrayInputStream(byteArrayOf(1, 2, 3)) | ||
assertEquals(1, inputStream.read()) | ||
assertEquals(2, inputStream.read()) | ||
assertEquals(3, inputStream.read()) | ||
} | ||
|
||
@Test | ||
fun `Test read word`() { | ||
val inputStream = ArrayInputStream(byteArrayOf(69, 42)) | ||
assertEquals(17706, inputStream.readWord()) | ||
} | ||
|
||
@Test | ||
fun `Test read dword`() { | ||
val inputStream = ArrayInputStream(byteArrayOf(1, 2, 3, 4)) | ||
assertEquals(16909060, inputStream.readDWord()) | ||
} | ||
|
||
@Test | ||
fun `Test read n bytes`() { | ||
val inputStream = ArrayInputStream(byteArrayOf(0, 1, 2, 3, 4, 5)) | ||
assertArrayEquals(byteArrayOf(0, 1, 2), inputStream.readNBytes(3)) | ||
assertArrayEquals(byteArrayOf(3, 4, 5), inputStream.readNBytes(3)) | ||
} | ||
|
||
@Test | ||
fun `Test skip`() { | ||
val inputStream = ArrayInputStream(byteArrayOf(0, 1, 2, 3, 4)) | ||
inputStream.skip(3) | ||
assertEquals(3, inputStream.read()) | ||
assertEquals(4, inputStream.read()) | ||
} | ||
|
||
@Test | ||
fun `Test 24 bit int`() { | ||
val inputStream = ArrayInputStream(byteArrayOf(4, 20, 69)) | ||
assertEquals(267333, inputStream.read24BitInt()) | ||
} | ||
|
||
@Test(expected = UnexpectedEndOfFileException::class) | ||
fun `Test read empty stream`() { | ||
val inputStream = ArrayInputStream(byteArrayOf()) | ||
inputStream.read() | ||
} | ||
|
||
@Test(expected = IndexOutOfBoundsException::class) | ||
fun `Test skip too many bytes`() { | ||
val inputStream = ArrayInputStream(byteArrayOf(0, 1, 2)) | ||
inputStream.skip(4) | ||
} | ||
|
||
@Test(expected = UnexpectedEndOfFileException::class) | ||
fun `Test read word with unexpected end of file`() { | ||
val inputStream = ArrayInputStream(byteArrayOf(0)) | ||
inputStream.readWord() | ||
} | ||
|
||
@Test(expected = UnexpectedEndOfFileException::class) | ||
fun `Test read dword with unexpected end of file`() { | ||
val inputStream = ArrayInputStream(byteArrayOf(0)) | ||
inputStream.readDWord() | ||
} | ||
|
||
@Test(expected = UnexpectedEndOfFileException::class) | ||
fun `Test read n bytes with unexpected end of file`() { | ||
val inputStream = ArrayInputStream(byteArrayOf(0)) | ||
inputStream.readNBytes(2) | ||
} | ||
|
||
@Test(expected = UnexpectedEndOfFileException::class) | ||
fun `Test read 24 bit int with unexpected end of file`() { | ||
val inputStream = ArrayInputStream(byteArrayOf(0)) | ||
inputStream.read24BitInt() | ||
} | ||
|
||
@Test(expected = UnexpectedEndOfFileException::class) | ||
fun `Test read VLQ with unexpected end of file`() { | ||
val inputStream = | ||
ArrayInputStream(byteArrayOf(0x81.toByte(), 0x80.toByte())) | ||
inputStream.readVlq() | ||
} | ||
|
||
@Test | ||
fun `Test read vlq`() { | ||
val inputStream = | ||
ArrayInputStream(byteArrayOf(0x81.toByte(), 0x80.toByte(), 0x00)) | ||
assertEquals(0x4000 to 3, inputStream.readVlq()) | ||
} | ||
|
||
@Test | ||
fun `Test position`() { | ||
val inputStream = ArrayInputStream(byteArrayOf(0, 1, 2, 3, 4)) | ||
assertEquals(0, inputStream.position) | ||
inputStream.read() | ||
assertEquals(1, inputStream.position) | ||
inputStream.skip(2) | ||
assertEquals(3, inputStream.position) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package org.wysko.kmidi.midi | ||
|
||
object SmfExamples { | ||
val example1 = | ||
intArrayOf( | ||
0x4D, | ||
0x54, | ||
0x68, | ||
0x64, | ||
0x00, | ||
0x00, | ||
0x00, | ||
0x06, | ||
0x00, | ||
0x00, | ||
0x00, | ||
0x01, | ||
0x00, | ||
0x60, | ||
0x4D, | ||
0x54, | ||
0x72, | ||
0x6B, | ||
0x00, | ||
0x00, | ||
0x00, | ||
0x3B, | ||
0x00, | ||
0xFF, | ||
0x58, | ||
0x04, | ||
0x04, | ||
0x02, | ||
0x18, | ||
0x08, | ||
0x00, | ||
0xFF, | ||
0x51, | ||
0x03, | ||
0x07, | ||
0xA1, | ||
0x20, | ||
0x00, | ||
0xC0, | ||
0x05, | ||
0x00, | ||
0xC1, | ||
0x2E, | ||
0x00, | ||
0xC2, | ||
0x46, | ||
0x00, | ||
0x92, | ||
0x30, | ||
0x60, | ||
0x00, | ||
0x3C, | ||
0x60, | ||
0x60, | ||
0x91, | ||
0x43, | ||
0x40, | ||
0x60, | ||
0x90, | ||
0x4C, | ||
0x20, | ||
0x81, | ||
0x40, | ||
0x82, | ||
0x30, | ||
0x40, | ||
0x00, | ||
0x3C, | ||
0x40, | ||
0x00, | ||
0x81, | ||
0x43, | ||
0x40, | ||
0x00, | ||
0x80, | ||
0x4C, | ||
0x40, | ||
0x00, | ||
0xFF, | ||
0x2F, | ||
0x00, | ||
).map { it.toByte() }.toByteArray() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
src/commonTest/kotlin/org/wysko/kmidi/midi/analysis/PolyphonyTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package org.wysko.kmidi.midi.analysis | ||
|
||
import org.wysko.kmidi.midi.event.NoteEvent | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
|
||
class PolyphonyTest { | ||
@Test | ||
fun `Test calculateMaximumPolyphony empty list`() { | ||
val events = emptyList<NoteEvent>() | ||
val result = Polyphony.calculateMaximumPolyphony(events) | ||
assertEquals(0, result) | ||
} | ||
|
||
@Test | ||
fun `Test calculateMaximumPolyphony single note`() { | ||
val events = | ||
listOf( | ||
NoteEvent.NoteOn(0, 0, 60, 127), | ||
NoteEvent.NoteOff(1, 0, 60), | ||
) | ||
val result = Polyphony.calculateMaximumPolyphony(events) | ||
assertEquals(1, result) | ||
} | ||
|
||
@Test | ||
fun `Test calculateMaximumPolyphony two simultaneous notes`() { | ||
val events = | ||
listOf( | ||
NoteEvent.NoteOn(0, 0, 60, 127), | ||
NoteEvent.NoteOn(0, 0, 61, 127), | ||
NoteEvent.NoteOff(1, 0, 60), | ||
NoteEvent.NoteOff(1, 0, 61), | ||
) | ||
val result = Polyphony.calculateMaximumPolyphony(events) | ||
assertEquals(2, result) | ||
} | ||
|
||
@Test | ||
fun `Test calculateMaximumPolyphony two notes with overlap`() { | ||
val events = | ||
listOf( | ||
NoteEvent.NoteOn(0, 0, 60, 127), | ||
NoteEvent.NoteOn(1, 0, 61, 127), | ||
NoteEvent.NoteOff(2, 0, 60), | ||
NoteEvent.NoteOff(3, 0, 61), | ||
) | ||
val result = Polyphony.calculateMaximumPolyphony(events) | ||
assertEquals(2, result) | ||
} | ||
|
||
@Test | ||
fun `Test averagePolyphony empty list`() { | ||
val events = emptyList<NoteEvent>() | ||
val result = Polyphony.averagePolyphony(events) | ||
assertEquals(0.0, result) | ||
} | ||
|
||
@Test | ||
fun `Test averagePolyphony single note`() { | ||
val events = | ||
listOf( | ||
NoteEvent.NoteOn(0, 0, 60, 127), | ||
NoteEvent.NoteOff(1, 0, 60), | ||
) | ||
val result = Polyphony.averagePolyphony(events) | ||
assertEquals(1.0, result) | ||
} | ||
|
||
@Test | ||
fun `Test averagePolyphony two simultaneous notes`() { | ||
val events = | ||
listOf( | ||
NoteEvent.NoteOn(0, 0, 60, 127), | ||
NoteEvent.NoteOn(0, 0, 61, 127), | ||
NoteEvent.NoteOff(1, 0, 60), | ||
NoteEvent.NoteOff(1, 0, 61), | ||
) | ||
val result = Polyphony.averagePolyphony(events) | ||
assertEquals(2.0, result) | ||
} | ||
|
||
@Test | ||
fun `Test averagePolyphony two notes with overlap`() { | ||
val events = | ||
listOf( | ||
NoteEvent.NoteOn(0, 0, 60, 127), | ||
NoteEvent.NoteOn(1, 0, 61, 127), | ||
NoteEvent.NoteOff(2, 0, 60), | ||
NoteEvent.NoteOff(3, 0, 61), | ||
) | ||
val result = Polyphony.averagePolyphony(events) | ||
assertEquals(4 / 3.0, result, 0.0001) | ||
} | ||
} |
3 changes: 2 additions & 1 deletion
3
src/commonTest/kotlin/ArcTest.kt → ...st/kotlin/org/wysko/kmidi/midi/ArcTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters