mirror of
https://github.com/onyx-and-iris/xair-cli.git
synced 2026-02-26 00:09:11 +00:00
implement Matrix type
add comp,eq factory methods for Matrix type update address maps
This commit is contained in:
parent
65d20408b1
commit
904e6c02d8
@ -10,7 +10,8 @@ var xairAddressMap = map[string]string{
|
||||
|
||||
var x32AddressMap = map[string]string{
|
||||
"main": "/main/st",
|
||||
"mainmono": "/main/mono",
|
||||
"mainmono": "/main/m",
|
||||
"matrix": "/mtx/%02d",
|
||||
"strip": "/ch/%02d",
|
||||
"bus": "/bus/%02d",
|
||||
"headamp": "/headamp/%03d",
|
||||
|
||||
@ -24,9 +24,7 @@ func newCompForStrip(c *Client) *Comp {
|
||||
return &Comp{
|
||||
client: c,
|
||||
baseAddress: c.addressMap["strip"],
|
||||
AddressFunc: func(fmtString string, args ...any) string {
|
||||
return fmt.Sprintf(fmtString, args...)
|
||||
},
|
||||
AddressFunc: fmt.Sprintf,
|
||||
}
|
||||
}
|
||||
|
||||
@ -35,9 +33,16 @@ func newCompForBus(c *Client) *Comp {
|
||||
return &Comp{
|
||||
client: c,
|
||||
baseAddress: c.addressMap["bus"],
|
||||
AddressFunc: func(fmtString string, args ...any) string {
|
||||
return fmt.Sprintf(fmtString, args...)
|
||||
},
|
||||
AddressFunc: fmt.Sprintf,
|
||||
}
|
||||
}
|
||||
|
||||
// Factory function to create Comp instance for Matrix
|
||||
func newCompForMatrix(c *Client) *Comp {
|
||||
return &Comp{
|
||||
client: c,
|
||||
baseAddress: c.addressMap["matrix"],
|
||||
AddressFunc: fmt.Sprintf,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -26,9 +26,7 @@ func newEqForStrip(c *Client) *Eq {
|
||||
return &Eq{
|
||||
client: c,
|
||||
baseAddress: c.addressMap["strip"],
|
||||
AddressFunc: func(fmtString string, args ...any) string {
|
||||
return fmt.Sprintf(fmtString, args...)
|
||||
},
|
||||
AddressFunc: fmt.Sprintf,
|
||||
}
|
||||
}
|
||||
|
||||
@ -37,9 +35,16 @@ func newEqForBus(c *Client) *Eq {
|
||||
return &Eq{
|
||||
client: c,
|
||||
baseAddress: c.addressMap["bus"],
|
||||
AddressFunc: func(fmtString string, args ...any) string {
|
||||
return fmt.Sprintf(fmtString, args...)
|
||||
},
|
||||
AddressFunc: fmt.Sprintf,
|
||||
}
|
||||
}
|
||||
|
||||
// Factory function to create Eq instance for Matrix
|
||||
func newEqForMatrix(c *Client) *Eq {
|
||||
return &Eq{
|
||||
client: c,
|
||||
baseAddress: c.addressMap["matrix"],
|
||||
AddressFunc: fmt.Sprintf,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -9,6 +9,7 @@ type Main struct {
|
||||
Comp *Comp
|
||||
}
|
||||
|
||||
// newMainStereo creates a new Main instance for stereo main output
|
||||
func newMainStereo(c *Client) *Main {
|
||||
return &Main{
|
||||
client: c,
|
||||
@ -18,14 +19,13 @@ func newMainStereo(c *Client) *Main {
|
||||
}
|
||||
}
|
||||
|
||||
/* Still considering the best way to implement main mono support.
|
||||
// newMainMono creates a new MainMono instance for mono main output (X32 only)
|
||||
func newMainMono(c *Client) *Main {
|
||||
return &Main{
|
||||
baseAddress: c.addressMap["mainmono"],
|
||||
client: c,
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
// Fader requests the current main L/R fader level
|
||||
func (m *Main) Fader() (float64, error) {
|
||||
|
||||
74
internal/xair/matrix.go
Normal file
74
internal/xair/matrix.go
Normal file
@ -0,0 +1,74 @@
|
||||
package xair
|
||||
|
||||
import "fmt"
|
||||
|
||||
type Matrix struct {
|
||||
client *Client
|
||||
baseAddress string
|
||||
Eq *Eq
|
||||
Comp *Comp
|
||||
}
|
||||
|
||||
// newMatrix creates a new Matrix instance
|
||||
func newMatrix(c *Client) *Matrix {
|
||||
return &Matrix{
|
||||
client: c,
|
||||
baseAddress: c.addressMap["matrix"],
|
||||
Eq: newEqForMatrix(c),
|
||||
Comp: newCompForMatrix(c),
|
||||
}
|
||||
}
|
||||
|
||||
// Fader requests the current main L/R fader level
|
||||
func (m *Matrix) Fader(index int) (float64, error) {
|
||||
address := fmt.Sprintf(m.baseAddress, index) + "/mix/fader"
|
||||
err := m.client.SendMessage(address)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
msg, err := m.client.ReceiveMessage()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
val, ok := msg.Arguments[0].(float32)
|
||||
if !ok {
|
||||
return 0, fmt.Errorf("unexpected argument type for matrix fader value")
|
||||
}
|
||||
return mustDbFrom(float64(val)), nil
|
||||
}
|
||||
|
||||
// SetFader sets the matrix fader level
|
||||
func (m *Matrix) SetFader(index int, level float64) error {
|
||||
address := fmt.Sprintf(m.baseAddress, index) + "/mix/fader"
|
||||
return m.client.SendMessage(address, float32(mustDbInto(level)))
|
||||
}
|
||||
|
||||
// Mute requests the current matrix mute status
|
||||
func (m *Matrix) Mute(index int) (bool, error) {
|
||||
address := fmt.Sprintf(m.baseAddress, index) + "/mix/on"
|
||||
err := m.client.SendMessage(address)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
msg, err := m.client.ReceiveMessage()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
val, ok := msg.Arguments[0].(int32)
|
||||
if !ok {
|
||||
return false, fmt.Errorf("unexpected argument type for matrix mute value")
|
||||
}
|
||||
return val == 0, nil
|
||||
}
|
||||
|
||||
// SetMute sets the matrix mute status
|
||||
func (m *Matrix) SetMute(index int, muted bool) error {
|
||||
address := fmt.Sprintf(m.baseAddress, index) + "/mix/on"
|
||||
var value int32
|
||||
if !muted {
|
||||
value = 1
|
||||
}
|
||||
return m.client.SendMessage(address, value)
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user