Merge pull request #7 from pblivingston/iremote

Add IRemote abstract base class.
This commit is contained in:
Onyx and Iris 2025-11-26 02:33:58 +00:00 committed by GitHub
commit 4d54e0a15f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 82 additions and 192 deletions

View File

@ -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

View File

@ -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

View File

@ -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) {
}

View File

@ -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')

52
lib/iremote.ps1 Normal file
View File

@ -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
}
}

View File

@ -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) {

View File

@ -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) {
}

View File

@ -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')

View File

@ -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() {