Hi guys,
I've a code where MIDI input come from serial port and the received array of bytes need to be converted to an array of integers to be routed on internal system Midi loopback.
I do not like my piece of code I wrote, even it should execute as fast possible, it is important because thit is a Serial-Midi bridge where Midi latency is very important to be as small possible.
Here my code, is there a better way to do it ?
Thanks
I've a code where MIDI input come from serial port and the received array of bytes need to be converted to an array of integers to be routed on internal system Midi loopback.
I do not like my piece of code I wrote, even it should execute as fast possible, it is important because thit is a Serial-Midi bridge where Midi latency is very important to be as small possible.
Here my code, is there a better way to do it ?
Thanks
B4X:
Sub AStream_NewData (Buffer() As Byte)
If Midi.attachedOutputs.Length > 0 Then SendMidiMessage(Buffer)
End Sub
Sub SendMidiMessage(Buffer() As Byte) ' <<< RECEIVE AN ARRAY OF BYTES
Dim debug As Boolean = ckDebug.Checked
If debug Then
Dim sb As StringBuilder
sb.Initialize
End If
Dim bf(Buffer.Length) As Int
For i = 0 To bf.Length -1
bf(i) = Buffer(i)
If debug Then
If bf(i) >= 0 Then
sb.Append(bf(i))
Else
sb.Append(bf(i)+256)
End If
If i < bf.Length -1 Then sb.Append(", ")
End If
Next
If debug Then LogMessage("Send Midi Message: " & bf.Length & " Bytes [" & sb.ToString & "]")
Midi.SendMessage(bf) ' <<< SEND AN ARRAY OF INTEGERS
End Sub
Last edited: