Compare commits

..

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

View File

@ -1,10 +1,10 @@
<# <#
.SYNOPSIS 1) Loop through an array of bus objects.
Rotates through specified Voicemeeter buses, unmuting one at a time. 2) Mute first unmuted bus
.DESCRIPTION 3) If next bus in array exists, unmute it, otherwise clear unmuted variable.
This script connects to Voicemeeter Potato and allows the user to rotate through a set 4) If every bus in array is muted, unmute the first bus specified in array.
of buses (1, 2, 4, and 6). When the user presses Enter, the next bus in the sequence is unmuted,
while all other specified buses are muted. The user can exit the rotation by typing 'Q'. Credits go to @bobsupercow
#> #>
[cmdletbinding()] [cmdletbinding()]
@ -12,58 +12,36 @@ param()
Import-Module ..\..\lib\Voicemeeter.psm1 Import-Module ..\..\lib\Voicemeeter.psm1
<#
A class that accepts a list of Voicemeeter buses and unmutes them one at a time in a round-robin fashion
#>
class BusRotator {
[object]$vmr = $null
[int]$CurrentIndex = -1
[object[]]$Buses
BusRotator([object]$vmr, [object[]]$buses) {
$this.vmr = $vmr
$this.Buses = $buses
}
hidden [object] GetNextBus() {
# Mute all buses in the list
foreach ($bus in $this.Buses) {
$bus.mute = $true
}
# Determine the next bus to unmute
$this.CurrentIndex = ($this.CurrentIndex + 1) % $this.Buses.Count
return $this.Buses[$this.CurrentIndex]
}
[object] UnmuteNextBus() {
$nextBus = $this.GetNextBus()
$nextBus.mute = $false
return $nextBus
}
}
try { try {
$vmr = Connect-Voicemeeter -Kind 'potato' $vmr = Connect-Voicemeeter -Kind 'potato'
# Mute all buses initially $buses = @($vmr.bus[1], $vmr.bus[2], $vmr.bus[4], $vmr.bus[6])
foreach ($bus in $vmr.bus) { "Buses in selection: $($buses)"
$bus.mute = $true $unmutedIndex = $null
}
$busesToRotate = @( # 1)
$vmr.bus[1], 'Cycling through bus selection to check for first unmuted Bus...' | Write-Host
$vmr.bus[2], foreach ($bus in $buses) {
$vmr.bus[4], # 2)
$vmr.bus[6] if (-not $bus.mute) {
) "Bus $($bus.index) is unmuted... muting it" | Write-Host
$unmutedIndex = $buses.IndexOf($bus)
$bus.mute = $true
$rotator = [BusRotator]::new($vmr, $busesToRotate) # 3)
while ((Read-Host "Press Enter to rotate buses or type 'Q' to quit.") -ne 'Q') { if ($buses[++$unmutedIndex]) {
$nextBus = $rotator.UnmuteNextBus() "Unmuting Bus $($buses[$unmutedIndex].index)" | Write-Host
Write-Host "Bus $nextBus is now unmuted." $buses[$unmutedIndex].mute = $false
break
}
else { Clear-Variable unmutedIndex }
}
} }
# 4)
if ($null -eq $unmutedIndex) {
$buses[0].mute = $false
"Unmuting Bus $($buses[0].index)" | Write-Host
}
} }
finally { Disconnect-Voicemeeter } finally { Disconnect-Voicemeeter }