mirror of
https://github.com/onyx-and-iris/xair-cli.git
synced 2026-02-04 07:27:47 +00:00
move bus commands into bus struct
update the cli
This commit is contained in:
parent
19779ae4c1
commit
615a95d9da
14
cmd/bus.go
14
cmd/bus.go
@ -45,7 +45,7 @@ var busMuteCmd = &cobra.Command{
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err := client.SetBusMute(busNum, muted)
|
err := client.Bus.SetMute(busNum, muted)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cmd.PrintErrln("Error setting bus mute status:", err)
|
cmd.PrintErrln("Error setting bus mute status:", err)
|
||||||
return
|
return
|
||||||
@ -79,7 +79,7 @@ For example:
|
|||||||
busIndex := mustConvToInt(args[0])
|
busIndex := mustConvToInt(args[0])
|
||||||
|
|
||||||
if len(args) == 1 {
|
if len(args) == 1 {
|
||||||
level, err := client.BusFader(busIndex)
|
level, err := client.Bus.Fader(busIndex)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cmd.PrintErrln("Error getting bus fader level:", err)
|
cmd.PrintErrln("Error getting bus fader level:", err)
|
||||||
return
|
return
|
||||||
@ -95,7 +95,7 @@ For example:
|
|||||||
|
|
||||||
level := mustConvToFloat64(args[1])
|
level := mustConvToFloat64(args[1])
|
||||||
|
|
||||||
err := client.SetBusFader(busIndex, level)
|
err := client.Bus.SetFader(busIndex, level)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cmd.PrintErrln("Error setting bus fader level:", err)
|
cmd.PrintErrln("Error setting bus fader level:", err)
|
||||||
return
|
return
|
||||||
@ -139,7 +139,7 @@ For example:
|
|||||||
target = mustConvToFloat64(args[1])
|
target = mustConvToFloat64(args[1])
|
||||||
}
|
}
|
||||||
|
|
||||||
currentFader, err := client.BusFader(busIndex)
|
currentFader, err := client.Bus.Fader(busIndex)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cmd.PrintErrln("Error getting current bus fader level:", err)
|
cmd.PrintErrln("Error getting current bus fader level:", err)
|
||||||
return
|
return
|
||||||
@ -156,7 +156,7 @@ For example:
|
|||||||
|
|
||||||
for currentFader > target {
|
for currentFader > target {
|
||||||
currentFader -= 1.0
|
currentFader -= 1.0
|
||||||
err := client.SetBusFader(busIndex, currentFader)
|
err := client.Bus.SetFader(busIndex, currentFader)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cmd.PrintErrln("Error setting bus fader level:", err)
|
cmd.PrintErrln("Error setting bus fader level:", err)
|
||||||
return
|
return
|
||||||
@ -203,7 +203,7 @@ For example:
|
|||||||
target = mustConvToFloat64(args[1])
|
target = mustConvToFloat64(args[1])
|
||||||
}
|
}
|
||||||
|
|
||||||
currentFader, err := client.BusFader(busIndex)
|
currentFader, err := client.Bus.Fader(busIndex)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cmd.PrintErrln("Error getting current bus fader level:", err)
|
cmd.PrintErrln("Error getting current bus fader level:", err)
|
||||||
return
|
return
|
||||||
@ -220,7 +220,7 @@ For example:
|
|||||||
|
|
||||||
for currentFader < target {
|
for currentFader < target {
|
||||||
currentFader += 1.0
|
currentFader += 1.0
|
||||||
err := client.SetBusFader(busIndex, currentFader)
|
err := client.Bus.SetFader(busIndex, currentFader)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cmd.PrintErrln("Error setting bus fader level:", err)
|
cmd.PrintErrln("Error setting bus fader level:", err)
|
||||||
return
|
return
|
||||||
|
|||||||
66
internal/xair/bus.go
Normal file
66
internal/xair/bus.go
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
package xair
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
type Bus struct {
|
||||||
|
client Client
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewBus(c Client) *Bus {
|
||||||
|
return &Bus{
|
||||||
|
client: c,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mute requests the current mute status for a bus
|
||||||
|
func (b *Bus) Mute(bus int) (bool, error) {
|
||||||
|
formatter := b.client.addressMap["bus"]
|
||||||
|
address := fmt.Sprintf(formatter, bus) + "/mix/on"
|
||||||
|
err := b.client.SendMessage(address)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
resp := <-b.client.respChan
|
||||||
|
val, ok := resp.Arguments[0].(int32)
|
||||||
|
if !ok {
|
||||||
|
return false, fmt.Errorf("unexpected argument type for bus mute value")
|
||||||
|
}
|
||||||
|
return val == 0, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetMute sets the mute status for a specific bus (1-based indexing)
|
||||||
|
func (b *Bus) SetMute(bus int, muted bool) error {
|
||||||
|
formatter := b.client.addressMap["bus"]
|
||||||
|
address := fmt.Sprintf(formatter, bus) + "/mix/on"
|
||||||
|
var value int32
|
||||||
|
if !muted {
|
||||||
|
value = 1
|
||||||
|
}
|
||||||
|
return b.client.SendMessage(address, value)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fader requests the current fader level for a bus
|
||||||
|
func (b *Bus) Fader(bus int) (float64, error) {
|
||||||
|
formatter := b.client.addressMap["bus"]
|
||||||
|
address := fmt.Sprintf(formatter, bus) + "/mix/fader"
|
||||||
|
err := b.client.SendMessage(address)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
resp := <-b.client.respChan
|
||||||
|
val, ok := resp.Arguments[0].(float32)
|
||||||
|
if !ok {
|
||||||
|
return 0, fmt.Errorf("unexpected argument type for bus fader value")
|
||||||
|
}
|
||||||
|
|
||||||
|
return mustDbFrom(float64(val)), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetFader sets the fader level for a specific bus (1-based indexing)
|
||||||
|
func (b *Bus) SetFader(bus int, level float64) error {
|
||||||
|
formatter := b.client.addressMap["bus"]
|
||||||
|
address := fmt.Sprintf(formatter, bus) + "/mix/fader"
|
||||||
|
return b.client.SendMessage(address, float32(mustDbInto(level)))
|
||||||
|
}
|
||||||
@ -16,6 +16,7 @@ type parser interface {
|
|||||||
type Client struct {
|
type Client struct {
|
||||||
engine
|
engine
|
||||||
Strip *Strip
|
Strip *Strip
|
||||||
|
Bus *Bus
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewClient creates a new XAirClient instance
|
// NewClient creates a new XAirClient instance
|
||||||
@ -56,6 +57,7 @@ func NewClient(mixerIP string, mixerPort int, opts ...Option) (*Client, error) {
|
|||||||
engine: *e,
|
engine: *e,
|
||||||
}
|
}
|
||||||
c.Strip = NewStrip(*c)
|
c.Strip = NewStrip(*c)
|
||||||
|
c.Bus = NewBus(*c)
|
||||||
|
|
||||||
return c, nil
|
return c, nil
|
||||||
}
|
}
|
||||||
@ -106,61 +108,6 @@ func (c *Client) RequestStatus() error {
|
|||||||
return c.SendMessage("/status")
|
return c.SendMessage("/status")
|
||||||
}
|
}
|
||||||
|
|
||||||
/* BUS METHODS */
|
|
||||||
|
|
||||||
// BusMute requests the current mute status for a bus
|
|
||||||
func (c *Client) BusMute(bus int) (bool, error) {
|
|
||||||
formatter := c.addressMap["bus"]
|
|
||||||
address := fmt.Sprintf(formatter, bus) + "/mix/on"
|
|
||||||
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 bus mute value")
|
|
||||||
}
|
|
||||||
return val == 0, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetBusMute sets the mute status for a specific bus (1-based indexing)
|
|
||||||
func (c *Client) SetBusMute(bus int, muted bool) error {
|
|
||||||
formatter := c.addressMap["bus"]
|
|
||||||
address := fmt.Sprintf(formatter, bus) + "/mix/on"
|
|
||||||
var value int32
|
|
||||||
if !muted {
|
|
||||||
value = 1
|
|
||||||
}
|
|
||||||
return c.SendMessage(address, value)
|
|
||||||
}
|
|
||||||
|
|
||||||
// BusFader requests the current fader level for a bus
|
|
||||||
func (c *Client) BusFader(bus int) (float64, error) {
|
|
||||||
formatter := c.addressMap["bus"]
|
|
||||||
address := fmt.Sprintf(formatter, bus) + "/mix/fader"
|
|
||||||
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 bus fader value")
|
|
||||||
}
|
|
||||||
|
|
||||||
return mustDbFrom(float64(val)), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetBusFader sets the fader level for a specific bus (1-based indexing)
|
|
||||||
func (c *Client) SetBusFader(bus int, level float64) error {
|
|
||||||
formatter := c.addressMap["bus"]
|
|
||||||
address := fmt.Sprintf(formatter, bus) + "/mix/fader"
|
|
||||||
return c.SendMessage(address, float32(mustDbInto(level)))
|
|
||||||
}
|
|
||||||
|
|
||||||
/* MAIN LR METHODS */
|
/* MAIN LR METHODS */
|
||||||
|
|
||||||
// MainLRFader requests the current main L/R fader level
|
// MainLRFader requests the current main L/R fader level
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user