voicemeeter-api-powershell/examples/cli/CLI.ps1

69 lines
1.6 KiB
PowerShell
Raw Normal View History

2022-10-27 21:21:19 +01:00
param(
[switch]$interactive,
[switch]$output,
2022-10-30 01:07:40 +00:00
[String]$kind="banana",
2022-10-27 21:21:19 +01:00
[String[]]$script = @()
)
Import-Module Voicemeeter
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 "!") {
if ($output) { "Toggling " + $line.substring(1) | Write-Host }
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("=")) {
if ($output) { "Setting $line" | Write-Host }
2022-10-27 21:21:19 +01:00
$vmr.SendText($line)
}
else {
if ($output) { "Getting $line" | Write-Host }
2022-10-27 21:21:19 +01:00
$retval = get-value -vmr $vmr -line $line
$line + " = " + $retval | Write-Host
}
}
function read-hostuntilempty {
2022-10-27 21:21:19 +01:00
param([object]$vmr)
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 {
switch ($kind) {
"basic" { $vmr = Get-RemoteBasic }
"banana" { $vmr = Get-RemoteBanana }
"potato" { $vmr = Get-RemotePotato }
}
if ($interactive) {
"Press <Enter> to exit" | Write-Host
read-hostuntilempty -vmr $vmr
2022-10-27 21:21:19 +01:00
return
}
$script | ForEach-Object {
msgHandler -vmr $vmr -line $_
}
}
finally { $vmr.Logout() }
}
if ($MyInvocation.InvocationName -ne '.') { main }