mirror of
https://github.com/onyx-and-iris/xair-cli.git
synced 2026-02-04 07:27:47 +00:00
headamp gain now accepts a --duration flag for safe gain staging.
This commit is contained in:
parent
98e131d4ad
commit
05a8f80150
@ -44,14 +44,14 @@ Use "xair-cli [command] --help" for more information about a command.
|
|||||||
xair-cli main fadeout
|
xair-cli main fadeout
|
||||||
```
|
```
|
||||||
|
|
||||||
*enable phantom power and set the gain to 28dB for strip 09*
|
*enable phantom power and set the gain to 28.0dB over a 10s duration for strip 09*
|
||||||
```console
|
```console
|
||||||
xair-cli headamp 9 phantom on
|
xair-cli headamp 9 phantom on
|
||||||
|
|
||||||
xair-cli headamp 9 gain 28
|
xair-cli headamp 9 gain 28.0 --duration 10s
|
||||||
```
|
```
|
||||||
|
|
||||||
*adjust strip 09 send level to bus 5*
|
*set strip 09 send level for bus 5 to -18.0dB*
|
||||||
```console
|
```console
|
||||||
xair-cli strip send 9 5 -- -18.0
|
xair-cli strip send 9 5 -- -18.0
|
||||||
```
|
```
|
||||||
|
|||||||
16
cmd/bus.go
16
cmd/bus.go
@ -104,7 +104,7 @@ var busFadeOutCmd = &cobra.Command{
|
|||||||
Long: "Fade out the bus fader to minimum level over a specified duration in seconds.",
|
Long: "Fade out the bus fader to minimum level over a specified duration in seconds.",
|
||||||
Use: "fadeout [bus number] --duration [seconds] [target level in dB]",
|
Use: "fadeout [bus number] --duration [seconds] [target level in dB]",
|
||||||
Example: ` # Fade out bus 1 over 5 seconds
|
Example: ` # Fade out bus 1 over 5 seconds
|
||||||
xair-cli bus fadeout 1 --duration 5 -- -90.0`,
|
xair-cli bus fadeout 1 --duration 5s -- -90.0`,
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
client := ClientFromContext(cmd.Context())
|
client := ClientFromContext(cmd.Context())
|
||||||
if client == nil {
|
if client == nil {
|
||||||
@ -117,7 +117,7 @@ var busFadeOutCmd = &cobra.Command{
|
|||||||
|
|
||||||
busIndex := mustConvToInt(args[0])
|
busIndex := mustConvToInt(args[0])
|
||||||
|
|
||||||
duration, err := cmd.Flags().GetFloat64("duration")
|
duration, err := cmd.Flags().GetDuration("duration")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Error getting duration flag: %w", err)
|
return fmt.Errorf("Error getting duration flag: %w", err)
|
||||||
}
|
}
|
||||||
@ -139,7 +139,7 @@ var busFadeOutCmd = &cobra.Command{
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
stepDelay := time.Duration(duration*1000/totalSteps) * time.Millisecond
|
stepDelay := time.Duration(duration.Seconds()*1000/totalSteps) * time.Millisecond
|
||||||
|
|
||||||
for currentFader > target {
|
for currentFader > target {
|
||||||
currentFader -= 1.0
|
currentFader -= 1.0
|
||||||
@ -161,7 +161,7 @@ var busFadeInCmd = &cobra.Command{
|
|||||||
Long: "Fade in the bus fader to maximum level over a specified duration in seconds.",
|
Long: "Fade in the bus fader to maximum level over a specified duration in seconds.",
|
||||||
Use: "fadein [bus number] --duration [seconds] [target level in dB]",
|
Use: "fadein [bus number] --duration [seconds] [target level in dB]",
|
||||||
Example: ` # Fade in bus 1 over 5 seconds
|
Example: ` # Fade in bus 1 over 5 seconds
|
||||||
xair-cli bus fadein 1 --duration 5 -- 0.0`,
|
xair-cli bus fadein 1 --duration 5s -- 0.0`,
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
client := ClientFromContext(cmd.Context())
|
client := ClientFromContext(cmd.Context())
|
||||||
if client == nil {
|
if client == nil {
|
||||||
@ -174,7 +174,7 @@ var busFadeInCmd = &cobra.Command{
|
|||||||
|
|
||||||
busIndex := mustConvToInt(args[0])
|
busIndex := mustConvToInt(args[0])
|
||||||
|
|
||||||
duration, err := cmd.Flags().GetFloat64("duration")
|
duration, err := cmd.Flags().GetDuration("duration")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Error getting duration flag: %w", err)
|
return fmt.Errorf("Error getting duration flag: %w", err)
|
||||||
}
|
}
|
||||||
@ -196,7 +196,7 @@ var busFadeInCmd = &cobra.Command{
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
stepDelay := time.Duration(duration*1000/totalSteps) * time.Millisecond
|
stepDelay := time.Duration(duration.Seconds()*1000/totalSteps) * time.Millisecond
|
||||||
|
|
||||||
for currentFader < target {
|
for currentFader < target {
|
||||||
currentFader += 1.0
|
currentFader += 1.0
|
||||||
@ -261,9 +261,9 @@ func init() {
|
|||||||
|
|
||||||
busCmd.AddCommand(busFaderCmd)
|
busCmd.AddCommand(busFaderCmd)
|
||||||
busCmd.AddCommand(busFadeOutCmd)
|
busCmd.AddCommand(busFadeOutCmd)
|
||||||
busFadeOutCmd.Flags().Float64P("duration", "d", 5.0, "Duration for fade out in seconds")
|
busFadeOutCmd.Flags().DurationP("duration", "d", 5*time.Second, "Duration for fade out in seconds")
|
||||||
busCmd.AddCommand(busFadeInCmd)
|
busCmd.AddCommand(busFadeInCmd)
|
||||||
busFadeInCmd.Flags().Float64P("duration", "d", 5.0, "Duration for fade in in seconds")
|
busFadeInCmd.Flags().DurationP("duration", "d", 5*time.Second, "Duration for fade in in seconds")
|
||||||
|
|
||||||
busCmd.AddCommand(busNameCmd)
|
busCmd.AddCommand(busNameCmd)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,7 +2,10 @@ package cmd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/charmbracelet/log"
|
||||||
|
"github.com/onyx-and-iris/xair-cli/internal/xair"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -23,12 +26,16 @@ var headampGainCmd = &cobra.Command{
|
|||||||
Use: "gain",
|
Use: "gain",
|
||||||
Short: "Get or set headamp gain level",
|
Short: "Get or set headamp gain level",
|
||||||
Long: `Get or set the gain level for a specified headamp index.
|
Long: `Get or set the gain level for a specified headamp index.
|
||||||
|
When setting gain, it will gradually increase from the current level to prevent
|
||||||
|
sudden jumps that could cause feedback or equipment damage.
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
# Get gain level for headamp index 1
|
# Get gain level for headamp index 1
|
||||||
xairctl headamp gain 1
|
xair-cli headamp gain 1
|
||||||
# Set gain level for headamp index 1 to 3.5 dB
|
# Set gain level for headamp index 1 to 3.5 dB (gradually over 5 seconds)
|
||||||
xairctl headamp gain 1 3.5`,
|
xair-cli headamp gain 1 3.5
|
||||||
|
# Set gain level for headamp index 1 to 3.5 dB over 10 seconds
|
||||||
|
xair-cli headamp gain 1 3.5 --duration 10s`,
|
||||||
Args: cobra.RangeArgs(1, 2),
|
Args: cobra.RangeArgs(1, 2),
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
client := ClientFromContext(cmd.Context())
|
client := ClientFromContext(cmd.Context())
|
||||||
@ -55,18 +62,79 @@ Examples:
|
|||||||
return fmt.Errorf("Please provide a gain level in dB")
|
return fmt.Errorf("Please provide a gain level in dB")
|
||||||
}
|
}
|
||||||
|
|
||||||
level := mustConvToFloat64(args[1])
|
targetLevel := mustConvToFloat64(args[1])
|
||||||
|
|
||||||
err := client.HeadAmp.SetGain(index, level)
|
currentGain, err := client.HeadAmp.Gain(index)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Error setting headamp gain level: %w", err)
|
return fmt.Errorf("Error getting current headamp gain level: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.Printf("Headamp %d Gain set to %.2f dB\n", index, level)
|
duration, err := cmd.Flags().GetDuration("duration")
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Error getting duration flag: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if currentGain == targetLevel {
|
||||||
|
cmd.Printf("Headamp %d Gain already at %.2f dB\n", index, targetLevel)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := gradualGainAdjust(client, cmd, index, currentGain, targetLevel, duration); err != nil {
|
||||||
|
return fmt.Errorf("Error adjusting headamp gain level: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd.Printf("Headamp %d Gain set to %.2f dB\n", index, targetLevel)
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// gradualGainAdjust gradually adjusts gain from current to target over specified duration
|
||||||
|
func gradualGainAdjust(
|
||||||
|
client *xair.Client,
|
||||||
|
cmd *cobra.Command,
|
||||||
|
index int,
|
||||||
|
currentGain, targetGain float64,
|
||||||
|
duration time.Duration,
|
||||||
|
) error {
|
||||||
|
gainDiff := targetGain - currentGain
|
||||||
|
|
||||||
|
stepInterval := 100 * time.Millisecond
|
||||||
|
totalSteps := int(duration / stepInterval)
|
||||||
|
|
||||||
|
if totalSteps < 1 {
|
||||||
|
totalSteps = 1
|
||||||
|
stepInterval = duration
|
||||||
|
}
|
||||||
|
|
||||||
|
stepIncrement := gainDiff / float64(totalSteps)
|
||||||
|
|
||||||
|
log.Debugf("Adjusting Headamp %d gain from %.2f dB to %.2f dB over %v...\n",
|
||||||
|
index, currentGain, targetGain, duration)
|
||||||
|
|
||||||
|
for step := 1; step <= totalSteps; step++ {
|
||||||
|
newGain := currentGain + (stepIncrement * float64(step))
|
||||||
|
|
||||||
|
if step == totalSteps {
|
||||||
|
newGain = targetGain
|
||||||
|
}
|
||||||
|
|
||||||
|
err := client.HeadAmp.SetGain(index, newGain)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if step%10 == 0 || step == totalSteps {
|
||||||
|
log.Debugf(" Step %d/%d: %.2f dB\n", step, totalSteps, newGain)
|
||||||
|
}
|
||||||
|
|
||||||
|
if step < totalSteps {
|
||||||
|
time.Sleep(stepInterval)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// headampPhantomPowerCmd represents the headamp phantom power command
|
// headampPhantomPowerCmd represents the headamp phantom power command
|
||||||
var headampPhantomPowerCmd = &cobra.Command{
|
var headampPhantomPowerCmd = &cobra.Command{
|
||||||
Use: "phantom",
|
Use: "phantom",
|
||||||
@ -137,5 +205,7 @@ func init() {
|
|||||||
rootCmd.AddCommand(headampCmd)
|
rootCmd.AddCommand(headampCmd)
|
||||||
|
|
||||||
headampCmd.AddCommand(headampGainCmd)
|
headampCmd.AddCommand(headampGainCmd)
|
||||||
|
headampGainCmd.Flags().DurationP("duration", "d", 5*time.Second, "Duration over which to gradually adjust gain")
|
||||||
|
|
||||||
headampCmd.AddCommand(headampPhantomPowerCmd)
|
headampCmd.AddCommand(headampPhantomPowerCmd)
|
||||||
}
|
}
|
||||||
|
|||||||
16
cmd/main.go
16
cmd/main.go
@ -116,7 +116,7 @@ This command will fade out the main output to the specified dB level.
|
|||||||
`,
|
`,
|
||||||
Use: "fadeout --duration [seconds] [target_db]",
|
Use: "fadeout --duration [seconds] [target_db]",
|
||||||
Example: ` # Fade out main output over 5 seconds
|
Example: ` # Fade out main output over 5 seconds
|
||||||
xair-cli main fadeout --duration 5 -- -90.0`,
|
xair-cli main fadeout --duration 5s -- -90.0`,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
client := ClientFromContext(cmd.Context())
|
client := ClientFromContext(cmd.Context())
|
||||||
if client == nil {
|
if client == nil {
|
||||||
@ -124,7 +124,7 @@ This command will fade out the main output to the specified dB level.
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
duration, err := cmd.Flags().GetFloat64("duration")
|
duration, err := cmd.Flags().GetDuration("duration")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cmd.PrintErrln("Error getting duration flag:", err)
|
cmd.PrintErrln("Error getting duration flag:", err)
|
||||||
return
|
return
|
||||||
@ -150,7 +150,7 @@ This command will fade out the main output to the specified dB level.
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Calculate delay per step to achieve exact duration
|
// Calculate delay per step to achieve exact duration
|
||||||
stepDelay := time.Duration(duration*1000/totalSteps) * time.Millisecond
|
stepDelay := time.Duration(duration.Seconds()*1000/totalSteps) * time.Millisecond
|
||||||
|
|
||||||
for currentFader > target {
|
for currentFader > target {
|
||||||
currentFader -= 1.0
|
currentFader -= 1.0
|
||||||
@ -175,7 +175,7 @@ This command will fade in the main output to the specified dB level.
|
|||||||
`,
|
`,
|
||||||
Use: "fadein --duration [seconds] [target_db]",
|
Use: "fadein --duration [seconds] [target_db]",
|
||||||
Example: ` # Fade in main output over 5 seconds
|
Example: ` # Fade in main output over 5 seconds
|
||||||
xair-cli main fadein --duration 5 -- 0.0`,
|
xair-cli main fadein --duration 5s -- 0.0`,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
client := ClientFromContext(cmd.Context())
|
client := ClientFromContext(cmd.Context())
|
||||||
if client == nil {
|
if client == nil {
|
||||||
@ -183,7 +183,7 @@ This command will fade in the main output to the specified dB level.
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
duration, err := cmd.Flags().GetFloat64("duration")
|
duration, err := cmd.Flags().GetDuration("duration")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cmd.PrintErrln("Error getting duration flag:", err)
|
cmd.PrintErrln("Error getting duration flag:", err)
|
||||||
return
|
return
|
||||||
@ -208,7 +208,7 @@ This command will fade in the main output to the specified dB level.
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Calculate delay per step to achieve exact duration
|
// Calculate delay per step to achieve exact duration
|
||||||
stepDelay := time.Duration(duration*1000/totalSteps) * time.Millisecond
|
stepDelay := time.Duration(duration.Seconds()*1000/totalSteps) * time.Millisecond
|
||||||
|
|
||||||
for currentFader < target {
|
for currentFader < target {
|
||||||
currentFader += 1.0
|
currentFader += 1.0
|
||||||
@ -231,7 +231,7 @@ func init() {
|
|||||||
|
|
||||||
mainCmd.AddCommand(mainFaderCmd)
|
mainCmd.AddCommand(mainFaderCmd)
|
||||||
mainCmd.AddCommand(mainFadeOutCmd)
|
mainCmd.AddCommand(mainFadeOutCmd)
|
||||||
mainFadeOutCmd.Flags().Float64P("duration", "d", 5, "Duration for fade out in seconds")
|
mainFadeOutCmd.Flags().DurationP("duration", "d", 5*time.Second, "Duration for fade out in seconds")
|
||||||
mainCmd.AddCommand(mainFadeInCmd)
|
mainCmd.AddCommand(mainFadeInCmd)
|
||||||
mainFadeInCmd.Flags().Float64P("duration", "d", 5, "Duration for fade in in seconds")
|
mainFadeInCmd.Flags().DurationP("duration", "d", 5*time.Second, "Duration for fade in in seconds")
|
||||||
}
|
}
|
||||||
|
|||||||
14
cmd/strip.go
14
cmd/strip.go
@ -134,7 +134,7 @@ var stripFadeOutCmd = &cobra.Command{
|
|||||||
Long: "Fade out the strip over a specified duration in seconds.",
|
Long: "Fade out the strip over a specified duration in seconds.",
|
||||||
Use: "fadeout [strip number] --duration [seconds] [target level in dB]",
|
Use: "fadeout [strip number] --duration [seconds] [target level in dB]",
|
||||||
Example: ` # Fade out strip 1 over 5 seconds
|
Example: ` # Fade out strip 1 over 5 seconds
|
||||||
xair-cli strip fadeout 1 --duration 5.0 -- -90.0`,
|
xair-cli strip fadeout 1 --duration 5s -- -90.0`,
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
client := ClientFromContext(cmd.Context())
|
client := ClientFromContext(cmd.Context())
|
||||||
if client == nil {
|
if client == nil {
|
||||||
@ -147,7 +147,7 @@ var stripFadeOutCmd = &cobra.Command{
|
|||||||
|
|
||||||
stripIndex := mustConvToInt(args[0])
|
stripIndex := mustConvToInt(args[0])
|
||||||
|
|
||||||
duration, err := cmd.Flags().GetFloat64("duration")
|
duration, err := cmd.Flags().GetDuration("duration")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Error getting duration flag: %w", err)
|
return fmt.Errorf("Error getting duration flag: %w", err)
|
||||||
}
|
}
|
||||||
@ -168,7 +168,7 @@ var stripFadeOutCmd = &cobra.Command{
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
stepDelay := time.Duration(duration*1000/totalSteps) * time.Millisecond
|
stepDelay := time.Duration(duration.Seconds()*1000/totalSteps) * time.Millisecond
|
||||||
|
|
||||||
for currentFader > target {
|
for currentFader > target {
|
||||||
currentFader -= 1.0
|
currentFader -= 1.0
|
||||||
@ -179,7 +179,7 @@ var stripFadeOutCmd = &cobra.Command{
|
|||||||
time.Sleep(stepDelay)
|
time.Sleep(stepDelay)
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.Printf("Strip %d faded out to %.2f dB over %.2f seconds\n", stripIndex, target, duration)
|
cmd.Printf("Strip %d faded out to %.2f dB over %.2f seconds\n", stripIndex, target, duration.Seconds())
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -190,7 +190,7 @@ var stripFadeInCmd = &cobra.Command{
|
|||||||
Long: "Fade in the strip over a specified duration in seconds.",
|
Long: "Fade in the strip over a specified duration in seconds.",
|
||||||
Use: "fadein [strip number] --duration [seconds] [target level in dB]",
|
Use: "fadein [strip number] --duration [seconds] [target level in dB]",
|
||||||
Example: ` # Fade in strip 1 over 5 seconds
|
Example: ` # Fade in strip 1 over 5 seconds
|
||||||
xair-cli strip fadein 1 --duration 5.0 0`,
|
xair-cli strip fadein 1 --duration 5s 0`,
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
client := ClientFromContext(cmd.Context())
|
client := ClientFromContext(cmd.Context())
|
||||||
if client == nil {
|
if client == nil {
|
||||||
@ -340,9 +340,9 @@ func init() {
|
|||||||
|
|
||||||
stripCmd.AddCommand(stripFaderCmd)
|
stripCmd.AddCommand(stripFaderCmd)
|
||||||
stripCmd.AddCommand(stripFadeOutCmd)
|
stripCmd.AddCommand(stripFadeOutCmd)
|
||||||
stripFadeOutCmd.Flags().Float64P("duration", "d", 5.0, "Duration of the fade out in seconds")
|
stripFadeOutCmd.Flags().DurationP("duration", "d", 5*time.Second, "Duration of the fade out in seconds")
|
||||||
stripCmd.AddCommand(stripFadeInCmd)
|
stripCmd.AddCommand(stripFadeInCmd)
|
||||||
stripFadeInCmd.Flags().Float64P("duration", "d", 5.0, "Duration of the fade in in seconds")
|
stripFadeInCmd.Flags().DurationP("duration", "d", 5*time.Second, "Duration of the fade in in seconds")
|
||||||
|
|
||||||
stripCmd.AddCommand(stripSendCmd)
|
stripCmd.AddCommand(stripSendCmd)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user