mirror of
https://github.com/onyx-and-iris/voicemeeter.git
synced 2024-11-15 17:40:51 +00:00
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:
parent
c05bf500ee
commit
2c6baf20e4
@ -4,16 +4,22 @@ A simple voicemeeter-cli program. Offers ability to toggle, get and set paramete
|
|||||||
|
|
||||||
## Use
|
## 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:
|
Expected output:
|
||||||
|
|
||||||
```
|
```
|
||||||
|
Logged into Voicemeeter potato
|
||||||
Running command strip[0].mute=0
|
Running command strip[0].mute=0
|
||||||
Value of strip[0].mute is: 0
|
Value of strip[0].mute is: 0
|
||||||
Toggling strip[0].mute
|
Toggling strip[0].mute
|
||||||
Value of strip[0].mute is: 1
|
Value of strip[0].mute is: 1
|
||||||
Running command bus[0].gain=-8.8
|
Running command bus[0].gain=-8.8
|
||||||
|
Running command command.lock=1
|
||||||
```
|
```
|
||||||
|
@ -1,45 +1,33 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/onyx-and-iris/voicemeeter-api-go"
|
"github.com/onyx-and-iris/voicemeeter-api-go"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
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 {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
defer vm.Logout()
|
defer vm.Logout()
|
||||||
|
|
||||||
for _, arg := range os.Args[1:] {
|
err = run_commands(vm)
|
||||||
if arg[0] == '!' {
|
if err != nil {
|
||||||
vm.SetFloat(arg[1:], 1-vm.GetFloat(arg[1:]))
|
fmt.Println(err)
|
||||||
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) {
|
func vmConnect(kindId *string, delay *int) (*voicemeeter.Remote, error) {
|
||||||
vm, err := voicemeeter.NewRemote("banana", 15)
|
vm, err := voicemeeter.NewRemote(*kindId, *delay)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -51,3 +39,39 @@ func vmConnect() (*voicemeeter.Remote, error) {
|
|||||||
|
|
||||||
return vm, nil
|
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
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user