implement eq type/mode/gain/freq/q commands for strip/bus

This commit is contained in:
onyx-and-iris 2026-02-01 22:37:17 +00:00
parent a9110f0986
commit 2cdfd0fdf9
5 changed files with 518 additions and 2 deletions

View File

@ -300,6 +300,228 @@ var busEqOnCmd = &cobra.Command{
},
}
// busEqModeCmd represents the bus EQ mode command.
var busEqModeCmd = &cobra.Command{
Short: "Get or set the bus EQ mode",
Long: `Get or set the EQ mode of a specific bus.`,
Use: "mode [bus number] [mode]",
RunE: func(cmd *cobra.Command, args []string) error {
client := ClientFromContext(cmd.Context())
if client == nil {
return fmt.Errorf("OSC client not found in context")
}
if len(args) < 1 {
return fmt.Errorf("Please provide bus number")
}
busIndex := mustConvToInt(args[0])
modeNames := []string{"peq", "geq", "teq"}
if len(args) == 1 {
mode, err := client.Bus.Eq.Mode(busIndex)
if err != nil {
return fmt.Errorf("Error getting bus EQ mode: %w", err)
}
cmd.Printf("Bus %d EQ mode: %s\n", busIndex, modeNames[mode])
return nil
}
mode := indexOf(modeNames, args[1])
if mode == -1 {
return fmt.Errorf("Invalid EQ mode. Valid modes are: %v", modeNames)
}
err := client.Bus.Eq.SetMode(busIndex, mode)
if err != nil {
return fmt.Errorf("Error setting bus EQ mode: %w", err)
}
cmd.Printf("Bus %d EQ mode set to %s\n", busIndex, modeNames[mode])
return nil
},
}
// busEqGainCmd represents the bus EQ gain command.
var busEqGainCmd = &cobra.Command{
Short: "Get or set the bus EQ gain for a specific band",
Long: `Get or set the EQ gain (in dB) for a specific band of a bus.
Gain values range from -15.0 dB to +15.0 dB.`,
Use: "gain [bus number] [band number] [gain in dB]",
RunE: func(cmd *cobra.Command, args []string) error {
client := ClientFromContext(cmd.Context())
if client == nil {
return fmt.Errorf("OSC client not found in context")
}
if len(args) < 2 {
return fmt.Errorf("Please provide bus number and band number")
}
busIndex, bandIndex := func() (int, int) {
return mustConvToInt(args[0]), mustConvToInt(args[1])
}()
if len(args) == 2 {
gain, err := client.Bus.Eq.Gain(busIndex, bandIndex)
if err != nil {
return fmt.Errorf("Error getting bus EQ gain: %w", err)
}
cmd.Printf("Bus %d EQ band %d gain: %.1f dB\n", busIndex, bandIndex, gain)
return nil
}
if len(args) < 3 {
return fmt.Errorf("Please provide bus number, band number, and gain (in dB)")
}
gain := mustConvToFloat64(args[2])
err := client.Bus.Eq.SetGain(busIndex, bandIndex, gain)
if err != nil {
return fmt.Errorf("Error setting bus EQ gain: %w", err)
}
cmd.Printf("Bus %d EQ band %d gain set to %.1f dB\n", busIndex, bandIndex, gain)
return nil
},
}
// busEqFreqCmd represents the bus EQ frequency command.
var busEqFreqCmd = &cobra.Command{
Short: "Get or set the bus EQ frequency for a specific band",
Long: `Get or set the EQ frequency (in Hz) for a specific band of a bus.`,
Use: "freq [bus number] [band number] [frequency in Hz]",
RunE: func(cmd *cobra.Command, args []string) error {
client := ClientFromContext(cmd.Context())
if client == nil {
return fmt.Errorf("OSC client not found in context")
}
if len(args) < 2 {
return fmt.Errorf("Please provide bus number and band number")
}
busIndex, bandIndex := func() (int, int) {
return mustConvToInt(args[0]), mustConvToInt(args[1])
}()
if len(args) == 2 {
freq, err := client.Bus.Eq.Frequency(busIndex, bandIndex)
if err != nil {
return fmt.Errorf("Error getting bus EQ frequency: %w", err)
}
cmd.Printf("Bus %d EQ band %d frequency: %.1f Hz\n", busIndex, bandIndex, freq)
return nil
}
if len(args) < 3 {
return fmt.Errorf("Please provide bus number, band number, and frequency (in Hz)")
}
freq := mustConvToFloat64(args[2])
err := client.Bus.Eq.SetFrequency(busIndex, bandIndex, freq)
if err != nil {
return fmt.Errorf("Error setting bus EQ frequency: %w", err)
}
cmd.Printf("Bus %d EQ band %d frequency set to %.1f Hz\n", busIndex, bandIndex, freq)
return nil
},
}
// busEqQCmd represents the bus EQ Q command.
var busEqQCmd = &cobra.Command{
Short: "Get or set the bus EQ Q factor for a specific band",
Long: `Get or set the EQ Q factor for a specific band of a bus.`,
Use: "q [bus number] [band number] [Q factor]",
RunE: func(cmd *cobra.Command, args []string) error {
client := ClientFromContext(cmd.Context())
if client == nil {
return fmt.Errorf("OSC client not found in context")
}
if len(args) < 2 {
return fmt.Errorf("Please provide bus number and band number")
}
busIndex, bandIndex := func() (int, int) {
return mustConvToInt(args[0]), mustConvToInt(args[1])
}()
if len(args) == 2 {
qFactor, err := client.Bus.Eq.Q(busIndex, bandIndex)
if err != nil {
return fmt.Errorf("Error getting bus EQ Q factor: %w", err)
}
cmd.Printf("Bus %d EQ band %d Q factor: %.2f\n", busIndex, bandIndex, qFactor)
return nil
}
if len(args) < 3 {
return fmt.Errorf("Please provide bus number, band number, and Q factor")
}
qFactor := mustConvToFloat64(args[2])
err := client.Bus.Eq.SetQ(busIndex, bandIndex, qFactor)
if err != nil {
return fmt.Errorf("Error setting bus EQ Q factor: %w", err)
}
cmd.Printf("Bus %d EQ band %d Q factor set to %.2f\n", busIndex, bandIndex, qFactor)
return nil
},
}
// busEqTypeCmd represents the bus EQ type command.
var busEqTypeCmd = &cobra.Command{
Short: "Get or set the bus EQ band type",
Long: `Get or set the EQ band type for a specific band of a bus.`,
Use: "type [bus number] [band number] [type]",
RunE: func(cmd *cobra.Command, args []string) error {
client := ClientFromContext(cmd.Context())
if client == nil {
return fmt.Errorf("OSC client not found in context")
}
if len(args) < 2 {
return fmt.Errorf("Please provide bus number and band number")
}
busIndex, bandIndex := func() (int, int) {
return mustConvToInt(args[0]), mustConvToInt(args[1])
}()
eqTypeNames := []string{"lcut", "lshv", "peq", "veq", "hshv", "hcut"}
if len(args) == 2 {
currentType, err := client.Bus.Eq.Type(busIndex, bandIndex)
if err != nil {
return fmt.Errorf("Error getting bus EQ band type: %w", err)
}
cmd.Printf("Bus %d EQ band %d type: %s\n", busIndex, bandIndex, eqTypeNames[currentType])
return nil
}
eqType := indexOf(eqTypeNames, args[2])
if eqType == -1 {
return fmt.Errorf("Invalid EQ band type. Valid types are: %v", eqTypeNames)
}
err := client.Bus.Eq.SetType(busIndex, bandIndex, eqType)
if err != nil {
return fmt.Errorf("Error setting bus EQ band type: %w", err)
}
cmd.Printf("Bus %d EQ band %d type set to %s\n", busIndex, bandIndex, eqTypeNames[eqType])
return nil
},
}
// busCompCmd represents the bus Compressor command.
var busCompCmd = &cobra.Command{
Short: "Commands to control bus Compressor settings",
@ -359,6 +581,11 @@ func init() {
busCmd.AddCommand(busEqCmd)
busEqCmd.AddCommand(busEqOnCmd)
busEqCmd.AddCommand(busEqModeCmd)
busEqCmd.AddCommand(busEqGainCmd)
busEqCmd.AddCommand(busEqFreqCmd)
busEqCmd.AddCommand(busEqQCmd)
busEqCmd.AddCommand(busEqTypeCmd)
busCmd.AddCommand(busCompCmd)
busCompCmd.AddCommand(busCompOnCmd)

View File

@ -475,6 +475,187 @@ If "false" or "0" is provided, the EQ is turned off.`,
},
}
// stripEqGainCmd represents the strip EQ Gain command.
var stripEqGainCmd = &cobra.Command{
Short: "Get or set the EQ band gain for a strip",
Long: "Get or set the EQ band gain for a specific strip and band.",
Use: "gain [strip number] [band number] [gain in dB]",
RunE: func(cmd *cobra.Command, args []string) error {
client := ClientFromContext(cmd.Context())
if client == nil {
return fmt.Errorf("OSC client not found in context")
}
if len(args) < 2 {
return fmt.Errorf("Please provide strip number and band number")
}
stripIndex, bandIndex := func() (int, int) {
return mustConvToInt(args[0]), mustConvToInt(args[1])
}()
if len(args) == 2 {
currentGain, err := client.Strip.Eq.Gain(stripIndex, bandIndex)
if err != nil {
return fmt.Errorf("Error getting strip EQ band gain: %w", err)
}
cmd.Printf("Strip %d EQ band %d gain: %.2f dB\n", stripIndex, bandIndex, currentGain)
return nil
}
if len(args) < 3 {
return fmt.Errorf("Please provide a gain in dB")
}
gain := mustConvToFloat64(args[2])
err := client.Strip.Eq.SetGain(stripIndex, bandIndex, gain)
if err != nil {
return fmt.Errorf("Error setting strip EQ band gain: %w", err)
}
cmd.Printf("Strip %d EQ band %d gain set to %.2f dB\n", stripIndex, bandIndex, gain)
return nil
},
}
// stripEqFreqCmd represents the strip EQ Frequency command.
var stripEqFreqCmd = &cobra.Command{
Short: "Get or set the EQ band frequency for a strip",
Long: "Get or set the EQ band frequency for a specific strip and band.",
Use: "freq [strip number] [band number] [frequency in Hz]",
RunE: func(cmd *cobra.Command, args []string) error {
client := ClientFromContext(cmd.Context())
if client == nil {
return fmt.Errorf("OSC client not found in context")
}
if len(args) < 2 {
return fmt.Errorf("Please provide strip number and band number")
}
stripIndex, bandIndex := func() (int, int) {
return mustConvToInt(args[0]), mustConvToInt(args[1])
}()
if len(args) == 2 {
currentFreq, err := client.Strip.Eq.Frequency(stripIndex, bandIndex)
if err != nil {
return fmt.Errorf("Error getting strip EQ band frequency: %w", err)
}
cmd.Printf("Strip %d EQ band %d frequency: %.2f Hz\n", stripIndex, bandIndex, currentFreq)
return nil
}
if len(args) < 3 {
return fmt.Errorf("Please provide a frequency in Hz")
}
freq := mustConvToFloat64(args[2])
err := client.Strip.Eq.SetFrequency(stripIndex, bandIndex, freq)
if err != nil {
return fmt.Errorf("Error setting strip EQ band frequency: %w", err)
}
cmd.Printf("Strip %d EQ band %d frequency set to %.2f Hz\n", stripIndex, bandIndex, freq)
return nil
},
}
// stripEqQCmd represents the strip EQ Q command.
var stripEqQCmd = &cobra.Command{
Short: "Get or set the EQ band Q factor for a strip",
Long: "Get or set the EQ band Q factor for a specific strip and band.",
Use: "q [strip number] [band number] [Q factor]",
RunE: func(cmd *cobra.Command, args []string) error {
client := ClientFromContext(cmd.Context())
if client == nil {
return fmt.Errorf("OSC client not found in context")
}
if len(args) < 2 {
return fmt.Errorf("Please provide strip number and band number")
}
stripIndex, bandIndex := func() (int, int) {
return mustConvToInt(args[0]), mustConvToInt(args[1])
}()
if len(args) == 2 {
currentQ, err := client.Strip.Eq.Q(stripIndex, bandIndex)
if err != nil {
return fmt.Errorf("Error getting strip EQ band Q factor: %w", err)
}
cmd.Printf("Strip %d EQ band %d Q factor: %.2f\n", stripIndex, bandIndex, currentQ)
return nil
}
if len(args) < 3 {
return fmt.Errorf("Please provide a Q factor")
}
q := mustConvToFloat64(args[2])
err := client.Strip.Eq.SetQ(stripIndex, bandIndex, q)
if err != nil {
return fmt.Errorf("Error setting strip EQ band Q factor: %w", err)
}
cmd.Printf("Strip %d EQ band %d Q factor set to %.2f\n", stripIndex, bandIndex, q)
return nil
},
}
// stripEqTypeCmd represents the strip EQ Type command.
var stripEqTypeCmd = &cobra.Command{
Short: "Get or set the EQ band type for a strip",
Long: "Get or set the EQ band type for a specific strip and band.",
Use: "type [strip number] [band number] [type]",
RunE: func(cmd *cobra.Command, args []string) error {
client := ClientFromContext(cmd.Context())
if client == nil {
return fmt.Errorf("OSC client not found in context")
}
if len(args) < 2 {
return fmt.Errorf("Please provide strip number and band number")
}
stripIndex, bandIndex := func() (int, int) {
return mustConvToInt(args[0]), mustConvToInt(args[1])
}()
eqTypeNames := []string{"lcut", "lshv", "peq", "veq", "hshv", "hcut"}
if len(args) == 2 {
currentType, err := client.Strip.Eq.Type(stripIndex, bandIndex)
if err != nil {
return fmt.Errorf("Error getting strip EQ band type: %w", err)
}
cmd.Printf("Strip %d EQ band %d type: %s\n", stripIndex, bandIndex, eqTypeNames[currentType])
return nil
}
if len(args) < 3 {
return fmt.Errorf("Please provide a type")
}
eqType := indexOf(eqTypeNames, args[2])
if eqType == -1 {
return fmt.Errorf("Invalid EQ band type. Valid types are: %v", eqTypeNames)
}
err := client.Strip.Eq.SetType(stripIndex, bandIndex, eqType)
if err != nil {
return fmt.Errorf("Error setting strip EQ band type: %w", err)
}
cmd.Printf("Strip %d EQ band %d type set to %s\n", stripIndex, bandIndex, eqTypeNames[eqType])
return nil
},
}
// stripCompCmd represents the strip Compressor command.
var stripCompCmd = &cobra.Command{
Short: "Commands to control the Compressor of individual strips.",
@ -563,6 +744,10 @@ func init() {
stripCmd.AddCommand(stripEqCmd)
stripEqCmd.AddCommand(stripEqOnCmd)
stripEqCmd.AddCommand(stripEqGainCmd)
stripEqCmd.AddCommand(stripEqFreqCmd)
stripEqCmd.AddCommand(stripEqQCmd)
stripEqCmd.AddCommand(stripEqTypeCmd)
stripCmd.AddCommand(stripCompCmd)
stripCompCmd.AddCommand(stripCompOnCmd)

View File

@ -21,3 +21,13 @@ func mustConvToInt(intStr string) int {
}
return val
}
// generic indexOf returns the index of elem in slice, or -1 if not found.
func indexOf[T comparable](slice []T, elem T) int {
for i, v := range slice {
if v == elem {
return i
}
}
return -1
}

View File

@ -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))
}

View File

@ -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: