17 Commits

Author SHA1 Message Date
ea6a41bf4f add 2.1.1 to CHANGELOG 2026-04-12 22:40:29 +01:00
30cacfac91 Merge pull request #9 from mdugas/dev
Adding BUS Sel and MonitorOnSel
2026-04-12 15:39:37 +01:00
Mathieu Dugas
2364ea13aa Adding BUS Select and MonitorOnSel 2026-04-12 00:31:34 -04:00
d7aa02e516 Merge pull request #8 from onyx-and-iris/dependabot/go_modules/github.com/sirupsen/logrus-1.9.1
Bump github.com/sirupsen/logrus from 1.9.0 to 1.9.1
2026-03-30 00:46:29 +01:00
dependabot[bot]
b4f0fa4449 Bump github.com/sirupsen/logrus from 1.9.0 to 1.9.1
Bumps [github.com/sirupsen/logrus](https://github.com/sirupsen/logrus) from 1.9.0 to 1.9.1.
- [Release notes](https://github.com/sirupsen/logrus/releases)
- [Changelog](https://github.com/sirupsen/logrus/blob/master/CHANGELOG.md)
- [Commits](https://github.com/sirupsen/logrus/compare/v1.9.0...v1.9.1)

---
updated-dependencies:
- dependency-name: github.com/sirupsen/logrus
  dependency-version: 1.9.1
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-03-29 23:46:01 +00:00
21d61d30e6 Merge pull request #7 from onyx-and-iris/dependabot/go_modules/examples/hotkeys/github.com/sirupsen/logrus-1.9.1
Bump github.com/sirupsen/logrus from 1.9.0 to 1.9.1 in /examples/hotkeys
2026-03-30 00:45:03 +01:00
dependabot[bot]
7b71086d7e Bump github.com/sirupsen/logrus from 1.9.0 to 1.9.1 in /examples/hotkeys
Bumps [github.com/sirupsen/logrus](https://github.com/sirupsen/logrus) from 1.9.0 to 1.9.1.
- [Release notes](https://github.com/sirupsen/logrus/releases)
- [Changelog](https://github.com/sirupsen/logrus/blob/master/CHANGELOG.md)
- [Commits](https://github.com/sirupsen/logrus/compare/v1.9.0...v1.9.1)

---
updated-dependencies:
- dependency-name: github.com/sirupsen/logrus
  dependency-version: 1.9.1
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-03-29 23:44:51 +00:00
943a921889 Merge pull request #6 from onyx-and-iris/dependabot/go_modules/examples/obs/github.com/sirupsen/logrus-1.9.1
Bump github.com/sirupsen/logrus from 1.9.0 to 1.9.1 in /examples/obs
2026-03-30 00:42:19 +01:00
dependabot[bot]
2f07a93c4e Bump github.com/sirupsen/logrus from 1.9.0 to 1.9.1 in /examples/obs
Bumps [github.com/sirupsen/logrus](https://github.com/sirupsen/logrus) from 1.9.0 to 1.9.1.
- [Release notes](https://github.com/sirupsen/logrus/releases)
- [Changelog](https://github.com/sirupsen/logrus/blob/master/CHANGELOG.md)
- [Commits](https://github.com/sirupsen/logrus/compare/v1.9.0...v1.9.1)

---
updated-dependencies:
- dependency-name: github.com/sirupsen/logrus
  dependency-version: 1.9.1
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-03-29 23:41:53 +00:00
dfe3cf5771 Merge pull request #5 from onyx-and-iris/dependabot/go_modules/examples/obs/github.com/buger/jsonparser-1.1.2
Bump github.com/buger/jsonparser from 1.1.1 to 1.1.2 in /examples/obs
2026-03-29 23:30:29 +01:00
dependabot[bot]
e8dc89b4f6 Bump github.com/buger/jsonparser from 1.1.1 to 1.1.2 in /examples/obs
Bumps [github.com/buger/jsonparser](https://github.com/buger/jsonparser) from 1.1.1 to 1.1.2.
- [Release notes](https://github.com/buger/jsonparser/releases)
- [Commits](https://github.com/buger/jsonparser/compare/v1.1.1...v1.1.2)

---
updated-dependencies:
- dependency-name: github.com/buger/jsonparser
  dependency-version: 1.1.2
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2026-03-29 22:29:51 +00:00
0bfc1e62ba define custom usage handler. 2024-07-02 10:54:27 +01:00
6211531f87 fix expected output 2024-07-02 06:57:58 +01:00
c9eaa76f62 fix expected output 2024-07-02 06:55:30 +01:00
1b9d633217 add help dialogue
add guard for toggleCmd to prevent unsafe gain changes.

use logrus for control of log levels.

add an input prompt for interactive mode
2024-07-02 06:50:28 +01:00
359c2d61b5 reword 2024-07-01 07:32:41 +01:00
e586478729 fix WithTimeout name in README
move it above WithBits
2024-07-01 07:23:40 +01:00
11 changed files with 180 additions and 103 deletions

View File

@@ -11,13 +11,21 @@ Before any major/minor/patch bump all unit tests will be run to verify they pass
- [x] - [x]
## [2.1.1] - 2026-04-12
### Added
- {Bus}.Sel()/{Bus}.SetSel() and {Bus}.Monitor()/{Bus}.SetMonitor(). [PR #9](https://github.com/onyx-and-iris/voicemeeter/pull/9)
## [2.1.0] - 2024-07-01 ## [2.1.0] - 2024-07-01
### Added ### Added
- Added a configurable timeout in seconds (defaults to 2). - Added a configurable login timeout in seconds (defaults to 2).
- Option function added for overriding the type of Voicemeeter GUI runVoicemeeter() will launch. - Option function added for overriding the type of Voicemeeter GUI runVoicemeeter() will launch.
- Explanation of Option functions added to README. - Explanation of Option functions added to README.
- {Recorder}.Gain. [PR #4](https://github.com/onyx-and-iris/voicemeeter/pull/4)
### Changed ### Changed

View File

@@ -81,18 +81,18 @@ Pass a delay in milliseconds to force the getters to wait for dirty parameters t
Useful if not listening for event updates. Useful if not listening for event updates.
### `voicemeeter.WithTimeout(timeout int)`
Set a login timeout, defaults to 2 seconds. For example to set it to 1s:
`voicemeeter.NewRemote("banana", 20, voicemeeter.WithTimeout(1))`
### `voicemeeter.WithBits(bits int)` ### `voicemeeter.WithBits(bits int)`
Override the type of Voicemeeter GUI to launch on 64 bit systems. For example, to force 32 bit GUI: Override the type of Voicemeeter GUI to launch on 64 bit systems. For example, to force 32 bit GUI:
`voicemeeter.NewRemote("banana", 20, voicemeeter.WithBits(32))` `voicemeeter.NewRemote("banana", 20, voicemeeter.WithBits(32))`
### `voicemeeter.WithBits(timeout int)`
Set a login timeout, defaults to 2 seconds. For example to set it to 1s:
`voicemeeter.NewRemote("banana", 20, voicemeeter.WithBits(1))`
## `Remote Type` ## `Remote Type`
#### `vm.Strip` #### `vm.Strip`
@@ -336,6 +336,10 @@ The following methods are available
- `SetMute(val bool)` - `SetMute(val bool)`
- `Mono() bool` - `Mono() bool`
- `SetMono(val bool)` - `SetMono(val bool)`
- `Sel() bool`
- `SetSel(val bool)`
- `Monitor() bool`
- `SetMonitor(val bool)`
- `Label() string` - `Label() string`
- `SetLabel(val string)` - `SetLabel(val string)`
- `Gain() float64` - `Gain() float64`

24
bus.go
View File

@@ -12,6 +12,10 @@ type iBus interface {
SetMute(val bool) SetMute(val bool)
Mono() bool Mono() bool
SetMono(val bool) SetMono(val bool)
Sel() bool
SetSel(val bool)
Monitor() bool
SetMonitor(val bool)
Label() string Label() string
SetLabel(val string) SetLabel(val string)
Gain() float64 Gain() float64
@@ -51,6 +55,26 @@ func (b *bus) SetMono(val bool) {
b.setter_bool("Mono", val) b.setter_bool("Mono", val)
} }
// Sel returns the value of the Sel parameter
func (b *bus) Sel() bool {
return b.getter_bool("Sel")
}
// SetSel sets the alue of the Sel parameter
func (b *bus) SetSel(val bool) {
b.setter_bool("Sel", val)
}
// Monitor returns the value of the Monitor parameter
func (b *bus) Monitor() bool {
return b.getter_bool("Monitor")
}
// SetMonitor sets the alue of the Monitor parameter
func (b *bus) SetMonitor(val bool) {
b.setter_bool("Monitor", val)
}
// Label returns the value of the MC parameter // Label returns the value of the MC parameter
func (b *bus) Label() string { func (b *bus) Label() string {
return b.getter_string("Label") return b.getter_string("Label")

View File

@@ -5,7 +5,7 @@ go 1.19
require ( require (
github.com/eiannone/keyboard v0.0.0-20220611211555-0d226195f203 github.com/eiannone/keyboard v0.0.0-20220611211555-0d226195f203
github.com/onyx-and-iris/voicemeeter/v2 v2.0.0 github.com/onyx-and-iris/voicemeeter/v2 v2.0.0
github.com/sirupsen/logrus v1.9.0 github.com/sirupsen/logrus v1.9.1
) )
require golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect require golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect

View File

@@ -7,8 +7,8 @@ github.com/onyx-and-iris/voicemeeter/v2 v2.0.0 h1:AXem+OMeKDuJd2KoLpzHEU70Rx2057
github.com/onyx-and-iris/voicemeeter/v2 v2.0.0/go.mod h1:ULRO0N2Wg7Ymj7CEg4TI7CJobx9yVEZ5Lbh7oWi7woA= github.com/onyx-and-iris/voicemeeter/v2 v2.0.0/go.mod h1:ULRO0N2Wg7Ymj7CEg4TI7CJobx9yVEZ5Lbh7oWi7woA=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 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/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.1 h1:Ou41VVR3nMWWmTiEUnj0OlsgOSCUFgsPAOl6jRIcVtQ=
github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= github.com/sirupsen/logrus v1.9.1/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 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.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=

View File

@@ -6,11 +6,11 @@ require (
github.com/BurntSushi/toml v1.2.0 github.com/BurntSushi/toml v1.2.0
github.com/andreykaipov/goobs v0.10.0 github.com/andreykaipov/goobs v0.10.0
github.com/onyx-and-iris/voicemeeter/v2 v2.0.0 github.com/onyx-and-iris/voicemeeter/v2 v2.0.0
github.com/sirupsen/logrus v1.9.0 github.com/sirupsen/logrus v1.9.1
) )
require ( require (
github.com/buger/jsonparser v1.1.1 // indirect github.com/buger/jsonparser v1.1.2 // indirect
github.com/gorilla/websocket v1.5.0 // indirect github.com/gorilla/websocket v1.5.0 // indirect
github.com/hashicorp/logutils v1.0.0 // indirect github.com/hashicorp/logutils v1.0.0 // indirect
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d // indirect github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d // indirect

View File

@@ -2,8 +2,8 @@ github.com/BurntSushi/toml v1.2.0 h1:Rt8g24XnyGTyglgET/PRUNlrUeu9F5L+7FilkXfZgs0
github.com/BurntSushi/toml v1.2.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/BurntSushi/toml v1.2.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/andreykaipov/goobs v0.10.0 h1:wa4CxbYu/NqwUmx5E4/baDqYRYEmfHwg2T23RAg3jlU= github.com/andreykaipov/goobs v0.10.0 h1:wa4CxbYu/NqwUmx5E4/baDqYRYEmfHwg2T23RAg3jlU=
github.com/andreykaipov/goobs v0.10.0/go.mod h1:EqG73Uu/4npyhXIWWszgRelNkEeIz+d0slUT6NKWYs4= 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.2 h1:frqHqw7otoVbk5M8LlE/L7HTnIq2v9RX6EJ48i9AxJk=
github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0= github.com/buger/jsonparser v1.1.2/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.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 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -17,8 +17,8 @@ github.com/onyx-and-iris/voicemeeter/v2 v2.0.0 h1:AXem+OMeKDuJd2KoLpzHEU70Rx2057
github.com/onyx-and-iris/voicemeeter/v2 v2.0.0/go.mod h1:ULRO0N2Wg7Ymj7CEg4TI7CJobx9yVEZ5Lbh7oWi7woA= github.com/onyx-and-iris/voicemeeter/v2 v2.0.0/go.mod h1:ULRO0N2Wg7Ymj7CEg4TI7CJobx9yVEZ5Lbh7oWi7woA=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 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/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.1 h1:Ou41VVR3nMWWmTiEUnj0OlsgOSCUFgsPAOl6jRIcVtQ=
github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= github.com/sirupsen/logrus v1.9.1/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 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.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=

View File

@@ -1,6 +1,6 @@
## About ## About
A simple voicemeeter-cli program. Offers ability to toggle, get and set parameters. A Voicemeeter CLI, offers ability to toggle, get and set parameters.
## Install ## Install
@@ -8,28 +8,32 @@ First build and install it with `go install` (skip this step if using binary fro
## Use ## Use
Toggle with `!` prefix, get by excluding `=` and set by including `=`. Mix and match arguments. Commands that begin with `!` will toggle a parameter, commands that contain `=` will set a parameter, all other commands will get a value.
You may pass the following optional flags: You may pass the following optional flags:
- -v: (-verbose) to toggle console output. - -h: Print the help message
- -i: (-interactive) to toggle interactive mode. - -i: Enable interactive mode
- -k: (-kind) to set the kind of Voicemeeter. Defaults to banana. - -k: The kind of Voicemeeter GUI to launch, defaults to Banana
- -d: (-delay) to set a delay on the getters. Defaults to 20ms. - -l: Log level (0 up to 6), defaults to 3, Warn Level
- -d: Set the delay between commands, defaults to 20ms
- -v: Enable extra console output (toggle and set messages).
for example: for example:
`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` `vm-cli.exe -v -l=4 -k=potato 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:
``` ```
Running command strip[0].mute=0 time="<timestamp>" level=info msg="Logged into Voicemeeter Potato v3.1.1.1"
Value of strip[0].mute is: 0 Setting strip[0].mute=0
strip[0].mute: 0.00
Toggling strip[0].mute Toggling strip[0].mute
Value of strip[0].mute is: 1 strip[0].mute: 1.00
Running command bus[0].gain=-8.8 Setting bus[0].gain=-8.8
Running command command.lock=1 Setting command.lock=1
time="<timestamp>" level=info msg="Logged out of Voicemeeter Potato"
``` ```
If running in interactive mode enter `q`, `quit` or `<Enter>` to exit. If running in interactive mode enter `Q`, to exit.

View File

@@ -4,18 +4,28 @@ import (
"bufio" "bufio"
"flag" "flag"
"fmt" "fmt"
"log"
"os" "os"
"strings" "strings"
log "github.com/sirupsen/logrus"
"github.com/onyx-and-iris/voicemeeter/v2" "github.com/onyx-and-iris/voicemeeter/v2"
) )
type ( const (
verbosePrinter struct { FLOAT = iota
STRING
)
type result struct {
kind int
stringParam string
floatParam float64
}
type verbosePrinter struct {
verbose bool verbose bool
} }
)
func newVerbosePrinter() *verbosePrinter { func newVerbosePrinter() *verbosePrinter {
return &verbosePrinter{} return &verbosePrinter{}
@@ -23,7 +33,7 @@ func newVerbosePrinter() *verbosePrinter {
func (v *verbosePrinter) printf(format string, a ...interface{}) { func (v *verbosePrinter) printf(format string, a ...interface{}) {
if v.verbose { if v.verbose {
fmt.Printf(format+"\n", a...) fmt.Printf(format, a...)
} }
} }
@@ -40,28 +50,68 @@ func main() {
kind string kind string
delay int delay int
interactive bool interactive bool
loglevel int
help bool
) )
flag.Usage = usage
flag.BoolVar(&help, "help", false, "print the help message")
flag.BoolVar(&help, "h", false, "print the help message (shorthand)")
flag.StringVar(&kind, "kind", "banana", "kind of voicemeeter") flag.StringVar(&kind, "kind", "banana", "kind of voicemeeter")
flag.StringVar(&kind, "k", "banana", "kind of voicemeeter (shorthand)") flag.StringVar(&kind, "k", "banana", "kind of voicemeeter (shorthand)")
flag.IntVar(&delay, "delay", 20, "delay between commands") flag.IntVar(&delay, "delay", 20, "delay between commands")
flag.IntVar(&delay, "d", 20, "delay between commands (shorthand)") flag.IntVar(&delay, "d", 20, "delay between commands (shorthand)")
flag.BoolVar(&vPrinter.verbose, "verbose", false, "toggle console output")
flag.BoolVar(&vPrinter.verbose, "v", false, "toggle console output (shorthand)")
flag.BoolVar(&interactive, "interactive", false, "toggle interactive mode") flag.BoolVar(&interactive, "interactive", false, "toggle interactive mode")
flag.BoolVar(&interactive, "i", false, "toggle interactive mode (shorthand)") flag.BoolVar(&interactive, "i", false, "toggle interactive mode (shorthand)")
flag.IntVar(&loglevel, "loglevel", int(log.WarnLevel), "set the log level")
flag.IntVar(&loglevel, "l", int(log.WarnLevel), "set the log level (shorthand)")
flag.BoolVar(&vPrinter.verbose, "verbose", false, "enable extra console output (toggle and set messages)")
flag.BoolVar(&vPrinter.verbose, "v", false, "enable extra console output (toggle and set messages) (shorthand)")
flag.Parse() flag.Parse()
if help {
flag.Usage()
return
}
if loglevel >= int(log.PanicLevel) && loglevel <= int(log.TraceLevel) {
log.SetLevel(log.Level(loglevel))
}
vm, err := vmConnect(kind, delay) vm, err := vmConnect(kind, delay)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
defer vm.Logout() defer vm.Logout()
err = runCommands(vm, interactive) if interactive {
if err != nil { interactiveMode(vm)
fmt.Println(err) return
} }
args := flag.Args()
if len(args) == 0 {
flag.Usage()
return
}
for _, arg := range args {
if err := parse(vm, arg); err != nil {
log.Error(err.Error())
}
}
}
func usage() {
fmt.Println("usage: ./vm-cli.exe [-h] [-i] [-k] [-l] [-d] [-v]\n" +
"Where:\n" +
"\th: Print the help message\n" +
"\ti: Enable interactive mode\n" +
"\tk: The kind of Voicemeeter GUI to launch, defaults to Banana\n" +
"\tl: Log level 0 up to 6, (defaults to 3, Warn Level)\n" +
"\td: Set the delay between commands (defaults to 20ms)\n" +
"\tv: Enable extra console output (toggle and set messages).")
} }
func vmConnect(kind string, delay int) (*voicemeeter.Remote, error) { func vmConnect(kind string, delay int) (*voicemeeter.Remote, error) {
@@ -78,38 +128,23 @@ func vmConnect(kind string, delay int) (*voicemeeter.Remote, error) {
return vm, nil return vm, nil
} }
func runCommands(vm *voicemeeter.Remote, interactive bool) error {
if interactive {
return interactiveMode(vm)
}
args := flag.Args()
if len(args) == 0 {
err := fmt.Errorf("must provide some commands to run")
return err
}
for _, arg := range args {
err := parse(vm, arg)
if err != nil {
vPrinter.printf(err.Error())
}
}
return nil
}
func interactiveMode(vm *voicemeeter.Remote) error { func interactiveMode(vm *voicemeeter.Remote) error {
vPrinter.printf("running in interactive mode... waiting for input") fmt.Println("Interactive mode enabled. Enter 'Q' to exit.")
scanner := bufio.NewScanner(os.Stdin) scanner := bufio.NewScanner(os.Stdin)
fmt.Printf(">> ")
for scanner.Scan() { for scanner.Scan() {
input := scanner.Text() input := scanner.Text()
if input == "q" || input == "quit" || input == "" { if strings.ToUpper(input) == "Q" {
return nil break
} }
for _, cmd := range strings.Split(input, " ") { for _, cmd := range strings.Split(input, " ") {
err := parse(vm, cmd) if err := parse(vm, cmd); err != nil {
if err != nil { log.Error(err.Error())
vPrinter.printf(err.Error())
} }
} }
fmt.Printf(">> ")
} }
if scanner.Err() != nil { if scanner.Err() != nil {
return scanner.Err() return scanner.Err()
@@ -119,58 +154,60 @@ func interactiveMode(vm *voicemeeter.Remote) error {
func parse(vm *voicemeeter.Remote, cmd string) error { func parse(vm *voicemeeter.Remote, cmd string) error {
if cmd[0] == '!' { if cmd[0] == '!' {
err := toggleCmd(vm, cmd[1:]) if err := toggleCmd(vm, cmd[1:]); err != nil {
if err != nil { return err
}
} else if strings.Contains(cmd, "=") {
if err := setCmd(vm, cmd); err != nil {
return err return err
} }
} else { } else {
if strings.Contains(cmd, "=") { r := result{kind: FLOAT}
err := setCmd(vm, cmd) if err := getCmd(vm, cmd, &r); err != nil {
if err != nil {
return err
}
} else {
err := getCmd(vm, cmd)
if err != nil {
return err return err
} }
switch r.kind {
case FLOAT:
fmt.Printf("%s: %.2f\n", cmd, r.floatParam)
case STRING:
fmt.Printf("%s: %s\n", cmd, r.stringParam)
} }
} }
return nil return nil
} }
func toggleCmd(vm *voicemeeter.Remote, cmd string) error { func toggleCmd(vm *voicemeeter.Remote, cmd string) error {
val, err := vm.GetFloat(cmd) r := result{kind: FLOAT}
if err != nil { if err := getCmd(vm, cmd, &r); err != nil {
err = fmt.Errorf("unable to toggle %s", cmd)
return err return err
} }
vm.SetFloat(cmd, 1-val) if r.kind == FLOAT && (r.floatParam == 0 || r.floatParam == 1) {
vPrinter.printf("Toggling %s", cmd) vPrinter.printf("Toggling %s\n", cmd)
vm.SetFloat(cmd, 1-r.floatParam)
} else {
log.Warnf("%s does not appear to be a boolean parameter", cmd)
}
return nil return nil
} }
func setCmd(vm *voicemeeter.Remote, cmd string) error { func setCmd(vm *voicemeeter.Remote, cmd string) error {
vPrinter.printf("Running command %s", cmd) if err := vm.SendText(cmd); err != nil {
err := vm.SendText(cmd)
if err != nil {
err = fmt.Errorf("unable to set %s", cmd) err = fmt.Errorf("unable to set %s", cmd)
return err return err
} }
vPrinter.printf("Setting %s\n", cmd)
return nil return nil
} }
func getCmd(vm *voicemeeter.Remote, cmd string) error { func getCmd(vm *voicemeeter.Remote, cmd string, r *result) error {
valF, err := vm.GetFloat(cmd) if val, err := vm.GetFloat(cmd); err == nil {
if err != nil { r.floatParam = val
valS, err := vm.GetString(cmd) } else if val, err := vm.GetString(cmd); err == nil {
if err != nil { r.kind = STRING
err = fmt.Errorf("unable to get %s", cmd) r.stringParam = val
return err
}
fmt.Printf("Value of %s is: %s", cmd, valS)
} else { } else {
fmt.Printf("Value of %s is: %v", cmd, valF) err := fmt.Errorf("unknown parameter '%s'", cmd)
return err
} }
return nil return nil
} }

2
go.mod
View File

@@ -3,7 +3,7 @@ module github.com/onyx-and-iris/voicemeeter/v2
go 1.18 go 1.18
require ( require (
github.com/sirupsen/logrus v1.9.0 github.com/sirupsen/logrus v1.9.1
github.com/stretchr/testify v1.8.0 github.com/stretchr/testify v1.8.0
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8
) )

4
go.sum
View File

@@ -3,8 +3,8 @@ 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/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 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/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.1 h1:Ou41VVR3nMWWmTiEUnj0OlsgOSCUFgsPAOl6jRIcVtQ=
github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= github.com/sirupsen/logrus v1.9.1/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=