mirror of
https://github.com/onyx-and-iris/voicemeeter-api-powershell.git
synced 2026-01-25 01:37:47 +00:00
nextbus example
This commit is contained in:
parent
dfa044d853
commit
448aa01ad2
@ -1,10 +1,10 @@
|
|||||||
<#
|
<#
|
||||||
1) Loop through an array of bus objects.
|
.SYNOPSIS
|
||||||
2) Mute first unmuted bus
|
Rotates through specified Voicemeeter buses, unmuting one at a time.
|
||||||
3) If next bus in array exists, unmute it, otherwise clear unmuted variable.
|
.DESCRIPTION
|
||||||
4) If every bus in array is muted, unmute the first bus specified in array.
|
This script connects to Voicemeeter Potato and allows the user to rotate through a set
|
||||||
|
of buses (1, 2, 4, and 6). When the user presses Enter, the next bus in the sequence is unmuted,
|
||||||
Credits go to @bobsupercow
|
while all other specified buses are muted. The user can exit the rotation by typing 'Q'.
|
||||||
#>
|
#>
|
||||||
|
|
||||||
[cmdletbinding()]
|
[cmdletbinding()]
|
||||||
@ -12,36 +12,58 @@ 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] MuteNextBus() {
|
||||||
|
$nextBus = $this.GetNextBus()
|
||||||
|
$nextBus.mute = $false
|
||||||
|
return $nextBus
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$vmr = Connect-Voicemeeter -Kind 'potato'
|
$vmr = Connect-Voicemeeter -Kind 'potato'
|
||||||
|
|
||||||
$buses = @($vmr.bus[1], $vmr.bus[2], $vmr.bus[4], $vmr.bus[6])
|
# Mute all buses initially
|
||||||
"Buses in selection: $($buses)"
|
foreach ($bus in $vmr.bus) {
|
||||||
$unmutedIndex = $null
|
$bus.mute = $true
|
||||||
|
|
||||||
# 1)
|
|
||||||
'Cycling through bus selection to check for first unmuted Bus...' | Write-Host
|
|
||||||
foreach ($bus in $buses) {
|
|
||||||
# 2)
|
|
||||||
if (-not $bus.mute) {
|
|
||||||
"Bus $($bus.index) is unmuted... muting it" | Write-Host
|
|
||||||
$unmutedIndex = $buses.IndexOf($bus)
|
|
||||||
$bus.mute = $true
|
|
||||||
|
|
||||||
# 3)
|
|
||||||
if ($buses[++$unmutedIndex]) {
|
|
||||||
"Unmuting Bus $($buses[$unmutedIndex].index)" | Write-Host
|
|
||||||
$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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$busesToRotate = @(
|
||||||
|
$vmr.bus[1],
|
||||||
|
$vmr.bus[2],
|
||||||
|
$vmr.bus[4],
|
||||||
|
$vmr.bus[6]
|
||||||
|
)
|
||||||
|
|
||||||
|
$rotator = [BusRotator]::new($vmr, $busesToRotate)
|
||||||
|
while ((Read-Host "Press Enter to rotate buses or type 'Q' to quit.") -ne 'Q') {
|
||||||
|
$nextBus = $rotator.MuteNextBus()
|
||||||
|
Write-Host "Bus $nextBus is now unmuted."
|
||||||
|
}
|
||||||
}
|
}
|
||||||
finally { Disconnect-Voicemeeter }
|
finally { Disconnect-Voicemeeter }
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user