mirror of
https://github.com/onyx-and-iris/voicemeeter.git
synced 2024-11-15 17:40:51 +00:00
return values for CAPI calls fixed.
Polling functions now return error types
This commit is contained in:
parent
4c54d924b3
commit
62b4956279
128
base.go
128
base.go
@ -55,8 +55,7 @@ func login(kindId string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
log.Info("Logged into Voicemeeter ", kindId)
|
log.Info("Logged into Voicemeeter ", kindId)
|
||||||
for pdirty() || mdirty() {
|
clear()
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,8 +64,8 @@ func login(kindId string) error {
|
|||||||
func logout(kindId string) error {
|
func logout(kindId string) error {
|
||||||
time.Sleep(100 * time.Millisecond)
|
time.Sleep(100 * time.Millisecond)
|
||||||
res, _, _ := vmLogout.Call()
|
res, _, _ := vmLogout.Call()
|
||||||
if res != 0 {
|
if int32(res) != 0 {
|
||||||
err := fmt.Errorf("VBVMR_Logout returned %d", res)
|
err := fmt.Errorf("VBVMR_Logout returned %d", int32(res))
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
log.Info("Logged out of Voicemeeter ", kindId)
|
log.Info("Logged out of Voicemeeter ", kindId)
|
||||||
@ -81,8 +80,8 @@ func runVoicemeeter(kindId string) error {
|
|||||||
"potato": 3,
|
"potato": 3,
|
||||||
}
|
}
|
||||||
res, _, _ := vmRunvm.Call(uintptr(vals[kindId]))
|
res, _, _ := vmRunvm.Call(uintptr(vals[kindId]))
|
||||||
if res != 0 {
|
if int32(res) != 0 {
|
||||||
err := fmt.Errorf("VBVMR_RunVoicemeeter returned %d", res)
|
err := fmt.Errorf("VBVMR_RunVoicemeeter returned %d", int32(res))
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@ -92,8 +91,8 @@ func runVoicemeeter(kindId string) error {
|
|||||||
func getVersion() (string, error) {
|
func getVersion() (string, error) {
|
||||||
var ver uint64
|
var ver uint64
|
||||||
res, _, _ := vmGetvmVersion.Call(uintptr(unsafe.Pointer(&ver)))
|
res, _, _ := vmGetvmVersion.Call(uintptr(unsafe.Pointer(&ver)))
|
||||||
if res != 0 {
|
if int32(res) != 0 {
|
||||||
err := fmt.Errorf("VBVMR_GetVoicemeeterVersion returned %d", res)
|
err := fmt.Errorf("VBVMR_GetVoicemeeterVersion returned %d", int32(res))
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
v1 := (ver & 0xFF000000) >> 24
|
v1 := (ver & 0xFF000000) >> 24
|
||||||
@ -104,33 +103,61 @@ func getVersion() (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// pdirty returns true iff a parameter value has changed
|
// pdirty returns true iff a parameter value has changed
|
||||||
func pdirty() bool {
|
func pdirty() (bool, error) {
|
||||||
res, _, _ := vmPdirty.Call()
|
res, _, _ := vmPdirty.Call()
|
||||||
return int(res) == 1
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
// mdirty returns true iff a macrobutton value has changed
|
// mdirty returns true iff a macrobutton value has changed
|
||||||
func mdirty() bool {
|
func mdirty() (bool, error) {
|
||||||
res, _, _ := vmMdirty.Call()
|
res, _, _ := vmMdirty.Call()
|
||||||
return int(res) == 1
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
// ldirty returns true iff a level value has changed
|
// ldirty returns true iff a level value has changed
|
||||||
func ldirty(k *kind) bool {
|
func ldirty(k *kind) (bool, error) {
|
||||||
_levelCache.stripLevelsBuff = make([]float64, (2*k.PhysIn)+(8*k.VirtIn))
|
_levelCache.stripLevelsBuff = make([]float64, (2*k.PhysIn)+(8*k.VirtIn))
|
||||||
_levelCache.busLevelsBuff = make([]float64, 8*k.NumBus())
|
_levelCache.busLevelsBuff = make([]float64, 8*k.NumBus())
|
||||||
|
|
||||||
for i := 0; i < (2*k.PhysIn)+(8*k.VirtIn); i++ {
|
for i := 0; i < (2*k.PhysIn)+(8*k.VirtIn); i++ {
|
||||||
val, _ := getLevel(_levelCache.stripMode, i)
|
val, err := getLevel(_levelCache.stripMode, i)
|
||||||
|
if err != nil {
|
||||||
|
log.Error(err.Error())
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
_levelCache.stripLevelsBuff[i] = val
|
_levelCache.stripLevelsBuff[i] = val
|
||||||
_levelCache.stripComp[i] = _levelCache.stripLevelsBuff[i] == _levelCache.stripLevels[i]
|
_levelCache.stripComp[i] = _levelCache.stripLevelsBuff[i] == _levelCache.stripLevels[i]
|
||||||
}
|
}
|
||||||
for i := 0; i < 8*k.NumBus(); i++ {
|
for i := 0; i < 8*k.NumBus(); i++ {
|
||||||
val, _ := getLevel(3, i)
|
val, err := getLevel(3, i)
|
||||||
|
if err != nil {
|
||||||
|
log.Error(err.Error())
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
_levelCache.busLevelsBuff[i] = val
|
_levelCache.busLevelsBuff[i] = val
|
||||||
_levelCache.busComp[i] = _levelCache.busLevelsBuff[i] == _levelCache.busLevels[i]
|
_levelCache.busComp[i] = _levelCache.busLevelsBuff[i] == _levelCache.busLevels[i]
|
||||||
}
|
}
|
||||||
return !(allTrue(_levelCache.stripComp, (2*k.PhysIn)+(8*k.VirtIn)) && allTrue(_levelCache.busComp, 8*k.NumBus()))
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// getVMType returns the type of Voicemeeter, as a string
|
// getVMType returns the type of Voicemeeter, as a string
|
||||||
@ -139,8 +166,8 @@ func getVMType() (string, error) {
|
|||||||
res, _, _ := vmGetvmType.Call(
|
res, _, _ := vmGetvmType.Call(
|
||||||
uintptr(unsafe.Pointer(&type_)),
|
uintptr(unsafe.Pointer(&type_)),
|
||||||
)
|
)
|
||||||
if res != 0 {
|
if int32(res) != 0 {
|
||||||
err := fmt.Errorf("VBVMR_GetVoicemeeterType returned %d", res)
|
err := fmt.Errorf("VBVMR_GetVoicemeeterType returned %d", int32(res))
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
vals := map[uint64]string{
|
vals := map[uint64]string{
|
||||||
@ -155,8 +182,7 @@ func getVMType() (string, error) {
|
|||||||
func getParameterFloat(name string) (float64, error) {
|
func getParameterFloat(name string) (float64, error) {
|
||||||
if vmsync {
|
if vmsync {
|
||||||
time.Sleep(time.Duration(vmdelay) * time.Millisecond)
|
time.Sleep(time.Duration(vmdelay) * time.Millisecond)
|
||||||
for pdirty() || mdirty() {
|
clear()
|
||||||
}
|
|
||||||
}
|
}
|
||||||
var value float32
|
var value float32
|
||||||
b := append([]byte(name), 0)
|
b := append([]byte(name), 0)
|
||||||
@ -164,8 +190,8 @@ func getParameterFloat(name string) (float64, error) {
|
|||||||
uintptr(unsafe.Pointer(&b[0])),
|
uintptr(unsafe.Pointer(&b[0])),
|
||||||
uintptr(unsafe.Pointer(&value)),
|
uintptr(unsafe.Pointer(&value)),
|
||||||
)
|
)
|
||||||
if res != 0 {
|
if int32(res) != 0 {
|
||||||
err := fmt.Errorf("VBVMR_GetParameterFloat returned %d", res)
|
err := fmt.Errorf("VBVMR_GetParameterFloat returned %d", int32(res))
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
return math.Round(float64(value)*10) / 10, nil
|
return math.Round(float64(value)*10) / 10, nil
|
||||||
@ -179,8 +205,8 @@ func setParameterFloat(name string, value float64) error {
|
|||||||
uintptr(unsafe.Pointer(&b1[0])),
|
uintptr(unsafe.Pointer(&b1[0])),
|
||||||
uintptr(b2),
|
uintptr(b2),
|
||||||
)
|
)
|
||||||
if res != 0 {
|
if int32(res) != 0 {
|
||||||
err := fmt.Errorf("VBVMR_SetParameterFloat returned %d", res)
|
err := fmt.Errorf("VBVMR_SetParameterFloat returned %d", int32(res))
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@ -190,8 +216,7 @@ func setParameterFloat(name string, value float64) error {
|
|||||||
func getParameterString(name string) (string, error) {
|
func getParameterString(name string) (string, error) {
|
||||||
if vmsync {
|
if vmsync {
|
||||||
time.Sleep(time.Duration(vmdelay) * time.Millisecond)
|
time.Sleep(time.Duration(vmdelay) * time.Millisecond)
|
||||||
for pdirty() || mdirty() {
|
clear()
|
||||||
}
|
|
||||||
}
|
}
|
||||||
b1 := append([]byte(name), 0)
|
b1 := append([]byte(name), 0)
|
||||||
var b2 [512]byte
|
var b2 [512]byte
|
||||||
@ -199,8 +224,8 @@ func getParameterString(name string) (string, error) {
|
|||||||
uintptr(unsafe.Pointer(&b1[0])),
|
uintptr(unsafe.Pointer(&b1[0])),
|
||||||
uintptr(unsafe.Pointer(&b2[0])),
|
uintptr(unsafe.Pointer(&b2[0])),
|
||||||
)
|
)
|
||||||
if res != 0 {
|
if int32(res) != 0 {
|
||||||
err := fmt.Errorf("VBVMR_GetParameterStringA returned %d", res)
|
err := fmt.Errorf("VBVMR_GetParameterStringA returned %d", int32(res))
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
str := bytes.Trim(b2[:], "\x00")
|
str := bytes.Trim(b2[:], "\x00")
|
||||||
@ -215,8 +240,8 @@ func setParameterString(name, value string) error {
|
|||||||
uintptr(unsafe.Pointer(&b1[0])),
|
uintptr(unsafe.Pointer(&b1[0])),
|
||||||
uintptr(unsafe.Pointer(&b2[0])),
|
uintptr(unsafe.Pointer(&b2[0])),
|
||||||
)
|
)
|
||||||
if res != 0 {
|
if int32(res) != 0 {
|
||||||
err := fmt.Errorf("VBVMR_SetParameterStringA returned %d", res)
|
err := fmt.Errorf("VBVMR_SetParameterStringA returned %d", int32(res))
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@ -228,8 +253,8 @@ func setParametersMulti(script string) error {
|
|||||||
res, _, _ := vmSetParameters.Call(
|
res, _, _ := vmSetParameters.Call(
|
||||||
uintptr(unsafe.Pointer(&b1[0])),
|
uintptr(unsafe.Pointer(&b1[0])),
|
||||||
)
|
)
|
||||||
if res != 0 {
|
if int32(res) != 0 {
|
||||||
err := fmt.Errorf("VBVMR_SetParameters returned %d", res)
|
err := fmt.Errorf("VBVMR_SetParameters returned %d", int32(res))
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@ -239,8 +264,7 @@ func setParametersMulti(script string) error {
|
|||||||
func getMacroStatus(id, mode int) (float64, error) {
|
func getMacroStatus(id, mode int) (float64, error) {
|
||||||
if vmsync {
|
if vmsync {
|
||||||
time.Sleep(time.Duration(vmdelay) * time.Millisecond)
|
time.Sleep(time.Duration(vmdelay) * time.Millisecond)
|
||||||
for pdirty() || mdirty() {
|
clear()
|
||||||
}
|
|
||||||
}
|
}
|
||||||
var state float32
|
var state float32
|
||||||
res, _, _ := vmGetMacroStatus.Call(
|
res, _, _ := vmGetMacroStatus.Call(
|
||||||
@ -248,8 +272,8 @@ func getMacroStatus(id, mode int) (float64, error) {
|
|||||||
uintptr(unsafe.Pointer(&state)),
|
uintptr(unsafe.Pointer(&state)),
|
||||||
uintptr(mode),
|
uintptr(mode),
|
||||||
)
|
)
|
||||||
if res != 0 {
|
if int32(res) != 0 {
|
||||||
err := fmt.Errorf("VBVMR_MacroButton_GetStatus returned %d", res)
|
err := fmt.Errorf("VBVMR_MacroButton_GetStatus returned %d", int32(res))
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
return float64(state), nil
|
return float64(state), nil
|
||||||
@ -262,8 +286,8 @@ func setMacroStatus(id, state, mode int) error {
|
|||||||
uintptr(state),
|
uintptr(state),
|
||||||
uintptr(mode),
|
uintptr(mode),
|
||||||
)
|
)
|
||||||
if res != 0 {
|
if int32(res) != 0 {
|
||||||
err := fmt.Errorf("VBVMR_MacroButton_SetStatus returned %d", res)
|
err := fmt.Errorf("VBVMR_MacroButton_SetStatus returned %d", int32(res))
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@ -292,8 +316,8 @@ func getDeviceDescription(i int, dir string) (string, uint64, string, error) {
|
|||||||
uintptr(unsafe.Pointer(&b1[0])),
|
uintptr(unsafe.Pointer(&b1[0])),
|
||||||
uintptr(unsafe.Pointer(&b2[0])),
|
uintptr(unsafe.Pointer(&b2[0])),
|
||||||
)
|
)
|
||||||
if res != 0 {
|
if int32(res) != 0 {
|
||||||
err := fmt.Errorf("VBVMR_Input_GetDeviceDescA returned %d", res)
|
err := fmt.Errorf("VBVMR_Input_GetDeviceDescA returned %d", int32(res))
|
||||||
return "", 0, "", err
|
return "", 0, "", err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -303,8 +327,8 @@ func getDeviceDescription(i int, dir string) (string, uint64, string, error) {
|
|||||||
uintptr(unsafe.Pointer(&b1[0])),
|
uintptr(unsafe.Pointer(&b1[0])),
|
||||||
uintptr(unsafe.Pointer(&b2[0])),
|
uintptr(unsafe.Pointer(&b2[0])),
|
||||||
)
|
)
|
||||||
if res != 0 {
|
if int32(res) != 0 {
|
||||||
err := fmt.Errorf("VBVMR_Output_GetDeviceDescA returned %d", res)
|
err := fmt.Errorf("VBVMR_Output_GetDeviceDescA returned %d", int32(res))
|
||||||
return "", 0, "", err
|
return "", 0, "", err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -321,28 +345,30 @@ func getLevel(type_, i int) (float64, error) {
|
|||||||
uintptr(i),
|
uintptr(i),
|
||||||
uintptr(unsafe.Pointer(&val)),
|
uintptr(unsafe.Pointer(&val)),
|
||||||
)
|
)
|
||||||
if res != 0 {
|
if int32(res) != 0 {
|
||||||
err := fmt.Errorf("VBVMR_GetLevel returned %d", res)
|
err := fmt.Errorf("VBVMR_GetLevel returned %d", int32(res))
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
return float64(val), nil
|
return float64(val), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// getMidiMessage gets midi channel, pitch and velocity for a single midi input
|
// getMidiMessage gets midi channel, pitch and velocity for a single midi input
|
||||||
func getMidiMessage() bool {
|
func getMidiMessage() (bool, error) {
|
||||||
var midi = newMidi()
|
var midi = newMidi()
|
||||||
var b1 [1024]byte
|
var b1 [1024]byte
|
||||||
res, _, _ := vmGetMidiMessage.Call(
|
res, _, _ := vmGetMidiMessage.Call(
|
||||||
uintptr(unsafe.Pointer(&b1[0])),
|
uintptr(unsafe.Pointer(&b1[0])),
|
||||||
uintptr(1024),
|
uintptr(1024),
|
||||||
)
|
)
|
||||||
x := int(res)
|
x := int32(res)
|
||||||
if x < 0 {
|
if x < 0 {
|
||||||
err := fmt.Errorf("VBVMR_GetMidiMessage returned %d", res)
|
if x == -2 {
|
||||||
if err != nil {
|
err := fmt.Errorf("VBVMR_GetMidiMessage returned %d", int32(res))
|
||||||
fmt.Println(err)
|
if err != nil {
|
||||||
|
log.Error(err)
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
msg := bytes.Trim(b1[:], "\x00")
|
msg := bytes.Trim(b1[:], "\x00")
|
||||||
if len(msg) > 0 {
|
if len(msg) > 0 {
|
||||||
@ -359,5 +385,5 @@ func getMidiMessage() bool {
|
|||||||
midi.cache[pitch] = vel
|
midi.cache[pitch] = vel
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return len(msg) > 0
|
return len(msg) > 0, nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user