From 7f5d92603e98228763ea40e50de6a2c3ee4de003 Mon Sep 17 00:00:00 2001 From: norm Date: Fri, 4 Nov 2022 01:51:40 +0000 Subject: [PATCH] obs example added readme for obs example added config.psd1 added to gitignore --- .gitignore | 2 ++ examples/obs/README.md | 22 +++++++++++++++++ examples/obs/Vm-Obs-Sync.ps1 | 47 ++++++++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+) create mode 100644 examples/obs/README.md create mode 100644 examples/obs/Vm-Obs-Sync.ps1 diff --git a/.gitignore b/.gitignore index f6517e5..5ed949e 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,5 @@ quick.ps1 lib/*.psd1 **/*.log + +config.psd1 diff --git a/examples/obs/README.md b/examples/obs/README.md new file mode 100644 index 0000000..7760121 --- /dev/null +++ b/examples/obs/README.md @@ -0,0 +1,22 @@ +## About + +Demonstrates how to sync Voicemeeter states with OBS scene switches. + +## Requirements + +- [OBS Studio 28+](https://obsproject.com/) +- [OBSWebSocket for Powershell](https://github.com/onyx-and-iris/OBSWebSocket-Powershell) + +## Use + +This example assumes your OBS connection info saved in `config.psd1`, placed next to `Vm-Obs-Sync.ps1`: + +```psd1 +@{ + hostname = "localhost" + port = 4455 + password = "mystrongpassword" +} +``` + +Simply run the script and change current OBS scene. diff --git a/examples/obs/Vm-Obs-Sync.ps1 b/examples/obs/Vm-Obs-Sync.ps1 new file mode 100644 index 0000000..09b3541 --- /dev/null +++ b/examples/obs/Vm-Obs-Sync.ps1 @@ -0,0 +1,47 @@ +Import-Module Voicemeeter +Import-Module OBSWebSocket + +$VerbosePreference = "Continue" + +$info = @{ + START = "Toggling Strip 0 mute" + BRB = "Setting Strip 0 gain to -8.3" + END = "Setting Strip 0 mono to `$false" + LIVE = "Setting Strip 0 color_x to 0.3" +} + +function CurrentProgramSceneChanged($data) { + "Switched to scene " + $data.sceneName | Write-Host + + switch ($data.SceneName) { + "START" { $vmr.strip[0].mute = !$vmr.strip[0].mute } + "BRB" { $vmr.strip[0].gain = -8.3 } + "END" { $vmr.strip[0].mono = $true } + "LIVE" { $vmr.strip[0].color_x = 0.3 } + default { "Expected START, BRB, END or LIVE scene" | Write-Host } + } + $info[$data.SceneName] | Write-Host +} + +function ConnFromFile { + $configpath = Join-Path $PSScriptRoot "config.psd1" + return Import-PowerShellDataFile -Path $configpath +} + +function main { + try { + $vmr = Get-RemoteBasic + $conn = ConnFromFile + $r_client = Get-OBSRequest -hostname $conn.hostname -port $conn.port -pass $conn.password + + $e_client = Get-OBSEvent -hostname $conn.hostname -port $conn.port -pass $conn.password + $callbacks = @("CurrentProgramSceneChanged", ${function:CurrentProgramSceneChanged}) + $e_client.Register($callbacks) + } finally { + $r_client.TearDown() + $e_client.TearDown() + $vmr.Logout() + } +} + +if ($MyInvocation.InvocationName -ne '.') { main }