mirror of
https://github.com/onyx-and-iris/xair-cli.git
synced 2026-02-04 07:27:47 +00:00
implement strip fader commands
This commit is contained in:
parent
c851d0e804
commit
d1657e09ab
200
cmd/strip.go
200
cmd/strip.go
@ -1,24 +1,22 @@
|
|||||||
/*
|
|
||||||
LICENSE: https://github.com/onyx-and-iris/xair-cli/blob/main/LICENSE
|
|
||||||
*/
|
|
||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"time"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
// stripCmd represents the strip command
|
// stripCmd represents the strip command.
|
||||||
var stripCmd = &cobra.Command{
|
var stripCmd = &cobra.Command{
|
||||||
Use: "strip",
|
Use: "strip",
|
||||||
Short: "Commands to control individual strips",
|
Short: "Commands to control individual strips",
|
||||||
Long: `Commands to control individual strips of the XAir mixer, including fader level and mute status.`,
|
Long: `Commands to control individual strips of the XAir mixer, including fader level and mute status.`,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, _ []string) {
|
||||||
fmt.Println("strip called")
|
cmd.Help()
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// stripMuteCmd represents the strip mute command.
|
||||||
var stripMuteCmd = &cobra.Command{
|
var stripMuteCmd = &cobra.Command{
|
||||||
Use: "mute",
|
Use: "mute",
|
||||||
Short: "Get or set the mute status of a strip",
|
Short: "Get or set the mute status of a strip",
|
||||||
@ -85,8 +83,196 @@ For example:
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// stripFaderCmd represents the strip fader command.
|
||||||
|
var stripFaderCmd = &cobra.Command{
|
||||||
|
Use: "fader",
|
||||||
|
Short: "Get or set the fader level of a strip",
|
||||||
|
Long: `Get or set the fader level of a specific strip.
|
||||||
|
|
||||||
|
If no level argument is provided, the current fader level is retrieved.
|
||||||
|
If a level argument (in dB) is provided, the strip fader is set to that level.
|
||||||
|
|
||||||
|
For example:
|
||||||
|
# Get the current fader level of strip 1
|
||||||
|
xair-cli strip fader 1
|
||||||
|
|
||||||
|
# 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) {
|
||||||
|
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 {
|
||||||
|
level, err := client.StripFader(stripIndex)
|
||||||
|
if err != nil {
|
||||||
|
cmd.PrintErrln("Error getting strip fader level:", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
cmd.Printf("Strip %d fader level: %.2f\n", stripIndex, level)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(args) < 2 {
|
||||||
|
cmd.PrintErrln("Please provide a fader level in dB")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
level := mustConvToFloat64(args[1])
|
||||||
|
|
||||||
|
err := client.SetStripFader(stripIndex, level)
|
||||||
|
if err != nil {
|
||||||
|
cmd.PrintErrln("Error setting strip fader level:", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
cmd.Printf("Strip %d fader set to %.2f dB\n", stripIndex, level)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
// stripFadeOutCmd represents the strip fade out command.
|
||||||
|
var stripFadeOutCmd = &cobra.Command{
|
||||||
|
Use: "fadeout",
|
||||||
|
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
|
||||||
|
`,
|
||||||
|
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 strip number")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
stripIndex := mustConvToInt(args[0])
|
||||||
|
|
||||||
|
duration, err := cmd.Flags().GetFloat64("duration")
|
||||||
|
if err != nil {
|
||||||
|
cmd.PrintErrln("Error getting duration flag:", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
target := -90.0
|
||||||
|
if len(args) > 1 {
|
||||||
|
target = mustConvToFloat64(args[1])
|
||||||
|
}
|
||||||
|
|
||||||
|
currentFader, err := client.StripFader(stripIndex)
|
||||||
|
if err != nil {
|
||||||
|
cmd.PrintErrln("Error getting current strip fader level:", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
totalSteps := float64(currentFader - target)
|
||||||
|
if totalSteps <= 0 {
|
||||||
|
cmd.Println("Strip is already at or below target level")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
stepDelay := time.Duration(duration*1000/totalSteps) * time.Millisecond
|
||||||
|
|
||||||
|
for currentFader > target {
|
||||||
|
currentFader -= 1.0
|
||||||
|
err := client.SetStripFader(stripIndex, currentFader)
|
||||||
|
if err != nil {
|
||||||
|
cmd.PrintErrln("Error setting strip fader level:", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
time.Sleep(stepDelay)
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd.Printf("Strip %d faded out to %.2f dB over %.2f seconds\n", stripIndex, target, duration)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
// stripFadeInCmd represents the strip fade in command.
|
||||||
|
var stripFadeInCmd = &cobra.Command{
|
||||||
|
Use: "fadein",
|
||||||
|
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
|
||||||
|
`,
|
||||||
|
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 strip number")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
stripIndex := mustConvToInt(args[0])
|
||||||
|
|
||||||
|
duration, err := cmd.Flags().GetFloat64("duration")
|
||||||
|
if err != nil {
|
||||||
|
cmd.PrintErrln("Error getting duration flag:", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
target := 0.0
|
||||||
|
if len(args) > 1 {
|
||||||
|
target = mustConvToFloat64(args[1])
|
||||||
|
}
|
||||||
|
|
||||||
|
currentFader, err := client.StripFader(stripIndex)
|
||||||
|
if err != nil {
|
||||||
|
cmd.PrintErrln("Error getting current strip fader level:", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
totalSteps := float64(target - currentFader)
|
||||||
|
if totalSteps <= 0 {
|
||||||
|
cmd.Println("Strip is already at or above target level")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
stepDelay := time.Duration(duration*1000/totalSteps) * time.Millisecond
|
||||||
|
|
||||||
|
for currentFader < target {
|
||||||
|
currentFader += 1.0
|
||||||
|
err := client.SetStripFader(stripIndex, currentFader)
|
||||||
|
if err != nil {
|
||||||
|
cmd.PrintErrln("Error setting strip fader level:", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
time.Sleep(stepDelay)
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd.Printf("Strip %d faded in to %.2f dB over %.2f seconds\n", stripIndex, target, duration)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
rootCmd.AddCommand(stripCmd)
|
rootCmd.AddCommand(stripCmd)
|
||||||
|
|
||||||
stripCmd.AddCommand(stripMuteCmd)
|
stripCmd.AddCommand(stripMuteCmd)
|
||||||
|
|
||||||
|
stripCmd.AddCommand(stripFaderCmd)
|
||||||
|
stripCmd.AddCommand(stripFadeOutCmd)
|
||||||
|
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")
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user