getMidiMessage implemented

midi type added.
This commit is contained in:
onyx-and-iris
2022-08-22 22:28:11 +01:00
parent 76e6d3cba7
commit 69476ffcd9
2 changed files with 61 additions and 0 deletions

33
base.go
View File

@@ -37,6 +37,8 @@ var (
vmMdirty = mod.NewProc("VBVMR_MacroButton_IsDirty")
vmGetMacroStatus = mod.NewProc("VBVMR_MacroButton_GetStatus")
vmSetMacroStatus = mod.NewProc("VBVMR_MacroButton_SetStatus")
vmGetMidiMessage = mod.NewProc("VBVMR_GetMidiMessage")
)
// login logs into the API,
@@ -315,3 +317,34 @@ func getLevel(type_, i int) float32 {
}
return val
}
// getMidiMessage gets midi channel, pitch and velocity for a single midi input
func getMidiMessage() bool {
var midi = newMidi()
var b1 [1024]byte
res, _, _ := vmGetMidiMessage.Call(
uintptr(unsafe.Pointer(&b1[0])),
uintptr(1024),
)
if int(res) < 0 {
err := fmt.Errorf("VBVMR_GetMidiMessage returned %d", res)
fmt.Println(err)
os.Exit(1)
}
msg := bytes.Trim(b1[:], "\x00")
if len(msg) > 0 {
for i := 0; i < len(msg)%3; i++ {
msg = append(msg, 0)
}
for i := 0; i < len(msg); i += 3 {
var ch = int(msg[i])
var pitch = int(msg[i+1])
var vel = int(msg[i+2])
midi.channel = ch
midi.current = pitch
midi.cache[pitch] = vel
}
}
return len(msg) > 0
}