implement Snapshot on Client struct

This commit is contained in:
onyx-and-iris 2026-02-04 11:15:52 +00:00
parent 6f995397a1
commit 66ab937296
3 changed files with 63 additions and 7 deletions

View File

@ -4,6 +4,7 @@ var xairAddressMap = map[string]string{
"strip": "/ch/%02d",
"bus": "/bus/%01d",
"headamp": "/headamp/%02d",
"snapshot": "/-snap",
}
var x32AddressMap = map[string]string{

View File

@ -3,6 +3,7 @@ package xair
import (
"fmt"
"net"
"time"
"github.com/charmbracelet/log"
@ -19,6 +20,7 @@ type Client struct {
Strip *Strip
Bus *Bus
HeadAmp *HeadAmp
Snapshot *Snapshot
}
// NewClient creates a new XAirClient instance
@ -85,6 +87,20 @@ func (c *Client) SendMessage(address string, args ...any) error {
return c.engine.sendToAddress(c.mixerAddr, address, args...)
}
// ReceiveMessage receives an OSC message from the mixer
func (c *Client) ReceiveMessage(timeout time.Duration) (*osc.Message, error) {
t := time.Tick(timeout)
select {
case <-t:
return nil, nil
case val := <-c.respChan:
if val == nil {
return nil, fmt.Errorf("no message received")
}
return val, nil
}
}
// RequestInfo requests mixer information
func (c *Client) RequestInfo() (error, InfoResponse) {
err := c.SendMessage("/xinfo")

39
internal/xair/snapshot.go Normal file
View File

@ -0,0 +1,39 @@
package xair
import "fmt"
type Snapshot struct {
baseAddress string
client *Client
}
func NewSnapshot(c *Client) *Snapshot {
return &Snapshot{
baseAddress: c.addressMap["snapshot"],
client: c,
}
}
// Name sets the name of the snapshot at the given index.
func (s *Snapshot) Name(index int, name string) error {
address := s.baseAddress + fmt.Sprintf("/name/%d", index)
return s.client.SendMessage(address, name)
}
// Load loads the snapshot at the given index.
func (s *Snapshot) Load(index int) error {
address := s.baseAddress + fmt.Sprintf("/load/%d", index)
return s.client.SendMessage(address)
}
// Save saves the current state to the snapshot at the given index.
func (s *Snapshot) Save(index int) error {
address := s.baseAddress + fmt.Sprintf("/save/%d", index)
return s.client.SendMessage(address)
}
// Delete deletes the snapshot at the given index.
func (s *Snapshot) Delete(index int) error {
address := s.baseAddress + fmt.Sprintf("/delete/%d", index)
return s.client.SendMessage(address)
}