From b39dc86236128f9009803cce173ca086aef20daa Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Wed, 4 Feb 2026 10:44:06 +0000 Subject: [PATCH] add raw command for sending raw OSC messages --- README.md | 1 + cmd/raw.go | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 cmd/raw.go diff --git a/README.md b/README.md index d3bf820..4ceb132 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,7 @@ Available Commands: headamp Commands to control headamp gain and phantom power help Help about any command main Commands to control the main output + raw Send a raw OSC message to the mixer strip Commands to control individual strips Flags: diff --git a/cmd/raw.go b/cmd/raw.go new file mode 100644 index 0000000..a47547c --- /dev/null +++ b/cmd/raw.go @@ -0,0 +1,58 @@ +package cmd + +import ( + "fmt" + "time" + + "github.com/spf13/cobra" +) + +// rawCmd represents the raw command +var rawCmd = &cobra.Command{ + Short: "Send a raw OSC message to the mixer", + Long: `Send a raw OSC message to the mixer. +You need to provide the OSC address and any parameters as arguments. + +Provide a timeout duration to wait for a response from the mixer.`, + Use: "raw", + Example: ` xair-cli raw /xinfo + xair-cli raw /ch/01/mix/fader 0.75 + xair-cli raw --timeout 500ms /bus/02/mix/on 1`, + Args: cobra.MinimumNArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + client := ClientFromContext(cmd.Context()) + if client == nil { + return fmt.Errorf("no client found in context") + } + + command := args[0] + params := make([]any, len(args[1:])) + for i, arg := range args[1:] { + params[i] = arg + } + if err := client.SendMessage(command, params...); err != nil { + return fmt.Errorf("error sending message: %v", err) + } + + timeout, err := cmd.Flags().GetDuration("timeout") + if err != nil { + return fmt.Errorf("error getting timeout flag: %v", err) + } + + msg, err := client.ReceiveMessage(timeout) + if err != nil { + return fmt.Errorf("error receiving message: %v", err) + } + + if msg != nil { + fmt.Printf("Received response: %v\n", msg) + } + return nil + }, +} + +func init() { + rootCmd.AddCommand(rawCmd) + + rawCmd.Flags().DurationP("timeout", "t", 200*time.Millisecond, "Timeout duration for receiving a response") +}