7 Commits

Author SHA1 Message Date
onyx-and-iris
50d045d823 fix ver in changelog 2022-09-07 21:04:14 +01:00
onyx-and-iris
6ed4e38dae changes to error handling
readme, changelog updated to reflect changes

version bump
2022-09-07 20:59:55 +01:00
onyx-and-iris
505b5969a2 go fmt all files.
add midi event toggle to the pooler
2022-08-23 14:03:07 +01:00
onyx-and-iris
7f992a1a87 only check subject once per update 2022-08-23 03:58:49 +01:00
onyx-and-iris
fa8e9f3e76 obs example added. 2022-08-23 03:53:51 +01:00
onyx-and-iris
7a79555cb8 use log.Fatal during setup procedures.
update readme example
2022-08-23 03:35:34 +01:00
onyx-and-iris
6fabc43998 return err from NewRemote\
pass Kind.Name to logout

update examples/tests to reflect changes
2022-08-23 03:16:43 +01:00
16 changed files with 309 additions and 108 deletions

View File

@@ -11,7 +11,15 @@ Before any major/minor/patch bump all unit tests will be run to verify they pass
- [x]
## [1.3.0] - 2022-08-22
## [1.5.0] - 2022-09-07
### Changed
- changes to error handling.
- functions that wrap capi calls now return error types.
- higher level functions print error messages
## [1.4.0] - 2022-08-22
### Added

View File

@@ -42,21 +42,27 @@ package main
import (
"fmt"
"log"
"github.com/onyx-and-iris/voicemeeter-api-go"
)
func main() {
kindId := "banana"
vm := voicemeeter.NewRemote(kindId)
vm, err := voicemeeter.NewRemote(kindId)
if err != nil {
log.Fatal(err)
}
vm.Login()
err = vm.Login()
if err != nil {
log.Fatal(err)
}
defer vm.Logout()
vm.Strip[0].SetLabel("rode podmic")
vm.Strip[0].SetMute(true)
fmt.Printf("Strip 0 (%s) mute was set to %v\n", vm.Strip[0].GetLabel(), vm.Strip[0].GetMute())
vm.Logout()
}
```

114
base.go
View File

@@ -4,7 +4,6 @@ import (
"bytes"
"fmt"
"math"
"os"
"strings"
"syscall"
"time"
@@ -44,36 +43,36 @@ var (
// login logs into the API,
// attempts to launch Voicemeeter if it's not running,
// initializes dirty parameters.
func login(kindId string) {
func login(kindId string) error {
res, _, _ := vmLogin.Call()
if res == 1 {
runVoicemeeter(kindId)
time.Sleep(time.Second)
} else if res != 0 {
err := fmt.Errorf("VBVMR_Login returned %d", res)
fmt.Println(err)
os.Exit(1)
return err
}
fmt.Println("Logged into API")
fmt.Printf("Logged into Voicemeeter %s\n", kindId)
for pdirty() || mdirty() {
}
return nil
}
// logout logs out of the API,
// delayed for 100ms to allow final operation to complete.
func logout() {
func logout(kindId string) error {
time.Sleep(100 * time.Millisecond)
res, _, _ := vmLogout.Call()
if res != 0 {
err := fmt.Errorf("VBVMR_Logout returned %d", res)
fmt.Println(err)
os.Exit(1)
return err
}
fmt.Println("Logged out of API")
fmt.Printf("Logged out of Voicemeeter %s\n", kindId)
return nil
}
// runVoicemeeter attempts to launch a Voicemeeter GUI of a kind.
func runVoicemeeter(kindId string) {
func runVoicemeeter(kindId string) error {
vals := map[string]uint64{
"basic": 1,
"banana": 2,
@@ -82,25 +81,24 @@ func runVoicemeeter(kindId string) {
res, _, _ := vmRunvm.Call(uintptr(vals[kindId]))
if res != 0 {
err := fmt.Errorf("VBVMR_RunVoicemeeter returned %d", res)
fmt.Println(err)
os.Exit(1)
return err
}
return nil
}
// getVersion returns the version of Voicemeeter as a string
func getVersion() string {
func getVersion() (string, error) {
var ver uint64
res, _, _ := vmGetvmVersion.Call(uintptr(unsafe.Pointer(&ver)))
if res != 0 {
err := fmt.Errorf("VBVMR_GetVoicemeeterVersion returned %d", res)
fmt.Println(err)
os.Exit(1)
return "", err
}
v1 := (ver & 0xFF000000) >> 24
v2 := (ver & 0x00FF0000) >> 16
v3 := (ver & 0x0000FF00) >> 8
v4 := ver & 0x000000FF
return fmt.Sprintf("%d.%d.%d.%d", v1, v2, v3, v4)
return fmt.Sprintf("%d.%d.%d.%d", v1, v2, v3, v4), nil
}
// pdirty returns true iff a parameter value has changed
@@ -121,37 +119,38 @@ func ldirty(k *kind) bool {
_levelCache.busLevelsBuff = make([]float32, 8*k.NumBus())
for i := 0; i < (2*k.PhysIn)+(8*k.VirtIn); i++ {
_levelCache.stripLevelsBuff[i] = float32(getLevel(_levelCache.stripMode, i))
val, _ := getLevel(_levelCache.stripMode, i)
_levelCache.stripLevelsBuff[i] = val
_levelCache.stripComp[i] = _levelCache.stripLevelsBuff[i] == _levelCache.stripLevels[i]
}
for i := 0; i < 8*k.NumBus(); i++ {
_levelCache.busLevelsBuff[i] = float32(getLevel(3, i))
val, _ := getLevel(3, i)
_levelCache.busLevelsBuff[i] = val
_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()))
}
// getVMType returns the type of Voicemeeter, as a string
func getVMType() string {
func getVMType() (string, error) {
var type_ uint64
res, _, _ := vmGetvmType.Call(
uintptr(unsafe.Pointer(&type_)),
)
if res != 0 {
err := fmt.Errorf("VBVMR_GetVoicemeeterType returned %d", res)
fmt.Println(err)
os.Exit(1)
return "", err
}
vals := map[uint64]string{
1: "basic",
2: "banana",
3: "potato",
}
return vals[type_]
return vals[type_], nil
}
// getParameterFloat gets the value of a float parameter
func getParameterFloat(name string) float64 {
func getParameterFloat(name string) (float64, error) {
var value float32
b := append([]byte(name), 0)
res, _, _ := vmGetParamFloat.Call(
@@ -160,14 +159,13 @@ func getParameterFloat(name string) float64 {
)
if res != 0 {
err := fmt.Errorf("VBVMR_GetParameterFloat returned %d", res)
fmt.Println(err)
os.Exit(1)
return 0, err
}
return math.Round(float64(value)*10) / 10
return math.Round(float64(value)*10) / 10, nil
}
// setParameterFloat sets the value of a float parameter
func setParameterFloat(name string, value float32) {
func setParameterFloat(name string, value float32) error {
b1 := append([]byte(name), 0)
b2 := math.Float32bits(value)
res, _, _ := vmSetParamFloat.Call(
@@ -176,13 +174,13 @@ func setParameterFloat(name string, value float32) {
)
if res != 0 {
err := fmt.Errorf("VBVMR_SetParameterFloat returned %d", res)
fmt.Println(err)
os.Exit(1)
return err
}
return nil
}
// getParameterString gets the value of a string parameter
func getParameterString(name string) string {
func getParameterString(name string) (string, error) {
b1 := append([]byte(name), 0)
var b2 [512]byte
res, _, _ := vmGetParamString.Call(
@@ -191,15 +189,14 @@ func getParameterString(name string) string {
)
if res != 0 {
err := fmt.Errorf("VBVMR_GetParameterStringA returned %d", res)
fmt.Println(err)
os.Exit(1)
return "", err
}
str := bytes.Trim(b2[:], "\x00")
return string(str)
return string(str), nil
}
// getParameterString sets the value of a string parameter
func setParameterString(name, value string) {
// setParameterString sets the value of a string parameter
func setParameterString(name, value string) error {
b1 := append([]byte(name), 0)
b2 := append([]byte(value), 0)
res, _, _ := vmSetParamString.Call(
@@ -208,26 +205,26 @@ func setParameterString(name, value string) {
)
if res != 0 {
err := fmt.Errorf("VBVMR_SetParameterStringA returned %d", res)
fmt.Println(err)
os.Exit(1)
return err
}
return nil
}
// setParametersMulti sets multiple parameters with a script
func setParametersMulti(script string) {
func setParametersMulti(script string) error {
b1 := append([]byte(script), 0)
res, _, _ := vmSetParameters.Call(
uintptr(unsafe.Pointer(&b1[0])),
)
if res != 0 {
err := fmt.Errorf("VBVMR_SetParameters returned %d", res)
fmt.Println(err)
os.Exit(1)
return err
}
return nil
}
// getMacroStatus gets a macrobutton value
func getMacroStatus(id, mode int) float32 {
func getMacroStatus(id, mode int) (float32, error) {
var state float32
res, _, _ := vmGetMacroStatus.Call(
uintptr(id),
@@ -236,14 +233,13 @@ func getMacroStatus(id, mode int) float32 {
)
if res != 0 {
err := fmt.Errorf("VBVMR_MacroButton_GetStatus returned %d", res)
fmt.Println(err)
os.Exit(1)
return 0, err
}
return state
return state, nil
}
// setMacroStatus sets a macrobutton value
func setMacroStatus(id, state, mode int) {
func setMacroStatus(id, state, mode int) error {
res, _, _ := vmSetMacroStatus.Call(
uintptr(id),
uintptr(state),
@@ -251,9 +247,9 @@ func setMacroStatus(id, state, mode int) {
)
if res != 0 {
err := fmt.Errorf("VBVMR_MacroButton_SetStatus returned %d", res)
fmt.Println(err)
os.Exit(1)
return err
}
return nil
}
// getNumDevices returns the number of hardware input/output devices
@@ -268,7 +264,7 @@ func getNumDevices(dir string) uint64 {
}
// getDeviceDescription returns name, driver type and hwid for a given device
func getDeviceDescription(i int, dir string) (string, uint64, string) {
func getDeviceDescription(i int, dir string) (string, uint64, string, error) {
var t_ uint64
var b1 [512]byte
var b2 [512]byte
@@ -281,8 +277,7 @@ func getDeviceDescription(i int, dir string) (string, uint64, string) {
)
if res != 0 {
err := fmt.Errorf("VBVMR_Input_GetDeviceDescA returned %d", res)
fmt.Println(err)
os.Exit(1)
return "", 0, "", err
}
} else {
res, _, _ := vmGetDevDescOut.Call(
@@ -293,17 +288,16 @@ func getDeviceDescription(i int, dir string) (string, uint64, string) {
)
if res != 0 {
err := fmt.Errorf("VBVMR_Output_GetDeviceDescA returned %d", res)
fmt.Println(err)
os.Exit(1)
return "", 0, "", err
}
}
name := bytes.Trim(b1[:], "\x00")
hwid := bytes.Trim(b2[:], "\x00")
return string(name), t_, string(hwid)
return string(name), t_, string(hwid), nil
}
// getLevel returns a single level value of type type_ for channel[i]
func getLevel(type_, i int) float32 {
func getLevel(type_, i int) (float32, error) {
var val float32
res, _, _ := vmGetLevelFloat.Call(
uintptr(type_),
@@ -312,10 +306,9 @@ func getLevel(type_, i int) float32 {
)
if res != 0 {
err := fmt.Errorf("VBVMR_GetLevel returned %d", res)
fmt.Println(err)
os.Exit(1)
return 0, err
}
return val
return val, nil
}
// getMidiMessage gets midi channel, pitch and velocity for a single midi input
@@ -326,10 +319,13 @@ func getMidiMessage() bool {
uintptr(unsafe.Pointer(&b1[0])),
uintptr(1024),
)
if int(res) < 0 {
x := int(res)
if x < 0 {
err := fmt.Errorf("VBVMR_GetMidiMessage returned %d", res)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
return false
}
msg := bytes.Trim(b1[:], "\x00")
if len(msg) > 0 {

View File

@@ -14,7 +14,11 @@ func newButton(i int) button {
// getter returns the value of a macrobutton parameter
func (m *button) getter(mode int) bool {
return getMacroStatus(m.index, mode) == 1
val, err := getMacroStatus(m.index, mode)
if err != nil {
fmt.Println(err)
}
return val == 1
}
// setter sets the value of a macrobutton parameter

View File

@@ -1,5 +1,7 @@
package voicemeeter
import "fmt"
type devDesc struct {
Name, Type, Hwid string
}
@@ -22,7 +24,10 @@ func (d *device) Outs() int {
}
func (d *device) Input(i int) devDesc {
n, t_, id := getDeviceDescription(i, "in")
n, t_, id, err := getDeviceDescription(i, "in")
if err != nil {
fmt.Println(err)
}
vals := map[uint64]string{
1: "mme",
3: "wdm",
@@ -33,7 +38,10 @@ func (d *device) Input(i int) devDesc {
}
func (d *device) Output(i int) devDesc {
n, t_, id := getDeviceDescription(i, "out")
n, t_, id, err := getDeviceDescription(i, "out")
if err != nil {
fmt.Println(err)
}
vals := map[uint64]string{
1: "mme",
3: "wdm",

16
examples/obs/go.mod Normal file
View File

@@ -0,0 +1,16 @@
module main
go 1.18
require (
github.com/andreykaipov/goobs v0.10.0
github.com/onyx-and-iris/voicemeeter-api-go v1.4.1
)
require (
github.com/buger/jsonparser v1.1.1 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/hashicorp/logutils v1.0.0 // indirect
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d // indirect
golang.org/x/sys v0.0.0-20220708085239-5a0f0661e09d // indirect
)

18
examples/obs/go.sum Normal file
View File

@@ -0,0 +1,18 @@
github.com/andreykaipov/goobs v0.10.0 h1:wa4CxbYu/NqwUmx5E4/baDqYRYEmfHwg2T23RAg3jlU=
github.com/andreykaipov/goobs v0.10.0/go.mod h1:EqG73Uu/4npyhXIWWszgRelNkEeIz+d0slUT6NKWYs4=
github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMUs=
github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/hashicorp/logutils v1.0.0 h1:dLEQVugN8vlakKOUE3ihGLTZJRB4j+M2cdTm/ORI65Y=
github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64=
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d h1:VhgPp6v9qf9Agr/56bj7Y/xa04UccTW04VP0Qed4vnQ=
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d/go.mod h1:YUTz3bUH2ZwIWBy3CJBeOBEugqcmXREj14T+iG/4k4U=
github.com/onyx-and-iris/voicemeeter-api-go v1.4.1 h1:2vGaRGCPwN9PlWspbdkDelsfxWHHkZqxozkd6FOcl28=
github.com/onyx-and-iris/voicemeeter-api-go v1.4.1/go.mod h1:zAdBhHXQ9n37CUbLizbOPmAutyZI8Ncqeu5e9u1Fy14=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
golang.org/x/sys v0.0.0-20220708085239-5a0f0661e09d h1:/m5NbqQelATgoSPVC2Z23sR4kVNokFwDDyWh/3rGY+I=
golang.org/x/sys v0.0.0-20220708085239-5a0f0661e09d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=

81
examples/obs/main.go Normal file
View File

@@ -0,0 +1,81 @@
package main
import (
"fmt"
"log"
"time"
"github.com/onyx-and-iris/voicemeeter-api-go"
"github.com/andreykaipov/goobs"
"github.com/andreykaipov/goobs/api/events"
)
func onStart(vm *voicemeeter.Remote) {
vm.Strip[0].SetMute(true)
vm.Strip[1].SetB1(true)
vm.Strip[2].SetB1(true)
}
func onBrb(vm *voicemeeter.Remote) {
vm.Strip[7].FadeTo(0, 500)
vm.Bus[0].SetMute(true)
}
func onLive(vm *voicemeeter.Remote) {
vm.Strip[0].SetMute(false)
vm.Strip[7].FadeTo(-6, 500)
vm.Strip[7].SetA3(true)
vm.Vban.InStream[0].SetOn(true)
}
func onEnd(vm *voicemeeter.Remote) {
vm.Strip[0].SetMute(true)
vm.Strip[1].SetMute(true)
vm.Strip[1].SetB1(false)
vm.Strip[2].SetMute(true)
vm.Strip[2].SetB1(false)
vm.Vban.InStream[0].SetOn(false)
}
func main() {
vm, err := voicemeeter.NewRemote("potato")
if err != nil {
log.Fatal(err)
}
err = vm.Login()
if err != nil {
log.Fatal(err)
}
defer vm.Logout()
obs, err := goobs.New("localhost:4455", goobs.WithPassword("mystrongpass"))
if err != nil {
log.Fatal(err)
}
defer obs.Disconnect()
version, _ := obs.General.GetVersion()
fmt.Printf("OBS Studio version: %s\n", version.ObsVersion)
fmt.Printf("Websocket server version: %s\n", version.ObsWebSocketVersion)
go obs.Listen(func(event any) {
switch e := event.(type) {
case *events.CurrentProgramSceneChanged:
fmt.Printf("Switched to scene %s\n", e.SceneName)
switch e.SceneName {
case "START":
onStart(vm)
case "BRB":
onBrb(vm)
case "LIVE":
onLive(vm)
case "END":
onEnd(vm)
}
}
})
time.Sleep(30 * time.Second)
}

View File

@@ -2,6 +2,7 @@ package main
import (
"fmt"
"log"
"time"
"github.com/onyx-and-iris/voicemeeter-api-go"
@@ -22,16 +23,13 @@ func (o observer) Deregister() {
func (o observer) OnUpdate(subject string) {
if subject == "pdirty" {
fmt.Println("pdirty!")
}
if subject == "mdirty" {
} else if subject == "mdirty" {
fmt.Println("mdirty!")
}
if subject == "midi" {
} else if subject == "midi" {
var current = o.vm.Midi.Current()
var val = o.vm.Midi.Get(current)
fmt.Printf("Value of midi button %d: %d\n", current, val)
}
if subject == "ldirty" {
} else if subject == "ldirty" {
fmt.Printf("%v %v %v %v %v %v %v %v\n",
o.vm.Bus[0].Levels().IsDirty(),
o.vm.Bus[1].Levels().IsDirty(),
@@ -46,8 +44,16 @@ func (o observer) OnUpdate(subject string) {
}
func main() {
vm := voicemeeter.NewRemote("potato")
vm.Login()
vm, err := voicemeeter.NewRemote("potato")
if err != nil {
log.Fatal(err)
}
err = vm.Login()
if err != nil {
log.Fatal(err)
}
defer vm.Logout()
// enable level updates (disabled by default)
vm.EventAdd("ldirty")
@@ -55,6 +61,4 @@ func main() {
o.Register()
time.Sleep(30 * time.Second)
o.Deregister()
vm.Logout()
}

View File

@@ -1,16 +1,21 @@
package voicemeeter
import (
"log"
"os"
"testing"
"time"
)
var (
vm = NewRemote("potato")
vm, err = NewRemote("potato")
)
func TestMain(m *testing.M) {
if err != nil {
log.Fatal(err)
}
vm.Login()
code := m.Run()
vm.Logout()

View File

@@ -19,7 +19,11 @@ func (ir *iRemote) identifier() string {
// getter_bool returns the value of a boolean parameter
func (ir *iRemote) getter_bool(p string) bool {
param := fmt.Sprintf("%s.%s", ir.identifier(), p)
return getParameterFloat(param) == 1
val, err := getParameterFloat(param)
if err != nil {
fmt.Println(err)
}
return val == 1
}
// setter_bool sets the value of a boolean parameter
@@ -31,41 +35,65 @@ func (ir *iRemote) setter_bool(p string, v bool) {
} else {
value = 0
}
setParameterFloat(param, float32(value))
err := setParameterFloat(param, float32(value))
if err != nil {
fmt.Println(err)
}
}
// getter_int returns the value of an int parameter p
func (ir *iRemote) getter_int(p string) int {
param := fmt.Sprintf("%s.%s", ir.identifier(), p)
return int(getParameterFloat(param))
val, err := getParameterFloat(param)
if err != nil {
fmt.Println(err)
}
return int(val)
}
// setter_int sets the value v of an int parameter p
func (ir *iRemote) setter_int(p string, v int) {
param := fmt.Sprintf("%s.%s", ir.identifier(), p)
setParameterFloat(param, float32(v))
err := setParameterFloat(param, float32(v))
if err != nil {
fmt.Println(err)
}
}
// getter_float returns the value of an int parameter p
func (ir *iRemote) getter_float(p string) float64 {
param := fmt.Sprintf("%s.%s", ir.identifier(), p)
return getParameterFloat(param)
val, err := getParameterFloat(param)
if err != nil {
fmt.Println(err)
}
return val
}
// setter_float sets the value v of an int parameter p
func (ir *iRemote) setter_float(p string, v float32) {
param := fmt.Sprintf("%s.%s", ir.identifier(), p)
setParameterFloat(param, float32(v))
err := setParameterFloat(param, float32(v))
if err != nil {
fmt.Println(err)
}
}
// getter_string returns the value of a string parameter p
func (ir *iRemote) getter_string(p string) string {
param := fmt.Sprintf("%s.%s", ir.identifier(), p)
return getParameterString(param)
val, err := getParameterString(param)
if err != nil {
fmt.Println(err)
}
return val
}
// setter_string sets the value v of a string parameter p
func (ir *iRemote) setter_string(p, v string) {
param := fmt.Sprintf("%s.%s", ir.identifier(), p)
setParameterString(param, v)
err := setParameterString(param, v)
if err != nil {
fmt.Println(err)
}
}

View File

@@ -3,7 +3,7 @@ package voicemeeter
import (
"errors"
"fmt"
"os"
"log"
"path/filepath"
"runtime"
"strings"
@@ -49,8 +49,7 @@ func dllPath() (string, error) {
func getDllPath() string {
path, err := dllPath()
if err != nil {
fmt.Println(err)
os.Exit(1)
log.Fatal(err)
}
return path
}

View File

@@ -119,7 +119,7 @@ func (p *pooler) macrobuttons() {
func (p *pooler) midi() {
for p.run {
if getMidiMessage() {
if p.event.midi && getMidiMessage() {
p.notify("midi")
}
time.Sleep(33 * time.Millisecond)

View File

@@ -2,7 +2,6 @@ package voicemeeter
import (
"fmt"
"os"
)
// A Remote type represents the API for a kind
@@ -27,26 +26,42 @@ func (r *Remote) String() string {
// Login logs into the API
// then it intializes the pooler
func (r *Remote) Login() {
login(r.Kind.Name)
func (r *Remote) Login() error {
err := login(r.Kind.Name)
if err != nil {
return err
}
r.pooler = newPooler(r.Kind)
return nil
}
// Logout logs out of the API
// it also terminates the pooler
func (r *Remote) Logout() {
func (r *Remote) Logout() error {
r.pooler.run = false
logout()
err := logout(r.Kind.Name)
if err != nil {
return err
}
return nil
}
// Type returns the type of Voicemeeter (basic, banana, potato)
func (r *Remote) Type() string {
return getVMType()
val, err := getVMType()
if err != nil {
fmt.Println(err)
}
return val
}
// Version returns the version of Voicemeeter as a string
func (r *Remote) Version() string {
return getVersion()
val, err := getVersion()
if err != nil {
fmt.Println(err)
}
return val
}
// Pdirty returns true iff a parameter value has changed
@@ -61,7 +76,11 @@ func (r *Remote) Mdirty() bool {
// Gets a float parameter value
func (r *Remote) GetFloat(name string) float64 {
return getParameterFloat(name)
val, err := getParameterFloat(name)
if err != nil {
fmt.Println(err)
}
return val
}
// Sets a float paramter value
@@ -71,7 +90,11 @@ func (r *Remote) SetFloat(name string, value float32) {
// Gets a string parameter value
func (r *Remote) GetString(name string) string {
return getParameterString(name)
val, err := getParameterString(name)
if err != nil {
fmt.Println(err)
}
return val
}
// Sets a string paramter value
@@ -289,12 +312,11 @@ func (potb *potatoBuilder) Build() remoteBuilder {
// NewRemote returns a Remote type for a kind
// this is the interface entry point
func NewRemote(kindId string) *Remote {
func NewRemote(kindId string) (*Remote, error) {
_kind, ok := kindMap[kindId]
if !ok {
err := fmt.Errorf("unknown Voicemeeter kind '%s'", kindId)
fmt.Println(err)
os.Exit(1)
return nil, err
}
director := director{}
@@ -307,5 +329,5 @@ func NewRemote(kindId string) *Remote {
director.SetBuilder(&potatoBuilder{genericBuilder{_kind, Remote{}}})
}
director.Construct()
return director.Get()
return director.Get(), nil
}

View File

@@ -8,7 +8,7 @@ import (
func TestGetBasicRemote(t *testing.T) {
//t.Skip("skipping test")
__rem := NewRemote("basic")
__rem, _ := NewRemote("basic")
t.Run("Should return a remote basic type", func(t *testing.T) {
assert.NotNil(t, __rem)
})
@@ -34,7 +34,7 @@ func TestGetBasicRemote(t *testing.T) {
func TestGetBananaRemote(t *testing.T) {
//t.Skip("skipping test")
__rem := NewRemote("banana")
__rem, _ := NewRemote("banana")
t.Run("Should return a remote banana type", func(t *testing.T) {
assert.NotNil(t, __rem)
})
@@ -60,7 +60,7 @@ func TestGetBananaRemote(t *testing.T) {
func TestGetPotatoRemote(t *testing.T) {
//t.Skip("skipping test")
__rem := NewRemote("potato")
__rem, _ := NewRemote("potato")
t.Run("Should return a remote basic type", func(t *testing.T) {
assert.NotNil(t, __rem)
})

View File

@@ -1,6 +1,7 @@
package voicemeeter_test
import (
"log"
"os"
"testing"
"time"
@@ -9,10 +10,15 @@ import (
)
var (
vm = voicemeeter.NewRemote("potato")
vm, err = voicemeeter.NewRemote("potato")
)
func TestMain(m *testing.M) {
if err != nil {
log.Fatal(err)
}
defer vm.Logout()
vm.Login()
code := m.Run()
vm.Logout()