diff --git a/lib/Voicemeeter.psm1 b/lib/Voicemeeter.psm1 index d132c4e..4d5519f 100644 --- a/lib/Voicemeeter.psm1 +++ b/lib/Voicemeeter.psm1 @@ -20,11 +20,15 @@ class Remote { [String]$vmpath [Hashtable]$kind [Object]$profiles + [String]$userpath + [String]$workingconfig Remote ([String]$kindId) { $this.vmpath = Setup_DLL $this.kind = GetKind($kindId) $this.profiles = Get_Profiles($this.kind.name) + $this.userpath = Join-Path ([Environment]::GetFolderPath('MyDocuments')) 'Voicemeeter' + $this.workingconfig = Join-Path $this.userpath ('vm' + $this.kind.name + '_working.xml') } [string] ToString() { diff --git a/lib/bus.ps1 b/lib/bus.ps1 index 38e32e4..787e950 100644 --- a/lib/bus.ps1 +++ b/lib/bus.ps1 @@ -97,7 +97,7 @@ class VirtualBus : Bus { } class BusDevice : IODevice { - BusDevice ([int]$index, [Object]$remote) : base ($index, $remote) { + BusDevice ([int]$index, [Object]$remote) : base ($index, $remote, 'Output') { if ($this.index -eq 0) { AddStringMembers -PARAMS @('asio') -WriteOnly } diff --git a/lib/io.ps1 b/lib/io.ps1 index eebe18f..f767900 100644 --- a/lib/io.ps1 +++ b/lib/io.ps1 @@ -100,9 +100,57 @@ class EqCell : IRemote { } class IODevice : IRemote { - IODevice ([int]$index, [Object]$remote) : base ($index, $remote) { + [string]$kindOfDevice + + IODevice ([int]$index, [Object]$remote, [string]$kindOfDevice) : base ($index, $remote) { + $this.kindOfDevice = $kindOfDevice + AddStringMembers -WriteOnly -PARAMS @('wdm', 'ks', 'mme') AddStringMembers -ReadOnly -PARAMS @('name') AddIntMembers -ReadOnly -PARAMS @('sr') } + + hidden $_driver = $($this | Add-Member ScriptProperty 'driver' ` + { + $path = $this.remote.workingconfig + $oldTime = if (Test-Path $path) { (Get-Item $path).LastWriteTime } else { [DateTime]::MinValue } + + $this.remote.Setter('Command.Save', $path) + + $timeout = New-TimeSpan -Seconds 2 + $sw = [Diagnostics.Stopwatch]::StartNew() + $line = $null + do { + if (Test-Path $path) { + $newTime = (Get-Item $path).LastWriteTime + if ($newTime -gt $oldTime) { + try { + $line = Get-Content $path | Select-String -Pattern "<$($this.kindOfDevice)Dev index='$($this.index + 1)'" + if ($line) { break } + } + catch {} + } + } + Start-Sleep -Milliseconds 20 + } while ($sw.elapsed -lt $timeout) + + if (-not $line) { return 'unknown' } + + $type = $null + if ($line.ToString() -match "type='(?\d+)'") { + $type = $matches['type'] + } + + switch ($type) { + '1' { return 'mme' } + '4' { return 'wdm' } + '8' { return 'ks' } + '256' { return 'asio' } + default { return 'none' } + } + } ` + { + Write-Warning ("ERROR: $($this.identifier()).driver is read only") + } + ) } \ No newline at end of file diff --git a/lib/strip.ps1 b/lib/strip.ps1 index 1ac1528..c7d920e 100644 --- a/lib/strip.ps1 +++ b/lib/strip.ps1 @@ -155,7 +155,7 @@ class StripEq : IOEq { } class StripDevice : IODevice { - StripDevice ([int]$index, [Object]$remote) : base ($index, $remote) { + StripDevice ([int]$index, [Object]$remote) : base ($index, $remote, 'Input') { } [string] identifier () { diff --git a/tests/higher.Tests.ps1 b/tests/higher.Tests.ps1 index 0d06d77..dc128d9 100644 --- a/tests/higher.Tests.ps1 +++ b/tests/higher.Tests.ps1 @@ -983,24 +983,16 @@ Describe -Tag 'higher', -TestName 'All Higher Tests' { @{ Index = $phys_out } ) { Context 'Device' -ForEach @( - @{ Value = 'testOutput' }, @{ Value = '' } + @{ Driver = 'mme'; Value = 'testMme'; Expected = 'mme' } + @{ Driver = 'wdm'; Value = 'testWdm'; Expected = 'wdm' } + @{ Driver = 'ks'; Value = 'testKs'; Expected = 'ks' } + @{ Driver = 'mme'; Value = ''; Expected = 'none' } ) { - 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 + It "Should set Bus[$index].Device.$($driver)" { + $vmr.bus[$index].device.$($driver) = $value Start-Sleep -Milliseconds 800 $vmr.bus[$index].device.name | Should -Be $value + $vmr.bus[$index].device.driver | Should -Be $expected } } } @@ -1009,24 +1001,16 @@ Describe -Tag 'higher', -TestName 'All Higher Tests' { @{ Index = $virt_out } ) { Context 'Device' -Skip:$ifNotBasic -ForEach @( - @{ Value = 'testOutput' }, @{ Value = '' } + @{ Driver = 'mme'; Value = 'testMme'; Expected = 'mme' } + @{ Driver = 'wdm'; Value = 'testWdm'; Expected = 'wdm' } + @{ Driver = 'ks'; Value = 'testKs'; Expected = 'ks' } + @{ Driver = 'mme'; Value = ''; Expected = 'none' } ) { - 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 + It "Should set Bus[$index].Device.$($driver)" { + $vmr.bus[$index].device.$($driver) = $value Start-Sleep -Milliseconds 800 $vmr.bus[$index].device.name | Should -Be $value + $vmr.bus[$index].device.driver | Should -Be $expected } } }