|
|
@ -196,11 +196,13 @@ public object Song { |
|
|
|
onVelocity = (onVelocity + onVelocityBuf.readUnsignedByte().toInt()) and 0x7F |
|
|
|
onVelocity = (onVelocity + onVelocityBuf.readUnsignedByte().toInt()) and 0x7F |
|
|
|
ShortMessage(ShortMessage.NOTE_ON, channel, key, onVelocity) |
|
|
|
ShortMessage(ShortMessage.NOTE_ON, channel, key, onVelocity) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
NOTE_OFF -> { |
|
|
|
NOTE_OFF -> { |
|
|
|
key = (key + keyBuf.readUnsignedByte().toInt()) and 0x7F |
|
|
|
key = (key + keyBuf.readUnsignedByte().toInt()) and 0x7F |
|
|
|
offVelocity = (offVelocity + offVelocityBuf.readUnsignedByte().toInt()) and 0x7F |
|
|
|
offVelocity = (offVelocity + offVelocityBuf.readUnsignedByte().toInt()) and 0x7F |
|
|
|
ShortMessage(ShortMessage.NOTE_OFF, channel, key, offVelocity) |
|
|
|
ShortMessage(ShortMessage.NOTE_OFF, channel, key, offVelocity) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
CONTROL_CHANGE -> { |
|
|
|
CONTROL_CHANGE -> { |
|
|
|
controller = (controller + controllerBuf.readUnsignedByte()) and 0x7F |
|
|
|
controller = (controller + controllerBuf.readUnsignedByte()) and 0x7F |
|
|
|
|
|
|
|
|
|
|
@ -218,6 +220,7 @@ public object Song { |
|
|
|
REGISTERED_LSB -> registeredLsbBuf.readUnsignedByte().toInt() |
|
|
|
REGISTERED_LSB -> registeredLsbBuf.readUnsignedByte().toInt() |
|
|
|
DAMPER, PORTAMENTO, ALL_SOUND_OFF, RESET_CONTROLLERS, ALL_NOTES_OFF -> |
|
|
|
DAMPER, PORTAMENTO, ALL_SOUND_OFF, RESET_CONTROLLERS, ALL_NOTES_OFF -> |
|
|
|
otherKnownControllerBuf.readUnsignedByte().toInt() |
|
|
|
otherKnownControllerBuf.readUnsignedByte().toInt() |
|
|
|
|
|
|
|
|
|
|
|
else -> unknownControllerBuf.readUnsignedByte().toInt() |
|
|
|
else -> unknownControllerBuf.readUnsignedByte().toInt() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -225,25 +228,30 @@ public object Song { |
|
|
|
values[controller] = value |
|
|
|
values[controller] = value |
|
|
|
ShortMessage(ShortMessage.CONTROL_CHANGE, channel, controller, value and 0x7F) |
|
|
|
ShortMessage(ShortMessage.CONTROL_CHANGE, channel, controller, value and 0x7F) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
PITCH_WHEEL_CHANGE -> { |
|
|
|
PITCH_WHEEL_CHANGE -> { |
|
|
|
pitchWheel += pitchWheelLsbBuf.readUnsignedByte().toInt() |
|
|
|
pitchWheel += pitchWheelLsbBuf.readUnsignedByte().toInt() |
|
|
|
pitchWheel += (pitchWheelMsbBuf.readUnsignedByte().toInt() shl 7) |
|
|
|
pitchWheel += (pitchWheelMsbBuf.readUnsignedByte().toInt() shl 7) |
|
|
|
pitchWheel = pitchWheel and 0x3FFF |
|
|
|
pitchWheel = pitchWheel and 0x3FFF |
|
|
|
ShortMessage(ShortMessage.PITCH_BEND, channel, pitchWheel and 0x7F, pitchWheel shr 7) |
|
|
|
ShortMessage(ShortMessage.PITCH_BEND, channel, pitchWheel and 0x7F, pitchWheel shr 7) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
CHANNEL_PRESSURE_CHANGE -> { |
|
|
|
CHANNEL_PRESSURE_CHANGE -> { |
|
|
|
channelPressure = (channelPressure + channelPressureBuf.readUnsignedByte().toInt()) and 0x7F |
|
|
|
channelPressure = (channelPressure + channelPressureBuf.readUnsignedByte().toInt()) and 0x7F |
|
|
|
ShortMessage(ShortMessage.CHANNEL_PRESSURE, channel, channelPressure, 0) |
|
|
|
ShortMessage(ShortMessage.CHANNEL_PRESSURE, channel, channelPressure, 0) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
KEY_PRESSURE_CHANGE -> { |
|
|
|
KEY_PRESSURE_CHANGE -> { |
|
|
|
key = (key + keyBuf.readUnsignedByte().toInt()) and 0x7F |
|
|
|
key = (key + keyBuf.readUnsignedByte().toInt()) and 0x7F |
|
|
|
keyPressure = (keyPressure + keyPressureBuf.readUnsignedByte().toInt()) and 0x7F |
|
|
|
keyPressure = (keyPressure + keyPressureBuf.readUnsignedByte().toInt()) and 0x7F |
|
|
|
ShortMessage(ShortMessage.POLY_PRESSURE, channel, key, keyPressure) |
|
|
|
ShortMessage(ShortMessage.POLY_PRESSURE, channel, key, keyPressure) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
PROGRAM_CHANGE -> { |
|
|
|
PROGRAM_CHANGE -> { |
|
|
|
val bankSelect = bankSelectBuf.readUnsignedByte().toInt() |
|
|
|
val bankSelect = bankSelectBuf.readUnsignedByte().toInt() |
|
|
|
ShortMessage(ShortMessage.PROGRAM_CHANGE, channel, bankSelect, 0) |
|
|
|
ShortMessage(ShortMessage.PROGRAM_CHANGE, channel, bankSelect, 0) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
else -> throw IllegalStateException() |
|
|
|
else -> throw IllegalStateException() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -317,9 +325,11 @@ public object Song { |
|
|
|
require(message.data.size == 3) |
|
|
|
require(message.data.size == 3) |
|
|
|
tempoBuf.writeBytes(message.data) |
|
|
|
tempoBuf.writeBytes(message.data) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
else -> throw IllegalArgumentException("Unsupported meta type: $type") |
|
|
|
else -> throw IllegalArgumentException("Unsupported meta type: $type") |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
is ShortMessage -> { |
|
|
|
is ShortMessage -> { |
|
|
|
val command = message.status and 0xF0 |
|
|
|
val command = message.status and 0xF0 |
|
|
|
val channel = message.status and 0xF |
|
|
|
val channel = message.status and 0xF |
|
|
@ -354,11 +364,13 @@ public object Song { |
|
|
|
onVelocityBuf.writeByte((onVelocity - prevOnVelocity) and 0x7F) |
|
|
|
onVelocityBuf.writeByte((onVelocity - prevOnVelocity) and 0x7F) |
|
|
|
prevOnVelocity = onVelocity |
|
|
|
prevOnVelocity = onVelocity |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ShortMessage.NOTE_OFF -> { |
|
|
|
ShortMessage.NOTE_OFF -> { |
|
|
|
val offVelocity = message.data2 |
|
|
|
val offVelocity = message.data2 |
|
|
|
offVelocityBuf.writeByte((offVelocity - prevOffVelocity) and 0x7F) |
|
|
|
offVelocityBuf.writeByte((offVelocity - prevOffVelocity) and 0x7F) |
|
|
|
prevOffVelocity = offVelocity |
|
|
|
prevOffVelocity = offVelocity |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ShortMessage.CONTROL_CHANGE -> { |
|
|
|
ShortMessage.CONTROL_CHANGE -> { |
|
|
|
val controller = message.data1 |
|
|
|
val controller = message.data1 |
|
|
|
controllerBuf.writeByte((controller - prevController) and 0x7F) |
|
|
|
controllerBuf.writeByte((controller - prevController) and 0x7F) |
|
|
@ -381,11 +393,13 @@ public object Song { |
|
|
|
REGISTERED_LSB -> registeredLsbBuf.writeByte(valueDelta) |
|
|
|
REGISTERED_LSB -> registeredLsbBuf.writeByte(valueDelta) |
|
|
|
DAMPER, PORTAMENTO, ALL_SOUND_OFF, RESET_CONTROLLERS, ALL_NOTES_OFF -> |
|
|
|
DAMPER, PORTAMENTO, ALL_SOUND_OFF, RESET_CONTROLLERS, ALL_NOTES_OFF -> |
|
|
|
otherKnownControllerBuf.writeByte(valueDelta) |
|
|
|
otherKnownControllerBuf.writeByte(valueDelta) |
|
|
|
|
|
|
|
|
|
|
|
else -> unknownControllerBuf.writeByte(valueDelta) |
|
|
|
else -> unknownControllerBuf.writeByte(valueDelta) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
prevValues[controller] = value |
|
|
|
prevValues[controller] = value |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ShortMessage.PITCH_BEND -> { |
|
|
|
ShortMessage.PITCH_BEND -> { |
|
|
|
val pitchWheel = message.data1 or (message.data2 shl 7) |
|
|
|
val pitchWheel = message.data1 or (message.data2 shl 7) |
|
|
|
val pitchWheelDelta = (pitchWheel - prevPitchWheel) and 0x3FFF |
|
|
|
val pitchWheelDelta = (pitchWheel - prevPitchWheel) and 0x3FFF |
|
|
@ -393,22 +407,27 @@ public object Song { |
|
|
|
pitchWheelMsbBuf.writeByte(pitchWheelDelta shr 7) |
|
|
|
pitchWheelMsbBuf.writeByte(pitchWheelDelta shr 7) |
|
|
|
prevPitchWheel = pitchWheel |
|
|
|
prevPitchWheel = pitchWheel |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ShortMessage.CHANNEL_PRESSURE -> { |
|
|
|
ShortMessage.CHANNEL_PRESSURE -> { |
|
|
|
val channelPressure = message.data1 |
|
|
|
val channelPressure = message.data1 |
|
|
|
channelPressureBuf.writeByte((channelPressure - prevChannelPressure) and 0x7F) |
|
|
|
channelPressureBuf.writeByte((channelPressure - prevChannelPressure) and 0x7F) |
|
|
|
prevChannelPressure = channelPressure |
|
|
|
prevChannelPressure = channelPressure |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ShortMessage.POLY_PRESSURE -> { |
|
|
|
ShortMessage.POLY_PRESSURE -> { |
|
|
|
val keyPressure = message.data2 |
|
|
|
val keyPressure = message.data2 |
|
|
|
keyPressureBuf.writeByte((keyPressure - prevKeyPressure) and 0x7F) |
|
|
|
keyPressureBuf.writeByte((keyPressure - prevKeyPressure) and 0x7F) |
|
|
|
prevKeyPressure = keyPressure |
|
|
|
prevKeyPressure = keyPressure |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ShortMessage.PROGRAM_CHANGE -> { |
|
|
|
ShortMessage.PROGRAM_CHANGE -> { |
|
|
|
bankSelectBuf.writeByte(message.data1) |
|
|
|
bankSelectBuf.writeByte(message.data1) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
else -> throw IllegalStateException() |
|
|
|
else -> throw IllegalStateException() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
else -> throw IllegalArgumentException("Unsupported message type: ${message.javaClass.name}") |
|
|
|
else -> throw IllegalArgumentException("Unsupported message type: ${message.javaClass.name}") |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|