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
}

28
midi.go Normal file
View File

@ -0,0 +1,28 @@
package voicemeeter
var midi *midi_t
type midi_t struct {
channel int
current int
cache map[int]int
}
func newMidi() *midi_t {
if midi == nil {
midi = &midi_t{0, 0, map[int]int{}}
}
return midi
}
func (m *midi_t) Channel() int {
return m.channel
}
func (m *midi_t) Current() int {
return m.current
}
func (m *midi_t) Get(key int) int {
return m.cache[key]
}