examples now using relative import path

obs example now using obs-powershell module. README updated.
This commit is contained in:
onyx-and-iris 2022-12-16 17:16:02 +00:00
parent 2586ca4089
commit 62ad51c6b8
4 changed files with 61 additions and 43 deletions

View File

@ -1,11 +1,11 @@
param(
[switch]$interactive,
[switch]$output,
[String]$kind="banana",
[String]$kind = "banana",
[String[]]$script = @()
)
Import-Module Voicemeeter
Import-Module ..\..\lib\Voicemeeter.psm1
function get-value {
param([object]$vmr, [string]$line)
@ -39,7 +39,7 @@ function msgHandler {
function read-hostuntilempty {
param([object]$vmr)
while (($line = Read-Host) -cne[string]::Empty) { msgHandler -vmr $vmr -line $line }
while (($line = Read-Host) -cne [string]::Empty) { msgHandler -vmr $vmr -line $line }
}
@ -47,11 +47,7 @@ function main {
[object]$vmr
try {
switch ($kind) {
"basic" { $vmr = Get-RemoteBasic }
"banana" { $vmr = Get-RemoteBanana }
"potato" { $vmr = Get-RemotePotato }
}
$vmr = Connect-Voicemeeter -Kind $kind
if ($interactive) {
"Press <Enter> to exit" | Write-Host
@ -62,7 +58,7 @@ function main {
msgHandler -vmr $vmr -line $_
}
}
finally { $vmr.Logout() }
finally { Disconnect-Voicemeeter }
}
if ($MyInvocation.InvocationName -ne '.') { main }

View File

@ -7,7 +7,7 @@
Credits go to @bobsupercow
#>
Import-Module Voicemeeter
Import-Module ..\..\lib\Voicemeeter.psm1
try {
$vmr = Get-RemotePotato
@ -20,7 +20,7 @@ try {
$bus = $_
# 2)
if (-not $bus.mute) {
"bus " + $bus.index + " is unmuted... muting it" | Write-Host
"bus " + $bus.index + " is unmuted... muting it" | Write-Host
$unmutedIndex = $buses.IndexOf($bus)
$bus.mute = $true

View File

@ -5,11 +5,12 @@ 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)
- [OBS-Powershell](https://github.com/StartAutomating/obs-powershell)
## Use
This example assumes the following:
- OBS connection info saved in `config.psd1`, placed next to `Vm-Obs-Sync.ps1`:
```psd1

View File

@ -1,26 +1,43 @@
Import-Module Voicemeeter
Import-Module OBSWebSocket
Import-Module ..\..\lib\Voicemeeter.psm1
Import-Module obs-powershell
$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 {
param([System.Object]$data)
Write-Host "Switched to scene", $data.sceneName
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 }
switch ($data.sceneName) {
"START" {
$vmr.strip[0].mute = !$vmr.strip[0].mute
"Toggling Strip 0 mute"
}
"BRB" {
$vmr.strip[0].gain = -8.3
"Setting Strip 0 gain to -8.3"
}
"END" {
$vmr.strip[0].mono = $true
"Setting Strip 0 mono to `$false"
}
"LIVE" {
$vmr.strip[0].color_x = 0.3
"Setting Strip 0 color_x to 0.3"
}
default { "Expected START, BRB, END or LIVE scene" | Write-Warning; return }
}
$info[$data.SceneName] | Write-Host
}
function ExitStarted {
param([System.Object]$data)
"OBS closing has begun!" | Write-Host
break
}
function eventHandler($data) {
if (Get-Command $data.eventType -ErrorAction SilentlyContinue) {
& $data.eventType -data $data.eventData
}
}
function ConnFromFile {
@ -29,21 +46,25 @@ function ConnFromFile {
}
function main {
try {
$vmr = Get-RemoteBasic
$conn = ConnFromFile
$r_client = Get-OBSRequest -hostname $conn.hostname -port $conn.port -pass $conn.password
$resp = $r_client.getVersion()
"obs version:" + $resp.obsVersion | Write-Host
"websocket version:" + $resp.obsWebSocketVersion | Write-Host
$vmr = Connect-Voicemeeter -Kind "basic"
$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()
$conn = ConnFromFile
$job = Watch-OBS -WebSocketURI "ws://$($conn.host):$($conn.port)" -WebSocketToken $conn.password
try {
while ($true) {
Receive-Job -Job $job | ForEach-Object {
$data = $_.MessageData
if ($data.op -eq 5) {
eventHandler($data.d)
}
}
}
}
finally {
Disconnect-OBS
Disconnect-Voicemeeter
}
}