[orx-midi] Allow incomplete device name (#310)
This commit is contained in:
@@ -277,7 +277,21 @@ fun listMidiDevices() = MidiDeviceDescription.list()
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Open a MIDI device by name
|
* Open a MIDI device by name
|
||||||
* @param name the name of the MIDI device to open
|
* @param name the name of the MIDI device to open. Either the
|
||||||
|
* exact name or the first characters of the name.
|
||||||
* @since 0.4.3
|
* @since 0.4.3
|
||||||
*/
|
*/
|
||||||
fun Program.openMidiDevice(name: String) = MidiTransceiver.fromDeviceVendor(this, name)
|
fun Program.openMidiDevice(name: String): MidiTransceiver {
|
||||||
|
val devices = listMidiDevices()
|
||||||
|
|
||||||
|
val matchingDevice = devices.firstOrNull {
|
||||||
|
// Existing device name matches `name`
|
||||||
|
it.name == name
|
||||||
|
} ?: devices.firstOrNull {
|
||||||
|
// Existing device name starts with `name`
|
||||||
|
it.name.startsWith(name)
|
||||||
|
}
|
||||||
|
val actualName = matchingDevice?.name ?: name
|
||||||
|
|
||||||
|
return MidiTransceiver.fromDeviceVendor(this, actualName)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user