mirror of
https://github.com/onyx-and-iris/xair-cli.git
synced 2026-02-03 23:17:47 +00:00
move main methods into Main struct
update the cli
This commit is contained in:
parent
615a95d9da
commit
ad7c910180
16
cmd/main.go
16
cmd/main.go
@ -44,7 +44,7 @@ For example:
|
||||
}
|
||||
|
||||
if len(args) == 0 {
|
||||
resp, err := client.MainLRMute()
|
||||
resp, err := client.Main.Mute()
|
||||
if err != nil {
|
||||
cmd.PrintErrln("Error getting main LR mute status:", err)
|
||||
return
|
||||
@ -58,7 +58,7 @@ For example:
|
||||
muted = true
|
||||
}
|
||||
|
||||
err := client.SetMainLRMute(muted)
|
||||
err := client.Main.SetMute(muted)
|
||||
if err != nil {
|
||||
cmd.PrintErrln("Error setting main LR mute status:", err)
|
||||
return
|
||||
@ -91,7 +91,7 @@ For example:
|
||||
}
|
||||
|
||||
if len(args) == 0 {
|
||||
resp, err := client.MainLRFader()
|
||||
resp, err := client.Main.Fader()
|
||||
if err != nil {
|
||||
cmd.PrintErrln("Error getting main LR fader:", err)
|
||||
return
|
||||
@ -100,7 +100,7 @@ For example:
|
||||
return
|
||||
}
|
||||
|
||||
err := client.SetMainLRFader(mustConvToFloat64(args[0]))
|
||||
err := client.Main.SetFader(mustConvToFloat64(args[0]))
|
||||
if err != nil {
|
||||
cmd.PrintErrln("Error setting main LR fader:", err)
|
||||
return
|
||||
@ -140,7 +140,7 @@ This command will fade out the main output to the specified dB level.
|
||||
target = mustConvToFloat64(args[0])
|
||||
}
|
||||
|
||||
currentFader, err := client.MainLRFader()
|
||||
currentFader, err := client.Main.Fader()
|
||||
if err != nil {
|
||||
cmd.PrintErrln("Error getting current main LR fader:", err)
|
||||
return
|
||||
@ -158,7 +158,7 @@ This command will fade out the main output to the specified dB level.
|
||||
|
||||
for currentFader > target {
|
||||
currentFader -= 1.0
|
||||
err = client.SetMainLRFader(currentFader)
|
||||
err = client.Main.SetFader(currentFader)
|
||||
if err != nil {
|
||||
cmd.PrintErrln("Error setting main LR fader:", err)
|
||||
return
|
||||
@ -200,7 +200,7 @@ This command will fade in the main output to the specified dB level.
|
||||
target = mustConvToFloat64(args[0])
|
||||
}
|
||||
|
||||
currentFader, err := client.MainLRFader()
|
||||
currentFader, err := client.Main.Fader()
|
||||
if err != nil {
|
||||
cmd.PrintErrln("Error getting current main LR fader:", err)
|
||||
return
|
||||
@ -218,7 +218,7 @@ This command will fade in the main output to the specified dB level.
|
||||
|
||||
for currentFader < target {
|
||||
currentFader += 1.0
|
||||
err = client.SetMainLRFader(currentFader)
|
||||
err = client.Main.SetFader(currentFader)
|
||||
if err != nil {
|
||||
cmd.PrintErrln("Error setting main LR fader:", err)
|
||||
return
|
||||
|
||||
@ -15,6 +15,7 @@ type parser interface {
|
||||
|
||||
type Client struct {
|
||||
engine
|
||||
Main *Main
|
||||
Strip *Strip
|
||||
Bus *Bus
|
||||
}
|
||||
@ -56,6 +57,7 @@ func NewClient(mixerIP string, mixerPort int, opts ...Option) (*Client, error) {
|
||||
c := &Client{
|
||||
engine: *e,
|
||||
}
|
||||
c.Main = newMain(*c)
|
||||
c.Strip = NewStrip(*c)
|
||||
c.Bus = NewBus(*c)
|
||||
|
||||
@ -107,49 +109,3 @@ func (c *Client) KeepAlive() error {
|
||||
func (c *Client) RequestStatus() error {
|
||||
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
57
internal/xair/main.go
Normal 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)
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user