8 Commits

Author SHA1 Message Date
onyx-and-iris
8bb8336599 interactive mode added to vm-cli example
toggle, get and set refactored into separate functions

flag vars moved from global  scope

-i flag added to README
2022-10-04 20:56:38 +01:00
onyx-and-iris
5b3f10c4b8 print bus level values in observer example 2022-10-04 20:18:48 +01:00
onyx-and-iris
7022c5dacf fix type error in getLevel 2022-10-04 20:18:26 +01:00
onyx-and-iris
5bb7eb9668 remove logrus from vm-cli 2022-09-29 19:04:32 +01:00
onyx-and-iris
5e5a82f198 upd -v flag description 2022-09-29 18:31:15 +01:00
onyx-and-iris
d8de82b90e add note to install in vm-cli 2022-09-29 18:27:26 +01:00
onyx-and-iris
5b4592f484 upd dep ver for obs, hotkeys examples 2022-09-29 18:25:23 +01:00
onyx-and-iris
b2dd96abc4 add install to vm-cli readme 2022-09-29 18:17:23 +01:00
9 changed files with 122 additions and 62 deletions

View File

@@ -315,7 +315,7 @@ func getDeviceDescription(i int, dir string) (string, uint64, string, error) {
// getLevel returns a single level value of type type_ for channel[i]
func getLevel(type_, i int) (float64, error) {
var val float64
var val float32
res, _, _ := vmGetLevelFloat.Call(
uintptr(type_),
uintptr(i),
@@ -325,7 +325,7 @@ func getLevel(type_, i int) (float64, error) {
err := fmt.Errorf("VBVMR_GetLevel returned %d", res)
return 0, err
}
return val, nil
return float64(val), nil
}
// getMidiMessage gets midi channel, pitch and velocity for a single midi input

View File

@@ -4,7 +4,7 @@ go 1.19
require (
github.com/eiannone/keyboard v0.0.0-20220611211555-0d226195f203
github.com/onyx-and-iris/voicemeeter v1.9.0
github.com/onyx-and-iris/voicemeeter v1.10.0
github.com/sirupsen/logrus v1.9.0
)

View File

@@ -5,6 +5,8 @@ github.com/eiannone/keyboard v0.0.0-20220611211555-0d226195f203 h1:XBBHcIb256gUJ
github.com/eiannone/keyboard v0.0.0-20220611211555-0d226195f203/go.mod h1:E1jcSv8FaEny+OP/5k9UxZVw9YFWGj7eI4KR/iOBqCg=
github.com/onyx-and-iris/voicemeeter v1.9.0 h1:4LbPP9iUj/P6FPymYqyh94ysfdvOunex+i2wUDSDn6s=
github.com/onyx-and-iris/voicemeeter v1.9.0/go.mod h1:bBWCYzL//4QmH4VL3TNpNIj9W89Oa+E6J5hgyt27mKg=
github.com/onyx-and-iris/voicemeeter v1.10.0 h1:FIavzL0p33c2fyzOCtuofFOCvIv+8DrL3jFMoTr5/io=
github.com/onyx-and-iris/voicemeeter v1.10.0/go.mod h1:LayUoN/MWSqKXSOGQ7AcLvwoefsL+zQ9CjncLs3WqsU=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0=

View File

@@ -5,7 +5,7 @@ go 1.18
require (
github.com/BurntSushi/toml v1.2.0
github.com/andreykaipov/goobs v0.10.0
github.com/onyx-and-iris/voicemeeter v1.9.0
github.com/onyx-and-iris/voicemeeter v1.10.0
github.com/sirupsen/logrus v1.9.0
)

View File

@@ -15,6 +15,8 @@ github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d h1:VhgPp6v9qf9Agr/
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d/go.mod h1:YUTz3bUH2ZwIWBy3CJBeOBEugqcmXREj14T+iG/4k4U=
github.com/onyx-and-iris/voicemeeter v1.9.0 h1:4LbPP9iUj/P6FPymYqyh94ysfdvOunex+i2wUDSDn6s=
github.com/onyx-and-iris/voicemeeter v1.9.0/go.mod h1:bBWCYzL//4QmH4VL3TNpNIj9W89Oa+E6J5hgyt27mKg=
github.com/onyx-and-iris/voicemeeter v1.10.0 h1:FIavzL0p33c2fyzOCtuofFOCvIv+8DrL3jFMoTr5/io=
github.com/onyx-and-iris/voicemeeter v1.10.0/go.mod h1:LayUoN/MWSqKXSOGQ7AcLvwoefsL+zQ9CjncLs3WqsU=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0=

View File

@@ -42,16 +42,11 @@ func (o observer) OnUpdate(subject string) {
var val = o.vm.Midi.Get(current)
fmt.Printf("Value of midi button %d: %d\n", current, val)
} 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(),
o.vm.Bus[2].Levels().IsDirty(),
o.vm.Bus[3].Levels().IsDirty(),
o.vm.Bus[4].Levels().IsDirty(),
o.vm.Bus[5].Levels().IsDirty(),
o.vm.Bus[6].Levels().IsDirty(),
o.vm.Bus[7].Levels().IsDirty(),
)
for _, bus := range o.vm.Bus {
if bus.Levels().IsDirty() {
fmt.Println(bus, bus.Levels().All())
}
}
}
}

View File

@@ -2,19 +2,24 @@
A simple voicemeeter-cli program. Offers ability to toggle, get and set parameters.
## Install
First build and install it with `go install` (skip this step if using binary from [Releases](https://github.com/onyx-and-iris/voicemeeter/releases))
## Use
Toggle with `!` prefix, get by excluding `=` and set by including `=`. Mix and match arguments.
You may pass the following optional flags:
- -v: (-verbose) to toggle console output. Defaults to false.
- -v: (-verbose) to toggle console output.
- -i: (-interactive) to toggle interactive mode.
- -k: (-kind) to set the kind of Voicemeeter. Defaults to banana.
- -d: (-delay) to set a delay on the getters. Defaults to 20ms.
for example:
`go run .\main.go -v -k=potato -d=25 strip[0].mute=0 strip[0].mute !strip[0].mute strip[0].mute bus[0].gain=-8.8 command.lock=1`
`vm-cli.exe -v -k=potato -d=25 strip[0].mute=0 strip[0].mute !strip[0].mute strip[0].mute bus[0].gain=-8.8 command.lock=1`
Expected output:

View File

@@ -1,28 +1,32 @@
package main
import (
"bufio"
"flag"
"fmt"
"log"
"os"
"strings"
log "github.com/sirupsen/logrus"
"github.com/onyx-and-iris/voicemeeter"
)
func main() {
var (
kind string
delay int
verbose bool
interactive bool
)
func main() {
flag.StringVar(&kind, "kind", "banana", "kind of voicemeeter")
flag.StringVar(&kind, "k", "banana", "kind of voicemeeter (shorthand)")
flag.IntVar(&delay, "delay", 20, "delay between commands")
flag.IntVar(&delay, "d", 20, "delay between commands (shorthand)")
flag.BoolVar(&verbose, "verbose", false, "toggle console output")
flag.BoolVar(&verbose, "v", false, "toggle console output (shorthand)")
flag.BoolVar(&interactive, "interactive", false, "toggle interactive mode")
flag.BoolVar(&interactive, "i", false, "toggle interactive mode (shorthand)")
flag.Parse()
vm, err := vmConnect(kind, delay)
@@ -31,7 +35,7 @@ func main() {
}
defer vm.Logout()
err = runCommands(vm, verbose)
err = runCommands(vm, verbose, interactive)
if err != nil {
fmt.Println(err)
}
@@ -51,45 +55,97 @@ func vmConnect(kind string, delay int) (*voicemeeter.Remote, error) {
return vm, nil
}
func runCommands(vm *voicemeeter.Remote, verbose bool) error {
func runCommands(vm *voicemeeter.Remote, verbose, interactive bool) error {
if interactive {
return interactiveMode(vm, verbose)
}
for _, arg := range flag.Args() {
if arg[0] == '!' {
val, err := vm.GetFloat(arg[1:])
err := parse(vm, arg, verbose)
if err != nil {
err = fmt.Errorf("unable to toggle %s", arg[1:])
return err
}
vm.SetFloat(arg[1:], 1-val)
if verbose {
fmt.Println("Toggling", arg[1:])
}
} else {
if strings.Contains(arg, "=") {
if verbose {
fmt.Println("Running command", arg)
return nil
}
err := vm.SendText(arg)
func interactiveMode(vm *voicemeeter.Remote, verbose bool) error {
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
input := scanner.Text()
if input == "q" || input == "quit" || input == "" {
return nil
}
for _, cmd := range strings.Split(input, " ") {
err := parse(vm, cmd, verbose)
if err != nil {
err = fmt.Errorf("unable to set %s", arg)
return err
}
} else {
valF, err := vm.GetFloat(arg)
if err != nil {
valS, err := vm.GetString(arg)
if err != nil {
err = fmt.Errorf("unable to get %s", arg)
return err
}
if verbose {
fmt.Println("Value of", arg, "is:", valS)
}
} else {
if verbose {
fmt.Println("Value of", arg, "is:", valF)
}
}
}
}
}
return nil
}
func parse(vm *voicemeeter.Remote, cmd string, verbose bool) error {
if cmd[0] == '!' {
err := toggleCmd(vm, cmd[1:], verbose)
if err != nil {
return err
}
} else {
if strings.Contains(cmd, "=") {
err := setCmd(vm, cmd, verbose)
if err != nil {
return err
}
} else {
err := getCmd(vm, cmd, verbose)
if err != nil {
return err
}
}
}
return nil
}
func toggleCmd(vm *voicemeeter.Remote, cmd string, verbose bool) error {
val, err := vm.GetFloat(cmd)
if err != nil {
err = fmt.Errorf("unable to toggle %s", cmd)
return err
}
vm.SetFloat(cmd[1:], 1-val)
if verbose {
fmt.Println("Toggling", cmd)
}
return nil
}
func setCmd(vm *voicemeeter.Remote, cmd string, verbose bool) error {
if verbose {
fmt.Println("Running command", cmd)
}
err := vm.SendText(cmd)
if err != nil {
err = fmt.Errorf("unable to set %s", cmd)
return err
}
return nil
}
func getCmd(vm *voicemeeter.Remote, cmd string, verbose bool) error {
valF, err := vm.GetFloat(cmd)
if err != nil {
valS, err := vm.GetString(cmd)
if err != nil {
err = fmt.Errorf("unable to get %s", cmd)
return err
}
if verbose {
fmt.Println("Value of", cmd, "is:", valS)
}
} else {
if verbose {
fmt.Println("Value of", cmd, "is:", valF)
}
}
return nil

View File

@@ -28,8 +28,8 @@ func roundFloat(val float64, precision uint) float64 {
// convertLevel performs the necessary math for a channel level
func convertLevel(i float64) float64 {
if i > 0 {
val := 20 * math.Log10(float64(i))
return float64(roundFloat(float64(val), 1))
val := 20 * math.Log10(i)
return roundFloat(val, 1)
}
return -200.0
}