From a0663350f83a8dc34d12303c344d9498e681a87d Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Sat, 31 Jan 2026 21:30:48 +0000 Subject: [PATCH] add strip send command --- cmd/strip.go | 69 ++++++++++++++++++++++++++++++++++++++---- internal/xair/strip.go | 22 ++++++++++++++ 2 files changed, 85 insertions(+), 6 deletions(-) diff --git a/cmd/strip.go b/cmd/strip.go index 39aec2b..71fe077 100644 --- a/cmd/strip.go +++ b/cmd/strip.go @@ -18,7 +18,7 @@ var stripCmd = &cobra.Command{ // stripMuteCmd represents the strip mute command. var stripMuteCmd = &cobra.Command{ - Use: "mute", + Use: "mute [strip number] [true|false]", Short: "Get or set the mute status of a strip", Long: `Get or set the mute status of a specific strip. @@ -85,7 +85,7 @@ For example: // stripFaderCmd represents the strip fader command. var stripFaderCmd = &cobra.Command{ - Use: "fader", + Use: "fader [strip number] [level in dB]", Short: "Get or set the fader level of a strip", Long: `Get or set the fader level of a specific strip. @@ -141,13 +141,13 @@ For example: // stripFadeOutCmd represents the strip fade out command. var stripFadeOutCmd = &cobra.Command{ - Use: "fadeout", + Use: "fadeout [strip number] --duration [seconds] [target level in dB]", Short: "Fade out the strip over a specified duration", Long: `Fade out the strip over a specified duration in seconds. For example: # Fade out strip 1 over 5 seconds - xair-cli strip fadeout 1 --duration 5.0 + xair-cli strip fadeout 1 --duration 5.0 -- -90.0 `, Run: func(cmd *cobra.Command, args []string) { client := ClientFromContext(cmd.Context()) @@ -204,13 +204,13 @@ For example: // stripFadeInCmd represents the strip fade in command. var stripFadeInCmd = &cobra.Command{ - Use: "fadein", + Use: "fadein [strip number] --duration [seconds] [target level in dB]", Short: "Fade in the strip over a specified duration", Long: `Fade in the strip over a specified duration in seconds. For example: # Fade in strip 1 over 5 seconds - xair-cli strip fadein 1 --duration 5.0 + xair-cli strip fadein 1 --duration 5.0 0 `, Run: func(cmd *cobra.Command, args []string) { client := ClientFromContext(cmd.Context()) @@ -265,6 +265,61 @@ For example: }, } +// stripSendCmd represents the strip send command. +var stripSendCmd = &cobra.Command{ + Use: "send [strip number] [bus number] [level in dB]", + Short: "Commands to get or set strip send levels", + Long: `Commands to get or set the send levels for individual strips. + +For example: + # Get the send level of strip 1 to bus 1 + xair-cli strip send 1 1 + + # Set the send level of strip 1 to bus 1 to -5.0 dB + xair-cli strip send 1 1 -- -5.0 +`, + Run: func(cmd *cobra.Command, args []string) { + client := ClientFromContext(cmd.Context()) + if client == nil { + cmd.PrintErrln("OSC client not found in context") + return + } + + if len(args) < 2 { + cmd.PrintErrln("Please provide strip number and bus number") + return + } + + stripIndex, busIndex := func() (int, int) { + return mustConvToInt(args[0]), mustConvToInt(args[1]) + }() + + if len(args) == 2 { + currentLevel, err := client.Strip.SendLevel(stripIndex, busIndex) + if err != nil { + cmd.PrintErrln("Error getting strip send level:", err) + return + } + cmd.Printf("Strip %d send level to bus %d: %.2f dB\n", stripIndex, busIndex, currentLevel) + return + } + + if len(args) < 3 { + cmd.PrintErrln("Please provide a send level in dB") + return + } + + level := mustConvToFloat64(args[2]) + + err := client.Strip.SetSendLevel(stripIndex, busIndex, level) + if err != nil { + cmd.PrintErrln("Error setting strip send level:", err) + return + } + cmd.Printf("Strip %d send level to bus %d set to %.2f dB\n", stripIndex, busIndex, level) + }, +} + func init() { rootCmd.AddCommand(stripCmd) @@ -275,4 +330,6 @@ func init() { stripFadeOutCmd.Flags().Float64P("duration", "d", 5.0, "Duration of the fade out in seconds") stripCmd.AddCommand(stripFadeInCmd) stripFadeInCmd.Flags().Float64P("duration", "d", 5.0, "Duration of the fade in in seconds") + + stripCmd.AddCommand(stripSendCmd) } diff --git a/internal/xair/strip.go b/internal/xair/strip.go index 648a55d..43af7b2 100644 --- a/internal/xair/strip.go +++ b/internal/xair/strip.go @@ -126,3 +126,25 @@ func (s *Strip) SetColor(strip int, color int32) error { address := fmt.Sprintf("/ch/%02d/config/color", strip) return s.client.SendMessage(address, color) } + +// Sends requests the sends level for a mixbus. +func (s *Strip) SendLevel(strip int, bus int) (float64, error) { + address := fmt.Sprintf("/ch/%02d/mix/%02d/level", strip, bus) + err := s.client.SendMessage(address) + if err != nil { + return 0, fmt.Errorf("failed to send strip send level request: %v", err) + } + + resp := <-s.client.respChan + val, ok := resp.Arguments[0].(float32) + if !ok { + return 0, fmt.Errorf("unexpected argument type for strip send level value") + } + return mustDbFrom(float64(val)), nil +} + +// SetSendLevel sets the sends level for a mixbus. +func (s *Strip) SetSendLevel(strip int, bus int, level float64) error { + address := fmt.Sprintf("/ch/%02d/mix/%02d/level", strip, bus) + return s.client.SendMessage(address, float32(mustDbInto(level))) +}