diff --git a/cmd/bus.go b/cmd/bus.go index 0c4feed..4f510a6 100644 --- a/cmd/bus.go +++ b/cmd/bus.go @@ -568,6 +568,47 @@ var busCompOnCmd = &cobra.Command{ }, } +// busCompModeCmd represents the bus Compressor mode command. +var busCompModeCmd = &cobra.Command{ + Short: "Get or set the bus Compressor mode", + Long: `Get or set the Compressor 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]) + + if len(args) == 1 { + mode, err := client.Bus.Comp.Mode(busIndex) + if err != nil { + return fmt.Errorf("Error getting bus Compressor mode: %w", err) + } + cmd.Printf("Bus %d Compressor mode: %s\n", busIndex, mode) + return nil + } + + mode := args[1] + if !contains([]string{"comp", "exp"}, mode) { + return fmt.Errorf("Invalid mode value. Valid values are: comp, exp") + } + + err := client.Bus.Comp.SetMode(busIndex, mode) + if err != nil { + return fmt.Errorf("Error setting bus Compressor mode: %w", err) + } + + cmd.Printf("Bus %d Compressor mode set to %s\n", busIndex, mode) + return nil + }, +} + // busCompThresholdCmd represents the bus Compressor threshold command. var busCompThresholdCmd = &cobra.Command{ Short: "Get or set the bus Compressor threshold", @@ -883,6 +924,7 @@ func init() { busCmd.AddCommand(busCompCmd) busCompCmd.AddCommand(busCompOnCmd) + busCompCmd.AddCommand(busCompModeCmd) busCompCmd.AddCommand(busCompThresholdCmd) busCompCmd.AddCommand(busCompRatioCmd) busCompCmd.AddCommand(busCompMixCmd) diff --git a/internal/xair/comp.go b/internal/xair/comp.go index 1490075..94c59c9 100644 --- a/internal/xair/comp.go +++ b/internal/xair/comp.go @@ -49,6 +49,31 @@ func (c *Comp) SetOn(index int, on bool) error { return c.client.SendMessage(address, value) } +// Mode retrieves the current mode of the Compressor for a specific strip or bus (1-based indexing). +func (c *Comp) Mode(index int) (string, error) { + address := fmt.Sprintf(c.baseAddress, index) + "/dyn/mode" + err := c.client.SendMessage(address) + if err != nil { + return "", err + } + + possibleModes := []string{"comp", "exp"} + + resp := <-c.client.respChan + val, ok := resp.Arguments[0].(int32) + if !ok { + return "", fmt.Errorf("unexpected argument type for Compressor mode value") + } + return possibleModes[val], nil +} + +// SetMode sets the mode of the Compressor for a specific strip or bus (1-based indexing). +func (c *Comp) SetMode(index int, mode string) error { + address := fmt.Sprintf(c.baseAddress, index) + "/dyn/mode" + possibleModes := []string{"comp", "exp"} + return c.client.SendMessage(address, int32(indexOf(possibleModes, mode))) +} + // Threshold retrieves the threshold value of the Compressor for a specific strip or bus (1-based indexing). func (c *Comp) Threshold(index int) (float64, error) { address := fmt.Sprintf(c.baseAddress, index) + "/dyn/thr"