2022-06-22 20:51:25 +01:00
|
|
|
package voicemeeter
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2024-07-01 07:20:05 +01:00
|
|
|
"errors"
|
2022-06-22 20:51:25 +01:00
|
|
|
"fmt"
|
|
|
|
"math"
|
2024-07-01 07:20:05 +01:00
|
|
|
"runtime"
|
2022-06-28 16:29:13 +01:00
|
|
|
"strings"
|
2022-06-22 20:51:25 +01:00
|
|
|
"syscall"
|
|
|
|
"time"
|
|
|
|
"unsafe"
|
2022-09-29 18:02:11 +01:00
|
|
|
|
|
|
|
log "github.com/sirupsen/logrus"
|
2022-06-22 20:51:25 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
mod = syscall.NewLazyDLL(getDllPath())
|
|
|
|
|
2022-06-23 14:01:39 +01:00
|
|
|
vmLogin = mod.NewProc("VBVMR_Login")
|
|
|
|
vmLogout = mod.NewProc("VBVMR_Logout")
|
|
|
|
vmRunvm = mod.NewProc("VBVMR_RunVoicemeeter")
|
|
|
|
vmGetvmType = mod.NewProc("VBVMR_GetVoicemeeterType")
|
|
|
|
vmGetvmVersion = mod.NewProc("VBVMR_GetVoicemeeterVersion")
|
|
|
|
vmPdirty = mod.NewProc("VBVMR_IsParametersDirty")
|
|
|
|
vmGetParamFloat = mod.NewProc("VBVMR_GetParameterFloat")
|
|
|
|
vmGetParamString = mod.NewProc("VBVMR_GetParameterStringA")
|
2022-06-22 20:51:25 +01:00
|
|
|
|
2022-06-30 20:08:46 +01:00
|
|
|
vmGetLevelFloat = mod.NewProc("VBVMR_GetLevel")
|
2022-06-22 20:51:25 +01:00
|
|
|
|
2022-06-23 14:01:39 +01:00
|
|
|
vmSetParamFloat = mod.NewProc("VBVMR_SetParameterFloat")
|
|
|
|
vmSetParameters = mod.NewProc("VBVMR_SetParameters")
|
|
|
|
vmSetParamString = mod.NewProc("VBVMR_SetParameterStringA")
|
2022-06-22 20:51:25 +01:00
|
|
|
|
2022-06-28 16:29:13 +01:00
|
|
|
vmGetDevNumIn = mod.NewProc("VBVMR_Input_GetDeviceNumber")
|
|
|
|
vmGetDevDescIn = mod.NewProc("VBVMR_Input_GetDeviceDescA")
|
|
|
|
vmGetDevNumOut = mod.NewProc("VBVMR_Output_GetDeviceNumber")
|
|
|
|
vmGetDevDescOut = mod.NewProc("VBVMR_Output_GetDeviceDescA")
|
2022-06-22 20:51:25 +01:00
|
|
|
|
2022-06-23 14:01:39 +01:00
|
|
|
vmMdirty = mod.NewProc("VBVMR_MacroButton_IsDirty")
|
|
|
|
vmGetMacroStatus = mod.NewProc("VBVMR_MacroButton_GetStatus")
|
|
|
|
vmSetMacroStatus = mod.NewProc("VBVMR_MacroButton_SetStatus")
|
2022-08-22 22:28:11 +01:00
|
|
|
|
|
|
|
vmGetMidiMessage = mod.NewProc("VBVMR_GetMidiMessage")
|
2022-06-22 20:51:25 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// login logs into the API,
|
2022-07-10 23:08:14 +01:00
|
|
|
// attempts to launch Voicemeeter if it's not running,
|
|
|
|
// initializes dirty parameters.
|
2024-07-01 07:20:05 +01:00
|
|
|
func login(kindId string, timeout, bits int) error {
|
2022-06-22 20:51:25 +01:00
|
|
|
res, _, _ := vmLogin.Call()
|
|
|
|
if res == 1 {
|
2024-07-01 07:20:05 +01:00
|
|
|
runVoicemeeter(kindId, bits)
|
2022-06-22 20:51:25 +01:00
|
|
|
} else if res != 0 {
|
|
|
|
err := fmt.Errorf("VBVMR_Login returned %d", res)
|
2022-09-07 20:59:55 +01:00
|
|
|
return err
|
2022-06-22 20:51:25 +01:00
|
|
|
}
|
2024-07-01 07:20:05 +01:00
|
|
|
|
|
|
|
var ver_s string
|
|
|
|
start := time.Now()
|
|
|
|
var err error
|
|
|
|
for time.Since(start).Seconds() < float64(timeout) {
|
|
|
|
time.Sleep(time.Duration(100) * time.Millisecond)
|
|
|
|
if ver_s, err = getVersion(); err == nil {
|
|
|
|
log.Infof("Logged into Voicemeeter %s v%s", kindMap[kindId], ver_s)
|
|
|
|
log.Debugf("Log in time: %.2f", time.Since(start).Seconds())
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
return errors.New("timeout logging into the API")
|
|
|
|
}
|
2022-12-08 10:26:19 +00:00
|
|
|
clear()
|
2022-09-07 20:59:55 +01:00
|
|
|
return nil
|
2022-06-22 20:51:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// logout logs out of the API,
|
|
|
|
// delayed for 100ms to allow final operation to complete.
|
2022-09-07 20:59:55 +01:00
|
|
|
func logout(kindId string) error {
|
2022-06-22 20:51:25 +01:00
|
|
|
time.Sleep(100 * time.Millisecond)
|
|
|
|
res, _, _ := vmLogout.Call()
|
2022-12-08 10:26:19 +00:00
|
|
|
if int32(res) != 0 {
|
|
|
|
err := fmt.Errorf("VBVMR_Logout returned %d", int32(res))
|
2022-09-07 20:59:55 +01:00
|
|
|
return err
|
2022-06-22 20:51:25 +01:00
|
|
|
}
|
2024-07-01 07:20:05 +01:00
|
|
|
log.Infof("Logged out of Voicemeeter %s", kindMap[kindId])
|
2022-09-07 20:59:55 +01:00
|
|
|
return nil
|
2022-06-22 20:51:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// runVoicemeeter attempts to launch a Voicemeeter GUI of a kind.
|
2024-07-01 07:20:05 +01:00
|
|
|
func runVoicemeeter(kindId string, bits int) error {
|
2022-06-22 20:51:25 +01:00
|
|
|
vals := map[string]uint64{
|
|
|
|
"basic": 1,
|
|
|
|
"banana": 2,
|
|
|
|
"potato": 3,
|
|
|
|
}
|
2024-07-01 07:20:05 +01:00
|
|
|
val := vals[kindId]
|
|
|
|
if strings.Contains(runtime.GOARCH, "64") && bits == 64 {
|
|
|
|
val += 3
|
|
|
|
}
|
|
|
|
res, _, _ := vmRunvm.Call(uintptr(val))
|
2022-12-08 10:26:19 +00:00
|
|
|
if int32(res) != 0 {
|
|
|
|
err := fmt.Errorf("VBVMR_RunVoicemeeter returned %d", int32(res))
|
2022-09-07 20:59:55 +01:00
|
|
|
return err
|
2022-06-22 20:51:25 +01:00
|
|
|
}
|
2022-09-07 20:59:55 +01:00
|
|
|
return nil
|
2022-06-22 20:51:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// getVersion returns the version of Voicemeeter as a string
|
2022-09-07 20:59:55 +01:00
|
|
|
func getVersion() (string, error) {
|
2022-06-22 20:51:25 +01:00
|
|
|
var ver uint64
|
|
|
|
res, _, _ := vmGetvmVersion.Call(uintptr(unsafe.Pointer(&ver)))
|
2022-12-08 10:26:19 +00:00
|
|
|
if int32(res) != 0 {
|
|
|
|
err := fmt.Errorf("VBVMR_GetVoicemeeterVersion returned %d", int32(res))
|
2024-07-01 07:20:05 +01:00
|
|
|
log.Error(err.Error())
|
2022-09-07 20:59:55 +01:00
|
|
|
return "", err
|
2022-06-22 20:51:25 +01:00
|
|
|
}
|
|
|
|
v1 := (ver & 0xFF000000) >> 24
|
|
|
|
v2 := (ver & 0x00FF0000) >> 16
|
|
|
|
v3 := (ver & 0x0000FF00) >> 8
|
|
|
|
v4 := ver & 0x000000FF
|
2022-09-07 20:59:55 +01:00
|
|
|
return fmt.Sprintf("%d.%d.%d.%d", v1, v2, v3, v4), nil
|
2022-06-22 20:51:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// pdirty returns true iff a parameter value has changed
|
2022-12-08 10:26:19 +00:00
|
|
|
func pdirty() (bool, error) {
|
2022-06-22 20:51:25 +01:00
|
|
|
res, _, _ := vmPdirty.Call()
|
2022-12-08 10:26:19 +00:00
|
|
|
if int32(res) < 0 {
|
|
|
|
err := fmt.Errorf("VBVMR_IsParametersDirty returned %d", int32(res))
|
|
|
|
log.Error(err.Error())
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
return int32(res) == 1, nil
|
2022-06-22 20:51:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// mdirty returns true iff a macrobutton value has changed
|
2022-12-08 10:26:19 +00:00
|
|
|
func mdirty() (bool, error) {
|
2022-06-22 20:51:25 +01:00
|
|
|
res, _, _ := vmMdirty.Call()
|
2022-12-08 10:26:19 +00:00
|
|
|
if int32(res) < 0 {
|
|
|
|
err := fmt.Errorf("VBVMR_MacroButton_IsDirty returned %d", int32(res))
|
|
|
|
log.Error(err.Error())
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
return int32(res) == 1, nil
|
2022-06-22 20:51:25 +01:00
|
|
|
}
|
|
|
|
|
2022-07-10 23:08:14 +01:00
|
|
|
// ldirty returns true iff a level value has changed
|
2022-12-08 10:26:19 +00:00
|
|
|
func ldirty(k *kind) (bool, error) {
|
2022-09-14 00:58:05 +01:00
|
|
|
_levelCache.stripLevelsBuff = make([]float64, (2*k.PhysIn)+(8*k.VirtIn))
|
|
|
|
_levelCache.busLevelsBuff = make([]float64, 8*k.NumBus())
|
2022-07-09 19:01:58 +01:00
|
|
|
|
2022-07-18 16:23:15 +01:00
|
|
|
for i := 0; i < (2*k.PhysIn)+(8*k.VirtIn); i++ {
|
2022-12-08 10:26:19 +00:00
|
|
|
val, err := getLevel(_levelCache.stripMode, i)
|
|
|
|
if err != nil {
|
|
|
|
log.Error(err.Error())
|
|
|
|
return false, err
|
|
|
|
}
|
2022-09-07 20:59:55 +01:00
|
|
|
_levelCache.stripLevelsBuff[i] = val
|
2022-07-09 19:01:58 +01:00
|
|
|
_levelCache.stripComp[i] = _levelCache.stripLevelsBuff[i] == _levelCache.stripLevels[i]
|
|
|
|
}
|
2022-07-18 16:23:15 +01:00
|
|
|
for i := 0; i < 8*k.NumBus(); i++ {
|
2022-12-08 10:26:19 +00:00
|
|
|
val, err := getLevel(3, i)
|
|
|
|
if err != nil {
|
|
|
|
log.Error(err.Error())
|
|
|
|
return false, err
|
|
|
|
}
|
2022-09-07 20:59:55 +01:00
|
|
|
_levelCache.busLevelsBuff[i] = val
|
2022-07-09 19:01:58 +01:00
|
|
|
_levelCache.busComp[i] = _levelCache.busLevelsBuff[i] == _levelCache.busLevels[i]
|
|
|
|
}
|
2022-12-08 10:26:19 +00:00
|
|
|
return !(allTrue(_levelCache.stripComp, (2*k.PhysIn)+(8*k.VirtIn)) && allTrue(_levelCache.busComp, 8*k.NumBus())), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func clear() {
|
|
|
|
for {
|
|
|
|
pdirty, _ := pdirty()
|
|
|
|
mdirty, _ := mdirty()
|
|
|
|
if !(pdirty || mdirty) {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
2022-07-09 19:01:58 +01:00
|
|
|
}
|
|
|
|
|
2022-06-22 20:51:25 +01:00
|
|
|
// getVMType returns the type of Voicemeeter, as a string
|
2022-09-07 20:59:55 +01:00
|
|
|
func getVMType() (string, error) {
|
2022-06-22 20:51:25 +01:00
|
|
|
var type_ uint64
|
|
|
|
res, _, _ := vmGetvmType.Call(
|
|
|
|
uintptr(unsafe.Pointer(&type_)),
|
|
|
|
)
|
2022-12-08 10:26:19 +00:00
|
|
|
if int32(res) != 0 {
|
|
|
|
err := fmt.Errorf("VBVMR_GetVoicemeeterType returned %d", int32(res))
|
2022-09-07 20:59:55 +01:00
|
|
|
return "", err
|
2022-06-22 20:51:25 +01:00
|
|
|
}
|
|
|
|
vals := map[uint64]string{
|
|
|
|
1: "basic",
|
|
|
|
2: "banana",
|
|
|
|
3: "potato",
|
|
|
|
}
|
2022-09-07 20:59:55 +01:00
|
|
|
return vals[type_], nil
|
2022-06-22 20:51:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// getParameterFloat gets the value of a float parameter
|
2022-09-07 20:59:55 +01:00
|
|
|
func getParameterFloat(name string) (float64, error) {
|
2022-09-14 16:05:15 +01:00
|
|
|
if vmsync {
|
|
|
|
time.Sleep(time.Duration(vmdelay) * time.Millisecond)
|
2022-12-08 10:26:19 +00:00
|
|
|
clear()
|
2022-09-14 16:05:15 +01:00
|
|
|
}
|
2022-06-22 20:51:25 +01:00
|
|
|
var value float32
|
|
|
|
b := append([]byte(name), 0)
|
2022-06-23 14:01:39 +01:00
|
|
|
res, _, _ := vmGetParamFloat.Call(
|
2022-06-22 20:51:25 +01:00
|
|
|
uintptr(unsafe.Pointer(&b[0])),
|
|
|
|
uintptr(unsafe.Pointer(&value)),
|
|
|
|
)
|
2022-12-08 10:26:19 +00:00
|
|
|
if int32(res) != 0 {
|
|
|
|
err := fmt.Errorf("VBVMR_GetParameterFloat returned %d", int32(res))
|
2022-09-07 20:59:55 +01:00
|
|
|
return 0, err
|
2022-06-22 20:51:25 +01:00
|
|
|
}
|
2022-09-07 20:59:55 +01:00
|
|
|
return math.Round(float64(value)*10) / 10, nil
|
2022-06-22 20:51:25 +01:00
|
|
|
}
|
|
|
|
|
2022-06-25 01:18:20 +01:00
|
|
|
// setParameterFloat sets the value of a float parameter
|
2022-09-14 00:58:05 +01:00
|
|
|
func setParameterFloat(name string, value float64) error {
|
2022-06-22 20:51:25 +01:00
|
|
|
b1 := append([]byte(name), 0)
|
2022-09-14 00:58:05 +01:00
|
|
|
b2 := math.Float32bits(float32(value))
|
2022-06-23 14:01:39 +01:00
|
|
|
res, _, _ := vmSetParamFloat.Call(
|
2022-06-22 20:51:25 +01:00
|
|
|
uintptr(unsafe.Pointer(&b1[0])),
|
|
|
|
uintptr(b2),
|
|
|
|
)
|
2022-12-08 10:26:19 +00:00
|
|
|
if int32(res) != 0 {
|
|
|
|
err := fmt.Errorf("VBVMR_SetParameterFloat returned %d", int32(res))
|
2022-09-07 20:59:55 +01:00
|
|
|
return err
|
2022-06-22 20:51:25 +01:00
|
|
|
}
|
2022-09-07 20:59:55 +01:00
|
|
|
return nil
|
2022-06-22 20:51:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// getParameterString gets the value of a string parameter
|
2022-09-07 20:59:55 +01:00
|
|
|
func getParameterString(name string) (string, error) {
|
2022-09-14 16:05:15 +01:00
|
|
|
if vmsync {
|
|
|
|
time.Sleep(time.Duration(vmdelay) * time.Millisecond)
|
2022-12-08 10:26:19 +00:00
|
|
|
clear()
|
2022-09-14 16:05:15 +01:00
|
|
|
}
|
2022-06-22 20:51:25 +01:00
|
|
|
b1 := append([]byte(name), 0)
|
|
|
|
var b2 [512]byte
|
2022-06-23 14:01:39 +01:00
|
|
|
res, _, _ := vmGetParamString.Call(
|
2022-06-22 20:51:25 +01:00
|
|
|
uintptr(unsafe.Pointer(&b1[0])),
|
|
|
|
uintptr(unsafe.Pointer(&b2[0])),
|
|
|
|
)
|
2022-12-08 10:26:19 +00:00
|
|
|
if int32(res) != 0 {
|
|
|
|
err := fmt.Errorf("VBVMR_GetParameterStringA returned %d", int32(res))
|
2022-09-07 20:59:55 +01:00
|
|
|
return "", err
|
2022-06-22 20:51:25 +01:00
|
|
|
}
|
|
|
|
str := bytes.Trim(b2[:], "\x00")
|
2022-09-07 20:59:55 +01:00
|
|
|
return string(str), nil
|
2022-06-22 20:51:25 +01:00
|
|
|
}
|
|
|
|
|
2022-09-07 20:59:55 +01:00
|
|
|
// setParameterString sets the value of a string parameter
|
|
|
|
func setParameterString(name, value string) error {
|
2022-06-22 20:51:25 +01:00
|
|
|
b1 := append([]byte(name), 0)
|
|
|
|
b2 := append([]byte(value), 0)
|
2022-06-23 14:01:39 +01:00
|
|
|
res, _, _ := vmSetParamString.Call(
|
2022-06-22 20:51:25 +01:00
|
|
|
uintptr(unsafe.Pointer(&b1[0])),
|
|
|
|
uintptr(unsafe.Pointer(&b2[0])),
|
|
|
|
)
|
2022-12-08 10:26:19 +00:00
|
|
|
if int32(res) != 0 {
|
|
|
|
err := fmt.Errorf("VBVMR_SetParameterStringA returned %d", int32(res))
|
2022-09-07 20:59:55 +01:00
|
|
|
return err
|
2022-06-22 20:51:25 +01:00
|
|
|
}
|
2022-09-07 20:59:55 +01:00
|
|
|
return nil
|
2022-06-22 20:51:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// setParametersMulti sets multiple parameters with a script
|
2022-09-07 20:59:55 +01:00
|
|
|
func setParametersMulti(script string) error {
|
2022-06-22 20:51:25 +01:00
|
|
|
b1 := append([]byte(script), 0)
|
2022-06-23 14:01:39 +01:00
|
|
|
res, _, _ := vmSetParameters.Call(
|
2022-06-22 20:51:25 +01:00
|
|
|
uintptr(unsafe.Pointer(&b1[0])),
|
|
|
|
)
|
2022-12-08 10:26:19 +00:00
|
|
|
if int32(res) != 0 {
|
|
|
|
err := fmt.Errorf("VBVMR_SetParameters returned %d", int32(res))
|
2022-09-07 20:59:55 +01:00
|
|
|
return err
|
2022-06-22 20:51:25 +01:00
|
|
|
}
|
2022-09-07 20:59:55 +01:00
|
|
|
return nil
|
2022-06-22 20:51:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// getMacroStatus gets a macrobutton value
|
2022-09-14 00:58:05 +01:00
|
|
|
func getMacroStatus(id, mode int) (float64, error) {
|
2022-09-14 16:05:15 +01:00
|
|
|
if vmsync {
|
|
|
|
time.Sleep(time.Duration(vmdelay) * time.Millisecond)
|
2022-12-08 10:26:19 +00:00
|
|
|
clear()
|
2022-09-14 16:05:15 +01:00
|
|
|
}
|
2022-06-22 20:51:25 +01:00
|
|
|
var state float32
|
2022-06-23 14:01:39 +01:00
|
|
|
res, _, _ := vmGetMacroStatus.Call(
|
2022-06-22 20:51:25 +01:00
|
|
|
uintptr(id),
|
|
|
|
uintptr(unsafe.Pointer(&state)),
|
|
|
|
uintptr(mode),
|
|
|
|
)
|
2022-12-08 10:26:19 +00:00
|
|
|
if int32(res) != 0 {
|
|
|
|
err := fmt.Errorf("VBVMR_MacroButton_GetStatus returned %d", int32(res))
|
2022-09-07 20:59:55 +01:00
|
|
|
return 0, err
|
2022-06-22 20:51:25 +01:00
|
|
|
}
|
2022-09-14 00:58:05 +01:00
|
|
|
return float64(state), nil
|
2022-06-22 20:51:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// setMacroStatus sets a macrobutton value
|
2022-09-07 20:59:55 +01:00
|
|
|
func setMacroStatus(id, state, mode int) error {
|
2022-06-23 14:01:39 +01:00
|
|
|
res, _, _ := vmSetMacroStatus.Call(
|
2022-06-22 20:51:25 +01:00
|
|
|
uintptr(id),
|
|
|
|
uintptr(state),
|
|
|
|
uintptr(mode),
|
|
|
|
)
|
2022-12-08 10:26:19 +00:00
|
|
|
if int32(res) != 0 {
|
|
|
|
err := fmt.Errorf("VBVMR_MacroButton_SetStatus returned %d", int32(res))
|
2022-09-07 20:59:55 +01:00
|
|
|
return err
|
2022-06-22 20:51:25 +01:00
|
|
|
}
|
2022-09-07 20:59:55 +01:00
|
|
|
return nil
|
2022-06-22 20:51:25 +01:00
|
|
|
}
|
|
|
|
|
2022-07-10 23:08:14 +01:00
|
|
|
// getNumDevices returns the number of hardware input/output devices
|
|
|
|
func getNumDevices(dir string) uint64 {
|
2022-06-28 16:29:13 +01:00
|
|
|
if strings.Compare(dir, "in") == 0 {
|
|
|
|
res, _, _ := vmGetDevNumIn.Call()
|
|
|
|
return uint64(res)
|
|
|
|
} else {
|
|
|
|
res, _, _ := vmGetDevNumOut.Call()
|
|
|
|
return uint64(res)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-10 23:08:14 +01:00
|
|
|
// getDeviceDescription returns name, driver type and hwid for a given device
|
2022-09-07 20:59:55 +01:00
|
|
|
func getDeviceDescription(i int, dir string) (string, uint64, string, error) {
|
2022-06-28 16:29:13 +01:00
|
|
|
var t_ uint64
|
|
|
|
var b1 [512]byte
|
|
|
|
var b2 [512]byte
|
|
|
|
if strings.Compare(dir, "in") == 0 {
|
|
|
|
res, _, _ := vmGetDevDescIn.Call(
|
|
|
|
uintptr(i),
|
|
|
|
uintptr(unsafe.Pointer(&t_)),
|
|
|
|
uintptr(unsafe.Pointer(&b1[0])),
|
|
|
|
uintptr(unsafe.Pointer(&b2[0])),
|
|
|
|
)
|
2022-12-08 10:26:19 +00:00
|
|
|
if int32(res) != 0 {
|
|
|
|
err := fmt.Errorf("VBVMR_Input_GetDeviceDescA returned %d", int32(res))
|
2022-09-07 20:59:55 +01:00
|
|
|
return "", 0, "", err
|
2022-06-28 16:29:13 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
res, _, _ := vmGetDevDescOut.Call(
|
|
|
|
uintptr(i),
|
|
|
|
uintptr(unsafe.Pointer(&t_)),
|
|
|
|
uintptr(unsafe.Pointer(&b1[0])),
|
|
|
|
uintptr(unsafe.Pointer(&b2[0])),
|
|
|
|
)
|
2022-12-08 10:26:19 +00:00
|
|
|
if int32(res) != 0 {
|
|
|
|
err := fmt.Errorf("VBVMR_Output_GetDeviceDescA returned %d", int32(res))
|
2022-09-07 20:59:55 +01:00
|
|
|
return "", 0, "", err
|
2022-06-28 16:29:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
name := bytes.Trim(b1[:], "\x00")
|
|
|
|
hwid := bytes.Trim(b2[:], "\x00")
|
2022-09-07 20:59:55 +01:00
|
|
|
return string(name), t_, string(hwid), nil
|
2022-06-28 16:29:13 +01:00
|
|
|
}
|
|
|
|
|
2022-06-22 20:51:25 +01:00
|
|
|
// getLevel returns a single level value of type type_ for channel[i]
|
2022-09-14 00:58:05 +01:00
|
|
|
func getLevel(type_, i int) (float64, error) {
|
2022-10-04 20:18:26 +01:00
|
|
|
var val float32
|
2022-06-30 20:08:46 +01:00
|
|
|
res, _, _ := vmGetLevelFloat.Call(
|
2022-06-22 20:51:25 +01:00
|
|
|
uintptr(type_),
|
|
|
|
uintptr(i),
|
|
|
|
uintptr(unsafe.Pointer(&val)),
|
|
|
|
)
|
2022-12-08 10:26:19 +00:00
|
|
|
if int32(res) != 0 {
|
|
|
|
err := fmt.Errorf("VBVMR_GetLevel returned %d", int32(res))
|
2022-09-07 20:59:55 +01:00
|
|
|
return 0, err
|
2022-06-22 20:51:25 +01:00
|
|
|
}
|
2022-10-04 20:18:26 +01:00
|
|
|
return float64(val), nil
|
2022-06-22 20:51:25 +01:00
|
|
|
}
|
2022-08-22 22:28:11 +01:00
|
|
|
|
|
|
|
// getMidiMessage gets midi channel, pitch and velocity for a single midi input
|
2022-12-08 10:26:19 +00:00
|
|
|
func getMidiMessage() (bool, error) {
|
2022-08-22 22:28:11 +01:00
|
|
|
var midi = newMidi()
|
|
|
|
var b1 [1024]byte
|
|
|
|
res, _, _ := vmGetMidiMessage.Call(
|
|
|
|
uintptr(unsafe.Pointer(&b1[0])),
|
|
|
|
uintptr(1024),
|
|
|
|
)
|
2022-12-08 10:26:19 +00:00
|
|
|
x := int32(res)
|
2022-08-23 14:03:07 +01:00
|
|
|
if x < 0 {
|
2022-12-08 10:26:19 +00:00
|
|
|
if x == -2 {
|
|
|
|
err := fmt.Errorf("VBVMR_GetMidiMessage returned %d", int32(res))
|
|
|
|
if err != nil {
|
|
|
|
log.Error(err)
|
|
|
|
return false, err
|
|
|
|
}
|
2022-09-07 20:59:55 +01:00
|
|
|
}
|
2022-08-22 22:28:11 +01:00
|
|
|
}
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
2022-12-08 10:26:19 +00:00
|
|
|
return len(msg) > 0, nil
|
2022-08-22 22:28:11 +01:00
|
|
|
}
|