From 6605d6e62d68f16d5ab3f84623a011e059b484d4 Mon Sep 17 00:00:00 2001 From: onyx-and-iris <75868496+onyx-and-iris@users.noreply.github.com> Date: Thu, 29 Sep 2022 18:05:21 +0100 Subject: [PATCH] set log level to info in examples add verbose flag to vm-cli example update readme for vm-cli example --- examples/hotkeys/go.mod | 5 +++-- examples/hotkeys/go.sum | 17 ++++++++++++---- examples/hotkeys/main.go | 7 ++++++- examples/obs/go.mod | 5 +++-- examples/obs/go.sum | 17 ++++++++++++---- examples/obs/main.go | 7 ++++++- examples/observer/main.go | 7 ++++++- examples/vm-cli/README.md | 9 ++++---- examples/vm-cli/main.go | 43 ++++++++++++++++++++++++++++----------- 9 files changed, 86 insertions(+), 31 deletions(-) diff --git a/examples/hotkeys/go.mod b/examples/hotkeys/go.mod index 194416b..86a581e 100644 --- a/examples/hotkeys/go.mod +++ b/examples/hotkeys/go.mod @@ -4,7 +4,8 @@ go 1.19 require ( github.com/eiannone/keyboard v0.0.0-20220611211555-0d226195f203 - github.com/onyx-and-iris/voicemeeter-api-go v1.8.0 + github.com/onyx-and-iris/voicemeeter v1.9.0 + github.com/sirupsen/logrus v1.9.0 ) -require golang.org/x/sys v0.0.0-20220708085239-5a0f0661e09d // indirect +require golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect diff --git a/examples/hotkeys/go.sum b/examples/hotkeys/go.sum index d90803a..2304381 100644 --- a/examples/hotkeys/go.sum +++ b/examples/hotkeys/go.sum @@ -1,10 +1,19 @@ +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/eiannone/keyboard v0.0.0-20220611211555-0d226195f203 h1:XBBHcIb256gUJtLmY22n99HaZTz+r2Z51xUPi01m3wg= github.com/eiannone/keyboard v0.0.0-20220611211555-0d226195f203/go.mod h1:E1jcSv8FaEny+OP/5k9UxZVw9YFWGj7eI4KR/iOBqCg= -github.com/onyx-and-iris/voicemeeter-api-go v1.8.0 h1:uVeKXG3+dnZUakJNZ0RjYFgVhFCzGPoiNnU32LqGR4Y= -github.com/onyx-and-iris/voicemeeter-api-go v1.8.0/go.mod h1:zAdBhHXQ9n37CUbLizbOPmAutyZI8Ncqeu5e9u1Fy14= +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/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= +github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 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= +golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ= +golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/examples/hotkeys/main.go b/examples/hotkeys/main.go index d6aa873..05ea9c8 100644 --- a/examples/hotkeys/main.go +++ b/examples/hotkeys/main.go @@ -2,12 +2,17 @@ package main import ( "fmt" - "log" + + log "github.com/sirupsen/logrus" "github.com/eiannone/keyboard" "github.com/onyx-and-iris/voicemeeter" ) +func init() { + log.SetLevel(log.InfoLevel) +} + func main() { if err := keyboard.Open(); err != nil { log.Fatal(err) diff --git a/examples/obs/go.mod b/examples/obs/go.mod index 3658cb0..710a42d 100644 --- a/examples/obs/go.mod +++ b/examples/obs/go.mod @@ -5,7 +5,8 @@ go 1.18 require ( github.com/BurntSushi/toml v1.2.0 github.com/andreykaipov/goobs v0.10.0 - github.com/onyx-and-iris/voicemeeter-api-go v1.8.0 + github.com/onyx-and-iris/voicemeeter v1.9.0 + github.com/sirupsen/logrus v1.9.0 ) require ( @@ -13,5 +14,5 @@ require ( 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 + golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect ) diff --git a/examples/obs/go.sum b/examples/obs/go.sum index 43ae8bd..3ddf49c 100644 --- a/examples/obs/go.sum +++ b/examples/obs/go.sum @@ -4,17 +4,26 @@ github.com/andreykaipov/goobs v0.10.0 h1:wa4CxbYu/NqwUmx5E4/baDqYRYEmfHwg2T23RAg 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.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 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.8.0 h1:uVeKXG3+dnZUakJNZ0RjYFgVhFCzGPoiNnU32LqGR4Y= -github.com/onyx-and-iris/voicemeeter-api-go v1.8.0/go.mod h1:zAdBhHXQ9n37CUbLizbOPmAutyZI8Ncqeu5e9u1Fy14= +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/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= +github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 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= +golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ= +golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/examples/obs/main.go b/examples/obs/main.go index 42f7671..d0f257f 100644 --- a/examples/obs/main.go +++ b/examples/obs/main.go @@ -2,10 +2,11 @@ package main import ( "fmt" - "log" "os" "time" + log "github.com/sirupsen/logrus" + "github.com/onyx-and-iris/voicemeeter" "github.com/andreykaipov/goobs" @@ -41,6 +42,10 @@ func onEnd(vm *voicemeeter.Remote) { vm.Vban.InStream[0].SetOn(false) } +func init() { + log.SetLevel(log.InfoLevel) +} + func main() { vm, err := vmConnect() if err != nil { diff --git a/examples/observer/main.go b/examples/observer/main.go index bf46a55..7748467 100644 --- a/examples/observer/main.go +++ b/examples/observer/main.go @@ -2,9 +2,10 @@ package main import ( "fmt" - "log" "time" + log "github.com/sirupsen/logrus" + "github.com/onyx-and-iris/voicemeeter" ) @@ -54,6 +55,10 @@ func (o observer) OnUpdate(subject string) { } } +func init() { + log.SetLevel(log.InfoLevel) +} + // main connects to Voiceemeter, registers observer for updates // runs updates for 30 seconds and then deregisters observer. func main() { diff --git a/examples/vm-cli/README.md b/examples/vm-cli/README.md index 6f476ba..e0419b2 100644 --- a/examples/vm-cli/README.md +++ b/examples/vm-cli/README.md @@ -6,18 +6,19 @@ A simple voicemeeter-cli program. Offers ability to toggle, get and set paramete 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 the following optional flags: -You may pass an optional flag -delay to set a delay on the getters. Defaults to 20ms. +- -v: (-verbose) to toggle console output. Defaults to false. +- -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 -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` +`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` Expected output: ``` -Logged into Voicemeeter potato Running command strip[0].mute=0 Value of strip[0].mute is: 0 Toggling strip[0].mute diff --git a/examples/vm-cli/main.go b/examples/vm-cli/main.go index 1d806e6..e3810d8 100644 --- a/examples/vm-cli/main.go +++ b/examples/vm-cli/main.go @@ -3,31 +3,42 @@ package main import ( "flag" "fmt" - "log" "strings" + log "github.com/sirupsen/logrus" + "github.com/onyx-and-iris/voicemeeter" ) +var ( + kind string + delay int + verbose bool +) + func main() { - kindId := flag.String("kind", "banana", "kind of voicemeeter") - delay := flag.Int("delay", 20, "delay between commands") + 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.Parse() - vm, err := vmConnect(kindId, delay) + vm, err := vmConnect(kind, delay) if err != nil { log.Fatal(err) } defer vm.Logout() - err = runCommands(vm) + err = runCommands(vm, verbose) if err != nil { fmt.Println(err) } } -func vmConnect(kindId *string, delay *int) (*voicemeeter.Remote, error) { - vm, err := voicemeeter.NewRemote(*kindId, *delay) +func vmConnect(kind string, delay int) (*voicemeeter.Remote, error) { + vm, err := voicemeeter.NewRemote(kind, delay) if err != nil { return nil, err } @@ -40,7 +51,7 @@ func vmConnect(kindId *string, delay *int) (*voicemeeter.Remote, error) { return vm, nil } -func runCommands(vm *voicemeeter.Remote) error { +func runCommands(vm *voicemeeter.Remote, verbose bool) error { for _, arg := range flag.Args() { if arg[0] == '!' { val, err := vm.GetFloat(arg[1:]) @@ -49,10 +60,14 @@ func runCommands(vm *voicemeeter.Remote) error { return err } vm.SetFloat(arg[1:], 1-val) - fmt.Println("Toggling", arg[1:]) + if verbose { + fmt.Println("Toggling", arg[1:]) + } } else { if strings.Contains(arg, "=") { - fmt.Println("Running command", arg) + if verbose { + fmt.Println("Running command", arg) + } err := vm.SendText(arg) if err != nil { err = fmt.Errorf("unable to set %s", arg) @@ -66,9 +81,13 @@ func runCommands(vm *voicemeeter.Remote) error { err = fmt.Errorf("unable to get %s", arg) return err } - fmt.Println("Value of", arg, "is:", valS) + if verbose { + fmt.Println("Value of", arg, "is:", valS) + } } else { - fmt.Println("Value of", arg, "is:", valF) + if verbose { + fmt.Println("Value of", arg, "is:", valF) + } } } }