Compare commits

..

No commits in common. "3119b1080e7084e64d5c267ba18b9fc6b7f3dd27" and "65424733945e07bb6a79d41191abe1f4ea46c07a" have entirely different histories.

2 changed files with 59 additions and 118 deletions

View File

@ -1,22 +1,5 @@
<#
.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 = @()
@ -24,99 +7,62 @@ param(
Import-Module ..\..\lib\Voicemeeter.psm1 Import-Module ..\..\lib\Voicemeeter.psm1
if ($help -or ($script.Count -eq 0 -and -not $interactive)) { function get-value {
Write-Host 'Voicemeeter CLI' param([object]$vmr, [string]$line)
Write-Host ''
Write-Host 'Usage:'
Write-Host ' CLI.ps1 [-interactive] [-kind <basic|banana|potato>] [-script <command1>, <command2>, ...]'
Write-Host ''
Write-Host 'Options:'
Write-Host ' -help Display this help message.'
Write-Host ' -interactive Start in interactive mode.'
Write-Host ' -kind <type> Specify the Voicemeeter type (basic, 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($Parameter) $retval = $vmr.Getter($line)
} }
catch { catch {
$retval = $vmr.Getter_String($Parameter) $retval = $vmr.Getter_String($line)
} }
$retval $retval
} }
function msgHandler {
function Invoke-VoicemeeterCLICommand { param([object]$vmr, [string]$line)
param( $line + ' passed to handler' | Write-Debug
[object]$vmr, if ($line[0] -eq '!') {
[string]$Command 'Toggling ' + $line.substring(1) | Write-Debug
) $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"
} }
# Set command elseif ($line.Contains('=')) {
elseif ($Command.Contains('=')) { "Setting $line" | Write-Debug
$vmr.SendText("$Command") $vmr.SendText($line)
Write-Host "Set $Command"
} }
# Get command
else { else {
$parameter = $Command.Trim() "Getting $line" | Write-Debug
$value = Get-ParameterValue -vmr $vmr -Parameter $parameter $retval = get-value -vmr $vmr -line $line
Write-Host "$parameter = $value" $line + ' = ' + $retval | Write-Host
} }
} }
function Start-VoicemeeterCLI { function read-hostuntilempty {
param( param([object]$vmr)
[object]$vmr while (($line = Read-Host) -cne [string]::Empty) { msgHandler -vmr $vmr -line $line }
)
Write-Host "Connected to Voicemeeter. Type 'Q' to quit." -ForegroundColor Green
while (($CommandFromInput = Read-Host 'command') -ne 'Q') {
try {
Invoke-VoicemeeterCLICommand -vmr $vmr -Command $CommandFromInput
}
catch {
Write-Host "Error: $_" -ForegroundColor Red
}
}
} }
try {
$vmr = Connect-Voicemeeter -Kind $kind function main {
[object]$vmr
try {
$vmr = Connect-Voicemeeter -Kind $kind
if ($interactive) { if ($interactive) {
Start-VoicemeeterCLI -vmr $vmr 'Press <Enter> to exit' | Write-Host
} read-hostuntilempty -vmr $vmr
else { return
foreach ($command in $script) { }
Invoke-VoicemeeterCLICommand -vmr $vmr -Command $command 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

View File

@ -1,39 +1,34 @@
## About ## About
A basic command-line interface A simple voicemeeter-cli script. Offers ability to toggle, get and set parameters.
## Use ## Use
```console Toggle with `!` prefix, get by excluding `=` and set by including `=`. Mix and match arguments.
Voicemeeter CLI
Usage: You may pass the following optional flags:
CLI.ps1 [-interactive] [-kind <basic|banana|potato>] [-script <command1>, <command2>, ...]
Options: - -o: (-output) to toggle console output.
-help Display this help message. - -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 (basic, 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 -script strip[0].mute, !strip[0].mute, strip[0].mute, bus[2].eq.on=1, command.lock=1 .\CLI.ps1 -o -k "banana" -s "strip[0].mute", "!strip[0].mute", "strip[0].mute", "bus[2].eq.on=1", "command.lock=1"
``` ```
should produce the output: Expected output:
```console ```powershell
strip[0].mute = 1 Getting strip[0].mute
Toggled strip[0].mute to 0
strip[0].mute = 0 strip[0].mute = 0
Set bus[2].eq.on=1 Toggling strip[0].mute
Set command.lock=1 Getting strip[0].mute
``` strip[0].mute = 1
Setting bus[2].eq.on=1
Setting command.lock=1
```
If running in interactive mode press `<Enter>` to exit.