From fa8e9f3e7669751f1e08e72794540f9f8fe22a63 Mon Sep 17 00:00:00 2001 From: onyx-and-iris <75868496+onyx-and-iris@users.noreply.github.com> Date: Tue, 23 Aug 2022 03:53:51 +0100 Subject: [PATCH] obs example added. --- examples/obs/go.mod | 16 +++++ examples/obs/go.sum | 18 +++++ examples/obs/main.go | 78 ++++++++++++++++++++++ examples/observer/{observer.go => main.go} | 0 4 files changed, 112 insertions(+) create mode 100644 examples/obs/go.mod create mode 100644 examples/obs/go.sum create mode 100644 examples/obs/main.go rename examples/observer/{observer.go => main.go} (100%) diff --git a/examples/obs/go.mod b/examples/obs/go.mod new file mode 100644 index 0000000..0ff1434 --- /dev/null +++ b/examples/obs/go.mod @@ -0,0 +1,16 @@ +module main + +go 1.18 + +require ( + github.com/andreykaipov/goobs v0.10.0 + github.com/onyx-and-iris/voicemeeter-api-go v1.4.1 +) + +require ( + github.com/buger/jsonparser v1.1.1 // indirect + github.com/gorilla/websocket v1.5.0 // indirect + github.com/hashicorp/logutils v1.0.0 // indirect + github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d // indirect + golang.org/x/sys v0.0.0-20220708085239-5a0f0661e09d // indirect +) diff --git a/examples/obs/go.sum b/examples/obs/go.sum new file mode 100644 index 0000000..9a0e806 --- /dev/null +++ b/examples/obs/go.sum @@ -0,0 +1,18 @@ +github.com/andreykaipov/goobs v0.10.0 h1:wa4CxbYu/NqwUmx5E4/baDqYRYEmfHwg2T23RAg3jlU= +github.com/andreykaipov/goobs v0.10.0/go.mod h1:EqG73Uu/4npyhXIWWszgRelNkEeIz+d0slUT6NKWYs4= +github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMUs= +github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= +github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= +github.com/hashicorp/logutils v1.0.0 h1:dLEQVugN8vlakKOUE3ihGLTZJRB4j+M2cdTm/ORI65Y= +github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64= +github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d h1:VhgPp6v9qf9Agr/56bj7Y/xa04UccTW04VP0Qed4vnQ= +github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d/go.mod h1:YUTz3bUH2ZwIWBy3CJBeOBEugqcmXREj14T+iG/4k4U= +github.com/onyx-and-iris/voicemeeter-api-go v1.4.1 h1:2vGaRGCPwN9PlWspbdkDelsfxWHHkZqxozkd6FOcl28= +github.com/onyx-and-iris/voicemeeter-api-go v1.4.1/go.mod h1:zAdBhHXQ9n37CUbLizbOPmAutyZI8Ncqeu5e9u1Fy14= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= +golang.org/x/sys v0.0.0-20220708085239-5a0f0661e09d h1:/m5NbqQelATgoSPVC2Z23sR4kVNokFwDDyWh/3rGY+I= +golang.org/x/sys v0.0.0-20220708085239-5a0f0661e09d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/examples/obs/main.go b/examples/obs/main.go new file mode 100644 index 0000000..2d035df --- /dev/null +++ b/examples/obs/main.go @@ -0,0 +1,78 @@ +package main + +import ( + "fmt" + "log" + "time" + + "github.com/onyx-and-iris/voicemeeter-api-go" + + "github.com/andreykaipov/goobs" + "github.com/andreykaipov/goobs/api/events" +) + +func onStart(vm *voicemeeter.Remote) { + vm.Strip[0].SetMute(true) + vm.Strip[1].SetB1(true) + vm.Strip[2].SetB1(true) +} + +func onBrb(vm *voicemeeter.Remote) { + vm.Strip[7].FadeTo(0, 500) + vm.Bus[0].SetMute(true) +} + +func onLive(vm *voicemeeter.Remote) { + vm.Strip[0].SetMute(false) + vm.Strip[7].FadeTo(-6, 500) + vm.Strip[7].SetA3(true) + vm.Vban.InStream[0].SetOn(true) +} + +func onEnd(vm *voicemeeter.Remote) { + vm.Strip[0].SetMute(true) + vm.Strip[1].SetMute(true) + vm.Strip[1].SetB1(false) + vm.Strip[2].SetMute(true) + vm.Strip[2].SetB1(false) + vm.Vban.InStream[0].SetOn(false) +} + +func main() { + vm, err := voicemeeter.NewRemote("potato") + if err != nil { + log.Fatal(err) + } + defer vm.Logout() + + vm.Login() + + obs, err := goobs.New("localhost:4455", goobs.WithPassword("mystrongpass")) + if err != nil { + log.Fatal(err) + } + defer obs.Disconnect() + + version, _ := obs.General.GetVersion() + fmt.Printf("OBS Studio version: %s\n", version.ObsVersion) + fmt.Printf("Websocket server version: %s\n", version.ObsWebSocketVersion) + + go obs.Listen(func(event any) { + switch e := event.(type) { + case *events.CurrentProgramSceneChanged: + fmt.Printf("Switched to scene %s\n", e.SceneName) + switch e.SceneName { + case "START": + onStart(vm) + case "BRB": + onBrb(vm) + case "LIVE": + onLive(vm) + case "END": + onEnd(vm) + } + } + }) + + time.Sleep(30 * time.Second) +} diff --git a/examples/observer/observer.go b/examples/observer/main.go similarity index 100% rename from examples/observer/observer.go rename to examples/observer/main.go