Skip to content

Commit

Permalink
citool: sending to virtual ports should always be optional.
Browse files Browse the repository at this point in the history
Also add some notes on `bytes` that it is MIDI 1.0 bytestream.
  • Loading branch information
atsushieno committed Sep 5, 2024
1 parent 5403a4b commit 4f7dce8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ class MidiDeviceManager {
private fun MidiOutput.send(bytes: ByteArray, timestampInNanoseconds: Long) =
send(bytes, 0, bytes.size, timestampInNanoseconds)

// `bytes` is a MIDI1 transport stream,
// so every time it tries to send to UMP port it needs to be translated to UMP.
fun sendToAll(group: Byte, bytes: ByteArray, timestampInNanoseconds: Long) {
try {
if (midiOutputError.value == null) {
Expand All @@ -128,15 +130,12 @@ class MidiDeviceManager {
Snapshot.withMutableSnapshot { midiOutputError.value = ex }
}
try {
if (virtualMidiOutput!!.details.midiTransportProtocol == MidiTransportProtocol.UMP) {
if (virtualMidiOutputError.value == null && virtualMidiOutput2 != null)
if (virtualMidiOutput2?.details?.midiTransportProtocol == MidiTransportProtocol.UMP) {
if (virtualMidiOutputError.value == null)
virtualMidiOutput2!!.send(translateMidi1BytesToUmp(bytes, group), timestampInNanoseconds)
else
virtualMidiOutput2!!.send(bytes, 0, bytes.size, timestampInNanoseconds)
} else {
if (virtualMidiOutputError.value == null && virtualMidiOutput != null)
virtualMidiOutput!!.send(translateMidi1BytesToUmp(bytes, group), timestampInNanoseconds)
else
}
if (virtualMidiOutput?.details?.midiTransportProtocol != MidiTransportProtocol.UMP) {
if (virtualMidiOutputError.value == null)
virtualMidiOutput!!.send(bytes, 0, bytes.size, timestampInNanoseconds)
}
} catch (ex: Exception) {
Expand Down
5 changes: 1 addition & 4 deletions ktmidi-ci-tool/src/desktopMain/kotlin/main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ fun main(args: Array<String>) = application {
else if (args.contains("jvm")) JvmMidiAccess()
else if (System.getProperty("os.name").contains("Windows")) JvmMidiAccess()
// else RtMidiAccess()
else MergedMidiAccess("LibreMidiAccess-1+2", listOf(
LibreMidiAccess.create(MidiTransportProtocol.UMP),
LibreMidiAccess.create(MidiTransportProtocol.MIDI1)
))
else LibreMidiAccess.create(MidiTransportProtocol.UMP)
Window(onCloseRequest = ::exitApplication,
state = rememberWindowState(),
title = "midi-ci-tool") {
Expand Down

0 comments on commit 4f7dce8

Please sign in to comment.