mirror of
https://github.com/onyx-and-iris/voicemeeter-api-powershell.git
synced 2026-01-25 01:37:47 +00:00
update CLI example
This commit is contained in:
parent
6542473394
commit
259c7309dc
@ -1,5 +1,22 @@
|
|||||||
|
<#
|
||||||
|
.SYNOPSIS
|
||||||
|
Command Line Interface for Voicemeeter control.
|
||||||
|
.DESCRIPTION
|
||||||
|
This script provides a command line interface to interact with Voicemeeter. It supports both interactive mode and scripted commands.
|
||||||
|
Users can specify the type of Voicemeeter (banana or potato) and execute commands to get or set parameters.
|
||||||
|
.PARAMETER help
|
||||||
|
Displays help information.
|
||||||
|
.PARAMETER interactive
|
||||||
|
Starts the CLI in interactive mode.
|
||||||
|
.PARAMETER kind
|
||||||
|
Specifies the type of Voicemeeter to connect to (banana or potato). Default is 'banana'.
|
||||||
|
.PARAMETER script
|
||||||
|
A list of commands to execute in sequence.
|
||||||
|
#>
|
||||||
|
|
||||||
[cmdletbinding()]
|
[cmdletbinding()]
|
||||||
param(
|
param(
|
||||||
|
[switch]$help,
|
||||||
[switch]$interactive,
|
[switch]$interactive,
|
||||||
[String]$kind = 'banana',
|
[String]$kind = 'banana',
|
||||||
[String[]]$script = @()
|
[String[]]$script = @()
|
||||||
@ -7,62 +24,98 @@ param(
|
|||||||
|
|
||||||
Import-Module ..\..\lib\Voicemeeter.psm1
|
Import-Module ..\..\lib\Voicemeeter.psm1
|
||||||
|
|
||||||
function get-value {
|
if ($help -or ($script.Count -eq 0 -and -not $interactive)) {
|
||||||
param([object]$vmr, [string]$line)
|
Write-Host 'Voicemeeter CLI'
|
||||||
|
Write-Host ''
|
||||||
|
Write-Host 'Usage:'
|
||||||
|
Write-Host ' CLI.ps1 [-interactive] [-kind <basic|banana|potato>] [-script <command1>, <command2>, ...]'
|
||||||
|
Write-Host ''
|
||||||
|
Write-Host 'Options:'
|
||||||
|
Write-Host ' -interactive Start in interactive mode.'
|
||||||
|
Write-Host ' -kind <type> Specify the Voicemeeter type (banana or potato). Default is banana.'
|
||||||
|
Write-Host ' -script <commands> Provide a list of commands to execute in sequence.'
|
||||||
|
Write-Host ''
|
||||||
|
Write-Host 'Commands can be of the form:'
|
||||||
|
Write-Host ' Parameter=Value Set a parameter to a specific value.'
|
||||||
|
Write-Host ' !Parameter Toggle a boolean parameter.'
|
||||||
|
Write-Host ' Parameter Get the current value of a parameter.'
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
|
||||||
|
function Get-ParameterValue {
|
||||||
|
param(
|
||||||
|
[object]$vmr,
|
||||||
|
[string]$Parameter
|
||||||
|
)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$retval = $vmr.Getter($line)
|
$retval = $vmr.Getter($Parameter)
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
$retval = $vmr.Getter_String($line)
|
$retval = $vmr.Getter_String($Parameter)
|
||||||
}
|
}
|
||||||
$retval
|
$retval
|
||||||
}
|
}
|
||||||
|
|
||||||
function msgHandler {
|
|
||||||
param([object]$vmr, [string]$line)
|
function Invoke-VoicemeeterCLICommand {
|
||||||
$line + ' passed to handler' | Write-Debug
|
param(
|
||||||
if ($line[0] -eq '!') {
|
[object]$vmr,
|
||||||
'Toggling ' + $line.substring(1) | Write-Debug
|
[string]$Command
|
||||||
$retval = get-value -vmr $vmr -line $line.substring(1)
|
)
|
||||||
$vmr.Setter($line.substring(1), 1 - $retval)
|
|
||||||
|
# Toggle command
|
||||||
|
if ($Command[0] -eq '!') {
|
||||||
|
$parameter = $Command.Substring(1).Trim()
|
||||||
|
$currentValue = Get-ParameterValue -vmr $vmr -Parameter $parameter
|
||||||
|
|
||||||
|
if ($currentValue -ne 0 -and $currentValue -ne 1) {
|
||||||
|
throw "Cannot toggle non-boolean parameter '$parameter' with value '$currentValue'"
|
||||||
|
}
|
||||||
|
|
||||||
|
$newValue = 1 - $currentValue
|
||||||
|
$vmr.SendText("$parameter=$newValue")
|
||||||
|
Write-Host "Toggled $parameter to $newValue"
|
||||||
}
|
}
|
||||||
elseif ($line.Contains('=')) {
|
# Set command
|
||||||
"Setting $line" | Write-Debug
|
elseif ($Command.Contains('=')) {
|
||||||
$vmr.SendText($line)
|
$vmr.SendText("$Command")
|
||||||
|
Write-Host "Set $Command"
|
||||||
|
}
|
||||||
|
# Get command
|
||||||
|
else {
|
||||||
|
$parameter = $Command.Trim()
|
||||||
|
$value = Get-ParameterValue -vmr $vmr -Parameter $parameter
|
||||||
|
Write-Host "$parameter = $value"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function Start-VoicemeeterCLI {
|
||||||
|
param(
|
||||||
|
[object]$vmr
|
||||||
|
)
|
||||||
|
|
||||||
|
Write-Host "Voicemeeter CLI Interactive Mode. Type 'exit' to quit."
|
||||||
|
while (($input = Read-Host "Press Enter to rotate buses or type 'Q' to quit.") -ne 'Q') {
|
||||||
|
try {
|
||||||
|
Invoke-VoicemeeterCLICommand -vmr $vmr -Command $input
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Write-Host "Error: $_" -ForegroundColor Red
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$vmr = Connect-Voicemeeter -Kind $kind
|
||||||
|
|
||||||
|
if ($interactive) {
|
||||||
|
Start-VoicemeeterCLI -vmr $vmr
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
"Getting $line" | Write-Debug
|
foreach ($command in $script) {
|
||||||
$retval = get-value -vmr $vmr -line $line
|
Invoke-VoicemeeterCLICommand -vmr $vmr -Command $command
|
||||||
$line + ' = ' + $retval | Write-Host
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function read-hostuntilempty {
|
|
||||||
param([object]$vmr)
|
|
||||||
while (($line = Read-Host) -cne [string]::Empty) { msgHandler -vmr $vmr -line $line }
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function main {
|
|
||||||
[object]$vmr
|
|
||||||
|
|
||||||
try {
|
|
||||||
$vmr = Connect-Voicemeeter -Kind $kind
|
|
||||||
|
|
||||||
if ($interactive) {
|
|
||||||
'Press <Enter> to exit' | Write-Host
|
|
||||||
read-hostuntilempty -vmr $vmr
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if ($script.Count -eq 0) {
|
|
||||||
'No script provided, exiting' | Write-Host
|
|
||||||
return
|
|
||||||
}
|
|
||||||
$script | ForEach-Object {
|
|
||||||
msgHandler -vmr $vmr -line $_
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
finally { Disconnect-Voicemeeter }
|
|
||||||
}
|
}
|
||||||
|
finally { Disconnect-Voicemeeter }
|
||||||
main
|
|
||||||
@ -1,34 +1,38 @@
|
|||||||
## About
|
## About
|
||||||
|
|
||||||
A simple voicemeeter-cli script. Offers ability to toggle, get and set parameters.
|
A basic command-line interface
|
||||||
|
|
||||||
## Use
|
## Use
|
||||||
|
|
||||||
Toggle with `!` prefix, get by excluding `=` and set by including `=`. Mix and match arguments.
|
```
|
||||||
|
Voicemeeter CLI
|
||||||
|
|
||||||
You may pass the following optional flags:
|
Usage:
|
||||||
|
CLI.ps1 [-interactive] [-kind <basic|banana|potato>] [-script <command1>, <command2>, ...]
|
||||||
|
|
||||||
- -o: (-output) to toggle console output.
|
Options:
|
||||||
- -i: (-interactive) to toggle interactive mode.
|
-interactive Start in interactive mode.
|
||||||
- -k: (-kind) to set the kind of Voicemeeter. Defaults to banana.
|
-kind <type> Specify the Voicemeeter type (banana or potato). Default is banana.
|
||||||
- -s: (script) a string array, one string for each command.
|
-script <commands> Provide a list of commands to execute in sequence.
|
||||||
|
|
||||||
|
Commands can be of the form:
|
||||||
|
Parameter=Value Set a parameter to a specific value.
|
||||||
|
!Parameter Toggle a boolean parameter.
|
||||||
|
Parameter Get the current value of a parameter.
|
||||||
|
```
|
||||||
|
|
||||||
for example:
|
for example:
|
||||||
|
|
||||||
```powershell
|
```powershell
|
||||||
.\CLI.ps1 -o -k "banana" -s "strip[0].mute", "!strip[0].mute", "strip[0].mute", "bus[2].eq.on=1", "command.lock=1"
|
.\CLI.ps1 -script strip[0].mute, !strip[0].mute, strip[0].mute, bus[2].eq.on=1, command.lock=1
|
||||||
```
|
```
|
||||||
|
|
||||||
Expected output:
|
should produce the output:
|
||||||
|
|
||||||
```powershell
|
```console
|
||||||
Getting strip[0].mute
|
|
||||||
strip[0].mute = 0
|
|
||||||
Toggling strip[0].mute
|
|
||||||
Getting strip[0].mute
|
|
||||||
strip[0].mute = 1
|
strip[0].mute = 1
|
||||||
Setting bus[2].eq.on=1
|
Toggled strip[0].mute to 0
|
||||||
Setting command.lock=1
|
strip[0].mute = 0
|
||||||
|
Set bus[2].eq.on=1
|
||||||
|
Set command.lock=1
|
||||||
```
|
```
|
||||||
|
|
||||||
If running in interactive mode press `<Enter>` to exit.
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user