-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 4bc9f5d
Showing
6 changed files
with
167 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
bin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
build: | ||
GOOS=windows GOARCH=386 go build -o bin/vrc-osc-audio.exe main.go |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# VRC OSC Audio Controls | ||
|
||
A go program to control your audio using VRChat OSC Parameters | ||
|
||
## Usage | ||
|
||
Download the executable from the releases page and double-click! | ||
|
||
## Contributing | ||
|
||
### Requirements | ||
- Go | ||
- make command | ||
|
||
## Getting Started | ||
|
||
1. Clone the repository | ||
```bash | ||
git clone [email protected]:uzair-ashraf/vrc-osc-audio-controls.git | ||
``` | ||
2. Run the program | ||
```bash | ||
go run main.go | ||
``` | ||
1. Compile the executable for windows | ||
```bash | ||
make build | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module vrc-ocs-audio-controls | ||
|
||
go 1.17 | ||
|
||
require github.com/hypebeast/go-osc v0.0.0-20210408213458-3287e1838f40 // indirect |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
github.com/hypebeast/go-osc v0.0.0-20210408213458-3287e1838f40 h1:w+HdpjIfD+5Kb8aJ1KK9ROuqS9No/p0mSYTx/0XCASc= | ||
github.com/hypebeast/go-osc v0.0.0-20210408213458-3287e1838f40/go.mod h1:lqMjoCs0y0GoRRujSPZRBaGb4c5ER6TfkFKSClxkMbY= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os/exec" | ||
"strconv" | ||
"strings" | ||
|
||
"github.com/hypebeast/go-osc/osc" | ||
) | ||
|
||
func main() { | ||
addr := "127.0.0.1:9001" | ||
d := osc.NewStandardDispatcher() | ||
d.AddMsgHandler("/avatar/parameters/OSC_AUDIO_CONTROLS_PLAY_PAUSE", handlePlayPauseSong) | ||
d.AddMsgHandler("/avatar/parameters/OSC_AUDIO_CONTROLS_NEXT", handleNextSong) | ||
d.AddMsgHandler("/avatar/parameters/OSC_AUDIO_CONTROLS_PREVIOUS", handlePreviousSong) | ||
d.AddMsgHandler("/avatar/parameters/OSC_AUDIO_CONTROLS_MUTE", handleMute) | ||
server := &osc.Server{ | ||
Addr: addr, | ||
Dispatcher: d, | ||
} | ||
server.ListenAndServe() | ||
} | ||
|
||
func handlePlayPauseSong(msg *osc.Message) { | ||
wasSelected, err := parseVRCBool(msg) | ||
if err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
if !wasSelected { | ||
return | ||
} | ||
playPauseSong() | ||
} | ||
|
||
func handleNextSong(msg *osc.Message) { | ||
wasSelected, err := parseVRCBool(msg) | ||
if err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
if !wasSelected { | ||
return | ||
} | ||
nextSong() | ||
} | ||
|
||
func handlePreviousSong(msg *osc.Message) { | ||
wasSelected, err := parseVRCBool(msg) | ||
if err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
if !wasSelected { | ||
return | ||
} | ||
previousSong() | ||
} | ||
|
||
func handleMute(msg *osc.Message) { | ||
wasSelected, err := parseVRCBool(msg) | ||
if err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
if !wasSelected { | ||
return | ||
} | ||
muteVolume() | ||
} | ||
|
||
func parseVRCBool(msg *osc.Message) (bool, error) { | ||
message := strings.Trim(msg.String(), " ") | ||
fmt.Println(message) | ||
if strings.HasSuffix(message, ",T true") { | ||
return true, nil | ||
} else if strings.HasSuffix(message, ",F false") { | ||
return false, nil | ||
} | ||
|
||
return false, fmt.Errorf("Unexpected value: %v\n", message) | ||
} | ||
|
||
func parseVRCFloat(msg *osc.Message) (float64, error) { | ||
message := strings.Trim(msg.String(), " ") | ||
messageSlice := strings.Split(message, " ") | ||
floatStr := messageSlice[len(messageSlice)-1] | ||
return strconv.ParseFloat(floatStr, 64) | ||
} | ||
|
||
func executePowershellCommand(command string) (string, error) { | ||
cmd := exec.Command("powershell", "-nologo", "-noprofile", command) | ||
stdin, err := cmd.StdinPipe() | ||
if err != nil { | ||
return "", err | ||
} | ||
defer stdin.Close() | ||
out, err := cmd.CombinedOutput() | ||
if err != nil { | ||
return "", err | ||
} | ||
return string(out), nil | ||
} | ||
func playPauseSong() (string, error) { | ||
return executePowershellCommand(` | ||
$wshell = New-Object -ComObject wscript.shell | ||
$wshell.SendKeys([Char]0xB3) | ||
`) | ||
} | ||
func nextSong() (string, error) { | ||
return executePowershellCommand(` | ||
$wshell = New-Object -ComObject wscript.shell | ||
$wshell.SendKeys([Char]0xB0) | ||
`) | ||
} | ||
func previousSong() (string, error) { | ||
return executePowershellCommand(` | ||
$wshell = New-Object -ComObject wscript.shell | ||
$wshell.SendKeys([Char]0xB1) | ||
`) | ||
} | ||
func muteVolume() (string, error) { | ||
return executePowershellCommand(` | ||
$wshell = New-Object -ComObject wscript.shell | ||
$wshell.SendKeys([Char]0xAD) | ||
`) | ||
} |