event Add() and Remove() now variadic.

in strip, vban, log warning then return zero value instead of panic.

update readme
This commit is contained in:
onyx-and-iris 2022-10-10 18:51:30 +01:00
parent 76ed3320d3
commit be6a49e3bc
5 changed files with 86 additions and 63 deletions

View File

@ -147,19 +147,19 @@ sets many parameters in script format eg. ("Strip[0].Mute=1;Bus[3].Gain=3.6")
#### `vm.Register(o observer)`
register an object as an observer
register an observer type as an observer
#### `vm.Deregister(o observer)`
deregister an object as an observer
deregister an observer type as an observer
#### `vm.EventAdd(<event>)`
#### `vm.EventAdd(<events>)`
adds an event to the pooler eg. vm.EventAdd("ldirty")
adds a single or multiple events to the pooler. Accepts a string or slice of strings.
#### `vm.EventRemove(<event>)`
#### `vm.EventRemove(<events>)`
removes an event to the pooler eg. vm.EventRemove("pdirty")
removes a single or multiple events from the pooler. Accepts a string or slice of strings.
#### `vm.Pdirty()`

View File

@ -2,6 +2,8 @@ package voicemeeter
import (
"time"
log "github.com/sirupsen/logrus"
)
// observer defines the interface any registered observers must satisfy
@ -51,8 +53,9 @@ func newEvent() *event {
return &event{true, true, true, false}
}
func (e *event) Add(ev string) {
switch ev {
func (e *event) Add(events ...string) {
for _, event := range events {
switch event {
case "pdirty":
e.pdirty = true
case "mdirty":
@ -62,10 +65,13 @@ func (e *event) Add(ev string) {
case "ldirty":
e.ldirty = true
}
log.Info(event, " added to the pooler")
}
}
func (e *event) Remove(ev string) {
switch ev {
func (e *event) Remove(events ...string) {
for _, event := range events {
switch event {
case "pdirty":
e.pdirty = false
case "mdirty":
@ -75,6 +81,8 @@ func (e *event) Remove(ev string) {
case "ldirty":
e.ldirty = false
}
log.Info(event, " removed from the pooler")
}
}
// pooler continuously polls the dirty paramters

View File

@ -8,7 +8,7 @@ import (
log "github.com/sirupsen/logrus"
)
// A Remote type represents the API for a kind
// Remote represents the API for a kind
type Remote struct {
Kind *kind
Strip []iStrip
@ -85,7 +85,7 @@ func (r *Remote) Sync() {
}
}
// Gets a float parameter value
// GetFloat gets a float parameter value
func (r *Remote) GetFloat(name string) (float64, error) {
val, err := getParameterFloat(name)
if err != nil {
@ -94,7 +94,7 @@ func (r *Remote) GetFloat(name string) (float64, error) {
return val, nil
}
// Sets a float paramter value
// SetFloat sets a float paramter value
func (r *Remote) SetFloat(name string, value float64) error {
err := setParameterFloat(name, value)
if err != nil {
@ -103,7 +103,7 @@ func (r *Remote) SetFloat(name string, value float64) error {
return nil
}
// Gets a string parameter value
// GetString gets a string parameter value
func (r *Remote) GetString(name string) (string, error) {
val, err := getParameterString(name)
if err != nil {
@ -112,7 +112,7 @@ func (r *Remote) GetString(name string) (string, error) {
return val, nil
}
// Sets a string paramter value
// SetString sets a string parameter value
func (r *Remote) SetString(name, value string) error {
err := setParameterString(name, value)
if err != nil {
@ -140,14 +140,14 @@ func (r *Remote) Deregister(o observer) {
r.pooler.Deregister(o)
}
// EventAdd adds an event to the Pooler
func (r *Remote) EventAdd(event string) {
r.pooler.event.Add(event)
// EventAdd adds events to the Pooler
func (r *Remote) EventAdd(events ...string) {
r.pooler.event.Add(events...)
}
// EventRemove removes an event from the Pooler
func (r *Remote) EventRemove(event string) {
r.pooler.event.Remove(event)
// EventRemove removes events from the Pooler
func (r *Remote) EventRemove(events ...string) {
r.pooler.event.Remove(events...)
}
// remoteBuilder defines the interface builder types must satisfy
@ -165,7 +165,7 @@ type remoteBuilder interface {
Get() *Remote
}
// directory is responsible for directing the genericBuilder
// director is responsible for directing the genericBuilder
type director struct {
builder remoteBuilder
}

View File

@ -3,9 +3,11 @@ package voicemeeter
import (
"fmt"
"time"
log "github.com/sirupsen/logrus"
)
// iStrip defines the interface bus types must satisfy
// iStrip defines the interface strip types must satisfy
type iStrip interface {
String() string
GetMute() bool
@ -179,14 +181,16 @@ func (p *physicalStrip) SetAudibility(val float64) {
p.setter_float("Audibility", val)
}
// GetMc panics reason invalid parameter
// GetMc logs a warning reason invalid parameter
// it always returns zero value
func (p *physicalStrip) GetMc() bool {
panic("invalid parameter MC for physicalStrip")
log.Warn("invalid parameter MC for physicalStrip")
return false
}
// SetMc panics reason invalid parameter
// SetMc logs a warning reason invalid parameter
func (p *physicalStrip) SetMc(val bool) {
panic("invalid parameter MC for physicalStrip")
log.Warn("invalid parameter MC for physicalStrip")
}
// virtualStrip represents a single virtual strip
@ -221,34 +225,40 @@ func (v *virtualStrip) SetMc(val bool) {
v.setter_bool("MC", val)
}
// GetComp panics reason invalid parameter
// GetComp logs a warning reason invalid parameter
// it always returns zero value
func (v *virtualStrip) GetComp() float64 {
panic("invalid parameter Comp for virtualStrip")
log.Warn("invalid parameter Comp for virtualStrip")
return 0
}
// SetComp panics reason invalid parameter
// SetComp logs a warning reason invalid parameter
func (v *virtualStrip) SetComp(val float64) {
panic("invalid parameter Comp for virtualStrip")
log.Warn("invalid parameter Comp for virtualStrip")
}
// GetGate panics reason invalid parameter
// GetGate logs a warning reason invalid parameter
// it always returns zero value
func (v *virtualStrip) GetGate() float64 {
panic("invalid parameter Gate for virtualStrip")
log.Warn("invalid parameter Gate for virtualStrip")
return 0
}
// SetGate panics reason invalid parameter
// SetGate logs a warning reason invalid parameter
func (v *virtualStrip) SetGate(val float64) {
panic("invalid parameter Gate for virtualStrip")
log.Warn("invalid parameter Gate for virtualStrip")
}
// GetAudibility panics reason invalid parameter
// GetAudibility logs a warning reason invalid parameter
// it always returns zero value
func (v *virtualStrip) GetAudibility() float64 {
panic("invalid parameter Audibility for virtualStrip")
log.Warn("invalid parameter Audibility for virtualStrip")
return 0
}
// SetAudibility panics reason invalid parameter
// SetAudibility logs a warning reason invalid parameter
func (v *virtualStrip) SetAudibility(val float64) {
panic("invalid parameter Audibility for virtualStrip")
log.Warn("invalid parameter Audibility for virtualStrip")
}
// AppGain sets the gain in db by val for the app matching name.

21
vban.go
View File

@ -1,6 +1,10 @@
package voicemeeter
import "fmt"
import (
"fmt"
log "github.com/sirupsen/logrus"
)
// iVban defines the interface vban types must satisfy
type iVban interface {
@ -105,7 +109,8 @@ func (v *vbanStream) SetBit(val int) {
case 24:
val = 2
default:
panic("expected value 16 or 24")
log.Warn("expected value 16 or 24")
return
}
v.setter_int("Bit", val)
}
@ -139,19 +144,19 @@ func newVbanInStream(i int) iVban {
return iVban(&vbi)
}
// SetSr panics reason read only
// SetSr logs a warning reason read only
func (vbi *vbanInStream) SetSr(val int) {
panic("SR is readonly for vban instreams")
log.Warn("SR is readonly for vban instreams")
}
// SetChannel panics reason read only
// SetChannel logs a warning reason read only
func (vbi *vbanInStream) SetChannel(val int) {
panic("channel is readonly for vban instreams")
log.Warn("channel is readonly for vban instreams")
}
// SetBit panics reason read only
// SetBit logs a warning reason read only
func (vbi *vbanInStream) SetBit(val int) {
panic("bit is readonly for vban instreams")
log.Warn("bit is readonly for vban instreams")
}
type vbanOutStream struct {