From cba2ac85ec87035fc7d9e1ff322c732b4faca9d0 Mon Sep 17 00:00:00 2001 From: onyx-and-iris <75868496+onyx-and-iris@users.noreply.github.com> Date: Mon, 22 Aug 2022 22:34:32 +0100 Subject: [PATCH] observer example updated with midi event. ldirty now enabled explicitly in observer example. --- examples/observer/observer.go | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/examples/observer/observer.go b/examples/observer/observer.go index a334f6f..11a062e 100644 --- a/examples/observer/observer.go +++ b/examples/observer/observer.go @@ -2,7 +2,6 @@ package main import ( "fmt" - "strings" "time" "github.com/onyx-and-iris/voicemeeter-api-go" @@ -12,14 +11,27 @@ type observer struct { vm *voicemeeter.Remote } +func (o observer) Register() { + o.vm.Register(o) +} + +func (o observer) Deregister() { + o.vm.Register(o) +} + func (o observer) OnUpdate(subject string) { - if strings.Compare(subject, "pdirty") == 0 { + if subject == "pdirty" { fmt.Println("pdirty!") } - if strings.Compare(subject, "mdirty") == 0 { + if subject == "mdirty" { fmt.Println("mdirty!") } - if strings.Compare(subject, "ldirty") == 0 { + if subject == "midi" { + var current = o.vm.Midi.Current() + var val = o.vm.Midi.Get(current) + fmt.Printf("Value of midi button %d: %d\n", current, val) + } + if subject == "ldirty" { fmt.Printf("%v %v %v %v %v %v %v %v\n", o.vm.Bus[0].Levels().IsDirty(), o.vm.Bus[1].Levels().IsDirty(), @@ -36,11 +48,13 @@ func (o observer) OnUpdate(subject string) { func main() { vm := voicemeeter.NewRemote("potato") vm.Login() + // enable level updates (disabled by default) + vm.EventAdd("ldirty") o := observer{vm} - vm.Register(o) + o.Register() time.Sleep(30 * time.Second) - vm.Deregister(o) + o.Deregister() vm.Logout() }