mirror of
https://github.com/onyx-and-iris/xair-cli.git
synced 2026-04-18 06:43:33 +00:00
Compare commits
17 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3ed0560d08 | |||
| 6a4577118f | |||
| 1597f8f352 | |||
| e80f17d211 | |||
| 40c7d03ff1 | |||
| 561faa0e95 | |||
| ce398e9a09 | |||
| b8b637b4b7 | |||
| 52d51a7094 | |||
| 09a4e9fbfc | |||
| 04f7319776 | |||
| 0c67887ad7 | |||
| 4db173154b | |||
| 27922d41bb | |||
| e21fd59564 | |||
| 2d829e28e1 | |||
| 3f8861ded2 |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -36,3 +36,5 @@ go.work.sum
|
|||||||
# .vscode/
|
# .vscode/
|
||||||
|
|
||||||
# End of ignr
|
# End of ignr
|
||||||
|
|
||||||
|
update_readme.py
|
||||||
108
README.md
108
README.md
@@ -12,11 +12,21 @@ go install github.com/onyx-and-iris/xair-cli@latest
|
|||||||
|
|
||||||
- --host/-H: Host of the mixer.
|
- --host/-H: Host of the mixer.
|
||||||
- --port/-P: Port of the mixer.
|
- --port/-P: Port of the mixer.
|
||||||
- --kind/-k: The kind of mixer. May one of (*xair*, *x32*).
|
- --kind/-k: The kind of mixer. May be one of (*xair*, *x32*).
|
||||||
- Use this flag to connect to an x32 mixer.
|
- 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
|
#### Environment Variables
|
||||||
|
|
||||||
|
Or you may load them from your environment:
|
||||||
|
|
||||||
Example .envrc:
|
Example .envrc:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
@@ -25,7 +35,8 @@ Example .envrc:
|
|||||||
XAIR_CLI_HOST=mixer.local
|
XAIR_CLI_HOST=mixer.local
|
||||||
XAIR_CLI_PORT=10024
|
XAIR_CLI_PORT=10024
|
||||||
XAIR_CLI_KIND=xair
|
XAIR_CLI_KIND=xair
|
||||||
XAIR_CLI_RAW_TIMEOUT=50ms
|
XAIR_CLI_TIMEOUT=100ms
|
||||||
|
XAIR_CLI_LOGLEVEL=warn
|
||||||
```
|
```
|
||||||
|
|
||||||
### Use
|
### Use
|
||||||
@@ -40,7 +51,9 @@ Flags:
|
|||||||
-H, --host="mixer.local" The host of the X-Air device ($XAIR_CLI_HOST).
|
-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).
|
-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).
|
-K, --kind="xair" The kind of the X-Air device ($XAIR_CLI_KIND).
|
||||||
-v, --version Print gobs-cli version information and quit
|
-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:
|
Commands:
|
||||||
completion (c) Generate shell completion scripts.
|
completion (c) Generate shell completion scripts.
|
||||||
@@ -49,10 +62,31 @@ Raw
|
|||||||
raw Send raw OSC messages to the mixer.
|
raw Send raw OSC messages to the mixer.
|
||||||
|
|
||||||
Main
|
Main
|
||||||
main mute Get or set the mute state 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 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 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 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
|
||||||
strip <index> mute Get or set the mute state of the strip.
|
strip <index> mute Get or set the mute state of the strip.
|
||||||
@@ -73,15 +107,21 @@ Strip
|
|||||||
strip <index> eq <band> freq Get or set the frequency of the EQ band.
|
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> 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> 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 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 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 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 makeup Get or set the compressor makeup gain of the
|
||||||
strip <index> comp attack Get or set the compressor attack time of the strip.
|
strip.
|
||||||
strip <index> comp hold Get or set the compressor hold time of the strip.
|
strip <index> comp attack Get or set the compressor attack time of the
|
||||||
strip <index> comp release Get or set the compressor release time of the strip.
|
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
|
||||||
bus <index> mute Get or set the mute state of the bus.
|
bus <index> mute Get or set the mute state of the bus.
|
||||||
@@ -90,25 +130,42 @@ Bus
|
|||||||
bus <index> fadeout Fade out the bus over a specified duration.
|
bus <index> fadeout Fade out the bus over a specified duration.
|
||||||
bus <index> name Get or set the name of the bus.
|
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 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> 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> 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> 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> eq <band> type Get or set the type of the EQ band (lcut, lshv,
|
||||||
bus <index> comp on Get or set the compressor on/off state of the bus.
|
peq, veq, hshv, hcut).
|
||||||
bus <index> comp mode Get or set the compressor mode of the bus (comp, exp).
|
bus <index> comp on Get or set the compressor on/off state of the
|
||||||
bus <index> comp threshold Get or set the compressor threshold of the bus (in dB).
|
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 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 mix Get or set the compressor mix level of the bus
|
||||||
bus <index> comp makeup Get or set the compressor makeup gain of the bus (in dB).
|
(in %).
|
||||||
bus <index> comp attack Get or set the compressor attack time of the bus (in ms).
|
bus <index> comp makeup Get or set the compressor makeup gain of the bus
|
||||||
bus <index> comp hold Get or set the compressor hold time of the bus (in ms).
|
(in dB).
|
||||||
bus <index> comp release Get or set the compressor release time of the bus (in ms).
|
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
|
||||||
headamp <index> gain Get or set the gain of the 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.
|
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.
|
Run "xair-cli <command> --help" for more information on a command.
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -155,6 +212,11 @@ xair-cli raw /ch/01/config/name 'rode podmic'
|
|||||||
xair-cli raw /ch/01/config/name
|
xair-cli raw /ch/01/config/name
|
||||||
```
|
```
|
||||||
|
|
||||||
|
*Save current mixer state to a snapshot*
|
||||||
|
```console
|
||||||
|
xair-cli snapshot 20 save 'twitch live'
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
### License
|
### License
|
||||||
|
|
||||||
|
|||||||
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
|
||||||
|
}
|
||||||
@@ -13,7 +13,7 @@ var x32AddressMap = map[string]string{
|
|||||||
"mainmono": "/main/mono",
|
"mainmono": "/main/mono",
|
||||||
"strip": "/ch/%02d",
|
"strip": "/ch/%02d",
|
||||||
"bus": "/bus/%02d",
|
"bus": "/bus/%02d",
|
||||||
"headamp": "/headamp/%02d",
|
"headamp": "/headamp/%03d",
|
||||||
"snapshot": "/-snap",
|
"snapshot": "/-snap",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,16 +3,16 @@ package xair
|
|||||||
import "fmt"
|
import "fmt"
|
||||||
|
|
||||||
type Bus struct {
|
type Bus struct {
|
||||||
baseAddress string
|
|
||||||
client *Client
|
client *Client
|
||||||
|
baseAddress string
|
||||||
Eq *Eq
|
Eq *Eq
|
||||||
Comp *Comp
|
Comp *Comp
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewBus(c *Client) *Bus {
|
func newBus(c *Client) *Bus {
|
||||||
return &Bus{
|
return &Bus{
|
||||||
baseAddress: c.addressMap["bus"],
|
|
||||||
client: c,
|
client: c,
|
||||||
|
baseAddress: c.addressMap["bus"],
|
||||||
Eq: newEqForBus(c),
|
Eq: newEqForBus(c),
|
||||||
Comp: newCompForBus(c),
|
Comp: newCompForBus(c),
|
||||||
}
|
}
|
||||||
@@ -26,8 +26,11 @@ func (b *Bus) Mute(bus int) (bool, error) {
|
|||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
resp := <-b.client.respChan
|
msg, err := b.client.ReceiveMessage()
|
||||||
val, ok := resp.Arguments[0].(int32)
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
val, ok := msg.Arguments[0].(int32)
|
||||||
if !ok {
|
if !ok {
|
||||||
return false, fmt.Errorf("unexpected argument type for bus mute value")
|
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
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
resp := <-b.client.respChan
|
msg, err := b.client.ReceiveMessage()
|
||||||
val, ok := resp.Arguments[0].(float32)
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
val, ok := msg.Arguments[0].(float32)
|
||||||
if !ok {
|
if !ok {
|
||||||
return 0, fmt.Errorf("unexpected argument type for bus fader value")
|
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)
|
return "", fmt.Errorf("failed to send bus name request: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
resp := <-b.client.respChan
|
msg, err := b.client.ReceiveMessage()
|
||||||
val, ok := resp.Arguments[0].(string)
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
val, ok := msg.Arguments[0].(string)
|
||||||
if !ok {
|
if !ok {
|
||||||
return "", fmt.Errorf("unexpected argument type for bus name value")
|
return "", fmt.Errorf("unexpected argument type for bus name value")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ func NewClient(mixerIP string, mixerPort int, opts ...Option) (*Client, error) {
|
|||||||
|
|
||||||
e := &engine{
|
e := &engine{
|
||||||
Kind: KindXAir,
|
Kind: KindXAir,
|
||||||
|
timeout: 100 * time.Millisecond,
|
||||||
conn: conn,
|
conn: conn,
|
||||||
mixerAddr: mixerAddr,
|
mixerAddr: mixerAddr,
|
||||||
parser: newParser(),
|
parser: newParser(),
|
||||||
@@ -57,10 +58,10 @@ func NewClient(mixerIP string, mixerPort int, opts ...Option) (*Client, error) {
|
|||||||
engine: *e,
|
engine: *e,
|
||||||
}
|
}
|
||||||
c.Main = newMainStereo(c)
|
c.Main = newMainStereo(c)
|
||||||
c.Strip = NewStrip(c)
|
c.Strip = newStrip(c)
|
||||||
c.Bus = NewBus(c)
|
c.Bus = newBus(c)
|
||||||
c.HeadAmp = NewHeadAmp(c)
|
c.HeadAmp = newHeadAmp(c)
|
||||||
c.Snapshot = NewSnapshot(c)
|
c.Snapshot = newSnapshot(c)
|
||||||
|
|
||||||
return c, nil
|
return c, nil
|
||||||
}
|
}
|
||||||
@@ -85,32 +86,35 @@ func (c *Client) SendMessage(address string, args ...any) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ReceiveMessage receives an OSC message from the mixer
|
// ReceiveMessage receives an OSC message from the mixer
|
||||||
func (c *Client) ReceiveMessage(timeout time.Duration) (*osc.Message, error) {
|
func (c *Client) ReceiveMessage() (*osc.Message, error) {
|
||||||
t := time.Tick(timeout)
|
t := time.Tick(c.engine.timeout)
|
||||||
select {
|
select {
|
||||||
case <-t:
|
case <-t:
|
||||||
return nil, nil
|
return nil, fmt.Errorf("timeout waiting for response")
|
||||||
case val := <-c.respChan:
|
case msg := <-c.respChan:
|
||||||
if val == nil {
|
if msg == nil {
|
||||||
return nil, fmt.Errorf("no message received")
|
return nil, fmt.Errorf("no message received")
|
||||||
}
|
}
|
||||||
return val, nil
|
return msg, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// RequestInfo requests mixer information
|
// RequestInfo requests mixer information
|
||||||
func (c *Client) RequestInfo() (InfoResponse, error) {
|
func (c *Client) RequestInfo() (InfoResponse, error) {
|
||||||
|
var info InfoResponse
|
||||||
err := c.SendMessage("/xinfo")
|
err := c.SendMessage("/xinfo")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return InfoResponse{}, err
|
return info, err
|
||||||
}
|
}
|
||||||
|
|
||||||
val := <-c.respChan
|
msg, err := c.ReceiveMessage()
|
||||||
var info InfoResponse
|
if err != nil {
|
||||||
if len(val.Arguments) >= 3 {
|
return info, err
|
||||||
info.Host = val.Arguments[0].(string)
|
}
|
||||||
info.Name = val.Arguments[1].(string)
|
if len(msg.Arguments) >= 3 {
|
||||||
info.Model = val.Arguments[2].(string)
|
info.Host = msg.Arguments[0].(string)
|
||||||
|
info.Name = msg.Arguments[1].(string)
|
||||||
|
info.Model = msg.Arguments[2].(string)
|
||||||
}
|
}
|
||||||
return info, nil
|
return info, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,18 @@ import "fmt"
|
|||||||
type Comp struct {
|
type Comp struct {
|
||||||
client *Client
|
client *Client
|
||||||
baseAddress string
|
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
|
// Factory function to create Comp instance for Strip
|
||||||
@@ -12,6 +24,9 @@ func newCompForStrip(c *Client) *Comp {
|
|||||||
return &Comp{
|
return &Comp{
|
||||||
client: c,
|
client: c,
|
||||||
baseAddress: c.addressMap["strip"],
|
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{
|
return &Comp{
|
||||||
client: c,
|
client: c,
|
||||||
baseAddress: c.addressMap["bus"],
|
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).
|
// 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) {
|
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)
|
err := c.client.SendMessage(address)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
resp := <-c.client.respChan
|
msg, err := c.client.ReceiveMessage()
|
||||||
val, ok := resp.Arguments[0].(int32)
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
val, ok := msg.Arguments[0].(int32)
|
||||||
if !ok {
|
if !ok {
|
||||||
return false, fmt.Errorf("unexpected argument type for Compressor on value")
|
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).
|
// 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 {
|
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
|
var value int32
|
||||||
if on {
|
if on {
|
||||||
value = 1
|
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).
|
// 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) {
|
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)
|
err := c.client.SendMessage(address)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
@@ -59,8 +80,11 @@ func (c *Comp) Mode(index int) (string, error) {
|
|||||||
|
|
||||||
possibleModes := []string{"comp", "exp"}
|
possibleModes := []string{"comp", "exp"}
|
||||||
|
|
||||||
resp := <-c.client.respChan
|
msg, err := c.client.ReceiveMessage()
|
||||||
val, ok := resp.Arguments[0].(int32)
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
val, ok := msg.Arguments[0].(int32)
|
||||||
if !ok {
|
if !ok {
|
||||||
return "", fmt.Errorf("unexpected argument type for Compressor mode value")
|
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).
|
// 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 {
|
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"}
|
possibleModes := []string{"comp", "exp"}
|
||||||
return c.client.SendMessage(address, int32(indexOf(possibleModes, mode)))
|
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).
|
// 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) {
|
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)
|
err := c.client.SendMessage(address)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
resp := <-c.client.respChan
|
msg, err := c.client.ReceiveMessage()
|
||||||
val, ok := resp.Arguments[0].(float32)
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
val, ok := msg.Arguments[0].(float32)
|
||||||
if !ok {
|
if !ok {
|
||||||
return 0, fmt.Errorf("unexpected argument type for Compressor threshold value")
|
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).
|
// 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 {
|
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)))
|
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).
|
// 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) {
|
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)
|
err := c.client.SendMessage(address)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
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}
|
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
|
msg, err := c.client.ReceiveMessage()
|
||||||
val, ok := resp.Arguments[0].(int32)
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
val, ok := msg.Arguments[0].(int32)
|
||||||
if !ok {
|
if !ok {
|
||||||
return 0, fmt.Errorf("unexpected argument type for Compressor ratio value")
|
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).
|
// 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 {
|
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}
|
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))))
|
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).
|
// 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) {
|
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)
|
err := c.client.SendMessage(address)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
resp := <-c.client.respChan
|
msg, err := c.client.ReceiveMessage()
|
||||||
val, ok := resp.Arguments[0].(float32)
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
val, ok := msg.Arguments[0].(float32)
|
||||||
if !ok {
|
if !ok {
|
||||||
return 0, fmt.Errorf("unexpected argument type for Compressor attack value")
|
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).
|
// 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 {
|
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)))
|
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).
|
// 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) {
|
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)
|
err := c.client.SendMessage(address)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
resp := <-c.client.respChan
|
msg, err := c.client.ReceiveMessage()
|
||||||
val, ok := resp.Arguments[0].(float32)
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
val, ok := msg.Arguments[0].(float32)
|
||||||
if !ok {
|
if !ok {
|
||||||
return 0, fmt.Errorf("unexpected argument type for Compressor hold value")
|
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).
|
// 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 {
|
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)))
|
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).
|
// 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) {
|
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)
|
err := c.client.SendMessage(address)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
resp := <-c.client.respChan
|
msg, err := c.client.ReceiveMessage()
|
||||||
val, ok := resp.Arguments[0].(float32)
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
val, ok := msg.Arguments[0].(float32)
|
||||||
if !ok {
|
if !ok {
|
||||||
return 0, fmt.Errorf("unexpected argument type for Compressor release value")
|
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).
|
// 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 {
|
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)))
|
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).
|
// 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) {
|
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)
|
err := c.client.SendMessage(address)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
resp := <-c.client.respChan
|
msg, err := c.client.ReceiveMessage()
|
||||||
val, ok := resp.Arguments[0].(float32)
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
val, ok := msg.Arguments[0].(float32)
|
||||||
if !ok {
|
if !ok {
|
||||||
return 0, fmt.Errorf("unexpected argument type for Compressor makeup gain value")
|
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).
|
// 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 {
|
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)))
|
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).
|
// 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) {
|
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)
|
err := c.client.SendMessage(address)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
resp := <-c.client.respChan
|
msg, err := c.client.ReceiveMessage()
|
||||||
val, ok := resp.Arguments[0].(float32)
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
val, ok := msg.Arguments[0].(float32)
|
||||||
if !ok {
|
if !ok {
|
||||||
return 0, fmt.Errorf("unexpected argument type for Compressor mix value")
|
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).
|
// 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 {
|
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)))
|
return c.client.SendMessage(address, float32(linSet(0, 100, mix)))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ type parser interface {
|
|||||||
|
|
||||||
type engine struct {
|
type engine struct {
|
||||||
Kind MixerKind
|
Kind MixerKind
|
||||||
|
timeout time.Duration
|
||||||
conn *net.UDPConn
|
conn *net.UDPConn
|
||||||
mixerAddr *net.UDPAddr
|
mixerAddr *net.UDPAddr
|
||||||
|
|
||||||
@@ -34,7 +35,7 @@ func (e *engine) receiveLoop() {
|
|||||||
case <-e.done:
|
case <-e.done:
|
||||||
return
|
return
|
||||||
default:
|
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))
|
e.conn.SetReadDeadline(time.Now().Add(100 * time.Millisecond))
|
||||||
n, _, err := e.conn.ReadFromUDP(buffer)
|
n, _, err := e.conn.ReadFromUDP(buffer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -1,10 +1,24 @@
|
|||||||
package xair
|
package xair
|
||||||
|
|
||||||
import "fmt"
|
import (
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
type Eq struct {
|
type Eq struct {
|
||||||
client *Client
|
client *Client
|
||||||
baseAddress string
|
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
|
// Factory function to create Eq instance for Strip
|
||||||
@@ -12,6 +26,9 @@ func newEqForStrip(c *Client) *Eq {
|
|||||||
return &Eq{
|
return &Eq{
|
||||||
client: c,
|
client: c,
|
||||||
baseAddress: c.addressMap["strip"],
|
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{
|
return &Eq{
|
||||||
client: c,
|
client: c,
|
||||||
baseAddress: c.addressMap["bus"],
|
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).
|
// 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) {
|
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)
|
err := e.client.SendMessage(address)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
resp := <-e.client.respChan
|
msg, err := e.client.ReceiveMessage()
|
||||||
val, ok := resp.Arguments[0].(int32)
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
val, ok := msg.Arguments[0].(int32)
|
||||||
if !ok {
|
if !ok {
|
||||||
return false, fmt.Errorf("unexpected argument type for EQ on value")
|
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).
|
// 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 {
|
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
|
var value int32
|
||||||
if on {
|
if on {
|
||||||
value = 1
|
value = 1
|
||||||
@@ -50,7 +73,7 @@ func (e *Eq) SetOn(index int, on bool) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (e *Eq) Mode(index int) (string, 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)
|
err := e.client.SendMessage(address)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
@@ -58,8 +81,11 @@ func (e *Eq) Mode(index int) (string, error) {
|
|||||||
|
|
||||||
possibleModes := []string{"peq", "geq", "teq"}
|
possibleModes := []string{"peq", "geq", "teq"}
|
||||||
|
|
||||||
resp := <-e.client.respChan
|
msg, err := e.client.ReceiveMessage()
|
||||||
val, ok := resp.Arguments[0].(int32)
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
val, ok := msg.Arguments[0].(int32)
|
||||||
if !ok {
|
if !ok {
|
||||||
return "", fmt.Errorf("unexpected argument type for EQ mode value")
|
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 {
|
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"}
|
possibleModes := []string{"peq", "geq", "teq"}
|
||||||
return e.client.SendMessage(address, int32(indexOf(possibleModes, mode)))
|
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).
|
// 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) {
|
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)
|
err := e.client.SendMessage(address)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
resp := <-e.client.respChan
|
msg, err := e.client.ReceiveMessage()
|
||||||
val, ok := resp.Arguments[0].(float32)
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
val, ok := msg.Arguments[0].(float32)
|
||||||
if !ok {
|
if !ok {
|
||||||
return 0, fmt.Errorf("unexpected argument type for EQ gain value")
|
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).
|
// 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 {
|
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)))
|
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).
|
// 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) {
|
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)
|
err := e.client.SendMessage(address)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
resp := <-e.client.respChan
|
msg, err := e.client.ReceiveMessage()
|
||||||
val, ok := resp.Arguments[0].(float32)
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
val, ok := msg.Arguments[0].(float32)
|
||||||
if !ok {
|
if !ok {
|
||||||
return 0, fmt.Errorf("unexpected argument type for EQ frequency value")
|
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).
|
// 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 {
|
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)))
|
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).
|
// 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) {
|
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)
|
err := e.client.SendMessage(address)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
resp := <-e.client.respChan
|
msg, err := e.client.ReceiveMessage()
|
||||||
val, ok := resp.Arguments[0].(float32)
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
val, ok := msg.Arguments[0].(float32)
|
||||||
if !ok {
|
if !ok {
|
||||||
return 0, fmt.Errorf("unexpected argument type for EQ Q value")
|
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).
|
// 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 {
|
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)))
|
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).
|
// 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) {
|
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)
|
err := e.client.SendMessage(address)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
@@ -148,8 +183,11 @@ func (e *Eq) Type(index int, band int) (string, error) {
|
|||||||
|
|
||||||
possibleTypes := []string{"lcut", "lshv", "peq", "veq", "hshv", "hcut"}
|
possibleTypes := []string{"lcut", "lshv", "peq", "veq", "hshv", "hcut"}
|
||||||
|
|
||||||
resp := <-e.client.respChan
|
msg, err := e.client.ReceiveMessage()
|
||||||
val, ok := resp.Arguments[0].(int32)
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
val, ok := msg.Arguments[0].(int32)
|
||||||
if !ok {
|
if !ok {
|
||||||
return "", fmt.Errorf("unexpected argument type for EQ type value")
|
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).
|
// 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 {
|
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"}
|
possibleTypes := []string{"lcut", "lshv", "peq", "veq", "hshv", "hcut"}
|
||||||
return e.client.SendMessage(address, int32(indexOf(possibleTypes, eqType)))
|
return e.client.SendMessage(address, int32(indexOf(possibleTypes, eqType)))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,8 +7,12 @@ type Gate struct {
|
|||||||
baseAddress string
|
baseAddress string
|
||||||
}
|
}
|
||||||
|
|
||||||
func newGate(c *Client) *Gate {
|
// Factory function to create Gate instance for Strip
|
||||||
return &Gate{client: c, baseAddress: c.addressMap["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).
|
// 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
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
resp := <-g.client.respChan
|
msg, err := g.client.ReceiveMessage()
|
||||||
val, ok := resp.Arguments[0].(int32)
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
val, ok := msg.Arguments[0].(int32)
|
||||||
if !ok {
|
if !ok {
|
||||||
return false, fmt.Errorf("unexpected argument type for Gate on value")
|
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"}
|
possibleModes := []string{"exp2", "exp3", "exp4", "gate", "duck"}
|
||||||
|
|
||||||
resp := <-g.client.respChan
|
msg, err := g.client.ReceiveMessage()
|
||||||
val, ok := resp.Arguments[0].(int32)
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
val, ok := msg.Arguments[0].(int32)
|
||||||
if !ok {
|
if !ok {
|
||||||
return "", fmt.Errorf("unexpected argument type for Gate mode value")
|
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
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
resp := <-g.client.respChan
|
msg, err := g.client.ReceiveMessage()
|
||||||
val, ok := resp.Arguments[0].(float32)
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
val, ok := msg.Arguments[0].(float32)
|
||||||
if !ok {
|
if !ok {
|
||||||
return 0, fmt.Errorf("unexpected argument type for Gate threshold value")
|
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
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
resp := <-g.client.respChan
|
msg, err := g.client.ReceiveMessage()
|
||||||
val, ok := resp.Arguments[0].(float32)
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
val, ok := msg.Arguments[0].(float32)
|
||||||
if !ok {
|
if !ok {
|
||||||
return 0, fmt.Errorf("unexpected argument type for Gate range value")
|
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
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
resp := <-g.client.respChan
|
msg, err := g.client.ReceiveMessage()
|
||||||
val, ok := resp.Arguments[0].(float32)
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
val, ok := msg.Arguments[0].(float32)
|
||||||
if !ok {
|
if !ok {
|
||||||
return 0, fmt.Errorf("unexpected argument type for Gate attack value")
|
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
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
resp := <-g.client.respChan
|
msg, err := g.client.ReceiveMessage()
|
||||||
val, ok := resp.Arguments[0].(float32)
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
val, ok := msg.Arguments[0].(float32)
|
||||||
if !ok {
|
if !ok {
|
||||||
return 0, fmt.Errorf("unexpected argument type for Gate hold value")
|
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
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
resp := <-g.client.respChan
|
msg, err := g.client.ReceiveMessage()
|
||||||
val, ok := resp.Arguments[0].(float32)
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
val, ok := msg.Arguments[0].(float32)
|
||||||
if !ok {
|
if !ok {
|
||||||
return 0, fmt.Errorf("unexpected argument type for Gate release value")
|
return 0, fmt.Errorf("unexpected argument type for Gate release value")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,14 +3,15 @@ package xair
|
|||||||
import "fmt"
|
import "fmt"
|
||||||
|
|
||||||
type HeadAmp struct {
|
type HeadAmp struct {
|
||||||
baseAddress string
|
|
||||||
client *Client
|
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{
|
return &HeadAmp{
|
||||||
baseAddress: c.addressMap["headamp"],
|
|
||||||
client: c,
|
client: c,
|
||||||
|
baseAddress: c.addressMap["headamp"],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -22,8 +23,11 @@ func (h *HeadAmp) Gain(index int) (float64, error) {
|
|||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
resp := <-h.client.respChan
|
msg, err := h.client.ReceiveMessage()
|
||||||
val, ok := resp.Arguments[0].(float32)
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
val, ok := msg.Arguments[0].(float32)
|
||||||
if !ok {
|
if !ok {
|
||||||
return 0, fmt.Errorf("unexpected argument type for headamp gain value")
|
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
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
resp := <-h.client.respChan
|
msg, err := h.client.ReceiveMessage()
|
||||||
val, ok := resp.Arguments[0].(int32)
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
val, ok := msg.Arguments[0].(int32)
|
||||||
if !ok {
|
if !ok {
|
||||||
return false, fmt.Errorf("unexpected argument type for phantom power value")
|
return false, fmt.Errorf("unexpected argument type for phantom power value")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,14 +3,18 @@ package xair
|
|||||||
import "fmt"
|
import "fmt"
|
||||||
|
|
||||||
type Main struct {
|
type Main struct {
|
||||||
baseAddress string
|
|
||||||
client *Client
|
client *Client
|
||||||
|
baseAddress string
|
||||||
|
Eq *Eq
|
||||||
|
Comp *Comp
|
||||||
}
|
}
|
||||||
|
|
||||||
func newMainStereo(c *Client) *Main {
|
func newMainStereo(c *Client) *Main {
|
||||||
return &Main{
|
return &Main{
|
||||||
baseAddress: c.addressMap["main"],
|
|
||||||
client: c,
|
client: c,
|
||||||
|
baseAddress: c.addressMap["main"],
|
||||||
|
Eq: newEqForMain(c),
|
||||||
|
Comp: newCompForMain(c),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,8 +35,11 @@ func (m *Main) Fader() (float64, error) {
|
|||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
resp := <-m.client.respChan
|
msg, err := m.client.ReceiveMessage()
|
||||||
val, ok := resp.Arguments[0].(float32)
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
val, ok := msg.Arguments[0].(float32)
|
||||||
if !ok {
|
if !ok {
|
||||||
return 0, fmt.Errorf("unexpected argument type for main LR fader value")
|
return 0, fmt.Errorf("unexpected argument type for main LR fader value")
|
||||||
}
|
}
|
||||||
@@ -53,8 +60,11 @@ func (m *Main) Mute() (bool, error) {
|
|||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
resp := <-m.client.respChan
|
msg, err := m.client.ReceiveMessage()
|
||||||
val, ok := resp.Arguments[0].(int32)
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
val, ok := msg.Arguments[0].(int32)
|
||||||
if !ok {
|
if !ok {
|
||||||
return false, fmt.Errorf("unexpected argument type for main LR mute value")
|
return false, fmt.Errorf("unexpected argument type for main LR mute value")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package xair
|
package xair
|
||||||
|
|
||||||
|
import "time"
|
||||||
|
|
||||||
type Option func(*engine)
|
type Option func(*engine)
|
||||||
|
|
||||||
func WithKind(kind string) Option {
|
func WithKind(kind string) Option {
|
||||||
@@ -8,3 +10,9 @@ func WithKind(kind string) Option {
|
|||||||
e.addressMap = addressMapForMixerKind(e.Kind)
|
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"
|
import "fmt"
|
||||||
|
|
||||||
type Snapshot struct {
|
type Snapshot struct {
|
||||||
baseAddress string
|
|
||||||
client *Client
|
client *Client
|
||||||
|
baseAddress string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSnapshot(c *Client) *Snapshot {
|
func newSnapshot(c *Client) *Snapshot {
|
||||||
return &Snapshot{
|
return &Snapshot{
|
||||||
baseAddress: c.addressMap["snapshot"],
|
|
||||||
client: c,
|
client: c,
|
||||||
|
baseAddress: c.addressMap["snapshot"],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Name gets the name of the snapshot at the given index.
|
// Name gets the name of the snapshot at the given index.
|
||||||
func (s *Snapshot) Name(index int) (string, error) {
|
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)
|
err := s.client.SendMessage(address)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
resp := <-s.client.respChan
|
msg, err := s.client.ReceiveMessage()
|
||||||
name, ok := resp.Arguments[0].(string)
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
name, ok := msg.Arguments[0].(string)
|
||||||
if !ok {
|
if !ok {
|
||||||
return "", fmt.Errorf("unexpected argument type for snapshot name")
|
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.
|
// SetName sets the name of the snapshot at the given index.
|
||||||
func (s *Snapshot) SetName(index int, name string) error {
|
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)
|
return s.client.SendMessage(address, name)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load loads the snapshot at the given index.
|
// CurrentName sets the name of the current snapshot.
|
||||||
func (s *Snapshot) Load(index int) error {
|
func (s *Snapshot) CurrentName(name string) error {
|
||||||
address := s.baseAddress + fmt.Sprintf("/load/%d", index)
|
address := s.baseAddress + "/name"
|
||||||
return s.client.SendMessage(address)
|
return s.client.SendMessage(address, name)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save saves the current state to the snapshot at the given index.
|
// CurrentLoad loads the snapshot at the given index.
|
||||||
func (s *Snapshot) Save(index int) error {
|
func (s *Snapshot) CurrentLoad(index int) error {
|
||||||
address := s.baseAddress + fmt.Sprintf("/save/%d", index)
|
address := s.baseAddress + "/load"
|
||||||
return s.client.SendMessage(address)
|
return s.client.SendMessage(address, int32(index))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete deletes the snapshot at the given index.
|
// CurrentSave saves the current state to the snapshot at the given index.
|
||||||
func (s *Snapshot) Delete(index int) error {
|
func (s *Snapshot) CurrentSave(index int) error {
|
||||||
address := s.baseAddress + fmt.Sprintf("/delete/%d", index)
|
address := s.baseAddress + "/save"
|
||||||
return s.client.SendMessage(address)
|
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"
|
import "fmt"
|
||||||
|
|
||||||
type Strip struct {
|
type Strip struct {
|
||||||
baseAddress string
|
|
||||||
client *Client
|
client *Client
|
||||||
|
baseAddress string
|
||||||
Gate *Gate
|
Gate *Gate
|
||||||
Eq *Eq
|
Eq *Eq
|
||||||
Comp *Comp
|
Comp *Comp
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewStrip(c *Client) *Strip {
|
func newStrip(c *Client) *Strip {
|
||||||
return &Strip{
|
return &Strip{
|
||||||
baseAddress: c.addressMap["strip"],
|
|
||||||
client: c,
|
client: c,
|
||||||
Gate: newGate(c),
|
baseAddress: c.addressMap["strip"],
|
||||||
|
Gate: newGateForStrip(c),
|
||||||
Eq: newEqForStrip(c),
|
Eq: newEqForStrip(c),
|
||||||
Comp: newCompForStrip(c),
|
Comp: newCompForStrip(c),
|
||||||
}
|
}
|
||||||
@@ -28,8 +28,11 @@ func (s *Strip) Mute(index int) (bool, error) {
|
|||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
resp := <-s.client.respChan
|
msg, err := s.client.ReceiveMessage()
|
||||||
val, ok := resp.Arguments[0].(int32)
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
val, ok := msg.Arguments[0].(int32)
|
||||||
if !ok {
|
if !ok {
|
||||||
return false, fmt.Errorf("unexpected argument type for strip mute value")
|
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
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
resp := <-s.client.respChan
|
msg, err := s.client.ReceiveMessage()
|
||||||
val, ok := resp.Arguments[0].(float32)
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
val, ok := msg.Arguments[0].(float32)
|
||||||
if !ok {
|
if !ok {
|
||||||
return 0, fmt.Errorf("unexpected argument type for fader value")
|
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)
|
return "", fmt.Errorf("failed to send strip name request: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
resp := <-s.client.respChan
|
msg, err := s.client.ReceiveMessage()
|
||||||
val, ok := resp.Arguments[0].(string)
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
val, ok := msg.Arguments[0].(string)
|
||||||
if !ok {
|
if !ok {
|
||||||
return "", fmt.Errorf("unexpected argument type for strip name value")
|
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)
|
return 0, fmt.Errorf("failed to send strip color request: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
resp := <-s.client.respChan
|
msg, err := s.client.ReceiveMessage()
|
||||||
val, ok := resp.Arguments[0].(int32)
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
val, ok := msg.Arguments[0].(int32)
|
||||||
if !ok {
|
if !ok {
|
||||||
return 0, fmt.Errorf("unexpected argument type for strip color value")
|
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)
|
return 0, fmt.Errorf("failed to send strip send level request: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
resp := <-s.client.respChan
|
msg, err := s.client.ReceiveMessage()
|
||||||
val, ok := resp.Arguments[0].(float32)
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
val, ok := msg.Arguments[0].(float32)
|
||||||
if !ok {
|
if !ok {
|
||||||
return 0, fmt.Errorf("unexpected argument type for strip send level value")
|
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." optional:""`
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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." optional:""`
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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 (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"time"
|
||||||
"os"
|
|
||||||
"runtime/debug"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/alecthomas/kong"
|
"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.
|
Fader MainFaderCmd `help:"Get or set the fader level of the Main L/R output." cmd:""`
|
||||||
type VersionFlag string
|
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
|
Eq MainEqCmdGroup `help:"Commands for controlling the equalizer settings of the Main L/R output." cmd:"eq"`
|
||||||
func (v VersionFlag) IsBool() bool { return true } // nolint: revive
|
Comp MainCompCmdGroup `help:"Commands for controlling the compressor settings of the Main L/R output." cmd:"comp"`
|
||||||
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)
|
// 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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type context struct {
|
// 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.
|
||||||
Client *xair.Client
|
type MainFaderCmd struct {
|
||||||
Out io.Writer
|
Level *float64 `arg:"" help:"The fader level to set. If not provided, the current level will be printed." optional:""`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Config struct {
|
// 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.
|
||||||
Host string `default:"mixer.local" help:"The host of the X-Air device." env:"XAIR_CLI_HOST" short:"H"`
|
func (cmd *MainFaderCmd) Run(ctx *context) error {
|
||||||
Port int `default:"10024" help:"The port of the X-Air device." env:"XAIR_CLI_PORT" short:"P"`
|
if cmd.Level == nil {
|
||||||
Kind string `default:"xair" help:"The kind of the X-Air device." env:"XAIR_CLI_KIND" short:"K" enum:"xair,x32"`
|
resp, err := ctx.Client.Main.Fader()
|
||||||
}
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to get Main L/R fader level: %w", err)
|
||||||
// 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.
|
fmt.Fprintf(ctx.Out, "Main L/R fader level: %.2f\n", resp)
|
||||||
type CLI struct {
|
return nil
|
||||||
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"`
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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 (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
|
||||||
|
"github.com/charmbracelet/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
// RawCmd represents the command to send raw OSC messages to the mixer.
|
// RawCmd represents the command to send raw OSC messages to the mixer.
|
||||||
type RawCmd struct {
|
type RawCmd struct {
|
||||||
Timeout time.Duration `help:"Timeout for the OSC message send operation." default:"100ms" short:"t" env:"XAIR_CLI_RAW_TIMEOUT"`
|
Address string `help:"The OSC address to send the message to." arg:""`
|
||||||
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:""`
|
||||||
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.
|
// 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)
|
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 {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to receive response for raw OSC message: %w", err)
|
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