move main methods into Main struct

update the cli
This commit is contained in:
onyx-and-iris 2026-01-31 21:19:38 +00:00
parent 615a95d9da
commit ad7c910180
3 changed files with 67 additions and 54 deletions

View File

@ -44,7 +44,7 @@ For example:
} }
if len(args) == 0 { if len(args) == 0 {
resp, err := client.MainLRMute() resp, err := client.Main.Mute()
if err != nil { if err != nil {
cmd.PrintErrln("Error getting main LR mute status:", err) cmd.PrintErrln("Error getting main LR mute status:", err)
return return
@ -58,7 +58,7 @@ For example:
muted = true muted = true
} }
err := client.SetMainLRMute(muted) err := client.Main.SetMute(muted)
if err != nil { if err != nil {
cmd.PrintErrln("Error setting main LR mute status:", err) cmd.PrintErrln("Error setting main LR mute status:", err)
return return
@ -91,7 +91,7 @@ For example:
} }
if len(args) == 0 { if len(args) == 0 {
resp, err := client.MainLRFader() resp, err := client.Main.Fader()
if err != nil { if err != nil {
cmd.PrintErrln("Error getting main LR fader:", err) cmd.PrintErrln("Error getting main LR fader:", err)
return return
@ -100,7 +100,7 @@ For example:
return return
} }
err := client.SetMainLRFader(mustConvToFloat64(args[0])) err := client.Main.SetFader(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
@ -140,7 +140,7 @@ This command will fade out the main output to the specified dB level.
target = mustConvToFloat64(args[0]) target = mustConvToFloat64(args[0])
} }
currentFader, err := client.MainLRFader() currentFader, err := client.Main.Fader()
if err != nil { if err != nil {
cmd.PrintErrln("Error getting current main LR fader:", err) cmd.PrintErrln("Error getting current main LR fader:", err)
return return
@ -158,7 +158,7 @@ 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
err = client.SetMainLRFader(currentFader) err = client.Main.SetFader(currentFader)
if err != nil { if err != nil {
cmd.PrintErrln("Error setting main LR fader:", err) cmd.PrintErrln("Error setting main LR fader:", err)
return return
@ -200,7 +200,7 @@ This command will fade in the main output to the specified dB level.
target = mustConvToFloat64(args[0]) target = mustConvToFloat64(args[0])
} }
currentFader, err := client.MainLRFader() currentFader, err := client.Main.Fader()
if err != nil { if err != nil {
cmd.PrintErrln("Error getting current main LR fader:", err) cmd.PrintErrln("Error getting current main LR fader:", err)
return return
@ -218,7 +218,7 @@ 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
err = client.SetMainLRFader(currentFader) err = client.Main.SetFader(currentFader)
if err != nil { if err != nil {
cmd.PrintErrln("Error setting main LR fader:", err) cmd.PrintErrln("Error setting main LR fader:", err)
return return

View File

@ -15,6 +15,7 @@ type parser interface {
type Client struct { type Client struct {
engine engine
Main *Main
Strip *Strip Strip *Strip
Bus *Bus Bus *Bus
} }
@ -56,6 +57,7 @@ func NewClient(mixerIP string, mixerPort int, opts ...Option) (*Client, error) {
c := &Client{ c := &Client{
engine: *e, engine: *e,
} }
c.Main = newMain(*c)
c.Strip = NewStrip(*c) c.Strip = NewStrip(*c)
c.Bus = NewBus(*c) c.Bus = NewBus(*c)
@ -107,49 +109,3 @@ func (c *Client) KeepAlive() error {
func (c *Client) RequestStatus() error { func (c *Client) RequestStatus() error {
return c.SendMessage("/status") return c.SendMessage("/status")
} }
/* MAIN LR METHODS */
// MainLRFader requests the current main L/R fader level
func (c *Client) MainLRFader() (float64, error) {
err := c.SendMessage("/lr/mix/fader")
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 main LR fader value")
}
return mustDbFrom(float64(val)), nil
}
// SetMainLRFader sets the main L/R fader level
func (c *Client) SetMainLRFader(level float64) error {
return c.SendMessage("/lr/mix/fader", float32(mustDbInto(level)))
}
// MainLRMute requests the current main L/R mute status
func (c *Client) MainLRMute() (bool, error) {
err := c.SendMessage("/lr/mix/on")
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 main LR mute value")
}
return val == 0, nil
}
// SetMainLRMute sets the main L/R mute status
func (c *Client) SetMainLRMute(muted bool) error {
var value int32
if !muted {
value = 1
}
return c.SendMessage("/lr/mix/on", value)
}

57
internal/xair/main.go Normal file
View File

@ -0,0 +1,57 @@
package xair
import "fmt"
type Main struct {
client Client
}
func newMain(c Client) *Main {
return &Main{
client: c,
}
}
// Fader requests the current main L/R fader level
func (m *Main) Fader() (float64, error) {
err := m.client.SendMessage("/lr/mix/fader")
if err != nil {
return 0, err
}
resp := <-m.client.respChan
val, ok := resp.Arguments[0].(float32)
if !ok {
return 0, fmt.Errorf("unexpected argument type for main LR fader value")
}
return mustDbFrom(float64(val)), nil
}
// SetFader sets the main L/R fader level
func (m *Main) SetFader(level float64) error {
return m.client.SendMessage("/lr/mix/fader", float32(mustDbInto(level)))
}
// Mute requests the current main L/R mute status
func (m *Main) Mute() (bool, error) {
err := m.client.SendMessage("/lr/mix/on")
if err != nil {
return false, err
}
resp := <-m.client.respChan
val, ok := resp.Arguments[0].(int32)
if !ok {
return false, fmt.Errorf("unexpected argument type for main LR mute value")
}
return val == 0, nil
}
// SetMute sets the main L/R mute status
func (m *Main) SetMute(muted bool) error {
var value int32
if !muted {
value = 1
}
return m.client.SendMessage("/lr/mix/on", value)
}