mirror of
https://github.com/onyx-and-iris/voicemeeter-api-powershell.git
synced 2025-01-18 13:20:47 +00:00
cli example added
This commit is contained in:
parent
24e2b581f8
commit
26cebc6a31
67
examples/cli/CLI.ps1
Normal file
67
examples/cli/CLI.ps1
Normal file
@ -0,0 +1,67 @@
|
||||
param(
|
||||
[switch]$interactive,
|
||||
[Parameter(Mandatory)]
|
||||
[String]$kind,
|
||||
[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 "!") {
|
||||
$retval = get-value -vmr $vmr -line $line.substring(1)
|
||||
$vmr.Setter($line.substring(1), 1 - $retval)
|
||||
}
|
||||
elseif ($line.Contains("=")) {
|
||||
"Setting value $line" | Write-Debug
|
||||
$vmr.SendText($line)
|
||||
}
|
||||
else {
|
||||
"Getting value $line" | Write-Debug
|
||||
$retval = get-value -vmr $vmr -line $line
|
||||
$line + " = " + $retval | Write-Host
|
||||
}
|
||||
}
|
||||
|
||||
function read-hostuntilflag {
|
||||
param([object]$vmr)
|
||||
while (($line = Read-Host) -cne [string]::Empty) { msgHandler -vmr $vmr -line $line }
|
||||
}
|
||||
|
||||
|
||||
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-hostuntilflag -vmr $vmr
|
||||
return
|
||||
}
|
||||
$script | ForEach-Object {
|
||||
msgHandler -vmr $vmr -line $_
|
||||
}
|
||||
}
|
||||
finally { $vmr.Logout() }
|
||||
}
|
||||
|
||||
if ($MyInvocation.InvocationName -ne '.') { main }
|
Loading…
Reference in New Issue
Block a user