vm-cli reworked.

now accepts -kind and -delay flags.

arg parsing moved into separate run_commands function.

README added to vm-cli example
This commit is contained in:
onyx-and-iris 2022-09-18 05:39:42 +01:00
parent c05bf500ee
commit 2c6baf20e4
2 changed files with 55 additions and 25 deletions

View File

@ -4,16 +4,22 @@ A simple voicemeeter-cli program. Offers ability to toggle, get and set paramete
## Use
Toggle with `!` prefix, get by excluding `=` and set by including `=`. Mix and match arguments, for example:
Toggle with `!` prefix, get by excluding `=` and set by including `=`. Mix and match arguments.
You may pass an optional flag -kind to set the kind of Voicemeeter. Defaults to banana.
You may pass an optional flag -delay to set a delay on the getters. Defaults to 15ms.
`go run .\main.go strip[0].mute=0 strip[0].mute !strip[0].mute strip[0].mute bus[0].gain=-8.8`
for example:
`go run .\main.go -kind=potato -delay=18 strip[0].mute=0 strip[0].mute !strip[0].mute strip[0].mute bus[0].gain=-8.8 command.lock=1`
Expected output:
```
Logged into Voicemeeter potato
Running command strip[0].mute=0
Value of strip[0].mute is: 0
Toggling strip[0].mute
Value of strip[0].mute is: 1
Running command bus[0].gain=-8.8
Running command command.lock=1
```

View File

@ -1,45 +1,33 @@
package main
import (
"flag"
"fmt"
"log"
"os"
"strings"
"github.com/onyx-and-iris/voicemeeter-api-go"
)
func main() {
vm, err := vmConnect()
kindId := flag.String("kind", "banana", "kind of voicemeeter")
delay := flag.Int("delay", 15, "delay between commands")
flag.Parse()
vm, err := vmConnect(kindId, delay)
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)
}
}
}
err = run_commands(vm)
if err != nil {
fmt.Println(err)
}
}
func vmConnect() (*voicemeeter.Remote, error) {
vm, err := voicemeeter.NewRemote("banana", 15)
func vmConnect(kindId *string, delay *int) (*voicemeeter.Remote, error) {
vm, err := voicemeeter.NewRemote(*kindId, *delay)
if err != nil {
return nil, err
}
@ -51,3 +39,39 @@ func vmConnect() (*voicemeeter.Remote, error) {
return vm, nil
}
func run_commands(vm *voicemeeter.Remote) error {
for _, arg := range flag.Args() {
if arg[0] == '!' {
val, err := vm.GetFloat(arg[1:])
if err != nil {
err = fmt.Errorf("unable to toggle %s", arg[1:])
return err
}
vm.SetFloat(arg[1:], 1-val)
fmt.Println("Toggling", arg[1:])
} else {
if strings.Contains(arg, "=") {
fmt.Println("Running command", arg)
err := vm.SendText(arg)
if err != nil {
err = fmt.Errorf("unable to set %s", arg)
return err
}
} else {
val_f, err := vm.GetFloat(arg)
if err != nil {
val_s, err := vm.GetString(arg)
if err != nil {
err = fmt.Errorf("unable to get %s", arg)
return err
}
fmt.Println("Value of", arg, "is:", val_s)
} else {
fmt.Println("Value of", arg, "is:", val_f)
}
}
}
}
return nil
}