mirror of
https://github.com/onyx-and-iris/xair-cli.git
synced 2026-02-03 23:17:47 +00:00
start implementing strip and bus commands
This commit is contained in:
parent
d5c88f31e0
commit
bb82d8653b
69
cmd/bus.go
Normal file
69
cmd/bus.go
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
/*
|
||||||
|
LICENSE: https://github.com/onyx-and-iris/xair-cli/blob/main/LICENSE
|
||||||
|
*/
|
||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
// busCmd represents the bus command
|
||||||
|
var busCmd = &cobra.Command{
|
||||||
|
Use: "bus",
|
||||||
|
Short: "A brief description of your command",
|
||||||
|
Long: `A longer description that spans multiple lines and likely contains examples
|
||||||
|
and usage of using your command. For example:
|
||||||
|
|
||||||
|
Cobra is a CLI library for Go that empowers applications.
|
||||||
|
This application is a tool to generate the needed files
|
||||||
|
to quickly create a Cobra application.`,
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
fmt.Println("bus called")
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
// busMuteCmd represents the bus mute command
|
||||||
|
var busMuteCmd = &cobra.Command{
|
||||||
|
Use: "mute",
|
||||||
|
Short: "Get or set the bus mute status",
|
||||||
|
Long: `Get or set the mute status of a specific bus.`,
|
||||||
|
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) < 2 {
|
||||||
|
cmd.PrintErrln("Please provide bus number and mute status (true/false)")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
busNum := mustConvToInt(args[0])
|
||||||
|
var muted bool
|
||||||
|
switch args[1] {
|
||||||
|
case "true", "1":
|
||||||
|
muted = true
|
||||||
|
case "false", "0":
|
||||||
|
muted = false
|
||||||
|
default:
|
||||||
|
cmd.PrintErrln("Invalid mute status. Use true/false or 1/0")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err := client.SetBusMute(busNum, muted)
|
||||||
|
if err != nil {
|
||||||
|
cmd.PrintErrln("Error setting bus mute status:", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
cmd.Printf("Bus %d mute set to %v\n", busNum, muted)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
rootCmd.AddCommand(busCmd)
|
||||||
|
|
||||||
|
busCmd.AddCommand(busMuteCmd)
|
||||||
|
}
|
||||||
18
cmd/main.go
18
cmd/main.go
@ -101,7 +101,7 @@ For example:
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err := client.SetMainLRFader(mustConv(args[0]))
|
err := client.SetMainLRFader(mustConvToFloat64(args[0]))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cmd.PrintErrln("Error setting main LR fader:", err)
|
cmd.PrintErrln("Error setting main LR fader:", err)
|
||||||
return
|
return
|
||||||
@ -137,7 +137,7 @@ This command will fade out the main output to the specified dB level.
|
|||||||
// Default target for fadeout
|
// Default target for fadeout
|
||||||
target := -90.0
|
target := -90.0
|
||||||
if len(args) > 0 {
|
if len(args) > 0 {
|
||||||
target = mustConv(args[0])
|
target = mustConvToFloat64(args[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
currentFader, err := client.MainLRFader()
|
currentFader, err := client.MainLRFader()
|
||||||
@ -158,7 +158,11 @@ This command will fade out the main output to the specified dB level.
|
|||||||
|
|
||||||
for currentFader > target {
|
for currentFader > target {
|
||||||
currentFader -= 1.0
|
currentFader -= 1.0
|
||||||
client.SetMainLRFader(currentFader)
|
err = client.SetMainLRFader(currentFader)
|
||||||
|
if err != nil {
|
||||||
|
cmd.PrintErrln("Error setting main LR fader:", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
time.Sleep(stepDelay)
|
time.Sleep(stepDelay)
|
||||||
}
|
}
|
||||||
cmd.Println("Main output faded out successfully")
|
cmd.Println("Main output faded out successfully")
|
||||||
@ -192,7 +196,7 @@ This command will fade in the main output to the specified dB level.
|
|||||||
|
|
||||||
target := 0.0
|
target := 0.0
|
||||||
if len(args) > 0 {
|
if len(args) > 0 {
|
||||||
target = mustConv(args[0])
|
target = mustConvToFloat64(args[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
currentFader, err := client.MainLRFader()
|
currentFader, err := client.MainLRFader()
|
||||||
@ -213,7 +217,11 @@ This command will fade in the main output to the specified dB level.
|
|||||||
|
|
||||||
for currentFader < target {
|
for currentFader < target {
|
||||||
currentFader += 1.0
|
currentFader += 1.0
|
||||||
client.SetMainLRFader(currentFader)
|
err = client.SetMainLRFader(currentFader)
|
||||||
|
if err != nil {
|
||||||
|
cmd.PrintErrln("Error setting main LR fader:", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
time.Sleep(stepDelay)
|
time.Sleep(stepDelay)
|
||||||
}
|
}
|
||||||
cmd.Println("Main output faded in successfully")
|
cmd.Println("Main output faded in successfully")
|
||||||
|
|||||||
97
cmd/strip.go
Normal file
97
cmd/strip.go
Normal file
@ -0,0 +1,97 @@
|
|||||||
|
/*
|
||||||
|
LICENSE: https://github.com/onyx-and-iris/xair-cli/blob/main/LICENSE
|
||||||
|
*/
|
||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
// stripCmd represents the strip command
|
||||||
|
var stripCmd = &cobra.Command{
|
||||||
|
Use: "strip",
|
||||||
|
Short: "A brief description of your command",
|
||||||
|
Long: `A longer description that spans multiple lines and likely contains examples
|
||||||
|
and usage of using your command. For example:
|
||||||
|
|
||||||
|
Cobra is a CLI library for Go that empowers applications.
|
||||||
|
This application is a tool to generate the needed files
|
||||||
|
to quickly create a Cobra application.`,
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
fmt.Println("strip called")
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
var stripMuteCmd = &cobra.Command{
|
||||||
|
Use: "mute",
|
||||||
|
Short: "Get or set the mute status of a strip",
|
||||||
|
Long: `Get or set the mute status of a specific strip.
|
||||||
|
|
||||||
|
If no argument is provided, the current mute status is retrieved.
|
||||||
|
If "true" or "1" is provided as an argument, the strip is muted.
|
||||||
|
If "false" or "0" is provided, the strip is unmuted.
|
||||||
|
|
||||||
|
For example:
|
||||||
|
# Get the current mute status of strip 1
|
||||||
|
xair-cli strip mute 1
|
||||||
|
|
||||||
|
# Mute strip 1
|
||||||
|
xair-cli strip mute 1 true
|
||||||
|
# Unmute strip 1
|
||||||
|
xair-cli strip mute 1 false
|
||||||
|
`,
|
||||||
|
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 {
|
||||||
|
resp, err := client.StripMute(stripIndex)
|
||||||
|
if err != nil {
|
||||||
|
cmd.PrintErrln("Error getting strip mute status:", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
cmd.Printf("Strip %d mute: %v\n", stripIndex, resp)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var muted bool
|
||||||
|
switch args[1] {
|
||||||
|
case "true", "1":
|
||||||
|
muted = true
|
||||||
|
case "false", "0":
|
||||||
|
muted = false
|
||||||
|
default:
|
||||||
|
cmd.PrintErrln("Invalid mute status. Use true/false or 1/0")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err := client.SetStripMute(stripIndex, muted)
|
||||||
|
if err != nil {
|
||||||
|
cmd.PrintErrln("Error setting strip mute status:", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if muted {
|
||||||
|
cmd.Printf("Strip %d muted successfully\n", stripIndex)
|
||||||
|
} else {
|
||||||
|
cmd.Printf("Strip %d unmuted successfully\n", stripIndex)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
rootCmd.AddCommand(stripCmd)
|
||||||
|
|
||||||
|
stripCmd.AddCommand(stripMuteCmd)
|
||||||
|
}
|
||||||
12
cmd/util.go
12
cmd/util.go
@ -7,10 +7,18 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
func mustConv(levelStr string) float64 {
|
func mustConvToFloat64(floatStr string) float64 {
|
||||||
level, err := strconv.ParseFloat(levelStr, 64)
|
level, err := strconv.ParseFloat(floatStr, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
return level
|
return level
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func mustConvToInt(intStr string) int {
|
||||||
|
val, err := strconv.Atoi(intStr)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return val
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user