mirror of
https://github.com/onyx-and-iris/xair-cli.git
synced 2026-02-03 23:17:47 +00:00
move strip commands into their own struct
update the cli
This commit is contained in:
parent
205baf310f
commit
fc8c8ad69a
16
cmd/strip.go
16
cmd/strip.go
@ -50,7 +50,7 @@ For example:
|
||||
stripIndex := mustConvToInt(args[0])
|
||||
|
||||
if len(args) == 1 {
|
||||
resp, err := client.StripMute(stripIndex)
|
||||
resp, err := client.Strip.Mute(stripIndex)
|
||||
if err != nil {
|
||||
cmd.PrintErrln("Error getting strip mute status:", err)
|
||||
return
|
||||
@ -70,7 +70,7 @@ For example:
|
||||
return
|
||||
}
|
||||
|
||||
err := client.SetStripMute(stripIndex, muted)
|
||||
err := client.Strip.SetMute(stripIndex, muted)
|
||||
if err != nil {
|
||||
cmd.PrintErrln("Error setting strip mute status:", err)
|
||||
return
|
||||
@ -114,7 +114,7 @@ For example:
|
||||
stripIndex := mustConvToInt(args[0])
|
||||
|
||||
if len(args) == 1 {
|
||||
level, err := client.StripFader(stripIndex)
|
||||
level, err := client.Strip.Fader(stripIndex)
|
||||
if err != nil {
|
||||
cmd.PrintErrln("Error getting strip fader level:", err)
|
||||
return
|
||||
@ -130,7 +130,7 @@ For example:
|
||||
|
||||
level := mustConvToFloat64(args[1])
|
||||
|
||||
err := client.SetStripFader(stripIndex, level)
|
||||
err := client.Strip.SetFader(stripIndex, level)
|
||||
if err != nil {
|
||||
cmd.PrintErrln("Error setting strip fader level:", err)
|
||||
return
|
||||
@ -174,7 +174,7 @@ For example:
|
||||
target = mustConvToFloat64(args[1])
|
||||
}
|
||||
|
||||
currentFader, err := client.StripFader(stripIndex)
|
||||
currentFader, err := client.Strip.Fader(stripIndex)
|
||||
if err != nil {
|
||||
cmd.PrintErrln("Error getting current strip fader level:", err)
|
||||
return
|
||||
@ -190,7 +190,7 @@ For example:
|
||||
|
||||
for currentFader > target {
|
||||
currentFader -= 1.0
|
||||
err := client.SetStripFader(stripIndex, currentFader)
|
||||
err := client.Strip.SetFader(stripIndex, currentFader)
|
||||
if err != nil {
|
||||
cmd.PrintErrln("Error setting strip fader level:", err)
|
||||
return
|
||||
@ -237,7 +237,7 @@ For example:
|
||||
target = mustConvToFloat64(args[1])
|
||||
}
|
||||
|
||||
currentFader, err := client.StripFader(stripIndex)
|
||||
currentFader, err := client.Strip.Fader(stripIndex)
|
||||
if err != nil {
|
||||
cmd.PrintErrln("Error getting current strip fader level:", err)
|
||||
return
|
||||
@ -253,7 +253,7 @@ For example:
|
||||
|
||||
for currentFader < target {
|
||||
currentFader += 1.0
|
||||
err := client.SetStripFader(stripIndex, currentFader)
|
||||
err := client.Strip.SetFader(stripIndex, currentFader)
|
||||
if err != nil {
|
||||
cmd.PrintErrln("Error setting strip fader level:", err)
|
||||
return
|
||||
|
||||
@ -28,6 +28,7 @@ type engine struct {
|
||||
|
||||
type Client struct {
|
||||
engine
|
||||
Strip *Strip
|
||||
}
|
||||
|
||||
// NewClient creates a new XAirClient instance
|
||||
@ -64,9 +65,12 @@ func NewClient(mixerIP string, mixerPort int, opts ...Option) (*Client, error) {
|
||||
opt(e)
|
||||
}
|
||||
|
||||
return &Client{
|
||||
c := &Client{
|
||||
engine: *e,
|
||||
}, nil
|
||||
}
|
||||
c.Strip = NewStrip(*c)
|
||||
|
||||
return c, nil
|
||||
}
|
||||
|
||||
// Start begins listening for messages in a goroutine
|
||||
@ -191,123 +195,6 @@ func (c *Client) RequestStatus() error {
|
||||
return c.SendMessage("/status")
|
||||
}
|
||||
|
||||
/* STRIP METHODS */
|
||||
|
||||
// StripMute gets mute state for a specific strip (1-based indexing)
|
||||
func (c *Client) StripMute(strip int) (bool, error) {
|
||||
address := fmt.Sprintf("/ch/%02d/mix/on", strip)
|
||||
err := c.SendMessage(address)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
resp := <-c.respChan
|
||||
val, ok := resp.Arguments[0].(int32)
|
||||
if !ok {
|
||||
return false, fmt.Errorf("unexpected argument type for strip mute value")
|
||||
}
|
||||
return val == 0, nil
|
||||
}
|
||||
|
||||
// SetStripMute sets mute state for a specific strip (1-based indexing)
|
||||
func (c *Client) SetStripMute(strip int, muted bool) error {
|
||||
address := fmt.Sprintf("/ch/%02d/mix/on", strip)
|
||||
var value int32 = 0
|
||||
if !muted {
|
||||
value = 1
|
||||
}
|
||||
return c.SendMessage(address, value)
|
||||
}
|
||||
|
||||
// StripFader requests the current fader level for a strip
|
||||
func (c *Client) StripFader(strip int) (float64, error) {
|
||||
address := fmt.Sprintf("/ch/%02d/mix/fader", strip)
|
||||
err := c.SendMessage(address)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
resp := <-c.respChan
|
||||
val, ok := resp.Arguments[0].(float32)
|
||||
if !ok {
|
||||
return 0, fmt.Errorf("unexpected argument type for fader value")
|
||||
}
|
||||
|
||||
return mustDbFrom(float64(val)), nil
|
||||
}
|
||||
|
||||
// SetStripFader sets the fader level for a specific strip (1-based indexing)
|
||||
func (c *Client) SetStripFader(strip int, level float64) error {
|
||||
address := fmt.Sprintf("/ch/%02d/mix/fader", strip)
|
||||
return c.SendMessage(address, float32(mustDbInto(level)))
|
||||
}
|
||||
|
||||
// StripMicGain requests the phantom gain for a specific strip
|
||||
func (c *Client) StripMicGain(strip int) (float64, error) {
|
||||
address := fmt.Sprintf("/ch/%02d/mix/gain", strip)
|
||||
err := c.SendMessage(address)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("failed to send strip gain request: %v", err)
|
||||
}
|
||||
|
||||
resp := <-c.respChan
|
||||
val, ok := resp.Arguments[0].(float32)
|
||||
if !ok {
|
||||
return 0, fmt.Errorf("unexpected argument type for strip gain value")
|
||||
}
|
||||
return mustDbFrom(float64(val)), nil
|
||||
}
|
||||
|
||||
// SetStripMicGain sets the phantom gain for a specific strip (1-based indexing)
|
||||
func (c *Client) SetStripMicGain(strip int, gain float32) error {
|
||||
address := fmt.Sprintf("/ch/%02d/mix/gain", strip)
|
||||
return c.SendMessage(address, gain)
|
||||
}
|
||||
|
||||
// StripName requests the name for a specific strip
|
||||
func (c *Client) StripName(strip int) (string, error) {
|
||||
address := fmt.Sprintf("/ch/%02d/config/name", strip)
|
||||
err := c.SendMessage(address)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to send strip name request: %v", err)
|
||||
}
|
||||
|
||||
resp := <-c.respChan
|
||||
val, ok := resp.Arguments[0].(string)
|
||||
if !ok {
|
||||
return "", fmt.Errorf("unexpected argument type for strip name value")
|
||||
}
|
||||
return val, nil
|
||||
}
|
||||
|
||||
// SetStripName sets the name for a specific strip
|
||||
func (c *Client) SetStripName(strip int, name string) error {
|
||||
address := fmt.Sprintf("/ch/%02d/config/name", strip)
|
||||
return c.SendMessage(address, name)
|
||||
}
|
||||
|
||||
// StripColor requests the color for a specific strip
|
||||
func (c *Client) StripColor(strip int) (int32, error) {
|
||||
address := fmt.Sprintf("/ch/%02d/config/color", strip)
|
||||
err := c.SendMessage(address)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("failed to send strip color request: %v", err)
|
||||
}
|
||||
|
||||
resp := <-c.respChan
|
||||
val, ok := resp.Arguments[0].(int32)
|
||||
if !ok {
|
||||
return 0, fmt.Errorf("unexpected argument type for strip color value")
|
||||
}
|
||||
return val, nil
|
||||
}
|
||||
|
||||
// SetStripColor sets the color for a specific strip (0-15)
|
||||
func (c *Client) SetStripColor(strip int, color int32) error {
|
||||
address := fmt.Sprintf("/ch/%02d/config/color", strip)
|
||||
return c.SendMessage(address, color)
|
||||
}
|
||||
|
||||
/* BUS METHODS */
|
||||
|
||||
// BusMute requests the current mute status for a bus
|
||||
|
||||
128
internal/xair/strip.go
Normal file
128
internal/xair/strip.go
Normal file
@ -0,0 +1,128 @@
|
||||
package xair
|
||||
|
||||
import "fmt"
|
||||
|
||||
type Strip struct {
|
||||
client Client
|
||||
}
|
||||
|
||||
func NewStrip(c Client) *Strip {
|
||||
return &Strip{
|
||||
client: c,
|
||||
}
|
||||
}
|
||||
|
||||
// Mute gets the mute status of the specified strip (1-based indexing).
|
||||
func (s *Strip) Mute(strip int) (bool, error) {
|
||||
address := fmt.Sprintf("/ch/%02d/mix/on", strip)
|
||||
err := s.client.SendMessage(address)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
resp := <-s.client.respChan
|
||||
val, ok := resp.Arguments[0].(int32)
|
||||
if !ok {
|
||||
return false, fmt.Errorf("unexpected argument type for strip mute value")
|
||||
}
|
||||
return val == 0, nil
|
||||
}
|
||||
|
||||
// SetMute sets the mute status of the specified strip (1-based indexing).
|
||||
func (s *Strip) SetMute(strip int, muted bool) error {
|
||||
address := fmt.Sprintf("/ch/%02d/mix/on", strip)
|
||||
var value int32 = 0
|
||||
if !muted {
|
||||
value = 1
|
||||
}
|
||||
return s.client.SendMessage(address, value)
|
||||
}
|
||||
|
||||
// Fader gets the fader level of the specified strip (1-based indexing).
|
||||
func (s *Strip) Fader(strip int) (float64, error) {
|
||||
address := fmt.Sprintf("/ch/%02d/mix/fader", strip)
|
||||
err := s.client.SendMessage(address)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
resp := <-s.client.respChan
|
||||
val, ok := resp.Arguments[0].(float32)
|
||||
if !ok {
|
||||
return 0, fmt.Errorf("unexpected argument type for fader value")
|
||||
}
|
||||
|
||||
return mustDbFrom(float64(val)), nil
|
||||
}
|
||||
|
||||
// SetFader sets the fader level of the specified strip (1-based indexing).
|
||||
func (s *Strip) SetFader(strip int, level float64) error {
|
||||
address := fmt.Sprintf("/ch/%02d/mix/fader", strip)
|
||||
return s.client.SendMessage(address, float32(mustDbInto(level)))
|
||||
}
|
||||
|
||||
// MicGain requests the phantom gain for a specific strip (1-based indexing).
|
||||
func (s *Strip) MicGain(strip int) (float64, error) {
|
||||
address := fmt.Sprintf("/ch/%02d/mix/gain", strip)
|
||||
err := s.client.SendMessage(address)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("failed to send strip gain request: %v", err)
|
||||
}
|
||||
|
||||
resp := <-s.client.respChan
|
||||
val, ok := resp.Arguments[0].(float32)
|
||||
if !ok {
|
||||
return 0, fmt.Errorf("unexpected argument type for strip gain value")
|
||||
}
|
||||
return mustDbFrom(float64(val)), nil
|
||||
}
|
||||
|
||||
// SetMicGain sets the phantom gain for a specific strip (1-based indexing).
|
||||
func (s *Strip) SetMicGain(strip int, gain float32) error {
|
||||
address := fmt.Sprintf("/ch/%02d/mix/gain", strip)
|
||||
return s.client.SendMessage(address, gain)
|
||||
}
|
||||
|
||||
// Name requests the name for a specific strip
|
||||
func (s *Strip) Name(strip int) (string, error) {
|
||||
address := fmt.Sprintf("/ch/%02d/config/name", strip)
|
||||
err := s.client.SendMessage(address)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to send strip name request: %v", err)
|
||||
}
|
||||
|
||||
resp := <-s.client.respChan
|
||||
val, ok := resp.Arguments[0].(string)
|
||||
if !ok {
|
||||
return "", fmt.Errorf("unexpected argument type for strip name value")
|
||||
}
|
||||
return val, nil
|
||||
}
|
||||
|
||||
// SetName sets the name for a specific strip
|
||||
func (s *Strip) SetName(strip int, name string) error {
|
||||
address := fmt.Sprintf("/ch/%02d/config/name", strip)
|
||||
return s.client.SendMessage(address, name)
|
||||
}
|
||||
|
||||
// Color requests the color for a specific strip
|
||||
func (s *Strip) Color(strip int) (int32, error) {
|
||||
address := fmt.Sprintf("/ch/%02d/config/color", strip)
|
||||
err := s.client.SendMessage(address)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("failed to send strip color request: %v", err)
|
||||
}
|
||||
|
||||
resp := <-s.client.respChan
|
||||
val, ok := resp.Arguments[0].(int32)
|
||||
if !ok {
|
||||
return 0, fmt.Errorf("unexpected argument type for strip color value")
|
||||
}
|
||||
return val, nil
|
||||
}
|
||||
|
||||
// SetColor sets the color for a specific strip (0-15)
|
||||
func (s *Strip) SetColor(strip int, color int32) error {
|
||||
address := fmt.Sprintf("/ch/%02d/config/color", strip)
|
||||
return s.client.SendMessage(address, color)
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user