diff --git a/internal/xair/bus.go b/internal/xair/bus.go index 5d9ec7c..1226ee6 100644 --- a/internal/xair/bus.go +++ b/internal/xair/bus.go @@ -3,14 +3,14 @@ package xair import "fmt" type Bus struct { - client *Client + client *client baseAddress string Eq *Eq Comp *Comp } // newBus creates a new Bus instance -func newBus(c *Client) *Bus { +func newBus(c *client) *Bus { return &Bus{ client: c, baseAddress: c.addressMap["bus"], diff --git a/internal/xair/client.go b/internal/xair/client.go index d8ee841..488f401 100644 --- a/internal/xair/client.go +++ b/internal/xair/client.go @@ -9,13 +9,9 @@ import ( "github.com/hypebeast/go-osc/osc" ) -type Client struct { - *engine -} - // XAirClient is a client for controlling XAir mixers type XAirClient struct { - Client + client Main *Main Strip *Strip Bus *Bus @@ -24,9 +20,29 @@ type XAirClient struct { DCA *DCA } +// NewXAirClient creates a new XAirClient instance with optional engine configuration +func NewXAirClient(mixerIP string, mixerPort int, opts ...EngineOption) (*XAirClient, error) { + e, err := newEngine(mixerIP, mixerPort, kindXAir, opts...) + if err != nil { + return nil, err + } + + c := &XAirClient{ + client: client{e}, + } + c.Main = newMainStereo(&c.client) + c.Strip = newStrip(&c.client) + c.Bus = newBus(&c.client) + c.HeadAmp = newHeadAmp(&c.client) + c.Snapshot = newSnapshot(&c.client) + c.DCA = newDCA(&c.client) + + return c, nil +} + // X32Client is a client for controlling X32 mixers type X32Client struct { - Client + client Main *Main MainMono *Main Matrix *Matrix @@ -45,48 +61,32 @@ func NewX32Client(mixerIP string, mixerPort int, opts ...EngineOption) (*X32Clie } c := &X32Client{ - Client: Client{e}, + client: client{e}, } - c.Main = newMainStereo(&c.Client) - c.MainMono = newMainMono(&c.Client) - c.Matrix = newMatrix(&c.Client) - c.Strip = newStrip(&c.Client) - c.Bus = newBus(&c.Client) - c.HeadAmp = newHeadAmp(&c.Client) - c.Snapshot = newSnapshot(&c.Client) - c.DCA = newDCA(&c.Client) + c.Main = newMainStereo(&c.client) + c.MainMono = newMainMono(&c.client) + c.Matrix = newMatrix(&c.client) + c.Strip = newStrip(&c.client) + c.Bus = newBus(&c.client) + c.HeadAmp = newHeadAmp(&c.client) + c.Snapshot = newSnapshot(&c.client) + c.DCA = newDCA(&c.client) return c, nil } -// NewXAirClient creates a new XAirClient instance with optional engine configuration -func NewXAirClient(mixerIP string, mixerPort int, opts ...EngineOption) (*XAirClient, error) { - e, err := newEngine(mixerIP, mixerPort, kindXAir, opts...) - if err != nil { - return nil, err - } - - c := &XAirClient{ - Client: Client{e}, - } - c.Main = newMainStereo(&c.Client) - c.Strip = newStrip(&c.Client) - c.Bus = newBus(&c.Client) - c.HeadAmp = newHeadAmp(&c.Client) - c.Snapshot = newSnapshot(&c.Client) - c.DCA = newDCA(&c.Client) - - return c, nil +type client struct { + *engine } // Start begins listening for messages in a goroutine -func (c *Client) StartListening() { +func (c *client) StartListening() { go c.engine.receiveLoop() log.Debugf("Started listening on %s...", c.engine.conn.LocalAddr().String()) } // Close stops the client and closes the connection -func (c *Client) Close() { +func (c *client) Close() { close(c.engine.done) if c.engine.conn != nil { c.engine.conn.Close() @@ -94,12 +94,12 @@ func (c *Client) Close() { } // SendMessage sends an OSC message to the mixer using the unified connection -func (c *Client) SendMessage(address string, args ...any) error { +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() (*osc.Message, error) { +func (c *client) ReceiveMessage() (*osc.Message, error) { t := time.Tick(c.engine.timeout) select { case <-t: @@ -113,7 +113,7 @@ func (c *Client) ReceiveMessage() (*osc.Message, error) { } // RequestInfo requests mixer information -func (c *Client) RequestInfo() (InfoResponse, error) { +func (c *client) RequestInfo() (InfoResponse, error) { var info InfoResponse err := c.SendMessage("/xinfo") if err != nil { @@ -133,11 +133,11 @@ func (c *Client) RequestInfo() (InfoResponse, error) { } // KeepAlive sends keep-alive message (required for multi-client usage) -func (c *Client) KeepAlive() error { +func (c *client) KeepAlive() error { return c.SendMessage("/xremote") } // RequestStatus requests mixer status -func (c *Client) RequestStatus() error { +func (c *client) RequestStatus() error { return c.SendMessage("/status") } diff --git a/internal/xair/comp.go b/internal/xair/comp.go index 8b1959e..e1d6fde 100644 --- a/internal/xair/comp.go +++ b/internal/xair/comp.go @@ -4,13 +4,13 @@ import "fmt" // Comp represents the compressor parameters. type Comp struct { - client *Client + client *client baseAddress string AddressFunc func(fmtString string, args ...any) string } // Factory function to create Comp instance with optional configuration -func newComp(c *Client, baseAddress string, opts ...CompOption) *Comp { +func newComp(c *client, baseAddress string, opts ...CompOption) *Comp { comp := &Comp{ client: c, baseAddress: fmt.Sprintf("%s/dyn", baseAddress), diff --git a/internal/xair/dca.go b/internal/xair/dca.go index dc9b6ff..6cf2043 100644 --- a/internal/xair/dca.go +++ b/internal/xair/dca.go @@ -3,12 +3,12 @@ package xair import "fmt" type DCA struct { - client *Client + client *client baseAddress string } // newDCA creates a new DCA instance -func newDCA(c *Client) *DCA { +func newDCA(c *client) *DCA { return &DCA{ client: c, baseAddress: c.addressMap["dca"], diff --git a/internal/xair/eq.go b/internal/xair/eq.go index 5b31c40..cb2f6fb 100644 --- a/internal/xair/eq.go +++ b/internal/xair/eq.go @@ -6,13 +6,13 @@ import ( // Eq represents the EQ parameters. type Eq struct { - client *Client + client *client baseAddress string AddressFunc func(fmtString string, args ...any) string } // Factory function to create Eq instance with optional configuration -func newEq(c *Client, baseAddress string, opts ...EqOption) *Eq { +func newEq(c *client, baseAddress string, opts ...EqOption) *Eq { eq := &Eq{ client: c, baseAddress: fmt.Sprintf("%s/eq", baseAddress), diff --git a/internal/xair/gate.go b/internal/xair/gate.go index 058f061..129b2c1 100644 --- a/internal/xair/gate.go +++ b/internal/xair/gate.go @@ -4,13 +4,13 @@ import "fmt" // Gate represents the gate parameters. type Gate struct { - client *Client + client *client baseAddress string AddressFunc func(fmtString string, args ...any) string } // Factory function to create Gate instance with optional configuration -func newGate(c *Client, baseAddress string, opts ...GateOption) *Gate { +func newGate(c *client, baseAddress string, opts ...GateOption) *Gate { gate := &Gate{ client: c, baseAddress: fmt.Sprintf("%s/gate", baseAddress), diff --git a/internal/xair/headamp.go b/internal/xair/headamp.go index a45e61b..458e05b 100644 --- a/internal/xair/headamp.go +++ b/internal/xair/headamp.go @@ -3,12 +3,12 @@ package xair import "fmt" type HeadAmp struct { - client *Client + client *client baseAddress string } // newHeadAmp creates a new HeadAmp instance with the provided client. -func newHeadAmp(c *Client) *HeadAmp { +func newHeadAmp(c *client) *HeadAmp { return &HeadAmp{ client: c, baseAddress: c.addressMap["headamp"], diff --git a/internal/xair/main.go b/internal/xair/main.go index 2e8f7a0..3c7a8a7 100644 --- a/internal/xair/main.go +++ b/internal/xair/main.go @@ -3,14 +3,14 @@ package xair import "fmt" type Main struct { - client *Client + client *client baseAddress string Eq *Eq Comp *Comp } // newMainStereo creates a new Main instance for stereo main output -func newMainStereo(c *Client) *Main { +func newMainStereo(c *client) *Main { addressFunc := func(fmtString string, args ...any) string { return fmtString } @@ -24,7 +24,7 @@ func newMainStereo(c *Client) *Main { } // newMainMono creates a new MainMono instance for mono main output (X32 only) -func newMainMono(c *Client) *Main { +func newMainMono(c *client) *Main { addressFunc := func(fmtString string, args ...any) string { return fmtString } diff --git a/internal/xair/matrix.go b/internal/xair/matrix.go index 7b4d234..bd4e460 100644 --- a/internal/xair/matrix.go +++ b/internal/xair/matrix.go @@ -3,14 +3,14 @@ package xair import "fmt" type Matrix struct { - client *Client + client *client baseAddress string Eq *Eq Comp *Comp } // newMatrix creates a new Matrix instance -func newMatrix(c *Client) *Matrix { +func newMatrix(c *client) *Matrix { return &Matrix{ client: c, baseAddress: c.addressMap["matrix"], diff --git a/internal/xair/snapshot.go b/internal/xair/snapshot.go index a88b042..859ded3 100644 --- a/internal/xair/snapshot.go +++ b/internal/xair/snapshot.go @@ -3,12 +3,12 @@ package xair import "fmt" type Snapshot struct { - client *Client + client *client baseAddress string } // newSnapshot creates a new Snapshot instance -func newSnapshot(c *Client) *Snapshot { +func newSnapshot(c *client) *Snapshot { return &Snapshot{ client: c, baseAddress: c.addressMap["snapshot"], diff --git a/internal/xair/strip.go b/internal/xair/strip.go index 4826fdc..d4b4fb3 100644 --- a/internal/xair/strip.go +++ b/internal/xair/strip.go @@ -3,7 +3,7 @@ package xair import "fmt" type Strip struct { - client *Client + client *client baseAddress string Gate *Gate Eq *Eq @@ -11,7 +11,7 @@ type Strip struct { } // newStrip creates a new Strip instance -func newStrip(c *Client) *Strip { +func newStrip(c *client) *Strip { return &Strip{ client: c, baseAddress: c.addressMap["strip"],