voicemeeter/examples/hotkeys/main.go

72 lines
1.1 KiB
Go
Raw Permalink Normal View History

2022-09-14 21:16:29 +01:00
package main
import (
"fmt"
log "github.com/sirupsen/logrus"
2022-09-14 21:16:29 +01:00
"github.com/eiannone/keyboard"
"github.com/onyx-and-iris/voicemeeter"
2022-09-14 21:16:29 +01:00
)
func init() {
log.SetLevel(log.InfoLevel)
}
2022-09-14 21:16:29 +01:00
func main() {
if err := keyboard.Open(); err != nil {
2022-09-18 05:35:53 +01:00
log.Fatal(err)
2022-09-14 21:16:29 +01:00
}
defer func() {
_ = keyboard.Close()
}()
2022-09-18 05:35:53 +01:00
vm, err := vmConnect()
2022-09-14 21:16:29 +01:00
if err != nil {
log.Fatal(err)
}
defer vm.Logout()
fmt.Println("Press ESC to quit")
2022-09-14 21:17:20 +01:00
Loop:
for {
char, key, err := keyboard.GetKey()
if err != nil {
panic(err)
}
2022-09-14 21:16:29 +01:00
2022-09-14 21:17:20 +01:00
switch char {
case '0':
fmt.Printf("Logged into Voicemeeter %s, version %s\n", vm.Type(), vm.Version())
case '1':
vm.Strip[0].SetMute(!vm.Strip[0].GetMute())
case '2':
if vm.Strip[3].GetGain() == -12.8 {
vm.Strip[3].FadeBy(-8.3, 500)
} else {
vm.Strip[3].FadeTo(-12.8, 500)
}
case '3':
vm.Strip[5].AppMute("Spotify", true)
default:
if key == keyboard.KeyEsc {
break Loop
}
2022-09-14 21:16:29 +01:00
}
2022-09-14 21:17:20 +01:00
}
2022-09-14 21:16:29 +01:00
}
2022-09-18 05:35:53 +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
}