mirror of
https://github.com/onyx-and-iris/voicemeeter-api-powershell.git
synced 2026-03-20 08:59:10 +00:00
Get(), Set($device), Clear()
methods added to IODevice manual and pester tests pass for all kinds
This commit is contained in:
parent
4ea371af2f
commit
7d9615d760
@ -106,6 +106,14 @@ class BusDevice : IODevice {
|
|||||||
[string] identifier () {
|
[string] identifier () {
|
||||||
return 'Bus[' + $this.index + '].Device'
|
return 'Bus[' + $this.index + '].Device'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[int] EnumCount () {
|
||||||
|
return $this.remote.GetOutputCount()
|
||||||
|
}
|
||||||
|
|
||||||
|
[PSObject] EnumDevice ([int]$eIndex) {
|
||||||
|
return $this.remote.GetOutputDevice($eIndex)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function Make_Buses ([Object]$remote) {
|
function Make_Buses ([Object]$remote) {
|
||||||
|
|||||||
49
lib/io.ps1
49
lib/io.ps1
@ -118,6 +118,55 @@ class IODevice : IRemote {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[int] EnumCount () {
|
||||||
|
throw [System.NotImplementedException]::new("$($this.GetType().Name) must override EnumCount()")
|
||||||
|
}
|
||||||
|
|
||||||
|
[PSObject] EnumDevice ([int]$eIndex) {
|
||||||
|
throw [System.NotImplementedException]::new("$($this.GetType().Name) must override EnumDevice()")
|
||||||
|
}
|
||||||
|
|
||||||
|
[PSObject] Get () {
|
||||||
|
$device = [PSCustomObject]@{
|
||||||
|
Driver = $this.driver
|
||||||
|
Name = $this.name
|
||||||
|
HardwareId = ''
|
||||||
|
IsOutput = $this.kindOfDevice -eq 'Output'
|
||||||
|
}
|
||||||
|
if (-not [string]::IsNullOrEmpty($device.Name)) {
|
||||||
|
for ($i = 0; $i -lt $this.EnumCount(); $i++) {
|
||||||
|
$eDevice = $this.EnumDevice($i)
|
||||||
|
if ($eDevice.Name -eq $device.Name -and $eDevice.Driver -eq $device.Driver) {
|
||||||
|
$device = $eDevice
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $device
|
||||||
|
}
|
||||||
|
|
||||||
|
[void] Set ([PSObject]$device) {
|
||||||
|
$v = $device.IsOutput -eq ($this.kindOfDevice -eq 'Output')
|
||||||
|
$d = $device.Driver
|
||||||
|
$n = $device.Name
|
||||||
|
|
||||||
|
if ($v -and $d -is [string] -and $n -is [string]) {
|
||||||
|
if ($d -eq '' -and $n -eq '') {
|
||||||
|
$this.Clear()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if ($d -in $this.drivers.Values) {
|
||||||
|
$this.Setter($d, $n)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Write-Warning "Invalid device object provided to Set method."
|
||||||
|
}
|
||||||
|
|
||||||
|
[void] Clear () {
|
||||||
|
$this.Setter('mme', '')
|
||||||
|
}
|
||||||
|
|
||||||
hidden $_driver = $($this | Add-Member ScriptProperty 'driver' `
|
hidden $_driver = $($this | Add-Member ScriptProperty 'driver' `
|
||||||
{
|
{
|
||||||
if ([string]::IsNullOrEmpty($this.name)) { return '' }
|
if ([string]::IsNullOrEmpty($this.name)) { return '' }
|
||||||
|
|||||||
@ -161,6 +161,14 @@ class StripDevice : IODevice {
|
|||||||
[string] identifier () {
|
[string] identifier () {
|
||||||
return 'Strip[' + $this.index + '].Device'
|
return 'Strip[' + $this.index + '].Device'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[int] EnumCount () {
|
||||||
|
return $this.remote.GetInputCount()
|
||||||
|
}
|
||||||
|
|
||||||
|
[PSObject] EnumDevice ([int]$eIndex) {
|
||||||
|
return $this.remote.GetInputDevice($eIndex)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class VirtualStrip : Strip {
|
class VirtualStrip : Strip {
|
||||||
|
|||||||
@ -850,24 +850,47 @@ Describe -Tag 'higher', -TestName 'All Higher Tests' {
|
|||||||
@{ Index = $phys_in }
|
@{ Index = $phys_in }
|
||||||
) {
|
) {
|
||||||
Context 'Device' -ForEach @(
|
Context 'Device' -ForEach @(
|
||||||
@{ Value = 'testInput' }, @{ Value = '' }
|
@{ Driver = 'mme'; Value = 'testMme'; Expected = 'mme' }
|
||||||
|
@{ Driver = 'wdm'; Value = 'testWdm'; Expected = 'wdm' }
|
||||||
|
@{ Driver = 'ks'; Value = 'testKs'; Expected = 'ks' }
|
||||||
|
@{ Driver = 'mme'; Value = ''; Expected = '' }
|
||||||
) {
|
) {
|
||||||
It "Should set Strip[$index].Device.wdm" {
|
BeforeEach {
|
||||||
$vmr.strip[$index].device.wdm = $value
|
$vmr.strip[$index].device.Clear()
|
||||||
Start-Sleep -Milliseconds 800
|
Start-Sleep -Milliseconds 800
|
||||||
$vmr.strip[$index].device.name | Should -Be $value
|
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Should set Strip[$index].Device.ks" {
|
It "Should set Strip[$index].Device.$($driver)" {
|
||||||
$vmr.strip[$index].device.ks = $value
|
$vmr.strip[$index].device.name | Should -Be ''
|
||||||
|
$vmr.strip[$index].device.driver | Should -Be ''
|
||||||
|
|
||||||
|
$vmr.strip[$index].device.$($driver) = $value
|
||||||
Start-Sleep -Milliseconds 800
|
Start-Sleep -Milliseconds 800
|
||||||
$vmr.strip[$index].device.name | Should -Be $value
|
$vmr.strip[$index].device.name | Should -Be $value
|
||||||
|
$vmr.strip[$index].device.driver | Should -Be $expected
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Should set Strip[$index].Device.mme" {
|
It "Should set Strip[$index].Device" -ForEach @(
|
||||||
$vmr.strip[$index].device.mme = $value
|
@{
|
||||||
|
Clear = [PSCustomObject]@{ Driver = ''; Name = ''; HardwareId = ''; IsOutput = $false }
|
||||||
|
Device = [PSCustomObject]@{ Driver = $expected; Name = $value; HardwareId = ''; IsOutput = $false }
|
||||||
|
}
|
||||||
|
) {
|
||||||
|
$initial = $vmr.strip[$index].device.Get()
|
||||||
|
|
||||||
|
$initial.Driver | Should -Be $clear.Driver
|
||||||
|
$initial.Name | Should -Be $clear.Name
|
||||||
|
$initial.HardwareId | Should -Be $clear.HardwareId
|
||||||
|
$initial.IsOutput | Should -Be $clear.IsOutput
|
||||||
|
|
||||||
|
$vmr.strip[$index].device.Set($device)
|
||||||
Start-Sleep -Milliseconds 800
|
Start-Sleep -Milliseconds 800
|
||||||
$vmr.strip[$index].device.name | Should -Be $value
|
$result = $vmr.strip[$index].device.Get()
|
||||||
|
|
||||||
|
$result.Driver | Should -Be $device.Driver
|
||||||
|
$result.Name | Should -Be $device.Name
|
||||||
|
$result.HardwareId | Should -Be $device.HardwareId
|
||||||
|
$result.IsOutput | Should -Be $device.IsOutput
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -986,14 +1009,45 @@ Describe -Tag 'higher', -TestName 'All Higher Tests' {
|
|||||||
@{ Driver = 'mme'; Value = 'testMme'; Expected = 'mme' }
|
@{ Driver = 'mme'; Value = 'testMme'; Expected = 'mme' }
|
||||||
@{ Driver = 'wdm'; Value = 'testWdm'; Expected = 'wdm' }
|
@{ Driver = 'wdm'; Value = 'testWdm'; Expected = 'wdm' }
|
||||||
@{ Driver = 'ks'; Value = 'testKs'; Expected = 'ks' }
|
@{ Driver = 'ks'; Value = 'testKs'; Expected = 'ks' }
|
||||||
@{ Driver = 'mme'; Value = ''; Expected = 'none' }
|
@{ Driver = 'mme'; Value = ''; Expected = '' }
|
||||||
) {
|
) {
|
||||||
|
BeforeEach {
|
||||||
|
$vmr.bus[$index].device.Clear()
|
||||||
|
Start-Sleep -Milliseconds 800
|
||||||
|
}
|
||||||
|
|
||||||
It "Should set Bus[$index].Device.$($driver)" {
|
It "Should set Bus[$index].Device.$($driver)" {
|
||||||
|
$vmr.bus[$index].device.name | Should -Be ''
|
||||||
|
$vmr.bus[$index].device.driver | Should -Be ''
|
||||||
|
|
||||||
$vmr.bus[$index].device.$($driver) = $value
|
$vmr.bus[$index].device.$($driver) = $value
|
||||||
Start-Sleep -Milliseconds 800
|
Start-Sleep -Milliseconds 800
|
||||||
$vmr.bus[$index].device.name | Should -Be $value
|
$vmr.bus[$index].device.name | Should -Be $value
|
||||||
$vmr.bus[$index].device.driver | Should -Be $expected
|
$vmr.bus[$index].device.driver | Should -Be $expected
|
||||||
}
|
}
|
||||||
|
|
||||||
|
It "Should set Bus[$index].Device" -ForEach @(
|
||||||
|
@{
|
||||||
|
Clear = [PSCustomObject]@{ Driver = ''; Name = ''; HardwareId = ''; IsOutput = $true }
|
||||||
|
Device = [PSCustomObject]@{ Driver = $expected; Name = $value; HardwareId = ''; IsOutput = $true }
|
||||||
|
}
|
||||||
|
) {
|
||||||
|
$initial = $vmr.bus[$index].device.Get()
|
||||||
|
|
||||||
|
$initial.Driver | Should -Be $clear.Driver
|
||||||
|
$initial.Name | Should -Be $clear.Name
|
||||||
|
$initial.HardwareId | Should -Be $clear.HardwareId
|
||||||
|
$initial.IsOutput | Should -Be $clear.IsOutput
|
||||||
|
|
||||||
|
$vmr.bus[$index].device.Set($device)
|
||||||
|
Start-Sleep -Milliseconds 800
|
||||||
|
$result = $vmr.bus[$index].device.Get()
|
||||||
|
|
||||||
|
$result.Driver | Should -Be $device.Driver
|
||||||
|
$result.Name | Should -Be $device.Name
|
||||||
|
$result.HardwareId | Should -Be $device.HardwareId
|
||||||
|
$result.IsOutput | Should -Be $device.IsOutput
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1004,14 +1058,45 @@ Describe -Tag 'higher', -TestName 'All Higher Tests' {
|
|||||||
@{ Driver = 'mme'; Value = 'testMme'; Expected = 'mme' }
|
@{ Driver = 'mme'; Value = 'testMme'; Expected = 'mme' }
|
||||||
@{ Driver = 'wdm'; Value = 'testWdm'; Expected = 'wdm' }
|
@{ Driver = 'wdm'; Value = 'testWdm'; Expected = 'wdm' }
|
||||||
@{ Driver = 'ks'; Value = 'testKs'; Expected = 'ks' }
|
@{ Driver = 'ks'; Value = 'testKs'; Expected = 'ks' }
|
||||||
@{ Driver = 'mme'; Value = ''; Expected = 'none' }
|
@{ Driver = 'mme'; Value = ''; Expected = '' }
|
||||||
) {
|
) {
|
||||||
|
BeforeEach {
|
||||||
|
$vmr.bus[$index].device.Clear()
|
||||||
|
Start-Sleep -Milliseconds 800
|
||||||
|
}
|
||||||
|
|
||||||
It "Should set Bus[$index].Device.$($driver)" {
|
It "Should set Bus[$index].Device.$($driver)" {
|
||||||
|
$vmr.bus[$index].device.name | Should -Be ''
|
||||||
|
$vmr.bus[$index].device.driver | Should -Be ''
|
||||||
|
|
||||||
$vmr.bus[$index].device.$($driver) = $value
|
$vmr.bus[$index].device.$($driver) = $value
|
||||||
Start-Sleep -Milliseconds 800
|
Start-Sleep -Milliseconds 800
|
||||||
$vmr.bus[$index].device.name | Should -Be $value
|
$vmr.bus[$index].device.name | Should -Be $value
|
||||||
$vmr.bus[$index].device.driver | Should -Be $expected
|
$vmr.bus[$index].device.driver | Should -Be $expected
|
||||||
}
|
}
|
||||||
|
|
||||||
|
It "Should set Bus[$index].Device" -ForEach @(
|
||||||
|
@{
|
||||||
|
Clear = [PSCustomObject]@{ Driver = ''; Name = ''; HardwareId = ''; IsOutput = $true }
|
||||||
|
Device = [PSCustomObject]@{ Driver = $expected; Name = $value; HardwareId = ''; IsOutput = $true }
|
||||||
|
}
|
||||||
|
) {
|
||||||
|
$initial = $vmr.bus[$index].device.Get()
|
||||||
|
|
||||||
|
$initial.Driver | Should -Be $clear.Driver
|
||||||
|
$initial.Name | Should -Be $clear.Name
|
||||||
|
$initial.HardwareId | Should -Be $clear.HardwareId
|
||||||
|
$initial.IsOutput | Should -Be $clear.IsOutput
|
||||||
|
|
||||||
|
$vmr.bus[$index].device.Set($device)
|
||||||
|
Start-Sleep -Milliseconds 800
|
||||||
|
$result = $vmr.bus[$index].device.Get()
|
||||||
|
|
||||||
|
$result.Driver | Should -Be $device.Driver
|
||||||
|
$result.Name | Should -Be $device.Name
|
||||||
|
$result.HardwareId | Should -Be $device.HardwareId
|
||||||
|
$result.IsOutput | Should -Be $device.IsOutput
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user