mirror of
https://github.com/onyx-and-iris/xair-cli.git
synced 2026-04-09 02:13:35 +00:00
main comp/eq commands implemented
factory methods unexported lr.go renamed to main.go main.go renamed to cli.go
This commit is contained in:
@@ -1,10 +1,24 @@
|
||||
package xair
|
||||
|
||||
import "fmt"
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type Eq struct {
|
||||
client *Client
|
||||
baseAddress string
|
||||
AddressFunc func(fmtString string, args ...any) string
|
||||
}
|
||||
|
||||
// Factory function to create Eq instance for Main
|
||||
func newEqForMain(c *Client) *Eq {
|
||||
return &Eq{
|
||||
client: c,
|
||||
baseAddress: c.addressMap["main"],
|
||||
AddressFunc: func(fmtString string, args ...any) string {
|
||||
return fmtString
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// Factory function to create Eq instance for Strip
|
||||
@@ -12,6 +26,9 @@ 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...)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,12 +37,15 @@ 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...)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// On retrieves the on/off status of the EQ for a specific strip or bus (1-based indexing).
|
||||
func (e *Eq) On(index int) (bool, error) {
|
||||
address := fmt.Sprintf(e.baseAddress, index) + "/eq/on"
|
||||
address := e.AddressFunc(e.baseAddress, index) + "/eq/on"
|
||||
err := e.client.SendMessage(address)
|
||||
if err != nil {
|
||||
return false, err
|
||||
@@ -44,7 +64,7 @@ func (e *Eq) On(index int) (bool, error) {
|
||||
|
||||
// SetOn sets the on/off status of the EQ for a specific strip or bus (1-based indexing).
|
||||
func (e *Eq) SetOn(index int, on bool) error {
|
||||
address := fmt.Sprintf(e.baseAddress, index) + "/eq/on"
|
||||
address := e.AddressFunc(e.baseAddress, index) + "/eq/on"
|
||||
var value int32
|
||||
if on {
|
||||
value = 1
|
||||
@@ -53,7 +73,7 @@ func (e *Eq) SetOn(index int, on bool) error {
|
||||
}
|
||||
|
||||
func (e *Eq) Mode(index int) (string, error) {
|
||||
address := fmt.Sprintf(e.baseAddress, index) + "/eq/mode"
|
||||
address := e.AddressFunc(e.baseAddress, index) + "/eq/mode"
|
||||
err := e.client.SendMessage(address)
|
||||
if err != nil {
|
||||
return "", err
|
||||
@@ -73,14 +93,14 @@ func (e *Eq) Mode(index int) (string, error) {
|
||||
}
|
||||
|
||||
func (e *Eq) SetMode(index int, mode string) error {
|
||||
address := fmt.Sprintf(e.baseAddress, index) + "/eq/mode"
|
||||
address := e.AddressFunc(e.baseAddress, index) + "/eq/mode"
|
||||
possibleModes := []string{"peq", "geq", "teq"}
|
||||
return e.client.SendMessage(address, int32(indexOf(possibleModes, mode)))
|
||||
}
|
||||
|
||||
// Gain retrieves the gain for a specific EQ band on a strip or bus (1-based indexing).
|
||||
func (e *Eq) Gain(index int, band int) (float64, error) {
|
||||
address := fmt.Sprintf(e.baseAddress, index) + fmt.Sprintf("/eq/%d/g", band)
|
||||
address := e.AddressFunc(e.baseAddress, index) + fmt.Sprintf("/eq/%d/g", band)
|
||||
err := e.client.SendMessage(address)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
@@ -99,13 +119,13 @@ func (e *Eq) Gain(index int, band int) (float64, error) {
|
||||
|
||||
// SetGain sets the gain for a specific EQ band on a strip or bus (1-based indexing).
|
||||
func (e *Eq) SetGain(index int, band int, gain float64) error {
|
||||
address := fmt.Sprintf(e.baseAddress, index) + fmt.Sprintf("/eq/%d/g", band)
|
||||
address := e.AddressFunc(e.baseAddress, index) + fmt.Sprintf("/eq/%d/g", band)
|
||||
return e.client.SendMessage(address, float32(linSet(-15, 15, gain)))
|
||||
}
|
||||
|
||||
// Frequency retrieves the frequency for a specific EQ band on a strip or bus (1-based indexing).
|
||||
func (e *Eq) Frequency(index int, band int) (float64, error) {
|
||||
address := fmt.Sprintf(e.baseAddress, index) + fmt.Sprintf("/eq/%d/f", band)
|
||||
address := e.AddressFunc(e.baseAddress, index) + fmt.Sprintf("/eq/%d/f", band)
|
||||
err := e.client.SendMessage(address)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
@@ -124,13 +144,13 @@ func (e *Eq) Frequency(index int, band int) (float64, error) {
|
||||
|
||||
// SetFrequency sets the frequency for a specific EQ band on a strip or bus (1-based indexing).
|
||||
func (e *Eq) SetFrequency(index int, band int, frequency float64) error {
|
||||
address := fmt.Sprintf(e.baseAddress, index) + fmt.Sprintf("/eq/%d/f", band)
|
||||
address := e.AddressFunc(e.baseAddress, index) + fmt.Sprintf("/eq/%d/f", band)
|
||||
return e.client.SendMessage(address, float32(logSet(20, 20000, frequency)))
|
||||
}
|
||||
|
||||
// Q retrieves the Q factor for a specific EQ band on a strip or bus (1-based indexing).
|
||||
func (e *Eq) Q(index int, band int) (float64, error) {
|
||||
address := fmt.Sprintf(e.baseAddress, index) + fmt.Sprintf("/eq/%d/q", band)
|
||||
address := e.AddressFunc(e.baseAddress, index) + fmt.Sprintf("/eq/%d/q", band)
|
||||
err := e.client.SendMessage(address)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
@@ -149,13 +169,13 @@ func (e *Eq) Q(index int, band int) (float64, error) {
|
||||
|
||||
// SetQ sets the Q factor for a specific EQ band on a strip or bus (1-based indexing).
|
||||
func (e *Eq) SetQ(index int, band int, q float64) error {
|
||||
address := fmt.Sprintf(e.baseAddress, index) + fmt.Sprintf("/eq/%d/q", band)
|
||||
address := e.AddressFunc(e.baseAddress, index) + fmt.Sprintf("/eq/%d/q", band)
|
||||
return e.client.SendMessage(address, float32(1.0-logSet(0.3, 10, q)))
|
||||
}
|
||||
|
||||
// Type retrieves the type for a specific EQ band on a strip or bus (1-based indexing).
|
||||
func (e *Eq) Type(index int, band int) (string, error) {
|
||||
address := fmt.Sprintf(e.baseAddress, index) + fmt.Sprintf("/eq/%d/type", band)
|
||||
address := e.AddressFunc(e.baseAddress, index) + fmt.Sprintf("/eq/%d/type", band)
|
||||
err := e.client.SendMessage(address)
|
||||
if err != nil {
|
||||
return "", err
|
||||
@@ -176,7 +196,7 @@ func (e *Eq) Type(index int, band int) (string, error) {
|
||||
|
||||
// SetType sets the type for a specific EQ band on a strip or bus (1-based indexing).
|
||||
func (e *Eq) SetType(index int, band int, eqType string) error {
|
||||
address := fmt.Sprintf(e.baseAddress, index) + fmt.Sprintf("/eq/%d/type", band)
|
||||
address := e.AddressFunc(e.baseAddress, index) + fmt.Sprintf("/eq/%d/type", band)
|
||||
possibleTypes := []string{"lcut", "lshv", "peq", "veq", "hshv", "hcut"}
|
||||
return e.client.SendMessage(address, int32(indexOf(possibleTypes, eqType)))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user