mirror of
https://github.com/onyx-and-iris/voicemeeter-api-powershell.git
synced 2025-01-18 13:20:47 +00:00
examples now using relative import path
obs example now using obs-powershell module. README updated.
This commit is contained in:
parent
2586ca4089
commit
62ad51c6b8
@ -1,11 +1,11 @@
|
|||||||
param(
|
param(
|
||||||
[switch]$interactive,
|
[switch]$interactive,
|
||||||
[switch]$output,
|
[switch]$output,
|
||||||
[String]$kind="banana",
|
[String]$kind = "banana",
|
||||||
[String[]]$script = @()
|
[String[]]$script = @()
|
||||||
)
|
)
|
||||||
|
|
||||||
Import-Module Voicemeeter
|
Import-Module ..\..\lib\Voicemeeter.psm1
|
||||||
|
|
||||||
function get-value {
|
function get-value {
|
||||||
param([object]$vmr, [string]$line)
|
param([object]$vmr, [string]$line)
|
||||||
@ -39,7 +39,7 @@ function msgHandler {
|
|||||||
|
|
||||||
function read-hostuntilempty {
|
function read-hostuntilempty {
|
||||||
param([object]$vmr)
|
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
|
[object]$vmr
|
||||||
|
|
||||||
try {
|
try {
|
||||||
switch ($kind) {
|
$vmr = Connect-Voicemeeter -Kind $kind
|
||||||
"basic" { $vmr = Get-RemoteBasic }
|
|
||||||
"banana" { $vmr = Get-RemoteBanana }
|
|
||||||
"potato" { $vmr = Get-RemotePotato }
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($interactive) {
|
if ($interactive) {
|
||||||
"Press <Enter> to exit" | Write-Host
|
"Press <Enter> to exit" | Write-Host
|
||||||
@ -62,7 +58,7 @@ function main {
|
|||||||
msgHandler -vmr $vmr -line $_
|
msgHandler -vmr $vmr -line $_
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
finally { $vmr.Logout() }
|
finally { Disconnect-Voicemeeter }
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($MyInvocation.InvocationName -ne '.') { main }
|
if ($MyInvocation.InvocationName -ne '.') { main }
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
Credits go to @bobsupercow
|
Credits go to @bobsupercow
|
||||||
#>
|
#>
|
||||||
|
|
||||||
Import-Module Voicemeeter
|
Import-Module ..\..\lib\Voicemeeter.psm1
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$vmr = Get-RemotePotato
|
$vmr = Get-RemotePotato
|
||||||
@ -20,7 +20,7 @@ try {
|
|||||||
$bus = $_
|
$bus = $_
|
||||||
# 2)
|
# 2)
|
||||||
if (-not $bus.mute) {
|
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)
|
$unmutedIndex = $buses.IndexOf($bus)
|
||||||
$bus.mute = $true
|
$bus.mute = $true
|
||||||
|
|
||||||
|
@ -5,11 +5,12 @@ Demonstrates how to sync Voicemeeter states with OBS scene switches.
|
|||||||
## Requirements
|
## Requirements
|
||||||
|
|
||||||
- [OBS Studio 28+](https://obsproject.com/)
|
- [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
|
## Use
|
||||||
|
|
||||||
This example assumes the following:
|
This example assumes the following:
|
||||||
|
|
||||||
- OBS connection info saved in `config.psd1`, placed next to `Vm-Obs-Sync.ps1`:
|
- OBS connection info saved in `config.psd1`, placed next to `Vm-Obs-Sync.ps1`:
|
||||||
|
|
||||||
```psd1
|
```psd1
|
||||||
|
@ -1,26 +1,43 @@
|
|||||||
Import-Module Voicemeeter
|
Import-Module ..\..\lib\Voicemeeter.psm1
|
||||||
Import-Module OBSWebSocket
|
Import-Module obs-powershell
|
||||||
|
|
||||||
$VerbosePreference = "Continue"
|
$VerbosePreference = "Continue"
|
||||||
|
|
||||||
$info = @{
|
function CurrentProgramSceneChanged {
|
||||||
START = "Toggling Strip 0 mute"
|
param([System.Object]$data)
|
||||||
BRB = "Setting Strip 0 gain to -8.3"
|
Write-Host "Switched to scene", $data.sceneName
|
||||||
END = "Setting Strip 0 mono to `$false"
|
|
||||||
LIVE = "Setting Strip 0 color_x to 0.3"
|
|
||||||
}
|
|
||||||
|
|
||||||
function CurrentProgramSceneChanged($data) {
|
switch ($data.sceneName) {
|
||||||
"Switched to scene " + $data.sceneName | Write-Host
|
"START" {
|
||||||
|
$vmr.strip[0].mute = !$vmr.strip[0].mute
|
||||||
switch ($data.SceneName) {
|
"Toggling Strip 0 mute"
|
||||||
"START" { $vmr.strip[0].mute = !$vmr.strip[0].mute }
|
}
|
||||||
"BRB" { $vmr.strip[0].gain = -8.3 }
|
"BRB" {
|
||||||
"END" { $vmr.strip[0].mono = $true }
|
$vmr.strip[0].gain = -8.3
|
||||||
"LIVE" { $vmr.strip[0].color_x = 0.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 }
|
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 {
|
function ConnFromFile {
|
||||||
@ -29,21 +46,25 @@ function ConnFromFile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function main {
|
function main {
|
||||||
try {
|
$vmr = Connect-Voicemeeter -Kind "basic"
|
||||||
$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
|
|
||||||
|
|
||||||
$e_client = Get-OBSEvent -hostname $conn.hostname -port $conn.port -pass $conn.password
|
$conn = ConnFromFile
|
||||||
$callbacks = @("CurrentProgramSceneChanged", ${function:CurrentProgramSceneChanged})
|
$job = Watch-OBS -WebSocketURI "ws://$($conn.host):$($conn.port)" -WebSocketToken $conn.password
|
||||||
$e_client.Register($callbacks)
|
|
||||||
} finally {
|
try {
|
||||||
$r_client.TearDown()
|
while ($true) {
|
||||||
$e_client.TearDown()
|
Receive-Job -Job $job | ForEach-Object {
|
||||||
$vmr.Logout()
|
$data = $_.MessageData
|
||||||
|
|
||||||
|
if ($data.op -eq 5) {
|
||||||
|
eventHandler($data.d)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
Disconnect-OBS
|
||||||
|
Disconnect-Voicemeeter
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user