diff --git a/README.md b/README.md index d3c4412..1718711 100644 --- a/README.md +++ b/README.md @@ -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()` +#### `vm.EventAdd()` -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()` +#### `vm.EventRemove()` -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()` diff --git a/publisher.go b/publisher.go index b3cb83b..1c0ade0 100644 --- a/publisher.go +++ b/publisher.go @@ -2,6 +2,8 @@ package voicemeeter import ( "time" + + log "github.com/sirupsen/logrus" ) // observer defines the interface any registered observers must satisfy @@ -51,29 +53,35 @@ func newEvent() *event { return &event{true, true, true, false} } -func (e *event) Add(ev string) { - switch ev { - case "pdirty": - e.pdirty = true - case "mdirty": - e.mdirty = true - case "midi": - e.midi = true - case "ldirty": - e.ldirty = true +func (e *event) Add(events ...string) { + for _, event := range events { + switch event { + case "pdirty": + e.pdirty = true + case "mdirty": + e.mdirty = true + case "midi": + e.midi = true + case "ldirty": + e.ldirty = true + } + log.Info(event, " added to the pooler") } } -func (e *event) Remove(ev string) { - switch ev { - case "pdirty": - e.pdirty = false - case "mdirty": - e.mdirty = false - case "midi": - e.midi = false - case "ldirty": - e.ldirty = false +func (e *event) Remove(events ...string) { + for _, event := range events { + switch event { + case "pdirty": + e.pdirty = false + case "mdirty": + e.mdirty = false + case "midi": + e.midi = false + case "ldirty": + e.ldirty = false + } + log.Info(event, " removed from the pooler") } } diff --git a/remote.go b/remote.go index 710821f..b809f86 100644 --- a/remote.go +++ b/remote.go @@ -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 } diff --git a/strip.go b/strip.go index 6ed9daa..5d27dd8 100644 --- a/strip.go +++ b/strip.go @@ -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. diff --git a/vban.go b/vban.go index 229781a..b974cdd 100644 --- a/vban.go +++ b/vban.go @@ -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 {