diff --git a/cmd/bus.go b/cmd/bus.go index 40f75fc..1b4a953 100644 --- a/cmd/bus.go +++ b/cmd/bus.go @@ -300,6 +300,52 @@ var busEqOnCmd = &cobra.Command{ }, } +// 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) @@ -313,4 +359,7 @@ func init() { busCmd.AddCommand(busEqCmd) busEqCmd.AddCommand(busEqOnCmd) + + busCmd.AddCommand(busCompCmd) + busCompCmd.AddCommand(busCompOnCmd) } diff --git a/cmd/strip.go b/cmd/strip.go index a4db0d2..06ecfde 100644 --- a/cmd/strip.go +++ b/cmd/strip.go @@ -333,6 +333,77 @@ If a name argument is provided, the strip name is set to that value.`, }, } +// stripGateCmd represents the strip Gate command. +var stripGateCmd = &cobra.Command{ + Short: "Commands to control the Gate of individual strips.", + Long: `Commands to control the Gate of individual strips, including turning the Gate on or off.`, + Use: "gate", + Run: func(cmd *cobra.Command, _ []string) { + cmd.Help() + }, +} + +// stripGateOnCmd represents the strip Gate on command. +var stripGateOnCmd = &cobra.Command{ + Short: "Get or set the Gate on/off status of a strip", + Long: `Get or set the Gate on/off status of a specific strip. + +If no status argument is provided, the current Gate status is retrieved. +If "true" or "1" is provided as an argument, the Gate is turned on. +If "false" or "0" is provided, the Gate is turned off.`, + Use: "on [strip number] [true|false]", + Example: ` # Get the current Gate status of strip 1 + xair-cli strip gate on 1 + + # Turn on Gate for strip 1 + xair-cli strip gate on 1 true + # Turn off Gate for strip 1 + xair-cli strip gate on 1 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) < 1 { + return fmt.Errorf("Please provide a strip number") + } + + stripIndex := mustConvToInt(args[0]) + + if len(args) == 1 { + on, err := client.Strip.Gate.On(stripIndex) + if err != nil { + return fmt.Errorf("Error getting strip Gate on status: %w", err) + } + cmd.Printf("Strip %d Gate on: %v\n", stripIndex, on) + return nil + } + + var on bool + switch args[1] { + case "true", "1": + on = true + case "false", "0": + on = false + default: + return fmt.Errorf("Invalid Gate status. Use true/false or 1/0") + } + + err := client.Strip.Gate.SetOn(stripIndex, on) + if err != nil { + return fmt.Errorf("Error setting strip Gate on status: %w", err) + } + + if on { + cmd.Printf("Strip %d Gate turned on successfully\n", stripIndex) + } else { + cmd.Printf("Strip %d Gate turned off successfully\n", stripIndex) + } + return nil + }, +} + // stripEqCmd represents the strip EQ command. var stripEqCmd = &cobra.Command{ Short: "Commands to control the EQ of individual strips.", @@ -404,6 +475,77 @@ If "false" or "0" is provided, the EQ is turned off.`, }, } +// stripCompCmd represents the strip Compressor command. +var stripCompCmd = &cobra.Command{ + Short: "Commands to control the Compressor of individual strips.", + Long: `Commands to control the Compressor of individual strips, including turning the Compressor on or off.`, + Use: "comp", + Run: func(cmd *cobra.Command, _ []string) { + cmd.Help() + }, +} + +// stripCompOnCmd represents the strip Compressor on command. +var stripCompOnCmd = &cobra.Command{ + Short: "Get or set the Compressor on/off status of a strip", + Long: `Get or set the Compressor on/off status of a specific strip. + +If no status argument is provided, the current Compressor status is retrieved. +If "true" or "1" is provided as an argument, the Compressor is turned on. +If "false" or "0" is provided, the Compressor is turned off.`, + Use: "on [strip number] [true|false]", + Example: ` # Get the current Compressor status of strip 1 + xair-cli strip comp on 1 + + # Turn on Compressor for strip 1 + xair-cli strip comp on 1 true + # Turn off Compressor for strip 1 + xair-cli strip comp on 1 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) < 1 { + return fmt.Errorf("Please provide a strip number") + } + + stripIndex := mustConvToInt(args[0]) + + if len(args) == 1 { + on, err := client.Strip.Comp.On(stripIndex) + if err != nil { + return fmt.Errorf("Error getting strip Compressor on status: %w", err) + } + cmd.Printf("Strip %d Compressor on: %v\n", stripIndex, on) + return nil + } + + var on bool + switch args[1] { + case "true", "1": + on = true + case "false", "0": + on = false + default: + return fmt.Errorf("Invalid Compressor status. Use true/false or 1/0") + } + + err := client.Strip.Comp.SetOn(stripIndex, on) + if err != nil { + return fmt.Errorf("Error setting strip Compressor on status: %w", err) + } + + if on { + cmd.Printf("Strip %d Compressor turned on successfully\n", stripIndex) + } else { + cmd.Printf("Strip %d Compressor turned off successfully\n", stripIndex) + } + return nil + }, +} + func init() { rootCmd.AddCommand(stripCmd) @@ -416,6 +558,12 @@ func init() { stripCmd.AddCommand(stripSendCmd) stripCmd.AddCommand(stripNameCmd) + stripCmd.AddCommand(stripGateCmd) + stripGateCmd.AddCommand(stripGateOnCmd) + stripCmd.AddCommand(stripEqCmd) stripEqCmd.AddCommand(stripEqOnCmd) + + stripCmd.AddCommand(stripCompCmd) + stripCompCmd.AddCommand(stripCompOnCmd) } diff --git a/internal/xair/comp.go b/internal/xair/comp.go index a62e85e..f98bec0 100644 --- a/internal/xair/comp.go +++ b/internal/xair/comp.go @@ -1,10 +1,13 @@ package xair +import "fmt" + type Comp struct { client *Client baseAddress string } +// Factory function to create Comp instance for Strip func newCompForStrip(c *Client) *Comp { return &Comp{ client: c, @@ -12,9 +15,36 @@ func newCompForStrip(c *Client) *Comp { } } +// Factory function to create Comp instance for Bus func newCompForBus(c *Client) *Comp { return &Comp{ client: c, baseAddress: c.addressMap["bus"], } } + +// On retrieves the on/off status of the Compressor for a specific strip or bus (1-based indexing). +func (c *Comp) On(index int) (bool, error) { + address := fmt.Sprintf(c.baseAddress, index) + "/dyn/on" + err := c.client.SendMessage(address) + if err != nil { + return false, err + } + + resp := <-c.client.respChan + val, ok := resp.Arguments[0].(int32) + if !ok { + return false, fmt.Errorf("unexpected argument type for Compressor on value") + } + return val != 0, nil +} + +// SetOn sets the on/off status of the Compressor for a specific strip or bus (1-based indexing). +func (c *Comp) SetOn(index int, on bool) error { + address := fmt.Sprintf(c.baseAddress, index) + "/dyn/on" + var value int32 + if on { + value = 1 + } + return c.client.SendMessage(address, value) +} diff --git a/internal/xair/eq.go b/internal/xair/eq.go index 28f8eb5..2b2e8b7 100644 --- a/internal/xair/eq.go +++ b/internal/xair/eq.go @@ -7,7 +7,7 @@ type Eq struct { baseAddress string } -// Helper function to create Eq instance for Strip +// Factory function to create Eq instance for Strip func newEqForStrip(c *Client) *Eq { return &Eq{ client: c, @@ -15,7 +15,7 @@ func newEqForStrip(c *Client) *Eq { } } -// Helper function to create Eq instance for Bus +// Factory function to create Eq instance for Bus func newEqForBus(c *Client) *Eq { return &Eq{ client: c, @@ -23,6 +23,7 @@ func newEqForBus(c *Client) *Eq { } } +// On retrieves the on/off status of the EQ for a specific strip or bus (1-based indexing). func (e *Eq) On(index int) (bool, error) { address := fmt.Sprintf(e.baseAddress, index) + "/eq/on" err := e.client.SendMessage(address) @@ -38,6 +39,7 @@ func (e *Eq) On(index int) (bool, error) { return val != 0, nil } +// SetOn sets the on/off status of the EQ for a specific strip or bus (1-based indexing). func (e *Eq) SetOn(index int, on bool) error { address := fmt.Sprintf(e.baseAddress, index) + "/eq/on" var value int32 diff --git a/internal/xair/gate.go b/internal/xair/gate.go index 4baec98..f1fce57 100644 --- a/internal/xair/gate.go +++ b/internal/xair/gate.go @@ -1,9 +1,38 @@ package xair +import "fmt" + type Gate struct { - client *Client + client *Client + baseAddress string } func newGate(c *Client) *Gate { - return &Gate{client: c} + return &Gate{client: c, baseAddress: c.addressMap["strip"]} +} + +// On retrieves the on/off status of the Gate for a specific strip (1-based indexing). +func (g *Gate) On(index int) (bool, error) { + address := fmt.Sprintf(g.baseAddress, index) + "/gate/on" + err := g.client.SendMessage(address) + if err != nil { + return false, err + } + + resp := <-g.client.respChan + val, ok := resp.Arguments[0].(int32) + if !ok { + return false, fmt.Errorf("unexpected argument type for Gate on value") + } + return val != 0, nil +} + +// SetOn sets the on/off status of the Gate for a specific strip (1-based indexing). +func (g *Gate) SetOn(index int, on bool) error { + address := fmt.Sprintf(g.baseAddress, index) + "/gate/on" + var value int32 + if on { + value = 1 + } + return g.client.SendMessage(address, value) }