use addressMap in strip struct

This commit is contained in:
onyx-and-iris 2026-02-01 00:53:32 +00:00
parent d894cc1317
commit 64b4be032f
2 changed files with 20 additions and 16 deletions

View File

@ -1,10 +1,12 @@
package xair package xair
var xairAddressMap = map[string]string{ var xairAddressMap = map[string]string{
"strip": "/ch/%02d",
"bus": "/bus/%01d", "bus": "/bus/%01d",
} }
var x32AddressMap = map[string]string{ var x32AddressMap = map[string]string{
"strip": "/ch/%02d",
"bus": "/bus/%02d", "bus": "/bus/%02d",
} }

View File

@ -3,18 +3,20 @@ package xair
import "fmt" import "fmt"
type Strip struct { type Strip struct {
baseAddress string
client Client client Client
} }
func NewStrip(c Client) *Strip { func NewStrip(c Client) *Strip {
return &Strip{ return &Strip{
baseAddress: c.addressMap["strip"],
client: c, client: c,
} }
} }
// Mute gets the mute status of the specified strip (1-based indexing). // Mute gets the mute status of the specified strip (1-based indexing).
func (s *Strip) Mute(strip int) (bool, error) { func (s *Strip) Mute(strip int) (bool, error) {
address := fmt.Sprintf("/ch/%02d/mix/on", strip) address := fmt.Sprintf(s.baseAddress, strip) + "/mix/on"
err := s.client.SendMessage(address) err := s.client.SendMessage(address)
if err != nil { if err != nil {
return false, err return false, err
@ -30,7 +32,7 @@ func (s *Strip) Mute(strip int) (bool, error) {
// SetMute sets the mute status of the specified strip (1-based indexing). // SetMute sets the mute status of the specified strip (1-based indexing).
func (s *Strip) SetMute(strip int, muted bool) error { func (s *Strip) SetMute(strip int, muted bool) error {
address := fmt.Sprintf("/ch/%02d/mix/on", strip) address := fmt.Sprintf(s.baseAddress, strip) + "/mix/on"
var value int32 = 0 var value int32 = 0
if !muted { if !muted {
value = 1 value = 1
@ -40,7 +42,7 @@ func (s *Strip) SetMute(strip int, muted bool) error {
// Fader gets the fader level of the specified strip (1-based indexing). // Fader gets the fader level of the specified strip (1-based indexing).
func (s *Strip) Fader(strip int) (float64, error) { func (s *Strip) Fader(strip int) (float64, error) {
address := fmt.Sprintf("/ch/%02d/mix/fader", strip) address := fmt.Sprintf(s.baseAddress, strip) + "/mix/fader"
err := s.client.SendMessage(address) err := s.client.SendMessage(address)
if err != nil { if err != nil {
return 0, err return 0, err
@ -57,13 +59,13 @@ func (s *Strip) Fader(strip int) (float64, error) {
// SetFader sets the fader level of the specified strip (1-based indexing). // SetFader sets the fader level of the specified strip (1-based indexing).
func (s *Strip) SetFader(strip int, level float64) error { func (s *Strip) SetFader(strip int, level float64) error {
address := fmt.Sprintf("/ch/%02d/mix/fader", strip) address := fmt.Sprintf(s.baseAddress, strip) + "/mix/fader"
return s.client.SendMessage(address, float32(mustDbInto(level))) return s.client.SendMessage(address, float32(mustDbInto(level)))
} }
// MicGain requests the phantom gain for a specific strip (1-based indexing). // MicGain requests the phantom gain for a specific strip (1-based indexing).
func (s *Strip) MicGain(strip int) (float64, error) { func (s *Strip) MicGain(strip int) (float64, error) {
address := fmt.Sprintf("/ch/%02d/mix/gain", strip) address := fmt.Sprintf(s.baseAddress, strip) + "/mix/gain"
err := s.client.SendMessage(address) err := s.client.SendMessage(address)
if err != nil { if err != nil {
return 0, fmt.Errorf("failed to send strip gain request: %v", err) return 0, fmt.Errorf("failed to send strip gain request: %v", err)
@ -79,13 +81,13 @@ func (s *Strip) MicGain(strip int) (float64, error) {
// SetMicGain sets the phantom gain for a specific strip (1-based indexing). // SetMicGain sets the phantom gain for a specific strip (1-based indexing).
func (s *Strip) SetMicGain(strip int, gain float32) error { func (s *Strip) SetMicGain(strip int, gain float32) error {
address := fmt.Sprintf("/ch/%02d/mix/gain", strip) address := fmt.Sprintf(s.baseAddress, strip) + "/mix/gain"
return s.client.SendMessage(address, gain) return s.client.SendMessage(address, gain)
} }
// Name requests the name for a specific strip // Name requests the name for a specific strip
func (s *Strip) Name(strip int) (string, error) { func (s *Strip) Name(strip int) (string, error) {
address := fmt.Sprintf("/ch/%02d/config/name", strip) address := fmt.Sprintf(s.baseAddress, strip) + "/config/name"
err := s.client.SendMessage(address) err := s.client.SendMessage(address)
if err != nil { if err != nil {
return "", fmt.Errorf("failed to send strip name request: %v", err) return "", fmt.Errorf("failed to send strip name request: %v", err)
@ -101,13 +103,13 @@ func (s *Strip) Name(strip int) (string, error) {
// SetName sets the name for a specific strip // SetName sets the name for a specific strip
func (s *Strip) SetName(strip int, name string) error { func (s *Strip) SetName(strip int, name string) error {
address := fmt.Sprintf("/ch/%02d/config/name", strip) address := fmt.Sprintf(s.baseAddress, strip) + "/config/name"
return s.client.SendMessage(address, name) return s.client.SendMessage(address, name)
} }
// Color requests the color for a specific strip // Color requests the color for a specific strip
func (s *Strip) Color(strip int) (int32, error) { func (s *Strip) Color(strip int) (int32, error) {
address := fmt.Sprintf("/ch/%02d/config/color", strip) address := fmt.Sprintf(s.baseAddress, strip) + "/config/color"
err := s.client.SendMessage(address) err := s.client.SendMessage(address)
if err != nil { if err != nil {
return 0, fmt.Errorf("failed to send strip color request: %v", err) return 0, fmt.Errorf("failed to send strip color request: %v", err)
@ -123,13 +125,13 @@ func (s *Strip) Color(strip int) (int32, error) {
// SetColor sets the color for a specific strip (0-15) // SetColor sets the color for a specific strip (0-15)
func (s *Strip) SetColor(strip int, color int32) error { func (s *Strip) SetColor(strip int, color int32) error {
address := fmt.Sprintf("/ch/%02d/config/color", strip) address := fmt.Sprintf(s.baseAddress, strip) + "/config/color"
return s.client.SendMessage(address, color) return s.client.SendMessage(address, color)
} }
// Sends requests the sends level for a mixbus. // Sends requests the sends level for a mixbus.
func (s *Strip) SendLevel(strip int, bus int) (float64, error) { func (s *Strip) SendLevel(strip int, bus int) (float64, error) {
address := fmt.Sprintf("/ch/%02d/mix/%02d/level", strip, bus) address := fmt.Sprintf(s.baseAddress, strip) + fmt.Sprintf("/mix/%02d/level", bus)
err := s.client.SendMessage(address) err := s.client.SendMessage(address)
if err != nil { if err != nil {
return 0, fmt.Errorf("failed to send strip send level request: %v", err) return 0, fmt.Errorf("failed to send strip send level request: %v", err)
@ -145,6 +147,6 @@ func (s *Strip) SendLevel(strip int, bus int) (float64, error) {
// SetSendLevel sets the sends level for a mixbus. // SetSendLevel sets the sends level for a mixbus.
func (s *Strip) SetSendLevel(strip int, bus int, level float64) error { func (s *Strip) SetSendLevel(strip int, bus int, level float64) error {
address := fmt.Sprintf("/ch/%02d/mix/%02d/level", strip, bus) address := fmt.Sprintf(s.baseAddress, strip) + fmt.Sprintf("/mix/%02d/level", bus)
return s.client.SendMessage(address, float32(mustDbInto(level))) return s.client.SendMessage(address, float32(mustDbInto(level)))
} }