mirror of
https://github.com/onyx-and-iris/xair-cli.git
synced 2026-02-03 23:17:47 +00:00
use RunE throughout
This commit is contained in:
parent
0b72556b7e
commit
08b232dcbf
93
cmd/bus.go
93
cmd/bus.go
@ -1,6 +1,7 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
@ -21,16 +22,14 @@ var busMuteCmd = &cobra.Command{
|
||||
Short: "Get or set the bus mute status",
|
||||
Long: `Get or set the mute status of a specific bus.`,
|
||||
Use: "mute [bus number] [true|false]",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
client := ClientFromContext(cmd.Context())
|
||||
if client == nil {
|
||||
cmd.PrintErrln("OSC client not found in context")
|
||||
return
|
||||
return fmt.Errorf("OSC client not found in context")
|
||||
}
|
||||
|
||||
if len(args) < 2 {
|
||||
cmd.PrintErrln("Please provide bus number and mute status (true/false)")
|
||||
return
|
||||
return fmt.Errorf("Please provide bus number and mute status (true/false)")
|
||||
}
|
||||
|
||||
busNum := mustConvToInt(args[0])
|
||||
@ -41,16 +40,16 @@ var busMuteCmd = &cobra.Command{
|
||||
case "false", "0":
|
||||
muted = false
|
||||
default:
|
||||
cmd.PrintErrln("Invalid mute status. Use true/false or 1/0")
|
||||
return
|
||||
return fmt.Errorf("Invalid mute status. Use true/false or 1/0")
|
||||
}
|
||||
|
||||
err := client.Bus.SetMute(busNum, muted)
|
||||
if err != nil {
|
||||
cmd.PrintErrln("Error setting bus mute status:", err)
|
||||
return
|
||||
return fmt.Errorf("Error setting bus mute status: %w", err)
|
||||
}
|
||||
|
||||
cmd.Printf("Bus %d mute set to %v\n", busNum, muted)
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
@ -66,11 +65,10 @@ If a level argument (in dB) is provided, the bus fader is set to that level.`,
|
||||
|
||||
# Set the fader level of bus 1 to -10.0 dB
|
||||
xair-cli bus fader 1 -10.0`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
client := ClientFromContext(cmd.Context())
|
||||
if client == nil {
|
||||
cmd.PrintErrln("OSC client not found in context")
|
||||
return
|
||||
return fmt.Errorf("OSC client not found in context")
|
||||
}
|
||||
|
||||
busIndex := mustConvToInt(args[0])
|
||||
@ -78,26 +76,25 @@ If a level argument (in dB) is provided, the bus fader is set to that level.`,
|
||||
if len(args) == 1 {
|
||||
level, err := client.Bus.Fader(busIndex)
|
||||
if err != nil {
|
||||
cmd.PrintErrln("Error getting bus fader level:", err)
|
||||
return
|
||||
return fmt.Errorf("Error getting bus fader level: %w", err)
|
||||
}
|
||||
cmd.Printf("Bus %d fader level: %.1f dB\n", busIndex, level)
|
||||
return
|
||||
return nil
|
||||
}
|
||||
|
||||
if len(args) < 2 {
|
||||
cmd.PrintErrln("Please provide bus number and fader level (in dB)")
|
||||
return
|
||||
return fmt.Errorf("Please provide bus number and fader level (in dB)")
|
||||
}
|
||||
|
||||
level := mustConvToFloat64(args[1])
|
||||
|
||||
err := client.Bus.SetFader(busIndex, level)
|
||||
if err != nil {
|
||||
cmd.PrintErrln("Error setting bus fader level:", err)
|
||||
return
|
||||
return fmt.Errorf("Error setting bus fader level: %w", err)
|
||||
}
|
||||
|
||||
cmd.Printf("Bus %d fader set to %.2f dB\n", busIndex, level)
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
@ -108,24 +105,21 @@ var busFadeOutCmd = &cobra.Command{
|
||||
Use: "fadeout [bus number] --duration [seconds] [target level in dB]",
|
||||
Example: ` # Fade out bus 1 over 5 seconds
|
||||
xair-cli bus fadeout 1 --duration 5 -- -90.0`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
client := ClientFromContext(cmd.Context())
|
||||
if client == nil {
|
||||
cmd.PrintErrln("OSC client not found in context")
|
||||
return
|
||||
return fmt.Errorf("OSC client not found in context")
|
||||
}
|
||||
|
||||
if len(args) < 1 {
|
||||
cmd.PrintErrln("Please provide bus number")
|
||||
return
|
||||
return fmt.Errorf("Please provide bus number")
|
||||
}
|
||||
|
||||
busIndex := mustConvToInt(args[0])
|
||||
|
||||
duration, err := cmd.Flags().GetFloat64("duration")
|
||||
if err != nil {
|
||||
cmd.PrintErrln("Error getting duration flag:", err)
|
||||
return
|
||||
return fmt.Errorf("Error getting duration flag: %w", err)
|
||||
}
|
||||
|
||||
target := -90.0
|
||||
@ -135,15 +129,14 @@ var busFadeOutCmd = &cobra.Command{
|
||||
|
||||
currentFader, err := client.Bus.Fader(busIndex)
|
||||
if err != nil {
|
||||
cmd.PrintErrln("Error getting current bus fader level:", err)
|
||||
return
|
||||
return fmt.Errorf("Error getting current bus fader level: %w", err)
|
||||
}
|
||||
|
||||
// Calculate total steps needed to reach target dB
|
||||
totalSteps := float64(currentFader - target)
|
||||
if totalSteps <= 0 {
|
||||
cmd.Println("Bus is already at or below target level")
|
||||
return
|
||||
return nil
|
||||
}
|
||||
|
||||
stepDelay := time.Duration(duration*1000/totalSteps) * time.Millisecond
|
||||
@ -152,13 +145,13 @@ var busFadeOutCmd = &cobra.Command{
|
||||
currentFader -= 1.0
|
||||
err := client.Bus.SetFader(busIndex, currentFader)
|
||||
if err != nil {
|
||||
cmd.PrintErrln("Error setting bus fader level:", err)
|
||||
return
|
||||
return fmt.Errorf("Error setting bus fader level: %w", err)
|
||||
}
|
||||
time.Sleep(stepDelay)
|
||||
}
|
||||
|
||||
cmd.Println("Bus fade out completed")
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
@ -169,24 +162,21 @@ var busFadeInCmd = &cobra.Command{
|
||||
Use: "fadein [bus number] --duration [seconds] [target level in dB]",
|
||||
Example: ` # Fade in bus 1 over 5 seconds
|
||||
xair-cli bus fadein 1 --duration 5 -- 0.0`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
client := ClientFromContext(cmd.Context())
|
||||
if client == nil {
|
||||
cmd.PrintErrln("OSC client not found in context")
|
||||
return
|
||||
return fmt.Errorf("OSC client not found in context")
|
||||
}
|
||||
|
||||
if len(args) < 1 {
|
||||
cmd.PrintErrln("Please provide bus number")
|
||||
return
|
||||
return fmt.Errorf("Please provide bus number")
|
||||
}
|
||||
|
||||
busIndex := mustConvToInt(args[0])
|
||||
|
||||
duration, err := cmd.Flags().GetFloat64("duration")
|
||||
if err != nil {
|
||||
cmd.PrintErrln("Error getting duration flag:", err)
|
||||
return
|
||||
return fmt.Errorf("Error getting duration flag: %w", err)
|
||||
}
|
||||
|
||||
target := 0.0
|
||||
@ -196,15 +186,14 @@ var busFadeInCmd = &cobra.Command{
|
||||
|
||||
currentFader, err := client.Bus.Fader(busIndex)
|
||||
if err != nil {
|
||||
cmd.PrintErrln("Error getting current bus fader level:", err)
|
||||
return
|
||||
return fmt.Errorf("Error getting current bus fader level: %w", err)
|
||||
}
|
||||
|
||||
// Calculate total steps needed to reach target dB
|
||||
totalSteps := float64(target - currentFader)
|
||||
if totalSteps <= 0 {
|
||||
cmd.Println("Bus is already at or above target level")
|
||||
return
|
||||
return nil
|
||||
}
|
||||
|
||||
stepDelay := time.Duration(duration*1000/totalSteps) * time.Millisecond
|
||||
@ -213,13 +202,13 @@ var busFadeInCmd = &cobra.Command{
|
||||
currentFader += 1.0
|
||||
err := client.Bus.SetFader(busIndex, currentFader)
|
||||
if err != nil {
|
||||
cmd.PrintErrln("Error setting bus fader level:", err)
|
||||
return
|
||||
return fmt.Errorf("Error setting bus fader level: %w", err)
|
||||
}
|
||||
time.Sleep(stepDelay)
|
||||
}
|
||||
|
||||
cmd.Println("Bus fade in completed")
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
@ -233,16 +222,14 @@ var busNameCmd = &cobra.Command{
|
||||
|
||||
# Set the name of bus 1 to "Vocals"
|
||||
xair-cli bus name 1 Vocals`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
client := ClientFromContext(cmd.Context())
|
||||
if client == nil {
|
||||
cmd.PrintErrln("OSC client not found in context")
|
||||
return
|
||||
return fmt.Errorf("OSC client not found in context")
|
||||
}
|
||||
|
||||
if len(args) < 1 {
|
||||
cmd.PrintErrln("Please provide bus number")
|
||||
return
|
||||
return fmt.Errorf("Please provide bus number")
|
||||
}
|
||||
|
||||
busIndex := mustConvToInt(args[0])
|
||||
@ -250,20 +237,20 @@ var busNameCmd = &cobra.Command{
|
||||
if len(args) == 1 {
|
||||
name, err := client.Bus.Name(busIndex)
|
||||
if err != nil {
|
||||
cmd.PrintErrln("Error getting bus name:", err)
|
||||
return
|
||||
return fmt.Errorf("Error getting bus name: %w", err)
|
||||
}
|
||||
cmd.Printf("Bus %d name: %s\n", busIndex, name)
|
||||
return
|
||||
return nil
|
||||
}
|
||||
|
||||
newName := args[1]
|
||||
err := client.Bus.SetName(busIndex, newName)
|
||||
if err != nil {
|
||||
cmd.PrintErrln("Error setting bus name:", err)
|
||||
return
|
||||
return fmt.Errorf("Error setting bus name: %w", err)
|
||||
}
|
||||
|
||||
cmd.Printf("Bus %d name set to: %s\n", busIndex, newName)
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
@ -28,16 +30,14 @@ Examples:
|
||||
# Set gain level for headamp index 1 to 3.5 dB
|
||||
xairctl headamp gain 1 3.5`,
|
||||
Args: cobra.RangeArgs(1, 2),
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
client := ClientFromContext(cmd.Context())
|
||||
if client == nil {
|
||||
cmd.PrintErrln("OSC client not found in context")
|
||||
return
|
||||
return fmt.Errorf("OSC client not found in context")
|
||||
}
|
||||
|
||||
if len(args) < 1 {
|
||||
cmd.PrintErrln("Please provide a headamp index")
|
||||
return
|
||||
return fmt.Errorf("Please provide a headamp index")
|
||||
}
|
||||
|
||||
index := mustConvToInt(args[0])
|
||||
@ -45,26 +45,25 @@ Examples:
|
||||
if len(args) == 1 {
|
||||
gain, err := client.HeadAmp.Gain(index)
|
||||
if err != nil {
|
||||
cmd.PrintErrln("Error getting headamp gain level:", err)
|
||||
return
|
||||
return fmt.Errorf("Error getting headamp gain level: %w", err)
|
||||
}
|
||||
cmd.Printf("Headamp %d Gain: %.2f dB\n", index, gain)
|
||||
return
|
||||
return nil
|
||||
}
|
||||
|
||||
if len(args) < 2 {
|
||||
cmd.PrintErrln("Please provide a gain level in dB")
|
||||
return
|
||||
return fmt.Errorf("Please provide a gain level in dB")
|
||||
}
|
||||
|
||||
level := mustConvToFloat64(args[1])
|
||||
|
||||
err := client.HeadAmp.SetGain(index, level)
|
||||
if err != nil {
|
||||
cmd.PrintErrln("Error setting headamp gain level:", err)
|
||||
return
|
||||
return fmt.Errorf("Error setting headamp gain level: %w", err)
|
||||
}
|
||||
|
||||
cmd.Printf("Headamp %d Gain set to %.2f dB\n", index, level)
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
@ -81,16 +80,14 @@ Examples:
|
||||
# Disable phantom power for headamp index 1
|
||||
xairctl headamp phantom 1 off`,
|
||||
Args: cobra.RangeArgs(1, 2),
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
client := ClientFromContext(cmd.Context())
|
||||
if client == nil {
|
||||
cmd.PrintErrln("OSC client not found in context")
|
||||
return
|
||||
return fmt.Errorf("OSC client not found in context")
|
||||
}
|
||||
|
||||
if len(args) < 1 {
|
||||
cmd.PrintErrln("Please provide a headamp index")
|
||||
return
|
||||
return fmt.Errorf("Please provide a headamp index")
|
||||
}
|
||||
|
||||
index := mustConvToInt(args[0])
|
||||
@ -98,20 +95,18 @@ Examples:
|
||||
if len(args) == 1 {
|
||||
enabled, err := client.HeadAmp.PhantomPower(index)
|
||||
if err != nil {
|
||||
cmd.PrintErrln("Error getting headamp phantom power status:", err)
|
||||
return
|
||||
return fmt.Errorf("Error getting headamp phantom power status: %w", err)
|
||||
}
|
||||
status := "disabled"
|
||||
if enabled {
|
||||
status = "enabled"
|
||||
}
|
||||
cmd.Printf("Headamp %d Phantom Power is %s\n", index, status)
|
||||
return
|
||||
return nil
|
||||
}
|
||||
|
||||
if len(args) < 2 {
|
||||
cmd.PrintErrln("Please provide phantom power status: on or off")
|
||||
return
|
||||
return fmt.Errorf("Please provide phantom power status: on or off")
|
||||
}
|
||||
|
||||
var enable bool
|
||||
@ -121,20 +116,20 @@ Examples:
|
||||
case "off", "disable":
|
||||
enable = false
|
||||
default:
|
||||
cmd.PrintErrln("Invalid phantom power status. Use 'on' or 'off'")
|
||||
return
|
||||
return fmt.Errorf("Invalid phantom power status. Use 'on' or 'off'")
|
||||
}
|
||||
|
||||
err := client.HeadAmp.SetPhantomPower(index, enable)
|
||||
if err != nil {
|
||||
cmd.PrintErrln("Error setting headamp phantom power status:", err)
|
||||
return
|
||||
return fmt.Errorf("Error setting headamp phantom power status: %w", err)
|
||||
}
|
||||
status := "disabled"
|
||||
if enable {
|
||||
status = "enabled"
|
||||
}
|
||||
|
||||
cmd.Printf("Headamp %d Phantom Power %s successfully\n", index, status)
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
36
cmd/main.go
36
cmd/main.go
@ -1,6 +1,7 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
@ -33,21 +34,19 @@ If "false" or "0" is provided, the main output is unmuted.`,
|
||||
|
||||
# Unmute the main output
|
||||
xair-cli main mute false`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
client := ClientFromContext(cmd.Context())
|
||||
if client == nil {
|
||||
cmd.PrintErrln("OSC client not found in context")
|
||||
return
|
||||
return fmt.Errorf("OSC client not found in context")
|
||||
}
|
||||
|
||||
if len(args) == 0 {
|
||||
resp, err := client.Main.Mute()
|
||||
if err != nil {
|
||||
cmd.PrintErrln("Error getting main LR mute status:", err)
|
||||
return
|
||||
return fmt.Errorf("Error getting main LR mute status: %w", err)
|
||||
}
|
||||
cmd.Printf("Main LR mute: %v\n", resp)
|
||||
return
|
||||
return nil
|
||||
}
|
||||
|
||||
var muted bool
|
||||
@ -57,16 +56,16 @@ If "false" or "0" is provided, the main output is unmuted.`,
|
||||
case "false", "0":
|
||||
muted = false
|
||||
default:
|
||||
cmd.PrintErrln("Invalid mute status. Use true/false or 1/0")
|
||||
return
|
||||
return fmt.Errorf("Invalid mute status. Use true/false or 1/0")
|
||||
}
|
||||
|
||||
err := client.Main.SetMute(muted)
|
||||
if err != nil {
|
||||
cmd.PrintErrln("Error setting main LR mute status:", err)
|
||||
return
|
||||
return fmt.Errorf("Error setting main LR mute status: %w", err)
|
||||
}
|
||||
|
||||
cmd.Println("Main LR mute status set successfully")
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
@ -83,29 +82,28 @@ If a dB value is provided as an argument, the fader level is set to that value.`
|
||||
|
||||
# Set the main LR fader level to -10.0 dB
|
||||
xair-cli main fader -- -10.0`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
client := ClientFromContext(cmd.Context())
|
||||
if client == nil {
|
||||
cmd.PrintErrln("OSC client not found in context")
|
||||
return
|
||||
return fmt.Errorf("OSC client not found in context")
|
||||
}
|
||||
|
||||
if len(args) == 0 {
|
||||
resp, err := client.Main.Fader()
|
||||
if err != nil {
|
||||
cmd.PrintErrln("Error getting main LR fader:", err)
|
||||
return
|
||||
return fmt.Errorf("Error getting main LR fader: %w", err)
|
||||
}
|
||||
cmd.Printf("Main LR fader: %.1f dB\n", resp)
|
||||
return
|
||||
return nil
|
||||
}
|
||||
|
||||
err := client.Main.SetFader(mustConvToFloat64(args[0]))
|
||||
if err != nil {
|
||||
cmd.PrintErrln("Error setting main LR fader:", err)
|
||||
return
|
||||
return fmt.Errorf("Error setting main LR fader: %w", err)
|
||||
}
|
||||
|
||||
cmd.Println("Main LR fader set successfully")
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
@ -163,6 +161,7 @@ This command will fade out the main output to the specified dB level.
|
||||
}
|
||||
time.Sleep(stepDelay)
|
||||
}
|
||||
|
||||
cmd.Println("Main output faded out successfully")
|
||||
},
|
||||
}
|
||||
@ -220,6 +219,7 @@ This command will fade in the main output to the specified dB level.
|
||||
}
|
||||
time.Sleep(stepDelay)
|
||||
}
|
||||
|
||||
cmd.Println("Main output faded in successfully")
|
||||
},
|
||||
}
|
||||
|
||||
120
cmd/strip.go
120
cmd/strip.go
@ -1,6 +1,7 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
@ -32,16 +33,14 @@ If "false" or "0" is provided, the strip is unmuted.`,
|
||||
xair-cli strip mute 1 true
|
||||
# Unmute strip 1
|
||||
xair-cli strip mute 1 false`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
client := ClientFromContext(cmd.Context())
|
||||
if client == nil {
|
||||
cmd.PrintErrln("OSC client not found in context")
|
||||
return
|
||||
return fmt.Errorf("OSC client not found in context")
|
||||
}
|
||||
|
||||
if len(args) < 1 {
|
||||
cmd.PrintErrln("Please provide a strip number")
|
||||
return
|
||||
return fmt.Errorf("Please provide a strip number")
|
||||
}
|
||||
|
||||
stripIndex := mustConvToInt(args[0])
|
||||
@ -49,11 +48,10 @@ If "false" or "0" is provided, the strip is unmuted.`,
|
||||
if len(args) == 1 {
|
||||
resp, err := client.Strip.Mute(stripIndex)
|
||||
if err != nil {
|
||||
cmd.PrintErrln("Error getting strip mute status:", err)
|
||||
return
|
||||
return fmt.Errorf("Error getting strip mute status: %w", err)
|
||||
}
|
||||
cmd.Printf("Strip %d mute: %v\n", stripIndex, resp)
|
||||
return
|
||||
return nil
|
||||
}
|
||||
|
||||
var muted bool
|
||||
@ -63,20 +61,20 @@ If "false" or "0" is provided, the strip is unmuted.`,
|
||||
case "false", "0":
|
||||
muted = false
|
||||
default:
|
||||
cmd.PrintErrln("Invalid mute status. Use true/false or 1/0")
|
||||
return
|
||||
return fmt.Errorf("Invalid mute status. Use true/false or 1/0")
|
||||
}
|
||||
|
||||
err := client.Strip.SetMute(stripIndex, muted)
|
||||
if err != nil {
|
||||
cmd.PrintErrln("Error setting strip mute status:", err)
|
||||
return
|
||||
return fmt.Errorf("Error setting strip mute status: %w", err)
|
||||
}
|
||||
|
||||
if muted {
|
||||
cmd.Printf("Strip %d muted successfully\n", stripIndex)
|
||||
} else {
|
||||
cmd.Printf("Strip %d unmuted successfully\n", stripIndex)
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
@ -93,16 +91,14 @@ If a level argument (in dB) is provided, the strip fader is set to that level.`,
|
||||
|
||||
# Set the fader level of strip 1 to -10.0 dB
|
||||
xair-cli strip fader 1 -10.0`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
client := ClientFromContext(cmd.Context())
|
||||
if client == nil {
|
||||
cmd.PrintErrln("OSC client not found in context")
|
||||
return
|
||||
return fmt.Errorf("OSC client not found in context")
|
||||
}
|
||||
|
||||
if len(args) < 1 {
|
||||
cmd.PrintErrln("Please provide a strip number")
|
||||
return
|
||||
return fmt.Errorf("Please provide a strip number")
|
||||
}
|
||||
|
||||
stripIndex := mustConvToInt(args[0])
|
||||
@ -110,26 +106,25 @@ If a level argument (in dB) is provided, the strip fader is set to that level.`,
|
||||
if len(args) == 1 {
|
||||
level, err := client.Strip.Fader(stripIndex)
|
||||
if err != nil {
|
||||
cmd.PrintErrln("Error getting strip fader level:", err)
|
||||
return
|
||||
return fmt.Errorf("Error getting strip fader level: %w", err)
|
||||
}
|
||||
cmd.Printf("Strip %d fader level: %.2f\n", stripIndex, level)
|
||||
return
|
||||
return nil
|
||||
}
|
||||
|
||||
if len(args) < 2 {
|
||||
cmd.PrintErrln("Please provide a fader level in dB")
|
||||
return
|
||||
return fmt.Errorf("Please provide a fader level in dB")
|
||||
}
|
||||
|
||||
level := mustConvToFloat64(args[1])
|
||||
|
||||
err := client.Strip.SetFader(stripIndex, level)
|
||||
if err != nil {
|
||||
cmd.PrintErrln("Error setting strip fader level:", err)
|
||||
return
|
||||
return fmt.Errorf("Error setting strip fader level: %w", err)
|
||||
}
|
||||
|
||||
cmd.Printf("Strip %d fader set to %.2f dB\n", stripIndex, level)
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
@ -140,24 +135,21 @@ var stripFadeOutCmd = &cobra.Command{
|
||||
Use: "fadeout [strip number] --duration [seconds] [target level in dB]",
|
||||
Example: ` # Fade out strip 1 over 5 seconds
|
||||
xair-cli strip fadeout 1 --duration 5.0 -- -90.0`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
client := ClientFromContext(cmd.Context())
|
||||
if client == nil {
|
||||
cmd.PrintErrln("OSC client not found in context")
|
||||
return
|
||||
return fmt.Errorf("OSC client not found in context")
|
||||
}
|
||||
|
||||
if len(args) < 1 {
|
||||
cmd.PrintErrln("Please provide strip number")
|
||||
return
|
||||
return fmt.Errorf("Please provide strip number")
|
||||
}
|
||||
|
||||
stripIndex := mustConvToInt(args[0])
|
||||
|
||||
duration, err := cmd.Flags().GetFloat64("duration")
|
||||
if err != nil {
|
||||
cmd.PrintErrln("Error getting duration flag:", err)
|
||||
return
|
||||
return fmt.Errorf("Error getting duration flag: %w", err)
|
||||
}
|
||||
|
||||
target := -90.0
|
||||
@ -167,14 +159,13 @@ var stripFadeOutCmd = &cobra.Command{
|
||||
|
||||
currentFader, err := client.Strip.Fader(stripIndex)
|
||||
if err != nil {
|
||||
cmd.PrintErrln("Error getting current strip fader level:", err)
|
||||
return
|
||||
return fmt.Errorf("Error getting current strip fader level: %w", err)
|
||||
}
|
||||
|
||||
totalSteps := float64(currentFader - target)
|
||||
if totalSteps <= 0 {
|
||||
cmd.Println("Strip is already at or below target level")
|
||||
return
|
||||
return nil
|
||||
}
|
||||
|
||||
stepDelay := time.Duration(duration*1000/totalSteps) * time.Millisecond
|
||||
@ -183,13 +174,13 @@ var stripFadeOutCmd = &cobra.Command{
|
||||
currentFader -= 1.0
|
||||
err := client.Strip.SetFader(stripIndex, currentFader)
|
||||
if err != nil {
|
||||
cmd.PrintErrln("Error setting strip fader level:", err)
|
||||
return
|
||||
return fmt.Errorf("Error setting strip fader level: %w", err)
|
||||
}
|
||||
time.Sleep(stepDelay)
|
||||
}
|
||||
|
||||
cmd.Printf("Strip %d faded out to %.2f dB over %.2f seconds\n", stripIndex, target, duration)
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
@ -200,24 +191,21 @@ var stripFadeInCmd = &cobra.Command{
|
||||
Use: "fadein [strip number] --duration [seconds] [target level in dB]",
|
||||
Example: ` # Fade in strip 1 over 5 seconds
|
||||
xair-cli strip fadein 1 --duration 5.0 0`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
client := ClientFromContext(cmd.Context())
|
||||
if client == nil {
|
||||
cmd.PrintErrln("OSC client not found in context")
|
||||
return
|
||||
return fmt.Errorf("OSC client not found in context")
|
||||
}
|
||||
|
||||
if len(args) < 1 {
|
||||
cmd.PrintErrln("Please provide strip number")
|
||||
return
|
||||
return fmt.Errorf("Please provide strip number")
|
||||
}
|
||||
|
||||
stripIndex := mustConvToInt(args[0])
|
||||
|
||||
duration, err := cmd.Flags().GetFloat64("duration")
|
||||
if err != nil {
|
||||
cmd.PrintErrln("Error getting duration flag:", err)
|
||||
return
|
||||
return fmt.Errorf("Error getting duration flag: %w", err)
|
||||
}
|
||||
|
||||
target := 0.0
|
||||
@ -227,14 +215,13 @@ var stripFadeInCmd = &cobra.Command{
|
||||
|
||||
currentFader, err := client.Strip.Fader(stripIndex)
|
||||
if err != nil {
|
||||
cmd.PrintErrln("Error getting current strip fader level:", err)
|
||||
return
|
||||
return fmt.Errorf("Error getting current strip fader level: %w", err)
|
||||
}
|
||||
|
||||
totalSteps := float64(target - currentFader)
|
||||
if totalSteps <= 0 {
|
||||
cmd.Println("Strip is already at or above target level")
|
||||
return
|
||||
return nil
|
||||
}
|
||||
|
||||
stepDelay := time.Duration(duration*1000/totalSteps) * time.Millisecond
|
||||
@ -243,13 +230,13 @@ var stripFadeInCmd = &cobra.Command{
|
||||
currentFader += 1.0
|
||||
err := client.Strip.SetFader(stripIndex, currentFader)
|
||||
if err != nil {
|
||||
cmd.PrintErrln("Error setting strip fader level:", err)
|
||||
return
|
||||
return fmt.Errorf("Error setting strip fader level: %w", err)
|
||||
}
|
||||
time.Sleep(stepDelay)
|
||||
}
|
||||
|
||||
cmd.Printf("Strip %d faded in to %.2f dB over %.2f seconds\n", stripIndex, target, duration)
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
@ -263,16 +250,14 @@ var stripSendCmd = &cobra.Command{
|
||||
|
||||
# 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) {
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
client := ClientFromContext(cmd.Context())
|
||||
if client == nil {
|
||||
cmd.PrintErrln("OSC client not found in context")
|
||||
return
|
||||
return fmt.Errorf("OSC client not found in context")
|
||||
}
|
||||
|
||||
if len(args) < 2 {
|
||||
cmd.PrintErrln("Please provide strip number and bus number")
|
||||
return
|
||||
return fmt.Errorf("Please provide strip number and bus number")
|
||||
}
|
||||
|
||||
stripIndex, busIndex := func() (int, int) {
|
||||
@ -282,26 +267,24 @@ var stripSendCmd = &cobra.Command{
|
||||
if len(args) == 2 {
|
||||
currentLevel, err := client.Strip.SendLevel(stripIndex, busIndex)
|
||||
if err != nil {
|
||||
cmd.PrintErrln("Error getting strip send level:", err)
|
||||
return
|
||||
return fmt.Errorf("Error getting strip send level: %w", err)
|
||||
}
|
||||
cmd.Printf("Strip %d send level to bus %d: %.2f dB\n", stripIndex, busIndex, currentLevel)
|
||||
return
|
||||
return nil
|
||||
}
|
||||
|
||||
if len(args) < 3 {
|
||||
cmd.PrintErrln("Please provide a send level in dB")
|
||||
return
|
||||
return fmt.Errorf("Please provide a send level in dB")
|
||||
}
|
||||
|
||||
level := mustConvToFloat64(args[2])
|
||||
|
||||
err := client.Strip.SetSendLevel(stripIndex, busIndex, level)
|
||||
if err != nil {
|
||||
cmd.PrintErrln("Error setting strip send level:", err)
|
||||
return
|
||||
return fmt.Errorf("Error setting strip send level: %w", err)
|
||||
}
|
||||
cmd.Printf("Strip %d send level to bus %d set to %.2f dB\n", stripIndex, busIndex, level)
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
@ -318,16 +301,14 @@ If a name argument is provided, the strip name is set to that value.`,
|
||||
|
||||
# Set the name of strip 1 to "Guitar"
|
||||
xair-cli strip name 1 "Guitar"`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
client := ClientFromContext(cmd.Context())
|
||||
if client == nil {
|
||||
cmd.PrintErrln("OSC client not found in context")
|
||||
return
|
||||
return fmt.Errorf("OSC client not found in context")
|
||||
}
|
||||
|
||||
if len(args) < 1 {
|
||||
cmd.PrintErrln("Please provide a strip number")
|
||||
return
|
||||
return fmt.Errorf("Please provide a strip number")
|
||||
}
|
||||
|
||||
stripIndex := mustConvToInt(args[0])
|
||||
@ -335,21 +316,20 @@ If a name argument is provided, the strip name is set to that value.`,
|
||||
if len(args) == 1 {
|
||||
name, err := client.Strip.Name(stripIndex)
|
||||
if err != nil {
|
||||
cmd.PrintErrln("Error getting strip name:", err)
|
||||
return
|
||||
return fmt.Errorf("Error getting strip name: %w", err)
|
||||
}
|
||||
cmd.Printf("Strip %d name: %s\n", stripIndex, name)
|
||||
return
|
||||
return nil
|
||||
}
|
||||
|
||||
name := args[1]
|
||||
|
||||
err := client.Strip.SetName(stripIndex, name)
|
||||
if err != nil {
|
||||
cmd.PrintErrln("Error setting strip name:", err)
|
||||
return
|
||||
return fmt.Errorf("Error setting strip name: %w", err)
|
||||
}
|
||||
cmd.Printf("Strip %d name set to: %s\n", stripIndex, name)
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user