mirror of
https://github.com/onyx-and-iris/xair-cli.git
synced 2026-04-08 18:03:37 +00:00
implement eq type/mode/gain/freq/q commands for strip/bus
This commit is contained in:
@@ -49,6 +49,26 @@ func (e *Eq) SetOn(index int, on bool) error {
|
||||
return e.client.SendMessage(address, value)
|
||||
}
|
||||
|
||||
func (e *Eq) Mode(index int) (int, error) {
|
||||
address := fmt.Sprintf(e.baseAddress, index) + "/eq/mode"
|
||||
err := e.client.SendMessage(address)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
resp := <-e.client.respChan
|
||||
val, ok := resp.Arguments[0].(int32)
|
||||
if !ok {
|
||||
return 0, fmt.Errorf("unexpected argument type for EQ mode value")
|
||||
}
|
||||
return int(val), nil
|
||||
}
|
||||
|
||||
func (e *Eq) SetMode(index int, mode int) error {
|
||||
address := fmt.Sprintf(e.baseAddress, index) + "/eq/mode"
|
||||
return e.client.SendMessage(address, int32(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)
|
||||
@@ -62,11 +82,77 @@ func (e *Eq) Gain(index int, band int) (float64, error) {
|
||||
if !ok {
|
||||
return 0, fmt.Errorf("unexpected argument type for EQ gain value")
|
||||
}
|
||||
return float64(val), nil
|
||||
return linGet(-15, 15, float64(val)), nil
|
||||
}
|
||||
|
||||
// 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)
|
||||
return e.client.SendMessage(address, float32(gain))
|
||||
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)
|
||||
err := e.client.SendMessage(address)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
resp := <-e.client.respChan
|
||||
val, ok := resp.Arguments[0].(float32)
|
||||
if !ok {
|
||||
return 0, fmt.Errorf("unexpected argument type for EQ frequency value")
|
||||
}
|
||||
return logGet(20, 20000, float64(val)), nil
|
||||
}
|
||||
|
||||
// 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)
|
||||
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)
|
||||
err := e.client.SendMessage(address)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
resp := <-e.client.respChan
|
||||
val, ok := resp.Arguments[0].(float32)
|
||||
if !ok {
|
||||
return 0, fmt.Errorf("unexpected argument type for EQ Q value")
|
||||
}
|
||||
return logGet(0.3, 10, 1.0-float64(val)), nil
|
||||
}
|
||||
|
||||
// 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)
|
||||
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) (int, error) {
|
||||
address := fmt.Sprintf(e.baseAddress, index) + fmt.Sprintf("/eq/%d/type", band)
|
||||
err := e.client.SendMessage(address)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
resp := <-e.client.respChan
|
||||
val, ok := resp.Arguments[0].(int32)
|
||||
if !ok {
|
||||
return 0, fmt.Errorf("unexpected argument type for EQ type value")
|
||||
}
|
||||
return int(val), nil
|
||||
}
|
||||
|
||||
// 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 int) error {
|
||||
address := fmt.Sprintf(e.baseAddress, index) + fmt.Sprintf("/eq/%d/type", band)
|
||||
return e.client.SendMessage(address, int32(eqType))
|
||||
}
|
||||
|
||||
@@ -10,6 +10,14 @@ func linSet(min float64, max float64, value float64) float64 {
|
||||
return (value - min) / (max - min)
|
||||
}
|
||||
|
||||
func logGet(min float64, max float64, value float64) float64 {
|
||||
return min * math.Exp(math.Log(max/min)*value)
|
||||
}
|
||||
|
||||
func logSet(min float64, max float64, value float64) float64 {
|
||||
return math.Log(value/min) / math.Log(max/min)
|
||||
}
|
||||
|
||||
func mustDbInto(db float64) float64 {
|
||||
switch {
|
||||
case db >= 10:
|
||||
|
||||
Reference in New Issue
Block a user