2023-08-16 16:38:00 +01:00
|
|
|
[cmdletbinding()]
|
2022-10-27 21:21:19 +01:00
|
|
|
param(
|
|
|
|
[switch]$interactive,
|
2022-12-16 17:16:02 +00:00
|
|
|
[String]$kind = "banana",
|
2022-10-27 21:21:19 +01:00
|
|
|
[String[]]$script = @()
|
|
|
|
)
|
|
|
|
|
2022-12-16 17:16:02 +00:00
|
|
|
Import-Module ..\..\lib\Voicemeeter.psm1
|
2022-10-27 21:21:19 +01:00
|
|
|
|
|
|
|
function get-value {
|
|
|
|
param([object]$vmr, [string]$line)
|
|
|
|
try {
|
|
|
|
$retval = $vmr.Getter($line)
|
|
|
|
}
|
|
|
|
catch {
|
|
|
|
$retval = $vmr.Getter_String($line)
|
|
|
|
}
|
|
|
|
$retval
|
|
|
|
}
|
|
|
|
|
|
|
|
function msgHandler {
|
|
|
|
param([object]$vmr, [string]$line)
|
|
|
|
$line + " passed to handler" | Write-Debug
|
|
|
|
if ($line[0] -eq "!") {
|
2023-08-16 16:38:00 +01:00
|
|
|
"Toggling " + $line.substring(1) | Write-Debug
|
2022-10-27 21:21:19 +01:00
|
|
|
$retval = get-value -vmr $vmr -line $line.substring(1)
|
|
|
|
$vmr.Setter($line.substring(1), 1 - $retval)
|
|
|
|
}
|
|
|
|
elseif ($line.Contains("=")) {
|
2023-08-16 16:38:00 +01:00
|
|
|
"Setting $line" | Write-Debug
|
2022-10-27 21:21:19 +01:00
|
|
|
$vmr.SendText($line)
|
|
|
|
}
|
|
|
|
else {
|
2023-08-16 16:38:00 +01:00
|
|
|
"Getting $line" | Write-Debug
|
2022-10-27 21:21:19 +01:00
|
|
|
$retval = get-value -vmr $vmr -line $line
|
|
|
|
$line + " = " + $retval | Write-Host
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-30 01:50:30 +01:00
|
|
|
function read-hostuntilempty {
|
2022-10-27 21:21:19 +01:00
|
|
|
param([object]$vmr)
|
2022-12-16 17:16:02 +00:00
|
|
|
while (($line = Read-Host) -cne [string]::Empty) { msgHandler -vmr $vmr -line $line }
|
2022-10-27 21:21:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function main {
|
|
|
|
[object]$vmr
|
|
|
|
|
|
|
|
try {
|
2022-12-16 17:16:02 +00:00
|
|
|
$vmr = Connect-Voicemeeter -Kind $kind
|
2022-10-27 21:21:19 +01:00
|
|
|
|
|
|
|
if ($interactive) {
|
|
|
|
"Press <Enter> to exit" | Write-Host
|
2022-10-30 01:50:30 +01:00
|
|
|
read-hostuntilempty -vmr $vmr
|
2022-10-27 21:21:19 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
$script | ForEach-Object {
|
|
|
|
msgHandler -vmr $vmr -line $_
|
|
|
|
}
|
|
|
|
}
|
2022-12-16 17:16:02 +00:00
|
|
|
finally { Disconnect-Voicemeeter }
|
2022-10-27 21:21:19 +01:00
|
|
|
}
|
|
|
|
|
2023-08-14 22:44:09 +01:00
|
|
|
main
|