mirror of
https://github.com/onyx-and-iris/xair-cli.git
synced 2026-02-03 23:17:47 +00:00
593 lines
16 KiB
Go
593 lines
16 KiB
Go
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
// busCmd represents the bus command.
|
|
var busCmd = &cobra.Command{
|
|
Short: "Commands to control individual buses",
|
|
Long: `Commands to control individual buses of the XAir mixer, including mute status.`,
|
|
Use: "bus",
|
|
Run: func(cmd *cobra.Command, _ []string) {
|
|
cmd.Help()
|
|
},
|
|
}
|
|
|
|
// busMuteCmd represents the bus mute command.
|
|
var busMuteCmd = &cobra.Command{
|
|
Short: "Get or set the bus mute status",
|
|
Long: `Get or set the mute status of a specific bus.`,
|
|
Use: "mute [bus number] [true|false]",
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
client := ClientFromContext(cmd.Context())
|
|
if client == nil {
|
|
return fmt.Errorf("OSC client not found in context")
|
|
}
|
|
|
|
if len(args) < 2 {
|
|
return fmt.Errorf("Please provide bus number and mute status (true/false)")
|
|
}
|
|
|
|
busNum := mustConvToInt(args[0])
|
|
var muted bool
|
|
switch args[1] {
|
|
case "true", "1":
|
|
muted = true
|
|
case "false", "0":
|
|
muted = false
|
|
default:
|
|
return fmt.Errorf("Invalid mute status. Use true/false or 1/0")
|
|
}
|
|
|
|
err := client.Bus.SetMute(busNum, muted)
|
|
if err != nil {
|
|
return fmt.Errorf("Error setting bus mute status: %w", err)
|
|
}
|
|
|
|
cmd.Printf("Bus %d mute set to %v\n", busNum, muted)
|
|
return nil
|
|
},
|
|
}
|
|
|
|
// busFaderCmd represents the bus fader command.
|
|
var busFaderCmd = &cobra.Command{
|
|
Short: "Get or set the bus fader level",
|
|
Long: `Get or set the fader level of a specific bus.
|
|
If no level argument is provided, the current fader level is retrieved.
|
|
If a level argument (in dB) is provided, the bus fader is set to that level.`,
|
|
Use: "fader [bus number] [level in dB]",
|
|
Example: ` # Get the current fader level of bus 1
|
|
xair-cli bus fader 1
|
|
|
|
# Set the fader level of bus 1 to -10.0 dB
|
|
xair-cli bus fader 1 -10.0`,
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
client := ClientFromContext(cmd.Context())
|
|
if client == nil {
|
|
return fmt.Errorf("OSC client not found in context")
|
|
}
|
|
|
|
busIndex := mustConvToInt(args[0])
|
|
|
|
if len(args) == 1 {
|
|
level, err := client.Bus.Fader(busIndex)
|
|
if err != nil {
|
|
return fmt.Errorf("Error getting bus fader level: %w", err)
|
|
}
|
|
cmd.Printf("Bus %d fader level: %.1f dB\n", busIndex, level)
|
|
return nil
|
|
}
|
|
|
|
if len(args) < 2 {
|
|
return fmt.Errorf("Please provide bus number and fader level (in dB)")
|
|
}
|
|
|
|
level := mustConvToFloat64(args[1])
|
|
|
|
err := client.Bus.SetFader(busIndex, level)
|
|
if err != nil {
|
|
return fmt.Errorf("Error setting bus fader level: %w", err)
|
|
}
|
|
|
|
cmd.Printf("Bus %d fader set to %.2f dB\n", busIndex, level)
|
|
return nil
|
|
},
|
|
}
|
|
|
|
// busFadeOutCmd represents the bus fade out command.
|
|
var busFadeOutCmd = &cobra.Command{
|
|
Short: "Fade out the bus fader over a specified duration",
|
|
Long: "Fade out the bus fader to minimum level over a specified duration in seconds.",
|
|
Use: "fadeout [bus number] --duration [seconds] [target level in dB]",
|
|
Example: ` # Fade out bus 1 over 5 seconds
|
|
xair-cli bus fadeout 1 --duration 5s -- -90.0`,
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
client := ClientFromContext(cmd.Context())
|
|
if client == nil {
|
|
return fmt.Errorf("OSC client not found in context")
|
|
}
|
|
|
|
if len(args) < 1 {
|
|
return fmt.Errorf("Please provide bus number")
|
|
}
|
|
|
|
busIndex := mustConvToInt(args[0])
|
|
|
|
duration, err := cmd.Flags().GetDuration("duration")
|
|
if err != nil {
|
|
return fmt.Errorf("Error getting duration flag: %w", err)
|
|
}
|
|
|
|
target := -90.0
|
|
if len(args) > 1 {
|
|
target = mustConvToFloat64(args[1])
|
|
}
|
|
|
|
currentFader, err := client.Bus.Fader(busIndex)
|
|
if err != nil {
|
|
return fmt.Errorf("Error getting current bus fader level: %w", err)
|
|
}
|
|
|
|
// Calculate total steps needed to reach target dB
|
|
totalSteps := float64(currentFader - target)
|
|
if totalSteps <= 0 {
|
|
cmd.Println("Bus is already at or below target level")
|
|
return nil
|
|
}
|
|
|
|
stepDelay := time.Duration(duration.Seconds()*1000/totalSteps) * time.Millisecond
|
|
|
|
for currentFader > target {
|
|
currentFader -= 1.0
|
|
err := client.Bus.SetFader(busIndex, currentFader)
|
|
if err != nil {
|
|
return fmt.Errorf("Error setting bus fader level: %w", err)
|
|
}
|
|
time.Sleep(stepDelay)
|
|
}
|
|
|
|
cmd.Println("Bus fade out completed")
|
|
return nil
|
|
},
|
|
}
|
|
|
|
// BusFadeInCmd represents the bus fade in command.
|
|
var busFadeInCmd = &cobra.Command{
|
|
Short: "Fade in the bus fader over a specified duration",
|
|
Long: "Fade in the bus fader to maximum level over a specified duration in seconds.",
|
|
Use: "fadein [bus number] --duration [seconds] [target level in dB]",
|
|
Example: ` # Fade in bus 1 over 5 seconds
|
|
xair-cli bus fadein 1 --duration 5s -- 0.0`,
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
client := ClientFromContext(cmd.Context())
|
|
if client == nil {
|
|
return fmt.Errorf("OSC client not found in context")
|
|
}
|
|
|
|
if len(args) < 1 {
|
|
return fmt.Errorf("Please provide bus number")
|
|
}
|
|
|
|
busIndex := mustConvToInt(args[0])
|
|
|
|
duration, err := cmd.Flags().GetDuration("duration")
|
|
if err != nil {
|
|
return fmt.Errorf("Error getting duration flag: %w", err)
|
|
}
|
|
|
|
target := 0.0
|
|
if len(args) > 1 {
|
|
target = mustConvToFloat64(args[1])
|
|
}
|
|
|
|
currentFader, err := client.Bus.Fader(busIndex)
|
|
if err != nil {
|
|
return fmt.Errorf("Error getting current bus fader level: %w", err)
|
|
}
|
|
|
|
// Calculate total steps needed to reach target dB
|
|
totalSteps := float64(target - currentFader)
|
|
if totalSteps <= 0 {
|
|
cmd.Println("Bus is already at or above target level")
|
|
return nil
|
|
}
|
|
|
|
stepDelay := time.Duration(duration.Seconds()*1000/totalSteps) * time.Millisecond
|
|
|
|
for currentFader < target {
|
|
currentFader += 1.0
|
|
err := client.Bus.SetFader(busIndex, currentFader)
|
|
if err != nil {
|
|
return fmt.Errorf("Error setting bus fader level: %w", err)
|
|
}
|
|
time.Sleep(stepDelay)
|
|
}
|
|
|
|
cmd.Println("Bus fade in completed")
|
|
return nil
|
|
},
|
|
}
|
|
|
|
// busNameCmd represents the bus name command.
|
|
var busNameCmd = &cobra.Command{
|
|
Short: "Get or set the bus name",
|
|
Long: `Get or set the name of a specific bus.`,
|
|
Use: "name [bus number] [new name]",
|
|
Example: ` # Get the name of bus 1
|
|
xair-cli bus name 1
|
|
|
|
# Set the name of bus 1 to "Vocals"
|
|
xair-cli bus name 1 Vocals`,
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
client := ClientFromContext(cmd.Context())
|
|
if client == nil {
|
|
return fmt.Errorf("OSC client not found in context")
|
|
}
|
|
|
|
if len(args) < 1 {
|
|
return fmt.Errorf("Please provide bus number")
|
|
}
|
|
|
|
busIndex := mustConvToInt(args[0])
|
|
|
|
if len(args) == 1 {
|
|
name, err := client.Bus.Name(busIndex)
|
|
if err != nil {
|
|
return fmt.Errorf("Error getting bus name: %w", err)
|
|
}
|
|
cmd.Printf("Bus %d name: %s\n", busIndex, name)
|
|
return nil
|
|
}
|
|
|
|
newName := args[1]
|
|
err := client.Bus.SetName(busIndex, newName)
|
|
if err != nil {
|
|
return fmt.Errorf("Error setting bus name: %w", err)
|
|
}
|
|
|
|
cmd.Printf("Bus %d name set to: %s\n", busIndex, newName)
|
|
return nil
|
|
},
|
|
}
|
|
|
|
// busEqCmd represents the bus EQ command.
|
|
var busEqCmd = &cobra.Command{
|
|
Short: "Commands to control bus EQ settings",
|
|
Long: `Commands to control the EQ of individual buses, including turning the EQ on or off.`,
|
|
Use: "eq",
|
|
Run: func(cmd *cobra.Command, _ []string) {
|
|
cmd.Help()
|
|
},
|
|
}
|
|
|
|
// busEqOnCmd represents the bus EQ on/off command.
|
|
var busEqOnCmd = &cobra.Command{
|
|
Short: "Get or set the bus EQ on/off status",
|
|
Long: `Get or set the EQ on/off status of a specific bus.`,
|
|
Use: "on [bus number] [true|false]",
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
client := ClientFromContext(cmd.Context())
|
|
if client == nil {
|
|
return fmt.Errorf("OSC client not found in context")
|
|
}
|
|
|
|
if len(args) < 2 {
|
|
return fmt.Errorf("Please provide bus number and EQ on status (true/false)")
|
|
}
|
|
|
|
busNum := mustConvToInt(args[0])
|
|
var eqOn bool
|
|
switch args[1] {
|
|
case "true", "1":
|
|
eqOn = true
|
|
case "false", "0":
|
|
eqOn = false
|
|
default:
|
|
return fmt.Errorf("Invalid EQ on status. Use true/false or 1/0")
|
|
}
|
|
|
|
err := client.Bus.Eq.SetOn(busNum, eqOn)
|
|
if err != nil {
|
|
return fmt.Errorf("Error setting bus EQ on status: %w", err)
|
|
}
|
|
|
|
cmd.Printf("Bus %d EQ on set to %v\n", busNum, eqOn)
|
|
return nil
|
|
},
|
|
}
|
|
|
|
// busEqModeCmd represents the bus EQ mode command.
|
|
var busEqModeCmd = &cobra.Command{
|
|
Short: "Get or set the bus EQ mode",
|
|
Long: `Get or set the EQ mode of a specific bus.`,
|
|
Use: "mode [bus number] [mode]",
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
client := ClientFromContext(cmd.Context())
|
|
if client == nil {
|
|
return fmt.Errorf("OSC client not found in context")
|
|
}
|
|
|
|
if len(args) < 1 {
|
|
return fmt.Errorf("Please provide bus number")
|
|
}
|
|
|
|
busIndex := mustConvToInt(args[0])
|
|
|
|
modeNames := []string{"peq", "geq", "teq"}
|
|
|
|
if len(args) == 1 {
|
|
mode, err := client.Bus.Eq.Mode(busIndex)
|
|
if err != nil {
|
|
return fmt.Errorf("Error getting bus EQ mode: %w", err)
|
|
}
|
|
cmd.Printf("Bus %d EQ mode: %s\n", busIndex, modeNames[mode])
|
|
return nil
|
|
}
|
|
|
|
mode := indexOf(modeNames, args[1])
|
|
if mode == -1 {
|
|
return fmt.Errorf("Invalid EQ mode. Valid modes are: %v", modeNames)
|
|
}
|
|
|
|
err := client.Bus.Eq.SetMode(busIndex, mode)
|
|
if err != nil {
|
|
return fmt.Errorf("Error setting bus EQ mode: %w", err)
|
|
}
|
|
|
|
cmd.Printf("Bus %d EQ mode set to %s\n", busIndex, modeNames[mode])
|
|
return nil
|
|
},
|
|
}
|
|
|
|
// busEqGainCmd represents the bus EQ gain command.
|
|
var busEqGainCmd = &cobra.Command{
|
|
Short: "Get or set the bus EQ gain for a specific band",
|
|
Long: `Get or set the EQ gain (in dB) for a specific band of a bus.
|
|
|
|
Gain values range from -15.0 dB to +15.0 dB.`,
|
|
Use: "gain [bus number] [band number] [gain in dB]",
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
client := ClientFromContext(cmd.Context())
|
|
if client == nil {
|
|
return fmt.Errorf("OSC client not found in context")
|
|
}
|
|
|
|
if len(args) < 2 {
|
|
return fmt.Errorf("Please provide bus number and band number")
|
|
}
|
|
|
|
busIndex, bandIndex := func() (int, int) {
|
|
return mustConvToInt(args[0]), mustConvToInt(args[1])
|
|
}()
|
|
|
|
if len(args) == 2 {
|
|
gain, err := client.Bus.Eq.Gain(busIndex, bandIndex)
|
|
if err != nil {
|
|
return fmt.Errorf("Error getting bus EQ gain: %w", err)
|
|
}
|
|
cmd.Printf("Bus %d EQ band %d gain: %.1f dB\n", busIndex, bandIndex, gain)
|
|
return nil
|
|
}
|
|
|
|
if len(args) < 3 {
|
|
return fmt.Errorf("Please provide bus number, band number, and gain (in dB)")
|
|
}
|
|
|
|
gain := mustConvToFloat64(args[2])
|
|
|
|
err := client.Bus.Eq.SetGain(busIndex, bandIndex, gain)
|
|
if err != nil {
|
|
return fmt.Errorf("Error setting bus EQ gain: %w", err)
|
|
}
|
|
|
|
cmd.Printf("Bus %d EQ band %d gain set to %.1f dB\n", busIndex, bandIndex, gain)
|
|
return nil
|
|
},
|
|
}
|
|
|
|
// busEqFreqCmd represents the bus EQ frequency command.
|
|
var busEqFreqCmd = &cobra.Command{
|
|
Short: "Get or set the bus EQ frequency for a specific band",
|
|
Long: `Get or set the EQ frequency (in Hz) for a specific band of a bus.`,
|
|
Use: "freq [bus number] [band number] [frequency in Hz]",
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
client := ClientFromContext(cmd.Context())
|
|
if client == nil {
|
|
return fmt.Errorf("OSC client not found in context")
|
|
}
|
|
|
|
if len(args) < 2 {
|
|
return fmt.Errorf("Please provide bus number and band number")
|
|
}
|
|
|
|
busIndex, bandIndex := func() (int, int) {
|
|
return mustConvToInt(args[0]), mustConvToInt(args[1])
|
|
}()
|
|
|
|
if len(args) == 2 {
|
|
freq, err := client.Bus.Eq.Frequency(busIndex, bandIndex)
|
|
if err != nil {
|
|
return fmt.Errorf("Error getting bus EQ frequency: %w", err)
|
|
}
|
|
cmd.Printf("Bus %d EQ band %d frequency: %.1f Hz\n", busIndex, bandIndex, freq)
|
|
return nil
|
|
}
|
|
|
|
if len(args) < 3 {
|
|
return fmt.Errorf("Please provide bus number, band number, and frequency (in Hz)")
|
|
}
|
|
|
|
freq := mustConvToFloat64(args[2])
|
|
|
|
err := client.Bus.Eq.SetFrequency(busIndex, bandIndex, freq)
|
|
if err != nil {
|
|
return fmt.Errorf("Error setting bus EQ frequency: %w", err)
|
|
}
|
|
|
|
cmd.Printf("Bus %d EQ band %d frequency set to %.1f Hz\n", busIndex, bandIndex, freq)
|
|
return nil
|
|
},
|
|
}
|
|
|
|
// busEqQCmd represents the bus EQ Q command.
|
|
var busEqQCmd = &cobra.Command{
|
|
Short: "Get or set the bus EQ Q factor for a specific band",
|
|
Long: `Get or set the EQ Q factor for a specific band of a bus.`,
|
|
Use: "q [bus number] [band number] [Q factor]",
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
client := ClientFromContext(cmd.Context())
|
|
if client == nil {
|
|
return fmt.Errorf("OSC client not found in context")
|
|
}
|
|
|
|
if len(args) < 2 {
|
|
return fmt.Errorf("Please provide bus number and band number")
|
|
}
|
|
|
|
busIndex, bandIndex := func() (int, int) {
|
|
return mustConvToInt(args[0]), mustConvToInt(args[1])
|
|
}()
|
|
|
|
if len(args) == 2 {
|
|
qFactor, err := client.Bus.Eq.Q(busIndex, bandIndex)
|
|
if err != nil {
|
|
return fmt.Errorf("Error getting bus EQ Q factor: %w", err)
|
|
}
|
|
cmd.Printf("Bus %d EQ band %d Q factor: %.2f\n", busIndex, bandIndex, qFactor)
|
|
return nil
|
|
}
|
|
|
|
if len(args) < 3 {
|
|
return fmt.Errorf("Please provide bus number, band number, and Q factor")
|
|
}
|
|
|
|
qFactor := mustConvToFloat64(args[2])
|
|
|
|
err := client.Bus.Eq.SetQ(busIndex, bandIndex, qFactor)
|
|
if err != nil {
|
|
return fmt.Errorf("Error setting bus EQ Q factor: %w", err)
|
|
}
|
|
|
|
cmd.Printf("Bus %d EQ band %d Q factor set to %.2f\n", busIndex, bandIndex, qFactor)
|
|
return nil
|
|
},
|
|
}
|
|
|
|
// busEqTypeCmd represents the bus EQ type command.
|
|
var busEqTypeCmd = &cobra.Command{
|
|
Short: "Get or set the bus EQ band type",
|
|
Long: `Get or set the EQ band type for a specific band of a bus.`,
|
|
Use: "type [bus number] [band number] [type]",
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
client := ClientFromContext(cmd.Context())
|
|
if client == nil {
|
|
return fmt.Errorf("OSC client not found in context")
|
|
}
|
|
|
|
if len(args) < 2 {
|
|
return fmt.Errorf("Please provide bus number and band number")
|
|
}
|
|
|
|
busIndex, bandIndex := func() (int, int) {
|
|
return mustConvToInt(args[0]), mustConvToInt(args[1])
|
|
}()
|
|
|
|
eqTypeNames := []string{"lcut", "lshv", "peq", "veq", "hshv", "hcut"}
|
|
|
|
if len(args) == 2 {
|
|
currentType, err := client.Bus.Eq.Type(busIndex, bandIndex)
|
|
if err != nil {
|
|
return fmt.Errorf("Error getting bus EQ band type: %w", err)
|
|
}
|
|
cmd.Printf("Bus %d EQ band %d type: %s\n", busIndex, bandIndex, eqTypeNames[currentType])
|
|
return nil
|
|
}
|
|
|
|
eqType := indexOf(eqTypeNames, args[2])
|
|
if eqType == -1 {
|
|
return fmt.Errorf("Invalid EQ band type. Valid types are: %v", eqTypeNames)
|
|
}
|
|
|
|
err := client.Bus.Eq.SetType(busIndex, bandIndex, eqType)
|
|
if err != nil {
|
|
return fmt.Errorf("Error setting bus EQ band type: %w", err)
|
|
}
|
|
|
|
cmd.Printf("Bus %d EQ band %d type set to %s\n", busIndex, bandIndex, eqTypeNames[eqType])
|
|
return nil
|
|
},
|
|
}
|
|
|
|
// busCompCmd represents the bus Compressor command.
|
|
var busCompCmd = &cobra.Command{
|
|
Short: "Commands to control bus Compressor settings",
|
|
Long: `Commands to control the Compressor of individual buses, including turning the Compressor on or off.`,
|
|
Use: "comp",
|
|
Run: func(cmd *cobra.Command, _ []string) {
|
|
cmd.Help()
|
|
},
|
|
}
|
|
|
|
// busCompOnCmd represents the bus Compressor on/off command.
|
|
var busCompOnCmd = &cobra.Command{
|
|
Short: "Get or set the bus Compressor on/off status",
|
|
Long: `Get or set the Compressor on/off status of a specific bus.`,
|
|
Use: "on [bus number] [true|false]",
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
client := ClientFromContext(cmd.Context())
|
|
if client == nil {
|
|
return fmt.Errorf("OSC client not found in context")
|
|
}
|
|
|
|
if len(args) < 2 {
|
|
return fmt.Errorf("Please provide bus number and Compressor on status (true/false)")
|
|
}
|
|
|
|
busNum := mustConvToInt(args[0])
|
|
var compOn bool
|
|
switch args[1] {
|
|
case "true", "1":
|
|
compOn = true
|
|
case "false", "0":
|
|
compOn = false
|
|
default:
|
|
return fmt.Errorf("Invalid Compressor on status. Use true/false or 1/0")
|
|
}
|
|
|
|
err := client.Bus.Comp.SetOn(busNum, compOn)
|
|
if err != nil {
|
|
return fmt.Errorf("Error setting bus Compressor on status: %w", err)
|
|
}
|
|
|
|
cmd.Printf("Bus %d Compressor on set to %v\n", busNum, compOn)
|
|
return nil
|
|
},
|
|
}
|
|
|
|
func init() {
|
|
rootCmd.AddCommand(busCmd)
|
|
|
|
busCmd.AddCommand(busMuteCmd)
|
|
busCmd.AddCommand(busFaderCmd)
|
|
busCmd.AddCommand(busFadeOutCmd)
|
|
busFadeOutCmd.Flags().DurationP("duration", "d", 5*time.Second, "Duration for fade out in seconds")
|
|
busCmd.AddCommand(busFadeInCmd)
|
|
busFadeInCmd.Flags().DurationP("duration", "d", 5*time.Second, "Duration for fade in in seconds")
|
|
busCmd.AddCommand(busNameCmd)
|
|
|
|
busCmd.AddCommand(busEqCmd)
|
|
busEqCmd.AddCommand(busEqOnCmd)
|
|
busEqCmd.AddCommand(busEqModeCmd)
|
|
busEqCmd.AddCommand(busEqGainCmd)
|
|
busEqCmd.AddCommand(busEqFreqCmd)
|
|
busEqCmd.AddCommand(busEqQCmd)
|
|
busEqCmd.AddCommand(busEqTypeCmd)
|
|
|
|
busCmd.AddCommand(busCompCmd)
|
|
busCompCmd.AddCommand(busCompOnCmd)
|
|
}
|