Also search on name when setting midi port
This commit is contained in:
@@ -74,11 +74,37 @@ object Midi {
|
||||
)
|
||||
}
|
||||
|
||||
fun setInput(id: String) {
|
||||
val selected = inputs.find { it.id == id }
|
||||
if (selected != null) {
|
||||
setInput(selected)
|
||||
fun setInput(id: String, name: String = "") {
|
||||
var selected = inputs.find { it.id == id }
|
||||
if (selected == null) {
|
||||
var maxMatchChar = 0
|
||||
inputs.forEach {
|
||||
val matchChars = matchChars(it.name, name)
|
||||
if (matchChars > maxMatchChar) {
|
||||
selected = it
|
||||
maxMatchChar = matchChars
|
||||
}
|
||||
}
|
||||
}
|
||||
setInput(selected)
|
||||
}
|
||||
|
||||
private fun matchChars(str1: String, str2: String): Int {
|
||||
var result = 0
|
||||
if (str1.length > str2.length) {
|
||||
for (ch in str1.toCharArray()) {
|
||||
if (str2.contains(ch)) {
|
||||
result++
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (ch in str2.toCharArray()) {
|
||||
if (str1.contains(ch)) {
|
||||
result++
|
||||
}
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
fun setInput(input: MIDIInput?) {
|
||||
|
||||
Reference in New Issue
Block a user