diff --git a/CHANGELOG.md b/CHANGELOG.md index 25bfbae..6cfe68d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,9 @@ Before any major/minor/patch is released all test units will be run to verify th ## [Unreleased] These changes have not been added to PSGallery yet -- [ ] +### Added + +- IRemote base class ## [3.3.0] - 2024-06-29 diff --git a/lib/Voicemeeter.psm1 b/lib/Voicemeeter.psm1 index 10b30f3..7002acb 100644 --- a/lib/Voicemeeter.psm1 +++ b/lib/Voicemeeter.psm1 @@ -2,6 +2,7 @@ . $PSScriptRoot\meta.ps1 . $PSScriptRoot\base.ps1 . $PSScriptRoot\kinds.ps1 +. $PSScriptRoot\iremote.ps1 . $PSScriptRoot\strip.ps1 . $PSScriptRoot\bus.ps1 . $PSScriptRoot\macrobuttons.ps1 diff --git a/lib/bus.ps1 b/lib/bus.ps1 index d6dba01..d59cdee 100644 --- a/lib/bus.ps1 +++ b/lib/bus.ps1 @@ -1,40 +1,4 @@ -class IBus { - [int]$index - [Object]$remote - - IBus ([int]$index, [Object]$remote) { - $this.index = $index - $this.remote = $remote - } - - [string] identifier () { - return 'Bus[' + $this.index + ']' - } - - [single] Getter ($param) { - $this.ToString() + " Getter: $($this.Cmd($param))" | Write-Debug - return $this.remote.Getter($this.Cmd($param)) - } - - [string] Getter_String ($param) { - $this.ToString() + " Getter_String: $($this.Cmd($param))" | Write-Debug - return $this.remote.Getter_String($this.Cmd($param)) - } - - [void] Setter ($param, $val) { - $this.ToString() + " Setter: $($this.Cmd($param))=$val" | Write-Debug - $this.remote.Setter($this.Cmd($param), $val) - } - - [string] Cmd ($param) { - if ([string]::IsNullOrEmpty($param)) { - return $this.identifier() - } - return "$($this.identifier()).$param" - } -} - -class Bus : IBus { +class Bus : IRemote { [Object]$mode [Object]$eq [Object]$levels @@ -49,8 +13,8 @@ class Bus : IBus { $this.levels = [BusLevels]::new($index, $remote) } - [string] ToString() { - return $this.GetType().Name + $this.index + [string] identifier () { + return 'Bus[' + $this.index + ']' } [void] FadeTo ([single]$target, [int]$time) { @@ -62,7 +26,7 @@ class Bus : IBus { } } -class BusLevels : IBus { +class BusLevels : IRemote { [int]$init [int]$offset @@ -93,7 +57,7 @@ class BusLevels : IBus { } } -class BusMode : IBus { +class BusMode : IRemote { [System.Collections.ArrayList]$modes BusMode ([int]$index, [Object]$remote) : base ($index, $remote) { @@ -119,7 +83,7 @@ class BusMode : IBus { } } -class BusEq : IBus { +class BusEq : IRemote { BusEq ([int]$index, [Object]$remote) : base ($index, $remote) { AddBoolMembers -PARAMS @('on', 'ab') } @@ -137,7 +101,7 @@ class PhysicalBus : Bus { } } -class BusDevice : IBus { +class BusDevice : IRemote { BusDevice ([int]$index, [Object]$remote) : base ($index, $remote) { } diff --git a/lib/command.ps1 b/lib/command.ps1 index 891fc38..4f1e3c3 100644 --- a/lib/command.ps1 +++ b/lib/command.ps1 @@ -1,33 +1,12 @@ -class Special { - [Object]$remote - - Special ([Object]$remote) { +class Special : IRemote { + Special ([Object]$remote) : base ($remote) { AddActionMembers -PARAMS @('restart', 'shutdown', 'show') - - $this.remote = $remote } [string] identifier () { return 'Command' } - [string] ToString() { - return $this.GetType().Name - } - - [single] Getter ($param) { - return $this.remote.Getter("$($this.identifier()).$param") - } - - [void] Setter ($param, $val) { - if ($val -is [Boolean]) { - $this.remote.Setter("$($this.identifier()).$param", $(if ($val) { 1 } else { 0 })) - } - else { - $this.remote.Setter("$($this.identifier()).$param", $val) - } - } - [void] RunMacrobuttons() { 'Launching the MacroButtons app' | Write-Verbose Start-Process -FilePath $(Join-Path -Path $this.remote.vmpath -ChildPath 'VoicemeeterMacroButtons.exe') diff --git a/lib/iremote.ps1 b/lib/iremote.ps1 new file mode 100644 index 0000000..31a4d95 --- /dev/null +++ b/lib/iremote.ps1 @@ -0,0 +1,52 @@ +class IRemote { + [Nullable[int]]$index + [Object]$remote + + IRemote ([Object]$remote) { + $this.remote = $remote + } + + IRemote ([int]$index, [Object]$remote) { + $this.index = $index + $this.remote = $remote + } + + [single] Getter ($param) { + $this.ToString() + " Getter: $($this.Cmd($param))" | Write-Debug + return $this.remote.Getter($this.Cmd($param)) + } + + [string] Getter_String ($param) { + $this.ToString() + " Getter_String: $($this.Cmd($param))" | Write-Debug + return $this.remote.Getter_String($this.Cmd($param)) + } + + [void] Setter ($param, $val) { + $this.ToString() + " Setter: $($this.Cmd($param))=$val" | Write-Debug + if ($val -is [Boolean]) { + $this.remote.Setter($this.Cmd($param), $(if ($val) { 1 } else { 0 })) + } + else { + $this.remote.Setter($this.Cmd($param), $val) + } + } + + [string] Cmd ($param) { + if ([string]::IsNullOrEmpty($param)) { + return $this.identifier() + } + return "$($this.identifier()).$param" + } + + # Must be overridden by derived classes + [string] identifier () { + throw [System.NotImplementedException]::new("$($this.GetType().Name) must override identifier()") + } + + [string] ToString() { + if ($null -ne $this.index) { + return $this.GetType().Name + $this.index + } + return $this.GetType().Name + } +} \ No newline at end of file diff --git a/lib/recorder.ps1 b/lib/recorder.ps1 index e87cd27..c8d95dd 100644 --- a/lib/recorder.ps1 +++ b/lib/recorder.ps1 @@ -1,35 +1,4 @@ -class IRecorder { - [Object]$remote - - IRecorder ([Object]$remote) { - $this.remote = $remote - } - - [single] Getter ($param) { - $this.Cmd($param) | Write-Debug - return $this.remote.Getter($this.Cmd($param)) - } - - [void] Setter ($param, $val) { - "$($this.Cmd($param))=$val" | Write-Debug - if ($val -is [Boolean]) { - $this.remote.Setter($this.Cmd($param), $(if ($val) { 1 } else { 0 })) - } - else { - $this.remote.Setter($this.Cmd($param), $val) - } - } - - [string] Cmd ($param) { - if ([string]::IsNullOrEmpty($param)) { - return $this.identifier() - } - return "$($this.identifier()).$param" - } -} - -class Recorder : IRecorder { - [Object]$remote +class Recorder : IRemote { [Object]$mode [System.Collections.ArrayList]$armstrip [System.Collections.ArrayList]$armbus @@ -54,10 +23,6 @@ class Recorder : IRecorder { return 'Recorder' } - [string] ToString() { - return $this.GetType().Name - } - hidden $_loop = $($this | Add-Member ScriptProperty 'loop' ` { [bool]$this.mode.loop @@ -160,7 +125,7 @@ class Recorder : IRecorder { } } -class RecorderMode : IRecorder { +class RecorderMode : IRemote { RecorderMode ([Object]$remote) : base ($remote) { AddBoolMembers -PARAMS @('recbus', 'playonload', 'loop', 'multitrack') } @@ -170,11 +135,8 @@ class RecorderMode : IRecorder { } } -class RecorderArm : IRecorder { - [int]$index - - RecorderArm ([int]$index, [Object]$remote) : base ($remote) { - $this.index = $index +class RecorderArm : IRemote { + RecorderArm ([int]$index, [Object]$remote) : base ($index, $remote) { } Set ([bool]$val) { diff --git a/lib/strip.ps1 b/lib/strip.ps1 index 52e75de..2c0821e 100644 --- a/lib/strip.ps1 +++ b/lib/strip.ps1 @@ -1,40 +1,4 @@ -class IStrip { - [int]$index - [Object]$remote - - IStrip ([int]$index, [Object]$remote) { - $this.index = $index - $this.remote = $remote - } - - [string] identifier () { - return 'Strip[' + $this.index + ']' - } - - [single] Getter ($param) { - $this.Cmd($param) | Write-Debug - return $this.remote.Getter($this.Cmd($param)) - } - - [string] Getter_String ($param) { - $this.Cmd($param) | Write-Debug - return $this.remote.Getter_String($this.Cmd($param)) - } - - [void] Setter ($param, $val) { - "$($this.Cmd($param))=$val" | Write-Debug - $this.remote.Setter($this.Cmd($param), $val) - } - - [string] Cmd ($param) { - if ([string]::IsNullOrEmpty($param)) { - return $this.identifier() - } - return "$($this.identifier()).$param" - } -} - -class Strip : IStrip { +class Strip : IRemote { [Object]$levels Strip ([int]$index, [Object]$remote) : base ($index, $remote) { @@ -49,8 +13,8 @@ class Strip : IStrip { $this.levels = [StripLevels]::new($index, $remote) } - [string] ToString() { - return $this.GetType().Name + $this.index + [string] identifier () { + return 'Strip[' + $this.index + ']' } [void] FadeTo ([single]$target, [int]$time) { @@ -62,7 +26,7 @@ class Strip : IStrip { } } -class StripLevels : IStrip { +class StripLevels : IRemote { [int]$init [int]$offset @@ -128,7 +92,7 @@ class PhysicalStrip : Strip { } } -class StripComp : IStrip { +class StripComp : IRemote { StripComp ([int]$index, [Object]$remote) : base ($index, $remote) { AddFloatMembers -PARAMS @('gainin', 'ratio', 'threshold', 'attack', 'release', 'knee', 'gainout') AddBoolMembers -PARAMS @('makeup') @@ -149,7 +113,7 @@ class StripComp : IStrip { ) } -class StripGate : IStrip { +class StripGate : IRemote { StripGate ([int]$index, [Object]$remote) : base ($index, $remote) { AddFloatMembers -PARAMS @('threshold', 'damping', 'bpsidechain', 'attack', 'hold', 'release') } @@ -169,7 +133,7 @@ class StripGate : IStrip { ) } -class StripDenoiser : IStrip { +class StripDenoiser : IRemote { StripDenoiser ([int]$index, [Object]$remote) : base ($index, $remote) { } @@ -188,7 +152,7 @@ class StripDenoiser : IStrip { ) } -class StripEq : IStrip { +class StripEq : IRemote { StripEq ([int]$index, [Object]$remote) : base ($index, $remote) { AddBoolMembers -PARAMS @('on', 'ab') } @@ -198,7 +162,7 @@ class StripEq : IStrip { } } -class StripDevice : IStrip { +class StripDevice : IRemote { StripDevice ([int]$index, [Object]$remote) : base ($index, $remote) { } diff --git a/lib/vban.ps1 b/lib/vban.ps1 index 60ce9ef..ed6fb55 100644 --- a/lib/vban.ps1 +++ b/lib/vban.ps1 @@ -1,11 +1,7 @@ -class IVban { - [int32]$index - [Object]$remote +class Vban : IRemote { [string]$direction - - IVban ([int]$index, [Object]$remote, [string]$direction) { - $this.index = $index - $this.remote = $remote + + Vban ([int]$index, [Object]$remote, [string]$direction) : base ($index, $remote) { $this.direction = $direction } @@ -13,36 +9,6 @@ class IVban { return 'vban.' + $this.direction + 'stream[' + $this.index + ']' } - [single] Getter ($param) { - return $this.remote.Getter($this.Cmd($param)) - } - - [string] Getter_String ($param) { - $this.Cmd($param) | Write-Debug - return $this.remote.Getter_String($this.Cmd($param)) - } - - [void] Setter ($param, $val) { - "$($this.Cmd($param))=$val" | Write-Debug - $this.remote.Setter($this.Cmd($param), $val) - } - - [string] Cmd ($param) { - if ([string]::IsNullOrEmpty($param)) { - return $this.identifier() - } - return "$($this.identifier()).$param" - } -} - -class Vban : IVban { - Vban ([int]$index, [Object]$remote, [string]$direction) : base ($index, $remote, $direction) { - } - - [string] ToString() { - return $this.GetType().Name + $this.index - } - hidden $_on = $($this | Add-Member ScriptProperty 'on' ` { $this.Getter('on') diff --git a/tests/run.ps1 b/tests/run.ps1 index 8c4b5fd..e6eafba 100644 --- a/tests/run.ps1 +++ b/tests/run.ps1 @@ -1,6 +1,6 @@ [Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseDeclaredVarsMoreThanAssignments", "", Target = "variablename")] Param([String]$tag, [string]$kind = 'potato') -Import-Module .\lib\Voicemeeter.psm1 +Import-Module (Join-Path (Split-Path $PSScriptRoot -Parent) 'lib\Voicemeeter.psm1') -Force function main() {