mirror of
https://github.com/onyx-and-iris/xair-cli.git
synced 2026-04-18 06:43:33 +00:00
Compare commits
30 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3ed0560d08 | |||
| 6a4577118f | |||
| 1597f8f352 | |||
| e80f17d211 | |||
| 40c7d03ff1 | |||
| 561faa0e95 | |||
| ce398e9a09 | |||
| b8b637b4b7 | |||
| 52d51a7094 | |||
| 09a4e9fbfc | |||
| 04f7319776 | |||
| 0c67887ad7 | |||
| 4db173154b | |||
| 27922d41bb | |||
| e21fd59564 | |||
| 2d829e28e1 | |||
| 3f8861ded2 | |||
| 1ad214ba4a | |||
| 66da965edd | |||
| 079a0b240d | |||
| fe711f79f1 | |||
| c94ac62cb8 | |||
| 5933b25114 | |||
| fa704832d5 | |||
| 69925021af | |||
| e092ed3c4e | |||
| d87bc2678c | |||
| c3221f3df5 | |||
| dc733ba500 | |||
| 2a5e0e022f |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -36,3 +36,5 @@ go.work.sum
|
||||
# .vscode/
|
||||
|
||||
# End of ignr
|
||||
|
||||
update_readme.py
|
||||
132
README.md
132
README.md
@@ -6,6 +6,39 @@
|
||||
go install github.com/onyx-and-iris/xair-cli@latest
|
||||
```
|
||||
|
||||
### Configuration
|
||||
|
||||
#### Flags
|
||||
|
||||
- --host/-H: Host of the mixer.
|
||||
- --port/-P: Port of the mixer.
|
||||
- --kind/-k: The kind of mixer. May be one of (*xair*, *x32*).
|
||||
- Use this flag to connect to an x32 mixer.
|
||||
- --timeout/-T: Timeout for OSC operations.
|
||||
- --loglevel/-L: The application's logging verbosity.
|
||||
|
||||
Pass `--host` and any other configuration as flags on the root commmand:
|
||||
|
||||
```console
|
||||
xair-cli --host mixer.local --kind xair --timeout 50ms --help
|
||||
```
|
||||
|
||||
#### Environment Variables
|
||||
|
||||
Or you may load them from your environment:
|
||||
|
||||
Example .envrc:
|
||||
|
||||
```bash
|
||||
#!/usr/bin/env bash
|
||||
|
||||
XAIR_CLI_HOST=mixer.local
|
||||
XAIR_CLI_PORT=10024
|
||||
XAIR_CLI_KIND=xair
|
||||
XAIR_CLI_TIMEOUT=100ms
|
||||
XAIR_CLI_LOGLEVEL=warn
|
||||
```
|
||||
|
||||
### Use
|
||||
|
||||
```console
|
||||
@@ -15,10 +48,12 @@ A CLI to control Behringer X-Air mixers.
|
||||
|
||||
Flags:
|
||||
-h, --help Show context-sensitive help.
|
||||
--host="mixer.local" The host of the X-Air device ($XAIR_CLI_HOST).
|
||||
--port=10024 The port of the X-Air device ($XAIR_CLI_PORT).
|
||||
--kind="xr18" The kind of the X-Air device ($XAIR_CLI_KIND).
|
||||
-v, --version Print gobs-cli version information and quit
|
||||
-H, --host="mixer.local" The host of the X-Air device ($XAIR_CLI_HOST).
|
||||
-P, --port=10024 The port of the X-Air device ($XAIR_CLI_PORT).
|
||||
-K, --kind="xair" The kind of the X-Air device ($XAIR_CLI_KIND).
|
||||
-T, --timeout=100ms Timeout for OSC operations ($XAIR_CLI_TIMEOUT).
|
||||
-L, --loglevel="warn" Log level for the CLI ($XAIR_CLI_LOGLEVEL).
|
||||
-v, --version Print xair-cli version information and quit
|
||||
|
||||
Commands:
|
||||
completion (c) Generate shell completion scripts.
|
||||
@@ -27,10 +62,31 @@ Raw
|
||||
raw Send raw OSC messages to the mixer.
|
||||
|
||||
Main
|
||||
main mute Get or set the mute state of the Main L/R output.
|
||||
main fader Get or set the fader level of the Main L/R output.
|
||||
main fadein Get or set the fade-in time of the Main L/R output.
|
||||
main fadeout Get or set the fade-out time of the Main L/R output.
|
||||
main mute Get or set the mute state of the Main L/R output.
|
||||
main fader Get or set the fader level of the Main L/R output.
|
||||
main fadein Fade in the Main L/R output over a specified duration.
|
||||
main fadeout Fade out the Main L/R output over a specified duration.
|
||||
main eq on Get or set the EQ on/off state of the Main L/R output.
|
||||
main eq <band> gain Get or set the gain of the specified EQ band.
|
||||
main eq <band> freq Get or set the frequency of the specified EQ band.
|
||||
main eq <band> q Get or set the Q factor of the specified EQ band.
|
||||
main eq <band> type Get or set the type of the specified EQ band.
|
||||
main comp on Get or set the compressor on/off state of the Main L/R
|
||||
output.
|
||||
main comp mode Get or set the compressor mode of the Main L/R output.
|
||||
main comp threshold Get or set the compressor threshold of the Main L/R
|
||||
output.
|
||||
main comp ratio Get or set the compressor ratio of the Main L/R output.
|
||||
main comp mix Get or set the compressor mix level of the Main L/R
|
||||
output.
|
||||
main comp makeup Get or set the compressor makeup gain of the Main L/R
|
||||
output.
|
||||
main comp attack Get or set the compressor attack time of the Main L/R
|
||||
output.
|
||||
main comp hold Get or set the compressor hold time of the Main L/R
|
||||
output.
|
||||
main comp release Get or set the compressor release time of the Main L/R
|
||||
output.
|
||||
|
||||
Strip
|
||||
strip <index> mute Get or set the mute state of the strip.
|
||||
@@ -51,15 +107,21 @@ Strip
|
||||
strip <index> eq <band> freq Get or set the frequency of the EQ band.
|
||||
strip <index> eq <band> q Get or set the Q factor of the EQ band.
|
||||
strip <index> eq <band> type Get or set the type of the EQ band.
|
||||
strip <index> comp on Get or set the compressor on/off state of the strip.
|
||||
strip <index> comp on Get or set the compressor on/off state of the
|
||||
strip.
|
||||
strip <index> comp mode Get or set the compressor mode of the strip.
|
||||
strip <index> comp threshold Get or set the compressor threshold of the strip.
|
||||
strip <index> comp threshold Get or set the compressor threshold of the
|
||||
strip.
|
||||
strip <index> comp ratio Get or set the compressor ratio of the strip.
|
||||
strip <index> comp mix Get or set the compressor mix of the strip.
|
||||
strip <index> comp makeup Get or set the compressor makeup gain of the strip.
|
||||
strip <index> comp attack Get or set the compressor attack time of the strip.
|
||||
strip <index> comp hold Get or set the compressor hold time of the strip.
|
||||
strip <index> comp release Get or set the compressor release time of the strip.
|
||||
strip <index> comp makeup Get or set the compressor makeup gain of the
|
||||
strip.
|
||||
strip <index> comp attack Get or set the compressor attack time of the
|
||||
strip.
|
||||
strip <index> comp hold Get or set the compressor hold time of the
|
||||
strip.
|
||||
strip <index> comp release Get or set the compressor release time of the
|
||||
strip.
|
||||
|
||||
Bus
|
||||
bus <index> mute Get or set the mute state of the bus.
|
||||
@@ -68,25 +130,42 @@ Bus
|
||||
bus <index> fadeout Fade out the bus over a specified duration.
|
||||
bus <index> name Get or set the name of the bus.
|
||||
bus <index> eq on Get or set the EQ on/off state of the bus.
|
||||
bus <index> eq mode Get or set the EQ mode of the bus (peq, geq or teq).
|
||||
bus <index> eq mode Get or set the EQ mode of the bus (peq, geq or
|
||||
teq).
|
||||
bus <index> eq <band> gain Get or set the gain of the EQ band.
|
||||
bus <index> eq <band> freq Get or set the frequency of the EQ band.
|
||||
bus <index> eq <band> q Get or set the Q factor of the EQ band.
|
||||
bus <index> eq <band> type Get or set the type of the EQ band (lcut, lshv, peq, veq, hshv, hcut).
|
||||
bus <index> comp on Get or set the compressor on/off state of the bus.
|
||||
bus <index> comp mode Get or set the compressor mode of the bus (comp, exp).
|
||||
bus <index> comp threshold Get or set the compressor threshold of the bus (in dB).
|
||||
bus <index> eq <band> type Get or set the type of the EQ band (lcut, lshv,
|
||||
peq, veq, hshv, hcut).
|
||||
bus <index> comp on Get or set the compressor on/off state of the
|
||||
bus.
|
||||
bus <index> comp mode Get or set the compressor mode of the bus (comp,
|
||||
exp).
|
||||
bus <index> comp threshold Get or set the compressor threshold of the bus
|
||||
(in dB).
|
||||
bus <index> comp ratio Get or set the compressor ratio of the bus.
|
||||
bus <index> comp mix Get or set the compressor mix level of the bus (in %).
|
||||
bus <index> comp makeup Get or set the compressor makeup gain of the bus (in dB).
|
||||
bus <index> comp attack Get or set the compressor attack time of the bus (in ms).
|
||||
bus <index> comp hold Get or set the compressor hold time of the bus (in ms).
|
||||
bus <index> comp release Get or set the compressor release time of the bus (in ms).
|
||||
bus <index> comp mix Get or set the compressor mix level of the bus
|
||||
(in %).
|
||||
bus <index> comp makeup Get or set the compressor makeup gain of the bus
|
||||
(in dB).
|
||||
bus <index> comp attack Get or set the compressor attack time of the bus
|
||||
(in ms).
|
||||
bus <index> comp hold Get or set the compressor hold time of the bus
|
||||
(in ms).
|
||||
bus <index> comp release Get or set the compressor release time of the
|
||||
bus (in ms).
|
||||
|
||||
Headamp
|
||||
headamp <index> gain Get or set the gain of the headamp.
|
||||
headamp <index> phantom Get or set the phantom power state of the headamp.
|
||||
|
||||
Snapshot
|
||||
snapshot list List all snapshots.
|
||||
snapshot <index> name Get or set the name of a snapshot.
|
||||
snapshot <index> save Save the current mixer state to a snapshot.
|
||||
snapshot <index> load Load a mixer state from a snapshot.
|
||||
snapshot <index> delete Delete a snapshot.
|
||||
|
||||
Run "xair-cli <command> --help" for more information on a command.
|
||||
```
|
||||
|
||||
@@ -133,6 +212,11 @@ xair-cli raw /ch/01/config/name 'rode podmic'
|
||||
xair-cli raw /ch/01/config/name
|
||||
```
|
||||
|
||||
*Save current mixer state to a snapshot*
|
||||
```console
|
||||
xair-cli snapshot 20 save 'twitch live'
|
||||
```
|
||||
|
||||
|
||||
### License
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ vars:
|
||||
|
||||
WINDOWS: '{{.BIN_DIR}}/{{.PROGRAM}}_windows_amd64.exe'
|
||||
LINUX: '{{.BIN_DIR}}/{{.PROGRAM}}_linux_amd64'
|
||||
MACOS: '{{.BIN_DIR}}/{{.PROGRAM}}_darwin_amd64'
|
||||
|
||||
tasks:
|
||||
default:
|
||||
@@ -22,6 +23,7 @@ tasks:
|
||||
cmds:
|
||||
- task: build-windows
|
||||
- task: build-linux
|
||||
- task: build-macos
|
||||
|
||||
vet:
|
||||
desc: Vet the code
|
||||
@@ -46,6 +48,12 @@ tasks:
|
||||
- GOOS=linux GOARCH=amd64 go build -o {{.LINUX}} -ldflags="-X main.version={{.VERSION}}"
|
||||
internal: true
|
||||
|
||||
build-macos:
|
||||
desc: Build the xair-cli project for macOS
|
||||
cmds:
|
||||
- GOOS=darwin GOARCH=amd64 go build -o {{.MACOS}} -ldflags="-X main.version={{.VERSION}}"
|
||||
internal: true
|
||||
|
||||
test:
|
||||
desc: Run tests
|
||||
cmds:
|
||||
|
||||
22
bus.go
22
bus.go
@@ -148,7 +148,7 @@ func (cmd *BusFadeoutCmd) Run(ctx *context, bus *BusCmdGroup) error {
|
||||
|
||||
// BusNameCmd defines the command for getting or setting the name of a bus.
|
||||
type BusNameCmd struct {
|
||||
Name *string `arg:"" help:"The name to set for the bus. If not provided, the current name will be returned."`
|
||||
Name *string `arg:"" help:"The name to set for the bus. If not provided, the current name will be returned." optional:""`
|
||||
}
|
||||
|
||||
// Run executes the BusNameCmd command, either retrieving the current name of the bus or setting it based on the provided argument.
|
||||
@@ -238,7 +238,7 @@ func (cmd *BusEqModeCmd) Run(ctx *context, bus *BusCmdGroup) error {
|
||||
|
||||
// BusEqBandGainCmd defines the command for getting or setting the gain of a specific EQ band of a bus.
|
||||
type BusEqBandGainCmd struct {
|
||||
Gain *float64 `arg:"" help:"The gain to set for the EQ band (in dB). If not provided, the current gain will be returned."`
|
||||
Gain *float64 `arg:"" help:"The gain to set for the EQ band (in dB). If not provided, the current gain will be returned." optional:""`
|
||||
}
|
||||
|
||||
// Run executes the BusEqBandGainCmd command, either retrieving the current gain of the specified EQ band of the bus or setting it based on the provided argument.
|
||||
@@ -261,7 +261,7 @@ func (cmd *BusEqBandGainCmd) Run(ctx *context, bus *BusCmdGroup, busEq *BusEqCmd
|
||||
|
||||
// BusEqBandFreqCmd defines the command for getting or setting the frequency of a specific EQ band of a bus.
|
||||
type BusEqBandFreqCmd struct {
|
||||
Freq *float64 `arg:"" help:"The frequency to set for the EQ band (in Hz). If not provided, the current frequency will be returned."`
|
||||
Freq *float64 `arg:"" help:"The frequency to set for the EQ band (in Hz). If not provided, the current frequency will be returned." optional:""`
|
||||
}
|
||||
|
||||
// Run executes the BusEqBandFreqCmd command, either retrieving the current frequency of the specified EQ band of the bus or setting it based on the provided argument.
|
||||
@@ -284,7 +284,7 @@ func (cmd *BusEqBandFreqCmd) Run(ctx *context, bus *BusCmdGroup, busEq *BusEqCmd
|
||||
|
||||
// BusEqBandQCmd defines the command for getting or setting the Q factor of a specific EQ band of a bus.
|
||||
type BusEqBandQCmd struct {
|
||||
Q *float64 `arg:"" help:"The Q factor to set for the EQ band. If not provided, the current Q factor will be returned."`
|
||||
Q *float64 `arg:"" help:"The Q factor to set for the EQ band. If not provided, the current Q factor will be returned." optional:""`
|
||||
}
|
||||
|
||||
// Run executes the BusEqBandQCmd command, either retrieving the current Q factor of the specified EQ band of the bus or setting it based on the provided argument.
|
||||
@@ -389,7 +389,7 @@ func (cmd *BusCompModeCmd) Run(ctx *context, bus *BusCmdGroup) error {
|
||||
|
||||
// BusCompThresholdCmd defines the command for getting or setting the compressor threshold of a bus.
|
||||
type BusCompThresholdCmd struct {
|
||||
Threshold *float64 `arg:"" help:"The compressor threshold to set (in dB). If not provided, the current compressor threshold will be returned."`
|
||||
Threshold *float64 `arg:"" help:"The compressor threshold to set (in dB). If not provided, the current compressor threshold will be returned." optional:""`
|
||||
}
|
||||
|
||||
// Run executes the BusCompThresholdCmd command, either retrieving the current compressor threshold of the bus or setting it based on the provided argument.
|
||||
@@ -412,7 +412,7 @@ func (cmd *BusCompThresholdCmd) Run(ctx *context, bus *BusCmdGroup) error {
|
||||
|
||||
// BusCompRatioCmd defines the command for getting or setting the compressor ratio of a bus.
|
||||
type BusCompRatioCmd struct {
|
||||
Ratio *float64 `arg:"" help:"The compressor ratio to set. If not provided, the current compressor ratio will be returned."`
|
||||
Ratio *float64 `arg:"" help:"The compressor ratio to set. If not provided, the current compressor ratio will be returned." optional:""`
|
||||
}
|
||||
|
||||
// Run executes the BusCompRatioCmd command, either retrieving the current compressor ratio of the bus or setting it based on the provided argument.
|
||||
@@ -435,7 +435,7 @@ func (cmd *BusCompRatioCmd) Run(ctx *context, bus *BusCmdGroup) error {
|
||||
|
||||
// BusCompMixCmd defines the command for getting or setting the compressor mix level of a bus.
|
||||
type BusCompMixCmd struct {
|
||||
Mix *float64 `arg:"" help:"The compressor mix level to set (in %). If not provided, the current compressor mix level will be returned."`
|
||||
Mix *float64 `arg:"" help:"The compressor mix level to set (in %). If not provided, the current compressor mix level will be returned." optional:""`
|
||||
}
|
||||
|
||||
// Run executes the BusCompMixCmd command, either retrieving the current compressor mix level of the bus or setting it based on the provided argument.
|
||||
@@ -458,7 +458,7 @@ func (cmd *BusCompMixCmd) Run(ctx *context, bus *BusCmdGroup) error {
|
||||
|
||||
// BusCompMakeupCmd defines the command for getting or setting the compressor makeup gain of a bus.
|
||||
type BusCompMakeupCmd struct {
|
||||
Makeup *float64 `arg:"" help:"The compressor makeup gain to set (in dB). If not provided, the current compressor makeup gain will be returned."`
|
||||
Makeup *float64 `arg:"" help:"The compressor makeup gain to set (in dB). If not provided, the current compressor makeup gain will be returned." optional:""`
|
||||
}
|
||||
|
||||
// Run executes the BusCompMakeupCmd command, either retrieving the current compressor makeup gain of the bus or setting it based on the provided argument.
|
||||
@@ -481,7 +481,7 @@ func (cmd *BusCompMakeupCmd) Run(ctx *context, bus *BusCmdGroup) error {
|
||||
|
||||
// BusCompAttackCmd defines the command for getting or setting the compressor attack time of a bus.
|
||||
type BusCompAttackCmd struct {
|
||||
Attack *float64 `arg:"" help:"The compressor attack time to set (in ms). If not provided, the current compressor attack time will be returned."`
|
||||
Attack *float64 `arg:"" help:"The compressor attack time to set (in ms). If not provided, the current compressor attack time will be returned." optional:""`
|
||||
}
|
||||
|
||||
// Run executes the BusCompAttackCmd command, either retrieving the current compressor attack time of the bus or setting it based on the provided argument.
|
||||
@@ -504,7 +504,7 @@ func (cmd *BusCompAttackCmd) Run(ctx *context, bus *BusCmdGroup) error {
|
||||
|
||||
// BusCompHoldCmd defines the command for getting or setting the compressor hold time of a bus.
|
||||
type BusCompHoldCmd struct {
|
||||
Hold *float64 `arg:"" help:"The compressor hold time to set (in ms). If not provided, the current compressor hold time will be returned."`
|
||||
Hold *float64 `arg:"" help:"The compressor hold time to set (in ms). If not provided, the current compressor hold time will be returned." optional:""`
|
||||
}
|
||||
|
||||
// Run executes the BusCompHoldCmd command, either retrieving the current compressor hold time of the bus or setting it based on the provided argument.
|
||||
@@ -527,7 +527,7 @@ func (cmd *BusCompHoldCmd) Run(ctx *context, bus *BusCmdGroup) error {
|
||||
|
||||
// BusCompReleaseCmd defines the command for getting or setting the compressor release time of a bus.
|
||||
type BusCompReleaseCmd struct {
|
||||
Release *float64 `arg:"" help:"The compressor release time to set (in ms). If not provided, the current compressor release time will be returned."`
|
||||
Release *float64 `arg:"" help:"The compressor release time to set (in ms). If not provided, the current compressor release time will be returned." optional:""`
|
||||
}
|
||||
|
||||
// Run executes the BusCompReleaseCmd command, either retrieving the current compressor release time of the bus or setting it based on the provided argument.
|
||||
|
||||
131
cli.go
Normal file
131
cli.go
Normal file
@@ -0,0 +1,131 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"runtime/debug"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/alecthomas/kong"
|
||||
"github.com/charmbracelet/log"
|
||||
kongcompletion "github.com/jotaen/kong-completion"
|
||||
"github.com/onyx-and-iris/xair-cli/internal/xair"
|
||||
)
|
||||
|
||||
var version string // Version of the CLI, set at build time.
|
||||
|
||||
// VersionFlag is a custom flag type that prints the version and exits.
|
||||
type VersionFlag string
|
||||
|
||||
func (v VersionFlag) Decode(_ *kong.DecodeContext) error { return nil } // nolint: revive
|
||||
func (v VersionFlag) IsBool() bool { return true } // nolint: revive
|
||||
func (v VersionFlag) BeforeApply(app *kong.Kong, vars kong.Vars) error { // nolint: revive, unparam
|
||||
fmt.Printf("xair-cli version: %s\n", vars["version"])
|
||||
app.Exit(0)
|
||||
return nil
|
||||
}
|
||||
|
||||
type context struct {
|
||||
Client *xair.Client
|
||||
Out io.Writer
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
Host string `default:"mixer.local" help:"The host of the X-Air device." env:"XAIR_CLI_HOST" short:"H"`
|
||||
Port int `default:"10024" help:"The port of the X-Air device." env:"XAIR_CLI_PORT" short:"P"`
|
||||
Kind string `default:"xair" help:"The kind of the X-Air device." env:"XAIR_CLI_KIND" short:"K" enum:"xair,x32"`
|
||||
Timeout time.Duration `default:"100ms" help:"Timeout for OSC operations." env:"XAIR_CLI_TIMEOUT" short:"T"`
|
||||
Loglevel string `default:"warn" help:"Log level for the CLI." env:"XAIR_CLI_LOGLEVEL" short:"L" enum:"debug,info,warn,error,fatal"`
|
||||
}
|
||||
|
||||
// CLI is the main struct for the command-line interface.
|
||||
// It embeds the Config struct for global configuration and defines the available commands and flags.
|
||||
type CLI struct {
|
||||
Config `embed:"" prefix:"" help:"The configuration for the CLI."`
|
||||
|
||||
Version VersionFlag `help:"Print xair-cli version information and quit" name:"version" short:"v"`
|
||||
|
||||
Completion kongcompletion.Completion `help:"Generate shell completion scripts." cmd:"" aliases:"c"`
|
||||
|
||||
Raw RawCmd `help:"Send raw OSC messages to the mixer." cmd:"" group:"Raw"`
|
||||
Main MainCmdGroup `help:"Control the Main L/R output" cmd:"" group:"Main"`
|
||||
Strip StripCmdGroup `help:"Control the strips." cmd:"" group:"Strip"`
|
||||
Bus BusCmdGroup `help:"Control the buses." cmd:"" group:"Bus"`
|
||||
Headamp HeadampCmdGroup `help:"Control input gain and phantom power." cmd:"" group:"Headamp"`
|
||||
Snapshot SnapshotCmdGroup `help:"Save and load mixer states." cmd:"" group:"Snapshot"`
|
||||
}
|
||||
|
||||
func main() {
|
||||
var cli CLI
|
||||
kongcompletion.Register(kong.Must(&cli))
|
||||
ctx := kong.Parse(
|
||||
&cli,
|
||||
kong.Name("xair-cli"),
|
||||
kong.Description("A CLI to control Behringer X-Air mixers."),
|
||||
kong.UsageOnError(),
|
||||
kong.ConfigureHelp(kong.HelpOptions{
|
||||
Compact: true,
|
||||
}),
|
||||
kong.Vars{
|
||||
"version": func() string {
|
||||
if version == "" {
|
||||
info, ok := debug.ReadBuildInfo()
|
||||
if !ok {
|
||||
return "(unable to read build info)"
|
||||
}
|
||||
version = strings.Split(info.Main.Version, "-")[0]
|
||||
}
|
||||
return version
|
||||
}(),
|
||||
},
|
||||
)
|
||||
|
||||
ctx.FatalIfErrorf(run(ctx, cli.Config))
|
||||
}
|
||||
|
||||
// run is the main entry point for the CLI.
|
||||
// It connects to the X-Air device, retrieves mixer info, and then runs the command.
|
||||
func run(ctx *kong.Context, config Config) error {
|
||||
loglevel, err := log.ParseLevel(config.Loglevel)
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid log level: %w", err)
|
||||
}
|
||||
log.SetLevel(loglevel)
|
||||
|
||||
client, err := connect(config)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to connect to X-Air device: %w", err)
|
||||
}
|
||||
defer client.Close()
|
||||
|
||||
client.StartListening()
|
||||
resp, err := client.RequestInfo()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
log.Infof("Received mixer info: %+v", resp)
|
||||
|
||||
ctx.Bind(&context{
|
||||
Client: client,
|
||||
Out: os.Stdout,
|
||||
})
|
||||
|
||||
return ctx.Run()
|
||||
}
|
||||
|
||||
// connect creates a new X-Air client based on the provided configuration.
|
||||
func connect(config Config) (*xair.Client, error) {
|
||||
client, err := xair.NewClient(
|
||||
config.Host,
|
||||
config.Port,
|
||||
xair.WithKind(config.Kind),
|
||||
xair.WithTimeout(config.Timeout),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return client, nil
|
||||
}
|
||||
@@ -19,7 +19,7 @@ type HeadampCmdGroup struct {
|
||||
// HeadampGainCmd defines the command for getting or setting the gain of a headamp, allowing users to specify the gain in dB and an optional duration for a gradual fade when setting the gain.
|
||||
type HeadampGainCmd struct {
|
||||
Duration time.Duration `help:"The duration of the fade in/out when setting the gain." default:"5s"`
|
||||
Gain *float64 `help:"The gain of the headamp in dB." arg:""`
|
||||
Gain *float64 `help:"The gain of the headamp in dB." arg:"" optional:""`
|
||||
}
|
||||
|
||||
// Run executes the HeadampGainCmd command, either retrieving the current gain of the headamp or setting it based on the provided argument, with an optional fade duration for smooth transitions.
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package xair
|
||||
|
||||
var xairAddressMap = map[string]string{
|
||||
"main": "/lr",
|
||||
"strip": "/ch/%02d",
|
||||
"bus": "/bus/%01d",
|
||||
"headamp": "/headamp/%02d",
|
||||
@@ -8,9 +9,12 @@ var xairAddressMap = map[string]string{
|
||||
}
|
||||
|
||||
var x32AddressMap = map[string]string{
|
||||
"strip": "/ch/%02d",
|
||||
"bus": "/bus/%02d",
|
||||
"headamp": "/headamp/%02d",
|
||||
"main": "/main/st",
|
||||
"mainmono": "/main/mono",
|
||||
"strip": "/ch/%02d",
|
||||
"bus": "/bus/%02d",
|
||||
"headamp": "/headamp/%03d",
|
||||
"snapshot": "/-snap",
|
||||
}
|
||||
|
||||
func addressMapForMixerKind(kind MixerKind) map[string]string {
|
||||
|
||||
@@ -3,16 +3,16 @@ package xair
|
||||
import "fmt"
|
||||
|
||||
type Bus struct {
|
||||
baseAddress string
|
||||
client *Client
|
||||
baseAddress string
|
||||
Eq *Eq
|
||||
Comp *Comp
|
||||
}
|
||||
|
||||
func NewBus(c *Client) *Bus {
|
||||
func newBus(c *Client) *Bus {
|
||||
return &Bus{
|
||||
baseAddress: c.addressMap["bus"],
|
||||
client: c,
|
||||
baseAddress: c.addressMap["bus"],
|
||||
Eq: newEqForBus(c),
|
||||
Comp: newCompForBus(c),
|
||||
}
|
||||
@@ -26,8 +26,11 @@ func (b *Bus) Mute(bus int) (bool, error) {
|
||||
return false, err
|
||||
}
|
||||
|
||||
resp := <-b.client.respChan
|
||||
val, ok := resp.Arguments[0].(int32)
|
||||
msg, err := b.client.ReceiveMessage()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
val, ok := msg.Arguments[0].(int32)
|
||||
if !ok {
|
||||
return false, fmt.Errorf("unexpected argument type for bus mute value")
|
||||
}
|
||||
@@ -52,8 +55,11 @@ func (b *Bus) Fader(bus int) (float64, error) {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
resp := <-b.client.respChan
|
||||
val, ok := resp.Arguments[0].(float32)
|
||||
msg, err := b.client.ReceiveMessage()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
val, ok := msg.Arguments[0].(float32)
|
||||
if !ok {
|
||||
return 0, fmt.Errorf("unexpected argument type for bus fader value")
|
||||
}
|
||||
@@ -75,8 +81,11 @@ func (b *Bus) Name(bus int) (string, error) {
|
||||
return "", fmt.Errorf("failed to send bus name request: %v", err)
|
||||
}
|
||||
|
||||
resp := <-b.client.respChan
|
||||
val, ok := resp.Arguments[0].(string)
|
||||
msg, err := b.client.ReceiveMessage()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
val, ok := msg.Arguments[0].(string)
|
||||
if !ok {
|
||||
return "", fmt.Errorf("unexpected argument type for bus name value")
|
||||
}
|
||||
|
||||
@@ -10,10 +10,6 @@ import (
|
||||
"github.com/hypebeast/go-osc/osc"
|
||||
)
|
||||
|
||||
type parser interface {
|
||||
Parse(data []byte) (*osc.Message, error)
|
||||
}
|
||||
|
||||
type Client struct {
|
||||
engine
|
||||
Main *Main
|
||||
@@ -45,6 +41,7 @@ func NewClient(mixerIP string, mixerPort int, opts ...Option) (*Client, error) {
|
||||
|
||||
e := &engine{
|
||||
Kind: KindXAir,
|
||||
timeout: 100 * time.Millisecond,
|
||||
conn: conn,
|
||||
mixerAddr: mixerAddr,
|
||||
parser: newParser(),
|
||||
@@ -60,10 +57,11 @@ func NewClient(mixerIP string, mixerPort int, opts ...Option) (*Client, error) {
|
||||
c := &Client{
|
||||
engine: *e,
|
||||
}
|
||||
c.Main = newMain(c)
|
||||
c.Strip = NewStrip(c)
|
||||
c.Bus = NewBus(c)
|
||||
c.HeadAmp = NewHeadAmp(c)
|
||||
c.Main = newMainStereo(c)
|
||||
c.Strip = newStrip(c)
|
||||
c.Bus = newBus(c)
|
||||
c.HeadAmp = newHeadAmp(c)
|
||||
c.Snapshot = newSnapshot(c)
|
||||
|
||||
return c, nil
|
||||
}
|
||||
@@ -88,32 +86,35 @@ func (c *Client) SendMessage(address string, args ...any) error {
|
||||
}
|
||||
|
||||
// ReceiveMessage receives an OSC message from the mixer
|
||||
func (c *Client) ReceiveMessage(timeout time.Duration) (*osc.Message, error) {
|
||||
t := time.Tick(timeout)
|
||||
func (c *Client) ReceiveMessage() (*osc.Message, error) {
|
||||
t := time.Tick(c.engine.timeout)
|
||||
select {
|
||||
case <-t:
|
||||
return nil, nil
|
||||
case val := <-c.respChan:
|
||||
if val == nil {
|
||||
return nil, fmt.Errorf("timeout waiting for response")
|
||||
case msg := <-c.respChan:
|
||||
if msg == nil {
|
||||
return nil, fmt.Errorf("no message received")
|
||||
}
|
||||
return val, nil
|
||||
return msg, nil
|
||||
}
|
||||
}
|
||||
|
||||
// RequestInfo requests mixer information
|
||||
func (c *Client) RequestInfo() (InfoResponse, error) {
|
||||
var info InfoResponse
|
||||
err := c.SendMessage("/xinfo")
|
||||
if err != nil {
|
||||
return InfoResponse{}, err
|
||||
return info, err
|
||||
}
|
||||
|
||||
val := <-c.respChan
|
||||
var info InfoResponse
|
||||
if len(val.Arguments) >= 3 {
|
||||
info.Host = val.Arguments[0].(string)
|
||||
info.Name = val.Arguments[1].(string)
|
||||
info.Model = val.Arguments[2].(string)
|
||||
msg, err := c.ReceiveMessage()
|
||||
if err != nil {
|
||||
return info, err
|
||||
}
|
||||
if len(msg.Arguments) >= 3 {
|
||||
info.Host = msg.Arguments[0].(string)
|
||||
info.Name = msg.Arguments[1].(string)
|
||||
info.Model = msg.Arguments[2].(string)
|
||||
}
|
||||
return info, nil
|
||||
}
|
||||
|
||||
@@ -5,6 +5,18 @@ import "fmt"
|
||||
type Comp struct {
|
||||
client *Client
|
||||
baseAddress string
|
||||
AddressFunc func(fmtString string, args ...any) string
|
||||
}
|
||||
|
||||
// Factory function to create Comp instance for Main
|
||||
func newCompForMain(c *Client) *Comp {
|
||||
return &Comp{
|
||||
client: c,
|
||||
baseAddress: c.addressMap["main"],
|
||||
AddressFunc: func(fmtString string, args ...any) string {
|
||||
return fmtString
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// Factory function to create Comp instance for Strip
|
||||
@@ -12,6 +24,9 @@ func newCompForStrip(c *Client) *Comp {
|
||||
return &Comp{
|
||||
client: c,
|
||||
baseAddress: c.addressMap["strip"],
|
||||
AddressFunc: func(fmtString string, args ...any) string {
|
||||
return fmt.Sprintf(fmtString, args...)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,19 +35,25 @@ func newCompForBus(c *Client) *Comp {
|
||||
return &Comp{
|
||||
client: c,
|
||||
baseAddress: c.addressMap["bus"],
|
||||
AddressFunc: func(fmtString string, args ...any) string {
|
||||
return fmt.Sprintf(fmtString, args...)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// On retrieves the on/off status of the Compressor for a specific strip or bus (1-based indexing).
|
||||
func (c *Comp) On(index int) (bool, error) {
|
||||
address := fmt.Sprintf(c.baseAddress, index) + "/dyn/on"
|
||||
address := c.AddressFunc(c.baseAddress, index) + "/dyn/on"
|
||||
err := c.client.SendMessage(address)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
resp := <-c.client.respChan
|
||||
val, ok := resp.Arguments[0].(int32)
|
||||
msg, err := c.client.ReceiveMessage()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
val, ok := msg.Arguments[0].(int32)
|
||||
if !ok {
|
||||
return false, fmt.Errorf("unexpected argument type for Compressor on value")
|
||||
}
|
||||
@@ -41,7 +62,7 @@ func (c *Comp) On(index int) (bool, error) {
|
||||
|
||||
// SetOn sets the on/off status of the Compressor for a specific strip or bus (1-based indexing).
|
||||
func (c *Comp) SetOn(index int, on bool) error {
|
||||
address := fmt.Sprintf(c.baseAddress, index) + "/dyn/on"
|
||||
address := c.AddressFunc(c.baseAddress, index) + "/dyn/on"
|
||||
var value int32
|
||||
if on {
|
||||
value = 1
|
||||
@@ -51,7 +72,7 @@ func (c *Comp) SetOn(index int, on bool) error {
|
||||
|
||||
// Mode retrieves the current mode of the Compressor for a specific strip or bus (1-based indexing).
|
||||
func (c *Comp) Mode(index int) (string, error) {
|
||||
address := fmt.Sprintf(c.baseAddress, index) + "/dyn/mode"
|
||||
address := c.AddressFunc(c.baseAddress, index) + "/dyn/mode"
|
||||
err := c.client.SendMessage(address)
|
||||
if err != nil {
|
||||
return "", err
|
||||
@@ -59,8 +80,11 @@ func (c *Comp) Mode(index int) (string, error) {
|
||||
|
||||
possibleModes := []string{"comp", "exp"}
|
||||
|
||||
resp := <-c.client.respChan
|
||||
val, ok := resp.Arguments[0].(int32)
|
||||
msg, err := c.client.ReceiveMessage()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
val, ok := msg.Arguments[0].(int32)
|
||||
if !ok {
|
||||
return "", fmt.Errorf("unexpected argument type for Compressor mode value")
|
||||
}
|
||||
@@ -69,21 +93,24 @@ func (c *Comp) Mode(index int) (string, error) {
|
||||
|
||||
// SetMode sets the mode of the Compressor for a specific strip or bus (1-based indexing).
|
||||
func (c *Comp) SetMode(index int, mode string) error {
|
||||
address := fmt.Sprintf(c.baseAddress, index) + "/dyn/mode"
|
||||
address := c.AddressFunc(c.baseAddress, index) + "/dyn/mode"
|
||||
possibleModes := []string{"comp", "exp"}
|
||||
return c.client.SendMessage(address, int32(indexOf(possibleModes, mode)))
|
||||
}
|
||||
|
||||
// Threshold retrieves the threshold value of the Compressor for a specific strip or bus (1-based indexing).
|
||||
func (c *Comp) Threshold(index int) (float64, error) {
|
||||
address := fmt.Sprintf(c.baseAddress, index) + "/dyn/thr"
|
||||
address := c.AddressFunc(c.baseAddress, index) + "/dyn/thr"
|
||||
err := c.client.SendMessage(address)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
resp := <-c.client.respChan
|
||||
val, ok := resp.Arguments[0].(float32)
|
||||
msg, err := c.client.ReceiveMessage()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
val, ok := msg.Arguments[0].(float32)
|
||||
if !ok {
|
||||
return 0, fmt.Errorf("unexpected argument type for Compressor threshold value")
|
||||
}
|
||||
@@ -92,13 +119,13 @@ func (c *Comp) Threshold(index int) (float64, error) {
|
||||
|
||||
// SetThreshold sets the threshold value of the Compressor for a specific strip or bus (1-based indexing).
|
||||
func (c *Comp) SetThreshold(index int, threshold float64) error {
|
||||
address := fmt.Sprintf(c.baseAddress, index) + "/dyn/thr"
|
||||
address := c.AddressFunc(c.baseAddress, index) + "/dyn/thr"
|
||||
return c.client.SendMessage(address, float32(linSet(-60, 0, threshold)))
|
||||
}
|
||||
|
||||
// Ratio retrieves the ratio value of the Compressor for a specific strip or bus (1-based indexing).
|
||||
func (c *Comp) Ratio(index int) (float32, error) {
|
||||
address := fmt.Sprintf(c.baseAddress, index) + "/dyn/ratio"
|
||||
address := c.AddressFunc(c.baseAddress, index) + "/dyn/ratio"
|
||||
err := c.client.SendMessage(address)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
@@ -106,8 +133,11 @@ func (c *Comp) Ratio(index int) (float32, error) {
|
||||
|
||||
possibleValues := []float32{1.1, 1.3, 1.5, 2.0, 2.5, 3.0, 4.0, 5.0, 7.0, 10, 20, 100}
|
||||
|
||||
resp := <-c.client.respChan
|
||||
val, ok := resp.Arguments[0].(int32)
|
||||
msg, err := c.client.ReceiveMessage()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
val, ok := msg.Arguments[0].(int32)
|
||||
if !ok {
|
||||
return 0, fmt.Errorf("unexpected argument type for Compressor ratio value")
|
||||
}
|
||||
@@ -117,7 +147,7 @@ func (c *Comp) Ratio(index int) (float32, error) {
|
||||
|
||||
// SetRatio sets the ratio value of the Compressor for a specific strip or bus (1-based indexing).
|
||||
func (c *Comp) SetRatio(index int, ratio float64) error {
|
||||
address := fmt.Sprintf(c.baseAddress, index) + "/dyn/ratio"
|
||||
address := c.AddressFunc(c.baseAddress, index) + "/dyn/ratio"
|
||||
possibleValues := []float32{1.1, 1.3, 1.5, 2.0, 2.5, 3.0, 4.0, 5.0, 7.0, 10, 20, 100}
|
||||
|
||||
return c.client.SendMessage(address, int32(indexOf(possibleValues, float32(ratio))))
|
||||
@@ -125,14 +155,17 @@ func (c *Comp) SetRatio(index int, ratio float64) error {
|
||||
|
||||
// Attack retrieves the attack time of the Compressor for a specific strip or bus (1-based indexing).
|
||||
func (c *Comp) Attack(index int) (float64, error) {
|
||||
address := fmt.Sprintf(c.baseAddress, index) + "/dyn/attack"
|
||||
address := c.AddressFunc(c.baseAddress, index) + "/dyn/attack"
|
||||
err := c.client.SendMessage(address)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
resp := <-c.client.respChan
|
||||
val, ok := resp.Arguments[0].(float32)
|
||||
msg, err := c.client.ReceiveMessage()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
val, ok := msg.Arguments[0].(float32)
|
||||
if !ok {
|
||||
return 0, fmt.Errorf("unexpected argument type for Compressor attack value")
|
||||
}
|
||||
@@ -141,20 +174,23 @@ func (c *Comp) Attack(index int) (float64, error) {
|
||||
|
||||
// SetAttack sets the attack time of the Compressor for a specific strip or bus (1-based indexing).
|
||||
func (c *Comp) SetAttack(index int, attack float64) error {
|
||||
address := fmt.Sprintf(c.baseAddress, index) + "/dyn/attack"
|
||||
address := c.AddressFunc(c.baseAddress, index) + "/dyn/attack"
|
||||
return c.client.SendMessage(address, float32(linSet(0, 120, attack)))
|
||||
}
|
||||
|
||||
// Hold retrieves the hold time of the Compressor for a specific strip or bus (1-based indexing).
|
||||
func (c *Comp) Hold(index int) (float64, error) {
|
||||
address := fmt.Sprintf(c.baseAddress, index) + "/dyn/hold"
|
||||
address := c.AddressFunc(c.baseAddress, index) + "/dyn/hold"
|
||||
err := c.client.SendMessage(address)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
resp := <-c.client.respChan
|
||||
val, ok := resp.Arguments[0].(float32)
|
||||
msg, err := c.client.ReceiveMessage()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
val, ok := msg.Arguments[0].(float32)
|
||||
if !ok {
|
||||
return 0, fmt.Errorf("unexpected argument type for Compressor hold value")
|
||||
}
|
||||
@@ -163,20 +199,23 @@ func (c *Comp) Hold(index int) (float64, error) {
|
||||
|
||||
// SetHold sets the hold time of the Compressor for a specific strip or bus (1-based indexing).
|
||||
func (c *Comp) SetHold(index int, hold float64) error {
|
||||
address := fmt.Sprintf(c.baseAddress, index) + "/dyn/hold"
|
||||
address := c.AddressFunc(c.baseAddress, index) + "/dyn/hold"
|
||||
return c.client.SendMessage(address, float32(logSet(0.02, 2000, hold)))
|
||||
}
|
||||
|
||||
// Release retrieves the release time of the Compressor for a specific strip or bus (1-based indexing).
|
||||
func (c *Comp) Release(index int) (float64, error) {
|
||||
address := fmt.Sprintf(c.baseAddress, index) + "/dyn/release"
|
||||
address := c.AddressFunc(c.baseAddress, index) + "/dyn/release"
|
||||
err := c.client.SendMessage(address)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
resp := <-c.client.respChan
|
||||
val, ok := resp.Arguments[0].(float32)
|
||||
msg, err := c.client.ReceiveMessage()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
val, ok := msg.Arguments[0].(float32)
|
||||
if !ok {
|
||||
return 0, fmt.Errorf("unexpected argument type for Compressor release value")
|
||||
}
|
||||
@@ -185,20 +224,23 @@ func (c *Comp) Release(index int) (float64, error) {
|
||||
|
||||
// SetRelease sets the release time of the Compressor for a specific strip or bus (1-based indexing).
|
||||
func (c *Comp) SetRelease(index int, release float64) error {
|
||||
address := fmt.Sprintf(c.baseAddress, index) + "/dyn/release"
|
||||
address := c.AddressFunc(c.baseAddress, index) + "/dyn/release"
|
||||
return c.client.SendMessage(address, float32(logSet(4, 4000, release)))
|
||||
}
|
||||
|
||||
// Makeup retrieves the makeup gain of the Compressor for a specific strip or bus (1-based indexing).
|
||||
func (c *Comp) Makeup(index int) (float64, error) {
|
||||
address := fmt.Sprintf(c.baseAddress, index) + "/dyn/mgain"
|
||||
address := c.AddressFunc(c.baseAddress, index) + "/dyn/mgain"
|
||||
err := c.client.SendMessage(address)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
resp := <-c.client.respChan
|
||||
val, ok := resp.Arguments[0].(float32)
|
||||
msg, err := c.client.ReceiveMessage()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
val, ok := msg.Arguments[0].(float32)
|
||||
if !ok {
|
||||
return 0, fmt.Errorf("unexpected argument type for Compressor makeup gain value")
|
||||
}
|
||||
@@ -207,20 +249,23 @@ func (c *Comp) Makeup(index int) (float64, error) {
|
||||
|
||||
// SetMakeup sets the makeup gain of the Compressor for a specific strip or bus (1-based indexing).
|
||||
func (c *Comp) SetMakeup(index int, makeup float64) error {
|
||||
address := fmt.Sprintf(c.baseAddress, index) + "/dyn/mgain"
|
||||
address := c.AddressFunc(c.baseAddress, index) + "/dyn/mgain"
|
||||
return c.client.SendMessage(address, float32(linSet(0, 24, makeup)))
|
||||
}
|
||||
|
||||
// Mix retrieves the mix value of the Compressor for a specific strip or bus (1-based indexing).
|
||||
func (c *Comp) Mix(index int) (float64, error) {
|
||||
address := fmt.Sprintf(c.baseAddress, index) + "/dyn/mix"
|
||||
address := c.AddressFunc(c.baseAddress, index) + "/dyn/mix"
|
||||
err := c.client.SendMessage(address)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
resp := <-c.client.respChan
|
||||
val, ok := resp.Arguments[0].(float32)
|
||||
msg, err := c.client.ReceiveMessage()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
val, ok := msg.Arguments[0].(float32)
|
||||
if !ok {
|
||||
return 0, fmt.Errorf("unexpected argument type for Compressor mix value")
|
||||
}
|
||||
@@ -229,6 +274,6 @@ func (c *Comp) Mix(index int) (float64, error) {
|
||||
|
||||
// SetMix sets the mix value of the Compressor for a specific strip or bus (1-based indexing).
|
||||
func (c *Comp) SetMix(index int, mix float64) error {
|
||||
address := fmt.Sprintf(c.baseAddress, index) + "/dyn/mix"
|
||||
address := c.AddressFunc(c.baseAddress, index) + "/dyn/mix"
|
||||
return c.client.SendMessage(address, float32(linSet(0, 100, mix)))
|
||||
}
|
||||
|
||||
@@ -9,8 +9,13 @@ import (
|
||||
"github.com/hypebeast/go-osc/osc"
|
||||
)
|
||||
|
||||
type parser interface {
|
||||
Parse(data []byte) (*osc.Message, error)
|
||||
}
|
||||
|
||||
type engine struct {
|
||||
Kind MixerKind
|
||||
timeout time.Duration
|
||||
conn *net.UDPConn
|
||||
mixerAddr *net.UDPAddr
|
||||
|
||||
@@ -30,7 +35,7 @@ func (e *engine) receiveLoop() {
|
||||
case <-e.done:
|
||||
return
|
||||
default:
|
||||
// Set read timeout to avoid blocking forever
|
||||
// Set a short read deadline to prevent blocking indefinitely
|
||||
e.conn.SetReadDeadline(time.Now().Add(100 * time.Millisecond))
|
||||
n, _, err := e.conn.ReadFromUDP(buffer)
|
||||
if err != nil {
|
||||
|
||||
@@ -1,10 +1,24 @@
|
||||
package xair
|
||||
|
||||
import "fmt"
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type Eq struct {
|
||||
client *Client
|
||||
baseAddress string
|
||||
AddressFunc func(fmtString string, args ...any) string
|
||||
}
|
||||
|
||||
// Factory function to create Eq instance for Main
|
||||
func newEqForMain(c *Client) *Eq {
|
||||
return &Eq{
|
||||
client: c,
|
||||
baseAddress: c.addressMap["main"],
|
||||
AddressFunc: func(fmtString string, args ...any) string {
|
||||
return fmtString
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// Factory function to create Eq instance for Strip
|
||||
@@ -12,6 +26,9 @@ func newEqForStrip(c *Client) *Eq {
|
||||
return &Eq{
|
||||
client: c,
|
||||
baseAddress: c.addressMap["strip"],
|
||||
AddressFunc: func(fmtString string, args ...any) string {
|
||||
return fmt.Sprintf(fmtString, args...)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,19 +37,25 @@ func newEqForBus(c *Client) *Eq {
|
||||
return &Eq{
|
||||
client: c,
|
||||
baseAddress: c.addressMap["bus"],
|
||||
AddressFunc: func(fmtString string, args ...any) string {
|
||||
return fmt.Sprintf(fmtString, args...)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// On retrieves the on/off status of the EQ for a specific strip or bus (1-based indexing).
|
||||
func (e *Eq) On(index int) (bool, error) {
|
||||
address := fmt.Sprintf(e.baseAddress, index) + "/eq/on"
|
||||
address := e.AddressFunc(e.baseAddress, index) + "/eq/on"
|
||||
err := e.client.SendMessage(address)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
resp := <-e.client.respChan
|
||||
val, ok := resp.Arguments[0].(int32)
|
||||
msg, err := e.client.ReceiveMessage()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
val, ok := msg.Arguments[0].(int32)
|
||||
if !ok {
|
||||
return false, fmt.Errorf("unexpected argument type for EQ on value")
|
||||
}
|
||||
@@ -41,7 +64,7 @@ func (e *Eq) On(index int) (bool, error) {
|
||||
|
||||
// SetOn sets the on/off status of the EQ for a specific strip or bus (1-based indexing).
|
||||
func (e *Eq) SetOn(index int, on bool) error {
|
||||
address := fmt.Sprintf(e.baseAddress, index) + "/eq/on"
|
||||
address := e.AddressFunc(e.baseAddress, index) + "/eq/on"
|
||||
var value int32
|
||||
if on {
|
||||
value = 1
|
||||
@@ -50,7 +73,7 @@ func (e *Eq) SetOn(index int, on bool) error {
|
||||
}
|
||||
|
||||
func (e *Eq) Mode(index int) (string, error) {
|
||||
address := fmt.Sprintf(e.baseAddress, index) + "/eq/mode"
|
||||
address := e.AddressFunc(e.baseAddress, index) + "/eq/mode"
|
||||
err := e.client.SendMessage(address)
|
||||
if err != nil {
|
||||
return "", err
|
||||
@@ -58,8 +81,11 @@ func (e *Eq) Mode(index int) (string, error) {
|
||||
|
||||
possibleModes := []string{"peq", "geq", "teq"}
|
||||
|
||||
resp := <-e.client.respChan
|
||||
val, ok := resp.Arguments[0].(int32)
|
||||
msg, err := e.client.ReceiveMessage()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
val, ok := msg.Arguments[0].(int32)
|
||||
if !ok {
|
||||
return "", fmt.Errorf("unexpected argument type for EQ mode value")
|
||||
}
|
||||
@@ -67,21 +93,24 @@ func (e *Eq) Mode(index int) (string, error) {
|
||||
}
|
||||
|
||||
func (e *Eq) SetMode(index int, mode string) error {
|
||||
address := fmt.Sprintf(e.baseAddress, index) + "/eq/mode"
|
||||
address := e.AddressFunc(e.baseAddress, index) + "/eq/mode"
|
||||
possibleModes := []string{"peq", "geq", "teq"}
|
||||
return e.client.SendMessage(address, int32(indexOf(possibleModes, mode)))
|
||||
}
|
||||
|
||||
// Gain retrieves the gain for a specific EQ band on a strip or bus (1-based indexing).
|
||||
func (e *Eq) Gain(index int, band int) (float64, error) {
|
||||
address := fmt.Sprintf(e.baseAddress, index) + fmt.Sprintf("/eq/%d/g", band)
|
||||
address := e.AddressFunc(e.baseAddress, index) + fmt.Sprintf("/eq/%d/g", band)
|
||||
err := e.client.SendMessage(address)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
resp := <-e.client.respChan
|
||||
val, ok := resp.Arguments[0].(float32)
|
||||
msg, err := e.client.ReceiveMessage()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
val, ok := msg.Arguments[0].(float32)
|
||||
if !ok {
|
||||
return 0, fmt.Errorf("unexpected argument type for EQ gain value")
|
||||
}
|
||||
@@ -90,20 +119,23 @@ func (e *Eq) Gain(index int, band int) (float64, error) {
|
||||
|
||||
// SetGain sets the gain for a specific EQ band on a strip or bus (1-based indexing).
|
||||
func (e *Eq) SetGain(index int, band int, gain float64) error {
|
||||
address := fmt.Sprintf(e.baseAddress, index) + fmt.Sprintf("/eq/%d/g", band)
|
||||
address := e.AddressFunc(e.baseAddress, index) + fmt.Sprintf("/eq/%d/g", band)
|
||||
return e.client.SendMessage(address, float32(linSet(-15, 15, gain)))
|
||||
}
|
||||
|
||||
// Frequency retrieves the frequency for a specific EQ band on a strip or bus (1-based indexing).
|
||||
func (e *Eq) Frequency(index int, band int) (float64, error) {
|
||||
address := fmt.Sprintf(e.baseAddress, index) + fmt.Sprintf("/eq/%d/f", band)
|
||||
address := e.AddressFunc(e.baseAddress, index) + fmt.Sprintf("/eq/%d/f", band)
|
||||
err := e.client.SendMessage(address)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
resp := <-e.client.respChan
|
||||
val, ok := resp.Arguments[0].(float32)
|
||||
msg, err := e.client.ReceiveMessage()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
val, ok := msg.Arguments[0].(float32)
|
||||
if !ok {
|
||||
return 0, fmt.Errorf("unexpected argument type for EQ frequency value")
|
||||
}
|
||||
@@ -112,20 +144,23 @@ func (e *Eq) Frequency(index int, band int) (float64, error) {
|
||||
|
||||
// SetFrequency sets the frequency for a specific EQ band on a strip or bus (1-based indexing).
|
||||
func (e *Eq) SetFrequency(index int, band int, frequency float64) error {
|
||||
address := fmt.Sprintf(e.baseAddress, index) + fmt.Sprintf("/eq/%d/f", band)
|
||||
address := e.AddressFunc(e.baseAddress, index) + fmt.Sprintf("/eq/%d/f", band)
|
||||
return e.client.SendMessage(address, float32(logSet(20, 20000, frequency)))
|
||||
}
|
||||
|
||||
// Q retrieves the Q factor for a specific EQ band on a strip or bus (1-based indexing).
|
||||
func (e *Eq) Q(index int, band int) (float64, error) {
|
||||
address := fmt.Sprintf(e.baseAddress, index) + fmt.Sprintf("/eq/%d/q", band)
|
||||
address := e.AddressFunc(e.baseAddress, index) + fmt.Sprintf("/eq/%d/q", band)
|
||||
err := e.client.SendMessage(address)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
resp := <-e.client.respChan
|
||||
val, ok := resp.Arguments[0].(float32)
|
||||
msg, err := e.client.ReceiveMessage()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
val, ok := msg.Arguments[0].(float32)
|
||||
if !ok {
|
||||
return 0, fmt.Errorf("unexpected argument type for EQ Q value")
|
||||
}
|
||||
@@ -134,13 +169,13 @@ func (e *Eq) Q(index int, band int) (float64, error) {
|
||||
|
||||
// SetQ sets the Q factor for a specific EQ band on a strip or bus (1-based indexing).
|
||||
func (e *Eq) SetQ(index int, band int, q float64) error {
|
||||
address := fmt.Sprintf(e.baseAddress, index) + fmt.Sprintf("/eq/%d/q", band)
|
||||
address := e.AddressFunc(e.baseAddress, index) + fmt.Sprintf("/eq/%d/q", band)
|
||||
return e.client.SendMessage(address, float32(1.0-logSet(0.3, 10, q)))
|
||||
}
|
||||
|
||||
// Type retrieves the type for a specific EQ band on a strip or bus (1-based indexing).
|
||||
func (e *Eq) Type(index int, band int) (string, error) {
|
||||
address := fmt.Sprintf(e.baseAddress, index) + fmt.Sprintf("/eq/%d/type", band)
|
||||
address := e.AddressFunc(e.baseAddress, index) + fmt.Sprintf("/eq/%d/type", band)
|
||||
err := e.client.SendMessage(address)
|
||||
if err != nil {
|
||||
return "", err
|
||||
@@ -148,8 +183,11 @@ func (e *Eq) Type(index int, band int) (string, error) {
|
||||
|
||||
possibleTypes := []string{"lcut", "lshv", "peq", "veq", "hshv", "hcut"}
|
||||
|
||||
resp := <-e.client.respChan
|
||||
val, ok := resp.Arguments[0].(int32)
|
||||
msg, err := e.client.ReceiveMessage()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
val, ok := msg.Arguments[0].(int32)
|
||||
if !ok {
|
||||
return "", fmt.Errorf("unexpected argument type for EQ type value")
|
||||
}
|
||||
@@ -158,7 +196,7 @@ func (e *Eq) Type(index int, band int) (string, error) {
|
||||
|
||||
// SetType sets the type for a specific EQ band on a strip or bus (1-based indexing).
|
||||
func (e *Eq) SetType(index int, band int, eqType string) error {
|
||||
address := fmt.Sprintf(e.baseAddress, index) + fmt.Sprintf("/eq/%d/type", band)
|
||||
address := e.AddressFunc(e.baseAddress, index) + fmt.Sprintf("/eq/%d/type", band)
|
||||
possibleTypes := []string{"lcut", "lshv", "peq", "veq", "hshv", "hcut"}
|
||||
return e.client.SendMessage(address, int32(indexOf(possibleTypes, eqType)))
|
||||
}
|
||||
|
||||
@@ -7,8 +7,12 @@ type Gate struct {
|
||||
baseAddress string
|
||||
}
|
||||
|
||||
func newGate(c *Client) *Gate {
|
||||
return &Gate{client: c, baseAddress: c.addressMap["strip"]}
|
||||
// Factory function to create Gate instance for Strip
|
||||
func newGateForStrip(c *Client) *Gate {
|
||||
return &Gate{
|
||||
client: c,
|
||||
baseAddress: c.addressMap["strip"],
|
||||
}
|
||||
}
|
||||
|
||||
// On retrieves the on/off status of the Gate for a specific strip (1-based indexing).
|
||||
@@ -19,8 +23,11 @@ func (g *Gate) On(index int) (bool, error) {
|
||||
return false, err
|
||||
}
|
||||
|
||||
resp := <-g.client.respChan
|
||||
val, ok := resp.Arguments[0].(int32)
|
||||
msg, err := g.client.ReceiveMessage()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
val, ok := msg.Arguments[0].(int32)
|
||||
if !ok {
|
||||
return false, fmt.Errorf("unexpected argument type for Gate on value")
|
||||
}
|
||||
@@ -47,8 +54,11 @@ func (g *Gate) Mode(index int) (string, error) {
|
||||
|
||||
possibleModes := []string{"exp2", "exp3", "exp4", "gate", "duck"}
|
||||
|
||||
resp := <-g.client.respChan
|
||||
val, ok := resp.Arguments[0].(int32)
|
||||
msg, err := g.client.ReceiveMessage()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
val, ok := msg.Arguments[0].(int32)
|
||||
if !ok {
|
||||
return "", fmt.Errorf("unexpected argument type for Gate mode value")
|
||||
}
|
||||
@@ -71,8 +81,11 @@ func (g *Gate) Threshold(index int) (float64, error) {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
resp := <-g.client.respChan
|
||||
val, ok := resp.Arguments[0].(float32)
|
||||
msg, err := g.client.ReceiveMessage()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
val, ok := msg.Arguments[0].(float32)
|
||||
if !ok {
|
||||
return 0, fmt.Errorf("unexpected argument type for Gate threshold value")
|
||||
}
|
||||
@@ -93,8 +106,11 @@ func (g *Gate) Range(index int) (float64, error) {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
resp := <-g.client.respChan
|
||||
val, ok := resp.Arguments[0].(float32)
|
||||
msg, err := g.client.ReceiveMessage()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
val, ok := msg.Arguments[0].(float32)
|
||||
if !ok {
|
||||
return 0, fmt.Errorf("unexpected argument type for Gate range value")
|
||||
}
|
||||
@@ -115,8 +131,11 @@ func (g *Gate) Attack(index int) (float64, error) {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
resp := <-g.client.respChan
|
||||
val, ok := resp.Arguments[0].(float32)
|
||||
msg, err := g.client.ReceiveMessage()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
val, ok := msg.Arguments[0].(float32)
|
||||
if !ok {
|
||||
return 0, fmt.Errorf("unexpected argument type for Gate attack value")
|
||||
}
|
||||
@@ -137,8 +156,11 @@ func (g *Gate) Hold(index int) (float64, error) {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
resp := <-g.client.respChan
|
||||
val, ok := resp.Arguments[0].(float32)
|
||||
msg, err := g.client.ReceiveMessage()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
val, ok := msg.Arguments[0].(float32)
|
||||
if !ok {
|
||||
return 0, fmt.Errorf("unexpected argument type for Gate hold value")
|
||||
}
|
||||
@@ -159,8 +181,11 @@ func (g *Gate) Release(index int) (float64, error) {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
resp := <-g.client.respChan
|
||||
val, ok := resp.Arguments[0].(float32)
|
||||
msg, err := g.client.ReceiveMessage()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
val, ok := msg.Arguments[0].(float32)
|
||||
if !ok {
|
||||
return 0, fmt.Errorf("unexpected argument type for Gate release value")
|
||||
}
|
||||
|
||||
@@ -3,14 +3,15 @@ package xair
|
||||
import "fmt"
|
||||
|
||||
type HeadAmp struct {
|
||||
baseAddress string
|
||||
client *Client
|
||||
baseAddress string
|
||||
}
|
||||
|
||||
func NewHeadAmp(c *Client) *HeadAmp {
|
||||
// newHeadAmp creates a new HeadAmp instance with the provided client.
|
||||
func newHeadAmp(c *Client) *HeadAmp {
|
||||
return &HeadAmp{
|
||||
baseAddress: c.addressMap["headamp"],
|
||||
client: c,
|
||||
baseAddress: c.addressMap["headamp"],
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,8 +23,11 @@ func (h *HeadAmp) Gain(index int) (float64, error) {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
resp := <-h.client.respChan
|
||||
val, ok := resp.Arguments[0].(float32)
|
||||
msg, err := h.client.ReceiveMessage()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
val, ok := msg.Arguments[0].(float32)
|
||||
if !ok {
|
||||
return 0, fmt.Errorf("unexpected argument type for headamp gain value")
|
||||
}
|
||||
@@ -45,8 +49,11 @@ func (h *HeadAmp) PhantomPower(index int) (bool, error) {
|
||||
return false, err
|
||||
}
|
||||
|
||||
resp := <-h.client.respChan
|
||||
val, ok := resp.Arguments[0].(int32)
|
||||
msg, err := h.client.ReceiveMessage()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
val, ok := msg.Arguments[0].(int32)
|
||||
if !ok {
|
||||
return false, fmt.Errorf("unexpected argument type for phantom power value")
|
||||
}
|
||||
|
||||
@@ -3,24 +3,43 @@ package xair
|
||||
import "fmt"
|
||||
|
||||
type Main struct {
|
||||
client *Client
|
||||
client *Client
|
||||
baseAddress string
|
||||
Eq *Eq
|
||||
Comp *Comp
|
||||
}
|
||||
|
||||
func newMain(c *Client) *Main {
|
||||
func newMainStereo(c *Client) *Main {
|
||||
return &Main{
|
||||
client: c,
|
||||
client: c,
|
||||
baseAddress: c.addressMap["main"],
|
||||
Eq: newEqForMain(c),
|
||||
Comp: newCompForMain(c),
|
||||
}
|
||||
}
|
||||
|
||||
/* Still considering the best way to implement main mono support.
|
||||
func newMainMono(c *Client) *Main {
|
||||
return &Main{
|
||||
baseAddress: c.addressMap["mainmono"],
|
||||
client: c,
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
// Fader requests the current main L/R fader level
|
||||
func (m *Main) Fader() (float64, error) {
|
||||
err := m.client.SendMessage("/lr/mix/fader")
|
||||
address := m.baseAddress + "/mix/fader"
|
||||
err := m.client.SendMessage(address)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
resp := <-m.client.respChan
|
||||
val, ok := resp.Arguments[0].(float32)
|
||||
msg, err := m.client.ReceiveMessage()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
val, ok := msg.Arguments[0].(float32)
|
||||
if !ok {
|
||||
return 0, fmt.Errorf("unexpected argument type for main LR fader value")
|
||||
}
|
||||
@@ -29,18 +48,23 @@ func (m *Main) Fader() (float64, error) {
|
||||
|
||||
// SetFader sets the main L/R fader level
|
||||
func (m *Main) SetFader(level float64) error {
|
||||
return m.client.SendMessage("/lr/mix/fader", float32(mustDbInto(level)))
|
||||
address := m.baseAddress + "/mix/fader"
|
||||
return m.client.SendMessage(address, float32(mustDbInto(level)))
|
||||
}
|
||||
|
||||
// Mute requests the current main L/R mute status
|
||||
func (m *Main) Mute() (bool, error) {
|
||||
err := m.client.SendMessage("/lr/mix/on")
|
||||
address := m.baseAddress + "/mix/on"
|
||||
err := m.client.SendMessage(address)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
resp := <-m.client.respChan
|
||||
val, ok := resp.Arguments[0].(int32)
|
||||
msg, err := m.client.ReceiveMessage()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
val, ok := msg.Arguments[0].(int32)
|
||||
if !ok {
|
||||
return false, fmt.Errorf("unexpected argument type for main LR mute value")
|
||||
}
|
||||
@@ -49,9 +73,10 @@ func (m *Main) Mute() (bool, error) {
|
||||
|
||||
// SetMute sets the main L/R mute status
|
||||
func (m *Main) SetMute(muted bool) error {
|
||||
address := m.baseAddress + "/mix/on"
|
||||
var value int32
|
||||
if !muted {
|
||||
value = 1
|
||||
}
|
||||
return m.client.SendMessage("/lr/mix/on", value)
|
||||
return m.client.SendMessage(address, value)
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package xair
|
||||
|
||||
import "time"
|
||||
|
||||
type Option func(*engine)
|
||||
|
||||
func WithKind(kind string) Option {
|
||||
@@ -8,3 +10,9 @@ func WithKind(kind string) Option {
|
||||
e.addressMap = addressMapForMixerKind(e.Kind)
|
||||
}
|
||||
}
|
||||
|
||||
func WithTimeout(timeout time.Duration) Option {
|
||||
return func(e *engine) {
|
||||
e.timeout = timeout
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,27 +3,30 @@ package xair
|
||||
import "fmt"
|
||||
|
||||
type Snapshot struct {
|
||||
baseAddress string
|
||||
client *Client
|
||||
baseAddress string
|
||||
}
|
||||
|
||||
func NewSnapshot(c *Client) *Snapshot {
|
||||
func newSnapshot(c *Client) *Snapshot {
|
||||
return &Snapshot{
|
||||
baseAddress: c.addressMap["snapshot"],
|
||||
client: c,
|
||||
baseAddress: c.addressMap["snapshot"],
|
||||
}
|
||||
}
|
||||
|
||||
// Name gets the name of the snapshot at the given index.
|
||||
func (s *Snapshot) Name(index int) (string, error) {
|
||||
address := s.baseAddress + fmt.Sprintf("/name/%d", index)
|
||||
address := s.baseAddress + fmt.Sprintf("/%02d/name", index)
|
||||
err := s.client.SendMessage(address)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
resp := <-s.client.respChan
|
||||
name, ok := resp.Arguments[0].(string)
|
||||
msg, err := s.client.ReceiveMessage()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
name, ok := msg.Arguments[0].(string)
|
||||
if !ok {
|
||||
return "", fmt.Errorf("unexpected argument type for snapshot name")
|
||||
}
|
||||
@@ -32,24 +35,30 @@ func (s *Snapshot) Name(index int) (string, error) {
|
||||
|
||||
// SetName sets the name of the snapshot at the given index.
|
||||
func (s *Snapshot) SetName(index int, name string) error {
|
||||
address := s.baseAddress + fmt.Sprintf("/name/%d", index)
|
||||
address := s.baseAddress + fmt.Sprintf("/%02d/name", index)
|
||||
return s.client.SendMessage(address, name)
|
||||
}
|
||||
|
||||
// Load loads the snapshot at the given index.
|
||||
func (s *Snapshot) Load(index int) error {
|
||||
address := s.baseAddress + fmt.Sprintf("/load/%d", index)
|
||||
return s.client.SendMessage(address)
|
||||
// CurrentName sets the name of the current snapshot.
|
||||
func (s *Snapshot) CurrentName(name string) error {
|
||||
address := s.baseAddress + "/name"
|
||||
return s.client.SendMessage(address, name)
|
||||
}
|
||||
|
||||
// Save saves the current state to the snapshot at the given index.
|
||||
func (s *Snapshot) Save(index int) error {
|
||||
address := s.baseAddress + fmt.Sprintf("/save/%d", index)
|
||||
return s.client.SendMessage(address)
|
||||
// CurrentLoad loads the snapshot at the given index.
|
||||
func (s *Snapshot) CurrentLoad(index int) error {
|
||||
address := s.baseAddress + "/load"
|
||||
return s.client.SendMessage(address, int32(index))
|
||||
}
|
||||
|
||||
// Delete deletes the snapshot at the given index.
|
||||
func (s *Snapshot) Delete(index int) error {
|
||||
address := s.baseAddress + fmt.Sprintf("/delete/%d", index)
|
||||
return s.client.SendMessage(address)
|
||||
// CurrentSave saves the current state to the snapshot at the given index.
|
||||
func (s *Snapshot) CurrentSave(index int) error {
|
||||
address := s.baseAddress + "/save"
|
||||
return s.client.SendMessage(address, int32(index))
|
||||
}
|
||||
|
||||
// CurrentDelete deletes the snapshot at the given index.
|
||||
func (s *Snapshot) CurrentDelete(index int) error {
|
||||
address := s.baseAddress + "/delete"
|
||||
return s.client.SendMessage(address, int32(index))
|
||||
}
|
||||
|
||||
@@ -3,18 +3,18 @@ package xair
|
||||
import "fmt"
|
||||
|
||||
type Strip struct {
|
||||
baseAddress string
|
||||
client *Client
|
||||
baseAddress string
|
||||
Gate *Gate
|
||||
Eq *Eq
|
||||
Comp *Comp
|
||||
}
|
||||
|
||||
func NewStrip(c *Client) *Strip {
|
||||
func newStrip(c *Client) *Strip {
|
||||
return &Strip{
|
||||
baseAddress: c.addressMap["strip"],
|
||||
client: c,
|
||||
Gate: newGate(c),
|
||||
baseAddress: c.addressMap["strip"],
|
||||
Gate: newGateForStrip(c),
|
||||
Eq: newEqForStrip(c),
|
||||
Comp: newCompForStrip(c),
|
||||
}
|
||||
@@ -28,8 +28,11 @@ func (s *Strip) Mute(index int) (bool, error) {
|
||||
return false, err
|
||||
}
|
||||
|
||||
resp := <-s.client.respChan
|
||||
val, ok := resp.Arguments[0].(int32)
|
||||
msg, err := s.client.ReceiveMessage()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
val, ok := msg.Arguments[0].(int32)
|
||||
if !ok {
|
||||
return false, fmt.Errorf("unexpected argument type for strip mute value")
|
||||
}
|
||||
@@ -54,8 +57,11 @@ func (s *Strip) Fader(strip int) (float64, error) {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
resp := <-s.client.respChan
|
||||
val, ok := resp.Arguments[0].(float32)
|
||||
msg, err := s.client.ReceiveMessage()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
val, ok := msg.Arguments[0].(float32)
|
||||
if !ok {
|
||||
return 0, fmt.Errorf("unexpected argument type for fader value")
|
||||
}
|
||||
@@ -77,8 +83,11 @@ func (s *Strip) Name(strip int) (string, error) {
|
||||
return "", fmt.Errorf("failed to send strip name request: %v", err)
|
||||
}
|
||||
|
||||
resp := <-s.client.respChan
|
||||
val, ok := resp.Arguments[0].(string)
|
||||
msg, err := s.client.ReceiveMessage()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
val, ok := msg.Arguments[0].(string)
|
||||
if !ok {
|
||||
return "", fmt.Errorf("unexpected argument type for strip name value")
|
||||
}
|
||||
@@ -99,8 +108,11 @@ func (s *Strip) Color(strip int) (int32, error) {
|
||||
return 0, fmt.Errorf("failed to send strip color request: %v", err)
|
||||
}
|
||||
|
||||
resp := <-s.client.respChan
|
||||
val, ok := resp.Arguments[0].(int32)
|
||||
msg, err := s.client.ReceiveMessage()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
val, ok := msg.Arguments[0].(int32)
|
||||
if !ok {
|
||||
return 0, fmt.Errorf("unexpected argument type for strip color value")
|
||||
}
|
||||
@@ -121,8 +133,11 @@ func (s *Strip) SendLevel(strip int, bus int) (float64, error) {
|
||||
return 0, fmt.Errorf("failed to send strip send level request: %v", err)
|
||||
}
|
||||
|
||||
resp := <-s.client.respChan
|
||||
val, ok := resp.Arguments[0].(float32)
|
||||
msg, err := s.client.ReceiveMessage()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
val, ok := msg.Arguments[0].(float32)
|
||||
if !ok {
|
||||
return 0, fmt.Errorf("unexpected argument type for strip send level value")
|
||||
}
|
||||
|
||||
129
lr.go
129
lr.go
@@ -1,129 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
// MainCmdGroup defines the command group for controlling the Main L/R output, including commands for mute state, fader level, and fade-in/fade-out times.
|
||||
type MainCmdGroup struct {
|
||||
Mute MainMuteCmd `help:"Get or set the mute state of the Main L/R output." cmd:""`
|
||||
|
||||
Fader MainFaderCmd `help:"Get or set the fader level of the Main L/R output." cmd:""`
|
||||
Fadein MainFadeinCmd `help:"Fade in the Main L/R output over a specified duration." cmd:""`
|
||||
Fadeout MainFadeoutCmd `help:"Fade out the Main L/R output over a specified duration." cmd:""`
|
||||
}
|
||||
|
||||
// MainMuteCmd defines the command for getting or setting the mute state of the Main L/R output, allowing users to specify the desired state as "true"/"on" or "false"/"off".
|
||||
type MainMuteCmd struct {
|
||||
Mute *bool `arg:"" help:"The mute state to set. If not provided, the current state will be printed."`
|
||||
}
|
||||
|
||||
// Run executes the MainMuteCmd command, either retrieving the current mute state of the Main L/R output or setting it based on the provided argument.
|
||||
func (cmd *MainMuteCmd) Run(ctx *context) error {
|
||||
if cmd.Mute == nil {
|
||||
resp, err := ctx.Client.Main.Mute()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get Main L/R mute state: %w", err)
|
||||
}
|
||||
fmt.Fprintf(ctx.Out, "Main L/R mute state: %t\n", resp)
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := ctx.Client.Main.SetMute(*cmd.Mute); err != nil {
|
||||
return fmt.Errorf("failed to set Main L/R mute state: %w", err)
|
||||
}
|
||||
fmt.Fprintf(ctx.Out, "Main L/R mute state set to: %t\n", *cmd.Mute)
|
||||
return nil
|
||||
}
|
||||
|
||||
// MainFaderCmd defines the command for getting or setting the fader level of the Main L/R output, allowing users to specify the desired level in dB.
|
||||
type MainFaderCmd struct {
|
||||
Level *float64 `arg:"" help:"The fader level to set. If not provided, the current level will be printed."`
|
||||
}
|
||||
|
||||
// Run executes the MainFaderCmd command, either retrieving the current fader level of the Main L/R output or setting it based on the provided argument.
|
||||
func (cmd *MainFaderCmd) Run(ctx *context) error {
|
||||
if cmd.Level == nil {
|
||||
resp, err := ctx.Client.Main.Fader()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get Main L/R fader level: %w", err)
|
||||
}
|
||||
fmt.Fprintf(ctx.Out, "Main L/R fader level: %.2f\n", resp)
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := ctx.Client.Main.SetFader(*cmd.Level); err != nil {
|
||||
return fmt.Errorf("failed to set Main L/R fader level: %w", err)
|
||||
}
|
||||
fmt.Fprintf(ctx.Out, "Main L/R fader level set to: %.2f\n", *cmd.Level)
|
||||
return nil
|
||||
}
|
||||
|
||||
// MainFadeinCmd defines the command for getting or setting the fade-in time of the Main L/R output, allowing users to specify the desired duration for the fade-in effect.
|
||||
type MainFadeinCmd struct {
|
||||
Duration time.Duration `flag:"" help:"The duration of the fade-in. (in seconds.)" default:"5s"`
|
||||
Target float64 ` help:"The target level for the fade-in. If not provided, the current target level will be printed." default:"0.0" arg:""`
|
||||
}
|
||||
|
||||
// Run executes the MainFadeinCmd command, either retrieving the current fade-in time of the Main L/R output or setting it based on the provided argument, with an optional target level for the fade-in effect.
|
||||
func (cmd *MainFadeinCmd) Run(ctx *context) error {
|
||||
currentLevel, err := ctx.Client.Main.Fader()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get Main L/R fader level: %w", err)
|
||||
}
|
||||
|
||||
if currentLevel >= cmd.Target {
|
||||
return fmt.Errorf(
|
||||
"current fader level (%.2f) is already at or above the target level (%.2f)",
|
||||
currentLevel,
|
||||
cmd.Target,
|
||||
)
|
||||
}
|
||||
|
||||
totalSteps := float64(cmd.Target - currentLevel)
|
||||
stepDuration := time.Duration(cmd.Duration.Seconds()*1000/totalSteps) * time.Millisecond
|
||||
for currentLevel < cmd.Target {
|
||||
currentLevel++
|
||||
if err := ctx.Client.Main.SetFader(currentLevel); err != nil {
|
||||
return fmt.Errorf("failed to set Main L/R fader level: %w", err)
|
||||
}
|
||||
time.Sleep(stepDuration)
|
||||
}
|
||||
fmt.Fprintf(ctx.Out, "Main L/R fade-in completed. Final level: %.2f\n", currentLevel)
|
||||
return nil
|
||||
}
|
||||
|
||||
// MainFadeoutCmd defines the command for getting or setting the fade-out time of the Main L/R output, allowing users to specify the desired duration for the fade-out effect and an optional target level to fade out to.
|
||||
type MainFadeoutCmd struct {
|
||||
Duration time.Duration `flag:"" help:"The duration of the fade-out. (in seconds.)" default:"5s"`
|
||||
Target float64 ` help:"The target level for the fade-out. If not provided, the current target level will be printed." default:"-90.0" arg:""`
|
||||
}
|
||||
|
||||
// Run executes the MainFadeoutCmd command, either retrieving the current fade-out time of the Main L/R output or setting it based on the provided argument, with an optional target level for the fade-out effect.
|
||||
func (cmd *MainFadeoutCmd) Run(ctx *context) error {
|
||||
currentLevel, err := ctx.Client.Main.Fader()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get Main L/R fader level: %w", err)
|
||||
}
|
||||
|
||||
if currentLevel <= cmd.Target {
|
||||
return fmt.Errorf(
|
||||
"current fader level (%.2f) is already at or below the target level (%.2f)",
|
||||
currentLevel,
|
||||
cmd.Target,
|
||||
)
|
||||
}
|
||||
|
||||
totalSteps := float64(currentLevel - cmd.Target)
|
||||
stepDuration := time.Duration(cmd.Duration.Seconds()*1000/totalSteps) * time.Millisecond
|
||||
for currentLevel > cmd.Target {
|
||||
currentLevel--
|
||||
if err := ctx.Client.Main.SetFader(currentLevel); err != nil {
|
||||
return fmt.Errorf("failed to set Main L/R fader level: %w", err)
|
||||
}
|
||||
time.Sleep(stepDuration)
|
||||
}
|
||||
fmt.Fprintf(ctx.Out, "Main L/R fade-out completed. Final level: %.2f\n", currentLevel)
|
||||
return nil
|
||||
}
|
||||
569
main.go
569
main.go
@@ -2,115 +2,488 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"runtime/debug"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/alecthomas/kong"
|
||||
"github.com/charmbracelet/log"
|
||||
kongcompletion "github.com/jotaen/kong-completion"
|
||||
"github.com/onyx-and-iris/xair-cli/internal/xair"
|
||||
)
|
||||
|
||||
var version string // Version of the CLI, set at build time.
|
||||
// MainCmdGroup defines the command group for controlling the Main L/R output, including commands for mute state, fader level, and fade-in/fade-out times.
|
||||
type MainCmdGroup struct {
|
||||
Mute MainMuteCmd `help:"Get or set the mute state of the Main L/R output." cmd:""`
|
||||
|
||||
// VersionFlag is a custom flag type that prints the version and exits.
|
||||
type VersionFlag string
|
||||
Fader MainFaderCmd `help:"Get or set the fader level of the Main L/R output." cmd:""`
|
||||
Fadein MainFadeinCmd `help:"Fade in the Main L/R output over a specified duration." cmd:""`
|
||||
Fadeout MainFadeoutCmd `help:"Fade out the Main L/R output over a specified duration." cmd:""`
|
||||
|
||||
func (v VersionFlag) Decode(_ *kong.DecodeContext) error { return nil } // nolint: revive
|
||||
func (v VersionFlag) IsBool() bool { return true } // nolint: revive
|
||||
func (v VersionFlag) BeforeApply(app *kong.Kong, vars kong.Vars) error { // nolint: revive, unparam
|
||||
fmt.Printf("xair-cli version: %s\n", vars["version"])
|
||||
app.Exit(0)
|
||||
Eq MainEqCmdGroup `help:"Commands for controlling the equalizer settings of the Main L/R output." cmd:"eq"`
|
||||
Comp MainCompCmdGroup `help:"Commands for controlling the compressor settings of the Main L/R output." cmd:"comp"`
|
||||
}
|
||||
|
||||
// MainMuteCmd defines the command for getting or setting the mute state of the Main L/R output, allowing users to specify the desired state as "true"/"on" or "false"/"off".
|
||||
type MainMuteCmd struct {
|
||||
Mute *string `arg:"" help:"The mute state to set. If not provided, the current state will be printed." optional:"" enum:"true,false"`
|
||||
}
|
||||
|
||||
// Run executes the MainMuteCmd command, either retrieving the current mute state of the Main L/R output or setting it based on the provided argument.
|
||||
func (cmd *MainMuteCmd) Run(ctx *context) error {
|
||||
if cmd.Mute == nil {
|
||||
resp, err := ctx.Client.Main.Mute()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get Main L/R mute state: %w", err)
|
||||
}
|
||||
fmt.Fprintf(ctx.Out, "Main L/R mute state: %t\n", resp)
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := ctx.Client.Main.SetMute(*cmd.Mute == "true"); err != nil {
|
||||
return fmt.Errorf("failed to set Main L/R mute state: %w", err)
|
||||
}
|
||||
fmt.Fprintf(ctx.Out, "Main L/R mute state set to: %s\n", *cmd.Mute)
|
||||
return nil
|
||||
}
|
||||
|
||||
type context struct {
|
||||
Client *xair.Client
|
||||
Out io.Writer
|
||||
// MainFaderCmd defines the command for getting or setting the fader level of the Main L/R output, allowing users to specify the desired level in dB.
|
||||
type MainFaderCmd struct {
|
||||
Level *float64 `arg:"" help:"The fader level to set. If not provided, the current level will be printed." optional:""`
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
Host string `default:"mixer.local" help:"The host of the X-Air device." env:"XAIR_CLI_HOST"`
|
||||
Port int `default:"10024" help:"The port of the X-Air device." env:"XAIR_CLI_PORT"`
|
||||
Kind string `default:"xr18" help:"The kind of the X-Air device." env:"XAIR_CLI_KIND"`
|
||||
}
|
||||
|
||||
// CLI is the main struct for the command-line interface.
|
||||
// It embeds the Config struct for global configuration and defines the available commands and flags.
|
||||
type CLI struct {
|
||||
Config `embed:"" prefix:"" help:"The configuration for the CLI."`
|
||||
|
||||
Version VersionFlag `help:"Print gobs-cli version information and quit" name:"version" short:"v"`
|
||||
|
||||
Completion kongcompletion.Completion `help:"Generate shell completion scripts." cmd:"" aliases:"c"`
|
||||
|
||||
Raw RawCmd `help:"Send raw OSC messages to the mixer." cmd:"" group:"Raw"`
|
||||
Main MainCmdGroup `help:"Control the Main L/R output" cmd:"" group:"Main"`
|
||||
Strip StripCmdGroup `help:"Control the strips." cmd:"" group:"Strip"`
|
||||
Bus BusCmdGroup `help:"Control the buses." cmd:"" group:"Bus"`
|
||||
Headamp HeadampCmdGroup `help:"Control input gain and phantom power." cmd:"" group:"Headamp"`
|
||||
}
|
||||
|
||||
func main() {
|
||||
var cli CLI
|
||||
kongcompletion.Register(kong.Must(&cli))
|
||||
ctx := kong.Parse(
|
||||
&cli,
|
||||
kong.Name("xair-cli"),
|
||||
kong.Description("A CLI to control Behringer X-Air mixers."),
|
||||
kong.UsageOnError(),
|
||||
kong.ConfigureHelp(kong.HelpOptions{
|
||||
Compact: true,
|
||||
}),
|
||||
kong.Vars{
|
||||
"version": func() string {
|
||||
if version == "" {
|
||||
info, ok := debug.ReadBuildInfo()
|
||||
if !ok {
|
||||
return "(unable to read build info)"
|
||||
}
|
||||
version = strings.Split(info.Main.Version, "-")[0]
|
||||
}
|
||||
return version
|
||||
}(),
|
||||
},
|
||||
)
|
||||
|
||||
ctx.FatalIfErrorf(run(ctx, cli.Config))
|
||||
}
|
||||
|
||||
// run is the main entry point for the CLI.
|
||||
// It connects to the X-Air device, retrieves mixer info, and then runs the command.
|
||||
func run(ctx *kong.Context, config Config) error {
|
||||
client, err := connect(config)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to connect to X-Air device: %w", err)
|
||||
}
|
||||
defer client.Close()
|
||||
|
||||
client.StartListening()
|
||||
resp, err := client.RequestInfo()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
log.Infof("Received mixer info: %+v", resp)
|
||||
|
||||
ctx.Bind(&context{
|
||||
Client: client,
|
||||
Out: os.Stdout,
|
||||
})
|
||||
|
||||
return ctx.Run()
|
||||
}
|
||||
|
||||
// connect creates a new X-Air client based on the provided configuration.
|
||||
func connect(config Config) (*xair.Client, error) {
|
||||
client, err := xair.NewClient(config.Host, config.Port, xair.WithKind(config.Kind))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
// Run executes the MainFaderCmd command, either retrieving the current fader level of the Main L/R output or setting it based on the provided argument.
|
||||
func (cmd *MainFaderCmd) Run(ctx *context) error {
|
||||
if cmd.Level == nil {
|
||||
resp, err := ctx.Client.Main.Fader()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get Main L/R fader level: %w", err)
|
||||
}
|
||||
fmt.Fprintf(ctx.Out, "Main L/R fader level: %.2f\n", resp)
|
||||
return nil
|
||||
}
|
||||
|
||||
return client, nil
|
||||
if err := ctx.Client.Main.SetFader(*cmd.Level); err != nil {
|
||||
return fmt.Errorf("failed to set Main L/R fader level: %w", err)
|
||||
}
|
||||
fmt.Fprintf(ctx.Out, "Main L/R fader level set to: %.2f\n", *cmd.Level)
|
||||
return nil
|
||||
}
|
||||
|
||||
// MainFadeinCmd defines the command for getting or setting the fade-in time of the Main L/R output, allowing users to specify the desired duration for the fade-in effect.
|
||||
type MainFadeinCmd struct {
|
||||
Duration time.Duration `flag:"" help:"The duration of the fade-in. (in seconds.)" default:"5s"`
|
||||
Target float64 ` help:"The target level for the fade-in. If not provided, the current target level will be printed." default:"0.0" arg:""`
|
||||
}
|
||||
|
||||
// Run executes the MainFadeinCmd command, either retrieving the current fade-in time of the Main L/R output or setting it based on the provided argument, with an optional target level for the fade-in effect.
|
||||
func (cmd *MainFadeinCmd) Run(ctx *context) error {
|
||||
currentLevel, err := ctx.Client.Main.Fader()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get Main L/R fader level: %w", err)
|
||||
}
|
||||
|
||||
if currentLevel >= cmd.Target {
|
||||
return fmt.Errorf(
|
||||
"current fader level (%.2f) is already at or above the target level (%.2f)",
|
||||
currentLevel,
|
||||
cmd.Target,
|
||||
)
|
||||
}
|
||||
|
||||
totalSteps := float64(cmd.Target - currentLevel)
|
||||
stepDuration := time.Duration(cmd.Duration.Seconds()*1000/totalSteps) * time.Millisecond
|
||||
for currentLevel < cmd.Target {
|
||||
currentLevel++
|
||||
if err := ctx.Client.Main.SetFader(currentLevel); err != nil {
|
||||
return fmt.Errorf("failed to set Main L/R fader level: %w", err)
|
||||
}
|
||||
time.Sleep(stepDuration)
|
||||
}
|
||||
fmt.Fprintf(ctx.Out, "Main L/R fade-in completed. Final level: %.2f\n", currentLevel)
|
||||
return nil
|
||||
}
|
||||
|
||||
// MainFadeoutCmd defines the command for getting or setting the fade-out time of the Main L/R output, allowing users to specify the desired duration for the fade-out effect and an optional target level to fade out to.
|
||||
type MainFadeoutCmd struct {
|
||||
Duration time.Duration `flag:"" help:"The duration of the fade-out. (in seconds.)" default:"5s"`
|
||||
Target float64 ` help:"The target level for the fade-out. If not provided, the current target level will be printed." default:"-90.0" arg:""`
|
||||
}
|
||||
|
||||
// Run executes the MainFadeoutCmd command, either retrieving the current fade-out time of the Main L/R output or setting it based on the provided argument, with an optional target level for the fade-out effect.
|
||||
func (cmd *MainFadeoutCmd) Run(ctx *context) error {
|
||||
currentLevel, err := ctx.Client.Main.Fader()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get Main L/R fader level: %w", err)
|
||||
}
|
||||
|
||||
if currentLevel <= cmd.Target {
|
||||
return fmt.Errorf(
|
||||
"current fader level (%.2f) is already at or below the target level (%.2f)",
|
||||
currentLevel,
|
||||
cmd.Target,
|
||||
)
|
||||
}
|
||||
|
||||
totalSteps := float64(currentLevel - cmd.Target)
|
||||
stepDuration := time.Duration(cmd.Duration.Seconds()*1000/totalSteps) * time.Millisecond
|
||||
for currentLevel > cmd.Target {
|
||||
currentLevel--
|
||||
if err := ctx.Client.Main.SetFader(currentLevel); err != nil {
|
||||
return fmt.Errorf("failed to set Main L/R fader level: %w", err)
|
||||
}
|
||||
time.Sleep(stepDuration)
|
||||
}
|
||||
fmt.Fprintf(ctx.Out, "Main L/R fade-out completed. Final level: %.2f\n", currentLevel)
|
||||
return nil
|
||||
}
|
||||
|
||||
// MainEqCmdGroup defines the command group for controlling the equalizer settings of the Main L/R output, including commands for getting or setting the EQ parameters.
|
||||
type MainEqCmdGroup struct {
|
||||
On MainEqOnCmd `help:"Get or set the EQ on/off state of the Main L/R output." cmd:"on"`
|
||||
Band struct {
|
||||
Band int `arg:"" help:"The EQ band number."`
|
||||
Gain MainEqBandGainCmd `help:"Get or set the gain of the specified EQ band." cmd:"gain"`
|
||||
Freq MainEqBandFreqCmd `help:"Get or set the frequency of the specified EQ band." cmd:"freq"`
|
||||
Q MainEqBandQCmd `help:"Get or set the Q factor of the specified EQ band." cmd:"q"`
|
||||
Type MainEqBandTypeCmd `help:"Get or set the type of the specified EQ band." cmd:"type"`
|
||||
} `help:"Commands for controlling individual EQ bands of the Main L/R output." arg:""`
|
||||
}
|
||||
|
||||
// Validate checks if the provided EQ band number is within the valid range (1-6) for the Main L/R output.
|
||||
func (cmd *MainEqCmdGroup) Validate(ctx kong.Context) error {
|
||||
if cmd.Band.Band < 1 || cmd.Band.Band > 6 {
|
||||
return fmt.Errorf("invalid EQ band number: %d. Valid range is 1-6", cmd.Band.Band)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// MainEqOnCmd defines the command for getting or setting the EQ on/off state of the Main L/R output, allowing users to specify the desired state as "true"/"on" or "false"/"off".
|
||||
type MainEqOnCmd struct {
|
||||
Enable *string `arg:"" help:"The EQ on/off state to set. If not provided, the current state will be printed." optional:"" enum:"true,false"`
|
||||
}
|
||||
|
||||
// Run executes the MainEqOnCmd command, either retrieving the current EQ on/off state of the Main L/R output or setting it based on the provided argument.
|
||||
func (cmd *MainEqOnCmd) Run(ctx *context, main *MainCmdGroup) error {
|
||||
if cmd.Enable == nil {
|
||||
resp, err := ctx.Client.Main.Eq.On(0)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get Main L/R EQ on/off state: %w", err)
|
||||
}
|
||||
fmt.Fprintf(ctx.Out, "Main L/R EQ on/off state: %t\n", resp)
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := ctx.Client.Main.Eq.SetOn(0, *cmd.Enable == "true"); err != nil {
|
||||
return fmt.Errorf("failed to set Main L/R EQ on/off state: %w", err)
|
||||
}
|
||||
fmt.Fprintf(ctx.Out, "Main L/R EQ on/off state set to: %t\n", *cmd.Enable == "true")
|
||||
return nil
|
||||
}
|
||||
|
||||
// MainEqBandGainCmd defines the command for getting or setting the gain of a specific EQ band on the Main L/R output, allowing users to specify the desired gain in dB.
|
||||
type MainEqBandGainCmd struct {
|
||||
Level *float64 `arg:"" help:"The gain level to set for the specified EQ band. If not provided, the current gain will be printed." optional:""`
|
||||
}
|
||||
|
||||
// Run executes the MainEqBandGainCmd command, either retrieving the current gain of a specific EQ band on the Main L/R output or setting it based on the provided argument.
|
||||
func (cmd *MainEqBandGainCmd) Run(ctx *context, main *MainCmdGroup, mainEq *MainEqCmdGroup) error {
|
||||
if cmd.Level == nil {
|
||||
resp, err := ctx.Client.Main.Eq.Gain(0, mainEq.Band.Band)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get Main L/R EQ band %d gain: %w", mainEq.Band.Band, err)
|
||||
}
|
||||
fmt.Fprintf(ctx.Out, "Main L/R EQ band %d gain: %.2f dB\n", mainEq.Band.Band, resp)
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := ctx.Client.Main.Eq.SetGain(0, mainEq.Band.Band, *cmd.Level); err != nil {
|
||||
return fmt.Errorf("failed to set Main L/R EQ band %d gain: %w", mainEq.Band.Band, err)
|
||||
}
|
||||
fmt.Fprintf(ctx.Out, "Main L/R EQ band %d gain set to: %.2f dB\n", mainEq.Band.Band, *cmd.Level)
|
||||
return nil
|
||||
}
|
||||
|
||||
// MainEqBandFreqCmd defines the command for getting or setting the frequency of a specific EQ band on the Main L/R output, allowing users to specify the desired frequency in Hz.
|
||||
type MainEqBandFreqCmd struct {
|
||||
Frequency *float64 `arg:"" help:"The frequency to set for the specified EQ band. If not provided, the current frequency will be printed." optional:""`
|
||||
}
|
||||
|
||||
// Run executes the MainEqBandFreqCmd command, either retrieving the current frequency of a specific EQ band on the Main L/R output or setting it based on the provided argument.
|
||||
func (cmd *MainEqBandFreqCmd) Run(ctx *context, main *MainCmdGroup, mainEq *MainEqCmdGroup) error {
|
||||
if cmd.Frequency == nil {
|
||||
resp, err := ctx.Client.Main.Eq.Frequency(0, mainEq.Band.Band)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get Main L/R EQ band %d frequency: %w", mainEq.Band.Band, err)
|
||||
}
|
||||
fmt.Fprintf(ctx.Out, "Main L/R EQ band %d frequency: %.2f Hz\n", mainEq.Band.Band, resp)
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := ctx.Client.Main.Eq.SetFrequency(0, mainEq.Band.Band, *cmd.Frequency); err != nil {
|
||||
return fmt.Errorf("failed to set Main L/R EQ band %d frequency: %w", mainEq.Band.Band, err)
|
||||
}
|
||||
fmt.Fprintf(ctx.Out, "Main L/R EQ band %d frequency set to: %.2f Hz\n", mainEq.Band.Band, *cmd.Frequency)
|
||||
return nil
|
||||
}
|
||||
|
||||
// MainEqBandQCmd defines the command for getting or setting the Q factor of a specific EQ band on the Main L/R output, allowing users to specify the desired Q factor.
|
||||
type MainEqBandQCmd struct {
|
||||
Q *float64 `arg:"" help:"The Q factor to set for the specified EQ band. If not provided, the current Q factor will be printed." optional:""`
|
||||
}
|
||||
|
||||
// Run executes the MainEqBandQCmd command, either retrieving the current Q factor of a specific EQ band on the Main L/R output or setting it based on the provided argument.
|
||||
func (cmd *MainEqBandQCmd) Run(ctx *context, main *MainCmdGroup, mainEq *MainEqCmdGroup) error {
|
||||
if cmd.Q == nil {
|
||||
resp, err := ctx.Client.Main.Eq.Q(0, mainEq.Band.Band)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get Main L/R EQ band %d Q factor: %w", mainEq.Band.Band, err)
|
||||
}
|
||||
fmt.Fprintf(ctx.Out, "Main L/R EQ band %d Q factor: %.2f\n", mainEq.Band.Band, resp)
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := ctx.Client.Main.Eq.SetQ(0, mainEq.Band.Band, *cmd.Q); err != nil {
|
||||
return fmt.Errorf("failed to set Main L/R EQ band %d Q factor: %w", mainEq.Band.Band, err)
|
||||
}
|
||||
fmt.Fprintf(ctx.Out, "Main L/R EQ band %d Q factor set to: %.2f\n", mainEq.Band.Band, *cmd.Q)
|
||||
return nil
|
||||
}
|
||||
|
||||
// MainEqBandTypeCmd defines the command for getting or setting the type of a specific EQ band on the Main L/R output, allowing users to specify the desired type as "peaking", "low_shelf", "high_shelf", "low_pass", or "high_pass".
|
||||
type MainEqBandTypeCmd struct {
|
||||
Type *string `arg:"" help:"The type to set for the specified EQ band. If not provided, the current type will be printed." optional:"" enum:"peaking,low_shelf,high_shelf,low_pass,high_pass"`
|
||||
}
|
||||
|
||||
// Run executes the MainEqBandTypeCmd command, either retrieving the current type of a specific EQ band on the Main L/R output or setting it based on the provided argument.
|
||||
func (cmd *MainEqBandTypeCmd) Run(ctx *context, main *MainCmdGroup, mainEq *MainEqCmdGroup) error {
|
||||
if cmd.Type == nil {
|
||||
resp, err := ctx.Client.Main.Eq.Type(0, mainEq.Band.Band)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get Main L/R EQ band %d type: %w", mainEq.Band.Band, err)
|
||||
}
|
||||
fmt.Fprintf(ctx.Out, "Main L/R EQ band %d type: %s\n", mainEq.Band.Band, resp)
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := ctx.Client.Main.Eq.SetType(0, mainEq.Band.Band, *cmd.Type); err != nil {
|
||||
return fmt.Errorf("failed to set Main L/R EQ band %d type: %w", mainEq.Band.Band, err)
|
||||
}
|
||||
fmt.Fprintf(ctx.Out, "Main L/R EQ band %d type set to: %s\n", mainEq.Band.Band, *cmd.Type)
|
||||
return nil
|
||||
}
|
||||
|
||||
// MainCompCmdGroup defines the command group for controlling the compressor settings of the Main L/R output, including commands for getting or setting the compressor parameters.
|
||||
type MainCompCmdGroup struct {
|
||||
On MainCompOnCmd `help:"Get or set the compressor on/off state of the Main L/R output." cmd:"on"`
|
||||
Mode MainCompModeCmd `help:"Get or set the compressor mode of the Main L/R output." cmd:"mode"`
|
||||
Threshold MainCompThresholdCmd `help:"Get or set the compressor threshold of the Main L/R output." cmd:"threshold"`
|
||||
Ratio MainCompRatioCmd `help:"Get or set the compressor ratio of the Main L/R output." cmd:"ratio"`
|
||||
Mix MainCompMixCmd `help:"Get or set the compressor mix level of the Main L/R output." cmd:"mix"`
|
||||
Makeup MainCompMakeupCmd `help:"Get or set the compressor makeup gain of the Main L/R output." cmd:"makeup"`
|
||||
Attack MainCompAttackCmd `help:"Get or set the compressor attack time of the Main L/R output." cmd:"attack"`
|
||||
Hold MainCompHoldCmd `help:"Get or set the compressor hold time of the Main L/R output." cmd:"hold"`
|
||||
Release MainCompReleaseCmd `help:"Get or set the compressor release time of the Main L/R output." cmd:"release"`
|
||||
}
|
||||
|
||||
// MainCompOnCmd defines the command for getting or setting the compressor on/off state of the Main L/R output, allowing users to specify the desired state as "true"/"on" or "false"/"off".
|
||||
type MainCompOnCmd struct {
|
||||
Enable *string `arg:"" help:"The compressor on/off state to set. If not provided, the current state will be printed." optional:"" enum:"true,false"`
|
||||
}
|
||||
|
||||
// Run executes the MainCompOnCmd command, either retrieving the current compressor on/off state of the Main L/R output or setting it based on the provided argument.
|
||||
func (cmd *MainCompOnCmd) Run(ctx *context, main *MainCmdGroup) error {
|
||||
if cmd.Enable == nil {
|
||||
resp, err := ctx.Client.Main.Comp.On(0)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get Main L/R compressor on/off state: %w", err)
|
||||
}
|
||||
fmt.Fprintf(ctx.Out, "Main L/R compressor on/off state: %t\n", resp)
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := ctx.Client.Main.Comp.SetOn(0, *cmd.Enable == "true"); err != nil {
|
||||
return fmt.Errorf("failed to set Main L/R compressor on/off state: %w", err)
|
||||
}
|
||||
fmt.Fprintf(ctx.Out, "Main L/R compressor on/off state set to: %t\n", *cmd.Enable == "true")
|
||||
return nil
|
||||
}
|
||||
|
||||
// MainCompModeCmd defines the command for getting or setting the compressor mode of the Main L/R output, allowing users to specify the desired mode as "comp" or "exp".
|
||||
type MainCompModeCmd struct {
|
||||
Mode *string `arg:"" help:"The compressor mode to set. If not provided, the current mode will be printed." optional:"" enum:"comp,exp"`
|
||||
}
|
||||
|
||||
// Run executes the MainCompModeCmd command, either retrieving the current compressor mode of the Main L/R output or setting it based on the provided argument.
|
||||
func (cmd *MainCompModeCmd) Run(ctx *context, main *MainCmdGroup) error {
|
||||
if cmd.Mode == nil {
|
||||
resp, err := ctx.Client.Main.Comp.Mode(0)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get Main L/R compressor mode: %w", err)
|
||||
}
|
||||
fmt.Fprintf(ctx.Out, "Main L/R compressor mode: %s\n", resp)
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := ctx.Client.Main.Comp.SetMode(0, *cmd.Mode); err != nil {
|
||||
return fmt.Errorf("failed to set Main L/R compressor mode: %w", err)
|
||||
}
|
||||
fmt.Fprintf(ctx.Out, "Main L/R compressor mode set to: %s\n", *cmd.Mode)
|
||||
return nil
|
||||
}
|
||||
|
||||
// MainCompThresholdCmd defines the command for getting or setting the compressor threshold of the Main L/R output, allowing users to specify the desired threshold in dB.
|
||||
type MainCompThresholdCmd struct {
|
||||
Threshold *float64 `arg:"" help:"The compressor threshold to set. If not provided, the current threshold will be printed." optional:""`
|
||||
}
|
||||
|
||||
// Run executes the MainCompThresholdCmd command, either retrieving the current compressor threshold of the Main L/R output or setting it based on the provided argument.
|
||||
func (cmd *MainCompThresholdCmd) Run(ctx *context, main *MainCmdGroup) error {
|
||||
if cmd.Threshold == nil {
|
||||
resp, err := ctx.Client.Main.Comp.Threshold(0)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get Main L/R compressor threshold: %w", err)
|
||||
}
|
||||
fmt.Fprintf(ctx.Out, "Main L/R compressor threshold: %.2f dB\n", resp)
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := ctx.Client.Main.Comp.SetThreshold(0, *cmd.Threshold); err != nil {
|
||||
return fmt.Errorf("failed to set Main L/R compressor threshold: %w", err)
|
||||
}
|
||||
fmt.Fprintf(ctx.Out, "Main L/R compressor threshold set to: %.2f dB\n", *cmd.Threshold)
|
||||
return nil
|
||||
}
|
||||
|
||||
// MainCompRatioCmd defines the command for getting or setting the compressor ratio of the Main L/R output, allowing users to specify the desired ratio.
|
||||
type MainCompRatioCmd struct {
|
||||
Ratio *float64 `arg:"" help:"The compressor ratio to set. If not provided, the current ratio will be printed." optional:""`
|
||||
}
|
||||
|
||||
// Run executes the MainCompRatioCmd command, either retrieving the current compressor ratio of the Main L/R output or setting it based on the provided argument.
|
||||
func (cmd *MainCompRatioCmd) Run(ctx *context, main *MainCmdGroup) error {
|
||||
if cmd.Ratio == nil {
|
||||
resp, err := ctx.Client.Main.Comp.Ratio(0)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get Main L/R compressor ratio: %w", err)
|
||||
}
|
||||
fmt.Fprintf(ctx.Out, "Main L/R compressor ratio: %.2f\n", resp)
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := ctx.Client.Main.Comp.SetRatio(0, *cmd.Ratio); err != nil {
|
||||
return fmt.Errorf("failed to set Main L/R compressor ratio: %w", err)
|
||||
}
|
||||
fmt.Fprintf(ctx.Out, "Main L/R compressor ratio set to: %.2f\n", *cmd.Ratio)
|
||||
return nil
|
||||
}
|
||||
|
||||
// MainCompMixCmd defines the command for getting or setting the compressor mix level of the Main L/R output, allowing users to specify the desired mix level in percentage.
|
||||
type MainCompMixCmd struct {
|
||||
Mix *float64 `arg:"" help:"The compressor mix level to set. If not provided, the current mix level will be printed." optional:""`
|
||||
}
|
||||
|
||||
// Run executes the MainCompMixCmd command, either retrieving the current compressor mix level of the Main L/R output or setting it based on the provided argument.
|
||||
func (cmd *MainCompMixCmd) Run(ctx *context, main *MainCmdGroup) error {
|
||||
if cmd.Mix == nil {
|
||||
resp, err := ctx.Client.Main.Comp.Mix(0)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get Main L/R compressor mix level: %w", err)
|
||||
}
|
||||
fmt.Fprintf(ctx.Out, "Main L/R compressor mix level: %.2f%%\n", resp)
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := ctx.Client.Main.Comp.SetMix(0, *cmd.Mix); err != nil {
|
||||
return fmt.Errorf("failed to set Main L/R compressor mix level: %w", err)
|
||||
}
|
||||
fmt.Fprintf(ctx.Out, "Main L/R compressor mix level set to: %.2f%%\n", *cmd.Mix)
|
||||
return nil
|
||||
}
|
||||
|
||||
// MainCompMakeupCmd defines the command for getting or setting the compressor makeup gain of the Main L/R output, allowing users to specify the desired makeup gain in dB.
|
||||
type MainCompMakeupCmd struct {
|
||||
Makeup *float64 `arg:"" help:"The compressor makeup gain to set. If not provided, the current makeup gain will be printed." optional:""`
|
||||
}
|
||||
|
||||
// Run executes the MainCompMakeupCmd command, either retrieving the current compressor makeup gain of the Main L/R output or setting it based on the provided argument.
|
||||
func (cmd *MainCompMakeupCmd) Run(ctx *context, main *MainCmdGroup) error {
|
||||
if cmd.Makeup == nil {
|
||||
resp, err := ctx.Client.Main.Comp.Makeup(0)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get Main L/R compressor makeup gain: %w", err)
|
||||
}
|
||||
fmt.Fprintf(ctx.Out, "Main L/R compressor makeup gain: %.2f dB\n", resp)
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := ctx.Client.Main.Comp.SetMakeup(0, *cmd.Makeup); err != nil {
|
||||
return fmt.Errorf("failed to set Main L/R compressor makeup gain: %w", err)
|
||||
}
|
||||
fmt.Fprintf(ctx.Out, "Main L/R compressor makeup gain set to: %.2f dB\n", *cmd.Makeup)
|
||||
return nil
|
||||
}
|
||||
|
||||
// MainCompAttackCmd defines the command for getting or setting the compressor attack time of the Main L/R output, allowing users to specify the desired attack time in milliseconds.
|
||||
type MainCompAttackCmd struct {
|
||||
Attack *float64 `arg:"" help:"The compressor attack time to set. If not provided, the current attack time will be printed." optional:""`
|
||||
}
|
||||
|
||||
// Run executes the MainCompAttackCmd command, either retrieving the current compressor attack time of the Main L/R output or setting it based on the provided argument.
|
||||
func (cmd *MainCompAttackCmd) Run(ctx *context, main *MainCmdGroup) error {
|
||||
if cmd.Attack == nil {
|
||||
resp, err := ctx.Client.Main.Comp.Attack(0)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get Main L/R compressor attack time: %w", err)
|
||||
}
|
||||
fmt.Fprintf(ctx.Out, "Main L/R compressor attack time: %.2f ms\n", resp)
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := ctx.Client.Main.Comp.SetAttack(0, *cmd.Attack); err != nil {
|
||||
return fmt.Errorf("failed to set Main L/R compressor attack time: %w", err)
|
||||
}
|
||||
fmt.Fprintf(ctx.Out, "Main L/R compressor attack time set to: %.2f ms\n", *cmd.Attack)
|
||||
return nil
|
||||
}
|
||||
|
||||
// MainCompHoldCmd defines the command for getting or setting the compressor hold time of the Main L/R output, allowing users to specify the desired hold time in milliseconds.
|
||||
type MainCompHoldCmd struct {
|
||||
Hold *float64 `arg:"" help:"The compressor hold time to set. If not provided, the current hold time will be printed." optional:""`
|
||||
}
|
||||
|
||||
// Run executes the MainCompHoldCmd command, either retrieving the current compressor hold time of the Main L/R output or setting it based on the provided argument.
|
||||
func (cmd *MainCompHoldCmd) Run(ctx *context, main *MainCmdGroup) error {
|
||||
if cmd.Hold == nil {
|
||||
resp, err := ctx.Client.Main.Comp.Hold(0)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get Main L/R compressor hold time: %w", err)
|
||||
}
|
||||
fmt.Fprintf(ctx.Out, "Main L/R compressor hold time: %.2f ms\n", resp)
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := ctx.Client.Main.Comp.SetHold(0, *cmd.Hold); err != nil {
|
||||
return fmt.Errorf("failed to set Main L/R compressor hold time: %w", err)
|
||||
}
|
||||
fmt.Fprintf(ctx.Out, "Main L/R compressor hold time set to: %.2f ms\n", *cmd.Hold)
|
||||
return nil
|
||||
}
|
||||
|
||||
// MainCompReleaseCmd defines the command for getting or setting the compressor release time of the Main L/R output, allowing users to specify the desired release time in milliseconds.
|
||||
type MainCompReleaseCmd struct {
|
||||
Release *float64 `arg:"" help:"The compressor release time to set. If not provided, the current release time will be printed." optional:""`
|
||||
}
|
||||
|
||||
// Run executes the MainCompReleaseCmd command, either retrieving the current compressor release time of the Main L/R output or setting it based on the provided argument.
|
||||
func (cmd *MainCompReleaseCmd) Run(ctx *context, main *MainCmdGroup) error {
|
||||
if cmd.Release == nil {
|
||||
resp, err := ctx.Client.Main.Comp.Release(0)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get Main L/R compressor release time: %w", err)
|
||||
}
|
||||
fmt.Fprintf(ctx.Out, "Main L/R compressor release time: %.2f ms\n", resp)
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := ctx.Client.Main.Comp.SetRelease(0, *cmd.Release); err != nil {
|
||||
return fmt.Errorf("failed to set Main L/R compressor release time: %w", err)
|
||||
}
|
||||
fmt.Fprintf(ctx.Out, "Main L/R compressor release time set to: %.2f ms\n", *cmd.Release)
|
||||
return nil
|
||||
}
|
||||
|
||||
15
raw.go
15
raw.go
@@ -2,14 +2,14 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/charmbracelet/log"
|
||||
)
|
||||
|
||||
// RawCmd represents the command to send raw OSC messages to the mixer.
|
||||
type RawCmd struct {
|
||||
Timeout time.Duration `help:"Timeout for the OSC message send operation." default:"200ms" short:"t"`
|
||||
Address string `help:"The OSC address to send the message to." arg:""`
|
||||
Args []string `help:"The arguments to include in the OSC message." arg:"" optional:""`
|
||||
Address string `help:"The OSC address to send the message to." arg:""`
|
||||
Args []string `help:"The arguments to include in the OSC message." arg:"" optional:""`
|
||||
}
|
||||
|
||||
// Run executes the RawCmd by sending the specified OSC message to the mixer and optionally waiting for a response.
|
||||
@@ -22,7 +22,12 @@ func (cmd *RawCmd) Run(ctx *context) error {
|
||||
return fmt.Errorf("failed to send raw OSC message: %w", err)
|
||||
}
|
||||
|
||||
msg, err := ctx.Client.ReceiveMessage(cmd.Timeout)
|
||||
if len(params) > 0 {
|
||||
log.Debugf("Sent OSC message: %s with args: %v\n", cmd.Address, cmd.Args)
|
||||
return nil
|
||||
}
|
||||
|
||||
msg, err := ctx.Client.ReceiveMessage()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to receive response for raw OSC message: %w", err)
|
||||
}
|
||||
|
||||
75
snapshot.go
Normal file
75
snapshot.go
Normal file
@@ -0,0 +1,75 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
type SnapshotCmdGroup struct {
|
||||
List ListCmd `help:"List all snapshots." cmd:"list"`
|
||||
Index struct {
|
||||
Index int `arg:"" help:"The index of the snapshot."`
|
||||
Name NameCmd `help:"Get or set the name of a snapshot." cmd:"name"`
|
||||
Save SaveCmd `help:"Save the current mixer state to a snapshot." cmd:"save"`
|
||||
Load LoadCmd `help:"Load a mixer state from a snapshot." cmd:"load"`
|
||||
Delete DeleteCmd `help:"Delete a snapshot." cmd:"delete"`
|
||||
} `help:"The index of the snapshot." arg:""`
|
||||
}
|
||||
|
||||
type ListCmd struct {
|
||||
}
|
||||
|
||||
func (c *ListCmd) Run(ctx *context) error {
|
||||
for i := range 64 {
|
||||
name, err := ctx.Client.Snapshot.Name(i + 1)
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
if name == "" {
|
||||
continue
|
||||
}
|
||||
fmt.Fprintf(ctx.Out, "%d: %s\n", i+1, name)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type NameCmd struct {
|
||||
Name *string `arg:"" help:"The name of the snapshot." optional:""`
|
||||
}
|
||||
|
||||
func (c *NameCmd) Run(ctx *context, snapshot *SnapshotCmdGroup) error {
|
||||
if c.Name == nil {
|
||||
name, err := ctx.Client.Snapshot.Name(snapshot.Index.Index)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Fprintln(ctx.Out, name)
|
||||
return nil
|
||||
}
|
||||
|
||||
return ctx.Client.Snapshot.SetName(snapshot.Index.Index, *c.Name)
|
||||
}
|
||||
|
||||
type SaveCmd struct {
|
||||
Name string `arg:"" help:"The name of the snapshot."`
|
||||
}
|
||||
|
||||
func (c *SaveCmd) Run(ctx *context, snapshot *SnapshotCmdGroup) error {
|
||||
err := ctx.Client.Snapshot.CurrentName(c.Name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return ctx.Client.Snapshot.CurrentSave(snapshot.Index.Index)
|
||||
}
|
||||
|
||||
type LoadCmd struct {
|
||||
}
|
||||
|
||||
func (c *LoadCmd) Run(ctx *context, snapshot *SnapshotCmdGroup) error {
|
||||
return ctx.Client.Snapshot.CurrentLoad(snapshot.Index.Index)
|
||||
}
|
||||
|
||||
type DeleteCmd struct {
|
||||
}
|
||||
|
||||
func (c *DeleteCmd) Run(ctx *context, snapshot *SnapshotCmdGroup) error {
|
||||
return ctx.Client.Snapshot.CurrentDelete(snapshot.Index.Index)
|
||||
}
|
||||
Reference in New Issue
Block a user