diff --git a/lib/Voicemeeter.psm1 b/lib/Voicemeeter.psm1 index d68e388..d132c4e 100644 --- a/lib/Voicemeeter.psm1 +++ b/lib/Voicemeeter.psm1 @@ -75,6 +75,22 @@ class Remote { [void] PDirty() { P_Dirty } [void] MDirty() { M_Dirty } + + [int] GetOutputCount() { + return Device_Count -IS_OUT $true + } + + [int] GetInputCount() { + return Device_Count + } + + [PSObject] GetOutputDevice([int]$index) { + return Device_Desc -INDEX $index -IS_OUT $true + } + + [PSObject] GetInputDevice([int]$index) { + return Device_Desc -INDEX $index + } } class RemoteBasic : Remote { diff --git a/lib/base.ps1 b/lib/base.ps1 index 331c8d5..84a4da5 100644 --- a/lib/base.ps1 +++ b/lib/base.ps1 @@ -225,4 +225,59 @@ function Get_Level { throw [CAPIError]::new($retval, 'VBVMR_GetLevel') } [float]$ptr +} + +function Device_Count { + param( + [bool]$IS_OUT = $false + ) + if ($IS_OUT) { + $retval = [int][Voicemeeter.Remote]::VBVMR_Output_GetDeviceNumber() + if ($retval -lt 0) { + throw [CAPIError]::new($retval, 'VBVMR_Output_GetDeviceNumber') + } + } + else { + $retval = [int][Voicemeeter.Remote]::VBVMR_Input_GetDeviceNumber() + if ($retval -lt 0) { + throw [CAPIError]::new($retval, 'VBVMR_Input_GetDeviceNumber') + } + } + $retval +} + +function Device_Desc { + param( + [int]$INDEX, [bool]$IS_OUT = $false + ) + $driver = 0 + $name = [System.Byte[]]::new(512) + $hardwareid = [System.Byte[]]::new(512) + + if ($IS_OUT) { + $retval = [int][Voicemeeter.Remote]::VBVMR_Output_GetDeviceDescA($INDEX, [ref]$driver, $name, $hardwareid) + if ($retval -notin @(0)) { + throw [CAPIError]::new($retval, 'VBVMR_Output_GetDeviceDescA') + } + } + else { + $retval = [int][Voicemeeter.Remote]::VBVMR_Input_GetDeviceDescA($INDEX, [ref]$driver, $name, $hardwareid) + if ($retval -notin @(0)) { + throw [CAPIError]::new($retval, 'VBVMR_Input_GetDeviceDescA') + } + } + + $drivers = @{ + 1 = 'MME' + 3 = 'WDM' + 4 = 'KS' + 5 = 'ASIO' + } + + [PSCustomObject]@{ + Driver = $drivers[$driver] + Name = [System.Text.Encoding]::ASCII.GetString($name).Trim([char]0) + HardwareID = [System.Text.Encoding]::ASCII.GetString($hardwareid).Trim([char]0) + IsOutput = $IS_OUT + } } \ No newline at end of file diff --git a/lib/binding.ps1 b/lib/binding.ps1 index 201ff26..a5ff579 100644 --- a/lib/binding.ps1 +++ b/lib/binding.ps1 @@ -43,6 +43,15 @@ function Setup_DLL { [DllImport(@"$dll")] public static extern int VBVMR_GetLevel(Int64 mode, Int64 index, ref float ptr); + + [DllImport(@"$dll")] + public static extern int VBVMR_Output_GetDeviceNumber(); + [DllImport(@"$dll")] + public static extern int VBVMR_Input_GetDeviceNumber(); + [DllImport(@"$dll")] + public static extern int VBVMR_Output_GetDeviceDescA(Int64 index, ref int type, byte[] name, byte[] hardwareid); + [DllImport(@"$dll")] + public static extern int VBVMR_Input_GetDeviceDescA(Int64 index, ref int type, byte[] name, byte[] hardwareid); "@ Add-Type -MemberDefinition $Signature -Name Remote -Namespace Voicemeeter -PassThru | Out-Null