2022-08-23 03:53:51 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2022-09-18 05:38:22 +01:00
|
|
|
"os"
|
2022-09-18 20:57:59 +01:00
|
|
|
"time"
|
2022-08-23 03:53:51 +01:00
|
|
|
|
2022-09-29 18:05:21 +01:00
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
|
2022-12-08 10:52:15 +00:00
|
|
|
"github.com/onyx-and-iris/voicemeeter/v2"
|
2022-08-23 03:53:51 +01:00
|
|
|
|
|
|
|
"github.com/andreykaipov/goobs"
|
|
|
|
"github.com/andreykaipov/goobs/api/events"
|
2022-09-18 05:38:22 +01:00
|
|
|
|
|
|
|
"github.com/BurntSushi/toml"
|
2022-08-23 03:53:51 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2022-09-29 18:05:21 +01:00
|
|
|
func init() {
|
|
|
|
log.SetLevel(log.InfoLevel)
|
|
|
|
}
|
|
|
|
|
2022-08-23 03:53:51 +01:00
|
|
|
func main() {
|
2022-09-18 05:38:22 +01:00
|
|
|
vm, err := vmConnect()
|
2022-09-07 20:59:55 +01:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
defer vm.Logout()
|
2022-08-23 03:53:51 +01:00
|
|
|
|
2022-09-18 05:38:22 +01:00
|
|
|
obs, err := obsConnect()
|
2022-08-23 03:53:51 +01:00
|
|
|
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)
|
|
|
|
}
|
2022-09-18 05:38:22 +01:00
|
|
|
|
|
|
|
func vmConnect() (*voicemeeter.Remote, error) {
|
|
|
|
vm, err := voicemeeter.NewRemote("potato", 0)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = vm.Login()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return vm, nil
|
|
|
|
}
|
|
|
|
|
2022-09-18 20:57:59 +01:00
|
|
|
func obsConnect() (*goobs.Client, error) {
|
2022-09-18 05:38:22 +01:00
|
|
|
type (
|
|
|
|
connection struct {
|
2022-09-18 20:57:59 +01:00
|
|
|
Host string
|
|
|
|
Port int
|
|
|
|
Password string
|
2022-09-18 05:38:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
config struct {
|
|
|
|
Connection map[string]connection
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
f := "config.toml"
|
|
|
|
if _, err := os.Stat(f); err != nil {
|
2022-09-18 20:57:59 +01:00
|
|
|
err := fmt.Errorf("unable to locate %s", f)
|
|
|
|
return nil, err
|
2022-09-18 05:38:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
var c config
|
|
|
|
_, err := toml.DecodeFile(f, &c.Connection)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
conn := c.Connection["connection"]
|
|
|
|
|
|
|
|
obs, err := goobs.New(fmt.Sprintf("%s:%d", conn.Host, conn.Port), goobs.WithPassword(conn.Password))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return obs, nil
|
|
|
|
}
|