2022-06-25 20:11:15 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2022-12-09 00:55:18 +00:00
|
|
|
"time"
|
2022-06-25 20:11:15 +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-06-25 20:11:15 +01:00
|
|
|
)
|
|
|
|
|
2022-09-18 05:37:10 +01:00
|
|
|
// observer represents a single receiver of updates
|
2022-06-25 20:36:34 +01:00
|
|
|
type observer struct {
|
2022-12-08 10:52:15 +00:00
|
|
|
vm *voicemeeter.Remote
|
|
|
|
events chan string
|
2022-06-25 20:36:34 +01:00
|
|
|
}
|
2022-06-25 20:11:15 +01:00
|
|
|
|
2022-12-08 19:45:18 +00:00
|
|
|
// newObserver returns an observer type
|
2022-09-18 05:37:10 +01:00
|
|
|
func newObserver(vm *voicemeeter.Remote) *observer {
|
2022-12-09 00:55:18 +00:00
|
|
|
return &observer{vm, make(chan string)}
|
2022-08-22 22:34:32 +01:00
|
|
|
}
|
|
|
|
|
2022-12-15 00:41:57 +00:00
|
|
|
// Listen registers the observer channel and listens for udpates.
|
2022-12-08 10:52:15 +00:00
|
|
|
func (o observer) Listen() {
|
|
|
|
o.vm.Register(o.events)
|
|
|
|
|
|
|
|
for s := range o.events {
|
|
|
|
switch s {
|
|
|
|
case "pdirty", "mdirty":
|
|
|
|
fmt.Println(s)
|
|
|
|
case "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)
|
|
|
|
case "ldirty":
|
|
|
|
for _, bus := range o.vm.Bus {
|
|
|
|
if bus.Levels().IsDirty() {
|
|
|
|
fmt.Println(bus, bus.Levels().All())
|
|
|
|
}
|
2022-10-04 20:18:48 +01:00
|
|
|
}
|
|
|
|
}
|
2022-07-09 19:01:58 +01:00
|
|
|
}
|
2022-06-25 20:11:15 +01:00
|
|
|
}
|
|
|
|
|
2022-09-29 18:05:21 +01:00
|
|
|
func init() {
|
|
|
|
log.SetLevel(log.InfoLevel)
|
|
|
|
}
|
|
|
|
|
2022-12-15 00:43:19 +00:00
|
|
|
// runObserver initiates a single observer and
|
|
|
|
// starts its Listen() function in a goroutine.
|
2022-12-08 10:52:15 +00:00
|
|
|
func runObserver(vm *voicemeeter.Remote) {
|
|
|
|
o := newObserver(vm)
|
2022-12-09 00:55:18 +00:00
|
|
|
go o.Listen()
|
2022-12-08 10:52:15 +00:00
|
|
|
}
|
|
|
|
|
2022-09-18 05:37:10 +01:00
|
|
|
// main connects to Voiceemeter, registers observer for updates
|
|
|
|
// runs updates for 30 seconds and then deregisters observer.
|
2022-06-25 20:11:15 +01:00
|
|
|
func main() {
|
2022-09-18 05:37:10 +01:00
|
|
|
vm, err := vmConnect()
|
2022-08-23 03:16:43 +01:00
|
|
|
if err != nil {
|
2022-08-23 03:35:34 +01:00
|
|
|
log.Fatal(err)
|
2022-08-23 03:16:43 +01:00
|
|
|
}
|
2022-09-18 05:37:10 +01:00
|
|
|
defer vm.Logout()
|
|
|
|
|
2022-12-08 10:52:15 +00:00
|
|
|
runObserver(vm)
|
2022-12-09 00:55:18 +00:00
|
|
|
|
|
|
|
time.Sleep(time.Duration(30) * time.Second)
|
2022-09-18 05:37:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// vmConnect connects to Voicemeeter potato and logs into the API
|
2022-12-15 00:41:57 +00:00
|
|
|
// it also add ldirty to event updates.
|
2022-09-18 05:37:10 +01:00
|
|
|
func vmConnect() (*voicemeeter.Remote, error) {
|
2022-12-08 10:52:15 +00:00
|
|
|
vm, err := voicemeeter.NewRemote("basic", 0)
|
2022-09-18 05:37:10 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2022-08-23 03:16:43 +01:00
|
|
|
|
2022-09-07 20:59:55 +01:00
|
|
|
err = vm.Login()
|
|
|
|
if err != nil {
|
2022-09-18 05:37:10 +01:00
|
|
|
return nil, err
|
2022-09-07 20:59:55 +01:00
|
|
|
}
|
2022-12-08 10:52:15 +00:00
|
|
|
vm.EventAdd("ldirty")
|
2022-06-25 20:11:15 +01:00
|
|
|
|
2022-09-18 05:37:10 +01:00
|
|
|
return vm, nil
|
2022-06-25 20:11:15 +01:00
|
|
|
}
|