add vm-cli example

This commit is contained in:
onyx-and-iris 2022-09-17 03:11:53 +01:00
parent 0a7b8e0662
commit 915e3a9609
3 changed files with 68 additions and 0 deletions

7
examples/vm-cli/go.mod Normal file
View File

@ -0,0 +1,7 @@
module main
go 1.19
require github.com/onyx-and-iris/voicemeeter-api-go v1.7.0
require golang.org/x/sys v0.0.0-20220708085239-5a0f0661e09d // indirect

8
examples/vm-cli/go.sum Normal file
View File

@ -0,0 +1,8 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/onyx-and-iris/voicemeeter-api-go v1.7.0 h1:WA1RGrfaWBOavgY2uoJltzy/rAgvs62PM3qzR+5/jt8=
github.com/onyx-and-iris/voicemeeter-api-go v1.7.0/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=

53
examples/vm-cli/main.go Normal file
View File

@ -0,0 +1,53 @@
package main
import (
"fmt"
"log"
"os"
"strings"
"github.com/onyx-and-iris/voicemeeter-api-go"
)
func main() {
vm, err := vmConnect()
if err != nil {
log.Fatal(err)
}
defer vm.Logout()
for _, arg := range os.Args[1:] {
if arg[0] == '!' {
vm.SetFloat(arg[1:], 1-vm.GetFloat(arg[1:]))
fmt.Println("Toggling", arg[1:])
} else {
if strings.Contains(arg, "=") {
fmt.Println("Running command", arg)
vm.SendText(arg)
} else {
s := strings.Split(arg, ".")
if strings.Contains(s[1], "label") {
val := vm.GetString(arg)
fmt.Println("Value of", arg, "is:", val)
} else {
val := vm.GetFloat(arg)
fmt.Println("Value of", arg, "is:", val)
}
}
}
}
}
func vmConnect() (*voicemeeter.Remote, error) {
vm, err := voicemeeter.NewRemote("banana", 15)
if err != nil {
return nil, err
}
err = vm.Login()
if err != nil {
return nil, err
}
return vm, nil
}