diff --git a/CHANGELOG.md b/CHANGELOG.md index 95abcc3..0cde41a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ Before any major/minor/patch is released all test units will be run to verify th - ArrayMember classes for array-like properties - Patch class - Option class +- Device classes ## [3.3.0] - 2024-06-29 diff --git a/README.md b/README.md index 12223c6..694399b 100644 --- a/README.md +++ b/README.md @@ -312,6 +312,7 @@ $vmr.bus[0].device.name name, sr are defined as read only. wdm, ks, mme, asio are defined as write only. +asio only defined for Bus[0].Device #### eq diff --git a/lib/Voicemeeter.psm1 b/lib/Voicemeeter.psm1 index 4c24d3e..42b0762 100644 --- a/lib/Voicemeeter.psm1 +++ b/lib/Voicemeeter.psm1 @@ -4,6 +4,7 @@ . $PSScriptRoot\kinds.ps1 . $PSScriptRoot\iremote.ps1 . $PSScriptRoot\arraymember.ps1 +. $PSScriptRoot\device.ps1 . $PSScriptRoot\strip.ps1 . $PSScriptRoot\bus.ps1 . $PSScriptRoot\macrobuttons.ps1 diff --git a/lib/bus.ps1 b/lib/bus.ps1 index d59cdee..bd0ac15 100644 --- a/lib/bus.ps1 +++ b/lib/bus.ps1 @@ -101,75 +101,35 @@ class PhysicalBus : Bus { } } -class BusDevice : IRemote { +class VirtualBus : Bus { + [Object]$device + + VirtualBus ([int]$index, [Object]$remote) : base ($index, $remote) { + if ($this.remote.kind.name -eq 'basic') { + $this.device = [BusDevice]::new($index, $remote) + } + } +} + +class BusDevice : Device { BusDevice ([int]$index, [Object]$remote) : base ($index, $remote) { + if ($this.index -eq 0) { + $this.AddASIO() + } } [string] identifier () { return 'Bus[' + $this.index + '].Device' } - hidden $_name = $($this | Add-Member ScriptProperty 'name' ` - { - $this.Getter_String('name') - } ` - { - return Write-Warning ("ERROR: $($this.identifier()).name is read only") - } - ) - - hidden $_sr = $($this | Add-Member ScriptProperty 'sr' ` - { - $this.Getter('sr') - } ` - { - return Write-Warning ("ERROR: $($this.identifier()).sr is read only") - } - ) - - hidden $_wdm = $($this | Add-Member ScriptProperty 'wdm' ` - { - return Write-Warning ("ERROR: $($this.identifier()).wdm is write only") - } ` - { - param($arg) - return $this.Setter('wdm', $arg) - } - ) - - hidden $_ks = $($this | Add-Member ScriptProperty 'ks' ` - { - return Write-Warning ("ERROR: $($this.identifier()).ks is write only") - } ` - { - param($arg) - return $this.Setter('ks', $arg) - } - ) - - hidden $_mme = $($this | Add-Member ScriptProperty 'mme' ` - { - return Write-Warning ("ERROR: $($this.identifier()).mme is write only") - } ` - { - param($arg) - return $this.Setter('mme', $arg) - } - ) - - hidden $_asio = $($this | Add-Member ScriptProperty 'asio' ` - { + hidden [void] AddASIO () { + Add-Member -InputObject $this -MemberType ScriptProperty -Name 'asio' ` + -Value { return Write-Warning ("ERROR: $($this.identifier()).asio is write only") - } ` - { + } -SecondValue { param($arg) return $this.Setter('asio', $arg) - } - ) -} - -class VirtualBus : Bus { - VirtualBus ([int]$index, [Object]$remote) : base ($index, $remote) { + } -Force } } diff --git a/lib/device.ps1 b/lib/device.ps1 new file mode 100644 index 0000000..df8feb3 --- /dev/null +++ b/lib/device.ps1 @@ -0,0 +1,52 @@ +class Device : IRemote { + Device ([int]$index, [Object]$remote) : base ($index, $remote) { + } + + hidden $_name = $($this | Add-Member ScriptProperty 'name' ` + { + $this.Getter_String('name') + } ` + { + return Write-Warning ("ERROR: $($this.identifier()).name is read only") + } + ) + + hidden $_sr = $($this | Add-Member ScriptProperty 'sr' ` + { + [int]$this.Getter('sr') + } ` + { + return Write-Warning ("ERROR: $($this.identifier()).sr is read only") + } + ) + + hidden $_wdm = $($this | Add-Member ScriptProperty 'wdm' ` + { + return Write-Warning ("ERROR: $($this.identifier()).wdm is write only") + } ` + { + param($arg) + return $this.Setter('wdm', $arg) + } + ) + + hidden $_ks = $($this | Add-Member ScriptProperty 'ks' ` + { + return Write-Warning ("ERROR: $($this.identifier()).ks is write only") + } ` + { + param($arg) + return $this.Setter('ks', $arg) + } + ) + + hidden $_mme = $($this | Add-Member ScriptProperty 'mme' ` + { + return Write-Warning ("ERROR: $($this.identifier()).mme is write only") + } ` + { + param($arg) + return $this.Setter('mme', $arg) + } + ) +} \ No newline at end of file diff --git a/lib/strip.ps1 b/lib/strip.ps1 index 2c0821e..ef16163 100644 --- a/lib/strip.ps1 +++ b/lib/strip.ps1 @@ -162,71 +162,13 @@ class StripEq : IRemote { } } -class StripDevice : IRemote { +class StripDevice : Device { StripDevice ([int]$index, [Object]$remote) : base ($index, $remote) { } [string] identifier () { return 'Strip[' + $this.index + '].Device' } - - hidden $_name = $($this | Add-Member ScriptProperty 'name' ` - { - $this.Getter_String('name') - } ` - { - return Write-Warning ("ERROR: $($this.identifier()).name is read only") - } - ) - - hidden $_sr = $($this | Add-Member ScriptProperty 'sr' ` - { - $this.Getter('sr') - } ` - { - return Write-Warning ("ERROR: $($this.identifier()).sr is read only") - } - ) - - hidden $_wdm = $($this | Add-Member ScriptProperty 'wdm' ` - { - return Write-Warning ("ERROR: $($this.identifier()).wdm is write only") - } ` - { - param($arg) - return $this.Setter('wdm', $arg) - } - ) - - hidden $_ks = $($this | Add-Member ScriptProperty 'ks' ` - { - return Write-Warning ("ERROR: $($this.identifier()).ks is write only") - } ` - { - param($arg) - return $this.Setter('ks', $arg) - } - ) - - hidden $_mme = $($this | Add-Member ScriptProperty 'mme' ` - { - return Write-Warning ("ERROR: $($this.identifier()).mme is write only") - } ` - { - param($arg) - return $this.Setter('mme', $arg) - } - ) - - hidden $_asio = $($this | Add-Member ScriptProperty 'asio' ` - { - return Write-Warning ("ERROR: $($this.identifier()).asio is write only") - } ` - { - param($arg) - return $this.Setter('asio', $arg) - } - ) } class VirtualStrip : Strip { diff --git a/tests/higher.Tests.ps1 b/tests/higher.Tests.ps1 index aa825ae..3f2dda0 100644 --- a/tests/higher.Tests.ps1 +++ b/tests/higher.Tests.ps1 @@ -251,39 +251,67 @@ Describe -Tag 'higher', -TestName 'All Higher Tests' { } } - Describe 'Int Tests' -ForEach @( - @{ Index = $phys_in }, @{ Index = $virt_in } - ) { - Context 'Strip, one physical, one virtual' -Skip:$ifBasic -ForEach @( - @{ Value = 3; Expected = 3 } - @{ Value = -6; Expected = -6 } + Describe 'Int Tests' { + Context 'Strip, one physical, one virtual' -ForEach @( + @{ Index = $phys_in }, @{ Index = $virt_in } ) { - It "Should set Strip[$index].Limit to 3" { + It "Should set and get Strip[$index].Limit" -Skip:$ifBasic -ForEach @( + @{ Value = 3; Expected = 3 } + @{ Value = -6; Expected = -6 } + ) { $vmr.strip[$index].limit = $value $vmr.strip[$index].limit | Should -Be $expected } } - Context 'Vban outstream' { - Context 'sr' -ForEach @( + Context 'Strip, physical only' -ForEach @( + @{ Index = $phys_in } + ) { + Context 'Device' { + It "Should get Strip[$index].Device.sr" { + $vmr.strip[$index].device.sr | Should -BeOfType [int] + } + } + } + + Context 'Bus, physical only' -ForEach @( + @{ Index = $phys_out } + ) { + Context 'Device' { + It "Should get Bus[$index].Device.sr" { + $vmr.bus[$index].device.sr | Should -BeOfType [int] + } + } + } + + Context 'Bus, virtual only' -ForEach @( + @{ Index = $virt_out } + ) { + Context 'Device' -Skip:$ifNotBasic { + It "Should get Bus[$index].Device.sr" { + $vmr.bus[$index].device.sr | Should -BeOfType [int] + } + } + } + + Context 'Vban outstream' -ForEach @( + @{ Index = $vban_out } + ) { + It "Should set vban.outstream[$index].sr to $value" -ForEach @( @{ Value = 44100; Expected = 44100 } @{ Value = 48000; Expected = 48000 } ) { - It "Should set vban.outstream[$index].sr to $value" { - $vmr.vban.outstream[$index].sr = $value - $vmr.vban.outstream[$index].sr | Should -Be $expected - } + $vmr.vban.outstream[$index].sr = $value + $vmr.vban.outstream[$index].sr | Should -Be $expected } - Context 'channel' -ForEach @( + It 'Should set vban.outstream[0].channel to 1' -ForEach @( @{ Value = 1; Expected = 1 } @{ Value = 2; Expected = 2 } ) { - It 'Should set vban.outstream[0].channel to 1' { - $vmr.vban.outstream[$index].channel = $value - $vmr.vban.outstream[$index].channel | Should -Be $expected - } - } + $vmr.vban.outstream[$index].channel = $value + $vmr.vban.outstream[$index].channel | Should -Be $expected + } } Context 'Patch' { @@ -341,6 +369,32 @@ Describe -Tag 'higher', -TestName 'All Higher Tests' { } } + Context 'Strip, physical only' -ForEach @( + @{ Index = $phys_in } + ) { + Context 'Device' -ForEach @( + @{ Value = 'testInput' }, @{ Value = '' } + ) { + It "Should set Strip[$index].Device.wdm" { + $vmr.strip[$index].device.wdm = $value + Start-Sleep -Milliseconds 800 + $vmr.strip[$index].device.name | Should -Be $value + } + + It "Should set Strip[$index].Device.ks" { + $vmr.strip[$index].device.ks = $value + Start-Sleep -Milliseconds 800 + $vmr.strip[$index].device.name | Should -Be $value + } + + It "Should set Strip[$index].Device.mme" { + $vmr.strip[$index].device.mme = $value + Start-Sleep -Milliseconds 800 + $vmr.strip[$index].device.name | Should -Be $value + } + } + } + Context 'Bus, one physical, one virtual' -ForEach @( @{ Index = $phys_out }, @{ Index = $virt_out } ) { @@ -353,6 +407,58 @@ Describe -Tag 'higher', -TestName 'All Higher Tests' { } } + Context 'Bus, physical only' -ForEach @( + @{ Index = $phys_out } + ) { + Context 'Device' -ForEach @( + @{ Value = 'testOutput' }, @{ Value = '' } + ) { + It "Should set Bus[$index].Device.wdm" { + $vmr.bus[$index].device.wdm = $value + Start-Sleep -Milliseconds 800 + $vmr.bus[$index].device.name | Should -Be $value + } + + It "Should set Bus[$index].Device.ks" { + $vmr.bus[$index].device.ks = $value + Start-Sleep -Milliseconds 800 + $vmr.bus[$index].device.name | Should -Be $value + } + + It "Should set Bus[$index].Device.mme" { + $vmr.bus[$index].device.mme = $value + Start-Sleep -Milliseconds 800 + $vmr.bus[$index].device.name | Should -Be $value + } + } + } + + Context 'Bus, virtual only' -ForEach @( + @{ Index = $virt_out } + ) { + Context 'Device' -Skip:$ifNotBasic -ForEach @( + @{ Value = 'testOutput' }, @{ Value = '' } + ) { + It "Should set Bus[$index].Device.wdm" { + $vmr.bus[$index].device.wdm = $value + Start-Sleep -Milliseconds 800 + $vmr.bus[$index].device.name | Should -Be $value + } + + It "Should set Bus[$index].Device.ks" { + $vmr.bus[$index].device.ks = $value + Start-Sleep -Milliseconds 800 + $vmr.bus[$index].device.name | Should -Be $value + } + + It "Should set Bus[$index].Device.mme" { + $vmr.bus[$index].device.mme = $value + Start-Sleep -Milliseconds 800 + $vmr.bus[$index].device.name | Should -Be $value + } + } + } + Describe 'Vban' -ForEach @( @{ Index = $vban_in } ) { diff --git a/tests/run.ps1 b/tests/run.ps1 index e6fa0a6..e592d91 100644 --- a/tests/run.ps1 +++ b/tests/run.ps1 @@ -21,6 +21,7 @@ function main() { # skip conditions by kind $ifBasic = $vmr.kind.name -eq 'basic' + $ifNotBasic = $vmr.kind.name -ne 'basic' $ifNotPotato = $vmr.kind.name -ne 'potato' Invoke-Pester -Tag $tag -PassThru | Out-Null