mirror of
https://github.com/onyx-and-iris/xair-cli.git
synced 2026-04-09 02:13:35 +00:00
move bus commands into bus struct
update the cli
This commit is contained in:
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)))
|
||||
}
|
||||
Reference in New Issue
Block a user