2026-02-01 15:09:38 +00:00

91 lines
2.3 KiB
Go

package xair
import "fmt"
type Bus struct {
baseAddress string
client *Client
Eq *Eq
Comp *Comp
}
func NewBus(c *Client) *Bus {
return &Bus{
baseAddress: c.addressMap["bus"],
client: c,
Eq: newEqForBus(c),
Comp: newCompForBus(c),
}
}
// Mute requests the current mute status for a bus
func (b *Bus) Mute(bus int) (bool, error) {
address := fmt.Sprintf(b.baseAddress, 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 {
address := fmt.Sprintf(b.baseAddress, 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) {
address := fmt.Sprintf(b.baseAddress, 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 {
address := fmt.Sprintf(b.baseAddress, bus) + "/mix/fader"
return b.client.SendMessage(address, float32(mustDbInto(level)))
}
// Name requests the name for a specific bus
func (b *Bus) Name(bus int) (string, error) {
address := fmt.Sprintf(b.baseAddress, bus) + "/config/name"
err := b.client.SendMessage(address)
if err != nil {
return "", fmt.Errorf("failed to send bus name request: %v", err)
}
resp := <-b.client.respChan
val, ok := resp.Arguments[0].(string)
if !ok {
return "", fmt.Errorf("unexpected argument type for bus name value")
}
return val, nil
}
// SetName sets the name for a specific bus
func (b *Bus) SetName(bus int, name string) error {
address := fmt.Sprintf(b.baseAddress, bus) + "/config/name"
return b.client.SendMessage(address, name)
}