6 Commits

Author SHA1 Message Date
c44413da6b add examples, notes and license to README 2026-02-01 03:37:42 +00:00
90839d24a1 use baseAddress 2026-02-01 03:20:14 +00:00
7d521e0111 remove LICENSE header from main.go 2026-02-01 02:19:29 +00:00
625987759f remove methods now implemented in headamp struct 2026-02-01 02:07:09 +00:00
08b232dcbf use RunE throughout 2026-02-01 01:56:03 +00:00
0b72556b7e upd readme 2026-02-01 01:31:17 +00:00
8 changed files with 176 additions and 195 deletions

View File

@@ -1,4 +1,10 @@
# Xair-CLI # xair-cli
### Installation
```console
go install github.com/onyx-and-iris/xair-cli@latest
```
### Use ### Use
@@ -14,6 +20,7 @@ Usage:
Available Commands: Available Commands:
bus Commands to control individual buses bus Commands to control individual buses
completion Generate the autocompletion script for the specified shell completion Generate the autocompletion script for the specified shell
headamp Commands to control headamp gain and phantom power
help Help about any command help Help about any command
main Commands to control the main output main Commands to control the main output
strip Commands to control individual strips strip Commands to control individual strips
@@ -24,6 +31,44 @@ Flags:
-k, --kind string Kind of mixer (xair, x32) (default "xair") -k, --kind string Kind of mixer (xair, x32) (default "xair")
-l, --loglevel string Log level (debug, info, warn, error, fatal, panic) (default "warn") -l, --loglevel string Log level (debug, info, warn, error, fatal, panic) (default "warn")
-p, --port int Port number of the X Air mixer (default 10024) -p, --port int Port number of the X Air mixer (default 10024)
-v, --version version for xair-cli
Use "xair-cli [command] --help" for more information about a command. Use "xair-cli [command] --help" for more information about a command.
``` ```
### Examples
Things that are possible with this CLI:
*Fade out main LR all the way to -∞*
```console
xair-cli main fadeout
```
*enable phantom power and set the gain to 28dB for strip 09*
```console
xair-cli headamp 9 phantom on
xair-cli headamp 9 gain 28
```
*adjust strip 09 send level to bus 5*
```console
xair-cli strip send 9 5 -- -18.0
```
*rename bus 01 to 'vocal mix'*
```console
xair-cli bus 1 name 'vocal mix'
```
### Notes
I've only implemented the parts I personally need, I don't know how much more I intend to add.
### License
`xair-cli` is distributed under the terms of the [MIT](https://spdx.org/licenses/MIT.html) license.

View File

@@ -1,6 +1,7 @@
package cmd package cmd
import ( import (
"fmt"
"time" "time"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@@ -21,16 +22,14 @@ var busMuteCmd = &cobra.Command{
Short: "Get or set the bus mute status", Short: "Get or set the bus mute status",
Long: `Get or set the mute status of a specific bus.`, Long: `Get or set the mute status of a specific bus.`,
Use: "mute [bus number] [true|false]", Use: "mute [bus number] [true|false]",
Run: func(cmd *cobra.Command, args []string) { RunE: func(cmd *cobra.Command, args []string) error {
client := ClientFromContext(cmd.Context()) client := ClientFromContext(cmd.Context())
if client == nil { if client == nil {
cmd.PrintErrln("OSC client not found in context") return fmt.Errorf("OSC client not found in context")
return
} }
if len(args) < 2 { if len(args) < 2 {
cmd.PrintErrln("Please provide bus number and mute status (true/false)") return fmt.Errorf("Please provide bus number and mute status (true/false)")
return
} }
busNum := mustConvToInt(args[0]) busNum := mustConvToInt(args[0])
@@ -41,16 +40,16 @@ var busMuteCmd = &cobra.Command{
case "false", "0": case "false", "0":
muted = false muted = false
default: default:
cmd.PrintErrln("Invalid mute status. Use true/false or 1/0") return fmt.Errorf("Invalid mute status. Use true/false or 1/0")
return
} }
err := client.Bus.SetMute(busNum, muted) err := client.Bus.SetMute(busNum, muted)
if err != nil { if err != nil {
cmd.PrintErrln("Error setting bus mute status:", err) return fmt.Errorf("Error setting bus mute status: %w", err)
return
} }
cmd.Printf("Bus %d mute set to %v\n", busNum, muted) cmd.Printf("Bus %d mute set to %v\n", busNum, muted)
return nil
}, },
} }
@@ -66,11 +65,10 @@ If a level argument (in dB) is provided, the bus fader is set to that level.`,
# Set the fader level of bus 1 to -10.0 dB # Set the fader level of bus 1 to -10.0 dB
xair-cli bus fader 1 -10.0`, xair-cli bus fader 1 -10.0`,
Run: func(cmd *cobra.Command, args []string) { RunE: func(cmd *cobra.Command, args []string) error {
client := ClientFromContext(cmd.Context()) client := ClientFromContext(cmd.Context())
if client == nil { if client == nil {
cmd.PrintErrln("OSC client not found in context") return fmt.Errorf("OSC client not found in context")
return
} }
busIndex := mustConvToInt(args[0]) busIndex := mustConvToInt(args[0])
@@ -78,26 +76,25 @@ If a level argument (in dB) is provided, the bus fader is set to that level.`,
if len(args) == 1 { if len(args) == 1 {
level, err := client.Bus.Fader(busIndex) level, err := client.Bus.Fader(busIndex)
if err != nil { if err != nil {
cmd.PrintErrln("Error getting bus fader level:", err) return fmt.Errorf("Error getting bus fader level: %w", err)
return
} }
cmd.Printf("Bus %d fader level: %.1f dB\n", busIndex, level) cmd.Printf("Bus %d fader level: %.1f dB\n", busIndex, level)
return return nil
} }
if len(args) < 2 { if len(args) < 2 {
cmd.PrintErrln("Please provide bus number and fader level (in dB)") return fmt.Errorf("Please provide bus number and fader level (in dB)")
return
} }
level := mustConvToFloat64(args[1]) level := mustConvToFloat64(args[1])
err := client.Bus.SetFader(busIndex, level) err := client.Bus.SetFader(busIndex, level)
if err != nil { if err != nil {
cmd.PrintErrln("Error setting bus fader level:", err) return fmt.Errorf("Error setting bus fader level: %w", err)
return
} }
cmd.Printf("Bus %d fader set to %.2f dB\n", busIndex, level) cmd.Printf("Bus %d fader set to %.2f dB\n", busIndex, level)
return nil
}, },
} }
@@ -108,24 +105,21 @@ var busFadeOutCmd = &cobra.Command{
Use: "fadeout [bus number] --duration [seconds] [target level in dB]", Use: "fadeout [bus number] --duration [seconds] [target level in dB]",
Example: ` # Fade out bus 1 over 5 seconds Example: ` # Fade out bus 1 over 5 seconds
xair-cli bus fadeout 1 --duration 5 -- -90.0`, xair-cli bus fadeout 1 --duration 5 -- -90.0`,
Run: func(cmd *cobra.Command, args []string) { RunE: func(cmd *cobra.Command, args []string) error {
client := ClientFromContext(cmd.Context()) client := ClientFromContext(cmd.Context())
if client == nil { if client == nil {
cmd.PrintErrln("OSC client not found in context") return fmt.Errorf("OSC client not found in context")
return
} }
if len(args) < 1 { if len(args) < 1 {
cmd.PrintErrln("Please provide bus number") return fmt.Errorf("Please provide bus number")
return
} }
busIndex := mustConvToInt(args[0]) busIndex := mustConvToInt(args[0])
duration, err := cmd.Flags().GetFloat64("duration") duration, err := cmd.Flags().GetFloat64("duration")
if err != nil { if err != nil {
cmd.PrintErrln("Error getting duration flag:", err) return fmt.Errorf("Error getting duration flag: %w", err)
return
} }
target := -90.0 target := -90.0
@@ -135,15 +129,14 @@ var busFadeOutCmd = &cobra.Command{
currentFader, err := client.Bus.Fader(busIndex) currentFader, err := client.Bus.Fader(busIndex)
if err != nil { if err != nil {
cmd.PrintErrln("Error getting current bus fader level:", err) return fmt.Errorf("Error getting current bus fader level: %w", err)
return
} }
// Calculate total steps needed to reach target dB // Calculate total steps needed to reach target dB
totalSteps := float64(currentFader - target) totalSteps := float64(currentFader - target)
if totalSteps <= 0 { if totalSteps <= 0 {
cmd.Println("Bus is already at or below target level") cmd.Println("Bus is already at or below target level")
return return nil
} }
stepDelay := time.Duration(duration*1000/totalSteps) * time.Millisecond stepDelay := time.Duration(duration*1000/totalSteps) * time.Millisecond
@@ -152,13 +145,13 @@ var busFadeOutCmd = &cobra.Command{
currentFader -= 1.0 currentFader -= 1.0
err := client.Bus.SetFader(busIndex, currentFader) err := client.Bus.SetFader(busIndex, currentFader)
if err != nil { if err != nil {
cmd.PrintErrln("Error setting bus fader level:", err) return fmt.Errorf("Error setting bus fader level: %w", err)
return
} }
time.Sleep(stepDelay) time.Sleep(stepDelay)
} }
cmd.Println("Bus fade out completed") cmd.Println("Bus fade out completed")
return nil
}, },
} }
@@ -169,24 +162,21 @@ var busFadeInCmd = &cobra.Command{
Use: "fadein [bus number] --duration [seconds] [target level in dB]", Use: "fadein [bus number] --duration [seconds] [target level in dB]",
Example: ` # Fade in bus 1 over 5 seconds Example: ` # Fade in bus 1 over 5 seconds
xair-cli bus fadein 1 --duration 5 -- 0.0`, xair-cli bus fadein 1 --duration 5 -- 0.0`,
Run: func(cmd *cobra.Command, args []string) { RunE: func(cmd *cobra.Command, args []string) error {
client := ClientFromContext(cmd.Context()) client := ClientFromContext(cmd.Context())
if client == nil { if client == nil {
cmd.PrintErrln("OSC client not found in context") return fmt.Errorf("OSC client not found in context")
return
} }
if len(args) < 1 { if len(args) < 1 {
cmd.PrintErrln("Please provide bus number") return fmt.Errorf("Please provide bus number")
return
} }
busIndex := mustConvToInt(args[0]) busIndex := mustConvToInt(args[0])
duration, err := cmd.Flags().GetFloat64("duration") duration, err := cmd.Flags().GetFloat64("duration")
if err != nil { if err != nil {
cmd.PrintErrln("Error getting duration flag:", err) return fmt.Errorf("Error getting duration flag: %w", err)
return
} }
target := 0.0 target := 0.0
@@ -196,15 +186,14 @@ var busFadeInCmd = &cobra.Command{
currentFader, err := client.Bus.Fader(busIndex) currentFader, err := client.Bus.Fader(busIndex)
if err != nil { if err != nil {
cmd.PrintErrln("Error getting current bus fader level:", err) return fmt.Errorf("Error getting current bus fader level: %w", err)
return
} }
// Calculate total steps needed to reach target dB // Calculate total steps needed to reach target dB
totalSteps := float64(target - currentFader) totalSteps := float64(target - currentFader)
if totalSteps <= 0 { if totalSteps <= 0 {
cmd.Println("Bus is already at or above target level") cmd.Println("Bus is already at or above target level")
return return nil
} }
stepDelay := time.Duration(duration*1000/totalSteps) * time.Millisecond stepDelay := time.Duration(duration*1000/totalSteps) * time.Millisecond
@@ -213,13 +202,13 @@ var busFadeInCmd = &cobra.Command{
currentFader += 1.0 currentFader += 1.0
err := client.Bus.SetFader(busIndex, currentFader) err := client.Bus.SetFader(busIndex, currentFader)
if err != nil { if err != nil {
cmd.PrintErrln("Error setting bus fader level:", err) return fmt.Errorf("Error setting bus fader level: %w", err)
return
} }
time.Sleep(stepDelay) time.Sleep(stepDelay)
} }
cmd.Println("Bus fade in completed") cmd.Println("Bus fade in completed")
return nil
}, },
} }
@@ -233,16 +222,14 @@ var busNameCmd = &cobra.Command{
# Set the name of bus 1 to "Vocals" # Set the name of bus 1 to "Vocals"
xair-cli bus name 1 Vocals`, xair-cli bus name 1 Vocals`,
Run: func(cmd *cobra.Command, args []string) { RunE: func(cmd *cobra.Command, args []string) error {
client := ClientFromContext(cmd.Context()) client := ClientFromContext(cmd.Context())
if client == nil { if client == nil {
cmd.PrintErrln("OSC client not found in context") return fmt.Errorf("OSC client not found in context")
return
} }
if len(args) < 1 { if len(args) < 1 {
cmd.PrintErrln("Please provide bus number") return fmt.Errorf("Please provide bus number")
return
} }
busIndex := mustConvToInt(args[0]) busIndex := mustConvToInt(args[0])
@@ -250,20 +237,20 @@ var busNameCmd = &cobra.Command{
if len(args) == 1 { if len(args) == 1 {
name, err := client.Bus.Name(busIndex) name, err := client.Bus.Name(busIndex)
if err != nil { if err != nil {
cmd.PrintErrln("Error getting bus name:", err) return fmt.Errorf("Error getting bus name: %w", err)
return
} }
cmd.Printf("Bus %d name: %s\n", busIndex, name) cmd.Printf("Bus %d name: %s\n", busIndex, name)
return return nil
} }
newName := args[1] newName := args[1]
err := client.Bus.SetName(busIndex, newName) err := client.Bus.SetName(busIndex, newName)
if err != nil { if err != nil {
cmd.PrintErrln("Error setting bus name:", err) return fmt.Errorf("Error setting bus name: %w", err)
return
} }
cmd.Printf("Bus %d name set to: %s\n", busIndex, newName) cmd.Printf("Bus %d name set to: %s\n", busIndex, newName)
return nil
}, },
} }

View File

@@ -1,6 +1,8 @@
package cmd package cmd
import ( import (
"fmt"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@@ -28,16 +30,14 @@ Examples:
# Set gain level for headamp index 1 to 3.5 dB # Set gain level for headamp index 1 to 3.5 dB
xairctl headamp gain 1 3.5`, xairctl headamp gain 1 3.5`,
Args: cobra.RangeArgs(1, 2), Args: cobra.RangeArgs(1, 2),
Run: func(cmd *cobra.Command, args []string) { RunE: func(cmd *cobra.Command, args []string) error {
client := ClientFromContext(cmd.Context()) client := ClientFromContext(cmd.Context())
if client == nil { if client == nil {
cmd.PrintErrln("OSC client not found in context") return fmt.Errorf("OSC client not found in context")
return
} }
if len(args) < 1 { if len(args) < 1 {
cmd.PrintErrln("Please provide a headamp index") return fmt.Errorf("Please provide a headamp index")
return
} }
index := mustConvToInt(args[0]) index := mustConvToInt(args[0])
@@ -45,26 +45,25 @@ Examples:
if len(args) == 1 { if len(args) == 1 {
gain, err := client.HeadAmp.Gain(index) gain, err := client.HeadAmp.Gain(index)
if err != nil { if err != nil {
cmd.PrintErrln("Error getting headamp gain level:", err) return fmt.Errorf("Error getting headamp gain level: %w", err)
return
} }
cmd.Printf("Headamp %d Gain: %.2f dB\n", index, gain) cmd.Printf("Headamp %d Gain: %.2f dB\n", index, gain)
return return nil
} }
if len(args) < 2 { if len(args) < 2 {
cmd.PrintErrln("Please provide a gain level in dB") return fmt.Errorf("Please provide a gain level in dB")
return
} }
level := mustConvToFloat64(args[1]) level := mustConvToFloat64(args[1])
err := client.HeadAmp.SetGain(index, level) err := client.HeadAmp.SetGain(index, level)
if err != nil { if err != nil {
cmd.PrintErrln("Error setting headamp gain level:", err) return fmt.Errorf("Error setting headamp gain level: %w", err)
return
} }
cmd.Printf("Headamp %d Gain set to %.2f dB\n", index, level) cmd.Printf("Headamp %d Gain set to %.2f dB\n", index, level)
return nil
}, },
} }
@@ -81,16 +80,14 @@ Examples:
# Disable phantom power for headamp index 1 # Disable phantom power for headamp index 1
xairctl headamp phantom 1 off`, xairctl headamp phantom 1 off`,
Args: cobra.RangeArgs(1, 2), Args: cobra.RangeArgs(1, 2),
Run: func(cmd *cobra.Command, args []string) { RunE: func(cmd *cobra.Command, args []string) error {
client := ClientFromContext(cmd.Context()) client := ClientFromContext(cmd.Context())
if client == nil { if client == nil {
cmd.PrintErrln("OSC client not found in context") return fmt.Errorf("OSC client not found in context")
return
} }
if len(args) < 1 { if len(args) < 1 {
cmd.PrintErrln("Please provide a headamp index") return fmt.Errorf("Please provide a headamp index")
return
} }
index := mustConvToInt(args[0]) index := mustConvToInt(args[0])
@@ -98,20 +95,18 @@ Examples:
if len(args) == 1 { if len(args) == 1 {
enabled, err := client.HeadAmp.PhantomPower(index) enabled, err := client.HeadAmp.PhantomPower(index)
if err != nil { if err != nil {
cmd.PrintErrln("Error getting headamp phantom power status:", err) return fmt.Errorf("Error getting headamp phantom power status: %w", err)
return
} }
status := "disabled" status := "disabled"
if enabled { if enabled {
status = "enabled" status = "enabled"
} }
cmd.Printf("Headamp %d Phantom Power is %s\n", index, status) cmd.Printf("Headamp %d Phantom Power is %s\n", index, status)
return return nil
} }
if len(args) < 2 { if len(args) < 2 {
cmd.PrintErrln("Please provide phantom power status: on or off") return fmt.Errorf("Please provide phantom power status: on or off")
return
} }
var enable bool var enable bool
@@ -121,20 +116,20 @@ Examples:
case "off", "disable": case "off", "disable":
enable = false enable = false
default: default:
cmd.PrintErrln("Invalid phantom power status. Use 'on' or 'off'") return fmt.Errorf("Invalid phantom power status. Use 'on' or 'off'")
return
} }
err := client.HeadAmp.SetPhantomPower(index, enable) err := client.HeadAmp.SetPhantomPower(index, enable)
if err != nil { if err != nil {
cmd.PrintErrln("Error setting headamp phantom power status:", err) return fmt.Errorf("Error setting headamp phantom power status: %w", err)
return
} }
status := "disabled" status := "disabled"
if enable { if enable {
status = "enabled" status = "enabled"
} }
cmd.Printf("Headamp %d Phantom Power %s successfully\n", index, status) cmd.Printf("Headamp %d Phantom Power %s successfully\n", index, status)
return nil
}, },
} }

View File

@@ -1,6 +1,7 @@
package cmd package cmd
import ( import (
"fmt"
"time" "time"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@@ -33,21 +34,19 @@ If "false" or "0" is provided, the main output is unmuted.`,
# Unmute the main output # Unmute the main output
xair-cli main mute false`, xair-cli main mute false`,
Run: func(cmd *cobra.Command, args []string) { RunE: func(cmd *cobra.Command, args []string) error {
client := ClientFromContext(cmd.Context()) client := ClientFromContext(cmd.Context())
if client == nil { if client == nil {
cmd.PrintErrln("OSC client not found in context") return fmt.Errorf("OSC client not found in context")
return
} }
if len(args) == 0 { if len(args) == 0 {
resp, err := client.Main.Mute() resp, err := client.Main.Mute()
if err != nil { if err != nil {
cmd.PrintErrln("Error getting main LR mute status:", err) return fmt.Errorf("Error getting main LR mute status: %w", err)
return
} }
cmd.Printf("Main LR mute: %v\n", resp) cmd.Printf("Main LR mute: %v\n", resp)
return return nil
} }
var muted bool var muted bool
@@ -57,16 +56,16 @@ If "false" or "0" is provided, the main output is unmuted.`,
case "false", "0": case "false", "0":
muted = false muted = false
default: default:
cmd.PrintErrln("Invalid mute status. Use true/false or 1/0") return fmt.Errorf("Invalid mute status. Use true/false or 1/0")
return
} }
err := client.Main.SetMute(muted) err := client.Main.SetMute(muted)
if err != nil { if err != nil {
cmd.PrintErrln("Error setting main LR mute status:", err) return fmt.Errorf("Error setting main LR mute status: %w", err)
return
} }
cmd.Println("Main LR mute status set successfully") cmd.Println("Main LR mute status set successfully")
return nil
}, },
} }
@@ -83,29 +82,28 @@ If a dB value is provided as an argument, the fader level is set to that value.`
# Set the main LR fader level to -10.0 dB # Set the main LR fader level to -10.0 dB
xair-cli main fader -- -10.0`, xair-cli main fader -- -10.0`,
Run: func(cmd *cobra.Command, args []string) { RunE: func(cmd *cobra.Command, args []string) error {
client := ClientFromContext(cmd.Context()) client := ClientFromContext(cmd.Context())
if client == nil { if client == nil {
cmd.PrintErrln("OSC client not found in context") return fmt.Errorf("OSC client not found in context")
return
} }
if len(args) == 0 { if len(args) == 0 {
resp, err := client.Main.Fader() resp, err := client.Main.Fader()
if err != nil { if err != nil {
cmd.PrintErrln("Error getting main LR fader:", err) return fmt.Errorf("Error getting main LR fader: %w", err)
return
} }
cmd.Printf("Main LR fader: %.1f dB\n", resp) cmd.Printf("Main LR fader: %.1f dB\n", resp)
return return nil
} }
err := client.Main.SetFader(mustConvToFloat64(args[0])) err := client.Main.SetFader(mustConvToFloat64(args[0]))
if err != nil { if err != nil {
cmd.PrintErrln("Error setting main LR fader:", err) return fmt.Errorf("Error setting main LR fader: %w", err)
return
} }
cmd.Println("Main LR fader set successfully") cmd.Println("Main LR fader set successfully")
return nil
}, },
} }
@@ -163,6 +161,7 @@ This command will fade out the main output to the specified dB level.
} }
time.Sleep(stepDelay) time.Sleep(stepDelay)
} }
cmd.Println("Main output faded out successfully") cmd.Println("Main output faded out successfully")
}, },
} }
@@ -220,6 +219,7 @@ This command will fade in the main output to the specified dB level.
} }
time.Sleep(stepDelay) time.Sleep(stepDelay)
} }
cmd.Println("Main output faded in successfully") cmd.Println("Main output faded in successfully")
}, },
} }

View File

@@ -1,6 +1,7 @@
package cmd package cmd
import ( import (
"fmt"
"time" "time"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@@ -32,16 +33,14 @@ If "false" or "0" is provided, the strip is unmuted.`,
xair-cli strip mute 1 true xair-cli strip mute 1 true
# Unmute strip 1 # Unmute strip 1
xair-cli strip mute 1 false`, xair-cli strip mute 1 false`,
Run: func(cmd *cobra.Command, args []string) { RunE: func(cmd *cobra.Command, args []string) error {
client := ClientFromContext(cmd.Context()) client := ClientFromContext(cmd.Context())
if client == nil { if client == nil {
cmd.PrintErrln("OSC client not found in context") return fmt.Errorf("OSC client not found in context")
return
} }
if len(args) < 1 { if len(args) < 1 {
cmd.PrintErrln("Please provide a strip number") return fmt.Errorf("Please provide a strip number")
return
} }
stripIndex := mustConvToInt(args[0]) stripIndex := mustConvToInt(args[0])
@@ -49,11 +48,10 @@ If "false" or "0" is provided, the strip is unmuted.`,
if len(args) == 1 { if len(args) == 1 {
resp, err := client.Strip.Mute(stripIndex) resp, err := client.Strip.Mute(stripIndex)
if err != nil { if err != nil {
cmd.PrintErrln("Error getting strip mute status:", err) return fmt.Errorf("Error getting strip mute status: %w", err)
return
} }
cmd.Printf("Strip %d mute: %v\n", stripIndex, resp) cmd.Printf("Strip %d mute: %v\n", stripIndex, resp)
return return nil
} }
var muted bool var muted bool
@@ -63,20 +61,20 @@ If "false" or "0" is provided, the strip is unmuted.`,
case "false", "0": case "false", "0":
muted = false muted = false
default: default:
cmd.PrintErrln("Invalid mute status. Use true/false or 1/0") return fmt.Errorf("Invalid mute status. Use true/false or 1/0")
return
} }
err := client.Strip.SetMute(stripIndex, muted) err := client.Strip.SetMute(stripIndex, muted)
if err != nil { if err != nil {
cmd.PrintErrln("Error setting strip mute status:", err) return fmt.Errorf("Error setting strip mute status: %w", err)
return
} }
if muted { if muted {
cmd.Printf("Strip %d muted successfully\n", stripIndex) cmd.Printf("Strip %d muted successfully\n", stripIndex)
} else { } else {
cmd.Printf("Strip %d unmuted successfully\n", stripIndex) cmd.Printf("Strip %d unmuted successfully\n", stripIndex)
} }
return nil
}, },
} }
@@ -93,16 +91,14 @@ If a level argument (in dB) is provided, the strip fader is set to that level.`,
# Set the fader level of strip 1 to -10.0 dB # Set the fader level of strip 1 to -10.0 dB
xair-cli strip fader 1 -10.0`, xair-cli strip fader 1 -10.0`,
Run: func(cmd *cobra.Command, args []string) { RunE: func(cmd *cobra.Command, args []string) error {
client := ClientFromContext(cmd.Context()) client := ClientFromContext(cmd.Context())
if client == nil { if client == nil {
cmd.PrintErrln("OSC client not found in context") return fmt.Errorf("OSC client not found in context")
return
} }
if len(args) < 1 { if len(args) < 1 {
cmd.PrintErrln("Please provide a strip number") return fmt.Errorf("Please provide a strip number")
return
} }
stripIndex := mustConvToInt(args[0]) stripIndex := mustConvToInt(args[0])
@@ -110,26 +106,25 @@ If a level argument (in dB) is provided, the strip fader is set to that level.`,
if len(args) == 1 { if len(args) == 1 {
level, err := client.Strip.Fader(stripIndex) level, err := client.Strip.Fader(stripIndex)
if err != nil { if err != nil {
cmd.PrintErrln("Error getting strip fader level:", err) return fmt.Errorf("Error getting strip fader level: %w", err)
return
} }
cmd.Printf("Strip %d fader level: %.2f\n", stripIndex, level) cmd.Printf("Strip %d fader level: %.2f\n", stripIndex, level)
return return nil
} }
if len(args) < 2 { if len(args) < 2 {
cmd.PrintErrln("Please provide a fader level in dB") return fmt.Errorf("Please provide a fader level in dB")
return
} }
level := mustConvToFloat64(args[1]) level := mustConvToFloat64(args[1])
err := client.Strip.SetFader(stripIndex, level) err := client.Strip.SetFader(stripIndex, level)
if err != nil { if err != nil {
cmd.PrintErrln("Error setting strip fader level:", err) return fmt.Errorf("Error setting strip fader level: %w", err)
return
} }
cmd.Printf("Strip %d fader set to %.2f dB\n", stripIndex, level) cmd.Printf("Strip %d fader set to %.2f dB\n", stripIndex, level)
return nil
}, },
} }
@@ -140,24 +135,21 @@ var stripFadeOutCmd = &cobra.Command{
Use: "fadeout [strip number] --duration [seconds] [target level in dB]", Use: "fadeout [strip number] --duration [seconds] [target level in dB]",
Example: ` # Fade out strip 1 over 5 seconds Example: ` # Fade out strip 1 over 5 seconds
xair-cli strip fadeout 1 --duration 5.0 -- -90.0`, xair-cli strip fadeout 1 --duration 5.0 -- -90.0`,
Run: func(cmd *cobra.Command, args []string) { RunE: func(cmd *cobra.Command, args []string) error {
client := ClientFromContext(cmd.Context()) client := ClientFromContext(cmd.Context())
if client == nil { if client == nil {
cmd.PrintErrln("OSC client not found in context") return fmt.Errorf("OSC client not found in context")
return
} }
if len(args) < 1 { if len(args) < 1 {
cmd.PrintErrln("Please provide strip number") return fmt.Errorf("Please provide strip number")
return
} }
stripIndex := mustConvToInt(args[0]) stripIndex := mustConvToInt(args[0])
duration, err := cmd.Flags().GetFloat64("duration") duration, err := cmd.Flags().GetFloat64("duration")
if err != nil { if err != nil {
cmd.PrintErrln("Error getting duration flag:", err) return fmt.Errorf("Error getting duration flag: %w", err)
return
} }
target := -90.0 target := -90.0
@@ -167,14 +159,13 @@ var stripFadeOutCmd = &cobra.Command{
currentFader, err := client.Strip.Fader(stripIndex) currentFader, err := client.Strip.Fader(stripIndex)
if err != nil { if err != nil {
cmd.PrintErrln("Error getting current strip fader level:", err) return fmt.Errorf("Error getting current strip fader level: %w", err)
return
} }
totalSteps := float64(currentFader - target) totalSteps := float64(currentFader - target)
if totalSteps <= 0 { if totalSteps <= 0 {
cmd.Println("Strip is already at or below target level") cmd.Println("Strip is already at or below target level")
return return nil
} }
stepDelay := time.Duration(duration*1000/totalSteps) * time.Millisecond stepDelay := time.Duration(duration*1000/totalSteps) * time.Millisecond
@@ -183,13 +174,13 @@ var stripFadeOutCmd = &cobra.Command{
currentFader -= 1.0 currentFader -= 1.0
err := client.Strip.SetFader(stripIndex, currentFader) err := client.Strip.SetFader(stripIndex, currentFader)
if err != nil { if err != nil {
cmd.PrintErrln("Error setting strip fader level:", err) return fmt.Errorf("Error setting strip fader level: %w", err)
return
} }
time.Sleep(stepDelay) time.Sleep(stepDelay)
} }
cmd.Printf("Strip %d faded out to %.2f dB over %.2f seconds\n", stripIndex, target, duration) cmd.Printf("Strip %d faded out to %.2f dB over %.2f seconds\n", stripIndex, target, duration)
return nil
}, },
} }
@@ -200,24 +191,21 @@ var stripFadeInCmd = &cobra.Command{
Use: "fadein [strip number] --duration [seconds] [target level in dB]", Use: "fadein [strip number] --duration [seconds] [target level in dB]",
Example: ` # Fade in strip 1 over 5 seconds Example: ` # Fade in strip 1 over 5 seconds
xair-cli strip fadein 1 --duration 5.0 0`, xair-cli strip fadein 1 --duration 5.0 0`,
Run: func(cmd *cobra.Command, args []string) { RunE: func(cmd *cobra.Command, args []string) error {
client := ClientFromContext(cmd.Context()) client := ClientFromContext(cmd.Context())
if client == nil { if client == nil {
cmd.PrintErrln("OSC client not found in context") return fmt.Errorf("OSC client not found in context")
return
} }
if len(args) < 1 { if len(args) < 1 {
cmd.PrintErrln("Please provide strip number") return fmt.Errorf("Please provide strip number")
return
} }
stripIndex := mustConvToInt(args[0]) stripIndex := mustConvToInt(args[0])
duration, err := cmd.Flags().GetFloat64("duration") duration, err := cmd.Flags().GetFloat64("duration")
if err != nil { if err != nil {
cmd.PrintErrln("Error getting duration flag:", err) return fmt.Errorf("Error getting duration flag: %w", err)
return
} }
target := 0.0 target := 0.0
@@ -227,14 +215,13 @@ var stripFadeInCmd = &cobra.Command{
currentFader, err := client.Strip.Fader(stripIndex) currentFader, err := client.Strip.Fader(stripIndex)
if err != nil { if err != nil {
cmd.PrintErrln("Error getting current strip fader level:", err) return fmt.Errorf("Error getting current strip fader level: %w", err)
return
} }
totalSteps := float64(target - currentFader) totalSteps := float64(target - currentFader)
if totalSteps <= 0 { if totalSteps <= 0 {
cmd.Println("Strip is already at or above target level") cmd.Println("Strip is already at or above target level")
return return nil
} }
stepDelay := time.Duration(duration*1000/totalSteps) * time.Millisecond stepDelay := time.Duration(duration*1000/totalSteps) * time.Millisecond
@@ -243,13 +230,13 @@ var stripFadeInCmd = &cobra.Command{
currentFader += 1.0 currentFader += 1.0
err := client.Strip.SetFader(stripIndex, currentFader) err := client.Strip.SetFader(stripIndex, currentFader)
if err != nil { if err != nil {
cmd.PrintErrln("Error setting strip fader level:", err) return fmt.Errorf("Error setting strip fader level: %w", err)
return
} }
time.Sleep(stepDelay) time.Sleep(stepDelay)
} }
cmd.Printf("Strip %d faded in to %.2f dB over %.2f seconds\n", stripIndex, target, duration) cmd.Printf("Strip %d faded in to %.2f dB over %.2f seconds\n", stripIndex, target, duration)
return nil
}, },
} }
@@ -263,16 +250,14 @@ var stripSendCmd = &cobra.Command{
# Set the send level of strip 1 to bus 1 to -5.0 dB # Set the send level of strip 1 to bus 1 to -5.0 dB
xair-cli strip send 1 1 -- -5.0`, xair-cli strip send 1 1 -- -5.0`,
Run: func(cmd *cobra.Command, args []string) { RunE: func(cmd *cobra.Command, args []string) error {
client := ClientFromContext(cmd.Context()) client := ClientFromContext(cmd.Context())
if client == nil { if client == nil {
cmd.PrintErrln("OSC client not found in context") return fmt.Errorf("OSC client not found in context")
return
} }
if len(args) < 2 { if len(args) < 2 {
cmd.PrintErrln("Please provide strip number and bus number") return fmt.Errorf("Please provide strip number and bus number")
return
} }
stripIndex, busIndex := func() (int, int) { stripIndex, busIndex := func() (int, int) {
@@ -282,26 +267,24 @@ var stripSendCmd = &cobra.Command{
if len(args) == 2 { if len(args) == 2 {
currentLevel, err := client.Strip.SendLevel(stripIndex, busIndex) currentLevel, err := client.Strip.SendLevel(stripIndex, busIndex)
if err != nil { if err != nil {
cmd.PrintErrln("Error getting strip send level:", err) return fmt.Errorf("Error getting strip send level: %w", err)
return
} }
cmd.Printf("Strip %d send level to bus %d: %.2f dB\n", stripIndex, busIndex, currentLevel) cmd.Printf("Strip %d send level to bus %d: %.2f dB\n", stripIndex, busIndex, currentLevel)
return return nil
} }
if len(args) < 3 { if len(args) < 3 {
cmd.PrintErrln("Please provide a send level in dB") return fmt.Errorf("Please provide a send level in dB")
return
} }
level := mustConvToFloat64(args[2]) level := mustConvToFloat64(args[2])
err := client.Strip.SetSendLevel(stripIndex, busIndex, level) err := client.Strip.SetSendLevel(stripIndex, busIndex, level)
if err != nil { if err != nil {
cmd.PrintErrln("Error setting strip send level:", err) return fmt.Errorf("Error setting strip send level: %w", err)
return
} }
cmd.Printf("Strip %d send level to bus %d set to %.2f dB\n", stripIndex, busIndex, level) cmd.Printf("Strip %d send level to bus %d set to %.2f dB\n", stripIndex, busIndex, level)
return nil
}, },
} }
@@ -318,16 +301,14 @@ If a name argument is provided, the strip name is set to that value.`,
# Set the name of strip 1 to "Guitar" # Set the name of strip 1 to "Guitar"
xair-cli strip name 1 "Guitar"`, xair-cli strip name 1 "Guitar"`,
Run: func(cmd *cobra.Command, args []string) { RunE: func(cmd *cobra.Command, args []string) error {
client := ClientFromContext(cmd.Context()) client := ClientFromContext(cmd.Context())
if client == nil { if client == nil {
cmd.PrintErrln("OSC client not found in context") return fmt.Errorf("OSC client not found in context")
return
} }
if len(args) < 1 { if len(args) < 1 {
cmd.PrintErrln("Please provide a strip number") return fmt.Errorf("Please provide a strip number")
return
} }
stripIndex := mustConvToInt(args[0]) stripIndex := mustConvToInt(args[0])
@@ -335,21 +316,20 @@ If a name argument is provided, the strip name is set to that value.`,
if len(args) == 1 { if len(args) == 1 {
name, err := client.Strip.Name(stripIndex) name, err := client.Strip.Name(stripIndex)
if err != nil { if err != nil {
cmd.PrintErrln("Error getting strip name:", err) return fmt.Errorf("Error getting strip name: %w", err)
return
} }
cmd.Printf("Strip %d name: %s\n", stripIndex, name) cmd.Printf("Strip %d name: %s\n", stripIndex, name)
return return nil
} }
name := args[1] name := args[1]
err := client.Strip.SetName(stripIndex, name) err := client.Strip.SetName(stripIndex, name)
if err != nil { if err != nil {
cmd.PrintErrln("Error setting strip name:", err) return fmt.Errorf("Error setting strip name: %w", err)
return
} }
cmd.Printf("Strip %d name set to: %s\n", stripIndex, name) cmd.Printf("Strip %d name set to: %s\n", stripIndex, name)
return nil
}, },
} }

View File

@@ -16,8 +16,7 @@ func NewBus(c Client) *Bus {
// Mute requests the current mute status for a bus // Mute requests the current mute status for a bus
func (b *Bus) Mute(bus int) (bool, error) { func (b *Bus) Mute(bus int) (bool, error) {
formatter := b.client.addressMap["bus"] address := fmt.Sprintf(b.baseAddress, bus) + "/mix/on"
address := fmt.Sprintf(formatter, bus) + "/mix/on"
err := b.client.SendMessage(address) err := b.client.SendMessage(address)
if err != nil { if err != nil {
return false, err return false, err

View File

@@ -128,25 +128,3 @@ func (s *Strip) SetSendLevel(strip int, bus int, level float64) error {
address := fmt.Sprintf(s.baseAddress, strip) + fmt.Sprintf("/mix/%02d/level", bus) address := fmt.Sprintf(s.baseAddress, strip) + fmt.Sprintf("/mix/%02d/level", bus)
return s.client.SendMessage(address, float32(mustDbInto(level))) return s.client.SendMessage(address, float32(mustDbInto(level)))
} }
// MicGain requests the phantom gain for a specific strip (1-based indexing).
func (s *Strip) MicGain(strip int) (float64, error) {
address := fmt.Sprintf(s.baseAddress, strip) + "/mix/gain"
err := s.client.SendMessage(address)
if err != nil {
return 0, fmt.Errorf("failed to send strip gain request: %v", err)
}
resp := <-s.client.respChan
val, ok := resp.Arguments[0].(float32)
if !ok {
return 0, fmt.Errorf("unexpected argument type for strip gain value")
}
return mustDbFrom(float64(val)), nil
}
// SetMicGain sets the phantom gain for a specific strip (1-based indexing).
func (s *Strip) SetMicGain(strip int, gain float64) error {
address := fmt.Sprintf(s.baseAddress, strip) + "/mix/gain"
return s.client.SendMessage(address, float32(mustDbInto(gain)))
}

View File

@@ -1,6 +1,3 @@
/*
LICENSE: https://github.com/onyx-and-iris/xair-cli/blob/main/LICENSE
*/
package main package main
import "github.com/onyx-and-iris/xair-cli/cmd" import "github.com/onyx-and-iris/xair-cli/cmd"