From d894cc131700e9542236648ae5df3f4e00dcd4f4 Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Sun, 1 Feb 2026 00:50:24 +0000 Subject: [PATCH] add strip/bus name commands --- cmd/bus.go | 46 ++++++++++++++++++++++++++++++++++++++++ cmd/strip.go | 50 ++++++++++++++++++++++++++++++++++++++++++++ internal/xair/bus.go | 37 +++++++++++++++++++++++++------- 3 files changed, 125 insertions(+), 8 deletions(-) diff --git a/cmd/bus.go b/cmd/bus.go index be58048..9ba6914 100644 --- a/cmd/bus.go +++ b/cmd/bus.go @@ -223,6 +223,50 @@ var busFadeInCmd = &cobra.Command{ }, } +// 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`, + 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) < 1 { + cmd.PrintErrln("Please provide bus number") + return + } + + busIndex := mustConvToInt(args[0]) + + if len(args) == 1 { + name, err := client.Bus.Name(busIndex) + if err != nil { + cmd.PrintErrln("Error getting bus name:", err) + return + } + cmd.Printf("Bus %d name: %s\n", busIndex, name) + return + } + + newName := args[1] + err := client.Bus.SetName(busIndex, newName) + if err != nil { + cmd.PrintErrln("Error setting bus name:", err) + return + } + cmd.Printf("Bus %d name set to: %s\n", busIndex, newName) + }, +} + func init() { rootCmd.AddCommand(busCmd) @@ -233,4 +277,6 @@ func init() { busFadeOutCmd.Flags().Float64P("duration", "d", 5.0, "Duration for fade out in seconds") busCmd.AddCommand(busFadeInCmd) busFadeInCmd.Flags().Float64P("duration", "d", 5.0, "Duration for fade in in seconds") + + busCmd.AddCommand(busNameCmd) } diff --git a/cmd/strip.go b/cmd/strip.go index 53aaccc..9fd7213 100644 --- a/cmd/strip.go +++ b/cmd/strip.go @@ -305,6 +305,54 @@ var stripSendCmd = &cobra.Command{ }, } +// stripNameCmd represents the strip name command. +var stripNameCmd = &cobra.Command{ + Short: "Get or set the name of a strip", + Long: `Get or set the name of a specific strip. + +If no name argument is provided, the current strip name is retrieved. +If a name argument is provided, the strip name is set to that value.`, + Use: "name [strip number] [name]", + Example: ` # Get the current name of strip 1 + xair-cli strip name 1 + + # Set the name of strip 1 to "Guitar" + xair-cli strip name 1 "Guitar"`, + 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) < 1 { + cmd.PrintErrln("Please provide a strip number") + return + } + + stripIndex := mustConvToInt(args[0]) + + if len(args) == 1 { + name, err := client.Strip.Name(stripIndex) + if err != nil { + cmd.PrintErrln("Error getting strip name:", err) + return + } + cmd.Printf("Strip %d name: %s\n", stripIndex, name) + return + } + + name := args[1] + + err := client.Strip.SetName(stripIndex, name) + if err != nil { + cmd.PrintErrln("Error setting strip name:", err) + return + } + cmd.Printf("Strip %d name set to: %s\n", stripIndex, name) + }, +} + func init() { rootCmd.AddCommand(stripCmd) @@ -317,4 +365,6 @@ func init() { stripFadeInCmd.Flags().Float64P("duration", "d", 5.0, "Duration of the fade in in seconds") stripCmd.AddCommand(stripSendCmd) + + stripCmd.AddCommand(stripNameCmd) } diff --git a/internal/xair/bus.go b/internal/xair/bus.go index 8ffe34f..f166412 100644 --- a/internal/xair/bus.go +++ b/internal/xair/bus.go @@ -3,12 +3,14 @@ package xair import "fmt" type Bus struct { - client Client + baseAddress string + client Client } func NewBus(c Client) *Bus { return &Bus{ - client: c, + baseAddress: c.addressMap["bus"], + client: c, } } @@ -31,8 +33,7 @@ func (b *Bus) Mute(bus int) (bool, error) { // SetMute sets the mute status for a specific bus (1-based indexing) func (b *Bus) SetMute(bus int, muted bool) error { - formatter := b.client.addressMap["bus"] - address := fmt.Sprintf(formatter, bus) + "/mix/on" + address := fmt.Sprintf(b.baseAddress, bus) + "/mix/on" var value int32 if !muted { value = 1 @@ -42,8 +43,7 @@ func (b *Bus) SetMute(bus int, muted bool) error { // Fader requests the current fader level for a bus func (b *Bus) Fader(bus int) (float64, error) { - formatter := b.client.addressMap["bus"] - address := fmt.Sprintf(formatter, bus) + "/mix/fader" + address := fmt.Sprintf(b.baseAddress, bus) + "/mix/fader" err := b.client.SendMessage(address) if err != nil { return 0, err @@ -60,7 +60,28 @@ func (b *Bus) Fader(bus int) (float64, error) { // SetFader sets the fader level for a specific bus (1-based indexing) func (b *Bus) SetFader(bus int, level float64) error { - formatter := b.client.addressMap["bus"] - address := fmt.Sprintf(formatter, bus) + "/mix/fader" + address := fmt.Sprintf(b.baseAddress, bus) + "/mix/fader" return b.client.SendMessage(address, float32(mustDbInto(level))) } + +// Name requests the name for a specific bus +func (b *Bus) Name(bus int) (string, error) { + address := fmt.Sprintf(b.baseAddress, bus) + "/config/name" + err := b.client.SendMessage(address) + if err != nil { + return "", fmt.Errorf("failed to send bus name request: %v", err) + } + + resp := <-b.client.respChan + val, ok := resp.Arguments[0].(string) + if !ok { + return "", fmt.Errorf("unexpected argument type for bus name value") + } + return val, nil +} + +// SetName sets the name for a specific bus +func (b *Bus) SetName(bus int, name string) error { + address := fmt.Sprintf(b.baseAddress, bus) + "/config/name" + return b.client.SendMessage(address, name) +}