diff --git a/.gitignore b/.gitignore index bbbc3e5..853335c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ -**/*.psd1 +lib/*.psd1 **/*.log diff --git a/README.md b/README.md index aacd95f..e5787ae 100644 --- a/README.md +++ b/README.md @@ -190,6 +190,20 @@ $vmr.Setter('Strip[4].Label', 'stripname') $vmr.Setter('Strip[0].Gain', -3.6) ``` +### Config Files +`$vmr.Set_Profile('config')` + +You may load config files in psd1 format. An example profile has been included with the package. Remember to save current settings before loading a profile. To test simply rename _profiles directory to profiles. It will be loaded into memory but not set. To set one you may do: +```powershell +Import-Module Voicemeeter +try { + $vmr = Get-RemoteBanana + $vmr.Set_Profile("config") +} +finally { $vmr.Logout() } +``` +will load a config file at profiles/banana/config.psd1 for Voicemeeter Banana. + ### Run tests Run tests using .\runall.ps1 which accepts two parameters: - tag Run tests of this type diff --git a/_profiles/banana/config.psd1 b/_profiles/banana/config.psd1 new file mode 100644 index 0000000..5f64798 --- /dev/null +++ b/_profiles/banana/config.psd1 @@ -0,0 +1,32 @@ +@{ + strip_0 = @{ + A1 = $false + A2 = $false + A3 = $false + B1 = $false + B2 = $false + mono = $false + solo = $false + mute = $false + } + strip_1 = @{ + A1 = $true + A2 = $true + A3 = $true + B1 = $true + B2 = $true + mono = $true + solo = $true + mute = $true + } + strip_2 = @{ + A1 = $false + A2 = $false + A3 = $false + B1 = $false + B2 = $false + mono = $false + solo = $false + mute = $false + } +} diff --git a/lib/Voicemeeter.psm1 b/lib/Voicemeeter.psm1 index 8bc8bfe..5ee04d7 100644 --- a/lib/Voicemeeter.psm1 +++ b/lib/Voicemeeter.psm1 @@ -6,7 +6,8 @@ class Remote { [System.Collections.ArrayList]$bus [System.Collections.ArrayList]$button [PSCustomObject]$vban - $command + [Object]$command + [Object]$profiles # Constructor Remote ([String]$kind) @@ -18,7 +19,8 @@ class Remote { [void] Setup() { if(Setup_DLL) { Login -KIND $this.kind - + + $this.profiles = Get_Profiles $this.strip = Make_Strips $this.bus = Make_Buses $this.button = Make_Buttons @@ -32,6 +34,10 @@ class Remote { Logout } + [void] Set_Profile([String]$config) { + Set_Profile -DATA $this.profiles -CONF $config + } + [Single] Getter([String]$param) { return Param_Get -PARAM $param } diff --git a/lib/base.ps1 b/lib/base.ps1 index a3b32e0..835c0e0 100644 --- a/lib/base.ps1 +++ b/lib/base.ps1 @@ -174,7 +174,7 @@ Function DefineVersion { if($TYPE -eq 1) { $layout = @{ - "version" = "basic" + "name" = "basic" "p_in" = 2 "v_in" = 1 "p_out" = 1 @@ -185,7 +185,7 @@ Function DefineVersion { } elseif($TYPE -eq 2) { $layout = @{ - "version" = "banana" + "name" = "banana" "p_in" = 3 "v_in" = 2 "p_out" = 3 @@ -196,7 +196,7 @@ Function DefineVersion { } elseif($TYPE -eq 3) { $layout = @{ - "version" = "potato" + "name" = "potato" "p_in" = 5 "v_in" = 3 "p_out" = 5 @@ -208,6 +208,47 @@ Function DefineVersion { $global:layout = $layout } +Function Get_Profiles { + $basepath = Join-Path -Path $(Split-Path -Path $PSScriptRoot) -ChildPath "profiles" + if (Test-Path $basepath) { + $fullpath = Join-Path -Path $basepath -ChildPath $layout.name + } else {return $null} + $filenames = @(Get-ChildItem -Path $fullpath -Filter *.psd1 -Recurse -File) + + if($filenames) { + [System.Collections.ArrayList]$configfiles = @() + $filenames | ForEach-Object { + $file = (Join-Path -Path $fullpath -ChildPath $_) + $configfiles.Add($file) + } + + [HashTable]$data = @{} + $configfiles | ForEach-Object { + $filename = [System.IO.Path]::GetFileNameWithoutExtension($_) + Write-Host ("Importing profile " + $layout.name + "/" + $filename) + $data[$filename] = Import-PowerShellDataFile -Path $_ + } + return $data + } + return $null +} + +Function Set_Profile { + param( + [Object]$DATA, [String]$CONF + ) + try { + if($null -eq $DATA -or -not $DATA.$CONF) { + throw [VMRemoteErrors]::new("No profile named $CONF was loaded") + } + Param_Set_Multi -HASH $DATA.$CONF + Start-Sleep -m 1 + } + catch [VMRemoteErrors] { + Write-Warning $_.Exception.ErrorMessage() + } +} + Function Login { param( [String]$KIND=$null