mirror of
https://github.com/onyx-and-iris/xair-cli.git
synced 2026-02-26 08:19:11 +00:00
implement Snapshot on Client struct
This commit is contained in:
parent
6f995397a1
commit
66ab937296
@ -4,6 +4,7 @@ var xairAddressMap = map[string]string{
|
|||||||
"strip": "/ch/%02d",
|
"strip": "/ch/%02d",
|
||||||
"bus": "/bus/%01d",
|
"bus": "/bus/%01d",
|
||||||
"headamp": "/headamp/%02d",
|
"headamp": "/headamp/%02d",
|
||||||
|
"snapshot": "/-snap",
|
||||||
}
|
}
|
||||||
|
|
||||||
var x32AddressMap = map[string]string{
|
var x32AddressMap = map[string]string{
|
||||||
|
|||||||
@ -3,6 +3,7 @@ package xair
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/charmbracelet/log"
|
"github.com/charmbracelet/log"
|
||||||
|
|
||||||
@ -19,6 +20,7 @@ type Client struct {
|
|||||||
Strip *Strip
|
Strip *Strip
|
||||||
Bus *Bus
|
Bus *Bus
|
||||||
HeadAmp *HeadAmp
|
HeadAmp *HeadAmp
|
||||||
|
Snapshot *Snapshot
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewClient creates a new XAirClient instance
|
// 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...)
|
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
|
// RequestInfo requests mixer information
|
||||||
func (c *Client) RequestInfo() (error, InfoResponse) {
|
func (c *Client) RequestInfo() (error, InfoResponse) {
|
||||||
err := c.SendMessage("/xinfo")
|
err := c.SendMessage("/xinfo")
|
||||||
|
|||||||
39
internal/xair/snapshot.go
Normal file
39
internal/xair/snapshot.go
Normal 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)
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user