From 66ab9372968eadbb75025a7f893f49c190688b3d Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Wed, 4 Feb 2026 11:15:52 +0000 Subject: [PATCH] implement Snapshot on Client struct --- internal/xair/address.go | 7 ++++--- internal/xair/client.go | 24 ++++++++++++++++++++---- internal/xair/snapshot.go | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 7 deletions(-) create mode 100644 internal/xair/snapshot.go diff --git a/internal/xair/address.go b/internal/xair/address.go index f4e0682..5aff65f 100644 --- a/internal/xair/address.go +++ b/internal/xair/address.go @@ -1,9 +1,10 @@ package xair var xairAddressMap = map[string]string{ - "strip": "/ch/%02d", - "bus": "/bus/%01d", - "headamp": "/headamp/%02d", + "strip": "/ch/%02d", + "bus": "/bus/%01d", + "headamp": "/headamp/%02d", + "snapshot": "/-snap", } var x32AddressMap = map[string]string{ diff --git a/internal/xair/client.go b/internal/xair/client.go index 8f753e1..1df86fb 100644 --- a/internal/xair/client.go +++ b/internal/xair/client.go @@ -3,6 +3,7 @@ package xair import ( "fmt" "net" + "time" "github.com/charmbracelet/log" @@ -15,10 +16,11 @@ type parser interface { type Client struct { engine - Main *Main - Strip *Strip - Bus *Bus - HeadAmp *HeadAmp + Main *Main + 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") diff --git a/internal/xair/snapshot.go b/internal/xair/snapshot.go new file mode 100644 index 0000000..98823bf --- /dev/null +++ b/internal/xair/snapshot.go @@ -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) +}