generated from rnentjes/kotlin-server-web-empty
Refactored MIDI message classes to improve modularity and flexibility, introducing separate classes for distinct MIDI message types. Updated `build.gradle.kts` version to `0.2.0` to reflect these changes. Removed `.idea/.name` file as part of cleanup.
76 lines
1.6 KiB
Kotlin
76 lines
1.6 KiB
Kotlin
package nl.astraeus.midi.message
|
|
|
|
import nl.astraeus.tba.DataType
|
|
import nl.astraeus.tba.MutableByteArrayHandler
|
|
import nl.astraeus.tba.SlicedByteArray
|
|
import nl.astraeus.tba.Type
|
|
import nl.astraeus.tba.TypedByteArray
|
|
import nl.astraeus.tba.blob
|
|
import nl.astraeus.tba.double
|
|
import nl.astraeus.tba.long
|
|
|
|
open class MidiMessage(
|
|
vararg types: Type
|
|
) : TypedByteArray(
|
|
Type("type", DataType.LONG),
|
|
*types,
|
|
) {
|
|
var type by long("type")
|
|
|
|
init {
|
|
this.type = MidiMessageTypes.MIDI_DATA.typeId
|
|
}
|
|
|
|
constructor(data: ByteArray): this() {
|
|
this.data = MutableByteArrayHandler(buffer = data)
|
|
}
|
|
}
|
|
|
|
class MidiDataMessage() : MidiMessage(
|
|
Type("midi", DataType.BLOB, 48),
|
|
) {
|
|
var midi by blob("data")
|
|
|
|
init {
|
|
this.type = MidiMessageTypes.MIDI_DATA.typeId
|
|
}
|
|
|
|
constructor(data: ByteArray): this() {
|
|
check(data.size == definition.size) {
|
|
"Invalid data size: ${data.size} != ${definition.size}"
|
|
}
|
|
|
|
this.data = MutableByteArrayHandler(data)
|
|
}
|
|
|
|
}
|
|
|
|
class TimedMidiMessage() : MidiMessage(
|
|
Type("timeToPlay", DataType.DOUBLE),
|
|
Type("midi", DataType.BLOB, 48),
|
|
) {
|
|
var timeToPlay by double("timeToPlay")
|
|
var midi by blob("data")
|
|
|
|
init {
|
|
this.type = MidiMessageTypes.MIDI_DATA.typeId
|
|
}
|
|
|
|
constructor(data: ByteArray): this() {
|
|
check(data.size == definition.size) {
|
|
"Invalid data size: ${data.size} != ${definition.size}"
|
|
}
|
|
|
|
this.data = MutableByteArrayHandler(data)
|
|
}
|
|
|
|
constructor(
|
|
timeToPlay: Double,
|
|
vararg data: Byte
|
|
): this() {
|
|
this.timeToPlay = timeToPlay
|
|
this.midi = SlicedByteArray(data)
|
|
}
|
|
|
|
}
|